In our ELF files generated via GCC linker the top of the ELF file is always the version identifier of the executable code.
This is achieved by creating version.c file and making the resulting object file the 1st linkable object in the link command.
However for one executable this has failed to work and the only difference we can find is that the executable contains a mixture of C and C++ code, and the version symbol is being relocated somewhere else.
The question is therefore is there a way of guaranteeing the absolute location of a symbol in a ELF file such that a symbol is always located at the top of the file either through linker commands or code attribute directives?
You can control the linker's output via scripts. In your case you can check: https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS for a possible solution.
For example:
SECTIONS {
.version 0x2020 : { version.o }
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) *(COMMON) }
}
This doesn't control where the sections will exactly appear in the linked executable, but it might influence it (it certainly does when dealing with ROM images), you'll have to experiment yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With