Parcourir la source

riscv: add support for static pie binaries

Just need to wire up a call to `reloc_static_pie` in the startup code
when creating rcrt1.o.

Explicit invocation of auipc and addi directly with pcrel operators are
nessecary instead of just `la` because otherwise the compiler generates
a relocation.

Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
Charles Mirabile il y a 1 mois
Parent
commit
f0c44249d7
2 fichiers modifiés avec 16 ajouts et 2 suppressions
  1. 8 1
      libc/sysdeps/linux/riscv32/crt1.S
  2. 8 1
      libc/sysdeps/linux/riscv64/crt1.S

+ 8 - 1
libc/sysdeps/linux/riscv32/crt1.S

@@ -47,7 +47,14 @@
 
 _start:
 	call  .Lload_gp
-	mv    a5, a0  /* rtld_fini.  */
+	mv    s0, a0  /* rtld_fini.  */
+#ifdef L_rcrt1
+1:
+	auipc a0, %pcrel_hi(__ehdr_start)
+	addi  a0, a0, %pcrel_lo(1b)
+	call  reloc_static_pie
+#endif
+	mv    a5, s0  /* rtld_fini.  */
 	/* main may be in a shared library.  */
 	la   a0, main
 	REG_L a1, 0(sp)      /* argc.  */

+ 8 - 1
libc/sysdeps/linux/riscv64/crt1.S

@@ -47,7 +47,14 @@
 
 _start:
 	call  .Lload_gp
-	mv    a5, a0  /* rtld_fini.  */
+	mv    s0, a0  /* rtld_fini.  */
+#ifdef L_rcrt1
+1:
+	auipc a0, %pcrel_hi(__ehdr_start)
+	addi  a0, a0, %pcrel_lo(1b)
+	call  reloc_static_pie
+#endif
+	mv    a5, s0  /* rtld_fini.  */
 	/* main may be in a shared library.  */
 	la   a0, main
 	REG_L a1, 0(sp)      /* argc.  */