From 365da5ab379a3e38e196cad370695c4b300cfe51 Mon Sep 17 00:00:00 2001 From: linted Date: Sat, 20 Aug 2022 16:41:38 -0400 Subject: Added support for creation of Static Position-Independent Executables (PIE) on mips Updated config to allow compilation of rcrt1.o for mips and modified it's crt1.S to perform relocates in __start. The mips architecture performs relocations differently then most other architectures. reloc_static_pie was rewritten, taking code from dl-startup.c, in order to perfrom the additional relocations. Modifications were made to mips' dl-startup.h to allow for the use of contained macros without including _start definition. Signed-off-by: linted --- libc/sysdeps/linux/mips/crt1.S | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libc/sysdeps') diff --git a/libc/sysdeps/linux/mips/crt1.S b/libc/sysdeps/linux/mips/crt1.S index 083615515..7c4db447c 100644 --- a/libc/sysdeps/linux/mips/crt1.S +++ b/libc/sysdeps/linux/mips/crt1.S @@ -77,6 +77,10 @@ #ifndef __UCLIBC_CTOR_DTOR__ .weak _init .weak _fini +#endif +#ifdef L_rcrt1 + .type reloc_static_pie,@function + .hidden .L0 #endif .type main,@function .type __uClibc_main,@function @@ -89,6 +93,25 @@ __start: #else PTR_LA $28, _gp /* Setup GP correctly if we're non-PIC. */ move $31, $0 +#endif +#ifdef L_rcrt1 + PTR_LA $4, _DYNAMIC /* Place _DYNAMIC into the GOT */ + REG_S $4, -0x7ff0($28) /* offset to GOT stolen from dl-startup */ + jal .L0 /* Get the current $pc address */ +.L0: + PTR_SUBU $4, $31, $25 /* Calculate load addr */ + move $31, $0 /* Clear ra */ + and $29, -2 * SZREG /* Ensure stack is aligned */ + PTR_ADDIU $29, (-2 * SZREG) /* Allocate 2 register spaces on stack */ + REG_S $2, SZREG($29) /* Store atexit in case it exists */ + PTR_LA $5, reloc_static_pie /* function calls before relocation + don't work unless we set $t9 manually */ + PTR_ADDU $25, $4, $5 /* store reloc_static_pie in $t9 */ + jalr $25 /* call reloc_static_pie */ + nop /* delay slot, just in case */ + REG_L $2, SZREG($29) /* cleanup stack */ + PTR_ADDIU $29, $29, (2 * SZREG) + #endif PTR_LA $4, main /* main */ -- cgit v1.2.3