How to load a program in memory at a different address than it is intended for?

狂风中的少年 提交于 2019-12-11 02:42:07

问题


Generally the user program binaries will be loaded in low address (usually around 0x400000) in the programs address space which will be specified in the elf binary (in the case of linux).

Can we force a user binary to load at a high address, possibly within the 2GB range of addresses where libc or other such libraries are loaded?

I have tried finding a solution on the net but could not find any concrete solution for this.

(I am working on Ubuntu 12.10 64bit OS)

Thanks


回答1:


Unless the binary is position-independent (PIE), this is not possible. Normal (non-PIE) binaries are hard-coded for a particular load address at link time, and during linking, the information necessary for relocating to a different address was already lost.

Edit: The above is assuming you're working with an existing binary. If you are producing the binary yourself, you can control the load address that's hard-coded into it with the following link options:

-Wl,-Ttext-segment,0x80000000

replacing 0x80000000 by your desired address. Certain addresses (such as those reserved for kernel use, typically beginning at 0xc0000000) will not work, and the address must be page-aligned (the last 3 hex digits must be 0).



来源:https://stackoverflow.com/questions/20234148/how-to-load-a-program-in-memory-at-a-different-address-than-it-is-intended-for

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