https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125593

            Bug ID: 125593
           Summary: Cross-compiling GCC fails with "cannot execute: cc1"
                    error
           Product: gcc
           Version: 14.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stefanbidi at gmail dot com
  Target Milestone: ---

I'm not really sure how to fully describe the issue or how to fully provide
information for this bug report, but I'll do my best.

I routinely, usually about once a year, will build a x86_64-pc-linux-musl
install just to remind myself how to do it. I've been doing this for a few
years now and it's always worked perfectly fine. This week, I took on the
endeavor again and immediate ran into issues. The build goes perfectly, until I
actually log into the host x86_64-pc-linux-musl host and try to compile
anything.

The following error happens consistently with the following combinations: (1)
binutils-2.46.0 + gcc-16.1.0 + musl-1.2.6, (2) binutils-2.45.1 + gcc-15.2.0 +
musl-1.2.5, (3) binutils-2.44.1 + gcc-14.3.0 + musl 1.2.6.

> (chroot) root:/usr/src# echo 'void main(){}' > dummy.c
> (chroot) root:/usr/src# gcc -v dummy.c                                        
>                           
> Using built-in specs.
> COLLECT_GCC=gcc
> Target: x86_64-linux-musl
> Configured with: ../configure --build=x86_64-pc-linux-gnu 
> --host=x86_64-linux-musl --target=x86_64-linux-musl --prefix=/usr 
> --libdir=/usr/lib --with-build-sysroot=/mnt/sysroot --enable-default-pie 
> --enable-default-ssp --disable-nls --disable-multilib --disable-libatomic 
> --disable-libgomp --disable-libquadmath --disable-libsanitizer 
> --disable-libssp --disable-libvtv --disable-libitm --enable-languages=c,c++ 
> --disable-lto-plugin
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 14.3.0 (GCC) 
> COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
>  cc1 -quiet -v -iprefix /bin/../lib/gcc/x86_64-linux-musl/14.3.0/ dummy.c 
> -quiet -dumpdir a- -dumpbase dummy.c -dumpbase-ext .c -mtune=generic 
> -march=x86-64 -version -o /tmp/ccjnoCOo.s
> gcc: fatal error: cannot execute 'cc1': posix_spawnp: No such file or 
> directory

Note that cc1 does not include the full path
`/usr/lib/gcc/x86_64-linux-musl/14.3.0/cc1`. It took a long time for me to
realize this was the actual issue. With GCC 14.2.0 I get the following output
instead:

> (chroot) root:/usr/src# gcc -v dummy.c
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/bin/../lib/gcc/x86_64-linux-musl/14.2.0/lto-wrapper
> Target: x86_64-linux-musl
> Configured with: ../configure --build=x86_64-pc-linux-gnu 
> --host=x86_64-linux-musl --target=x86_64-linux-musl --prefix=/usr 
> --libdir=/usr/lib --libexecdir=/usr/lib --with-build-sysroot=/mnt/sysroot 
> --enable-default-pie --enable-default-ssp --disable-nls --disable-multilib 
> --disable-libatomic --disable-libgomp --disable-libquadmath 
> --disable-libsanitizer --disable-libssp --disable-libvtv --disable-libitm 
> --enable-languages=c,c++ --disable-lto-plugin
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 14.2.0 (GCC) 
> COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
>  /bin/../lib/gcc/x86_64-linux-musl/14.2.0/cc1 -quiet -v -iprefix 
> /bin/../lib/gcc/x86_64-linux-musl/14.2.0/ dummy.c -quiet -dumpdir a- 
> -dumpbase dummy.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -o 
> /tmp/ccccBjed.s
> GNU C17 (GCC) version 14.2.0 (x86_64-linux-musl)
>         compiled by GNU C version 14.3.0, GMP version 6.3.0, MPFR version 
> 4.2.1, > MPC version 1.4.1, isl version none
> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> ignoring nonexistent directory 
> "/bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../../../x86_64-linux-musl/include"
> ignoring nonexistent directory "/usr/local/include"
> ignoring nonexistent directory 
> "/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/14.2.0/../../../../x86_64-linux-musl/include"
> ignoring duplicate directory 
> "/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/14.2.0/include"
> #include "..." search starts here:
> #include <...> search starts here:
>  /bin/../lib/gcc/x86_64-linux-musl/14.2.0/include
>  /usr/include
> End of search list.
> Compiler executable checksum: ca4213bc6773b632bd2e71bc3522111a
> COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
>  as -v --64 -o /tmp/cceeKLod.o /tmp/ccccBjed.s
> GNU assembler version 2.44 (x86_64-linux-musl) using BFD version (GNU 
> Binutils) 2.44
> COMPILER_PATH=/bin/../lib/gcc/x86_64-linux-musl/14.2.0/:/bin/../lib/gcc/
> LIBRARY_PATH=/bin/../lib/gcc/x86_64-linux-musl/14.2.0/:/bin/../lib/gcc/:/bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../../:/lib/:/usr/lib/
> COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'
>  /bin/../lib/gcc/x86_64-linux-musl/14.2.0/collect2 --eh-frame-hdr -m 
> elf_x86_64 -dynamic-linker /lib/ld-musl-x86_64.so.1 -pie 
> /bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../../../lib/Scrt1.o 
> /bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../../../lib/crti.o 
> /bin/../lib/gcc/x86_64-linux-musl/14.2.0/crtbeginS.o 
> -L/bin/../lib/gcc/x86_64-linux-musl/14.2.0 -L/bin/../lib/gcc 
> -L/bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../../../lib -L/lib/../lib 
> -L/usr/lib/../lib -L/bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../.. 
> /tmp/cceeKLod.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc 
> --push-state --as-needed -lgcc_s --pop-state 
> /bin/../lib/gcc/x86_64-linux-musl/14.2.0/crtendS.o 
> /bin/../lib/gcc/x86_64-linux-musl/14.2.0/../../../../lib/crtn.o
> COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'

Again, note that GCC 14.2.0 correctly adds the path to cc1 and collect2 to the
invocation. Looking at the release history, this seems to have been a change
made from the 14.2.0 -> 14.3.0 release since 15.2.0 and 16.1.0 (both released
after 14.2.0) are also effected. I did not test with any other version of GCC.

Also of note, the successfully cross-compiled 14.2.0 build uses a 14.3.0
cross-compiler. So 14.3.0 is able to cross-compile 14.2.0 properly, but not
14.3.0 itself. The configure parameters for the cross compiler were:

> Using built-in specs.
> COLLECT_GCC=x86_64-linux-musl-gcc
> COLLECT_LTO_WRAPPER=/opt/x86_64-linux-musl/libexec/gcc/x86_64-linux-musl/14.3.0/lto-wrapper
> Target: x86_64-linux-musl
> Configured with: ../configure --host=x86_64-pc-linux-gnu 
> --target=x86_64-linux-musl --prefix=/opt/x86_64-linux-musl 
> --with-sysroot=/mnt/sysroot --enable-languages=c,c++ --enable-default-pie 
> --enable-default-ssp --enable-threads=posix --disable-multilib --disable-nls 
> --disable-libatomic --disable-libgomp --disable-libitm --disable-libmpx 
> --disable-libmudflap --disable-libquadmath --disable-libsanitizer 
> --disable-libssp --disable-libvtv --disable-libstdcxx-pch --disable-lto
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 14.3.0 (GCC)

Reply via email to