public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Template Instantiation
@ 1998-02-08 11:38 David Greene
  1998-02-08 18:44 ` Joe Buck
  0 siblings, 1 reply; 5+ messages in thread
From: David Greene @ 1998-02-08 11:38 UTC (permalink / raw)
  To: egcs

First off, great job with egcs!  This project is a BIG help!

Now on to the question:

Can someone clarify exactly how template instantiation
works in egcs?  I'm using x86/Linux/ELF and SPARC/Solaris 
systems.  

I've been using -frepo when linking object files.  When creating 
liraries, I've been manually instantiating templates though IIRC, 
someone mentioned that this wasn't necessary.

In the (very outdated) g++ FAQ at www.cygnus.com, I
found this passage:

   Jason Merrill writes: "To perform closure on a set of objects, just try
   to link them together. It will fail, but as a side effect all needed
   instances will be generated in the objects." 

Maybe I'm dense, but I don't understand this.  If I link object
files using -frepo, recompilation takes place and there is no
failure.  If I link using libraries, it fails, but nothing gets
generated.

I also seem to recall someone indicating that -frepo wasn't
necessary under ELF.  Is this true?  It would certainly reduce
build times.  What do I do to get everything to link correctly?

Thanks much for the help!

                                    -Dave


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Template Instantiation
  1998-02-08 11:38 Template Instantiation David Greene
@ 1998-02-08 18:44 ` Joe Buck
  1998-02-09  9:08   ` David Greene
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Buck @ 1998-02-08 18:44 UTC (permalink / raw)
  To: greened; +Cc: egcs

> Can someone clarify exactly how template instantiation
> works in egcs?  I'm using x86/Linux/ELF and SPARC/Solaris 
> systems.  

On both of these systems, it works pretty much like it does with Borland
C++.  All needed templates are instantiated in each object file, but
weak symbols are used.  At link time, one weak symbol is used as the
definition.  If you have a recent GNU ld, the duplicate definitions, if
any, get stripped out and are not included in the binary.  If you have
an older linker or are using the Solaris linker, everything works, but
your executable may contain extra copies of some functions.

> I've been using -frepo when linking object files.  When creating 
> liraries, I've been manually instantiating templates though IIRC, 
> someone mentioned that this wasn't necessary.

You're better off using no flags at all and just allowing things to work.

> In the (very outdated) g++ FAQ at www.cygnus.com,

It contains text referring to old versions as well as sections referring
to the latest version.

> I found this passage:
> 
>    Jason Merrill writes: "To perform closure on a set of objects, just try
>    to link them together. It will fail, but as a side effect all needed
>    instances will be generated in the objects." 
> 
> Maybe I'm dense, but I don't understand this.

It refers to 2.7.2.x .  The procedure is not recommended with 2.8.0 or
egcs.  The reason it worked is because -frepo attaches the instantiated
functions to the original .o files.  So if you did

	g++ -frepo *.o -o dummy

then -frepo would try to instantiate templates as needed; the link will
fail because there is no main defined.  But after that you can do

	ar qc libfoo.a *.o

to make the library, and the library will contain template expansions.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Template Instantiation
  1998-02-08 18:44 ` Joe Buck
@ 1998-02-09  9:08   ` David Greene
  1998-02-09 11:54     ` Joe Buck
  0 siblings, 1 reply; 5+ messages in thread
From: David Greene @ 1998-02-09  9:08 UTC (permalink / raw)
  To: Joe Buck; +Cc: egcs

On Sun, 8 Feb 1998, Joe Buck wrote:
 
> > Can someone clarify exactly how template instantiation
> > works in egcs?  I'm using x86/Linux/ELF and SPARC/Solaris 
> > systems.  
> 
> On both of these systems, it works pretty much like it does with Borland
> C++.  All needed templates are instantiated in each object file, but
> weak symbols are used.  At link time, one weak symbol is used as the
> definition.  If you have a recent GNU ld, the duplicate definitions, if
> any, get stripped out and are not included in the binary.  If you have
> an older linker or are using the Solaris linker, everything works, but
> your executable may contain extra copies of some functions.

This just does not work at all:

CXXFLAGS = -DDEBUG=0 -DLINUX_LIBC6 -pipe -frtti -Wno-reorder \
-Wno-unused 

I get lots and lots of undefined symbols, all of them from
templates.  I create a library with

ar -r libblah <lots of .o files here>
ranlib libblah

I know that ranlib is not realy necessary, but it shouldn't hurt
anything.  Perhaps the template code does not get generated, though 
from your passage above, I gather that it should have been generated 
when the .o files were created.  Is this true?

My system stats:

>>-drakh-> uname -a
Linux drakh.eecs.umich.edu 2.0.33 #1 Mon Feb 2 17:39:49 EST 1998 i686
unknown

>>-drakh-> g++ -v
Reading specs from
/nfs/srvrdsk1.eecs.umich.edu/t/Install/i686/Linux/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.23/specs
gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)

>>-drakh-> ar --version
GNU ar 980114
Copyright 1997 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.

>>-drakh-> ld --version
GNU ld 2.8.2
Copyright 1997 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
  Supported emulations:
   elf_i386
   i386linux

What am I doing wrong?

                                       -Dave


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Template Instantiation
  1998-02-09 11:54     ` Joe Buck
@ 1998-02-09 11:54       ` David Greene
  0 siblings, 0 replies; 5+ messages in thread
From: David Greene @ 1998-02-09 11:54 UTC (permalink / raw)
  To: Joe Buck; +Cc: egcs

On Mon, 9 Feb 1998, Joe Buck wrote:

> > CXXFLAGS = -DDEBUG=0 -DLINUX_LIBC6 -pipe -frtti -Wno-reorder \
> > -Wno-unused 
> > 
> > I get lots and lots of undefined symbols, all of them from
> > templates.
> 
> I didn't state something because I assumed you knew it: the compiler
> must see the definitions of your template functions, not just their
> declarations.  Definitions must be visible at the point of use.  With
> or without -frepo, the compiler and linker won't go looking in other
> files for template definitions.

Ack!  How did I forget that?!  Duh...

Thanks for your help!

                                   -Dave


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Template Instantiation
  1998-02-09  9:08   ` David Greene
@ 1998-02-09 11:54     ` Joe Buck
  1998-02-09 11:54       ` David Greene
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Buck @ 1998-02-09 11:54 UTC (permalink / raw)
  To: greened; +Cc: jbuck, egcs

> > On both of these systems, it works pretty much like it does with Borland
> > C++.  All needed templates are instantiated in each object file, but
> > weak symbols are used.  At link time, one weak symbol is used as the
> > definition.  If you have a recent GNU ld, the duplicate definitions, if
> > any, get stripped out and are not included in the binary.  If you have
> > an older linker or are using the Solaris linker, everything works, but
> > your executable may contain extra copies of some functions.
> 
> This just does not work at all:
> 
> CXXFLAGS = -DDEBUG=0 -DLINUX_LIBC6 -pipe -frtti -Wno-reorder \
> -Wno-unused 
> 
> I get lots and lots of undefined symbols, all of them from
> templates.

I didn't state something because I assumed you knew it: the compiler
must see the definitions of your template functions, not just their
declarations.  Definitions must be visible at the point of use.  With
or without -frepo, the compiler and linker won't go looking in other
files for template definitions.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-02-09 11:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-08 11:38 Template Instantiation David Greene
1998-02-08 18:44 ` Joe Buck
1998-02-09  9:08   ` David Greene
1998-02-09 11:54     ` Joe Buck
1998-02-09 11:54       ` David Greene

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).