# SPDX-License-Identifier: GPL-2.0-only
config CC_VERSION_TEXT
	string
	default "$(CC_VERSION_TEXT)"
	help
	  This is used in unclear ways:

	  - Re-run Kconfig when the compiler is updated
	    The 'default' property references the environment variable,
	    CC_VERSION_TEXT so it is recorded in include/config/auto.conf.cmd.
	    When the compiler is updated, Kconfig will be invoked.

	  - Ensure full rebuild when the compiler is updated
	    include/linux/compiler-version.h contains this option in the comment
	    line so fixdep adds include/config/CC_VERSION_TEXT into the
	    auto-generated dependency. When the compiler is updated, syncconfig
	    will touch it and then every file will be rebuilt.

config CC_IS_GCC
	def_bool $(success,test "$(cc-name)" = GCC)

config GCC_VERSION
	int
	default $(cc-version) if CC_IS_GCC
	default 0

config CC_IS_CLANG
	def_bool $(success,test "$(cc-name)" = Clang)

config CLANG_VERSION
	int
	default $(cc-version) if CC_IS_CLANG
	default 0

config AS_IS_GNU
	def_bool $(success,test "$(as-name)" = GNU)

config AS_IS_LLVM
	def_bool $(success,test "$(as-name)" = LLVM)

config AS_VERSION
	int
	# Use clang version if this is the integrated assembler
	default CLANG_VERSION if AS_IS_LLVM
	default $(as-version)

config LD_IS_BFD
	def_bool $(success,test "$(ld-name)" = BFD)

config LD_VERSION
	int
	default $(ld-version) if LD_IS_BFD
	default 0

config LD_IS_LLD
	def_bool $(success,test "$(ld-name)" = LLD)

config LLD_VERSION
	int
	default $(ld-version) if LD_IS_LLD
	default 0

config RUSTC_VERSION
	int
	default $(rustc-version)
	help
	  It does not depend on `RUST` since that one may need to use the version
	  in a `depends on`.

config RUST_IS_AVAILABLE
	def_bool $(success,$(srctree)/scripts/rust_is_available.sh)
	help
	  This shows whether a suitable Rust toolchain is available (found).

	  Please see Documentation/rust/quick-start.rst for instructions on how
	  to satisfy the build requirements of Rust support.

	  In particular, the Makefile target 'rustavailable' is useful to check
	  why the Rust toolchain is not being detected.

config RUSTC_LLVM_VERSION
	int
	default $(rustc-llvm-version)

config ARCH_HAS_CC_CAN_LINK
	bool

config CC_CAN_LINK
	bool
	default ARCH_CC_CAN_LINK if ARCH_HAS_CC_CAN_LINK
	default $(cc_can_link_user,$(m64-flag)) if 64BIT
	default $(cc_can_link_user,$(m32-flag))

# Fixed in GCC 14, 13.3, 12.4 and 11.5
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921
config GCC_ASM_GOTO_OUTPUT_BROKEN
	bool
	depends on CC_IS_GCC
	default y if GCC_VERSION < 110500
	default y if GCC_VERSION >= 120000 && GCC_VERSION < 120400
	default y if GCC_VERSION >= 130000 && GCC_VERSION < 130300

config CC_HAS_ASM_GOTO_OUTPUT
	def_bool y
	depends on !GCC_ASM_GOTO_OUTPUT_BROKEN
	# Detect basic support
	depends on $(success,echo 'int foo(int x) { asm goto ("": "=r"(x) ::: bar); return x; bar: return 0; }' | $(CC) -x c - -c -o /dev/null)
	# Detect clang (< v17) scoped label issues
	depends on $(success,echo 'void b(void **);void* c(void);int f(void){{asm goto(""::::l0);return 0;l0:return 1;}void *x __attribute__((cleanup(b)))=c();{asm goto(""::::l1);return 2;l1:return 3;}}' | $(CC) -x c - -c -o /dev/null)

config CC_HAS_ASM_GOTO_TIED_OUTPUT
	depends on CC_HAS_ASM_GOTO_OUTPUT
	# Detect buggy gcc and clang, fixed in gcc-11 clang-14.
	def_bool $(success,echo 'int foo(int *x) { asm goto (".long (%l[bar]) - .": "+m"(*x) ::: bar); return *x; bar: return 0; }' | $CC -x c - -c -o /dev/null)

config TOOLS_SUPPORT_RELR
	def_bool $(success,env "CC=$(CC)" "LD=$(LD)" "NM=$(NM)" "OBJCOPY=$(OBJCOPY)" $(srctree)/scripts/tools-support-relr.sh)

config CC_HAS_ASM_INLINE
	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)

config CC_HAS_ASSUME
	bool
	# clang needs to be at least 19.1.0 since the meaning of the assume
	# attribute changed:
	# https://github.com/llvm/llvm-project/commit/c44fa3e8a9a44c2e9a575768a3c185354b9f6c17
	default y if CC_IS_CLANG && CLANG_VERSION >= 190100
	# supported since gcc 13.1.0
	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106654
	default y if CC_IS_GCC && GCC_VERSION >= 130100

config CC_HAS_NO_PROFILE_FN_ATTR
	def_bool $(success,echo '__attribute__((no_profile_instrument_function)) int x();' | $(CC) -x c - -c -o /dev/null -Werror)

config CC_HAS_COUNTED_BY
	bool
	# clang needs to be at least 20.1.0 to avoid potential crashes
	# when building structures that contain __counted_by
	# https://github.com/ClangBuiltLinux/linux/issues/2114
	# https://github.com/llvm/llvm-project/commit/160fb1121cdf703c3ef5e61fb26c5659eb581489
	default y if CC_IS_CLANG && CLANG_VERSION >= 200100
	# supported since gcc 15.1.0
	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
	default y if CC_IS_GCC && GCC_VERSION >= 150100
