ld of binutils-stage1 does not find dependent library in proper path
Context
binutils-stage1 is configured with '--with-lib-path' option. But pathes in '--with-lib-path' does not take sysroot into account. ld will search dependent library in /usr/%{lib} and /usr/lib. But what we expected is ld should first search %{sysroot}/usr/%{lib} and %{sysroot}/usr/lib.
A simple test case:
cd bootstrap
bst build gcc-stage2.bst
bst shell -b gcc.bst
echo 'int main(){}' >t.c
/cross/bin/x86_64-unknown-linux-gnu-gcc -lstdc++ -Wl,--verbose t.c
Output shows ld choose libm.so.6 (dependency of libstdc++) in /usr/lib:
libm.so.6 needed by /cross/lib/gcc/x86_64-unknown-linux-gnu/8.2.0/../../../../x86_64-unknown-linux-gnu/lib/x86_64-linux-gnu/libstdc++.so
attempt to open /cross-installation/cross/x86_64-unknown-linux-gnu/lib64/libm.so.6 failed
attempt to open /usr/lib/x86_64-linux-gnu/libm.so.6 failed
found libm.so.6 at /usr/lib/libm.so.6
Description
We should configure binutils-stage1 with '--with-lib-path="%{sysroot}/usr/%{lib}:%{sysroot}/usr/lib:/usr/%{lib}:/usr/lib"'. After the fix, the output will changed to:
libm.so.6 needed by /cross/lib/gcc/x86_64-unknown-linux-gnu/8.2.0/../../../../x86_64-unknown-linux-gnu/lib/x86_64-linux-gnu/libstdc++.so
attempt to open /cross-installation/cross/x86_64-unknown-linux-gnu/lib64/libm.so.6 failed
found libm.so.6 at /cross-installation/usr/lib/x86_64-linux-gnu/libm.so.6
Acceptance Criteria
Linking wrong library is apparently bad and may turn to link failure in the future.