Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-11-02
08:20 • Closed ticket [218530ffff]: dynamical linking in standalone executables plus... artifact: 6026fd5ce2 user: dgp
2001-04-16
21:07 • Ticket [218530ffff]: 3 changes artifact: efb41f3097 user: dgp
2000-10-26
08:24 • Closed ticket [218530ffff]. artifact: e357d31bd4 user: welch
01:01 • New ticket [218530ffff]. artifact: 1f466d6e80 user: nobody

dynamical linking in standalone executables

Closed / Fixed218530ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 25 years ago
Descriptionplain2000-10-26 01:01:46
OriginalBugID: 913 Bug
Version: 8.0.3
SubmitDate: '1998-12-04'
LastModified: '1999-04-16'
Severity: LOW
Status: Released
Submitter: welch
ChangedBy: stanton
OS: Windows NT
OSVersion: NT4.0 SP3
Machine: X86
FixedDate: '1999-04-16'
FixedInVersion: 8.1b3
ClosedDate: '2000-10-25'


Name:
Jan Nijtmans

CustomShell:
plus-patch. But because this problem is

ReproducibleScript:
- produce a standalone executable on
  a system which doesn't support
  backlinking (e.g. Windows 95/98/NT).
  (I did this with the plus-patch, but
  since this problem is generic I am
  sure that the TclPro wrapper has
  the same problem)
- dynamicaly load any extension
  (e.g. "package require Tix")

ObservedBehavior:
Unhandled exception. The stack trace
in the above described case looks like (although I doubt it is useful)

TK80! 00cafaa2()
TIX4180! 10019d92()
WISH80S! 0040e097()
WISH80S! 0043f879()
WISH80S! 0040e966()
WISH80S! 0040e72f()
WISH80S! 0040fc0c()
WISH80S! 004133f5()
WISH80S! 0041322a()
WISH80S! 00413a1e()
WISH80S! 0040e097()
WISH80S! 0043f879()
WISH80S! 0040e966()
WISH80S! 0040fc3c()
WISH80S! 00413103()
WISH80S! 00412ff3()
WISH80S! 00401941()
WISH80S! 0040e097()
WISH80S! 0043f879()
WISH80S! 0040e966()
WISH80S! 0041fbcb()
WISH80S! 0043f879()
WISH80S! 0040e966()
WISH80S! 0040e72f()
WISH80S! 0040fc0c()
WISH80S! 004787f0()
WISH80S! 004678fd()
WISH80S! 0044bb61()
WISH80S! 0044be36()
WISH80S! 0041a9ff()
WISH80S! 0041ac9d()
WISH80S! 0044bea0()
WISH80S! 004010b8()
WISH80S! 00402146()
KERNEL32! 77f1b304()

DesiredBehavior:
nice error message: "Cannot load package in statically linked executable", or something like that.
The patch below is able to catch
this kind of error, before anything
bad happens. (The same can happen
with any global variable in tcl.dll
or tk.dll, but tclEmptyStringRep is
the easiest to check for). I tested
this on Windows NT4/SP3.

Patch:
*** generic/tclPkg.c.origThu Apr 02 00:39:49 1998
--- generic/tclPkg.cTue Nov 17 15:29:57 1998
***************
*** 150,155 ****
--- 150,173 ----
      Tcl_DString command;

      /*
+      *  Test if global variables are correctly initialized. If not,
+      *  the only explanation is that we are trying to load a binary
+      *  package into a statically linked executable on a system
+      *  which doesn't support backlinking (e.g. Windows, AIX). In
+      *  that case there are two global variables "tclEmptyStringRep":
+      *  one in the static executable and one in the shared Tcl
+      *  library. If we are addressing the wrong one here (and that
+      *  is what happens if we try dynamical loading), it's better
+      *  to produce a nice error message, than having a crash later.
+      */
+ 
+     if (!tclEmptyStringRep) {
+         Tcl_AppendResult(interp, "Cannot load package \"", name, 
+                 "\" in statically linked executable", NULL);
+         return NULL;
+     }
+ 
+     /*
       * It can take up to three passes to find the package:  one pass to
       * run the "package unknown" script, one to run the "package ifneeded"
       * script for a specific version, and a final pass to lookup the

PatchFiles:
tclPkg.c



Explanation how this solution works:
If the system doesn't support backlinking, there are two global variables "tclEmptyStringRep": one in the static executable and one in the shared Tcl library. If the function
Tcl_PkgRequire() (which is usually
the first function in the extension)
is executing in a only partly
initialized dll, that is asking for
trouble.

On AIX it is currently impossible to do this, because --disable-load is coupled with --enable-shared. With this change, it would be possible to remove this coupling: There will still an error
message be generated if the used tries
to do dynamical loading.

(B.T.W, it is possible to produce libraries which can be dynamically loaded on AIX in statically linked executables. Paul Duffin is working on that, with very good results)

This is incorporated by the stubs patches.
04/16/1999 14:44 - stanton -
welch Closed ticket [218530ffff]. [History diff]2000-10-26 08:24:12
dgp Ticket [218530ffff]: 3 changes [History diff]2001-04-16 21:07:33
dgpplain2001-11-02 08:20:54
Logged In: YES 
user_id=80530

Moving this from Closed to Pending so I can get
some feedback from Jan Nijtmans on it.

As reported in Bug 476537

http://sf.net/tracker/?func=detail&aid=476537&group_id=10894&atid=110894

the patch in Bug Report 218530 has a problem (that may have
arisen long after the patch was accepted) that when
tclEmptyStringRep is invalid, the call to
Tcl_AppendResult() will panic.

Since I'm working on a fix for that problem anyway, I want
to also update the comment describing the check so that
programmers other than Jan Nijtmans and Paul Duffin can
understand it!  Bug Report 218530 contains more detail,
so I'm understanding it better.  I can see how two copies
of a global variable can exist within the executable on
a platform without backlinking support, but there are two
things I don't understand

1) What does it mean for a DLL to be "partially
initialized"?  

2) How can it be that Tcl_PkgRequireEx() is referencing the
wrong (uninitialized) tclEmptyStringRep variable?  When
Tcl_InitStubs(interp,version,exact) is called, the
stubs pointer from interp is the one used to look
up Tcl_PkgRequireEx, so both ought to be coming from 
the original executable.  How is it that the 
Tcl_PkgRequireEx() in the original executable is
somehow seeing an uninitialized tclEmptyStringRep, 
presumably from the improperly-stub-enabled shared
library?

I await enlightenment from Jan Nijtmans, or anyone
else who wants to volunteer.
Log in (anonymous is fine) to add a comment.