From 70833192a803061008d2221b27e9baada6042c90 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sun, 18 Dec 2022 01:06:20 +0100 Subject: Fix dynamic linker symbol resolver and assert macro --- libpsn00b/psxetc/_dl_resolve_wrapper.s | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'libpsn00b/psxetc/_dl_resolve_wrapper.s') diff --git a/libpsn00b/psxetc/_dl_resolve_wrapper.s b/libpsn00b/psxetc/_dl_resolve_wrapper.s index eedfa10..a0944c6 100644 --- a/libpsn00b/psxetc/_dl_resolve_wrapper.s +++ b/libpsn00b/psxetc/_dl_resolve_wrapper.s @@ -1,5 +1,5 @@ # PSn00bSDK dynamic linker -# (C) 2021 spicyjpeg - MPL licensed +# (C) 2021-2022 spicyjpeg - MPL licensed # # This function is called by the lazy loader stubs generated by GCC in the # .plt/.MIPS.stubs section when attempting to call a GOT entry whose address @@ -16,34 +16,32 @@ .global _dl_resolve_wrapper .type _dl_resolve_wrapper, @function _dl_resolve_wrapper: - # Push the registers we're going to use onto the stack. - addiu $sp, -16 + # Save the arguments being passed to the function to be resolved. + addiu $sp, -20 sw $a0, 0($sp) sw $a1, 4($sp) - sw $v0, 8($sp) - sw $t7, 12($sp) # (will be restored directly to $ra) + sw $a2, 8($sp) + sw $a3, 12($sp) + sw $t7, 16($sp) # (will be restored directly to $ra) # Figure out where the DLL's struct is. dlinit() places a pointer to the # struct in the second GOT entry, so it's just a matter of indexing the GOT # using $gp. Then call _dl_resolve_helper with the struct and $t8 as # arguments, and store the return value into $t0. - lw $a0, -0x7fec($gp) # (DLL *) sizeof(uint32_t) - 0x7ff0 [see dll.ld] + lw $a0, -0x7fec($gp) # dll = &((uint32_t *) (gp - 0x7ff0))[1] move $a1, $t8 jal _dl_resolve_helper addiu $sp, -8 addiu $sp, 8 - move $t0, $v0 - - # Restore registers from the stack and tail-call the function at the - # address returned by the resolver. This will cause the resolved function - # to run and return directly to the code that called the stub. + # Restore the arguments from the stack and tail-call the function at the + # address returned by the resolver. lw $a0, 0($sp) lw $a1, 4($sp) - lw $v0, 8($sp) - lw $ra, 12($sp) - addiu $sp, 16 + lw $a2, 8($sp) + lw $a3, 12($sp) + lw $ra, 16($sp) - jr $t0 - nop + jr $v0 + addiu $sp, 20 -- cgit v1.2.3