diff options
author | Stan Shebs <stanshebs@google.com> | 2018-01-18 15:18:30 -0800 |
---|---|---|
committer | Stan Shebs <stanshebs@google.com> | 2019-04-24 09:06:59 -0700 |
commit | 868fc27ff4c37ae6e30ffc4ee78e5d2594998658 (patch) | |
tree | 2a29a30c0fbd1444603af2a6e4e5fe94f02bd477 | |
parent | fbf200117db8f703c05a6c2c53dc25d5b8dc080b (diff) | |
download | glibc-868fc27ff4c37ae6e30ffc4ee78e5d2594998658.tar.gz glibc-868fc27ff4c37ae6e30ffc4ee78e5d2594998658.tar.xz glibc-868fc27ff4c37ae6e30ffc4ee78e5d2594998658.zip |
Un-nest nested functions in dynamic linker
-rw-r--r-- | elf/dl-conflict.c | 27 | ||||
-rw-r--r-- | elf/dl-reloc.c | 44 | ||||
-rw-r--r-- | elf/dynamic-link.h | 4 | ||||
-rw-r--r-- | elf/get-dynamic-info.h | 10 | ||||
-rw-r--r-- | elf/rtld.c | 36 |
5 files changed, 120 insertions, 1 deletions
diff --git a/elf/dl-conflict.c b/elf/dl-conflict.c index bb8c228418..4178641e9a 100644 --- a/elf/dl-conflict.c +++ b/elf/dl-conflict.c @@ -27,6 +27,25 @@ #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) diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c index e7fb8da276..8e7986f112 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[], @@ -223,6 +257,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]); @@ -251,6 +287,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 454b0e388c..240ab4ad8e 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 <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 diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h index 0e4cc735f3..97b9f1508a 100644 --- a/elf/get-dynamic-info.h +++ b/elf/get-dynamic-info.h @@ -22,6 +22,8 @@ #include <assert.h> #include <libc-diag.h> +#if defined NESTING || !defined SAW_EGDI + #ifndef RESOLVE_MAP static #else @@ -183,3 +185,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 5d97f41b7b..75c740e34e 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -325,7 +325,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 @@ -440,9 +440,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 @@ -458,6 +476,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 @@ -2794,3 +2813,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 |