Linux Debugging: Listing Shared Libraries at Runtime

I had a library (a python plugin) that crashed and outputted the “very useful”:

illegal instruction

I tried pdb (the Python Debugger) to find the issue without success.

So I tried to add some printf to this library but none were outputted at runtime.  So I guessed the illegal instructions was generated by the shared libraries.

Let’s see how many libraries we’ve got:

ldd libbrowsernode.so | wc -l
125

Oh dear!… 125 libraries.. This is where panic sets in.

Luckily, there is a simple way to list the dynamic libraries as they are loaded (and some more useful info). Simply set:

export LD_DEBUG=files

before running your program. This is extremely verbose, so I recommend you redirect the output to a file.

This method allowed me to find undefined symbols during dynamic libraries load time with errors such as:

opening file=/usr/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-png.so [0]; direct_opencount=1
14121:
14121:     /usr/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-png.so: error: symbol lookup error: undefined symbol: g_module_check_init (fatal)
14121:     /usr/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-png.so: error: symbol lookup error: undefined symbol: g_module_unload (fatal)

or even:

/usr/bin/python: error: symbol lookup error: undefined symbol: nspr_use_zone_allocator (fatal)

Finally, you just need to find the libraries containing those symbols to fix the issue.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX Rockchip RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
1 Comment
oldest
newest
Ikem
11 years ago

Speaking about libraries, I never get LD_PRELOAD to work.

Would you write a post about it?

Boardcon Rockchip RK3588S SBC with 8K, WiFI 6, 4G LTE, NVME SSD, HDMI 2.1...