Skip to content

Commit 5ff8ad3

Browse files
committed
kbuild: Add '-fms-extensions' to areas with dedicated CFLAGS
This is a follow up to commit c4781dc ("Kbuild: enable -fms-extensions") but in a separate change due to being substantially different from the initial submission. There are many places within the kernel that use their own CFLAGS instead of the main KBUILD_CFLAGS, meaning code written with the main kernel's use of '-fms-extensions' in mind that may be tangentially included in these areas will result in "error: declaration does not declare anything" messages from the compiler. Add '-fms-extensions' to all these areas to ensure consistency, along with -Wno-microsoft-anon-tag to silence clang's warning about use of the extension that the kernel cares about using. parisc does not build with clang so it does not need this warning flag. LoongArch does not need it either because -W flags from KBUILD_FLAGS are pulled into cflags-vdso. Reported-by: Christian Brauner <brauner@kernel.org> Closes: https://lore.kernel.org/20251030-meerjungfrau-getrocknet-7b46eacc215d@brauner/ Reviewed-by: Christian Brauner <brauner@kernel.org> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent c4781dc commit 5ff8ad3

9 files changed

Lines changed: 20 additions & 11 deletions

File tree

arch/arm64/kernel/vdso32/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
6363
$(filter -Werror,$(KBUILD_CPPFLAGS)) \
6464
-Werror-implicit-function-declaration \
6565
-Wno-format-security \
66-
-std=gnu11
66+
-std=gnu11 -fms-extensions
6767
VDSO_CFLAGS += -O2
6868
# Some useful compiler-dependent flags from top-level Makefile
6969
VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
7070
VDSO_CFLAGS += -fno-strict-overflow
7171
VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
7272
VDSO_CFLAGS += -Werror=date-time
7373
VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
74+
VDSO_CFLAGS += $(if $(CONFIG_CC_IS_CLANG),-Wno-microsoft-anon-tag)
7475

7576
# Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is
7677
# unreliable.

arch/loongarch/vdso/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ccflags-vdso := \
1919
cflags-vdso := $(ccflags-vdso) \
2020
-isystem $(shell $(CC) -print-file-name=include) \
2121
$(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
22-
-std=gnu11 -O2 -g -fno-strict-aliasing -fno-common -fno-builtin \
22+
-std=gnu11 -fms-extensions -O2 -g -fno-strict-aliasing -fno-common -fno-builtin \
2323
-fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
2424
$(call cc-option, -fno-asynchronous-unwind-tables) \
2525
$(call cc-option, -fno-stack-protector)

arch/parisc/boot/compressed/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ KBUILD_CFLAGS += -fno-PIE -mno-space-regs -mdisable-fpregs -Os
1818
ifndef CONFIG_64BIT
1919
KBUILD_CFLAGS += -mfast-indirect-calls
2020
endif
21-
KBUILD_CFLAGS += -std=gnu11
21+
KBUILD_CFLAGS += -std=gnu11 -fms-extensions
2222

2323
LDFLAGS_vmlinux := -X -e startup --as-needed -T
2424
$(obj)/vmlinux: $(obj)/vmlinux.lds $(addprefix $(obj)/, $(OBJECTS)) $(LIBGCC) FORCE

arch/powerpc/boot/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BOOTCPPFLAGS := -nostdinc $(LINUXINCLUDE)
7070
BOOTCPPFLAGS += -isystem $(shell $(BOOTCC) -print-file-name=include)
7171

7272
BOOTCFLAGS := $(BOOTTARGETFLAGS) \
73-
-std=gnu11 \
73+
-std=gnu11 -fms-extensions \
7474
-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
7575
-fno-strict-aliasing -O2 \
7676
-msoft-float -mno-altivec -mno-vsx \
@@ -86,6 +86,7 @@ BOOTARFLAGS := -crD
8686

8787
ifdef CONFIG_CC_IS_CLANG
8888
BOOTCFLAGS += $(CLANG_FLAGS)
89+
BOOTCFLAGS += -Wno-microsoft-anon-tag
8990
BOOTAFLAGS += $(CLANG_FLAGS)
9091
endif
9192

arch/s390/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ KBUILD_AFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -D__ASSEMBLY__
2222
ifndef CONFIG_AS_IS_LLVM
2323
KBUILD_AFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),$(aflags_dwarf))
2424
endif
25-
KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 -mpacked-stack -std=gnu11
25+
KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 -mpacked-stack -std=gnu11 -fms-extensions
2626
KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY
2727
KBUILD_CFLAGS_DECOMPRESSOR += -D__DECOMPRESSOR
2828
KBUILD_CFLAGS_DECOMPRESSOR += -Wno-pointer-sign
@@ -35,6 +35,7 @@ KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-disable-warning, address-of-packed-membe
3535
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g)
3636
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,))
3737
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)
3839

3940
UTS_MACHINE := s390x
4041
STACK_SIZE := $(if $(CONFIG_KASAN),65536,$(if $(CONFIG_KMSAN),65536,16384))

arch/s390/purgatory/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ CFLAGS_sha256.o := -D__NO_FORTIFY
1313
$(obj)/mem.o: $(srctree)/arch/s390/lib/mem.S FORCE
1414
$(call if_changed_rule,as_o_S)
1515

16-
KBUILD_CFLAGS := -std=gnu11 -fno-strict-aliasing -Wall -Wstrict-prototypes
16+
KBUILD_CFLAGS := -std=gnu11 -fms-extensions -fno-strict-aliasing -Wall -Wstrict-prototypes
1717
KBUILD_CFLAGS += -Wno-pointer-sign -Wno-sign-compare
1818
KBUILD_CFLAGS += -fno-zero-initialized-in-bss -fno-builtin -ffreestanding
1919
KBUILD_CFLAGS += -Os -m64 -msoft-float -fno-common
2020
KBUILD_CFLAGS += -fno-stack-protector
2121
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
2222
KBUILD_CFLAGS += -D__DISABLE_EXPORTS
2323
KBUILD_CFLAGS += $(CLANG_FLAGS)
24+
KBUILD_CFLAGS += $(if $(CONFIG_CC_IS_CLANG),-Wno-microsoft-anon-tag)
2425
KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
2526
KBUILD_AFLAGS := $(filter-out -DCC_USING_EXPOLINE,$(KBUILD_AFLAGS))
2627
KBUILD_AFLAGS += -D__DISABLE_EXPORTS

arch/x86/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ endif
4848

4949
# How to compile the 16-bit code. Note we always compile for -march=i386;
5050
# that way we can complain to the user if the CPU is insufficient.
51-
REALMODE_CFLAGS := -std=gnu11 -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS \
51+
REALMODE_CFLAGS := -std=gnu11 -fms-extensions -m16 -g -Os \
52+
-DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS \
5253
-Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
5354
-fno-strict-aliasing -fomit-frame-pointer -fno-pic \
5455
-mno-mmx -mno-sse $(call cc-option,-fcf-protection=none)
@@ -60,6 +61,7 @@ REALMODE_CFLAGS += $(cc_stack_align4)
6061
REALMODE_CFLAGS += $(CLANG_FLAGS)
6162
ifdef CONFIG_CC_IS_CLANG
6263
REALMODE_CFLAGS += -Wno-gnu
64+
REALMODE_CFLAGS += -Wno-microsoft-anon-tag
6365
endif
6466
export REALMODE_CFLAGS
6567

arch/x86/boot/compressed/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
2525
# avoid errors with '-march=i386', and future flags may depend on the target to
2626
# be valid.
2727
KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
28-
KBUILD_CFLAGS += -std=gnu11
28+
KBUILD_CFLAGS += -std=gnu11 -fms-extensions
2929
KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
3030
KBUILD_CFLAGS += -Wundef
3131
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
@@ -36,7 +36,10 @@ KBUILD_CFLAGS += -mno-mmx -mno-sse
3636
KBUILD_CFLAGS += -ffreestanding -fshort-wchar
3737
KBUILD_CFLAGS += -fno-stack-protector
3838
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
39-
KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
39+
ifdef CONFIG_CC_IS_CLANG
40+
KBUILD_CFLAGS += -Wno-gnu
41+
KBUILD_CFLAGS += -Wno-microsoft-anon-tag
42+
endif
4043
KBUILD_CFLAGS += -Wno-pointer-sign
4144
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
4245
KBUILD_CFLAGS += -D__DISABLE_EXPORTS

drivers/firmware/efi/libstub/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ cflags-y := $(KBUILD_CFLAGS)
1111

1212
cflags-$(CONFIG_X86_32) := -march=i386
1313
cflags-$(CONFIG_X86_64) := -mcmodel=small
14-
cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -std=gnu11 \
14+
cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -std=gnu11 -fms-extensions \
1515
-fPIC -fno-strict-aliasing -mno-red-zone \
1616
-mno-mmx -mno-sse -fshort-wchar \
1717
-Wno-pointer-sign \
1818
$(call cc-disable-warning, address-of-packed-member) \
19-
$(call cc-disable-warning, gnu) \
19+
$(if $(CONFIG_CC_IS_CLANG),-Wno-gnu -Wno-microsoft-anon-tag) \
2020
-fno-asynchronous-unwind-tables \
2121
$(CLANG_FLAGS)
2222

0 commit comments

Comments
 (0)