Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LD_LIBRARY_PATH side effects

Tags:

linux

bash

unix

ld

I am having strange side effects on changing LD_LIBRARY_PATH.

When I append a path containing a library, e.g. :

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_path/lib

Then, everything becomes unbelievably slow. For example, a simple ls can be 10 seconds long.

ldd output is exactly the same before and after the LD_LIBRARY_PATH change and I tried to debug the execution of the slow ls with strace : I get the exact same execution in both cases. The execution does not even get stuck during the execution of ls (since strace does not output anything during the 10-second lag and then suddenly perfectly executes ls). So I thought it could come from my shell, but this is the same, running strace on my bash and executing ls in both cases gives me the same strace output : the shell executes ls and wait for the end of its execution (the last strace output before the lag strace is waitpid(...)). So I guess something wrong happens between the the launch of ls and its execution, like if it was a kernel-level issue. It really acts like if a sleep was made on ls (0 cpu usage).

During the lag, my CPU and network activity are perfectly normal...

Note that the library in the new LD path does not conflict with any "standard library", so it does not disturb ls in my example.

So I am interesting in deeper explanations about LD_LIBRARY_PATH side effects or how to deeply debug my example.

like image 388
Julio Guerra Avatar asked Jun 05 '12 15:06

Julio Guerra


People also ask

How does LD_LIBRARY_PATH work?

The LD_LIBRARY_PATH environment variable tells Linux applications, such as the JVM, where to find shared libraries when they are located in a different directory from the directory that is specified in the header section of the program.

Why not use LD_LIBRARY_PATH?

For security reasons, LD_LIBRARY_PATH is ignored at runtime for executables that have their setuid or setgid bit set. This severely limits the usefulness of LD_LIBRARY_PATH.

What is LD in LD_LIBRARY_PATH?

LD_LIBRARY_PATH - stands for LOAD LIBRARY PATH or some times called as LOADER LIBRARY PATH.


1 Answers

This post is quit old, so I don't know if you find already a solution. Anyway, I don't know if this may help, but in most modern GNU/Linux systems, the use of LD_LIBRARY_PATH is deprecated and discouraged.

Therefore I have a couple of suggestions:

  1. if you want to continue using it, try first by pre-pending instead of appending your library path to the LD_LIBRARY_PATH. This should help if there is something that takes long time to scan the path in previous library directories.

  2. Use LDCONFIG system, which is the (new) proper way of using LD directories nowadays. You simply have to add the path to your library in /etc/ld.so.conf file, or better, add a file in /etc/ld.so.conf.d/ which contains the path to your library (it will be sourced if there is an include directive in /etc/ld.so.conf, which is usually the case by default). Then run sudo ldconfig to update the system LD search path.

I hope this help. Cheers

like image 98
Danduk82 Avatar answered Sep 22 '22 12:09

Danduk82