-
Notifications
You must be signed in to change notification settings - Fork 87
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
Crash in dotnet 5.0 on Ubuntu Groovy #168
Comments
Can you please try to load any other PKCS#11 library e.g. PKCS11-MOCK? There might be a conflict between the native dependencies of .NET 5 runtime and unmanaged library you are loading. |
I did not notice this comment the first time I was reading your post 🤔 I see two options now:
|
I have tried #2 above and it tells me very little. There seems to be no debugging info in the dotnet-generated binary. What I did get is What I did notice is also that it crashes even if I just do a Console.WriteLine on the first line of Main and then return... The program I'm testing with is here https://github.com/qpernil/pkcs11-tester BR |
I have now tested on Ubuntu Xenial, Bionic, Focal and Groovy. It fails the same way except in one instance, Bionic, where I can successfully run the application if I call dotnet run, but not if I do dotnet /path-to-dll/pkcs11-tester.dll, in which case if crashes the same as on other platforms.. Very weird. Also, I want to point out that I have a different dotnet application I can run successfully on all those machines. That one is also using p-invoke. Weird.. |
I just installed Ubuntu 20.10 and "classic" packaged version of .NET 5.0 SDK from Anyway there seems to be a problem with
|
Segfaults on my system too with .NET 5 installed from SNAP but only after I created that quick'n'dirty
|
I managed to resolve my segfault with .NET 5 installed from SNAP, quick'n'dirty using System.Reflection;
using System.Runtime.InteropServices;
static IntPtr CustomDllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? dllImportSearchPath)
{
string mappedLibraryName = (libraryName == "libdl") ? "libdl.so.2" : libraryName;
return NativeLibrary.Load(mappedLibraryName, assembly, dllImportSearchPath);
}
static void Main(string[] args)
{
NativeLibrary.SetDllImportResolver(typeof(Pkcs11InteropFactories).Assembly, CustomDllImportResolver);
...
} @qpernil can you please try whether this fixes your issue? |
If I use dotnet 5.0 from the (apparently broken earlier but corrected today) microsoft 20.10 package everything works fine like before. So it would seem the snap is currently broken. Your custom mapping thing doesn't seem to be working as it seems the NativeLibrary.Load appends another .so to the end of the library name, and thus it fails. I could see this by setting the env var LD_DEBUG=libs. But it's not needed with the working dotnet version. Thanks for your support on this ! |
Right now there is no link to the 20.10 packages file, I just took the url for Focal and changed 20.04 to 20.10 and that worked, I got Groovy apt packages. When I tried with the Focal stuff it failed to load the library, probably the same isssue you were seeing above even though I didn't see the message about libdl not being found. |
So I'm happy to close this issue now unless you want to use it to investigate more. Thx again ! Pkcs11Interop is very useful. |
Tested that it works as before on xenial, bionic, focal and groovy. |
OK. I'm closing this issue as I'm unable to reproduce your segfault 😉 |
A final note - I discovered that if you use the NativeLibrary.Load with one argument it uses your library name as-is, and if you use the one with three args it does platform-specific 'decorating' so that foo becomes libfoo.so etc |
Hi,
I have been using Pkcs11Interop to test a pkcs#11 library, and it has been working great. Recently I updated from dotnet core 3.1 to dotnet 5.0 (as they call it now, it's still dotnet core) as Ubuntu Groovy had silently updated my dotnet installation (via snap). Once I did that I seem to be getting segmentation faults before even calling any functions in the pkcs11 library (I get no debugging output from it). In fact I just tested using the wrong library name and it still segfaults. Running the same on macos and dotnet 5.0 still works.
The text was updated successfully, but these errors were encountered: