[PATCH 02/11] Fix rtld link_map initialization issues

Aleksandar Rakic rakicaleksandar1999@gmail.com
Thu Jan 23 13:42:58 GMT 2025


Import patch fixing rtld link_map initialization issues from:
https://sourceware.org/ml/libc-alpha/2015-03/msg00704.html
Author: Sandra Loosemore

Cherry-picked 1507c7be47ef07d4b264168ab031d8c2ed4678f2
from https://github.com/MIPS/glibc

Signed-off-by: Matthew Fortune <matthew.fortune@imgtec.com>
Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Aleksandar Rakic <aleksandar.rakic@htecgroup.com>
---
 elf/rtld.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/elf/rtld.c b/elf/rtld.c
index 1e2e9ad5a8..252f4d6666 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -522,7 +522,7 @@ _dl_start (void *arg)
   rtld_timer_start (&info.start_time);
 #endif
 
-  /* Partly clean the `bootstrap_map' structure up.  Don't use
+  /* Zero-initialize the `bootstrap_map' structure.  Don't use
      `memset' since it might not be built in or inlined and we cannot
      make function calls at this point.  Use '__builtin_memset' if we
      know it is available.  We do not have to clear the memory if we
@@ -530,12 +530,14 @@ _dl_start (void *arg)
      are initialized to zero by default.  */
 #ifndef DONT_USE_BOOTSTRAP_MAP
 # ifdef HAVE_BUILTIN_MEMSET
-  __builtin_memset (bootstrap_map.l_info, '\0', sizeof (bootstrap_map.l_info));
+  __builtin_memset (&bootstrap_map, '\0', sizeof (struct link_map));
 # else
-  for (size_t cnt = 0;
-       cnt < sizeof (bootstrap_map.l_info) / sizeof (bootstrap_map.l_info[0]);
-       ++cnt)
-    bootstrap_map.l_info[cnt] = 0;
+  {
+    char *p = (char *) &bootstrap_map;
+    char *pend = p + sizeof (struct link_map);
+    while (p < pend)
+      *(p++) = '\0';
+  }
 # endif
 #endif
 
-- 
2.34.1



More information about the Libc-alpha mailing list