Skip to content

Commit 684abd0

Browse files
committed
build-pgo.sh: check that llvm-profdata matches the LLVM of rustc
The profile format changes between LLVM major versions, and an llvm-profdata from another one either fails to merge what the instrumented binary wrote, or writes a profile rustc cannot use. Either way that only showed up after the instrumented build and the training. Compare the major LLVM versions reported by `rustc -vV` and `llvm-profdata --version` as soon as llvm-profdata is found, and stop with the version to use if they differ. That matters mostly without rustup, when llvm-profdata comes from the distribution through --llvm-profdata.
1 parent 4115917 commit 684abd0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎scripts/build-pgo.sh‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ if [ ! -x "$LLVM_PROFDATA" ]; then
9696
fi
9797
echo "llvm-profdata: ${LLVM_PROFDATA}"
9898

99+
# The profile format changes between LLVM major versions: an llvm-profdata from
100+
# another one either cannot read what the instrumented binary writes, or writes
101+
# a profile rustc cannot read. Check it now rather than after the builds.
102+
RUSTC_LLVM="$(rustc -vV | sed -n 's/^LLVM version: *//p')"
103+
PROFDATA_LLVM="$("$LLVM_PROFDATA" --version | sed -n 's/.*LLVM version \([0-9][0-9.]*\).*/\1/p' | head -n 1)"
104+
if [ -z "$RUSTC_LLVM" ] || [ -z "$PROFDATA_LLVM" ]; then
105+
echo "warning: could not compare the LLVM versions of rustc (${RUSTC_LLVM:-unknown})" \
106+
"and llvm-profdata (${PROFDATA_LLVM:-unknown})" >&2
107+
elif [ "${RUSTC_LLVM%%.*}" != "${PROFDATA_LLVM%%.*}" ]; then
108+
echo "llvm-profdata is from LLVM ${PROFDATA_LLVM}, but rustc uses LLVM ${RUSTC_LLVM}" >&2
109+
echo "Pass an llvm-profdata from LLVM ${RUSTC_LLVM%%.*} with --llvm-profdata," \
110+
"or run: rustup component add llvm-tools" >&2
111+
exit 1
112+
fi
113+
echo "LLVM version: ${PROFDATA_LLVM} (rustc: ${RUSTC_LLVM})"
114+
99115
# Integration tests used for training. They start their own servers and must
100116
# run sequentially; the dist ones need Docker and are left out.
101117
TRAINING_TESTS=(system sccache_cargo sccache_rustc cache_hit_rate sccache_args)

0 commit comments

Comments
 (0)