Commit graph

975 commits

Author SHA1 Message Date
Konstantin Belousov f73055ab1e rtld.1: clarify interaction between -u and -o
(cherry picked from commit 6a7819e43f)
2024-05-07 11:59:07 +03:00
Konstantin Belousov e45b440633 rtld direct exec: make -u behavior match the description
(cherry picked from commit ef2694f368)
2024-05-07 11:59:07 +03:00
Konstantin Belousov 10484ee13a rtld: add direct-exec option -o
(cherry picked from commit d1cd0cc32b)
2024-05-07 11:59:07 +03:00
Konstantin Belousov d9ec850bde rtld snprintf: do not erronously skip a char at the buffer boundary
(cherry picked from commit 56ee5fc43c)
2024-05-03 03:26:26 +03:00
Konstantin Belousov ed9f44083d rtld(1): minor clarification for LD_STATIC_TLS_EXTRA
(cherry picked from commit 8d74737035)
2024-04-23 03:32:54 +03:00
Stephen J. Kiernan 57d49c4bcb rtld: introduce STATIC_TLS_EXTRA
(cherry picked from commit 95335dd3c1)
2024-04-23 03:32:54 +03:00
Stefan Eßer f61d786c29 rtld-elf: support either byte-order of hints file
Accept either little-endian or big-endian representation of the ELF
hints magic number in the header of a hints file and convert the
parameters to the native byte-order of the repsective system.

This is a pre-requisite for a planned change to always write the byte
order in little-endian format on all architectures. The only relvant
architecture that uses big-endian data is powerpc64, and it is not
likely that new architectures will choose that representation of data
in memory.

When all supported architectures use little-endian data in the hints
file, the byte swap logic can be enabled for big-endian CPUs at
compile time. Up to that point, there is a very small run-time penalty
that is paid on all systems to check the byte-order of the hints file
and to provide the option to byte-swap the parameters read from the
hints file header.

This commit contains the changes from review D44080 (which had been
split off from this patch for easier review),

Reviewed by:	kib
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D44053

(cherry picked from commit 7b77d37a56)

rtld-elf: add some debug print statements

The byte-order independent code has been reported to fail on powerpc64.
Add some more debug statements to help identify the parametrs used and
to verify the correct operation of the byte-swap macros used..

(cherry picked from commit 173953182a)

rtld: fix check for endianess of elf hints file

Don't check if the elf hints file is in host byte order, but check
if it is in little endian by looking at the magic number.
This fixes rtld on big endian platforms.

Reviewed by:	se, kib (prior version of the patch)
Fixes:		7b77d37a56 ("rtld-elf: support either byte-order of hints")
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D44472

(cherry picked from commit da2d6e2815)

rtld: reduce debug messages after fix on big-endian hosts

Remove a debug message that had been added to support the debugging
of a mis-detection of the hint files endianness on powerpc64.

MFC after:	3 days

(cherry picked from commit c44bf7d2e9)
2024-03-29 07:43:52 +01:00
Kyle Evans 7e93233111 rtld: add some dlopen tests
dlopen_basic just tests that libthr.so can be dlopen()ed, which will
just serve as a sanity check that "libthr.so" is a thing that can be
dlopened in case we get a weird failure in dlopen_recursing.

dlopen_recursing tests a regression reported after the libsys split,
where some dlopen() may cause infinite recursion and a resulting crash.
This case is inspired by bdrewery's description of what seemed to be
causing his issue.

The corresponding fix landed in commit
968a18975a ("rtld: ignore load_filtees() calls if we already [...]")

Reviewed by:	kib

(cherry picked from commit c5796f1572)
2024-03-17 22:34:05 -05:00
Konstantin Belousov 8b84d2da9a rtld: use generated map file to check for some leaks from libc into rtld
(cherry picked from commit 5db5c6c87a)
2024-03-06 09:42:42 +02:00
Konstantin Belousov fd5a82ecd2 rtld: unconditionally generate map file during build
(cherry picked from commit 799940154c)
2024-03-06 09:42:42 +02:00
Konstantin Belousov af4c7ac93b rtld: remove pointless "extern"
(cherry picked from commit 180df764c4)
2024-02-29 02:24:43 +02:00
Konstantin Belousov 1545d8732d fdlopen(3): do not create a new object mapping if already loaded
PR:	277169

(cherry picked from commit 452c5e9995)
2024-02-29 02:24:43 +02:00
Konstantin Belousov c4ca9a5660 rtld: ignore load_filtees() calls if we already loading filtees for the obj
(cherry picked from commit 968a18975a)
2024-02-29 02:24:43 +02:00
Konstantin Belousov 3d49b2e4d7 rtld load_filtees(): reindent and reduce block nesting
(cherry picked from commit 30b5f6b33b)
2024-02-29 02:24:43 +02:00
Mark Johnston 2d5c2324af rtld-elf: Avoid unnecessary lock_restart_for_upgrade() calls
(cherry picked from commit e7951d0b04)
2024-02-29 02:24:43 +02:00
Konstantin Belousov 9ef04f1abe rtld symlook_obj: move common code to check filtees into helper
(cherry picked from commit 9ea864b54b)
2024-02-29 02:24:43 +02:00
John Baldwin 7da77f0266 Stop #defining FREEBSD_ELF
This was originally used (along with FREEBSD_AOUT) to prefer the use
of ELF in various tools instead of a.out as part of the a.out to ELF
transition in the 3.x days.  The last use of it was removed from
<link.h> in commit 66422f5b7a back in
2002, but various files still #define it.

Reviewed by:	kevans, imp, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42964

(cherry picked from commit 4a3cf5f329)
2024-01-04 16:28:53 -08:00
Kyle Evans 9986fd59d8 rtld: add a test for RTLD_DEEPBIND
This tests that with RTLD_DEEPBIND, symbols are looked up in all of the
object's needed objects before the global object.

ATF_REQUIRE_INTEQ was added after stable/13 branched, so we shim it out
here.

PR:		275393
Reviewed by:	kib
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.

(cherry picked from commit d9c543b6b0)
2023-12-15 10:56:59 -06:00
Konstantin Belousov 07fa8d431c RTLD_DEEPBIND: make lookup not just symbolic, but walk all refobj' DAGs
PR:	275393

(cherry picked from commit 9daf6cd0f4)
2023-12-07 02:27:34 +02:00
John Baldwin de270f81b2 Purge more stray embedded $FreeBSD$ strings
These do not use __FBSDID but instead use bare char arrays.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41957

(cherry picked from commit eba230afba)
2023-10-24 11:13:18 -07:00
Konstantin Belousov 5d6adc09cf rtld: output rtld errors into the dbg channel
(cherry picked from commit 72d97e1dd9)
2023-09-19 11:31:49 +03:00
Konstantin Belousov 875f06276b __crt_aligned_alloc_offset(): fix ov_index for backing allocation address
(cherry picked from commit 03a7c36ddb)
2023-09-09 11:27:32 +03:00
Konstantin Belousov 0a12bf2332 rtld: switch from malloc_aligned() to __crt_aligned_alloc()
(cherry picked from commit feaae6ba1a)
2023-08-28 03:27:48 +03:00
Konstantin Belousov a3a71ddc77 rtld_malloc: add __crt_aligned_alloc_offset()
(cherry picked from commit c29ee08204)
2023-08-28 03:27:48 +03:00
Konstantin Belousov 0c8823bad5 rtld_malloc: increase overhead index to uint16
(cherry picked from commit d60130bf32)
2023-08-28 03:27:48 +03:00
Konstantin Belousov 8925d38da3 rtld_malloc.c: change return type of cp2op() to void
(cherry picked from commit 6bb7f05850)
2023-08-28 03:27:48 +03:00
Konstantin Belousov cee16ae06d rtld: unlock bind lock when calling into crt __pthread_distribute_static_tls method
(cherry picked from commit b1d3e2b771)
2023-08-27 03:50:17 +03:00
Warner Losh b144e70a33 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/

Similar commit in main:
(cherry picked from commit fa9896e082)
2023-08-23 11:43:31 -06:00
Warner Losh 023fc80ee3 Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/

Similar commit in main:
(cherry picked from commit d0b2dbfa0e)
2023-08-23 11:43:30 -06:00
Warner Losh 3d497e17eb Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/

Similar commit in main:
(cherry picked from commit 1d386b48a5)
2023-08-23 11:43:26 -06:00
Warner Losh 34041aac83 Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/

Similar commit in main:
(cherry picked from commit 42b388439b)
2023-08-23 11:43:22 -06:00
Warner Losh 17da660ad5 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/

Similar commit in main:
(cherry picked from commit b3e7694832)
2023-08-23 11:43:21 -06:00
Konstantin Belousov 4c22848d1a rtld_malloc: add cp2op() helper
(cherry picked from commit 86c7368f2b)
2023-08-02 03:36:40 +03:00
Konstantin Belousov 04085d4b69 rtld_malloc: only include internal rtld headers when building for rtld
(cherry picked from commit bc7e86106d)
2023-08-02 03:36:39 +03:00
Konstantin Belousov b619a7f161 rtld: remove dup __crt_malloc prototypes
(cherry picked from commit cf6dbdd135)
2023-08-02 03:36:39 +03:00
Konstantin Belousov 9c62017171 rtld_malloc: remove outdated comments
(cherry picked from commit a24726a6f3)
2023-08-02 03:36:39 +03:00
Konstantin Belousov 05e7db731d rtld: fix dlopen() for an object that is already mapped but not yet initialized
(cherry picked from commit 1005d3d053)
2023-07-30 03:29:09 +03:00
Warner Losh f73b4bf27c spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD
The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix

(cherry picked from commit b61a573019)
2023-07-25 09:15:32 -06:00
Warner Losh caa41f6417 spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix

(cherry picked from commit 4d846d260e)
2023-07-25 09:13:49 -06:00
Konstantin Belousov d0fec56f90 rtld: fix typo in comment
(cherry picked from commit a254f67102)
2023-06-12 02:39:43 +03:00
Konstantin Belousov 62bc41c614 rtld: fix allocate_module_tls() variant I fallback to static allocation
(cherry picked from commit e9a38ed2fa)
2023-06-12 02:39:43 +03:00
Konstantin Belousov dc56749b20 rtld: do not allow both dynamic DTV index and static TLS offset
(cherry picked from commit 91880e07f6)
2023-06-12 02:39:43 +03:00
Konstantin Belousov 60e3db0c45 rtld: rename tls_done to tls_static
(cherry picked from commit 283a4f4097)
2023-06-12 02:39:43 +03:00
Konstantin Belousov d231ca7fe3 rtld_tls.h: style
(cherry picked from commit a7bca69492)
2023-06-12 02:39:43 +03:00
Ed Maste 26cc23c84e rtld: fix SysV hash function overflow
Quoting from https://maskray.me/blog/2023-04-12-elf-hash-function:

The System V Application Binary Interface (generic ABI) specifies the
ELF object file format. When producing an output executable or shared
object needing a dynamic symbol table (.dynsym), a linker generates a
.hash section with type SHT_HASH to hold a symbol hash table. A DT_HASH
tag is produced to hold the address of .hash.

The function is supposed to return a value no larger than 0x0fffffff.
Unfortunately, there is a bug. When unsigned long consists of more than
32 bits, the return value may be larger than UINT32_MAX. For instance,
elf_hash((const unsigned char *)"\xff\x0f\x0f\x0f\x0f\x0f\x12") returns
0x100000002, which is clearly unintended, as the function should behave
the same way regardless of whether long represents a 32-bit integer or
a 64-bit integer.

Reviewed by:	kib, Fangrui Song
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39517

(cherry picked from commit 29e3a06510)
2023-04-27 13:05:22 -04:00
Ed Maste 937d152b3e rtld: reindent and style(9) elf_hash()
In preparation for an upcoming change (D39517).

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 87443cb6c6)
2023-04-27 13:05:17 -04:00
Konstantin Belousov c38df24407 rtld: fixes for handling of the grouped options
(cherry picked from commit 7cdfe51f30)
2023-04-16 14:11:35 +03:00
Konstantin Belousov 1889a973af sys/param.h: Add _WANT_P_OSREL
(cherry picked from commit 5942b4b6fd)
2023-02-19 07:16:25 +02:00
Konstantin Belousov c23f077cc4 rtld: add support for the $LIB token
MFC note: the arm soft case is not handled, it is probably worth
expanding $LIB to libsoft there.

(cherry picked from commit 8cc44a1e59)
2022-11-18 04:15:18 +02:00
Konstantin Belousov bc53b440fb rtld: remove unused macro FPTR_TARGET
(cherry picked from commit f585d13dd6)
2022-10-25 03:37:43 +03:00