Define new code section in assembly code to compile ELF binary

 ̄綄美尐妖づ 提交于 2021-01-28 08:06:41

问题


I defined a new code section in my assembly program, which is going to be compiled into 32-bit ELF binary, on x86.

I use the linker scripts to assign a specified address for this new code section, it works. However, I noticed that this new section does not be loaded to the memory, after some debugging!

I use readelf and figure out that there is no "execution" privilege of this new section:

[15] .trampoline       PROGBITS        080483d0 004020 000117 00      0   0 16

Then I did this:

objcopy --set-section-flags .trampoline=alloc,code a.out

However, I got this warning:

BFD: stQWykoH: warning: allocated section `.trampoline' not in segment

Now I realize that I didn't explicitly assign a segment information to my new section!!

So here is my question:

  1. How to assign a segment information to a new code section I defined? I double-checked the linker script (follow instruction here to dump), and I have no idea how to modify the script...

  2. I just want to add a new executable section to my assembly program, and assign a fixed address to this new section. So am I on the right way now?

来源:https://stackoverflow.com/questions/28440283/define-new-code-section-in-assembly-code-to-compile-elf-binary

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