Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM Thumb mode: Code Size not decreasing

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
....
....
like image 471
HaggarTheHorrible Avatar asked Nov 05 '10 15:11

HaggarTheHorrible


People also ask

What is Thumb mode in ARM processor?

Thumb code is typically 65% of the size of ARM code, and provides 160% of the performance of ARM code when running from a 16-bit memory system. Thumb, therefore, makes the ARM7TDMI core ideally suited to embedded applications with restricted memory bandwidth, where code density and footprint is important.

How is switching between ARM and Thumb state done?

To direct the assembler to generate ARM or Thumb instruction encodings, you must set the assembler mode using an ARM or THUMB directive. To generate ThumbEE code, use the THUMBX directive. Assembly code using CODE32 and CODE16 directives can still be assembled, but ARM recommends using ARM and THUMB for new code.

What are the registers available to thumb?

Notice that the 12 registers accessible in Thumb state are exactly the same physical 32-bit registers accessible in ARM state. Thus data can be passed between software running in the ARM state and software running in the Thumb state via registers R0 through R7. This is done frequently in actual applications.


2 Answers

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

like image 98
old_timer Avatar answered Sep 18 '22 12:09

old_timer


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.
like image 43
Igor Skochinsky Avatar answered Sep 19 '22 12:09

Igor Skochinsky