Overview
| Artifact ID: | 95ddfd18ab636b2f5f5437cce009251f2b12444cd6efdd0754b3da078e9543ba |
|---|---|
| Ticket: | 0b809cd3fc8b6e5e19cd8a9a91357e425472cd69
SIGSEGV on shutdown with TclOO, coroutines, namespaces, and -DPURIFY |
| User & Date: | andy on 2024-12-03 06:31:08 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-markdown"
- comment changed to:
A complex interaction between TclOO, coroutines, namespaces, and -DPURIFY can cause SIGSEGV on shutdown, not completely deterministically. The case presented below died 17 out of the last 20 runs. Create ~/crash.tcl with contents as follows: ``` oo::class create class oo::define class method yield {} {yield} namespace eval ns {coroutine coro [class new] yield} ``` Build and test like so: ``` cd $HOME/tcl/unix fossil clean -verily CPPFLAGS=-DPURIFY ./configure --enable-symbols --prefix=$HOME/tcl/install make -j`nproc` install ../install/bin/tclsh* $HOME/crash.tcl ``` I couldn't figure out how to reproduce this crash without -DPURIFY. Adding `namespace delete ns` and/or `class destroy` did not SIGSEGV, nor any other namespace shenanigans I could dream up. The crash happens with or without `--enable-symbols`, but it's great for debugging. In addition to 8.6.15, I confirmed this fails in the latest trunk version at time of writing. I was unable to find any unaffected versions. Using commit [b688a485b2](https://core.tcl-lang.org/tcl/info/b688a485b253869b), the backtrace looks like this: ``` #0 0x00007ffff7f384e7 in TclOOObjectName (interp=0x40f030, oPtr=0x497) at /root/tcl/generic/tclOO.c:3118 #1 0x00007ffff7f4c831 in MethodErrorHandler (interp=0x40f030, dummy1213=0x4956b0) at /root/tcl/generic/tclOOMethod.c:1235 #2 0x00007ffff7edb740 in InterpProcNR2 (data=0x481088, interp=0x40f030, result=1) at /root/tcl/generic/tclProc.c:1876 #3 0x00007ffff7d82ead in TclNRRunCallbacks (interp=0x40f030, result=1, rootPtr=0x4a9fa0) at /root/tcl/generic/tclBasic.c:4656 #4 0x00007ffff7d8a361 in DeleteCoroutine (clientData=0x40eae0) at /root/tcl/generic/tclBasic.c:9106 #5 0x00007ffff7d81c3f in Tcl_DeleteCommandFromToken (interp=0x40f030, cmd=0x4963c0) at /root/tcl/generic/tclBasic.c:3767 #6 0x00007ffff7ebb44f in Tcl_DeleteNamespace (namespacePtr=0x4d73c0) at /root/tcl/generic/tclNamesp.c:1063 #7 0x00007ffff7ebb81d in TclDeleteNamespaceChildren (nsPtr=0x40f660) at /root/tcl/generic/tclNamesp.c:1227 #8 0x00007ffff7ebbb47 in TclTeardownNamespace (nsPtr=0x40f660) at /root/tcl/generic/tclNamesp.c:1340 #9 0x00007ffff7d7f282 in DeleteInterpProc (blockPtr=0x40f030) at /root/tcl/generic/tclBasic.c:1949 #10 0x00007ffff7ed8465 in Tcl_Release (clientData=0x40f030) at /root/tcl/generic/tclPreserve.c:229 #11 0x00007ffff7eba500 in FreeMainInterp (clientData=0x40f030) at /root/tcl/generic/tclMain.c:930 #12 0x00007ffff7e54ee1 in InvokeExitHandlers () at /root/tcl/generic/tclEvent.c:917 #13 0x00007ffff7e55048 in Tcl_Finalize () at /root/tcl/generic/tclEvent.c:1198 #14 0x00007ffff7e54f91 in Tcl_Exit (status=0) at /root/tcl/generic/tclEvent.c:973 #15 0x00007ffff7da55f8 in Tcl_ExitObjCmd (dummy981=0x0, interp=0x40f030, objc=2, objv=0x484c00) at /root/tcl/generic/tclCmdAH.c:998 #16 0x00007ffff7d82e49 in Dispatch (data=0x496108, interp=0x40f030, dummy4602=0) at /root/tcl/generic/tclBasic.c:4640 #17 0x00007ffff7d82ead in TclNRRunCallbacks (interp=0x40f030, result=0, rootPtr=0x0) at /root/tcl/generic/tclBasic.c:4656 #18 0x00007ffff7d85af7 in TclEvalObjEx (interp=0x40f030, objPtr=0x4d8560, flags=131072, invoker=0x0, word=0) at /root/tcl/generic/tclBasic.c:6115 #19 0x00007ffff7d85a8b in Tcl_EvalObjEx (interp=0x40f030, objPtr=0x4d8560, flags=131072) at /root/tcl/generic/tclBasic.c:6096 #20 0x00007ffff7eb9dde in Tcl_MainEx (argc=-1, argv=0x7fffffffe2d8, appInitProc=0x4011c5 <Tcl_AppInit>, interp=0x40f030) at /root/tcl/generic/tclMain.c:610 #21 0x00000000004011c5 in main (argc=2, argv=0x7fffffffe2d8) at /root/tcl/unix/tclAppInit.c:94 ``` The SIGSEGV arises in `oPtr->cachedNameObj` because `oPtr` is garbage (0x497 in the above trace), yet `MethodErrorHandler` is trying to generate a nice error message. The result code (1, shown above) is due to the following in `TEBCresume`, which doesn't set an interpreter result (thus it is `tclEmptyString`): ``` if (iPtr->execEnvPtr->rewind) { result = TCL_ERROR; goto abnormalReturn; } ``` This code is invoked due to `DeleteCoroutine` having called `RewindCoroutine` immediately before launching into `TclNRRunCallbacks`, on account of the coroutine being suspended. - foundin changed to: "8.6.15"
- is_private changed to: "0"
- login: "andy"
- priority changed to: "5 Medium"
- private_contact changed to: "662c23482b0bf6a505f39e48fb7ad43af8dee4d3"
- resolution changed to: "None"
- severity changed to: "Important"
- status changed to: "Open"
- submitter changed to: "andy"
- subsystem changed to: "35. TclOO Package"
- title changed to:
SIGSEGV on shutdown with TclOO, coroutines, namespaces, and -DPURIFY
- type changed to: "Bug"