about summary refs log tree commit diff
path: root/elf/get-dynamic-info.h
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-10-15 14:35:31 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-10-18 09:51:56 -0300
commit5118dcac68c4eadfd6304bb33adde63d062dc07f (patch)
treea36d657aa4cf152f6eee05feac6d7171cb3816ad /elf/get-dynamic-info.h
parent1d3decee997ba2fc24af81803299b2f4f3c47063 (diff)
downloadglibc-5118dcac68c4eadfd6304bb33adde63d062dc07f.tar.gz
glibc-5118dcac68c4eadfd6304bb33adde63d062dc07f.tar.xz
glibc-5118dcac68c4eadfd6304bb33adde63d062dc07f.zip
elf: Fix elf_get_dynamic_info() for bootstrap
THe d6d89608ac8c broke powerpc for --enable-bind-now because it turned
out that different than patch assumption rtld elf_get_dynamic_info()
does require to handle RTLD_BOOTSTRAP to avoid DT_FLAGS and
DT_RUNPATH (more specially the GLRO usage which is not reallocate
yet).

This patch fixes by passing two arguments to elf_get_dynamic_info()
to inform that by rtld (bootstrap) or static pie initialization
(static_pie_bootstrap).  I think using explicit argument is way more
clear and burried C preprocessor, and compiler should remove the
dead code.

I checked on x86_64 and i686 with default options, --enable-bind-now,
and --enable-bind-now and --enable--static-pie.  I also check on
aarch64, armhf, powerpc64, and powerpc with default and
--enable-bind-now.
Diffstat (limited to 'elf/get-dynamic-info.h')
-rw-r--r--elf/get-dynamic-info.h95
1 files changed, 56 insertions, 39 deletions
diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h
index 1ac0663d1f..f63e07dc6d 100644
--- a/elf/get-dynamic-info.h
+++ b/elf/get-dynamic-info.h
@@ -26,7 +26,8 @@
 #include <libc-diag.h>
 
 static inline void __attribute__ ((unused, always_inline))
-elf_get_dynamic_info (struct link_map *l)
+elf_get_dynamic_info (struct link_map *l, bool bootstrap,
+		      bool static_pie_bootstrap)
 {
 #if __ELF_NATIVE_CLASS == 32
   typedef Elf32_Word d_tag_utype;
@@ -35,7 +36,7 @@ elf_get_dynamic_info (struct link_map *l)
 #endif
 
 #ifndef STATIC_PIE_BOOTSTRAP
-  if (l->l_ld == NULL)
+  if (!bootstrap && l->l_ld == NULL)
     return;
 #endif
 
@@ -112,47 +113,63 @@ elf_get_dynamic_info (struct link_map *l)
   if (info[DT_REL] != NULL)
     assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
 #endif
-#ifdef STATIC_PIE_BOOTSTRAP
-  assert (info[DT_RUNPATH] == NULL);
-  assert (info[DT_RPATH] == NULL);
-#endif
-  if (info[DT_FLAGS] != NULL)
+  if (bootstrap || static_pie_bootstrap)
     {
-      /* Flags are used.  Translate to the old form where available.
-	 Since these l_info entries are only tested for NULL pointers it
-	 is ok if they point to the DT_FLAGS entry.  */
-      l->l_flags = info[DT_FLAGS]->d_un.d_val;
-
-      if (l->l_flags & DF_SYMBOLIC)
-	info[DT_SYMBOLIC] = info[DT_FLAGS];
-      if (l->l_flags & DF_TEXTREL)
-	info[DT_TEXTREL] = info[DT_FLAGS];
-      if (l->l_flags & DF_BIND_NOW)
-	info[DT_BIND_NOW] = info[DT_FLAGS];
+      assert (info[DT_RUNPATH] == NULL);
+      assert (info[DT_RPATH] == NULL);
     }
-  if (info[VERSYMIDX (DT_FLAGS_1)] != NULL)
+  if (bootstrap)
     {
-      l->l_flags_1 = info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val;
-      if (l->l_flags_1 & DF_1_NODELETE)
-	l->l_nodelete_pending = true;
-
-      /* Only DT_1_SUPPORTED_MASK bits are supported, and we would like
-	 to assert this, but we can't. Users have been setting
-	 unsupported DF_1_* flags for a long time and glibc has ignored
-	 them. Therefore to avoid breaking existing applications the
-	 best we can do is add a warning during debugging with the
-	 intent of notifying the user of the problem.  */
-      if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0)
-	  && l->l_flags_1 & ~DT_1_SUPPORTED_MASK)
-	_dl_debug_printf ("\nWARNING: Unsupported flag value(s) of 0x%x in DT_FLAGS_1.\n",
-			  l->l_flags_1 & ~DT_1_SUPPORTED_MASK);
-
-      if (l->l_flags_1 & DF_1_NOW)
-	info[DT_BIND_NOW] = info[VERSYMIDX (DT_FLAGS_1)];
+      /* Only the bind now flags are allowed.  */
+      assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
+	      || (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
+      /* Flags must not be set for ld.so.  */
+      assert (info[DT_FLAGS] == NULL
+	      || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
     }
-  if (info[DT_RUNPATH] != NULL)
-    /* If both RUNPATH and RPATH are given, the latter is ignored.  */
-    info[DT_RPATH] = NULL;
+  else
+    {
+      if (info[DT_FLAGS] != NULL)
+	{
+	  /* Flags are used.  Translate to the old form where available.
+	     Since these l_info entries are only tested for NULL pointers it
+	     is ok if they point to the DT_FLAGS entry.  */
+	  l->l_flags = info[DT_FLAGS]->d_un.d_val;
+
+	  if (l->l_flags & DF_SYMBOLIC)
+	    info[DT_SYMBOLIC] = info[DT_FLAGS];
+	  if (l->l_flags & DF_TEXTREL)
+	    info[DT_TEXTREL] = info[DT_FLAGS];
+	  if (l->l_flags & DF_BIND_NOW)
+	    info[DT_BIND_NOW] = info[DT_FLAGS];
+	}
+
+      if (info[VERSYMIDX (DT_FLAGS_1)] != NULL)
+	{
+	  l->l_flags_1 = info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val;
+	  if (l->l_flags_1 & DF_1_NODELETE)
+	    l->l_nodelete_pending = true;
+
+	  /* Only DT_1_SUPPORTED_MASK bits are supported, and we would like
+	     to assert this, but we can't. Users have been setting
+	     unsupported DF_1_* flags for a long time and glibc has ignored
+	     them. Therefore to avoid breaking existing applications the
+	     best we can do is add a warning during debugging with the
+	     intent of notifying the user of the problem.  */
+	  if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0)
+	      && l->l_flags_1 & ~DT_1_SUPPORTED_MASK)
+	    _dl_debug_printf ("\nWARNING: Unsupported flag value(s) of 0x%x "
+			      "in DT_FLAGS_1.\n",
+			     l->l_flags_1 & ~DT_1_SUPPORTED_MASK);
+
+	 if (l->l_flags_1 & DF_1_NOW)
+	   info[DT_BIND_NOW] = info[VERSYMIDX (DT_FLAGS_1)];
+       }
+
+    if (info[DT_RUNPATH] != NULL)
+      /* If both RUNPATH and RPATH are given, the latter is ignored.  */
+      info[DT_RPATH] = NULL;
+   }
 }
 
 #endif