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

Always append the "dll" extension for native libraries loads on Windows #66666

Merged
merged 6 commits into from
Mar 17, 2022

Conversation

AaronRobinsonMSFT
Copy link
Member

Fixes #66608

Due to case-sensitive file systems on Windows the runtime will now always append the ".dll" extension unless the name contains a trailing "." or a known loadable extension. This is an attempt to mitigate the default Windows behavior that appends a ".DLL" which is rarely the casing used for Windows shared libraries.

Documentation PR to follow.

/cc @dotnet/interop-contrib

Due to case-sensitive file systems on Windows the runtime will now
  always append the ".dll" extension unless the name contains a trailing
  "." or a known loadable extensions. This is an attempt to mitigate
  the default Windows behavior that appends a ".DLL" which is rarely the
  casing used for Windows shared libraries.
@AaronRobinsonMSFT
Copy link
Member Author

My cursory look in Mono indicates they do not suffer from this issue. @lambdageek can you confirm my understanding of the following code:

static MonoDl *
netcore_probe_for_module_variations (const char *mdirname, const char *file_name, int raw_flags)
{
void *iter = NULL;
char *full_name = NULL;
MonoDl *module = NULL;
while (module == NULL && (full_name = mono_dl_build_path (mdirname, file_name, &iter))) {
char *error_msg = NULL;
module = mono_dl_open_full (full_name, MONO_DL_LAZY, raw_flags, &error_msg);
if (!module) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "DllImport error loading library '%s': '%s'.", full_name, error_msg);
g_free (error_msg);
}
g_free (full_name);
}
return module;
}

@jkotas
Copy link
Member

jkotas commented Mar 15, 2022

@AaronRobinsonMSFT
Copy link
Member Author

Does https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/LibraryNameVariation.Windows.cs need fixing to be in sync?

Yes. I don't think how this was done makes a lot of sense. Having this code duplication logic is a recipe for failure. Thanks for pointing it out.

@jkoritzinsky
Copy link
Member

Based on commit history, the duplicate implementation in managed is used by NativeAOT.

@jkotas
Copy link
Member

jkotas commented Mar 15, 2022

Based on commit history, the duplicate implementation in managed is used by NativeAOT.

And AssemblyDependencyResolver.

@lambdageek
Copy link
Member

My cursory look in Mono indicates they do not suffer from this issue. @lambdageek can you confirm my understanding of the following code:

Mono will probe for several different variations on the name - first as given, then with the mono_dl_get_so_suffixes suffixes (".dll" on Windows - lowercase), and also with a prefix mono_dl_get_so_prefix () ("" on Windows)- until it finds a name that works.

So I agree - I don't think Mono is affected.

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 60478d2 into dotnet:main Mar 17, 2022
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the runtime_66608 branch March 17, 2022 21:41
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
…ws (dotnet#66666)

* Always append the "dll" extension for native libraries loads on Windows

Due to case-sensitive file systems on Windows the runtime will now
  always append the ".dll" extension unless the name contains a trailing
  "." or a known loadable extensions. This is an attempt to mitigate
  the default Windows behavior that appends a ".DLL" which is rarely the
  casing used for Windows shared libraries.

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@ghost ghost locked as resolved and limited conversation to collaborators Apr 17, 2022
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.

[DllImport] on Windows fails to load library on case sensitive filesystem
5 participants