From 67898b4f6e30964267c3e3a47fc591d7af5ce9fc Mon Sep 17 00:00:00 2001 From: Haonan Chen Date: Sat, 20 Dec 2025 17:15:37 +0800 Subject: [PATCH] bintools-wrapper: fix rpath handling with symlinks in the store #454199 --- .../bintools-wrapper/ld-wrapper.sh | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index 944e45edac1b..ae76e7a223f7 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -202,13 +202,32 @@ if [[ "$NIX_DONT_SET_RPATH_@suffixSalt@" != 1 && "$linkType" != static-pie ]]; t # the link time chosen objects will be those of runtime linking. declare -A rpaths for dir in ${libDirs+"${libDirs[@]}"}; do - if [[ "$dir" =~ [/.][/.] ]] && dir2=$(readlink -f "$dir"); then + # If the path is in the store, do not resolve any symlinks and add it to the rpath. + # Resolving symlinks in the store breaks bootstrapping, see issue #454199. + # If it is outside the store, resolve symlinks step by step until it falls + # into the store or it becomes not a symlink. + # Always canonicalize the path before checking it is in the store or not. + if dir2=$(realpath -s "$dir"); then dir="$dir2" + else + continue fi + while [ -z "${rpaths[$dir]:-}" ] && [[ "$dir" != "${NIX_STORE:-}"/* ]] && [ -L "$dir" ]; do + if dir2=$(readlink "$dir"); then + dir="dir2" + else + break + fi + if dir2=$(realpath -s "$dir"); then + dir="dir2" + else + break + fi + done + # If the path turns out to be outside the store, we do not add it to rpath. + # This typically happens for libraries in /tmp that are later + # copied to $out/lib. If not, we're screwed. if [ -n "${rpaths[$dir]:-}" ] || [[ "$dir" != "${NIX_STORE:-}"/* ]]; then - # If the path is not in the store, don't add it to the rpath. - # This typically happens for libraries in /tmp that are later - # copied to $out/lib. If not, we're screwed. continue fi for path in "$dir"/*; do