diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-07-23 21:38:11 (GMT) |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-07-23 21:38:11 (GMT) |
commit | 719b4aa4c8cc70727e80ec1af34766d4ddcafcea (patch) | |
tree | 859a8098ac5f4668b5c20d221e859027c88a65a3 | |
parent | a0c441999ea95292e6dac7d5998a909a0cd44b2d (diff) | |
parent | 36a33fbffbb058c9e1b632268a2727b58de90578 (diff) | |
download | patchelf-719b4aa4c8cc70727e80ec1af34766d4ddcafcea.zip patchelf-719b4aa4c8cc70727e80ec1af34766d4ddcafcea.tar.gz patchelf-719b4aa4c8cc70727e80ec1af34766d4ddcafcea.tar.bz2 |
Merge branch 'patch-3' of https://github.com/darealshinji/patchelfmod
-rw-r--r-- | src/patchelf.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index ac83859..8771776 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -154,7 +154,7 @@ public: void setInterpreter(const string & newInterpreter); - typedef enum { rpPrint, rpShrink, rpSet } RPathOp; + typedef enum { rpPrint, rpShrink, rpSet, rpRemove } RPathOp; void modifyRPath(RPathOp op, string newRPath); @@ -1097,6 +1097,29 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath) } } + if (op == rpRemove) { + if (!rpath) { + debug("no RPATH to delete\n"); + return; + } + + Elf_Dyn * dyn = (Elf_Dyn *) (contents + rdi(shdrDynamic.sh_offset)); + Elf_Dyn * last = dyn; + for ( ; rdi(dyn->d_tag) != DT_NULL; dyn++) { + if (rdi(dyn->d_tag) == DT_RPATH) { + debug("removing DT_RPATH entry\n"); + changed = true; + } else if (rdi(dyn->d_tag) == DT_RUNPATH) { + debug("removing DT_RUNPATH entry\n"); + changed = true; + } else { + *last++ = *dyn; + } + } + memset(last, 0, sizeof(Elf_Dyn) * (dyn - last)); + return; + } + if (string(rpath ? rpath : "") == newRPath) return; @@ -1328,6 +1351,7 @@ static string newSoname; static string newInterpreter; static bool shrinkRPath = false; +static bool removeRPath = false; static bool setRPath = false; static bool printRPath = false; static string newRPath; @@ -1358,6 +1382,8 @@ static void patchElf2(ElfFile & elfFile, mode_t fileMode) if (shrinkRPath) elfFile.modifyRPath(elfFile.rpShrink, ""); + else if (removeRPath) + elfFile.modifyRPath(elfFile.rpRemove, ""); else if (setRPath) elfFile.modifyRPath(elfFile.rpSet, newRPath); @@ -1419,6 +1445,7 @@ void showHelp(const string & progName) [--print-soname]\t\tPrints 'DT_SONAME' entry of .dynamic section. Raises an error if DT_SONAME doesn't exist\n\ [--set-soname SONAME]\t\tSets 'DT_SONAME' entry to SONAME. Raises an error if DT_SONAME doesn't exist\n\ [--set-rpath RPATH]\n\ + [--remove-rpath]\n\ [--shrink-rpath]\n\ [--print-rpath]\n\ [--force-rpath]\n\ @@ -1459,6 +1486,9 @@ int main(int argc, char * * argv) setSoname = true; newSoname = argv[i]; } + else if (arg == "--remove-rpath") { + removeRPath = true; + } else if (arg == "--shrink-rpath") { shrinkRPath = true; } |