libc, smart linking, binary size (elf/a.out)

Herbert Rosmanith (herp@wildsau.idv.uni-linz.ac.at)
Thu, 25 Apr 1996 20:04:35 +0200 (MET DST)


salam,

well, I know this aint a kernel issue, but I dunno if there's a libc list
(and don't want to look :-) ... so forgive me for being ignorant.

I compiled a rather small piece of code, hardly a full A4 page. I use
two libc functions, "gethostbyname" and "gethostbyaddr".

surprise, surprise, on an elf-system , the binary size is 160KB !!!!
on another machine, a a.out system, the binary size is 14KB.
jesus christ ...

nm shows that a lot of code is included in this binary, that I don't use
at all. YP, for instance (yp_all, yp_bind, yp_first..) and "xdr", I don't
know what this is. xdr_memcreate, and so on ... quite a lot of stuff
for a little DNS-query!

and here's a related question:

o How can one use "smart linking" with static libraries ?

assume the following code:

> t1.c:
>
> void gna() { printf("gna\n"); }
> void bot() { printf("bot\n"); }

> main.c:
>
> void main() { gna(); }

now we do:

> cc -c t1.c
> ar rcv libt1.a t1.c
> cc -o gna main.c -L./ -lt1

now doing a "nm gna" will show that "bot" is a defined symbol of type T.

does that mean that "gna" contains the all the code for "bot", allthough
"bot" is never used ? a waste of space!
is there a switch to tell "ld" to kick out code for unused external references ?

/herp