Search code examples
gcccompilationarmtoolchainthumb

Change default ARM gcc option to thumb


I want to change the behavior of the ARM toolchain arm-linux-gnueabi-gcc in my Linux machine, that the compiled code will be in Thumb mode as default - same as passing the -mthumb flag.

I came across this document, which under the section of --with-mode describes exactly what I try to achieve. However, I couldn't understand from their explanation how can I actually set this option.

Can anyone clarify this for me, or suggest another way to achieve my goal?


Solution

  • You can "mask" the executable file /usr/bin/arm-linux-gnueabi-gcc with your own script that is named the same inside /usr/local/bin.

    • Create a file /usr/local/bin/arm-linux-gnueabi-gcc
    • With the content
      • #!/bin/sh
      • /usr/bin/arm-linux-gnueabi-gcc -mthumb "$@"
    • Add executable permissions to /usr/local/bin/arm-linux-gnueabi-gcc

    Because PATH should list /usr/local/bin directory before /usr/bin, when you type arm-linux-gnueabi-gcc without the path in your console, your script will chosen first and will execute the real arm-linux-gnueabi-gcc executable with the additional option.