Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions scripts/pgo.bash
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ if [ "$PGO_BUILD_TOOL" = "cross" ]; then
export CROSS_CONTAINER_OPTS="${CROSS_CONTAINER_OPTS:-} -v $PGO_DATA_DIR:$PGO_DATA_DIR:rw"
fi

# Keep PGO Rust-only on macOS. The cc crate mirrors -Cprofile-generate /
# -Cprofile-use from RUSTFLAGS into the C compiler command line
# (-fprofile-generate / -fprofile-use), so vendored C code (openssl, lua)
# gets instrumented by Apple clang — whose profile-runtime format follows
# Xcode's LLVM, not rustc's. When those disagree (Xcode 16 = raw version 8,
# rustc 1.97 = 10), the instrumented binary aborts every profile write with
# LLVM Profile Error: Runtime and instrumentation version mismatch
# and training produces zero .profraw files. C-side profiles couldn't be
# consumed by a mismatched clang in phase 3b anyway. cc appends environment
# flags after rustc-inherited ones, so these -fno- overrides win.
if [ "$(uname -s)" = "Darwin" ]; then
export CFLAGS="${CFLAGS:-} -fno-profile-generate -fno-profile-use"
export CXXFLAGS="${CXXFLAGS:-} -fno-profile-generate -fno-profile-use"
Comment on lines +97 to +98

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 When CFLAGS (or CXXFLAGS) is unset, ${CFLAGS:-} expands to an empty string, so the exported value begins with a leading space (e.g., -fno-profile-generate -fno-profile-use). This is harmless for clang/gcc in practice, but the ${VAR:+$VAR } idiom avoids it cleanly.

Suggested change
export CFLAGS="${CFLAGS:-} -fno-profile-generate -fno-profile-use"
export CXXFLAGS="${CXXFLAGS:-} -fno-profile-generate -fno-profile-use"
export CFLAGS="${CFLAGS:+$CFLAGS }-fno-profile-generate -fno-profile-use"
export CXXFLAGS="${CXXFLAGS:+$CXXFLAGS }-fno-profile-generate -fno-profile-use"

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

fi

# ---------- Phase 1: instrumented build ----------
echo ">>> [1/3] Building instrumented binary ($PGO_BUILD_TOOL, profile=$PGO_PROFILE${PGO_TARGET:+, target=$PGO_TARGET})"
# shellcheck disable=SC2086 # intentional word-splitting on $target_arg
Expand Down