Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argument unused during compilation: '-march=armv6k' #1315

Closed
nickdesaulniers opened this issue Mar 1, 2021 · 15 comments
Closed

argument unused during compilation: '-march=armv6k' #1315

nickdesaulniers opened this issue Mar 1, 2021 · 15 comments
Assignees
Labels
[ARCH] arm32 This bug impacts ARCH=arm [BUG] linux A bug that should be fixed in the mainline kernel. Clean build Issue needs to be fixed to get a warning-free all*config build [FIXED][LINUX] 6.2 This bug was fixed in Linux 6.2 [TOOL] integrated-as The issue is relevant to LLVM integrated assembler

Comments

@nickdesaulniers
Copy link
Member

forked from #1195

Building 32b arm targets with LLVM_IAS=1 with clang-13 (after https://reviews.llvm.org/rG1d51c699b9e2ebc5bcfdbe85c74cc871426333d4) now produces warnings related to the -march= flags.

The kernel uses the compiler as the driver for assembler input, as it generally is assembler with c preprocessor .S sources.

It seems that the 32b ARM kernel sometimes specifies -march=foo -Wa,-march=foo (ie. tell the compiler and the assembler which arch we're targeting). Based on the code in LLVM (see test cases in https://reviews.llvm.org/rG1d51c699b9e2ebc5bcfdbe85c74cc871426333d4), it seems the compiler argument is redundant.

I assume that the kernel/Kbuild should not be setting -march= for KBUILD_AFLAGS, only -Wa,-march= (so tentatively marking this a bug on the kernel side).

Though, I'm also curious whether we're handing -Qunused-arguments correctly for assembler input, or -Wa,-W correctly. (I haven't checked yet whether either of those are currently set for assembler input. I thought they were but could be misremembering).

cc @arndb @DavidSpickett

@nickdesaulniers nickdesaulniers added [BUG] linux A bug that should be fixed in the mainline kernel. [TOOL] integrated-as The issue is relevant to LLVM integrated assembler [ARCH] arm32 This bug impacts ARCH=arm labels Mar 1, 2021
@arndb
Copy link

arndb commented Mar 1, 2021

I assume that the kernel/Kbuild should not be setting -march= for KBUILD_AFLAGS, only -Wa,-march= (so tentatively marking this a bug on the kernel side).

I think your earlier patch to move all the -Wa,-march= flags into .arch directives in the assembler files is still the best fix here.

Though, I'm also curious whether we're handing -Qunused-arguments correctly for assembler input, or -Wa,-W correctly. (I haven't checked yet whether either of those are currently set for assembler input. I thought they were but could be misremembering).

I don't see any reference to -Qunused-arguments in the Makefile, except for the arm64 vdso32 code, which is probably a mistake. I have sent patches to remove unused arguments in the past, to avoid these warnings.

@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Oct 20, 2021

@nickdesaulniers nickdesaulniers added the [PATCH] Exists There is a patch that fixes this issue label Oct 20, 2021
@nathanchance nathanchance added the Clean build Issue needs to be fixed to get a warning-free all*config build label Dec 11, 2021
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue May 16, 2022
Similar to commit a6c3087 ("ARM: 8989/1: use .fpu assembler
directives instead of assembler arguments").

GCC and GNU binutils support setting the "sub arch" via -march=,
-Wa,-march, target function attribute, and .arch assembler directive.

Clang was missing support for -Wa,-march=, but this was implemented in
clang-13.

The behavior of both GCC and Clang is to
prefer -Wa,-march= over -march= for assembler and assembler-with-cpp
sources, but Clang will warn about the -march= being unused.

clang: warning: argument unused during compilation: '-march=armv6k'
[-Wunused-command-line-argument]

Since most assembler is non-conditionally assembled with one sub arch
(modulo arch/arm/delay-loop.S which conditionally is assembled as armv4
based on CONFIG_ARCH_RPC, and arch/arm/mach-at91/pm-suspend.S which is
conditionally assembled as armv7-a based on CONFIG_CPU_V7), prefer the
.arch assembler directive.

Link: llvm/llvm-project@1d51c69
Link: https://bugs.llvm.org/show_bug.cgi?id=48894
Link: ClangBuiltLinux#1195
Link: ClangBuiltLinux#1315
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
[arnd] add a few more instances found in compile testing
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue May 16, 2022
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: ClangBuiltLinux#1315
Link: ClangBuiltLinux#1587
Link: https://lore.kernel.org/llvm/628249e8.1c69fb81.d20fd.02ea@mx.google.com/
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
@nickdesaulniers
Copy link
Member Author

@nickdesaulniers nickdesaulniers self-assigned this May 17, 2022
@nickdesaulniers nickdesaulniers added [PATCH] Submitted A patch has been submitted for review and removed [PATCH] Exists There is a patch that fixes this issue labels May 17, 2022
@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented May 19, 2022

This might just be a bug in clang. cc @DavidSpickett

@DavidSpickett
Copy link

I'm going to look into this today.

@nickdesaulniers
Copy link
Member Author

@DavidSpickett I'm guessing the warning makes sense for -x assembler, but not -x assembler-with-cpp.

@nickdesaulniers
Copy link
Member Author

I don't think that not warning is the way to go.

I don't think that supporting different values for -march=<foo> -Wa,-march=<foo> is worth it and the kernel doesn't need support for different values between the two though that is a subtle behavior that gcc does support.

@nathanchance sugguested maybe another go of https://lore.kernel.org/llvm/20220516210954.1660716-1-ndesaulniers@google.com/ but rather than just remove -march= we maybe set KBUILD_AFLAGS += -D__thumb2__=2 when CONFIG_THUMB2_KERNEL=y. (2 to avoid unexpected redefinition)

@nickdesaulniers nickdesaulniers added [PATCH] Bitrot Patch is outdated and needs to be refreshed or revisited and removed [PATCH] Submitted A patch has been submitted for review labels Sep 10, 2022
@nathanchance
Copy link
Member

I think this is all that should be needed:

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index c5fd0bcf1b5b..b58998749ead 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -132,7 +132,7 @@ AFLAGS_NOWARN       :=$(call as-option,-Wa$(comma)-mno-warn-deprecated,-Wa$(comma)-W)

 ifeq ($(CONFIG_THUMB2_KERNEL),y)
 CFLAGS_ISA     :=-mthumb -Wa,-mimplicit-it=always $(AFLAGS_NOWARN)
-AFLAGS_ISA     :=$(CFLAGS_ISA) -Wa$(comma)-mthumb
+AFLAGS_ISA     :=$(CFLAGS_ISA) -Wa$(comma)-mthumb -D__thumb2__=2
 else
 CFLAGS_ISA     :=$(call cc-option,-marm,) $(AFLAGS_NOWARN)
 AFLAGS_ISA     :=$(CFLAGS_ISA)

With that, the error that the kernel test robot reported disappears. I do see another set of errors with allmodconfig along the lines of:

../arch/arm/mach-tegra/sleep.S:35:2: error: instruction requires: data-barriers
 dmb @ ensure ordering
 ^
<instantiation>:2:2: error: invalid instruction, any one of the following would fix this:
 ubfx r4, r4, #4, #12
 ^
<instantiation>:6:2: note: while in macro instantiation
 check_cpu_part_num 0xc09, r4, r5
 ^
../arch/arm/mach-tegra/sleep.S:50:2: note: while in macro instantiation
 exit_smp r4, r5
 ^
<instantiation>:2:2: note: instruction requires: armv6t2
 ubfx r4, r4, #4, #12
 ^
<instantiation>:6:2: note: while in macro instantiation
 check_cpu_part_num 0xc09, r4, r5
 ^
../arch/arm/mach-tegra/sleep.S:50:2: note: while in macro instantiation
 exit_smp r4, r5
 ^
<instantiation>:2:2: note: instruction requires: thumb2
 ubfx r4, r4, #4, #12
 ^
<instantiation>:6:2: note: while in macro instantiation
 check_cpu_part_num 0xc09, r4, r5
 ^
../arch/arm/mach-tegra/sleep.S:50:2: note: while in macro instantiation
 exit_smp r4, r5
 ^
...

This is resolved with:

diff --git a/arch/arm/mach-tegra/sleep.S b/arch/arm/mach-tegra/sleep.S
index 8f88944831c5..945f2c1474f7 100644
--- a/arch/arm/mach-tegra/sleep.S
+++ b/arch/arm/mach-tegra/sleep.S
@@ -22,6 +22,8 @@
 #define CLK_RESET_CCLK_BURST   0x20
 #define CLK_RESET_CCLK_DIVIDER  0x24

+.arch armv7-a
+
 #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
 /*
  * tegra_disable_clean_inv_dcache

The series still applies to -next with:

$ b4 am -o - 20220516210954.1660716-1-ndesaulniers@google.com | git am -3

@nickdesaulniers
Copy link
Member Author

I think this is all that should be needed:

Will GCC warn if you set via command line -D flag a flag its preprocessor would have defined?

@nathanchance
Copy link
Member

I think this is all that should be needed:

Will GCC warn if you set via command line -D flag a flag its preprocessor would have defined?

Yes:

$ echo "int main(void) { return __thumb__; }" | arm-none-eabi-gcc -mthumb -Werror -x c -c -o /dev/null -

$ echo "int main(void) { return __thumb__; }" | arm-none-eabi-gcc -mthumb -D__thumb__=2 -Werror -x c -c -o /dev/null -
<command-line>: error: "__thumb__" redefined [-Werror]
<built-in>: note: this is the location of the previous definition
cc1: all warnings being treated as errors

@nickdesaulniers
Copy link
Member Author

@nickdesaulniers nickdesaulniers added [PATCH] Submitted A patch has been submitted for review and removed [PATCH] Bitrot Patch is outdated and needs to be refreshed or revisited labels Oct 14, 2022
@nickdesaulniers nickdesaulniers self-assigned this Oct 14, 2022
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Oct 17, 2022
Similar to commit a6c3087 ("ARM: 8989/1: use .fpu assembler
directives instead of assembler arguments").

GCC and GNU binutils support setting the "sub arch" via -march=,
-Wa,-march, target function attribute, and .arch assembler directive.

Clang was missing support for -Wa,-march=, but this was implemented in
clang-13.

The behavior of both GCC and Clang is to
prefer -Wa,-march= over -march= for assembler and assembler-with-cpp
sources, but Clang will warn about the -march= being unused.

clang: warning: argument unused during compilation: '-march=armv6k'
[-Wunused-command-line-argument]

Since most assembler is non-conditionally assembled with one sub arch
(modulo arch/arm/delay-loop.S which conditionally is assembled as armv4
based on CONFIG_ARCH_RPC, and arch/arm/mach-at91/pm-suspend.S which is
conditionally assembled as armv7-a based on CONFIG_CPU_V7), prefer the
.arch assembler directive.

Add a few more instances found in compile testing as found by Arnd and
Nathan.

Link: llvm/llvm-project@1d51c69
Link: https://bugs.llvm.org/show_bug.cgi?id=48894
Link: ClangBuiltLinux#1195
Link: ClangBuiltLinux#1315
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Oct 17, 2022
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#1315
Link: ClangBuiltLinux#1587
Link: llvm/llvm-project#55656
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
@nickdesaulniers nickdesaulniers added [PATCH] Accepted A submitted patch has been accepted upstream and removed [PATCH] Submitted A patch has been submitted for review labels Nov 7, 2022
jonhunter pushed a commit to jonhunter/linux that referenced this issue Nov 8, 2022
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#1315
Link: ClangBuiltLinux#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>
@nathanchance
Copy link
Member

Russell appears to have picked up 9262/1, 9264/1, and 9265/1, but not 9263/1, which seems highly problematic to me, as the final patch heavily relies on the second one, so I suspect ARM builds in -next are about to break heavily :/

@nathanchance
Copy link
Member

I've pinged Russell on the v4 thread: https://lore.kernel.org/Y2qgTyFcPdnNfkpj@dev-arch.thelio-3990X/

jonhunter pushed a commit to jonhunter/linux that referenced this issue Nov 9, 2022
…lags

Similar to commit a6c3087 ("ARM: 8989/1: use .fpu assembler
directives instead of assembler arguments").

GCC and GNU binutils support setting the "sub arch" via -march=,
-Wa,-march, target function attribute, and .arch assembler directive.

Clang was missing support for -Wa,-march=, but this was implemented in
clang-13.

The behavior of both GCC and Clang is to
prefer -Wa,-march= over -march= for assembler and assembler-with-cpp
sources, but Clang will warn about the -march= being unused.

clang: warning: argument unused during compilation: '-march=armv6k'
[-Wunused-command-line-argument]

Since most assembler is non-conditionally assembled with one sub arch
(modulo arch/arm/delay-loop.S which conditionally is assembled as armv4
based on CONFIG_ARCH_RPC, and arch/arm/mach-at91/pm-suspend.S which is
conditionally assembled as armv7-a based on CONFIG_CPU_V7), prefer the
.arch assembler directive.

Add a few more instances found in compile testing as found by Arnd and
Nathan.

Link: llvm/llvm-project@1d51c69
Link: https://bugs.llvm.org/show_bug.cgi?id=48894
Link: ClangBuiltLinux#1195
Link: ClangBuiltLinux#1315

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
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>
jonhunter pushed a commit to jonhunter/linux that referenced this issue Nov 9, 2022
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#1315
Link: ClangBuiltLinux#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>
@nathanchance
Copy link
Member

@nathanchance nathanchance added [FIXED][LINUX] 6.2 This bug was fixed in Linux 6.2 and removed [PATCH] Accepted A submitted patch has been accepted upstream labels Dec 22, 2022
cristibirsan pushed a commit to linux4microchip/linux that referenced this issue Feb 15, 2023
…lags

Similar to commit a6c3087 ("ARM: 8989/1: use .fpu assembler
directives instead of assembler arguments").

GCC and GNU binutils support setting the "sub arch" via -march=,
-Wa,-march, target function attribute, and .arch assembler directive.

Clang was missing support for -Wa,-march=, but this was implemented in
clang-13.

The behavior of both GCC and Clang is to
prefer -Wa,-march= over -march= for assembler and assembler-with-cpp
sources, but Clang will warn about the -march= being unused.

clang: warning: argument unused during compilation: '-march=armv6k'
[-Wunused-command-line-argument]

Since most assembler is non-conditionally assembled with one sub arch
(modulo arch/arm/delay-loop.S which conditionally is assembled as armv4
based on CONFIG_ARCH_RPC, and arch/arm/mach-at91/pm-suspend.S which is
conditionally assembled as armv7-a based on CONFIG_CPU_V7), prefer the
.arch assembler directive.

Add a few more instances found in compile testing as found by Arnd and
Nathan.

Link: llvm/llvm-project@1d51c69
Link: https://bugs.llvm.org/show_bug.cgi?id=48894
Link: ClangBuiltLinux#1195
Link: ClangBuiltLinux#1315

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[ARCH] arm32 This bug impacts ARCH=arm [BUG] linux A bug that should be fixed in the mainline kernel. Clean build Issue needs to be fixed to get a warning-free all*config build [FIXED][LINUX] 6.2 This bug was fixed in Linux 6.2 [TOOL] integrated-as The issue is relevant to LLVM integrated assembler
Projects
None yet
Development

No branches or pull requests

4 participants