about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2024-01-17 15:35:57 +0100
committerAndreas Schwab <schwab@suse.de>2024-01-22 14:58:23 +0100
commit6edaa12b41a373f249469d7b516d2043f81aea37 (patch)
tree12d244129f9d4987e3a1526a4759e4e183eb5194
parentbcf2abd43bbe6ffdd8b6a1e1e36cc67a9769e508 (diff)
downloadglibc-6edaa12b41a373f249469d7b516d2043f81aea37.tar.gz
glibc-6edaa12b41a373f249469d7b516d2043f81aea37.tar.xz
glibc-6edaa12b41a373f249469d7b516d2043f81aea37.zip
riscv: add support for static PIE
In order to support static PIE the startup code must avoid relocations
before __libc_start_main is called.
-rw-r--r--sysdeps/riscv/start.S11
1 files changed, 11 insertions, 0 deletions
diff --git a/sysdeps/riscv/start.S b/sysdeps/riscv/start.S
index 0a1f713742..ede186ef23 100644
--- a/sysdeps/riscv/start.S
+++ b/sysdeps/riscv/start.S
@@ -50,7 +50,13 @@ ENTRY (ENTRY_POINT)
 	call  load_gp
 	mv    a5, a0  /* rtld_fini.  */
 	/* main may be in a shared library.  */
+#if defined PIC && !defined SHARED
+	/* Avoid relocation in static PIE since _start is called before it
+	   is relocated.  */
+	lla   a0, __wrap_main
+#else
 	la   a0, main
+#endif
 	REG_L a1, 0(sp)      /* argc.  */
 	addi  a2, sp, SZREG  /* argv.  */
 	andi  sp, sp, ALMASK /* Align stack. */
@@ -62,6 +68,11 @@ ENTRY (ENTRY_POINT)
 	ebreak
 END (ENTRY_POINT)
 
+#if defined PIC && !defined SHARED
+__wrap_main:
+	tail  main@plt
+#endif
+
 /* Dynamic links need the global pointer to be initialized prior to calling
    any shared library's initializers, so we use preinit_array to load it.
    This doesn't cut it for static links, though, since the global pointer