about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-load.c2
-rw-r--r--elf/dl-reloc-static-pie.c2
-rw-r--r--elf/dl-static-tls.h51
-rw-r--r--elf/dynamic-link.h33
-rw-r--r--elf/get-dynamic-info.h25
-rw-r--r--elf/rtld.c23
-rw-r--r--elf/setup-vdso.h2
7 files changed, 73 insertions, 65 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 335c79fad5..18d3e8fe64 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1298,7 +1298,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
   else
     l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
 
-  elf_get_dynamic_info (l, false);
+  elf_get_dynamic_info (l);
 
   /* Make sure we are not dlopen'ing an object that has the
      DF_1_NOOPEN flag set, or a PIE object.  */
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index 8a99c4995b..40a031f2e9 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -52,7 +52,7 @@ _dl_relocate_static_pie (void)
 	break;
       }
 
-  elf_get_dynamic_info (main_map, false);
+  elf_get_dynamic_info (main_map);
 
 # ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
   ELF_MACHINE_BEFORE_RTLD_RELOC (main_map, main_map->l_info);
diff --git a/elf/dl-static-tls.h b/elf/dl-static-tls.h
new file mode 100644
index 0000000000..730924fc01
--- /dev/null
+++ b/elf/dl-static-tls.h
@@ -0,0 +1,51 @@
+/* Inline functions for dynamic linking.
+   Copyright (C) 1995-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _DL_STATIC_TLS_H
+#define _DL_STATIC_TLS_H
+
+/* This macro is used as a callback from elf_machine_rel{a,} when a
+   static TLS reloc is about to be performed.  Since (in dl-load.c) we
+   permit dynamic loading of objects that might use such relocs, we
+   have to check whether each use is actually doable.  If the object
+   whose TLS segment the reference resolves to was allocated space in
+   the static TLS block at startup, then it's ok.  Otherwise, we make
+   an attempt to allocate it in surplus space on the fly.  If that
+   can't be done, we fall back to the error that DF_STATIC_TLS is
+   intended to produce.  */
+#define HAVE_STATIC_TLS(map, sym_map)					\
+    (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET		\
+		       && ((sym_map)->l_tls_offset			\
+			   != FORCED_DYNAMIC_TLS_OFFSET), 1))
+
+#define CHECK_STATIC_TLS(map, sym_map)					\
+    do {								\
+      if (!HAVE_STATIC_TLS (map, sym_map))				\
+	_dl_allocate_static_tls (sym_map);				\
+    } while (0)
+
+#define TRY_STATIC_TLS(map, sym_map)					\
+    (__builtin_expect ((sym_map)->l_tls_offset				\
+		       != FORCED_DYNAMIC_TLS_OFFSET, 1)			\
+     && (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1)	\
+	 || _dl_try_allocate_static_tls (sym_map, true) == 0))
+
+int _dl_try_allocate_static_tls (struct link_map *map, bool optional)
+  attribute_hidden;
+
+#endif
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
index 21cdfc88bb..ac4cc70dea 100644
--- a/elf/dynamic-link.h
+++ b/elf/dynamic-link.h
@@ -16,35 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-/* This macro is used as a callback from elf_machine_rel{a,} when a
-   static TLS reloc is about to be performed.  Since (in dl-load.c) we
-   permit dynamic loading of objects that might use such relocs, we
-   have to check whether each use is actually doable.  If the object
-   whose TLS segment the reference resolves to was allocated space in
-   the static TLS block at startup, then it's ok.  Otherwise, we make
-   an attempt to allocate it in surplus space on the fly.  If that
-   can't be done, we fall back to the error that DF_STATIC_TLS is
-   intended to produce.  */
-#define HAVE_STATIC_TLS(map, sym_map)					\
-    (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET		\
-		       && ((sym_map)->l_tls_offset			\
-			   != FORCED_DYNAMIC_TLS_OFFSET), 1))
-
-#define CHECK_STATIC_TLS(map, sym_map)					\
-    do {								\
-      if (!HAVE_STATIC_TLS (map, sym_map))				\
-	_dl_allocate_static_tls (sym_map);				\
-    } while (0)
-
-#define TRY_STATIC_TLS(map, sym_map)					\
-    (__builtin_expect ((sym_map)->l_tls_offset				\
-		       != FORCED_DYNAMIC_TLS_OFFSET, 1)			\
-     && (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1)	\
-	 || _dl_try_allocate_static_tls (sym_map, true) == 0))
-
-int _dl_try_allocate_static_tls (struct link_map *map, bool optional)
-  attribute_hidden;
-
+#include <dl-machine.h>
 #include <elf.h>
 
 #ifdef RESOLVE_MAP
@@ -91,9 +63,6 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
 # endif
 #endif
 
-#include <dl-machine.h>
-
-
 #ifdef RESOLVE_MAP
 
 # if defined RTLD_BOOTSTRAP || defined STATIC_PIE_BOOTSTRAP
diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h
index d169099fbc..1ac0663d1f 100644
--- a/elf/get-dynamic-info.h
+++ b/elf/get-dynamic-info.h
@@ -22,10 +22,11 @@
 #define _GET_DYNAMIC_INFO_H
 
 #include <assert.h>
+#include <dl-machine-rel.h>
 #include <libc-diag.h>
 
 static inline void __attribute__ ((unused, always_inline))
-elf_get_dynamic_info (struct link_map *l, bool check)
+elf_get_dynamic_info (struct link_map *l)
 {
 #if __ELF_NATIVE_CLASS == 32
   typedef Elf32_Word d_tag_utype;
@@ -33,7 +34,7 @@ elf_get_dynamic_info (struct link_map *l, bool check)
   typedef Elf64_Xword d_tag_utype;
 #endif
 
-#if !defined RTLD_BOOTSTRAP && !defined STATIC_PIE_BOOTSTRAP
+#ifndef STATIC_PIE_BOOTSTRAP
   if (l->l_ld == NULL)
     return;
 #endif
@@ -111,21 +112,10 @@ elf_get_dynamic_info (struct link_map *l, bool check)
   if (info[DT_REL] != NULL)
     assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
 #endif
-#ifdef RTLD_BOOTSTRAP
-  if (check)
-    {
-      /* 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);
-# ifdef STATIC_PIE_BOOTSTRAP
-      assert (info[DT_RUNPATH] == NULL);
-      assert (info[DT_RPATH] == NULL);
-# endif
-    }
-#else
+#ifdef STATIC_PIE_BOOTSTRAP
+  assert (info[DT_RUNPATH] == NULL);
+  assert (info[DT_RPATH] == NULL);
+#endif
   if (info[DT_FLAGS] != NULL)
     {
       /* Flags are used.  Translate to the old form where available.
@@ -163,7 +153,6 @@ elf_get_dynamic_info (struct link_map *l, bool check)
   if (info[DT_RUNPATH] != NULL)
     /* If both RUNPATH and RPATH are given, the latter is ignored.  */
     info[DT_RPATH] = NULL;
-#endif
 }
 
 #endif
diff --git a/elf/rtld.c b/elf/rtld.c
index fe5ee9ec4d..6cfb7cf672 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -32,7 +32,6 @@
 #include <fpu_control.h>
 #include <hp-timing.h>
 #include <libc-lock.h>
-#include "dynamic-link.h"
 #include <dl-librecon.h>
 #include <unsecvars.h>
 #include <dl-cache.h>
@@ -50,9 +49,18 @@
 #include <dl-main.h>
 #include <gnu/lib-names.h>
 #include <dl-tunables.h>
+#include <get-dynamic-info.h>
 
 #include <assert.h>
 
+/* This #define produces dynamic linking inline functions for
+   bootstrap relocation instead of general-purpose relocation.
+   Since ld.so must not have any undefined symbols the result
+   is trivial: always the map of ld.so itself.  */
+#define RTLD_BOOTSTRAP
+#define RESOLVE_MAP(map, scope, sym, version, flags) map
+#include "dynamic-link.h"
+
 /* Only enables rtld profiling for architectures which provides non generic
    hp-timing support.  The generic support requires either syscall
    (clock_gettime), which will incur in extra overhead on loading time.
@@ -507,15 +515,6 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
 # define bootstrap_map info.l
 #endif
 
-  /* This #define produces dynamic linking inline functions for
-     bootstrap relocation instead of general-purpose relocation.
-     Since ld.so must not have any undefined symbols the result
-     is trivial: always the map of ld.so itself.  */
-#define RTLD_BOOTSTRAP
-#define RESOLVE_MAP(map, scope, sym, version, flags) map
-#include "get-dynamic-info.h"
-#include "dynamic-link.h"
-
 static ElfW(Addr) __attribute_used__
 _dl_start (void *arg)
 {
@@ -548,7 +547,7 @@ _dl_start (void *arg)
 
   /* Read our own dynamic section and fill in the info array.  */
   bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
-  elf_get_dynamic_info (&bootstrap_map, true);
+  elf_get_dynamic_info (&bootstrap_map);
 
 #if NO_TLS_OFFSET != 0
   bootstrap_map.l_tls_offset = NO_TLS_OFFSET;
@@ -1616,7 +1615,7 @@ dl_main (const ElfW(Phdr) *phdr,
   if (! rtld_is_main)
     {
       /* Extract the contents of the dynamic section for easy access.  */
-      elf_get_dynamic_info (main_map, false);
+      elf_get_dynamic_info (main_map);
 
       /* If the main map is libc.so, update the base namespace to
 	 refer to this map.  If libc.so is loaded later, this happens
diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
index 6fdffafcca..f44748bc98 100644
--- a/elf/setup-vdso.h
+++ b/elf/setup-vdso.h
@@ -64,7 +64,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
       l->l_map_end += l->l_addr;
       l->l_text_end += l->l_addr;
       l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
-      elf_get_dynamic_info (l, false);
+      elf_get_dynamic_info (l);
       _dl_setup_hash (l);
       l->l_relocated = 1;