From 0e47e74a77447575cbabd71315481c6dd9632601 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Thu, 13 Apr 2017 23:27:40 +0300 Subject: Do not obliterate old rpath because it might be used due to read only data sharing. Closes #1619. --- mesonbuild/scripts/depfixer.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'mesonbuild') diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py index 1404619..16050d7 100644 --- a/mesonbuild/scripts/depfixer.py +++ b/mesonbuild/scripts/depfixer.py @@ -297,11 +297,20 @@ class Elf(DataSizes): old_rpath = self.read_str() if len(old_rpath) < len(new_rpath): sys.exit("New rpath must not be longer than the old one.") - self.bf.seek(rp_off) - self.bf.write(new_rpath) - self.bf.write(b'\0' * (len(old_rpath) - len(new_rpath) + 1)) + # The linker does read-only string deduplication. If there is a + # string that shares a suffix with the rpath, they might get + # dedupped. This means changing the rpath string might break something + # completely unrelated. This has already happened once with X.org. + # Thus we want to keep this change as small as possible to minimize + # the chance of obliterating other strings. It might still happen + # but our behaviour is identical to what chrpath does and it has + # been in use for ages so based on that this should be rare. if len(new_rpath) == 0: self.remove_rpath_entry(entrynum) + else: + self.bf.seek(rp_off) + self.bf.write(new_rpath) + self.bf.write(b'\0') def remove_rpath_entry(self, entrynum): sec = self.find_section(b'.dynamic') -- cgit v1.1