开发者

gcc -nostdlib and mudflap

I need to run my program in another linux distro which does not have the mudflap library installed and has a different glibc version. I have tried to compile my program with -static but it is not possible:

warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

So, I'm trying -nostdlib and attaching the libs manually but get these errors:

myuser@linux:~/Desktop$ gcc -nostdlib -Wl,-dynamic-linker,/home/myuser/Desktop/ld-linux-x86-64.so.2,-rpath,/home/myuser/Desktop /home/myuser/Desktop/libc.so.6 -fmudflap /home/myuser/Desktop/libmudflap.so.0 /home/myuser/Desktop开发者_StackOverflow社区/libdl.so.2 simple.c
myuser@linux:~/Desktop$ ./a.out
mf: dlsym("mmap") = NULL
Aborted (core dumped)
myuser@linux:~/Desktop$ ldd a.out
    linux-vdso.so.1 =>  (0x00007fff2bad2000)
    libc.so.6 => /home/myuser/Desktop/libc.so.6 (0x00007fddfd521000)
    libmudflap.so.0 => /home/myuser/Desktop/libmudflap.so.0 (0x00007fddfd175000)
    libdl.so.2 => /home/myuser/Desktop/libdl.so.2 (0x00007fddfcf70000)
    /home/myuser/Desktop/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007fddfd884000)
myuser@linux:~/Desktop$
  1. Which ld is really being used ? The one in my Desktop or the one in /lib64 ?
  2. What other flags have to be included to make it compile correctly ?


Instead of trying to link libraries statically, carry them with your executable, and have either LD_LIBRARY_PATH or rpath point to the directory containing them.

But never carry the libc, if you are linking your program on an older libc version you should be safe. This means that you need to compile your application in an environment that is either older or exactly the same as the target systems.

You may be able to get away with a more recent system, as long as you don't use symbols that got versioned updates between the compiling and the target system.

Static linking is unfortunately much more complicated than it sounds.


Not so complicated. Use strace to find out what libraries your binary links to.

gcc -Xlinker -rpath=/path/to/provided/libs -Xlinker -I/path/to/provided/linker/ld-2.11.2.so -std=c99 -D_POSIX_C_SOURCE=200112L -fmudflap /path/to/provided/mudflap/libmudflap.so.0 simple.c

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜