[release/10.0.1xx] [dotnet-linker] Mark field references in trimmed INativeObject/NSObject constructors. Fixes #24663.#24689
Conversation
…ct constructors. Fixes #24663. When the ManagedRegistrarLookupTablesStep re-marks a trimmed INativeObject or NSObject constructor (for the ConstructINativeObject/ConstructNSObject lookup tables), it was only marking MethodReference operands in the constructor body but not FieldReference operands. This caused the linker's SweepStep to remove fields referenced by the constructor (setting their DeclaringType to null), and Cecil would then fail with 'Member is declared in another module' when writing the assembly. The fix extracts the marking logic into a new MarkConstructorIfTrimmed method (eliminating code duplication) and adds marking of FieldReference operands alongside the existing MethodReference marking. Fixes #24663
There was a problem hiding this comment.
Pull request overview
This PR backports a fix from #24687 to the release/10.0.1xx branch for issue #24663, where the linker fails with "Member is declared in another module" when building apps with MtouchLink=SdkOnly. The issue occurred because the ManagedRegistrarLookupTablesStep was only marking MethodReference operands in trimmed constructor bodies but not FieldReference operands, causing the linker's SweepStep to remove fields referenced by the constructor.
Changes:
- Extracts duplicated constructor marking logic into a new
MarkConstructorIfTrimmedmethod - Adds marking of FieldReference operands alongside existing MethodReference marking
- Eliminates code duplication between
GenerateConstructNSObjectandGenerateConstructINativeObject
✅ [CI Build #2247f58] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #2247f58] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #2247f58] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #2247f58] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #2247f58] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #2247f58] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #2247f58] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #2247f58] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #2247f58] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 117 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
When the ManagedRegistrarLookupTablesStep re-marks a trimmed INativeObject
or NSObject constructor (for the ConstructINativeObject/ConstructNSObject
lookup tables), it was only marking MethodReference operands in the
constructor body but not FieldReference operands. This caused the linker's
SweepStep to remove fields referenced by the constructor (setting their
DeclaringType to null), and Cecil would then fail with 'Member is declared
in another module' when writing the assembly.
The fix extracts the marking logic into a new MarkConstructorIfTrimmed
method (eliminating code duplication) and adds marking of FieldReference
operands alongside the existing MethodReference marking.
Fixes #24663
Backport of #24687.