[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] Minimal libraries
From: |
Gaius Mulley |
Subject: |
Re: [Gm2] Minimal libraries |
Date: |
Tue, 30 Jun 2009 15:56:05 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
Waldek Hebisch <address@hidden> writes:
> Gaius Mulley wrote:
>> address@hidden writes:
>>
>> > Gnu C, Gnu C++, and Critical Mass Modula 3 all produce "hello world"
>> > binaries of 6-8Kb stripped, where Gnu Modula 2 produces 110Kb stripped.
>> > I doubt that the differences are due to lack of link time optimisations,
>> > tho' they may be. Anyway, thanks.
>> >
>> > Will
>>
>> Hi,
>>
>> C, C++ and gm2 all use the same middle and backend. The difference is
>> the way the libraries are organised. For example glibc is composed of
>> 6244 C files, most of which consist of one function per object, thus
>> when linking against glibc.a the linker pulls in only an object
>> matching a function, (hence a pretty minimal binary).
>
> The last time I tried _statically_ linking with glibc gave me about
> 90 kb. I think that days of 4kb static executables are gone, all
> really small "hello world" programs from Gnu use dynamically
> linked libraries.
>
> It is possible to get some link optimizations with current compiler.
> IIRC the '-ffunction-sections' option to the compiler marks function
> boundaries in the object files, so that with proper linker option
> one can link in only needed functions. However, few years ago
> (when I checked this) linker could do this only for completely
> static build. So the price was static linking to glibc, bringing
> about 90 kb of routines from there and defeating the purpose.
> New release of binutils was supposed to fix problem of mixing
> per-function sections and shared libraries, so anybody interested
> should probably re-check.
Hi Waldek,
many thanks for the pointers to these flags. I've now enabled
-ffunction-sections -fdata-sections when building all libraries.
Linking the standard hello world example gives the following sized
binary:
$ gm2 -c -g -I. -ffunction-sections -fdata-sections hello.mod
$ gm2 -g -I. -ffunction-sections -fdata-sections hello.mod -Wl,--gc-sections
$ size a.out
text data bss dec hex filename
63780 808 10088 74676 123b4 a.out
$ gm2 -c -g -I. -ffunction-sections -fdata-sections hello.mod -fno-exceptions
$ gm2 -g -I. -ffunction-sections -fdata-sections hello.mod -Wl,--gc-sections
-fno-exceptions
$ size a.out
text data bss dec hex filename
44679 728 9552 54959 d6af a.out
definitely an improvement and I suspect more options might remove
further dead code..
regards,
Gaius