Only pass -u__llvm_profile_runtime when linking for Linux #2221
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 472 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.368
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2221"
general
weight: 0.35
cachemeifyoucan
Problem
When linking with profiling instrumentation (
-profile-generate,-ir-profile-generate,-cs-profile-generate, ...),GenericUnixToolchainalways adds-u__llvm_profile_runtimeto the clang linker-driver invocation, no matter which OS is being targeted:https://github.com/swiftlang/swift-driver/blob/2b30a750/Sources/SwiftDriver/Jobs/GenericUnixToolchain%2BLinkerSupport.swift#L308-L317
On FreeBSD, clang then warns on every instrumented link:
This is currently breaking swift-build's FreeBSD CI, where
ObjectLibraryBuildOperationTests.dynamicLibraryConsumingObjectLibraryWithCodeCoverage()builds withCLANG_COVERAGE_MAPPING=YESand asserts there are no diagnostics:(https://github.com/swiftlang/swift-build/actions/runs/37103365827/job/111889818672?pr=1828)
Why the flag is only needed on Linux
The flag copies what clang's Linux toolchain does. It is only needed there because of how LLVM lowers instrumentation:
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp,InstrLowerer::emitRuntimeHook():On every other target, each instrumented module gets its own reference to
__llvm_profile_runtime, so the linker pulls in the runtime without-u.clang/lib/Driver/ToolChains/Linux.cpp(Linux::addProfileRTLibs) is where clang adds-u__llvm_profile_runtimefor Linux. The FreeBSD, OpenBSD, NetBSD, Haiku, etc. toolchains don't add it.-uto the linker (Gnu.cpp:Args.addAllArgs(CmdArgs, {options::OPT_s, options::OPT_t, options::OPT_u})). The FreeBSD link step forwards only{OPT_T_Group, OPT_s, OPT_t}(FreeBSD.cpp), so-uis never used there and clang reports it as unused. OpenBSD, NetBSD and Haiku don't forwardOPT_ueither.So on non-Linux generic Unix targets, the flag does nothing except produce the warning.
Fix
Only add
-u__llvm_profile_runtimewhentargetTriple.os == .linux. Android triples (*-linux-android) count as Linux, so they keep the flag. This now matches clang's behavior. The profile runtime archive is still linked on every target.Testing
profileGenerateLinksRuntimeOnFreeBSDtest toMiscDriverTests(x86_64-unknown-freebsd14.3), covering-profile-generateand the-ir-/-cs-profile-generate[=]variants. It checks that the profile runtime archive is still linked and that-u__llvm_profile_runtimeis not passed.-u__llvm_profile_runtime, are unchanged.-driver-print-jobs -profile-generate:-
x86_64-unknown-freebsd14.3: linksclang/lib/freebsd/libclang_rt.profile-x86_64.a, no-u-
x86_64-unknown-linux-gnu: linksclang/lib/linux/libclang_rt.profile-x86_64.a, adds-u__llvm_profile_runtime-
aarch64-unknown-linux-android: linksclang/lib/linux/libclang_rt.profile-aarch64-android.a, adds-u__llvm_profile_runtimeThis test is skipped on Darwin hosts (no
swift-autolink-extract), so CI on Linux and Windows will be the first to actually run it.