Skip to content

[dotnet] Fix inlined-dlfcn native symbol generation when the trimmer is skipped - #25999

Merged
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/test-inlined-dlfcn-prepare-assemblies
Jul 14, 2026
Merged

[dotnet] Fix inlined-dlfcn native symbol generation when the trimmer is skipped#25999
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/test-inlined-dlfcn-prepare-assemblies

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

When PrepareAssemblies + PostProcessAssemblies are enabled and the trimmer is skipped (_CanSkipTrimmer), its output directory (IntermediateLinkDir) is empty, so _ComputeTrimmedAssemblies found no assemblies to scan. As a result _CollectPostILTrimInformation collected no inlined-dlfcn native symbols and no native code was generated for them, causing undefined native symbols (_xamarin_Dlfcn_*_Native) at link time.

Fix

  • Collect the assemblies to scan from @(ResolvedFileToPublish) (the same source every other target uses) instead of the trimmer's output directory. This works whether or not the trimmer ran: when it's skipped the published assemblies are the final ones, and when it did run they're derived from the trimmed output, so the surviving symbol set is identical (verified against a normal trimmed build).
  • Harden CollectPostILTrimInformation to skip files that aren't managed assemblies, since @(ResolvedFileToPublish) can contain native libraries with a managed extension (e.g. a native NativeLibrary.dll), which make Cecil throw BadImageFormatException.

Test

Add a dontlink|prepare-assemblies|inline-dlfcn-methods-compat variation for monotouch-test that reproduces the issue. This only needs explicit coverage on .NET 10: there iOS defaults to MonoVM, which links the SDK by default, so the trimmer isn't skipped unless linking is explicitly disabled and InlineDlfcnMethods is enabled. On .NET 11+ iOS defaults to CoreCLR (which doesn't link) and InlineDlfcnMethods is enabled by default, so the plain prepare-assemblies variation already covers it — the new variation is therefore ignored on .NET 11+. A reusable dontlink test variation is also added.

🤖 Pull request created by Copilot

rolfbjarne and others added 2 commits July 9, 2026 09:50
…is skipped

When PrepareAssemblies + PostProcessAssemblies are enabled and the
trimmer is skipped (_CanSkipTrimmer), its output directory
(IntermediateLinkDir) is empty, so _ComputeTrimmedAssemblies found no
assemblies to scan and the inlined-dlfcn native symbols were never
collected, resulting in undefined native symbols at link time.

Collect the assemblies to scan from @(ResolvedFileToPublish) (the same
source every other target uses) instead of the trimmer's output
directory. This works whether or not the trimmer ran: when it's skipped
the published assemblies are the final ones, and when it did run they're
derived from the trimmed output, so the surviving symbol set is
identical (verified against a normal trimmed build).

Since @(ResolvedFileToPublish) can also contain native libraries with a
managed extension (e.g. a native 'NativeLibrary.dll'), harden
CollectPostILTrimInformation to skip files that aren't managed
assemblies (Cecil throws BadImageFormatException on those).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…prepare-assemblies issue

Add a 'dontlink|prepare-assemblies|inline-dlfcn-methods-compat' variation
for monotouch-test that exercises the inlined-dlfcn native symbol
generation when the trimmer is skipped.

This scenario only needs explicit coverage on .NET 10: there iOS defaults
to MonoVM, which links the SDK by default, so the trimmer isn't skipped
unless linking is explicitly disabled and InlineDlfcnMethods is enabled.
On .NET 11+ iOS defaults to CoreCLR (which doesn't link) and
InlineDlfcnMethods is enabled by default, so the plain 'prepare-assemblies'
variation already covers it; the new variation is therefore ignored on
.NET 11+.

Also add a 'dontlink' test variation (MtouchLink/LinkMode = None) to
compose this configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a build-time regression where inlined-dlfcn native symbols aren’t generated when PrepareAssemblies + PostProcessAssemblies are enabled and the trimmer is skipped (empty IntermediateLinkDir), which can otherwise lead to undefined _xamarin_Dlfcn_*_Native symbols at native link time.

Changes:

  • Update _ComputeTrimmedAssemblies to scan assemblies from @(ResolvedFileToPublish) instead of $(IntermediateLinkDir).
  • Harden CollectPostILTrimInformation to skip non-managed .dll inputs (catch BadImageFormatException).
  • Add a reusable dontlink test variation and introduce a new monotouch-test Jenkins variation intended to cover the “trimmer skipped” scenario.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/xharness/Jenkins/TestVariationsFactory.cs Adds a monotouch-test variation to exercise PrepareAssemblies + inline-dlfcn with trimming disabled (currently missing PostProcessAssemblies).
tests/common/test-variations.csproj Adds dontlink variation for disabling trimming/linking in tests (suggest adding postprocess-assemblies too).
msbuild/Xamarin.MacDev.Tasks/Tasks/CollectPostILTrimInformation.cs Skips non-managed .dll inputs to avoid Cecil BadImageFormatException when scanning publish items.
dotnet/targets/Xamarin.Shared.Sdk.targets Switches post-trim symbol collection input from IntermediateLinkDir to @(ResolvedFileToPublish) to work even when the trimmer is skipped.

Comment thread tests/xharness/Jenkins/TestVariationsFactory.cs
Comment thread tests/common/test-variations.csproj
Comment thread tests/common/test-variations.csproj
@rolfbjarne
rolfbjarne marked this pull request as ready for review July 9, 2026 17:43
@rolfbjarne
rolfbjarne requested a review from mauroa as a code owner July 9, 2026 17:43
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 9363c102b2817b621f780b93feee816f4f419f7a [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #9363c10] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 203 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 9363c102b2817b621f780b93feee816f4f419f7a [PR build]

@rolfbjarne
rolfbjarne merged commit 6ee72be into main Jul 14, 2026
57 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/test-inlined-dlfcn-prepare-assemblies branch July 14, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants