I'm trying to compile a C program to the ARM Thumb-2 instruction set through GCC 6.2, using arm-linux-gnueabihf-gcc
from the 6.2.0-5ubuntu12 package on Ubuntu GNU/Linux.
The problem is I'm getting the same binary as when I'm not using the "-mthumb" option:
$ arm-linux-gnueabihf-gcc -c hello.c
$ arm-linux-gnueabihf-objdump -S hello.o
hello.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <main>:
0: b580 push {r7, lr}
2: af00 add r7, sp, #0
4: f240 0000 movw r0, #0
8: f2c0 0000 movt r0, #0
c: f7ff fffe bl 0 <puts>
10: 2300 movs r3, #0
12: 4618 mov r0, r3
14: bd80 pop {r7, pc}
And:
$ arm-linux-gnueabihf-gcc -mthumb -c hello.c
$ arm-linux-gnueabihf-objdump -S hello.o
hello.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <main>:
0: b580 push {r7, lr}
2: af00 add r7, sp, #0
4: f240 0000 movw r0, #0
8: f2c0 0000 movt r0, #0
c: f7ff fffe bl 0 <puts>
10: 2300 movs r3, #0
12: 4618 mov r0, r3
14: bd80 pop {r7, pc}
I'm getting the same code. I also tried with more complex code (computing the decimals of Pi), and still getting the same code.
I'm getting the same behavior with gcc-4.7-arm-linux-gnueabihf, so the issue is probably in the way I'm using the compiler...
It's hard to believe I'm the only one facing this issue. There must be a way to get GCC to do what's it's supposed to.