-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
NativeAOT: Export native methods from referenced assemblies. #65755
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
@josephmoresena Could you elaborate on what kind of experience you want to see here? |
Hi @agocke! Some simple way to export methods from a referenced package/assembly in a NativeAOT-compiled class library project would be desirable. |
@agocke we have encountered a very similar scenario while trying to integrate NativeAOT with Xamarin framework. Scenario
[UnmanagedCallersOnly (EntryPoint = "xamarin_objcruntime_runtime_nativeaotinitialize")]
unsafe static void SafeInitialize (InitializationOptions* options, IntPtr* exception_gchandle)
{
...
Initialize (options);
...
}
using UIKit;
...
static void Main (string[] args)
{
UIApplication.Main (args, null, typeof (AppDelegate));
}
...
xamarin_objcruntime_runtime_nativeaotinitialize(options, gchandle);
__managed_Main(argc, argv);
... In the build process ILC is invoked to build NOTE: There are other WorkaroundWhen compiling ProposalAfter a discussion with @MichalStrehovsky, one idea is to:
@josephmoresena, would this work for you as well? |
Just to make sure I'm understanding -- is the basic problem here that AOT library compilation only includes the "current project" assembly as a root? And you want to have more libraries referenced as roots? |
The issue is that the compiler currently looks for This proposes adding functionality to make the entrypoint rooting more controllable. The only question is whether we would want more granularity (ability to select individual named entrypoints vs "all named entrypoint in the assembly"). Probably all named entrypoints is sufficient. |
Partially. In that test, the JNI library that I was using did not require its own implementation of JNI_OnLoad or JNI_OnUnload, but this may not be the majority, especially if we refer to Android, where many things may have to be done through JNI. I wonder... what if (several?) different assemblies require this type of initialization on a single exported EntryPoint, and additionally if the invocation of that EntryPoint returns a result? For example, in the case of JNI_OnLoad, the minimum version of the JVM that guarantees the operation of the library. It may be one for the functionality initialized in the framework, but for the functionality implemented in the output assembly it is a higher one. |
I agree with you, however I think that this type of method would go far beyond the definition of UCO. |
@agocke I might not have been clear enough with the intention, Michal gave a more thorough explanation above
@josephmoresena, I am not sure I understand the use case you are referring to. ILCompiler exports managed methods decorated with As Michal stated, there is an optimization in ILCompiler, which will not export these kind of methods from referenced libraries, but only from the assemblies passed as inputs to the compiler. The example I gave above tries to express the need for handling this in more formal way. If you think this is not the same, as the issue you are describing, could you please provide more context and possibly a code example? Moreover, if there is a discrepancy between the two I can open a separate GH issue, regarding my comment above. |
Maybe this can be handled in the similar fashion as direct PInvoke calls are supported? |
This thread is for exactly what you're referring to: Exporting symbols of assemblies referenced from the library project. Exploring that idea in #72556, I found that exporting those kinds of symbols would be problematic if more than one assembly needs to export the same symbol, and not just because of the 'redefinition' issue. It will be especially problematic if those symbols are exported from Framework libraries or NuGet packages so that all this happens 'behind the scenes' of the project developer. So I think this kind of symbol export should be something that goes beyond the UCO functionality. |
This is a problem for domain-specific interop libraries to solve. For example, if multiple assemblies need subscribe to |
According with dotnet/corert#7215 it is possible to export native methods declared in other assemblies by passing them as input to ILCompiler.
However the way shown there is not very friendly. Would be possible to mark the referenced packages or projects in order to include them as ILCompiler input?
The text was updated successfully, but these errors were encountered: