Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • martin/relibc
  • ashton/relibc
  • vincent/relibc
  • boomshroom/relibc
  • gmacd/relibc
  • mati865/relibc
  • nicoan/relibc
  • lmiskiew/relibc
  • devnexen/relibc
  • jamesgraves/relibc
  • oddcoder/relibc
  • andar1an/relibc
  • bitstr0m/relibc
  • gugz0r/relibc
  • matijaskala/relibc
  • redox-os/relibc
  • arthurpaulino/relibc
  • Majoneza/relibc
  • 4lDO2/relibc
  • enygmator/relibc
  • JustAnotherDev/relibc
  • doriancodes/relibc
  • adamantinum/relibc
  • wiredtv/relibc
  • stratact/relibc
  • Ramla-I/relibc
  • njskalski/relibc
  • bpisch/relibc
  • henritel/relibc
  • smckay/relibc
  • xTibor/relibc
  • devajithvs/relibc
  • andypython/relibc
  • t-nil/relibc
  • zen3ger/relibc
  • DataTriny/relibc
  • SteveLauC/relibc
  • dlrobertson/relibc
  • josh/relibc
  • AgostonSzepessy/relibc
  • TheDarkula/relibc
  • willnode/relibc
  • bamontan/relibc
  • raffaeleragni/relibc
  • redoxeon/relibc
  • darley/relibc
  • ayf/relibc
  • heghe/relibc
  • Ivan/relibc
  • hasheddan/relibc
  • dahc/relibc
  • auwardoctor/relibc
  • kodicraft/relibc
  • jasonhansel/relibc
  • kel/relibc
  • microcolonel/relibc
  • GrayJack/relibc
  • sahitpj/relibc
  • plimkilde/relibc
  • BjornTheProgrammer/relibc
  • defra/relibc
  • jD91mZM2/relibc
  • Schyrsivochter/relibc
  • ebalalic/relibc
  • adchacon/relibc
  • aaronjanse/relibc
  • josh_williams/relibc
  • 8tab/relibc
  • athei/relibc
  • carrot93/relibc
  • RA_GM1/relibc
  • zhaozhao/relibc
  • JCake/relibc
  • KGrewal1/relibc
  • feliwir/relibc
  • emturner/relibc
  • LuigiPiucco/relibc
  • bfrascher/relibc
  • starsheriff/relibc
  • kcired/relibc
  • jamespcfrancis/relibc
  • omar-mohamed-khallaf/relibc
  • neallred/relibc
  • rw_van/relibc
  • Skallwar/relibc
  • matt-vdv/relibc
  • SoyaOhnishi/relibc
  • ArniDagur/relibc
  • tlam/relibc
  • glongo/relibc
  • kamirr/relibc
  • abdullah/relibc
  • saeedtabrizi/relibc
  • sajattack/relibc
  • seanpk/relibc
  • MaikuZ/relibc
  • jamadazi/relibc
  • coolreader18/relibc
  • wt/relibc
  • lebensterben/relibc
  • uuuvn/relibc
  • vadorovsky/relibc
  • ids1024/relibc
  • freewilll/relibc
  • LLeny/relibc
  • alfredoyang/relibc
  • batonius/relibc
  • TornaxO7/relibc
  • bjorn3/relibc
  • Arcterus/relibc
  • Tommoa/relibc
  • samuela/relibc
  • mindriot101/relibc
  • lygstate/relibc
114 results
Show changes
Commits on Source (655)
...@@ -6,6 +6,8 @@ variables: ...@@ -6,6 +6,8 @@ variables:
stages: stages:
- build - build
- test - test
before_script:
cargo install cbindgen
default: default:
cache: cache:
......
[submodule "openlibm"] [submodule "openlibm"]
path = openlibm path = openlibm
url = https://gitlab.redox-os.org/redox-os/openlibm.git url = https://github.com/JuliaMath/openlibm.git
[submodule "ralloc"] branch = master
path = ralloc
url = https://gitlab.redox-os.org/redox-os/ralloc.git
[submodule "core_io"]
path = core_io
url = https://gitlab.redox-os.org/redox-os/core_io.git
[submodule "posix-regex"] [submodule "posix-regex"]
path = posix-regex path = posix-regex
url = https://gitlab.redox-os.org/redox-os/posix-regex.git url = https://gitlab.redox-os.org/redox-os/posix-regex.git
[submodule "pthreads-emb"]
path = pthreads-emb
url = https://gitlab.redox-os.org/redox-os/pthreads-emb.git
[submodule "compiler-builtins"] [submodule "compiler-builtins"]
path = compiler-builtins path = compiler-builtins
url = https://gitlab.redox-os.org/redox-os/compiler-builtins.git url = https://gitlab.redox-os.org/redox-os/compiler-builtins.git
branch = relibc_fix_dup_symbols branch = relibc_fix_dup_symbols
[submodule "src/dlmalloc-rs"]
path = dlmalloc-rs
url = https://gitlab.redox-os.org/redox-os/dlmalloc-rs.git
{
"cmake.ignoreCMakeListsMissing": true
}
\ No newline at end of file
This diff is collapsed.
...@@ -9,47 +9,64 @@ name = "relibc" ...@@ -9,47 +9,64 @@ name = "relibc"
crate-type = ["staticlib"] crate-type = ["staticlib"]
[workspace] [workspace]
members = ["src/crt0", "src/crti", "src/crtn", "src/ld_so", "src/platform/redox/redox-exec"] members = [
exclude = ["core_io", "ralloc", "tests"] "src/crt0",
"src/crti",
"src/crtn",
"redox-rt",
"ld_so",
"generic-rt",
]
exclude = ["tests", "dlmalloc-rs"]
[build-dependencies] [build-dependencies]
cbindgen = "0.26" cc = "1"
cc = "1.0.25"
#env_logger = "0.10"
[dependencies] [dependencies]
bitflags = "2" bitflags = "2"
cbitset = "0.2" cbitset = "0.2"
core_io = { path = "core_io", features = ["collections"] }
memoffset = "0.9"
posix-regex = { path = "posix-regex", features = ["no_std"] } posix-regex = { path = "posix-regex", features = ["no_std"] }
# TODO: For some reason, rand_jitter hasn't been updated to use the latest rand_core # TODO: For some reason, rand_jitter hasn't been updated to use the latest rand_core
rand = { version = "0.7", default-features = false } rand = { version = "0.8", default-features = false, features = ["small_rng"] }
rand_xorshift = "0.2" rand_xorshift = "0.3"
rand_jitter = "0.3" rand_jitter = "0.4"
memchr = { version = "2.2.0", default-features = false } memchr = { version = "2.2.0", default-features = false }
plain = "0.2" plain = "0.2"
unicode-width = "0.1" unicode-width = "0.1"
__libc_only_for_layout_checks = { package = "libc", version = "0.2.149", optional = true } __libc_only_for_layout_checks = { package = "libc", version = "0.2.149", optional = true }
md5-crypto = { package = "md-5", version = "0.10.6", default-features = false }
sha-crypt = { version = "0.5", default-features = false }
base64ct = { version = "1.6", default-features = false, features = ["alloc"] }
bcrypt-pbkdf = { version = "0.10", default-features = false, features = [
"alloc",
] }
scrypt = { version = "0.11", default-features = false, features = ["simple"] }
pbkdf2 = { version = "0.12", features = ["sha2"] }
sha2 = { version = "0.10", default-features = false }
generic-rt = { path = "generic-rt" }
chrono-tz = {version = "0.10", default-features = false}
chrono = {version = "0.4", default-features = false, features = ["alloc"]}
libm = "0.2"
object = { version = "0.36.7", git = "https://gitlab.redox-os.org/andypython/object", default-features = false, features = ["elf", "read_core"] }
spin = "0.9.8"
[dependencies.goblin] [dependencies.dlmalloc]
version = "0.7" path = "dlmalloc-rs"
default-features = false default-features = false
features = ["elf32", "elf64", "endian_fd"] features = ["c_api"]
[dependencies.ralloc]
path = "ralloc"
default-features = false
optional = true
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
sc = "0.2.3" sc = "0.2.3"
[target.'cfg(target_os = "redox")'.dependencies] [target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.4" redox_syscall = "0.5.8"
redox-exec = { path = "src/platform/redox/redox-exec" } redox-rt = { path = "redox-rt" }
redox-path = "0.2"
redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git", default-features = false, features = [
"redox_syscall",
] }
[features] [features]
default = ["check_against_libc_crate"] default = ["check_against_libc_crate"]
...@@ -63,4 +80,4 @@ panic = "abort" ...@@ -63,4 +80,4 @@ panic = "abort"
panic = "abort" panic = "abort"
[patch.crates-io] [patch.crates-io]
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall" } cc-11 = { git = "https://github.com/tea/cc-rs", branch = "riscv-abi-arch-fix", package = "cc" }
TARGET?=$(shell rustc -Z unstable-options --print target-spec-json | grep llvm-target | cut -d '"' -f4) ifndef TARGET
export TARGET:=$(shell rustc -Z unstable-options --print target-spec-json | grep llvm-target | cut -d '"' -f4)
endif
CARGO?=cargo CARGO?=cargo
CARGO_TEST?=$(CARGO) CARGO_TEST?=$(CARGO)
...@@ -7,42 +9,70 @@ CARGOFLAGS?=$(CARGO_COMMON_FLAGS) ...@@ -7,42 +9,70 @@ CARGOFLAGS?=$(CARGO_COMMON_FLAGS)
RUSTCFLAGS?= RUSTCFLAGS?=
export OBJCOPY?=objcopy export OBJCOPY?=objcopy
BUILD?="$(shell pwd)/target/$(TARGET)" BUILD?=$(shell pwd)/target/$(TARGET)
CARGOFLAGS+="--target=$(TARGET)" CARGOFLAGS+=--target=$(TARGET)
TARGET_HEADERS?=$(BUILD)/include
export CFLAGS=-I$(TARGET_HEADERS)
PROFILE?=release
HEADERS_UNPARSED=$(shell find src/header -mindepth 1 -maxdepth 1 -type d -not -name "_*" -printf "%f\n")
HEADERS_DEPS=$(shell find src/header -type f \( -name "cbindgen.toml" -o -name "*.rs" \))
#HEADERS=$(patsubst %,%.h,$(subst _,/,$(HEADERS_UNPARSED)))
ifeq ($(TARGET),aarch64-unknown-linux-gnu) ifeq ($(TARGET),aarch64-unknown-linux-gnu)
export CC=aarch64-linux-gnu-gcc export CC=aarch64-linux-gnu-gcc
export LD=aarch64-linux-gnu-ld export LD=aarch64-linux-gnu-ld
export AR=aarch64-linux-gnu-ar export AR=aarch64-linux-gnu-ar
export NM=aarch64-linux-gnu-nm
export OBJCOPY=aarch64-linux-gnu-objcopy export OBJCOPY=aarch64-linux-gnu-objcopy
export CPPFLAGS=
endif endif
ifeq ($(TARGET),aarch64-unknown-redox) ifeq ($(TARGET),aarch64-unknown-redox)
export CC=aarch64-unknown-redox-gcc export CC=aarch64-unknown-redox-gcc
export LD=aarch64-unknown-redox-ld export LD=aarch64-unknown-redox-ld
export AR=aarch64-unknown-redox-ar export AR=aarch64-unknown-redox-ar
export NM=aarch64-unknown-redox-nm
export OBJCOPY=aarch64-unknown-redox-objcopy export OBJCOPY=aarch64-unknown-redox-objcopy
export CPPFLAGS=
endif endif
ifeq ($(TARGET),x86_64-unknown-linux-gnu) ifeq ($(TARGET),x86_64-unknown-linux-gnu)
export CC=x86_64-linux-gnu-gcc export CC=x86_64-linux-gnu-gcc
export LD=x86_64-linux-gnu-ld export LD=x86_64-linux-gnu-ld
export AR=x86_64-linux-gnu-ar export AR=x86_64-linux-gnu-ar
export OBJCOPY=x86_64-linux-gnu-objcopy export NM=x86_64-linux-gnu-nm
export OBJCOPY=objcopy
export CPPFLAGS=
endif endif
ifeq ($(TARGET),i686-unknown-redox) ifeq ($(TARGET),i686-unknown-redox)
export CC=i686-unknown-redox-gcc export CC=i686-unknown-redox-gcc
export LD=i686-unknown-redox-ld export LD=i686-unknown-redox-ld
export AR=i686-unknown-redox-ar export AR=i686-unknown-redox-ar
export NM=i686-unknown-redox-nm
export OBJCOPY=i686-unknown-redox-objcopy export OBJCOPY=i686-unknown-redox-objcopy
export CPPFLAGS=
endif endif
ifeq ($(TARGET),x86_64-unknown-redox) ifeq ($(TARGET),x86_64-unknown-redox)
export CC=x86_64-unknown-redox-gcc export CC=x86_64-unknown-redox-gcc
export LD=x86_64-unknown-redox-ld export LD=x86_64-unknown-redox-ld
export AR=x86_64-unknown-redox-ar export AR=x86_64-unknown-redox-ar
export NM=x86_64-unknown-redox-nm
export OBJCOPY=x86_64-unknown-redox-objcopy export OBJCOPY=x86_64-unknown-redox-objcopy
export CPPFLAGS=
endif
ifeq ($(TARGET),riscv64gc-unknown-redox)
export CC=riscv64-unknown-redox-gcc
export LD=riscv64-unknown-redox-ld
export AR=riscv64-unknown-redox-ar
export NM=riscv64-unknown-redox-nm
export OBJCOPY=riscv64-unknown-redox-objcopy
export CPPFLAGS=-march=rv64gc -mabi=lp64d
endif endif
SRC=\ SRC=\
...@@ -51,9 +81,26 @@ SRC=\ ...@@ -51,9 +81,26 @@ SRC=\
BUILTINS_VERSION=0.1.70 BUILTINS_VERSION=0.1.70
.PHONY: all clean fmt install install-libs install-headers install-tests libs submodules test .PHONY: all clean fmt install install-libs install-headers install-tests libs headers submodules test
all: | libs all: | headers libs
headers: $(HEADERS_DEPS)
rm -rf $(TARGET_HEADERS)
mkdir -pv $(TARGET_HEADERS)
cp -rv include/* $(TARGET_HEADERS)
cp -v "openlibm/include"/*.h $(TARGET_HEADERS)
cp -v "openlibm/src"/*.h $(TARGET_HEADERS)
set -e ; \
for header in $(HEADERS_UNPARSED); do \
echo "Header $$header"; \
if test -f "src/header/$$header/cbindgen.toml"; then \
out=`echo "$$header" | sed 's/_/\//g'`; \
out="$(TARGET_HEADERS)/$$out.h"; \
cat "src/header/$$header/cbindgen.toml" cbindgen.globdefs.toml \
| cbindgen "src/header/$$header/mod.rs" --config=/dev/stdin --output "$$out"; \
fi \
done
clean: clean:
$(CARGO) clean $(CARGO) clean
...@@ -66,31 +113,28 @@ check: ...@@ -66,31 +113,28 @@ check:
fmt: fmt:
./fmt.sh ./fmt.sh
install-headers: libs install-headers: headers libs
mkdir -pv "$(DESTDIR)/include" mkdir -pv "$(DESTDIR)/include"
cp -rv "include"/* "$(DESTDIR)/include" cp -rv "$(TARGET_HEADERS)"/* "$(DESTDIR)/include"
cp -rv "target/include"/* "$(DESTDIR)/include"
cp -v "openlibm/include"/*.h "$(DESTDIR)/include"
cp -v "openlibm/src"/*.h "$(DESTDIR)/include"
libs: \ libs: \
$(BUILD)/release/libc.a \ $(BUILD)/$(PROFILE)/libc.a \
$(BUILD)/release/libc.so \ $(BUILD)/$(PROFILE)/libc.so \
$(BUILD)/release/crt0.o \ $(BUILD)/$(PROFILE)/crt0.o \
$(BUILD)/release/crti.o \ $(BUILD)/$(PROFILE)/crti.o \
$(BUILD)/release/crtn.o \ $(BUILD)/$(PROFILE)/crtn.o \
$(BUILD)/release/ld_so $(BUILD)/$(PROFILE)/ld_so
install-libs: libs install-libs: headers libs
mkdir -pv "$(DESTDIR)/lib" mkdir -pv "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/libc.a" "$(DESTDIR)/lib" cp -v "$(BUILD)/$(PROFILE)/libc.a" "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/libc.so" "$(DESTDIR)/lib" cp -v "$(BUILD)/$(PROFILE)/libc.so" "$(DESTDIR)/lib"
ln -vnfs libc.so "$(DESTDIR)/lib/libc.so.6" ln -vnfs libc.so "$(DESTDIR)/lib/libc.so.6"
cp -v "$(BUILD)/release/crt0.o" "$(DESTDIR)/lib" cp -v "$(BUILD)/$(PROFILE)/crt0.o" "$(DESTDIR)/lib"
ln -vnfs crt0.o "$(DESTDIR)/lib/crt1.o" ln -vnfs crt0.o "$(DESTDIR)/lib/crt1.o"
cp -v "$(BUILD)/release/crti.o" "$(DESTDIR)/lib" cp -v "$(BUILD)/$(PROFILE)/crti.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/crtn.o" "$(DESTDIR)/lib" cp -v "$(BUILD)/$(PROFILE)/crtn.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/release/ld_so" "$(DESTDIR)/lib/ld64.so.1" cp -v "$(BUILD)/$(PROFILE)/ld_so" "$(DESTDIR)/lib/ld64.so.1"
cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a" cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
# Empty libraries for dl, pthread, and rt # Empty libraries for dl, pthread, and rt
$(AR) -rcs "$(DESTDIR)/lib/libdl.a" $(AR) -rcs "$(DESTDIR)/lib/libdl.a"
...@@ -122,6 +166,19 @@ test: sysroot ...@@ -122,6 +166,19 @@ test: sysroot
$(MAKE) -C tests run $(MAKE) -C tests run
$(MAKE) -C tests verify $(MAKE) -C tests verify
$(BUILD)/$(PROFILE)/libc.so: $(BUILD)/$(PROFILE)/librelibc.a $(BUILD)/openlibm/libopenlibm.a
$(CC) -nostdlib \
-shared \
-Wl,--gc-sections \
-Wl,-z,pack-relative-relocs \
-Wl,--sort-common \
-Wl,--allow-multiple-definition \
-Wl,--whole-archive $^ -Wl,--no-whole-archive \
-Wl,-soname,libc.so.6 \
-lgcc \
-o $@
# Debug targets # Debug targets
$(BUILD)/debug/libc.a: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm.a $(BUILD)/debug/libc.a: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm.a
...@@ -133,32 +190,29 @@ $(BUILD)/debug/libc.a: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm. ...@@ -133,32 +190,29 @@ $(BUILD)/debug/libc.a: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm.
echo "end" >> "$@.mri" echo "end" >> "$@.mri"
$(AR) -M < "$@.mri" $(AR) -M < "$@.mri"
$(BUILD)/debug/libc.so: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm.a
$(CC) -nostdlib -shared -Wl,--allow-multiple-definition -Wl,--whole-archive $^ -Wl,--no-whole-archive -Wl,-soname,libc.so.6 -o $@
$(BUILD)/debug/librelibc.a: $(SRC) $(BUILD)/debug/librelibc.a: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS) $(CARGO) rustc $(CARGOFLAGS) -- --emit link=$@ -g -C debug-assertions=no $(RUSTCFLAGS)
./renamesyms.sh $@ $(BUILD)/debug/deps/ ./renamesyms.sh "$@" "$(BUILD)/debug/deps/"
touch $@ touch $@
$(BUILD)/debug/crt0.o: $(SRC) $(BUILD)/debug/crt0.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/debug/crti.o: $(SRC) $(BUILD)/debug/crti.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/debug/crtn.o: $(SRC) $(BUILD)/debug/crtn.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/debug/ld_so.o: $(SRC) $(BUILD)/debug/ld_so.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --manifest-path ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort -g -C debug-assertions=no $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/debug/ld_so: $(BUILD)/debug/ld_so.o $(BUILD)/debug/crti.o $(BUILD)/debug/libc.a $(BUILD)/debug/crtn.o $(BUILD)/debug/ld_so: $(BUILD)/debug/ld_so.o $(BUILD)/debug/crti.o $(BUILD)/debug/libc.a $(BUILD)/debug/crtn.o
$(LD) --no-relax -T src/ld_so/ld_script/$(TARGET).ld --allow-multiple-definition --gc-sections --gc-keep-exported $^ -o $@ $(LD) --no-relax -T ld_so/ld_script/$(TARGET).ld --allow-multiple-definition --gc-sections $^ -o $@
# Release targets # Release targets
...@@ -171,34 +225,31 @@ $(BUILD)/release/libc.a: $(BUILD)/release/librelibc.a $(BUILD)/openlibm/libopenl ...@@ -171,34 +225,31 @@ $(BUILD)/release/libc.a: $(BUILD)/release/librelibc.a $(BUILD)/openlibm/libopenl
echo "end" >> "$@.mri" echo "end" >> "$@.mri"
$(AR) -M < "$@.mri" $(AR) -M < "$@.mri"
$(BUILD)/release/libc.so: $(BUILD)/release/librelibc.a $(BUILD)/openlibm/libopenlibm.a
$(CC) -nostdlib -shared -Wl,--allow-multiple-definition -Wl,--whole-archive $^ -Wl,--no-whole-archive -Wl,-soname,libc.so.6 -o $@
$(BUILD)/release/librelibc.a: $(SRC) $(BUILD)/release/librelibc.a: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --release $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS) $(CARGO) rustc --release $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS)
# TODO: Better to only allow a certain whitelisted set of symbols? Perhaps # TODO: Better to only allow a certain whitelisted set of symbols? Perhaps
# use some cbindgen hook, specify them manually, or grep for #[no_mangle]. # use some cbindgen hook, specify them manually, or grep for #[no_mangle].
./renamesyms.sh $@ $(BUILD)/release/deps/ ./renamesyms.sh "$@" "$(BUILD)/release/deps/"
touch $@ touch $@
$(BUILD)/release/crt0.o: $(SRC) $(BUILD)/release/crt0.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/release/crti.o: $(SRC) $(BUILD)/release/crti.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --release --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/release/crtn.o: $(SRC) $(BUILD)/release/crtn.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --release --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/release/ld_so.o: $(SRC) $(BUILD)/release/ld_so.o: $(SRC)
CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS) $(CARGO) rustc --release --manifest-path ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@ touch $@
$(BUILD)/release/ld_so: $(BUILD)/release/ld_so.o $(BUILD)/release/crti.o $(BUILD)/release/libc.a $(BUILD)/release/crtn.o $(BUILD)/release/ld_so: $(BUILD)/release/ld_so.o $(BUILD)/release/crti.o $(BUILD)/release/libc.a $(BUILD)/release/crtn.o
$(LD) --no-relax -T src/ld_so/ld_script/$(TARGET).ld --allow-multiple-definition --gc-sections --gc-keep-exported $^ -o $@ $(LD) --no-relax -T ld_so/ld_script/$(TARGET).ld --allow-multiple-definition --gc-sections $^ -o $@
# Other targets # Other targets
...@@ -210,4 +261,5 @@ $(BUILD)/openlibm: openlibm ...@@ -210,4 +261,5 @@ $(BUILD)/openlibm: openlibm
touch $@ touch $@
$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/release/librelibc.a $(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/release/librelibc.a
$(MAKE) AR=$(AR) CC=$(CC) LD=$(LD) CPPFLAGS="-fno-stack-protector -I $(shell pwd)/include -I $(shell pwd)/target/include" -C $< libopenlibm.a $(MAKE) AR=$(AR) CC=$(CC) LD=$(LD) CPPFLAGS="$(CPPFLAGS) -fno-stack-protector -I$(shell pwd)/include -I$(TARGET_HEADERS)" -C $< libopenlibm.a
./renamesyms.sh "$@" "$(BUILD)/release/deps/"
# relibc # Redox C Library (relibc)
relibc is a portable POSIX C standard library written in Rust. It is under heavy development, and currently supports Redox and Linux. relibc is a portable POSIX C standard library written in Rust and is under heavy development.
The motivation for this project is twofold: Reduce issues that the Redox developers were having with [newlib](https://sourceware.org/newlib/), and create a safer alternative to a C standard library written in C. It is mainly designed to be used under Redox, as an alternative to newlib, but it also supports Linux system calls via the [sc](https://crates.io/crates/sc) crate. The motivation for this project is twofold: Reduce issues that the Redox developers were having with [newlib](https://sourceware.org/newlib/), and create a safer alternative to a C standard library written in C. It is mainly designed to be used under Redox, as an alternative to newlib, but it also supports Linux system calls via the [sc](https://crates.io/crates/sc) crate.
### Repository Layout Currently Redox and Linux are supported.
## redox-rt
redox-rt is our equivalent for [vDSO](https://en.wikipedia.org/wiki/VDSO) from Linux.
## Repository Layout
- `include` - Header files (mostly macros and variadic functions `cbindgen` can't generate) - `include` - Header files (mostly macros and variadic functions `cbindgen` can't generate)
- `src` - Source files - `src` - Source files
...@@ -22,7 +28,61 @@ The motivation for this project is twofold: Reduce issues that the Redox develop ...@@ -22,7 +28,61 @@ The motivation for this project is twofold: Reduce issues that the Redox develop
- `src/sync` - Synchronization primitives - `src/sync` - Synchronization primitives
- `tests` - C tests (each MR needs to give success in all of them) - `tests` - C tests (each MR needs to give success in all of them)
### Build On The Build System ## Download the sources
To download the relibc sources run the following command:
```sh
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`
```sh
cargo install cbindgen
```
#### Install the `expect` tool
- Debian, Ubuntu and PopOS:
```sh
sudo apt install expect
```
- Fedora:
```sh
sudo dnf install expect
```
- Arch Linux:
```sh
sudo pacman -S expect
```
### Build Relibc
To build the relibc library objects, run the following command:
```sh
make all
```
- Clean old library objects and tests
```sh
make clean
```
## Build relibc inside the Redox build system
Inside of your Redox build system, run: Inside of your Redox build system, run:
...@@ -30,9 +90,59 @@ Inside of your Redox build system, run: ...@@ -30,9 +90,59 @@ Inside of your Redox build system, run:
make prefix make prefix
``` ```
(It only works if the timestamp of the `relibc` folder changed) If you need to rebuild `relibc` for testing a Cookbook recipe, run:
```sh
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
This section explain how to build and run the tests.
### Build
To build the tests run `make all` on the `tests` folder, it will store the executables at `tests/bins_static`
If you did changes to your tests, run `make clean all` to rebuild the executables.
### Redox OS Testing
To test on Redox do the following steps:
- Add the `relibc-tests` recipe on your filesystem configuration at `config/your-cpu/your-config.toml` (generally `desktop.toml`)
- Run the following commands to rebuild relibc with your changes, update the `relibc-tests` recipe and update your QEMU image:
```sh
touch relibc
```
```sh
make prefix cr.relibc-tests image
```
- Run the tests
```sh
/usr/share/relibc-tests/bins_static/test-name
```
### Linux Testing
Run `make test` on the relibc directory.
If you want to run one test, run the following command:
```sh
tests/bins_static/test-name
```
### Issues ## Issues
#### I'm building for my own platform which I run, and am getting `x86_64-linux-gnu-ar: command not found` (or similar) #### I'm building for my own platform which I run, and am getting `x86_64-linux-gnu-ar: command not found` (or similar)
...@@ -51,16 +161,17 @@ An easy fix would be to replace the corresponding lines in the Makefile, e.g. ...@@ -51,16 +161,17 @@ An easy fix would be to replace the corresponding lines in the Makefile, e.g.
endif endif
``` ```
### Contributing ## Contributing
Before starting to contribute, read [this](CONTRIBUTING.md) document. Before starting to contribute, read [this](CONTRIBUTING.md) document.
### Supported OSes ## Supported OSes
- Redox OS - Redox OS
- Linux - Linux
### Supported architectures ## Supported architectures
- x86_64 (Intel/AMD) - i686 (Intel/AMD)
- Aarch64 (ARM64) - x86_64 (Intel/AMD)
- Aarch64 (ARM64)
[dependencies.alloc]
extern crate cbindgen;
extern crate cc; extern crate cc;
use std::{env, fs, fs::DirEntry, path::Path}; use std::{env, fs};
// include src/header directories that don't start with '_'
fn include_dir(d: &DirEntry) -> bool {
d.metadata().map(|m| m.is_dir()).unwrap_or(false)
&& d.path()
.iter()
.nth(2)
.map_or(false, |c| c.to_str().map_or(false, |x| !x.starts_with("_")))
}
fn get_target() -> String { fn get_target() -> String {
env::var("TARGET").unwrap_or( env::var("TARGET").unwrap_or(
...@@ -18,57 +8,15 @@ fn get_target() -> String { ...@@ -18,57 +8,15 @@ fn get_target() -> String {
) )
} }
fn generate_bindings(cbindgen_config_path: &Path) {
let relative_path = cbindgen_config_path
.strip_prefix("src/header")
.ok()
.and_then(|p| p.parent())
.and_then(|p| p.to_str())
.unwrap()
.replace("_", "/");
let header_path = Path::new("target/include")
.join(&relative_path)
.with_extension("h");
let mod_path = cbindgen_config_path.with_file_name("mod.rs");
let config = cbindgen::Config::from_file(cbindgen_config_path).unwrap();
cbindgen::Builder::new()
.with_config(config)
.with_src(mod_path)
.generate()
.expect("Unable to generate bindings")
.write_to_file(header_path);
}
fn main() { fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let target = get_target(); let target = get_target();
// Generate C includes
// - based on contents of src/header/**
// - headers written to target/include
fs::read_dir(&Path::new("src/header"))
.unwrap()
.into_iter()
.filter_map(Result::ok)
.filter(|d| include_dir(d))
.map(|d| d.path().as_path().join("cbindgen.toml"))
.filter(|p| p.exists())
.for_each(|p| {
println!("cargo:rerun-if-changed={:?}", p.parent().unwrap());
println!("cargo:rerun-if-changed={:?}", p);
println!("cargo:rerun-if-changed={:?}", p.with_file_name("mod.rs"));
generate_bindings(&p);
});
println!("cargo:rerun-if-changed=src/c"); println!("cargo:rerun-if-changed=src/c");
let mut cc_builder = &mut cc::Build::new(); let mut cc_builder = &mut cc::Build::new();
cc_builder = cc_builder cc_builder = cc_builder.flag("-nostdinc").flag("-nostdlib");
.flag("-nostdinc")
.flag("-nostdlib")
.include(&format!("{}/include", crate_dir))
.include(&format!("{}/target/include", crate_dir));
if target.starts_with("aarch64") { if target.starts_with("aarch64") {
cc_builder = cc_builder.flag("-mno-outline-atomics") cc_builder = cc_builder.flag("-mno-outline-atomics")
......
# needs a leading newline
[defines]
"target_os=redox" = "__redox__"
"target_os=linux" = "__linux__"
"target_pointer_width=64" = "__LP64__"
"target_pointer_width=32" = "__LP32__"
"target_arch=x86" = "__i386__"
"target_arch=x86_64" = "__x86_64__"
"target_arch=aarch64" = "__aarch64__"
# This is not exact. It should be `defined(__riscv) && defined(__LP64__)`, or `defined(__riscv) && __riscv_xlen==64`
# This will do however, as long as we only support riscv64 and not riscv32
"target_arch=riscv64" = "__riscv"
# XXX: silences a warning
"feature = no_std" = "__relibc__"
# Ensure attributes are passed down from Rust
# <features.h> must be included where attributes are used in relibc
[fn]
must_use = "__nodiscard"
deprecated = "__deprecated"
deprecated_with_note = "__deprecatedNote({})"
no_return = "__noreturn"
Subproject commit bcb799d1d1f610cbcc3c5db0188eef63677ad97e
Subproject commit 2242e05dc862f221fa1c0cc8ef23f0e9595b1dfa
#!/usr/bin/env bash #!/usr/bin/env bash
cargo fmt --package relibc --package crt0 "$@" cargo fmt --package relibc --package crt0 --package redox-rt "$@"
[package]
name = "generic-rt"
version = "0.1.0"
edition = "2021"
[dependencies]
#![no_std]
#![feature(core_intrinsics)]
use core::{
arch::asm,
mem::{self, offset_of},
};
#[derive(Debug)]
#[repr(C)]
pub struct GenericTcb<Os> {
/// Pointer to the end of static TLS. Must be the first member
pub tls_end: *mut u8,
/// Size of the memory allocated for the static TLS in bytes (multiple of page size)
pub tls_len: usize,
/// Pointer to this structure
pub tcb_ptr: *mut Self,
/// Size of the memory allocated for this structure in bytes (should be same as page size)
pub tcb_len: usize,
pub os_specific: Os,
}
impl<Os> GenericTcb<Os> {
/// Architecture specific code to read a usize from the TCB - aarch64
#[inline(always)]
#[cfg(target_arch = "aarch64")]
pub unsafe fn arch_read(offset: usize) -> usize {
let abi_ptr: usize;
asm!(
"mrs {}, tpidr_el0",
out(reg) abi_ptr,
);
let tcb_ptr = *(abi_ptr as *const usize);
*((tcb_ptr + offset) as *const usize)
}
/// Architecture specific code to read a usize from the TCB - x86
#[inline(always)]
#[cfg(target_arch = "x86")]
pub unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"
mov {}, gs:[{}]
",
out(reg) value,
in(reg) offset,
);
value
}
/// Architecture specific code to read a usize from the TCB - x86_64
#[inline(always)]
#[cfg(target_arch = "x86_64")]
pub unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"
mov {}, fs:[{}]
",
out(reg) value,
in(reg) offset,
);
value
}
/// Architecture specific code to read a usize from the TCB - riscv64
#[inline(always)]
#[cfg(target_arch = "riscv64")]
unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"ld {value}, -8(tp)", // TCB
"add {value}, {value}, {offset}",
"ld {value}, 0({value})",
value = out(reg) value,
offset = in(reg) offset,
);
value
}
pub unsafe fn current_ptr() -> Option<*mut Self> {
let tcb_ptr = Self::arch_read(offset_of!(Self, tcb_ptr)) as *mut Self;
let tcb_len = Self::arch_read(offset_of!(Self, tcb_len));
if tcb_ptr.is_null() || tcb_len < mem::size_of::<Self>() {
None
} else {
Some(tcb_ptr)
}
}
pub unsafe fn current() -> Option<&'static mut Self> {
Some(&mut *Self::current_ptr()?)
}
}
pub fn panic_notls(msg: impl core::fmt::Display) -> ! {
//eprintln!("panicked in ld.so: {}", msg);
core::intrinsics::abort();
}
pub trait ExpectTlsFree {
type Unwrapped;
fn expect_notls(self, msg: &str) -> Self::Unwrapped;
}
impl<T, E: core::fmt::Debug> ExpectTlsFree for Result<T, E> {
type Unwrapped = T;
fn expect_notls(self, msg: &str) -> T {
match self {
Ok(t) => t,
Err(err) => panic_notls(format_args!(
"{}: expect failed for Result with err: {:?}",
msg, err
)),
}
}
}
impl<T> ExpectTlsFree for Option<T> {
type Unwrapped = T;
fn expect_notls(self, msg: &str) -> T {
match self {
Some(t) => t,
None => panic_notls(format_args!("{}: expect failed for Option", msg)),
}
}
}
#ifndef _BITS_ASSERT_H // Do not use include guard, to ensure assert is always defined
#define _BITS_ASSERT_H #ifdef assert
#undef assert
#endif
#ifdef NDEBUG #ifdef NDEBUG
# define assert(cond) (void) 0 # define assert(cond) (void) 0
...@@ -7,5 +9,3 @@ ...@@ -7,5 +9,3 @@
# define assert(cond) \ # define assert(cond) \
((void)((cond) || (__assert_fail(__func__, __FILE__, __LINE__, #cond), 0))) ((void)((cond) || (__assert_fail(__func__, __FILE__, __LINE__, #cond), 0)))
#endif #endif
#endif
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
extern "C" { extern "C" {
#endif #endif
#define ENOTSUP EOPNOTSUPP
#define errno (*__errno_location()) #define errno (*__errno_location())
#define program_invocation_name (*__program_invocation_name()) #define program_invocation_name (*__program_invocation_name())
#define program_invocation_short_name (*__program_invocation_short_name()) #define program_invocation_short_name (*__program_invocation_short_name())
......
#ifndef _BITS_FCNTL_H #ifndef _BITS_FCNTL_H
#define _BITS_FCNTL_H #define _BITS_FCNTL_H
#ifdef __cplusplus
extern "C" {
#endif
int open(const char* filename, int flags, ...);
int fcntl(int fildes, int cmd, ...);
#ifdef __cplusplus
} // extern "C"
#endif
#endif #endif
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define UINT_MAX 0xffffffff #define UINT_MAX 0xffffffff
#define ULLONG_MAX 0xffffffffffffffff #define ULLONG_MAX 0xffffffffffffffff
#define ULONG_MAX 0xffffffffffffffff #define ULONG_MAX 0xffffffffffffffff
#define USHRT_MAX 0xffffffffffffffff #define USHRT_MAX 0xffff
#define WORD_BIT 32 #define WORD_BIT 32
#endif #endif
#ifndef _MALLOC_H #ifndef _BITS_MALLOC_H
#define _MALLOC_H #define _BITS_MALLOC_H
#include <stddef.h> #include <stddef.h>
......