mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-11 10:33:33 +08:00
f41c80910d
1997-08-24 12:24 Ulrich Drepper <drepper@cygnus.com> * configure.in (INSTALL): Quote `$'. * libc.map: Add __xpg_basename. * csu/Makefile (initfini.s): Disable optimization. * elf/dl-deps.c: Implement handling of DL_FILTER. * elf/dl-load.c (_dl_init_paths): Add error check. * intl/finddomain.c (_nl_find_domain): Correct comment. * intl/localealias.c: Include <bits/libc-lock.h> not <libc-lock.h>. * libio/stdio.h: Make {,v}snprintf available if __USE_BSD. Change extern inline functions to work correctly in C++. * locale/iso-4217.def: Update for more recent ISO 4217 version. * locale/loadlocale.c (_nl_load_locale): Add cast. * manual/message.texi: Finish gettext section. * posix/getopt_init.c: Don't use relative #include path. (__getopt_clean_environment): Change function to take pointer to environment as argument. Optimize generation of test string a bit. * sysdeps/unix/sysv/linux/init-first.c: Call __getopt_clean_environment with additional argument. * poisx/glob.c: Add prototype for next_brace_sub. * sysdeps/generic/dl-sysdep.c: Recognize AT_BASE value on auxiliary vector. * sysdeps/i386/dl-machine.h (elf_machine_load_address): Rewrite to not generate relocation entry. Suggested by Richard Henderson. (ELF_MACHINE_BEFORE_RTLD_RELOC): Removed. (elf_machine_runtime_setup): Add .aligns. * sysdeps/i386/fpu/fraiseexcpt.c: Add volatile to asms. * sysdeps/i386/fpu/bits/mathinline.h: Partially undo change of 1997-08-14 03:14. gcc 2.7.2* is really broken in some aspects. * sysdeps/standalone/i386/i386.h: Clean up asm statements a bit. * sysdeps/standalone/i960/i960ca.h: Likewise. 1997-08-22 19:04 Richard Henderson <rth@cygnus.com> * elf/rtld.c (_dl_start): Init _dl_rtld_map.l_opencount due to undocumented test addition in _dl_map_object. Support ET_EXEC versions of ld.so, for debugging at least: * elf/dl-load.c (_dl_map_object): Add_name_to_object could get called despite the DT_SONAME != NULL test, segfaulting. Simplify the code here as well. * elf/dl-lookup.c (do_lookup): Skip objects with no symtab. (_dl_setup_hash): Likewise for hash tables. * elf/dl-version.c (_dl_check_map_versions): Likewise for strtabs. * elf/rtld.c (_dl_start): Likewise for rpath. (_dl_rtld_libname2): New variable. (dl_main): Use it to add an soname for ourselves when we don't have one of our own. Base it on the target's .interp. (dl_main): Again, skip printing of objects that don't have strtabs. Sparc 32 merge: * elf/dl-runtime.c (ELF_FIXUP_RETURN_VALUE): Provide default value. (fixup): Simplify code. Use ELF_FIXUP_RETURN_VALUE. (profile_fixup): Likewise, though this still needs fixing for Sparc32 and PPC. * sysdeps/powerpc/dl-machine.h: Transmute ELF_FIXUP_RETURNS_ADDRESS to ELF_FIXUP_RETURN_VALUE. * sysdeps/sparc/sparc32/dl-machine.h: Implement lazy relocation. Fix up _dl_start_user to handle _dl_skip_args properly. Use _dl_hwcap to determine if "flush" is available/needed. * sysdeps/sparc/configure.in: Remove. It doesn't actually do anything anymore, and what it did do is done somewhere else. * sysdeps/sparc/configure: Likewise. * sysdeps/sparc/fpu/bits/mathdef.h (FP_ILOGB0, FP_ILOGBNAN): New. * sysdeps/sparc/fpu/fraiseexcpt.c: Rearrange for smaller code. * sysdeps/sparc/sparc32/Makefile: Fix sparc->sparc/sparc32 bits in divrem expansions. * sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h (END, LOC): New definitions for assembly syntax differences. * sysdeps/sparc/sparc32/__longjmp.S: %g6,%g7 are reserved to the "system". Use %g2,%g3 instead. Use new local label macro. * sysdeps/sparc/sparc32/add_n.S: Use <sysdep.h> and ENTRY, END, and LOC for proper assembly headers/footers. * sysdeps/sparc/sparc32/addmul_1.S: Likewise. * sysdeps/sparc/sparc32/alloca.S: Likewise. * sysdeps/sparc/sparc32/dotmul.S: Likewise. * sysdeps/sparc/sparc32/lshift.S: Likewise. * sysdeps/sparc/sparc32/mul_1.S: Likewise. * sysdeps/sparc/sparc32/rshift.S: Likewise. * sysdeps/sparc/sparc32/sparcv8/addmul_1.S: Likewise. * sysdeps/sparc/sparc32/sparcv8/mul_1.S: Likewise. * sysdeps/sparc/sparc32/sparcv8/submul_1.S: Likewise. * sysdeps/sparc/sparc32/sparcv8/udiv_qrnnd.S: Likewise. * sysdeps/sparc/sparc32/sub_n.S: Likewise. * sysdeps/sparc/sparc32/submul_1.S: Likewise. * sysdeps/sparc/sparc32/udiv_qrnnd.S: Likewise. * sysdeps/sparc/sparc32/umul.S: Likewise. * sysdeps/sparc/sparc32/divrem.m4: Likewise. * sysdeps/sparc/sparc32/rem.S: Regenerate. * sysdeps/sparc/sparc32/sdiv.S: Regenerate. * sysdeps/sparc/sparc32/udiv.S: Regenerate. * sysdeps/sparc/sparc32/urem.S: Regenerate. * sysdeps/sparc/sparc32/sparcv8/dotmul.S: New file. * sysdeps/sparc/sparc32/sparcv8/rem.S: New file. * sysdeps/sparc/sparc32/sparcv8/sdiv.S: New file. * sysdeps/sparc/sparc32/sparcv8/udiv.S: New file. * sysdeps/sparc/sparc32/sparcv8/umul.S: New file. * sysdeps/sparc/sparc32/sparcv8/urem.S: New file. * sysdeps/sparc/sparc32/bsd-_setjmp.S: Dike out. * sysdeps/sparc/sparc32/bsd-setjmp.S: Likewise. * sysdeps/sparc/sparc32/setjmp.S: Add _setjmp and setjmp entry points. * sysdeps/unix/sysv/linux/sparc/sparc32/__sigtrampoline.S: Clean up PIC code. * sysdeps/sparc/sparc32/elf/start.S: New file, slightly modified from the sparc64 version. * sysdeps/sparc/sparc32/elf/start.c: Removed. * sysdeps/unix/sysv/linux/sparc/sparc32/init-first.h: Rewrite in assembly based on the sparc64 version. * sysdeps/sparc/sparc32/fpu/bits/fenv.h: Duh. Use proper syntax for manipulating %fsr. * sysdeps/sparc/sparc32/fpu/fpu_control.h: Make IEEE conformance be the default. * elf/elf.h (HWCAP_SPARC_*): New definitions. * elf/rtld.c (_dl_hwcap): New variable. * sysdeps/generic/dl-sysdep.c (_dl_sysdep_start): Record AT_HWCAP. * sysdeps/unix/sysv/linux/sparc/sparc32/getpagesize.c: New file. Attempt to get hold of the page size based on what we might have been told at startup time in _dl_pagesize. This will be obsolete when I finish the kernel hooks for a proper sysconf(), stay tuned. Sparc 64 merge: * sysdeps/sparc/sparc64/dl-machine.h (ELF_FIXUP_RETURN_VALUE): New. Figure out the right thing to return based on the .plt format. * sysdeps/sparc/sparc64/fpu/fpu_control.h: Update comment. * sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h (__dev_t): Should have been 64-bits wide. * sysdeps/unix/sysv/linux/sparc/sparc64/init-first.h: sll->sllx, optimize for branch delay slot usage. 1997-08-22 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * csu/Makefile ($(objpfx)crt%.o): Fix a missing *.so -> *.os change. 1997-08-20 Andreas Jaeger <aj@arthur.rhein-neckar.de> * math/libm-test.c (identities): Change epsilon. * sysdeps/i386/fpu/bits/mathinline.h: Correct arguments to fabs, fabsf, fabsl, __fabsl. * sysdeps/libm-i387/e_remainderl.S: Pop extra value from FPU stack. * sysdeps/libm-ieee754/s_csinhl.c: Include <fenv.h>.
384 lines
12 KiB
C
384 lines
12 KiB
C
/* Look up a symbol in the loaded objects.
|
|
Copyright (C) 1995, 1996, 1997 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 Library General Public License as
|
|
published by the Free Software Foundation; either version 2 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
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
#include <alloca.h>
|
|
#include <stddef.h>
|
|
#include <link.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
#include "dl-hash.h"
|
|
#include <dl-machine.h>
|
|
#include <stdio-common/_itoa.h>
|
|
|
|
#define VERSTAG(tag) (DT_NUM + DT_PROCNUM + DT_VERSIONTAGIDX (tag))
|
|
|
|
/* We need this string more than once. */
|
|
static const char undefined_msg[] = "undefined symbol: ";
|
|
|
|
|
|
struct sym_val
|
|
{
|
|
ElfW(Addr) a;
|
|
const ElfW(Sym) *s;
|
|
};
|
|
|
|
|
|
#define make_string(string, rest...) \
|
|
({ \
|
|
const char *all[] = { string, ## rest }; \
|
|
size_t len, cnt; \
|
|
char *result, *cp; \
|
|
\
|
|
len = 1; \
|
|
for (cnt = 0; cnt < sizeof (all) / sizeof (all[0]); ++cnt) \
|
|
len += strlen (all[cnt]); \
|
|
\
|
|
cp = result = alloca (len); \
|
|
for (cnt = 0; cnt < sizeof (all) / sizeof (all[0]); ++cnt) \
|
|
cp = stpcpy (cp, all[cnt]); \
|
|
\
|
|
result; \
|
|
})
|
|
|
|
|
|
/* Inner part of the lookup functions. We return a value > 0 if we
|
|
found the symbol, the value 0 if nothing is found and < 0 if
|
|
something bad happened. */
|
|
static inline int
|
|
do_lookup (const char *undef_name, unsigned long int hash,
|
|
const ElfW(Sym) *ref, struct sym_val *result,
|
|
struct link_map *list[], size_t i, size_t n,
|
|
const char *reference_name, const struct r_found_version *version,
|
|
struct link_map *skip, int reloc_type)
|
|
{
|
|
struct link_map *map;
|
|
|
|
for (; i < n; ++i)
|
|
{
|
|
const ElfW(Sym) *symtab;
|
|
const char *strtab;
|
|
const ElfW(Half) *verstab;
|
|
ElfW(Symndx) symidx;
|
|
|
|
map = list[i];
|
|
|
|
/* Here come the extra test needed for `_dl_lookup_symbol_skip'. */
|
|
if (skip != NULL && map == skip)
|
|
continue;
|
|
|
|
/* Skip objects that could not be opened, which can occur in trace
|
|
mode. */
|
|
if (map->l_opencount == 0)
|
|
continue;
|
|
|
|
/* Don't search the executable when resolving a copy reloc. */
|
|
if (elf_machine_lookup_noexec_p (reloc_type) &&
|
|
map->l_type == lt_executable)
|
|
continue;
|
|
|
|
/* Skip objects without symbol tables. */
|
|
if (map->l_info[DT_SYMTAB] == NULL)
|
|
continue;
|
|
|
|
symtab = ((void *) map->l_addr + map->l_info[DT_SYMTAB]->d_un.d_ptr);
|
|
strtab = ((void *) map->l_addr + map->l_info[DT_STRTAB]->d_un.d_ptr);
|
|
if (map->l_nversions > 0 && map->l_info[VERSTAG (DT_VERSYM)] != NULL)
|
|
verstab = ((void *) map->l_addr
|
|
+ map->l_info[VERSTAG (DT_VERSYM)]->d_un.d_ptr);
|
|
else
|
|
verstab = NULL;
|
|
|
|
/* Search the appropriate hash bucket in this object's symbol table
|
|
for a definition for the same symbol name. */
|
|
for (symidx = map->l_buckets[hash % map->l_nbuckets];
|
|
symidx != STN_UNDEF;
|
|
symidx = map->l_chain[symidx])
|
|
{
|
|
const ElfW(Sym) *sym = &symtab[symidx];
|
|
|
|
if (sym->st_value == 0 || /* No value. */
|
|
(elf_machine_lookup_noplt_p (reloc_type) /* Reject PLT entry. */
|
|
&& sym->st_shndx == SHN_UNDEF))
|
|
continue;
|
|
|
|
if (ELFW(ST_TYPE) (sym->st_info) > STT_FUNC)
|
|
/* Ignore all but STT_NOTYPE, STT_OBJECT and STT_FUNC entries
|
|
since these are no code/data definitions. */
|
|
continue;
|
|
|
|
if (sym != ref && strcmp (strtab + sym->st_name, undef_name))
|
|
/* Not the symbol we are looking for. */
|
|
continue;
|
|
|
|
if (version == NULL)
|
|
{
|
|
/* No specific version is selected. When the object
|
|
file also does not define a version we have a match.
|
|
Otherwise we only accept the default version, i.e.,
|
|
the version which name is "". */
|
|
if (verstab != NULL)
|
|
{
|
|
ElfW(Half) ndx = verstab[symidx] & 0x7fff;
|
|
if (ndx > 2) /* map->l_versions[ndx].hash != 0) */
|
|
continue;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (verstab == NULL)
|
|
{
|
|
/* We need a versioned system but haven't found any.
|
|
If this is the object which is referenced in the
|
|
verneed entry it is a bug in the library since a
|
|
symbol must not simply disappear. */
|
|
if (version->filename != NULL
|
|
&& _dl_name_match_p (version->filename, map))
|
|
return -2;
|
|
/* Otherwise we accept the symbol. */
|
|
}
|
|
else
|
|
{
|
|
/* We can match the version information or use the
|
|
default one. */
|
|
ElfW(Half) ndx = verstab[symidx] & 0x7fff;
|
|
if ((map->l_versions[ndx].hash != version->hash
|
|
|| strcmp (map->l_versions[ndx].name, version->name))
|
|
&& (version->hidden || map->l_versions[ndx].hash))
|
|
/* It's not the version we want. */
|
|
continue;
|
|
}
|
|
}
|
|
|
|
switch (ELFW(ST_BIND) (sym->st_info))
|
|
{
|
|
case STB_GLOBAL:
|
|
/* Global definition. Just what we need. */
|
|
result->s = sym;
|
|
result->a = map->l_addr;
|
|
return 1;
|
|
case STB_WEAK:
|
|
/* Weak definition. Use this value if we don't find
|
|
another. */
|
|
if (! result->s)
|
|
{
|
|
result->s = sym;
|
|
result->a = map->l_addr;
|
|
}
|
|
break;
|
|
default:
|
|
/* Local symbols are ignored. */
|
|
break;
|
|
}
|
|
|
|
/* There cannot be another entry for this symbol so stop here. */
|
|
break;
|
|
}
|
|
|
|
/* If this current map is the one mentioned in the verneed entry
|
|
and we have not found a weak entry, it is a bug. */
|
|
if (symidx == STN_UNDEF && version != NULL && version->filename != NULL
|
|
&& _dl_name_match_p (version->filename, map))
|
|
return -1;
|
|
}
|
|
|
|
/* We have not found anything until now. */
|
|
return 0;
|
|
}
|
|
|
|
/* Search loaded objects' symbol tables for a definition of the symbol
|
|
UNDEF_NAME. */
|
|
|
|
ElfW(Addr)
|
|
_dl_lookup_symbol (const char *undef_name, const ElfW(Sym) **ref,
|
|
struct link_map *symbol_scope[],
|
|
const char *reference_name,
|
|
int reloc_type)
|
|
{
|
|
const unsigned long int hash = _dl_elf_hash (undef_name);
|
|
struct sym_val current_value = { 0, NULL };
|
|
struct link_map **scope;
|
|
|
|
/* Search the relevant loaded objects for a definition. */
|
|
for (scope = symbol_scope; *scope; ++scope)
|
|
if (do_lookup (undef_name, hash, *ref, ¤t_value,
|
|
(*scope)->l_searchlist, 0, (*scope)->l_nsearchlist,
|
|
reference_name, NULL, NULL, reloc_type))
|
|
break;
|
|
|
|
if (current_value.s == NULL &&
|
|
(*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK))
|
|
/* We could find no value for a strong reference. */
|
|
_dl_signal_error (0, reference_name,
|
|
make_string (undefined_msg, undef_name));
|
|
|
|
*ref = current_value.s;
|
|
return current_value.a;
|
|
}
|
|
|
|
|
|
/* This function is nearly the same as `_dl_lookup_symbol' but it
|
|
skips in the first list all objects until SKIP_MAP is found. I.e.,
|
|
it only considers objects which were loaded after the described
|
|
object. If there are more search lists the object described by
|
|
SKIP_MAP is only skipped. */
|
|
ElfW(Addr)
|
|
_dl_lookup_symbol_skip (const char *undef_name, const ElfW(Sym) **ref,
|
|
struct link_map *symbol_scope[],
|
|
const char *reference_name,
|
|
struct link_map *skip_map)
|
|
{
|
|
const unsigned long int hash = _dl_elf_hash (undef_name);
|
|
struct sym_val current_value = { 0, NULL };
|
|
struct link_map **scope;
|
|
size_t i;
|
|
|
|
/* Search the relevant loaded objects for a definition. */
|
|
scope = symbol_scope;
|
|
for (i = 0; (*scope)->l_dupsearchlist[i] != skip_map; ++i)
|
|
assert (i < (*scope)->l_ndupsearchlist);
|
|
|
|
if (! do_lookup (undef_name, hash, *ref, ¤t_value,
|
|
(*scope)->l_dupsearchlist, i, (*scope)->l_ndupsearchlist,
|
|
reference_name, NULL, skip_map, 0))
|
|
while (*++scope)
|
|
if (do_lookup (undef_name, hash, *ref, ¤t_value,
|
|
(*scope)->l_dupsearchlist, 0, (*scope)->l_ndupsearchlist,
|
|
reference_name, NULL, skip_map, 0))
|
|
break;
|
|
|
|
*ref = current_value.s;
|
|
return current_value.a;
|
|
}
|
|
|
|
|
|
/* This function works like _dl_lookup_symbol but it takes an
|
|
additional arguement with the version number of the requested
|
|
symbol.
|
|
|
|
XXX We'll see whether we need this separate function. */
|
|
ElfW(Addr)
|
|
_dl_lookup_versioned_symbol (const char *undef_name, const ElfW(Sym) **ref,
|
|
struct link_map *symbol_scope[],
|
|
const char *reference_name,
|
|
const struct r_found_version *version,
|
|
int reloc_type)
|
|
{
|
|
const unsigned long int hash = _dl_elf_hash (undef_name);
|
|
struct sym_val current_value = { 0, NULL };
|
|
struct link_map **scope;
|
|
|
|
/* Search the relevant loaded objects for a definition. */
|
|
for (scope = symbol_scope; *scope; ++scope)
|
|
{
|
|
int res = do_lookup (undef_name, hash, *ref, ¤t_value,
|
|
(*scope)->l_searchlist, 0, (*scope)->l_nsearchlist,
|
|
reference_name, version, NULL, reloc_type);
|
|
if (res > 0)
|
|
break;
|
|
|
|
if (res < 0)
|
|
/* Oh, oh. The file named in the relocation entry does not
|
|
contain the needed symbol. */
|
|
_dl_signal_error (0, reference_name,
|
|
make_string ("symbol ", undef_name, ", version ",
|
|
version->name,
|
|
" not defined in file ",
|
|
version->filename,
|
|
" with link time reference",
|
|
res == -2
|
|
? " (no version symbols)" : ""));
|
|
}
|
|
|
|
if (current_value.s == NULL &&
|
|
(*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK))
|
|
/* We could find no value for a strong reference. */
|
|
_dl_signal_error (0, reference_name,
|
|
make_string (undefined_msg, undef_name,
|
|
", version ", version->name ?: NULL));
|
|
|
|
*ref = current_value.s;
|
|
return current_value.a;
|
|
}
|
|
|
|
|
|
/* Similar to _dl_lookup_symbol_skip but takes an additional argument
|
|
with the version we are looking for. */
|
|
ElfW(Addr)
|
|
_dl_lookup_versioned_symbol_skip (const char *undef_name,
|
|
const ElfW(Sym) **ref,
|
|
struct link_map *symbol_scope[],
|
|
const char *reference_name,
|
|
const struct r_found_version *version,
|
|
struct link_map *skip_map)
|
|
{
|
|
const unsigned long int hash = _dl_elf_hash (undef_name);
|
|
struct sym_val current_value = { 0, NULL };
|
|
struct link_map **scope;
|
|
size_t i;
|
|
|
|
/* Search the relevant loaded objects for a definition. */
|
|
scope = symbol_scope;
|
|
for (i = 0; (*scope)->l_dupsearchlist[i] != skip_map; ++i)
|
|
assert (i < (*scope)->l_ndupsearchlist);
|
|
|
|
if (! do_lookup (undef_name, hash, *ref, ¤t_value,
|
|
(*scope)->l_dupsearchlist, i, (*scope)->l_ndupsearchlist,
|
|
reference_name, version, skip_map, 0))
|
|
while (*++scope)
|
|
if (do_lookup (undef_name, hash, *ref, ¤t_value,
|
|
(*scope)->l_dupsearchlist, 0, (*scope)->l_ndupsearchlist,
|
|
reference_name, version, skip_map, 0))
|
|
break;
|
|
|
|
if (current_value.s == NULL &&
|
|
(*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK))
|
|
{
|
|
/* We could find no value for a strong reference. */
|
|
const size_t len = strlen (undef_name);
|
|
char buf[sizeof undefined_msg + len];
|
|
memcpy (buf, undefined_msg, sizeof undefined_msg - 1);
|
|
memcpy (&buf[sizeof undefined_msg - 1], undef_name, len + 1);
|
|
_dl_signal_error (0, reference_name, buf);
|
|
}
|
|
|
|
*ref = current_value.s;
|
|
return current_value.a;
|
|
}
|
|
|
|
|
|
/* Cache the location of MAP's hash table. */
|
|
|
|
void
|
|
_dl_setup_hash (struct link_map *map)
|
|
{
|
|
ElfW(Symndx) *hash;
|
|
ElfW(Symndx) nchain;
|
|
|
|
if (!map->l_info[DT_HASH])
|
|
return;
|
|
hash = (void *)(map->l_addr + map->l_info[DT_HASH]->d_un.d_ptr);
|
|
|
|
map->l_nbuckets = *hash++;
|
|
nchain = *hash++;
|
|
map->l_buckets = hash;
|
|
hash += map->l_nbuckets;
|
|
map->l_chain = hash;
|
|
}
|