简体   繁体   English

如何将程序加载到与目标地址不同的内存中?

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

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). 通常,用户程序二进制文件将被加载到程序地址空间的低地址(通常为0x400000左右)中,该地址将在elf二进制文件中指定(对于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? 我们是否可以强制将用户二进制文件加载到较高的地址(可能在2GB范围内的libc或其他此类库已加载的地址)内?

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) (我正在使用Ubuntu 12.10 64位操作系统)

Thanks 谢谢

Unless the binary is position-independent (PIE), this is not possible. 除非二进制文件与位置无关(PIE),否则这是不可能的。 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. 正常(非PIE)二进制文件在链接时针对特定的加载地址进行了硬编码,并且在链接期间,重新定位到其他地址所需的信息已经丢失。

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. 用您想要的地址替换0x80000000 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). 某些地址(例如保留给内核使用的地址,通常从0xc0000000开始)将不起作用,并且该地址必须是页面对齐的(最后3个十六进制数字必须为0)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM