]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Un-nest nested functions in dynamic linker
authorStan Shebs <stanshebs@google.com>
Thu, 18 Jan 2018 23:18:30 +0000 (15:18 -0800)
committerStan Shebs <stanshebs@google.com>
Thu, 25 Jan 2018 00:03:39 +0000 (16:03 -0800)
elf/dl-conflict.c
elf/dl-reloc.c
elf/dynamic-link.h
elf/get-dynamic-info.h
elf/rtld.c

index 70f14b04cd3830482e2161862b3252d695f89016..18e8f2edbc2c8724d32f06322e980d1239eea2eb 100644 (file)
 #include <sys/types.h>
 #include "dynamic-link.h"
 
+#ifndef NESTING
+
+
+    /* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code.  */
+#define RESOLVE_MAP(ref, version, flags) (*ref = NULL, NULL)
+#define RESOLVE(ref, version, flags) (*ref = NULL, 0)
+#define RESOLVE_CONFLICT_FIND_MAP(map, r_offset) \
+  do {                                                                       \
+    while ((resolve_conflict_map->l_map_end < (ElfW(Addr)) (r_offset))       \
+          || (resolve_conflict_map->l_map_start > (ElfW(Addr)) (r_offset)))  \
+      resolve_conflict_map = resolve_conflict_map->l_next;                   \
+                                                                             \
+    (map) = resolve_conflict_map;                                            \
+  } while (0)
+
+#include "dynamic-link.h"
+
+#endif /* n NESTING */
+
 void
 _dl_resolve_conflicts (struct link_map *l, ElfW(Rela) *conflict,
                       ElfW(Rela) *conflictend)
@@ -39,6 +58,8 @@ _dl_resolve_conflicts (struct link_map *l, ElfW(Rela) *conflict,
     /* Do the conflict relocation of the object and library GOT and other
        data.  */
 
+#ifdef NESTING
+
     /* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code.  */
 #define RESOLVE_MAP(ref, version, flags) (*ref = NULL, NULL)
 #define RESOLVE(ref, version, flags) (*ref = NULL, 0)
@@ -51,13 +72,19 @@ _dl_resolve_conflicts (struct link_map *l, ElfW(Rela) *conflict,
     (map) = resolve_conflict_map;                                            \
   } while (0)
 
+#endif /* NESTING */
+
     /* Prelinking makes no sense for anything but the main namespace.  */
     assert (l->l_ns == LM_ID_BASE);
     struct link_map *resolve_conflict_map __attribute__ ((__unused__))
       = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
 
+#ifdef NESTING
+
 #include "dynamic-link.h"
 
+#endif /* NESTING */
+
     /* Override these, defined in dynamic-link.h.  */
 #undef CHECK_STATIC_TLS
 #define CHECK_STATIC_TLS(ref_map, sym_map) ((void) 0)
index 053916eeae50467c3813ccfdfad5b5ef11ddd3f7..0ed9398ad0542bb8098829cba66eee793fe2a8a8 100644 (file)
@@ -141,6 +141,40 @@ _dl_nothread_init_static_tls (struct link_map *map)
          '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
 }
 
+#ifndef NESTING
+
+    /* String table object symbols.  */
+
+static struct link_map *glob_l;
+static struct r_scope_elem **glob_scope;
+static const char *glob_strtab;
+
+/* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code.  */
+#define RESOLVE_MAP(ref, version, r_type) \
+    ((ELFW(ST_BIND) ((*ref)->st_info) != STB_LOCAL                           \
+      && __glibc_likely (!dl_symbol_visibility_binds_local_p (*ref)))        \
+     ? ((__builtin_expect ((*ref) == glob_l->l_lookup_cache.sym, 0)                  \
+        && elf_machine_type_class (r_type) == glob_l->l_lookup_cache.type_class) \
+       ? (bump_num_cache_relocations (),                                     \
+          (*ref) = glob_l->l_lookup_cache.ret,                               \
+          glob_l->l_lookup_cache.value)                                              \
+       : ({ lookup_t _lr;                                                    \
+            int _tc = elf_machine_type_class (r_type);                       \
+            glob_l->l_lookup_cache.type_class = _tc;                         \
+            glob_l->l_lookup_cache.sym = (*ref);                                     \
+            const struct r_found_version *v = NULL;                          \
+            if ((version) != NULL && (version)->hash != 0)                   \
+              v = (version);                                                 \
+            _lr = _dl_lookup_symbol_x (glob_strtab + (*ref)->st_name, glob_l, (ref),   \
+                                       glob_scope, v, _tc,                           \
+                                       DL_LOOKUP_ADD_DEPENDENCY, NULL);      \
+            glob_l->l_lookup_cache.ret = (*ref);                                     \
+            glob_l->l_lookup_cache.value = _lr; }))                                  \
+     : glob_l)
+
+#include "dynamic-link.h"
+
+#endif /* n NESTING */
 
 void
 _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
@@ -227,6 +261,8 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
   {
     /* Do the actual relocation of the object's GOT and other data.  */
 
+#ifdef NESTING
+
     /* String table object symbols.  */
     const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
 
@@ -255,6 +291,14 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
 
 #include "dynamic-link.h"
 
+#else
+
+    glob_l = l;
+    glob_scope = scope;
+    glob_strtab = (const void *) D_PTR (glob_l, l_info[DT_STRTAB]);
+
+#endif /* NESTING */
+
     ELF_DYNAMIC_RELOCATE (l, lazy, consider_profiling, skip_ifunc);
 
 #ifndef PROF
index 9e9d5a3b28bc06c552a3a4605b8d2ef94e42228a..628df10739074046f3f70772a38da194413a236a 100644 (file)
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef NESTING
+#define auto static
+#endif
+
 /* 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
index d1bbd817be68a68a32b223d1d5943222f83bed03..f9c5b84d6a5d90e359c4a915047413390fd17f3a 100644 (file)
@@ -22,6 +22,8 @@
 #include <assert.h>
 #include <libc-diag.h>
 
+#if defined NESTING || !defined SAW_EGDI
+
 #ifndef RESOLVE_MAP
 static
 #else
@@ -184,3 +186,11 @@ elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp)
     info[DT_RPATH] = NULL;
 #endif
 }
+
+#endif
+
+#ifndef NESTING
+#ifndef SAW_EGDI
+#define SAW_EGDI
+#endif
+#endif /* n NESTING */
index 453f56eb157b1795c86f9eddd2df45fcab9a0a9b..aaf8c325959993f94be8add10acaff2712fc2ef0 100644 (file)
@@ -324,7 +324,7 @@ DL_SYSINFO_IMPLEMENTATION
    is fine, too.  The latter is important here.  We can avoid setting
    up a temporary link map for ld.so if we can mark _rtld_global as
    hidden.  */
-#ifdef PI_STATIC_AND_HIDDEN
+#if 0 //def PI_STATIC_AND_HIDDEN
 # define DONT_USE_BOOTSTRAP_MAP        1
 #endif
 
@@ -439,9 +439,27 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
   return start_addr;
 }
 
+#ifndef NESTING
+#ifdef DONT_USE_BOOTSTRAP_MAP
+# define bootstrap_map GL(dl_rtld_map)
+#else
+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(sym, version, flags) (&bootstrap_map)
+#include "dynamic-link.h"
+#endif /* n NESTING */
+
 static ElfW(Addr) __attribute_used__
 _dl_start (void *arg)
 {
+#ifdef NESTING
 #ifdef DONT_USE_BOOTSTRAP_MAP
 # define bootstrap_map GL(dl_rtld_map)
 #else
@@ -457,6 +475,7 @@ _dl_start (void *arg)
 #define BOOTSTRAP_MAP (&bootstrap_map)
 #define RESOLVE_MAP(sym, version, flags) BOOTSTRAP_MAP
 #include "dynamic-link.h"
+#endif /* NESTING */
 
   if (HP_TIMING_INLINE && HP_SMALL_TIMING_AVAIL)
 #ifdef DONT_USE_BOOTSTRAP_MAP
@@ -2785,3 +2804,18 @@ print_statistics (hp_timing_t *rtld_total_timep)
     }
 #endif
 }
+
+#ifndef NESTING
+char *dummy1 = (char *)elf_get_dynamic_info;
+# if ! ELF_MACHINE_NO_REL
+char *dummy2 = (char *)elf_machine_rel;
+char *dummy3 = (char *)elf_machine_rel_relative;
+#endif
+# if ! ELF_MACHINE_NO_RELA
+char *dummy4 = (char *)elf_machine_rela;
+char *dummy5 = (char *)elf_machine_rela_relative;
+#endif
+# if ELF_MACHINE_NO_RELA || defined ELF_MACHINE_PLT_REL
+char *dummy6 = (char *)elf_machine_lazy_rel;
+#endif
+#endif