5

Guys, I have a project which I have compiled for the ARM Cortex-A8 processor. I'm making use of GCC to do this. Currently the size of my executable is 220.1 KB. Now I modify my makefile and I add the flag -mthumb, the makefile line looks somewhat like this -

gcc -mcpu=cortex-a8 -mthumb -marm -mfloat-abi=softfp -mfpu=neon

I do this changes in all my makefiles and I build my project, but the executable I get finally still continues to be of 220.1 KB.

I made one more change to my command line, I added the -mthumb-interwork option

gcc -mcpu=cortex-a8 -mthumb -mthumb-interwork -marm -mfloat-abi=softfp -mfpu=neon

Once again I get the same sized executable 220.1 KB. Am I missing anything while doing this?

I wrote a small program, to find the smallest of two numbers and I compiled it using the following command line

gcc main.c -o main

I get a 8.5 KB executable

Next, I do a

gcc -mthumb main.c -o main

I still get a 8.5 KB executable.

Whats wrong here?

I did a cat /proc/cpuinfo to see if thumb is really supported by my processor, and I see that it is indeed supported. I get -

Processor: ARMv7 Processor rev 5 (v7l)
Features: swp half thumb fastmult vfp edsp neon vfpv3
....
....
artless noise
  • 18,969
  • 5
  • 57
  • 95
HaggarTheHorrible
  • 6,335
  • 16
  • 63
  • 79

3 Answers3

6

I think -marm means you have an arm with no thumb, try removing -marm.

old_timer
  • 62,459
  • 8
  • 79
  • 150
  • 1
    I think that is it, it is pretty easy to demonstrate, try -S -mthumb -marm on a tiny file with a small function and see that it generates arm code because the -marm the last thing you asked it to do. then change it to -marm -mthumb, with -mthumb last it generates thumb code. So having -marm last trumps all the thumb stuff you are trying to do. – old_timer Nov 06 '10 at 00:36
  • 1
    When in doubt, use "gcc -save-temps" to preserve the asm file, or "objdump -d" on the object code for a disassembly. The difference between ARM and Thumb is pretty easy to spot based on the instruction widths (ARM are always 4 bytes, Thumb is 2 bytes, Thumb2 is 2 or 4). I've seen cases where Thumb < ARM < Thumb2 in gcc output, but that was a while back. – fadden Dec 08 '10 at 22:46
2

It's hard to say without having the actual code, but I have a couple of suggestions.

  1. Enable optimizations. (e.g. -O3 -ffunction-sections -fdata-sections)
  2. Strip the executable to make sure the debug info is not counted.
  3. Check the actual code (.text) size, not the file size. Maybe there is some padding going on. You can use objdump for that.
  4. Dump the assembly code (-S switch) and check that it actually produces ARM instructions in one case and Thumb in another.
Igor Skochinsky
  • 22,978
  • 1
  • 62
  • 101
0

With some compilers, thumb is the default when compiling for ARMv7. Are you sure that your original executable wasn't built to thumb?

Try building with -mno-thumb and see if the code size increases.

Stephen Canon
  • 97,302
  • 18
  • 172
  • 256