mbox series

[v3,0/4] pass -march= only to compiler

Message ID 20220516210954.1660716-1-ndesaulniers@google.com
Headers show
Series pass -march= only to compiler | expand

Message

Nick Desaulniers May 16, 2022, 9:09 p.m. UTC
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`.

Arnd sent a v2 of my previous patch
https://lore.kernel.org/linux-arm-kernel/20210928154143.2106903-14-arnd@kernel.org/
I added yet a few more instances I found since then.

Fixing this will allow us to enable
-Werror=unused-command-line-argument for clang builds.

Nick Desaulniers (4):
  ARM: remove lazy evaluation in Makefile
  ARM: use .arch directives instead of assembler command line flags
  ARM: only use -mtp=cp15 for the compiler
  ARM: pass -march= only to compiler

 arch/arm/Makefile                   | 76 ++++++++++++++++-------------
 arch/arm/boot/compressed/Makefile   |  1 -
 arch/arm/common/Makefile            |  2 -
 arch/arm/common/mcpm_head.S         |  2 +
 arch/arm/common/vlock.S             |  2 +
 arch/arm/kernel/Makefile            |  2 -
 arch/arm/kernel/hyp-stub.S          |  2 +
 arch/arm/kernel/swp_emulate.c       |  1 +
 arch/arm/lib/Makefile               |  4 --
 arch/arm/lib/delay-loop.S           |  4 ++
 arch/arm/mach-at91/Makefile         |  3 --
 arch/arm/mach-at91/pm_suspend.S     |  4 ++
 arch/arm/mach-imx/Makefile          |  3 --
 arch/arm/mach-imx/headsmp.S         |  2 +
 arch/arm/mach-imx/resume-imx6.S     |  2 +
 arch/arm/mach-imx/suspend-imx6.S    |  2 +
 arch/arm/mach-mvebu/Makefile        |  3 --
 arch/arm/mach-mvebu/coherency_ll.S  |  1 +
 arch/arm/mach-mvebu/pmsu.c          |  1 +
 arch/arm/mach-npcm/Makefile         |  2 -
 arch/arm/mach-npcm/headsmp.S        |  2 +
 arch/arm/mach-tegra/Makefile        |  2 -
 arch/arm/mach-tegra/reset-handler.S |  2 +
 arch/arm/mach-tegra/sleep-tegra20.S |  2 +
 arch/arm/mach-tegra/sleep-tegra30.S |  2 +
 arch/arm/mm/Makefile                | 15 ------
 arch/arm/mm/abort-ev6.S             |  1 +
 arch/arm/mm/abort-ev7.S             |  1 +
 arch/arm/mm/cache-v6.S              |  2 +
 arch/arm/mm/cache-v7.S              |  2 +
 arch/arm/mm/cache-v7m.S             |  2 +
 arch/arm/mm/copypage-feroceon.c     |  1 +
 arch/arm/mm/proc-v6.S               |  2 +
 arch/arm/mm/proc-v7-2level.S        |  2 +
 arch/arm/mm/proc-v7.S               |  2 +
 arch/arm/mm/tlb-v6.S                |  2 +
 arch/arm/mm/tlb-v7.S                |  2 +
 drivers/memory/Makefile             |  2 -
 drivers/memory/ti-emif-sram-pm.S    |  1 +
 drivers/soc/bcm/brcmstb/pm/Makefile |  1 -
 drivers/soc/bcm/brcmstb/pm/s2-arm.S |  1 +
 41 files changed, 94 insertions(+), 74 deletions(-)


base-commit: 0ac824f379fba2c2b17b75fd5ada69cd68c66348

Comments

Nick Desaulniers May 16, 2022, 9:14 p.m. UTC | #1
+ Ard (I messed up my command line invocation of git send-email, sorry
for more noise)
https://lore.kernel.org/llvm/20220516210954.1660716-1-ndesaulniers@google.com/

On Mon, May 16, 2022 at 2:10 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> 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`.
>
> Arnd sent a v2 of my previous patch
> https://lore.kernel.org/linux-arm-kernel/20210928154143.2106903-14-arnd@kernel.org/
> I added yet a few more instances I found since then.
>
> Fixing this will allow us to enable
> -Werror=unused-command-line-argument for clang builds.
>
> Nick Desaulniers (4):
>   ARM: remove lazy evaluation in Makefile
>   ARM: use .arch directives instead of assembler command line flags
>   ARM: only use -mtp=cp15 for the compiler
>   ARM: pass -march= only to compiler
>
>  arch/arm/Makefile                   | 76 ++++++++++++++++-------------
>  arch/arm/boot/compressed/Makefile   |  1 -
>  arch/arm/common/Makefile            |  2 -
>  arch/arm/common/mcpm_head.S         |  2 +
>  arch/arm/common/vlock.S             |  2 +
>  arch/arm/kernel/Makefile            |  2 -
>  arch/arm/kernel/hyp-stub.S          |  2 +
>  arch/arm/kernel/swp_emulate.c       |  1 +
>  arch/arm/lib/Makefile               |  4 --
>  arch/arm/lib/delay-loop.S           |  4 ++
>  arch/arm/mach-at91/Makefile         |  3 --
>  arch/arm/mach-at91/pm_suspend.S     |  4 ++
>  arch/arm/mach-imx/Makefile          |  3 --
>  arch/arm/mach-imx/headsmp.S         |  2 +
>  arch/arm/mach-imx/resume-imx6.S     |  2 +
>  arch/arm/mach-imx/suspend-imx6.S    |  2 +
>  arch/arm/mach-mvebu/Makefile        |  3 --
>  arch/arm/mach-mvebu/coherency_ll.S  |  1 +
>  arch/arm/mach-mvebu/pmsu.c          |  1 +
>  arch/arm/mach-npcm/Makefile         |  2 -
>  arch/arm/mach-npcm/headsmp.S        |  2 +
>  arch/arm/mach-tegra/Makefile        |  2 -
>  arch/arm/mach-tegra/reset-handler.S |  2 +
>  arch/arm/mach-tegra/sleep-tegra20.S |  2 +
>  arch/arm/mach-tegra/sleep-tegra30.S |  2 +
>  arch/arm/mm/Makefile                | 15 ------
>  arch/arm/mm/abort-ev6.S             |  1 +
>  arch/arm/mm/abort-ev7.S             |  1 +
>  arch/arm/mm/cache-v6.S              |  2 +
>  arch/arm/mm/cache-v7.S              |  2 +
>  arch/arm/mm/cache-v7m.S             |  2 +
>  arch/arm/mm/copypage-feroceon.c     |  1 +
>  arch/arm/mm/proc-v6.S               |  2 +
>  arch/arm/mm/proc-v7-2level.S        |  2 +
>  arch/arm/mm/proc-v7.S               |  2 +
>  arch/arm/mm/tlb-v6.S                |  2 +
>  arch/arm/mm/tlb-v7.S                |  2 +
>  drivers/memory/Makefile             |  2 -
>  drivers/memory/ti-emif-sram-pm.S    |  1 +
>  drivers/soc/bcm/brcmstb/pm/Makefile |  1 -
>  drivers/soc/bcm/brcmstb/pm/s2-arm.S |  1 +
>  41 files changed, 94 insertions(+), 74 deletions(-)
>
>
> base-commit: 0ac824f379fba2c2b17b75fd5ada69cd68c66348
> --
> 2.36.0.550.gb090851708-goog
>
Nick Desaulniers May 16, 2022, 9:15 p.m. UTC | #2
+ Ard (I messed up my command line invocation of git send-email, sorry
for more noise)
https://lore.kernel.org/llvm/20220516210954.1660716-1-ndesaulniers@google.com/

On Mon, May 16, 2022 at 2:10 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> arch-y and tune-y used lazy evaluation since they used to contain
> cc-option checks. They don't any longer, so just eagerly evaluate these
> command line flags.
>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  arch/arm/Makefile | 60 +++++++++++++++++++++--------------------------
>  1 file changed, 27 insertions(+), 33 deletions(-)
>
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index a2391b8de5a5..99a7ed7e9f09 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -60,44 +60,38 @@ KBUILD_CFLAGS       += $(call cc-option,-fno-ipa-sra)
>  # Note that GCC does not numerically define an architecture version
>  # macro, but instead defines a whole series of macros which makes
>  # testing for a specific architecture or later rather impossible.
> -arch-$(CONFIG_CPU_32v7M)       =-D__LINUX_ARM_ARCH__=7 -march=armv7-m
> -arch-$(CONFIG_CPU_32v7)                =-D__LINUX_ARM_ARCH__=7 -march=armv7-a
> -arch-$(CONFIG_CPU_32v6)                =-D__LINUX_ARM_ARCH__=6 -march=armv6
> -# Only override the compiler option if ARMv6. The ARMv6K extensions are
> +arch-$(CONFIG_CPU_32v7M)       :=-D__LINUX_ARM_ARCH__=7 -march=armv7-m
> +arch-$(CONFIG_CPU_32v7)                :=-D__LINUX_ARM_ARCH__=7 -march=armv7-a
> +arch-$(CONFIG_CPU_32v6)                :=-D__LINUX_ARM_ARCH__=6 -march=armv6
> +# Only override the compiler opt:ion if ARMv6. The ARMv6K extensions are
>  # always available in ARMv7
>  ifeq ($(CONFIG_CPU_32v6),y)
> -arch-$(CONFIG_CPU_32v6K)       =-D__LINUX_ARM_ARCH__=6 -march=armv6k
> +arch-$(CONFIG_CPU_32v6K)       :=-D__LINUX_ARM_ARCH__=6 -march=armv6k
>  endif
> -arch-$(CONFIG_CPU_32v5)                =-D__LINUX_ARM_ARCH__=5 -march=armv5te
> -arch-$(CONFIG_CPU_32v4T)       =-D__LINUX_ARM_ARCH__=4 -march=armv4t
> -arch-$(CONFIG_CPU_32v4)                =-D__LINUX_ARM_ARCH__=4 -march=armv4
> -arch-$(CONFIG_CPU_32v3)                =-D__LINUX_ARM_ARCH__=3 -march=armv3m
> -
> -# Evaluate arch cc-option calls now
> -arch-y := $(arch-y)
> +arch-$(CONFIG_CPU_32v5)                :=-D__LINUX_ARM_ARCH__=5 -march=armv5te
> +arch-$(CONFIG_CPU_32v4T)       :=-D__LINUX_ARM_ARCH__=4 -march=armv4t
> +arch-$(CONFIG_CPU_32v4)                :=-D__LINUX_ARM_ARCH__=4 -march=armv4
> +arch-$(CONFIG_CPU_32v3)                :=-D__LINUX_ARM_ARCH__=3 -march=armv3m
>
>  # This selects how we optimise for the processor.
> -tune-$(CONFIG_CPU_ARM7TDMI)    =-mtune=arm7tdmi
> -tune-$(CONFIG_CPU_ARM720T)     =-mtune=arm7tdmi
> -tune-$(CONFIG_CPU_ARM740T)     =-mtune=arm7tdmi
> -tune-$(CONFIG_CPU_ARM9TDMI)    =-mtune=arm9tdmi
> -tune-$(CONFIG_CPU_ARM940T)     =-mtune=arm9tdmi
> -tune-$(CONFIG_CPU_ARM946E)     =-mtune=arm9e
> -tune-$(CONFIG_CPU_ARM920T)     =-mtune=arm9tdmi
> -tune-$(CONFIG_CPU_ARM922T)     =-mtune=arm9tdmi
> -tune-$(CONFIG_CPU_ARM925T)     =-mtune=arm9tdmi
> -tune-$(CONFIG_CPU_ARM926T)     =-mtune=arm9tdmi
> -tune-$(CONFIG_CPU_FA526)       =-mtune=arm9tdmi
> -tune-$(CONFIG_CPU_SA110)       =-mtune=strongarm110
> -tune-$(CONFIG_CPU_SA1100)      =-mtune=strongarm1100
> -tune-$(CONFIG_CPU_XSCALE)      =-mtune=xscale
> -tune-$(CONFIG_CPU_XSC3)                =-mtune=xscale
> -tune-$(CONFIG_CPU_FEROCEON)    =-mtune=xscale
> -tune-$(CONFIG_CPU_V6)          =-mtune=arm1136j-s
> -tune-$(CONFIG_CPU_V6K)         =-mtune=arm1136j-s
> -
> -# Evaluate tune cc-option calls now
> -tune-y := $(tune-y)
> +tune-$(CONFIG_CPU_ARM7TDMI)    :=-mtune=arm7tdmi
> +tune-$(CONFIG_CPU_ARM720T)     :=-mtune=arm7tdmi
> +tune-$(CONFIG_CPU_ARM740T)     :=-mtune=arm7tdmi
> +tune-$(CONFIG_CPU_ARM9TDMI)    :=-mtune=arm9tdmi
> +tune-$(CONFIG_CPU_ARM940T)     :=-mtune=arm9tdmi
> +tune-$(CONFIG_CPU_ARM946E)     :=-mtune=arm9e
> +tune-$(CONFIG_CPU_ARM920T)     :=-mtune=arm9tdmi
> +tune-$(CONFIG_CPU_ARM922T)     :=-mtune=arm9tdmi
> +tune-$(CONFIG_CPU_ARM925T)     :=-mtune=arm9tdmi
> +tune-$(CONFIG_CPU_ARM926T)     :=-mtune=arm9tdmi
> +tune-$(CONFIG_CPU_FA526)       :=-mtune=arm9tdmi
> +tune-$(CONFIG_CPU_SA110)       :=-mtune=strongarm110
> +tune-$(CONFIG_CPU_SA1100)      :=-mtune=strongarm1100
> +tune-$(CONFIG_CPU_XSCALE)      :=-mtune=xscale
> +tune-$(CONFIG_CPU_XSC3)                :=-mtune=xscale
> +tune-$(CONFIG_CPU_FEROCEON)    :=-mtune=xscale
> +tune-$(CONFIG_CPU_V6)          :=-mtune=arm1136j-s
> +tune-$(CONFIG_CPU_V6K)         :=-mtune=arm1136j-s
>
>  ifeq ($(CONFIG_AEABI),y)
>  CFLAGS_ABI     :=-mabi=aapcs-linux -mfpu=vfp
> --
> 2.36.0.550.gb090851708-goog
>
Nick Desaulniers May 16, 2022, 9:15 p.m. UTC | #3
+ Ard (I messed up my command line invocation of git send-email, sorry
for more noise)
https://lore.kernel.org/llvm/20220516210954.1660716-1-ndesaulniers@google.com/

On Mon, May 16, 2022 at 2:10 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> Avoids an error from the assembler for CONFIG_THUMB2 kernels:
>
> clang-15: error: hardware TLS register is not supported for the thumbv4t
> sub-architecture
>
> This flag only makes sense to pass to the compiler, not the assembler.
>
> Perhaps CFLAGS_ABI can be renamed to CPPFLAGS_ABI to reflect that they
> will be passed to both the compiler and assembler for sources that
> require pre-processing.
>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  arch/arm/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 99a7ed7e9f09..1029c2503aef 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -108,7 +108,7 @@ CFLAGS_ABI  += -meabi gnu
>  endif
>
>  ifeq ($(CONFIG_CURRENT_POINTER_IN_TPIDRURO),y)
> -CFLAGS_ABI     += -mtp=cp15
> +KBUILD_CFLAGS  += -mtp=cp15
>  endif
>
>  # Accept old syntax despite ".syntax unified"
> --
> 2.36.0.550.gb090851708-goog
>
Nick Desaulniers May 16, 2022, 9:16 p.m. UTC | #4
+ Ard (I messed up my command line invocation of git send-email, sorry
for more noise)
https://lore.kernel.org/llvm/20220516210954.1660716-1-ndesaulniers@google.com/

On Mon, May 16, 2022 at 2:10 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> 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.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1315
> Link: https://github.com/ClangBuiltLinux/linux/issues/1587
> Link: https://lore.kernel.org/llvm/628249e8.1c69fb81.d20fd.02ea@mx.google.com/
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  arch/arm/Makefile | 34 ++++++++++++++++++++++++----------
>  1 file changed, 24 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 1029c2503aef..47a300f6f99c 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -57,21 +57,34 @@ endif
>  KBUILD_CFLAGS  += $(call cc-option,-fno-ipa-sra)
>
>  # This selects which instruction set is used.
> +arch-$(CONFIG_CPU_32v7M)       :=-march=armv7-m
> +arch-$(CONFIG_CPU_32v7)                :=-march=armv7-a
> +arch-$(CONFIG_CPU_32v6)                :=-march=armv6
> +# Only override the compiler option if ARMv6. The ARMv6K extensions are
> +# always available in ARMv7
> +ifeq ($(CONFIG_CPU_32v6),y)
> +arch-$(CONFIG_CPU_32v6K)       :=-march=armv6k
> +endif
> +arch-$(CONFIG_CPU_32v5)                :=-march=armv5te
> +arch-$(CONFIG_CPU_32v4T)       :=-march=armv4t
> +arch-$(CONFIG_CPU_32v4)                :=-march=armv4
> +arch-$(CONFIG_CPU_32v3)                :=-march=armv3m
> +
>  # Note that GCC does not numerically define an architecture version
>  # macro, but instead defines a whole series of macros which makes
>  # testing for a specific architecture or later rather impossible.
> -arch-$(CONFIG_CPU_32v7M)       :=-D__LINUX_ARM_ARCH__=7 -march=armv7-m
> -arch-$(CONFIG_CPU_32v7)                :=-D__LINUX_ARM_ARCH__=7 -march=armv7-a
> -arch-$(CONFIG_CPU_32v6)                :=-D__LINUX_ARM_ARCH__=6 -march=armv6
> -# Only override the compiler opt:ion if ARMv6. The ARMv6K extensions are
> +cpp-$(CONFIG_CPU_32v7M)                :=-D__LINUX_ARM_ARCH__=7
> +cpp-$(CONFIG_CPU_32v7)         :=-D__LINUX_ARM_ARCH__=7
> +cpp-$(CONFIG_CPU_32v6)         :=-D__LINUX_ARM_ARCH__=6
> +# Only override the compiler option if ARMv6. The ARMv6K extensions are
>  # always available in ARMv7
>  ifeq ($(CONFIG_CPU_32v6),y)
> -arch-$(CONFIG_CPU_32v6K)       :=-D__LINUX_ARM_ARCH__=6 -march=armv6k
> +cpp-$(CONFIG_CPU_32v6K)                :=-D__LINUX_ARM_ARCH__=6
>  endif
> -arch-$(CONFIG_CPU_32v5)                :=-D__LINUX_ARM_ARCH__=5 -march=armv5te
> -arch-$(CONFIG_CPU_32v4T)       :=-D__LINUX_ARM_ARCH__=4 -march=armv4t
> -arch-$(CONFIG_CPU_32v4)                :=-D__LINUX_ARM_ARCH__=4 -march=armv4
> -arch-$(CONFIG_CPU_32v3)                :=-D__LINUX_ARM_ARCH__=3 -march=armv3m
> +cpp-$(CONFIG_CPU_32v5)         :=-D__LINUX_ARM_ARCH__=5
> +cpp-$(CONFIG_CPU_32v4T)                :=-D__LINUX_ARM_ARCH__=4
> +cpp-$(CONFIG_CPU_32v4)         :=-D__LINUX_ARM_ARCH__=4
> +cpp-$(CONFIG_CPU_32v3)         :=-D__LINUX_ARM_ARCH__=3
>
>  # This selects how we optimise for the processor.
>  tune-$(CONFIG_CPU_ARM7TDMI)    :=-mtune=arm7tdmi
> @@ -123,8 +136,9 @@ AFLAGS_ISA  :=$(CFLAGS_ISA)
>  endif
>
>  # Need -Uarm for gcc < 3.x
> +KBUILD_CPPFLAGS        +=$(cpp-y)
>  KBUILD_CFLAGS  +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
> -KBUILD_AFLAGS  +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float
> +KBUILD_AFLAGS  +=$(CFLAGS_ABI) $(AFLAGS_ISA) -Wa,$(arch-y) $(tune-y) -include asm/unified.h -msoft-float
>
>  CHECKFLAGS     += -D__arm__
>
> --
> 2.36.0.550.gb090851708-goog
>