Skip to content

Commit cf56e6e

Browse files
nathanchanceopsiff
authored andcommitted
kbuild: Add '-fms-extensions' to areas with dedicated CFLAGS
[ Upstream commit 5ff8ad3909524ad55297a434f87c238224825bf4 ] This is a follow up to commit c4781dc3d1cf ("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> [ Backport from v6.19-rc1 ] Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
1 parent abc6fb8 commit cf56e6e

File tree

9 files changed

+23
-11
lines changed

9 files changed

+23
-11
lines changed

arch/arm64/kernel/vdso32/Makefile

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

7778
# The 32-bit compiler does not provide 128-bit integers, which are used in
7879
# some headers that are indirectly included from the vDSO code.

arch/loongarch/vdso/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ccflags-vdso := \
2323
cflags-vdso := $(ccflags-vdso) \
2424
-isystem $(shell $(CC) -print-file-name=include) \
2525
$(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
26-
-std=gnu11 -O2 -g -fno-strict-aliasing -fno-common -fno-builtin \
26+
-std=gnu11 -fms-extensions -O2 -g -fno-strict-aliasing -fno-common -fno-builtin \
2727
-fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
2828
$(call cc-option, -fno-asynchronous-unwind-tables) \
2929
$(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
@@ -22,7 +22,7 @@ KBUILD_CFLAGS += -fno-PIE -mno-space-regs -mdisable-fpregs -Os
2222
ifndef CONFIG_64BIT
2323
KBUILD_CFLAGS += -mfast-indirect-calls
2424
endif
25-
KBUILD_CFLAGS += -std=gnu11
25+
KBUILD_CFLAGS += -std=gnu11 -fms-extensions
2626

2727
LDFLAGS_vmlinux := -X -e startup --as-needed -T
2828
$(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
@@ -72,7 +72,7 @@ BOOTCPPFLAGS := -nostdinc $(LINUXINCLUDE)
7272
BOOTCPPFLAGS += -isystem $(shell $(BOOTCC) -print-file-name=include)
7373

7474
BOOTCFLAGS := $(BOOTTARGETFLAGS) \
75-
-std=gnu11 \
75+
-std=gnu11 -fms-extensions \
7676
-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
7777
-fno-strict-aliasing -O2 \
7878
-msoft-float -mno-altivec -mno-vsx \
@@ -88,6 +88,7 @@ BOOTARFLAGS := -crD
8888

8989
ifdef CONFIG_CC_IS_CLANG
9090
BOOTCFLAGS += $(CLANG_FLAGS)
91+
BOOTCFLAGS += -Wno-microsoft-anon-tag
9192
BOOTAFLAGS += $(CLANG_FLAGS)
9293
endif
9394

arch/s390/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ KBUILD_AFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -D__ASSEMBLY__
2121
ifndef CONFIG_AS_IS_LLVM
2222
KBUILD_AFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),$(aflags_dwarf))
2323
endif
24-
KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 -mpacked-stack -std=gnu11
24+
KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 -mpacked-stack -std=gnu11 -fms-extensions
2525
KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY
2626
KBUILD_CFLAGS_DECOMPRESSOR += -fno-delete-null-pointer-checks -msoft-float -mbackchain
2727
KBUILD_CFLAGS_DECOMPRESSOR += -fno-asynchronous-unwind-tables
@@ -32,6 +32,7 @@ KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-disable-warning, address-of-packed-membe
3232
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g)
3333
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,))
3434
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_NO_ARRAY_BOUNDS),-Wno-array-bounds)
35+
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_IS_CLANG),-Wno-microsoft-anon-tag)
3536

3637
UTS_MACHINE := s390x
3738
STACK_SIZE := $(if $(CONFIG_KASAN),65536,16384)

arch/s390/purgatory/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ UBSAN_SANITIZE := n
2121
KASAN_SANITIZE := n
2222
KCSAN_SANITIZE := n
2323

24-
KBUILD_CFLAGS := -std=gnu11 -fno-strict-aliasing -Wall -Wstrict-prototypes
24+
KBUILD_CFLAGS := -std=gnu11 -fms-extensions -fno-strict-aliasing -Wall -Wstrict-prototypes
2525
KBUILD_CFLAGS += -Wno-pointer-sign -Wno-sign-compare
2626
KBUILD_CFLAGS += -fno-zero-initialized-in-bss -fno-builtin -ffreestanding
2727
KBUILD_CFLAGS += -Os -m64 -msoft-float -fno-common
2828
KBUILD_CFLAGS += -fno-stack-protector
2929
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
3030
KBUILD_CFLAGS += $(CLANG_FLAGS)
31+
KBUILD_CFLAGS += $(if $(CONFIG_CC_IS_CLANG),-Wno-microsoft-anon-tag)
3132
KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
3233
KBUILD_AFLAGS := $(filter-out -DCC_USING_EXPOLINE,$(KBUILD_AFLAGS))
3334

arch/x86/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ endif
4343

4444
# How to compile the 16-bit code. Note we always compile for -march=i386;
4545
# that way we can complain to the user if the CPU is insufficient.
46-
REALMODE_CFLAGS := -std=gnu11 -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS \
46+
REALMODE_CFLAGS := -std=gnu11 -fms-extensions -m16 -g -Os \
47+
-DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS \
4748
-Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
4849
-fno-strict-aliasing -fomit-frame-pointer -fno-pic \
4950
-mno-mmx -mno-sse $(call cc-option,-fcf-protection=none)
@@ -53,6 +54,10 @@ REALMODE_CFLAGS += -fno-stack-protector
5354
REALMODE_CFLAGS += -Wno-address-of-packed-member
5455
REALMODE_CFLAGS += $(cc_stack_align4)
5556
REALMODE_CFLAGS += $(CLANG_FLAGS)
57+
ifdef CONFIG_CC_IS_CLANG
58+
REALMODE_CFLAGS += -Wno-gnu
59+
REALMODE_CFLAGS += -Wno-microsoft-anon-tag
60+
endif
5661
export REALMODE_CFLAGS
5762

5863
# BITS is used as extension for files which are available in a 32 bit

arch/x86/boot/compressed/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
3434
# avoid errors with '-march=i386', and future flags may depend on the target to
3535
# be valid.
3636
KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
37-
KBUILD_CFLAGS += -std=gnu11
37+
KBUILD_CFLAGS += -std=gnu11 -fms-extensions
3838
KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
3939
KBUILD_CFLAGS += -Wundef
4040
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
@@ -45,7 +45,10 @@ KBUILD_CFLAGS += -mno-mmx -mno-sse
4545
KBUILD_CFLAGS += -ffreestanding -fshort-wchar
4646
KBUILD_CFLAGS += -fno-stack-protector
4747
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
48-
KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
48+
ifdef CONFIG_CC_IS_CLANG
49+
KBUILD_CFLAGS += -Wno-gnu
50+
KBUILD_CFLAGS += -Wno-microsoft-anon-tag
51+
endif
4952
KBUILD_CFLAGS += -Wno-pointer-sign
5053
KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
5154
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables

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)