Skip to content

Commit 00afc44

Browse files
authored
Fix MIPS __start linker error with default relocation model (#171)
Turns out `la $t9, {entry}` generates a CALL16 relocation in PIC mode, and CALL16 needs the target to be a global symbol. Since `entry` is pub(super), the linker rightfully complains. Swapped to lui/addiu which use HI16/LO16 and don't care about visibility.
1 parent 6aff4f5 commit 00afc44

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/arch/mips32.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ pub(super) unsafe extern "C" fn __start() -> ! {
5050
"and $sp, $sp, -8", // Align stack to 8 bytes.
5151
"subu $sp, $sp, 16", // Reserve 16 bytes for O32 ABI argument save area.
5252
"move $ra, $zero", // Set the return address to zero.
53-
"la $t9, {entry}", // Load entry address into $t9.
54-
"jr $t9", // Jump to `entry` via $t9 (required for PIC).
53+
"lui $t9, %hi({entry})", // Load entry address into $t9.
54+
"addiu $t9, $t9, %lo({entry})", //
55+
"jr $t9", // Jump to `entry` via $t9 (PIC convention).
5556
"nop", // Branch delay slot.
5657
".set reorder",
5758
entry = sym super::program::entry

0 commit comments

Comments
 (0)