Search code examples
cgccarmthumb

C Preprocessor/compiler directives to specify ARM or Thumb modes?


When working directly with ARM assembly I can use .thumb and .thumb_func and their analogous arm directives to instruct the assembler which flavor of instructions to output.

Is there a matching compiler directive when developing C code? The GCC documentation I've seen mentions various command line options to allow thumb and arm code to work in the same binary but the output looks like it's an entire binary that's in either thumb or ARM. I want to be able to specify how individual functions are compiled.

If not, is there another way to accomplish this? I was thinking I could compile multiple times and then manually splice the disassemble to manually splice the functions together in a new binary but I'm hoping there's an easier way.


Solution

  • Looks like what you want is a target function attribute. Have a look at the arm and thumb attributes at https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/ARM-Function-Attributes.html#ARM-Function-Attributes

    These should allow you to compile individual functions in a file for A32 or T32.