Skip to content

[Linux] DllImport should invoke with RTLD_GLOBAL flag #11901

@ghost

Description

@ghost

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:

dotnetcorebug

And Mono Runtime would print the following:
mono

This is tested on Dotnet Core 2.2.102 and Mono 5.16.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions