-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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] Introduce designated direct pinvokes to mono aot compiler #79721
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first pass, but didn't complete it full since there is already a bunch of things to look over.
A couple of things I had in mind around the organization of data in hash tables:
We always add a *
to the hash table, I guess the intent should be all pinvokes, like the bool we had in the pass. I guess it shouldn't be added unless a user uses a pinvoke entry with *
? Maybe we should optimize that use case a little since its the old use case that we still need to support, direct-pinvoke
or we break command line combability, so I suggest that you keep the bool and it can be set with the direct-pinvoke
flag as it used to do and you have that as part of the check to speed up old scenario where you enable direct-pinvoke
for all dllimports. The same would apply if you find a direct-pinvokes=*
or a line in the file with *
, that would toggle on the old bool flag, if you combine those you should probably get a warning that all dllimports will be direct-pinvoke
, since *
will override any specific module or module!entrypoint
records.
Maybe we should add an optimization for all entry points in a module as well since I believe that will be common use case as well, so if you have just module, that should make sure you override any specific entry points and you should probably issue a warning if you have a combination of module and module!entrypoints
. That could be done by holding a struct in the hash table with a bool and a pointer to the hash table for entry points, if you just use module meaning all entrypoints, then add a struct with bool set to true (and don't allocate hash table) and later validate records and warn if you have bool set to true and a hash table allocated as well. That way you can quickly find out if a all entrypoints in a module should be direct-pinvoke
or if you need to make another lookup in the modules entrypoint hash table.
ceba361
to
3efffe8
Compare
661dd17
to
5f2bfec
Compare
…cified_for_method
…direct_pinvoke_lists
@mdh1418 Fix up the build warnings and get all CI lanes pass. Did you validate everything with a end to end test? Once that is done I believe this is ready to be merged. |
@lateralusX The end-to-end testing I've done so far was only on iOS device to see whether the unmanaged code's symbol appears in the shared library.
And setting an ItemGroup
|
For more testing, proceeded to build a static library based on a source file (
and linked the resulting
With a test by linking the static library (without defining the appropriate native function, i.e. changing to hdm2) adding HelloiOS to the DirectPInvokes itemgroup, and adding a call to
iOSWhen properly adding the function declaration to the source file that is built into a static library that is linked into the final shared lib/executable, I was able to run the app with the expected results on iOS. AndroidThough having the same steps as iOS, Android seems to hit other errors and has an app crash. |
From my testing, I believe this has to do with the fallout from the runtime trying to |
Sounds like a different issue, the fact that you get an IL error at runtime indicate that the wrapper gets JIT:ed and not picked up from the AOT module and looking through your log it clearly says that it can't use the static linked AOT module since its full AOT, meaning that the embedding has not set the AOT mode correctly for the runtime in order to run full AOT: : assembly_preload_hook: System.Private.CoreLib (null) /data/user/0/net.dot.HelloAndroid/files Looking at the AndroidAppBuilder it looks like it needs both ForceAOT and ForceFullAOT msbuild properties set in order to end up calling: mono_jit_set_aot_mode(MONO_AOT_MODE_FULL); Have you made sure you can run you app with the pinvoke on Android using regular JIT? |
After setting |
Unless there are other things to ensure, I think that completes the end-to-end testing for Android and iOS. |
Contributes to #79377
On Mono, the Managed/native Interop story does not facilitate a granular specification of which native libraries or entry points for generating direct pinvoke calls. Instead, there was only a blanket boolean flag to handle direct pinvoke logic. On the other hand, Native AOT allows specification of which unmanaged libraries, entrypoints, or even files containing a list of such unmanaged libraries and entrypoints to generate direct pinvoke calls. To expand the capabilities on mono, similar logic can be introduced to the mono aot compiler.
This PR does the following:
mono_aot_direct_pinvoke_enabled_for_method
that compares the method being aot compiled with the direct-pinvoke Hash Table mapping