[PATCH] ld should always search in the sysroot first

Sven Rebhan odinshorse@googlemail.com
Tue Jun 16 21:05:00 GMT 2009


Please CC me, as I'm not subscribed to the list!

Hello List,

when ld was configured with a sysroot, it should always search
libraries first in this sysroot. This is especially important when
cross-compiling. The following test illustrates the problem (you need
a cross-compile toolchain and a target lib called "libfoo.so" in the
dir of the test script):

----
#!/bin/bash
echo "int main(void) { return 0; }" > test.c

echo "Testing without lib..."
armv4tl-softfloat-linux-gnueabi-gcc test.c -o test

echo "Testing with relative lib..."
armv4tl-softfloat-linux-gnueabi-gcc test.c -o test ./libfoo.so

echo "Testing with relative linker script..."
echo "GROUP ( ./libfoo.so )" > "${PWD}/libfoo-script.so"
armv4tl-softfloat-linux-gnueabi-gcc test.c -o test libfoo-script.so

echo "Testing with absolute linker script (local libfoo)..."
echo "GROUP ( ${PWD}/libfoo.so )" > "${PWD}/libfoo-script.so"
armv4tl-softfloat-linux-gnueabi-gcc test.c -o test libfoo-script.so

echo "Testing with absolute linker script (systems libz)..."
echo "GROUP ( /lib/libz.so )" > "${PWD}/libfoo-script.so"
armv4tl-softfloat-linux-gnueabi-gcc test.c -o test libfoo-script.so
----

The output of this script for the stock ld-2.19.1 is:
----
Testing without lib...
Testing with relative lib...
Testing with relative linker script...
Testing with absolute linker script (local libfoo)...
Testing with absolute linker script (systems libz)...
/lib/libz.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
----

as the "/lib/libz.so" in the linker script is not prepended with the
sysroot prefix. By applying the attached patch, the test runs
successfully also for this case. The patch was tested agains a native
compilation (no sysroot prefix) amd64 Gentoo system and a
cross-compiled armv4tl-softfloat-linux-gnueabi Gentoo system. Both
systems work.

Best regards,

    Sven
-------------- next part --------------
A non-text attachment was scrubbed...
Name: binutils-2.19.1-ld-sysroot.patch
Type: application/octet-stream
Size: 1190 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20090616/f94776d8/attachment.obj>


More information about the Binutils mailing list