Skip to content
Tcl Source Code View Ticket
Login

View Ticket

gcc compiled Tcl library needs libgcc

Closed / Out of Date541181ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 19 years ago
Descriptionplain2002-04-08 19:54:33
CC -ptr./solaris -staticlib=Crun solaris/omfsh.o
-L../../pkg/if/solaris -lif -L../../pkg/nb/solaris -lnb
-L../../pkg/oc/solaris -loc
-L/home/fs3c/dgp/sparc/solaris2/lib -ltk8.4
-L/home/fs3c/dgp/sparc/solaris2/lib -ltcl8.4
-L/usr/openwin/lib -lX11 -ldl -lsocket -lnsl -lm -o
solaris/omfsh
Undefined                       first referenced
 symbol                             in file
__ashldi3                          
/home/fs3c/dgp/sparc/solaris2/lib/libtcl8.4.so
__ashrdi3                          
/home/fs3c/dgp/sparc/solaris2/lib/libtcl8.4.so
__floatdidf                        
/home/fs3c/dgp/sparc/solaris2/lib/libtcl8.4.so
ld: fatal: Symbol referencing errors. No output written
to solaris/omfsh
dgpplain2002-04-09 02:57:40
Logged In: YES 
user_id=80530

These symbols seem to come in due to generic/tclExecute.c.
dgpplain2002-04-09 03:26:50
Logged In: YES 
user_id=80530

I traced the problem to a compiler/linker mismatch.

The Tcl library was compiled with gcc, but the program
that embeds Tcl was compiled with the Sun Workshop
compiler.  That difference seems to cause the trouble.
When I compiled both with the Sun compiler, everything
worked fine.

So, I do have a workaround, but it seems to me that 
compiler matching should not be necessary.  That is,
the shared libraries produced by Tcl's build process
ought to be able to be linked into programs using any
compiler -- at least on reasonable operating systems...
msoferplain2002-04-26 19:50:08
Logged In: YES 
user_id=148712

I don't even know where to start looking; anybody to whack
me with a big clue-by-four?
andreas_kupriesplain2002-04-26 23:47:54
Logged In: YES 
user_id=75003

The missing thing could be that the tcl library was not 
linked against -lgcc, i.e. the gcc support library.
dgpplain2002-04-27 02:25:45
Logged In: YES 
user_id=80530

Perhaps, but if additional libraries are required for
successful static linking against the Tcl library,
those libraries should be part of the TCL_LIBS
definition in tclConfig.sh.
dgpplain2002-04-27 02:31:36
Logged In: YES 
user_id=80530

Tracing futher, it appears the root of the trouble
is the #include <float.h>.  Why does tclExecute.c
need that header file?
andreas_kupriesplain2002-04-27 02:58:15
Logged In: YES 
user_id=75003

Bytecompiled expressions ?
msoferplain2002-04-27 03:02:36
Logged In: YES 
user_id=148712

Beats me; commenting out lines 20-24 compiles OK and passes
the test suite on linux.
dgpplain2002-04-27 03:30:20
Logged In: YES 
user_id=80530

ditto on Soaris 8
msoferplain2002-04-27 05:09:40
Logged In: YES 
user_id=148712

Those #include are in since the very first version on SF
(1.1); what's more, compat/float.h has been empty since
those days too! So: what is actually the point of

#ifdef NO_FLOAT_H
#   include "../compat/float.h"
#else
#   include <float.h>
#endif

Also, unix/tclUnixPort.h includes <float.h> to define
FLT_MAX (used in generic/tclBinary.c) and FLT_MIN (unused);
if float.h is not available, it tries <values.h>; if that is
not available either, it defines default values that almost
coincide with what I find in my
/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/float.h

Note that FLT_MAX is only used in [binary format], to
represent too-large single-precision floats.

So: what is really the point of <float.h> in tcl?
Note: win/tclWinPort.h also includes <float.h>.
msoferplain2002-06-05 01:57:14
Logged In: YES 
user_id=148712

We could safely eliminate <float.h> everywhere in the unix
branch if we make sure that FLT_MAX is defined properly in
unix/tclUnixPort.h.

I do not really know what a good generic definition for
FLT_MAX would be. I wonder if the default defined in
unix/tclUnixPort.h is OK for all platforms or it is just a
"safe" default.

Donal: do you know?
dkfplain2002-06-07 16:18:28
Logged In: YES 
user_id=79902

Well, I've tried examining what the various definitions for
FLT_MAX (and DBL_MAX) are on various platforms
(Solaris/SPARC, Linux/ix86, and IRIX64 in both 32bit and
64-bit mode) and all report the same values:
FLT_MAX=3.4028234663852886e+38
DBL_MAX=1.7976931348623157e+308

Examining the code, so long as "tclPort.h" is #included, we
don't need to explicitly #include <float.h> anyway.  But
tclExecute.c is somewhat bizarre here.  Will have a go at
fixing it anyway.
dkfplain2002-06-07 17:42:48
Logged In: YES 
user_id=79902

OK, I think tclExecute.c is now right; any faults now are
probably to do with the build system and/or not running
configure and/or something else which I don't understand.

(Doesn't mean I understand what those error messages really
are though! :^))
dgpplain2002-06-27 03:36:07
Logged In: YES 
user_id=80530

Re-opening this.  I'm seeing the same problem with
the 8.4b1 sources.  Investigating...
dgpplain2002-06-27 12:06:59
Logged In: YES 
user_id=80530

The missing symbols are routines supplied by
gcc for doing math on "long long" values.
The implementation of these routines is 
in libgcc.a, so the linking of the embedding
application can be completed by adding
that library to those linked, as Andreas
suggested before.  Note that I see this
problem with both gcc-2.95.2 and gcc-3.0.3.
It is a new problem because of new
"long long" code within Tcl, not because
of a change in compiler.

So, one approach to fix this would be to
see that the appropriate -L... -lgcc options
get added to the TCL_LIBS value in
tclConfig.sh.  Another might be to require
embedders to use the TCL_CC compiler
recorded in tclConfig.sh.

Neither of those is really a satisfactory 
answer though, because it requires the
embedder to use the same toolset as
the library builder.  It would be better if
the binary Tcl and Tk libraries could be
distributed in a binary distribution for
embedding into applications possibly by a
different toolset.

So, it would be best to find some options
to pass to the linker during the construction
of libtcl8.4.so that force it to pull the 
math support code out of libgcc and put
it directly into libtcl8.4.so.  (I'm assuming
that libgcc is LGPL).  Anyone know
linker options well enough to proceed
along that path?
dkfplain2002-06-27 15:33:29
Logged In: YES 
user_id=79902

Linker options are not my specialty.
dkfplain2002-06-27 17:17:28
Logged In: YES 
user_id=79902

However, building with SunPro cc on Solaris should produce
code that doesn't require these functions.
dgpplain2002-06-27 22:40:47
Logged In: YES 
user_id=80530

Yes, of course.  But that answer translates
to "you cannot use gcc to build a binary
distro of Tcl".  The root of the problem
is probably bad design choices in gcc,
but if we can work around them it would
be a good idea.
dgp Ticket [541181ffff]: 1 change [History diff]2002-06-28 02:18:22
dgpplain2002-06-28 02:56:27
Logged In: YES 
user_id=80530

OK, the linker options required are just
to include libgcc among the items
linked together to produce the
Tcl shared library.  I achieved
success adding the appropriate
-L... -lgcc to the MATH_LIBS,
but that's not the right solution
within the Makefile architecture.
Can someone advise the better
way?
dgpplain2002-06-29 03:51:53
Logged In: YES 
user_id=80530

It appears that what must change is
what gets run during the
${TCL_LIB_FILE} target.  The key
line is

    ${SHLIB_LD} -o $@ ${OBJS} ${LIBS}

Perhaps {SHLIB_LD} needs to be some kind
of invocation of gcc rather than /usr/ccs/bin/ld ?

Or perhaps LIBS needs to include -L... -lgcc,
but somehow, keep those additions out of
the TCL_LIBS variable in tclConfig.sh
rmaxplain2002-07-01 22:37:52
Logged In: YES 
user_id=124643

Just for completeness. It is allowed to link libgcc.a to
binaries that are not GPL, or not even open source. The C
file for libgcc.a contains a comment, that says:
        
  In addition to the permissions in the GNU General Public
License, the
  Software Foundation gives you unlimited permission to link the
  compiled version of this file into combinations with other
programs,
  and to distribute those combinations without any
restriction coming
  from the use of this file.  (The General Public License
restrictions
  do apply in other respects; for example, they cover
modification of
  the file, and distribution when not linked into a combine
  executable.
dkf Closed ticket [541181ffff]. [History diff]2002-07-01 22:45:13
dgpplain2004-11-18 01:59:19
Logged In: YES 
user_id=80530

FWIW, this problem has
shown up again on the HEAD.
dgp Ticket [541181ffff]: 1 change [History diff]2004-11-18 02:28:10
dgpplain2004-11-18 03:29:41
Logged In: YES 
user_id=80530

broken in 8.4.8 too.
dgp Ticket [541181ffff]: 1 change [History diff]2004-11-18 03:35:02
dgpplain2004-11-18 03:35:03
Logged In: YES 
user_id=80530

dropping priority.
This is an unusual, anti-recommended
configuration, and fixing it looks hard.

Just pick one compiler and use it
for all.
hobbs Pending ticket [541181ffff]. [History diff]2007-02-10 01:31:32
sf-robotplain2007-02-24 10:20:10
Logged In: YES 
user_id=1312539
Originator: NO

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
dgpplain2007-10-05 02:16:32
Logged In: YES 
user_id=80530
Originator: YES


-static-libgcc option to the gcc linker
might be a way out of this dilemma.
dgpplain2008-04-15 22:55:25
Logged In: YES 
user_id=80530
Originator: YES


Can't reproduce with 8.4.19 and
a modern Solaris/gcc combination.
sf-robotplain2008-04-30 09:20:24
Logged In: YES 
user_id=1312539
Originator: NO

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.