Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst - #126493

Merged
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure
Apr 9, 2026
Merged

Disable FEATURE_PGO on WebAssembly, iOS, TVOS, and MacCatalyst#126493
jkotas merged 21 commits into
mainfrom
copilot/remove-pgo-infrastructure

Conversation

CopilotAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

FEATURE_PGO (PGO infrastructure) is not meaningful on WebAssembly, iOS, TVOS, or MacCatalyst targets and should be excluded from those builds. FEATURE_PGO is now gated under the FEATURE_DYNAMIC_CODE_COMPILED block in clrfeatures.cmake, following the same pattern as FEATURE_REJIT.

Changes

  • src/coreclr/clrfeatures.cmake: Move FEATURE_PGO inside the FEATURE_DYNAMIC_CODE_COMPILED block next to set(FEATURE_REJIT 1). WASM, iOS, TVOS, and MacCatalyst are all implicitly excluded since FEATURE_DYNAMIC_CODE_COMPILED is not set for those targets.
  • src/coreclr/clrdefinitions.cmake: Gate add_compile_definitions(FEATURE_PGO) on the FEATURE_PGO variable (was unconditional).
  • src/coreclr/vm/pgo.cpp: Fix stale !FEATURE_PGO stub implementations to match current declarations in pgo.h:
    • getPgoInstrumentationResults: updated signature to use BYTE** and added the missing ICorJitInfo::PgoSource* parameter; added missing *ppSchema = NULL out-parameter initialization.
    • CreatePgoManager: updated parameter to PgoManager* volatile*.
    • Added missing stub for getPgoInstrumentationResultsFromR2RFormat, which is referenced from readytoruninfo.cpp (always compiled) but had no implementation in non-PGO builds.
  • src/coreclr/vm/pgo.h: Fixed pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in the getPgoInstrumentationResults declaration.
  • src/coreclr/vm/jitinterface.cpp: Guard g_pConfig->TieredPGO() call in getPgoInstrumentationResults with #ifdef FEATURE_PGO; returns false for non-PGO builds. Added *pSchema = NULL initialization for out-parameter consistency.
  • src/coreclr/vm/tieredcompilation.cpp: Guard TieredPGO() && TieredPGO_InstrumentOnlyHotCode() block in the OptimizationTier0 path with #ifdef FEATURE_PGO.
  • src/coreclr/inc/jithelpers.h: Gate all 10 PGO profiling JIT helper table entries (CLASSPROFILE32/64, DELEGATEPROFILE32/64, VTABLEPROFILE32/64, COUNTPROFILE32/64, VALUEPROFILE32/64) under #ifdef FEATURE_PGO / #else NULL #endif, following the pattern used by FEATURE_RESOLVE_HELPER_DISPATCH.
  • src/coreclr/vm/jithelpers.cpp: Wrap the actual PGO profiling JIT helper implementations (JIT_ValueProfile32/64, JIT_ClassProfile32/64, JIT_DelegateProfile32/64, JIT_VTableProfile32/64, JIT_CountProfile32/64) in #ifdef FEATURE_PGO. No stub implementations are needed for !FEATURE_PGO builds since the JIT helper table entries are now NULL.

Changes to public API

No public API changes.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9be1dcea-b234-4f56-ad13-b3f3578acce2
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalystDisable FEATURE_PGO on WebAssembly and iOS/MacCatalystApr 3, 2026
CopilotAI requested a review from davidwrightonApril 3, 2026 00:25
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
CopilotAI requested a review from jkotasApril 3, 2026 00:49
Comment threadsrc/coreclr/clrfeatures.cmake Outdated
Comment threadsrc/coreclr/clrdefinitions.cmake
Comment threadsrc/coreclr/clrdefinitions.cmake
@github-actions

This comment has been minimized.

@davidwrighton

Copy link
Copy Markdown
Member

@copilot the build fails with errors like

270/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/precode_portable.cpp.o
[271/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/pgo.cpp.o
FAILED: [code=1] vm/CMakeFiles/cee_dac.dir/pgo.cpp.o /usr/bin/clang++ -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDACCESS_COMPILE -DDEBUGGING_SUPPORTED -DDISABLE_CONTRACTS -DFEATURE_BASICFREEZE -DFEATURE_CACHED_INTERFACE_DISPATCH -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DBGIPC_TRANSPORT_DI -DFEATURE_DBGIPC_TRANSPORT_VM -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EMULATE_SINGLESTEP -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_INTERPRETER -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MAP_THUNKS_FROM_IMAGE -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_MULTITHREADING -DFEATURE_OBJCMARSHAL -DFEATURE_PAL_ANSI -DFEATURE_PERFMAP -DFEATURE_PERFTRACING -DFEATURE_READYTORUN -DFEATURE_REMAP_FUNCTION -DFEATURE_REMOTE_PROC_MEM -DFEATURE_STATICALLY_LINKED -DFEATURE_STUBPRECODE_DYNAMIC_HELPERS -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_APPLE -DHOST_ARM64 -DHOST_MACCATALYST -DHOST_UNIX -DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT -DNDEBUG -DOSX_ARM64_ABI -DPROFILING_SUPPORTED_DATA -DTARGET_64BIT -DTARGET_APPLE -DTARGET_ARM64 -DTARGET_MACCATALYST -DTARGET_UNIX -DUNICODE -DURTBLDENV_FRIENDLY=Retail -D_DARWIN_C_SOURCE -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_XOPEN_SOURCE -D__DARWIN_NON_CANCELABLE=1 -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm -I/Users/runner/work/1/s/src/coreclr/vm -I/Users/runner/work/1/s/src/native -I/Users/runner/work/1/s/src/native/inc -I/Users/runner/work/1/s/src/coreclr/pal/prebuilt/inc -I/Users/runner/work/1/s/artifacts/obj -I/Users/runner/work/1/s/src/coreclr/pal/inc -I/Users/runner/work/1/s/src/coreclr/pal/inc/rt -I/Users/runner/work/1/s/src/coreclr/pal/src/safecrt -I/Users/runner/work/1/s/src/coreclr/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc -I/Users/runner/work/1/s/src/coreclr/debug/inc/arm64 -I/Users/runner/work/1/s/src/coreclr/debug/inc/dump -I/Users/runner/work/1/s/src/coreclr/md/inc -I/Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/inc -I/Users/runner/work/1/s/src/coreclr/hosts/inc -I/Users/runner/work/1/s/src/coreclr/interpreter/inc -I/Users/runner/work/1/s/src/coreclr/minipal -I/Users/runner/work/1/s/src/coreclr/nativeresources -I/Users/runner/work/1/s/src/coreclr/vm/arm64 -I/Users/runner/work/1/s/src/coreclr/vm/../interop/inc -I/Users/runner/work/1/s/src/coreclr/runtime -I/Users/runner/work/1/s/src/native/libs/System.IO.Compression.Native -I/Users/runner/work/1/s/src/native/libs/Common -I/Users/runner/work/1/s/src/coreclr/vm/eventing/eventpipe -target arm64-apple-ios17.0-macabi -Wno-overriding-option -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIC -O3 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fno-strict-overflow -fno-strict-aliasing -fstack-protector -mcpu=apple-m1 -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections -Wno-null-arithmetic -Winvalid-pch -Xclang -include-pch -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/runner/work/1/s/artifacts/obj/coreclr/maccatalyst.arm64.Release/vm/CMakeFiles/cee_dac.dir/cmake_pch.hxx -MD -MT vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -MF vm/CMakeFiles/cee_dac.dir/pgo.cpp.o.d -o vm/CMakeFiles/cee_dac.dir/pgo.cpp.o -c /Users/runner/work/1/s/src/coreclr/vm/pgo.cpp
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1233:21: error: out-of-line definition of 'getPgoInstrumentationResults' does not match any declaration in 'PgoManager'
1233 | HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder<BYTE> *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.cpp:1247:18: error: out-of-line definition of 'CreatePgoManager' does not match any declaration in 'PgoManager'
1247 | void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator)
| ^~~~~~~~~~~~~~~~
/Users/runner/work/1/s/src/coreclr/vm/pgo.h:38:34: note: type of 1st parameter of member declaration does not match definition ('PgoManager *volatile *' vs 'PgoManager **')
38 | static void CreatePgoManager(PgoManager* volatile* ppPgoManager, bool loaderAllocator);
| ^
2 errors generated.
[272/2319] Building CXX object vm/CMakeFiles/cee_dac.dir/prestub.cpp.o

Please fix.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/10208c32-9727-496d-ae23-933873d32c46
Co-authored-by: davidwrighton <10779849+davidwrighton@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:50
Comment threadsrc/coreclr/clrdefinitions.cmake Outdated

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 8, 2026 01:55

CopilotAI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/pgo.cpp:1257

  • In the !FEATURE_PGO stub for PgoManager::getPgoInstrumentationResults, not all out parameters are initialized: ppSchema and pPgoSource are left untouched. Callers may inspect these even on failure (e.g., to distinguish "no data" vs "mismatch"), so leaving them uninitialized risks undefined behavior. Initialize *ppSchema to NULL and *pPgoSource to ICorJitInfo::PgoSource::Unknown (similar to the FEATURE_PGO implementation).
HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource)
{
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
return E_NOTIMPL;

@github-actions

Copy link
Copy Markdown
Contributor

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

#CheckVerdict
1All g_pConfig PGO accessor call-sites guarded
2No PGO-only symbols reachable when FEATURE_PGO undefined⚠️
3pgo.cpp stubs match pgo.h declarations⚠️
4Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5NULL JIT helper table entries safe

✅ (1) All g_pConfig PGO accessors are properly guarded

Every call to TieredPGO(), TieredPGO_InstrumentOnlyHotCode(), and TieredPGO_ScalableCountThreshold() is either:

  • Inside a #ifdef FEATURE_PGO block (tieredcompilation.cpp:267-301, tieredcompilation.cpp:1052-1061, jitinterface.cpp:10857-10868, jitinterface.cpp:12724-12728, eeconfig.cpp:790+, eventtrace.cpp:5489+), or
  • Inside function bodies that are themselves compiled only when FEATURE_PGO is defined (pgo.cpp:357, jithelpers.cpp:2138/2164 — wrapped by the new #ifdef FEATURE_PGO at jithelpers.cpp:1779/2184).

No unguarded accessor call exists.


⚠️ (2) getPgoInstrumentationResults stub: missing output-parameter initializations

File:src/coreclr/vm/pgo.cpp:1252-1258

The !FEATURE_PGO stub for getPgoInstrumentationResults does not initialize *ppSchema or *pPgoSource:

// stub (lines 1253-1257)
*pAllocatedData = NULL;
*pCountSchemaItems = 0;
*pInstrumentationData = NULL;
returnE_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stubgetPgoInstrumentationResultsFromR2RFormat (pgo.cpp:1243-1246) which does set *ppSchema = NULL.

Practical impact is low because the only call site (jitinterface.cpp:12732-12767) has its own #ifdef FEATURE_PGO guard that skips calling the stub entirely, and the caller pre-initializes *pSchema = NULL and *pPgoSource = Unknown at lines 12720-12723. However, the stub is part of the public PgoManager API; any future direct caller would get uninitialized out-params.

Recommendation: Add *ppSchema = NULL; and *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the stub for consistency and defensive correctness.


⚠️ (3) Pre-existing pgo.h declaration typo (not introduced by this PR)

File:src/coreclr/vm/pgo.h:26

staticHRESULTgetPgoInstrumentationResults(MethodDesc* pMD,
BYTE **pAllocatedDatapAllocatedData, ...);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doubled parameter name

This is pre-existing and cosmetic (parameter names in declarations don't affect compilation), but since this PR touched the corresponding stub signatures, it would be a good opportunity to fix it. This is not a blocker.


✅ (3 cont.) Other stub signatures match declarations correctly

MethodSignature matchOut-params initialized
getPgoInstrumentationResultsFromR2RFormat✅ matches pgo.h:28-36✅ all 4
allocPgoInstrumentationBySchema✅ matches pgo.h:27
CreatePgoManagervolatile qualifier matches pgo.h:38
VerifyAddress✅ matches pgo.h:41N/A

✅ (4) FEATURE_PGO under FEATURE_DYNAMIC_CODE_COMPILED is architecturally consistent

clrfeatures.cmake now sets FEATURE_PGO alongside FEATURE_TIERED_COMPILATION and FEATURE_REJIT inside the FEATURE_DYNAMIC_CODE_COMPILED block. This is sound because:

  • PGO requires JIT recompilation (tiered compilation) → requires dynamic code
  • Platforms that disable dynamic code (iOS, tvOS, WASM) cannot use PGO anyway
  • NativeAOT has zero FEATURE_PGO references (uses its own AOT PGO pipeline)
  • The JIT itself has zero #ifdef FEATURE_PGO checks — it receives PGO data through the JIT-EE interface, so it's naturally decoupled

✅ (5) NULL JIT helper table entries are safe

When FEATURE_PGO is off, all 10 PGO helpers (CORINFO_HELP_CLASSPROFILE32 through CORINFO_HELP_VALUEPROFILE64) are set to NULL in jithelpers.h:344-353. This is safe because:

  1. JIT-side guard: The JIT only emits calls to these helpers when JIT_FLAG_BBINSTR is set (src/coreclr/jit/importercalls.cpp:9448).
  2. VM-side guard:CORJIT_FLAG_BBINSTR is only set for OptimizationTier0Instrumented / OptimizationTier1Instrumented tiers, and the BBINSTR_IF_LOOPS path is wrapped in #ifdef FEATURE_PGO (tieredcompilation.cpp:1052-1061).
  3. Precedent: The same NULL pattern is used for other conditional helpers (e.g., CORINFO_HELP_STACK_PROBE).

No code path can reach a NULL helper dereference when FEATURE_PGO is off.


💡 Additional observation: *pSchema = NULL initialization in jitinterface.cpp

The PR adds *pSchema = NULL; at jitinterface.cpp:12720, which was missing in the baseline (7fa0e1ed). This is a good defensive fix — previously *pSchema could be left uninitialized on the !FEATURE_PGO path. Nice catch.


Overall Verdict: ✅ Ship-ready with minor suggestions

The PR is correct and safe. The conditional compilation is thorough — all PGO accessor calls, helper functions, and JIT flag settings are properly guarded. The architectural placement under FEATURE_DYNAMIC_CODE_COMPILED is sound. The two warnings above are low-severity:

  1. Minor: Add *ppSchema = NULL; *pPgoSource = ICorJitInfo::PgoSource::Unknown; to the getPgoInstrumentationResults stub in pgo.cpp for defensive completeness.
  2. Cosmetic: Fix the pAllocatedDatapAllocatedData typo in pgo.h:26 (pre-existing, not a regression).

Generated by Code Review for issue #126493 ·

@jkotas

Copy link
Copy Markdown
Member

/ba-g intermittent networking failures

@jkotas

Copy link
Copy Markdown
Member

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
(3) Pre-existing pgo.h declaration typo (not introduced by this PR)

… pgo.h parameter name typo
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/51af0fd3-5ce0-4f5f-bf48-eaa6f46fac97
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

CopilotAI commented Apr 9, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Fix this feedback

(2) getPgoInstrumentationResults stub: missing output-parameter initializations
...

Fixed in 283f203:

  • (2) Added *ppSchema = NULL to the !FEATURE_PGO stub for getPgoInstrumentationResults in pgo.cpp
  • (3) Fixed the pre-existing parameter name typo pAllocatedDatapAllocatedDatapAllocatedData in pgo.h line 26

CopilotAI requested a review from jkotasApril 9, 2026 02:33
@jkotas
jkotas merged commit a4b3fc5 into mainApr 9, 2026
108 of 112 checks passed
@jkotas
jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 10, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove Pgo infrastructure. Notably, we shouldn't support FEATURE_PGO on WebAssembly.

6 participants

@davidwrighton@jkotas@steveisok@AaronRobinsonMSFT