2

I want to investigate a way for my other question (gcc: Strip unused functions) by building the latest gcc 6.3.0.

There are some options from https://gcc.gnu.org/install/configure.html and https://gcc.gnu.org/onlinedocs/libstdc++/manual/configure.html that I would like to try, but don't understand what they meant.

Specifically, these are the flags I want to try:

  • --disable-libstdcxx-verbose: I rarely use exceptions so I am not very familiar with how it works. I have never seen the "verbose messages" it mentioned before.
  • --enable-linker-build-id and --enable-gnu-unique-object: Simply don't understand what the explanations are trying to say. What are the benefits exactly?
  • --enable-cxx-flags="-ffunction-sections -fstrict-aliasing -fno-exceptions": If I use -fno-exceptions in libstdc++, doesn't that means I get no exceptions if I use libstdc++? -ffunction-sections is used, but where to put -Wl,-gc-sections?

Although I always use --enable-lto, but with ld.bfd, it seems to be quite useless compared to the famous gold linker.

If you have more flags you think I should try, please let me know!

Community
  • 1
  • 1
John London
  • 1,164
  • 13
  • 24

1 Answers1

3

--disable-libstdcxx-verbose: I rarely use exceptions so I am not very familiar with how it works. I have never seen the "verbose messages" it mentioned before.

+1, you normally don't run into errors which trigger these friendly error messages you can avoid paying for them.

--enable-linker-build-id and --enable-gnu-unique-object: Simply don't understand what the explanations are trying to say. What are the benefits exactly?

There are none.

Unique objects is a badly designed feature that prevents shared libraries which contain references to globally used objects (usually vtables) from unloading on dlclose. AFAIR it's enabled by default (as it's needed to simulate C++ semantics in shared libs environment).

Build id is needed to support separate debuginfo.

--enable-cxx-flags="-ffunction-sections -fstrict-aliasing -fno-exceptions":

You won't benefit from -fstrict-aliasing as it's enabled at -O2 and higher by default.

-ffunction-sections is used, but where to put -Wl,-gc-sections?

To --enable-cxx-flags as well (note that it wants double-dash i.e. -Wl,--gc-sections).

Although I always use --enable-lto, but with ld.bfd, it seems to be quite useless compared to the famous gold linker.

This flags simply enables LTO support in GCC (it's actually equivalent to adding lto to --enable-languages). It won't cause any difference unless you enable -flto in CXXFLAGS as well. Keep in mind that LTO will normally increase executable size (as compiler will have more opportunities for inlining).

If you have more flags you think I should try, please let me know!

Speaking of size reduction, I'd say -ffunction-sections is your best bet (be sure to verify that configure machinery passes all options correctly and libstdc++.a indeed has one section per function). You could also add -fdata-sections.

yugr
  • 13,457
  • 3
  • 37
  • 71
  • 1
    Turns out `-ffunction-sections -fdata-sections` are already used for libstdc++ without being specified in `--enable-cxx-flags`. `-Wl,--gc-sections` is unnecessary because no linking steps in libstdc++, I will use this flag when I build my program. Skipped `--enable-linker-build-id` and `--enable-gnu-unique-object`. Did try `--disable-libstdcxx-verbose`. Tested my http://stackoverflow.com/questions/40856787/gcc-strip-unused-functions again, no improvement. I can only say gcc 6.3.0 + binutils 2.27 perform pretty bad on COFF/PE. if only Windows support ELF. – John London Dec 29 '16 at 13:30
  • "gcc 6.3.0 + binutils 2.27 perform pretty bad on COFF/PE" - yup, that's a fact. Note that unless you somehow inform Cygwin/MinGW developers (and supply them with repro) this isn't going to change. – yugr Dec 29 '16 at 14:42
  • I filed a bug at https://sourceforge.net/p/mingw-w64/bugs/578/ , hope to get some attentions. Thanks for your suggestion! – John London Dec 30 '16 at 02:48