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?
Asked
Active
Viewed 4,800 times
1
-
Related: C level: http://stackoverflow.com/questions/3097825/is-there-a-gcc-compiler-linker-option-to-change-the-name-of-main , assembly level: http://stackoverflow.com/questions/6563663/how-to-compile-assembly-whose-entry-point-is-not-main-with-gcc – Ciro Santilli OurBigBook.com Jul 13 '15 at 23:08
3 Answers
3
There's a special (GNU) linker script command that sets entry point to given symbol's address ENTRY(symbol)
. Refer to official documentation.

Werkov
- 606
- 5
- 12
1
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.

CTS_AE
- 12,987
- 8
- 62
- 63
0
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

Community
- 1
- 1

Ciro Santilli OurBigBook.com
- 347,512
- 102
- 1,199
- 985