[PATCH 04/16] UBUNTU: SAUCE: rust: allow to use INIT_STACK_ALL_ZERO
Andrea Righi
andrea.righi at canonical.com
Thu Mar 16 09:05:17 UTC 2023
BugLink: https://bugs.launchpad.net/bugs/2007654
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
going to be removed in the future (as the name of the option suggests),
with clang-16.
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: https://github.com/llvm/llvm-project/issues/44842
(backported from https://lore.kernel.org/lkml/8178319F-4188-4F8E-AD8D-DCC392E26DBF@kernel.org/T/)
[changed clang-17 -> clang-16 dependency]
Signed-off-by: Andrea Righi <andrea.righi at canonical.com>
---
rust/Makefile | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/rust/Makefile b/rust/Makefile
index ff70c4c916f8..6d899d7b9a4b 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -269,6 +269,19 @@ BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
# some configurations, with new GCC versions, etc.
bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
+# Auto variable zero-initialization requires an additional special option with
+# clang that is going to be removed sometimes in the future (likely in
+# clang-16), so make sure to pass this option only if clang supports it
+# (libclang major version < 16).
+#
+# https://github.com/llvm/llvm-project/issues/44842
+ifdef CONFIG_INIT_STACK_ALL_ZERO
+libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p')
+ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1)
+bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
+endif
+endif
+
bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
$(bindgen_extra_c_flags)
endif
--
2.39.2
More information about the kernel-team
mailing list