[systemd-devel] [PATCH v2] build-sys: remove --gc-sections to fix debugging

Peter Wu peter at lekensteyn.nl
Wed Nov 26 10:31:30 PST 2014


The `--gc-sections` linker option triggers a bug in the gold linker[1]
(binutils 2.24 or older). This results in a bogus .eh_frame section
making debugging harder: gdb backtraces stop at a library built by
systemd and libunwind simply segfaults because it does not check for
garbage values.

Workaround that bug by removing `-Wl,--gc-sections`. Also remove
`-fdata-sections` and `-ffunction-sections` as suggested by Gustavo
Sverzut Barbieri. There is no benefit in creating separate sections for
each function or data item if unused sections are not removed.

The additional disk space saved by this option is marginal anyway (less
than 1%). To illustrate this, see this `du -ks` on the installed files
(where `-Wl,--gc-sections` is removed):

    83548   broken-binutils-without-gc-sections/install
    83432   broken-binutils-with-gc-sections/install
    25796   broken-binutils-without-gc-sections/install-strip
    25752   broken-binutils-with-gc-sections/install-strip

    84024   binutils-master-without-gc-sections/install
    83988   binutils-master-with-gc-sections/install
    26384   binutils-master-without-gc-sections/install-strip
    26380   binutils-master-with-gc-sections/install-strip

 [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=17639

https://bugs.freedesktop.org/show_bug.cgi?id=86666
---
 v2:    removed -ffunction-sections and -fdata-sections too, mention
        that binutils fixed the bug.
---
 configure.ac | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index bd3cc0e..baba072 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 \
@@ -219,7 +217,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 \
-- 
1.9.1



More information about the systemd-devel mailing list