summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/i386/reloc.c
Commit message (Collapse)AuthorAgeFilesLines
* Do not call callbacks for dl_iterate_phdr(3) with the rtld bind andkib2016-01-201-1/+2
| | | | | | | | | | | | | | | | | | phdr locks locked. This allows to call rtld services from the callback, which is only reasonable for dlopen(path, RTLD_NOLOAD) to test existence of the library in the image, and for dlsym(). The later might still be not quite safe, due to the lazy resolution of filters. To allow dropping the locks around iteration in dl_iterate_phdr(3), we insert markers to track current position between relocks. The global objects list is converted to tailq and all iterators skip markers, globallist_next() and globallist_curr() helpers are added. Reported and tested by: davide Reviewed by: kan Sponsored by: The FreeBSD Foundation MFC after: 3 weeks
* Change compiler setting to make default visibility of the symbols forkib2015-03-291-0/+1
| | | | | | | | | | | rtld on x86 to be hidden. This is a micro-optimization, which allows intrinsic references inside rtld to be handled without indirection through PLT. The visibility of rtld symbols for other objects in the symbol namespace is controlled by a version script. Reviewed by: kan, jilles Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* Optimize r270798, only do the second pass over non-plt relocationskib2014-08-291-1/+3
| | | | | | | when the first pass found IFUNCs. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* IFUNC symbol type shall be processed for non-PLT relocations,kib2014-08-291-144/+118
| | | | | | | | | | | | | | | | | | | e.g. when a global variable is initialized with a pointer to ifunc. Add symbol type check and call resolver for STT_GNU_IFUNC symbol types when processing non-PLT relocations, but only after non-IFUNC relocations are done. The two-phase proceessing is required since resolvers may reference other symbols, which must be ready to use when resolver calls are done. Restructure reloc_non_plt() on x86 to call find_symdef() and handle IFUNC in single place. For non-x86 reloc_non_plt(), check for call for IFUNC relocation and do nothing, to avoid processing relocs twice. PR: 193048 Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* Add GNU hash support for rtld.kib2012-04-301-1/+1
| | | | | | | Based on dragonflybsd support for GNU hash by John Marino <draco marino st> Reviewed by: kan Tested by: bapt MFC after: 2 weeks
* Fix several problems with our ELF filters implementation.kib2012-03-201-14/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Do not relocate twice an object which happens to be needed by loaded binary (or dso) and some filtee opened due to symbol resolution when relocating need objects. Record the state of the relocation processing in Obj_Entry and short-circuit relocate_objects() if current object already processed. Do not call constructors for filtees loaded during the early relocation processing before image is initialized enough to run user-provided code. Filtees are loaded using dlopen_object(), which normally performs relocation and initialization. If filtee is lazy-loaded during the relocation of dso needed by the main object, dlopen_object() runs too earlier, when most runtime services are not yet ready. Postpone the constructors call to the time when main binary and depended libraries constructors are run, passing the new flag RTLD_LO_EARLY to dlopen_object(). Symbol lookups callers inform symlook_* functions about early stage of initialization with SYMLOOK_EARLY. Pass flags through all functions participating in object relocation. Use the opportunity and fix flags argument to find_symdef() in arch-specific reloc.c to use proper name SYMLOOK_IN_PLT instead of true, which happen to have the same numeric value. Reported and tested by: theraven Reviewed by: kan MFC after: 2 weeks
* Remove unneeded dtv variable.ed2012-01-171-4/+0
| | | | | | | It is only assigned and not used at all. The object files stay identical when the variables are removed. Approved by: kib
* _rtld_bind() read-locks the bind lock, and possible plt resolutionkib2011-12-141-1/+8
| | | | | | | | | | | | | | | | | | | | | | from the dispatcher would also acquire bind lock in read mode, which is the supported operation. plt is explicitely designed to allow safe multithreaded updates, so the shared lock do not cause problems. The error in r228435 is that it allows read lock acquisition after the write lock for the bind block. If we dlopened the shared object that contains IRELATIVE or jump slot which target is STT_GNU_IFUNC, then possible recursive plt resolve from the dispatcher would cause it. Postpone the resolution for irelative/ifunc right before initializers are called, and drop bind lock around calls to dispatcher. Use initlist to iterate over the objects instead of the ->next, due to drop of the bind lock in iteration. For i386/reloc.c:reloc_iresolve(), fix calculation of the dispatch function address for dso, by taking into account possible non-zero relocbase. MFC after: 3 weeks
* Add support for STT_GNU_IFUNC and R_MACHINE_IRELATIVE GNU extensions tokib2011-12-121-15/+95
| | | | | | | | | | | | | | | | | rtld on 386 and amd64. This adds runtime bits neccessary for the use of the dispatch functions from the dynamically-linked executables and shared libraries. To allow use of external references from the dispatch function, resolution of the R_MACHINE_IRESOLVE relocations in PLT is postponed until GOT entries for PLT are prepared, and normal resolution of the GOT entries is finished. Similar to how it is done by GNU, IRELATIVE relocations are resolved in advance, instead of normal lazy handling for PLT. Move the init_pltgot() call before the relocations for the object are processed. MFC after: 3 weeks
* Handle the R_386_TLS_TPOFF32 relocation, which is similar to R_386_TLS_TPOFF,kib2011-10-081-2/+7
| | | | | | | | but with negative relocation value. Found by: mpfr test suite, pointed to by ale Reviewed by: kan MFC after: 1 week
* Implement support for ELF filters in rtld. Both normal and auxillarykib2010-12-251-18/+24
| | | | | | | | | | | | | | | | | filters are implemented. Filtees are loaded on demand, unless LD_LOADFLTR environment variable is set or -z loadfltr was specified during the linking. This forces rtld to upgrade read-locked rtld_bind_lock to write lock when it encounters an object with filter during symbol lookup. Consolidate common arguments of the symbol lookup functions in the SymLook structure. Track the state of the rtld locks in the RtldLockState structure. Pass local RtldLockState through the rtld symbol lookup calls to allow lock upgrades. Reviewed by: kan Tested by: Mykola Dzham <i levsha me>, nwhitehorn (powerpc)
* Only use the cache after the early stage of loading. This isrdivacky2010-05-181-5/+6
| | | | | | | | | | because calling mmap() etc. may use GOT which is not set up yet. Use calloc() instead of mmap() in cases where this was the case before (sparc64, powerpc, arm). Submitted by: Dimitry Andric (dimitry andric com) Reviewed by: kan Approved by: ed (mentor)
* Allocate space for thread pointer, this allows thread library to accessdavidxu2006-03-281-1/+1
| | | | its pointer from begin, and simplifies _get_curthread() in libthr.
* Implement ELF symbol versioning using GNU semantics. This code aimskan2005-12-181-1/+3
| | | | | | | | | to be compatible with symbol versioning support as implemented by GNU libc and documented by http://people.redhat.com/~drepper/symbol-versioning and LSB 3.0. Implement dlvsym() function to allow lookups for a specific version of a given symbol.
* Clean out the leftovers from the i386_set_gsbase() TLS conversion.peter2005-06-291-17/+1
| | | | | | | | Like on libthr, there is an i386_set_gsbase() stub implementation here to avoid libc.so.5 issues. This should likely be a weak symbol and I expect this will be fixed soon. Approved by: re
* Fix compilation problem.davidxu2005-04-271-1/+1
|
* Stop calling _amd64_set_gsbase() for COMPAT_32BIT. The amd64 kernelpeter2005-04-261-9/+2
| | | | implements i386_set_gsbase(), so there is no need for the variation.
* Attempt to use i386_set_gsbase(), and gracefully fall back to LDT methodspeter2005-04-141-13/+16
| | | | if the direct access methods are not implemented.
* The 32 bit compatability ld-elf32.so.1 cannot use i386_set_ldt() whenpeter2004-11-061-0/+6
| | | | | running on an amd64 kernel. Use the recently exposed direct %fs/%gs set routines instead for the TLS setup of 32 bit binaries.
* Add support for Thread Local Storage.dfr2004-08-031-0/+114
|
* No need to zero fill memory, mmapped anonymously. Kernel willkan2003-03-141-2/+0
| | | | | | return pre-zeroed pages itself. Noticed by: jake
* Fix the handling of high PLT entries (> 32764) on sparc64. This requirestmm2002-11-181-1/+1
| | | | | | | | additional arguments to reloc_jmpslot(), which is why MI code and MD code of other platforms had to be changed. Reviewed by: jake Approved by: re
* Correct a bug in the last commit. The whole point of creating a 'done:'dillon2002-06-101-3/+3
| | | | | | | goto target was so the cache could be freed. So free the cache after done: rather then before done: (!) Submitted by: Gavin Atkinson <gavin@ury.york.ac.uk>
* In tracking down an installation seg fault with then openoffice portdillon2002-06-101-9/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | Martin Blapp determined that the elf dynamic loader was at fault. In particular, the loader uses alloca() to allocate a symbol cache on the stack. Normally this would work just fine, but if the loader is called from a threaded program and the object being loaded is fairly large the alloca() can blow away the thread stack and effect other nearby thread stacks as well. My testing showed that the symbol cache can be as large as 250KBytes during the openoffice port build and install sequence. Martin was able to work around the problem by disabling the symbol cache (cache = NULL;). However, this solution is not adequate for commit because it can cause an enormous cpu burden for applications which do a lot of dynamic loading (e.g. like konqueror). The solution is to use anonymous mmap() to temporarily allocate space to hold the symbol cache. In testing I found that replacing the alloca() with mmap() has no observable degredation in performance. It should be noted that this bug does not necessarily cause an immediate crash but can instead result in long term corruption and instability in applications that load modules from threads. The bug is almost certainly responsible for some of the instabilities found in konqueror, for example, and possibly netscape too. Sleuthing work by: Martin Blapp <mb@imp.ch> X-MFC after: Before or after the 4.6 release depending on the release engineers
* Add ia64 support. Various adjustments were made to existing targets todfr2001-10-151-2/+3
| | | | | cope with a few interface changes required by the ia64. In particular, function pointers on ia64 need special treatment in rtld.
* Performance improvements for the ELF dynamic linker. Thesejdp2001-05-051-4/+9
| | | | | | | | | | | | | | | | | | | | particularly help programs which load many shared libraries with a lot of relocations. Large C++ programs such as are found in KDE are a prime example. While relocating a shared object, maintain a vector of symbols which have already been looked up, directly indexed by symbol number. Typically, symbols which are referenced by a relocation entry are referenced by many of them. This is the same optimization I made to the a.out dynamic linker in 1995 (rtld.c revision 1.30). Also, compare the first character of a sought-after symbol with its symbol table entry before calling strcmp(). On a PII/400 these changes reduce the start-up time of a typical KDE program from 833 msec (elapsed) to 370 msec. MFC after: 5 days
* When a threads package registers locking methods with dllockinit(),jdp2000-01-291-10/+25
| | | | | | | | | | figure out which shared object(s) contain the the locking methods and fully bind those objects as if they had been loaded with LD_BIND_NOW=1. The goal is to keep the locking methods from requiring any lazy binding. Otherwise infinite recursion occurs in _rtld_bind. This fixes the infinite recursion problem in the linuxthreads port.
* Add a new function dllockinit() for registering thread lockingjdp1999-12-271-9/+0
| | | | | | | | | | | | | | | | | | | functions to be used by the dynamic linker. This can be called by threads packages at start-up time. I will add the call to libc_r soon. Also add a default locking method that is used up until dllockinit() is called. The default method works by blocking SIGVTALRM, SIGPROF, and SIGALRM in critical sections. It is based on the observation that most user-space threads packages implement thread preemption with one of these signals (usually SIGVTALRM). The dynamic linker has never been reentrant, but it became less reentrant in revision 1.34 of "src/libexec/rtld-elf/rtld.c". Starting with that revision, multiple threads each doing lazy binding could interfere with each other. The usual symptom was that a symbol was falsely reported as undefined at start-up time. It was rare but not unseen. This commit fixes it.
* $Id$ -> $FreeBSD$peter1999-08-281-1/+1
|
* Fix a serious performance bug for large programs on the Alpha,jdp1999-06-251-25/+21
| | | | | | | | | | | | | | | discovered by Hidetoshi Shimokawa. Large programs need multiple GOTs. The lazy binding stub in the PLT can be reached from any of these GOTs, but the dynamic linker only has enough information to fix up the first GOT entry. Thus calls through the other GOTs went through the time-consuming lazy binding process on every call. This fix rewrites the PLT entries themselves to bypass the lazy binding. Tested by Hidetoshi Shimokawa and Steve Price. Reviewed by: Doug Rabson <dfr@freebsd.org>
* Eliminate all machine-dependent code from the main source body andjdp1999-04-091-1/+11
| | | | | | | | | | | | | | | the Makefile, and move it down into the architecture-specific subdirectories. Eliminate an asm() statement for the i386. Make the dynamic linker work if it is built as an executable instead of as a shared library. See i386/Makefile.inc to find out how to do it. Note, this change is not enabled and it might never be enabled. But it might be useful in the future. Building the dynamic linker as an executable should make it start up faster, because it won't have any relocations. But in practice I suspect the difference is negligible.
* Add alpha support.dfr1998-09-041-0/+236
Submitted by: John Birrell <jb@cimlogic.com.au> (with extra hacks by me) Obtained from: Probably NetBSD
OpenPOWER on IntegriCloud