summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf
Commit message (Collapse)AuthorAgeFilesLines
* Calculate relocation base for the main object, and apply the relocationkib2009-10-101-14/+15
| | | | | | | | | | | | | | adjustment for all virtual addresses encoded into the ELF structures of it. PIE binary could and should be loaded at non-zero mapbase. For sym_zero pseudosymbol used as a return value from find_symdef() for undefined weak symbols, st_value also should be adjusted, since _rtld_bind corrects symbol values by relocbase. Discussed with: bz Reviewed by: kan Tested by: bz (i386, amd64), bsam (linux) MFC after: some time
* In rtld's map_object(), use pread(..., 0) rather than read() to read therwatson2009-10-061-1/+1
| | | | | | | | | ELF header from the front of the file. As all other I/O on the binary is done using mmap(), this avoids the need for seek privileges on the file descriptor during run-time linking. MFC after: 1 month Sponsored by: Google
* Implement RTLD_NOLOAD flag for dlopen(3).kib2009-07-171-6/+10
| | | | | | Requested and tested by: jkim Reviewed by: kan Approved by: re (kensmith)
* Only perform .bss mapping and cleaning operations when segment file sizekib2009-07-171-21/+27
| | | | | | | | | | | | | | | | | | | | | | | | is not equal to its memory size. This eliminates unneeded clearing of the text segment that often happens due to text end not being page-aligned. For instance, $ readelf -l /lib/libedit.so.6 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x00000000 0x00000000 0x139e1 0x139e1 R E 0x1000 LOAD 0x014000 0x00014000 0x00014000 0x00f04 0x00f14 RW 0x1000 DYNAMIC 0x014cc4 0x00014cc4 0x00014cc4 0x000d0 0x000d0 RW 0x4 $ procstat -v $$ (for /bin/sh) 68585 0x28097000 0x280aa000 r-x 6 0 21 14 CN vn /lib/libedit.so.6 68585 0x280aa000 0x280ab000 r-x 1 0 1 0 CN vn /lib/libedit.so.6 <== 68585 0x280ab000 0x280ac000 rwx 1 0 1 0 CN vn /lib/libedit.so.6 Note the splitted map entry marked by '<=='. Reviewed by: kan Approved by: re (kensmith) MFC after: 1 month
* Second attempt at eliminating .text relocations in shared librarieskan2009-07-141-1/+1
| | | | | | | | | | | | | | compiled with stack protector. Use libssp_nonshared library to pull __stack_chk_fail_local symbol into each library that needs it instead of pulling it from libc. GCC generates local calls to this function which result in absolute relocations put into position-independent code segment, making dynamic loader do extra work every time given shared library is being relocated and making affected text pages non-shareable. Reviewed by: kib Approved by: re (kib)
* Back out previous revision until better tested fix is ready.kan2009-06-291-1/+1
| | | | Approved by: re (impliciti, by approving previos check-in)
* Eliminate .text relocations in shared libraries compiled with stack protector.kan2009-06-281-1/+1
| | | | | | | | | | | | Use libssp_nonshared library to pull __stack_chk_fail_local symbol into each library that needs it instead of pulling it from libc. GCC generates local calls to this function which result in absolute relocations put into position-independent code segment, making dynamic loader do extra work everys time given shared library is being relocated and making affected text pages non-shareable. Reviewed by: kib Approved by: re (kensmith)
* Fix a typo in the same comment, one line below.ed2009-06-231-1/+1
| | | | Submitted by: bf1783 googlemail com
* Fix typo in comment.ed2009-06-231-1/+1
| | | | Submitted by: Christoph Mallon
* Allow order of initialization of loaded shared objects to bekan2009-06-202-48/+47
| | | | | | | | | | | | | | | | | 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
* FreeBSD returns main object handle from dlopen(NULL, ...) calls.kan2009-06-161-0/+10
| | | | | | | | | | dlsym seaches using this handle are expected to look for symbol definitions in all objects loaded at the program start time along with all objects currently in RTLD_GLOBAL scope. Discussed with: kib Reported by: Maho NAKATA MFC after: 2 weeks
* Increase the size of the static TLS area slightly (required for the NVidia'sdfr2009-05-271-1/+1
| | | | OpenGL driver on amd64).
* Prefer <sys/param.h> to <machine/param.h> for the definition ofrwatson2009-04-201-1/+1
| | | | | | | CACHE_LINE_SIZE. Submitted by: bde MFC after: 2 weeks
* Explicitly include machine/param.h for CACHE_LINE_SIZE.rwatson2009-04-191-0/+2
| | | | MFC after: 2 weeks
* Now that the kernel defines CACHE_LINE_SIZE in machine/param.h, userwatson2009-04-197-14/+0
| | | | | | | | that definition in the custom locking code for the run-time linker rather than local definitions. Pointed out by: tinderbox MFC after: 2 weeks
* Currently, when mapping an object, rtld reserves the whole address spacekib2009-04-101-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | for the mapping by the object' file with the protection and mode of the first loadable segment over the whole region. Then, it maps other segments at the appropriate addresses inside the region. On amd64, due to default alignment of the segments being 1Gb, the subsequent segment mappings leave the holes in the region, that usually contain mapping of the object' file past eof. Such mappings prevent wiring of the address space, because the pages cannot be faulted in. Change the way the mapping of the ELF objects is constructed, by first mapping PROT_NONE anonymous memory over the whole range, and then mapping the segments of the object over it. Take advantage of this new order and allocate .bss by changing the protection of the range instead of remapping. Note that we cannot simply keep the holes between segments, because other mappings may be made there. Among other issues, when the dso is unloaded, rtld unmaps the whole region, deleting unrelated mappings. The kernel ELF image activator does put the holes between segments, but this is not critical for now because kernel loads only executable image and interpreter, both cannot be unloaded. This will be fixed later, if needed. Reported and tested by: Hans Ottevanger <fbsdhackers beasties demon nl> Suggested and reviewed by: kan, alc
* Update comment to the reality, rtld supports any number of loadable segments.kib2009-04-101-3/+2
| | | | | | Fix spacing. Reviewed by: kan
* Allow the NULL, RTLD_SELF and RTLD_NEXT handles to work with dlfunc(3).kib2009-04-032-0/+15
| | | | | | | | | | | | | | | | dlfunc() called dlsym() to do the work, and dlsym() determines the dso that originating the call by the return address. Due to this, dlfunc() operated as if the caller is always the libc. To fix this, move the dlfunc() to rtld, where it can call the internal implementation of dlsym, and still correctly fetch return address. Provide usual weak stub for the symbol from libc for static binaries. dlfunc is put to FBSD_1.0 symver namespace in the ld.so export to override dlfunc@FBSD_1.0 weak symbol, exported by libc. Reported, analyzed and tested by: Tijl Coosemans <tijl ulyssis org> PR: standards/133339 Reviewed by: kan
* Document RTLD_NODELETE, -z nodelete and -z origin support.kib2009-04-011-1/+20
|
* Implement support for RTLD_NODELETE flag for dlopen() and -z nodeletekib2009-03-302-4/+20
| | | | | | | static linker option. Do it by incrementing reference count on the loaded object and its dependencies. Reviewed by: davidxu, kan
* Do not dereference NULL pointer. refobj is NULL for the objects that arekib2009-03-281-1/+1
| | | | | | preloaded. Reported and tested by: ed
* Support for a new environment variable, LD_ELF_HINTS_PATH for overridingdelphij2009-03-232-3/+15
| | | | | | | | | | | the rtld hints file. This environment variable would be unset if the process is considered as tainted with setuid/setgid. This feature gives a convenient way of using a custom set of shared library that is not located in the default location and switch back. Feature requested by: iXsystems Original patch by: John Hixson MFC after: 2 weeks
* Implement the dynamic string token substitution in the rpath andkib2009-03-183-10/+148
| | | | | | | | | | | | | | | 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
* Fix build when WITH_SSP is set explicitly.ru2009-02-211-2/+1
| | | | Submitted by: Jeremie Le Hen
* Provide custom simple allocator for rtld locks in libthr. The allocatorkib2008-12-021-0/+1
| | | | | | | | | does not use any external symbols, thus avoiding possible recursion into rtld to resolve symbols, when called. Reviewed by: kan, davidxu Tested by: rink MFC after: 1 month
* Add two rtld exported symbols, _rtld_atfork_pre and _rtld_atfork_post.kib2008-11-274-0/+22
| | | | | | | | | | | | | | Threading library calls _pre before the fork, allowing the rtld to lock itself to ensure that other threads of the process are out of dynamic linker. _post releases the locks. This allows the rtld to have consistent state in the child. Although child may legitimately call only async-safe functions, the call may need plt relocation resolution, and this requires working rtld. Reported and debugging help by: rink Reviewed by: kan, davidxu MFC after: 1 month (anyway, not before 7.1 is out)
* This code has no copyright. It is fairly obvious to me that we're aimp2008-10-131-14/+48
| | | | | | | | | | derivitive of NetBSD's mips_reloc.c, so pull in the copyright notice from there. Also, a minor tweak to load/store pointers. Other changes from NetBSD likely would be useful too... Obtained from: NetBSD
* MFp4: Fix a bug in the mips relocation code that prevents shared imagesimp2008-10-101-22/+14
| | | | | | | | | | | | | | | | | | | | | | | | from working. From p4 filelog of the upstream file in p4 //depot/projects/mips2-jnpr/src/libexec/rtld-elf/mips/reloc.c ... #6 change 140737 edit on 2008/04/27 by gonzo@gonzo_jeeves (text+ko) o Looks like handler for R_MIPS_REL32 brought by CS 137942 is broken for tradmips. Code from NetBSD's libexec/ld.elf_so/arch/mips/mips_reloc.c works just fine. ... #3 change 137942 edit on 2008/03/17 by rrs@rrs-mips2-jnpr (text+ko) Any relocation symbol lookup if its 0. It looks like this is the way the compiler indicates you need to look in another shared library. When we hit these as we relocate a object we will do the symbol lookups and setup the relocation table with the right value. Submitted by: rrs@, gonzo@
* Allow strong symbols to override weak ones for lookups done throughkan2008-10-101-4/+21
| | | | | | | | dlsym with RTLD_NEXT/RTLD_SELF handles. Allow symbols from ld-elf.so to be located this way too. Based on report and original patch from sobomax@.
* Allow multiple locks to be acquired by detecting correspondingdavidxu2008-09-161-2/+2
| | | | | | | | bit flag, otherwise if a thread acquired a lock, another thread or the current thread itself can no longer acquire another lock because thread_mask_set() return whole flag word, this results bit leaking in the word and misbehavior in later locking and unlocking.
* Make sure internal rtld malloc routines are not called from unlockedkan2008-09-031-14/+17
| | | | | | | | | | | | | contexts as rtld's malloc is not thread safe and is only supposed to be called with exclusive bind lock already held. The originating PR submitted a patch on top of different pre-requisite workaroud for unsafe dlopen calls, and the patch was midief slighlty to apply to stock sources for the purpose of this commit. Running rtld malloc from unlocked contexts is a bug on its own. PR: 126950 Submited by: Oleg Dolgov
* Enable GCC stack protection (aka Propolice) for userland:ru2008-06-251-0/+2
| | | | | | | | | | | | | | | | | | | | | - It is opt-out for now so as to give it maximum testing, but it may be turned opt-in for stable branches depending on the consensus. You can turn it off with WITHOUT_SSP. - WITHOUT_SSP was previously used to disable the build of GNU libssp. It is harmless to steal the knob as SSP symbols have been provided by libc for a long time, GNU libssp should not have been much used. - SSP is disabled in a few corners such as system bootstrap programs (sys/boot), process bootstrap code (rtld, csu) and SSP symbols themselves. - It should be safe to use -fstack-protector-all to build world, however libc will be automatically downgraded to -fstack-protector because it breaks rtld otherwise. - This option is unavailable on ia64. Enable GCC stack protection (aka Propolice) for kernel: - It is opt-out for now so as to give it maximum testing. - Do not compile your kernel with -fstack-protector-all, it won't work. Submitted by: Jeremie Le Hen <jeremie@le-hen.org>
* Make the meaning of the %A format specifier, as passed tobms2008-05-151-2/+5
| | | | LD_TRACE_LOADED_OBJECTS_FMT[12], more obvious for users like me.
* Fix the problem with the C++ exception handling for the multithreadedkib2008-05-063-4/+8
| | | | | | | | | | | | | | | | | | | | programs. From the PR description: The gcc runtime's _Unwind_Find_FDE function, invoked during exception handling's stack unwinding, is not safe to execute from within multiple threads. FreeBSD' s dl_iterate_phdr() however permits multiple threads to pass through it though. The result is surprisingly reliable infinite looping of one or more threads if they just happen to be unwinding at the same time. Introduce the new lock that is write locked around the dl_iterate_pdr, thus providing required exclusion for the stack unwinders. PR: threads/123062 Submitted by: Andy Newman <an at atrn org> Reviewed by: kan MFC after: 2 weeks
* MFp4: Add mips support for dynamic linking.imp2008-04-045-5/+602
| | | | | | | 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.
* For un-prototyped static inline functions declared in pthread_md.h onrwatson2007-12-011-1/+1
| | | | | | sparc64, use ANSI function headers and specifically indicate the lack of arguments with 'void'. Otherwise, warnings are generated at WARNS=3 for libkse, leading to a compile failure with -Werror.
* Include an extra header to get a function prototype.jb2007-11-191-0/+1
|
* - Fix the handling of R_SPARC_OLO10, which is a bit of a special casemarius2007-10-161-9/+14
| | | | | | | | | | | | | | | | | | | | in the way we implement handling of relocations. As for the kernel part this fixes the loading of lots of modules, which failed to load due to unresolvable symbols when built after the GCC 4.2.0 import. This wasn't due to a change in GCC itself though but one of several changes in configuration done along the import. Specfically, HAVE_AS_REGISTER_PSEUDO_OP, which causes GCC to denote global registers used for scratch purposes and in turn GAS uses R_SPARC_OLO10 relocations for, is now defined. While at it replace some more ELF_R_TYPE which should have been ELF64_R_TYPE_ID but didn't cause problems so far. - Sync a sanity check between kernel and rtld(1) and change it to be maintenance free regarding the type used for the lookup table. - Sprinkle const on lookup tables. - Use __FBSDID. Reported and tested by: yongari MFC after: 5 days
* Unbreak the dynamic linker by not creating a cache for rtld-elfmarcel2007-07-151-2/+6
| | | | | | | | | itself. It needs mmap(2), which now needs getosreldate(3) and which in turn uses a global variable to cache the result. This cannot be done before linking is done. See also: ../sparc64/reloc.c:1.15 Approved by: re (kensmith)
* Cache does not serve any purpose when rtld is relocating itself, dokensmith2007-07-131-2/+6
| | | | | | | not bother allocating one. Submitted by: kan Approved by: re (bmah)
* Add r_debug_state to the list of symbols exported from rtld. GDB needs tokan2007-07-111-0/+1
| | | | | | be able to find it in order to trap shared library events from rtld. Approved by: re (rwatson)
* Update the man page to reflect that certain variables will be unset incsjp2007-05-171-2/+4
| | | | | the case that the program is set-user-ID or set-group-ID. Add missing annotations for LIBMAP and LIBMAP_DISABLE.
* In the event a process is tainted (setuid/setgid binaries), un-set anycsjp2007-05-171-10/+20
| | | | | | | | | | | | | | | | | | | | potentially dangerous environment variables all together. It should be noted that the run-time linker will not honnor these environment variables if the process is tainted currently. However, once a child of the tainted process calls setuid(2), it's status as being tainted (as defined by issetugid(2)) will be removed. This could be problematic because subsequent activations of the run-time linker could honnor these dangerous variables. This is more of an anti foot-shot mechanism, there is nothing I am aware of in base that does this, however there may be third party utilities which do, and there is no real negative impact of clearing these environment variables. Discussed on: secteam Reviewed by: cperciva PR: kern/109836 MFC after: 2 weeks
* Don't enable symbol versioning on ia64 for now. It causesmarcel2007-05-161-0/+2
| | | | | | | symbol lookup failures that later result in null-pointer dereferences. This needs looking into, but since we're close to release it's possible that it's not resolved before that time.
* We don't need --export-dynamic for ld-elf.so.1, because it's amarcel2007-05-161-1/+0
| | | | shared object.
* Enable symbol versioning by default. Use WITHOUT_SYMVER to disable it.deischen2007-05-131-1/+3
| | | | | | | | | | Warning, after symbol versioning is enabled, going back is not easy (use WITHOUT_SYMVER at your own risk). Change the default thread library to libthr. There most likely still needs to be a version bump for at least the thread libraries. If necessary, this will happen later.
* Remove %m formatter, it's ifdef 0'ed in the code from the very beginningpav2007-05-121-2/+0
| | | | MFC after: 1 week
* Expand documentation for LD_TRACE_LOADED_OBJECTS_FMT? variablespav2007-05-121-0/+6
| | | | | | PR: docs/66265 (inspired by) Submitted by: Michel Lavondes <fox@vader.aacc.cc.md.us> MFC after: 1 week
* Fix a TLS memory leak.davidxu2007-05-051-0/+1
| | | | | PR: threads/112297 MFC: 1 week
* Catch up with the private namespace change (s/FBSDprivate/FBSDprivate_1.0).deischen2007-05-011-1/+1
|
OpenPOWER on IntegriCloud