[PATCH] ARM: Emit ".code 16" before global inline-asm instructions in thumb mode

Jim Grosbach grosbach at apple.com
Fri Jul 25 09:54:24 PDT 2014


> On Jul 25, 2014, at 1:32 AM, Renato Golin <renato.golin at linaro.org> wrote:
> 
> On 25 July 2014 01:29, Eric Christopher <echristo at gmail.com> wrote:
>> Does gcc emit a .code16 for file level inline assembly when compiling
>> with -mthumb?
> 
> Yes, the patch is in line with GCC's behaviour, and I honestly thought
> we were doing this, already... :/

We are, sorta. We’re correctly emitting the directive after the module assembly, just not before it.

> 
> We could do better, however, because we do parse and validate inline
> assembly. We should be able to tell if the snippet contains ARM/Thumb
> code or any .code modifiers, and thus only change after the inline asm
> if really needed.
> 

That’s not going to be 100% reliable as there are many mnemonics valid in both. For example, what do you do for “_foo: bx lr”? I prefer the simple and easy to explain answer this patch implements.


> Saleem, I remember you had a look at that, didn't you have a working prototype?
> 
> For now, the patch looks good and would be perfect for 99% of the
> cases and mostly harmless for the rest. The only problem is if the
> code was in ARM mode, with Thumb code in the snippet changed via
> .code16, and the user forgot to change it back to ARM before the end
> of the snippet. But that's advanced user stupidity detection, and is
> an enhancement at best.
> 

There already is a .code16 emitted before any thumb functions, so I think we’re OK here. There might be something if there’s multiple module asm blocks that don’t play nicely with one another, but I agree that’s a corner case we don’t have to sort out now.

> Thanks for spotting that!
> 
> cheers,
> --renato





More information about the llvm-commits mailing list