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'sd9760bdccommit 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:ccd379c6used '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).
Redox C Library (relibc)
relibc is a portable C standard library written in Rust and is under heavy development, this library contains 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 functionscbindgencan't generate)src- Source filessrc/c- C codesrc/crt0- Runtime codesrc/crti- Runtime codesrc/crtn- Runtime codesrc/header- Header files implementationsrc/header/*- Each folder has acbindgen.tomlfile, it generates a C-to-Rust interface and header filessrc/ld_so- Dynamic loader codesrc/platform- Platform-specific and common codesrc/platform/redox- Redox-specific codesrc/platform/linux- Linux-specific codesrc/pthread- pthread implementationsrc/sync- Synchronization primitivestests- 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, orriscv64gc
- Arch can be
./check.sh --test=stdio/printf- Run a single test- Can be combined with
--hostor--arch - Will run statically linked test in Linux, dynamically linked in Redox
- Can be combined with
Couple of notes:
- Relibc and its tests will rebuild if files are changed, however switching between arch or host requires you to run
make clean - Redoxer is needed to run tests for Redox without
--host. You can install it usingcargo install redoxer - Tests can hang, 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.
