Tag Archives: debugging

Peeking into the linux loader

This post is as much as a tip as a demonstration on how beautifully simple it is to “look-neath-the-hood” when working with linux. This is the reason why linux programmers are happy programmers. Anyways, on with the details.
If you have ever seen errors like …

error while loading shared libraries: foo.so: cannot load shared object file: No such file or directory

when you know that foo.so exists, or have see something like ….

java.lang.UnsatisfiedLinkError: no foobar in shared library path
java.lang.UnsatisfiedLinkError: /some/module/soandso.so: libstdc++.so.6: cannot handle TLS data

you may use the LD_DEBUG feature to zoom-in on the problem.

The linux loader (/lib/ld-<version>.so) looks at the environment variable “LD_DEBUG” to print out interesting debug information as it loads libraries and resolves symbols. What exactly is printed out depends on the value that the variable is set to. You may get the list of valid values by setting LD_DEBUG=help. For example:

$ LD_DEBUG=help ls
Valid options for the LD_DEBUG environment variable are:

libs display library search paths
reloc display relocation processing
files display progress for input file
symbols display symbol table processing
bindings display information about symbol binding
versions display version dependencies
all all previous options combined
statistics display relocation statistics
unused determined unused DSOs
help display this help message and exit

To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

What you make of this info. and how much it helps depends on the specific problems you are facing but all in all this is a useful thing to know when you are facing ^library issues^. More detailed information about working/writing libraries on linux is available at the Program Library HOWTO