From d401bfc00f6bd9fd65bf6d9b92c7ba72f98f2aa2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 28 Oct 2026 00:30:11 +0000 Subject: [PATCH] bintools-wrapper: look only at shared libraries in library directories To decide whether a store library directory belongs in the rpath, ld-wrapper looks up each entry of the directory among the libraries being linked. But those are all named lib*.so (from -l), or *.so or *.so.* (when given by path), so only entries matching *.so* can be among them. List only those, leaving bash with far fewer entries to look up; the directory is still read just once. Linking an empty C program with 1500 different store library directories, which together have 12241 entries but only 7614 matching *.so*, now takes about 0.40 s instead of 0.44 s, in a VM where starting a process is slow. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Anders Kaseorg --- pkgs/build-support/bintools-wrapper/ld-wrapper.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index f85c448ba4f6..dd751666a1c9 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -221,7 +221,9 @@ if [[ "$NIX_DONT_SET_RPATH_@suffixSalt@" != 1 && "$linkType" != static-pie ]]; t if [ -n "${rpaths[$dir]:-}" ] || [[ "$dir" != "${NIX_STORE:-}"/* ]]; then continue fi - for path in "$dir"/*; do + # Every name in libs is that of a shared library, ending in .so or + # containing .so., so the rest of the directory can be skipped. + for path in "$dir"/*.so*; do file="${path##*/}" if [ "${libs[$file]:-}" ]; then # This library may have been provided by a previous directory,