diff mbox series

[v3,12/32] elf: Move __rtld_malloc_init_stubs call into _dl_start_final

Message ID 6eab32e6135995d90fe989dd763c627cc9e8d9f5.1701944612.git.fweimer@redhat.com
State New
Headers show
Series RELRO linkmaps | expand

Commit Message

Florian Weimer Dec. 7, 2023, 10:31 a.m. UTC
Calling an extern function in a different translation unit before
self-relocation is brittle.  The compiler may load the address
at an earlier point in _dl_start, before self-relocation.  In
_dl_start_final, the call is behidn a compiler barrier, so this
cannot happen.
---
 elf/rtld.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Joseph Myers Feb. 22, 2024, 10:30 p.m. UTC | #1
On Thu, 7 Dec 2023, Florian Weimer wrote:

> Calling an extern function in a different translation unit before
> self-relocation is brittle.  The compiler may load the address
> at an earlier point in _dl_start, before self-relocation.  In
> _dl_start_final, the call is behidn a compiler barrier, so this
> cannot happen.

OK.
Andreas Schwab Feb. 22, 2024, 11:06 p.m. UTC | #2
On Dez 07 2023, Florian Weimer wrote:

> Calling an extern function in a different translation unit before
> self-relocation is brittle.  The compiler may load the address
> at an earlier point in _dl_start, before self-relocation.  In
> _dl_start_final, the call is behidn a compiler barrier, so this

s/behidn/behind/
diff mbox series

Patch

diff --git a/elf/rtld.c b/elf/rtld.c
index a00a8d9d0f..05cbcee24a 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -452,6 +452,8 @@  _dl_start_final (void *arg, struct dl_start_final_info *info)
 {
   ElfW(Addr) start_addr;
 
+  __rtld_malloc_init_stubs ();
+
   /* Do not use an initializer for these members because it would
      interfere with __rtld_static_init.  */
   GLRO (dl_find_object) = &_dl_find_object;
@@ -574,8 +576,6 @@  _dl_start (void *arg)
      function, that way the compiler cannot put accesses to the GOT
      before ELF_DYNAMIC_RELOCATE.  */
 
-  __rtld_malloc_init_stubs ();
-
 #ifdef DONT_USE_BOOTSTRAP_MAP
   return _dl_start_final (arg);
 #else