Skip to content

Commit 1d2e9b6

Browse files
nickdesaulniersRussell King (Oracle)
authored andcommitted
ARM: 9265/1: pass -march= only to compiler
When both -march= and -Wa,-march= are specified for assembler or assembler-with-cpp sources, GCC and Clang will prefer the -Wa,-march= value but Clang will warn that -march= is unused. warning: argument unused during compilation: '-march=armv6k' [-Wunused-command-line-argument] This is the top group of warnings we observe when using clang to assemble the kernel via `ARCH=arm make LLVM=1`. Split the arch-y make variable into two, so that -march= flags only get passed to the compiler, not the assembler. -D flags are added to KBUILD_CPPFLAGS which is used for both C and assembler-with-cpp sources. Clang is trying to warn that it doesn't support different values for -march= and -Wa,-march= (like GCC does, but the kernel doesn't need this) though the value of the preprocessor define __thumb2__ is based on -march=. Make sure to re-set __thumb2__ via -D flag for assembler sources now that we're no longer passing -march= to the assembler. Set it to a different value than the preprocessor would for -march= in case -march= gets accidentally re-added to KBUILD_AFLAGS in the future. Thanks to Ard and Nathan for this suggestion. Link: ClangBuiltLinux/linux#1315 Link: ClangBuiltLinux/linux#1587 Link: llvm/llvm-project#55656 Suggested-by: Ard Biesheuvel <ardb@kernel.org> Suggested-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Nathan Chancellor <nathan@kernel.org> Tested-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
1 parent 26b12e0 commit 1d2e9b6

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

arch/arm/Makefile

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,34 @@ endif
6060
KBUILD_CFLAGS += $(call cc-option,-fno-ipa-sra)
6161

6262
# This selects which instruction set is used.
63+
arch-$(CONFIG_CPU_32v7M) :=-march=armv7-m
64+
arch-$(CONFIG_CPU_32v7) :=-march=armv7-a
65+
arch-$(CONFIG_CPU_32v6) :=-march=armv6
66+
# Only override the compiler option if ARMv6. The ARMv6K extensions are
67+
# always available in ARMv7
68+
ifeq ($(CONFIG_CPU_32v6),y)
69+
arch-$(CONFIG_CPU_32v6K) :=-march=armv6k
70+
endif
71+
arch-$(CONFIG_CPU_32v5) :=-march=armv5te
72+
arch-$(CONFIG_CPU_32v4T) :=-march=armv4t
73+
arch-$(CONFIG_CPU_32v4) :=-march=armv4
74+
arch-$(CONFIG_CPU_32v3) :=-march=armv3m
75+
6376
# Note that GCC does not numerically define an architecture version
6477
# macro, but instead defines a whole series of macros which makes
6578
# testing for a specific architecture or later rather impossible.
66-
arch-$(CONFIG_CPU_32v7M) :=-D__LINUX_ARM_ARCH__=7 -march=armv7-m
67-
arch-$(CONFIG_CPU_32v7) :=-D__LINUX_ARM_ARCH__=7 -march=armv7-a
68-
arch-$(CONFIG_CPU_32v6) :=-D__LINUX_ARM_ARCH__=6 -march=armv6
69-
# Only override the compiler opt:ion if ARMv6. The ARMv6K extensions are
79+
cpp-$(CONFIG_CPU_32v7M) :=-D__LINUX_ARM_ARCH__=7
80+
cpp-$(CONFIG_CPU_32v7) :=-D__LINUX_ARM_ARCH__=7
81+
cpp-$(CONFIG_CPU_32v6) :=-D__LINUX_ARM_ARCH__=6
82+
# Only override the compiler option if ARMv6. The ARMv6K extensions are
7083
# always available in ARMv7
7184
ifeq ($(CONFIG_CPU_32v6),y)
72-
arch-$(CONFIG_CPU_32v6K) :=-D__LINUX_ARM_ARCH__=6 -march=armv6k
85+
cpp-$(CONFIG_CPU_32v6K) :=-D__LINUX_ARM_ARCH__=6
7386
endif
74-
arch-$(CONFIG_CPU_32v5) :=-D__LINUX_ARM_ARCH__=5 -march=armv5te
75-
arch-$(CONFIG_CPU_32v4T) :=-D__LINUX_ARM_ARCH__=4 -march=armv4t
76-
arch-$(CONFIG_CPU_32v4) :=-D__LINUX_ARM_ARCH__=4 -march=armv4
77-
arch-$(CONFIG_CPU_32v3) :=-D__LINUX_ARM_ARCH__=3 -march=armv3m
87+
cpp-$(CONFIG_CPU_32v5) :=-D__LINUX_ARM_ARCH__=5
88+
cpp-$(CONFIG_CPU_32v4T) :=-D__LINUX_ARM_ARCH__=4
89+
cpp-$(CONFIG_CPU_32v4) :=-D__LINUX_ARM_ARCH__=4
90+
cpp-$(CONFIG_CPU_32v3) :=-D__LINUX_ARM_ARCH__=3
7891

7992
# This selects how we optimise for the processor.
8093
tune-$(CONFIG_CPU_ARM7TDMI) :=-mtune=arm7tdmi
@@ -119,15 +132,16 @@ AFLAGS_NOWARN :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W)
119132

120133
ifeq ($(CONFIG_THUMB2_KERNEL),y)
121134
CFLAGS_ISA :=-mthumb -Wa,-mimplicit-it=always $(AFLAGS_NOWARN)
122-
AFLAGS_ISA :=$(CFLAGS_ISA) -Wa$(comma)-mthumb
135+
AFLAGS_ISA :=$(CFLAGS_ISA) -Wa$(comma)-mthumb -D__thumb2__=2
123136
else
124137
CFLAGS_ISA :=$(call cc-option,-marm,) $(AFLAGS_NOWARN)
125138
AFLAGS_ISA :=$(CFLAGS_ISA)
126139
endif
127140

128141
# Need -Uarm for gcc < 3.x
142+
KBUILD_CPPFLAGS +=$(cpp-y)
129143
KBUILD_CFLAGS +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
130-
KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float
144+
KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) -Wa,$(arch-y) $(tune-y) -include asm/unified.h -msoft-float
131145

132146
CHECKFLAGS += -D__arm__
133147

0 commit comments

Comments
 (0)