Re: [PATCH 1/2] MIPS: Loongson64: Clean up use of cc-ifversion

From: Jiaxun Yang
Date: Tue Jan 25 2022 - 16:20:18 EST




在2022年1月25日一月 上午1:25,Nathan Chancellor写道:
[...]
>
> So something like this (completely untested)?

Yep, tested with multiple GCC toolchains and it works :-)

Thanks.

>
> diff --git a/arch/mips/loongson64/Platform b/arch/mips/loongson64/Platform
> index 3e660d6d3c2b..36ab2fe00835 100644
> --- a/arch/mips/loongson64/Platform
> +++ b/arch/mips/loongson64/Platform
> @@ -5,24 +5,9 @@
>
> cflags-$(CONFIG_CPU_LOONGSON64) += -Wa,--trap
>
> -#
> -# binutils from v2.25 on and gcc starting from v4.9.0 treat
> -march=loongson3a
> -# as MIPS64 R2; older versions as just R1. This leaves the
> possibility open
> -# that GCC might generate R2 code for -march=loongson3a which then is
> rejected
> -# by GAS. The cc-option can't probe for this behaviour so
> -march=loongson3a
> -# can't easily be used safely within the kbuild framework.
> -#
> -ifeq ($(call cc-ifversion, -ge, 0409, y), y)
> - ifeq ($(call ld-ifversion, -ge, 22500, y), y)
> - cflags-$(CONFIG_CPU_LOONGSON64) += \
> - $(call cc-option,-march=loongson3a -U_MIPS_ISA
> -D_MIPS_ISA=_MIPS_ISA_MIPS64)
> - else
> - cflags-$(CONFIG_CPU_LOONGSON64) += \
> - $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA
> -D_MIPS_ISA=_MIPS_ISA_MIPS64)
> - endif
> -else
> - cflags-$(CONFIG_CPU_LOONGSON64) += \
> - $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA
> -D_MIPS_ISA=_MIPS_ISA_MIPS64)
> +ifdef CONFIG_CPU_LOONGSON64
> +cflags-$(CONFIG_CC_IS_CLANG) += -march=mips64r2
> +cflags-$(CONFIG_CC_IS_GCC) += -march=loongson3a
> endif
>
> # Some -march= flags enable MMI instructions, and GCC complains about that
>
>> >
>> > Reviewed-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
>> >
>> >> ---
>> >> arch/mips/loongson64/Platform | 13 +++----------
>> >> 1 file changed, 3 insertions(+), 10 deletions(-)
>> >>
>> >> diff --git a/arch/mips/loongson64/Platform b/arch/mips/loongson64/Platform
>> >> index 3e660d6d3c2b..981d3abc150e 100644
>> >> --- a/arch/mips/loongson64/Platform
>> >> +++ b/arch/mips/loongson64/Platform
>> >> @@ -12,17 +12,10 @@ cflags-$(CONFIG_CPU_LOONGSON64) += -Wa,--trap
>> >> # by GAS. The cc-option can't probe for this behaviour so -march=loongson3a
>> >> # can't easily be used safely within the kbuild framework.
>> >> #
>> >> -ifeq ($(call cc-ifversion, -ge, 0409, y), y)
>> >> - ifeq ($(call ld-ifversion, -ge, 22500, y), y)
>> >> - cflags-$(CONFIG_CPU_LOONGSON64) += \
>> >> - $(call cc-option,-march=loongson3a -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64)
>> >> - else
>> >> - cflags-$(CONFIG_CPU_LOONGSON64) += \
>> >> - $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64)
>> >> - endif
>> >> +ifeq ($(CONFIG_CC_IS_GCC)$(call ld-ifversion, -ge, 22500, y), yy)
>> >> + cflags-$(CONFIG_CPU_LOONGSON64) += -march=loongson3a -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64
>> >> else
>> >> - cflags-$(CONFIG_CPU_LOONGSON64) += \
>> >> - $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64)
>> >> + cflags-$(CONFIG_CPU_LOONGSON64) += -march=mips64r2
>> >> endif
>> >>
>> >> # Some -march= flags enable MMI instructions, and GCC complains about that
>> >>
>> >> base-commit: 2c271fe77d52a0555161926c232cd5bc07178b39
>> >> --
>> >> 2.34.1
>> >>
>> >
>> >
>> > --
>> > Thanks,
>> > ~Nick Desaulniers
>>
>> --
>> - Jiaxun

--
- Jiaxun