From 4743ad90cf53b3a451f51917f920296512992e52 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Thu, 14 May 2015 16:53:51 +0300 Subject: [PATCH] When new rpath is empty, remove rpath defintion from the dynamic entry table too because an empty rpath is different from a nonexisting one and this causes problems when building rpms. Closes #110. --- depfixer.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/depfixer.py b/depfixer.py index 8db7ab62f..c240935ab 100755 --- a/depfixer.py +++ b/depfixer.py @@ -52,6 +52,7 @@ def init_datasizes(self, ptrsize, is_le): class DynamicEntry(): def __init__(self, ifile, ptrsize, is_le): init_datasizes(self, ptrsize, is_le) + self.ptrsize = ptrsize if ptrsize == 64: self.d_tag = struct.unpack(self.Sxword, ifile.read(self.SxwordSize))[0]; self.val = struct.unpack(self.XWord, ifile.read(self.XWordSize))[0]; @@ -59,6 +60,14 @@ class DynamicEntry(): self.d_tag = struct.unpack(self.Sword, ifile.read(self.SwordSize))[0] self.val = struct.unpack(self.Word, ifile.read(self.WordSize))[0] + def write(self, ofile): + if self.ptrsize == 64: + ofile.write(struct.pack(self.Sxword, self.d_tag)) + ofile.write(struct.pack(self.XWord, self.val)) + else: + ofile.write(struct.pack(self.Sword, self.d_tag)) + ofile.write(struct.pack(self.Word, self.val)) + class SectionHeader(): def __init__(self, ifile, ptrsize, is_le): init_datasizes(self, ptrsize, is_le) @@ -259,6 +268,21 @@ class Elf(): self.bf.seek(rp_off) self.bf.write(new_rpath) self.bf.write(b'\0'*(len(old_rpath) - len(new_rpath) + 1)) + if len(new_rpath) == 0: + self.remove_rpath_entry() + + def remove_rpath_entry(self): + sec = self.find_section(b'.dynamic') + for (i, entry) in enumerate(self.dynamic): + if entry.d_tag == DT_RPATH: + rpentry = self.dynamic[i] + rpentry.d_tag = 0 + self.dynamic = self.dynamic[:i] + self.dynamic[i+1:] + [rpentry] + break; + self.bf.seek(sec.sh_offset) + for entry in self.dynamic: + entry.write(self.bf) + return None if __name__ == '__main__': if len(sys.argv) < 2 or len(sys.argv) > 3: