linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] bcm: address clang inline asm incompatibility
Date: Wed, 28 Jan 2015 19:38:17 +0000	[thread overview]
Message-ID: <CAKv+Gu88G2QqAupD9j4_-t2=0VJGNbWkUViLBM2nUuyuN-PHWA@mail.gmail.com> (raw)
In-Reply-To: <54C9383D.10901@linaro.org>

On 28 January 2015 at 19:27, Alex Elder <elder@linaro.org> wrote:
> On 01/28/2015 01:17 PM, Ard Biesheuvel wrote:
>> On 28 January 2015 at 17:20, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>>> On 28 January 2015 at 17:08, Alex Elder <elder@linaro.org> wrote:
>>>> On 01/28/2015 10:17 AM, Ard Biesheuvel wrote:
>>>>> On 28 January 2015 at 14:11, Alex Elder <elder@linaro.org> wrote:
>>>>>> On 01/28/2015 05:15 AM, Ard Biesheuvel wrote:
>>>>>>> On 28 January 2015 at 05:18, Behan Webster <behanw@converseincode.com> wrote:
>>>>>>>> From: Alex Elder <elder@linaro.org>
>>>>>>>>
>>>>>>>> My GCC-based build environment likes to call register r12 by the
>>>>>>>> name "ip" in inline asm.  Behan Webster informed me that his Clang-
>>>>>>>> based build environment likes "r12" instead.
>>>>>>>>
>>>>>>>> Try to make them both happy.
>>>>>>>>
>>>>>>>> Signed-off-by: Alex Elder <elder@linaro.org>
>>>>>>>> Signed-off-by: Behan Webster <behanw@converseincode.com>
>>>>>>>> ---
>>>>>>>>  arch/arm/mach-bcm/bcm_kona_smc.c | 9 +++++++--
>>>>>>>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>>>>>>>
>>>>>>>> diff --git a/arch/arm/mach-bcm/bcm_kona_smc.c b/arch/arm/mach-bcm/bcm_kona_smc.c
>>>>>>>> index a55a7ec..3937bd5 100644
>>>>>>>> --- a/arch/arm/mach-bcm/bcm_kona_smc.c
>>>>>>>> +++ b/arch/arm/mach-bcm/bcm_kona_smc.c
>>>>>>>> @@ -106,9 +106,14 @@ int __init bcm_kona_smc_init(void)
>>>>>>>>   * request result appropriately.  This result value is found in r0
>>>>>>>>   * when the "smc" request completes.
>>>>>>>>   */
>>>>>>>> +#ifdef __clang__
>>>>>>>> +#define R12    "r12"
>>>>>>>> +#else  /* !__clang__ */
>>>>>>>> +#define R12    "ip"    /* gcc calls r12 "ip" */
>>>>>>>> +#endif /* !__clang__ */
>>>>>>>
>>>>>>> Why not just use r12 for both?
>>>>>>
>>>>>> Yes, that would have been an obvious fix.  But the
>>>>>> assembler (in the GCC environment) doesn't accept that.
>>>>>>
>>>>>
>>>>> Mine has no problems with it at all
>>>>>
>>>>> $ echo 'mov r12, #0' | arm-linux-gnueabihf-gcc -c -x assembler-with-cpp -
>>>>>
>>>>> and grepping for r12 under arch/arm suggests the same
>>>>
>>>> The use of "r12" is fine.  But it's not just the assembler,
>>>> I believe it also involves gcc.
>>>>
>>>> The problem is with the use of the __asmeq(x, y) macro.
>>>>
>>>
>>> Ah right. Apologies for assuming that you had missed something obvious here.
>>> But __asmeq is not the toolchain, it is a local construct #define'd in
>>> compiler.h
>>>
>>>> If I assign the "ip" variable with "r12":
>>>>         register u32 ip asm("r12");     /* Also called ip */
>>>>
>>>> Then that's fine.  However, this line then causes an error:
>>>>                 __asmeq("%0", "r12")
>>>>
>>>> Apparently gcc uses register "ip" when it sees asm("r12").  So
>>>> attempting to verify the desired register got used with __asmeq()
>>>> causes a string mismatch--"ip" is not equal to "r12".
>>>>
>>>> So I could use:
>>>>
>>>>         register u32 ip asm("r12");     /* Also called ip */
>>>>                 ...
>>>>                 __asmeq("%0", "ip")
>>>>
>>>> And that will build.  But it's a little non-intuitive, and
>>>> I suspect that clang might (rightfully) have a failure in
>>>> this __asmeq() call.
>>>>
>>>
>>> In that case, I would strongly suggest fixing the __asmeq () macro
>>> instead, and teach it that ("r12","ip") and ("ip","r12") are fine too.
>>>
>>> The thing is, inline asm is a dodgy area to begin with in terms of
>>> clang-to-gcc compatibility. On arm64, we have been seeing issues where
>>> the width of the register -which is fixed on gcc- is selected based on
>>> the size of that variable, i.e., an int32 gets a w# register and int64
>>> gets a x# register. Imagine debugging that, e.g., a str %0, [xx] that
>>> writes 8 bytes on GCC suddenly only writing 4 bytes when built with
>>> clang.
>>>
>>> If we also start using the preprocessor to conditionalise what is
>>> emitted by inline asm, the waters get even murkier and it becomes even
>>> harder to claim parity between the two.
>>>
>>
>> Something like this perhaps?
>
> So __asmeq() yields true if the register names (strings) are
> equal, or if one is "ip" and the other is "r12" (in either order).
>
> I can't comment on whether it's right in all build environments but
> this looks OK to me, to handle this special case.
>
> I would much rather you generate that patch.  Is that OK?
>

Sure, I can cook up a patch if you guys can confirm that it fixes your
use case. (I tested GCC myself but I don't have clang installed)

-- 
Ard.

  reply	other threads:[~2015-01-28 19:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-28  5:18 [PATCH] bcm: address clang inline asm incompatibility Behan Webster
2015-01-28 11:15 ` Ard Biesheuvel
2015-01-28 14:11   ` Alex Elder
2015-01-28 16:17     ` Ard Biesheuvel
2015-01-28 17:08       ` Alex Elder
2015-01-28 17:20         ` Ard Biesheuvel
2015-01-28 19:17           ` Ard Biesheuvel
2015-01-28 19:27             ` Alex Elder
2015-01-28 19:38               ` Ard Biesheuvel [this message]
2015-01-28 20:11                 ` Ard Biesheuvel
2015-01-28 20:15                   ` Alex Elder
2015-01-28 21:18                   ` Behan Webster
2015-01-28 21:07                 ` Behan Webster
2015-01-28 19:30             ` Behan Webster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKv+Gu88G2QqAupD9j4_-t2=0VJGNbWkUViLBM2nUuyuN-PHWA@mail.gmail.com' \
    --to=ard.biesheuvel@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).