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 3,770 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 Путлер Капут 六四事 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
- 586
- 4
- 12
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 Путлер Капут 六四事
- 302,449
- 85
- 1,093
- 879
0
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
- 10,343
- 7
- 50
- 55