aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf/rtld.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r362958Leandro Lupori2020-07-201-1/+4
| | | | | | | Handle non-PLT GNU IFUNC relocations in rtld Notes: svn path=/stable/12/; revision=363372
* MFC r362347:Konstantin Belousov2020-06-251-0/+1
| | | | | | | rtld: Apply relro to itself. Notes: svn path=/stable/12/; revision=362604
* MFC r362346:Konstantin Belousov2020-06-251-0/+30
| | | | | | | rtld: Parse own phdr and notes. Notes: svn path=/stable/12/; revision=362603
* MFC r362251:Konstantin Belousov2020-06-231-3/+4
| | | | | | | rtld: Allow to load ET_DYN && DF_1_PIE when tracing. Notes: svn path=/stable/12/; revision=362526
* MFC r362250:Konstantin Belousov2020-06-231-0/+3
| | | | | | | rtld: Add debug line for dlopen_object(). Notes: svn path=/stable/12/; revision=362525
* MFC r362249:Konstantin Belousov2020-06-231-2/+3
| | | | | | | Systematically pass RTLD_LO_TRACE to load_needed_objects(). Notes: svn path=/stable/12/; revision=362524
* MFC r362128:Konstantin Belousov2020-06-191-2/+31
| | | | | | | rtld: set osrel when in the direct exec mode. Notes: svn path=/stable/12/; revision=362370
* MFC r361725, r361728:Konstantin Belousov2020-06-091-0/+6
| | | | | | | Do not allow to load ET_DYN object with DF_1_PIE flag set. Notes: svn path=/stable/12/; revision=361963
* MFC r361672, r361675, r361676, r361680:Konstantin Belousov2020-06-071-14/+57
| | | | | | | rtld direct exec: add -b and -v options. Notes: svn path=/stable/12/; revision=361881
* MFC r361303, r361349, r361394, r361398, r361537:Konstantin Belousov2020-05-271-35/+46
| | | | | | | | | Change link_map::l_addr to mean load offset in ABI-compatible way. Add link_map::l_refname. Add rtld feature indicators. Notes: svn path=/stable/12/; revision=361564
* MFC r361073:Konstantin Belousov2020-05-221-0/+4
| | | | | | | | | Implement RTLD_DEEPBIND. PR: 246462 Notes: svn path=/stable/12/; revision=361380
* MFC r360091:Konstantin Belousov2020-04-291-5/+6
| | | | | | | Align initial-exec TLS segments to the p_vaddr % align. Notes: svn path=/stable/12/; revision=360457
* MFC r360201:Konstantin Belousov2020-04-291-4/+4
| | | | | | | rtld: ignore static TLS segments when tracing. Notes: svn path=/stable/12/; revision=360456
* MFC r359634:Konstantin Belousov2020-04-181-28/+34
| | | | | | | Make p_vaddr % p_align == p_offset % p_align for (some) TLS segments. Notes: svn path=/stable/12/; revision=360067
* MFC r357895, r357910:Konstantin Belousov2020-02-201-1/+4
| | | | | | | Handle non-plt IRELATIVE relocations, at least for x86. Notes: svn path=/stable/12/; revision=358142
* MFC r357813:Konstantin Belousov2020-02-151-20/+24
| | | | | | | Fix indent. Notes: svn path=/stable/12/; revision=357949
* MFC r356548, r356630:Konstantin Belousov2020-01-161-4/+17
| | | | | | | Resolve relative argv0 for direct exec mode to absolute path for AT_EXECPATH. Notes: svn path=/stable/12/; revision=356787
* MFC r356549:Konstantin Belousov2020-01-161-14/+25
| | | | | | | rtld: Return error if $ORIGIN for a dlopen-ed library cannot be resolved. Notes: svn path=/stable/12/; revision=356784
* MFC r356300, r356503:Konstantin Belousov2020-01-091-12/+30
| | | | | | | Fix AT_EXECPATH for direct exec mode. Notes: svn path=/stable/12/; revision=356544
* MFC r347151,347181,347968,348421,348698,348701:Konstantin Belousov2019-06-121-1/+1
| | | | | | | | | | Switch to use shared vnode locks for text files during image activation. For MFC, VOP_GET_WRITECOUNT was left in the slot for KBI stability, but it is unused. Notes: svn path=/stable/12/; revision=348991
* MFC r346225:Konstantin Belousov2019-04-221-1/+20
| | | | | | | Fix order of destructors between main binary and libraries. Notes: svn path=/stable/12/; revision=346537
* MFC r345703:Konstantin Belousov2019-04-121-6/+40
| | | | | | | Fix initial exec TLS mode for dynamically loaded shared objects. Notes: svn path=/stable/12/; revision=346155
* MFC r345620:Konstantin Belousov2019-03-301-7/+7
| | | | | | | rtld: disable relro enforcement for irelative relocation processing. Notes: svn path=/stable/12/; revision=345731
* MFC r339877-r339879,r343564-r343566,r343580,r343754:Konstantin Belousov2019-02-111-72/+123
| | | | | | | | | | | Untangle jemalloc and mutexes initialization. The merge includes required warnings cleanup by arichardson, both to avoid conflicts and to make rtld_malloc.c compilable with the libthr WARNS settings. Notes: svn path=/stable/12/; revision=344011
* MFC r343484:Konstantin Belousov2019-02-031-10/+0
| | | | | | | | Remove now redundand ifunc relocation code which should have been removed as part of r341441. Notes: svn path=/stable/12/; revision=343692
* MFC r342113:Michal Meloun2019-01-071-1/+1
| | | | | | | | | | | Improve R_AARCH64_TLSDESC relocation. The original code did not support dynamically loaded libraries and used suboptimal access to TLS variables. New implementation removes lazy resolving of TLS relocation - due to flaw in TLSDESC design is impossible to switch resolver function at runtime without expensive locking. Notes: svn path=/stable/12/; revision=342847
* MFC r341439:Konstantin Belousov2018-12-101-0/+22
| | | | | | | | Provide naive but self-contained implementations of memset(3) and bzero(3) for rtld. Notes: svn path=/stable/12/; revision=341773
* MFC r341441:Konstantin Belousov2018-12-101-42/+49
| | | | | | | Some fixes for LD_BIND_NOW + ifuncs. Notes: svn path=/stable/12/; revision=341772
* MFC r340858:Konstantin Belousov2018-12-071-0/+8
| | | | | | | rtld: parse FreeBSD Feature Control note on the object load. Notes: svn path=/stable/12/; revision=341687
* MFC r340675:Konstantin Belousov2018-11-271-2/+5
| | | | | | | | rtld: when immediate bind mode is requested, process irelocs in PLT immediately after other PLT relocs. Notes: svn path=/stable/12/; revision=341053
* MFC r339896:Konstantin Belousov2018-11-071-1/+2
| | | | | | | | | Initialize ifunc calling machinery earlier. Approved by: re (gjb) Notes: svn path=/stable/12/; revision=340226
* MFC r340137: rtld: move relro enforcement after ifunc processingEd Maste2018-11-071-4/+4
| | | | | | | | | | | | | | | | | | | Previously the combination of relro (implicit), -z now and ifunc use resulted in a segfault when applying ifuncs after relro (test binary here just calls amd64_get_fsbase()): | % env LD_DEBUG=1 libexec/rtld-elf/obj/ld-elf.so.1 a.out | ... | enforcing main obj relro | ... | resolving ifuncs | reloc_jmpslot: *0x203198 = 0x189368ea4570 | zsh: bus error (core dumped) LD_DEBUG=1 obj/ld-elf.so.1 ~/a.out Approved by: re (gjb) Notes: svn path=/stable/12/; revision=340225
* Provide refobj context when doing libmap substitution insideKonstantin Belousov2018-09-261-33/+47
| | | | | | | | | | | | | | search_library_path(). This corrects the scope of libmap matches. Reported and tested by: Andreas Longwitz <longwitz@incore.de> Sponsored by: The FreeBSD Foundation Approved by: re (gjb) MFC after: 1 week Notes: svn path=/head/; revision=338956
* Rework rtld's TLS Variant I implementation to match r326794Brooks Davis2018-09-051-16/+61
| | | | | | | | | | | | | | | | | | | | | The above commit fixed handling overaligned TLS segments in libc's TLS Variant I implementation, but rtld provides its own implementation for dynamically-linked executables which lacks these fixes. Thus, port these changes to rtld. This was previously commited as r337978 and reverted in r338149 due to exposing a bug the ARM rtld. This bug was fixed in r338317 by mmel. Submitted by: James Clarke Approved by: re (kib) Reviewed by: kbowling Testing by: kbowling (powerpc64), br (riscv), kevans (armv7) Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16510 Notes: svn path=/head/; revision=338486
* Revert r337978: Rework rtld's TLS Variant I implementation to match r326794Brooks Davis2018-08-211-61/+16
| | | | | | | | | | Michal Meloun reports that it breaks ctype (isspace()..) related functions on armv7 so back out while we diagnose the issue. Reported by: Michal Meloun <melounmichal@gmail.com> Notes: svn path=/head/; revision=338149
* Rework rtld's TLS Variant I implementation to match r326794Brooks Davis2018-08-171-16/+61
| | | | | | | | | | | | | | | | | The above commit fixed handling overaligned TLS segments in libc's TLS Variant I implementation, but rtld provides its own implementation for dynamically-linked executables which lacks these fixes. Thus, port these changes to rtld. Submitted by: James Clarke Reviewed by: kbowling Testing byL kbowling (powerpc64), br (riscv), kevans (armv7) Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16510 Notes: svn path=/head/; revision=337978
* Make sure the rtld(1) error messages go to stderr, not stdout.Edward Tomasz Napierala2018-08-021-15/+15
| | | | | | | | | | | | | | While here fix capitalization of a few nearby strings, add the rtld's file name prefix so it's obvious where the message come from, and return zero when "-h" is used. Reviewed by: kib MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16530 Notes: svn path=/head/; revision=337067
* Make rtld use libc_nossp_pic.a. Remove SSP shims.Konstantin Belousov2018-05-091-42/+1
| | | | | | | | | Submitted by: Luis Pires Reviewed by: brooks Differential revision: https://reviews.freebsd.org/D15341 Notes: svn path=/head/; revision=333398
* o Let rtld(1) set up psABI user trap handlers prior to executing theMarius Strobl2018-02-031-0/+6
| | | | | | | | | | | | | | | | | objects' init functions instead of doing the setup via a constructor in libc as the init functions may already depend on these handlers to be in place. This gets us rid of: - the undefined order in which libc constructors as __guard_setup() and jemalloc_constructor() are executed WRT __sparc_utrap_setup(), - the requirement to link libc last so __sparc_utrap_setup() gets called prior to constructors in other libraries (see r122883). For static binaries, crt1.o still sets up the user trap handlers. o Move misplaced prototypes for MD functions in to the MD prototype section of rtld.h. o Sprinkle nitems(). Notes: svn path=/head/; revision=328834
* libexec: adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. No functional change intended. Notes: svn path=/head/; revision=326274
* Remove unneeded calls to access(2) from rtld(1); just call open(2) instead.Edward Tomasz Napierala2017-10-241-13/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The result looks like this: --- przed 2017-10-21 23:19:21.445034000 +0100 +++ po 2017-10-21 23:18:50.031865000 +0100 @@ -11,7 +11,6 @@ mmap(0x0,102,PROT_READ,MAP_PRIVATE,3,0x0) = 343665418 close(3) = 0 (0x0) open("/usr/local/etc/libmap.d",O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC,0165) ERR#2 'No such file or directory' munmap(0x80067d000,102) = 0 (0x0) -access("/usr/local/lib/libintl.so.8",F_OK) = 0 (0x0) openat(AT_FDCWD,"/usr/local/lib/libintl.so.8",O_RDONLY|O_CLOEXEC|O_VERIFY,00) = 3 (0x3) fstat(3,{ mode=-rw-r--r-- ,inode=642560,size=55188,blksize=32768 }) = 0 (0x0) mmap(0x0,4096,PROT_READ,MAP_PRIVATE|MAP_PREFAULT_READ,3,0x0) = 34366541824 (0x80067d000) @@ -20,14 +19,13 @@ mmap(0x800877000,40960,PROT_READ|PROT_EXEC,MAP_PRIVATE mmap(0x800a81000,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_PREFAULT_READ,3,0xa000) = 34370752512 (0x800a81000) munmap(0x80067d000,4096) = 0 (0x0) close(3) = 0 (0x0) -access("/usr/local/lib/libc.so.7",F_OK) ERR#2 'No such file or directory' +openat(AT_FDCWD,"/usr/local/lib/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,00) ERR#2 'No such file or directory' openat(AT_FDCWD,"/var/run/ld-elf.so.hints",O_RDONLY|O_CLOEXEC,00) = 3 (0x3) read(3,"Ehnt\^A\0\0\0\M^@\0\0\0\M-2\0\0"...,128) = 128 (0x80) fstat(3,{ mode=-r--r--r-- ,inode=970684,size=306,blksize=32768 }) = 0 (0x0) lseek(3,0x80,SEEK_SET) = 128 (0x80) read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,178) = 178 (0xb2) close(3) = 0 (0x0) -access("/lib/libc.so.7",F_OK) = 0 (0x0) openat(AT_FDCWD,"/lib/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,00) = 3 (0x3) fstat(3,{ mode=-r--r--r-- ,inode=1605239,size=1910320,blksize=32768 }) = 0 (0x0) mmap(0x0,4096,PROT_READ,MAP_PRIVATE|MAP_PREFAULT_READ,3,0x0) = 34366541824 (0x80067d000) Reviewed by: kib MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D12766 Notes: svn path=/head/; revision=324953
* Replace lseek(2)/read(2) pair with pread(2), removing yet another syscallEdward Tomasz Napierala2017-10-241-4/+3
| | | | | | | | | | from the binary startup code. MFC after: 2 weeks Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=324952
* Make find_library() conform to style(9). No functional changes.Edward Tomasz Napierala2017-10-241-78/+79
| | | | | | | | | Suggested by: kib MFC after: 2 weeks Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=324951
* Reword the conditional; it was ugly, and adding another parameter,Edward Tomasz Napierala2017-10-241-17/+44
| | | | | | | | | | | which I'm going to do in a subsequent commit, would make it even uglier. No functional changes. MFC after: 2 weeks Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=324950
* Handle relocations for newer non-PIC MIPS ABI.John Baldwin2017-09-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Newer binutils supports extensions to the MIPS ABI for non-PIC code that is used when compiling O32 binaries with clang 5 (but not used for N64 oddly enough). These extensions require support for R_MIPS_COPY relocations as well as a second PLT GOT using R_MIPS_JUMP_SLOT relocations. For R_MIPS_COPY, use the same approach as on other architectures where fixups are deferred to the MD do_copy_relocations. The additional PLT GOT for jump slots is located in a .got.plt section which is identified by a DT_MIPS_PLTGOT dynamic entry. This GOT also requires fixups for the first two GOT entries just as the normal GOT. However, the entry point for this second GOT uses a different calling convention. Rather than passing an offset into the GOT, it passes an offset into the .rel.plt section. This requires a second entry point (_rtld_pltbind_start) which calls the normal _rtld_bind() rather than _mips_rtld_bind(). This also means providing a real version of reloc_jmpslot() which is used by _rtld_bind(). In addition, add real implementions of reloc_plt() and reloc_jmpslots() which walk .rel.plt handling R_MIPS_JUMP_SLOT relocations. Reviewed by: kib Sponsored by: DARPA / AFRL Differential Revision: https://reviews.freebsd.org/D12326 Notes: svn path=/head/; revision=323501
* Read max_stack_flags from correct object.John Baldwin2017-08-301-1/+1
| | | | | | | | | | | 'obj' is not initialized here. Reviewed by: kib MFC after: 1 week Sponsored by: DARPA / AFRL Notes: svn path=/head/; revision=323025
* o Replace __riscv__ with __riscvRuslan Bukin2017-08-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | o Replace __riscv64 with (__riscv && __riscv_xlen == 64) This is required to support new GCC 7.1 compiler. This is compatible with current GCC 6.1 compiler. RISC-V is extensible ISA and the idea here is to have built-in define per each extension, so together with __riscv we will have some subset of these as well (depending on -march string passed to compiler): __riscv_compressed __riscv_atomic __riscv_mul __riscv_div __riscv_muldiv __riscv_fdiv __riscv_fsqrt __riscv_float_abi_soft __riscv_float_abi_single __riscv_float_abi_double __riscv_cmodel_medlow __riscv_cmodel_medany __riscv_cmodel_pic __riscv_xlen Reviewed by: ngie Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D11901 Notes: svn path=/head/; revision=322168
* Allow to specify targets by absolute paths in libmap.conf.Konstantin Belousov2017-07-271-9/+10
| | | | | | | | | Submitted by: Tatu Kilappa <tatu.kilappa@iki.fi> PR: 221032 MFC after: 2 weeks Notes: svn path=/head/; revision=321607
* In open_binary_fd: when using buffer size for strl* and snprintf,Xin LI2017-07-051-3/+3
| | | | | | | | | | | always use >= instead of > to avoid truncation. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D11474 MFC after: 3 days Notes: svn path=/head/; revision=320665
* When reporting undefined symbol, note the version, if specified.Konstantin Belousov2017-07-041-3/+7
| | | | | | | | | | | | Use the standard syntax of name@version, I do not expect a confusion due to unlikely possibility of the name containing the '@' character. Requested by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=320658