问题
I want to specify the entry point to my ELF file using the linker script. I already defined some sections in my ELF, so want to set an entry point also withit. Can anyone tell me how to do it?
回答1:
There's a special (GNU) linker script command that sets entry point to given symbol's address ENTRY(symbol)
. Refer to official documentation.
回答2:
First get the current linker script to a file with:
ld --verbose a.o | sed '/======/,/======/!d;//d' > myscript
Here we filtered the lines between =====
, as mentioned at: How to select lines between two marker patterns which may occur multiple times with awk/sed
Then edit the ENTRY(_start)
line to your desired symbol.
Finally use -T
to select the custom script:
ld --verbose -T myscript a.o
回答3:
Looks like the command line argument -e entryName
is the way to go about it. A man ld
should give you a heads up as well.
来源:https://stackoverflow.com/questions/30390932/how-set-set-entry-point-in-a-elf-target-using-ld-script