Search code examples
cmodulelinkerlibtool

What is the difference between libdl and libltdl?


What is the difference between libdl and libltdl. I just noticed that libodbc links to both of them

ldd /usr/lib/x86_64-linux-gnu/libodbc.so.2 | grep -i dl
    libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f411b822000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f411b01f000)

I know Perl links again libdl.

ldd /usr/bin/perl | grep -i dl
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f55faa2e000)

I see two seperate shared objects on the system,

ls -lah /usr/lib/x86_64-linux-gnu/libltdl.so.7.3.1 /lib/x86_64-linux-gnu/libdl-2.26.so 
-rw-r--r-- 1 root root 39K Aug 20  2016 /usr/lib/x86_64-linux-gnu/libltdl.so.7.3.1
-rw-r--r-- 1 root root 15K Oct 11 15:21 /lib/x86_64-linux-gnu/libdl-2.26.so

They both link to similar stuff too,

ldd /usr/lib/x86_64-linux-gnu/libltdl.so.7.3.1
    linux-vdso.so.1 =>  (0x00007ffc3e66b000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007efcbad4c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007efcba96c000)
    /lib64/ld-linux-x86-64.so.2 (0x00007efcbb15a000)
ldd /lib/x86_64-linux-gnu/libdl-2.26.so
    linux-vdso.so.1 =>  (0x00007ffe7889c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbc9a14e000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fbc9a732000)

What makes libltdl different?


Solution

  • It's a feature of libtool to provide a libdl API (e.g. dlopen) for many different platforms that have the same or similar functionality (e.g. POSIX's dlopen etc., Windows's LoadLibrary etc.), and shared library emulation for platforms whose linkers don't support dynamic linking.

    I did some analysis on libodbc.so.2 on my Linux box. nm -D seems to show only libltdl symbols for libodbc.so.2, and objdump -p seems to have only libltdl.so.7 in the NEEDED section, so ldd doesn't seem to be printing out entirely accurate info in this case (Your grep output appears similar to what I see).