Skip to content

Add TARGET_APPLE to System.Private.CoreLib DefineConstants for Apple platforms#126652

Merged
jkotas merged 3 commits intomainfrom
copilot/fix-type-load-exception-incremental-hash-tests
Apr 9, 2026
Merged

Add TARGET_APPLE to System.Private.CoreLib DefineConstants for Apple platforms#126652
jkotas merged 3 commits intomainfrom
copilot/fix-type-load-exception-incremental-hash-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

TypeLoadException: Could not load type 'System.Runtime.InteropServices.Swift.SwiftSelf' from assembly 'System.Private.CoreLib' on tvos_arm64 CoreCLR. The Swift interop types (SwiftSelf, SwiftError, SwiftIndirectResult) were being trimmed from System.Private.CoreLib.dll by ILLink on Apple builds.

The CreateRuntimeRootILLinkDescriptorFile task generates the ILLink root descriptor by processing corelib.h with DefineConstants="$(DefineConstants);FOR_ILLINK". Since corelib.h gates the Swift type definitions behind #ifdef TARGET_APPLE, and TARGET_APPLE was absent from the C# DefineConstants, the task didn't emit preservation roots for these types. ILLink then trimmed them as unreachable, causing CoreLibBinder::GetClass(CLASS__SWIFT_SELF) to throw at runtime.

Fixes #126557

Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 18:21
@github-actions github-actions bot added the area-Tools-ILVerification Issues related to ilverify tool and IL verification in general label Apr 8, 2026
Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 18:45
Copilot AI changed the title [WIP] Fix TypeLoadException in Verify_Clone_Hash on tvos_arm64 Add TARGET_APPLE to System.Private.CoreLib DefineConstants for Apple platforms Apr 8, 2026
Copilot AI requested a review from jkotas April 8, 2026 18:46
@jkotas
Copy link
Copy Markdown
Member

jkotas commented Apr 8, 2026

/azp run runtime-extra-platforms

@jkotas jkotas marked this pull request as ready for review April 8, 2026 21:12
Copilot AI review requested due to automatic review settings April 8, 2026 21:12
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Apr 8, 2026

/azp run runtime-extra-platforms

@jkotas jkotas requested a review from vitek-karas April 8, 2026 21:13
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas jkotas added area-System.Runtime.InteropServices and removed area-Tools-ILVerification Issues related to ilverify tool and IL verification in general labels Apr 8, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

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

This PR fixes Apple (tvOS arm64) CoreCLR runtime failures caused by ILLink trimming Swift interop types from System.Private.CoreLib by ensuring TARGET_APPLE is present in the CoreLib MSBuild DefineConstants used to generate the runtime ILLink root descriptor.

Changes:

  • Add TARGET_APPLE to DefineConstants when IsApplePlatform is true so corelib.h #ifdef TARGET_APPLE blocks are included during descriptor generation.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

🤖 Copilot Code Review — PR #126652

Note

This review was generated by GitHub Copilot.

Holistic Assessment

Motivation: Justified and well-traced regression fix. PR #125083 added #ifdef TARGET_APPLE guards around Swift interop types in corelib.h, but the corresponding TARGET_APPLE C# DefineConstants was never added. The CreateRuntimeRootILLinkDescriptorFile task (which uses DefineConstants to parse corelib.h) therefore stopped emitting preservation roots for SwiftSelf, SwiftError, and SwiftIndirectResult, causing ILLink to trim them on Apple builds.

Approach: Correct and minimal. Adding TARGET_APPLE to DefineConstants conditioned on IsApplePlatform follows the established pattern of sibling defines (TARGET_OSX, TARGET_IOS, TARGET_TVOS, etc.) in the same <PropertyGroup>. The IsApplePlatform property (defined on line 15 of the same file) correctly covers macOS, MacCatalyst, iOS, and tvOS — matching the semantics of TARGET_APPLE as used in corelib.h.

Summary: ✅ LGTM. Single-line MSBuild fix that restores the missing TARGET_APPLE define, enabling the ILLink descriptor generator to preserve Swift interop types on Apple platforms. No side effects — there are currently zero #if TARGET_APPLE guards in CoreLib C# source, so the only effect is on the ILLink descriptor task's processing of corelib.h. Already approved by @jkoritzinsky.


Detailed Findings

✅ Correctness — Fix addresses root cause

Verified the regression chain: corelib.h:878-883 gates Swift types behind #ifdef TARGET_APPLECreateRuntimeRootILLinkDescriptorFile.targets:46 passes DefineConstants to the task → without TARGET_APPLE in DefineConstants, task skips those types → ILLink trims them → TypeLoadException at runtime. The fix directly addresses the gap.

✅ Platform coverage — IsApplePlatform is complete

IsApplePlatform (line 15) = TargetsOSXIsiOSLike, where IsiOSLike (line 14) = TargetsMacCatalystTargetsiOSTargetstvOS. This covers all Apple platforms that the C/C++ side recognizes as TARGET_APPLE.

✅ Placement — Consistent with existing pattern

The new define is correctly positioned before the more-specific platform defines (TARGET_OSX, TARGET_MACCATALYST, etc.), following the general → specific ordering used throughout this <PropertyGroup>.

✅ Side effects — None

No C# source files in System.Private.CoreLib/src/ currently use #if TARGET_APPLE. The define only affects the ILLink descriptor generation task. (Several files use the more specific TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS pattern, which could be consolidated to TARGET_APPLE in a follow-up, but that's out of scope.)

Generated by Code Review for issue #126652 ·

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Apr 9, 2026

/ba-g other runtime-extra-platforms failures are being worked on

@jkotas jkotas merged commit 295ecbd into main Apr 9, 2026
159 of 218 checks passed
@jkotas jkotas deleted the copilot/fix-type-load-exception-incremental-hash-tests branch April 9, 2026 01:43
This was referenced 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.

TypeLoadException in Verify_Clone_Hash (IncrementalHashTests) on tvos_arm64 - missing SwiftSelf

6 participants