Skip to content

Apps that took dependency on libcoreclr.so fail in single file mode #41859

Closed

Description

@MichalStrehovsky

@migueldeicaza's Gui.cs is an example of a library that took dependency on libcoreclr.so (because apparently that's a way to get at CoreCLR's dlopen).

https://github.com/migueldeicaza/gui.cs/blob/fa29269ade64482c65cf657b2dfcfa68c59ba2de/Terminal.Gui/ConsoleDrivers/CursesDriver/UnmanagedLibrary.cs#L254-L266

This obviously fails in single file mode where libcoreclr.so doesn't exist:

Curses failed to initialize, the exception is: System.DllNotFoundException: Unable to load shared library 'libcoreclr.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibcoreclr.so: cannot open shared object file: No such file or directory
   at Mono.Terminal.Internal.UnmanagedLibrary.CoreCLR.dlopen(String filename, Int32 flags)
   at Mono.Terminal.Internal.UnmanagedLibrary.PlatformSpecificLoadLibrary(String libraryPath)
   at Mono.Terminal.Internal.UnmanagedLibrary..ctor(String[] libraryPathAlternatives, Boolean isFullPath)
   at Unix.Terminal.Curses.LoadMethods()
   at Unix.Terminal.Curses.FindNCurses()
   at Unix.Terminal.Curses.initscr()
   at Terminal.Gui.CursesDriver.Init(Action terminalResized)
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Unix.Terminal.Curses.raw()
   at Terminal.Gui.CursesDriver.Init(Action terminalResized)
   at Terminal.Gui.Application.Init(Func`1 topLevelFactory)
   at Terminal.Gui.Application.Init()
   at Demo.Main()
Aborted

Should we quirk DllImports from libcoreclr.so?

I filed tui-cs/Terminal.Gui#889 in Gui.cs, but this might end up being a pattern.

I'm putting this 5.0 so that it's looked at, but feel free to move around.

Activity

  1. added this to the 5.0.0 milestone on Sep 4, 2020
  2. added
    untriaged
    on Sep 4, 2020
  3. benaadams commented on Sep 4, 2020

    @benaadams
    Member

    https://github.com/migueldeicaza/gui.cs/blob/91a86c9460751dd0ed40ee8945b12f6cdb33b5fd/Terminal.Gui/ConsoleDrivers/CursesDriver/UnmanagedLibrary.cs#L254-L266

    /// <summary>
    /// Similarly as for Mono on Linux, we load symbols for
    /// dlopen and dlsym from the "libcoreclr.so",
    /// to avoid the dependency on libc-dev Linux.
    /// </summary>
    static class CoreCLR
    {
        [DllImport ("libcoreclr.so")]
        internal static extern IntPtr dlopen (string filename, int flags);
    
        [DllImport ("libcoreclr.so")]
        internal static extern IntPtr dlsym (IntPtr handle, string symbol);
    }
  4. benaadams commented on Sep 4, 2020

    @benaadams
    Member

    It looks to be to avoid a runtime dependency on libc-dev which it takes for the non-Mono, non-CoreCLR path https://github.com/migueldeicaza/gui.cs/blob/91a86c9460751dd0ed40ee8945b12f6cdb33b5fd/Terminal.Gui/ConsoleDrivers/CursesDriver/UnmanagedLibrary.cs#L220-L227

    static class Linux
    {
        [DllImport ("libdl.so")]
        internal static extern IntPtr dlopen (string filename, int flags);
    
        [DllImport ("libdl.so")]
        internal static extern IntPtr dlsym (IntPtr handle, string symbol);
    }
  5. jkotas commented on Sep 4, 2020

    @jkotas
    Member

    Should we quirk DllImports from libcoreclr.so?

    No. If we start adding compatibility quirks like this to runtime to virtualize the environment, we won't know where to stop. https://github.com/dotnet/designs/blob/master/accepted/2020/form-factors.md#single-file

    This should be fixed in the library. In the meantime, I believe that this can be worked around in the app by subscribing to AssemblyLoadContext.ResolvingUnmanagedDll event and rerouting libcoreclr.so.

  6. removed
    untriaged
    on Sep 4, 2020
  7. agocke commented on Sep 4, 2020

    @agocke
    Member

    No. If we start adding compatibility quirks like this to runtime to virtualize the environment, we won't know where to stop.

    Agreed. Fundamentally we need to have a set of supported API points and focus on that. PInvoking coreclr.dll is not one of those, it's simply an implementation detail.

  8. removed this from the 5.0.0 milestone on Sep 4, 2020
  9. ghost locked as resolved and limited conversation to collaborators on Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions