Skip to content

Commit

Permalink
libc: Work around LLVM's misassembly of j <reg> on mips r6.
Browse files Browse the repository at this point in the history
See: #21315
  • Loading branch information
alexrp committed Sep 18, 2024
1 parent 41330c9 commit 40803a4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/libc/glibc/sysdeps/mips/mips32/crtn.S
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
lw $31,28($sp)
.set noreorder
.set nomacro
j $31
/* zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315 */
jr $31
addiu $sp,$sp,32
.set macro
.set reorder
Expand All @@ -51,7 +52,8 @@
lw $31,28($sp)
.set noreorder
.set nomacro
j $31
/* zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315 */
jr $31
addiu $sp,$sp,32
.set macro
.set reorder
6 changes: 4 additions & 2 deletions lib/libc/glibc/sysdeps/mips/mips64/n32/crtn.S
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
ld $28,0($sp)
.set noreorder
.set nomacro
j $31
/* zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315 */
jr $31
addiu $sp,$sp,16
.set macro
.set reorder
Expand All @@ -53,7 +54,8 @@
ld $28,0($sp)
.set noreorder
.set nomacro
j $31
/* zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315 */
jr $31
addiu $sp,$sp,16
.set macro
.set reorder
6 changes: 4 additions & 2 deletions lib/libc/glibc/sysdeps/mips/mips64/n64/crtn.S
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
ld $28,0($sp)
.set noreorder
.set nomacro
j $31
/* zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315 */
jr $31
daddiu $sp,$sp,16
.set macro
.set reorder
Expand All @@ -53,7 +54,8 @@
ld $28,0($sp)
.set noreorder
.set nomacro
j $31
/* zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315 */
jr $31
daddiu $sp,$sp,16
.set macro
.set reorder
3 changes: 2 additions & 1 deletion lib/libc/glibc/sysdeps/unix/mips/sysdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
.end function; \
.size function,.-function

#define ret j ra ; nop
// zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315
#define ret jr ra ; nop

#undef PSEUDO_END
#define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
Expand Down
6 changes: 4 additions & 2 deletions lib/libc/musl/crt/mips/crtn.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
.section .init
lw $gp,24($sp)
lw $ra,28($sp)
j $ra
# zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315
jr $ra
addu $sp,$sp,32

.section .fini
lw $gp,24($sp)
lw $ra,28($sp)
j $ra
# zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315
jr $ra
addu $sp,$sp,32
6 changes: 4 additions & 2 deletions lib/libc/musl/crt/mips64/crtn.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
.section .init
ld $gp,16($sp)
ld $ra,24($sp)
j $ra
# zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315
jr $ra
daddu $sp,$sp,32

.section .fini
ld $gp,16($sp)
ld $ra,24($sp)
j $ra
# zig patch: j <reg> -> jr <reg> for https://github.com/ziglang/zig/issues/21315
jr $ra
daddu $sp,$sp,32

0 comments on commit 40803a4

Please sign in to comment.