cross-gcc-toolchain for riscv64 doesn't search crt1.o properly

  • Open
  • quality assurance status badge
Details
3 participants
  • Ekaitz Zarraga
  • Jean-Pierre De Jesus Diaz
  • Thiago Jung Bauermann
Owner
unassigned
Submitted by
Ekaitz Zarraga
Severity
normal
E
E
Ekaitz Zarraga wrote on 25 Feb 21:07 +0100
(name . bug-guix@gnu.org)(address . bug-guix@gnu.org)
35296725-34bd-074f-0582-b066c11b06dc@elenq.tech
Hi,

I made this package:

```
(define-module (cross)
#:use-module (guix packages)
#:use-module (guix gexp)
#:use-module (gnu packages cross-base))

(define-public gcc-cross-riscv64-linux-gnu-toolchain
(cross-gcc-toolchain "riscv64-linux-gnu"))
```

And used in in the session you can read in the bottom of this email.

During the session, the `crt1.o` file is not found, and the
`riscv64-linux-gnu-gcc -v whatever.c` call shows `crt1.o` is passed to
the compiler using only the name, while in `gcc-toolchain` it's passed
using the full path to the libc.

This looks like the `cross-gcc-toolchain` is missing some configuration
for proper usage in a guix shell.

Best,
Ekaitz


The session I that explains the behavior:

```
# Using gcc-toolchain here `crt1.o` is found:
Ekaitz@tuxedo ~/projects/nlnet/gzip-1.2.4$ guix shell gcc-toolchain
Ekaitz@tuxedo ~/projects/nlnet/gzip-1.2.4 [env]$ gcc -v deflate.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/13.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/13.2.0/cc1
-quiet -v deflate.c -quiet -dumpdir a- -dumpbase deflate.c -dumpbase-ext
.c -mtune=generic -march=x86-64 -version -o /tmp/ccffA64a.s
GNU C17 (GCC) version 13.2.0 (x86_64-unknown-linux-gnu)
compiled by GNU C version 13.2.0, GMP version 6.2.1, MPFR version
4.2.0, MPC version 1.3.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/no-gcc-local-prefix/include"
ignoring nonexistent directory
"/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/../../../../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/gnu/store/0pr5ryw11f7pg5nhn42616k17ahdnily-profile/include
/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/include
/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/include-fixed
/gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/include
End of search list.
Compiler executable checksum: cd54e13587d35c4cb99945e5484c0675
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
as -v --64 -o /tmp/cciGP5tQ.o /tmp/ccffA64a.s
GNU assembler version 2.38 (x86_64-unknown-linux-gnu) using BFD version
(GNU Binutils) 2.38
COMPILER_PATH=/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/13.2.0/:/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/13.2.0/:/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/:/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/:/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/gnu/store/0pr5ryw11f7pg5nhn42616k17ahdnily-profile/lib/:/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/:/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/../../../:/gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/lib
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'
/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/13.2.0/collect2
-plugin
/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/13.2.0/liblto_plugin.so
-plugin-opt=/gnu/store/vjjk375kysja1jz0837lypd09rdgs47c-gcc-13.2.0/libexec/gcc/x86_64-unknown-linux-gnu/13.2.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccdr9flx.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
--eh-frame-hdr -m elf_x86_64 -dynamic-linker
/gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/lib/ld-linux-x86-64.so.2
/gnu/store/0pr5ryw11f7pg5nhn42616k17ahdnily-profile/lib/crt1.o
/gnu/store/0pr5ryw11f7pg5nhn42616k17ahdnily-profile/lib/crti.o
/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/crtbegin.o
-L/gnu/store/0pr5ryw11f7pg5nhn42616k17ahdnily-profile/lib
-L/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0
-L/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/../../..
-L/gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/lib
/tmp/cciGP5tQ.o -lgcc --push-state --as-needed -lgcc_s --pop-state
-L/gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/lib
-rpath=/gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/lib
-rpath=/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib
-lgcc_s -lc -lgcc --push-state --as-needed -lgcc_s --pop-state
/gnu/store/m57d52krll9vlzmc0cqfg6dwn7n0p52j-gcc-13.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/crtend.o
/gnu/store/0pr5ryw11f7pg5nhn42616k17ahdnily-profile/lib/crtn.o
ld: /gnu/store/0pr5ryw11f7pg5nhn42616k17ahdnily-profile/lib/crt1.o: in
function `_start':
(.text+0x17): undefined reference to `main'
...



Ekaitz@tuxedo ~/projects/nlnet/gzip-1.2.4 [env]$ exit

# Now with riscv64, crt1.o is passed using a relative path and it fails:
Ekaitz@tuxedo ~/projects/nlnet/gzip-1.2.4$ guix shell
gcc-cross-riscv64-linux-gnu-toolchain
Ekaitz@tuxedo ~/projects/nlnet/gzip-1.2.4 [env]$ riscv64-linux-gnu-gcc
-v deflate.c
Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/11.3.0/lto-wrapper
Target: riscv64-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.3.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-march=rv64gc' '-mabi=lp64d' '-misa-spec=2.2'
'-march=rv64imafdc' '-dumpdir' 'a-'
/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/11.3.0/cc1
-quiet -v deflate.c -quiet -dumpdir a- -dumpbase deflate.c -dumpbase-ext
.c -march=rv64gc -mabi=lp64d -misa-spec=2.2 -march=rv64imafdc -version
-o /tmp/ccjXCE2o.s
GNU C17 (GCC) version 11.3.0 (riscv64-linux-gnu)
compiled by GNU C version 11.3.0, GMP version 6.2.1, MPFR version
4.2.0, MPC version 1.3.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/no-gcc-local-prefix/include"
ignoring nonexistent directory
"/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/../../../../../../../riscv64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/include
/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/include-fixed
/gnu/store/f0rksvsrhzbn4ss4gd4p1s677awfzz08-glibc-cross-riscv64-linux-gnu-2.35/include
End of search list.
GNU C17 (GCC) version 11.3.0 (riscv64-linux-gnu)
compiled by GNU C version 11.3.0, GMP version 6.2.1, MPFR version
4.2.0, MPC version 1.3.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c32f88db5f6319705b0dc5f3836ff976
COLLECT_GCC_OPTIONS='-v' '-march=rv64gc' '-mabi=lp64d' '-misa-spec=2.2'
'-march=rv64imafdc' '-dumpdir' 'a-'
/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/as
-v --traditional-format -march=rv64gc -march=rv64imafdc -mabi=lp64d
-misa-spec=2.2 -o /tmp/ccLQFrsU.o /tmp/ccjXCE2o.s
GNU assembler version 2.38 (riscv64-linux-gnu) using BFD version (GNU
Binutils) 2.38
COMPILER_PATH=/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/11.3.0/:/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/11.3.0/:/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/:/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/:/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/
CROSS_LIBRARY_PATH=/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/:/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/../../../../riscv64-linux-gnu/lib/:/gnu/store/f0rksvsrhzbn4ss4gd4p1s677awfzz08-glibc-cross-riscv64-linux-gnu-2.35/lib
COLLECT_GCC_OPTIONS='-v' '-march=rv64gc' '-mabi=lp64d' '-misa-spec=2.2'
'-march=rv64imafdc' '-dumpdir' 'a.'
/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/11.3.0/collect2
-plugin
/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/11.3.0/liblto_plugin.so
-plugin-opt=/gnu/store/dl52ppai6dvdlw0jybx8qj5yvclhwqgl-gcc-cross-riscv64-linux-gnu-11.3.0/libexec/gcc/riscv64-linux-gnu/11.3.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/cc0p0r5t.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 -melf64lriscv -dynamic-linker
/gnu/store/f0rksvsrhzbn4ss4gd4p1s677awfzz08-glibc-cross-riscv64-linux-gnu-2.35/lib/ld-linux-riscv64-lp64d.so.1
crt1.o
/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/crti.o
/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/crtbegin.o
-L/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0
-L/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/../../../../riscv64-linux-gnu/lib
-L/gnu/store/f0rksvsrhzbn4ss4gd4p1s677awfzz08-glibc-cross-riscv64-linux-gnu-2.35/lib
/tmp/ccLQFrsU.o -lgcc --push-state --as-needed -lgcc_s --pop-state
-L/gnu/store/f0rksvsrhzbn4ss4gd4p1s677awfzz08-glibc-cross-riscv64-linux-gnu-2.35/lib
-rpath=/gnu/store/f0rksvsrhzbn4ss4gd4p1s677awfzz08-glibc-cross-riscv64-linux-gnu-2.35/lib
-rpath=/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/riscv64-linux-gnu/lib
-lgcc_s -lc -lgcc --push-state --as-needed -lgcc_s --pop-state
/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/crtend.o
/gnu/store/rn39sf79yb5wcfclkfxzwz8r71jmwi6c-gcc-cross-riscv64-linux-gnu-11.3.0-lib/lib/gcc/riscv64-linux-gnu/11.3.0/crtn.o
riscv64-linux-gnu-ld: cannot find crt1.o: No such file or directory
collect2: error: ld returned 1 exit status
```
J
J
Jean-Pierre De Jesus Diaz wrote on 29 Feb 14:59 +0100
(address . 69394@debbugs.gnu.org)(address . ekaitz@elenq.tech)
CAG1gdUqip+HzcsMrqHXi7xQH1yzzrSxuGqCkKxpyY9aGDWZ9KA@mail.gmail.com
Hello Ekaitz,

This problem is also present for other targets such as AVR[1] as when
I introduced
the cross-gcc-toolchain procedure I didn't add the NATIVE-SEARCH-PATHS and
SEARCH-PATHS fields for the toolchains as:

1. SEARCH-PATHS doesn't quite work with shells right now, as it is
impossible to create
a profile with cross packages. E.g. trying to use
gcc-cross-avr-toolchain and unity
built for AVR. So it is a bit useless, unless the toolchain is used
inside of GNU Guix as
a NATIVE-INPUT, but STANDARD-CROSS-PACKAGES takes care of this in
GNU-BUILD-SYSTEM by adding cross-gcc and cross-libc as inputs.

2. The other solution is to use NATIVE-SEARCH-PATHS but when using
mixed toolchains
in a single environment all of the cross compilers will share this
environment variable.

For example:

guix shell gcc-cross-avr-toolchain gcc-cross-i686-w64-mingw32-toolchain

Would have the same CROSS_* environment variables and could mix things up.

Ideally one should have per target cross variables, like, CROSS_AVR_*
CROSS_I686_W64_MINGW32_*, but this is not done right now.

Another option is to wrap every binary of the toolchain and set the
CROSS_* variables
so that they can find the C standard library includes and binaries
without adding
search paths to avoid collisions with other toolchains for the moment and since
profiles don't support cross-packages yet I think it is a fair trade-off.

I think I could update https://issues.guix.gnu.org/68058to use the
latter method.


--
Jean-Pierre De Jesus DIAZ
Foundation Devices, Inc.
T
T
Thiago Jung Bauermann wrote on 10 Apr 00:33 +0200
Re: bug#69394: cross-gcc-toolchain for riscv64 doesn't search crt1.o properly
(name . Jean-Pierre De Jesus Diaz via Bug reports for GNU Guix)(address . bug-guix@gnu.org)
87sezu88uh.fsf@linaro.org
Hello Jean-Pierre,

Today I ran into the issue reported in this bug with a custom toolchain
package for aarch64-linux-gnu. I applied your patch from issue 68058 and
that solved the problem!

Thank you very much for your insights and proposed solutions. A couple
of comments below:

Jean-Pierre De Jesus Diaz via Bug reports for GNU Guix <bug-guix@gnu.org> writes:

Toggle quote (24 lines)
> 2. The other solution is to use NATIVE-SEARCH-PATHS but when using
> mixed toolchains
> in a single environment all of the cross compilers will share this
> environment variable.
>
> For example:
>
> guix shell gcc-cross-avr-toolchain gcc-cross-i686-w64-mingw32-toolchain
>
> Would have the same CROSS_* environment variables and could mix things up.
>
> Ideally one should have per target cross variables, like, CROSS_AVR_*
> CROSS_I686_W64_MINGW32_*, but this is not done right now.
>
> Another option is to wrap every binary of the toolchain and set the
> CROSS_* variables
> so that they can find the C standard library includes and binaries
> without adding
> search paths to avoid collisions with other toolchains for the moment and since
> profiles don't support cross-packages yet I think it is a fair trade-off.
>
> I think I could update https://issues.guix.gnu.org/68058 to use the
> latter method.

That would be awesome.

If I understand correctly what you wrote, as things stand today many
cross toolchains are unusable because of this problem (but not all? IIUC
bare-metal cross toolchains aren't affected because they don't use
crt*.o files, right?)

So even your patch as it is currently proposed in issue 68058 would be
an improvement over the status quo.

IMHO, supporting more than one cross toolchain installed in the same
profile would be interesting (I for one would find it useful to have
both aarch64-linux-gnu and arm-linux-gnueabihf cross toolchains
installed at the same time) but even if that is not possible yet,
supporting just one cross toolchain installed in a profile would be an
important improvement. :-)

All this to say: unless there are other downsides to the patch in 68058,
I think it should be committed.

--
Thiago
?