Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: Consolidate C dialect options

Introduce CC_FLAGS_DIALECT to make it easier to update the various
places in the tree that rely on the GNU C standard and Microsoft
extensions flags atomically. All remaining uses of '-std=gnu11' and
'-fms-extensions' are in the tools directory (which has its own build
system) and other standalone Makefiles. This will allow the kernel to
use a narrower option to enable the Microsoft anonymous tagged structure
extension in a simpler manner. Place the CC_FLAGS_DIALECT block after
the configuration include (so that a future change can move the
selection of the flag to Kconfig) but before the
arch/$(SRCARCH)/Makefile include (so that CC_FLAGS_DIALECT is available
for use in those Makefiles).

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Helge Deller <deller@gmx.de> # parisc
Link: https://patch.msgid.link/20260223-fms-anonymous-structs-v1-1-8ee406d3c36c@kernel.org
Signed-off-by: Nicolas Schier <nsc@kernel.org>

authored by

Nathan Chancellor and committed by
Nicolas Schier
ec4c2827 febb5c81

+21 -31
+12 -4
Makefile
··· 587 587 KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE 588 588 589 589 KBUILD_CFLAGS := 590 - KBUILD_CFLAGS += -std=gnu11 591 590 KBUILD_CFLAGS += -fshort-wchar 592 591 KBUILD_CFLAGS += -funsigned-char 593 592 KBUILD_CFLAGS += -fno-common ··· 788 789 ifdef need-config 789 790 include $(objtree)/include/config/auto.conf 790 791 endif 792 + 793 + CC_FLAGS_DIALECT := -std=gnu11 794 + # Allow including a tagged struct or union anonymously in another struct/union. 795 + CC_FLAGS_DIALECT += -fms-extensions 796 + # Clang enables warnings about GNU and Microsoft extensions by default, disable 797 + # them because this is expected with the above options. 798 + ifdef CONFIG_CC_IS_CLANG 799 + CC_FLAGS_DIALECT += -Wno-gnu 800 + CC_FLAGS_DIALECT += -Wno-microsoft-anon-tag 801 + endif 802 + export CC_FLAGS_DIALECT 803 + KBUILD_CFLAGS += $(CC_FLAGS_DIALECT) 791 804 792 805 ifeq ($(KBUILD_EXTMOD),) 793 806 # Objects we will link into vmlinux / subdirs we need to visit ··· 1103 1092 # arrays. Enforce this for everything that may examine structure sizes and 1104 1093 # perform bounds checking. 1105 1094 KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3) 1106 - 1107 - # Allow including a tagged struct or union anonymously in another struct/union. 1108 - KBUILD_CFLAGS += -fms-extensions 1109 1095 1110 1096 # disable invalid "can't wrap" optimizations for signed / pointers 1111 1097 KBUILD_CFLAGS += -fno-strict-overflow
+1 -2
arch/arm64/kernel/vdso32/Makefile
··· 63 63 $(filter -Werror,$(KBUILD_CPPFLAGS)) \ 64 64 -Werror-implicit-function-declaration \ 65 65 -Wno-format-security \ 66 - -std=gnu11 -fms-extensions 66 + $(CC_FLAGS_DIALECT) 67 67 VDSO_CFLAGS += -O2 68 68 # Some useful compiler-dependent flags from top-level Makefile 69 69 VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign) ··· 71 71 VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes) 72 72 VDSO_CFLAGS += -Werror=date-time 73 73 VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types) 74 - VDSO_CFLAGS += $(if $(CONFIG_CC_IS_CLANG),-Wno-microsoft-anon-tag) 75 74 76 75 # Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is 77 76 # unreliable.
+1 -1
arch/loongarch/vdso/Makefile
··· 24 24 cflags-vdso := $(ccflags-vdso) \ 25 25 -isystem $(shell $(CC) -print-file-name=include) \ 26 26 $(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \ 27 - -std=gnu11 -fms-extensions -O2 -g -fno-strict-aliasing -fno-common -fno-builtin \ 27 + $(CC_FLAGS_DIALECT) -O2 -g -fno-strict-aliasing -fno-common -fno-builtin \ 28 28 -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ 29 29 $(call cc-option, -fno-asynchronous-unwind-tables) \ 30 30 $(call cc-option, -fno-stack-protector)
+1 -1
arch/parisc/boot/compressed/Makefile
··· 18 18 ifndef CONFIG_64BIT 19 19 KBUILD_CFLAGS += -mfast-indirect-calls 20 20 endif 21 - KBUILD_CFLAGS += -std=gnu11 -fms-extensions 21 + KBUILD_CFLAGS += $(CC_FLAGS_DIALECT) 22 22 23 23 LDFLAGS_vmlinux := -X -e startup --as-needed -T 24 24 $(obj)/vmlinux: $(obj)/vmlinux.lds $(addprefix $(obj)/, $(OBJECTS)) $(LIBGCC) FORCE
+1 -2
arch/powerpc/boot/Makefile
··· 70 70 BOOTCPPFLAGS += -isystem $(shell $(BOOTCC) -print-file-name=include) 71 71 72 72 BOOTCFLAGS := $(BOOTTARGETFLAGS) \ 73 - -std=gnu11 -fms-extensions \ 73 + $(CC_FLAGS_DIALECT) \ 74 74 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ 75 75 -fno-strict-aliasing -O2 \ 76 76 -msoft-float -mno-altivec -mno-vsx \ ··· 86 86 87 87 ifdef CONFIG_CC_IS_CLANG 88 88 BOOTCFLAGS += $(CLANG_FLAGS) 89 - BOOTCFLAGS += -Wno-microsoft-anon-tag 90 89 BOOTAFLAGS += $(CLANG_FLAGS) 91 90 endif 92 91
+1 -2
arch/s390/Makefile
··· 22 22 ifndef CONFIG_AS_IS_LLVM 23 23 KBUILD_AFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),$(aflags_dwarf)) 24 24 endif 25 - KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 -mpacked-stack -std=gnu11 -fms-extensions 25 + KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 -mpacked-stack $(CC_FLAGS_DIALECT) 26 26 KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY 27 27 KBUILD_CFLAGS_DECOMPRESSOR += -D__DECOMPRESSOR 28 28 KBUILD_CFLAGS_DECOMPRESSOR += -Wno-pointer-sign ··· 35 35 KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) 36 36 KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,)) 37 37 KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_NO_ARRAY_BOUNDS),-Wno-array-bounds) 38 - KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_IS_CLANG),-Wno-microsoft-anon-tag) 39 38 40 39 UTS_MACHINE := s390x 41 40 STACK_SIZE := $(if $(CONFIG_KASAN),65536,$(if $(CONFIG_KMSAN),65536,16384))
+1 -2
arch/s390/purgatory/Makefile
··· 13 13 $(obj)/mem.o: $(srctree)/arch/s390/lib/mem.S FORCE 14 14 $(call if_changed_rule,as_o_S) 15 15 16 - KBUILD_CFLAGS := -std=gnu11 -fms-extensions -fno-strict-aliasing -Wall -Wstrict-prototypes 16 + KBUILD_CFLAGS := $(CC_FLAGS_DIALECT) -fno-strict-aliasing -Wall -Wstrict-prototypes 17 17 KBUILD_CFLAGS += -Wno-pointer-sign -Wno-sign-compare 18 18 KBUILD_CFLAGS += -fno-zero-initialized-in-bss -fno-builtin -ffreestanding 19 19 KBUILD_CFLAGS += -Os -m64 -msoft-float -fno-common ··· 21 21 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING 22 22 KBUILD_CFLAGS += -D__DISABLE_EXPORTS 23 23 KBUILD_CFLAGS += $(CLANG_FLAGS) 24 - KBUILD_CFLAGS += $(if $(CONFIG_CC_IS_CLANG),-Wno-microsoft-anon-tag) 25 24 KBUILD_CFLAGS += $(call cc-option,-fno-PIE) 26 25 KBUILD_CFLAGS += $(call cc-option, -Wno-default-const-init-unsafe) 27 26 KBUILD_AFLAGS := $(filter-out -DCC_USING_EXPOLINE,$(KBUILD_AFLAGS))
+1 -5
arch/x86/Makefile
··· 48 48 49 49 # How to compile the 16-bit code. Note we always compile for -march=i386; 50 50 # that way we can complain to the user if the CPU is insufficient. 51 - REALMODE_CFLAGS := -std=gnu11 -fms-extensions -m16 -g -Os \ 51 + REALMODE_CFLAGS := $(CC_FLAGS_DIALECT) -m16 -g -Os \ 52 52 -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS \ 53 53 -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \ 54 54 -fno-strict-aliasing -fomit-frame-pointer -fno-pic \ ··· 59 59 REALMODE_CFLAGS += -Wno-address-of-packed-member 60 60 REALMODE_CFLAGS += $(cc_stack_align4) 61 61 REALMODE_CFLAGS += $(CLANG_FLAGS) 62 - ifdef CONFIG_CC_IS_CLANG 63 - REALMODE_CFLAGS += -Wno-gnu 64 - REALMODE_CFLAGS += -Wno-microsoft-anon-tag 65 - endif 66 62 export REALMODE_CFLAGS 67 63 68 64 # BITS is used as extension for files which are available in a 32 bit
+1 -5
arch/x86/boot/compressed/Makefile
··· 25 25 # avoid errors with '-march=i386', and future flags may depend on the target to 26 26 # be valid. 27 27 KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS) 28 - KBUILD_CFLAGS += -std=gnu11 -fms-extensions 28 + KBUILD_CFLAGS += $(CC_FLAGS_DIALECT) 29 29 KBUILD_CFLAGS += -fno-strict-aliasing -fPIE 30 30 KBUILD_CFLAGS += -Wundef 31 31 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING ··· 36 36 KBUILD_CFLAGS += -ffreestanding -fshort-wchar 37 37 KBUILD_CFLAGS += -fno-stack-protector 38 38 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 39 - ifdef CONFIG_CC_IS_CLANG 40 - KBUILD_CFLAGS += -Wno-gnu 41 - KBUILD_CFLAGS += -Wno-microsoft-anon-tag 42 - endif 43 39 KBUILD_CFLAGS += -Wno-pointer-sign 44 40 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables 45 41 KBUILD_CFLAGS += -D__DISABLE_EXPORTS
+1 -2
drivers/firmware/efi/libstub/Makefile
··· 11 11 12 12 cflags-$(CONFIG_X86_32) := -march=i386 13 13 cflags-$(CONFIG_X86_64) := -mcmodel=small 14 - cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -std=gnu11 -fms-extensions \ 14 + cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ $(CC_FLAGS_DIALECT) \ 15 15 -fPIC -fno-strict-aliasing -mno-red-zone \ 16 16 -mno-mmx -mno-sse -fshort-wchar \ 17 17 -Wno-pointer-sign \ 18 18 $(call cc-disable-warning, address-of-packed-member) \ 19 - $(if $(CONFIG_CC_IS_CLANG),-Wno-gnu -Wno-microsoft-anon-tag) \ 20 19 -fno-asynchronous-unwind-tables \ 21 20 $(CLANG_FLAGS) 22 21
-5
scripts/Makefile.warn
··· 28 28 KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds 29 29 30 30 ifdef CONFIG_CC_IS_CLANG 31 - # The kernel builds with '-std=gnu11' and '-fms-extensions' so use of GNU and 32 - # Microsoft extensions is acceptable. 33 - KBUILD_CFLAGS += -Wno-gnu 34 - KBUILD_CFLAGS += -Wno-microsoft-anon-tag 35 - 36 31 # Clang checks for overflow/truncation with '%p', while GCC does not: 37 32 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219 38 33 KBUILD_CFLAGS += $(call cc-option, -Wno-format-overflow-non-kprintf)