From 93582802573349d1c4f7d6c0317318bf70ef46fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=A5=A4?= Date: Mon, 13 Jun 2016 10:26:24 +0800 Subject: [PATCH] add --shrink-prefix used for build while package is not installed --- patchelf.1 | 3 +++ src/patchelf.cc | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/patchelf.1 b/patchelf.1 index 8067dff0..05856d63 100644 --- a/patchelf.1 +++ b/patchelf.1 @@ -53,6 +53,9 @@ For instance, if an executable references one library libfoo.so, has an RPATH "/lib:/usr/lib:/foo/lib", and libfoo.so can only be found in /foo/lib, then the new RPATH will be "/foo/lib". +.IP --shrink-prefix +Work with --shrink-rpath, used in stage of build before installed to real dest path. + .IP --print-rpath Prints the RPATH for an executable or library. diff --git a/src/patchelf.cc b/src/patchelf.cc index ca8fb49e..299408e5 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -1092,7 +1092,13 @@ void ElfFile::modifyRPath(RPathOp op, string newRPath) needed library. */ if (op == rpShrink) { static vector neededLibFound(neededLibs.size(), false); + string shrinkPath; + if (newRPath != "") { + shrinkPath = newRPath; + } + else + shrinkPath = ""; newRPath = ""; char * pos = rpath; @@ -1117,7 +1123,12 @@ void ElfFile::modifyRPath(RPathOp op, string newRPath) bool libFound = false; for (unsigned int j = 0; j < neededLibs.size(); ++j) if (!neededLibFound[j]) { - string libName = dirName + "/" + neededLibs[j]; + string libName; + if (shrinkPath != "") { + libName = shrinkPath + "/" + dirName + "/" + neededLibs[j]; + } + else + libName = dirName + "/" + neededLibs[j]; struct stat st; if (stat(libName.c_str(), &st) == 0) { neededLibFound[j] = true; @@ -1455,6 +1466,7 @@ static bool setSoname = false; static string newSoname; static string newInterpreter; static bool shrinkRPath = false; +static string shrinkPrefix; static bool removeRPath = false; static bool setRPath = false; static bool printRPath = false; @@ -1486,7 +1498,7 @@ static void patchElf2(ElfFile & elfFile) elfFile.modifyRPath(elfFile.rpPrint, ""); if (shrinkRPath) - elfFile.modifyRPath(elfFile.rpShrink, ""); + elfFile.modifyRPath(elfFile.rpShrink, shrinkPrefix); else if (removeRPath) elfFile.modifyRPath(elfFile.rpRemove, ""); else if (setRPath) @@ -1553,6 +1565,7 @@ void showHelp(const string & progName) [--set-rpath RPATH]\n\ [--remove-rpath]\n\ [--shrink-rpath]\n\ + [--shrink-prefix]\n\ [--print-rpath]\n\ [--force-rpath]\n\ [--add-needed LIBRARY]\n\ @@ -1604,6 +1617,10 @@ int main(int argc, char * * argv) else if (arg == "--shrink-rpath") { shrinkRPath = true; } + else if (arg == "--shrink-prefix") { + if (++i == argc) error("missing argument"); + shrinkPrefix = argv[i]; + } else if (arg == "--set-rpath") { if (++i == argc) error("missing argument"); setRPath = true;