Is there a way to check the current rpath on Linux?

I know you can use 'readelf -d | grep RPATH 'to check the given bit from the shell, but is it possible to do this in the process?

Something like (my fully composed system call):

/* get a copy of current rpath into buffer */ sys_get_current_rpath(&buffer); 

I am trying to diagnose some suspicious SO binding problems in our code base and would like to test RPATH if possible (I would prefer not to create an external script).

+49
linux rpath
May 14 '10 at 17:42
source share
3 answers
 #include <stdio.h> #include <elf.h> #include <link.h> int main() { const ElfW(Dyn) *dyn = _DYNAMIC; const ElfW(Dyn) *rpath = NULL; const char *strtab = NULL; for (; dyn->d_tag != DT_NULL; ++dyn) { if (dyn->d_tag == DT_RPATH) { rpath = dyn; } else if (dyn->d_tag == DT_STRTAB) { strtab = (const char *)dyn->d_un.d_val; } } if (strtab != NULL && rpath != NULL) { printf("RPATH: %s\n", strtab + rpath->d_un.d_val); } return 0; } 
+38
May 17 '10 at 4:52
source share

For the record, here are a few commands that will display the rpath header.

 objdump -x binary-or-library |grep RPATH 

Perhaps an even better way to do this is:

 readelf -d binary-or-library |head -20 

The second command also displays direct dependencies on other libraries, followed by rpath .

+96
Jun 14 '11 at 18:39
source share

perhaps you can use the code from github.com/NixOS/patchelf, but AFAIK is not an ATM library.

0
Jan 18 '17 at 13:46 on
source share



All Articles