Commit Graph

1034 Commits

Author SHA1 Message Date
skrll 45f12ca261 Restore the fptr_t type of {init,fini}{,_array} that was removed when initial
support for indirect functions was added.  This fixes {init,fini}_array support
on hppa where each member of the array is (already) a plabel.

Discussed with joerg.

 4 files changed, 29 insertions(+), 39 deletions(-)
: ----------------------------------------------------------------------
2021-12-04 14:39:08 +00:00
skrll dab59e4bc1 Provide a stub _rtld_call_ifunc when a platform doesn't use one of the
common ones or doesn't provide its own.
2021-12-04 08:53:34 +00:00
skrll 741d1b8708 Add a newline 2021-12-04 08:50:41 +00:00
skrll 95123c27a8 Error if there are undefined symbols, e.g. _rtld_call_ifunc 2021-12-04 08:45:56 +00:00
riastradh 07fb20a384 ld.elf_so(1): Omit needless membar_enter.
The use of membar_enter is to separate atomic r/m/w on a lock from
the body of the critical section so two different critical sections
happen in order:

		body of previous critical section;

	exit critical section:
		membar_exit();
		atomic_r/m/w(lock stuff);

	enter critical section:
		atomic_r/m/w(lock stuff);
		membar_enter();

		body of next critical section;

_rtld_shared_enter does this, but it _also_ issued an extraneous
membar_enter before the atomic_r/m/w part, which doesn't impose any
semantically important order but may cost some performance.
2021-06-16 21:53:51 +00:00
joerg 130482d98d Don't use the return address hack with clang. 2021-05-30 02:26:08 +00:00
christos 0f1e1628dd Don't or the got object in, just assign it. Fixes cc -mabi=64 hello.c -lcrypto
Now all 64 bit binaries work, and I tested that we did not break the 32 bit
ones
XXX: That 0x80000000 seems wrong for 64 bit stuff.
2021-03-06 20:11:08 +00:00
christos d42a77727b pretend we know about %# and %j... 2021-03-06 20:09:39 +00:00
kamil f420d54c39 Correct r_ldbase valuse
It shall be the relocbase value, not linkmap.
2020-09-22 00:41:27 +00:00
kamil f3656ffa1a Upgrade the SVR4 RTLD r_debug protocol to version 1
Changes:
 - Add a new field r_ldbase in the r_debug struct.
 - Set r_version to 1.

This harmonizes the support with OpenBSD and Linux.
FreeBSD uses version 0 (or no version).
Solaris uses version 2 that is not implemented elsewhere and relies on
SVR4 specific design and interfaces.

Update the code comments as r_debug and link_map is used by other software
than GDB, namely: sanitizers, rump, LLDB.
2020-09-21 16:08:57 +00:00
joerg 5df17207d3 R_ARM_TLS_TPOFF32 needs to adjust the existing value, not blindly
overwrite it.
2020-06-16 21:02:20 +00:00
joerg 41844ca786 Honor addend for R_AARCH64_TLS_TPREL relocation. 2020-06-16 21:01:30 +00:00
macallan d4e6a9fda0 new binutils/gcc started emitting R_PPC_UADDR32 reloc entries, so for now
treat them like R_PPC_ADDR32
XXX
these relocs have been observed in the xf86-video-radeon driver, but only in
the AtomBios support code, which is unused on PowerPC. This allows the driver
to load but it's not clear if the affected parts would actually function.
2020-05-24 02:33:11 +00:00
skrll d736ede907 Fix debug build 2020-05-16 16:43:15 +00:00
skrll eeabd67ad2 Avoid compiler warnings about uninitialised symnum 2020-05-16 16:43:00 +00:00
skrll fab263653b Trailing whitespace 2020-05-10 06:42:38 +00:00
joerg dca0c0f499 Mark _rtld_invalid_paths static as ldd can end up with two copies 2020-04-22 23:54:32 +00:00
joerg 25a494ecc4 Rename __atomic_fork to __locked_fork and give it &errno as argument.
rtld and libc use different storage, so the initial version would
incorrectly report the failure reason for fork().

There is still a small race condition inside ld.elf_so as it doesn't use
thread-safe errno internally, but that's a more contained internal
issue.
2020-04-19 01:06:15 +00:00
joerg 11954c74b6 Introduce intermediate locking for fork, so that the dynamic linker is
in a consistent state. This most importantly avoids races between dlopen
and friends and fork, potentially resulting in dead locks in the child
when it itself tries to acquire locks.
2020-04-16 14:39:58 +00:00
thorpej da570a6238 PT_GNU_RELRO segments are arranged such that their vaddr + memsz ends
on a linker common page size boundary.  However, if the common page size
used by the linker is less than the VM page size being used by the kernel,
this can end up in the middle of a VM page and when the region is write-
protected, this can cause objects in neighboring .data to get incorrectly
write-protected, resulting in a crash.

Avoid this situation by calculating the end of the RELRO region not by
rounding memsz up to the VM page size, but rather by adding vaddr + memsz
and then truncating to the VM page size.

Fixes PR toolchain/55043.

XXX pullup-9
2020-03-04 01:21:17 +00:00
kamil 0b0e2ac42c Add extra cast to suppress incompatible-pointer-types GCC warning 2020-02-29 18:53:55 +00:00
kamil 33f6117993 Fix vax and mips build 2020-02-29 18:45:20 +00:00
kamil e8e477017a Implement DT_GNU_HASH
DT_GNU_HASH serves the same purpose as DT_HASH, however it is a distinct
and faster apprach implemented and designed in the GNU toolchain in 2006.

DT_GNU_HASH is preferred whenever available.

Original GNU benchmarks claim 50% faster dynamic linking time.
https://www.sourceware.org/ml/binutils/2006-06/msg00418.html

Code based on FreeBSD and OpenBSD, both were based on DragonFlyBSD.
2020-02-29 04:24:33 +00:00
kamil 4e9bea3d5d Implement and integrate GNU Hashing function
Define Elf_Hash struct that contains ELF/SYSV and GNU hash checksum.
Implement _rtld_gnu_hash() for DT_GNU_HASH.
Adapt existing code to compute all Elf_Hash types, instead of only
the ELF/SYSV one.
Rename _rtld_elf_hash() to _rtld_sysv_hash() to match the GNU toolchain
terminology.

_rtld_gnu_hash() uses Dan Bernstein's string hash function posted eons ago
on comp.lang.c.
2020-02-29 04:23:05 +00:00
kamil e5a904478f Separate matched symbol functionality out of _rtld_symlook_obj()
Simplifies the code and it will allow to use the matched symbol
functionality by other users.
2020-02-29 04:21:42 +00:00
kamil ac23308f24 Specify NOLIBCSANITIZER for the ELF loader
The sanitizer does not work reliably before finishing initialization of
ld.elf_so. There is also a number of false positives that are not real
problems here.
2020-02-09 09:11:59 +00:00
uwe 3582b90734 Use existing lo() and hi() macros. Same object code is generated. 2019-12-08 23:49:16 +00:00
uwe f3a8613fae Resolve ADDR16_LO, ADDR16_HI, and ADDR16_HA relocs.
Recent GNU ld does not resolve them statically if the reloc is in a
writable section and the symbol is not already referenced from text.
2019-12-08 22:57:51 +00:00
uwe 1cea4da77d Fix typo in a comment. 2019-12-08 22:41:42 +00:00
uwe 9332bf7c88 _rtld_relro - fix debug printf format for a size_t argument 2019-12-08 22:35:27 +00:00
joerg 336e4f812b Use alignof and not size_t for platforms with non-natural base
alignments.
2019-11-05 22:22:42 +00:00
joerg a0e0f8b685 PR 54093: Align static TLS area to max_align_t. 2019-11-04 12:45:10 +00:00
christos ba0758a3b7 simplify pointer gymnastics that sprained gcc-8 2019-11-03 03:15:59 +00:00
mrg 9d7a8fa9a3 use strlcpy to ensure termination.
the buffer is statically sized so that it works without an
allocator, so truncation is the desired effect here.
2019-10-13 20:18:42 +00:00
christos 7519806b07 use __func__ (c99, c++11) instead of __FUNCTION__ 2019-10-04 01:57:53 +00:00
tnn e91fbc780d improve error message 2019-10-03 10:34:30 +00:00
kamil 3b610a6e8d Return the ELF loader dl_phdr_info information for dl_iterate_phdr(3)
Sync the behavior of dl_iterate_phdr(3) with Linux/FreeBSD/OpenBSD.
2019-09-15 13:40:46 +00:00
maya 3bb853ed54 r_symndx is no longer declared, use symnum and initialize it before use.
Completes the changes in the commit:
"Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects."
http://mail-index.netbsd.org/source-changes/2017/06/19/msg085496.html
2019-04-15 19:13:03 +00:00
maya 53dcb847d9 $ORIGIN support is now enabled.
Thanks martin for the heads up.
2019-04-15 10:17:01 +00:00
abhinav 55eec9d71a Typo: s/a indirection/an indirection/ 2019-04-15 06:42:06 +00:00
wiz a30bc70869 Use more Dv. 2019-04-14 22:09:50 +00:00
maya 9a04775cfa Note that we now search DT_RUNPATH paths as well. 2019-04-14 20:27:02 +00:00
christos fb007af046 undo previous unlock/relock; it is not needed now that we added the tls model
declaration to all externs in jemalloc (suggested by joerg@)
2019-04-14 19:21:37 +00:00
christos 15018ca013 Fix c++ exceptions on arm; jemalloc calls _rtld_tls_get_addr from inside
dl_iterate_phdr, so we need to unlock and relock.
2019-04-13 03:15:25 +00:00
rin e66054b66e Do not compile __tls_get_addr() into ldd(1), which fixes ldd(1) crashing
on arm after switching to new jemalloc.

jemalloc invokes __tls_get_addr() under some condition. If anything other
than ld.elf_so nor libc exports it, inconsistency arises as a result.
2019-04-13 00:23:32 +00:00
christos 39fadeea40 Disable optimization for rtld.c on the vax with gcc-7. 2019-04-03 21:37:58 +00:00
skrll 69e8dca2e5 Adapt https://svnweb.freebsd.org/base?view=revision&revision=342113 to
NetBSD.

This brings us resolving for dynamically loaded libraries and makes
tests/libexec/ld.elf_so/t_thread_local_dtor pass.

With suggestions from joerg@
2019-01-18 11:59:03 +00:00
christos d17b8a0ea7 print the program name when we don't find a library.
XXX: really most _rtld_error() should do that, and most do.
2019-01-12 18:58:10 +00:00
joerg 06c9aa1116 When loading a non-PIE main binary, the virtual address must match.
Use MAP_TRYFIXED and verify that the result matches the expectation.
2019-01-06 19:44:54 +00:00
joerg 08e505b543 MAP_ALIGNED has existed for years, just assume it exists. 2019-01-04 19:54:56 +00:00