Skip to contentSkip to conversation

MIPS: Loongson64: Clean up use of cc-ifversion

PATCH Superseded Nathan Chancellor 3 participants 10 messages Jan 20, 2022 – Jan 25, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

This Makefile checks that GCC is 4.9 or newer, which is redundant after commit 76ae847497bc ("Documentation: raise minimum supported version of GCC to 5.1"), so cc-option can be removed.

Clang does not support -march=loongson3a so it needs to continue to use -march=mips64r2, along with binutils less than 2.25, so check that both GCC and binutils 2.25 or newer are being used before using -march=loongson3a. These flags do not need to be checked with cc-option anymore because all GCC versions support -march=loongson3a and -march=mips64r2 and all clang versions support -march=mips64r2.

---
 arch/mips/loongson64/Platform | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
arch/mips/loongson64/Platform +3 -10
index 3e660d6d3c2b..981d3abc150e 100644
@@ -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

Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 MIPS: Loongson64: Wrap -mno-branch-likely with cc-option

This flag is not supported by clang, which results in a warning:

clang-14: warning: argument unused during compilation: '-mno-branch-likely' [-Wunused-command-line-argument]

This breaks cc-option, which adds -Werror to make this warning fatal and catch flags that are not supported. Wrap the flag in cc-option so that it does not cause cc-option to fail, which can cause randconfigs to be really noisy.

---
 arch/mips/loongson64/Platform | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/loongson64/Platform +2 -1
index 981d3abc150e..acf9edc9b15d 100644
@@ -26,5 +26,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64
+cflags-$(CONFIG_MACH_LOONGSON64) += $(call cc-option,-mno-branch-likely)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#6 lore raw
In reply to Nathan Chancellor
Quoted 5 lines · Nathan Chancellor

This Makefile checks that GCC is 4.9 or newer, which is redundant after commit 76ae847497bc ("Documentation: raise minimum supported version of GCC to 5.1"), so cc-option can be removed.

Quoted 8 lines

Clang does not support -march=loongson3a so it needs to continue to use -march=mips64r2, along with binutils less than 2.25, so check that both GCC and binutils 2.25 or newer are being used before using -march=loongson3a. These flags do not need to be checked with cc-option anymore because all GCC versions support -march=loongson3a and -march=mips64r2 and all clang versions support -march=mips64r2.

Thanks for the patch. I wonder why _MIPS_ISA only seems to be set at all for -march=loongson3a AFAICT, though that question is orthogonal to this patch. Perhaps the Loongson or MIPS maintainers know more? Otherwise seems like most uses of _MIPS_ISA can either be deleted or simplified now.

Quoted 34 lines
---
 arch/mips/loongson64/Platform | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
arch/mips/loongson64/Platform +3 -10
index 3e660d6d3c2b..981d3abc150e 100644
@@ -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

Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] MIPS: Loongson64: Wrap -mno-branch-likely with cc-option

In reply to Nathan Chancellor
Quoted 11 lines · Nathan Chancellor

This flag is not supported by clang, which results in a warning:

clang-14: warning: argument unused during compilation: '-mno-branch-likely' [-Wunused-command-line-argument]

This breaks cc-option, which adds -Werror to make this warning fatal and catch flags that are not supported. Wrap the flag in cc-option so that it does not cause cc-option to fail, which can cause randconfigs to be really noisy.

We should convert more of these tests to Kconfig checks that run once per configuration, rather than multiple times for a build. IIRC Linus mentioned this somewhere...yeah, the -Wimplicit-fallthrough patches. See
dee2b702bcf06 ("kconfig: Add support for -Wimplicit-fallthrough")

I wonder if we can check ARCH or SUBARCH in Kconfig to limit invoking the tool under test for certain arch specific command line flags?

I'll take this patch over such a larger change, but I think towards the goal of speeding up already configured builds, we eventually want to be migrating cc-option and ld-option checks to Kconfig.

Quoted 20 lines
---
 arch/mips/loongson64/Platform | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/loongson64/Platform +2 -2
index 981d3abc150e..acf9edc9b15d 100644
@@ -26,5 +26,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64
+cflags-$(CONFIG_MACH_LOONGSON64) += $(call cc-option,-mno-branch-likely)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
--

2.34.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw

Re: [PATCH 2/2] MIPS: Loongson64: Wrap -mno-branch-likely with cc-option

Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Nathan Chancellor

This flag is not supported by clang, which results in a warning:

clang-14: warning: argument unused during compilation: '-mno-branch-likely' [-Wunused-command-line-argument]

This breaks cc-option, which adds -Werror to make this warning fatal and catch flags that are not supported. Wrap the flag in cc-option so that it does not cause cc-option to fail, which can cause randconfigs to be really noisy.

We should convert more of these tests to Kconfig checks that run once per configuration, rather than multiple times for a build. IIRC Linus mentioned this somewhere...yeah, the -Wimplicit-fallthrough patches. See
dee2b702bcf06 ("kconfig: Add support for -Wimplicit-fallthrough")

Quoted 8 lines

I wonder if we can check ARCH or SUBARCH in Kconfig to limit invoking the tool under test for certain arch specific command line flags?

I'll take this patch over such a larger change, but I think towards the goal of speeding up already configured builds, we eventually want to be migrating cc-option and ld-option checks to Kconfig.

Something like this appears to work, if that is more preferrable?

arch/mips/Kconfig +6 -0
index 058446f01487..a27a3ade810e 100644
@@ -3232,3 +3232,9 @@ endmenu
 source "arch/mips/kvm/Kconfig"
 
 source "arch/mips/vdso/Kconfig"
+
+config CC_MNO_BRANCH_LIKELY
+	string
+	default "-mno-branch-likely"
+	depends on MACH_LOONGSON64 || MACH_LOONGSON2EF
+	depends on $(cc-option,-mno-branch-likely)
arch/mips/loongson2ef/Platform +1 -1
index 50e659aca543..66ed09581417 100644
@@ -41,6 +41,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef $(CONFIG_CC_MNO_BRANCH_LIKELY)
 load-$(CONFIG_LEMOTE_FULOONG2E) += 0xffffffff80100000
 load-$(CONFIG_LEMOTE_MACH2F) += 0xffffffff80200000
arch/mips/loongson64/Platform +1 -1
index 3e660d6d3c2b..88fbdfe9ffcc 100644
@@ -33,5 +33,5 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 $(CONFIG_CC_MNO_BRANCH_LIKELY)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
Quoted 25 lines
Quoted 20 lines
---
 arch/mips/loongson64/Platform | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/loongson64/Platform +2 -2
index 981d3abc150e..acf9edc9b15d 100644
@@ -26,5 +26,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64
+cflags-$(CONFIG_MACH_LOONGSON64) += $(call cc-option,-mno-branch-likely)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
--

2.34.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw

Re: [PATCH 2/2] MIPS: Loongson64: Wrap -mno-branch-likely with cc-option

Quoted 51 lines · Nathan Chancellor
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Nathan Chancellor

This flag is not supported by clang, which results in a warning:

clang-14: warning: argument unused during compilation: '-mno-branch-likely' [-Wunused-command-line-argument]

This breaks cc-option, which adds -Werror to make this warning fatal and catch flags that are not supported. Wrap the flag in cc-option so that it does not cause cc-option to fail, which can cause randconfigs to be really noisy.

We should convert more of these tests to Kconfig checks that run once per configuration, rather than multiple times for a build. IIRC Linus mentioned this somewhere...yeah, the -Wimplicit-fallthrough patches. See
dee2b702bcf06 ("kconfig: Add support for -Wimplicit-fallthrough")

Quoted 8 lines

I wonder if we can check ARCH or SUBARCH in Kconfig to limit invoking the tool under test for certain arch specific command line flags?

I'll take this patch over such a larger change, but I think towards the goal of speeding up already configured builds, we eventually want to be migrating cc-option and ld-option checks to Kconfig.

Something like this appears to work, if that is more preferrable?

arch/mips/Kconfig +6 -0
index 058446f01487..a27a3ade810e 100644
@@ -3232,3 +3232,9 @@ endmenu
 source "arch/mips/kvm/Kconfig"
 
 source "arch/mips/vdso/Kconfig"
+
+config CC_MNO_BRANCH_LIKELY
+       string
+       default "-mno-branch-likely"
+       depends on MACH_LOONGSON64 || MACH_LOONGSON2EF
+       depends on $(cc-option,-mno-branch-likely)
arch/mips/loongson2ef/Platform +0 -0
index 50e659aca543..66ed09581417 100644

arch/mips/loongson2ef/Platform cflags-y += $(call cc-option,-mno-loongson-mmi) · line 44

Quoted 5 lines
arch/mips/loongson2ef/Platform +1 -1
@@ -41,6 +41,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef $(CONFIG_CC_MNO_BRANCH_LIKELY)

Does that allow someone to modify the value for CC_MNO_BRANCH_LIKELY in menuconfig?

If so, I'd rather the Makefiles have:

cflags-$(CONFIG_CC_MNO_BRANCH_LIKELY) += -mno-branch-likely

and CONFIG_CC_MNO_BRANCH_LIKELY be a bool rather than an editable string. I think that makes the Makefile more readable; you don't have to see what CONFIG_CC_MNO_BRANCH_LIKELY expands to in a different file.

See also CC_HAS_ASM_GOTO and CC_HAS_ASM_GOTO_OUTPUT in init/Kconfig.

Quoted 40 lines
arch/mips/loongson2ef/Platform +0 -0
 load-$(CONFIG_LEMOTE_FULOONG2E) += 0xffffffff80100000
 load-$(CONFIG_LEMOTE_MACH2F) += 0xffffffff80200000
arch/mips/loongson64/Platform +1 -1
index 3e660d6d3c2b..88fbdfe9ffcc 100644
@@ -33,5 +33,5 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 $(CONFIG_CC_MNO_BRANCH_LIKELY)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
Quoted 26 lines
Quoted 18 lines
---
 arch/mips/loongson64/Platform | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/loongson64/Platform +2 -2
index 981d3abc150e..acf9edc9b15d 100644
@@ -26,5 +26,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64
+cflags-$(CONFIG_MACH_LOONGSON64) += $(call cc-option,-mno-branch-likely)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
--
Quoted 3 lines

2.34.1

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw

Re: [PATCH 2/2] MIPS: Loongson64: Wrap -mno-branch-likely with cc-option

Quoted 55 lines · Nick Desaulniers
Quoted 54 lines · Nathan Chancellor
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Nathan Chancellor

This flag is not supported by clang, which results in a warning:

clang-14: warning: argument unused during compilation: '-mno-branch-likely' [-Wunused-command-line-argument]

This breaks cc-option, which adds -Werror to make this warning fatal and catch flags that are not supported. Wrap the flag in cc-option so that it does not cause cc-option to fail, which can cause randconfigs to be really noisy.

We should convert more of these tests to Kconfig checks that run once per configuration, rather than multiple times for a build. IIRC Linus mentioned this somewhere...yeah, the -Wimplicit-fallthrough patches. See
dee2b702bcf06 ("kconfig: Add support for -Wimplicit-fallthrough")

Quoted 8 lines

I wonder if we can check ARCH or SUBARCH in Kconfig to limit invoking the tool under test for certain arch specific command line flags?

I'll take this patch over such a larger change, but I think towards the goal of speeding up already configured builds, we eventually want to be migrating cc-option and ld-option checks to Kconfig.

Something like this appears to work, if that is more preferrable?

arch/mips/Kconfig +6 -0
index 058446f01487..a27a3ade810e 100644
@@ -3232,3 +3232,9 @@ endmenu
 source "arch/mips/kvm/Kconfig"
 
 source "arch/mips/vdso/Kconfig"
+
+config CC_MNO_BRANCH_LIKELY
+       string
+       default "-mno-branch-likely"
+       depends on MACH_LOONGSON64 || MACH_LOONGSON2EF
+       depends on $(cc-option,-mno-branch-likely)
arch/mips/loongson2ef/Platform +0 -0
index 50e659aca543..66ed09581417 100644
@@ -41,6 +41,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
Quoted 5 lines

arch/mips/loongson2ef/Platform cflags-y += $(call cc-option,-mno-loongson-mmi) · line 44

Quoted 2 lines
arch/mips/loongson2ef/Platform +1 -1
-cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef $(CONFIG_CC_MNO_BRANCH_LIKELY)

Does that allow someone to modify the value for CC_MNO_BRANCH_LIKELY in menuconfig?

No because it is a hidden symbol; in other words:

config ...
string

rather than

config ...

    string "..."
Quoted 10 lines

If so, I'd rather the Makefiles have:

cflags-$(CONFIG_CC_MNO_BRANCH_LIKELY) += -mno-branch-likely

and CONFIG_CC_MNO_BRANCH_LIKELY be a bool rather than an editable string. I think that makes the Makefile more readable; you don't have to see what CONFIG_CC_MNO_BRANCH_LIKELY expands to in a different file.

See also CC_HAS_ASM_GOTO and CC_HAS_ASM_GOTO_OUTPUT in init/Kconfig.

Regardless, your suggestion is simpler. I can send that as v2 if this is preferrable.

arch/mips/Kconfig +4 -0
index 058446f01487..4f83fb5610cb 100644
@@ -3232,3 +3232,7 @@ endmenu
 source "arch/mips/kvm/Kconfig"
 
 source "arch/mips/vdso/Kconfig"
+
+config CC_HAS_MNO_BRANCH_LIKELY
+	def_bool y
+	depends on $(cc-option,-mno-branch-likely)
arch/mips/loongson2ef/Platform +2 -1
index 50e659aca543..eebabf9df6ac 100644
@@ -41,6 +41,7 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON2EF) += -I$(srctree)/arch/mips/include/asm/mach-loongson2ef
+cflags-$(CONFIG_CC_HAS_MNO_BRANCH_LIKELY) += -mno-branch-likely
 load-$(CONFIG_LEMOTE_FULOONG2E) += 0xffffffff80100000
 load-$(CONFIG_LEMOTE_MACH2F) += 0xffffffff80200000
arch/mips/loongson64/Platform +2 -1
index 3e660d6d3c2b..2fd9dc218a68 100644
@@ -33,5 +33,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64
+cflags-$(CONFIG_CC_HAS_MNO_BRANCH_LIKELY) += -mno-branch-likely
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
Quoted 45 lines
Quoted 40 lines
arch/mips/loongson2ef/Platform +0 -0
 load-$(CONFIG_LEMOTE_FULOONG2E) += 0xffffffff80100000
 load-$(CONFIG_LEMOTE_MACH2F) += 0xffffffff80200000
arch/mips/loongson64/Platform +1 -1
index 3e660d6d3c2b..88fbdfe9ffcc 100644
@@ -33,5 +33,5 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 $(CONFIG_CC_MNO_BRANCH_LIKELY)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
Quoted 26 lines
Quoted 18 lines
---
 arch/mips/loongson64/Platform | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/loongson64/Platform +2 -2
index 981d3abc150e..acf9edc9b15d 100644
@@ -26,5 +26,6 @@ cflags-y += $(call cc-option,-mno-loongson-mmi)
 # Loongson Machines' Support
 #
 
-cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64 -mno-branch-likely
+cflags-$(CONFIG_MACH_LOONGSON64) += -I$(srctree)/arch/mips/include/asm/mach-loongson64
+cflags-$(CONFIG_MACH_LOONGSON64) += $(call cc-option,-mno-branch-likely)
 load-$(CONFIG_CPU_LOONGSON64) += 0xffffffff80200000
--
Quoted 3 lines

2.34.1

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#7 lore raw
In reply to Nick Desaulniers
Quoted 13 lines · 在2022年1月24日一月 下午8:31,Nick Desaulniers写道:
Quoted 12 lines · Nathan Chancellor

This Makefile checks that GCC is 4.9 or newer, which is redundant after commit 76ae847497bc ("Documentation: raise minimum supported version of GCC to 5.1"), so cc-option can be removed.

Clang does not support -march=loongson3a so it needs to continue to use -march=mips64r2, along with binutils less than 2.25, so check that both GCC and binutils 2.25 or newer are being used before using -march=loongson3a. These flags do not need to be checked with cc-option anymore because all GCC versions support -march=loongson3a and -march=mips64r2 and all clang versions support -march=mips64r2.

Quoted 7 lines
Quoted 1 line

Thanks for the patch. I wonder why _MIPS_ISA only seems to be set at all for -march=loongson3a AFAICT, though that question is orthogonal to this patch. Perhaps the Loongson or MIPS maintainers know more? Otherwise seems like most uses of _MIPS_ISA can either be deleted or simplified now.

This is because earlier GCC mistakenly set loongson3a to MIPS64 not MIPS64R2.

But given that it's earlier than the minimal requirement GCC of kernel today, I think it should be safe to just move the whole logic.

Thanks.

Quoted 42 lines
Quoted 34 lines
---
 arch/mips/loongson64/Platform | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
arch/mips/loongson64/Platform +3 -10
index 3e660d6d3c2b..981d3abc150e 100644
@@ -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

Signature · 2 lines
Thanks,
~Nick Desaulniers
Signature · 1 line
- Jiaxun
#8 lore raw
Quoted 24 lines · Jiaxun Yang
Quoted 13 lines · 在2022年1月24日一月 下午8:31,Nick Desaulniers写道:
Quoted 12 lines · Nathan Chancellor

This Makefile checks that GCC is 4.9 or newer, which is redundant after commit 76ae847497bc ("Documentation: raise minimum supported version of GCC to 5.1"), so cc-option can be removed.

Clang does not support -march=loongson3a so it needs to continue to use -march=mips64r2, along with binutils less than 2.25, so check that both GCC and binutils 2.25 or newer are being used before using -march=loongson3a. These flags do not need to be checked with cc-option anymore because all GCC versions support -march=loongson3a and -march=mips64r2 and all clang versions support -march=mips64r2.

Quoted 7 lines
Quoted 1 line

Thanks for the patch. I wonder why _MIPS_ISA only seems to be set at all for -march=loongson3a AFAICT, though that question is orthogonal to this patch. Perhaps the Loongson or MIPS maintainers know more? Otherwise seems like most uses of _MIPS_ISA can either be deleted or simplified now.

Quoted 5 lines

This is because earlier GCC mistakenly set loongson3a to MIPS64 not MIPS64R2.

But given that it's earlier than the minimal requirement GCC of kernel today, I think it should be safe to just move the whole logic.

Thanks.

So something like this (completely untested)?

arch/mips/loongson64/Platform +3 -18
index 3e660d6d3c2b..36ab2fe00835 100644
@@ -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
Quoted 45 lines
Quoted 42 lines
Quoted 34 lines
---
 arch/mips/loongson64/Platform | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
arch/mips/loongson64/Platform +3 -10
index 3e660d6d3c2b..981d3abc150e 100644
@@ -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

Signature · 2 lines
Thanks,
~Nick Desaulniers
Signature · 1 line
- Jiaxun
maintainer
#9 lore raw

在2022年1月25日一月 上午1:25,Nathan Chancellor写道:
[...]

Quoted 2 lines

So something like this (completely untested)?

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

Thanks.

Quoted 86 lines
arch/mips/loongson64/Platform +0 -4
index 3e660d6d3c2b..36ab2fe00835 100644
@@ -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

arch/mips/loongson64/Platform +3 -18
-# 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
Quoted 46 lines
Quoted 43 lines
Quoted 34 lines
---
 arch/mips/loongson64/Platform | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
arch/mips/loongson64/Platform +3 -10
index 3e660d6d3c2b..981d3abc150e 100644
@@ -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

Signature · 2 lines
Thanks,
~Nick Desaulniers
Signature · 1 line
- Jiaxun
Signature · 1 line
- Jiaxun