summaryrefslogtreecommitdiff
path: root/libexec/ld.so/resolve.c
AgeCommit message (Collapse)Author
2024-01-22ugly whitespacesTheo de Raadt
2024-01-16Read PT_OPENBSD_SYSCALLS in libc.so, and convert it to a table forTheo de Raadt
pinsyscalls(2). ok kettenis
2023-07-08turn an ifdef'd _dl_printf call into DL_DEB and various whitespace fixesJasper Lievisse Adriaanse
sure deraadt@
2023-04-13Avoid an overflow in the ELF SYSV ABI hash function.Todd C. Miller
The hash function is supposed to return a value less than or equal to 0x0fffffff. Due to a bug in the sample code supplied with the ELF SYSV ABI documentation, the hash function can overflow on 64-bit systems. Apply the same fix used by GNU libc, MUSL libc and FreeBSD. Prompted by https://maskray.me/blog/2023-04-12-elf-hash-function OK tb@ miod@
2023-04-09Treat symlinks better in $ORIGIN determination in ld.soGreg Steuck
Now symlinking an executable away from the rest of its installation tree no longer prevents it from finding the libraries. This matches the behavior of other OS linkers. Prompted by a behavior change in lang/ghc test suite. Swapped the order of dirname/realpath in _dl_origin_path. Added some regress tests that pass and then bin3 that fails without this change and reflects the behavior needd for lang/ghc. Suggestion by semarie@, OK deraadt@
2022-01-08Prep .c files for removing the #includes from */archdep.hPhilip Guenther
* replace #include "archdep.h" with #includes of what is used, pulling in "syscall.h", "util.h", and "archdep.h" as needed * delete #include <sys/syscall.h> from syscall.h * only pull in <sys/stat.h> to the three files that use _dl_fstat(), forward declare struct stat in syscall.h for the others * NBBY is for <sys/select.h> macros; just use '8' in dl_printf.c * <machine/vmparam.h> is only needed on i386; conditionalize it * stop using __LDPGSZ: use _MAX_PAGE_SHIFT (already used by malloc.c) where necessary * delete other bogus #includes, order legit per style: <sys/*> then <*/*>, then <*>, then "*" dir.c improvement from jsg@ ok and testing assistance deraadt@
2021-11-12Add support for RELR relocations in the executable and share objects.Philip Guenther
This doesn't affect ld.so's self-reloc, which still requires DT_REL/DT_RELA ok kettenis@
2021-06-02add RTLD_NODELETE supportSebastien Marie
if RTLD_NODELETE isn't POSIX, it is widely deployed: at least linux, freebsd, dragonfly, netbsd, solaris, illumos, apple, and fuchsia have it. ok kettenis@ on previous version with help from and ok guenther@ diff partially inspired from a diff from brad@
2019-10-04Convert the child_list member from a linked list to a vector.Philip Guenther
ok mpi@
2019-10-03Use a better algorithm for calculating the grpsym library order.Philip Guenther
The existing code did a full recursive walk for O(horrible). Instead, keep a single list of nodes plus the index of the first node whose children haven't been scanned; lookup until that index catches the end, appending the unscanned children of the node at the index. This also makes the grpsym list order match that calculated by FreeBSD and glibc in dependency trees with inconsistent ordering of dependent libs. To make this easier and more cache friendly, convert grpsym_list to a vector: the size is bounded by the number of objects currently loaded. Other, related fixes: * increment the grpsym generation number _after_ pushing the loading object onto its grpsym list, to avoid double counting it * increment the grpsym generation number when building the grpsym list for an already loaded object that's being dlopen()ed, to avoid incomplete grpsym lists * use a more accurate test of whether an object already has a grpsym list Prompted by a diff from Nathanael Rensen (nathanael (at) list.polymorpheus.com) that pointed to _dl_cache_grpsym_list() as a performance bottleneck. Much proding from robert@, sthen@, aja@, jca@ no problem reports after being in snaps ok mpi@
2019-08-04Simplify _dl_find_symbol(). Currently, it returns three values:Philip Guenther
- the symbol it found, returned via the second argument - the base offset of the the object it was found in, via the return value - optionally: the object it was found in, returned via the last argument Instead, return a struct with the symbol and object pointers and let the caller get the base offset from the object's obj_base member. On at least aarch64, amd64, mips64, powerpc, and sparc64, a two word struct like this is passed in registers. ok mpi@, kettenis@
2019-07-21In 2004, we upgraded to binutils 2.14 with did -zcombreloc by default.Philip Guenther
In 2013, I implemented the single-entry LRU cache that gets the maximal symbol reuse from combreloc. Since then, the ld.so generic relocation symcache has been a waste of CPU and memory with 0% hit-rate, so kill it. ok mpi@
2019-07-14ld.so's $ORIGIN handling when argv[0] is a relative path was broken byPhilip Guenther
the change in __getcwd(2)'s return value. Fix it by switching to the __realpath(2) syscall, eliminating the ld.so copy of realpath(). problem caught by regress and noted by bluhm@ ok deraadt@
2019-04-21Now that all Elf_foo types are correct, we don't need to use Elf32_WordTheo de Raadt
anywhere and can use Elf_Word instead. ok guenther
2019-04-21On alpha, the buckets of DT_HASH are 8 bytes instead of 4 bytes. This wasPhilip Guenther
previously 'implemented' by having the Elf_Word typedef in <sys/exec_elf.h> vary, but that doesn't match the spec and breaks libelf so it's gone away. Implement the variation here by defining our own type locally for this. ok deraadt@
2018-11-28Implement support for DT_GNU_HASH, taking all the interesting bitsPhilip Guenther
from Matt Dillon's implementation in DragonFlyBSD commit 7629c631. One difference is that as long as DT_HASH is still present, ld.so will use that to get the total number of symbols rather than walking the GNU hash chains. Note that the GPLv2 binutils we have doesn't support DT_GNU_HASH, so this only helps archs were lld is used. ok kettenis@ mpi@
2018-11-16Finish ld.so's transition to GNU_RELRO: eliminate support for usingPhilip Guenther
__got_{start,end} to find a region to mark read-only. It was only used for binaries that didn't have a GNU_RELRO segment, but all archs have been using that for over a year. Since support for insecure-PLT layouts on powerpc and alpha have been removed, all archs handle GNU_RELRO the same way and the support can be moved from the MD code to the MI code. ok mpi@
2018-11-16Borrow an idea from DragonFly BSD: factor out the "does this symbol match whatPhilip Guenther
we're looking up?" logic from _dl_find_symbol_obj() into matched_symbol(), so that the former is just the "iterate across the hash" logic. matched_symbol() returns zero on "not found", one on "found strong symbol", and negative one on "found weak symbol". The last of those lets the caller give up on this object after finding a weak symbol, as there's no point in continuing to search for a strong symbol in the same object. ok mpi@
2018-11-15Put all the symbol lookup parameters (except the object being searched) andPhilip Guenther
the return pointers into a structure and pass that to _dl_find_symbol_obj(). Set sl->sl_obj_out in _dl_find_symbol_obj() so that the callers don't need to each record the object. ok mpi@
2018-10-22Use int, not char*, for booleansPhilip Guenther
ok millert@
2018-03-09Add support for the DF_TEXTREL flag.Mark Kettenis
ok patrick@, millert@
2017-01-24On fatal errors, kill ourselves with thrkill(0,9,NULL) instead ofPhilip Guenther
simply exiting, via helper functions _dl_die(), _dl_diedie(), and _dl_oom(). prompted by a complaint from jsing@ ok jsing@ deraadt@
2017-01-24Unbreak $ORIGIN support when only one of DT_RUNPATH and DT_RPATH is usedPhilip Guenther
2017-01-23remove line that slipped in with rev 1.77 but doesn't belong there; ok sthen@Christian Weisgerber
2017-01-23Whoops, lost the adjustment of DT_RUNPATH value as a DT_STRTAB value.Philip Guenther
problem reported by semarie@
2017-01-23Mark a bunch of stuff staticPhilip Guenther
ok kettenis@
2017-01-22Add support for DT_RUNPATH and DT_FLAGSPhilip Guenther
ok kettenis@
2016-08-23Implement support for DT_INIT_ARRAY, DT_FINI_ARRAY and DT_PREINIT_ARRAY.Mark Kettenis
Don't skip DT_INIT and DT_FINI for the main executable. This matches what Linux and Solaris do. ok guenther@
2016-08-08Look for a PT_GNU_RELRO section per object and, if present, mprotect thatPhilip Guenther
range instead of the [__got_start, __got_end) range. On many archs this will cover _DYNAMIC too, so move up the DT_DEBUG handling to before relocations and the mprotect are done. ok kettenis@
2016-07-04Remove prebind support: binding to symbol table indices is too fragilePhilip Guenther
for our development process. ok kettenis@ deraadt@
2016-03-20Export environ and __progname, making the latter a copy of just the filenamePhilip Guenther
portion like crt0 does. This is prep for eliminating _dl_fixup_user_env() Mark almost everything in resolve.h as hidden, to improve code generation. ok kettenis@ mpi@ "good time" deraadt@
2016-01-24Delete remnants of grpsym cache setting during symbol search: it's done atPhilip Guenther
load time only nwo. Rename _dl_searchnum and lastlookup to _dl_grpsym_gen and grpsym_gen as they are generation numbers. Merge _dl_newsymsearch() into _dl_cache_grpsym_list_setup(). ok millert@
2016-01-24Lacking precise dependency-from-relocation tracking, a nodelete objectPhilip Guenther
needs to lock down the entire load group, not just the specific object. problem report and ok sthen@ been in snaps for a week
2015-11-02Factor out the logic for mprotecting the memory between two symbols intoPhilip Guenther
a new MI routine _dl_protect_segment(), and use that for protecting the GOT and--on some archs--the PLT. Amazing testing turnaround by miod@, who apparently violated relativity to get back results on some archs as fast as he did
2015-01-22delete annoying white space that annoyTheo de Raadt
2014-07-10check all memory allocations; ok miod@ guenther@Otto Moerbeek
2014-06-21Move to a non-zeroing _dl_malloc, a _dl_calloc and _dl_reallocarry andOtto Moerbeek
fix _dl_strdup to return NULL instead of crash; ok deraadt@
2013-11-27unsigned char for ctypeTheo de Raadt
ok okan kettenis
2013-11-13prototype & void * math cleanupTheo de Raadt
ok guenther
2013-06-01Introduce ltrace(1). This tool works with ld.so to inject utrace record forMiod Vallat
each plt call, allowing to trace a binary linked against shared library at the public function call level. To do so, ltrace(1) sets up some environment variables to enable plt tracing in ld.so, and invokes ktrace(2) for utrace events. ld.so will force lazy binding and will send an utrace record in the plt resolver, without updating the plt. Minimal filtering capabilities are provided, inspired by Solaris' truss -u, to limit tracing to libraries and/or symbol names. Non-traced libraries and symbols will have the regular resolver processing, with the expected plt update. "Get it in" deraadt
2013-05-08Implement symbol caching and RELACOUNT/RELCOUNT optimizations.Philip Guenther
Much assistance and testing by miod ok miod@
2013-04-05- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.Kurt Miller
Improvements and okay matthew@, millert@, guenther@
2013-03-20- Parse colon separated paths into NULL terminated arrays of stringKurt Miller
pointers to prepare for adding rpath ORIGIN support. okay matthew@ millert@
2012-07-06Fix LD_DEBUG=1 regression introduced by previous commit.Matthew Dempsky
ok kurt
2012-06-14Add support for DF_1_NOOPEN. Based on an origional diff from matthew@.Mark Kettenis
ok matthew@
2011-11-28Add support for getting some flags from DT_FLAGS_1: new flagsPhilip Guenthe
DF_1_NODELETE and DF_1_INITFIRST, as well as DF_1_NOW and DF_1_GLOBAL. Committing for kurt@ who worked out the final version; ok guenther@ drahn@
2011-06-27Backout the dynamic linker speed improvement diff for now, it stillStuart Henderson
has some issues. Discussed with various, ok drahn@
2011-05-26No need to call _dl_newsymsearch() twice; ok drahn@Otto Moerbeek
2011-05-22Dynamic linker speed improvement diff. tested by several sinc k2k11.Dale Rahn
get it in tree now deraadt@, ok by several ports folks. Thanks for the testing.
2011-05-10Fix previous. On i386, library.c isn't compiledOtto Moerbeek