I have an elf binary that was statically linked to libc. I do not have access to his C code. I would like to use the OpenOnload library, which has a socket implementation in user space and therefore provides lower latency compared to standard libc versions. OpenOnload implements a standard api socket and overrides the libc version using LD_PRELOAD. But since this elven binary system is statically connected, it cannot use the version of the OpenOnload socket API.
I believe it is possible to convert this binary to a dynamic connection with OpenOnload with the following steps:
- Add new program titles: PT_INTERP, PT_DYNAMIC and PT_LOAD.
- Add entries to PT_DYNAMIC to determine libc dependency.
- Add PLT stubs for the required libc functions to the new PT_LOAD section.
- Modify the existing binary for libc functions to go to the corresponding PLT stubs.
As the first cut, I tried just adding 3 PT_LOAD segments. New segment headers have been added after existing PT_LOAD segment headers. In addition, vm_addr of existing segments has not been changed. The file offset of existing segments was shifted lower to the next aligned address based on p_align. New PT_LOAD segments have been added to the file at the end of the file.
After re-writing the file, when I ran it, it was loaded properly by the kernel, but then it immediately failed.
My questions:
- If I just shift the file offset in the elf binary without changing vm_addresses, can it cause any error when the binary is launched?
- Can I do what I'm trying to do? Has anyone tried to do this?
c linux elf openonload
javed
source share