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 <andersk@mit.edu>
(cherry picked from commit d401bfc00f)
This commit is contained in:
Anders Kaseorg
2026-10-28 00:30:11 +00:00
committed by github-actions[bot]
parent dff6a2d844
commit 4015c7572f

View File

@@ -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,