Skip to content

Remove Swift ObjC classes from Apple crypto native shim#128917

Merged
vcsjones merged 3 commits into
dotnet:mainfrom
vcsjones:fix-128867-2
Jun 3, 2026
Merged

Remove Swift ObjC classes from Apple crypto native shim#128917
vcsjones merged 3 commits into
dotnet:mainfrom
vcsjones:fix-128867-2

Conversation

@vcsjones
Copy link
Copy Markdown
Member

@vcsjones vcsjones commented Jun 2, 2026

Replace Swift class-backed opaque handles with typed pointer-backed Swift value types so loading multiple copies of the Apple crypto native library does not register duplicate ObjC classes in the process.

Add a native build validation script that fails if future Swift bindings introduce locally-defined Swift ObjC class metadata so that we don't run in to this problem again, since it is basically impossible to catch in CI.

Fixes #128867

 Replace Swift class-backed opaque handles with typed pointer-backed Swift
 value types so loading multiple copies of the Apple crypto native library
 does not register duplicate ObjC classes in the process.

 Add a native build validation script that fails if future Swift bindings
 introduce locally-defined Swift ObjC class metadata.

 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

@vcsjones vcsjones requested a review from bartonjs June 2, 2026 19:49
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 updates the Apple crypto native shim to avoid emitting Swift/ObjC class metadata (which is process-global) by replacing class-backed opaque handles with pointer-backed Swift value types. It also adds a post-build validation step to prevent reintroducing Swift ObjC class definitions in the future.

Changes:

  • Replace final class handle wrappers in pal_swiftbindings.swift with value types stored behind typed UnsafeMutablePointer<T> allocations, eliminating local Swift ObjC classes.
  • Add a new verify-no-swift-objc-classes.sh script that scans the built binary/archive for Swift ObjC class definitions.
  • Wire the new verification into the Apple crypto native library CMake post-build steps (shared + static).
Show a summary per file
File Description
src/native/libs/verify-no-swift-objc-classes.sh New validation script to detect Swift ObjC class definitions in the produced binary/archive.
src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift Replaces class-backed handles with pointer-backed value types to avoid Swift ObjC class registration.
src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt Adds post-build invocation of the new validation script for shared and static outputs.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread src/native/libs/verify-no-swift-objc-classes.sh Outdated
Comment thread src/native/libs/verify-no-swift-objc-classes.sh Outdated
Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 23:38
@vcsjones vcsjones enabled auto-merge (squash) June 2, 2026 23:42
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.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new

@vcsjones vcsjones merged commit 5e11a0f into dotnet:main Jun 3, 2026
117 checks passed
@vcsjones vcsjones deleted the fix-128867-2 branch June 3, 2026 13:53
@vcsjones vcsjones added this to the 11.0.0 milestone Jun 3, 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.

Two CLR-based apps cannot coexist on Apple platforms

4 participants