Commit Graph

73 Commits

Author SHA1 Message Date
kamil 33f6117993 Fix vax and mips build 2020-02-29 18:45:20 +00:00
kamil e8e477017a Implement DT_GNU_HASH
DT_GNU_HASH serves the same purpose as DT_HASH, however it is a distinct
and faster apprach implemented and designed in the GNU toolchain in 2006.

DT_GNU_HASH is preferred whenever available.

Original GNU benchmarks claim 50% faster dynamic linking time.
https://www.sourceware.org/ml/binutils/2006-06/msg00418.html

Code based on FreeBSD and OpenBSD, both were based on DragonFlyBSD.
2020-02-29 04:24:33 +00:00
kamil 4e9bea3d5d Implement and integrate GNU Hashing function
Define Elf_Hash struct that contains ELF/SYSV and GNU hash checksum.
Implement _rtld_gnu_hash() for DT_GNU_HASH.
Adapt existing code to compute all Elf_Hash types, instead of only
the ELF/SYSV one.
Rename _rtld_elf_hash() to _rtld_sysv_hash() to match the GNU toolchain
terminology.

_rtld_gnu_hash() uses Dan Bernstein's string hash function posted eons ago
on comp.lang.c.
2020-02-29 04:23:05 +00:00
kamil e5a904478f Separate matched symbol functionality out of _rtld_symlook_obj()
Simplifies the code and it will allow to use the matched symbol
functionality by other users.
2020-02-29 04:21:42 +00:00
joerg 493a7561e4 If a DF_1_NODELETE DSO has been removed from the DAG list, it still
needs to be able to resolve relocations against itself. As such, search
the referencing object explicitly last, if it hasn't been searched
before.
2017-08-09 18:44:32 +00:00
joerg e45d4ba084 Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.
The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.
2017-06-19 11:57:01 +00:00
christos f9f702d000 Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@
2016-12-01 14:29:15 +00:00
christos d32757ced4 Emulate the standard symbol search order in dlsym() i.e. resolve weak or
not found symbols that are in the dynamic linker list of exported symbols
from the dynamic linker itself.
2016-11-30 19:43:32 +00:00
matt 243b0ccea7 Don't provide __gnu_Unwind_Find_exidx if __ARM_DWARF_EH__ is defined 2014-08-10 23:35:26 +00:00
matt 22fbc67ed0 Don't resolve symbols to PLT entries on the VAX. It just causes a lot of
overhead.
2014-03-21 01:40:41 +00:00
skrll 653c73bf56 Remove trailing whitespace 2013-05-03 10:27:05 +00:00
matt 5417f425b2 Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.
2013-04-24 22:37:20 +00:00
matt e3dfed33b6 Add .init_array/.fini_array support (conditionalized on HAVE_INITFINI_ARRAY). 2012-08-15 03:46:06 +00:00
joerg 52a4c27e3e Add _dlauxinfo helper function to provide access to the ELF auxilary
vector. This can normally be found via __ps_strings, but libc is
initialised too early when linked dynamically and doesn't have access to
it yet, so provide an alternative mechanism via ld.elf_so.
Bump libc minor.
2012-02-16 23:00:38 +00:00
joerg 7878f85385 Replace if() NADA else if() NADA else continue logic with one explicit
block. Split out the MIPS handling to make it explicit and readable.
2011-11-25 14:39:02 +00:00
christos 9813f2c42a printing the pathname of the shared object is much more useful than the
object's address.
2011-08-13 22:24:57 +00:00
nonaka c52f9a5df2 PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.
2011-06-25 05:45:10 +00:00
joerg 854e6cd69f Add TLS support for AMD64, i386 and SH3.
This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
2011-03-12 22:54:36 +00:00
joerg aad599979d Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
2011-03-09 23:10:05 +00:00
skrll e6cdac9c4b Implement dl_iterate_phdr.
Somewhat taken from FreeBSD. Manual page from OpenBSD.
2010-10-16 10:27:06 +00:00
joerg ff0f2fb483 Use fast_remainder32 for the ELF hash. For the hot cache case, this
speeds up Firefox startup by over 2% on AMD64.
Limit hash table buckets to 32bit.
2010-04-05 14:01:26 +00:00
roy d5e8f757b8 Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.
2010-03-18 22:17:55 +00:00
roy b02ec7e9f8 Implement negative cache checks for symbol lookups.
Uses the Donelist idea from FreeBSD.
2010-02-27 11:16:38 +00:00
christos 12bd4dbd45 PR/39240: Satoshi Suetake: Don't fail when attempting to resolve weak symbols
when we are doing immediate binding, leave them alone and they will be dealt
with later during lazy binding. From skrll@
2010-01-13 20:17:21 +00:00
skrll 8f7db61734 Reset the COMBRELOC cache Obj_Entry if it was freed.
Fixes PR 41482. Done slightly differently to the patch in the PR.
2010-01-10 07:29:47 +00:00
pooka 4c1e54d82b Add Solarisa-like dlinfo() interface to the ELF dynamic linker.
Implement RTLD_DI_LINKMAP which returns a pointer to the linkmap
chain at the given object.  Other Solaris queries are currently
unimplemented.
2009-09-24 21:21:33 +00:00
skrll 8c9056ada8 lib/39649: dlsym(3) does not follow dependencies
Pull across code from FreeBSD to do a search of the passed object and it's
NEEDED objects (dependencies).

Reviewed by gimpy.
2008-10-04 09:37:12 +00:00
matt 38bdc8954f Refactor common code to _rtld_relocate_plt_object to i386 and arm so they
act like the other versions.
In _rtld_bind, if the result is 0, call _rtld_die.
Initialize _rtld_sym_zero.st_value to -_rtld_objself.maprelocbase.  Now when
the symbol is resolved, st_value + maprelocbase will equal 0 and the above
check in _rtld_bind will fire and a call to NULL will be avoided.
2008-07-24 04:39:25 +00:00
christos d3b459e727 abort() if we are trying to use an undefined weak symbol from the plt. Remove
check from relocate_plt_object() since we cannot return _rtld_sym_zero anymore.
Code from gimpy.
2008-07-23 18:16:42 +00:00
yamt 8c93baa802 constify 2008-01-14 08:53:42 +00:00
christos 5ad1b72097 print the symbol we are seaching for [when debugging] 2007-12-26 21:10:03 +00:00
matt 364993dede Don't use cached results for plt lookups (nor save them). 2007-02-23 01:16:32 +00:00
matt 4d10e5e667 Make the COMBRELOC support generic. 2007-02-22 18:57:48 +00:00
skrll bd7cbb198e Correct the lookup order of _rtld_symlook_default and make
_rtld_find_symdef use _rtld_symlook_default.

This reduces the code size and means that dlsym(RTLD_DEFAULT,...) has the
correct lookup order.

Reviewed by kleink. Thanks.
2005-10-13 11:14:09 +00:00
chs 14480c4191 in _rtld_is_exported(), use a function pointer type instead of Elf_Addr
so that hppa knows to do the plabel thang.
2005-05-10 13:15:56 +00:00
martin d7931a6191 Quote symbol names in a debug message (to make it easier to spot an empty
symbol name, a common failure mode)
2005-01-11 21:58:27 +00:00
skrll 2728318e3c Add __RCSIDs.
OK'd by mycroft.
2004-10-22 05:39:56 +00:00
thorpej 2a63e04007 - Change the strong dlfcn names in libc to ___name, and make the __name
versions used by others in libc weak, so that we have:
	name: weak
	__name: weak
	___name: strong
- Add __name strong aliases of the dlfcn names in ld.elf_so, so that we have:
	name: strong
	__name: strong

This allows ld.elf_so to self-resolve both the name and __name variants
of the dlfcn functions, the former being required for dlfcn support in
applications, the latter being required for dlfcn support in libc.

Fixes the problem described in:

    http://mail-index.netbsd.org/tech-toolchain/2004/07/17/0000.html

Reviewed by Nick.
2004-07-18 17:26:19 +00:00
mrauch f06ab72b6e Change the symbol lookup order to search RTLD_GLOBAL objects
before referencing object's DAG. This makes it possible for
C++ exceptions to work across shared libraries.

Patch taken from FreeBSD: src/libexec/rtld-elf/rtld.c: 1.67 -> 1.68,
committed there by kan@FreeBSD.org.
2003-12-07 09:36:06 +00:00
fvdl d83c6c4294 Don't use NULL for integers. 2003-10-21 01:19:10 +00:00
skrll d900731978 Resolve dlsym(3) and friends directly so that dlsym(RTLD_NEXT,...) works.
Previously dlsym resolved to the version in crt0.o or libc which would
mean that the caller's shared object couldn't be determined correctly
using __builtin_return_address(0).

Mainly from FreeBSD, but adapted by me. Benefits of this solutions are:

	- backward comptibility maintained
	- existing broken binaries are fixed with a new ld.elf_so
	- __mainprog_obj can be removed from crt0.o
	- we do the same thing as FreeBSD

Fixes PR 22067.

OKed by Jason and Christos.
2003-08-12 09:18:38 +00:00
skrll 59b0f10729 KNF 2003-08-05 19:41:53 +00:00
skrll 5f573ab68d ANSIfy and de-__P(). 2003-07-24 10:12:25 +00:00
skrll d4cfd1c666 s/_rltd_obj_rtld/_rtld_objself/ in #ifdef notyet code. 2003-07-15 07:39:55 +00:00
skrll 9192c2eed4 Whitespace 2003-07-15 07:38:29 +00:00
christos 683092605c Add RTLD_FIRST, RTLD_NEXT, RTLD_DEFAULT, from FreeBSD 2003-05-30 15:43:33 +00:00
mycroft f57f7ac072 Back out previous change for now -- it needs more work. 2003-04-24 16:55:29 +00:00
mycroft 8826c5e475 Attempt to give dlsym() the same symbol-searching semantics as _rtld_bind().
Tested in a handful of cases.
Reviewed by: a dead silence
2003-04-23 17:40:25 +00:00
mycroft ad8ccd6290 Minor cleanup. 2002-10-05 11:59:03 +00:00
mycroft 2a88686d7a Recode _rtld_elf_hash() so it compiles better (at least on i386 and arm).
Still could be better on i386, but only written in assembler...
2002-10-04 20:34:10 +00:00