Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ld.so alternatives

I need to make my linux executable "compile once, run everywhere". Theoretically it's possible, because my program only use very basic system calls (system calls for network IO and file IO). In practice, it's a different story:

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

I need a dynamic loader which would blindly load everything I want it to load. Anyone knows such a dynamic loader on linux ? I'm not sure whether I'm heading to the right direction, so any suggestion is welcome.

like image 852
user416983 Avatar asked Jan 29 '13 05:01

user416983


1 Answers

please check

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

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

There are some tricks to make relative paths working. After some experiments I came to the conclusion that patching the target binary is not necessary because the ld.so can be used to load the target program directly from the command line, ex:

$ /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)

The option:

--library-path

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

I hope this can help :)

like image 127
Piero Randazzo Avatar answered Oct 19 '22 02:10

Piero Randazzo