Commit graph

897 commits

Author SHA1 Message Date
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
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
Fangrui Song
a3c0eaa3c2 rtld: Fix i386/amd64 TP offset when p_vaddr % p_align != 0
(cherry picked from commit e6c7696203)
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
98ef339d44 rtld: fix the man page
(cherry picked from commit e086aff91c)
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
Mark Johnston
61acafc6c6 rtld/arm64: Remove checks for undefined symbols when processing TPREL64
lld emits several GOT relocations referencing the null sumbol in libc.so
when compiled with -ftls-model=initial-exec.  This symbol is specified
to be undefined.

We generally do not handle dynamic TLS relocations against weak,
undefined symbols, so avoid printing a warning here.  This makes it
possible to compile libc.so using the initial-exec TLS model on arm64.

Reviewed by:	jrtc27, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f238ebd142)
2021-07-29 20:32:58 -04: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
db4a2731e9 rtld: initialize default dlerror_seen_val as true
PR:	255698

(cherry picked from commit 529ab5a759)
2021-05-19 06:13:14 +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
13e0ef8230 rtld_lock.h: add some comments about versioning of struct RtldLockInfo
(cherry picked from commit 9b33518ada)
2021-04-23 14:14:08 +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
b75aa0eaf3 rtld: workaround for broken ABI
(cherry picked from commit 08bfbd4359)
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
b26e7715b0 rtld: use _get_tp() in __tls_get_addr()
(cherry picked from commit e8b9c508b7)
2021-04-23 14:14:07 +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
4bcc2e90a0 rtld: define TLS_DTV_OFFSET on all architectures
(cherry picked from commit 99c2ce7ef1)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
520806c476 rtld_lock.h: Expand scope for IN_RTLD to avoid some conflicts with libc
(cherry picked from commit 34ca6025dd)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
d252df1e11 rtld/x86/reloc.c: style
(cherry picked from commit f61ecf60cf)
2021-04-23 14:14:06 +03:00
Konstantin Belousov
1bcab3da2b rtld_lock.h: remove tautological extern's
(cherry picked from commit 38e0610df7)
2021-04-23 14:14:06 +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