Skip to content

Commit c59ec4e

Browse files
committed
Replace the nm symbol check with a Rust implementation
This should be less error-prone and have better cross-platform support.
1 parent fbe400c commit c59ec4e

File tree

4 files changed

+270
-108
lines changed

4 files changed

+270
-108
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"crates/libm-macros",
77
"crates/musl-math-sys",
88
"crates/panic-handler",
9+
"crates/symbol-check",
910
"crates/util",
1011
"libm",
1112
"libm-test",

ci/run.sh

Lines changed: 17 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -47,87 +47,25 @@ else
4747
fi
4848
fi
4949

50-
51-
declare -a rlib_paths
52-
53-
# Set the `rlib_paths` global array to a list of all compiler-builtins rlibs
54-
update_rlib_paths() {
55-
if [ -d /builtins-target ]; then
56-
rlib_paths=( /builtins-target/"${target}"/debug/deps/libcompiler_builtins-*.rlib )
57-
else
58-
rlib_paths=( target/"${target}"/debug/deps/libcompiler_builtins-*.rlib )
59-
fi
60-
}
61-
62-
# Remove any existing artifacts from previous tests that don't set #![compiler_builtins]
63-
update_rlib_paths
64-
rm -f "${rlib_paths[@]}"
65-
66-
cargo build -p compiler_builtins --target "$target"
67-
cargo build -p compiler_builtins --target "$target" --release
68-
cargo build -p compiler_builtins --target "$target" --features c
69-
cargo build -p compiler_builtins --target "$target" --features c --release
70-
cargo build -p compiler_builtins --target "$target" --features no-asm
71-
cargo build -p compiler_builtins --target "$target" --features no-asm --release
72-
cargo build -p compiler_builtins --target "$target" --features no-f16-f128
73-
cargo build -p compiler_builtins --target "$target" --features no-f16-f128 --release
74-
75-
PREFIX=${target//unknown-/}-
76-
case "$target" in
77-
armv7-*)
78-
PREFIX=arm-linux-gnueabihf-
79-
;;
80-
thumb*)
81-
PREFIX=arm-none-eabi-
82-
;;
83-
*86*-*)
84-
PREFIX=
85-
;;
86-
esac
87-
88-
NM=$(find "$(rustc --print sysroot)" \( -name llvm-nm -o -name llvm-nm.exe \) )
89-
if [ "$NM" = "" ]; then
90-
NM="${PREFIX}nm"
91-
fi
92-
93-
# i686-pc-windows-gnu tools have a dependency on some DLLs, so run it with
94-
# rustup run to ensure that those are in PATH.
95-
TOOLCHAIN="$(rustup show active-toolchain | sed 's/ (default)//')"
96-
if [[ "$TOOLCHAIN" == *i686-pc-windows-gnu ]]; then
97-
NM="rustup run $TOOLCHAIN $NM"
98-
fi
99-
100-
# Look out for duplicated symbols when we include the compiler-rt (C) implementation
101-
update_rlib_paths
102-
for rlib in "${rlib_paths[@]}"; do
103-
set +x
104-
echo "================================================================"
105-
echo "checking $rlib for duplicate symbols"
106-
echo "================================================================"
107-
set -x
108-
109-
duplicates_found=0
110-
111-
# NOTE On i586, It's normal that the get_pc_thunk symbol appears several
112-
# times so ignore it
113-
$NM -g --defined-only "$rlib" 2>&1 |
114-
sort |
115-
uniq -d |
116-
grep -v __x86.get_pc_thunk --quiet |
117-
grep 'T __' && duplicates_found=1
118-
119-
if [ "$duplicates_found" != 0 ]; then
120-
echo "error: found duplicate symbols"
121-
exit 1
122-
else
123-
echo "success; no duplicate symbols found"
124-
fi
125-
done
126-
127-
rm -f "${rlib_paths[@]}"
50+
# Ensure there are no duplicate symbols or references to `core` when
51+
# `compiler-builtins` is built with various features. Symcheck invokes Cargo to
52+
# build with the arguments we provide it, then validates the built artifacts.
53+
symcheck=(cargo run -p symbol-check --release)
54+
[[ "$target" = "wasm"* ]] && symcheck+=(--features wasm)
55+
symcheck+=(-- build-and-check)
56+
57+
"${symcheck[@]}" -p compiler_builtins --target "$target"
58+
"${symcheck[@]}" -p compiler_builtins --target "$target" --release
59+
"${symcheck[@]}" -p compiler_builtins --target "$target" --features c
60+
"${symcheck[@]}" -p compiler_builtins --target "$target" --features c --release
61+
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-asm
62+
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-asm --release
63+
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-f16-f128
64+
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-f16-f128 --release
12865

12966
build_intrinsics_test() {
130-
cargo build \
67+
# symcheck also checks the results of builtins-test-intrinsics
68+
"${symcheck[@]}" \
13169
--target "$target" --verbose \
13270
--manifest-path builtins-test-intrinsics/Cargo.toml "$@"
13371
}
@@ -143,35 +81,6 @@ build_intrinsics_test --features c --release
14381
CARGO_PROFILE_DEV_LTO=true build_intrinsics_test
14482
CARGO_PROFILE_RELEASE_LTO=true build_intrinsics_test --release
14583

146-
# Ensure no references to any symbols from core
147-
update_rlib_paths
148-
for rlib in "${rlib_paths[@]}"; do
149-
set +x
150-
echo "================================================================"
151-
echo "checking $rlib for references to core"
152-
echo "================================================================"
153-
set -x
154-
155-
tmpdir="${CARGO_TARGET_DIR:-target}/tmp"
156-
test -d "$tmpdir" || mkdir "$tmpdir"
157-
defined="$tmpdir/defined_symbols.txt"
158-
undefined="$tmpdir/defined_symbols.txt"
159-
160-
$NM --quiet -U "$rlib" | grep 'T _ZN4core' | awk '{print $3}' | sort | uniq > "$defined"
161-
$NM --quiet -u "$rlib" | grep 'U _ZN4core' | awk '{print $2}' | sort | uniq > "$undefined"
162-
grep_has_results=0
163-
grep -v -F -x -f "$defined" "$undefined" && grep_has_results=1
164-
165-
if [ "$target" = "powerpc64-unknown-linux-gnu" ]; then
166-
echo "FIXME: powerpc64 fails these tests"
167-
elif [ "$grep_has_results" != 0 ]; then
168-
echo "error: found unexpected references to core"
169-
exit 1
170-
else
171-
echo "success; no references to core found"
172-
fi
173-
done
174-
17584
# Test libm
17685

17786
# Make sure a simple build works

crates/symbol-check/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "symbol-check"
3+
version = "0.1.0"
4+
edition = "2024"
5+
publish = false
6+
7+
[dependencies]
8+
# FIXME: used as a git dependency since the latest release does not support wasm
9+
object = { git = "https://github.com/gimli-rs/object.git", rev = "013fac75da56a684377af4151b8164b78c1790e0" }
10+
serde_json = "1.0.140"
11+
12+
[features]
13+
wasm = ["object/wasm"]

0 commit comments

Comments
 (0)