On Thu, Nov 27, 2014 at 06:50:19PM +0100, David Herrmann wrote: > Hi > > On Thu, Nov 27, 2014 at 6:35 PM, Peter Wu <pe...@lekensteyn.nl> wrote: > > On Thursday 27 November 2014 13:42:27 Gustavo Sverzut Barbieri wrote: > >> I'm asking because from Peter Wu's email we're 26384 - 26380 = 4Kb > >> heavier in the whole installed set of binaries. If this is correct I > >> doubt the gc-sections is making any difference in the linkage of > >> static libraries (src/shared). In this case my *assumption* (as I have > >> no deep knowledge about the linker) is that it's selectively picking > >> the symbols it uses and leaving the other stuff out of it. > >> > >> Peter, could you provide more in-depth information, for instance you > >> could see: > >> - what binaries are bigger; > >> - what -Wl,--gc-sections -Wl,--print-gc-section says > > > > OK, here is a description of the test setup such you can reproduce it. > > Environment: > > - Arch Linux x86_64 in a QEMU VM (live iso with systemd makedepends > > installed). > > - with systemd git in /tmp/systemd. > > - master is at 9a20fcbcd1b010ad88bfbb8b7f0417bec7327fb4 > > - gcc 4.9.2 > > - binutils 2.24-8 (the broken one) > > > > Commands to build two versions: > > > > cd /tmp/systemd > > # Currently at 9a20fcbcd1b010ad88bfbb8b7f0417bec7327fb4 + patch to > > # remove --gc-sections and -f{data,function}-sections > > git clean -xfd && ./autogen.sh && mkdir build && cd $_ && > > ../configure && make -j6 && make install DESTDIR=$PWD/fs && > > (cd fs && find * -type f -printf '%h/%f\t%s\n') > /tmp/0.txt > > > > # Now let's see what happens with --gc-sections > > git checkout HEAD~ && > > git clean -xfd && ./autogen.sh && mkdir build && cd $_ && > > ../configure && make -j6 && make install DESTDIR=$PWD/fs && > > (cd fs && find * -type f -printf '%h/%f\t%s\n') > /tmp/1.txt > > > > Now build a table to compare the sizes: > > > > join {0,1}.txt | awk '$2!=$3{print $2,$3,$2-$3,$2/$3,$1}' | > > sort -k4n | column -t > results.txt > > > > The columns explained: > > 1. Size of binaries built without --gc-sections and -f... > > 2. Size of binaries built with --gc-sections and -f... > > 3. Absolute "saved" bytes when built with --gc-sections. > > 4. Ratio between the sizes, numbers smaller than 1 indicate a saving, > > numbers larger than 1 show that --gc-sections increase the sizes. > > > > These results are strange, it suggests that --gc-sections make the > > binaries larger overall! I have repeated it three times just to make > > sure that I did not made a mistake. > > Of course it gets bigger if every symbol is placed into it's own > section. It's -ffunction-section and -fdata-section that make it > bigger. But those are required for --gc-sections to work. > > Btw., you run with LTO, which makes --gc-sections obsolete. But we > don't enable LTO for debug builds and I think distributions may > disable it, too. Until we decide to rely on LTO, I'd strongly suggest > keeping our --gc-sections + function/data-section. Either LTO _or_ > --gc-sections is required! > > My numbers were generated via debug-builds, which explicitly disables LTO. > > I'd be fine with a patch that drops --gc-sections and friends if LTO > is enabled. But that requires us to check for LTO during ./configure > and really make sure we know that it's enabled. So far, we just enable > it if it's available, but never really check whether it was enabled.
Hum, then the difference makes sense. LTO :-) Currently configure.ac has the LTO logic inside an: AS_CASE([$CFLAGS], [*-O[[12345\ ]]*], .... We can make the "else" block check/enable for gc-sections alongside printing the result. See the attached (untested!) patch. -- Gustavo Sverzut Barbieri Intel Open source Technology Center
>From 1ea1bde342a94400fc02d7937ce1e0a0d7846b0d Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri <gustavo.barbi...@intel.com> Date: Thu, 27 Nov 2014 16:28:09 -0200 Subject: [PATCH] configure: only use -Wl,--gc-sections if not using -flto link time optimization (LTO) fulfills the same requirements we get using -Wl,--gc-sections -ffunction-sectios -fdata-sections, that is, it will remove unused symbols when linking static libraries such as src/shared. --- configure.ac | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index a4e91e3..20f1b75 100644 --- a/configure.ac +++ b/configure.ac @@ -191,8 +191,6 @@ CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\ -fdiagnostics-show-option \ -fno-strict-aliasing \ -fvisibility=hidden \ - -ffunction-sections \ - -fdata-sections \ -fstack-protector \ -fstack-protector-strong \ -fPIE \ @@ -207,7 +205,12 @@ AS_CASE([$CC], [*clang*], AS_CASE([$CFLAGS], [*-O[[12345\ ]]*], [CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\ -flto -ffat-lto-objects])], - [AC_MSG_RESULT([skipping -flto, optimization not enabled])]) + [AC_MSG_RESULT([skipping -flto, optimization not enabled]) + CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\ + -ffunction-sections -fdata-sections]) + CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [\ + -Wl,--gc-sections]) + ]) AC_SUBST([OUR_CFLAGS], "$with_cflags $sanitizer_cflags") AS_CASE([$CFLAGS], [*-O[[12345\ ]]*], @@ -219,7 +222,6 @@ AC_SUBST([OUR_CPPFLAGS], "$with_cppflags $sanitizer_cppflags") CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [\ -Wl,--as-needed \ -Wl,--no-undefined \ - -Wl,--gc-sections \ -Wl,-z,relro \ -Wl,-z,now \ -pie \ -- 2.1.3
_______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel