This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: ld sysroot scripts



> From: Feuerbacher, Alan 
> Sent: Friday, July 20, 2012 10:06 AM
> To: 'binutils@sourceware.org'
> Subject: ld sysroot scripts
>
> Hi,
>
> I'm having a problem with cross compiling binutils, gcc and glibc on a
> Redhat5 system. I think that the problem is addressed by Alan Modra in his post "ld sysroot > > scripts":
>
> http://sourceware.org/ml/binutils/2012-03/msg00076.html
>
> I've tried applying the supplied patch, but get a lot of errors like "Hunk #2 FAILED at 83".
>
> Is there any information available on applying this patch, or on a later version?
>
> Obviously I'm trying to compile binutils-2.22.
>
> Alan Feuerbacher


Hi again,

I seem to have figured a way to get around the above-mentioned problem, but it's not really fixed.

After looking around for some time I found the latest binutils snapshots here:

ftp://sourceware.org/pub/binutils/snapshots/

After comparing one of the files (ldfile.c) mentioned in Alan Modra's above-mentioned patch between the latest snapshot (binutils-2.22.52) and the latest official version (binutils-2.22), I saw that the patch changes were in the latest version; hence no need to apply a patch.

I then cross-compiled binutils-2.22.52, gcc-4.7.1 and glibc-2.15 successfully, using variations of ideas from the Linux From Scratch folks. But I still ended up with the same problem as before -- as described in Alan Modra's patch link ( http://sourceware.org/ml/binutils/2012-03/msg00076.html ), namely, ld seems improperly to tack the sysroot prefix onto the library path when searching for three shared library files, and then complains that it can't find the files. This problem is more or less described at the end of this link:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35804

This says:

************************
Alan Modra 2009-01-18 23:36:48 UTC

I believe that this is a user error and that this bugzilla should be closed. 
Your problem with ld "cannot find /tools/lib/libc.so.6 inside /tools" is simply that your glibc is built wrongly for your sysroot.  (glibc is not sysroot
aware.)  You'll find that the script libc.so has a line something like

GROUP ( /tools/lib/libc.so.6 /tools/usr/lib/libc_nonshared.a  AS_NEEDED (
/tools/lib/ld-linux.so.2 ) )

The /tools sysroot prefix ought not be present on any of these paths.
************************

I've run into exactly the same problem, where the three files libc.so.6, libc_nonshared.a and ld-linux.so.2 cannot be found by ld. 

The script libc.so ends up containing the following, which mentions these shared files:

************************
/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /home/afbacher/LFS71/lfs/tools/lib/libc.so.6 /home/afbacher/LFS71/lfs/tools/lib/libc_nonshared.a  AS_NEEDED ( /home/afbacher/LFS71/lfs/tools/lib/ld-linux-x86-64.so.2 ) )
************************

I compiled both binutils and gcc using "--with-sysroot=/home/afbacher/LFS71/lfs". I fixed the problem by removing the sysroot string from the last line of libc.so:

************************
GROUP ( /tools/lib/libc.so.6 /tools/lib/libc_nonshared.a  AS_NEEDED ( /tools/lib/ld-linux-x86-64.so.2 ) )
************************

The Linux From Scratch instructions tell you to do the following test after compiling binutils, gcc and glibc:

************************
echo 'main(){}' >| dummy.c
x86_64-lfs-linux-gnu-gcc dummy.c
readelf -l a.out
************************

You should see a line like this if everything is working right:

************************
[Requesting program interpreter: /home/afbacher/LFS71/lfs/tools/lib64/ld-linux-x86-64.so.2]
************************

However, immediately after compiling the three programs, the "x86_64-lfs-linux-gnu-gcc dummy.c" line fails with something like this for each of the shared files:

************************
/home/afbacher/LFS71/lfs/tools/lib/gcc/x86_64-lfs-linux-gnu/4.7.1/../../../../x86_64-lfs-linux-gnu/bin/ld: cannot find /home/afbacher/LFS71/fum/tools/lib/libc.so.6 inside /home/afbacher/LFS71/lfs
************************

But after I change the "GROUP" line in libc.so as described above, everything works fine.

It appears to me that either the last line of libc.so is being generated improperly (i.e., it improperly contains sysroot) or that ld is improperly tacking sysroot onto the front of the library paths defined in the GROUP statement in libc.so. I'm not qualified to do more than speculate about this, but it seems to me that the patch described in Alan Modra's references above is not working.

By the way, modifying libc.so as above, and using the un-patched binutils-2.22, also fixes the problem. This again suggests that the patch is not working as intended.

Again, any help in getting this stuff fixed will be appreciated.

Alan Feuerbacher


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]