From 22bef64863b19cbe6057e680e2ae62b4f74432fd Mon Sep 17 00:00:00 2001 From: Stan Shebs Date: Thu, 18 Jan 2018 15:18:30 -0800 Subject: Un-nest nested functions in dynamic linker --- elf/dl-conflict.c | 27 +++++++++++++++++++++++++++ elf/dl-reloc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ elf/dynamic-link.h | 4 ++++ elf/get-dynamic-info.h | 10 ++++++++++ elf/rtld.c | 36 +++++++++++++++++++++++++++++++++++- 5 files changed, 120 insertions(+), 1 deletion(-) diff --git a/elf/dl-conflict.c b/elf/dl-conflict.c index 70f14b0..18e8f2e 100644 --- a/elf/dl-conflict.c +++ b/elf/dl-conflict.c @@ -27,6 +27,25 @@ #include #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) diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c index 053916e..0ed9398 100644 --- a/elf/dl-reloc.c +++ b/elf/dl-reloc.c @@ -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 diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h index 9e9d5a3..628df10 100644 --- a/elf/dynamic-link.h +++ b/elf/dynamic-link.h @@ -16,6 +16,10 @@ License along with the GNU C Library; if not, see . */ +#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 diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h index d1bbd81..f9c5b84 100644 --- a/elf/get-dynamic-info.h +++ b/elf/get-dynamic-info.h @@ -22,6 +22,8 @@ #include #include +#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 */ diff --git a/elf/rtld.c b/elf/rtld.c index 453f56e..aaf8c32 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -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 -- cgit v1.1