From patchwork Wed Jan 28 19:17:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 43884 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 11C622410D for ; Wed, 28 Jan 2015 19:19:54 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id k14sf12020900wgh.3 for ; Wed, 28 Jan 2015 11:19:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=K690ZcFa8loeMwIPModK9KuauAMoZz0c5tm4v7WhBFU=; b=MQuYKESbK6XLu6akh6p7yP79WzKFkHifb2R/su6LA4dYJenFNBexUSsYWICGW0fHTg JIHyX0cUxpPRjDIJ2WrdkyB1yHS4dr2Zm9pzhwNe9hyAGfvrfceDEE0xvCfCx7Obd7FO BWVr2SbAotRUmjHRdOqj4MaymRdkxsBfMO5G/WerJYIzFW8QYR5LHq1WgroIPTntTunR /fp5TW69lA50IZncAnFgCCoYu/5pB6pwxxbPPTKuI7B9tz1MtMIpWgcD3ndKup2sWlpY /5wK8yMdzTTpctvrtFk27xmpRjVTdGWdoyMmroOMvMMnIAXuf1Fdv6v7SKjw5BH/jHX9 zgbQ== X-Gm-Message-State: ALoCoQmEjRbYJVGe6M60nWOvEqlmSqCE2vwwRZtpQPSUWLg8fMDl4fSfSAL1dzrTymwtzk4y5+Ng X-Received: by 10.112.167.166 with SMTP id zp6mr486550lbb.5.1422472793265; Wed, 28 Jan 2015 11:19:53 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.99 with SMTP id 3ls216374lat.107.gmail; Wed, 28 Jan 2015 11:19:53 -0800 (PST) X-Received: by 10.152.244.163 with SMTP id xh3mr10408336lac.25.1422472793126; Wed, 28 Jan 2015 11:19:53 -0800 (PST) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id ld8si998127lac.86.2015.01.28.11.19.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 28 Jan 2015 11:19:52 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id q1so20941042lam.2 for ; Wed, 28 Jan 2015 11:19:52 -0800 (PST) X-Received: by 10.112.41.234 with SMTP id i10mr10473704lbl.25.1422472792641; Wed, 28 Jan 2015 11:19:52 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1538912lbj; Wed, 28 Jan 2015 11:19:51 -0800 (PST) X-Received: by 10.68.94.69 with SMTP id da5mr7983759pbb.99.1422472790728; Wed, 28 Jan 2015 11:19:50 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id u3si6869493pdl.168.2015.01.28.11.19.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jan 2015 11:19:50 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YGY84-00073Z-Es; Wed, 28 Jan 2015 19:18:20 +0000 Received: from mail-ie0-f173.google.com ([209.85.223.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YGY80-0006vU-Or for linux-arm-kernel@lists.infradead.org; Wed, 28 Jan 2015 19:18:17 +0000 Received: by mail-ie0-f173.google.com with SMTP id tr6so23839009ieb.4 for ; Wed, 28 Jan 2015 11:17:52 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.42.71.194 with SMTP id l2mr4649129icj.71.1422472671652; Wed, 28 Jan 2015 11:17:51 -0800 (PST) Received: by 10.36.56.77 with HTTP; Wed, 28 Jan 2015 11:17:51 -0800 (PST) In-Reply-To: References: <1422422306-27473-1-git-send-email-behanw@converseincode.com> <54C8EE04.6060809@linaro.org> <54C91791.9030508@linaro.org> Date: Wed, 28 Jan 2015 19:17:51 +0000 Message-ID: Subject: Re: [PATCH] bcm: address clang inline asm incompatibility From: Ard Biesheuvel To: Alex Elder X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150128_111816_851555_8590E5DE X-CRM114-Status: GOOD ( 20.57 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.223.173 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.223.173 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record Cc: Florian Fainelli , Russell King - ARM Linux , bcm@fixthebug.org, "linux-kernel@vger.kernel.org" , Matt Porter , bcm-kernel-feedback-list@broadcom.com, "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 On 28 January 2015 at 17:20, Ard Biesheuvel wrote: > On 28 January 2015 at 17:08, Alex Elder wrote: >> On 01/28/2015 10:17 AM, Ard Biesheuvel wrote: >>> On 28 January 2015 at 14:11, Alex Elder wrote: >>>> On 01/28/2015 05:15 AM, Ard Biesheuvel wrote: >>>>> On 28 January 2015 at 05:18, Behan Webster wrote: >>>>>> From: Alex Elder >>>>>> >>>>>> 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 >>>>>> Signed-off-by: Behan Webster >>>>>> --- >>>>>> 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? -------->8---------- -------->8---------- diff --git a/arch/arm/include/asm/compiler.h b/arch/arm/include/asm/compiler.h index 8155db2f7fa1..f99c674b3751 100644 --- a/arch/arm/include/asm/compiler.h +++ b/arch/arm/include/asm/compiler.h @@ -9,7 +9,8 @@ * will cause compilation to stop on mismatch. * (for details, see gcc PR 15089) */ -#define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t" +#define __asmeq(x, y) ".ifnc " x "," y " ; .ifnc " x y ",ipr12 ; " \ + ".ifnc " x y ",r12ip ; .err ; .endif ; .endif ; .endif\n\t" #endif /* __ASM_ARM_COMPILER_H */