dslm4515 / Musl-LFS

Linux From Scratch using Musl as Libc
GNU General Public License v3.0
170 stars 21 forks source link

GCC 10.2.0 fails to Build under armv7 in Chroot #40

Closed dslm4515 closed 3 years ago

dslm4515 commented 3 years ago

Hardware: Raspberry Pi 3

During chroot, GCC fails to compile:

checking whether make supports nested variables... yes
checking for armv7l-linux-musleabihf-gcc... /sources/gcc-10.2.0/build/./gcc/xgcc -B/sources/gcc-10.2.0/build/./gcc/ -B/usr/armv7l-linux-musleabihf/bin/ -B/usr/armv7l-linux-musleabihf/lib/ -isystem /usr/armv7l-linux-musleabihf/include -isystem /usr/armv7l-linux-musleabihf/sys-include      
checking whether the C compiler works... no
configure: error: in `/sources/gcc-10.2.0/build/armv7l-linux-musleabihf/libgomp':                                                               
configure: error: C compiler cannot create executables
See `config.log' for more details
make[1]: *** [Makefile:14436: configure-target-libgomp] Error 1
make[1]: Leaving directory '/sources/gcc-10.2.0/build'
make: *** [Makefile:962: all] Error 2
(mlfs chroot) root:/sources/gcc-10.2.0/build#

Same build instructions work fine on x86

firasuke commented 3 years ago

Are you sure libgcc is being built correctly before libgomp? Can you post the config.log on some online bins?

dslm4515 commented 3 years ago

Oops. I forgot to post that log. Something about selected cpu does not have vfpu

The failed build had these flags

--with-arch=armv7-a 
--with-tune=generic-armv7-a 
--with-fpu=vfpv3-d16 
--with-float=hard 
--with-abi=aapcs-linux 
--with-mode=thumb

Which i do not remember using in my previous builds of MLFS on raspberry Pi 3 or Odroid XU4.

I am retrying build with less flags:

--with-arch=armv7-a 
--with-float=hard 
--with-abi=aapcs-linux 
--with-mode=thumb
dslm4515 commented 3 years ago

Less flags did not mean less troubles, lol. Build failed again:

/sources/gcc-10.2.0/build/./gcc/xgcc -B/sources/gcc-10.2.0/build/./gcc/ -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/testsuite/selftests
/sources/gcc-10.2.0/build/./gcc/xgcc -B/sources/gcc-10.2.0/build/./gcc/ -xc++ -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/testsuite/selftests
cc1: error: '-mfloat-abi=hard': selected processor lacks an FPU
cc1: note: self-tests are not enabled in this build
make[2]: *** [../../gcc/c/Make-lang.in:124: s-selftest-c] Error 1
make[2]: *** Waiting for unfinished jobs....
cc1plus: error: '-mfloat-abi=hard': selected processor lacks an FPU
cc1plus: note: self-tests are not enabled in this build
make[2]: *** [../../gcc/cp/Make-lang.in:178: s-selftest-c++] Error 1
rm gcc.pod
make[2]: Leaving directory '/sources/gcc-10.2.0/build/gcc'
make[1]: *** [Makefile:4399: all-gcc] Error 2
make[1]: Leaving directory '/sources/gcc-10.2.0/build'
make: *** [Makefile:962: all] Error 2
dslm4515 commented 3 years ago

I just realized the RPi3 has a 64-bit Cortex-A53.

Maybe I can salvage the build by using my ODroid-XU4 (Cortex-A15)

dslm4515 commented 3 years ago

Nope. Switching to an actual armv7 cpu didn't help

firasuke commented 3 years ago

I still didn't get to read the config.log, so I can't answer.

dslm4515 commented 3 years ago

I’ll run it again and post it here

dslm4515 commented 3 years ago

config.log for libgomp: https://pastebin.com/AFCQ9MKN

firasuke commented 3 years ago

First of all, the RPI 3 has an armv8-a architecture afaik.

After examining the log file, this seems to be the problem:

uses VFP register arguments, a.out does not

It's either not finding/using the correct libc, or (most likely) you're specifying a wrong set of flags.

firasuke commented 3 years ago

Another thing to note is the tuple should either be armv7hl or arm-linux-musleabihf, so maybe test those as well (since musl only understands arm (look in musl/arm)).

firasuke commented 3 years ago

If that also fails then try --with-fpu=neon or maybe remove --with-fpu entirely.

dslm4515 commented 3 years ago

The toolchain was built on a RPi3 but libgomp (GCC) was built on an ODroid-XU4 (definitely armv7)... would that matter?

dslm4515 commented 3 years ago

Yeah I realized that RPI3 is aarch64, so I switched to ODROID-XU4...

armv7l-linux-musleabihf did work for GCC 8.2 ... was it dropped for 9.3 and 10.2?

I will retry with those suggested flags and post results

dslm4515 commented 3 years ago

So I tried setting --with-fpu=neon with same error:

configure:3913: checking whether the C compiler works
configure:3935: /sources/gcc-10.2.0/build/./gcc/xgcc -B/sources/gcc-10.2.0/build/./gcc/ -B/usr/armv7l-linux-musleabihf/bin/ -B/usr/armv7l-linux-musleabihf/lib/ -isystem /usr/armv7l-linux-musleabihf/include -isystem /usr/armv7l-linux-musleabihf/sys-include    -g -O2   conftest.c  >&5
/tools/lib/gcc/armv7l-mlfs-linux-musleabihf/10.2.0/../../../../armv7l-mlfs-linux-musleabihf/bin/ld: error: /sources/gcc-10.2.0/build/./gcc/crtbeginS.o uses VFP register arguments, a.out does not
/tools/lib/gcc/armv7l-mlfs-linux-musleabihf/10.2.0/../../../../armv7l-mlfs-linux-musleabihf/bin/ld: failed to merge target specific data of file /sources/gcc-10.2.0/build/./gcc/crtbeginS.o
/tools/lib/gcc/armv7l-mlfs-linux-musleabihf/10.2.0/../../../../armv7l-mlfs-linux-musleabihf/bin/ld: error: /tmp/cchPAhLd.o uses VFP register arguments, a.out does not
/tools/lib/gcc/armv7l-mlfs-linux-musleabihf/10.2.0/../../../../armv7l-mlfs-linux-musleabihf/bin/ld: failed to merge target specific data of file /tmp/cchPAhLd.o
/tools/lib/gcc/armv7l-mlfs-linux-musleabihf/10.2.0/../../../../armv7l-mlfs-linux-musleabihf/bin/ld: error: /sources/gcc-10.2.0/build/./gcc/crtendS.o uses VFP register arguments, a.out does not
/tools/lib/gcc/armv7l-mlfs-linux-musleabihf/10.2.0/../../../../armv7l-mlfs-linux-musleabihf/bin/ld: failed to merge target specific data of file /sources/gcc-10.2.0/build/./gcc/crtendS.o
collect2: error: ld returned 1 exit status
configure:3939: $? = 1
configure:3977: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU Offloading and Multi Processing Runtime Library"
| #define PACKAGE_TARNAME "libgomp"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU Offloading and Multi Processing Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgomp/"
| #define PACKAGE "libgomp"
| #define VERSION "1.0"
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:3982: error: in `/sources/gcc-10.2.0/build/armv7l-linux-musleabihf/libgomp':
configure:3984: error: C compiler cannot create executables
See `config.log' for more details
dslm4515 commented 3 years ago

Re-tried the build with just setting the arch and ABI-type ( --with-arch=armv7-a --with-float=hard) and no CPU specifics :

/sources/gcc-10.2.0/build/./gcc/xgcc -B/sources/gcc-10.2.0/build/./gcc/ -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/testsuite/selftests
/sources/gcc-10.2.0/build/./gcc/xgcc -B/sources/gcc-10.2.0/build/./gcc/ -xc++ -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/testsuite/selftests
cc1: error: '-mfloat-abi=hard': selected processor lacks an FPU
cc1: note: self-tests are not enabled in this build
make[2]: *** [../../gcc/c/Make-lang.in:124: s-selftest-c] Error 1
make[2]: *** Waiting for unfinished jobs....
cc1plus: error: '-mfloat-abi=hard': selected processor lacks an FPU
cc1plus: note: self-tests are not enabled in this build
make[2]: *** [../../gcc/cp/Make-lang.in:178: s-selftest-c++] Error 1
rm gcc.pod
make[2]: Leaving directory '/sources/gcc-10.2.0/build/gcc'
make[1]: *** [Makefile:4399: all-gcc] Error 2
make[1]: Leaving directory '/sources/gcc-10.2.0/build'
make: *** [Makefile:962: all] Error 2
dslm4515 commented 3 years ago

Only setting --with-arch=armv7-a allows build to complete with out errors.

SED=sed  libat_cv_have_ifunc=no       \
../configure --prefix=/usr            \
             --build=armv7l-linux-musleabihf \
             --with-system-zlib       \
             --with-isl \
             --with-linker-hash-style=gnu \
             --enable-languages=c,c++ \
             --enable-threads=posix \
             --enable-clocale=generic \
             --enable-tls \
             --enable-libstdcxx-time \
             --enable-fully-dynamic-string \
             --enable-default-pie \
             --enable-default-ssp \
             --enable-vtable-verify \
             --enable-linker-build-id \
             --enable-fast-character \
             --disable-libstdcxx-pch \
             --disable-nls \
             --disable-multilib       \
             --disable-bootstrap      \
             --disable-symvers \
             --disable-libsanitizer \
             --disable-target-libiberty \
             --disable-libunwind-exceptions \
             --disable-libssp --disable-libmpx \
             --disable-libmudflap  \
             --with-pkgversion="Musl-LFS 8.03" \
             --with-arch=armv7-a
firasuke commented 3 years ago

The way you're constructing toolchains isn't optimal (the style of CLFS/LFS isn't the best, as modifying the sources of GCC isn't always the greatest of ideas...).

Also many of the flags you're using aren't up-to-date and some are even deprecated (e.g. mudflap was removed from GCC since 4.9 so there's no point in specifying --disable-libmudflap as it won't do anything, also mpx was removed since 5.6 so specifying --disable-libmpx won't do anything as well).

Either check musl-cross-make (cross and native) or mussel (cross only) as they both have almost all arches supported.

dslm4515 commented 3 years ago

Sorry, I forgot your repo does keep up to date. I will check and update my flags!

dslm4515 commented 3 years ago

Rebuilt toolchain and optimized it for my ODROID-XU4 with these flags:

--with-arch=armv7-a+neon-vfpv4
--with-tune=cortex-a15.cortex-a7
--wiith-float=hard
--with-abi=aapcs-linux 
--with-mode=thumb

Also fixed an issue where I did not realize i had to use armhf instead of arm:

/tools/lib/ld-musl-armhf.so.1
/mnt/mlfs/lib/ld-musl-armhf.so.1

Then i tried building GCC with same flags... no errors!

firasuke commented 3 years ago

Interesting.

dslm4515 commented 3 years ago

Linux kernel now fails to compile:

/tmp/cckiCidh.s:17299: Error: selected processor does not support `isb ' in ARM mode
/tmp/cckiCidh.s:17789: Error: selected processor does not support `dmb ishst' in ARM mode
/tmp/cckiCidh.s:18531: Error: architectural extension `mp' is not allowed for the current base architecture

But fixed it by specifying compiler flags:

KCFLAGS=" -march=armv7-a+neon-vfpv4 -mtune=cortex-a15.cortex-a7 -mthumb-interwork" make