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
2025-12-09 22:28:39 +11:00
2026-01-04 02:44:50 +07:00
2025-12-28 19:43:54 +07:00
2026-01-06 15:43:11 +07:00
2020-08-07 14:16:45 +00:00
2026-01-05 14:38:11 +07:00
2019-02-20 19:27:18 +01:00
2024-07-18 23:59:48 +02:00
2018-03-07 17:29:33 -07:00
2025-10-03 21:51:10 -06:00
2025-10-06 12:44:20 +07:00

Redox C Library (relibc)

relibc is a portable C standard library written in Rust and is under heavy development, this library contain the following items:

  • C, Linux, BSD functions and extensions
  • POSIX compatibility layer
  • Interfaces for system components

The motivation for this project is twofold: Reduce issues that the Redox developers were having with newlib, and create a more stable and safe alternative to C standard libraries written in C. It is mainly designed to be used under Redox, as an alternative to newlib, but it also supports Linux via the sc crate.

Currently Redox and Linux are supported.

redox-rt

redox-rt is a runtime library that provides much of the code that enables POSIX on Redox, like fork, exec, signal handling, etc. Relibc uses it as backend in src/platform/redox, and it's intended to eventually be usable independently, without relibc.

Repository Layout

  • include - Header files (mostly macros and variadic functions cbindgen can't generate)
  • src - Source files
  • src/c - C code
  • src/crt0 - Runtime code
  • src/crti - Runtime code
  • src/crtn - Runtime code
  • src/header - Header files implementation
  • src/header/* - Each folder has a cbindgen.toml file, it generates a C-to-Rust interface and header files
  • src/ld_so - Dynamic loader code
  • src/platform - Platform-specific and common code
  • src/platform/redox - Redox-specific code
  • src/platform/linux - Linux-specific code
  • src/pthread - pthread implementation
  • src/sync - Synchronization primitives
  • tests - C tests (each MR needs to give success in all of them)

Download the sources

To download the relibc sources run the following command:

git clone --recursive https://gitlab.redox-os.org/redox-os/relibc

Build Instructions

To build relibc out of the Redox build system, do the following steps:

Dependencies

  • Install cbindgen
cargo install cbindgen

Install the expect tool

  • Debian, Ubuntu and PopOS:
sudo apt install expect
  • Fedora:
sudo dnf install expect
  • Arch Linux:
sudo pacman -S expect

Build Relibc

To build the relibc library objects, run the following command:

make all
  • Clean old library objects and tests
make clean

Build relibc inside the Redox build system

Inside of your Redox build system, run:

make prefix

If you need to rebuild relibc for testing a Cookbook recipe, run:

touch relibc
make prefix r.recipe-name

Touching (changing the "last modified time" of) the relibc folder is needed to trigger recompilation for make prefix. Replace recipe-name with your desired recipe name.

Note: Do not edit relibc inside prefix folder! Do your work on relibc folder directly inside your Redox build system instead.

Tests

Relibc has a test suite that also runs every time a new commit get pushed. You can see .gitlab-ci.yml to see how it's being executed. That being said, ./check.sh is the recommended way to run tests. Here's few examples:

  • ./check.sh - Run build, without running the test
  • ./check.sh --test - Run all tests in x86_64 Redox using Redoxer
  • ./check.sh --test --host - Run all tests in host (Linux)
  • ./check.sh --test --arch=aarch64 - Run all tests in specified arch
    • Arch can be x86_64, aarch64, i586, or riscv64gc
  • ./check.sh --test=stdio/printf - Run a single test
    • Can be combined with --host or --arch
    • Will run statically linked test in Linux, dynamically linked in Redox

Couple of notes:

  • Relibc and its tests will rebuild if files changed, however switching between arch or host requires you to run make clean
  • Redoxer is needed to run tests for Redox. You can install it using cargo install redoxer
  • Tests can hangs, the test runner can anticipate this, assuming the kernel doesn't hang too.

Issues

I'm building for my own platform which I run, and am getting x86_64-linux-gnu-ar: command not found (or similar)

The Makefile expects GNU compiler tools prefixed with the platform specifier, as would be present when you installed a cross compiler. Since you are building for your own platform, some Linux distributions (like Manjaro) don't install/symlink the prefixed executables.

An easy fix would be to replace the corresponding lines in config.mk, e.g.

ifeq ($(TARGET),x86_64-unknown-linux-gnu)
-	export CC=x86_64-linux-gnu-gcc
-	export LD=x86_64-linux-gnu-ld
-	export AR=x86_64-linux-gnu-ar
-	export NM=x86_64-linux-gnu-nm
+       export CC=gcc
+       export LD=ld
+       export AR=ar
+       export NM=nm
	export OBJCOPY=objcopy
	export CPPFLAGS=
	LD_SO_PATH=lib/ld64.so.1
endif

Contributing

Before starting to contribute, read this document.

Supported OSes

  • Redox OS
  • Linux

Supported architectures

  • i586 (Intel/AMD)
  • x86_64 (Intel/AMD)
  • aarch64 (ARM64)
  • riscv64gc (RISC-V)

Funding - Unix-style Signals and Process Management

This project is funded through NGI Zero Core, a fund established by NLnet with financial support from the European Commission's Next Generation Internet program. Learn more at the NLnet project page.

NLnet foundation logo NGI Zero Logo

S
Description
RedBear Operating System, based on RedoxOS. Licenced under MIT license.
https://redbearos.org
Readme MIT 18 GiB
Languages
C 37.5%
C++ 37.2%
JavaScript 6.7%
QML 3.4%
HTML 3.2%
Other 11.4%