Skip to content

Commit 0daf8c8

Browse files
committed
tools/nolibc: mips: load current function to $t9
The MIPS calling convention requires the address of the current function to be available in $t9. This was not done so far. For GCC this seems to have worked, but when compiled with clang the executable segfault instantly. Properly load the address of _start_c() into $t9 before calling it. Acked-by: Willy Tarreau <w@1wt.eu> Link: https://lore.kernel.org/r/20240807-nolibc-llvm-v2-2-c20f2f5fc7c2@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
1 parent 55850eb commit 0daf8c8

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

tools/include/nolibc/arch-mips.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
194194
"li $t0, -8\n"
195195
"and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */
196196
"addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */
197-
"jal _start_c\n" /* transfer to c runtime */
197+
"lui $t9, %hi(_start_c)\n" /* ABI requires current function address in $t9 */
198+
"ori $t9, %lo(_start_c)\n"
199+
"jalr $t9\n" /* transfer to c runtime */
198200
" nop\n" /* delayed slot */
199201
".set pop\n"
200202
);

0 commit comments

Comments
 (0)