Tcl Source Code

View Ticket
Login
Ticket UUID: 3459659
Title: tclsh85sg crashes in BaseThreadInitThunk
Type: Bug Created on: 2011-12-14 19:23:46
Submitter: tombert Assigned to: andreas_kupries
Subsystem: 49. Threading Severity:
Priority: 5 Medium Last modified: 2011-12-17 01:05:27
Status: Closed Closed by: tombert
Resolution: Invalid Closed on: 2011-12-16 18:05:27
Version: None
Description:
Compiling Tcl 8.5.11 trunk with MinGW, gcc 4.6.1, Win7 32bit causes tcl to crash on exit:

catched with dr. mingw:

tclsh85sg.exe caused an Access Violation at location 004a1d4e in module tclsh85sg.exe Reading from location ffffffff.
Registers:
eax=0180cb68 ebx=00000051 ecx=00000000 edx=004a1d4e esi=0000002b edi=00000003
eip=004a1d4e esp=0022e69c ebp=0022e878 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

Call stack:
004A1D4E  tclsh85sg.exe:004A1D4E
00473926  tclsh85sg.exe:00473926
004CDF57  tclsh85sg.exe:004CDF57
004CCA0B  tclsh85sg.exe:004CCA0B
004749B8  tclsh85sg.exe:004749B8
0049CBC7  tclsh85sg.exe:0049CBC7
00472A03  tclsh85sg.exe:00472A03
004716DE  tclsh85sg.exe:004716DE
00471857  tclsh85sg.exe:00471857
0046C093  tclsh85sg.exe:0046C093
0046BA7E  tclsh85sg.exe:0046BA7E
0046BB23  tclsh85sg.exe:0046BB23
00434EF9  tclsh85sg.exe:00434EF9
0043536B  tclsh85sg.exe:0043536B
0043544C  tclsh85sg.exe:0043544C
00436990  tclsh85sg.exe:00436990
00436864  tclsh85sg.exe:00436864
00445C6B  tclsh85sg.exe:00445C6B
0040202C  tclsh85sg.exe:0040202C
00401404  tclsh85sg.exe:00401404
004010B9  tclsh85sg.exe:004010B9  __mingw_CRTStartup  crt1.c:244

00401284  tclsh85sg.exe:00401284  WinMainCRTStartup  crt1.c:274

7675ED6C  kernel32.dll:7675ED6C  BaseThreadInitThunk
770337F5  ntdll.dll:770337F5  RtlInitializeExceptionChain
770337C8  ntdll.dll:770337C8  RtlInitializeExceptionChain


To reproduce:
Compile 8.5.11 trunk with latest mingw in Win7 with compiler switches:
--enable-threads --enable-symbols --disable-shared

start the shell tclsh85sg.exe
and then type "exit" and enter - the application crashes.

My original trackers are these:
https://sourceforge.net/tracker/?func=detail&aid=3448556&group_id=10894&atid=110894
https://sourceforge.net/tracker/?func=detail&aid=3454495&group_id=516797&atid=2100300

But with disabled-shared I'am able to crash with tcl only.

I assume that this is the cause of all other issues.

thx
User Comments:
nijtmans added on 2011-12-15 15:27:38:
Tried to reproduce this:
- On Windows 7 with VS2010, no crash
- On Windows XP with latest mingw and with latest mingw-w64: no crash.

Could you try this with gdb, maybe we get some symbols then.
When I do that, I get no crash, so the question is:
- what are you doing differently?
- Is this Windows 7 specific?
Using gdb on Windows XP with latest mingw:

$ cd C:/localdata/workspace/tcl8.5/win
$ gdb ./tclsh85sg.exe
GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from c:\localdata\workspace\tcl8.5\win\tclsh85sg.exe...done.
(gdb) run
Starting program: c:\localdata\workspace\tcl8.5\win\tclsh85sg.exe
[New Thread 3228.0x19c]
[New Thread 3228.0x108]
[New Thread 3228.0x1190]
% exit
[New Thread 3228.0x838]
[Inferior 1 (process 3228) exited normally]
(gdb) quit
$

tombert added on 2011-12-15 20:20:20:
Unfort. the above described crash I can't reproduce any more ... don't know how I did that!?

But I've got some other good news: I think I finally found the problem:
I was using pgtclng with the following package script (which comes with the source code):

proc Pgtcl__load_with_path {dir} {
  global env
  set save_path $env(PATH)
  append env(PATH) ";$dir"
  load [file join $dir libpgtcl.dll]
  set env(PATH) $save_path
}
package ifneeded Pgtcl 2.0.0 [list Pgtcl__load_with_path $dir]

In order to get it working I copied all the needed dlls into the pgtclng folder (i.e. libpq.dll, msvcr71.dll, ... = all dlls from the postgres bin directory).
Now loading the pgtcl package goes fine, but exiting gave me the error 0x3=ERROR_PATH_NOT_FOUND (http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx)

Copying all the dlls into the tcl bin directory I didn't have the problem. So for me it looks like I was fooled by the windows dll late binding feature.(http://blogs.msdn.com/b/davidklinems/archive/2006/11/27/what-is-late-binding.aspx)

For the moment I assume that all this was causing my postgres thread to crash (because it didn't find a missing dll while exiting). Also it's possible (or at least I hope so) that this was causing my more fatal segmentation faults ... but time will tell.

Currently I'am trying to build postgres from scratch to get static libraries

thx

tombert added on 2011-12-17 01:05:27:

allow_comments - 1

I'am closing this one as I think this was related to my other findings in pgtclng.
Still having other "problems" but opened separate trackers:
https://sourceforge.net/tracker/?func=detail&aid=3461051&group_id=10894&atid=110894
https://sourceforge.net/tracker/?func=detail&aid=3461049&group_id=10894&atid=110894