2010-01-17

display the RUNPATH/RPATH of a Unix binary

First a short explanation what RUNPATH / RPATH is and why we want to use it. You know about shared libraries and their advantages over static linking. You also encountered the "shared object xxx not found" problem. There dynamic linker looks in four places for shared objects, in this order:

  1. the environment variable LD_LIBRARY_PATH
  2. a global file /etc/ld.so.conf or its cache /etc/ld.so.cache
  3. the RPATH and RUNPATH information in the executables header
  4. some hardwired default paths like /lib and /usr/lib
Working with binaries, it is advisable to avoid the first two methods whenever possible. They should be left to sysadmins and as a last resort.

RPATH and RUNPATH information is created at link time.

This is how to extract and display RPATH and RUNPATH from a given binary files:

Solaris:
/usr/ccs/bin/dump -Lv <binary> | egrep 'RPATH|RUNPATH'

Linux:
/usr/bin/objdump -p <binary> | egrep 'RPATH|RUNPATH'

1 comment:

  1. I just discovered the utility eu-readelf -d which comes with the package elfutils. It does the same as objdump but looks more thorough.

    ReplyDelete