Skip to content

Commit 41eca4c

Browse files
committed
update
1 parent b5a4697 commit 41eca4c

File tree

2 files changed

+37
-109
lines changed

2 files changed

+37
-109
lines changed

ci/run.sh

Lines changed: 16 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,20 @@ update_rlib_paths() {
5454
fi
5555
}
5656

57+
run_with_rlibs() {
58+
if [ -d /builtins-target ]; then
59+
rlib_paths=( /builtins-target/"${target}"/debug/deps/libcompiler_builtins-*.rlib )
60+
else
61+
rlib_paths=( target/"${target}"/debug/deps/libcompiler_builtins-*.rlib )
62+
fi
63+
64+
"$@" "${rlib_paths[@]}"
65+
}
66+
5767
# Remove any existing artifacts from previous tests that don't set #![compiler_builtins]
58-
update_rlib_paths
59-
rm -f "${rlib_paths[@]}"
68+
# update_rlib_paths
69+
# rm -f "${rlib_paths[@]}"
70+
run_with_rlibs rm -f
6071

6172
cargo build --target "$target"
6273
cargo build --target "$target" --release
@@ -67,64 +78,9 @@ cargo build --target "$target" --release --features no-asm
6778
cargo build --target "$target" --features no-f16-f128
6879
cargo build --target "$target" --release --features no-f16-f128
6980

70-
PREFIX=${target//unknown-/}-
71-
case "$target" in
72-
armv7-*)
73-
PREFIX=arm-linux-gnueabihf-
74-
;;
75-
thumb*)
76-
PREFIX=arm-none-eabi-
77-
;;
78-
*86*-*)
79-
PREFIX=
80-
;;
81-
esac
82-
83-
NM=$(find "$(rustc --print sysroot)" \( -name llvm-nm -o -name llvm-nm.exe \) )
84-
if [ "$NM" = "" ]; then
85-
NM="${PREFIX}nm"
86-
fi
87-
88-
# i686-pc-windows-gnu tools have a dependency on some DLLs, so run it with
89-
# rustup run to ensure that those are in PATH.
90-
TOOLCHAIN="$(rustup show active-toolchain | sed 's/ (default)//')"
91-
if [[ "$TOOLCHAIN" == *i686-pc-windows-gnu ]]; then
92-
NM="rustup run $TOOLCHAIN $NM"
93-
fi
94-
9581
# Look out for duplicated symbols when we include the compiler-rt (C) implementation
96-
update_rlib_paths
97-
98-
for rlib in "${rlib_paths[@]}"; do
99-
set +x
100-
echo "================================================================"
101-
echo "checking $rlib for duplicate symbols"
102-
echo "================================================================"
103-
set -x
104-
105-
duplicates_found=0
106-
107-
# NOTE On i586, It's normal that the get_pc_thunk symbol appears several
108-
# times so ignore it
109-
$NM -g --defined-only "$rlib" 2>&1 |
110-
sort |
111-
uniq -d |
112-
grep -v __x86.get_pc_thunk --quiet |
113-
grep 'T __' && duplicates_found=1
114-
115-
if [ "$duplicates_found" != 0 ]; then
116-
echo "error: found duplicate symbols"
117-
exit 1
118-
else
119-
echo "success; no duplicate symbols found"
120-
fi
121-
done
122-
123-
$NM -AUg "${rlib_paths[@]}"
124-
125-
cargo run -p symbol-check -- check-duplicates "${rlib_paths[@]}"
126-
127-
rm -f "${rlib_paths[@]}"
82+
run_with_rlibs cargo run -p symbol-check -- check-duplicates
83+
run_with_rlibs rm -f
12884

12985
build_intrinsics_test() {
13086
cargo build --target "$target" -v --package builtins-test-intrinsics "$@"
@@ -144,35 +100,4 @@ CARGO_PROFILE_RELEASE_LTO=true \
144100
cargo build --target "$target" --package builtins-test-intrinsics --release
145101

146102
# 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-
175-
176-
cargo run -p symbol-check -- check-core-syms "${rlib_paths[@]}"
177-
178-
true
103+
run_with_rlibs cargo run -p symbol-check -- check-core-syms

crates/symbol-check/src/main.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
use object::read::archive::{ArchiveFile, ArchiveMember};
55
use object::{Object, ObjectSymbol, Symbol, SymbolKind, SymbolScope, SymbolSection};
66
use std::collections::{BTreeMap, BTreeSet};
7-
use std::fs;
8-
use std::path::Path;
7+
use std::{fs, path::Path};
98

109
const USAGE: &str = "Usage:
1110
12-
symbol-check check-duplicates PATHS...
13-
symbol-check check-core-syms PATHS...
14-
";
11+
symbol-check check-duplicates ARCHIVE ...
12+
symbol-check check-core-syms ARCHIVE ...
13+
14+
Note that multiple archives may be specified but they are checked independently
15+
rather than as a group.";
1516

1617
fn main() {
18+
// Create a `&str` vec so we can match on it.
1719
let args = std::env::args().collect::<Vec<_>>();
1820
let args_ref = args.iter().map(String::as_str).collect::<Vec<_>>();
1921

@@ -73,8 +75,8 @@ fn verify_no_duplicates(path: impl AsRef<Path>) {
7375
let mut dups = Vec::new();
7476

7577
for_each_symbol(path, |sym, member| {
78+
// Only check defined globals
7679
if !sym.is_global() || sym.is_undefined() {
77-
// Only check defined globals
7880
return;
7981
}
8082

@@ -91,18 +93,20 @@ fn verify_no_duplicates(path: impl AsRef<Path>) {
9193
});
9294

9395
if cfg!(windows) {
96+
// Ignore literal constants
9497
let allowed_dup_pfx = ["__real@", "__xmm@"];
9598
dups.retain(|sym| !allowed_dup_pfx.iter().any(|pfx| sym.name.starts_with(pfx)));
9699
}
97100

98101
if !dups.is_empty() {
99102
dups.sort_unstable_by(|a, b| a.name.cmp(&b.name));
100-
panic!("Found duplicate symbols: {dups:#?}");
103+
panic!("found duplicate symbols: {dups:#?}");
101104
}
102105

103106
println!("success: no duplicate symbols found");
104107
}
105108

109+
/// Ensure that there are no references to symbols from `core` that aren't also (somehow) defined.
106110
fn verify_core_symbols(path: impl AsRef<Path>) {
107111
println!(
108112
"Checking for references to core at {}",
@@ -113,6 +117,7 @@ fn verify_core_symbols(path: impl AsRef<Path>) {
113117
let mut undefined = Vec::new();
114118

115119
for_each_symbol(path, |sym, member| {
120+
// Find only symbols from `core`
116121
if !sym.name().unwrap().contains("_ZN4core") {
117122
return;
118123
}
@@ -125,27 +130,25 @@ fn verify_core_symbols(path: impl AsRef<Path>) {
125130
}
126131
});
127132

133+
// Discard any symbols that are defined somewhere in the archive
128134
undefined.retain(|sym| !defined.contains(&sym.name));
129135

130136
if !undefined.is_empty() {
131137
undefined.sort_unstable_by(|a, b| a.name.cmp(&b.name));
132-
panic!("Found undefined symbols from `core`: {undefined:#?}");
138+
panic!("found undefined symbols from core: {undefined:#?}");
133139
}
134140

135141
println!("success: no undefined references to core found");
136142
}
137143

138144
/// For a given archive path, do something with each symbol.
139145
fn for_each_symbol(path: impl AsRef<Path>, mut f: impl FnMut(Symbol, &ArchiveMember)) {
140-
let archive_data = fs::read(path).expect("reading file failed");
141-
let x = ArchiveFile::parse(archive_data.as_slice()).expect("archive parse failed");
142-
for member in x.members() {
143-
let member = member.unwrap();
144-
let data = member.data(&*archive_data).unwrap();
145-
let obj = object::File::parse(data).expect("object parse failed");
146-
147-
for sym in obj.symbols() {
148-
f(sym, &member);
149-
}
146+
let data = fs::read(path).expect("reading file failed");
147+
let archive = ArchiveFile::parse(data.as_slice()).expect("archive parse failed");
148+
for member in archive.members() {
149+
let member = member.expect("failed to access member");
150+
let obj_data = member.data(&*data).expect("failed to access object");
151+
let obj = object::File::parse(obj_data).expect("failed to parse object");
152+
obj.symbols().for_each(|sym| f(sym, &member));
150153
}
151154
}

0 commit comments

Comments
 (0)