arm: clang: use -mthumb when -mthumb-interwork is not supported
PATCH 1/1 arm: clang: use -mthumb when -mthumb-interwork is not supported
With SYS_THUMB_BUILD, config.mk asks for "-mthumb -mthumb-interwork" and falls back to ARM code (-marm) if the compiler rejects the pair. Clang has no -mthumb-interwork (interworking is always on), so clang builds come out as ARM code, about 30 % larger than gcc's Thumb-2 build.
Try plain -mthumb before falling back to -marm.
Tested with clang 19 on mk808_defconfig: 467 KB instead of ~600 KB, boots on an MK808B (RK3066); the interworking veneers around save_boot_params were checked in the disassembly.
--- arch/arm/config.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/config.mk +2 -1
@@ -48,9 +48,10 @@ ifeq ($(CONFIG_$(PHASE_)SYS_THUMB_BUILD),y) AFLAGS_IMPLICIT_IT := $(call as-option,-Wa$(comma)-mimplicit-it=always) PF_CPPFLAGS_ARM := $(AFLAGS_IMPLICIT_IT) \ $(call cc-option, -mthumb -mthumb-interwork,\ + $(call cc-option, -mthumb,\ $(call cc-option,-marm,)\ $(call cc-option,-mno-thumb-interwork,)\ - ) + )) else ifneq ($(CONFIG_ARM64),y) PF_CPPFLAGS_ARM := $(call cc-option,-marm,) \ $(call cc-option,-mno-thumb-interwork,)
Signature · 1 line
2.47.3
Quoted 23 lines · Yalçın Can
With
SYS_THUMB_BUILD, config.mk asks for "-mthumb -mthumb-interwork" and falls back to ARM code (-marm) if the compiler rejects the pair. Clang has no -mthumb-interwork (interworking is always on), so clang builds come out as ARM code, about 30 % larger than gcc's Thumb-2 build.Try plain -mthumb before falling back to -marm.
Tested with clang 19 on
mk808_defconfig: 467 KB instead of ~600 KB, boots on an MK808B (RK3066); the interworking veneers aroundsave_boot_paramswere checked in the disassembly.Co-Authored-By Claude Opus 5.5 <[email protected]>Signed-off-by Yalçın Can <[email protected]>--- arch/arm/config.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/config.mk +0
-0@@ -48,9 +48,10 @@ ifeq ($(CONFIG_$(PHASE_)SYS_THUMB_BUILD),y) AFLAGS_IMPLICIT_IT := $(call as-option,-Wa$(comma)-mimplicit-it=always)
arch/arm/config.mk ifeq ($(CONFIG_$(PHASE_)SYS_THUMB_BUILD),y) · line 57
Quoted 10 lines
arch/arm/config.mk +2
-1PF_CPPFLAGS_ARM := $(AFLAGS_IMPLICIT_IT) \ $(call cc-option, -mthumb -mthumb-interwork,\ + $(call cc-option, -mthumb,\ $(call cc-option,-marm,)\ $(call cc-option,-mno-thumb-interwork,)\ - ) + )) else ifneq ($(CONFIG_ARM64),y) PF_CPPFLAGS_ARM := $(call cc-option,-marm,) \ $(call cc-option,-mno-thumb-interwork,)
This is a case where I'm glad someone looked at the overall failure. It's maybe why using clang overflows on a bunch of other targets, too. The fix however, is wrong. Looking at where everything came from, we need to look at the linux kernel, and then can see:
commit 22905a24306c8c312c2d66da9f90d09af0414f81
Author: Stefan Agner <[email protected]> Date: Tue May 8 22:49:49 2018 +0100
ARM: 8766/1: drop no-thumb-interwork in EABI mode
According to GCC documentation -m(no-)thumb-interwork is meaningless in AAPCS configurations. Also clang does not support the flag:
clang-5.0: error: unknown argument: '-mno-thumb-interwork'
Just drop -mno-thumb-interwork in AEABI configuration.
And we should just do the same in U-Boot and reference the kernel having made this correction in the above commit.
Signature · 1 line
Tom