Linked StaticLib Relocated OutOf Kernel Image To New Address
Posted: Mon Sep 28, 2009 1:17 pm
I have a small static ELF library with both code and data that I want to be able to relocate (entirely in userspace) to the address 0xFCFF0000 (which is usermode) at runtime, then jump to. It needs to be at this address - the reason why is irrelevant. However, I want it to be loaded around where the code and data of the rest of the executable is (~0x1000). The library only has to run it's main routines after being relocated, so I don't think I need position independent code.
There are two problems I've encountered:
1. It is hard to delimit the code/data I need to copy with symbols, so I can find it.
2. I can't figure out how to make the code run at one address but be loaded at another.
The first one is hard because I can't use a linker script (afaik) when creating a static library, and therefore can't insert symbols around the library's code/data segments. It also seems like it would be bad to have separate ELF sections for this library's code and data, because that would require modifying the system-wide linker script, and not many programs use this library (pretty much only the shell does).
The second one, regardless of its similarity to bootstrapping an ELF higher half kernel, is hard because the physical address field in the ELF program header is ignored for userspace loading, preventing the higher half kernel linker script trick. Is the only option here to use position independent code so that I don't have to care which address it is written to run at?
What is the best way to solve these problems?
Thanks,
Nick
There are two problems I've encountered:
1. It is hard to delimit the code/data I need to copy with symbols, so I can find it.
2. I can't figure out how to make the code run at one address but be loaded at another.
The first one is hard because I can't use a linker script (afaik) when creating a static library, and therefore can't insert symbols around the library's code/data segments. It also seems like it would be bad to have separate ELF sections for this library's code and data, because that would require modifying the system-wide linker script, and not many programs use this library (pretty much only the shell does).
The second one, regardless of its similarity to bootstrapping an ELF higher half kernel, is hard because the physical address field in the ELF program header is ignored for userspace loading, preventing the higher half kernel linker script trick. Is the only option here to use position independent code so that I don't have to care which address it is written to run at?
What is the best way to solve these problems?
Thanks,
Nick