Skip to content
Tcl Source Code View Ticket
Login

View Ticket

segfault in obj-34.1

Closed / Fixed6eb8d79cb86f8a16d14a191e5871a3e6672d7a21Created 3 years agoUpdated 3 years ago
Descriptionplain2024-04-22 15:44:29
(gdb) run ../tests/obj.test -match obj-34.1 -verbose bpste
...
---- obj-34.1 start

Program received signal SIGSEGV, Segmentation fault.
0x000000000042676f in TestbignumobjCmd (dummy159=0x0, interp=0x8f2870, objc=4, 
    objv=0x8f7658) at /home/dgp/fossil/tcl8.7/generic/tclTestObj.c:197
197             if (mp_init(&bignumValue) != MP_OKAY) {
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64 zlib-1.2.7-21.el7_9.x86_64
(gdb) bt
#0  0x000000000042676f in TestbignumobjCmd (dummy159=0x0, interp=0x8f2870, 
    objc=4, objv=0x8f7658) at /home/dgp/fossil/tcl8.7/generic/tclTestObj.c:197
#1  0x00000000004359ab in Dispatch (data=0x9e0108, interp=0x8f2870, 
    dummy4913=0) at /home/dgp/fossil/tcl8.7/generic/tclBasic.c:4951
#2  0x0000000000435a39 in TclNRRunCallbacks (interp=0x8f2870, result=0, 
    rootPtr=0x0) at /home/dgp/fossil/tcl8.7/generic/tclBasic.c:4991
#3  0x000000000043519b in Tcl_EvalObjv (interp=0x8f2870, objc=6, 
    objv=0x8f6b60, flags=2097168)
    at /home/dgp/fossil/tcl8.7/generic/tclBasic.c:4710
#4  0x0000000000437b94 in TclEvalEx (interp=0x8f2870, 
    script=0x99e4f0 "# Functionality covered: this file contains a collection of tests for the\n# procedures in tclObj.c that implement Tcl's basic type support and the\n# type managers for the types boolean, double, and in"..., 
    numBytes=22788, flags=0, line=582, clNextOuter=0x0, 
    outerScript=0x99e4f0 "# Functionality covered: this file contains a collection of tests for the\n# procedures in tclObj.c that implement Tcl's basic type support and the\n# type managers for the types boolean, double, and in"...)
    at /home/dgp/fossil/tcl8.7/generic/tclBasic.c:5868
#5  0x000000000056b2d8 in Tcl_FSEvalFileEx (interp=0x8f2870, pathPtr=0x93ea90, 
    encodingName=0x64707c "utf-8")
    at /home/dgp/fossil/tcl8.7/generic/tclIOUtil.c:1794
#6  0x0000000000578250 in Tcl_MainEx (argc=-1, argv=0x7fffffffcea8, 
    appInitProc=0x410210 <Tcl_AppInit>, interp=0x8f2870)
    at /home/dgp/fossil/tcl8.7/generic/tclMain.c:404
#7  0x0000000000410209 in main (argc=6, argv=0x7fffffffcea8)
    at /home/dgp/fossil/tcl8.7/unix/tclAppInit.c:94
Referenced by3
dgpplain2024-04-22 15:49:33
Problem showed up with the TIP 648 implementation.
jan.nijtmanswiki2024-04-22 16:05:16

Yes, I'm aware of it. Working on it ....

jan.nijtmanswiki2024-04-22 16:30:49

Fixed [here]

apnadkarnimarkdown2024-04-23 02:41:10

Question from an extension writer's perspective - does an extension also need to call Tcl_TomMath_InitStubs (if it uses tommath routines) ?

If so, how does it know if Tcl was built with TCL_WITH_EXTERNAL_TOMMATH or not?

/Ashok

apnadkarniplain2024-04-23 02:43:16
OT: Curiously, the ticket summary above shows Closed by: apnadkarni. I am pretty sure I did not change the Status field in my previous edit.
jan.nijtmanswiki2024-04-23 05:46:16

> does an extension also need to call `Tcl_TomMath_InitStubs` (if it uses tommath routines)

The extension needs to call `Tcl_TomMath_InitStubs` if it included `<tclTomMath.h>` (Method 1). It doesn't need to call `Tcl_TomMath_InitStubs` if it includes `<tommath.h>` (Method 2, but the it has to link with the libtommath library itself, `-ltommath`). The extension can freely choose what it wants.

The disadvantage of Method 2 is that the extension loses 8.6-compatibility. Therefore I guess most most extensions will continue to use Method 1.

apnadkarnimarkdown2024-04-23 06:45:45

Tx for clarifying but that raises another question. Will there be any issues if Tcl is built using its own libtommath (or libtommath.dll on Windows) and the extension uses the system libtommath? Or vice versa?

I've taken the liberty of adding your comment to the migration wiki page

jan.nijtmanswiki2024-04-23 08:52:08

> Will there be any issues ...

The thing to watch for is 2 different libtommath's in the same process. If Tcl is built with an external libtommath that cannot happen. If the extension is using stubs that cannot happen. But if Tcl uses its internal libtommath, and the extension uses an external libtommath, that's when problems should be expected.

1) The internal and external libtommath could be compiled differently, MP_32BIT vs MP_64BIT.

2) And they can use different allocators (ckalloc vs malloc). Exchanging mp_int's between the two library will give unexpected results.

Log in (anonymous is fine) to add a comment.