[comp.misc] Linking functions separately

rfm@urth (Rich McAllister) (12/08/89)

Well, though I admit I don't know of a C compiler that actually does it, it
would certainly be possible to generate object code for IBM S/370 that would
allow you to "pick and choose" functions from one file.  Of course, the
ridiculous 8-character limit will get in your way, but ignore that for a
while. Assume all files have (are hashed to, etc) 8 character names, and
that no function names collide with file names.  What you'd do is generate
one CSECT in one library member for the statics:

FILENAME CSECT
STATVAR  DC  F'0'
         ...
         END

Then generate each function in its own CSECT and library member.  Since the
statics will be in a separate CSECT, you'd have to play some tricks to get
at them, but no worse than the general hassle you have to put up with
because of base registers:

FUNC     CSECT
         EXTERN FILENAME
         ....
         L     1,=A(FILENAME)
	 A     1,offset of STATVAR     compiler stores this in sym table..
*                                      could play games with DSECTs if you
*				       want to make assembler do the work
         L     1,0(1)                  Gets value of STATVAR
         ...
         END

Now, any external ref to FUNC will drag in its member and the ref to
FILENAME in FUNC will drag in the statics, and Tim Maroney should
be ecstatic :-).


Rich McAllister (rfm@eng.sun.com)