]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
riscv: add support for static PIE
authorAndreas Schwab <schwab@suse.de>
Wed, 17 Jan 2024 14:35:57 +0000 (15:35 +0100)
committerAndreas Schwab <schwab@suse.de>
Mon, 22 Jan 2024 13:58:23 +0000 (14:58 +0100)
In order to support static PIE the startup code must avoid relocations
before __libc_start_main is called.

sysdeps/riscv/start.S

index 0a1f7137429b8ffa9560f320ec9c964d0f58f5bf..ede186ef23b35b5af7c1c4ddf04b12519ed26e42 100644 (file)
@@ -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