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

libdl.so is not available on many Linux distros, causing crashes on native library load #1492

Closed
CasualPokePlayer opened this issue Jun 8, 2023 · 4 comments · Fixed by #1499
Labels
bug Something isn't working

Comments

@CasualPokePlayer
Copy link
Contributor

Summary

Many Linux distros do not have libdl.so, rather they only have libdl.so.2. This causes a DllNotFoundException when using its native functions.

This would only occur when using .NET Framework / .NET Standard, as .NET Core / .NET 5+ just use System.Runtime.InteropServices.NativeLibrary instead of P/Invoking libdl directly.

According to the loader readme, the code was taken from NativeLibraryLoader, which seems to have this issue fixed already, so it's probably as simple as porting over that fix.

Steps to reproduce

  • Platform: Linux (Ubuntu 22.04 was used for this case)
  • Framework Version: .NET Framework / .NET Standard (.NET Core / .NET 5+ is not affected)
  1. Do anything which loads in a native library (e.g. Sdl.GetApi).
@CasualPokePlayer CasualPokePlayer added the bug Something isn't working label Jun 8, 2023
@Perksey
Copy link
Member

Perksey commented Jun 8, 2023

Thanks for letting us know. I have looked at the fix and concluded that this isn't an appropriate fix for Silk.NET, namely the try-and-catch method tends to create a poor user experience given that users are encouraged to have first chance exception handling on when debugging their applications. As you have identified that this is working on the newer .NET versions, I don't think we will take any action here. Please use the latest .NET.

@Perksey Perksey closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2023
@CasualPokePlayer
Copy link
Contributor Author

To be clear, upgrading to the latest .NET version is not possible at this time for my use case. I've been looking into Silk.NET to provide bindings for use in the BizHawk project, which is stuck on .NET Framework due to several .NET Framework only dependencies (e.g. OpenTK for OpenAL/OpenGL bindings), so we've been moving away from dependencies one by one by switching them to .NET Standard 2.0, allowing us to easily upgrade when we no longer have .NET Framework dependencies.

Considering that most (if not all?) Linux distros seem to just have libdl.so.2, perhaps it'd be fair to just switch the p/invoke to that?

@Beyley
Copy link
Contributor

Beyley commented Jun 8, 2023

I would be happy switching exclusively to just libdl.so.2 this is what osu-framework does, and i havent heard of/experienced any problems with that, feel free to open a PR changing that/come onto the discord to discuss more, if you are sure it wont cause any problems

@CasualPokePlayer
Copy link
Contributor Author

CasualPokePlayer commented Jun 8, 2023

https://refspecs.linuxfoundation.org/LSB_1.0.0/gLSB/libdl.html
https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/libdl.html

Actually, I suspect that practically every Linux distro should have libdl.so.2, otherwise they wouldn't even conform with LSB (which seems to have and still specify libdl.so.2 as the .so name for libdl). So I highly doubt it would cause issues (and for the small fraction of users who can't use new .NET versions and have a Linux distro which does not comply with LSB, which even then at that point I doubt they could use .NET in the first place, they could workaround this with a dllmap hack)

(also, other Unix targets wouldn't be affected in reality, as they use the BsdLibraryLoader, which just uses libc)

CasualPokePlayer added a commit to CasualPokePlayer/Silk.NET that referenced this issue Jun 8, 2023
Nearly all (or all if only counting LSB conforming) Linux distros have libdl.so.2, and usually don't have a libdl.so symlink unless dev packages are installed.

Fixes dotnet#1492
@Perksey Perksey moved this from Todo to Done in Silk.NET Development Tracker Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants