Page MenuHomePhabricator

C#: Fix class registration when running with dotnet core
Closed, ResolvedPublic

Description

Current function registration code uses dlsym(RTLD_DEFAULT, ...). While it works on Mono (which dlopen's with RTLD_GLOBAL), it fails in dotnet core which uses RTLD_LOCAL (dlopen's default).

We should change the registration code to use the library handles when dlsym'ing the function pointers.

lauromoura triaged this task as High priority.
woohyun added a subscriber: woohyun.Dec 6 2018, 6:29 PM

@lauromoura

Could you share the progress of this work ?

@lauromoura

ping ? Could you check above question ?

Hi,

So, the problem is a bit worse. It seems using RTLD_GLOBAL is not stable and gives all kinds of problems (as per dotnet github issue https://github.com/dotnet/corefx/issues/33879).
Also, one other problem is that Mono and Visual Studio .NET allows for DllMaps to map library names to actual library files. This will be implemented in a completely different way in dotnet, however and will only be available in dotnet 3.0.0 version (which is still a preview).

So, the workaround for this to work in dotnet is to create code that imperatively calls LoadLibrary/dlopen and GetProcAddress/dlsym and save those as delegates. Just as CoreFX does it self.
This means a considerable (but localized) amount of changes to the generator.

We need to consider its priority in consideration to other bugs (such as inheritance, constructors, etc).