Skip to contentSkip to conversation

arm64: Depend on newer binutils when building PAC

PATCH Superseded Mark Brown 2 participants 3 messages Jun 18, 2020 arm64

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 arm64: Depend on newer binutils when building PAC

Versions of binutils prior to 2.33.1 don't understand the ELF notes that are added by modern compilers to indicate the PAC and BTI options used to build the code. This causes them to emit large numbers of warnings in the form:

aarch64-linux-gnu-nm: warning: .tmp_vmlinux.kallsyms2: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0000000

during the kernel build.

In commit 15cd0e675f3f76b (arm64: Kconfig: ptrauth: Add binutils version check to fix mismatch) we added a dependency on binutils to avoid this issue when building with versions of GCC that emit the notes but did not do so for clang as it was believed that the existing check for .cfi_negate_ra_state was already requiring a new enough binutils. This does not appear to be the case for some versions of binutils (eg, the binutils in Debian 10) so add an explicit binutils version check for clang too.

---
 arch/arm64/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/Kconfig +1 -1
index 31380da53689..dd9d1bdee32a 100644
@@ -1521,7 +1521,7 @@ config ARM64_PTR_AUTH
 	# GCC 9.1 and later inserts a .note.gnu.property section note for PAC
 	# which is only understood by binutils starting with version 2.33.1.
 	depends on !CC_IS_GCC || GCC_VERSION < 90100 || LD_VERSION >= 233010000
-	depends on !CC_IS_CLANG || AS_HAS_CFI_NEGATE_RA_STATE
+	depends on !CC_IS_CLANG || AS_HAS_CFI_NEGATE_RA_STATE || LD_VERSION >= 233010000
 	depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
 	help
 	  Pointer authentication (part of the ARMv8.3 Extensions) provides
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw
Quoted 11 lines · Mark Brown

Versions of binutils prior to 2.33.1 don't understand the ELF notes that are added by modern compilers to indicate the PAC and BTI options used to build the code. This causes them to emit large numbers of warnings in the form:

aarch64-linux-gnu-nm: warning: .tmp_vmlinux.kallsyms2: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0000000

during the kernel build.

In commit 15cd0e675f3f76b (arm64: Kconfig: ptrauth: Add binutils version

Ah, thanks for the references. That's the exact error message we're observing. I know it's just a warning, but it's blowing up our KernelCI reports to the point where I'm not reading them for our clang-10 aarch64 builds, which is bad. Documentation/process/changes.rst mentions that the kernel support binutils 2.23+, so we should make sure to support those users.

Quoted 11 lines

check to fix mismatch) we added a dependency on binutils to avoid this issue when building with versions of GCC that emit the notes but did not do so for clang as it was believed that the existing check for .cfi_negate_ra_state was already requiring a new enough binutils. This does not appear to be the case for some versions of binutils (eg, the binutils in Debian 10) so add an explicit binutils version check for clang too.

Thanks for the patch. I'm curious about the case for LD=ld.lld, which we use on Android and CrOS.
I think this would be solved via an explicit line for the linker to check:
depends on CC_IS_LLD || LD_VERSION >= 233010000
Since we probably don't want to remove the check when using GCC?

Though, LD_VERSION is only a weak proxy for binutils version.

It's tricky right now for CC=clang builds because we still depend on GNU as from binutils. So you could do:

$ make CC=clang LD=ld.lld

which would be a problem since clang would emit the notes, and the Kconfig check against ld.lld would succeed, but then the binutils older than 2.33.1 would still choke. Would a script that checks $(AR) $(OBJCOPY) $(OBJDUMP) $(STRIP) $(NM) $(LD) support be overkill (feature test or version check)? See the Link above; we see warnings from all of those tools when binutils < 2.33.1. In that case, I'd even remove the check for AS_HAS_CFI_NEGATE_RA_STATE (err, maybe not, looking at commit 3b446c7d27dd ("arm64: Kconfig: verify binutils support for ARM64_PTR_AUTH") cites binutils 2.34. It would be good to support a build of just LLVM tools, or just GNU tools, but right now a lot of various builds that use clang are still a mix of various GNU binutil utilities. (See commit a0d1c951ef08 ("kbuild:
support LLVM=1 to switch the default tools to Clang/LLVM") for a view of what we're looking to use once we've burned down a few more bugs). This mixing and matching does slightly complicate support for new features that require extensive tooling support, but I think we can make it work for everyone.

We can credit KernelCI for this one, too.

(Also, general plea to please use scripts/get_maintainer.pl, which should cc our list for any patch mentioning clang or llvm; we may have caught this in code review before it hit mainline).

Quoted 20 lines
---
 arch/arm64/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/Kconfig +1 -2
index 31380da53689..dd9d1bdee32a 100644
@@ -1521,7 +1521,7 @@ config ARM64_PTR_AUTH
        # GCC 9.1 and later inserts a .note.gnu.property section note for PAC
        # which is only understood by binutils starting with version 2.33.1.
        depends on !CC_IS_GCC || GCC_VERSION < 90100 || LD_VERSION >= 233010000
-       depends on !CC_IS_CLANG || AS_HAS_CFI_NEGATE_RA_STATE
+       depends on !CC_IS_CLANG || AS_HAS_CFI_NEGATE_RA_STATE || LD_VERSION >= 233010000
        depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
        help
          Pointer authentication (part of the ARMv8.3 Extensions) provides
--

2.20.1

Signature · 7 lines
Thanks,
~Nick Desaulniers

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#2 lore raw
Quoted 4 lines · Nick Desaulniers

Thanks for the patch. I'm curious about the case for LD=ld.lld, which we use on Android and CrOS.
I think this would be solved via an explicit line for the linker to check:
depends on CC_IS_LLD || LD_VERSION >= 233010000

Ah, I see LD_IS_LLD is actually upstream now which complicates it - I managed to miss it when looking earlier (must've thought of the wrong name).

Quoted 1 line

Since we probably don't want to remove the check when using GCC?

Worse, with GCC we only want to check the binutils version if GCC is new enough to emit the notes so we need to make the binutils check. I think

	depends on LD_IS_LLD || LD_VERSION >= 233010000 || (CC_IS_GCC && GCC_VERSION < 90100)

in place of the existing GCC line covers it.

Quoted 10 lines

Though, LD_VERSION is only a weak proxy for binutils version.

It's tricky right now for CC=clang builds because we still depend on GNU as from binutils. So you could do:

$ make CC=clang LD=ld.lld

which would be a problem since clang would emit the notes, and the Kconfig check against ld.lld would succeed, but then the binutils older than 2.33.1 would still choke. Would a script that checks $(AR)

Oh, bother.

Quoted 11 lines

$(OBJCOPY) $(OBJDUMP) $(STRIP) $(NM) $(LD) support be overkill (feature test or version check)? See the Link above; we see warnings from all of those tools when binutils < 2.33.1. In that case, I'd even remove the check for AS_HAS_CFI_NEGATE_RA_STATE (err, maybe not, looking at commit 3b446c7d27dd ("arm64: Kconfig: verify binutils support for ARM64_PTR_AUTH") cites binutils 2.34. It would be good to support a build of just LLVM tools, or just GNU tools, but right now a lot of various builds that use clang are still a mix of various GNU binutil utilities. (See commit a0d1c951ef08 ("kbuild:
support LLVM=1 to switch the default tools to Clang/LLVM") for a view of what we're looking to use once we've burned down a few more bugs).

This is a mess. I think the most robust thing here is going to be to abandon version checks and do an end to end build check to see if the feature is supported, that's overhead but anything else is starting to look like nailing jelly to a wall.

Quoted 3 lines

This mixing and matching does slightly complicate support for new features that require extensive tooling support, but I think we can make it work for everyone.

Hopefully the learning curve with this will make things smoother in future.

Quoted 3 lines

(Also, general plea to please use scripts/get_maintainer.pl, which should cc our list for any patch mentioning clang or llvm; we may have caught this in code review before it hit mainline).

Especially for a file like Kconfig get_maintainer.pl is rather prone to false positives and negatives unfortunately :(

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel