How to set the start address of the text segment?
Posted: Thu Aug 18, 2011 11:48 pm
I am trying to build dummy executables to test my loader. I can get 32-bit executables to link with the specified text segment start address, but 64-bit ones always seem to be linked with a text segment start address of 0, with the specified address only affecting the start of the text section within the segment rather than the start of the segment itself (i.e. there is a large amount of padding between the ELF header and the start of the text section). How do I prevent the text segment from being padded to start at 0 (and why does this only happen to 64-bit executables)?
Here is the linker script that I am using (the only difference between 32- and 64-bit versions are the OUTPUT_FORMAT and OUTPUT_ARCH lines). It is based on the libpayload linker script from coreboot. I am building my executables with GNU ld on Linux.
Here is the linker script that I am using (the only difference between 32- and 64-bit versions are the OUTPUT_FORMAT and OUTPUT_ARCH lines). It is based on the libpayload linker script from coreboot. I am building my executables with GNU ld on Linux.
Code: Select all
BASE_ADDRESS = 0x100000;
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
HEAP_SIZE = 16384;
STACK_SIZE = 16384;
SECTIONS
{
. = BASE_ADDRESS;
.text : {
*(.text._entry)
*(.text)
*(.text.*)
}
.rodata : {
*(.rodata)
*(.rodata.*)
}
. = ALIGN(0x1000);
_etext = .;
.data : {
*(.data)
*(.data.*)
}
_edata = .;
.bss : {
*(.sbss)
*(.sbss.*)
*(.bss)
*(.bss.*)
*(COMMON)
/* Stack and heap */
. = ALIGN(16);
_heap = .;
. += HEAP_SIZE;
. = ALIGN(16);
_eheap = .;
_estack = .;
. += STACK_SIZE;
. = ALIGN(16);
_stack = .;
}
_end = .;
/DISCARD/ : {
*(.comment)
*(.note.gnu.build-id)
}
}