Commit Graph

151 Commits

Author SHA1 Message Date
auronandace e714c570bc make mut_from_ref deny 2026-07-02 08:28:38 +01:00
auronandace c4509c9684 add implicit_clone clippy lint and tackle a few others 2026-06-15 12:14:07 +01:00
Wildan M 519bc8ebc8 Remove ld.so cache 2026-05-13 07:11:36 +07:00
sourceturner ef46ff8746 rename RTLDState enum members 2026-04-22 21:58:02 +02:00
auronandace b4009544a8 minor code cleanups 2026-04-03 14:39:56 +01:00
Wildan M 459b8da27b Implement ld_so cache backed by shm 2026-03-29 05:34:14 +07:00
auronandace a01313467e tackle some clippy lints in ld_so 2026-03-14 14:20:22 +00:00
auronandace 8a2bfa2ed5 tackle some lints 2026-03-10 18:20:06 +00:00
Wildan M e45ec784b7 Fix dynamic linker hitting unwrap 2026-03-05 13:02:52 +07:00
auronandace 53273c35c4 remove allowed unused imports 2026-02-17 15:35:58 +00:00
Anhad Singh 0430081f4a feat(redox-rt): preload the executable
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-16 12:29:19 +11:00
auronandace b9d956bacb try again with allow 2026-02-10 18:04:40 +00:00
auronandace 8307ba25b3 missed some 2026-02-10 17:30:29 +00:00
auronandace ac0a7e71f4 apply clippy::borrow-as-ptr lint 2026-02-03 12:02:26 +00:00
Wildan M 7b9402783d Add log crate, use it to all trace cmd 2026-01-24 22:39:05 +07:00
Anhad Singh bbc86d8027 fix(libc): use ld.so's allocator
Previously, this was implemented incorrectly because `tcb.mspace` was
set just *before* jumping to the program's entry point. However,
`alloc_init` is called when the init functions are run for `libc.so`, so
`tcb.mspace` must be initialized *before* the init functions are
run.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-01-20 14:00:29 +11:00
Anhad Singh df647941c5 misc(pthread): remove the need for tid_mutex
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-01-09 22:55:58 +11:00
Anhad Singh 4245e9148e fix(load_objects_recursive): TLS overallocation
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-27 01:12:07 +11:00
Anhad Singh 64d3793190 fix(ld_so): page faulting when library not found
The error handling was already in place. The reason it was page faulting
is that, on failure, the function exits as soon as it encounters an
`Err` variant. When that happens, the DSO object for which the
dependency was being loaded is dropped. Dropping it calls `munmap` to
unload the executable and also runs the functions in `.fini`. However,
`run_fini` should only be called if the `DSO` is being unloaded after it
has been successfully loaded (i.e. all dependencies were satisfied and
all init functions had run).

Closes #1599

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-10 13:24:53 +11:00
Jeremy Soller 74e3ad1c2c Do TLS alignment in reliable way 2025-11-13 12:07:06 -07:00
Wildan M abdfd3d0ac Fix ld_so multiple objects loading the same object 2025-10-29 15:46:35 +07:00
Wildan M ab8021fdbe Expose PIE information with LD_DEBUG 2025-10-06 12:53:22 +07:00
Jeremy Soller 82084440ad Support nightly-2025-10-03 2025-10-03 21:51:10 -06:00
Jacob Lorentzon 9c5f11fbc8 Add Out<T> wrapper 2025-09-21 14:36:12 +02:00
elle 5d77f617f5 ld_so: use mutex for _r_debug
Uses a `spin::Mutex` for the global static `_r_debug` instance to remove
warning about a global mutable static.

Guarantees exclusive mutable access to the `_r_debug` variable.
2025-09-08 20:23:36 +00:00
Jeremy Soller 84bbf90ce1 Fix ___tls_get_addr on x86 2025-07-03 10:52:46 -06:00
Jeremy Soller 0b1133a965 ld_so: do relocations before TLS 2025-05-07 16:27:00 -06:00
Jeremy Soller 2b06118d5f Fix deadlock when logging scopes 2025-05-06 21:50:38 -06:00
Jeremy Soller 78bab94ee0 Add end of dynamic library mapping to debug messages 2025-05-06 20:45:39 -06:00
4lDO2 59090a83f4 Fix thread+proc fd init in ld.so 2025-04-19 19:26:59 +02:00
4lDO2 ad5efd0f11 Reach init fork 2025-04-19 19:26:57 +02:00
Anhad Singh c64058c8b7 tcb: aarch64 2025-04-20 02:41:35 +10:00
Josh Megnauth 51c04d2470 Use C string literals & deprecate c_str! 2025-03-14 21:17:53 -04:00
Anhad Singh d3073fdad4 feat(ld.so): more debug info for scopes
When scopes is set for `LD_DEBUG`, more debug information is displayed
now,

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-01-19 00:11:51 +11:00
Anhad Singh 99449094d4 chore: formatting
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-01-19 00:03:07 +11:00
Anhad Singh 4a08220664 fix(ld.so): copy relocations
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-01-18 23:51:53 +11:00
Jeremy Soller a3c12e27e4 Fix build for i686 2025-01-14 18:01:26 -07:00
Anhad Singh b9e0505715 fix(ld.so): less locks
Acquire the global scope lock at the start of relocate.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-01-13 23:48:03 +11:00
Jeremy Soller af50d18d16 Return error instead of panic when load_library cannot find root DSO 2025-01-09 13:33:29 -07:00
Anhad Singh aae27c5e0c feat(ld.so): switch to object crate
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-01-08 16:50:47 +11:00
Anhad Singh e49072655c feat(ld.so): partially switch to object
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-01-08 16:50:10 +11:00
Anhad Singh bfe1c0b545 fix(ld.so): redox build
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-31 19:30:37 +11:00
Anhad Singh 01e6eda258 misc(dlfcn): cleanup
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-31 19:03:05 +11:00
Anhad Singh 42d884c6a3 fix(ld.so): errors UB
Currently, how ld.so errors are handled by functions in dlfcn is wrong.
dlopen calls `linker.load_library` which returns a
`Result<ObjectHandler, goblin::Error>`. Now `goblin::Error` may have
variants that are heap allocated. For example:
`Error::Malformed(format!("invalid path: '{}': {}", path, err))`. The
error string would be allocated by ld.so's allocator but will be dropped
inside libc. This is UB.

After this patch, we now return a custom `DlError` instead. To get more
information about the error, `LD_DEBUG=all` can be set.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-31 18:35:20 +11:00
Anhad Singh 9cf72fd0b2 feat(ld.so): add all option for LD_DEBUG
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-31 18:00:45 +11:00
Anhad Singh 60f700fb50 chore(linker): remove todo
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-31 15:26:23 +11:00
Anhad Singh c25292ae21 misc(ld.so): clippy fixes
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-31 15:25:40 +11:00
Anhad Singh cfe89f828a feat: rwlock instead of mutex for global scope
* Rwlock -> InnerRwLock
* RwLock makes use of InnerRwLock.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-31 00:54:52 +11:00
Anhad Singh 2be4316aec feat(dlfcn): return DSO as the handle
Fine because:
> The value of this handle should not be interpreted in any way by the
> caller.
From: https://pubs.opengroup.org/onlinepubs/009696599/functions/dlopen.html

* Add tests for unload
* Implement NOLOAD so we can test that the loaded object has been
  destroyed.
* Minor cleanup.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-25 16:17:51 +11:00
Anhad Singh 1612c78774 fix(ld.so): disable lazy binding on non-x86_64
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-24 20:51:53 +11:00