macossegmentation-faultdmacos-sequoia

Dlang application crashes with "Segmentation fault: 11" on macOS 15.4


After upgrading macOS from 15.3.1 to 15.4, my D executable crashes with Segmentation fault: 11.

I've tried using lldb to figure out what's going on, but am not sure what this reveals:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x00007ff80c4978c1 libsystem_pthread.dylib`pthread_getspecific
libsystem_pthread.dylib`pthread_getspecific:
->  0x7ff80c4978c1 <+0>: movq   %gs:(,%rdi,8), %rax
    0x7ff80c4978ca <+9>: retq   

libsystem_pthread.dylib`pthread_setspecific:
    0x7ff80c4978cb <+0>: leaq   -0xa(%rdi), %rcx
    0x7ff80c4978cf <+4>: movl   $0x16, %eax
Target 0: (test) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00007ff80c4978c1 libsystem_pthread.dylib`pthread_getspecific
    frame #1: 0x0000000100091df3 test`_D2rt18sections_darwin_647tlvInfoFNbNixPS4core3sys6darwin4mach6loader14mach_header_64ZSQDhQDh13dyld_tlv_info(header=0x0000000100000000) at sections_darwin_64.d:95:5
    frame #2: 0x0000000100091d72 test`_D2rt18sections_darwin_6411getTLSRangeFNbNixPvZAv(tlsSymbol="\U00000001") at sections_darwin_64.d:43:9
    frame #3: 0x0000000100092416 test`_D2rt19sections_elf_shared3DSO8tlsRangeMxFNbNiZAv(this=<unavailable>) at sections_elf_shared.d:201:13
    frame #4: 0x0000000100092957 test`_d_dso_registry(arg="\U00000001") at sections_elf_shared.d:606:13
    frame #5: 0x0000000100088d63 test`_D2rt3dso12register_dsoFZv at dso.d:51:9
    frame #6: 0x00007ff80c10c5a2 dyld`invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 290
    frame #7: 0x00007ff80c13de9a dyld`invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 234
    frame #8: 0x00007ff80c16c45c dyld`invocation function for block in mach_o::Header::forEachSection(void (mach_o::Header::SectionInfo const&, bool&) block_pointer) const + 271
    frame #9: 0x00007ff80c16985d dyld`mach_o::Header::forEachLoadCommand(void (load_command const*, bool&) block_pointer) const + 191
    frame #10: 0x00007ff80c16adb2 dyld`mach_o::Header::forEachSection(void (mach_o::Header::SectionInfo const&, bool&) block_pointer) const + 116
    frame #11: 0x00007ff80c13da7c dyld`dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 470
    frame #12: 0x00007ff80c10c40a dyld`dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 150
    frame #13: 0x00007ff80c112bdb dyld`dyld4::JustInTimeLoader::runInitializers(dyld4::RuntimeState&) const + 21
    frame #14: 0x00007ff80c10c77c dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&, dyld3::Array<dyld4::Loader const*>&) const + 276
    frame #15: 0x00007ff80c1101c9 dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_0::operator()() const + 147
    frame #16: 0x00007ff80c10c825 dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 115
    frame #17: 0x00007ff80c1267cb dyld`dyld4::APIs::runAllInitializersForMain() + 269
    frame #18: 0x00007ff80c0f8634 dyld`dyld4::prepare(dyld4::APIs&, mach_o::Header const*) + 3587
    frame #19: 0x00007ff80c0f781f dyld`dyld4::start(dyld4::KernelArgs*, void*, void*)::$_0::operator()() const + 239
    frame #20: 0x00007ff80c0f74da dyld`start + 2970

Solution

  • macOS seems to have changed something in 15.4 that makes all D programs compiled with LDC >=1.29 (released in 2022) fail.

    The easiest workaround for now is to use LDC <=1.28 to recompile programs.

    A fix might appear in a future LDC release, presumably 1.40.2 or 1.41 (current version is 1.40.1).

    The issue is tracked on Github at https://github.com/dlang/dmd/issues/21126