summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarealshinji <djcj@gmx.de>2015-07-13 18:09:24 (GMT)
committerdarealshinji <djcj@gmx.de>2015-07-13 18:09:24 (GMT)
commit36a33fbffbb058c9e1b632268a2727b58de90578 (patch)
tree16e9e0be1c2a096867f17151809ecca81f5aa079
parentf6886c2c33a1cf8771163919f3d20f6340c0ce38 (diff)
downloadpatchelf-36a33fbffbb058c9e1b632268a2727b58de90578.zip
patchelf-36a33fbffbb058c9e1b632268a2727b58de90578.tar.gz
patchelf-36a33fbffbb058c9e1b632268a2727b58de90578.tar.bz2
Add '--remove-rpath' option
-rw-r--r--src/patchelf.cc32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index df75593..0ef0695 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -160,7 +160,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);
@@ -1103,6 +1103,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;
@@ -1334,6 +1357,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;
@@ -1364,6 +1388,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);
@@ -1423,6 +1449,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\
@@ -1463,6 +1490,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;
}