Re: [PATCH V4 14/14] LoongArch: Adjust build infrastructure for 32BIT/64BIT
From: hev
Date: Fri Apr 24 2026 - 22:29:47 EST
Hi Nathan,
On Sat, Apr 25, 2026 at 2:19 AM Nathan Chancellor <nathan@xxxxxxxxxx> wrote:
>
> Hi Rui,
>
> On Fri, Apr 24, 2026 at 07:06:23PM +0800, WANG Rui wrote:
> > > 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@xxxxxxxxx/
> > >
> > > 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.
>
> Hmmm, okay, that definitely explains it. As the comment at the top of
> scripts/Makefile.clang states, we rely on targets supporting switching
> their word size via '-m32' / '-m64' so that we can use a 64-bit triple
> but still get a 32-bit one if necessary. For example:
>
> --target=x86_64-linux-gnu -m32
>
> effectively becomes
>
> --target=i386-linux-gnu
>
> It seems like this works for LoongArch in clang as well?
>
> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
> index 47516aeea9d2..2837004d0d75 100644
> --- a/arch/loongarch/Makefile
> +++ b/arch/loongarch/Makefile
> @@ -67,6 +67,9 @@ ifneq ($(SUBARCH),$(ARCH))
> endif
>
> ifdef CONFIG_32BIT
> +ifdef CONFIG_CC_IS_CLANG
> +cflags-y += -m32
> +endif
> ifdef CONFIG_32BIT_STANDARD
> ld-emul = $(32bit-emul)
> cflags-y += -march=la32v1.0 -mabi=ilp32s -mcmodel=normal
> diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile
> index 42aa96249828..eeda13ecb711 100644
> --- a/arch/loongarch/vdso/Makefile
> +++ b/arch/loongarch/vdso/Makefile
> @@ -14,6 +14,7 @@ ccflags-vdso := \
> $(filter -E%,$(KBUILD_CFLAGS)) \
> $(filter -march=%,$(KBUILD_CFLAGS)) \
> $(filter -m%-float,$(KBUILD_CFLAGS)) \
> + $(filter -m32,$(KBUILD_CFLAGS)) \
> $(CLANG_FLAGS) \
> -D__VDSO__
>
> --
>
> appears to do the right thing?
>
> $ make -skj"$(nproc)" ARCH=loongarch LLVM=1 mrproper loongarch32_defconfig all
>
> $ file vmlinux arch/loongarch/boot/vmlinux.efi
> vmlinux: ELF 32-bit LSB executable, LoongArch, version 1 (SYSV), statically linked, BuildID[sha1]=26b4af26bb14c923270429f4ccdc66a519c059b1, not stripped
> arch/loongarch/boot/vmlinux.efi: PE32+ executable for EFI (application), LoongArch 32-bit (stripped to external PDB), 2 section
>
Ah, I see now that Clang already maps -m32/-m64 to the corresponding
triple variants in the common layer.
Thanks for the clarification!
Rui
> Cheers,
> Nathan