cygwin-dll-link: improve search path order

The search order will now be:

1. link target path
2. output bin paths
3. explicit input paths (e.g. libc)
4. HOST_PATH
This commit is contained in:
David McFarland 2026-02-08 18:51:59 -04:00
parent f2ac4eef52
commit f5353dd50e
2 changed files with 10 additions and 7 deletions

View file

@ -603,7 +603,7 @@ stdenvNoCC.mkDerivation {
installPhase =
if targetPlatform.isCygwin then
''
echo addToSearchPath "HOST_PATH" "${cc_solib}/bin" >> $out
echo addToSearchPath "_linkDeps_inputPath" "${cc_solib}/bin" >> $out
# Work around build failure caused by the gnulib workaround for
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after
# gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep)

View file

@ -8,13 +8,15 @@ _moveDLLsToLib() {
preFixupHooks+=(_moveDLLsToLib)
addOutputDLLPaths() {
declare _linkDeps_inputPath _linkDeps_outputPath
_addOutputDLLPaths() {
for output in $(getAllOutputNames); do
addToSearchPath "HOST_PATH" "${!output}/bin"
addToSearchPath _linkDeps_outputPath "${!output}/bin"
done
}
preFixupHooks+=(addOutputDLLPaths)
preFixupHooks+=(_addOutputDLLPaths)
_dllDeps() {
@objdump@ -p "$1" \
@ -35,12 +37,13 @@ _linkDeps() {
continue
fi
# Locate the DLL - it should be an *executable* file on $HOST_PATH.
local dllPath
if ! dllPath="$(PATH="$(dirname "$target"):$HOST_PATH" type -P "$dll")"; then
local dllPath searchPath
searchPath=$(dirname "$target"):$_linkDeps_outputPath:$_linkDeps_inputPath:$HOST_PATH
if ! dllPath="$(PATH="$searchPath" type -P "$dll")"; then
if [[ -z "$check" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then
continue
fi
echo unable to find "$dll" in "$HOST_PATH" >&2
echo unable to find "$dll" in "$searchPath" >&2
exit 1
fi
echo ' linking to:' "$dllPath"