[RFC] Add compiler flags to discard unused functions

Gustavo Sverzut Barbieri barbieri at profusion.mobi
Fri Oct 1 20:53:36 PDT 2010


On Friday, October 1, 2010, Lucas De Marchi
<lucas.demarchi at profusion.mobi> wrote:
> Request compiler to emit every function and data variable in its own
> section, then request the linker to remove unused sections. This reduces
> the size of the final binary. Compiling with --disable-iwmx, we have the
> following results:
>
> Before:
> =======
>
>    text    data     bss     dec     hex filename
>  418450   29144    1392  448986   6d9da src/connmand
>
>  Binary size: 1792091 B
>  Binary size stripping symbols: 450296B
>
> After:
> ======
>
>    text    data     bss     dec     hex filename
>  408486   29032    1384  438902   6b276 src/connmand
>
>  Binary size: 1840021B
>  Binary size stripping symbols: 440736B
> ---
>  Makefile.am  |    5 ++++-
>  acinclude.m4 |    1 +
>  2 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/Makefile.am b/Makefile.am
> index cb377ca..42dc155 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -83,7 +83,10 @@ src_connmand_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ \
>                                         @CAPNG_LIBS@ @UDEV_LIBS@ -lresolv -ldl
>
>  src_connmand_LDFLAGS = -Wl,--export-dynamic \
> -                               -Wl,--version-script=$(srcdir)/src/connman.ver
> +                               -Wl,--version-script=$(srcdir)/src/connman.ver \
> +                               -Wl,--as-needed \
> +                               -Wl,--gc-sections \
> +                               -Wl,--print-gc-sections
>
>  CLEANFILES = src/connman.conf src/builtin.h $(local_headers)
>
> diff --git a/acinclude.m4 b/acinclude.m4
> index 84086fd..4909abc 100644
> --- a/acinclude.m4
> +++ b/acinclude.m4
> @@ -23,6 +23,7 @@ AC_DEFUN([COMPILER_FLAGS], [
>                 CFLAGS+=" -Wredundant-decls"
>                 CFLAGS+=" -Wcast-align"
>         fi
> +       CFLAGS+=" -ffunction-sections -fdata-sections"
>  ])
>
>  AC_DEFUN([GTK_DOC_CHECK],


Did u test it with non-built in plugins? After I sent the same to
systemd, I tried to apply this to other projects and realized e17
broke as it had couple of unused syms that would be used by its
plugins! Other than that, it is safe and helps.

-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbieri at gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202


More information about the connman mailing list