Commit graph

1006 commits

Author SHA1 Message Date
Ed Maste
f06d322e9d Remove "All Rights Reserved" from FreeBSD Foundation copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 5c2bc3db201a4fe8d7911cf816bea104d5dc2138)
2024-08-06 15:39:53 -04:00
Konstantin Belousov
279e543dc7 rtld: add LD_NO_DL_ITERATE_PHDR_AFTER_FORK env var
PR:	280318

(cherry picked from commit 860c4d94ac46cee35a678cf3c9cdbd437dfed75e)
2024-08-05 03:32:11 +03:00
Konstantin Belousov
da32a0616b rtld: make ld_get_env_var() usable for all rtld source files
(cherry picked from commit 47315d6d3562111883142bb09320d35f05d34a58)
2024-08-05 03:32:11 +03:00
Konstantin Belousov
f0d4329dc2 rtld(1): Spell value as VALUE, not NAME
(cherry picked from commit bc25bc6850e512c4c45effdff6178d20b5eca558)
2024-08-05 03:32:11 +03:00
Andrew Turner
c2e0dea93f rtld: Add MD_OBJ_ENTRY to extend Struct_Obj_Entry
Add a macro the architectures can use to add per-arch fields to
Struct_Obj_Entry.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45116

(cherry picked from commit 06db20ffeca9898e5802d63f3b06caaa37c3a4ed)
2024-07-15 12:24:58 +00:00
Konstantin Belousov
0d47501246 rtld.1: clarify interaction between -u and -o
(cherry picked from commit 6a7819e43f938992304472054c83f4a6602a9e19)
2024-05-06 07:42:19 +03:00
Konstantin Belousov
6c85003139 rtld direct exec: make -u behavior match the description
(cherry picked from commit ef2694f368cee5957ee44b0298da88ff8360d561)
2024-05-06 07:42:19 +03:00
Konstantin Belousov
d63c680d39 rtld: add direct-exec option -o
(cherry picked from commit d1cd0cc32b53c09e72e33116b94a5b0b9781a183)
2024-05-06 07:42:19 +03:00
Konstantin Belousov
44debee9fc rtld snprintf: do not erronously skip a char at the buffer boundary
(cherry picked from commit 56ee5fc43c40479e2651b21862e299bcf73017ae)
2024-05-03 03:25:33 +03:00
Konstantin Belousov
2cd1939e2e rtld(1): minor clarification for LD_STATIC_TLS_EXTRA
(cherry picked from commit 8d7473703520f315c1bcd3b3d12498eee10d563e)
2024-04-23 03:32:21 +03:00
Stephen J. Kiernan
0b56acfc49 rtld: introduce STATIC_TLS_EXTRA
(cherry picked from commit 95335dd3c19e0ade161bb4dc8462fc3d045ce4f8)
2024-04-20 16:52:16 +03:00
Stefan Eßer
32364f99e1 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 7b77d37a561b47db093a2528b8032dbfe5791698)

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 173953182af060dcab43990e179ee91e9f2d1e54)

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:		7b77d37a561b ("rtld-elf: support either byte-order of hints")
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D44472

(cherry picked from commit da2d6e2815d7694e3ccbd561508074c547b02dd6)

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 c44bf7d2e9d2292867f2e23f291266af26762354)
2024-03-29 07:34:44 +01:00
Kyle Evans
a7b90458a2 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
968a18975ad ("rtld: ignore load_filtees() calls if we already [...]")

Reviewed by:	kib

(cherry picked from commit c5796f1572c82b88e8b6a2810c92f30e5ac3e118)
2024-03-18 10:52:57 -05:00
Konstantin Belousov
3cce838c60 rtld: use generated map file to check for some leaks from libc into rtld
(cherry picked from commit 5db5c6c87a75f8b1871f021726fc4697253ae5cf)
2024-03-07 02:34:34 +02:00
Konstantin Belousov
5a98473132 rtld: unconditionally generate map file during build
(cherry picked from commit 799940154c70597a46627deb4d0b98e174b27b98)
2024-03-07 02:34:34 +02:00
Konstantin Belousov
11137153ab fdlopen(3): do not create a new object mapping if already loaded
PR:	277169

(cherry picked from commit 452c5e9995ab4cd6c7ea230cffe0c53bfa65c1ab)
2024-02-29 02:24:06 +02:00
Konstantin Belousov
0a246310f7 rtld: remove pointless "extern"
(cherry picked from commit 180df764c4ee570850deb4a910a11780ec3316df)
2024-02-29 02:24:06 +02:00
Andrew Turner
d416325740 rtld: Teach rtld about the BTI elf note
Add the Branch Target Identification (BTI) note to libc assembly
sources. As all obect files need the note for rtld to have it we need
to insert it in all asm files.

Reviewed by:	markj, emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42228

(cherry picked from commit 5270cc9757fb4e0c1303ec44c2602b75acf3806d)
2024-02-19 13:12:18 +00:00
Konstantin Belousov
25bd875397 rtld: ignore load_filtees() calls if we already loading filtees for the obj
(cherry picked from commit 968a18975adc9c2a619bb52aa2f009de99fc9e24)
2024-02-18 12:01:47 +02:00
Konstantin Belousov
e43855c6f1 rtld load_filtees(): reindent and reduce block nesting
(cherry picked from commit 30b5f6b33b35623e6b6aa1d27a78311e199fa602)
2024-02-18 12:01:47 +02:00
Konstantin Belousov
c6d4339208 rtld symlook_obj: move common code to check filtees into helper
(cherry picked from commit 9ea864b54b57f2d0125860fb923f8db52b20eac2)
2024-02-18 12:01:46 +02:00
Mark Johnston
323226829a rtld-elf: Avoid unnecessary lock_restart_for_upgrade() calls
In order to atomically upgrade the rtld bind lock, load_filtees() may
trigger a longjmp back to _rtld_bind() so that the binding can be done
with the write lock held.  However, the write lock is only needed when
filtee objects haven't already been loaded, so move the
lock_restart_for_upgrade() call to avoid unnecessary lock upgrades when
a filtee is defined.

Reviewed by:	kib
Tested by:	brooks
MFC after:	1 week
Sponsored by:	Innovate UK

(cherry picked from commit e7951d0b04e6464b37264b8166b1e9ce368a9f1d)
2024-02-09 09:55:56 -05:00
John Baldwin
a697425ccc 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 4a3cf5f329d69076aa9d093d596eb0ee82d917f5)
2024-01-04 16:28:48 -08:00
Kyle Evans
2ef9079ece 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.

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

(cherry picked from commit d9c543b6b0cabea6e6679d70b4e701018e7eab80)
2023-12-14 18:58:36 -06:00
Konstantin Belousov
8d0740e8b9 RTLD_DEEPBIND: make lookup not just symbolic, but walk all refobj' DAGs
PR:	275393

(cherry picked from commit 9daf6cd0f46416d9c6eb0411ea6042cd42b8a9bc)
2023-12-07 02:27:19 +02:00
John Baldwin
260bab9f1e 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 eba230afba4932f02a1ca44efc797cf7499a5cb0)
2023-10-24 10:10:12 -07:00
Konstantin Belousov
3f3c631da0 rtld: output rtld errors into the dbg channel
(cherry picked from commit 72d97e1dd9cc72a2acb96e35e56db6f3f51bca7d)
2023-09-19 11:31:24 +03:00
Konstantin Belousov
cbf1bbe5c8 __crt_aligned_alloc_offset(): fix ov_index for backing allocation address
(cherry picked from commit 03a7c36ddbc0ddb1063d2c8a37c64d83e1519c55)
2023-09-09 11:26:33 +03:00
Konstantin Belousov
feaae6ba1a rtld: switch from malloc_aligned() to __crt_aligned_alloc()
Use regular free(), since it works now.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
c29ee08204 rtld_malloc: add __crt_aligned_alloc_offset()
It is modelled after aligned_alloc(3).  Most importantly, to free the
allocation, __crt_free() can be used.  Additionally, caller may specify
offset into the aligned allocation, so that we return offset-ed from
alignment pointer.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
d60130bf32 rtld_malloc: increase overhead index to uint16
Reorder it with magic, to keep alignment.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
6bb7f05850 rtld_malloc.c: change return type of cp2op() to void
for it to be useful to return unaligned pointer.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
b1d3e2b771 rtld: unlock bind lock when calling into crt __pthread_distribute_static_tls method
The method might require resolving and binding symbols, which means
recursing on the bind lock. It is safe to unlock the bind lock,
since we operate on the private object list, and user attempting to
unload an object from the list of not yet fully loaded objects caused
self-inflicted race.

It is similar to how we treat user' init/fini methods.

Reported by:	stevek
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-08-20 15:30:13 +03:00
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Jessica Clarke
195e50541e libexec: Automatically generate rtld-elf list and generalise TAGS
Note that the pattern for matching is made slightly more specific, so as
to permit libcompats where one is a prefix of another (e.g. CheriBSD has
lib64 and lib64c).

Reviewed by:	brooks, jhb, emaste, imp, kib
Differential Revision:	https://reviews.freebsd.org/D41183
2023-07-27 05:10:45 +01:00
Konstantin Belousov
86c7368f2b rtld_malloc: add cp2op() helper
converting user allocation address into overhead pointer

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:18 +03:00
Konstantin Belousov
bc7e86106d rtld_malloc: only include internal rtld headers when building for rtld
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:17 +03:00
Konstantin Belousov
cf6dbdd135 rtld: remove dup __crt_malloc prototypes
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:17 +03:00
Konstantin Belousov
a24726a6f3 rtld_malloc: remove outdated comments
The ovu_magic is not neccessary overlaps with low byte of the ov_next,
for the big endian machines.

There is no range checking in the allocator.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:17 +03:00
Robert Clausecker
c1e63e352e libexec/rtld-elf/rtld-libc/Makefile.inc: do not use machdep string functions
With ifunc based SIMD dispatch, we cannot use the amd64 assembly
implementations of string functions.  Modify rtld to instead use
the generic functions.  To avoid an architecture-specific special
case, this change is applied to all architectures.

This change is a prerequisite to and formerly part of D40693.

Sponsored by:	FreeBSD Foundation
Approved by:	kib
See also:	D40693
Differential Revision: https://reviews.freebsd.org/D41050
2023-07-16 18:41:55 +03:00
Konstantin Belousov
1005d3d053 rtld: fix dlopen() for an object that is already mapped but not yet initialized
For instance, dso might be mapped as needed but not yet initialized from
the other subtree of needed objects, while current object' constructor
does dlopen() for the dso.  Right now rtld does relocations and other
processing based on the arrival of new objects in the global list, which
is not happens there.  Directly check for the initialization state of
the object, for which we would return the handle.

One practical use case of this support is e.g. dlopen("libthr.so",
RTLD_NOLOAD) by libraries that are threading-aware but happy to live
with libc pthread shims if the program is not multithreaded.

Reviewed by:	tijl
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2023-07-16 15:34:34 +03:00
Dmitry Chagin
e541cf8316 rtld: Annotate .rtld_start on i386
Add a stop indicator to rtld_start to satisfy unwinders:
The right unwinding stop indicator should be CFI-undefined PC.
https://dwarfstd.org/doc/Dwarf3.pdf - page 118:
If a Return Address register is defined in the virtual unwind table,
and its rule is undefined (for example, by DW_CFA_undefined), then
there is no return address and no call address, and the virtual
unwind of stack activations is complete.

That is allows gdb and libunwind successfully stop when unwinding stack
from global constructors and destructors.

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D40949
2023-07-11 15:10:32 +03:00
Dmitry Chagin
86c63225ea rtld: Microoptimize rtld_start on i386
Initial stack pointer is preserved in calle-saved %esi,
use it bellow to pass initial stack pointer to _rtld().

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D40950
2023-07-11 15:10:08 +03:00
Jessica Clarke
076a4dc59b rtld-elf: Remove _PATH_ELF32_HINTS and _COMPAT32_PATH_RTLD
These are no longer referenced, with the one user of each now using the
double-underscore version with "32" as an argument instead.

Reviewed by:	kib, brooks, jhb
Differential Revision:	https://reviews.freebsd.org/D40935
2023-07-09 18:50:30 +01:00
Jessica Clarke
f940929d41 rtld-elf: Migrate from COMPAT_32BIT to generic COMPAT_libcompat/LIBCOMPAT
We still have a tiny amount of libcompat-specific code in rtld_paths.h,
but it's been deduplicated as much as possible, and in future we may
wish to just push these variables down to the few consumers of them and
make them use the double-underscore variants with a libcompat argument
rather than give them names here.

See commit 8fad2cda93 ("bsd.compat.mk: Provide new CPP and sub-make
variables") for the context behind this change.

Reviewed by:	kib, brooks, jhb
Differential Revision:	https://reviews.freebsd.org/D40925
2023-07-09 18:49:07 +01:00
Jessica Clarke
5181fe24b2 rtld-elf: Reuse _BASENAME_RTLD for debug.h rather than duplicating logic
Reviewed by:	kib, brooks, jhb
Differential Revision:	https://reviews.freebsd.org/D40919
2023-07-09 18:45:49 +01:00