Skip to content

[macOS] Hosting CoreCLR inside an LLDB plugin fails to initialize the runtime #99977

@lambdageek

Description

@lambdageek

This is related to dotnet/diagnostics#4259 and dotnet/diagnostics#4551

SOS is an LLDB plugin that is hosts a CoreCLR runtime. It have been failing to work on recent versions of macOS / Xcode, and in Sonoma macOS 14.4 loading the plugin actually kills the LLDB process entirely (see dotnet/diagnostics#4551)

I have only tried on osx-arm64. SIP is not disabled

I have created a standalone repro https://github.com/lambdageek/repro-coreclr-lldb

Build:

$ cmake -B out -S .
$ cmake --build out

Run:

$ lldb -b -o "plugin load ./out/libhihost.dylib"
(lldb) plugin load ./out/libhihost.dylib
Hello from C
hostfxr path is /Users/alklig/work/hihost/out/libhostfxr.dylib
running with dotnet root /Users/alklig/work/hihost/out/
coreclr initialized
zsh: killed     lldb -b -o "plugin load ./out/libhihost.dylib"

The above happens with macOS Sonoma 14.4. With 14.3, you get a bit further, but the runtime will still fail to initialize.

In dotnet/diagnostics#4551 we found a workaround to at least get past the whole LLDB process aborting, by passing PAL_MachExceptionMode=7

$ PAL_MachExceptionMode=7 lldb -b -o "plugin load ./out/libhihost.dylib"
(lldb) plugin load ./out/libhihost.dylib
Hello from C
hostfxr path is /Users/alklig/work/hihost/out/libhostfxr.dylib
running with dotnet root /Users/alklig/work/hihost/out/
coreclr initialized
host says: Failed to create CoreCLR, HRESULT: 0x8007000C
hostfxr_run_app finished

Expected output (compare with a "normal" hardened runtime macOS app):

$ ./out/runmyself
Hello from C
hostfxr path is /Users/alklig/work/hihost/out/libhostfxr.dylib
running with dotnet root /Users/alklig/work/hihost/out/
coreclr initialized
Hello from C#
hostfxr_run_app finished

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions