I'm aware that it is possible to use readelf -d <elf> | grep RPATH
to inspect a given binary from the shell, but is it possible to do this within a process?
Something like (my completely made up system call):
/* get a copy of current rpath into buffer */ sys_get_current_rpath(&buffer);
I'm trying to diagnose some suspect SO linking issues in our codebase, and would like to inspect the RPATH this way if possible (I'd rather not have to spawn an external script).
If there is a way to add the rPath tag to the library, that would be the best option. You can create a shell wrapper that would set LD_LIBRARY_PATH , call the app via exec and pass all arguments to the app itself via $@ . You can putt a wrapper in path, call it app for example and call the real app app-bin .
In computing, rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries. Specifically, it encodes a path to shared libraries into the header of an executable (or another shared library).
Both rpath and runpath are used to specify directories to search for shared libraries(dynamic libraries). If you are not sure what shared libraries is, I have a story written on Static vs Dynamic libraries. Shared libraries are libraries which are not bundles along with the executable. They are loaded at the run time.
The RPATH entries for directories contained within the build tree can be made relative to enable relocatable builds and to help achieve reproducible builds by omitting the build directory from the build environment.
For the record, here are a couple of commands that will show the rpath
header.
objdump -x binary-or-library |grep RPATH
Maybe an even better way to do it is the following:
readelf -d binary-or-library |head -20
The second command also lists the direct dependencies on other libraries followed by rpath
.
#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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With