summaryrefslogtreecommitdiff
path: root/libexec/ld.so
AgeCommit message (Collapse)Author
2019-10-05Tighten handling of pure relative DIR32 relocations and those referencingPhilip Guenther
sections; despite being a RELA arch, ld.so was making assumptions about the initialization of the targeted location. Add the relative relocation optimization, handling relocations covered by the DT_RELACOUNT value in a tight loop. ok mpi@ deraadt@
2019-10-05Delete some obsolete debugging #ifdefs blocksPhilip Guenther
ok mlarkin@, mpi@, krw@, deraadt@
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-09-30Oops: the call to ofree() in orealloc() was misconverted into a call toPhilip Guenther
_dl_free(), which would trigger a "recursive call" assertion...if we had ever realloced in ld.so ok deraadt@
2019-09-02Remove some duplicate symbol definitions.mortimer
ok visa@ guenther@
2019-08-31Delete the last argument to fit recent _dl_find_symbol change.Kenji Aoyama
ok guenther@
2019-08-06Factor out TEXTREL mprotecting from the per-arch files into _dl_rtld(),Philip Guenther
hiding the actual grotty bits in inline functions 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-08-03The ABI says JUMP_SLOT relocations don't have an addend, so don't add it inPhilip Guenther
ok kettenis@
2019-08-03Suppress DWARF2 warnings on clang archs by building with -gdwarf-4Philip Guenther
ok deraadt@, 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-07-01Compile with -fno-jump-tables to avoid relocations in _dl_boot_bind() whenMark Kettenis
building with clang. ok deraadt@, visa@
2019-07-01Remove stray comma.Mark Kettenis
ok deraadt@, visa@
2019-06-07make gc workaround compile on non-clangTheo de Raadt
2019-06-04Disable the unmapping of ld.so's boot data for now, as boehm-gc apparentlyPhilip Guenther
follows some pointer into the middle of it. Best to keep things working while tracking down the wonkiness. problem noted by naddy@
2019-05-12Indentation fixPhilip Guenther
2019-05-11Prune visited leaves when walking dependencies to call init functions inPhilip Guenther
topological sort order, reducing it to O(n) from O(2^n) (ouch!) diff from Nathanael Rensen (nathanael(at)list.polymorpheus.com) Much testing and pleading by robert@ and ajacoutot@ ok drahn@ mpi@
2019-05-10ld.so boot cleanup support:Philip Guenther
- put functions and data which are only used before calling the executable's start function into their own page-aligned segments for unmapping (only done on amd64, arm64, armv7, powerpc, and sparc64 so far) - pass .init_array and .preinit_array functions an addition argument which is a callback to get a structure which includes a function that frees the boot text and data - sometimes delay doing RELRO processing: for a shared-object marked DF_1_INITFIRST do it after the object's .init_array, for the executable do it after the .preinit_array - improve test-ld.so to link against libpthread and trigger its initialization late libc changes to use this will come later ok kettenis@
2019-05-08On retguard systems, remove the ld.so-local stack-protector handlingTheo de Raadt
functions because retguard uses hard-traps instead. ok mortimer.
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@
2019-04-19Prevent clang from using builtins and jump tables in _dl_boot_bind()Visa Hankala
on mips64. They need relocation and consequently cannot be used in that function. OK kettenis@
2019-02-14spelling/consistency fix; from nam nguyenJason McIntyre
2019-02-03_dl_cerror is trivial on powerpc; just inline the handling into the stubsPhilip Guenther
based on a diff from miod@
2019-02-03_dl_cerror is trivial on alpha and m88k; just inline the hanlding intoPhilip Guenther
the stubs noted by miod@
2019-01-25On i386, ensure that the first PT_LOAD segment is below the W^XKurt Miller
line unless it is writable. lld places read-only sections below the gap so this is needed to be able to retain W^X with lld. Note however the read-only sections below the W^X line are now executable on pre-NX machines and a possible source of gadgets. This is a change from Gnu ld where RO sections were ordered above the W^X line and not executable. okay drahn@ kettenis@ deraadt@
2019-01-25I am retiring my old email address; replace it with my OpenBSD one.Todd C. Miller
2018-12-05Delete an unused struct member that has hid out here for 17 yearsPhilip Guenther
2018-12-03DT_MIPS_RLD_MAP is an offset, so relocate it when present.Philip Guenther
This fixes handling of lld-linked executables on mips64. problem reported by visa@ and worked out with him
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-22Make alpha less special: _dl_boot_bind() is written to completePhilip Guenther
relocation of ld.so's GOT without using it, so _reloc_alpha_got() merely made the call to _dl_boot_bind() from asm simpler...while itself being a call that required special handling. diff and muild baking by miod@ ok guenther@
2018-11-20On mips64, DT_DEBUG doesn't need mprotecting if it's in the GNU_RELRO segmentPhilip Guenther
ok visa@
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-11-12Delete support for non-secureplt binaries. The secure PLT format has beenPhilip Guenther
the default for years and ports doesn't appear to have anything patching to use the old format. ok deraadt@
2018-11-09Delete superfluous libc reach-around variables, left over from thePhilip Guenther
old syscall stubs. Prompted by miod@'s poke on m88k ok visa@
2018-11-09Delete superfluous libc reacharounds.Philip Guenther
Replace magic numbers with symbolic constants in ldasm.S Let the kernel do the cacheflush optimization. from miod@
2018-11-09Delete support for obsolete BSS PLT format, which was last known to bePhilip Guenther
used by the dearly departed editors/emacs21 port. Per naddy@, we'll keep an eye out for issues in the next ports bulk build
2018-11-02ld.so's malloc has no runtime option processing, so remove theOtto Moerbeek
setting flags and replace them by constants. ok deraadt@ guenther@
2018-10-25The compilers already put static arrays in .rodata when not written to;Philip Guenther
marking them const will keep a source change from silently moving them back to .data ok deraadt@ kettenis@
2018-10-23Delay processing of ld.so's own PT_GNU_RELRO section until after environmentPhilip Guenther
processing and malloc initialization, and then move variables set by those steps, including malloc's mopts structure, into the .data.rel.ro segment. This protects more data and eliminates the extra padding of the mopts. ok kettenis@
2018-10-22Use int, not char*, for booleansPhilip Guenther
ok millert@
2018-10-01Add retguard to arm64 ld.so.mortimer
ok kettenis@
2018-08-29make ld.so build reproducible by including a FILE symbol and by removingRobert Nagy
-x from ld; this is only used for syspatch creation so builds are still randomized just as before ok guenther@
2018-07-24Fix address calculation for _DYNAMIC. We want to address of _DYNAMIC itself,Mark Kettenis
not the address of its GOT entry. The current code mixed the high bits of the GOT entry address with the low bits of the true address. This only worked by accident for small binaries where _DYNAMIC and its GOT entry happen to reside on the same page. ok guenther@, mortimer@
2018-07-09unify the various per-arch syscall.h as much as possibleTheo de Raadt
ok kettenis guenther
2018-06-16Add add PIE support for m88k (requires gcc4 toolchain)Philip Guenther
Convert __cerror to hidden visibility. from miod@