Tcl Source Code

View Ticket
Login
Ticket UUID: 2553828
Title: crash in CompileSubExpr() -> SEGFAULT
Type: Bug Created on: 2009-01-31 22:45:04
Submitter: matzek Assigned to: dgp
Subsystem: 47. Bytecode Compiler Severity:
Priority: 8 Last modified: 2009-02-01 22:36:38
Status: Closed Closed by: dgp
Resolution: Wont Fix Closed on: 2009-02-01 15:36:38
Version: obsolete: 8.4.19
Description:
Hi *,

please note this crash affects Tcl 8.4 only. It does not happen with core-8-5-branch or trunk.

Tcl is 8.4.19, system is Linux openSUSE 11.1 on x86_64, build from sources with --enable-symbols.

While playing around with Richard's "Profiling with execution traces" (http://wiki.tcl.tk/21333), I noticed first degrading performance and then a segfault. I reduced it to the following code sample:

# -----
proc stat list {
    set sum [expr double([join $list +])] ;# <- that's the bastard!
    format "%10.0f" $sum
}

proc boom {} {
    set l [list 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
    while 1 {
eval {lappend l} $l
puts "[stat $l]"
    }
}

boom
# -----

As the stack trace is very large I will omit it and give only the level #0, #1 and then the last 20 levels, everything in between is just the recurring call of CompileSubExpr().

(gdb) bt full
#0  0x00007f001af8b4bd in CompileSubExpr (exprTokenPtr=Cannot access memory at address 0x7fff22c45f28
) at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:344
interp = (Tcl_Interp *) 0x6157b0
tokenPtr = (Tcl_Token *) 0x7fff22c46100
endPtr = (Tcl_Token *) 0x6157d1
afterSubexprPtr = (Tcl_Token *) 0x7fff22c46080
opDescPtr = (OperatorDesc *) 0x7f001afad536
hPtr = (Tcl_HashEntry *) 0x6157b0
operator = 0x6157b0 ""
opBuf = Cannot access memory at address 0x7fff22c45f40

(gdb) up
#1  0x00007f001af8bede in CompileSubExpr (exprTokenPtr=0x7f001a49dfc0, infoPtr=0x7fff23441280, envPtr=0x7fff23441320)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:485
485    code = CompileSubExpr(tokenPtr, infoPtr, envPtr);

(gdb) bt -20
#19366 0x00007f001af8bede in CompileSubExpr (exprTokenPtr=0x7f001a3bb0d0, infoPtr=0x7fff23441280, envPtr=0x7fff23441320)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:485
#19367 0x00007f001af8bede in CompileSubExpr (exprTokenPtr=0x7f001a3bb0a0, infoPtr=0x7fff23441280, envPtr=0x7fff23441320)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:485
#19368 0x00007f001af8bede in CompileSubExpr (exprTokenPtr=0x7f001a3bb070, infoPtr=0x7fff23441280, envPtr=0x7fff23441320)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:485
#19369 0x00007f001af8bede in CompileSubExpr (exprTokenPtr=0x7f001a3bb040, infoPtr=0x7fff23441280, envPtr=0x7fff23441320)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:485
#19370 0x00007f001af8d06b in CompileMathFuncCall (exprTokenPtr=0x7f001a3bb010, funcName=0x7fff23440ec0 "double", infoPtr=0x7fff23441280, 
    envPtr=0x7fff23441320, endPtrPtr=0x7fff23440f88) at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:886
#19371 0x00007f001af8bca9 in CompileSubExpr (exprTokenPtr=0x7f001a3bb010, infoPtr=0x7fff23441280, envPtr=0x7fff23441320)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:438
#19372 0x00007f001af8b39e in TclCompileExpr (interp=0x604090, 
    script=0x72de30 "double(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1"..., numBytes=65543, envPtr=0x7fff23441320)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclCompExpr.c:266
#19373 0x00007f001af9b3f7 in Tcl_ExprObj (interp=0x604090, objPtr=0x6142d0, resultPtrPtr=0x7fff23442100)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclExecute.c:794
#19374 0x00007f001af9ceda in TclExecuteByteCode (interp=0x604090, codePtr=0x618940)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclExecute.c:1694
#19375 0x00007f001af9bb53 in TclCompEvalObj (interp=0x604090, objPtr=0x614690) at /home/matze/cvs/tcl-8.4/unix/../generic/tclExecute.c:1107
#19376 0x00007f001afdcdc6 in TclObjInterpProc (clientData=0x6234e0, interp=0x604090, objc=2, objv=0x608380)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclProc.c:1207
#19377 0x00007f001af6522f in TclEvalObjvInternal (interp=0x604090, objc=2, objv=0x608380, command=0x0, length=0, flags=0)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclBasic.c:3260
#19378 0x00007f001af9cbe9 in TclExecuteByteCode (interp=0x604090, codePtr=0x618680)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclExecute.c:1584
#19379 0x00007f001af9bb53 in TclCompEvalObj (interp=0x604090, objPtr=0x614810) at /home/matze/cvs/tcl-8.4/unix/../generic/tclExecute.c:1107
#19380 0x00007f001afdcdc6 in TclObjInterpProc (clientData=0x613770, interp=0x604090, objc=1, objv=0x7fff23443a20)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclProc.c:1207
#19381 0x00007f001af6522f in TclEvalObjvInternal (interp=0x604090, objc=1, objv=0x7fff23443a20, command=0x6246f1 "bum", length=3, flags=0)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclBasic.c:3260
#19382 0x00007f001af65ed2 in Tcl_EvalEx (interp=0x604090, 
    script=0x6242a0 "set i 1234567890\nset n /dev/zero\n\nproc foo {n i} {\n    set f [open $n r]\n    fconfigure $f -translation binary -buffering full -buffersize 4096\n\n    upvar #0 data($n,raw) r\n    set r \"\"\n\n    while {$i"..., numBytes=1108, flags=0)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclBasic.c:4053
#19383 0x00007f001afc07f2 in Tcl_FSEvalFile (interp=0x604090, pathPtr=0x614ed0) at /home/matze/cvs/tcl-8.4/unix/../generic/tclIOUtil.c:1776
#19384 0x00007f001afc9674 in Tcl_Main (argc=-1, argv=0x7fff234442c8, appInitProc=0x400925 <Tcl_AppInit>)
    at /home/matze/cvs/tcl-8.4/unix/../generic/tclMain.c:295
#19385 0x000000000040091e in main (argc=2, argv=0x7fff234442b8) at /home/matze/cvs/tcl-8.4/unix/tclAppInit.c:90

I do not need a fix here, as there is a very simple workaround that is also a lot faster. And it doesn't happen in 8.5, so I propose to leave it for documentation ...

-- Matthias Kraft
User Comments:
dgp added on 2009-02-01 08:11:18:
probably connected to 903765.

matzek added on 2009-02-01 22:22:14:
Actually thats both 903765 and 906201. The latter is marked as Fixed, but Group is 8.5a4, while the report talks about 8.4 ... and it is not fixed for 8.4. But looking into the code I fear that there is no such thing that could be called a Fix - looks as it would need a complete rewrite. Which is also mentioned in the commentary of the referenced bug reports. And the rewrite has been done for 8.5. I'll take it that there is no easy back port ...

-- Matthias Kraft

dgp added on 2009-02-01 22:36:37:
Right.  This is a dup of 906201.
Won't Fix for 8.4.

dgp added on 2009-02-01 22:36:38:

allow_comments - 1