StephanTLavavej / mingw-distro

MinGW distro build scripts.
494 stars 55 forks source link

Consider --disable-libstdcxx-verbose to reduce generated executable size #35

Closed rongjiecomputer closed 7 years ago

rongjiecomputer commented 7 years ago

Based on your build scripts, I managed to create my own gcc and binutils just to see what other customization you can try as well.

I found out that the sizes of executables produced by my toolchain and yours are different, though execution time is more or less the same.

31/12/2016  05:02 PM            16,896 fib-s-gc.exe # -O3 -march=native -s -ffunction-sections -Wl,--gc-sections
31/12/2016  05:02 PM            17,920 fib-s.exe # -O3 -march=native -s
31/12/2016  05:02 PM           397,922 fib.exe # -O3 -march=native
31/12/2016  05:02 PM            16,896 fib2-s-gc.exe # ditto, but compiled with your toolchain
31/12/2016  05:02 PM            17,408 fib2-s.exe
31/12/2016  05:02 PM            56,296 fib2.exe
31/12/2016  05:02 PM            16,384 pi-s-gc.exe
31/12/2016  05:02 PM            17,920 pi-s.exe
31/12/2016  05:02 PM           397,939 pi.exe
31/12/2016  05:02 PM            16,384 pi2-s-gc.exe
31/12/2016  05:02 PM            17,408 pi2-s.exe
31/12/2016  05:02 PM            56,313 pi2.exe

Without -s and so on, my toolchain always produces larger executables, probably because I did not use -s when I built Mingw-w64 runtime and gcc's libraries. With -s -ffunction-sections -Wl,--gc-sections, there is no difference in size.

31/12/2016  05:02 PM            99,328 nbody-s-gc.exe
31/12/2016  05:02 PM           102,400 nbody-s.exe
31/12/2016  05:02 PM           807,990 nbody.exe
31/12/2016  05:02 PM           183,808 nbody2-s-gc.exe
31/12/2016  05:02 PM           186,368 nbody2-s.exe
31/12/2016  05:02 PM           375,265 nbody2.exe

With -s -ffunction-sections -Wl,--gc-sections, my toolchain produces executable about half the size than yours.

Attached size.zip for you to test it in your machine. (Github does not support .7z)

Note:

rongjiecomputer commented 7 years ago

Forgot to post my gcc spec:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/6.3.0/lto-w
rapper.exe
Target: x86_64-w64-mingw32
Configured with: ../configure --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw
32 --target=x86_64-w64-mingw32 --prefix=/c/mingw64 --with-sysroot=/c/mingw64 --w
ith-gmp=/c/mingw64/gmp --with-mpfr=/c/mingw64/mpfr --with-mpc=/c/mingw64/mpc --d
isable-nls --disable-multilib --disable-libstdcxx-pch --disable-shared --disable
-win32-registry --disable-libstdcxx-debug --disable-libstdcxx-verbose --with-tun
e=haswell --enable-lto --enable-checking=release --enable-languages=c,c++ --enab
le-libstdcxx-time --enable-threads=win32 --enable-libatomic --enable-fully-dynam
ic-string
Thread model: win32
gcc version 6.3.0 (GCC)
StephanTLavavej commented 7 years ago

I'm confused as to what change you're requesting from me here.

rongjiecomputer commented 7 years ago

I found out what happens now: it is due to --disable-libstdcxx-verbose, this disables verbose messages for unhandled exceptions and also saves a lot of space.

Example:

int main() {
  throw 5;
}

With --disable-libstdcxx-verbose, program will abort silently the usual message like this:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Otherwise it will show extra message:

terminate called after throwing an instance of 'int'

If users really need this verbose message for debugging, they can do this:

#include <exception>
#include <stdexcept>

int main() {
  std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  throw 5;
}
StephanTLavavej commented 7 years ago

Thanks, I'll think about it.

Note to self: read https://gcc.gnu.org/onlinedocs/libstdc++/manual/configure.html