Subject: [PATCH 16/29] kbuild: Add support for 'as-instr' to be used in Kconfig files

From: Catalin Marinas <[email-masked]>
Date: Wed, 15 Jan 2020 11:30:07 +0000

commit 42d519e3d0c071161d0a1c36e95a3743b113c590 upstream.

Similar to 'cc-option' or 'ld-option', it is occasionally necessary to
check whether the assembler supports certain ISA extensions. In the
arm64 code we currently do this in Makefile with an additional define:

lseinstr := $(call as-instr,.arch_extension lse,-DCONFIG_AS_LSE=1)

Add the 'as-instr' option so that it can be used in Kconfig directly:

	def_bool $(as-instr,.arch_extension lse)

Acked-by: Masahiro Yamada <[email-masked]>
Reviewed-by: Vladimir Murzin <[email-masked]>
Tested-by: Vladimir Murzin <[email-masked]>
Signed-off-by: Catalin Marinas <[email-masked]>
Signed-off-by: Will Deacon <[email-masked]>
Signed-off-by: Nick Desaulniers <[email-masked]>
---
 scripts/Kconfig.include | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index 79455ad6b386..b762e02c0c31 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -26,5 +26,16 @@ cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /de
 # Return y if the linker supports <flag>, n otherwise
 ld-option = $(success,$(LD) -v $(1))
 
+# $(as-instr,<instr>)
+# Return y if the assembler supports <instr>, n otherwise
+as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
+
+# check if $(CC) and $(LD) exist
+$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
+$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
+
+# Fail if the linker is gold as it's not capable of linking the kernel proper
+$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
+
 # gcc version including patch level
 gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//')
-- 
2.31.0.rc2.261.g7f71774620-goog