-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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] Add direct pinvoke module variations #81548
Conversation
@mdh1418 So thinking some more about this, I'm not sure this is the right approach. What we really would like to handle is the case where unix have dllimport of libMyLibrary and on windows it would be MyLibrary and avoid having to handle duplicate entries in the configurations to support both, but still give the user the power to do so if needed. Maybe a better way would be to support a very basic regexp in module names passed to AOT compiler, like (lib)?MyLibrary ,that would add both libMyLibrary and MyLibrary to the hash table. Parsing the simple regexp could be done very simple, look for ( if found look for )?, if found , create the two strings in hash table. You might need to support some escaping as well When we check if a module is part of the direct pinvoke hash table, we should first start using the literal from dllimport, without path (like we currently do) but with any prefix/suffix, if that is not a match, then we strip the suffix and make a search again, if that is not a match, the module is not defined and the dllimport should not be direct pinvoked. Thoughts? |
What does NativeAOT do? |
I had asked the same question to @mdh1418 offline, he will take a look to see, but I have not seen that they have any additional support in the specification of direct pinvokes than module!entrypoint. Right now I feel that we could stick to what we have for now and improve if needed later. |
Just looking now at runtime/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs Lines 81 to 133 in 47071da
module/entrypoint pairs. Doesn't seem like they do anything to check the prefix atleast from the side of building known map/table of module/etnrypoints. Maybe they have something before building the map/table, I'll have to keep looking, and I'm not exactly sure what they do from the perspective of compiling the managed code's [DllImport(module)] side yet, I'll need to find out where that is done for NativeAOT
They also have some sort of Entrypoint variation that we dont have. Is this something we need to implement as well? I'm not familiar with the entrypoint variations. |
That is for windows where you can have A or W depending on char set. I think we can add that later, right now we target android/ios, so that is no variations happening there. The module variation seems to match what we currently implemented. |
Follow up to #79721
When specifying
DirectPInvokes
/DirectPInvokeLists
andDllImport
modules in the Mono aot compiler, there are no strict limitations on what values can be passed in. Any exact mismatch betweenmodule(!entrypoint)
values passed intoDirectPInvokes
/DirectPInvokeLists
in the.csproj
and module/entrypoint values specified inDllImport
declarations on the managed side will result in undesired behavior.MATCH
NO MATCH
Currently, the mono aot compiler views the above as a mismatch, because the literal values are not equal even though its understood that the module of
libmodule.so
ismodule
.Across all supported platforms and architectures, the shared library prefixes and suffixes vary greatly, leading to a situation where the managed side
DllImport
invocation would need to vary for different platform/architecture.This PR looks to expand the module/entrypoint pairs added to the aot compiler's known
direct_pinvokes
hashtable that is responsible for filtering which direct pinvokes to generate direct calls for.More specifically:
DirectPInvokes
andDirectPInvokeLists
will be stripped of known shared library prefixes/suffixes, and both themodule/entrypoint
andstripped module/entrypoint
(if different) will be added to the hashtable for matching.DllImport
will no longer by stripped of extensionsSpecific cases that may cause problems:
libc.so, libz.so