Search code examples
linuxgccassemblyarmthumb

How to compile ARM32 only binary (no thumb)


Is there a GCC configuration which will produce an executable only containing ARM32 code? I know the -marm switch tells the compiler not to produce Thumb code, but it applies only to the user code of the program, while initialization routines (e.g. _start, frame_dummy, ...) still contain Thumb instructions. I am using the Linaro cross compiler tool-chain (arm-linux-gnueabihf-) on a Linux x86-64 system.

EDIT :

While recompiling the tool-chain I found the (probable) solution myself. The initialization routines encoded as Thumb are part of glibc and can be found in the object files crt1.o, crti.o and crtbegin.o. I haven't tried recompiling it, but there may be a configuration value which forces the whole libc to be encoded as ARM32.


Solution

  • Is there a GCC configuration which will produce an executable only containing ARM32 code? I know the -marm switch ...

    Your main problem is that that code (e.g. _start) is not produced by the compiler but it is already present pre-compiled (as thumb code).

    If you want to have these functions to be non-thumb code you'll have to "replace" the existing files (thumb) by your own ones (non-thumb).

    (You don't have to overwrite the existing files but you can instruct the linker to search for these files in a different directory.)

    If you don't find pre-built non-thumb files you'll have to create them yourself (what may be a lot of work).