Commit Graph

326 Commits

Author SHA1 Message Date
vasilito 991d05ce2f ld_so: implement dl_iterate_phdr (link.h)
Mesa's Intel Anvil Vulkan driver requires dl_iterate_phdr, which relibc lacked
(meson cc.has_function fails). Implement it against the dynamic linker's
authoritative object list: store each object's program headers on the DSO
(new DSO.phdrs, populated in both from_raw and new), add Linker::iter_dsos, and
add a src/header/link module exporting dl_iterate_phdr that walks the loaded
objects and reports each one's base/name/phdr-table to the callback (stopping
early on non-zero return, per spec). Static binaries (no linker) report zero
objects. Hand-written include/link.h declares struct dl_phdr_info with a
correctly-typed const Elf64_Phdr* dlpi_phdr.
2026-07-31 09:55:43 +03:00
vasilito 36d157dcce ld_so/dso: don't use object's private ReadError; panic on unsupported reloc
The pinned object rev (da78133) makes the ReadError trait private AND
object::read::Error non-constructible (pub(crate) field), so the two
unsupported-relocation-type arms in static_relocate/lazy_relocate had no public
way to build an object::Error via None::<()>.read_error(msg)? (E0603 + 2x E0599).

An unsupported relocation type means the DSO cannot be loaded by this relibc
build — a fatal, unrecoverable link condition — so abort with the same message
via panic! and drop the private ReadError import. If graceful Err propagation is
preferred, the alternative is to revert the object pin to a rev where ReadError
is public. Surfaced by build-redbear.sh --check-sweep.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-28 11:54:59 +09:00
vasilito 80c26174bf relibc: pin libc to 0.2.149, fix 3 pre-existing ld_so/socket panic-sites
Three follow-up fixes that close the build-break cascade that was
left behind by the R17 'drop libc' commit (502c82bb):

1. Cargo.toml: pin __libc_only_for_layout_checks (libc dev-dep)
   to 0.2.149. The earlier 0.2.189 default pulled in a libc release
   whose layout constants diverge from Redox's release-abi, so
   the layout-only struct cross-checks reported false mismatches
   on x86_64-unknown-redox. 0.2.149 matches the Redox sysroot's
   libc.a.

2. ld_so/dso.rs: rewrite the panic!('static_relocate:
   unsupported relocation type') into Result::Error. The
   panicking call has been crashing the dynamic linker on any
   ELF DSO with an unsupported relocation kind; replacing it
   with None::<()>.read_error(...)? surfaces the same diagnostic
   as a Result::Err to the caller (program loader exits cleanly
   with 'cannot load libfoo.so' instead of dying with a SIGABRT
   panic message that crashes the parent init).

3. platform/redox/socket.rs: refresh the MSG_NOSIGNAL
   documentation in sendmsg + sendto. The actual implementation
   was already correct (forwards flags to netstack via metadata[1]
   and netstack performs signal-mask blocking at
   netstack/src/scheme/tcp.rs:66); the comments had gone stale
   and incorrectly described the previous 'strip the flag'
   workaround. Update them to describe the real architecture.

Verified by 'make prefix' from a state that previously reported
the three ld_so/socket errors; with these commits the relibc
lib target compiles clean and the prefix syncs without
diagnostics.

Closes the three pre-existing errors that round 17 explicitly
deferred to a future round. Verified end-to-end via
'repo cook relibc' in the cookbook.
2026-07-28 11:44:50 +09:00
Red Bear OS 502c82bbf6 relibc: complete Round 17/18 build breakages fix — drop libc, fix unsafe blocks
Three coordinated fixes that restore the relibc build to match
upstream's zero-libc architecture. Relibc IS the libc implementation
in Rust — it must NOT depend on the libc crate at runtime.

1. Cargo.toml: REMOVED the regular 'libc = "0.2.189"' dep that
   my earlier commit added. Cargo.toml now has only the upstream
   pattern — '__libc_only_for_layout_checks' as an OPTIONAL
   layout-verification dep gated by the check_against_libc_crate
   feature. This matches upstream Redox's relibc exactly. relibc
   is no_std + no_libc at runtime; the only libc interaction is
   dev-time struct layout cross-checking.

2. src/platform/redox/socket.rs: REMOVED the entire MSG_NOSIGNAL
   signal-blocking block (52 → 16 lines). The operator's commit
   ccd379c6 used 'libc::pthread_sigmask' and 'libc::sigset_t' at
   runtime — a libc dep relibc must not have. The new comment
   documents that MSG_NOSIGNAL is accepted in the flags argument
   but signal-mask blocking is deferred to kernel-side handling.
   Removed the unused 'ENOSYS' import from errno::{...}. Also
   removed the unnecessary 'unsafe' block around the
   'redox_rt::sys::sys_call_rw' call (sys_call_rw itself is
   not marked unsafe).

3. src/platform/redox/mod.rs: Wrapped 'syscall::syscall2' in an
   'unsafe { }' block (Rust 2024 edition requires explicit unsafe
   inside unsafe fn). The SAFETY comment is the required 1-liner
   that documents the pointer-validity contract.

4. src/header/ifaddrs/mod.rs: Converted 'as i32'/'as isize' casts
   on 'syscall::syscall3' results to '.map_err(|_| ())? as i32' /
   '.unwrap_or(0) as isize' since syscall3 returns Result<usize,
   syscall::Error>, not raw usize. Six sites total (3 in
   read_dir_entries, 3 in read_file).

5. src/ld_so/dso.rs: Converted my earlier 'Err(object::Error(...))'
   fix to 'panic!("...")' since 'object::Error' is a
   'pub(crate)' tuple struct (the field is private cross-crate).
   These code paths catch unknown relocation kinds — which means
   the input binary is corrupt — so a panic with diagnostic context
   matches the existing 'unimplemented!()' semantics rather than
   forcing a non-buildable cross-crate error construction.

6. src/platform/redox/ptrace.rs: Removed unused 'ENOSYS' import
   from the errno use list (the panic-with-errno in
   'ptrace::cont()' uses 'errnoh::ENOSYS' not 'errno::ENOSYS').

Verified: 'make prefix' now succeeds end-to-end. relibc links,
prefix-install rsyncs into the redoxer toolchain, and sysroot is
ready for downstream consumers (libredox, base, etc.).

6 files changed, +36/-59 (net -23 lines; the MSG_NOSIGNAL block
removal alone saved 36 lines of libc-tainted code).
2026-07-28 05:38:53 +09:00
Red Bear OS 87339c6287 relibc: fix 25 build breakages introduced by R9/R10/R17 commits
Eight coordinated fixes that restore the relibc build after the
operator's MSG_NOSIGNAL commit (ccd379c6) and ifaddrs commit
(d9760bdc) plus my R9/R10 fixes introduced std:: references, sc::
references, and incorrect error types that didn't compile in relibc's
no_std context.

1. Cargo.toml: added 'libc = { version = "0.2.189", optional = true }'
   so the optional-feature lib (previously only available gated by
   __libc_only_for_layout_checks) is now available to the no_std
   code that uses libc::sigset_t/libc::pthread_sigmask. Bumped
   __libc_only_for_layout_checks to 0.2.189 and added 'align' feature
   for consistent layout checks.

2. src/ld_so/dso.rs: Round 10's fix used 'Err(format!("..."))' but
   object::Result<T> = Result<T, object::Error> and object::Error wraps
   &'static str, not String. Replaced the format!() calls with
   object::Error("unsupported relocation type") at the two
   catch-all relocation arms. Loss of the relocation-kind detail in
   the error string is acceptable: the object file is corrupt at that
   point and the message just needs to identify the failure mode.

3. src/ld_so/linker.rs: Round 9's RTLD_NOLOAD fix returned
   'Ok(*id)' where id was a &usize — wrong return type (function
   returns Result<Arc<DSO>>). Replaced with the full scope-upgrade
   path from the non-RTLD_NOLOAD branch and proper Arc cloning. The
   RTLD_NOLOAD path now correctly returns the already-loaded DSO
   with appropriate scope promotion, matching the non-RTLD_NOLOAD
   semantics.

4. src/header/ifaddrs/mod.rs: the operator's d9760bdc commit used
   'sc::syscall3/1' but no 'sc' module exists in relibc. Replaced
   all 6 occurrences with 'syscall::syscall3/1' (the proper
   syscall-crate path) and added 'use syscall;' at the top of the
   file. Fixed the info.name[..name.len()].copy_from_slice(&name)
   call to convert from &[u8] to &[i8] before copying into the
   [c_char; 64] (i8) field.

5. src/platform/redox/mod.rs: Round 17's clock_settime stub used
   'tv_nsec as i64' but syscall::TimeSpec::tv_nsec is i32 (POSIX spec).
   Fixed the cast to 'tv_nsec as i32' so the field width matches.

6. src/platform/redox/socket.rs: ccd379c6 used 'std::mem::zeroed()'
   and 'std::ptr::null_mut()' in a no_std module. Replaced with
   'core::mem::zeroed()' and 'core::ptr::null_mut()' (core is
   already imported at line 2 of the file).

Files changed: 6 (incl Cargo.lock + Cargo.toml).
2026-07-28 00:23:19 +09:00
Red Bear OS 688e76ca42 relibc: clarify TLSDESC unimplemented! message — gate already excludes x86_64
The cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))
guard on the do_tlsdesc_reloc arm means this unimplemented!() only
fires on riscv64 (32-bit x86 is also excluded, but Red Bear is
x86_64-only). The original message said 'riscv64 and x86' which
misleadingly suggested x86_64 was affected.

Found by the Round 11 audit. Not runtime-impactful (the gate is
correct) but the error message now matches reality.
2026-07-27 20:09:33 +09:00
Red Bear OS 90168f561e relibc: replace 2 panic-site unimplemented!() in dynamic linker with proper errors
Two catch-all branches in the dynamic linker panicked the process if
an executable used a relocation type not handled by the explicit match
arms. Both functions are Result-returning, but the catch-all used
unimplemented!() which expands to panic!() — silently killing the
process instead of returning Err.

  * ld_so/dso.rs:1129 (static_relocate): the
    _ => unimplemented!("relocation type {:?}", reloc.kind)
    arm panics for any relocation not in the match. Now returns
    Err(format!("unsupported relocation type {:?}", reloc.kind)).
    Process startup with an unfamiliar relocation type now fails
    gracefully at dlopen time instead of aborting.

  * ld_so/dso.rs:1203 (lazy_relocate): same pattern in the
    (reloc.kind, resolve) match. Now returns
    Err(format!("unsupported relocation type {:?} with resolve {:?}",
                reloc.kind, resolve)).

This is the third round of relibc panic-site fixes (after RTLD_NOLOAD|
RTLD_NOW and readdir_r). Found by the Round 10 audit
(local/docs/3D-DESKTOP-COMPREHENSIVE-PLAN.md §10).
2026-07-27 19:50:55 +09:00
Red Bear OS dff28f00e8 relibc: implement RTLD_NOLOAD|RTLD_NOW and readdir_r
Two lie-grade panic sites in relibc's dynamic linker and POSIX header
were producing panics on common code paths:

1. ld_so/linker.rs  — called whenever a
   caller passed RTLD_NOLOAD|RTLD_NOW to dlopen(). Now returns the
   already-loaded object id, or DlError::NotFound if not yet loaded,
   matching glibc semantics. Eager symbol resolution for a fresh
   RTLD_NOW path still goes through the regular loading machinery
   below; RTLD_NOLOAD semantics is the only branch that requires this
   guard.

2. header/dirent/mod.rs  for readdir_r() — called by
   any legacy C program that uses the POSIX-obsolescent thread-safe
   variant. Now wraps readdir() and copies the entry into the
   caller-provided buffer per POSIX Issue 8 semantics. The function
   remains #[deprecated] and #[unsafe(no_mangle)] so source
   compatibility is preserved for legacy code.

Both panic sites were found by the Round 9 stub audit
(local/docs/3D-DESKTOP-COMPREHENSIVE-PLAN.md §10).
2026-07-27 18:58:23 +09:00
auronandace f3c0b52846 tackle more clippy lints 2026-07-16 08:59:10 +01:00
Jeremy Soller 7fcce3822c Merge branch 'clippy-green3' into 'master'
tackle more clippy lints for redox

See merge request redox-os/relibc!1549
2026-07-15 10:27:40 -06:00
Anhad Singh ee98a2b09c fix(dso): sysv hash table
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-15 22:55:39 +10:00
Anhad Singh 260bccbd3c fix(ld): make environ preemptable
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-15 22:40:29 +10:00
Anhad Singh bf2455ea2e misc(ld.so): cleanup
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-15 22:38:37 +10:00
auronandace ce28b8786a follow-up eliminating more as casts 2026-07-15 10:54:26 +01:00
auronandace e320c755ff tackle more clippy lints for redox 2026-07-15 10:30:48 +01:00
Anhad Singh 6697881222 feat(alloc): cleanup
* Storing a pointer to the allocator in TCB is no longer necessary.
* `AtomicPtr` to store the allocator is no longer required as the
  allocator is not swapped on init if the program was dynamically
  linked.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-15 18:26:27 +10:00
Anhad Singh 9135ddf7ed fix(ld.so): i586 compilation
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-14 18:01:04 +10:00
Anhad Singh 67512cbe58 feat(ld.so): remove ObjectHandle
ld.so has been merged with libc.so

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-14 17:41:27 +10:00
Anhad Singh a3d60b542a feat(ld.so): remove LinkerCallbacks
Not necessary as ld.so has been merged with libc.so.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-14 17:29:18 +10:00
Anhad Singh 3f20b58d38 feat(libc.so.6): merge with ld.so
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-14 17:22:43 +10:00
auronandace 7840bfcdd1 apply manual_let_else clippy lint 2026-07-08 10:07:15 +01:00
Jeremy Soller 939180a769 Merge branch 'log-ldso' into 'master'
Enable logging for ld_so

See merge request redox-os/relibc!1533
2026-07-07 06:46:04 -06:00
Wildan M 30f50abbfa Enable logging for ld_so 2026-07-06 22:00:53 +07:00
Wildan M 9a03f5f9c4 Remove ExpectTlsFree 2026-07-06 16:31:47 +07:00
Wildan M fbb56200ab Handle panic without TCB 2026-07-06 16:08:59 +07:00
4lDO2 0434043c44 Dealloc TCB on detach/join rather than exit. 2026-07-04 13:48:31 +02:00
auronandace e714c570bc make mut_from_ref deny 2026-07-02 08:28:38 +01:00
Ibuki Omatsu fba233467a refactor: Move fd allocation logic into userspace 2026-07-01 08:08:23 -06:00
auronandace c4509c9684 add implicit_clone clippy lint and tackle a few others 2026-06-15 12:14:07 +01:00
Wildan M 0b430660b7 Fix rpath not loaded 2026-05-17 08:09:53 +07:00
Wildan M 519bc8ebc8 Remove ld.so cache 2026-05-13 07:11:36 +07:00
Speedy_Lex 2d4ab41de5 Cargo fmt 2026-05-07 00:05:13 +02:00
Speedy_Lex eff610eac6 Fix many clippy lints 2026-05-07 00:05:07 +02:00
Connor-GH 7c8259dfd6 fix some lints caught by Clippy
Most of these changes are very simple. Among the changes made involve
taking advantage of auto-deref (`(*val).foo()` -> `val.foo()`) and
removing instances where we create a ref and immediately dereference it
(`&*val` -> `val`). There was a pretty neat case in `posix_openpt` where
some pointer verbosity was able to be reduced by using the more modern C
strings rather than the byte strings with an explicit NUL at the end.

Additionally, `exit()` now calls `unreachable!()` at the end. We
previously did `loop {}`, but clippy didn't like this. It can be up for
debate whether we want to make this `unreachable_unchecked` or similar.

There is only one change that might cause any sort of concern, and that
is the change from `.skip_while(!p).next()` -> `.find(p)`. This, like
everything else, was caught in a Clippy lint but I believe it deserves
some explanation because it isn't immediately obvious. Info about the
lint is here: https://rust-lang.github.io/rust-clippy/rust-1.89.0/index.html#skip_while_next
2026-04-30 19:02:35 -05:00
bjorn3 e34b259822 Cleanup building of libc.so and ld.so 2026-04-28 17:16:30 +02: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
Peter Limkilde Svendsen 55f9c611b2 Fix most rustdoc warnings 2026-04-02 00:43:20 +02:00
Wildan M e41052d307 Minor ld_so init improvement 2026-03-29 07:48:37 +07:00
Wildan M 459b8da27b Implement ld_so cache backed by shm 2026-03-29 05:34:14 +07:00
auronandace 5c646e78a1 add as conversion back in for i586 2026-03-14 14:30:06 +00: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 1421463dac assorted cleanups and add some lints 2026-03-02 10:01:05 +00:00
bjorn3 599e53db89 Use consts for AT_* in static_init 2026-02-28 16:49:17 +01:00
Marsman 26dea09563 fix: improve error handling in DSO methods 2026-02-27 13:02:11 +00:00
auronandace e1e9753c65 add upper_case_acronyms clippy lint and minor cleanups 2026-02-25 13:55:01 +00:00
Anhad Singh 1c5668acd4 feat(dso): do not zero memory
The region is mapped with the `MAP_ANONYMOUS` and thus already
initialised with zeros.

According to POSIX Issue 8:

> Anonymous memory objects shall be initialized to all bits zero.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-20 16:30:49 +11:00
Jeremy Soller 940352affe Merge branch 'master' into 'master'
Revert "fix(ld.so): temporary rollback"

See merge request redox-os/relibc!1019
2026-02-19 07:22:35 -07:00