问题
Is there a way to force gcc
or ld
place code section at the end of output ELF-format file?
Maybe I can force them not to produce any other section except .text
if, for example, I dont have anything in .data, .rodata, .bss
and other sections?
回答1:
The minimal version of script that worked for me looked like:
ENTRY(_start)
SECTIONS
{
.data : { *(.data) }
.bss : { *(.bss) *(COMMON) }
.text : { *(.text) }
}
But after I've made some more research (docs here) I've replaced this script with default one (ld --verbose
). Then I've just placed code section in the very end of verbose script and it worked perfectly.
来源:https://stackoverflow.com/questions/41882899/swap-sections-in-elf