glibc/backport-elf-Move-__rtld_malloc_init_stubs-call-into-_dl_star.patch
shixuantong 0b68e30fad sync some patches:
elf: avoid jumping over a needed declaration
    elf: Move __rtld_malloc_init_stubs call into _dl_start_final

(cherry picked from commit 6b2ec1fa1524750b9d8282baf3e13e739a0d5d80)
2024-11-29 14:12:42 +08:00

43 lines
1.3 KiB
Diff

From 2abfa1907218c5ec9d52bb81bee3f1af652f67c7 Mon Sep 17 00:00:00 2001
From: Florian Weimer <fweimer@redhat.com>
Date: Tue, 24 Sep 2024 13:23:10 +0200
Subject: [PATCH] elf: Move __rtld_malloc_init_stubs call into _dl_start_final
Reference:https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=2abfa1907218c5ec9d52bb81bee3f1af652f67c7
Conflict:NA
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 behind a compiler barrier, so this
cannot happen.
---
elf/rtld.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/elf/rtld.c b/elf/rtld.c
index 13b4134b..5a82c1ab 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -449,6 +449,8 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
{
ElfW(Addr) start_addr;
+ __rtld_malloc_init_stubs ();
+
/* If it hasn't happen yet record the startup time. */
rtld_timer_start (&start_time);
#if !defined DONT_USE_BOOTSTRAP_MAP
@@ -574,7 +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
--
2.33.0