>> There were linkers written, long ago, that would extract only the code 
>> from a library that was used by a program, and the binary got pretty 
> 
> we do that in inferno's 5l.  richard miller implemented it originally in 5l

There may be a small misunderstanding here.

The change I made in 5l was to discard all unreachable code, whether
it came from a library object file or from the main program.  It was
mostly useful for tidying up programs which had been evolving for
a while, when the authors hadn't bothered to delete functions which
were no longer used.  But that wouldn't help with what Russ described:

> Much of the bloat is from library routines 
> that don't actually get called in practice
> but end up linked into every binary anyway
> (like the formatters for %e, %f, and %g).

The floating point format routines are always reachable if you use any
functions of the print() family, because they're in the list of built-in
formats (/sys/src/libc/fmt/fmt.c:39,41).  There's no way to determine
statically at link time that they won't be called at runtime, because
format strings might be constructed dynamically or even read in.

There was a hack in some early Unixes to solve this particular
instance of the problem: the C compiler would generate an external
reference to pull in a "special" version of printf from the library --
the one with calls to floating-point conversion routines -- if any
floating-point instructions were generated during the compilation.  If
none of your program's object files contained this reference, then you
would get the integer-only printf.  This was in 1978 or so when memory
footprint really made a difference -- e.g. we ran a timesharing lab
with 7 terminals on an Interdata minicomputer with 192 kilobytes of
RAM and two 5-megabyte hard disks.

-- Richard

Reply via email to