Commit graph

418 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Konstantin Belousov
2395d5ddbf rtld: rework how environment variables are named
(cherry picked from commit 451dc2b7cc)
2021-08-23 12:20:56 +03:00
Fangrui Song
edb509a026 rtld: Switch to the standard symbol lookup behavior if LD_DYNAMIC_WEAK is set
(cherry picked from commit 7da378f9de)
2021-08-23 12:20:56 +03:00
Fangrui Song
2aa761055c rtld: Remove calculate_tls_end
(cherry picked from commit 8f63fa78e8)
2021-08-23 12:20:56 +03:00
Konstantin Belousov
02e46073bd rtld: Round down relro_size
(cherry picked from commit c9f833abf1)
2021-08-20 12:31:46 +03:00
Mariusz Zaborski
7b845dc144 rtld: introduce PRELOAD_FDS
(cherry picked from commit f90218886f)
2021-08-20 12:31:46 +03:00
Mariusz Zaborski
a90bcfbadd rtld: style nits
(cherry picked from commit 852a88a1d9)
2021-08-20 12:31:46 +03:00
Alex Richardson
58137266b6 rtld-elf: Check the return value of obj_enforce_relro()
The mprotect() call was failing on CheriBSD when changing rtld's relro
page permissions due to missing CHERI capability permissions on the
mprotect() argument but did not report an error since the return value
was being ignored. It should never fail on any supported FreeBSD
architecture, but checking the return value seems like a good
sanity check to me.

Reviewed By:	kib, imp
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D30820

(cherry picked from commit e3be51b2bc)
2021-07-05 10:46:12 +01:00
Konstantin Belousov
59a876238f rtld: Rename -t option to -u (ignore LD_ vars)
(cherry picked from commit e3149e0a02)
2021-06-04 03:32:50 +03:00
Konstantin Belousov
99e1896f20 rtld direct exec: add option to ignore LD_ variables
(cherry picked from commit d81f999ac2)
2021-06-04 03:32:50 +03:00
Konstantin Belousov
29b896e67d rtld: preserve the 'seen' state of the dlerror message in errmsg_save()
PR:	255698

(cherry picked from commit 630caa95d4)
2021-05-19 06:13:14 +03:00
Konstantin Belousov
7bbfb5d959 rtld: make dlerror() thread-local
(cherry picked from commit 4d9128da54)
2021-04-23 14:14:08 +03:00
Konstantin Belousov
fe86eb8f34 rtld: unstaticise lockinfo and obj_from_addr()
(cherry picked from commit 4d7f08c84b)
2021-04-23 14:14:08 +03:00
Konstantin Belousov
e703bd6341 rtld: avoid recursing on rtld_bind_lock for write
(cherry picked from commit 7cb32a0d03)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
ab34960582 rtld: allow to use tls_get_addr_slow() from context where rtld_bind_lock is locked
(cherry picked from commit 8950804842)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
127849157a rtld: style tls_get_addr_slow
(cherry picked from commit 85d846b369)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
c3f97dd75a rtld dl_iterate_phdr(): dlpi_tls_data is wrong
(cherry picked from commit d36d681615)
2021-04-23 14:14:06 +03:00
David Chisnall
7d9e00cd8b rtld: Fix null-pointer dereference
(cherry picked from commit 43d44842ae)
2021-02-09 06:14:48 +02:00
Ed Maste
613a08cfa2 rtld: map without PROT_EXEC for relocation
This makes text segment relocation work under W^X.

Submitted by:	Greg V <greg@unrelenting.technology> (original version)
Reviewed by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D27953
2021-01-05 10:57:14 -05:00
Marius Strobl
b58c853edf rtld-elf(1): remove obsolete pre_init() hook
It's no longer used since 600ee699ed
and r358358 respectively.
2020-12-25 19:47:46 +01:00
Konstantin Belousov
71df6a153f rtld: bump r_debug.r_version to 1 from current 0.
Add r_ldbase.

Requested and reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D27429
2020-12-01 22:28:01 +00:00
Konstantin Belousov
1db23efb83 rtld: pass argc/argv/env to dso inits.
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
2020-09-07 21:32:27 +00:00
Konstantin Belousov
500433057e rtld: do not refuse to relocate objects without dynamic symtabs.
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
2020-09-05 22:44:38 +00:00
Konstantin Belousov
2b49b95cfa rtld: do not process absent dynamic.
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
2020-09-05 22:41:31 +00:00
John Baldwin
e9751a84dd Include FreeBSD ABI tag note in the ELF runtime loader.
Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D25306
2020-07-16 22:01:01 +00:00
Leandro Lupori
a5467d6ca2 Handle non-PLT GNU IFUNC relocations in rtld
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
2020-07-06 11:57:59 +00:00
Konstantin Belousov
7e400f1ade rtld: Apply relro to itself.
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D25319
2020-06-18 23:07:58 +00:00