From 9351537ca00e363fd096f75514fdb8a201f49185 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sun, 5 Oct 2025 23:42:35 +0700 Subject: [PATCH 1/3] Strip conflicting symbols from compiler builtins --- Makefile | 11 ++++++----- stripcore.sh | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100755 stripcore.sh diff --git a/Makefile b/Makefile index 134fb8dfdf..a3e37238c8 100644 --- a/Makefile +++ b/Makefile @@ -175,21 +175,20 @@ test: sysroot $(MAKE) -C tests verify -$(BUILD)/$(PROFILE)/libc.so: $(BUILD)/$(PROFILE)/librelibc.a $(BUILD)/openlibm/libopenlibm.a +$(BUILD)/$(PROFILE)/libc.so: $(BUILD)/openlibm/libopenlibm.a $(BUILD)/$(PROFILE)/librelibc.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,--whole-archive $(BUILD)/openlibm/libopenlibm.a $(BUILD)/$(PROFILE)/librelibc.a \ + -Wl,--no-whole-archive \ -Wl,-soname,libc.so.6 \ -lgcc \ -o $@ # Debug targets -$(BUILD)/debug/libc.a: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm.a +$(BUILD)/debug/libc.a: $(BUILD)/openlibm/libopenlibm.a $(BUILD)/debug/librelibc.a echo "create $@" > "$@.mri" for lib in $^; do\ echo "addlib $$lib" >> "$@.mri"; \ @@ -201,6 +200,7 @@ $(BUILD)/debug/libc.a: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm. $(BUILD)/debug/librelibc.a: $(SRC) $(CARGO) rustc $(CARGOFLAGS) -- --emit link=$@ -g -C debug-assertions=no $(RUSTCFLAGS) ./renamesyms.sh "$@" "$(BUILD)/debug/deps/" + ./stripcore.sh "$@" touch $@ $(BUILD)/debug/crt0.o: $(SRC) @@ -238,6 +238,7 @@ $(BUILD)/release/librelibc.a: $(SRC) # TODO: Better to only allow a certain whitelisted set of symbols? Perhaps # use some cbindgen hook, specify them manually, or grep for #[unsafe(no_mangle)]. ./renamesyms.sh "$@" "$(BUILD)/release/deps/" + ./stripcore.sh "$@" touch $@ $(BUILD)/release/crt0.o: $(SRC) diff --git a/stripcore.sh b/stripcore.sh new file mode 100755 index 0000000000..4e16184e90 --- /dev/null +++ b/stripcore.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# This script exists as a workaround for https://github.com/rust-lang/rust/issues/142119 + +set -e + +target=$1 + +if [ -z "$target" ]; then + echo "Usage:\n\t./stripcore.sh TARGET" + exit 1 +fi + +for sym in cbrt ceil copysign fabs fdim floor fmax fmaximum fmin fminimum fmod rint round roundeven sqrt trunc; do \ + objcopy --globalize-symbol=$sym --strip-symbol=$sym "$target"; \ +done From 359361591880fa4dd6eca189d7e16f9fe54817eb Mon Sep 17 00:00:00 2001 From: Wildan Mubarok Date: Sun, 5 Oct 2025 16:48:28 +0000 Subject: [PATCH 2/3] Revert changes --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a3e37238c8..747dc29fb3 100644 --- a/Makefile +++ b/Makefile @@ -175,20 +175,21 @@ test: sysroot $(MAKE) -C tests verify -$(BUILD)/$(PROFILE)/libc.so: $(BUILD)/openlibm/libopenlibm.a $(BUILD)/$(PROFILE)/librelibc.a +$(BUILD)/$(PROFILE)/libc.so: $(BUILD)/$(PROFILE)/librelibc.a $(BUILD)/openlibm/libopenlibm.a $(CC) -nostdlib \ -shared \ -Wl,--gc-sections \ -Wl,-z,pack-relative-relocs \ - -Wl,--whole-archive $(BUILD)/openlibm/libopenlibm.a $(BUILD)/$(PROFILE)/librelibc.a \ - -Wl,--no-whole-archive \ + -Wl,--sort-common \ + -Wl,--allow-multiple-definition \ + -Wl,--whole-archive $^ -Wl,--no-whole-archive \ -Wl,-soname,libc.so.6 \ -lgcc \ -o $@ # Debug targets -$(BUILD)/debug/libc.a: $(BUILD)/openlibm/libopenlibm.a $(BUILD)/debug/librelibc.a +$(BUILD)/debug/libc.a: $(BUILD)/debug/librelibc.a $(BUILD)/openlibm/libopenlibm.a echo "create $@" > "$@.mri" for lib in $^; do\ echo "addlib $$lib" >> "$@.mri"; \ From 9c43abbcf9b22ab156924749d574327c90942f03 Mon Sep 17 00:00:00 2001 From: Wildan Mubarok Date: Sun, 5 Oct 2025 17:05:25 +0000 Subject: [PATCH 3/3] Add f functions --- stripcore.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stripcore.sh b/stripcore.sh index 4e16184e90..3808722529 100755 --- a/stripcore.sh +++ b/stripcore.sh @@ -11,6 +11,7 @@ if [ -z "$target" ]; then exit 1 fi -for sym in cbrt ceil copysign fabs fdim floor fmax fmaximum fmin fminimum fmod rint round roundeven sqrt trunc; do \ +for sym in cbrtf ceilf copysignf fabsf fdimf floorf fmaxf fminf fmofd rintf roundf sqrtf truncf \ + cbrt ceil copysign fabs fdim floor fmax fmin fmod rint round sqrt trunc; do \ objcopy --globalize-symbol=$sym --strip-symbol=$sym "$target"; \ done