Figured out some more: The problem affects all arm architectures > armv6. The root cause is in libgcc/config/arm/bpabi.S which does not contain code for thumb mode at all but unconditionally build arm code. The only exception is armv6 pulled in from libgcc/config/arm/bpabi-v6m.S which handles arm and thumb mode. Since the affected functions are rather rare used 64bit integer operations, it seems no one realized that yet. But, in my case, I activated 64bit printf support in newlib, the problem pops up. As a workaround , I included bpabi-v6m.S in libgcc/config/arm/lib1funcs.S if __thumb__ is defined. This fixes the problem, at least for the functions I mentioned above. But maybe using armv6m instructions is not the most effective code .... so, I think, this should be looked at by someone having more insight than me. I still verifying that for some more build variants. -----Original-Nachricht----- Betreff: GCC creates code having the wrong instruction set Datum: 2017-03-07T20:28:44+0100 Von: "onkel.jack@xxxxxxxxxxx" <onkel.jack@xxxxxxxxxxx> An: "gcc-help mailing list" <gcc-help@xxxxxxxxxxx> I try to build an arm tool chain based on GCC 6.3.0 with newlib 2.5.0. Almost everything went fine, except for thumb mode some code in thumb/libgcc.a is generated with the wrong instruction set. Affected are i.e. __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod and some more, while most of the symbols has correct thumb instructions. code which has ARM instructions instead of thumb. I use the default multilib config, but tried aprofile too, with same result. Here is the Makefile containing all config options I use: BINUTILS_VERSION = 2.27 GCC_VERSION = 6.3.0 NEWLIB_VERSION = 2.5.0 GDB_VERSION = 7.12.1 BINUTILS = binutils-$(BINUTILS_VERSION) GCC = gcc-$(GCC_VERSION) NEWLIB = newlib-$(NEWLIB_VERSION) GDB = gdb-$(GDB_VERSION) TARGET=arm-nanix-eabi PREFIX=$(PWD)/$(TARGET)-$(GCC_VERSION) PATH:=$(PREFIX)/bin:$(PATH) PLATFORM=$(shell uname -s) #ifeq ($(PLATFORM), MINGW64_NT-6.1) # BUILD=--build=x86_64-w64-mingw32 #endif default : all clean: rm -rf *-build rm -rf $(PREFIX) binutils: binutils-build/build-done gcc-boot: gcc-build/build-boot-done newlib: newlib-build/build-done gcc: gcc-build/build-done gdb: gdb-build/build-done #all: binutils gcc-boot newlib gcc gdb all: gcc-boot newlib gcc gdb $(BINUTILS).tar.bz2: echo "Grabbing $@" curl ftp://ftp.gnu.org/gnu/binutils/$@ -o $@ $(GCC).tar.bz2: echo "Grabbing $@" curl ftp://ftp.gnu.org/gnu/gcc/$(GCC)/$@ -o $@ $(NEWLIB).tar.gz: echo "Grabbing $@" curl ftp://sources.redhat.com/pub/newlib/$@ -o $@ $(GDB).tar.gz: echo "Grabbing $@" curl ftp://ftp.gnu.org/gnu/gdb/$@ -o $@ $(BINUTILS) : $(BINUTILS).tar.bz2 echo -n "extracting $< : " tar -jxf $< touch $@ $(GCC) : $(GCC).tar.bz2 echo -n "extracting $< : " tar -jxf $< touch $@ $(NEWLIB) : $(NEWLIB).tar.gz echo -n "extracting $< : " tar -zxf $< patch -p 1 -d $(NEWLIB) < $(NEWLIB)-nanix.patch touch $@ $(GDB) : $(GDB).tar.gz echo -n "extracting $< : " tar -zxf $< touch $@ %-build: mkdir -p $@ $(GCC)/gmp: | $(GCC) cd $(GCC); ./contrib/download_prerequisites touch $@ $(GCC)/mpfr:| $(GCC) cd $(GCC); ./contrib/download_prerequisites touch $@ $(GCC)/mpc: | $(GCC) cd $(GCC); ./contrib/download_prerequisites touch $@ # Build a set of compatible Binutils for this architecture. Need this before # we can build GCC. binutils-build/config-done: $(BINUTILS) rm -f $@ mkdir -p binutils-build cd binutils-build ;\ ../$(BINUTILS)/configure $(BUILD) LDFLAGS="-static" --target=$(TARGET) --prefix=$(PREFIX) --disable-nls\ && touch config-done binutils-build/build-done: binutils-build/config-done rm -f $@ make -C binutils-build all install 2>&1 | tee binutils-build/make.log; test $${PIPESTATUS[0]} = 0 && touch $@ # Build and configure GCC with the Newlib C runtime. gcc-build/config-boot-done: binutils-build/build-done $(GCC) $(GCC)/gmp $(GCC)/mpfr $(GCC)/mpc rm -f $@ mkdir -p gcc-build cd gcc-build ; ../$(GCC)/configure $(BUILD) LDFLAGS="-static" --target=$(TARGET) --prefix=$(PREFIX) \ --with-newlib \ --disable-nls \ --disable-libssp \ --disable-gomp \ --disable-libstcxx-pch \ --enable-threads \ --disable-shared \ --enable-static \ --disable-libmudflap --enable-languages=c,c++\ --without-libiconv-prefix\ && touch config-boot-done gcc-build/build-boot-done: gcc-build/config-boot-done rm -f $@ make -C gcc-build all-gcc install-gcc 2>&1 | tee -a gcc-build/boot-make.log; test $${PIPESTATUS[0]} = 0 && touch $@ newlib-build/config-done: gcc-build/build-boot-done $(NEWLIB) rm -f $@ mkdir -p newlib-build cd newlib-build ; ../$(NEWLIB)/configure CFLAGS_FOR_TARGET=-fstack-usage LDFLAGS="-static" $(BUILD) --target=$(TARGET) --prefix=$(PREFIX) \ --enable-multilib \ --enable-shared=no --enable-static=yes \ --enable-newlib-nano-malloc \ --enable-target-optspace\ --enable-lite-exit \ --enable-newlib-global-atexit \ --enable-newlib-reent-small \ --enable-newlib-multithread\ --enable-newlib-nano-formatted-io --disable-newlib-unbuf-stream-opt\ --disable-newlib-fvwrite-in-streamio \ --disable-newlib-wide-orient \ && touch config-done newlib-build/build-done: newlib-build/config-done rm -f $@ make -C newlib-build all install INCLUDE=$(pwd)/$(NEWLIB)/include 2>&1 | tee -a newlib-build/make.log; test $${PIPESTATUS[0]} = 0 && touch $@ gcc-build/build-done: newlib-build/config-done rm -f $@ make -C gcc-build all install 2>&1 | tee -a gcc-build/make.log; test $${PIPESTATUS[0]} = 0 && touch $@ gdb-build/config-done: gcc-build/build-done $(GDB) rm -f $@ mkdir -p gdb-build cd gdb-build ; ../$(GDB)/configure $(BUILD) LDFLAGS="-static" --target=$(TARGET) --prefix=$(PREFIX) \ && touch config-done gdb-build/build-done: gdb-build/config-done rm -f $@ make -C gdb-build all install 2>&1 | tee -a ../make.log; test $${PIPESTATUS[0]} = 0 && touch $@ So, how I can build that toolchain supporting multiple targets having correct generated code ?