ARM inline assembly usage in Linux kernel

Ramana Radhakrishnan ramana.gcc@googlemail.com
Thu Feb 20 10:11:00 GMT 2014


On Wed, Feb 19, 2014 at 11:19 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> On Wed, Feb 19, 2014 at 3:17 PM, Renato Golin <renato.golin@linaro.org> wrote:
>> On 19 February 2014 11:58, Richard Sandiford
>> <rsandifo@linux.vnet.ibm.com> wrote:
>>> I agree that having an unrecognised asm shouldn't be a hard error until
>>> assembly time though.  Saleem, is the problem that this is being rejected
>>> earlier?
>>
>> Hi Andrew, Richard,
>>
>> Thanks for your reviews! We agree that we should actually just ignore
>> the contents until object emission.
>>
>> Just for context, one of the reasons why we enabled inline assembly
>> checks is for some obscure cases when the snippet changes the
>> instructions set (arm -> thumb) and the rest of the function becomes
>> garbage.

The current behaviour is that when the compiler generates code for
Thumb1 and Thumb2 we switch back to the appropriate state after inline
assembler is emitted. We don't switch back to ARM state on the (fairly
robust) assumption that most inline assembler is written in ARM state.

In any case when users are switching ARM and Thumb states, they need
to be careful anyway to make sure that the *machine* is going to get
back to the *correct* state and having a screen full of possibly
meaningless compile time errors may not be the most productive. FTR
this is to be the motivation behind such a change based on a
conversation with rearnsha.


>> Our initial implementation was to always emit .arm/.thumb
>> after *any* inline assembly, which would become a nop in the worst
>> case. But since we had easy access to the assembler, we thought: "why
>> not?".

.arm / .thumb directives should not assemble to any instruction least
of all nop. You mean ignored here :).

>
> With the unified assembly format, you should not need those
> .arm/.thumb and in fact emitting them can make things even worse.

Why ? Care to explain when and how it is worse ?

UAL makes no reference to the actual assembler directives required
which is (assembler) implementation dependent. It is purely a grammar
for the instructions in the assembly language and doesn't attempt to
standardize assembler directives which would have evolved differently
over time and different assemblers. How do you otherwise tell the
assembler whether to assemble for ARM state or Thumb instructions ?

regards
Ramana


>
> Thanks,
> Andrew Pinski
>
>
>>
>> The idea is now to try to parse the snippet for cases like .arm/.thumb
>> but only emit a warning IFF -Wbad-inline-asm (or whatever) is set (and
>> not to make it on by default), otherwise, ignore. We're hoping our
>> assembler will be able to cope with the multiple levels of indirection
>> automagically. ;)
>>
>> Thanks again!
>> --renato



More information about the Gcc mailing list