Article View: gnu.g++.help
Article #552collect and ld++
From: David Boyce
Date: Wed, 05 Jun 1991 09:04
Date: Wed, 05 Jun 1991 09:04
45 lines
2780 bytes
2780 bytes
Elizabeth Zwicky writes:
>If someone could explain to me about collect and ld++, for once and
>for all, I'd be grateful. I seem to be using them jointly on one
>machine (a Sun3 running Mach), although my original reading of the
>docs (and Encore's) would suggest that they are mutually incompatible.
If you use GAS and GNU LD, then you don't need to use collect. __CTOR_LIST__
and __DTOR_LIST__ are *lists* of vectors, and need to be handled a little
differently, hence the need for GAS and GNU LD.
When you define a global object, G++ puts out a special stab line in the
output, which defines __CTOR_LIST__ as being a set-vector type, and which
has the value of the address of the contructor for the object you've
just defined. So among all your object files, you've got lots of
declarations of __CTOR_LIST__, each one having the value of the address
of a constructor. (And similarly for __DTOR_LIST__.)
GAS is needed because the stab used to define the set-vector isn't
standard (I would assume), and other assemblers are likely to either
barf on the symbol, or completely ignore it. What GNU LD does is collect
all these __CTOR_LIST__ and __DTOR_LIST__ declarations into an array, which
it outputs along with your standard text and data segment stuff. (I think
it appears in the data segment now.) So you would have two symbols,
__CTOR_LIST__ and __DTOR_LIST__, each one points to an array which contains
the number of elements in the array, followed by a list of pointers to
functions, (ie, the constructors/destructors).
When your executable starts up, it
calls special initialisation code which picks up __CTOR_LIST__, and calls
each routine in the array. Close-down code uses __DTOR_LIST__.
I believe that what collect does is to go through the object files, finding
all the __CTOR_LIST__ and __DTOR_LIST__ declarations, and outputting them
to a separate .o file that can be used with a normal linker.
Hope this helps.
- Dave
-----
David Boyce, Schlumberger Instruments, | boyce@sifvs3.sinet.slb.com
Farnborough, Hants, UK, (+44) 252 544433 x5543 |
Disclaimer: My employer doesn't know I post | Made in Scotland
to this list. | from girders
Technical Details
Message-ID:
<9106050904.AA00885@SLCS.SLB.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage From: boyce@sifvs3.sinet.slb.com (David Boyce) Newsgroups: gnu.g++.help,comp.lang.c++ Subject: collect and ld++ Message-ID: <9106050904.AA00885@SLCS.SLB.COM> Date: 5 Jun 91 09:04:29 GMT Sender: daemon@tut.cis.ohio-state.edu Followup-To: gnu.g++.help Distribution: world Organization: Gatewayed from the GNU Project mailing list help-g++@prep.ai.mit.edu Lines: 45