diff --git a/MemoryModule/Linux/GlibcInterop/RtldGlobal.cs b/MemoryModule/Linux/GlibcInterop/RtldGlobal.cs index 6af4065..b3ee048 100644 --- a/MemoryModule/Linux/GlibcInterop/RtldGlobal.cs +++ b/MemoryModule/Linux/GlibcInterop/RtldGlobal.cs @@ -114,21 +114,39 @@ private RtldGlobal(byte* memory) private static RtldGlobal GetInstance() { - var libdl = dlopen("libdl.so"); - var ptr = dlsym(libdl, "_rtld_global"); + IntPtr libdl; + IntPtr ptr; + + try + { + // Recent glibc updates have removed libdl.so from glibc. + // https://unix.stackexchange.com/questions/700097/unable-to-load-shared-library-libdl-so-or-one-of-its-dependencies + libdl = dlopen("libc.so"); + ptr = dlsym(libdl, "_rtld_global"); + } + catch (DllNotFoundException) + { + libdl = dlopen_dl("libdl.so"); + ptr = dlsym_dl(libdl, "_rtld_global"); + } return new RtldGlobal((byte*)ptr); } - [DllImport("dl")] + [DllImport("libc")] private static extern IntPtr dlopen([MarshalAs(UnmanagedType.LPStr)] string name, int mode = 0x01); - [DllImport("dl")] + [DllImport("libc")] private static extern IntPtr dlsym(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string name); [DllImport("libc")] private static extern void _dl_get_tls_static_info(out UIntPtr size, out UIntPtr align); + [DllImport("dl")] + private static extern IntPtr dlopen_dl([MarshalAs(UnmanagedType.LPStr)] string name, int mode = 0x01); + + [DllImport("dl")] + private static extern IntPtr dlsym_dl(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string name); } //[StructLayout(LayoutKind.Sequential)]