I am compiling a C++ executable (let's say myexec) and two of the libraries it depends on (let's say mylib1.so and mylib2.so), using GCC 8.5.0, on Red Hat Enterprise Linux 8.

Running ldd myexec returns:

        linux-vdso.so.1 (0x00007ffcf9852000)                                       
        libpython3.6m.so.1.0 => /lib64/libpython3.6m.so.1.0 (0x00007fa8571aa000)   
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa856f8a000)             
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fa856d86000)                       
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fa856b82000)                   
        mylib1.so => not found  # First missing lib 
        mylib2.so => not found  # Second missing lib
        # ...more libs follow

Which means, AFAIU, that the two custom linked libraries are not found. I'd say this is expected, since the libraries are in a directory which is not searched by ldd.

I would expect that, setting LD_PRELOAD would help, so I run:

export LD_PRELOAD="/path/to/mylib1.so:/path/to/mylib2.so"
ldd myexec

which returns me:

        linux-vdso.so.1 (0x00007fc5a293c000)                                       
        /path/to/mylib1.so (0x00007fc5a31ed000)  # First lib found
        /path/to/mylib2.so (0x00007fc5a2e7e000)  # Second lib found
        libpython3.6m.so.1.0 => /lib64/libpython3.6m.so.1.0 (0x00007fc5a293c000)   
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc5a271c000)             
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fc5a2518000)                       
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fc5a2314000)                   
        mylib1.so => not found   # First lib...also NOT found?
        # ...more libs follow   

Note that mylib2.so is found, but mylib1.so is listed twice, both as found and not found.

So, my question is: how come mylib1.so is missing, if ldd lists it? Does it have to do with symbols not being found in the one I'm trying to link with LD_PRELOAD?


Edit: Even more cryptic for me is that soft-linking the mylib1.so library in /usr/lib64 leads to:

        linux-vdso.so.1 (0x00007fff3c3e7000)                                       
        /path/to/mylib1.so (0x00007f5dc2cfa000)  # First lib found
        /path/to/mylib2.so (0x00007f5dc298b000)  # Second lib found
        libpython3.6m.so.1.0 => /lib64/libpython3.6m.so.1.0 (0x00007f5dc2449000)   
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f5dc2229000)             
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f5dc2025000)                       
        libutil.so.1 => /lib64/libutil.so.1 (0x00007f5dc1e21000)                    
        # ...more libs follow

i.e. The mylib1.so => not found entry is gone. However, I don't want to solve the issue like that, as it would mean messing with all other users of the machine.


Edit 2: I tried setting LD_LIBRARY_PATH to something like /dir/containing/mylib1/ but it does not work, still not finding the mylib1.so. In the end LD_LIBRARY_PATH worked, and it seems like one viable solution, but I would still like to know why LD_PRELOAD was not honored.


Edit 3: Running LD_DEBUG=all ldd myexec lists some extra info which I still don't understand:

     57257:     file=/path/to/mylib1.so [0];  needed by /path/to/myexec [0]
     57257:     file=/path/to/mylib1 [0];  generating link map
     57257:       dynamic: 0x00007f7d44ecdd40  base: 0x00007f7d44cbd000   size: 0x00000000002114c0
     57257:         entry: 0x00007f7d44cc2eb0  phdr: 0x00007f7d44cbd040  phnum:                  9

     # ... more lines follow
     
     57257:     file=mylib1.so [0];  needed by /path/to/myexec [0]
     57257:     find library=mylib1.so [0]; searching
     57257:      search cache=/etc/ld.so.cache

     # ... searches all remaining paths, like /usr/lib64, where I decided to make a soft link>

So it finds the mylib1.so I specify with LD_PRELOAD, but it's not satisfied, and keeps on searching for it.

0

There are 0 best solutions below