aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf
Commit message (Collapse)AuthorAgeFilesLines
* rtld-elf: link udivmoddi4 from compiler_rtRyan Libby2020-12-191-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the gcc9 build of rtld-elf32 on amd64, which needed an implementation of udivmoddi4. rtld-elf uses certain functions normally found in libc, and so it includes certain files from libc in its own build. It has two mechanisms to include files from libc: one that rebuilds source files in the rtld-elf environment, and one that extracts object files from a purpose-built no-SSP PIC archive. In addition to libc functions, rtld-elf may need to link functions normally found in libcompiler_rt (formerly libgcc). Now, add an ability to rebuild libcompiler_rt source files in the rtld-elf environment. We don't yet have a need for an object file extraction mechanism. libcompiler_rt could also supply udivdi3 and umoddi3, but leave them alone for now. Reviewed by: arichardson, kib Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D27665 Notes: svn path=/head/; revision=368789
* rtld-libc: fix incremental buildRyan Libby2020-12-191-1/+2
| | | | | | | | | | | | | | ar cr is an update of an archive, not a creation of a new one. During incremental builds (e.g. with meta mode) the archive was not getting cleaned, and so could retain now-deleted objects from previous builds. Now, delete the archive before creating/updating it. Reviewed by: arichardson, bdrewery, kib Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D27663 Notes: svn path=/head/; revision=368788
* Add CFI start/end proc directives to arm64, i386, and ppcConrad Meyer2020-12-053-9/+8
| | | | | | | | | | | | | | Follow-up to r353959 and r368070: do the same for other architectures. arm32 already seems to use its own .fnstart/.fnend directives, which appear to be ARM-specific variants of the same thing. Likewise, MIPS uses .frame directives. Reviewed by: arichardson Differential Revision: https://reviews.freebsd.org/D27387 Notes: svn path=/head/; revision=368354
* rtld: bump r_debug.r_version to 1 from current 0.Konstantin Belousov2020-12-011-0/+2
| | | | | | | | | | | | Add r_ldbase. Requested and reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27429 Notes: svn path=/head/; revision=368260
* Fix a few mandoc issuesGordon Bergling2020-10-091-1/+1
| | | | | | | | | | | | - whitespace at end of input line - skipping paragraph macro: Pp at the end of Sh - new sentence, new line - consider using OS macro: Fx - AUTHORS section without An macro - skipping paragraph macro: Pp before Ss Notes: svn path=/head/; revision=366575
* Do a sweep and remove most WARNS=6 settingsKyle Evans2020-10-012-2/+0
| | | | | | | | | | | | | | | Repeating the default WARNS here makes it slightly more difficult to experiment with default WARNS changes, e.g. if we did something absolutely bananas and introduced a WARNS=7 and wanted to try lifting the default to that. Drop most of them; there is one in the blake2 kernel module, but I suspect it should be dropped -- the default WARNS in the rest of the build doesn't currently apply to kernel modules, and I haven't put too much thought into whether it makes sense to make it so. Notes: svn path=/head/; revision=366304
* [PowerPC64LE] Use a shared LIBC_ARCH for powerpc64le.Brandon Bergren2020-09-232-4/+4
| | | | | | | | | | | | | | | Given that we have converted to ELFv2 for BE already, endianness is the only difference between the two ARCHs. As such, there is no need to differentiate LIBC_ARCH between the two. Combining them like this lets us avoid needing to have two copies of several bits for no good reason. Sponsored by: Tag1 Consulting, Inc. Notes: svn path=/head/; revision=366039
* rtld: pass argc/argv/env to dso inits.Konstantin Belousov2020-09-071-1/+1
| | | | | | | | | | | | | | | This is consistent with how array inits are called, and also makes us more compatible with glibc environment. Requested by: Alex S <iwtcex@gmail.com> PR: 249162 Reviewed by: dim, emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D26351 Notes: svn path=/head/; revision=365432
* Undo 'fix off by one' part of r365360.Konstantin Belousov2020-09-051-1/+1
| | | | | | | | | Noted by: emaste Sponsored by: The FreeBSD Foundation MFC after: 6 days Notes: svn path=/head/; revision=365370
* rtld: do not refuse to relocate objects without dynamic symtabs.Konstantin Belousov2020-09-051-5/+2
| | | | | | | | | | | | | Such objects can still have valid relocations not requiring symbolic references. PR: 249121 Reported by: wsh@riski.sh Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=365369
* rtld: do not process absent dynamic.Konstantin Belousov2020-09-051-1/+4
| | | | | | | | | | | | | | | If object has no dynamic phdr, do not try to dereference NULL. This means that we cannot process any relocation, and that there cannot be symbols defined, but it is up to static linker to produce meaningful objects. PR: 249121 Reported by: wsh@riski.sh Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=365368
* rtld: Handle ELF dso with program headers outside the first page.Konstantin Belousov2020-09-051-10/+28
| | | | | | | | | | | Reported by: Alex Arslan <alex.arslan@julialang.org> PR: 229708 Reviewed by: dim (previous version), emaste Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D26323 Notes: svn path=/head/; revision=365360
* Maintain a stack alignment of 16-bytes.Brooks Davis2020-09-041-2/+3
| | | | | | | | | | | | | | | This violated the RISC-V 64-bit ABI. On CheriBSD this manifested as a trap when attempting to store 16-byte aligned types while zeroing the stack. Reported by: CHERI, jrtc27 Reviewed by: mhorne, br Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D26327 Notes: svn path=/head/; revision=365342
* Don't explicitly specify c99 or gnu99 as the default is now gnu99.Xin LI2020-08-171-1/+0
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=364292
* Include FreeBSD ABI tag note in the ELF runtime loader.John Baldwin2020-07-162-14/+3
| | | | | | | | | Reviewed by: kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D25306 Notes: svn path=/head/; revision=363264
* Handle non-PLT GNU IFUNC relocations in rtldLeandro Lupori2020-07-061-1/+4
| | | | | | | | | | | | | | | | In the last IFUNC related changes to rtld, the code that handled non-PLT GNU IFUNC relocations ended up getting lost. This could leave some relocations unhandled, causing crashes or misbehavior. This change restores the handling of these relocations, but now together with the other IFUNC relocations, allowing resolvers to reference external symbols. Reviewed by: kib MFC after: 2 weeks Sponsored by: Eldorado Research Institute (eldorado.org.br) Differential Revision: https://reviews.freebsd.org/D25550 Notes: svn path=/head/; revision=362958
* rtld: Apply relro to itself.Konstantin Belousov2020-06-181-0/+1
| | | | | | | | | | Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D25319 Notes: svn path=/head/; revision=362347
* rtld: Parse own phdr and notes.Konstantin Belousov2020-06-181-0/+30
| | | | | | | | | | Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D25319 Notes: svn path=/head/; revision=362346
* rtld: Allow to load ET_DYN && DF_1_PIE when tracing.Konstantin Belousov2020-06-161-3/+4
| | | | | | | | | | | | | | | This makes old ldd to still work on newer tagged PIE binaries. Also move debug line for hashes before both decisions to not load are done, so that the end of digest_dynamic() processing and reason to not load or load is seen in debug trace. Noted by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=362251
* rtld: Add debug line for dlopen_object().Konstantin Belousov2020-06-161-0/+3
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=362250
* Systematically pass RTLD_LO_TRACE to load_needed_objects().Konstantin Belousov2020-06-161-2/+3
| | | | | | | | | | | Which makes all calls to load_object() to observe the flag, except the calls for preloaded DSOs. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=362249
* rtld: set osrel when in the direct exec mode.Konstantin Belousov2020-06-122-3/+32
| | | | | | | | | | | | | | | | | Rtld itself is a shared object which does not have vendor note, so after the direct exec of ld-elf.so.1 process has p_osrel set to zero. This affects the ABI of syscalls. Set osrel to the __FreeBSD_version value at compile time right after rtld identified direct exec mode. Then, switch to the osrel read from the binary note or zero if no note, right before starting calling ifunc resolvers, which is the first byte of the user code. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=362128
* Uppercase 'dso' to indicate that it is abbreviation.Konstantin Belousov2020-06-021-1/+1
| | | | | | | | | Suggested by: arichardson Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361728
* Do not allow to load ET_DYN object with DF_1_PIE flag set.Konstantin Belousov2020-06-022-0/+7
| | | | | | | | | | | | | | | | | Linkers are supposed to mark PIE binaries with DF_1_PIE, such binary cannot be correctly and usefully loaded neither by dlopen(3) nor as a dependency of other object. For instance, we cannot do anything useful with COPY relocations, among other things. Glibc already added similar restriction. Requested and reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D25086 Notes: svn path=/head/; revision=361725
* rtld: Add -b option to allow to specify image name different from arg0.Konstantin Belousov2020-05-312-6/+40
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361680
* rtld: Fix indent in print_usage().Konstantin Belousov2020-05-311-9/+9
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361676
* rtld: Add -v switch to print some useful information about the rtld binary.Konstantin Belousov2020-05-312-1/+24
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361675
* rtld: Add -p switch to direct exec mode summary line.Konstantin Belousov2020-05-311-2/+2
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361672
* Add version indicators to rtld.Konstantin Belousov2020-05-263-0/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is wrong to relate on __FreeBSD_version, either from include/param.h, kernel, or libc, to check for rtld features. Rtld might be from newer world than the running userspace. Add special private symbols exported by rtld itself, to indicate the changes in runtime behavior, and features that cannot be otherwise detected or deduced at runtime. Note that the symbols are not exported from libc, so they intentionally cannot be linked against, and exported from the private namespace from rtld. Consumers are required to use dlsym(3). For instance, for _rtld_version_laddr_offset, user should do ptr = dlsym(RTLD_DEFAULT, "_rtld_version_laddr_offset") or even ptr = dlvsym(RTLD_DEFAULT, "_rtld_version_laddr_offset", "FBSDprivate_1.0"); Non-null ptr means that the change is present. Also add _rtld_version__FreeBSD_version indicator to report the headers version used at time of the rtld build. Reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24982 Notes: svn path=/head/; revision=361537
* Implement Solaris-like link_map l_refname member.Konstantin Belousov2020-05-221-0/+7
| | | | | | | | | | | The implementation is based on the public documentation, in particular dlinfo(3) from Solaris. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361398
* Convert linkmap_add() and linkmap_delete() to style(8).Konstantin Belousov2020-05-221-32/+33
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361394
* Restore the binary compatibility for link_map l_addr.Konstantin Belousov2020-05-211-1/+2
| | | | | | | | | | | | | | | | | Keep link_map l_addr binary layout compatible, rename l_addr to l_base where rtld returns map base. Provide relocbase in newly added l_addr. This effectively reverts the patch to the initial version of D24918. Reported by: antoine (portmgr) Reviewed by: jhb, markj Tested by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24946 Notes: svn path=/head/; revision=361349
* Change the samantic of struct link_map l_addr member.Konstantin Belousov2020-05-201-5/+1
| | | | | | | | | | | | | | | | | | | | It previously returned the object map base address, while all other ELF operating systems return load offset, i.e. the difference between map base and the link base. Explain the meaning of the field in the man page. Stop filling the mips-only l_offs member, which is apparently unused. PR: 246561 Requested by: Damjan Jovanovic <damjan.jov@gmail.com> Reviewed by: emaste, jhb, cem (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24918 Notes: svn path=/head/; revision=361303
* Implement RTLD_DEEPBIND.Konstantin Belousov2020-05-152-0/+5
| | | | | | | | | | | PR: 246462 Tested by: Martin Birgmeier <d8zNeCFG@aon.at> Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24841 Notes: svn path=/head/; revision=361073
* Remove tests for obsolete compilers in the build systemEric van Gyzen2020-05-121-4/+0
| | | | | | | | | | | | | | Assume gcc is at least 6.4, the oldest xtoolchain in the ports tree. Assume clang is at least 6, which was in 11.2-RELEASE. Drop conditions for older compilers. Reviewed by: imp (earlier version), emaste, jhb MFC after: 2 weeks Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D24802 Notes: svn path=/head/; revision=360964
* Move ARM specific flags to arm/Makefile.incMichal Meloun2020-04-292-3/+2
| | | | | | | | Requested by: kib MFC with: r360463 Notes: svn path=/head/; revision=360469
* Don't allow to use FPU inside of rtld library.Michal Meloun2020-04-291-0/+3
| | | | | | | | | | | Clang10 may use FPU instructions for optimizing operations with memory blocks. But we don't want to do lengthy save/restore of all FPU registers across each rtld_start() call. MFC after: 3 week Notes: svn path=/head/; revision=360463
* rtld: ignore static TLS segments when tracing.Konstantin Belousov2020-04-222-4/+5
| | | | | | | | | | | | | | | | | For PIE binaries, ldd(1) performs dlopen(RTLD_TRACE) on the binary. It is legal for binary to use initial exec TLS mode, but when such binary (actually dso) is dlopened, we might not have enough free space in the finalized static TLS segment. Make ldd operational by skipping TLS space allocation, we are not going to execute any code from the dso anyway. Reported by: tobik PR: 245677 Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=360201
* Align initial-exec TLS segments to the p_vaddr % align.Konstantin Belousov2020-04-1911-33/+86
| | | | | | | | | | | | | | | This is continuation of D21163/r359634, which handled the alignment for global mode. Non-x86 arches are not handled, maintainers are welcomed. Tested by: emaste Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D24366 Notes: svn path=/head/; revision=360091
* Make p_vaddr % p_align == p_offset % p_align for (some) TLS segments.Konstantin Belousov2020-04-044-35/+49
| | | | | | | | | | | | | | | | | | See https://sourceware.org/bugzilla/show_bug.cgi?id=24606 for the test case. See https://reviews.llvm.org/D64930 for the background and more discussion. Also this fixes another bug in malloc_aligned() where total size of the allocated memory might be not enough to fit the aligned requested block after the initial pointer is incremented by the pointer size. Reviewed by: bdragon Tested by: antoine (exp-run PR 244866), bdragon, emaste Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D21163 Notes: svn path=/head/; revision=359634
* Remove sparc64 source files from rtld-elfWarner Losh2020-02-264-1139/+0
| | | | | | | | | These were missed in the prior sweep. Submitted by: jhb@ Notes: svn path=/head/; revision=358358
* Remove sparc64 specific parts of rtld-elf.Warner Losh2020-02-263-12/+5
| | | | Notes: svn path=/head/; revision=358346
* vfs: add realpathat syscallMateusz Guzik2020-02-201-1/+1
| | | | | | | | | | | | | | | | | | realpath(3) is used a lot e.g., by clang and is a major source of getcwd and fstatat calls. This can be done more efficiently in the kernel. This works by performing a regular lookup while saving the name and found parent directory. If the terminal vnode is a directory we can resolve it using usual means. Otherwise we can use the name saved by lookup and resolve the parent. See the review for sample syscall counts. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D23574 Notes: svn path=/head/; revision=358172
* r357895: fix typo in the relocation name for i386 IRELATIVE.Konstantin Belousov2020-02-141-1/+1
| | | | | | | | | Reported by: antoine Sponsored by: The FreeBSD Foundation MFC after: 6 days Notes: svn path=/head/; revision=357910
* Handle non-plt IRELATIVE relocations, at least for x86.Konstantin Belousov2020-02-1311-49/+180
| | | | | | | | | | | | | lld 10.0 seems to generate this relocation for rdtsc_mb() ifunc in our libc. Reported, reviewed, and tested by: dim (amd64, previous version) Discussed with: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D23652 Notes: svn path=/head/; revision=357895
* Fix indent.Konstantin Belousov2020-02-121-20/+24
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 3 days Notes: svn path=/head/; revision=357813
* Use sigfastblock(2) in rtld.Konstantin Belousov2020-02-094-41/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | This allows for rtld to not issue two sigprocmask(2) syscalls for each symbol binding operation in single-threaded processes. Rtld needs to block signals as part of locking to ensure signal safety of the bind process, because signal handlers might need to lazily resolve symbol references. As result, number of syscalls issued on startup by simple programs not using libthr, is typically reduced 2x. For instance, for hello world, I see: non-sigfastblock # (truss ./hello > /dev/null) |& wc -l 63 sigfastblock # (truss ./hello > /dev/null) |& wc -l 37 Tested by: pho Disscussed with: cem, emaste, jilles Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D12773 Notes: svn path=/head/; revision=357697
* rtld: remove hand rolled memset and bzeroMateusz Guzik2020-01-152-25/+3
| | | | | | | | | | | | | | | They were introduced to take care of ifunc, but right now no architecture provides ifunc'ed variants. Since rtld uses memset extensively this results in a pessmization. Should someone want to use ifunc here they should provide a mandatory symbol (e.g., rtld_memset). See the review for profiling data. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D23176 Notes: svn path=/head/; revision=356741
* rtld: clean up Makefile.Konstantin Belousov2020-01-117-32/+18
| | | | | | | | | | | | | Move all MD statements into $MACHINE_ARCH/Makefile.inc. Unconditionally apply version script to rtld, the interpreter is not functional without it for long time. Reviewed by: brooks, emaste Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D23083 Notes: svn path=/head/; revision=356631
* Stop prepending prefix to the result of realpath(3).Konstantin Belousov2020-01-111-21/+6
| | | | | | | | | | | | The path is already absolute. Noted and reviewed by: rstone Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D23121 Notes: svn path=/head/; revision=356630