[comp.lang.c] smart linker

swie@cs.umn.edu (S. T. Tan) (02/21/91)

Is there a C compiler bundled with a "smart linker" for DOS?
What I meant by a smart linker is the linker which will only link and include 
those routines which are referenced in the main program, and all of the 
remaining unused routines are ignored so that the size of the excutable file 
can be reduced.

Thanks in advance
swie@cs.umn.edu

gwyn@smoke.brl.mil (Doug Gwyn) (02/22/91)

In article <1991Feb21.102123.9868@cs.umn.edu> swie@cs.umn.edu (S. T. Tan) writes:
>Is there a C compiler bundled with a "smart linker" for DOS?
>What I meant by a smart linker is the linker which will only link and include 
>those routines which are referenced in the main program, and all of the 
>remaining unused routines are ignored so that the size of the excutable file 
>can be reduced.

While I'm not aware of the characteristics of MS-DOS C offerings,
I feel I should point out that the selective linking must be done
on the basis of OBJECT MODULE, not FUNCTION.  (An object module
would be the linkable unit produced by compiling one "translation
unit" [in C standard parlance].)  Generally in the UNIX world
linkers do act that way and also do not include in the image any
object modules from libraries except when they are needed to
satisfy external references.  With a minor amount of assistance
from the compiler, it is even possible to exploit this behavior
to exclude floating-point support from printf() when there has
been no use of floating-point in the program being linked.

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (02/22/91)

In article <15279@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes:
>In article <1991Feb21.102123.9868@cs.umn.edu> swie@cs.umn.edu (S. T. Tan) writes:
>>Is there a C compiler bundled with a "smart linker" for DOS?
>>What I meant by a smart linker is the linker which will only link and include 
>>those routines which are referenced in the main program, and all of the 
>>remaining unused routines are ignored so that the size of the excutable file 
>>can be reduced.
>
>While I'm not aware of the characteristics of MS-DOS C offerings,


I am. In general they work just like Unix.

>I feel I should point out that the selective linking must  be done
>on the basis of OBJECT MODULE, not FUNCTION. 


Here "must" is too strong. There is a continuum of gradation between
"source code" and "executable code". the MIPS compilers for instance
have an intermediate form of code that is such that subroutines
in modules can indeed be left out of the final executable. This is
just deferring dead code elimination to a "link" step.


(Note: I not sure that the MIPS system actually DOES this.)

> (An object module
>would be the linkable unit produced by compiling one "translation
>unit" [in C standard parlance].)  Generally in the UNIX world
>linkers do act that way and also do not include in the image any
>object modules from libraries except when they are needed to
>satisfy external references.  With a minor amount of assistance
>from the compiler, it is even possible to exploit this behavior
>to exclude floating-point support from printf() when there has
>been no use of floating-point in the program being linked.

As to this latter floating point stuff, MS-DOS also does this.

Doug McDonald

gwyn@smoke.brl.mil (Doug Gwyn) (02/23/91)

In article <1991Feb22.011332.24359@ux1.cso.uiuc.edu> mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes:
>>I feel I should point out that the selective linking must  be done
>>on the basis of OBJECT MODULE, not FUNCTION. 
>Here "must" is too strong.

The deferred "dead code elimination" is fine, but the point is that
a conforming C implementation must act AS THOUGH external linkage
operated on the translation unit as a whole.

bliss@sp64.csrd.uiuc.edu (Brian Bliss) (02/24/91)

I used to use Pyramid's sequent multiprocessor for a class.
It has an optimizing linker that only included routines that
were referenced, not entire object modules.  If I remember correctly,
It would also removeunreferenced code/data from object modules that 
were not in libraries, so the algorithm used must have bee more
along the lines of "include a module, then remove everything
unreferenced", instead of "only include the needed symbols".

bb