Bug#841846: meson: breaks DT_MIPS_RLD_MAP_REL elf entry when removing RPATH entry

Aurelien Jarno <[email protected]>
Newsgroups gmane.linux.debian.ports.mips
Message-ID <[email protected]>
Package: meson
Version: 0.35.1-1
Severity: important
Tags: patch upstream

The depfixer.py script in meson has the possibility to remove RPATH or
RUNPATH entries. It does this by moving all of the other dynamic tags up
one entry. Unfortunately some of the tags are relative to the offset of
the tag within the executable. That is at least the case of the
DT_MIPS_RLD_MAP_REL tag on MIPS, and it results into broken binaries
which segfaults.

The patch below fixes the issue by adjusting the value of the
DT_MIPS_RLD_MAP_REL tag when it is shifted, the same way it is done in
chrpath.

diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py
index 7124c6f..34fb2f7 100755
--- a/mesonbuild/scripts/depfixer.py
+++ b/mesonbuild/scripts/depfixer.py
@@ -23,6 +23,7 @@ DT_RPATH = 15
 DT_RUNPATH = 29
 DT_STRTAB = 5
 DT_SONAME = 14
+DT_MIPS_RLD_MAP_REL = 1879048245
 
 class DataSizes():
     def __init__(self, ptrsize, is_le):
@@ -307,6 +308,11 @@ class Elf(DataSizes):
                 rpentry.d_tag = 0
                 self.dynamic = self.dynamic[:i] + self.dynamic[i+1:] + [rpentry]
                 break;
+        # DT_MIPS_RLD_MAP_REL is relative to the offset of the tag. Adjust it consequently.
+        for entry in self.dynamic[i:]:
+            if entry.d_tag == DT_MIPS_RLD_MAP_REL:
+                entry.val += 2 * (self.ptrsize // 8)
+                break
         self.bf.seek(sec.sh_offset)
         for entry in self.dynamic:
             entry.write(self.bf)

-- System Information:
Debian Release: stretch/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: mips64el (mips64)

Kernel: Linux 4.7.0-1-5kc-malta
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.