Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Export unmanagedcallersonly method symbols #79424

Merged

Conversation

mdh1418
Copy link
Member

@mdh1418 mdh1418 commented Dec 8, 2022

Contributes to #79377

Native developers want to be able to call managed functions from their native applications using a shared library with the mono runtime. In order for this to happen, symbols corresponding to the managed functions need to be known while linking together the shared library. Typically, such methods are marked with UnmanagedCallersOnly Attribute, and the expectation is that the developers will designate an EntryPoint field corresponding to the desired function on the native side. (e.g. [UnmanagedCallersOnly(EntryPoint = "<native_function/symbol>"])

In order to build the shared library, a list of symbols corresponding to the methods decorated with such attributes exemplified above need to be generated while compiling each assembly, and consumed when building the shared library.
This PR targets the first part by generating for each assembly an .exportsymbols file which is a plain text file containing each EntryPoint symbol on its own line if and only if there is a positive number of such EntryPoint symbols.

Specifically, this PR:

  • Introduces an export symbols outfile parameter to the mono aot compiler that is designated as <assembly>.exportsymbols in the MonoAOTCompiler Task when in full aot mode and when the EnableUnmanagedCallersOnlyMethodsExport flag is on.
  • Generates the corresponding export symbols outfile if and only if there is a positive number of methods decorated with the UnmanagedCallersOnly attribute containing an EntryPoint corresponding to the desired native function, where each symbol is formatted based on the target platform.
  • Bundles the outfile into the MonoAOTCompiler Task's output assembly's metadata to be consumed by respective App Builders

[mono] Export EntryPoint of methods decorated with UnmanagedCallersOnlyAttribute to specified export_symbols_outfile
@mdh1418 mdh1418 force-pushed the export_unmanagedcallersonly_method_symbols branch from 581dde9 to 18dffe1 Compare December 9, 2022 05:11
Copy link
Member

@lateralusX lateralusX left a comment

Choose a reason for hiding this comment

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

LGTM!

@mdh1418
Copy link
Member Author

mdh1418 commented Dec 19, 2022

The failure is known #79439

@mdh1418 mdh1418 merged commit 73b5ac0 into dotnet:main Dec 19, 2022
@mdh1418 mdh1418 deleted the export_unmanagedcallersonly_method_symbols branch December 19, 2022 20:13
@ghost ghost locked as resolved and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants