Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-09-18
00:43 • Closed ticket [2860233fff]: Calling Tcl_FindCommand() from a shared lib segfault... artifact: 0c1c2c4651 user: dgp
00:22 • Open ticket [2860233fff]. artifact: f8bdff0883 user: eriklns
2009-09-17
05:27 • Pending ticket [2860233fff]. artifact: 2c7f8047bc user: dgp
02:45 • Ticket [2860233fff]: 4 changes artifact: 339494d970 user: eriklns
02:45 • Add attachment tclsh8.4g.png to ticket [2860233fff] artifact: f5604105e0 user: eriklns
02:43 • Add attachment gdb_backtrace.txt to ticket [2860233fffffffff|2860233fff... artifact: dcb01766a9 user: eriklns
02:43 • Ticket [2860233fff] Calling Tcl_FindCommand() from a shared lib segfaults st... artifact: ddcfb7c3ea user: eriklns
02:42 • Ticket [2860233fff]: 4 changes artifact: 9dab2e51c9 user: eriklns
02:42 • Add attachment build to ticket [2860233fff] artifact: 4b97dd8a23 user: eriklns
02:41 • Ticket [2860233fff] Calling Tcl_FindCommand() from a shared lib segfaults st... artifact: e6e9fee117 user: eriklns
02:41 • Add attachment fc.c to ticket [2860233fff] artifact: ef796d4b02 user: eriklns
2009-09-16
19:41 • New ticket [2860233fff] Calling Tcl_FindCommand() from a shared lib segfaults</i... artifact: 87c654b159 user: eriklns

Calling Tcl_FindCommand() from a shared lib segfaults

Closed / Invalid2860233fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-09-16 19:41:02
Observed
--------
Tcl8.4 segfaults when calling Tcl_FindCommand() from a stubs enabled shared object.

The segfault occurs at the assembler instruction "call", and the program never makes it into the function. At the moment of the call instruction, the cpu register that holds the memory location to which the call is made, holds the value 0x0.

Running the code from the same shared lib in tclsh8.5 (8.5.7) does not exhibit the problem.

System specification:

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine)   = i686
tcl_platform(os)        = Linux
tcl_platform(osVersion) = 2.6.18.8-0.13-default
tcl_platform(platform)  = unix
tcl_platform(user)      = erik
tcl_platform(wordSize)  = 4
% set tcl_patchLevel
8.4.19


How to reproduce
----------------
Attached to this report is the code for a Tcl extension that registers a new command "findcommand" in file fc.c. Also attached is the build script to produce the shared lib "fc.so". Assuming the completion of the build, you simply do:

> tclsh8.4
% load ./fc.so
% findcommand whatever
Segmentation fault (core dumped)


Preliminary analysis
--------------------

A. ddd inspection
Attached you find a screendump from the ddd debugger, showing:
- a breakpoint at the line in the C code where the call to Tcl_FindCommand is made
- the assembler instructions from that breakpoint up to the call instruction which fails.
- the cpu registers just before the call instruction.
Note the 0x0 value in the edx register.

B. backtrace from core dump: see attached file gdb_backtrace.txt


Preliminary interpretation
--------------------------
Since Tcl itself has calls to Tcl_FindCommand all over the place without them giving cause to complain, there must be something out of the ordinary. Maybe an issue with the stubs interface?
eriklnsplain2009-09-17 02:41:03
File Added - 343243: fc.c
eriklnsplain2009-09-17 02:42:33
File Added - 343244: build
eriklnsplain2009-09-17 02:43:27
File Added - 343245: gdb_backtrace.txt
eriklnsplain2009-09-17 02:45:12
File Added - 343246: tclsh8.4g.png
dgpplain2009-09-17 05:27:09
I suspect you compiled your code against Tcl 8.5
(or later) header files, then tried to [load] into a
Tcl 8.4 interp.  That does not work.

Compile against the header files of the earliest
version you wish to support [load]ing into.
eriklnsplain2009-09-18 00:22:55
You are right.
The header file was picked up from the system-installed include directory, which held header files of tcl8.5 .

Invalid issue indeed.

Sorry for the noise.
dgpplain2009-09-18 00:43:16
allow_comments - 1


One way to help catch such things is to use

    Tcl_InitStubs(interp, TCL_VERSION, 0);

so that your extension will demand at the
time it is [load]ed to have a Tcl interp at least
as new as the headers it was compiled against.
When that fails, a [load] error is more useful
than a crash.
Log in (anonymous is fine) to add a comment.

Attachments: