对于个人项目,我需要编写一个在非默认内存地址加载的可执行文件。从这个 SO question中,我知道我可以设置 ELF 的入口地址并手动修改部分地址,以便可执行文件有效地基于我选择的某个地址。但是,答案表明,这仅在我不进行 glibc 初始化(我需要此项目)的情况下才有效,并且每次编译时都设置段内存地址会很困难(更不用说乏味了)。
似乎应该有更好的方法在构建时为 ELF 设置基地址,但如果需要,我将使用构建后的脚本手动进行。ld
如果它不是特定于 PE 端口的,则此选项将是完美的:
--image-base value
Use value as the base address of your program or dll. This is the lowest
memory location that will be used when your program or dll is loaded. To
reduce the need to relocate and improve performance of your dlls, each should
have a unique base address and not overlap any other dlls. The default is
0x400000 for executables, and 0x10000000 for dlls. [This option is specific
to the i386 PE targeted port of the linker]
我还没有找到一个 ELF 等价物。不存在吗?自己解析 ELF 文件不会是世界末日,但似乎这个功能应该存在于某个地方。