aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf/rtld.h
Commit message (Collapse)AuthorAgeFilesLines
* MFC r259043:Konstantin Belousov2013-12-131-0/+2
| | | | | | | | Build an allocator for the aligned memory on top of the rtld-private malloc. Notes: svn path=/stable/9/; revision=259291
* MFC r256101:Konstantin Belousov2013-10-141-0/+1
| | | | | | | Implement support for the interpose dso flag. Notes: svn path=/stable/9/; revision=256436
* MFC r238471:Konstantin Belousov2012-09-101-0/+10
| | | | | | | | | | | Implement DT_RUNPATH and -z nodefaultlib. MFC note: The ld_library_path_rpath default value was flipped to true, effectively reverting rtld back to the pre-patch behaviour, unless LD_LIBRARY_PATH_RPATH environment variable is set and its value is 0/N/n. Notes: svn path=/stable/9/; revision=240308
* MFC r234840:Konstantin Belousov2012-05-131-1/+19
| | | | | | | | | | | | | | | | | Split the symlook_obj1 into a loop iterating over the ELF object symbol hash elements, and a helper matched_symbol() which match the given hash entry and request, performing needed type and version checks. MFC r234841: Add GNU hash support for rtld. MFC r235054: Work around a situation where symlook_obj() could be called for the object for which digest_dynamic1() was not done yet. Just return EINVAL and do not try to dereference NULL buckets hash array. Notes: svn path=/stable/9/; revision=235396
* MFC r233361:Konstantin Belousov2012-04-061-10/+10
| | | | | | | Remove superfluous extern keywords. Notes: svn path=/stable/9/; revision=233935
* MFC r233307:Konstantin Belousov2012-04-051-2/+2
| | | | | | | | | | | | | | | Use xmalloc() instead of malloc() in the places where malloc() calls are assumed to not fail. Make the xcalloc() calling conventions follow the calloc(3) calling conventions and replace unchecked calls to calloc() with calls to xcalloc(). Remove redundand declarations from xmalloc.c, which are already present in rtld.h. Notes: svn path=/stable/9/; revision=233922
* MFC r233546:Konstantin Belousov2012-04-031-0/+1
| | | | | | | | Prevent rtld_verify_object_versions() from being called several times for the same object. Notes: svn path=/stable/9/; revision=233832
* MFC r233231:Konstantin Belousov2012-04-031-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix several problems with our ELF filters implementation. 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. MFC r233777 (by kan): Do not try to adjust stacks if dlopen_object is called too early. MFC r233778 (by kan): Remove extra blank line from revious commit. MFC note: the ARM and MIPS TLS support is not merged back, so the chunks from r233231 which fix misuse of flags in calls to find_symdef() in the corresponding relocation type handlers were not applied. When TLS support is merged, the rest of r233231 should be applied too. Notes: svn path=/stable/9/; revision=233831
* MFC r232974:Konstantin Belousov2012-03-301-0/+1
| | | | | | | | | Stop using strerror(3) in rtld, which brings in msgcat and stdio. Directly access sys_errlist array of errno messages with private rtld_strerror() function. Notes: svn path=/stable/9/; revision=233697
* MFC r232831:Konstantin Belousov2012-03-301-0/+15
| | | | | | | | | | | | | | | | | | | | | Add support for preinit, init and fini arrays to rtld. Only binaries marked with proper ABI note gets array ctr/dtrs called. MFC r232856: When iterating over the dso program headers, the object is not initialized yet, and object segments are not yet mapped. Only parse the notes that appear in the first page of the dso (as it should be anyway), and use the preloaded page content. MFC r232857 (by dim): Fix a warning/error with clang. MFC r232859 (by dim): Amend r232857, now dropping the casts entirely, as they were not necessary at all. Notes: svn path=/stable/9/; revision=233694
* MFC r230784:Konstantin Belousov2012-02-131-0/+3
| | | | | | | Add support for GNU RELRO. Notes: svn path=/stable/9/; revision=231579
* MFC r228435:Konstantin Belousov2012-01-041-0/+5
| | | | | | | | | | | | | | | | | | | | | | | Add support for STT_GNU_IFUNC and R_MACHINE_IRELATIVE GNU extensions to rtld on 386 and amd64. MFC r228503: 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 r228635 (by nwhitehorn): Fix RTLD on PowerPC after r228435. Changing the order of init_pltgot() caused the icache to be invalidated at the wrong time, resulting in an icache full of nonsense in the PLT section. Notes: svn path=/stable/9/; revision=229503
* MFC r228375:Konstantin Belousov2011-12-301-1/+1
| | | | | | | Typo. Notes: svn path=/stable/9/; revision=229017
* Rtld links with the specially built pic static libc library to get someKonstantin Belousov2011-08-241-0/+1
| | | | | | | | | | | | | | | | | | | | C runtime services, like printf(). Unfortunately, the multithread-safeness measures in the libc do not work in rtld environment. Rip the kernel printf() implementation and use it in the rtld instead of libc version. This printf does not require any shared global data and thus is mt-safe. Systematically use rtld_printf() and related functions, remove the calls to err(3). Note that stdio is still pulled from libc due to libmap implementaion using fopen(). This is safe but unoptimal, and can be changed later. Reported and tested by: pgj Diagnosed and reviewed by: kan (previous version) Approved by: re (bz) Notes: svn path=/head/; revision=225152
* Use sigsetjmp/siglongjmp with disabled signal mask access forKonstantin Belousov2011-02-091-1/+1
| | | | | | | | | lock upgrade in rtld. There is no need to care about the mask, which causes a lot of unneeded sigprocmask(2) calls during each symbol lookup. Notes: svn path=/head/; revision=218476
* In rtld, read the initial stack access mode from AT_STACKPROT as setKonstantin Belousov2011-01-081-0/+1
| | | | | | | | | | | | | | | | | | by kernel, and parse PT_GNU_STACK phdr from linked and loaded dsos. If the loaded dso requires executable stack, as specified by PF_X bit of p_flags of PT_GNU_STACK phdr, but current stack protection does not permit execution, the __pthread_map_stacks_exec symbol is looked up and called. It should be implemented in libc or threading library and change the protection mode of all thread stacks to be executable. Provide a private interface _rtld_get_stack_prot() to export the stack access mode as calculated by rtld. Reviewed by: kan Notes: svn path=/head/; revision=217153
* Implement support for ELF filters in rtld. Both normal and auxillaryKonstantin Belousov2010-12-251-5/+40
| | | | | | | | | | | | | | | | | | | | 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) Notes: svn path=/head/; revision=216695
* If dlopen() is called for the dso that has been already loaded as aKonstantin Belousov2010-11-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dependency, then the dso never has its DAG initialized. Empty DAG makes ref_dag() call in dlopen() a nop, and the dso refcount is off by one. Initialize the DAG on the first dlopen() call, using a boolean flag to prevent double initialization. From the PR (edited): Assume we have a library liba.so, containing a function a(), and a library libb.so, containing function b(). liba.so needs functionality from libb.so, so liba.so links in libb.so. An application doesn't know about the relation between these libraries, but needs to call a() and b(). It dlopen()s liba.so and obtains a pointer to a(), then it dlopen()s libb.so and obtains a pointer to b(). As soon as the application doesn't need a() anymore, it dlclose()s liba.so. Expected result: the pointer to b() is still valid and can be called Actual result: the pointer to b() has become invalid, even though the application did not dlclose() the handle to libb.so. On calling b(), the application crashes with a segmentation fault. PR: misc/151861 Based on patch by: jh Reviewed by: kan Tested by: Arjan van Leeuwen <freebsd-maintainer opera com> MFC after: 1 week Notes: svn path=/head/; revision=214728
* Check for undefined weak symbols during PLT binding on powerpc64, and doNathan Whitehorn2010-09-121-0/+1
| | | | | | | | | | not attempt to copy NULL function descriptors. This fixes LD_BIND_NOW on powerpc64 after r211706. Reviewed by: kib Notes: svn path=/head/; revision=212497
* Allow to load not-openable dso when tracing. This fixes ldd on such dso orKonstantin Belousov2009-11-281-2/+3
| | | | | | | | | | | dso linked to non-openable object. Remove '\n' at the end of error message. End comments with dot. MFC after: 3 weeks (together with r199829) Notes: svn path=/head/; revision=199877
* Implement rtld part of the support for -z nodlopen (see ld(1)).Konstantin Belousov2009-11-261-0/+5
| | | | | | | | Reviewed by: kan MFC after: 3 weeks Notes: svn path=/head/; revision=199829
* Allow order of initialization of loaded shared objects to beAlexander Kabaev2009-06-201-2/+4
| | | | | | | | | | | | | | | | | | | | altered through their .init code. This might happen if init vector calls dlopen on its own and that dlopen causes some not yet initialized object to be initialized earlier as part of that dlopened DAG. Do not reset module reference counts to zero on final fini vector run when process is exiting. Just add an additional parameter to force fini vector invocation regardless of current reference count value if object was not destructed yet. This allows dlclose called from fini vector to proceed normally instead of failing with handle validation error. Reviewed by: kib Reported by: venki kaps Notes: svn path=/head/; revision=194531
* Increase the size of the static TLS area slightly (required for the NVidia'sDoug Rabson2009-05-271-1/+1
| | | | | | | OpenGL driver on amd64). Notes: svn path=/head/; revision=192922
* Implement support for RTLD_NODELETE flag for dlopen() and -z nodeleteKonstantin Belousov2009-03-301-0/+2
| | | | | | | | | | static linker option. Do it by incrementing reference count on the loaded object and its dependencies. Reviewed by: davidxu, kan Notes: svn path=/head/; revision=190543
* Implement the dynamic string token substitution in the rpath andKonstantin Belousov2009-03-181-1/+2
| | | | | | | | | | | | | | | | | | soneeded pathes. The $ORIGIN, $OSNAME, $OSREL and $PLATFORM tokens are supported. Enabling the substitution requires DF_ORIGIN flag in DT_FLAGS or DF_1_ORIGIN if DF_FLAGS_1, that may be set with -z origin gnu ld flag. Translation is unconditionally disabled for setuid/setgid processes. The $ORIGIN translation relies on the AT_EXECPATH auxinfo supplied by kernel. Requested by: maho Tested by: maho, pho Reviewed by: kan Notes: svn path=/head/; revision=189959
* MFp4: Add mips support for dynamic linking.Warner Losh2008-04-041-0/+5
| | | | | | | | | | This code came from the merged mips2 and Juniper mips repositories. Warner Losh, Randall Seager, Oleksandr Tymoshenko and Olivier Houchard worked to merge, debug and integrate this code. This code may also contain code derived from NetBSD. Notes: svn path=/head/; revision=177924
* Implement dl_iterate_phdr function.Alexander Kabaev2007-04-031-9/+10
| | | | | | | | Convert boolean flags in internal Obj_Entry structure into bitfields. Properly check for loaded segment alignment in map_object. Notes: svn path=/head/; revision=168312
* Implement ELF symbol versioning using GNU semantics. This code aimsAlexander Kabaev2005-12-181-3/+34
| | | | | | | | | | | | 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. Notes: svn path=/head/; revision=153515
* Make our ELF64 type definitions match standards. In particular thisMarcel Moolenaar2005-12-181-2/+2
| | | | | | | | | | | | | | | | means: o Remove Elf64_Quarter, o Redefine Elf64_Half to be 16-bit, o Redefine Elf64_Word to be 32-bit, o Add Elf64_Xword and Elf64_Sxword for 64-bit entities, o Use Elf_Size in MI code to abstract the difference between Elf32_Word and Elf64_Word. o Add Elf_Ssize as the signed counterpart of Elf_Size. MFC after: 2 weeks Notes: svn path=/head/; revision=153504
* Attempt to free any static TLS space used by a shared library when itDoug Rabson2005-02-271-0/+1
| | | | | | | | | | is unloaded. This allows applications which load and unload libraries like libGL.so.1 several times to work properly. MFC after: 2 days Notes: svn path=/head/; revision=142645
* Add support for Thread Local Storage.Doug Rabson2004-08-031-0/+23
| | | | Notes: svn path=/head/; revision=133063
* Add initial support for compiling a special 32 bit version ofPeter Wemm2004-03-211-0/+12
| | | | | | | | | | ld-elf.so.1 on 64 bit systems. Most of this involves using alternate paths, environment variables and diagnostic messages. The build glue is seperate. Notes: svn path=/head/; revision=127250
* Prepend /lib to the builtin library search path in rtld.Gordon Tetlow2003-08-171-1/+1
| | | | Notes: svn path=/head/; revision=119013
* Provide a mechanism for dumping relocation information.Matthew N. Dodd2003-06-191-0/+5
| | | | | | | | | | Setting the LD_DUMP_REL_PRE or LD_DUMP_REL_POST environment variables cause rtld-elf to output a table of all relocations. This is useful for debugging. Notes: svn path=/head/; revision=116563
* Move MD function prototypes together.Matthew N. Dodd2003-06-191-4/+8
| | | | Notes: svn path=/head/; revision=116558
* Fix warnings; no parameters in function prototypes.Matthew N. Dodd2003-06-191-1/+1
| | | | Notes: svn path=/head/; revision=116557
* - Add support for DT_FLAGS.Matthew N. Dodd2003-06-181-0/+2
| | | | | | | - Define various things from the most recent ELF spec. Notes: svn path=/head/; revision=116511
* Allow threading libraries to register their own lockingAlexander Kabaev2003-05-291-1/+2
| | | | | | | | | | | | | implementation in case default one provided by rtld is not suitable. Consolidate various identical MD lock implementation into a single file using appropriate machine/atomic.h. Approved by: re (scottl) Notes: svn path=/head/; revision=115396
* Implement dlinfo() function.Alexander Kabaev2003-02-131-1/+1
| | | | | | | | | | | | | Introdice RTLD_SELF special handle and properly process it within dlsym() and dlinfo() functions. The intention is to improve our compatibility with Solaris and to make a Java port easier. Partially submitted by: phantom Notes: svn path=/head/; revision=110804
* Remove /usr/lib/elf from a default search path.Alexander Kabaev2003-02-131-1/+1
| | | | | | | | | Move xprintf to malloc.c, it is only used there. Make static. Submitted by: phantom Notes: svn path=/head/; revision=110801
* Update rtld for the "new" ia64 ABI. In the old toolchain, thePeter Wemm2001-10-291-2/+2
| | | | | | | | | | | | | | | | | | DT_INIT and DT_FINI tags pointed to fptr records. In 2.11.2, it points to the actuall address of the function. On IA64 you cannot just take an address of a function, store it in a function pointer variable and call it.. the function pointers point to a fptr data block that has the target gp and address in it. This is absolutely necessary for using the in-tree binutils toolchain, but (unfortunately) will not work with old shared libraries. Save your old ld-elf.so.1 if you want to use old ones still. Do not mix-and-match. This is a no-op change for i386 and alpha. Reviewed by: dfr Notes: svn path=/head/; revision=85677
* Add ia64 support. Various adjustments were made to existing targets toDoug Rabson2001-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. Notes: svn path=/head/; revision=85004
* Performance improvements for the ELF dynamic linker. TheseJohn Polstra2001-05-051-1/+10
| | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=76296
* * include/elf.h has been repo copied to include/elf-hints.h, and it noDavid E. O'Brien2001-05-021-1/+2
| | | | | | | | | | | longer includes machine/elf.h. * consumers of elf.h now use the minimalist elf header possible. This change is motivated by Binutils 2.11.0 and too much clashing over our base elf headers and the Binutils elf headers. Notes: svn path=/head/; revision=76224
* Add support for dlsym(RTLD_DEFAULT, ...).John Polstra2000-09-191-2/+2
| | | | Notes: svn path=/head/; revision=66056
* Revamp the code that calls shared libraries' init and fini functions.John Polstra2000-07-261-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Formerly the init functions were called in the opposite of the order in which libraries were loaded, and libraries were loaded according to a breadth-first traversal of the dependency graph. That ordering came from SVR4.0, and it was easy to implement but not always sensible. Now we do a depth-first walk over the dependency graph and call the init functions in an order such that each shared object's needed objects are initialized before the shared object itself. At the same time we build a list of finalization (fini) functions in the opposite order, to guarantee correct C++ destructor ordering whenever possible. (It may not be possible if dlopen and dlclose are used in strange ways, but we come as close as one can come.) The need for this renovation has become apparent as more programs have started using multithreading. The multithreaded C library libc_r requires initialization, whereas the standard libc does not. Since virtually every other object depends on the C library, it is important that it get initialized first. Notes: svn path=/head/; revision=63870
* Solve the dynamic linker's problems with multithreaded programs onceJohn Polstra2000-07-081-5/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and for all (I hope). Packages such as wine, JDK, and linuxthreads should no longer have any problems with re-entering the dynamic linker. This commit replaces the locking used in the dynamic linker with a new spinlock-based reader/writer lock implementation. Brian Fundakowski Feldman <green> argued for this from the very beginning, but it took me a long time to come around to his point of view. Spinlocks are the only kinds of locks that work with all thread packages. But on uniprocessor systems they can be inefficient, because while a contender for the lock is spinning the holder of the lock cannot make any progress toward releasing it. To alleviate this disadvantage I have borrowed a trick from Sleepycat's Berkeley DB implementation. When spinning for a lock, the requester does a nanosleep() call for 1 usec. each time around the loop. This will generally yield the CPU to other threads, allowing the lock holder to finish its business and release the lock. I chose 1 usec. as the minimum sleep which would with reasonable certainty not be rounded down to 0. The formerly machine-independent file "lockdflt.c" has been moved into the architecture-specific subdirectories by repository copy. It now contains the machine-dependent spinlocking code. For the spinlocks I used the very nifty "simple, non-scalable reader-preference lock" which I found at <http://www.cs.rochester.edu/u/scott/synchronization/pseudocode/rw.html> on all CPUs except the 80386 (the specific CPU model, not the architecture). The 80386 CPU doesn't support the necessary "cmpxchg" instruction, so on that CPU a simple exclusive test-and-set lock is used instead. 80386 CPUs are detected at initialization time by trying to execute "cmpxchg" and catching the resulting SIGILL signal. To reduce contention for the locks, I have revamped a couple of key data structures, permitting all common operations to be done under non-exclusive (reader) locking. The only operations that require exclusive locking now are the rare intrusive operations such as dlopen() and dlclose(). The dllockinit() interface is now deprecated. It still exists, but only as a do-nothing stub. I plan to remove it as soon as is reasonably possible. (From the very beginning it was clearly labeled as experimental and subject to change.) As far as I know, only the linuxthreads port uses dllockinit(). This interface turned out to have several problems. As one example, when the dynamic linker called a client-supplied locking function, that function sometimes needed lazy binding, causing re-entry into the dynamic linker and a big looping mess. And in any case, it turned out to be too burdensome to require threads packages to register themselves with the dynamic linker. Notes: svn path=/head/; revision=62801
* Back out the previous change to the queue(3) interface.Jake Burkholder2000-05-261-4/+4
| | | | | | | | | It was not discussed and should probably not happen. Requested by: msmith and others Notes: svn path=/head/; revision=60938
* Change the way that the queue(3) structures are declared; don't assume thatJake Burkholder2000-05-231-4/+4
| | | | | | | | | | | the type argument to *_HEAD and *_ENTRY is a struct. Suggested by: phk Reviewed by: phk Approved by: mdodd Notes: svn path=/head/; revision=60833
* When a threads package registers locking methods with dllockinit(),John Polstra2000-01-291-1/+3
| | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=56780