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

Jim Grosbach grosbach at apple.com
Thu Jul 24 18:06:06 PDT 2014


They don't default to thumb. Not sure what they do with an explicit -mthumb which is the closest analogy. 

> On Jul 24, 2014, at 5:29 PM, Eric Christopher <echristo at gmail.com> wrote:
> 
>> On Thu, Jul 24, 2014 at 5:27 PM, Jim Grosbach <grosbach at apple.com> wrote:
>> For the assembler, there’s no concept of that. It always starts in ARM mode. Even for the compiler, the defaulting to thumb mode for armv7 is a darwin only thing, I think. Used to be, anyway.
>> 
>> From another point of view, it also keeps us more compatible with other tools like gas.
> 
> o.O
> 
> Does gcc emit a .code16 for file level inline assembly when compiling
> with -mthumb?
> 
> -eric
> 
>> -Jim
>> 
>> 
>>> On Jul 24, 2014, at 5:24 PM, Eric Christopher <echristo at gmail.com> wrote:
>>> 
>>> Why not just start the assembler in the right mode for the target
>>> we're assembling?
>>> 
>>> -eric
>>> 
>>>> On Thu, Jul 24, 2014 at 5:19 PM, Jim Grosbach <grosbach at apple.com> wrote:
>>>> Hi Akira,
>>>> 
>>>> Patch LGTM. The testcase should also run with ARM (a second RUN line w/ a
>>>> distinct check prefix) w/ check lines there to verify we don’t emit the
>>>> “.code 16” then.
>>>> 
>>>> -Jim
>>>> 
>>>> On Jul 24, 2014, at 3:02 PM, Akira Hatanaka <ahatanak at gmail.com> wrote:
>>>> 
>>>> ToT clang (correctly) errors-out when the target is armv7 (thumb2) and the
>>>> program it's compiling has an ARM mode file-level inline assembly statement:
>>>> 
>>>> $ cat test2.c
>>>> 
>>>> __asm__ ("stmib sp, {r0-r14};");
>>>> 
>>>> $ clang -arch armv7  -S -o - test2.c
>>>> .section __TEXT,__text,regular,pure_instructions
>>>> .ios_version_min 5, 0
>>>> .section __TEXT,__textcoal_nt,coalesced,pure_instructions
>>>> .section __TEXT,__const_coal,coalesced
>>>> .section __TEXT,__picsymbolstub4,symbol_stubs,none,16
>>>> .section __TEXT,__StaticInit,regular,pure_instructions
>>>> .section __TEXT,__cstring,cstring_literals
>>>> .syntax unified
>>>>                                       @ Start of file scope inline
>>>> assembly
>>>> <inline asm>:1:1: error: instruction requires: arm-mode
>>>> stmib sp, {r0-r14};
>>>> 
>>>> However, when the .s file is generated with -no-integrated-as first, and
>>>> then assembled later, clang completes assembling the .s file without any
>>>> errors.
>>>> 
>>>> $ clang -arch armv7  -S -o test2.s -no-integrated-as test2.c
>>>> $ clang -arch armv7  test2.s -c
>>>> 
>>>> The attached patch fixes this discrepancy in clang's behavior by emitting
>>>> directive ".code 16" before global inline-asm instructions when the target
>>>> is thumb. Without this directive, clang assembles the global inline-asm
>>>> instruction in ARM mode, since the assembler always starts in ARM mode and
>>>> stays in that mode until it sees directives that instruct it to switch to
>>>> thumb.
>>>> 
>>>> <rdar://problem/17757232>
>>>> 
>>>> <code16.patch>_______________________________________________
>>>> llvm-commits mailing list
>>>> llvm-commits at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> llvm-commits mailing list
>>>> llvm-commits at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>> 




More information about the llvm-commits mailing list