From 64e3c5d087dc5c94bf2bc5698608daf546fdcf2d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 29 Sep 2005 15:58:41 +0000 Subject: * Add an operation `--print-rpath' to print the RPATH of the library or executable and exit. --- src/patchelf.c | 14 ++++++++++++-- tests/shrink.sh | 14 +++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/patchelf.c b/src/patchelf.c index adf1c8f..a957aa1 100644 --- a/src/patchelf.c +++ b/src/patchelf.c @@ -16,6 +16,7 @@ static char * fileName = 0; static char * newInterpreter = 0; static int doShrinkRPath = 0; +static int printRPath = 0; static int printInterpreter = 0; @@ -188,7 +189,7 @@ static void concat(char * dst, char * src) static void shrinkRPath(void) { /* Shrink the RPATH. */ - if (doShrinkRPath) { + if (doShrinkRPath || printRPath) { /* Find the .dynamic section. */ int i, dynSec = 0; @@ -241,6 +242,11 @@ static void shrinkRPath(void) } } + if (printRPath) { + printf("%s\n", rpath ? rpath : ""); + exit(0); + } + if (!rpath) { fprintf(stderr, "no RPATH to shrink\n"); return; @@ -311,7 +317,7 @@ static void shrinkRPath(void) static void patchElf(void) { - if (!printInterpreter) + if (!printInterpreter && !printRPath) fprintf(stderr, "patching ELF file `%s'\n", fileName); mode_t fileMode; @@ -395,6 +401,7 @@ int main(int argc, char * * argv) [--interpreter FILENAME]\n\ [--print-interpreter]\n\ [--shrink-rpath]\n\ + [--print-rpath]\n\ FILENAME\n", argv[0]); return 1; } @@ -411,6 +418,9 @@ int main(int argc, char * * argv) else if (strcmp(argv[i], "--shrink-rpath") == 0) { doShrinkRPath = 1; } + else if (strcmp(argv[i], "--print-rpath") == 0) { + printRPath = 1; + } else break; } diff --git a/tests/shrink.sh b/tests/shrink.sh index fe50346..563270f 100755 --- a/tests/shrink.sh +++ b/tests/shrink.sh @@ -1,8 +1,8 @@ #! /bin/sh -e -echo -n "RPATH before: " -readelf -a ./libfoo.so | grep RPATH -if ! readelf -a ./libfoo.so | grep RPATH | grep -q /no-such-path; then +rpath=$(../src/patchelf --print-rpath ./libfoo.so) +echo "RPATH before: $rpath" +if ! echo "$rpath" | grep -q /no-such-path; then echo "incomplete RPATH" exit 1 fi @@ -12,10 +12,10 @@ mkdir -p scratch cp libfoo.so scratch/ ../src/patchelf --shrink-rpath scratch/libfoo.so -echo -n "RPATH after: " -readelf -a scratch/libfoo.so | grep RPATH -if readelf -a scratch/libfoo.so | grep RPATH | grep -q /no-such-path; then - echo "incomplete RPATH" +rpath=$(../src/patchelf --print-rpath scratch/libfoo.so) +echo "RPATH after: $rpath" +if echo "$rpath" | grep -q /no-such-path; then + echo "RPATH not shrunk" exit 1 fi -- cgit v0.12