Skip to content

Commit d966c3c

Browse files
Andrea Righiojeda
authored andcommitted
rust: allow to use INIT_STACK_ALL_ZERO
With CONFIG_INIT_STACK_ALL_ZERO enabled, bindgen passes -ftrivial-auto-var-init=zero to clang, that triggers the following error: error: '-ftrivial-auto-var-init=zero' hasn't been enabled; enable it at your own peril for benchmarking purpose only with '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' However, this additional option that is currently required by clang is deprecated since clang-16 and going to be removed in the future, likely with clang-18. So, make sure bindgen is using this extra option if the major version of the libclang used by bindgen is < 16. In this way we can enable CONFIG_INIT_STACK_ALL_ZERO with CONFIG_RUST without triggering any build error. Link: llvm/llvm-project#44842 Link: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags Signed-off-by: Andrea Righi <[email protected]> Reviewed-by: Kees Cook <[email protected]> [Changed to < 16, added link and reworded] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent ccc4505 commit d966c3c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

rust/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,20 @@ BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
262262
# some configurations, with new GCC versions, etc.
263263
bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
264264

265+
# Auto variable zero-initialization requires an additional special option with
266+
# clang that is going to be removed sometime in the future (likely in
267+
# clang-18), so make sure to pass this option only if clang supports it
268+
# (libclang major version < 16).
269+
#
270+
# https://github.com/llvm/llvm-project/issues/44842
271+
# https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags
272+
ifdef CONFIG_INIT_STACK_ALL_ZERO
273+
libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p')
274+
ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1)
275+
bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
276+
endif
277+
endif
278+
265279
bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
266280
$(bindgen_extra_c_flags)
267281
endif

0 commit comments

Comments
 (0)