When building gcc 10.4.0 or 11.3.0 for Cortex-M3 or M7, the build fails with: ../../../libgcc/libgcc2.c: In function '__clear_cache': ../../../libgcc/libgcc2.c:2174:1: error: r7 cannot be used in 'asm' here 2174 | } | ^ Makefile:501: recipe for target '_clear_cache.o' failed GCC was configured like this: (cd /home/buildroot/autobuild/instance-0/output-1/build/host-gcc-initial-10.4.0/build && rm -rf config.cache; PATH="/home/buildroot/autobuild/instance-0/output-1/host/bin:/home/buildroot/autobuild/instance-0/output-1/host/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" PKG_CONFIG="/home/buildroot/autobuild/instance-0/output-1/host/bin/pkg-config" PKG_CONFIG_SYSROOT_DIR="/" PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_LIBDIR="/home/buildroot/autobuild/instance-0/output-1/host/lib/pkgconfig:/home/buildroot/autobuild/instance-0/output-1/host/share/pkgconfig" AR="/usr/bin/ar" AS="/usr/bin/as" LD="/usr/bin/ld" NM="/usr/bin/nm" CC="/usr/bin/gcc" GCC="/usr/bin/gcc" CXX="/usr/bin/g++" CPP="/usr/bin/cpp" OBJCOPY="/usr/bin/objcopy" RANLIB="/usr/bin/ranlib" CPPFLAGS="-I/home/buildroot/autobuild/instance-0/output-1/host/include" CFLAGS="-O2 -I/home/buildroot/autobuild/instance-0/output-1/host/include" CXXFLAGS="-O2 -I/home/buildroot/autobuild/instance-0/output-1/host/include" LDFLAGS="-L/home/buildroot/autobuild/instance-0/output-1/host/lib -Wl,-rpath,/home/buildroot/autobuild/instance-0/output-1/host/lib" INTLTOOL_PERL=/usr/bin/perl CFLAGS="-O2 -I/home/buildroot/autobuild/instance-0/output-1/host/include" LDFLAGS="-L/home/buildroot/autobuild/instance-0/output-1/host/lib -Wl,-rpath,/home/buildroot/autobuild/instance-0/output-1/host/lib" MAKEINFO=missing CFLAGS_FOR_TARGET="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O0 -g0 -Wl,-elf2flt=-r -static" CXXFLAGS_FOR_TARGET="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O0 -g0 -Wl,-elf2flt=-r -static -Wl,-elf2flt=-r -static" AR_FOR_TARGET=gcc-ar NM_FOR_TARGET=gcc-nm RANLIB_FOR_TARGET=gcc-ranlib CONFIG_SITE=/dev/null ./configure --prefix="/home/buildroot/autobuild/instance-0/output-1/host" --sysconfdir="/home/buildroot/autobuild/instance-0/output-1/host/etc" --localstatedir="/home/buildroot/autobuild/instance-0/output-1/host/var" --enable-shared --disable-static --disable-gtk-doc --disable-gtk-doc-html --disable-doc --disable-docs --disable-documentation --disable-debug --with-xmlto=no --with-fop=no --disable-nls --disable-dependency-tracking --target=arm-buildroot-uclinux-uclibcgnueabi --with-sysroot=/home/buildroot/autobuild/instance-0/output-1/host/arm-buildroot-uclinux-uclibcgnueabi/sysroot --enable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --disable-decimal-float --with-gmp=/home/buildroot/autobuild/instance-0/output-1/host --with-mpc=/home/buildroot/autobuild/instance-0/output-1/host --with-mpfr=/home/buildroot/autobuild/instance-0/output-1/host --with-pkgversion="Buildroot 2022.05-439-g18f6e4bf70" --with-bugurl="http://bugs.buildroot.net/" --without-zstd --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-tls --enable-threads --without-isl --without-cloog --with-float=soft --with-abi="aapcs-linux" --with-cpu=cortex-m3 --with-float=soft --with-mode=thumb --enable-languages=c --disable-shared --without-headers --disable-threads --with-newlib --disable-largefile ) Full build log of GCC 10.4.0 for Cortex-M3: http://autobuild.buildroot.net/results/e91/e91fa76142cf50e514d5fe4791a06f3c3c014b5a/build-end.log Full build log of GCC 11.3.0 for Cortex-M7: http://autobuild.buildroot.net/results/9f7/9f7a43a375d476f47702cd7848eba53b76fcd386/build-end.log
At quick glance, I think this is caused by the definition of CLEAR_INSN_CACHE in gcc/config/arm/uclinux-eabi.h: /* Clear the instruction cache from `beg' to `end'. This makes an inline system call to SYS_cacheflush. */ #undef CLEAR_INSN_CACHE #define CLEAR_INSN_CACHE(BEG, END) \ { \ register unsigned long _beg __asm ("a1") = (unsigned long) (BEG); \ register unsigned long _end __asm ("a2") = (unsigned long) (END); \ register unsigned long _flg __asm ("a3") = 0; \ register unsigned long _scno __asm ("r7") = 0xf0002; \ __asm __volatile ("swi 0x0 @ sys_cacheflush" \ : "=r" (_beg) \ : "0" (_beg), "r" (_end), "r" (_flg), "r" (_scno)); \ } which makes explicit use of r7. This code has been like that since it was committed in 2007.... So I suspect nobody ever tried to build this configuration.
Thanks for the feedback. There must be something special in those configurations, because I did build a Cortex-M4 configuration with gcc 11.3.0 just a few days ago, and it built fine.
Interesting.... Did you use the same target triplet? arm*-*-uclinuxfdpiceabi is handled differently from arm-buildroot-uclinux-uclibcgnueabi
Yes, same triplet. We do not (yet) have FDPIC support for ARM in Buildroot (we have a patch series pending for that).
Could you share the preprocessed source file in the M3 and M4 cases along with the full command line used to compile it?
In Thumb code r7 is the frame pointer, so can't be used in inline assembler without a dance whenever the frame pointer might be needed. I'm surprised this hasn't shown up before. We're going to need a separate definition of this macro when compiling for Thumb as you can't easily rewrite this. The code will need to do something like mov scratch, r7 mov r7, #<syscall-value> svc 0 mov r7, scratch
Indeed, but I am surprised it seems to compile for cortex-m4?
Perhaps something is changing the decision on the use of the frame pointer.