Skip to contentSkip to conversation

ARM: Drop '-mthumb' from AFLAGS_ISA

PATCH In review Nathan Chancellor 2 participants 2 messages Nov 18, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: Drop '-mthumb' from AFLAGS_ISA

When building with CONFIG_THUMB2_KERNEL=y + a version of clang from Debian using CROSS_COMPILE=arm-linux-gnueabihf-, the following warning occurs frequently:

  <built-in>:383:9: warning: '__thumb2__' macro redefined [-Wmacro-redefined]
  #define __thumb2__ 2
          ^
  <built-in>:353:9: note: previous definition is here
  #define __thumb2__ 1
          ^
  1 warning generated.

Debian carries a downstream patch that changes the default CPU of the arm-linux-gnueabihf target from 'arm1176jzf-s' (v6) to 'cortex-a7' (v7). As a result, '-mthumb' defines both '__thumb__' and '__thumb2__'. The define of '__thumb2__' via the command line was purposefully added to catch a situation like this.

In a similar vein as commit 26b12e084bce ("ARM: 9264/1: only use -mtp=cp15 for the compiler"), do not add '-mthumb' to AFLAGS_ISA, as it is already passed to the assembler via '-Wa,-mthumb' and '__thumb2__' is already defined for preprocessing.

---
v2:
* Add Nick's review and test tags.
* Call out explicitly that CROSS_COMPILE=arm-linux-gnueabihf- is needed to reproduce this issue in commit message (Nick).
* Fix dead link in commit message (Nick).
* Use the snapshot branch for the patch link, as the diff is more up to date against upstream LLVM (Nick).
v1: https://lore.kernel.org/[email protected]/

 arch/arm/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/Makefile +2 -1
index 357f0d9b8607..d1ebb746ff40 100644
@@ -131,8 +131,9 @@ endif
 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)
+CFLAGS_ISA	:=-Wa,-mimplicit-it=always $(AFLAGS_NOWARN)
 AFLAGS_ISA	:=$(CFLAGS_ISA) -Wa$(comma)-mthumb -D__thumb2__=2
+CFLAGS_ISA	+=-mthumb
 else
 CFLAGS_ISA	:=$(call cc-option,-marm,) $(AFLAGS_NOWARN)
 AFLAGS_ISA	:=$(CFLAGS_ISA)

base-commit: 0c52591d22e99759da3793f19249bbf45ad742bd

Signature · 1 line
2.38.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 24 lines · Nathan Chancellor

When building with CONFIG_THUMB2_KERNEL=y + a version of clang from Debian using CROSS_COMPILE=arm-linux-gnueabihf-, the following warning occurs frequently:

  <built-in>:383:9: warning: '__thumb2__' macro redefined [-Wmacro-redefined]
  #define __thumb2__ 2
          ^
  <built-in>:353:9: note: previous definition is here
  #define __thumb2__ 1
          ^
  1 warning generated.

Debian carries a downstream patch that changes the default CPU of the arm-linux-gnueabihf target from 'arm1176jzf-s' (v6) to 'cortex-a7' (v7). As a result, '-mthumb' defines both '__thumb__' and '__thumb2__'. The define of '__thumb2__' via the command line was purposefully added to catch a situation like this.

In a similar vein as commit 26b12e084bce ("ARM: 9264/1: only use -mtp=cp15 for the compiler"), do not add '-mthumb' to AFLAGS_ISA, as it is already passed to the assembler via '-Wa,-mthumb' and '__thumb2__' is already defined for preprocessing.

Quoted 6 lines
Quoted 32 lines

---
v2:
* Add Nick's review and test tags.
* Call out explicitly that CROSS_COMPILE=arm-linux-gnueabihf- is needed to reproduce this issue in commit message (Nick).
* Fix dead link in commit message (Nick).
* Use the snapshot branch for the patch link, as the diff is more up to date against upstream LLVM (Nick).
v1: https://lore.kernel.org/[email protected]/

 arch/arm/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/Makefile +2 -1
index 357f0d9b8607..d1ebb746ff40 100644
@@ -131,8 +131,9 @@ endif
 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)
+CFLAGS_ISA     :=-Wa,-mimplicit-it=always $(AFLAGS_NOWARN)
 AFLAGS_ISA     :=$(CFLAGS_ISA) -Wa$(comma)-mthumb -D__thumb2__=2
+CFLAGS_ISA     +=-mthumb
 else
 CFLAGS_ISA     :=$(call cc-option,-marm,) $(AFLAGS_NOWARN)
 AFLAGS_ISA     :=$(CFLAGS_ISA)

base-commit: 0c52591d22e99759da3793f19249bbf45ad742bd --
2.38.1