https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90059
Bug ID: 90059 Summary: Solaris mcontext_t, ucontext_t declarations are wrong 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: *-*-solaris2.* Initially, all Solaris 11/SPARC execution tests (both 32 and 64-bit) FAILed like this: Thread 2 received signal SIGSEGV, Segmentation fault. [Switching to Thread 1 (LWP 1)] 0xfec37d08 in rw_wrlock_impl () from /lib/libc.so.1 (gdb) where #0 0xfec37d08 in rw_wrlock_impl () from /lib/libc.so.1 #1 0xfec3e62c in sigaction () from /lib/libc.so.1 #2 0x000a8be4 in runModuleUnitTests () at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/core/runtime.d:506 #3 0x0007bfac in runAll (this=this@entry=0xffbfe78c) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/dmain2.d:484 #4 0x0007ba9c in tryExec (this=0xffbfe78c, dg=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/dmain2.d:460 #5 0x0007bcb4 in _d_run_main (argc=1, argv=<optimized out>, mainFunc=<optimized out>) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/dmain2.d:493 #6 0x000686d4 in main (argc=1, argv=0xffbfe864) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/__entrypoint.di:44 #7 0x000684c4 in _start () Backtrace stopped: previous frame identical to this frame (corrupt stack?) with libphobos built with -g3 -O0: 0xfec37cec <rw_wrlock_impl>: save %sp, -96, %sp 0xfec37cf0 <rw_wrlock_impl+4>: ld [ %g7 + 0x54 ], %i5 0xfec37cf4 <rw_wrlock_impl+8>: sethi %hi(0x2800), %i3 0xfec37cf8 <rw_wrlock_impl+12>: mov %g7, %l6 0xfec37cfc <rw_wrlock_impl+16>: add %i3, 0x146, %i2 0xfec37d00 <rw_wrlock_impl+20>: rd %pc, %i4 0xfec37d04 <rw_wrlock_impl+24>: sethi %hi(0x6a000), %g1 => 0xfec37d08 <rw_wrlock_impl+28>: ldsb [ %i5 + %i2 ], %l7 (gdb) p/x $i5 $14 = 0x0 (gdb) p/x $i2 $15 = 0x2946 The first arg (an rwlock_t *) should never be NULL. After some debugging, this turned out to be memory corruption happening after the call to swapcontext in fiber_switchContext. The root cause was that the declarations of mcontext_t and ucontext_t in core.sys.posix.ucontext are badly wrong for Solaris/SPARC. After correcting them as in the attached patch, those SEGVs are gone. Solaris/x86 is mostly right, the only correction being the introduction of the uc_xrs member of struct ucontext_t. This doesn't change either size or alignment, so it's primarily a cosmetic issue. This again seems strongly to argue for an approach like libgo's (generating Go structure declarations from the system headers at build time) or at least libsanitizer's (verifying struct sizes and member offsets at runtime) to avoid such isses.