Skip to content

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

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

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

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

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>
Copilot AI changed the title [WIP] Remove PGO infrastructure from WebAssembly and iOS/MacCatalyst Disable FEATURE_PGO on WebAssembly and iOS/MacCatalyst Apr 3, 2026
Copilot AI requested a review from davidwrighton April 3, 2026 00:25
Copilot AI requested a review from jkotas April 3, 2026 00:49
@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>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 8, 2026 01:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 8, 2026 01:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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

github-actions bot commented Apr 8, 2026

Note

This comment was generated by Copilot reviewing PR #126493.

Code Review: Making FEATURE_PGO Conditional

Checked areas

# Check Verdict
1 All g_pConfig PGO accessor call-sites guarded
2 No PGO-only symbols reachable when FEATURE_PGO undefined ⚠️
3 pgo.cpp stubs match pgo.h declarations ⚠️
4 Architectural consistency under FEATURE_DYNAMIC_CODE_COMPILED
5 NULL 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;
return E_NOTIMPL;
// ← *ppSchema and *pPgoSource never set

Compare with the real implementation (pgo.cpp:831-835) which initializes both, and the sibling stub getPgoInstrumentationResultsFromR2RFormat (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

static HRESULT getPgoInstrumentationResults(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

Method Signature match Out-params initialized
getPgoInstrumentationResultsFromR2RFormat ✅ matches pgo.h:28-36 ✅ all 4
allocPgoInstrumentationBySchema ✅ matches pgo.h:27
CreatePgoManager volatile qualifier matches pgo.h:38
VerifyAddress ✅ matches pgo.h:41 N/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

jkotas commented Apr 9, 2026

/ba-g intermittent networking failures

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Apr 9, 2026

@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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 9, 2026

@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

Copilot AI requested a review from jkotas April 9, 2026 02:33
@jkotas jkotas merged commit a4b3fc5 into main Apr 9, 2026
108 of 112 checks passed
@jkotas jkotas deleted the copilot/remove-pgo-infrastructure branch April 9, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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