New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 824526 link

Starred by 2 users

Issue metadata

Status: Verified
Owner:
Closed: Apr 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug
Build-Toolchain



Sign in to add a comment

clang: arm64: support rN register names

Project Member Reported by mka@chromium.org, Mar 21 2018

Issue description

The upstream kernel commit f2d3b2e8759a ("arm/arm64: smccc: Implement SMCCC v1.1 inline primitive") 
 (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f2d3b2e8759a5833df6f022e42df2d581e6d843c) uses the names "r0", "r1", ... for the general purpose registers that are usually known as "x0", "x1", ...

Use of the rN register names for arm64 is supported by gcc, but not by clang, in consequence upstream kernels and v4.14 (LTS/CrOS) currently don't build with clang for arm64.

Kernel maintainers don't seem to be inclined to use the xN names, probably also because the code in question is shared between arm64 and arm32, and arm32 registers are named rN.

"I'd say this is really a bug in Clang. Architecturally, the register in AArch64 state is still named "r0"; "x0"/"w0" are assembler operands which additionally encode the size of the corresponding *access* to r0."

https://lkml.org/lkml/2018/3/1/186

Maintainers might accept a fix, but expect LLVM to work on supporting rN register names for arm64 in future releases:

"It would be preferable to see evidence of the llvm community committing to fix this before we consider merging a bodge into Linux for it."
 
Luis, can you talk with ARM regarding this in the next meeting?
Btw, I do have a patch to address it.

Comment 3 by mka@chromium.org, Mar 21 2018

#2: Great, thanks! Please let me know when it is uploaded for upstream LLVM review, then we can use it to convince kernel folks that a LLVM fix is underway.
mka@, A counter example for GCC was just posted on the llvm bug
https://bugs.llvm.org/show_bug.cgi?id=36862

int function(void)
{
    asm("mov r0,r0\n");
    return 0;
}

Error: operand 1 should be an integer register -- 'mov r0,r0'

Maybe this is enough to counter that GCC supports "r" registers in all cases?
Hmm, gcc 6.3 and 7.2 actually supports the above example.

Comment 6 by mka@chromium.org, Mar 22 2018

From https://bugs.llvm.org/show_bug.cgi?id=36862 :

"From the kernel patch it looks like that this is only being used in restricted cases, for example register constraints. Do you have a list of what can and can't be given as "r"?"

For this bug it should indeed be sufficient to supports rN for register constraints, not sure if rN could be used in other contexts in the future though.

Probably best to check with ARM folks, if you want I can loop you in to the kernel thread where 3 ARM employees participated. Or you can reach out privately: Robin Murphy <robin.murphy@arm.com>, Dave Martin <Dave.Martin@arm.com>, Marc Zyngier <marc.zyngier@arm.com>

Comment 7 Deleted

Sent the patch at https://reviews.llvm.org/D44815
Project Member

Comment 9 by bugdroid1@chromium.org, Apr 3 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/ef4b52b72f55d62765eccd091446f754221cb264

commit ef4b52b72f55d62765eccd091446f754221cb264
Author: Manoj Gupta <manojgupta@google.com>
Date: Tue Apr 03 08:29:15 2018

llvm: Cherry-pick clang for parsing rN registers in AArch64.

CL summary:
Author:     Manoj Gupta <manojgupta@google.com>

    [AArch64]: Add support for parsing rN registers.

    Summary:
    Allow rN registers to be simply parsed as correspoing xN registers.
    The "register ... asm("rN")" is an command to the
    compiler's register allocator, not an operand to any individual assembly
    instruction. GCC documents this syntax as "...the name of the register
    that should be used."

    This is needed to support the changes in Linux kernel (see
    https://lkml.org/lkml/2018/3/1/268 )

BUG= chromium:824526 
TEST=sudo emerge llvm works.

Change-Id: I159b98e51f38e782daa6941650b292ba40125450
Reviewed-on: https://chromium-review.googlesource.com/990583
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Ting-Yuan Huang <laszio@chromium.org>

[rename] https://crrev.com/ef4b52b72f55d62765eccd091446f754221cb264/sys-devel/llvm/llvm-7.0_pre326829_p20180318-r6.ebuild
[add] https://crrev.com/ef4b52b72f55d62765eccd091446f754221cb264/sys-devel/llvm/files/cherry/8c8aea3ce916068052d4e4029f6878d8d7dd53da.patch

Matthias, I have cherry-picked the upstream  patch to Chrome OS clang. Is it possible for you to test the upstream ARM64 kernel with it?

Running "sudo emerge llvm" should pull in the new llvm (version llvm-7.0_pre326829_p20180318-r6).

Comment 11 by mka@chromium.org, Apr 3 2018

Status: Verified (was: Assigned)
upstream ToT and CrOS v4.14 build with the latest LLVM. Thanks!
Thanks Manoj for implementing this! :D

Sign in to add a comment