Re: -ffunction-sections, -fdata-sections and -Wl,--gc-sections

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Mon, 16 Sep 2013 08:52:01 +0200
On Sep 16, 2013, at 03:08, Adrian Chadd <adrian_at_freebsd.org> wrote:
>> The results are interesting. On amd64:
>> 
>> - devd suddenly becomes 500 KB in size, instead of a megabyte,
>> - init's size drops from 900 KB to 600 KB,
>> - clang becomes a megabyte smaller.
>> 
> 
> .. so, I'd like to know specific information as to why these three are now
> smaller. So what's going on?


This is simply unreferenced code and data being eliminated.  It is quite
normal for libraries (libc, the LLVM libs, etc) to contain functions
that aren't called by the program you are linking.  However, any .o file
with multiple functions in it will be linked in as a whole, even if just
one of the functions is called.

I really think functions and data should always be separately "packaged"
in object files, but for some reason this has never been the default for
GNU tools, and everybody has apparently copied the behavior. :-)

-Dimitry


Received on Mon Sep 16 2013 - 04:52:18 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:41 UTC