gcc-thumb (arm), let's build a cross-compiler - Page 1
Forum section: electronics / general

author: DiTBho
author_rank: Super Contributor
timestamp: January 05, 2023, 06:34:21 pm
content: so, I am still working (hacking?) with a toolchain builder, and I am bit confused about the support required by Nintendo GBA (GameBoy Advance, 32 bit ARM7TDMI @ 16,78 MHz, 8 bit Z80 @ 8,338 MHz).Z80 requires sdccARM Thumb requires gccNow, I have used gcc-v9.3.0 for most of the other architectures I need to supportCode:c3750 /projects/devchain-baremetal-2023 # ./mybuild info allBC success: m6811-elf, binutils v2.23, gcc v3.3.6-s12x, mini modeBC success: m68k-elf, binutils v2.34, gcc v9.3.0, mini modefailure: m68k-aout, binutils v2.34, gcc v9.3.0, mini modeBC success: m88k-coff, binutils v2.16.1, gcc v3.1.1, mini modeBC success: mips-elf, binutils v2.24, gcc v9.3.0, mini modeBC success: mips64-elf, binutils v2.24, gcc v9.3.0, mini modeBC success: powerpc-elf, binutils v2.24, gcc v9.3.0, mini modeBC success: powerpc-eabi, binutils v2.24, gcc v9.3.0, mini modeBC success: arm-eabi, binutils v2.24, gcc v9.3.0, mini modeBC success: arm-thumb-elf, binutils v2.24, gcc v9.3.0, mini modeBC success: sh2-elf, binutils v2.24, gcc v9.3.0, mini modeBC success: sh4-elf, binutils v2.24, gcc v9.3.0, mini modeBC success: riscv32-elf, binutils v2.39, gcc v9.3.0, mini modeBC success: hppa-unknown-linux-gnu, binutils v2.24, gcc v9.3.0, mini modeI can successfully configure and build both binutils-v2.24 and gcc-v4.1.2 with --target=arm-thumb-elf.Code:c3750 /projects/devchain-baremetal-2023 # ./mybuild info tarmBC success: arm-thumb-elf, binutils v2.24, gcc v4.1.2-core, mini modec3750 /projects/devchain-baremetal-2023 # ./mybuild test tarmtesting arm-thumb-elf-gcc ... successgcc-v9.3.0 failsCode:c3750 /projects/devchain-baremetal-2023 # ./mybuild build gcc0 tarmbuilding gcc0 for tarm ...gcc-9.3.0, checking source ... okgcc-9.3.0, checking build ... okgcc-9.3.0, machine=arm-thumb-elf, mode=mini.bootstrap.without-gnu-bugcc-9.3.0, preparing(defs.h) ... successgcc-9.3.0, building(bootstrap2) ... failurec3750 /projects/devchain-baremetal-2023 # ./mybuild log2 gcc0 tarm----------------- build/tarm/gcc-9.3.0/make2.log2 -----------------configure: WARNING: decimal float is not supported for this target, ignored*** Configuration arm-thumb-elf not supportedmake: *** [Makefile:4236: configure-gcc] Error 1make: *** [Makefile:933: all] Error 2gcc-v9.3.0 accepts { -mthumb, -marm } options. The-thumb optioninstructs the compiler to generate thumb code rather than ARM code and link in thumb libraries.So, I could support GBA with the "-mthumb" option passed to gcc-v9.3.0, however, I'd like to know which is the last gcc version that can be configured witharm-thumb-elf, since I largely prefer to avoid passing to many options to the compiler.Tempted to hack gcc, to force thumb by default, but this I will cause a similar issue to Cortex-M architectures, for which the "-mthumb" option is NOT needed.Basically, I want/prefer a dedicated compiler for thumb, and one a compiler for Cortex-M.(possibly, plus, PXA, and others ... for future needs)NOTE: why not a newer toolchain for thumb?Well, because newer binutils add more symbols in thumb mode than older binutils, which makes thumb mode binaries file size larger than the with old binutils and larger than ARM mode binaries 7. These extra symbols only affect the file size and sections loaded to memory are smaller in thumb mode than in ARM mode.GBA doesn't have a lot of ram, so ... less bits and bytes is better

author: eutectique
author_rank: Frequent Contributor
timestamp: January 05, 2023, 09:46:35 pm
content: ARM7TDMI is architecture ARMv4T. Hence, passing-march=armv4twould do the job nicely. Don't forget-mthumb-interwork.Other ARM-related options for gcc can be had here:https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html

author: DiTBho
author_rank: Super Contributor
timestamp: January 05, 2023, 09:49:19 pm
content: Quote from: eutectique on January 05, 2023, 09:46:35 pmbut I don't want to pass *ANYTHING*, I want thumb by default

author: DiTBho
author_rank: Super Contributor
timestamp: January 05, 2023, 09:50:37 pm
content: Quote from: DiTBho on January 05, 2023, 06:34:21 pm

author: eutectique
author_rank: Frequent Contributor
timestamp: January 05, 2023, 10:00:14 pm
content: QuoteUse an alias, for example? In bash it would be something likealias thumb-none-eabi-gcc='arm-none-eabi-gcc -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork'Edit: changed the alias name to a more appealing one.

author: DiTBho
author_rank: Super Contributor
timestamp: January 05, 2023, 10:04:20 pm
content: Quote from: eutectique on January 05, 2023, 10:00:14 pmI know how bash works, but for A LOT of other reasons it cannot be done that way.If I spend time asking a specific question ...

author: DiTBho
author_rank: Super Contributor
timestamp: January 05, 2023, 10:07:05 pm
content: I will likely hack gcc v9.3.01) adding the old arm-thumb-elf spec in confic.ac2) forcing thumb by default when --target is thumb

author: eutectique
author_rank: Frequent Contributor
timestamp: January 05, 2023, 10:12:27 pm
content: QuoteI am no quite sure what you mean bylast gcc version, but the latest version available on ARM website is 12.2:https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads, including the source code. Is it what you are after?Sorry, I must have missed the beginning of the long saga. Please, ignore my comments.

author: DiTBho
author_rank: Super Contributor
timestamp: January 06, 2023, 12:09:35 am
content: Code:c3750 /projects/devchain-baremetal-2023 # ./mybuild build gcc0 tarmbuilding gcc0 for tarm ...gcc-4.6.4, checking source ... okgcc-4.6.4, checking build ... okgcc-4.6.4, machine=arm-thumb-elf, mode=mini.bootstrap.without-gnu-bugcc-4.6.4, preparing(defs.h) ... successgcc-4.6.4, building(bootstrap2) ... successgcc-4.6.4, installing ... successGcc-v4.6.4 can be configured with --target=arm-thumb-elfIt needs patches to fix texi and other stuff, but it works!

author: DiTBho
author_rank: Super Contributor
timestamp: January 06, 2023, 12:22:20 am
content: Gcc-v4.7.0 is the last one supporting arm-thumb-elfCode:*** Configuration arm-thumb-elf is obsolete.*** Specify --enable-obsolete to build it anyway.*** Support will be REMOVED in the next major release of GCC,Ok, this answers my question

author: Nominal Animal
author_rank: Super Contributor
timestamp: January 06, 2023, 02:31:31 pm
content: What's the ABI difference betweenarm-thumb-elfandarm-none-eabi? I thought the latter includes the former since ARM EABI 2.0, but I'm surely mistaken, since decimal float support was mentioned.Quote from: DiTBho on January 05, 2023, 10:07:05 pmYou can use aGCC .spec filefor these.Furthermore, since/usr/bin/gccis usually a symlink (to/usr/bin/arch-gcc-version), you can replace/usr/bin/gccwith a script, perhaps something likeCode:#!/bin/dashexec /usr/bin/arch-gcc-version $GCC_OPTIONS "$@"so you can use e.g.export GCC_OPTIONS="-spec=/usr/lib/gcc/arch/version-sub-patch/custom.spec"orexport GCC_OPTIONS="-march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork"Just remember that it will be evaluated twice by the shell (affecting quoting and escapes).

author: DiTBho
author_rank: Super Contributor
timestamp: January 06, 2023, 11:56:23 pm
content: Quote from: Nominal Animal on January 06, 2023, 02:31:31 pmDunno, ARM is very confusingPOWER9, POWER10, and PowerPC are even more confusing regarding ISA and ABI.Quote from: DiTBho on January 05, 2023, 10:07:05 pmyupCode:ls -l /usr/bin/gcclrwxrwxrwx 1 root root 41 Dec 30 18:36 /usr/bin/gcc -> /usr/hppa-linux-gnu/gcc-bin/10.2.0/gcc(native compiler, emerged by Gentoo/emerge)Code:ls -l /usr/bin/mips-unknown-linux-gnu-gcclrwxrwxrwx 1 root root 86 Jul 22 2021 /usr/bin/mips-unknown-linux-gnu-gcc -> /usr/hppa-linux-gnu/mips-unknown-linux-gnu/gcc-bin/6.5.0/mips-unknown-linux-gnu-gcc(cross-compiler, emerged by Gentoo/crossdev)That's the Gentoo way, but for this project I need ALL the binaries into the same place, doing the right stuff for arm-thumb without passing too many options to cc1I need to pass ONLY this CFLAGS, and to see the job doneCode:CC = arm-thumb-elf-gccAS = arm-thumb-elf-asLD = arm-thumb-elf-ldOBJCOPY = arm-thumb-elf-objcopyCFLAGS = -WallPROJECT = bsp...(makefile, GBA project)cannot pass/want avoid to pass CFLAGS=-marm -mcpu=arm7tdmi, ... because gcc already passes too many stuff to cc1 (the piece of toolchain that compiles C into assembly) and I have limited support with the number of args I can pass.Also, I hacked gcc to have cc1 in a specific folder and with the same prefix (arm-thumb-elf) specifiedQuoteit's all there because I need to have everything there, without wrappers, or alias, or other stuff.Code:c3750# lsprettysize /usr/idp/bin/arm-thumb-elf-*926. 7 Kbyte /usr/idp/bin/arm-thumb-elf-addr2line965. 4 Kbyte /usr/idp/bin/arm-thumb-elf-ar1. 7 Mbyte /usr/idp/bin/arm-thumb-elf-as15. 5 Mbyte /usr/idp/bin/arm-thumb-elf-cc1642. 6 Kbyte /usr/idp/bin/arm-thumb-elf-cpp40. 9 Kbyte /usr/idp/bin/arm-thumb-elf-elfedit638. 5 Kbyte /usr/idp/bin/arm-thumb-elf-gcc35. 6 Kbyte /usr/idp/bin/arm-thumb-elf-gcc-ar35. 6 Kbyte /usr/idp/bin/arm-thumb-elf-gcc-nm35. 6 Kbyte /usr/idp/bin/arm-thumb-elf-gcc-ranlib280. 4 Kbyte /usr/idp/bin/arm-thumb-elf-gcov1. 0 Mbyte /usr/idp/bin/arm-thumb-elf-gprof1. 3 Mbyte /usr/idp/bin/arm-thumb-elf-ld1. 3 Mbyte /usr/idp/bin/arm-thumb-elf-ld.bfd941. 5 Kbyte /usr/idp/bin/arm-thumb-elf-nm1. 1 Mbyte /usr/idp/bin/arm-thumb-elf-objcopy1. 4 Mbyte /usr/idp/bin/arm-thumb-elf-objdump965. 4 Kbyte /usr/idp/bin/arm-thumb-elf-ranlib634. 5 Kbyte /usr/idp/bin/arm-thumb-elf-readelf927. 2 Kbyte /usr/idp/bin/arm-thumb-elf-size926. 6 Kbyte /usr/idp/bin/arm-thumb-elf-strings1. 1 Mbyte /usr/idp/bin/arm-thumb-elf-stripAs far as I see, gcc-v4.7.0 works as I need right out of the box once patched for- doc/texi ignore, don't build- force no-bootstrap- force cc1 at a custom pathAll GBA examples perfectly compile and run on real hardware.I am going to cross-compile again, this time for a RISC-OS machine.Now you can understand why not ... Bash, sym-links, alias, other too-unix-ish stuff.I only have partial UNIX support on RISC OS v4.39 adjust.

author: DiTBho
author_rank: Super Contributor
timestamp: January 07, 2023, 12:05:16 am
content: on Gentoo, for gcc-v10.0, cc1 is expected to be hereCode:/usr/libexec/gcc/hppa-linux-gnu/10.0/cc1for the native compilerand here for a cross-compilerCode:/usr/libexec/gcc/mips-unknown-linux-gnu/10.0/cc1

author: DiTBho
author_rank: Super Contributor
timestamp: January 07, 2023, 02:42:00 pm
content: I also have to fix a marginally but annoying issue: the default include-folder-pathsCode:ignoring nonexistent directory "/usr/idp/lib/gcc/arm-thumb-elf/4.7.0/include"ignoring nonexistent directory "/usr/idp/lib/gcc/arm-thumb-elf/4.7.0/include-fixed"ignoring nonexistent directory "/usr/idp/arm-thumb-elf/sys-include"this stuff is automatically configured and it's difficult to customize -> yet an other hack -> patchwanted paths:Code:/usr/idp/arm-thumb-elf/include/usr/idp/include

author: DiTBho
author_rank: Super Contributor
timestamp: January 07, 2023, 05:10:42 pm
content: spent one hour hackingfound, hacked, and solvedCode:~ gcc/incpath.c~ gcc/cppdefault.cThese two files in gcc-v4.7.0 manage the default include-paths.

author: Nominal Animal
author_rank: Super Contributor
timestamp: January 07, 2023, 05:52:40 pm
content: Are you sure you cannot set these in the defaultspecs file?It does not exist by default, but you can see where gcc looks for them by runningstrace -e access gcc --version; for me, it would be/usr/lib/gcc/x86_64-linux-gnu/9/specs.