Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Sep 1996 12:01:44 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-current@FreeBSD.org, peter@spinner.DIALix.COM
Subject:   Re: BLOAT in minimal programs
Message-ID:  <199609270201.MAA05537@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>peter@spinner[11:19pm]/tmp-973> cc -c foo.c
>peter@spinner[11:19pm]/tmp-974> cc -v -static -o foo.exe foo.o
>gcc version 2.7.2.1
> /usr/bin/ld -e start -dc -dp -Bstatic -o foo.exe /usr/lib/scrt0.o foo.o /usr/lib/libgcc.a -lc /usr/lib/libgcc.a
>
>[add the -M flag to ld to see the map output ]
>
>peter@spinner[11:20pm]/tmp-975> /usr/bin/ld -M -e start -dc -dp -Bstatic -o foo.exe /usr/lib/scrt0.o foo.o /usr/lib/libgcc.a -lc /usr/lib/libgcc.a | head
>/usr/lib/libgcc.a(__main.o) needed due to ___main

It's easier to add the -M to the cc command:

	cc -static -o foo foo.c -Wl,-M
	                        ^^^^ pass following options to linker
				    ^^ desired linker flag

>So, in a nutshell if you want a small static program that doesn't use
>C++ anywhere:
>
>peter@spinner[11:27pm]/tmp-985> cat foo.c
>__main() { /* dummy stub */ }
>
>main()
>{
>}

Except that exit() should be attached to atexit() there if stdio
is linked.  Currently we use the special method of calling stdio's
_cleanup() from exit() through the function pointer __cleanup.

>peter@spinner[11:27pm]/tmp-988> size foo.exe
>text    data    bss     dec     hex
>4096    4096    0       8192    2000
>
>Now, you can't get smaller than that without ELF.

I got considerably smaller sizes using a.out under Minix, from a
space-optimized stdio (1200 bytes for putc(), 4528 bytes for printf())
and a __LDPGSZ of 16.  How does ELF handle paging if its sizes aren't
multiples of PAGE_SIZE?

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609270201.MAA05537>