Subject: Re: dynamic linker
To: NetBSD User's Discussion List <netbsd-users@netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: netbsd-users
Date: 03/19/2002 18:17:49
[ On Tuesday, March 19, 2002 at 21:45:30 (+0100), Wojciech Puchar wrote: ]
> Subject: Re: dynamic linker
>
> whole program took <4kB dynamic and <12kB static.
 
Indeed, but every exec() of a dynamic executable starts by executing ld.elf_so:

	$ size /usr/libexec/ld.elf_so                                       
	text    data    bss     dec     hex     filename
	35299   928     1356    37583   92cf    /usr/libexec/ld.elf_so
 
It's not huge, but it's not always running either......

FYI on sparc the empty main() function takes about 12KB too:

	$ echo 'main(){}' > test.c
	$ cc -static -o test test.c
	$ file test 
	test: ELF 32-bit (SYSV) MSB executable, SPARC, version 1, statically linked, not stripped
	$ size test
	text    data    bss     dec     hex     filename
	12040   108     288     12436   3094    test

> yes i know it but why running STATIC binary takes so much?
> or am i missing something.

the average time to execute is pretty meaningless if you want to know
why it took that long....

Try writing a wrapper program that exec's your empty test program a few
thousand times in a tight loop and then prints all the structure field
values returned by:

	struct rusage child_rusage;
	getrusage(RUSAGE_CHILDREN, &child_rusage);

> BTW. you wrote "BSD for ELF binaries".

Yes, because SunOS-4's dynamic loader, from which NetBSD's was derived,
was originally for a.out binaries.

> so you mean with a.out binaries
> it's faster/better? if so why we moved to ELF?

I don't know....  John Levine implies so in his book "Linkers & Loaders"
though:  "Shared libraries, ELF shared libraries in particular, can be
very slow."

> and how much RAM does it take (esp with X11) ...

(BTW, that's with X11 clients -- this machine runs headless serving some
X11 workstations and terminals)

: NetBSD 1.5W (GENERIC) #13: Sat Jun 30 15:04:13 EDT 2001
:     woods@sometimes:/build/NetBSD-obj/arch/sparc/compile/GENERIC
: total memory = 287 MB
: avail memory = 262 MB
: using 896 buffers containing 14812 KB of memory

There's not too much running right at the moment, but:

VMstat says:

          memory totals (in KB)
         real   virtual    free
Active  44920     57660  184460
All    102592    115332 1745276

top says:

Memory: 44M Act, 6944K Inact, 1904K Wired, 180M Free, 12M Swp, 1524M Swp free

ps -alxc says:

$ ps -alxc
  UID   PID PPID CPU PRI  NI   VSZ  RSS WCHAN    STAT TT      TIME COMMAND
    0     0    0   0 -18   0     0 1104 schedule DKs  ??   0:07.05 swapper
    0     1    0  27  10   0   444   44 wait     Is   ??   0:00.42 init
    0     2    0   0  -6   0     0 1104 sccomp   DK   ??   0:00.00 esp0:0
    0     3    0   0 -18   0     0 1104 pgdaemon DK   ??   0:01.29 pagedaemon
    0     4    0   0 -18   0     0 1104 reaper   DK   ??   2:41.26 reaper
    0     5    0   0  18   0     0 1104 syncer   DK   ?? 146:26.81 ioflush
    0     6    0   0 -18   0     0 1104 aiodoned DK   ??   0:31.83 aiodoned
    0    95    1   0   2   0   404   88 select   Is   ??   1:01.19 syslogd
    0   103    1   0  10   0   944   12 nanoslee Ss   ??   3:12.33 ipmon
32769   108    1   0   2   0  1964   84 select   Is   ??   0:07.33 named
    0   114    1   0   2   0  1616  124 select   Is   ??   0:16.67 rpcbind
    0   124    1   0  10   0 64540    0 mfsidl   Is   ??   0:04.40 mount_mfs
    0   130    0   0  10   0     0 1104 nfsidl   IK   ??   0:13.82 nfsio
    0   131    0   0  10   0     0 1104 nfsidl   IK   ??   0:10.73 nfsio
    0   132    0   0  10   0     0 1104 nfsidl   IK   ??   0:03.06 nfsio
    0   133    0   0  10   0     0 1104 nfsidl   IK   ??   0:02.50 nfsio
    0   145    1   0   2   0  3760  152 select   Ss   ??   3:34.40 xfs
    0   157    1   0   2   0   488    0 select   Is   ??   0:02.13 mountd
    0   165    1   0   2   0   312    0 select   Is   ??   0:02.71 nfsd
    0   168    1   0   2   0   388    0 select   Is   ??   0:01.91 rpc.statd
    0   170    1   0   2   0   392    0 select   Is   ??   0:02.03 rpc.lockd
    0   172  165   0   2   0   292    0 nfsd     IL   ??  17:55.90 nfsd
    0   173  165   0   2   0   292    0 nfsd     IL   ??   0:00.20 nfsd
    0   174  165   0   2   0   292    0 nfsd     IL   ??   0:16.45 nfsd
    0   175  165   0   2   0   292    0 nfsd     IL   ??   0:01.10 nfsd
    0   191    1   0   2   0   120   96 netio    Is   ??   2:06.34 rwhod
    0   199    1   0   2   0   332    0 select   Is   ??   0:01.67 rarpd
    0   202    1   0  18 -12   988  192 pause    S<s  ??   9:56.82 ntpd
    0   213    1   0   2   0   440    0 select   Is   ??   0:01.08 lpd
    0   219    1   0   2   0   344    0 select   Is   ??   0:01.07 rpc.bootparam
    0   233    1   0   2   0  1328   56 select   Is   ??   0:02.16 sshd2
    0   236    1   0   2   0   596    0 select   Is   ??   0:01.15 snmptrapd
    0   294    1   0   2   0   520  112 select   Is   ??   1:37.36 master
    0   299    1   0   2   0   424  156 select   Is   ??   0:07.05 inetd
   12   304  294   0   2   4   608  144 select   IN   ??  15:41.19 qmgr
    0   305    1   0  10   0   604  116 nanoslee Is   ??   0:41.84 cron
    0  6532  299   0   2   0   720  172 select   I    ??   0:00.20 rshd
    0  6533 6532   0   2   0  4048  148 select   I    ??   0:09.50 xterm
    0  8878  299   0   2   0   720  172 select   I    ??   0:00.15 rshd
 1000  8879 8878   0   2   0  1364  144 select   S    ??   0:08.36 xload
    0  8880  299   0   2   0   720  172 select   I    ??   0:00.15 rshd
 1000  8881 8880   0  18   0   536  180 pause    I    ??   0:00.03 ksh
    0  8882 8881   0   2   0  2308  148 -        R    ??   0:05.83 xterm
    0  8883  299   0   2   0   720  172 select   I    ??   0:00.15 rshd
 1000  8884 8883   0  18   0   536  180 pause    I    ??   0:00.03 ksh
    0  8885 8884   0   2   0  2292  148 select   I    ??   0:00.39 xterm
   12 10359  294   0   2   0   484  152 select   I    ??   0:00.06 pickup
    0   239    1   0   2   0  1436  108 select   I    a-   4:48.02 snmpd
    0   307    1   0   3   0   428  100 ttyin    Is+  a    0:00.06 getty
 1000  5346    1   0  18   0   704  188 pause    Is   p0   0:01.04 ksh
 1000  5512 5346   0   2   0  1516  124 select   I    p0   0:03.60 ssh2
 1000  6534 6533   0   3   0   732  188 ttyin    Is+  p0   0:01.61 ksh
 1000  8887 8882   1  18   0   704  188 pause    Ss   p1   0:01.15 ksh
 1000 10380 8887   2  30   0   456  112 -        R+   p1   0:00.01 ps
 1000  8886 8885  23   3   0   704  188 ttyin    Is+  p2   0:01.04 ksh
 1000  7051    1   0  18   0   704  188 pause    Is   p3   0:01.04 ksh
 1000  7213 7051   0   2   0  1516  128 select   I+   p3   0:03.42 ssh2


-- 
								Greg A. Woods

+1 416 218-0098;  <gwoods@acm.org>;  <g.a.woods@ieee.org>;  <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>