Created attachment 7515 [details]
Commit 0f70b6b is causing *all* search paths to be prefixed with '='. AFAICS though, this is incorrect for $exec_prefix/$target_alias/lib* and $exec_prefix/$TOOL_LIB/lib*; these directories generally exist in the real root and not in the sysroot.
Steps to reproduce:
1) configure binutils with a non-native --target and --with-sysroot
3) ./ld/ld-new --verbose | grep SEARCH_DIR
You will see entries such as SEARCH_DIR("=/usr/$target/lib") and (on multilib targets) SEARCH_DIR("=/usr/$target/lib64"). IIUC these should not be sysroot-prefixed.
There is probably a much better way of fixing this, but I'm attaching a possible patch.
I believe the sysroot general equivalent should be "=/lib".
(Adjustable by target emulparams script to e.g. "=/lib32", "=/lib64" etc.)
When a sysroot is in use, libraries usually end up in =/lib and =/usr/lib (or =/mingw/lib for *-*-mingw*), but $exec_prefix/$target_alias/lib has still been scanned. Not only is that not happening at the moment, but sysrooting that directory really doesn't make sense.
(In reply to Cygwin/X maintainer from comment #2)
> When a sysroot is in use, libraries usually end up in =/lib and =/usr/lib
> (or =/mingw/lib for *-*-mingw*), but $exec_prefix/$target_alias/lib has
> still been scanned. Not only is that not happening at the moment, but
> sysrooting that directory really doesn't make sense.
I'm not sure whether you agree or disagree. :)
To wit, I'm saying 'don't scan "$exec_prefix/$target_alias/lib", scan the target-adjusted equivalent of "=/lib"; i.e. "=/mingw/lib" for *-*-mingw*'. ...maybe also "=/usr/lib" where that isn't a capital offence, e.g. *-*-gnu...
IIUC (I'm certainly not sure) sysroot targets don't have (*should* not have) anything in $exec_prefix/$target_alias/lib but everything in "=/lib" or "=/usr/lib" so $exec_prefix/$target_alias/lib should not be scanned at all (as such, that is).
I'm not sure how I came to be assigned to this bug, possibly with the original submission due to being responsible for commit 0f70b6b. I don't think there should be any change to $tooldir. Firstly, sysroot really does mean the dir structure ought to be the same as native (non-sysroot) but under the sysroot. Secondly, it's unclear what should be done about $tooldir in the Canadian cross case.