boyce@sifvs3.sinet.slb.com (David Boyce) (06/05/91)
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