From 0d3fccf68d9873a3c824fb70be0dbb2c4642aa90 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Mon, 23 Feb 2026 12:10:29 -0700 Subject: [PATCH] kbuild: Use '-fms-anonymous-structs' if it is available Clang recently added '-fms-anonymous-structs' [1] to specifically enable the Microsoft tagged anonymous structure / union extension, for which the kernel added '-fms-extensions' in commit c4781dc3d1cf ("Kbuild: enable -fms-extensions"). Switch to this more narrow option if it is available, which would have helped avoid the issue addressed by commit a6773e6932cb ("jfs: Rename _inline to avoid conflict with clang's '-fms-extensions'"). GCC has talked about adding a similar flag [2] as well but potentially naming it differently. Move the selection of the flag to Kconfig to make it easier to use cc-option (as CC_FLAGS_DIALECT may be used in arch Makefiles, which may be too early for cc-option in Kbuild) and customize based on compiler flag names. Link: https://github.com/llvm/llvm-project/commit/c391efe6fb67329d8e2fd231692cc6b0ea902956 [1] Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123623 [2] Signed-off-by: Nathan Chancellor Reviewed-by: Nicolas Schier Reviewed-by: Kees Cook Acked-by: Ard Biesheuvel Acked-by: Helge Deller # parisc Link: https://patch.msgid.link/20260223-fms-anonymous-structs-v1-2-8ee406d3c36c@kernel.org Signed-off-by: Nicolas Schier --- Makefile | 2 +- init/Kconfig | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 06ff3032a6bc4..1d5c0ab9ed5c3 100644 --- a/Makefile +++ b/Makefile @@ -791,7 +791,7 @@ endif CC_FLAGS_DIALECT := -std=gnu11 # Allow including a tagged struct or union anonymously in another struct/union. -CC_FLAGS_DIALECT += -fms-extensions +CC_FLAGS_DIALECT += $(CONFIG_CC_MS_EXTENSIONS) # Clang enables warnings about GNU and Microsoft extensions by default, disable # them because this is expected with the above options. ifdef CONFIG_CC_IS_CLANG diff --git a/init/Kconfig b/init/Kconfig index c25869cf59c17..c4282d0494634 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -960,6 +960,11 @@ config CC_IMPLICIT_FALLTHROUGH default "-Wimplicit-fallthrough=5" if CC_IS_GCC && $(cc-option,-Wimplicit-fallthrough=5) default "-Wimplicit-fallthrough" if CC_IS_CLANG && $(cc-option,-Wunreachable-code-fallthrough) +config CC_MS_EXTENSIONS + string + default "-fms-anonymous-structs" if $(cc-option,-fms-anonymous-structs) + default "-fms-extensions" + # Currently, disable gcc-10+ array-bounds globally. # It's still broken in gcc-13, so no upper bound yet. config GCC10_NO_ARRAY_BOUNDS -- 2.47.3