Skip to content

Conversation

grendello
Copy link
Contributor

@grendello grendello commented Jun 18, 2025

Context: 96a73e6
Context: f37158e

This is another PR in the series that remove native relocations from
the libxamarin-app.so library.

Modify the typemap data so that no pointers to per-module data for
the primary and duplicate maps need to be stored. Module here refers
to a single assembly used by the application. Each assembly/module is
described by an instance of a C++ struct which used to contain up to
two pointers to tables containing actual type mapping data - one for the
primary map (all modules have this one) and an optional map of duplicate
types, which was stored in another pointer.

The two pointers pointed to separate arrays of map data structures. Instead,
this PR now puts all of the primary map data for all modules in one array,
and all of the duplicate map data in another array. The assembly/module descriptor
structures now merely contain indices into those arrays.

This removes up to X*2 relocations (with X being the number of assemblies).

The change gives us another modest startup performance boost of 0.67% on a Pixel 8
device, using the dotnet new maui -sc sample. It also decreases the number of
relocations in libxamarin-app.so from 394 to 70 entries for this sample app.

Modest size decrease of libxamarin-app.so is another outcome:

  • arm64: 370936 to 363976 bytes (1.87%)
  • x64: 362520 to 355496 bytes (1.93%)

@grendello grendello changed the title [WIP] Compiles but applications won't build Generate less relocations in the native typemap code Jun 23, 2025
@grendello grendello force-pushed the dev/grendel/clr-host-typemap-less-relocs branch 2 times, most recently from 77ed61f to fa405a6 Compare June 24, 2025 18:23
@grendello grendello requested a review from Copilot June 25, 2025 10:29
Copilot

This comment was marked as outdated.

@grendello
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@grendello
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@grendello grendello force-pushed the dev/grendel/clr-host-typemap-less-relocs branch from 7e7b44d to 37c49f7 Compare June 27, 2025 10:45
@grendello grendello force-pushed the dev/grendel/clr-host-typemap-less-relocs branch from 37c49f7 to 9b627d9 Compare July 1, 2025 07:33
@grendello grendello changed the title Generate less relocations in the native typemap code [CoreCLR] Generate less relocations in the native typemap code Jul 1, 2025
@grendello grendello marked this pull request as ready for review July 1, 2025 08:56
Copy link

@Copilot 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 refactors the native typemap data in order to reduce the number of relocations in libxamarin-app.so by replacing per-module pointer fields with array indices. Key changes include replacing pointer fields with index fields in TypeMapModule, reorganizing type mapping arrays for primary and duplicate maps in both native and managed code, and updating the LLVM IR generation to support the new array-based layout.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/native/clr/xamarin-app-stub/application_dso_stub.cc Added declarations for modules_map_data and modules_duplicates_data arrays.
src/native/clr/include/xamarin-app.hh Modified TypeMapModule to store indices instead of pointers.
src/native/clr/host/typemap.cc Updated typemap lookup logic to use the new index fields and arrays.
src/Xamarin.Android.Build.Tasks/Utilities/TypeMappingReleaseNativeAssemblyGeneratorCLR.cs Removed redundant symbol name lookup methods that referenced removed pointer fields.
src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/* Updated LLVM IR generation code to support the new sectioned array types for module maps.

@grendello grendello enabled auto-merge (squash) July 1, 2025 09:00
@grendello grendello merged commit 3ccad61 into main Jul 1, 2025
59 checks passed
@grendello grendello deleted the dev/grendel/clr-host-typemap-less-relocs branch July 1, 2025 12:52
@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants