Skip to content

Fix NativeAOT export lookup test on Android - #130365

Open
sbomer wants to merge 1 commit into
dotnet:mainfrom
sbomer:sbomer-investigate-aot-failure
Open

sbomer wants to merge 1 commit into
dotnet:mainfrom
sbomer:sbomer-investigate-aot-failure

Conversation

@sbomer

@sbomer sbomer commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #129366

Summary

  • Re-enable the Android path for UnmanagedCallersOnlyAssociatedSourceType in the NativeAOT TrimmingBehaviors smoke test.
  • Resolve exported entry points from the Android app library handle, while preserving NativeLibrary.GetMainProgramHandle() on other platforms.

Testing

  • ./build.sh clr+libs -lc release -rc checked
  • Local NativeAOT TrimmingBehaviors executable on osx.arm64.Checked
  • Android arm64 NativeAOT TrimmingBehaviors APK under instrumentation (return-code=100)

Note

This PR description was created with assistance from GitHub Copilot.

Use the Android app library handle when resolving exported NativeAOT test entry points, while preserving GetMainProgramHandle for other platforms.

Co-authored-by: Copilot App <[email protected]>

Assisted-by: Copilot CLI:gpt-5.5
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

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

This change updates the NativeAOT TrimmingBehaviors smoke test to resolve unmanaged exports from a different module handle on Android, rather than always using NativeLibrary.GetMainProgramHandle(). This effectively re-enables the Android code path for UnmanagedCallersOnlyAssociatedSourceType by loading the app/library module on Android and using that handle for export lookup.

Changes:

  • Removed the Android early-return skip so the test executes on Android again.
  • Introduced GetExportOwnerHandle() to use NativeLibrary.Load(...) on Android while preserving GetMainProgramHandle() on other platforms.
Show a summary per file
File Description
src/tests/nativeaot/SmokeTests/TrimmingBehaviors/UnmanagedCallersOnlyAssociatedSourceType.cs Re-enables the Android test path and changes export lookup to use an Android-appropriate module handle.

Copilot's findings

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

Comment on lines +49 to +53

Assembly assembly = typeof(UnmanagedCallersOnlyAssociatedSourceType).Assembly;
string libraryName = assembly.GetName().Name!;
return NativeLibrary.Load(libraryName, assembly, searchPath: null);
}

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we were to load the .so with native AOT bits using RTLD_GLOBAL, the NativeLibrary.GetMainProgramHandle would probably work as-is (this is not the only test using it, we just do very little testing on Android).

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "44d48431960a190420875fd700bec73a62dea098",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "1ab7d0535812a71e3c95c70761fcf1af49511e51",
  "last_reviewed_commit": "44d48431960a190420875fd700bec73a62dea098",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "1ab7d0535812a71e3c95c70761fcf1af49511e51",
  "last_recorded_worker_run_id": "29682984780",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "44d48431960a190420875fd700bec73a62dea098",
      "review_id": 4730585457
    }
  ]
}

@github-actions github-actions Bot 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.

Holistic Review

Motivation: The NativeAOT TrimmingBehaviors smoke test UnmanagedCallersOnlyAssociatedSourceType was disabled on Android (ActiveIssue #129366) because NativeLibrary.GetMainProgramHandle() did not resolve the [UnmanagedCallersOnly(EntryPoint=...)] exports there. On Android, NativeAOT compiles the app into a shared library rather than the main program, so the exports live in that .so, not in the main program handle, producing EntryPointNotFoundException.

Approach: The fix removes the Android early-return and introduces GetExportOwnerHandle(), which keeps GetMainProgramHandle() on other platforms but on Android loads the app's own library by its assembly name via NativeLibrary.Load(libraryName, assembly, searchPath: null). This is a minimal, platform-scoped change that re-enables real coverage instead of returning success unconditionally, which is the right approach. The author reports verifying return-code=100 on Android arm64 under instrumentation.

Summary: ✅ LGTM. Test-only change that re-enables previously skipped Android coverage by resolving exports from the correct library handle. The logic is clear and correctly gated per-platform; the loaded handle is intentionally left unreleased, which is acceptable for a short-lived smoke test. No blocking concerns.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 42 AIC · ⌖ 15.2 AIC · ⊞ 10K

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[ci-scan] Test failure: UnmanagedCallersOnlyAssociatedSourceType.Run on android-x64 NativeAOT

3 participants