[PATCH] kbuild: don't allow GCC data store races

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Nov 25 07:08:38 PST 2024


This is a port of kernel commit 69102311a57d1f ("./Makefile: tell gcc
optimizer to never introduce new data races"), which does what it says
on the tin: prevent gcc from replacing conditional loads with a
non-conditional one as this could lead to issues around memory remapping
functions.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 .clangd  | 2 +-
 Makefile | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/.clangd b/.clangd
index 58e83cd2871a..4057270b2a83 100644
--- a/.clangd
+++ b/.clangd
@@ -1,2 +1,2 @@
 CompileFlags:
-  Remove: -mabi=lp64
+  Remove: [ -mabi=lp64, -fno-allow-store-data-races]
diff --git a/Makefile b/Makefile
index 46707fb44f68..991e11bd0dee 100644
--- a/Makefile
+++ b/Makefile
@@ -670,6 +670,14 @@ KBUILD_CFLAGS += $(call cc-disable-warning, trampolines)
 
 KBUILD_CFLAGS += $(call cc-option, -fno-delete-null-pointer-checks,)
 
+# Tell gcc to never replace conditional load with a non-conditional one
+ifdef CONFIG_CC_IS_GCC
+# gcc-10 renamed --param=allow-store-data-races=0 to
+# -fno-allow-store-data-races.
+KBUILD_CFLAGS	+= $(call cc-option,--param=allow-store-data-races=0)
+KBUILD_CFLAGS	+= $(call cc-option,-fno-allow-store-data-races)
+endif
+
 # disable invalid "can't wrap" optimizations for signed / pointers
 KBUILD_CFLAGS	+= $(call cc-option,-fno-strict-overflow)
 
-- 
2.39.5




More information about the barebox mailing list