Bug#629819: libc6: gcc-4.2 from lenny no longer works
Aurelien Jarno wrote:
> Last time we talk with that on #multiarch, it seems it was not really a
> good idea to do that, especially given it only solves half of the
> problem (the library one, not the includes one). What should be done
> instead is trying to understand why --sysroot doesn't work.
Thanks.
Well, that mystery is easily dispelled. :) --sysroot works by adding
the specified prefix to the relevant paths that gcc would be using.
So instead of looking at /usr/include, it will look at
/usr/lib/$arch/usr/include; instead of looking at /usr/lib, it will
look at /usr/lib/$arch/usr/lib; and so on.
Which is not quite what we want. It never could have worked.
| $ gcc-4.3 --sysroot /usr/lib/x86_64-linux-gnu -Wall -W -O -o hello hello.c
| hello.c:1:19: error: stdio.h: No such file or directory
| hello.c: In function ‘main’:
| hello.c:5: warning: implicit declaration of function ‘puts’
Luckily, even without --sysroot, gcc-4.3 from squeeze already has
/usr/lib/$arch in its library search path. Why doesn't it work?
| $ gcc-4.3 -Wall -W -O -o hello hello.c
| /usr/bin/ld: error: cannot open /usr/lib/gcc/x86_64-linux-gnu/4.3.5/libgcc_s.so: No such file or directory
| /usr/bin/ld: error: cannot open /usr/lib/gcc/x86_64-linux-gnu/4.3.5/libgcc_s.so: No such file or directory
| collect2: ld returned 1 exit status
| $ ls -l /usr/lib/gcc/x86_64-linux-gnu/4.3.5/libgcc_s.so
| lrwxrwxrwx 1 root root 18 Mar 14 10:15 /usr/lib/gcc/x86_64-linux-gnu/4.3.5/libgcc_s.so -> /lib/libgcc_s.so.1
--sysroot only modifies some items in the search path and not others.
In gcc-4.3[*]:
Search path item Modified?
---------------- ---------
/usr/lib/gcc/x86_64-linux-gnu/4.3 no
/usr/x86_64-linux-gnu/lib/x86_64-linux-gnu/4.3.5 no
/usr/x86_64-linux-gnu/lib no
/usr/lib/x86_64-linux-gnu/4.3.5 no
/usr/lib no
/lib/x86_64-linux-gnu/4.3.5 yes
/lib yes
/usr/lib/x86_64-linux-gnu/4.3.5 yes
/usr/lib yes
/usr/lib/x86_64-linux-gnu/x86_64-linux-gnu/4.3.5 no
/usr/lib/lib no
/usr/x86_64-linux-gnu/lib no
/usr/lib no
/lib yes
/usr/lib yes
/usr/lib/x86_64-linux-gnu no
In particular, gcc still looks for startup files and libgcc in its
private directory regardless of sysroot. The problem then is the
target of the libgcc_s.so and libgomp.so symlinks.
In other words, this is a different bug than the one Andreas reported.
Working around it is very simple:
# ln -s x86_64-linux-gnu/libgcc_s.so.1 /lib/
$ gcc-4.3 -Wall -W -O -o hello hello.c
$ ./hello
$ hi
and it has nothing to do with libc. Will clone with a separate
message.
Now for the separate problem of toolchains (like upstream gcc and
Debian gcc-4.0) not being able to find libraries under /lib/$arch and
/usr/lib/$arch as Andreas reported, all the symlinks in the world will
not help, since there will always be another library. If I ran into
it, I would try something like
cc -I/usr/include/$arch -L/usr/lib/$arch -L/lib/$arch
I don't know if there is some shortcut for that. Unless I am
misunderstanding something basic, --sysroot won't do.
[*] gcc 4.6 is a little less wacky, but the same ideas apply to it,
too.
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6 no
/usr/x86_64-linux-gnu/lib/x86_64-linux-gnu/4.6.1 no
/usr/x86_64-linux-gnu/lib no
/usr/lib/x86_64-linux-gnu/x86_64-linux-gnu/4.6.1 no
/usr/lib/x86_64-linux-gnu no
/lib/x86_64-linux-gnu/4.6.1 yes
/lib yes
/usr/lib/x86_64-linux-gnu/4.6.1 yes
/usr/lib yes
/usr/lib/x86_64-linux-gnu/x86_64-linux-gnu/4.6.1 no
/usr/lib/x86_64-linux-gnu no
Retrieved with
gcc --sysroot=/foo -print-search-dirs |
grep '^libraries' |
cut -d= -f2- |
tr : '
' |
while read line
do
readlink -m $line
done
Reply to: