Skip to content

Commit

Permalink
llvm: fix mips tail call in compiler-rt
Browse files Browse the repository at this point in the history
  • Loading branch information
chenx97 committed Jan 2, 2024
1 parent 0e707c7 commit d569a2c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
see https://reviews.llvm.org/D158491, still unreviewed upstream

Index: llvm-toolchain-snapshot_18~++20231206102350+b304873134e8/compiler-rt/lib/interception/interception.h
===================================================================
--- llvm-toolchain-snapshot_18~++20231206102350+b304873134e8.orig/compiler-rt/lib/interception/interception.h
+++ llvm-toolchain-snapshot_18~++20231206102350+b304873134e8/compiler-rt/lib/interception/interception.h
@@ -205,8 +205,9 @@ const interpose_substitution substitutio
ASM_TYPE_FUNCTION_STR "\n" \
SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n" \
SANITIZER_STRINGIFY(CFI_STARTPROC) "\n" \
- SANITIZER_STRINGIFY(ASM_TAIL_CALL) " __interceptor_" \
- SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func)) "\n" \
+ C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)), \
+ "__interceptor_" \
+ SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n" \
SANITIZER_STRINGIFY(CFI_ENDPROC) "\n" \
".size " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", " \
".-" SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n" \
Index: llvm-toolchain-snapshot_18~++20231206102350+b304873134e8/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
===================================================================
--- llvm-toolchain-snapshot_18~++20231206102350+b304873134e8.orig/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
+++ llvm-toolchain-snapshot_18~++20231206102350+b304873134e8/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
@@ -44,6 +44,8 @@

#if defined(__x86_64__) || defined(__i386__) || defined(__sparc__)
# define ASM_TAIL_CALL jmp
+#elif defined(__mips__) && __mips_isa_rev >= 6
+# define ASM_TAIL_CALL bc
#elif defined(__arm__) || defined(__aarch64__) || defined(__mips__) || \
defined(__powerpc__) || defined(__loongarch_lp64)
# define ASM_TAIL_CALL b
@@ -53,6 +55,25 @@
# define ASM_TAIL_CALL tail
#endif

+#if defined(__mips64) && __mips_isa_rev < 6
+# define C_ASM_TAIL_CALL(tfunc, ifunc) \
+ "lui $t8, %hi(%neg(%gp_rel(" tfunc ")))\n" \
+ "daddu $t8, $t8, $t9\n" \
+ "daddu $t8, $t8, %lo(%neg(%gp_rel(" tfunc ")))\n" \
+ "ld $t9, %got_disp(" ifunc ")($t8)\n" \
+ "jr $t9\n"
+#elif defined(__mips__) && __mips_isa_rev < 6
+# define C_ASM_TAIL_CALL(tfunc, ifunc) \
+ ".set noreorder\n" \
+ ".cpload $t9\n" \
+ ".set reorder\n" \
+ "lw $t9, %got(" ifunc ")($gp)\n" \
+ "jr $t9\n"
+#elif defined(ASM_TAIL_CALL)
+# define C_ASM_TAIL_CALL(tfunc, ifunc) \
+ SANITIZER_STRINGIFY(ASM_TAIL_CALL) " " ifunc
+#endif
+
#if defined(__ELF__) && defined(__x86_64__) || defined(__i386__) || \
defined(__riscv)
# define ASM_PREEMPTIBLE_SYM(sym) sym@plt
2 changes: 1 addition & 1 deletion app-devel/llvm/02-compiler/build
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abinfo "Moving conflicting LLVM replacements for GCC-compatible files ..."
mkdir -pv "$PKGDIR"/usr/lib/llvm/
if ! ab_match_arch loongarch64 && \
! ab_match_arch loongson3 && \
! ab_match_march mips64r6el; then
! ab_match_arch mips64r6el; then
mv -v \
"$PKGDIR"/usr/include/libunwind.* \
"$PKGDIR"/usr/include/unwind* \
Expand Down
1 change: 1 addition & 0 deletions app-devel/llvm/spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VER=17.0.6
REL=1
SRCS="https://github.com/llvm/llvm-project/releases/download/llvmorg-$VER/llvm-project-$VER.src.tar.xz"
SUBDIR="llvm-project-$VER.src/llvm"
CHKSUMS="sha256::58a8818c60e6627064f312dbf46c02d9949956558340938b71cf731ad8bc0813"
Expand Down

0 comments on commit d569a2c

Please sign in to comment.