Skip to content

Fix Thread offset for non-desktop platforms without FEATURE_CORPROFILER#126710

Closed
steveisok wants to merge 1 commit intodotnet:mainfrom
steveisok:fix/tvos-asmconstants-profiler-offset
Closed

Fix Thread offset for non-desktop platforms without FEATURE_CORPROFILER#126710
steveisok wants to merge 1 commit intodotnet:mainfrom
steveisok:fix/tvos-asmconstants-profiler-offset

Conversation

@steveisok
Copy link
Copy Markdown
Member

@steveisok steveisok commented Apr 9, 2026

Summary

PR #126550 disabled FEATURE_CORPROFILER for tvOS but left Android, MacCatalyst, and iOS commented out as placeholders. This removed profiler fields from the Thread struct (m_pProfilerFilterContext, m_profilerCallbackState, m_dwProfilerEvacuationCounters — 144 bytes total), shifting m_pInterpThreadContext to a lower offset without updating asmconstants.h.

Changes

1. src/coreclr/vm/arm64/asmconstants.h

Add PROFILING_SUPPORTED || PROFILING_SUPPORTED_DATA conditionals to select the correct m_pInterpThreadContext offset:

Configuration With Profiler Without Profiler
Release + Unix 0x2b8 (696) 0x228 (552)
Debug + Unix 0xb20 (2848) 0xa90 (2704)
Windows 0xb48 (unchanged) N/A (profiler always enabled)

The existing ASMCONSTANTS_C_ASSERT validates these values at compile time.

2. src/coreclr/clrfeatures.cmake

Uncomment the Android, MacCatalyst, and iOS exclusions so all non-desktop platforms consistently disable FEATURE_CORPROFILER. Since asmconstants.h now handles both cases, all mobile platforms can safely disable profiling without hitting the same offset mismatch.

Per review feedback: #126550 should have treated tvOS the same as the other mobile platforms (all commented out, or all active). This PR completes the intended work by enabling all four mobile platforms to disable profiling together, with the assembly constants properly updated.

Build failure

Internal unified-build on main (build 2946990) fails on 3/54 tvOS legs:

asmconstants.h:304:23: error: static assertion failed due to requirement
  '696 == __builtin_offsetof(Thread, m_pInterpThreadContext)'

Affected legs: tvOS_Shortstack_arm64, tvOSSimulator_Shortstack_x64, tvOSSimulator_Shortstack_arm64.

cc @AaronRobinsonMSFT @kotlarmilos @akoeplinger

Copilot AI review requested due to automatic review settings April 9, 2026 14:37
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@steveisok steveisok requested a review from a team April 9, 2026 14:38
@steveisok steveisok requested a review from kotlarmilos April 9, 2026 14:39
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

Updates CoreCLR ARM64 assembly constants to account for tvOS builds where profiler-related Thread fields are compiled out (when FEATURE_CORPROFILER disables PROFILING_SUPPORTED / PROFILING_SUPPORTED_DATA), ensuring OFFSETOF__Thread__m_pInterpThreadContext matches the actual struct layout and fixes the unified-build static_assert failure.

Changes:

  • Add PROFILING_SUPPORTED || PROFILING_SUPPORTED_DATA conditionals for OFFSETOF__Thread__m_pInterpThreadContext in Unix Debug/Release cases.
  • Introduce alternative offset values for non-profiling builds (e.g., 0x2b80x228, 0xb200xa90).

Comment on lines +303 to +307
#if defined(PROFILING_SUPPORTED) || defined(PROFILING_SUPPORTED_DATA)
#define OFFSETOF__Thread__m_pInterpThreadContext 0xb20
#else
#define OFFSETOF__Thread__m_pInterpThreadContext 0xa90
#endif
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

This fixes the ARM64 offsets when profiling fields are compiled out, but the same Thread layout change applies to other 64-bit targets with FEATURE_CORPROFILER disabled (notably tvOSSimulator x64). src/coreclr/vm/amd64/asmconstants.h still hardcodes OFFSETOF__Thread__m_pInterpThreadContext without a PROFILING_SUPPORTED || PROFILING_SUPPORTED_DATA guard, so its ASMCONSTANTS_C_ASSERT is likely to fail in non-profiling builds. Please apply the same conditional offset selection there (and any other affected arch asmconstants) so all tvOS legs are covered.

Copilot uses AI. Check for mistakes.
@akoeplinger
Copy link
Copy Markdown
Member

akoeplinger commented Apr 9, 2026

#126550 turned off FEATURE_CORPROFILER on iOS but not tvOS, that's why we didn't see it on iOS

@steveisok
Copy link
Copy Markdown
Member Author

#126550 turned off FEATURE_CORPROFILER on iOS but not tvOS, that's why we didn't see it on iOS

That feels like a mistake. @AaronRobinsonMSFT was there a reason to keep tvos disabled? I see that as a package deal with iOS / MacCatlyst.

PR dotnet#126550 disabled FEATURE_CORPROFILER for tvOS but left iOS,
MacCatalyst, and Android commented out (profiler still enabled).
There is no reason to single out tvOS from its sibling Apple mobile
platforms. They should be treated as a package deal.

The uncommented 'AND NOT CLR_CMAKE_TARGET_TVOS' line removed profiler
fields from the Thread struct on tvOS, making the hardcoded
OFFSETOF__Thread__m_pInterpThreadContext in asmconstants.h wrong
(0x2b8 vs actual 0x228), breaking all 3 tvOS legs in unified-build.

Comment out the tvOS line to match iOS/MacCatalyst/Android, keeping
the profiler enabled until all mobile platforms disable it together.

Fixes internal unified-build tvOS failures on main (build 2946990).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok steveisok closed this Apr 9, 2026
@steveisok steveisok force-pushed the fix/tvos-asmconstants-profiler-offset branch from 1cd4703 to a1d0b19 Compare April 9, 2026 15:40
@steveisok steveisok changed the title Fix OFFSETOF__Thread__m_pInterpThreadContext for tvOS without FEATURE_CORPROFILER Re-enable FEATURE_CORPROFILER for tvOS to match iOS/MacCatalyst Apr 9, 2026
@steveisok steveisok changed the title Re-enable FEATURE_CORPROFILER for tvOS to match iOS/MacCatalyst Fix Thread offset for non-desktop platforms without FEATURE_CORPROFILER Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants