Next: , Previous: Special startups, Up: Top


7 Set elements - a nice feature of the gnu ld

Set elements are used very often by this library. Since most people don't know them they are explained here a second time.

You can tell the linker to build up an array of pointers to every global symbol in your program (functions or variables) even if your symbols are scattered among some object files. These arrays are called set elements.

You can take 4 Library base pointers

DOSBase’, ‘IntuitionBase’, ‘GfxBase’, ‘IconBase

tell the linker to put them together into a set element called ‘librarybases’ by placing some assembler lines like

asm(".stabs \"_librarybases\",24,0,0,_DOSBase")

into your code (22 for text, 24 for data, 26 for bss - and don't forget the single underscore) and get an array of pointers like this:

     void *librarybases[]=
     { (void *)4,&DOSBase,&IntuitionBase,&GfxBase,&Iconbase,NULL };

The first element contains the number of symbols. The last element contains a NULL pointer. And remember: This are pointers to the pointer variables.

This is the basis of global constructors and destructors in C++ and is very useful on the amiga to implement an auto-library-opening feature :-). Set elements are used in this library for collecting together library bases, initialization routines and cleanup routines.