# Re: \[PATCH\] arm64: Kconfig: verify binutils support for ARM64\_PTR\_AUTH

- From: Nathan Chancellor \<hidden\>
- Date: 2020-03-19 18:35:48 
- List: linux-arm-kernel
- Page: https://ratatoskr.run/linux-arm-kernel/2020/03/8792249
- Thread: https://ratatoskr.run/linux-arm-kernel/2020/03/8792017/t.md

```text
On Thu, Mar 19, 2020 at 11:19:51AM -0700, 'Nick Desaulniers' via Clang Built Linux wrote:
> Clang relies on GNU as from binutils to assemble the Linux kernel,
> currently. A recent patch to enable the armv8.3-a extension for pointer
> authentication checked for compiler support of the relevant flags.
> Everything works with binutils 2.34+, but for older versions we observe
> assembler errors:
> 
> /tmp/vgettimeofday-36a54b.s: Assembler messages:
> /tmp/vgettimeofday-36a54b.s:40: Error: unknown pseudo-op: `.cfi_negate_ra_state'
> 
> When compiling with Clang, require the assembler to support
> .cfi_negate_ra_state directives, in order to support CONFIG_ARM64_PTR_AUTH.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/938
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> Tested with binutils 2.33.1 and ToT. Boot tested in QEMU.
> I added this requirement only for Clang.
> 
> GCC maybe doesn't produce these assembler directives, or looks like GCC
> 8.2 produces .cfi_window_save (https://godbolt.org/z/awZWZ5, godbolt
> doesn't have a newer aarch64-linux-gnu-gcc...) instead of
> .cfi_negate_ra_state. Maybe ARM can sort out the inconsistency between
> compilers?
> 
> If we plan to add .cfi_negate_ra_state to out of
> line assembly, we may want to make AS_HAS_CFI_NEGATE_RA_STATE a hard
> requirement, regardless of compiler.
> 
> Also, rather than CC_IS_GCC, we could do !CC_IS_CLANG || ...
> 
> 
>  arch/arm64/Kconfig | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index b889d7956abf..1ee1d8fab218 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -1506,6 +1506,7 @@ config ARM64_PTR_AUTH
>  	default y
>  	depends on !KVM || ARM64_VHE
>  	depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC
> +	depends on CC_IS_GCC || (CC_IS_CLANG && AS_HAS_CFI_NEGATE_RA_STATE)
>  	depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
>  	help
>  	  Pointer authentication (part of the ARMv8.3 Extensions) provides
> @@ -1550,6 +1551,9 @@ config CC_HAS_SIGN_RETURN_ADDRESS
>  config AS_HAS_PAC
>  	def_bool $(as-option,-Wa$(comma)-march=armv8.3-a)
>  
> +config AS_HAS_CFI_NEGATE_RA_STATE
> +	def_bool $(as-instr,.cfi_startproc\n.cfi_negate_ra_state\n.cfi_endproc\n)
> +
>  endmenu
>  
>  menu "ARMv8.4 architectural features"
> -- 
> 2.25.1.696.g5e7596f4ac-goog
> 

It would be nice to make this kind of check work for both GCC and Clang
but like you noted, there appears to be inconsistencies between them so
something for another day. CONFIG_ARM64_PTR_AUTH is getting a little
gnarly in terms of dependencies but I suppose that makes sense given its
nature. I verified that AS_HAS_CFI_NEGATE_RA_STATE gets set with ToT
binutils and that it does not with an older version.

Reviewed-by: Nathan Chancellor <redacted>
Tested-by: Nathan Chancellor <redacted>

This unlocks our CI so hopefully it can get picked up quickly.

https://travis-ci.com/github/ClangBuiltLinux/continuous-integration/jobs/299816618

Cheers,
Nathan

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
```
