Strip conflicting symbols from compiler builtins

This commit is contained in:
Wildan M
2025-10-05 23:42:35 +07:00
parent 48a6dcf39e
commit 9351537ca0
2 changed files with 22 additions and 5 deletions
+6 -5
View File
@@ -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)
Executable
+16
View File
@@ -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