From 58ec67927fb649a8325c016f04e050d17f787d66 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 30 Sep 2005 23:04:25 +0000 Subject: * `patchelf --set-rpath': short case. --- src/patchelf.cc | 39 ++++++++++++++++++++++++++++----------- tests/Makefile.am | 2 +- tests/set-rpath.sh | 13 ++++++------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index 1932fa3..a5b804b 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -437,15 +437,23 @@ static void modifyRPath(RPathOp op, string newRPath) } - if (string(rpath) != newRPath) { - assert(newRPath.size() <= strlen(rpath)); - /* Zero out the previous rpath to prevent retained - dependencies in Nix. */ - memset(rpath, 0, strlen(rpath)); + if (string(rpath) == newRPath) return; + + changed = true; + + /* Zero out the previous rpath to prevent retained + dependencies in Nix. */ + unsigned int rpathSize = strlen(rpath); + memset(rpath, 0, rpathSize); + + fprintf(stderr, "new rpath is `%s'\n", newRPath.c_str()); + + if (newRPath.size() <= rpathSize) { strcpy(rpath, newRPath.c_str()); - changed = true; + return; } - + + fprintf(stderr, "rpath is too long, resizing...\n"); } @@ -499,11 +507,13 @@ static void parseElf() } +static bool printInterpreter = false; static string newInterpreter; static bool shrinkRPath = false; +static bool setRPath = false; static bool printRPath = false; -static bool printInterpreter = false; +static string newRPath; static void patchElf() @@ -527,12 +537,14 @@ static void patchElf() if (newInterpreter != "") setInterpreter(newInterpreter); - if (shrinkRPath) - modifyRPath(rpShrink, ""); - if (printRPath) modifyRPath(rpPrint, ""); + if (shrinkRPath) + modifyRPath(rpShrink, ""); + else if (setRPath) + modifyRPath(rpSet, newRPath); + if (changed){ rewriteSections(); @@ -567,6 +579,11 @@ int main(int argc, char * * argv) else if (arg == "--shrink-rpath") { shrinkRPath = true; } + else if (arg == "--set-rpath") { + if (++i == argc) error("missing argument"); + setRPath = true; + newRPath = argv[i]; + } else if (arg == "--print-rpath") { printRPath = true; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 45d8c16..ccd86dd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,7 @@ check_PROGRAMS = main simple TESTS = plain-run.sh shrink.sh set-interpreter-short.sh \ - set-interpreter-long.sh $(XFAIL_TESTS) # set-rpath.sh + set-interpreter-long.sh set-rpath.sh $(XFAIL_TESTS) XFAIL_TESTS = plain-fail.sh diff --git a/tests/set-rpath.sh b/tests/set-rpath.sh index e3c3fe4..6446395 100755 --- a/tests/set-rpath.sh +++ b/tests/set-rpath.sh @@ -1,17 +1,16 @@ #! /bin/sh -e -oldInterpreter=$(../src/patchelf --print-interpreter ./simple) -echo "current interpreter is $oldInterpreter" - rm -rf scratch mkdir -p scratch +mkdir -p scratch/libsA +mkdir -p scratch/libsB cp main scratch/ -cp libfoo.so scratch/ -cp libbar.so scratch/ +cp libfoo.so scratch/libsA/ +cp libbar.so scratch/libsB/ -../src/patchelf --set-rpath $(pwd)/scratch scratch/main -../src/patchelf --set-rpath $(pwd)/scratch scratch/libfoo.so +../src/patchelf --set-rpath $(pwd)/scratch/libsA scratch/main +../src/patchelf --set-rpath $(pwd)/scratch/libsB scratch/libsA/libfoo.so exitCode=0 scratch/main || exitCode=$? -- cgit v0.12