-
Notifications
You must be signed in to change notification settings - Fork 132
Workaround for Linux library loader bug #49
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
Conversation
@tmat Does this PR mean that the approach suggested for LibGit2Sharp to manually load the libraries doesn't work? |
@bording It works on Windows but as it turned out it doesn't work on other platforms :( |
I don't think LibGit2Sharp can do anything to fix this. The Core CLR needs to be fixed. |
Meanwhile plugins (like msbuild tasks) loading native libraries can implement more sophisticated workaround that works well with multiple RIDs: #50. |
That's really unfortunate. That massively negates the benefit of the work I've done in libgit2/libgit2sharp#1571 to handle all of the linux RIDs.
Is there an issue filed to track getting this fixed? Do you happen to know how mono works in this scenario? If it also works correctly, then my PR is still useful.
Would there be some way to incorporate a custom AssemblyLoadContext into LibGit2Sharp, or would that always need to be in the assembly that's loading the LibGit2Sharp assembly? |
Mono uses .config files for configuring the loading paths, which is yet another mechanism. I haven't tested it.
I thought about that and it would be very messy. Two alternatives:
Since SourceLink only needs a few functions that are called from the build tasks it was relatively easy to split it into 2 assemblies - one that has build tasks and loads the other via Reflection to a custom load context and the other then loads LibGit2Sharp into the same load context. The interface between these two assemblies is rather simple - half a dozen method calls, so easy to do via Reflection. |
@jeffschwMSFT Is there an issue tracking improvements in loading native libraries in CoreCLR? When searching related CoreCLR github issues it seems like there are many problems in this area. Is there an umbrella issue that summarizes all of them and tracks proposed design? |
Yeah, but it's really inflexible and you have to trick it into working with libraries in a folder (it only works if the folder begins with My goal with libgit2/libgit2sharp#1571 was to use the manual loading you introduced to avoid the need for the config file in mono as well, unifying how we handle loading the library for all platforms. That's why I was wondering if you knew how mono behaves.
And that's exactly why I've never considering trying to go down the manual loading road before. You stating that DllImport would just use the manually-loaded library was a revelation! It turning out to not work in all cases is definitely putting a damper on things. |
Yeah, sadly it only works on Windows (both .NET Core and .NET FX). It will probably work on Windows on Mono as well. Seems like a property of the Windows loader rather then CLR. |
Not sure what to do about the plugin scenarios on Linux before Core CLR gets fixed. We can reintroduce setting the PATH when running on Linux/Mac to make it work but it's not safe when running in an environment like msbuild where multiple plugins can be loaded in parallel. |
Changing PATH doesn't work for Linux/Mac anyway. That was only something that worked on Windows. |
Oh, ok :(. Then the only solution is for the consumers to implement the manual load context loading as I did in SourceLink. |
At this point I'm thinking it might be worth it to consider the function pointer approach just to be able to take control of things and actually get it working properly. |
Maybe the pointer initialization code can be generated... Might be a quite a bit of work though. |
No description provided.