Re: [PATCH V4 14/14] LoongArch: Adjust build infrastructure for 32BIT/64BIT

WANG Rui
2026-04-24T11:06:34Z

Hi Nathan,

>> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
>> index 8d45b860fe56..47516aeea9d2 100644
>> --- a/arch/loongarch/Makefile
>> +++ b/arch/loongarch/Makefile
>...
>> @@ -62,9 +66,19 @@ ifneq ($(SUBARCH),$(ARCH))
>> endif
>> endif
>>
>> +ifdef CONFIG_32BIT
>> +ifdef CONFIG_32BIT_STANDARD
>> +ld-emul = $(32bit-emul)
>> +cflags-y += -march=la32v1.0 -mabi=ilp32s -mcmodel=normal
>> +else # CONFIG_32BIT_REDUCED
>> +ld-emul = $(32bit-emul)
>> +cflags-y += -march=la32rv1.0 -mabi=ilp32s -mcmodel=normal
>> +endif
>> +endif
>
> As a result of the above problem, I see
>
> clang: error: ignoring '-mabi=ilp32s' as it conflicts with that implied by '-msoft-float' (lp64s) [-Werror,-Woption-ignored]
> clang: error: ignoring '-mabi=ilp32s' as it conflicts with that implied by '-msoft-float' (lp64s) [-Werror,-Woption-ignored]
> clang: error: ignoring '-mabi=ilp32s' as it conflicts with that implied by '-msoft-float' (lp64s) [-Werror,-Woption-ignored]
>
> when building configurations that I expected to be 64-bit but had been
> turned into 32-bit ones with LLVM. This was also reported by the test
> robot with allnoconfig.
>
> https://lore.kernel.org/202604232041.ESJDwVG4-lkp@intel.com/
>
> Maybe some change is needed on the LLVM side?

The root cause is that scripts/Makefile.clang unconditionally sets
CLANG_TARGET_FLAGS_loongarch to loongarch64-linux-gnusf.
However, Clang with --target=loongarch64 does not support a 32-bit ABI.
LLVM clearly separates loongarch32 and loongarch64 targets.

Since CLANG_TARGET_FLAGS gets initialized before CONFIG is available, the
current setup effectively assumes that a 64-bit target must also handle
a 32-bit ABI. That assumption may not hold for LLVM, which models 32-bit
and 64-bit LoongArch as separate targets.

I have a workaround patch for now, though I’d appreciate suggestions if
there’s a cleaner fix.

diff --git a/Makefile b/Makefile
index 54e1ae602000..f03ff854014a 100644
--- a/Makefile
+++ b/Makefile
@@ -725,6 +725,10 @@ CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null
RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null))
PAHOLE_VERSION = $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE))

+ifdef need-config
+-include $(objtree)/include/config/auto.conf
+endif
+
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
include $(srctree)/scripts/Makefile.clang
endif
diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
index b67636b28c35..1c4db2f6543e 100644
--- a/scripts/Makefile.clang
+++ b/scripts/Makefile.clang
@@ -4,7 +4,11 @@
CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
+ifdef CONFIG_32BIT
+CLANG_TARGET_FLAGS_loongarch := loongarch32-linux-gnusf
+else
CLANG_TARGET_FLAGS_loongarch := loongarch64-linux-gnusf
+endif
CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu
CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu
CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu

--
Thanks,
Rui