summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/arm/crt1.S
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/arm/crt1.S')
-rw-r--r--libc/sysdeps/linux/arm/crt1.S19
1 files changed, 19 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/arm/crt1.S b/libc/sysdeps/linux/arm/crt1.S
index a1d7f0f23..fade1d25c 100644
--- a/libc/sysdeps/linux/arm/crt1.S
+++ b/libc/sysdeps/linux/arm/crt1.S
@@ -246,6 +246,22 @@ _start:
mov lr, #0
#ifdef __ARCH_USE_MMU__
+#ifdef L_rcrt1
+ /* We don't need to save a1 since no dynamic linker should have run */
+ ldr a1, .L_GOT /* Get value at .L_GOT + 0 (offset to GOT)*/
+ adr a2, .L_GOT /* Get address of .L_GOT */
+ ldr a3, .L_GOT+16 /* Get value of _start(GOT) stored in .L_GOT */
+ adr a4, _start /* Get address of _start after relocation (changes to pc - ~30 or so) */
+ add a1, a1, a2 /* Calculate where the GOT is */
+ ldr a2, [a1, a3] /* GOT + _start(GOT) = offset of _start from begin of file */
+ sub a1, a4, a2 /* Current addr of _start - offset from beginning of file = load addr */
+ bl reloc_static_pie
+ mov a1, #0 /* Clean up a1 so that a random address won't get called at the end of program */
+
+ /* Clear the frame pointer and link register again since it might be modified by previous call */
+ mov fp, #0
+ mov lr, #0
+#endif
/* Pop argc off the stack and save a pointer to argv */
ldr a2, [sp], #4
mov a3, sp
@@ -309,6 +325,9 @@ _start:
.word _fini(GOT)
.word _init(GOT)
.word main(GOT)
+#ifdef L_rcrt1
+ .word _start(GOT)
+#endif
#endif
#endif