Fix PGO instrumentation for libcoreclr.so static libraries#128412
Fix PGO instrumentation for libcoreclr.so static libraries#128412EgorBo wants to merge 2 commits into
Conversation
On non-Windows, add_pgo(coreclr) used target_compile_options(PRIVATE) which only applied -fprofile-instr-generate to coreclr's directly compiled sources (mscoree.cpp, exports.cpp). The vast majority of the runtime code lives in static libraries (cee_wks, utilcode, coreclrpal, etc.) that were linked in without instrumentation. Fix by adding directory-scoped PGO compile flags in pgosupport.cmake so all C/C++ sources in the coreclr tree get instrumentation/optimization flags. The existing add_pgo() function is unchanged - it still sets per-target LTO link flags for the final shared libraries. Fixes #124141 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR updates CoreCLR’s native build configuration so Profile Guided Optimization (PGO) compile flags apply broadly across the src/coreclr C/C++ compilation units on non-Windows builds, rather than only affecting the few sources compiled directly into a shared library target.
Changes:
- Adds directory-scoped
-fprofile-instr-generate/-fprofile-instr-usecompile options for non-Windows PGO builds (C/C++ only). - Adds a directory-scoped link option for instrumentation builds to ensure profiling runtime symbols resolve when instrumented static libraries are linked into shared libraries.
- Looks for a global
coreclr.profdatato enable PGO optimization flags across the CoreCLR tree when present.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Code Review: Fix PGO instrumentation for libcoreclr.so static librariesSummaryThis PR adds directory-scoped PGO compile flags ( Verdict: ✅ Approve (no blocking issues)The fix is correct, well-scoped, well-commented, and directly addresses the root cause described in #124141. The approach is sound: directory-scope compile flags propagate into static library sub-targets, while Detailed Findings
|
|
@hoyosjs @AndyAyersMS opinions? seems to be producing instrumented bits NOTE: this only fixes libcoreclr, the System.* shared libs need additional changes, but I'd like to validate that this one works as expected first. |
|
Seems like a great idea. I wonder how hard it will be to observe the impact? |
I checked that it does produce a fully instrumented shared lib, so the next step would be to wait for an instrumented SDK to be produced & consumed by dotnet-optimization after this PR is merged. From my quick look there should be no actions needed in dotnet-optimization and it will eventually produce a profdata that includes coreclr (we will test it by inspecting pgo data coming with nuget after the roundtrip and the final optimized binary). |
Note
This PR was created with the assistance of GitHub Copilot.
Fixes #124141
On non-Windows,
add_pgo(coreclr)usedtarget_compile_options(PRIVATE)which only applied-fprofile-instr-generate/-fprofile-instr-useto the 2 source files directly compiled by thecoreclrtarget (mscoree.cpp,exports.cpp). The runtime's real code lives in static libraries (cee_wks,utilcode,coreclrpal, etc.) that were linked in without instrumentation. This doesn't affectclrjit(all JIT sources compile directly into the shared library) or Windows (PGO uses link-time/LTCGflags).Fix: add directory-scoped PGO compile flags in
pgosupport.cmakeso all C/C++ sources in the coreclr tree get the flags. The existingadd_pgo()is unchanged — it still sets per-target LTO link flags. Assembly files are excluded via$<$<COMPILE_LANGUAGE:C,CXX>:...>.Before (instrumented
libcoreclr.so)__llvm_prf_names__llvm_prf_cnts__llvm_prf_dataAfter (instrumented
libcoreclr.so)__llvm_prf_names__llvm_prf_cnts__llvm_prf_dataNo changes needed in
dotnet-optimization— the training pipeline already collects all*.profrawfiles and merges them intocoreclr.profdata.