-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
The CoreCLR behavior seems to be behaving as if library is loaded as RTLD_LOCAL despite the fact that the actual code resolves them with RTLD_LAZY flag when using dlopen. This causes some difficulty of using CoreCLR for P/Invoke code that since current P/Invoke API currently cannot access global library variables (at least cleanly), we would normally use dlopen/dlsym to access the global library variables. The problem is that it behaves in a way that it seems as if there are 2 instances of the same library. It has persisted for more than 2 years now.
I've written a minimal reproduction code that can be tested on Mono and CoreCLR:
https://github.com/BlackCentipede/PinvokeBug
To test, simply run dotnet run and clang -std=c99 -shared -fPIC -olibTest.so Test.c && mcs Program.cs && mono Program.exe under TestPInvoke directory.
Dotnet Core would print the following:
And Mono Runtime would print the following:

This is tested on Dotnet Core 2.2.102 and Mono 5.16.0.
