Commit graph

926 commits

Author SHA1 Message Date
Konstantin Belousov
bc53b440fb rtld: remove unused macro FPTR_TARGET
(cherry picked from commit f585d13dd6)
2022-10-25 03:37:43 +03:00
Konstantin Belousov
d074059e98 rtld: fix typo in comment
(cherry picked from commit ca2560bd85)
2022-10-19 18:00:42 +03:00
Konstantin Belousov
5955bc6b69 rtld: teach LD_SHOW_AUXV about AT_USRSTACK*
(cherry picked from commit daa85548d5)
2022-09-30 03:29:10 +03:00
Konstantin Belousov
6958ee33b7 ldd: remove '[preloaded]' marker for the preloaded objects
PR:	265750

(cherry picked from commit 2f72ee987d)
2022-09-29 03:29:09 +03:00
Konstantin Belousov
5593488d8b rtld-elf/libmap.c: correct comment
(cherry picked from commit 1251cf8a30)
2022-09-25 14:18:25 +03:00
Konstantin Belousov
b76c89cb33 rtld-elf/libmap.h: style declarations
(cherry picked from commit 1fd4dec26e)
2022-09-25 14:18:25 +03:00
Konstantin Belousov
eb9f61ee16 rtld-elf/libmap.h: add include guard
(cherry picked from commit 3aed5ddb8b)
2022-09-25 14:18:24 +03:00
Konstantin Belousov
fd73d53223 rtld.c: remove extra blank line
(cherry picked from commit 832b40f7ff)
2022-09-18 03:33:46 +03:00
Konstantin Belousov
b09c2d924f rtld: style the rest of rtld_lock.c
(cherry picked from commit 7444f54bd3)
2022-09-18 03:33:45 +03:00
Konstantin Belousov
982584532d rtld: mask signals for default read locks
(cherry picked from commit a687683b99)
2022-09-18 03:33:45 +03:00
Gordon Bergling
eadbe9faeb rtld(1): Fix a typo in a source code comment
- s/interger/integer/

(cherry picked from commit 3576233cd3)
2022-09-06 07:42:17 +02:00
Konstantin Belousov
a5afb6fe1a rtld: fix display of the mapbase for the traced objects
(cherry picked from commit 008475d3c8)
2022-08-17 03:34:09 +03:00
Jessica Clarke
461cad31f3 rtld-elf: Fix leaks and wild frees in origin_subst
55abf23dd3 inverted the value passed to origin_subst_one when rolling
up the existing code into a loop. If the first token is found ($ORIGIN),
this results in a wild free of part of strtab. Processing the second
token works fine and will act how the first should have regardless of
whether found, allocating memory for the string without freeing.
Processing subsequent tokens however will then leak, regardless of
whether found, as they will also believe they need to allocate memory
and can't free the string.

Found by:	CHERI
Reviewed by:	kib, markj
Fixes:		55abf23dd3 ("rtld: make token substitution table-driven")
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D35792

(cherry picked from commit becd9908be)
2022-08-11 00:11:48 +01:00
Andrew Turner
f9bea2bdff Have rtld query the page size from the kernel
To allow for a dynamic page size on arm64 have the runtime linker
query the kernel for the currentl page size.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34765

(cherry picked from commit e85eaa9308)
2022-05-03 15:04:04 +01:00
John Baldwin
a641444939 TLS: Use <machine/tls.h> for libc and rtld.
- Include <machine/tls.h> in MD rtld_machdep.h headers.

- Remove local definitions of TLS_* constants from rtld_machdep.h
  headers and libc using the values from <machine/tls.h> instead.

- Use _tcb_set() instead of inlined versions in MD
  allocate_initial_tls() routines in rtld.  The one exception is amd64
  whose _tcb_set() invokes the amd64_set_fsbase ifunc.  rtld cannot
  use ifuncs, so amd64 inlines the logic to optionally write to fsbase
  directly.

- Use _tcb_set() instead of _set_tp() in libc.

- Use '&_tcb_get()->tcb_dtv' instead of _get_tp() in both rtld and libc.
  This permits removing _get_tp.c from rtld.

- Use TLS_TCB_SIZE and TLS_TCB_ALIGN with allocate_tls() in MD
  allocate_initial_tls() routines in rtld.

Reviewed by:	kib, jrtc27 (earlier version)
Differential Revision:	https://reviews.freebsd.org/D33353

(cherry picked from commit 8bcdb144eb)
2022-04-29 13:50:05 -07:00
John Baldwin
1e2235df43 amd64: Allocate TCB with alignment of 16 rather than 8.
This matches the TLS_TCB_ALIGN definition in libc.

Reviewed by:	kib, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33349

(cherry picked from commit 299617496c)
2022-04-29 13:50:05 -07:00
John Baldwin
b602867013 mips: Add TLS_DTV_OFFSET to the result of tls_get_addr_common.
Previously TLS_DTV_OFFSET was added to the offset passed to
tls_get_addr_common; however, this approach matches powerpc and RISC-V
and better matches the intention.

Reviewed by:	kib, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33347

(cherry picked from commit 23e0c0e9a3)
2022-04-29 13:50:05 -07:00
John Baldwin
bd3afd5274 mips: Rename TLS_DTP_OFFSET to TLS_DTV_OFFSET.
This is the more standard name for the bias of dtv pointers used on
other platforms.  This also fixes a few other places that were using
the wrong bias previously on MIPS such as dlpi_tls_data in struct
dl_phdr_info and the recently added __libc_tls_get_addr().

Reviewed by:	kib, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33346

(cherry picked from commit 03f6b14106)
2022-04-29 13:50:04 -07:00
John Baldwin
6138e84981 rtld-elf: Use _get_tp in __tls_get_addr for aarch64 and riscv64.
Reviewed by:	kib
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33047

(cherry picked from commit b928e924f7)
2022-04-29 13:50:04 -07:00
Konstantin Belousov
c193f01267 rtld: trace preloaded objects
(cherry picked from commit 0913953c9e)
2022-04-08 04:25:17 +03:00
Konstantin Belousov
739e497145 rtld trace_loaded_objects(): use bool for the list_containers variable
(cherry picked from commit db0372808a)
2022-04-08 04:25:17 +03:00
Konstantin Belousov
6c32463ba5 rtld: use style(9) for trace_loaded_objects()
(cherry picked from commit b0bc8cc705)
2022-04-08 04:25:17 +03:00
Konstantin Belousov
bd36c56807 rtld: extract printer for a single traced object into a helper
(cherry picked from commit 24d0c9c1f5)
2022-04-08 04:25:17 +03:00
Konstantin Belousov
61bb7ef551 rtld: extract calculation of the format strings for trace into a helper
(cherry picked from commit c25f36f630)
2022-04-08 04:25:17 +03:00
John F. Carr
19624b4c6b rtld.1: Fix misplaced text
PR:		262194
Fixes:		f90218886f ("rtld: introduce PRELOAD_FDS")

(cherry picked from commit 6c799530d8)
2022-02-28 09:05:30 -05:00
Konstantin Belousov
6914c8ff5d rtld: Add ${TOKEN} aliases to $TOKEN
(cherry picked from commit b1b5174123)
2022-02-18 04:01:24 +02:00
Konstantin Belousov
1bce4afb06 rtld: make token substitution table-driven
(cherry picked from commit 55abf23dd3)
2022-02-18 04:01:24 +02:00
Konstantin Belousov
1a28d9343c rtld: load preloaded vdso
(cherry picked from commit c210ef1347)
2022-01-02 18:43:01 +02:00
Konstantin Belousov
d00ebd9b9c Pass vdso address to userspace
(cherry picked from commit 01c77a436e)
2022-01-02 18:43:01 +02:00
Konstantin Belousov
ba839bc9d3 rtld: extract header validation into new helper check_elf_headers()
(cherry picked from commit 63fc4e820c)
2021-12-13 02:58:22 +02:00
Ed Maste
bf4a70bb40 libc: Use musl's optimized strchr and strchrnul
Parentheses added to HASZERO macro to avoid a GCC warning, and formatted
with clang-format as we have adopted these and don't consider them
'contrib' code.

Obtained from:	musl (snapshot at commit 4d0a82170a25)
Reviewed by:	kib (libc integration), mjg (both earlier)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17630

(cherry picked from commit 7f72497ef7)
2021-12-12 17:32:33 -05:00
Konstantin Belousov
a95dbfaa3d rtld_paths.h: Provide _PATH_ELF32_HINTS string, unconditionally
(cherry picked from commit f340188625)
2021-12-01 03:07:19 +02:00
Konstantin Belousov
b26ac07d6c rtld dump_auxv: be pedantic and distiguish between auxv union members based on format
(cherry picked from commit b61bce17f3)
2021-11-19 06:25:27 +02:00
Konstantin Belousov
f363b08c6d rtld dump_auxv: consistently use long modifier for non-pointer auxv vals
(cherry picked from commit 3a902ef253)
2021-11-19 06:25:27 +02:00
Konstantin Belousov
8ade0046f6 rtld: Implement LD_SHOW_AUXV
(cherry picked from commit 64ba1f4cf3)
2021-11-19 06:25:27 +02:00
Konstantin Belousov
ec3bd288b6 rtld: add rtld_fdprintfx()
(cherry picked from commit 77c088ab21)
2021-11-19 06:25:27 +02:00
Konstantin Belousov
7647baa1e8 rtld: style adjustments
(cherry picked from commit 74aec9618f)
2021-11-10 21:36:20 +02:00
Konstantin Belousov
1d6fd007eb rtld: ignore fstatfs(2) errors when checking MNT_NOEXEC flag
(cherry picked from commit c5637b8be8)
2021-11-10 21:36:20 +02:00
Konstantin Belousov
514a095250 rtld: fix dangerous_ld_env calculation for ld_dynamic_weak
(cherry picked from commit 8363963a8f)
2021-11-09 06:49:26 +02:00
Emmanuel Vadot
b6b9176030 rtld: Do not install libmap.conf when installing the COMPAT32 version
This has the effect of installing the same file twice at the same location
and confuse pkgbase as we add this file twice in the package config part.

MFC after:  1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG

(cherry picked from commit d0f0e0bd74)
2021-11-06 16:03:06 +01:00
Konstantin Belousov
57dc5bdc12 rtld: Print currently configured search path for libraries for -v
(cherry picked from commit 40ddde6ef9)
2021-10-28 03:35:53 +03:00
Konstantin Belousov
a3876ab1eb rtld-elf/paths.h: Make it usable outside rtld
(cherry picked from commit 33dba3bb0e)
2021-10-23 02:32:27 +03:00
Fangrui Song
c99fa2c634 rtld: Support DT_RELR relative relocation format
(cherry picked from commit a7d137fcbc)
2021-10-23 02:32:27 +03:00
Konstantin Belousov
00df149452 crt_malloc: more accurate handling of mmap(2) failure
PR:	259076

(cherry picked from commit 73dddffc31)
2021-10-23 02:32:27 +03:00
Konstantin Belousov
e5a8b8152a crt_malloc: Be more persistent when handling mmap() failure
PR:	259076

(cherry picked from commit 19e008e7f7)
2021-10-23 02:32:27 +03:00
Konstantin Belousov
cf12f7ba97 crt_malloc: use uintptr_t instead of long for arithmetic on addresses
(cherry picked from commit 0b72d2965d)
2021-10-23 02:32:27 +03:00
Konstantin Belousov
5aebce3790 rtld direct exec: add -d option
(cherry picked from commit ba7f9c1b61)
2021-10-20 03:42:25 +03:00
Konstantin Belousov
2c0233d2a0 rtld: constify most variables holding references to the environment values
(cherry picked from commit aa68b3bb2e)
2021-08-23 12:20:56 +03:00
Konstantin Belousov
2b5ccf507a rtld: provide private getenv(3)
(cherry picked from commit b4b2748891)
2021-08-23 12:20:56 +03:00
Konstantin Belousov
f2f2f23ad7 rtld: avoid use of of getenv(3) for evaluating rtld env vars (LD_XXX)
(cherry picked from commit bfd4c875a1)
2021-08-23 12:20:56 +03:00