From 818d0f8cf1aeec10c1370b5534c1393c4ced265b Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Sat, 14 Jan 2023 19:07:39 +0100 Subject: [PATCH 1/2] auto-patchelf: don't resolve symlinks if basenames don't match The auto-patchelf python script assembles a list of library (so=shared object) file names and their paths. This helps speed up the discovery of library files later when patching elf files. As further optimization, if a symlink points to a library file, the script uses the resolved path and file name. However, this produces a broken list entry if the symlink's target name doesn't match the symlink's name. A symptom of the bug, affecting the `tsm-client` package, is fixed in https://github.com/NixOS/nixpkgs/pull/172372 . The commit at hand stops resolving symlinks if the target name differs from the symlink's name. The commit has been authored by layus (Guillaume Maudoux ) in pull request comment https://github.com/NixOS/nixpkgs/pull/172372#issuecomment-1194687183 --- pkgs/build-support/setup-hooks/auto-patchelf.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.py b/pkgs/build-support/setup-hooks/auto-patchelf.py index efb65a809962..e731feb1b125 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.py +++ b/pkgs/build-support/setup-hooks/auto-patchelf.py @@ -131,7 +131,14 @@ def populate_cache(initial: List[Path], recursive: bool =False) -> None: if not path.is_file(): continue + # As an optimisation, resolve the symlinks here, as the target is unique + # XXX: (layus, 2022-07-25) is this really an optimisation in all cases ? + # It could make the rpath bigger or break the fragile precedence of $out. resolved = path.resolve() + # Do not use resolved paths when names do not match + if resolved.name != path.name: + resolved = path + try: with open_elf(path) as elf: osabi = get_osabi(elf) From 57c8c6c3d2c9afec2a57433f0c06560e90724c4e Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Sat, 14 Jan 2023 19:22:38 +0100 Subject: [PATCH 2/2] Revert "tsm-client: fix patching rpath with autoPatchelf" This reverts commit 1ed9ba08f1e83a5fdcebcffa0aff2d5b4452c9b1. After the underlying bug in `auto-patchelf.py` got fixed, this workaround is no longer necessary. --- pkgs/tools/backup/tsm-client/default.nix | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pkgs/tools/backup/tsm-client/default.nix b/pkgs/tools/backup/tsm-client/default.nix index ef94eee2429f..03bd62924048 100644 --- a/pkgs/tools/backup/tsm-client/default.nix +++ b/pkgs/tools/backup/tsm-client/default.nix @@ -159,16 +159,6 @@ let ln --symbolic --force --no-target-directory "$out/$(cut -b 7- <<< "$target")" "$link" done ''; - - # since 7b9fd5d1c9802131ca0a01ff08a3ff64379d2df4 - # autopatchelf misses to add $out/lib to rpath; - # we have to call autopatchelf manually as it would - # run too late and overwrite our rpath otherwise - dontAutoPatchelf = true; - postFixup = '' - autoPatchelf $out - patchelf --add-rpath $out/lib $out/lib/* - ''; }; binPath = lib.makeBinPath ([ acl gnugrep procps ]