Commit Graph

1024 Commits

Author SHA1 Message Date
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
martin
e4d02a93c7 Add support for DT_RUNPATH - it is just the same as we always have treated
DT_RPATH.  Approved by core.
2018-12-30 11:55:15 +00:00
christos
d30b19ef3d - fix wrong reloc name in assert
- fix uninitialized
2018-12-30 03:23:46 +00:00
christos
61268f23da binutils 2.31.1 can put copy relocations in the relro segment. Delay
protecting the relro segment for the main object until copy relocations
are done.
2018-12-30 01:48:37 +00:00
christos
2c62c57fa6 initfini array support for everyone. 2018-12-27 18:58:14 +00:00
christos
ba044c6310 explain why we skip objmain. 2018-12-27 18:57:43 +00:00
skrll
66b7511afb Fix typos 2018-12-01 13:01:57 +00:00
joerg
335f313f07 Now that lib/csu no longer uses the object handle, drop the magic and
version field from the internal object. It is kept in the legacy version
of the main object.
2018-11-26 17:40:26 +00:00
skrll
c7af211bee Fix RTLD_DEBUG_RELOC build 2018-11-23 11:26:05 +00:00
skrll
0d71550e67 Trailing whitespace 2018-11-23 10:59:20 +00:00
joerg
4312beab4f Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.
2018-10-17 23:36:58 +00:00