How set set entry point in a elf target using ld script

孤街浪徒 提交于 2019-12-13 01:17:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!