Skip to contentSkip to conversation

arm64: alternative: fix build with clang integrated assembler

PATCH In review Ilie Halip 3 participants 3 messages Mar 19, 2020 – Mar 20, 2020 arm64

lore
Share & tools
lore

Ilie Halip

author
#0 lore raw

PATCH 1/1 arm64: alternative: fix build with clang integrated assembler

Building an arm64 defconfig with clang's integrated assembler, this error occurs:

    <instantiation>:2:2: error: unrecognized instruction mnemonic
     _ASM_EXTABLE 9999b, 9f
     ^
    arch/arm64/mm/cache.S:50:1: note: while in macro instantiation
    user_alt 9f, "dc cvau, x4", "dc civac, x4", 0
    ^

While GNU as seems fine with case-sensitive macro instantiations, clang doesn't, so use the actual macro name (_asm_extable) as in the rest of the file.

Also checked that the generated assembly matches the GCC output.

Fixes 290622efc76e ("arm64: fix "dc cvau" cache operation on errata-affected core")
---
 arch/arm64/include/asm/alternative.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/alternative.h +1 -1
index 324e7d5ab37e..5e5dc05d63a0 100644
@@ -221,7 +221,7 @@ alternative_endif
 
 .macro user_alt, label, oldinstr, newinstr, cond
 9999:	alternative_insn "\oldinstr", "\newinstr", \cond
-	_ASM_EXTABLE 9999b, \label
+	_asm_extable 9999b, \label
 .endm
 
 /*
Signature · 1 line
2.17.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 28 lines · Ilie Halip

Building an arm64 defconfig with clang's integrated assembler, this error occurs:

    <instantiation>:2:2: error: unrecognized instruction mnemonic
     _ASM_EXTABLE 9999b, 9f
     ^
    arch/arm64/mm/cache.S:50:1: note: while in macro instantiation
    user_alt 9f, "dc cvau, x4", "dc civac, x4", 0
    ^

While GNU as seems fine with case-sensitive macro instantiations, clang doesn't, so use the actual macro name (_asm_extable) as in the rest of the file.

Also checked that the generated assembly matches the GCC output.

Fixes 290622efc76e ("arm64: fix "dc cvau" cache operation on errata-affected core")
---
 arch/arm64/include/asm/alternative.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/alternative.h +0 -0
index 324e7d5ab37e..5e5dc05d63a0 100644

arch/arm64/include/asm/alternative.h alternative_endif · line 225

Quoted 6 lines
arch/arm64/include/asm/alternative.h +1 -1
@@ -221,7 +221,7 @@ alternative_endif
 
 .macro user_alt, label, oldinstr, newinstr, cond
 9999:  alternative_insn "\oldinstr", "\newinstr", \cond
-       _ASM_EXTABLE 9999b, \label
+       _asm_extable 9999b, \label
 .endm

Testing a -next defconfig build, if I apply this, apply fixes for
https://github.com/ClangBuiltLinux/linux/issues/913, then disable CONFIG_KVM, I can assemble (with Clang's integrated assembler) and boot an aarch64 kernel. I think that's a first for Clang. Wow.

For CONFIG_KVM, I see:
arch/arm64/kvm/hyp/entry.S:112:87: error: too many positional arguments
alternative_insn nop, .inst (0xd500401f | ((0) << 16 | (4) << 5) |
((!!1) << 8)), 4, 1

               ^

which also uses alternative_insn, but not user_alt, so another bug for us to look into, filed:
https://github.com/ClangBuiltLinux/linux/issues/939

Looks like _asm_extable itself is a macro, defined in arch/arm64/include/asm/assembler.h on line 125. It's probably easy to fix this in clang, but from a consistency with the rest of the file (arch/arm64/include/asm/alternative.h) this patch should be accepted.

Should be easy to fix in Clang, too. Filed:
https://bugs.llvm.org/show_bug.cgi?id=45257
Thanks for the patch!

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#2 lore raw
Quoted 51 lines · Nick Desaulniers
Quoted 28 lines · Ilie Halip

Building an arm64 defconfig with clang's integrated assembler, this error occurs:

    <instantiation>:2:2: error: unrecognized instruction mnemonic
     _ASM_EXTABLE 9999b, 9f
     ^
    arch/arm64/mm/cache.S:50:1: note: while in macro instantiation
    user_alt 9f, "dc cvau, x4", "dc civac, x4", 0
    ^

While GNU as seems fine with case-sensitive macro instantiations, clang doesn't, so use the actual macro name (_asm_extable) as in the rest of the file.

Also checked that the generated assembly matches the GCC output.

Fixes 290622efc76e ("arm64: fix "dc cvau" cache operation on errata-affected core")
---
 arch/arm64/include/asm/alternative.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/alternative.h +0 -0
index 324e7d5ab37e..5e5dc05d63a0 100644

arch/arm64/include/asm/alternative.h alternative_endif · line 225

Quoted 6 lines
arch/arm64/include/asm/alternative.h +1 -1
@@ -221,7 +221,7 @@ alternative_endif
 
 .macro user_alt, label, oldinstr, newinstr, cond
 9999:  alternative_insn "\oldinstr", "\newinstr", \cond
-       _ASM_EXTABLE 9999b, \label
+       _asm_extable 9999b, \label
 .endm

Testing a -next defconfig build, if I apply this, apply fixes for
https://github.com/ClangBuiltLinux/linux/issues/913, then disable CONFIG_KVM, I can assemble (with Clang's integrated assembler) and boot an aarch64 kernel. I think that's a first for Clang. Wow.

For CONFIG_KVM, I see:
arch/arm64/kvm/hyp/entry.S:112:87: error: too many positional arguments
alternative_insn nop, .inst (0xd500401f | ((0) << 16 | (4) << 5) |
((!!1) << 8)), 4, 1

               ^

which also uses alternative_insn, but not user_alt, so another bug for us to look into, filed:
https://github.com/ClangBuiltLinux/linux/issues/939

Quoted 7 lines

Looks like _asm_extable itself is a macro, defined in arch/arm64/include/asm/assembler.h on line 125. It's probably easy to fix this in clang, but from a consistency with the rest of the file (arch/arm64/include/asm/alternative.h) this patch should be accepted.

Thanks, I'll pick this up as a fix.

Will