https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90060
Bug ID: 90060 Summary: libphobos.druntime_shared/core/thread.d FAILs on Solaris/SPARC Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: d Assignee: ibuclaw at gdcproject dot org Reporter: ro at gcc dot gnu.org Target Milestone: --- Target: sparc*-sun-solaris2.11 Created attachment 46150 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46150&action=edit Use __makecontext_v2 on Solaris/SPARC With PR d/90059 fixed, (at least) the core.thread unittest FAILs: FAIL: libphobos.druntime_shared/core/thread.d execution test Segmentation fault while running unittests: ---------------- Program terminated with signal SIGSEGV, Segmentation fault. #0 sparc64_is_sighandler (nframes=<synthetic pointer>, cfa=0xffffffff7fffd470, pc=0xffffffff7f5c3fc8) at ./md-unwind-support.h:39 39 ./md-unwind-support.h: No such file or directory. [Current thread is 2 (Thread 1 (LWP 1))] (gdb) where #0 sparc64_is_sighandler (nframes=<synthetic pointer>, cfa=0xffffffff7fffd470, pc=0xffffffff7f5c3fc8) at ./md-unwind-support.h:39 #1 sparc64_fallback_frame_state (fs=0xffffffff7fffbf40, context=0xffffffff7fffbb50) at ./md-unwind-support.h:271 #2 uw_frame_state_for (context=context@entry=0xffffffff7fffbb50, fs=fs@entry=0xffffffff7fffbf40) at /builds2/ulhg/workspace/Solaris_Trunk/Userland/full-build/02b-build-sparc/components/gcc7/gcc-7.3.0/libgcc/unwind-dw2.c:1257 #3 0xffffffff73b0ed50 in _Unwind_Backtrace ( trace=0xffffffff5d362438 <simple_unwind>, trace_argument=0xffffffff7fffc6d0) at /builds2/ulhg/workspace/Solaris_Trunk/Userland/full-build/02b-build-sparc/components/gcc7/gcc-7.3.0/libgcc/unwind.inc:290 #4 0xffffffff5d3624dc in backtrace_simple (state=0xffffffff7f5e8000, skip=<optimized out>, callback=0xffffffff5d2e40c4 <simpleCallback>, error_callback=0xffffffff5d2e4c28 <simpleErrorCallback>, data=0xffffffff7fffc860) at /vol/gcc/src/hg/trunk/solaris/libbacktrace/simple.c:106 #5 0xffffffff5d2e521c in gcc.backtrace.LibBacktrace.this(int) ( this=0xffffffff7fffc860, firstFrame=1) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/gcc/backtrace.d:227 #6 0xffffffff5d2cd248 in core.runtime.runModuleUnitTests().unittestSegvHandler(int, core.sys.posix.signal.siginfo_t*, void*) (signum=11, info=0xffffffff7fffd370, ptr=0xffffffff7fffd060) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/core/runtime.d:492 #7 <signal handler called> #8 0xffffffff7ef261b0 in memset%sun4v-hwcap4 () from /lib/64/libc.so.1 #9 0xffffffff7ede9108 in makecontext () from /lib/64/libc.so.1 #10 0x0000000100015bbc in core.thread.Fiber.initStack() ( this=0xffffffff7f1f6000) at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/../libdruntime/core/thread.d:5051 #11 0x0000000100015930 in core.thread.Fiber.reset() (this=0xffffffff7f1f6000) at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/../libdruntime/core/thread.d:4294 #12 0x000000010001536c in core.thread.Fiber.reset(void() delegate) ( this=0xffffffff7f1f6000, dg=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/../libdruntime/core/thread.d:4309 #13 0x00000001000152a4 in core.thread.Fiber.this(void() delegate, ulong, ulong) (this=0xffffffff7f1f6000, dg=..., sz=32768, guardPageSize=8192) at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/../libdruntime/core/thread.d:4157 #14 0x000000010001620c in core.thread.TestFiber.this() ( this=0xffffffff7f1f6000) at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/../libdruntime/core/thread.d:5175 #15 0x0000000100016300 in core.thread.runTen() () at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/../libdruntime/core/thread.d:5195 #16 0x0000000100016578 in core.thread.__unittestL5218_20() () at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/../libdruntime/core/thread.d:5220 #17 0x0000000100018cf8 in core.thread.__modtest() () at <no_file>:1 #18 0xffffffff5d2cd388 in __foreachbody2 (this=0xffffffff7fffe308, m=0x1001208b8 <ModuleInfo for core.gdc.modtest__thread>) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/core/runtime.d:558 #19 0xffffffff5d2f49ec in object.ModuleInfo.__lambda2 ( this=0xffffffff7fffe230, m=0x1001208b8 <ModuleInfo for core.gdc.modtest__thread>) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/object.d:1599 #20 0xffffffff5d30f600 in rt.minfo.__foreachbody2 (this=0xffffffff7fffe158, sg=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/minfo.d:777 #21 0xffffffff5d314410 in rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (dg=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/sections_elf_shared.d:69 #22 0xffffffff5d30f4e8 in rt.minfo.moduleinfos_apply(scope int(immutable(object.ModuleInfo*)) delegate) (dg=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/minfo.d:770 #23 0xffffffff5d2f26bc in object.ModuleInfo.opApply(scope int(object.ModuleInfo*) delegate) (dg=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/object.d:1598 #24 0xffffffff5d2cd074 in runModuleUnitTests () at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/core/runtime.d:548 #25 0xffffffff5d3031fc in runAll (this=0xffffffff7fffe640) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/dmain2.d:484 #26 0xffffffff5d30313c in tryExec (this=0xffffffff7fffe640, dg=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/dmain2.d:460 #27 0xffffffff5d303034 in _d_run_main (argc=1, argv=0xffffffff7fffe898, mainFunc=0x100018dfc <D main>) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/dmain2.d:493 #28 0x0000000100018dac in main (argc=1, argv=0xffffffff7fffe898) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/__entrypoint.di:44 #29 0x000000010000d3ec in _start () Backtrace stopped: previous frame identical to this frame (corrupt stack?) truss shows that this is an access to unmapped memory /1: getcontext(0xFFFFFFFF7F1F6060) Incurred fault #6, FLTBOUNDS %pc = 0xFFFFFFFF7EF261B0 siginfo: SIGSEGV SEGV_MAPERR addr=0xFFFFFFFF7F5C3F40 Received signal #11, SIGSEGV [caught] siginfo: SIGSEGV SEGV_MAPERR addr=0xFFFFFFFF7F5C3F40 which initially seemed weird happening when makecontext calls memset. Ultimately I remembered that Solaris/SPARC has a weird quirk in makecontext, as documented in makecontext(3C): NOTES The semantics of the uc_stack member of the ucontext_t structure have changed as they apply to inputs to makecontext(). Prior to Solaris 10, the ss_sp member of the uc_stack structure represented the high memory address of the area reserved for the stack. The ss_sp member now repre- sents the base (low memory address), in keeping with other uses of ss_sp. Compatibility with older code is achieved by this snippet in <ucontext.h>: #ifdef __sparc #ifdef __PRAGMA_REDEFINE_EXTNAME #pragma redefine_extname makecontext __makecontext_v2 The attached patch does the same in ucontext.d, which makes the test PASS.