Commit Graph

286 Commits

Author SHA1 Message Date
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
Anhad Singh 5568bb5a8a Revert "fix(ld.so): temporary rollback"
This reverts commit 5cf865189d.
2026-02-18 10:57:08 +11:00
Jeremy Soller 6c6232ad70 Merge branch 'correct-unused-imports' into 'master'
remove allowed unused imports

See merge request redox-os/relibc!1012
2026-02-17 09:42:44 -07:00
Anhad Singh 5cf865189d fix(ld.so): temporary rollback
See the "Redox OS/Support" channel. This commit temporarily fixes the
issue by rolling back the changes to preload the executable.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-18 02:36:03 +11:00
auronandace 53273c35c4 remove allowed unused imports 2026-02-17 15:35:58 +00:00
Anhad Singh e3abf808f3 misc(ld.so): remove no_mangle for stage2
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-17 00:47:36 +11:00
Anhad Singh d234e81fc9 fix(ld.so): debug build
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-17 00:15:10 +11:00
Anhad Singh f5ebd7882d misc(ld.so): minor cleanup
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-16 22:51:14 +11:00
Anhad Singh 0c3f88f462 misc(ld.so): fix logging
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-16 22:46:45 +11:00
Anhad Singh 371540d2ae fix(ld.so/i586): build
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-16 17:04:01 +11: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
Anhad Singh 8cb41ed4e2 feat(ld.so): shared library
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-15 19:14:07 +11:00
Anhad Singh f9487321c0 fix(ld.so): base_addr
Not guaranteed that the program headers immediately follow the ELF
header.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-15 15:47:02 +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 4a84b2f04c tidy up lints and add zero_ptr 2026-02-07 14:58:02 +00:00
auronandace be0bc8ca11 add clippy lint ref_as_ptr 2026-02-06 21:05:29 +00:00
auronandace 028061ca0f add clippy lint ptr_as_ptr 2026-02-06 17:17:07 +00:00
auronandace 473bf0389a start adding some clippy lints to Cargo.toml 2026-02-06 14:53:59 +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
Jeremy Soller 3a8f64aa14 Merge branch 'namespace-improvement' into 'master'
Introduce namespace fd and related features

See merge request redox-os/relibc!797
2026-01-20 20:43:06 -07:00
Ibuki Omatsu 1bcb6dff78 Introduce namespace fd and related features 2026-01-20 20:43:05 -07:00
Jeremy Soller 4a50c8f313 Merge branch 'p12' into 'master'
fix(libc): use `ld.so`'s allocator

See merge request redox-os/relibc!882
2026-01-20 20:35:12 -07:00
sourceturner defd2ce7c3 Deny deny-unsafe_op_in_unsafe_fn on the crate level 2026-01-21 00:41:57 +01: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 79c0df3dda fix(ld_so/dso): TPOFF with undefined symbol index
Fixes random `rustc` errors/page fault:
```
Dump of assembler code for function _RNvYNCNkNvNtNtCskfd1poFMNVt_21rustc_data_structures4sync12worker_local8REGISTRY00INtNtNtCs713rKgAoQ4g_4core3ops8function6FnOnceTINtNtB1o_6option6OptionQIB23_INtNtNtB1o_4cell4once8OnceCellNtB8_8RegistryEEEEE9call_onceBc_:
   0x0000000007651e50 <+0>:	41 56              	push   r14
   0x0000000007651e52 <+2>:	53                 	push   rbx
   0x0000000007651e53 <+3>:	50                 	push   rax
   0x0000000007651e54 <+4>:	48 8b 1d 6d 9c 46 02	mov    rbx,QWORD PTR [rip+0x2469c6d]        # 0x9abbac8
   0x0000000007651e5b <+11>:	64 48 8b 04 25 00 00 00 00	mov    rax,QWORD PTR fs:0x0
   0x0000000007651e64 <+20>:	0f b6 4c 18 08     	movzx  ecx,BYTE PTR [rax+rbx*1+0x8]
   0x0000000007651e69 <+25>:	48 01 d8           	add    rax,rbx
   0x0000000007651e6c <+28>:	83 f9 01           	cmp    ecx,0x1
   0x0000000007651e6f <+31>:	74 07              	je     0x7651e78 <_RNvYNCNkNvNtNtCskfd1poFMNVt_21rustc_data_structures4sync12worker_local8REGISTRY00INtNtNtCs713rKgAoQ4g_4core3ops8function6FnOnceTINtNtB1o_6option6OptionQIB23_INtNtNtB1o_4cell4once8OnceCellNtB8_8RegistryEEEEE9call_onceBc_+40>
   0x0000000007651e71 <+33>:	83 f9 02           	cmp    ecx,0x2
   0x0000000007651e74 <+36>:	75 0a              	jne    0x7651e80 <_RNvYNCNkNvNtNtCskfd1poFMNVt_21rustc_data_structures4sync12worker_local8REGISTRY00INtNtNtCs713rKgAoQ4g_4core3ops8function6FnOnceTINtNtB1o_6option6OptionQIB23_INtNtNtB1o_4cell4once8OnceCellNtB8_8RegistryEEEEE9call_onceBc_+48>
   0x0000000007651e76 <+38>:	31 c0              	xor    eax,eax
   0x0000000007651e78 <+40>:	48 83 c4 08        	add    rsp,0x8
   0x0000000007651e7c <+44>:	5b                 	pop    rbx
   0x0000000007651e7d <+45>:	41 5e              	pop    r14
   0x0000000007651e7f <+47>:	c3                 	ret
   0x0000000007651e80 <+48>:	48 8d 35 69 11 00 00	lea    rsi,[rip+0x1169]        # 0x7652ff0 <_RINvNtNtNtNtCs7Gz96wxcBnT_3std3sys12thread_local6native5eager7destroyINtNtNtCs713rKgAoQ4g_4core4cell4once8OnceCellNtNtNtCskfd1poFMNVt_21rustc_data_structures4sync12worker_local8RegistryEEB1U_.llvm.5183627946997663933>
   0x0000000007651e87 <+55>:	48 89 c7           	mov    rdi,rax
   0x0000000007651e8a <+58>:	49 89 c6           	mov    r14,rax
   0x0000000007651e8d <+61>:	ff 15 c5 6b 47 02  	call   QWORD PTR [rip+0x2476bc5]        # 0x9ac8a58
   0x0000000007651e93 <+67>:	4c 89 f0           	mov    rax,r14
   0x0000000007651e96 <+70>:	64 48 8b 0c 25 00 00 00 00	mov    rcx,QWORD PTR fs:0x0
    # rcx = 0x20aeb000 [FSBASE]
    # rbx = 0x2b40
   0x0000000007651e9f <+79>:	c6 44 19 08 01     	mov    BYTE PTR [rcx+rbx*1+0x8],0x1 # <--- PAGE FAULT
   0x0000000007651ea4 <+84>:	48 83 c4 08        	add    rsp,0x8
   0x0000000007651ea8 <+88>:	5b                 	pop    rbx
   0x0000000007651ea9 <+89>:	41 5e              	pop    r14
   0x0000000007651eab <+91>:	c3                 	ret
```

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-01-08 11:45:36 +11:00
Anhad Singh 75f6b9d64e fix(dl-tls): TLS overallocation
* `offset` is the offset in TLS to copy initial data to NOT the segment
  size
* Only zero the region which is required to be zeroed

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-29 17:13:23 +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 a7918b108d misc(ld_so/start): consistent log formatting
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-22 19:06:10 +11:00
Anhad Singh aa86e9e027 fix(riscv64/x86): build
Stub `__tlsdesc_dynamic` for riscv64/x86 for now.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-10 13:52:37 +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
Anhad Singh 8572c855fc feat(ld_so/dso): TLSDESC
The dynamic linker now works on aarch64. You can also try it on Linux by
setting `TEST_RUNNER` to `qemu-aarch64` when running `make test
TARGET=aarch64-unknown-linux-gnu`

Co-authored-by: @willnode
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-09 22:28:39 +11:00
Anhad Singh 4f1920ab96 feat(ld_so/tcb): implement os_arch_activate for aarch64 linux
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-01 14:46:07 +11:00
Anhad Singh 6262c4ae50 fix(ld_so): getting TP on linux
`ARCH_GET_FS` is x86_64 specific. On aarch64 it is not platform
specific and just need to read out the TP from `TPIDR_EL0`

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-01 14:46:07 +11:00
Jeremy Soller 0844e6fc90 WIP: use upper fd table 2025-11-15 07:55:37 -07:00
Jeremy Soller 74e3ad1c2c Do TLS alignment in reliable way 2025-11-13 12:07:06 -07:00
Jeremy Soller c4050203e8 Revert "Align TLS to 16 bytes again"
This reverts commit 860a8e6e4b.
2025-11-13 08:16:22 -07:00
Jeremy Soller 860a8e6e4b Align TLS to 16 bytes again 2025-11-10 17:05:57 -07:00
Jeremy Soller cb0acf3e57 Revert "Make sure TLS modules are aligned to 16 bytes for SSE"
This reverts commit d39fe6c9fb.
2025-11-01 10:44:34 -06:00