summaryrefslogtreecommitdiffstats
path: root/src/patchelf.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-05-28 11:31:54 (GMT)
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-05-28 11:31:54 (GMT)
commit1f713dd5684829f1714e161aae6c64e295e68e5a (patch)
treefa9fea0dfbd2b5b3d2bc351c8b2f39c0333ca3e5 /src/patchelf.cc
parent15ba1450c3e9878e6e9aa8dad28a64f39b51bc6c (diff)
downloadpatchelf-1f713dd5684829f1714e161aae6c64e295e68e5a.zip
patchelf-1f713dd5684829f1714e161aae6c64e295e68e5a.tar.gz
patchelf-1f713dd5684829f1714e161aae6c64e295e68e5a.tar.bz2
* Add the DT_RUNPATH (or DT_RPATH) entry to the top of the .dynamic
section, otherwise "readelf" barfs for unknown reasons.
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r--src/patchelf.cc19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 27e220d..f47c814 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -1016,21 +1016,18 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath)
rdi(shdrDynamic.sh_size) + sizeof(Elf_Dyn));
unsigned int idx = 0;
- dyn = (Elf_Dyn *) newDynamic.c_str();
- for ( ; rdi(dyn->d_tag) != DT_NULL; dyn++, idx++) ;
-
+ for ( ; rdi(((Elf_Dyn *) newDynamic.c_str())[idx].d_tag) != DT_NULL; idx++) ;
debug("DT_NULL index is %d\n", idx);
-
+
+ /* Shift all entries down by one. */
+ setSubstr(newDynamic, sizeof(Elf_Dyn),
+ string(newDynamic, 0, sizeof(Elf_Dyn) * (idx + 1)));
+
+ /* Add the DT_RUNPATH entry at the top. */
Elf_Dyn newDyn;
wri(newDyn.d_tag, forceRPath ? DT_RPATH : DT_RUNPATH);
newDyn.d_un.d_val = shdrDynStr.sh_size;
- setSubstr(newDynamic, idx * sizeof(Elf_Dyn),
- string((char *) &newDyn, sizeof(Elf_Dyn)));
-
- wri(newDyn.d_tag, DT_NULL);
- wri(newDyn.d_un.d_val, 0);
- setSubstr(newDynamic, (idx + 1) * sizeof(Elf_Dyn),
- string((char *) &newDyn, sizeof(Elf_Dyn)));
+ setSubstr(newDynamic, 0, string((char *) &newDyn, sizeof(Elf_Dyn)));
}
}