This was discovered in December, hence the git commit hashes are 5 months old.
Comment #5 by ibuclaw — 2021-05-13T14:34:27Z
To describe what looks like is happening:
1. A D fiber context switch occurs.
2. An exception is thrown.
3. libunwind's entry point for raising exceptions is called.
4. Segfault somewhere deep in libc/pthread.
The unittest block that matches the encoded line numbers in the function name is:
---
// Test exception handling inside fibers.
unittest
{
enum MSG = "Test message.";
string caughtMsg;
(new Fiber({
try
{
throw new Exception(MSG);
}
catch (Exception e)
{
caughtMsg = e.msg;
}
})).call();
assert(caughtMsg == MSG);
}
Comment #6 by lio+bugzilla — 2021-09-11T23:13:58Z
I suspect I'm running into this same bug while running the DMD 2.097.2 test suite on Big Sur:
$ test_results/runnable/test15779_0
fish: “test_results/runnable/test15779…” terminated by signal SIGBUS (Misaligned address error)
$ lldb test_results/runnable/test15779_0
(lldb) target create "test_results/runnable/test15779_0"
Current executable set to '/Users/llunesu/repos/d/dmd/test/test_results/runnable/test15779_0' (x86_64).
(lldb) r
Process 854 launched: '/Users/llunesu/repos/d/dmd/test/test_results/runnable/test15779_0' (x86_64)
Process 854 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x1001edc60)
frame #0: 0x00007fff2031b4a8 libsystem_pthread.dylib`___chkstk_darwin + 96
libsystem_pthread.dylib`___chkstk_darwin:
-> 0x7fff2031b4a8 <+96>: testq %rcx, (%rcx)
0x7fff2031b4ab <+99>: popq %rcx
0x7fff2031b4ac <+100>: retq
libsystem_pthread.dylib`pthread_getspecific:
0x7fff2031b4ad <+0>: movq %gs:(,%rdi,8), %rax
Target 0: (test15779_0) stopped.
(lldb)
$ sw_vers
ProductName: macOS
ProductVersion: 11.5.2
BuildVersion: 20G95
$ clang --version
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ xcodebuild -version
Xcode 12.5.1
Build version 12E507
$ uname -v
Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
dmd, druntime, Phobos: tag v2.097.2
Comment #9 by ibuclaw — 2021-11-07T18:44:18Z
Done some prodding around, and the root cause is darwin's libunwind now overflows the Fiber's small 16kb stack.
Fix then is to bump the stack allocated for Fibers.
version (Windows)
// exception handling walks the stack, invoking DbgHelp.dll which
// needs up to 16k of stack space depending on the version of DbgHelp.dll,
// the existence of debug symbols and other conditions. Avoid causing
// stack overflows by defaulting to a larger stack size
enum defaultStackPages = 8;
+ else version (OSX)
+ {
+ version (X86_64)
+ enum defaultStackPages = 8;
+ else
+ enum defaultStackPages = 4;
+ }
else
enum defaultStackPages = 4;
Darwin x86 pagesize is 4k, whilst arm64 is 16k, so this fix should only be applied to 64-bit code.
Comment #10 by dlang-bot — 2021-11-07T22:13:25Z
@ibuclaw updated dlang/druntime pull request #3612 "fix Issue 21919 - darwin: SEGV in core.thread tests on OSX 11" fixing this issue:
- fix Issue 21919 - darwin: SEGV in core.thread tests on OSX 11
https://github.com/dlang/druntime/pull/3612
Comment #11 by dlang-bot — 2021-11-08T06:33:49Z
dlang/druntime pull request #3612 "fix Issue 21919 - darwin: SEGV in core.thread tests on OSX 11" was merged into stable:
- ad6583ff842694a07ecb0464aaf5efde13f5c67c by Iain Buclaw:
fix Issue 21919 - darwin: SEGV in core.thread tests on OSX 11
https://github.com/dlang/druntime/pull/3612
Comment #12 by dlang-bot — 2021-11-08T15:54:11Z
dlang/druntime pull request #3615 "Merge `stable` in `mater`" was merged into master:
- 17f51ab99725494c449257a89637e827721becde by Iain Buclaw:
fix Issue 21919 - darwin: SEGV in core.thread tests on OSX 11
https://github.com/dlang/druntime/pull/3615
Comment #13 by ibuclaw — 2021-11-22T14:14:15Z
*** Issue 22025 has been marked as a duplicate of this issue. ***