Skip to contentSkip to conversation

MIPS: Workaround clang inline compat branch issue

PATCH Applied Jiaxun Yang 4 participants 4 messages Feb 28, 2023 – Mar 1, 2023 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 MIPS: Workaround clang inline compat branch issue

Clang is unable to handle the situation that a chunk of inline assembly ends with a compat branch instruction and then compiler generates another control transfer instruction immediately after this compat branch. The later instruction will end up in forbidden slot and cause exception.

Workaround by add a option to control the use of compact branch. Currently it's selected by CC_IS_CLANG and hopefully we can change it to a version check in future if clang manages to fix it.

Fix boot on boston board.

---
v2: Add Link tag to LLVM bug
v3: Docuement issue link in Kconfig as well

---
 arch/mips/Kconfig           | 4 ++++
 arch/mips/include/asm/asm.h | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
arch/mips/Kconfig +4 -0
index 37072e15b263..c8b878aa690f 100644
@@ -3206,6 +3206,10 @@ config CC_HAS_MNO_BRANCH_LIKELY
 	def_bool y
 	depends on $(cc-option,-mno-branch-likely)
 
+# https://github.com/llvm/llvm-project/issues/61045
+config CC_HAS_BROKEN_INLINE_COMPAT_BRANCH
+	def_bool y if CC_IS_CLANG
+
 menu "Power management options"
 
 config ARCH_HIBERNATION_POSSIBLE
arch/mips/include/asm/asm.h +1 -1
index 336ac9b65235..2e99450f4228 100644
@@ -336,7 +336,7 @@ symbol		=	value
  */
 #ifdef CONFIG_WAR_R10000_LLSC
 # define SC_BEQZ	beqzl
-#elif MIPS_ISA_REV >= 6
+#elif !defined(CONFIG_CC_HAS_BROKEN_INLINE_COMPAT_BRANCH) && MIPS_ISA_REV >= 6
 # define SC_BEQZ	beqzc
 #else
 # define SC_BEQZ	beqz
Signature · 1 line
2.37.1 (Apple Git-137.1)
Acked-by on v3 1/1
#1 lore raw
Quoted 11 lines · Jiaxun Yang

Clang is unable to handle the situation that a chunk of inline assembly ends with a compat branch instruction and then compiler generates another control transfer instruction immediately after this compat branch. The later instruction will end up in forbidden slot and cause exception.

Workaround by add a option to control the use of compact branch. Currently it's selected by CC_IS_CLANG and hopefully we can change it to a version check in future if clang manages to fix it.

Quoted 5 lines

Fix boot on boston board.

Thanks for the patch!

Quoted 40 lines

---
v2: Add Link tag to LLVM bug
v3: Docuement issue link in Kconfig as well

---
 arch/mips/Kconfig           | 4 ++++
 arch/mips/include/asm/asm.h | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
arch/mips/Kconfig +4 -0
index 37072e15b263..c8b878aa690f 100644
@@ -3206,6 +3206,10 @@ config CC_HAS_MNO_BRANCH_LIKELY
        def_bool y
        depends on $(cc-option,-mno-branch-likely)
 
+# https://github.com/llvm/llvm-project/issues/61045
+config CC_HAS_BROKEN_INLINE_COMPAT_BRANCH
+       def_bool y if CC_IS_CLANG
+
 menu "Power management options"
 
 config ARCH_HIBERNATION_POSSIBLE
arch/mips/include/asm/asm.h +1 -2
index 336ac9b65235..2e99450f4228 100644
@@ -336,7 +336,7 @@ symbol              =       value
  */
 #ifdef CONFIG_WAR_R10000_LLSC
 # define SC_BEQZ       beqzl
-#elif MIPS_ISA_REV >= 6
+#elif !defined(CONFIG_CC_HAS_BROKEN_INLINE_COMPAT_BRANCH) && MIPS_ISA_REV >= 6
 # define SC_BEQZ       beqzc
 #else
 # define SC_BEQZ       beqz
--

2.37.1 (Apple Git-137.1)

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer Applied
#2 lore raw
In reply to Jiaxun Yang
Quoted 15 lines · Jiaxun Yang

Clang is unable to handle the situation that a chunk of inline assembly ends with a compat branch instruction and then compiler generates another control transfer instruction immediately after this compat branch. The later instruction will end up in forbidden slot and cause exception.

Workaround by add a option to control the use of compact branch. Currently it's selected by CC_IS_CLANG and hopefully we can change it to a version check in future if clang manages to fix it.

Fix boot on boston board.

Quoted 7 lines

---
v2: Add Link tag to LLVM bug
v3: Docuement issue link in Kconfig as well

---
 arch/mips/Kconfig           | 4 ++++
 arch/mips/include/asm/asm.h | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

applied to mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
Reviewed-by on v3 1/1
#3 lore raw
In reply to Jiaxun Yang
Quoted 15 lines · Jiaxun Yang

Clang is unable to handle the situation that a chunk of inline assembly ends with a compat branch instruction and then compiler generates another control transfer instruction immediately after this compat branch. The later instruction will end up in forbidden slot and cause exception.

Workaround by add a option to control the use of compact branch. Currently it's selected by CC_IS_CLANG and hopefully we can change it to a version check in future if clang manages to fix it.

Fix boot on boston board.

Quoted 7 lines

---
v2: Add Link tag to LLVM bug
v3: Docuement issue link in Kconfig as well

---
  arch/mips/Kconfig           | 4 ++++
  arch/mips/include/asm/asm.h | 2 +-
  2 files changed, 5 insertions(+), 1 deletion(-)