Subject: bug#48913: closed (Re: bug#48913: i686-linux-gnu cross-compiler cannot find libgcc_s [core-updates])

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 03 Jul 2021 13:41:02 +0000

Your bug report

#48913: i686-linux-gnu cross-compiler cannot find libgcc_s [core-updates]

which was filed against the guix package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
48913: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=48913
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#48913: i686-linux-gnu cross-compiler cannot find libgcc_s [core-updates]
From: Maxime Devos <[email-masked]>
To: Ludovic Courtès <[email-masked]>
Cc: [email-masked]
Date: Sat, 03 Jul 2021 15:40:21 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Ludovic Courtès schreef op vr 18-06-2021 om 11:32 [+0200]:
> Hi,
> 
> Maxime Devos <[email-masked]> skribis:
> 
> >   ./pre-inst-env guix build --target=i686-linux-gnu hello --keep-failed
> 
> “i686-linux-gnu” is not among the supported cross-compilation triplets,
> which are roughly those that appears in (@ (gnu ci) %cross-targets).
> 
> It’s rarely useful to cross-compile to i686-linux-gnu because you can
> just build natively on an x86_64-linux-gnu machine:
> 
>   guix build -s i686-linux hello
> 
> All this to say, I don’t think we should spend energy on the
> i686-linux-gnu cross toolchain.
>
> WDYT?

Agreed, closing.  Though if someone has the same issue when building
a cross-compiler from, say, aarch64 to i686, then I'd recommend reopening
it.

Greetings,
Maxime.

Subject: i686-linux-gnu cross-compiler cannot find libgcc_s [core-updates]
From: Maxime Devos <[email-masked]>
To: [email-masked]
Date: Tue, 08 Jun 2021 10:41:11 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

I tested this on 683eb7c5b118440001b89944563603a39fc2ac05.
The problem does not occur on master.

How to reproduce:

  # --target=aarch64-linux-gnu also fails, but that's another issue
  ./pre-inst-env guix build --target=i686-linux-gnu hello --keep-failed

Error message (during 'configure' phase):

checking for i686-linux-gnu-gcc... i686-linux-gnu-gcc
checking whether the C compiler works... no
configure: error: in `/tmp/guix-build-hello-2.10.drv-0/hello-2.10':
configure: error: C compiler cannot create executables
See `config.log' for more details
error: in phase 'configure': uncaught exception:
%exception #<&invoke-error program: "/gnu/store/kpkbyk7jlw6n5z3jkbia9mcr0bhflzbf-bash-minimal-5.1.8/bin/bash" arguments: ("./configure" "CC_FOR_BUILD=gcc"
"CONFIG_SHELL=/gnu/store/kpkbyk7jlw6n5z3jkbia9mcr0bhflzbf-bash-minimal-5.1.8/bin/bash" "SHELL=/gnu/store/kpkbyk7jlw6n5z3jkbia9mcr0bhflzbf-bash-minimal-5.1.8/bin/bash" "
--prefix=/gnu/store/wmkbla5nncld4rdyqkwc9lw9kzypvdab-hello-2.10" "--enable-fast-install" "--build=x86_64-unknown-linux-gnu" "--host=i686-linux-gnu") exit-status: 77 term-signal: #f stop-signal: #f> 
phase `configure' failed after 3.1 seconds

From 'config.log':

  configure:4014: checking whether the C compiler works
configure:4036: i686-linux-gnu-gcc    conftest.c  >&5
i686-linux-gnu-ld: cannot find -lgcc_s
i686-linux-gnu-ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
configure:4040: $? = 1
configure:4078: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU Hello"
| #define PACKAGE_TARNAME "hello"
| #define PACKAGE_VERSION "2.10"
| #define PACKAGE_STRING "GNU Hello 2.10"
| #define PACKAGE_BUGREPORT "[email-masked]"
| #define PACKAGE_URL "http://www.gnu.org/software/hello/"
| #define PACKAGE "hello"
| #define VERSION "2.10"
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:4083: error: in `/tmp/guix-build-hello-2.10.drv-0/hello-2.10':
configure:4085: error: C compiler cannot create executables

Issue:

Somehow, the C cross-compiler does not find "libgcc_s".
Look at CROSS_LIBRARY_PATH and LIBRARY_PATH in /tmp/[...]/environment-variables,
we have (line breaks added):

export CROSS_LIBRARY_PATH=
  /gnu/store/glc86jl13yj70k2h4mm3pqwff351mxav-glibc-cross-i686-linux-gnu-2.33/lib:
  /gnu/store/wk761j8qqq7yf949wyxjgcbqxcx574nf-glibc-cross-i686-linux-gnu-2.33-static/lib
export LIBRARY_PATH=
  /gnu/store/w6ydl1fjxhkc69cs90vmg3g48vwcy59w-binutils-cross-i686-linux-gnu-2.36.1/lib:
  /gnu/store/lv8zj6sl3fc6db2ljq10haba3sfhvq6b-bzip2-1.0.8/lib:
  /gnu/store/hhg5z17xyfj7zvg864br41nsj6g918ym-xz-5.2.5/lib:
  /gnu/store/pnj9pzyk4ajs9a245krx5l4sp4p8xwyk-file-5.39/lib:
  /gnu/store/0amam2n0vjb62zh6jssb9pjnwcf302hw-gawk-5.1.0/lib:
  /gnu/store/3fasjd1jnnm6vhyff5wb3kkahnxzbl49-binutils-2.36.1/lib:
  /gnu/store/mf4kmmhka2dagnna6a0h4fciz5ijaxsn-glibc-2.33/lib:
  /gnu/store/dj2p4mwp6gwbx8fpd6gqsj2c307mm6sp-glibc-2.33-static/lib:
  /gnu/store/dxplmvm0xf8z968m3lbwzizc95h9nldc-glibc-utf8-locales-2.33/lib

When I run "ls -l" on each of these directories, I notice none of these
have a "libgcc_s.so" file. So it's not very surprising GNU ld (via GCC) cannot find it.
Now, where could we find "libgcc_s.so"?

I found it in
  /gnu/store/6b4sgmqd3nrajbx47zryi0n4s08sfrb6-gcc-cross-i686-linux-gnu-8.5.0/i686-linux-gnu/lib/

By explicitely passing "-L/gnu/store/6b4sgmqd3nrajbx47zryi0n4s08sfrb6-gcc-cross-i686-linux-gnu-8.5.0/i686-linux-gnu/lib/",
the C program compiles. So, I guess we need to add that directory to CROSS_LIBRARY_PATH. Or ...

* Shouldn't this be present in the spec file?

Let's test.

/gnu/store/6b4sgmqd3nrajbx47zryi0n4s08sfrb6-gcc-cross-i686-linux-gnu-8.5.0/bin/i686-linux-gnu-gcc -dumpspecs

Output (only a part shown)
*lib:
%{!mandroid|tno-android-ld:-L/gnu/store/glc86jl13yj70k2h4mm3pqwff351mxav-glibc-cross-i686-linux-gnu-2.33/lib %{!static:-rpath=/gnu/store/glc86jl13yj70k2h4mm3pqwff351mxav-glibc-cross-i686-linux-gnu-
2.33/lib %{!static-libgcc:-rpath=/gnu/store/53i7hxqwf3apvz77bsapjvrigjiimg29-gcc-cross-i686-linux-gnu-8.5.0-lib/i686-linux-gnu/lib -lgcc_s}} %{pthread:-lpthread} %{shared:-lc}    %{!shared:%{profile:-
lc_p}%{!profile:-lc}};:%{shared:-lc}    %{!shared:%{profile:-lc_p}%{!profile:-lc}} %{!static: -ldl}}

Curiously, /gnu/store/53i7hxqwf3apvz77bsapjvrigjiimg29-gcc-cross-i686-linux-gnu-8.5.0-lib/i686-linux-gnu/lib
is actualy present! Let's compile in verbose mode.

$ i686-linux-gnu-gcc -v conftest.o

Output:
> Using built-in specs.
> COLLECT_GCC=i686-linux-gnu-gcc
> COLLECT_LTO_WRAPPER=/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0/libexec/gcc/i686-linux-gnu/8.5.0/lto-wrapper
> Target: i686-linux-gnu
> Configured with: 
> Thread model: posix
> gcc version 8.5.0 (GCC) 
> COMPILER_PATH=/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0/libexec/gcc/i686-linux-gnu/8.5.0/:/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0/libexec/gcc/i686-linux-gnu/8.5.0/:/gnu/store/[...]-
gcc-cross-i686-linux-gnu-8.5.0/libexec/gcc/i686-linux-gnu/:/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-lib/lib/gcc/i686-linux-gnu/8.5.0/:/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-
lib/lib/gcc/i686-linux-gnu/
> CROSS_LIBRARY_PATH=/gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib/:/gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33-static/lib/:/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-
lib/lib/gcc/i686-linux-gnu/8.5.0/:/gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib
> COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=pentiumpro'
> /gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0/libexec/gcc/i686-linux-gnu/8.5.0/collect2 -plugin /gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0/libexec/gcc/i686-linux-gnu/8.5.0/liblto_plugin.so
-plugin-opt=/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0/libexec/gcc/i686-linux-gnu/8.5.0/lto-wrapper -plugin-opt=-fresolution=/tmp/guix-build-hello-2.10.drv-0/ccxP5sep.res -plugin-opt=-pass-
through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --sysroot=/ --eh-
frame-hdr -m elf_i386 -dynamic-linker /gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib/ld-linux.so.2 /gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib/crt1.o /gnu/store/[...]-glibc-cross-i686-
linux-gnu-2.33/lib/crti.o /gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-lib/lib/gcc/i686-linux-gnu/8.5.0/crtbegin.o -L/gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib -L/gnu/store/[...]-glibc-
cross-i686-linux-gnu-2.33-static/lib -L/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-lib/lib/gcc/i686-linux-gnu/8.5.0 -L/gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib conftest.o -lgcc --as-
needed -lgcc_s --no-as-needed -L/gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib -rpath=/gnu/store/[...]-glibc-cross-i686-linux-gnu-2.33/lib -rpath=/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-
lib/i686-linux-gnu/lib -lgcc_s -lc -lgcc --as-needed -lgcc_s --no-as-needed /gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-lib/lib/gcc/i686-linux-gnu/8.5.0/crtend.o /gnu/store/[...]-glibc-cross-i686-
linux-gnu-2.33/lib/crtn.o
> i686-linux-gnu-ld: cannot find -lgcc_s
> i686-linux-gnu-ld: cannot find -lgcc_s

What went wrong here? I took a look at the folowing entry in CROSS_LIBRARY_PATH:
/gnu/store/[...]-gcc-cross-i686-linux-gnu-8.5.0-lib/lib/gcc/i686-linux-gnu/8.5.0/.
In this directory, there is a "libgcc.a", but not a "libgcc_s.so"! So, we have
a static libgcc library, but not a dynamic libgcc_s library!

To be investigated ... or worked around by tweaking CROSS_LIBRARY_PATH ...