4

I am trying to mix ARM and THUMB instructions in my assembly code. For example, in the following code I try to use both modes:

.thumb  @ .code 16
.section __TEXT,__text
.globl mySymbol1
mySymbol1:
 ....
.arm   @ .code 32
.section __TEXT,__text
.globl mySymbol2
mySymbol2:
...

Now, as per my understanding when I compile this code into a library and run it through nm, mysymbol1 should show up as arm and mysymbol2 should show up as thumb, i.e,

0000xxxx (__TEXT,__text) external mySymbol1
0000yyyy (__TEXT,__text) external [Thumb] mySymbol2

But both are showing up as arm. What am I missing here? My assembler command is:

as -arch armv7 -o a.o a.s
user1165084
  • 97
  • 2
  • 7

1 Answers1

4

you need .thumb_func before the thumb labels for them to be thumb targets otherwise the gnu tools will treat it as an arm target. (yes you need the .thumb once AND .thumb_func for EVERY label you want to use as a thumb target). Many examples http://github.com/dwelch67

old_timer
  • 69,149
  • 8
  • 89
  • 168
  • Thanks, that did it. Do you know why this is so? Also can a thumb target not be a function? What would happen then? – user1165084 Jul 20 '12 at 08:54
  • 3
    Yes, the branch exchange (BX) is used to switch modes, among a few other places, the lsbit of the address indicates to the logic whether that address is a thumb address or arm address, indicating a mode switch or stay the same. In order to get the gnu assembler to produce the right address, allthough silly as gas knows the mode already you have to use thumb_func. I call it a bug, but whatever it is what it is. Other tools no doubt have their own nuances. (gas likes to mess up assembly language wherever it can not just arm) – old_timer Jul 20 '12 at 13:48
  • getting the gnu tools to go both ways is possible, one way is easier than another, there is a long answer I gave to someone else on this topic plus some examples, would have to search so for this. there is a command line switch you tell the gnu tools to be prepared for going back and forth between modes. despite the almost constant arm programming I do I rarely need it so I dont have it memorized. – old_timer Jul 20 '12 at 13:50