HOWTO debug shared libraries

Background: I am refactoring a large codebase, with an objective to cut and trim the fats (unused code / obsoleted features) out.

Compile normally works — a good IDE would help you with that. When tests begin to fail because of missing entries, there are several ways:

  1. Use -z flag
    Without the flag, compile & link will succeed:

    $ gcc -shared -fPIC -o libsilly.so silly.c && echo succeeded || echo failed
    

    Without the flag, compile & link will succeed:

    $ gcc -shared -fPIC -o libsilly.so silly.c -Wl,-z,defs && echo succeeded || echo failed
     
  2. Use nm
    While ar shows the object files in the library, nm is your good friend for hunting that broken dependency/forgotten implementations:

    nm -C -u libshared.so
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s