xref: /linux/scripts/Kconfig.toolchain (revision bb29b957eaaa15be33243550d9ee576c2d601669)
1# SPDX-License-Identifier: GPL-2.0-only
2config CC_VERSION_TEXT
3	string
4	default "$(CC_VERSION_TEXT)"
5	help
6	  This is used in unclear ways:
7
8	  - Re-run Kconfig when the compiler is updated
9	    The 'default' property references the environment variable,
10	    CC_VERSION_TEXT so it is recorded in include/config/auto.conf.cmd.
11	    When the compiler is updated, Kconfig will be invoked.
12
13	  - Ensure full rebuild when the compiler is updated
14	    include/linux/compiler-version.h contains this option in the comment
15	    line so fixdep adds include/config/CC_VERSION_TEXT into the
16	    auto-generated dependency. When the compiler is updated, syncconfig
17	    will touch it and then every file will be rebuilt.
18
19config CC_IS_GCC
20	def_bool $(success,test "$(cc-name)" = GCC)
21
22config GCC_VERSION
23	int
24	default $(cc-version) if CC_IS_GCC
25	default 0
26
27config CC_IS_CLANG
28	def_bool $(success,test "$(cc-name)" = Clang)
29
30config CLANG_VERSION
31	int
32	default $(cc-version) if CC_IS_CLANG
33	default 0
34
35config AS_IS_GNU
36	def_bool $(success,test "$(as-name)" = GNU)
37
38config AS_IS_LLVM
39	def_bool $(success,test "$(as-name)" = LLVM)
40
41config AS_VERSION
42	int
43	# Use clang version if this is the integrated assembler
44	default CLANG_VERSION if AS_IS_LLVM
45	default $(as-version)
46
47config LD_IS_BFD
48	def_bool $(success,test "$(ld-name)" = BFD)
49
50config LD_VERSION
51	int
52	default $(ld-version) if LD_IS_BFD
53	default 0
54
55config LD_IS_LLD
56	def_bool $(success,test "$(ld-name)" = LLD)
57
58config LLD_VERSION
59	int
60	default $(ld-version) if LD_IS_LLD
61	default 0
62
63config RUSTC_VERSION
64	int
65	default $(rustc-version)
66	help
67	  It does not depend on `RUST` since that one may need to use the version
68	  in a `depends on`.
69
70config RUST_IS_AVAILABLE
71	def_bool $(success,$(srctree)/scripts/rust_is_available.sh)
72	help
73	  This shows whether a suitable Rust toolchain is available (found).
74
75	  Please see Documentation/rust/quick-start.rst for instructions on how
76	  to satisfy the build requirements of Rust support.
77
78	  In particular, the Makefile target 'rustavailable' is useful to check
79	  why the Rust toolchain is not being detected.
80
81config RUSTC_LLVM_VERSION
82	int
83	default $(rustc-llvm-version)
84
85config RUSTC_LLVM_MAJOR_VERSION
86	int
87	default $(shell,expr $(rustc-llvm-version) / 10000)
88
89config RUSTC_CLANG_LLVM_COMPATIBLE
90	bool
91	default y if CC_IS_CLANG && RUSTC_LLVM_MAJOR_VERSION = $(shell,expr $(cc-version) / 10000)
92	help
93	  This indicates whether Rust and Clang use LLVM of the same major
94	  version.
95
96	  Operations involving handling LLVM IR or bitcode (e.g. cross-language
97	  LTO) require the same LLVM major version to work properly. For best
98	  compatibility it is recommended that the exact same LLVM is used.
99
100config ARCH_HAS_CC_CAN_LINK
101	bool
102
103config CC_CAN_LINK
104	bool
105	default ARCH_CC_CAN_LINK if ARCH_HAS_CC_CAN_LINK
106	default $(cc_can_link_user,$(m64-flag)) if 64BIT
107	default $(cc_can_link_user,$(m32-flag))
108
109# Fixed in GCC 14, 13.3, 12.4 and 11.5
110# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921
111config GCC_ASM_GOTO_OUTPUT_BROKEN
112	bool
113	depends on CC_IS_GCC
114	default y if GCC_VERSION < 110500
115	default y if GCC_VERSION >= 120000 && GCC_VERSION < 120400
116	default y if GCC_VERSION >= 130000 && GCC_VERSION < 130300
117
118config CC_HAS_ASM_GOTO_OUTPUT
119	def_bool y
120	depends on !GCC_ASM_GOTO_OUTPUT_BROKEN
121	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)
122
123config CC_HAS_ASM_GOTO_TIED_OUTPUT
124	depends on CC_HAS_ASM_GOTO_OUTPUT
125	# Detect buggy gcc and clang, fixed in gcc-11 clang-14.
126	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)
127
128config TOOLS_SUPPORT_RELR
129	def_bool $(success,env "CC=$(CC)" "LD=$(LD)" "NM=$(NM)" "OBJCOPY=$(OBJCOPY)" $(srctree)/scripts/tools-support-relr.sh)
130
131config CC_HAS_ASM_INLINE
132	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
133
134config CC_HAS_ASSUME
135	bool
136	# clang needs to be at least 19.1.0 since the meaning of the assume
137	# attribute changed:
138	# https://github.com/llvm/llvm-project/commit/c44fa3e8a9a44c2e9a575768a3c185354b9f6c17
139	default y if CC_IS_CLANG && CLANG_VERSION >= 190100
140	# supported since gcc 13.1.0
141	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106654
142	default y if CC_IS_GCC && GCC_VERSION >= 130100
143
144config CC_HAS_NO_PROFILE_FN_ATTR
145	def_bool $(success,echo '__attribute__((no_profile_instrument_function)) int x();' | $(CC) -x c - -c -o /dev/null -Werror)
146
147config CC_OPT_ZERO_INIT_PADDING_BITS
148	def_string "$(cc-option-str,-fzero-init-padding-bits=all)"
149
150config CC_OPT_NO_ADDRSIG
151	def_string "$(cc-option-str,-fno-addrsig)"
152
153config CC_OPT_DIAGNOSTICS_SHOW_CONTEXT
154	def_string "$(cc-option-str,-fdiagnostics-show-context=2)"
155
156config CC_OPT_DIAGNOSTICS_SHOW_INLINING_CHAIN
157	def_string "$(cc-option-str,-fdiagnostics-show-inlining-chain)"
158
159config CC_OPT_STRICT_FLEX_ARRAYS
160	def_string "$(cc-option-str,-fstrict-flex-arrays=3)"
161
162# gcc-10 renamed --param=allow-store-data-races=0 to -fno-allow-store-data-races
163config CC_OPT_ALLOW_STORE_DATA_RACES_PARAM
164	def_string "$(cc-option-str,--param=allow-store-data-races=0)"
165
166config CC_OPT_NO_ALLOW_STORE_DATA_RACES
167	def_string "$(cc-option-str,-fno-allow-store-data-races)"
168
169config CC_HAS_MNOP_MCOUNT
170	def_bool $(cc-option,-mnop-mcount)
171
172# s390-linux-gnu-gcc did not support -mfentry until gcc-9.
173config CC_HAS_MFENTRY
174	def_bool $(cc-option,-mfentry)
175
176config LD_OPT_FORCE_GROUP_ALLOCATION
177	def_string "$(ld-option-str,--force-group-allocation)"
178
179config LD_OPT_NO_WARN_RWX_SEGMENTS
180	def_string "$(ld-option-str,--no-warn-rwx-segments)"
181
182config CC_OPT_WNO_ADDRESS_OF_PACKED_MEMBER
183	def_string "$(cc-option-str,-Wno-address-of-packed-member)"
184
185config CC_OPT_WNO_FORMAT_OVERFLOW_NON_KPRINTF
186	def_string "$(cc-option-str,-Wno-format-overflow-non-kprintf)"
187
188config CC_OPT_WNO_FORMAT_TRUNCATION_NON_KPRINTF
189	def_string "$(cc-option-str,-Wno-format-truncation-non-kprintf)"
190
191config CC_OPT_WNO_DEFAULT_CONST_INIT_UNSAFE
192	def_string "$(cc-option-str,-Wno-default-const-init-unsafe)"
193
194config CC_OPT_WNO_DANGLING_POINTER
195	def_string "$(cc-option-str,-Wno-dangling-pointer)"
196
197config CC_OPT_WVLA_LARGER_THAN
198	def_string "$(cc-option-str,-Wvla-larger-than=1)"
199
200config CC_HAS_WSTRINGOP_OVERFLOW
201	def_bool $(cc-option,-Wstringop-overflow)
202
203config CC_OPT_WNO_UNTERMINATED_STRING_INITIALIZATION
204	def_string "$(cc-option-str,-Wno-unterminated-string-initialization)"
205
206config CC_OPT_WERROR_DESIGNATED_INIT
207	def_string "$(cc-option-str,-Werror=designated-init)"
208
209config CC_OPT_WENUM_CONVERSION
210	def_string "$(cc-option-str,-Wenum-conversion)"
211
212config CC_OPT_WNO_PACKED_NOT_ALIGNED
213	def_string "$(cc-option-str,-Wno-packed-not-aligned)"
214
215config CC_OPT_WNO_FORMAT_OVERFLOW
216	def_string "$(cc-option-str,-Wno-format-overflow)"
217
218config CC_OPT_WNO_STRINGOP_TRUNCATION
219	def_string "$(cc-option-str,-Wno-stringop-truncation)"
220
221config CC_HAS_COUNTED_BY
222	bool
223	# clang needs to be at least 20.1.0 to avoid potential crashes
224	# when building structures that contain __counted_by
225	# https://github.com/ClangBuiltLinux/linux/issues/2114
226	# https://github.com/llvm/llvm-project/commit/160fb1121cdf703c3ef5e61fb26c5659eb581489
227	default y if CC_IS_CLANG && CLANG_VERSION >= 200100
228	# supported since gcc 15.1.0
229	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
230	default y if CC_IS_GCC && GCC_VERSION >= 150100
231
232config CC_HAS_COUNTED_BY_PTR
233	bool
234	# supported since clang 22
235	default y if CC_IS_CLANG && CLANG_VERSION >= 220100
236	# supported since gcc 16.0.0
237	default y if CC_IS_GCC && GCC_VERSION >= 160000
238
239config CC_HAS_BROKEN_COUNTED_BY_REF
240	bool
241	# https://github.com/llvm/llvm-project/issues/182575
242	default y if CC_IS_CLANG && CLANG_VERSION < 220100
243
244config CC_HAS_ALLOC_TOKEN
245	def_bool $(cc-option,-falloc-token-max=123)
246
247config CC_HAS_MULTIDIMENSIONAL_NONSTRING
248	def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror)
249
250config CC_OPT_INLINE_MEMSET
251	string
252	default "-finline-stringops=memset" if $(cc-option,-finline-stringops=memset)
253	default "-mllvm -max-store-memset=4294967294" if $(cc-option,-mllvm -max-store-memset=4294967294)
254
255config LD_CAN_USE_KEEP_IN_OVERLAY
256	# ld.lld prior to 21.0.0 did not support KEEP within an overlay description
257	# https://github.com/llvm/llvm-project/pull/130661
258	def_bool LD_IS_BFD || LLD_VERSION >= 210000
259
260config RUSTC_HAS_UNNECESSARY_TRANSMUTES
261	def_bool RUSTC_VERSION >= 108800
262
263config RUSTC_HAS_FILE_WITH_NUL
264	def_bool RUSTC_VERSION >= 108900
265
266config RUSTC_HAS_FILE_AS_C_STR
267	def_bool RUSTC_VERSION >= 109100
268
269config RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS
270	def_bool RUSTC_VERSION >= 109800
271
272config PAHOLE_VERSION
273	int
274	default "$(PAHOLE_VERSION)"
275