git.iko.soy/typeable/nixpkgs
on master help sign in
meson: Fix rpath clearing

Meson allows projects to set `build_rpath` property, containing paths that will be added during build but will be removed when installing. When Meson removes build_rpath from `DT_RUNPATH` entry, it just writes the shorter ␀-terminated new rpath over the old one to reduce the risk of potentially breaking the ELF files (when the linker does string de-duplication or something). But this can cause much bigger problem for Nix, as it can produce cut-in-half-by-␀ store path references. For example, in systemd’s libudev, it was removing three `$ORIGIN`-relative paths from $ORIGIN/../libsystemd:$ORIGIN/../basic:$ORIGIN/../shared:…␀ resulting in the following `DT_RUNPATH` entry: …␀store/v589pqjhvxrj73g3r0xb41yr84z5pwb7-gcc-9.3.0-lib/lib␀ We previously handled this in `fix-rpath.patch` but the method we prevent Meson from removing paths added to rpath through `NIX_LDFLAGS` was changed during 0.55.0 update and I forgot about this second purpose of the patch. Let’s re-add this clearing code, as it worked without issues for a long time.

commit74ea2b2123672e43a41d3142070ac50eab46b60f authorJan Tojnar <jtojnar@gmail.com> dateTue 11 Aug 2020, 15:30 (6 years ago) parent66dd4f3
2 files changed+28
pkgs/development/tools/build-managers/meson/clear-old-rpath.patch+20 pkgs/development/tools/build-managers/meson/default.nix+8
pkgs/development/tools/build-managers/meson/clear-old-rpath.patchnew file+20
@@ -0,0 +1,20 @@
1+diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py
2+index 77ac03d66..d12f77592 100644
3+--- a/mesonbuild/scripts/depfixer.py
4++++ b/mesonbuild/scripts/depfixer.py
5+@@ -337,6 +337,15 @@ class Elf(DataSizes):
6+ if not new_rpath:
7+ self.remove_rpath_entry(entrynum)
8+ else:
9++ # Clear old rpath to avoid stale references,
10++ # not heeding the warning above about de-duplication
11++ # since it does not seem to cause issues for us
12++ # and not doing so trips up Nix’s reference checker.
13++ # See https://github.com/NixOS/nixpkgs/pull/46020
14++ # and https://github.com/NixOS/nixpkgs/issues/95163
15++ self.bf.seek(rp_off)
16++ self.bf.write(b'\0'*len(old_rpath))
17++
18+ self.bf.seek(rp_off)
19+ self.bf.write(new_rpath)
20+ self.bf.write(b'\0')
pkgs/development/tools/build-managers/meson/default.nix+8
@@ -43,6 +43,14 @@ python3.pkgs.buildPythonApplication rec {
4343 src = ./fix-rpath.patch;
4444 inherit (builtins) storeDir;
4545 })
46+
47+ # When Meson removes build_rpath from DT_RUNPATH entry, it just writes
48+ # the shorter NUL-terminated new rpath over the old one to reduce
49+ # the risk of potentially breaking the ELF files.
50+ # But this can cause much bigger problem for Nix as it can produce
51+ # cut-in-half-by-\0 store path references.
52+ # Let’s just clear the whole rpath and hope for the best.
53+ ./clear-old-rpath.patch
4654 ];
4755
4856 setupHook = ./setup-hook.sh;