[PATCH] LoongArch: Specify -m32/-m64 explicitly for 32BIT/64BIT

Huacai Chen posted 1 patch 1 month, 2 weeks ago
arch/loongarch/Makefile      | 2 ++
arch/loongarch/vdso/Makefile | 2 ++
2 files changed, 4 insertions(+)
[PATCH] LoongArch: Specify -m32/-m64 explicitly for 32BIT/64BIT
Posted by Huacai Chen 1 month, 2 weeks ago
Clang/LLVM build needs -m32/-m64 to switch triple variants (i.e. the
--target=xxx parameter). Otherwise we get build errors for CONFIG_32BIT.

GCC doesn't support -m32/-m64 now, but maybe support in future, so use
cc-option to specify them.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202604232041.ESJDwVG4-lkp@intel.com/
Suggested-by: Nathan Chancellor <nathan@kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/loongarch/Makefile      | 2 ++
 arch/loongarch/vdso/Makefile | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index 47516aeea9d2..54fcfa1eac1f 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -55,9 +55,11 @@ endif
 ifdef CONFIG_32BIT
 tool-archpref		= $(32bit-tool-archpref)
 UTS_MACHINE		:= loongarch32
+cflags-y		+= $(call cc-option,-m32)
 else
 tool-archpref		= $(64bit-tool-archpref)
 UTS_MACHINE		:= loongarch64
+cflags-y		+= $(call cc-option,-m64)
 endif
 
 ifneq ($(SUBARCH),$(ARCH))
diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile
index 42aa96249828..9c9181bb4071 100644
--- a/arch/loongarch/vdso/Makefile
+++ b/arch/loongarch/vdso/Makefile
@@ -12,6 +12,8 @@ obj-vdso-$(CONFIG_GENERIC_GETTIMEOFDAY) += vgettimeofday.o
 ccflags-vdso := \
 	$(filter -I%,$(KBUILD_CFLAGS)) \
 	$(filter -E%,$(KBUILD_CFLAGS)) \
+	$(filter -m32,$(KBUILD_CFLAGS)) \
+	$(filter -m64,$(KBUILD_CFLAGS)) \
 	$(filter -march=%,$(KBUILD_CFLAGS)) \
 	$(filter -m%-float,$(KBUILD_CFLAGS)) \
 	$(CLANG_FLAGS) \
-- 
2.52.0
Re: [PATCH] LoongArch: Specify -m32/-m64 explicitly for 32BIT/64BIT
Posted by WANG Rui 1 month, 2 weeks ago
On Tue, Apr 28, 2026 at 3:07 PM Huacai Chen <chenhuacai@loongson.cn> wrote:
>
> Clang/LLVM build needs -m32/-m64 to switch triple variants (i.e. the
> --target=xxx parameter). Otherwise we get build errors for CONFIG_32BIT.
>
> GCC doesn't support -m32/-m64 now, but maybe support in future, so use
> cc-option to specify them.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202604232041.ESJDwVG4-lkp@intel.com/
> Suggested-by: Nathan Chancellor <nathan@kernel.org
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>

Tested-by: WANG Rui <wangrui@loongson.cn>

Both Clang 18 building loongarch64 and Clang 22 building loongarch32
work as expected.

Cheers,
Rui


> ---
>  arch/loongarch/Makefile      | 2 ++
>  arch/loongarch/vdso/Makefile | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
> index 47516aeea9d2..54fcfa1eac1f 100644
> --- a/arch/loongarch/Makefile
> +++ b/arch/loongarch/Makefile
> @@ -55,9 +55,11 @@ endif
>  ifdef CONFIG_32BIT
>  tool-archpref          = $(32bit-tool-archpref)
>  UTS_MACHINE            := loongarch32
> +cflags-y               += $(call cc-option,-m32)
>  else
>  tool-archpref          = $(64bit-tool-archpref)
>  UTS_MACHINE            := loongarch64
> +cflags-y               += $(call cc-option,-m64)
>  endif
>
>  ifneq ($(SUBARCH),$(ARCH))
> diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile
> index 42aa96249828..9c9181bb4071 100644
> --- a/arch/loongarch/vdso/Makefile
> +++ b/arch/loongarch/vdso/Makefile
> @@ -12,6 +12,8 @@ obj-vdso-$(CONFIG_GENERIC_GETTIMEOFDAY) += vgettimeofday.o
>  ccflags-vdso := \
>         $(filter -I%,$(KBUILD_CFLAGS)) \
>         $(filter -E%,$(KBUILD_CFLAGS)) \
> +       $(filter -m32,$(KBUILD_CFLAGS)) \
> +       $(filter -m64,$(KBUILD_CFLAGS)) \
>         $(filter -march=%,$(KBUILD_CFLAGS)) \
>         $(filter -m%-float,$(KBUILD_CFLAGS)) \
>         $(CLANG_FLAGS) \
> --
> 2.52.0
>
>