For a personal project, I need to write an executable that loads at a non-default memory address. From this SO question, I know I can set the entry address for an ELF and modify the section addresses manually so that the executable is effectively based at some address I choose. However, the answer suggests that this is only works if I don't glibc initialization (which I need for this project), and setting section memory addresses every time I compile would be difficult (not to mention tedious).
It seems like there should be a better way to set a base address for an ELF when building, though I'll resort to doing it manually with a script post-build if need be. This option for ld
would be perfect if it wasn't specific to the PE port:
--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]
I haven't yet found an ELF equivalent. Does none exist? Parsing the ELF file myself wouldn't be the end of the world, but it seems like this feature should exist somewhere.