Skip to content
Tcl Source Code View Ticket
Login

View Ticket

A bug in Tcl 64bit libraries

Closed / Invalid0f14b45adc1932e4f9fbe0ad03777c13a09809b2Created 12 years agoUpdated 12 years ago
Descriptionplain2014-10-07 05:53:15
I was trying to compile an open source program on windows 64bit. the program needs at least 64bit TCL libraries so I have build tcl85 static and dynamic libraries. And seems to work ok. Then I compiled my program which was also ok during compile time with no error or warning . I created the executables and when I try to run my program the program crashes in startup at a Tcl_SetVar statement with memory access violation error. I have put a zip file of the debugable executable here: 

http://gpiutmd.iut.ac.ir/vmd/MYVMD.rar

for reproducing the error you should extract the rar file to an empty folder (it was originally on C:\temp\MYVMD in my computer) and run the vmd_WIN64.exe. it has the required pdb files for debugging.

I compiled the program using a 64bit VS2008 with the latest updates and service pack, and tried to fix the error about 1 week but no chance. The only thing I guess is making the problem is the assembly translation of the code which I think is making the problem (maybe there is a bug in VS2008 compile optimization which in my opinion makes a pointer problem). any help would be appreciated.

BTW If anyone thinks I should download the ready and compiled libraries of TCL 8.5 from tcl.tk instead of making them myself I should say, I have done this and the same problem persists. I also guess that I should try to build the TCL with a special kind of compiler flag to disable optimization but I don't know how I should do that in its windows makefile.vc, if my previous guess is right. And also most important to this, the very same program works fine with 32bit compilation (also 32bit tcl). I have checked it.

Please help me (of course in detail) what should I do?
cheers
ekd123plain2014-10-07 12:17:58
Tested on Win 8.1 x64.

Output:
Failed to find registry key in 64-bit registry.
Falling back in desparation for 32-bit registry key...
Complete and total failure finding any usable registry key.
Guessing VMD location from default 32-bit install directory
Failed to find registry key.

Backtrace:
>	vmd_WIN64.exe!TclTextInterp::TclTextInterp(VMDApp * vmdapp, int guienabled, int mpienabled) Line 155	C++
 	vmd_WIN64.exe!UIText::UIText(VMDApp * vmdapp, int guienabled, int mpienabled) Line 78	C++
 	vmd_WIN64.exe!VMDApp::VMDinit(int argc, char * * argv, const char * displaytype, int * displayLoc, int * displaySize) Line 435	C++
 	vmd_WIN64.exe!main(int argc, char * * argv) Line 49	C++
 	vmd_WIN64.exe!__tmainCRTStartup() Line 266	C
 	vmd_WIN64.exe!mainCRTStartup() Line 182	C

Debugger recognized an access to NULL.
dgpplain2014-10-07 13:53:01
If the problem has been isolated to a Tcl_SetVar() call,
then copy and paste that call and all relevant code nearby,
such as that code that controls the state of the arguments
passed in to it.

You say the crash is at startup.  Does your program successfully
call Tcl_FindExecutable() ?  How about Tcl_Init() ?  These are
things embedders often overlook.
dgpplain2014-10-07 14:08:15
It might also help if you report precisely what
Tcl sources you are using.  A URL is the best
identifier.
dgpplain2014-10-07 14:12:05
Is there any chance that this call to Tcl_SetVar() passes the
TCL_APPEND_VALUE flag?  If so, please see the Tcl 8.5.16
release notes and http://core.tcl.tk/tcl/tktedit?name=7368d225a6
anonymousplain2014-10-07 14:26:57
Hi every body and thanks for the replies.
I forget to add the source files. I am sorry.

you can download the source files from:
http://gpiutmd.iut.ac.ir/vmd/vmd.rar

the source contents was originally on this folder (c:\temp\VMD\vmd) on my computer.
I should add you can find the file TclTextInterp.C in the src folder.
the app crashes at line 155.

The registry errors are not really important. you can silent them by adding this registry (also note to use your own path to the vmd_WIN64.exe):

[HKEY_LOCAL_MACHINE\SOFTWARE\University of Illinois\VMD\1.9.2]
"VMDDIR"="C:\\Temp\\MYVMD"

I am currently working on your responses.
many thanks in advance.
anonymousplain2014-10-07 14:30:10
Hi every body and thanks for the replies.
I forget to add the source files. I am sorry.

you can download the source files from:
http://gpiutmd.iut.ac.ir/vmd/vmd.rar

the source contents was originally on this folder (c:\temp\VMD\vmd) on my computer.
I should add you can find the file TclTextInterp.C in the src folder.
the app crashes at line 155.

The registry errors are not really important. you can silent them by adding this registry (also note to use your own path to the vmd_WIN64.exe):

[HKEY_LOCAL_MACHINE\SOFTWARE\University of Illinois\VMD\1.9.2]
"VMDDIR"="C:\\Temp\\MYVMD"

I am currently working on your responses.
many thanks in advance.
anonymousplain2014-10-07 14:34:51
And also the TCL source I used:

http://prdownloads.sourceforge.net/tcl/tcl8516-src.zip
dgpplain2014-10-07 16:27:23
So what specifically goes wrong on line 155?

Is something invalid about the value app->argv_m[0] ?
anonymousplain2014-10-07 19:38:54
The question is as you said.
The app->argv_m[0] has no problem. In debug mode it has a value (which is the path to where VMD had been run from) it is also a const char * , and when you look at the disassembly you see that the register is destroying itself. I'm not an experienced programmer but I think there is a problem with VS2008 utilizing TCL libraries or vice versa. I fyou think the problem is somewhere else please explain it more. Thanks a lot
dgpplain2014-10-08 02:56:28
Precisely what are all the arguments to Tcl_SetVar()
when it fails?

Do not refer me to debuggers.  I am not on your platform.
anonymousplain2014-10-08 11:10:06
Hi again

The exact statement:
Tcl_SetVar(interp, "argv0", app->argv_m[0], TCL_GLOBAL_ONLY);

interp is an interpreter initialized in previous lines and its pointers and values are valid.

app->argv_m[0] is a const char * with the following text value it points to:
"C:/temp/MYVMD/vmd_WIN64.exe"

and as I have told you before there is no problem to the app->argv_m[0] pointer or its value.
dgpplain2014-10-08 11:48:27
Is there any regression information that might
help?  As in, does this same code build and
run successfully with other releases of Tcl?

If your speculation is correct that this
is really the effects of a broken toolchain,
there's only so much that we can do.

I think I've reached the end of what I can do.
Leaving the ticket open for some other
dev to pick up.
apnadkarniplain2014-10-08 16:58:03
I believe that you are compiling your modules with different preprocessor flags (nothing to do with Tcl).

Stepping through the disassembled code (will not be visible at  C level) of TclTextInterp::TclTextInterp, the offset to argv_m member in the object is 0x68. This value is NULL and hence the crash.

The initialization of argv_m happens in VMDApp::VMDApp where it is initialized at offset 0x60 (NOT 0x68). Looking at the definition of the VMDApp class, there are a couple of #defines wrapping members. My guess is one of these is not defined when you are compiling VMDApp but defined for TclTextInterp. Hence the inconsistency.

Do not look at the debugger symbol values. Those assume compilation with consistent flags and hence will not show true state. Look at the actual memory dump.

BTW, if you look at the contents of argcbuf[] a few lines before the crash, you will see a bogus value has been sprintf'ed into the buffer for the same reason.

/Ashok
anonymousplain2014-10-10 11:45:33
Thanks for your analysis.
That was my fault. The problem was the compiling flags.
Cheers
jan.nijtmans Ticket [0f14b45adc]: 5 changes [History diff]2014-10-10 12:08:05
Log in (anonymous is fine) to add a comment.