Ld.so alternatives

I need to make a linux executable "compile once, work everywhere". In theory this is possible because my program only uses the most basic system calls (system calls for network IO and file IO). In practice, this is a different story:

My development platform is Ubuntu 12.04 which has a fairly recent kernel, glibc, and toolchain. I tried a static link to my executable first, but the executable refuses to run on centos 5 (kernel version 2.6.18). If the executable is dynamically linked, the dynamic loader (ld.so) refuses to load my executable. I even tried to send a modified dynamic loader (I modified it to ignore the kernel version), libc, libgcc_s still doesn't work because the modified loader always tries to load libc from the system and ignore the libc sent along with my executable.

I need a dynamic loader that will blindly load whatever I want to load. Does anyone know of such a dynamic bootloader on linux? I'm not sure if I'll go back in the right direction, so any suggestion is appreciated.

+3


source to share


3 answers


check

http://sourceforge.net/projects/html5remote/

      

In this project, I played around with patchElf, LD_PRELOAD, and LD_LIBRARY_PATH.

There are several ways to make relative paths work. After some experimentation, I've come to the conclusion that patching the target binary is not required as ld.so can be used to load the target program directly from the command line, e.g .:

$ / lib64 / ld-linux-x86-64.so.2 [OPTION] ... EXECUTABLE-FILE [ARGS-FOR-PROGRAM ...]

In this case, the interpreter written in the elf header of the target binary is ignored, ex:



$ ldd / usr / bin / mysql

    linux-vdso.so.1 =>  (0x00007fff3fde0000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72f89ea000)
    libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f72f87a8000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f72f8590000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72f838c000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f72f8090000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72f7cd0000)
    /original/path/to/ld.so (0x00007f72f9187000) ** ignored **
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f72f7aa9000)

      

Option:

- library path

tells the loader ld.so where to look for shared libraries (ex: libc.so, etc.)

Hope this helps :)

+3


source


Try using CentOS 5 as your build machine and run the executable on newer platforms and not vice versa.



+2


source


0


source







All Articles