/* Statistics function. */
unsigned long int _dl_num_relocations;
-unsigned long int _dl_num_cache_relocations;
/* We have two different situations when looking up a simple: with or
const struct r_found_version *const version,
struct link_map *skip, int noexec, int noplt);
-struct lookup_cache _dl_lookup_cache;
-struct lookup_cache _dl_lookup_cache_versioned;
/* Search loaded objects' symbol tables for a definition of the symbol
UNDEF_NAME. */
const ElfW(Sym) **ref, struct r_scope_elem *symbol_scope[],
int reloc_type, int explicit)
{
- unsigned long int hash;
- struct sym_val current_value;
+ unsigned long int hash = _dl_elf_hash (undef_name);
+ struct sym_val current_value = { NULL, NULL };
struct r_scope_elem **scope;
int protected;
int noexec = elf_machine_lookup_noexec_p (reloc_type);
int noplt = elf_machine_lookup_noplt_p (reloc_type);
- /* First check if we can find it in the cache. */
- if (__builtin_expect (*ref == _dl_lookup_cache.sym, 0)
- && _dl_lookup_cache.map == undef_map
- && _dl_lookup_cache.noexec == noexec
- && _dl_lookup_cache.noplt == noplt)
- {
- ++_dl_num_cache_relocations;
- *ref = _dl_lookup_cache.ret;
- return _dl_lookup_cache.value;
- }
-
++_dl_num_relocations;
- hash = _dl_elf_hash (undef_name);
- current_value = ((struct sym_val) { NULL, NULL });
-
/* Search the relevant loaded objects for a definition. */
for (scope = symbol_scope; *scope; ++scope)
if (do_lookup (undef_name, hash, *ref, ¤t_value, *scope, 0, NULL,
in the global scope which was dynamically loaded. In this case
we have to prevent the latter from being unloaded unless the
UNDEF_MAP object is also unloaded. */
- if (__builtin_expect (current_value.m->l_global, 0)
- && (__builtin_expect (current_value.m->l_type, lt_library)
- == lt_loaded)
+ if (__builtin_expect (current_value.m->l_type == lt_loaded, 0)
+ && current_value.m->l_global
&& undef_map != current_value.m
/* Don't do this for explicit lookups as opposed to implicit
runtime lookups. */
- && __builtin_expect (! explicit, 1)
+ && ! explicit
/* Add UNDEF_MAP to the dependencies. */
&& add_dependency (undef_map, current_value.m) < 0)
/* Something went wrong. Perhaps the object we tried to reference
break;
}
- /* Update common information in the cache. */
- _dl_lookup_cache.sym = *ref;
- _dl_lookup_cache.noexec = noexec;
- _dl_lookup_cache.noplt = noplt;
-
if (__builtin_expect (current_value.s == NULL, 0))
{
const char *reference_name = undef_map ? undef_map->l_name : NULL;
? reference_name
: (_dl_argv[0] ?: "<main program>")),
make_string (undefined_msg, undef_name));
- _dl_lookup_cache.ret = NULL;
- _dl_lookup_cache.value = 0;
*ref = NULL;
return 0;
}
if (__builtin_expect (protected == 0, 1))
{
- _dl_lookup_cache.ret = current_value.s;
- _dl_lookup_cache.value = LOOKUP_VALUE (current_value.m);
*ref = current_value.s;
return LOOKUP_VALUE (current_value.m);
}
if (protected_value.s == NULL || protected_value.m == undef_map)
{
- _dl_lookup_cache.ret = current_value.s;
- _dl_lookup_cache.value = LOOKUP_VALUE (current_value.m);
*ref = current_value.s;
return LOOKUP_VALUE (current_value.m);
}
- _dl_lookup_cache.ret = *ref;
- _dl_lookup_cache.value = LOOKUP_VALUE (undef_map);
return LOOKUP_VALUE (undef_map);
}
const struct r_found_version *version,
int reloc_type, int explicit)
{
- unsigned long int hash;
- struct sym_val current_value;
+ unsigned long int hash = _dl_elf_hash (undef_name);
+ struct sym_val current_value = { NULL, NULL };
struct r_scope_elem **scope;
int protected;
int noexec = elf_machine_lookup_noexec_p (reloc_type);
int noplt = elf_machine_lookup_noplt_p (reloc_type);
- /* First check if we can find it in the cache. */
- if (__builtin_expect (*ref == _dl_lookup_cache_versioned.sym, 0)
- && _dl_lookup_cache_versioned.map == undef_map
- && _dl_lookup_cache_versioned.noexec == noexec
- && _dl_lookup_cache_versioned.noplt == noplt
- && _dl_lookup_cache_versioned.version == version)
- {
- ++_dl_num_cache_relocations;
- *ref = _dl_lookup_cache_versioned.ret;
- return _dl_lookup_cache_versioned.value;
- }
-
++_dl_num_relocations;
- hash = _dl_elf_hash (undef_name);
- current_value = ((struct sym_val) { NULL, NULL });
-
/* Search the relevant loaded objects for a definition. */
for (scope = symbol_scope; *scope; ++scope)
{
in the global scope which was dynamically loaded. In this case
we have to prevent the latter from being unloaded unless the
UNDEF_MAP object is also unloaded. */
- if (__builtin_expect (current_value.m->l_global, 0)
- && (__builtin_expect (current_value.m->l_type, lt_library)
- == lt_loaded)
+ if (__builtin_expect (current_value.m->l_type == lt_loaded, 0)
+ && current_value.m->l_global
&& undef_map != current_value.m
/* Don't do this for explicit lookups as opposed to implicit
runtime lookups. */
- && __builtin_expect (! explicit, 1)
+ && ! explicit
/* Add UNDEF_MAP to the dependencies. */
&& add_dependency (undef_map, current_value.m) < 0)
/* Something went wrong. Perhaps the object we tried to reference
}
}
- /* Update common information in the cache. */
- _dl_lookup_cache_versioned.sym = *ref;
- _dl_lookup_cache_versioned.noexec = noexec;
- _dl_lookup_cache_versioned.noplt = noplt;
- _dl_lookup_cache_versioned.version = version;
-
if (__builtin_expect (current_value.s == NULL, 0))
{
if (*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK)
", version ",
version->name ?: NULL));
}
-
- _dl_lookup_cache_versioned.ret = NULL;
- _dl_lookup_cache_versioned.value = 0;
*ref = NULL;
return 0;
}
if (__builtin_expect (protected == 0, 1))
{
- _dl_lookup_cache_versioned.ret = current_value.s;
- _dl_lookup_cache_versioned.value = LOOKUP_VALUE (current_value.m);
*ref = current_value.s;
return LOOKUP_VALUE (current_value.m);
}
if (protected_value.s == NULL || protected_value.m == undef_map)
{
- _dl_lookup_cache_versioned.ret = current_value.s;
- _dl_lookup_cache_versioned.value = LOOKUP_VALUE (current_value.m);
*ref = current_value.s;
return LOOKUP_VALUE (current_value.m);
}
- _dl_lookup_cache_versioned.ret = *ref;
- _dl_lookup_cache_versioned.value = LOOKUP_VALUE (undef_map);
return LOOKUP_VALUE (undef_map);
}
}
#include <sys/types.h>
#include "dynamic-link.h"
+/* Statistics function. */
+unsigned long int _dl_num_cache_relocations;
+
void
_dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
/* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code. */
#define RESOLVE_MAP(ref, version, flags) \
(ELFW(ST_BIND) ((*ref)->st_info) != STB_LOCAL \
- ? ((version) != NULL && (version)->hash != 0 \
- ? _dl_lookup_versioned_symbol (strtab + (*ref)->st_name, l, (ref), \
- scope, (version), (flags), 0) \
- : _dl_lookup_symbol (strtab + (*ref)->st_name, l, (ref), scope, \
- (flags), 0)) \
+ ? ((__builtin_expect ((*ref) == l->l_lookup_cache.sym, 0) \
+ && elf_machine_lookup_noexec_p (flags) == l->l_lookup_cache.noexec \
+ && elf_machine_lookup_noplt_p (flags) == l->l_lookup_cache.noplt) \
+ ? (++_dl_num_cache_relocations, \
+ (*ref) = l->l_lookup_cache.ret, \
+ l->l_lookup_cache.value) \
+ : ({ lookup_t _lr; \
+ l->l_lookup_cache.sym = (*ref); \
+ l->l_lookup_cache.noexec = elf_machine_lookup_noexec_p (flags); \
+ l->l_lookup_cache.noplt = elf_machine_lookup_noplt_p (flags); \
+ _lr = ((version) != NULL && (version)->hash != 0 \
+ ? _dl_lookup_versioned_symbol (strtab + (*ref)->st_name, \
+ l, (ref), scope, \
+ (version), (flags), 0) \
+ : _dl_lookup_symbol (strtab + (*ref)->st_name, l, (ref), \
+ scope, (flags), 0)); \
+ l->l_lookup_cache.ret = (*ref); \
+ l->l_lookup_cache.value = _lr; })) \
: l)
#define RESOLVE(ref, version, flags) \
(ELFW(ST_BIND) ((*ref)->st_info) != STB_LOCAL \
- ? ((version) != NULL && (version)->hash != 0 \
- ? _dl_lookup_versioned_symbol (strtab + (*ref)->st_name, l, (ref), \
- scope, (version), (flags), 0) \
- : _dl_lookup_symbol (strtab + (*ref)->st_name, l, (ref), scope, \
- (flags), 0)) \
+ ? ((__builtin_expect ((*ref) == l->l_lookup_cache.sym, 0) \
+ && elf_machine_lookup_noexec_p (flags) == l->l_lookup_cache.noexec \
+ && elf_machine_lookup_noplt_p (flags) == l->l_lookup_cache.noplt) \
+ ? (++_dl_num_cache_relocations, \
+ (*ref) = l->l_lookup_cache.ret, \
+ l->l_lookup_cache.value) \
+ : ({ lookup_t _lr; \
+ l->l_lookup_cache.sym = (*ref); \
+ l->l_lookup_cache.noexec = elf_machine_lookup_noexec_p (flags); \
+ l->l_lookup_cache.noplt = elf_machine_lookup_noplt_p (flags); \
+ _lr = ((version) != NULL && (version)->hash != 0 \
+ ? _dl_lookup_versioned_symbol (strtab + (*ref)->st_name, \
+ l, (ref), scope, \
+ (version), (flags), 0) \
+ : _dl_lookup_symbol (strtab + (*ref)->st_name, l, (ref), \
+ scope, (flags), 0)); \
+ l->l_lookup_cache.ret = (*ref); \
+ l->l_lookup_cache.value = _lr; })) \
: l->l_addr)
#include "dynamic-link.h"
- /* Start symbol lookup caching for this object. */
- _dl_lookup_cache.map = l;
- _dl_lookup_cache_versioned.map = l;
ELF_DYNAMIC_RELOCATE (l, lazy, consider_profiling);
- _dl_lookup_cache.map = NULL;
- _dl_lookup_cache_versioned.map = NULL;
-
if (__builtin_expect (consider_profiling, 0))
{
/* Allocate the array which will contain the already found