dladdr link issues

I compulsively must resolve things to their very heart, or I feel like I am living in chaos. So here is the issue. When I use my sighandler code it needs to be linked with -ldl, which makes sense. If I link it with -lSDL_mixer it links without err. That is what scares me. What possible method could be at work here to link an address to nowhere, which is what it must be.

Sadly, I am going to strip the code to its simplest form and see how and what that link becomes, so I can find where the flaw arises, or if there is some link magic that is beyond me. I will put the results here as I find them.

`strings /usr/lib/libdl.so | grep dladdr` finds the element and also `nm -D /usr/lib/libdl.so| grep dladdr` shows the link and mixer does not. It runs contrary to a basic concept in my thinking. How can I link to an external object when that object is not defined? Bizzarre! I will find out what is going on and report my solution here in this post.

#include <dlfcn.h>
int main(){
void *ip = 0;Dl_info dlinfo;
dladdr(ip, &dlinfo);
return 0;}
 Wed Dec 23 09:52 AM$ gcc testdl.c -D_GNU_SOURCE
/tmp/cc6Wkaq8.o: In function `main':
testdl.c:(.text+0x19): undefined reference to `dladdr'
collect2: ld returned 1 exit status
 Wed Dec 23 09:52 AM$ gcc testdl.c -D_GNU_SOURCE -lSDL_mixer
 Wed Dec 23 09:52 AM$ gcc testdl.c -D_GNU_SOURCE -lSDL_mixer
 Wed Dec 23 09:53 AM$ gcc testdl.c -D_GNU_SOURCE -ldl
 Wed Dec 23 09:53 AM$ gcc testdl.c -D_GNU_SOURCE
/tmp/ccOffYal.o: In function `main':
testdl.c:(.text+0x19): undefined reference to `dladdr'
collect2: ld returned 1 exit status
 Wed Dec 23 09:53 AM$   

Now into the assembly code, as I still have no idea how this could even happen, or what library it is linked with. There is no dladdr in SDL_mixer and yet it links! I don't get it, but when I am done it should be very enlightening.

 Wed Dec 23 10:07 AM$ gcc testdl.c -D_GNU_SOURCE -ldl
 Wed Dec 23 10:08 AM$ ldd a.out
        linux-vdso.so.1 =>  (0x00007fff489fe000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007fdc40562000)
        libc.so.6 => /lib/libc.so.6 (0x00007fdc40200000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fdc40766000)
 Wed Dec 23 10:08 AM$ gcc testdl.c -D_GNU_SOURCE -lSDL_mixer
 Wed Dec 23 10:08 AM$ ldd a.out
        linux-vdso.so.1 =>  (0x00007fff613fe000)
        libSDL_mixer-1.2.so.0 => /usr/lib/libSDL_mixer-1.2.so.0 (0x00007ff958e2b000)
        libc.so.6 => /lib/libc.so.6 (0x00007ff958ac9000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007ff9588c5000)
        libm.so.6 => /lib/libm.so.6 (0x00007ff958644000)
        libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0x00007ff9583a5000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff9590a7000)
        libasound.so.2 => /usr/lib/libasound.so.2 (0x00007ff9580ca000)
        libartsc.so.0 => /usr/lib/libartsc.so.0 (0x00007ff957ec4000)
        libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x00007ff957cc1000)
        libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x00007ff957abd000)
        librt.so.1 => /lib/librt.so.1 (0x00007ff9578b4000)
        libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007ff9575f4000)
        libesd.so.0 => /usr/lib/libesd.so.0 (0x00007ff9573ea000)
        libaudiofile.so.0 => /usr/lib/libaudiofile.so.0 (0x00007ff9571c2000)
        libpulse-simple.so.0 => /usr/lib/libpulse-simple.so.0 (0x00007ff956fb5000)
        libpulse.so.0 => /usr/lib/libpulse.so.0 (0x00007ff956d66000)
        libaudio.so.2 => /usr/lib/libaudio.so.2 (0x00007ff956b4d000)
        libXt.so.6 => /usr/lib/libXt.so.6 (0x00007ff9568e9000)
        libdirectfb-1.0.so.0 => /usr/lib/libdirectfb-1.0.so.0 (0x00007ff95667b000)
        libfusion-1.0.so.0 => /usr/lib/libfusion-1.0.so.0 (0x00007ff956473000)
        libdirect-1.0.so.0 => /usr/lib/libdirect-1.0.so.0 (0x00007ff95625e000)
        libaa.so.1 => /usr/lib/libaa.so.1 (0x00007ff95603f000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00007ff955e23000)
        libpcre.so.3 => /usr/lib/libpcre.so.3 (0x00007ff955bfd000)
        libcap.so.1 => /lib/libcap.so.1 (0x00007ff9559f9000)
        libSM.so.6 => /usr/lib/libSM.so.6 (0x00007ff9557f1000)
        libICE.so.6 => /usr/lib/libICE.so.6 (0x00007ff9555d6000)
        libX11.so.6 => /usr/lib/libX11.so.6 (0x00007ff9552d3000)
        libncurses.so.5 => /lib/libncurses.so.5 (0x00007ff955098000)
        libslang.so.2 => /lib/libslang.so.2 (0x00007ff954d4d000)
        libgpm.so.1 => /usr/lib/libgpm.so.1 (0x00007ff954b47000)
        libxcb-xlib.so.0 => /usr/lib/libxcb-xlib.so.0 (0x00007ff954946000)
        libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007ff95472b000)
        libXau.so.6 => /usr/lib/libXau.so.6 (0x00007ff954529000)
        libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007ff954324000)
 Wed Dec 23 10:08 AM$   

This is the answer and though it is mundane, I still think it is informative for me at least. This "libdl.so.2 => /lib/libdl.so.2 (0x00007ff9588c5000)" library which is included as an associated library with SDL is the answer. I just wonder what SDL is doing with that, but I am sure it is something nice :). Some libraries can include other libraries when linking and this is something I did not factor into my overall understanding of the process. I was under the impression that it had to be literal and that seems like a poor choice of assumption, as it would be unworkable and horribly burdensome.

 Wed Dec 23 10:19 AM$ strings /usr/lib/libSDL_sound-1.0.so.1.0.0 | grep libdl
libdl.so.2

So the final answer is that there is link magic taking place and I was not aware of the process, now I am smarter and I am more comfortable with my stupidity.

0 comments:

Contributors

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen