jmeubank / tdm-gcc-src

GCC sources for the TDM GCC releases
GNU General Public License v2.0
138 stars 22 forks source link

File after compilation is too big #3

Closed Wongboo closed 3 years ago

Wongboo commented 4 years ago

When I compile several .cpp files to .exe files, a huge bug comes up. File after tdm-gcc compilation is about 3000kb,. File after mingw64 compilation is about 100kb. Then I do a careful comparison between these, I found tdm-gcc .exe are 3000kb exactly bigger than mingw64 .exe (only a slice error). It looks as if it has something to do with strip, but the .exe after strip is still 900kb, still too huge comparing to mingw64.exe

jmeubank commented 4 years ago

Please provide (1) the GCC versions you are comparing (TDM-GCC, MinGW64); (2) the command-line flags you are using.

TDM-GCC statically links libgcc and libstdc++ into your executables by default, which increases their total size but is still smaller than the size of the executable plus libgcc.dll plus libstdc++.dll. You can link to the DLLs if you prefer with "-shared-libgcc -shared-libstdc++".

Versions of GCC from 4.7 and earlier produce smaller C++-based executables by default.

Wongboo commented 4 years ago

TDM-GCC,mingw64 version(problem still exists, even if I just print hello word, the file after TDM-GCC-64 is already 3000kb big, which is quite confusing):

Using built-in specs.

COLLECT_GCC=C:\TDM-GCC-64\bin\gcc.exe

COLLECT_LTO_WRAPPER=C:/TDM-GCC-64/bin/../libexec/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe

Target: x86_64-w64-mingw32

Configured with: ../../../src/gcc-git-9.2.0/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --enable-large-address-aware --disable-rpath --disable-symvers --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=http://tdm-gcc.tdragon.net/bugs

Thread model: posix

gcc version 9.2.0 (tdm64-1)

Using built-in specs.

COLLECT_GCC=C:\mingw64\bin\gcc.exe

COLLECT_LTO_WRAPPER=C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe

Target: x86_64-w64-mingw32

Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '

Thread model: posix

gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

发件人: bounces+848413-e865-ustcw0ng=mail.ustc.edu.cn@sgmail.github.com bounces+848413-e865-ustcw0ng=mail.ustc.edu.cn@sgmail.github.com 代表 John E. 发送时间: 2020年7月25日 23:53 收件人: jmeubank/tdm-gcc-src tdm-gcc-src@noreply.github.com 抄送: ustcw0ng ustcw0ng@mail.ustc.edu.cn; Author author@noreply.github.com 主题: Re: [jmeubank/tdm-gcc-src] File after compilation is too big (#3)

Please provide (1) the GCC versions you are comparing (TDM-GCC, MinGW64); (2) the command-line flags you are using.

TDM-GCC statically links libgcc and libstdc++ into your executables by default, which increases their total size but is still smaller than the size of the executable plus libgcc.dll plus libstdc++.dll. You can link to the DLLs if you prefer with "-shared-libgcc -shared-libstdc++".

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jmeubank/tdm-gcc-src/issues/3#issuecomment-663870377 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AKWIHI7EXHOMLLTHAQCOYFTR5L5T5ANCNFSM4PHHRKSA .

jmeubank commented 3 years ago

Unfortunately you haven't provided enough information about the file you're compiling and the flags you're using when you compile, so I can only say, I agree that certain programs are shockingly large when compiled with GCC and I hope the GCC and MinGW-w64 maintainers will spend some time optimizing for size at some point.

In the meantime, here is a size-optimized hello world, and I recommend doing more research on how to optimize for size on Google and in GCC's online documentation.

C:\crossdev\tests>type hello.cpp
#include <iostream>
using namespace std;
int main() {
        cout << "Hello, world!" << endl;
        cout << "Hello, my darling!" << endl;
        cout << "Hello, my friends!" << endl;
        return 0;
}

C:\crossdev\tests>"C:\TDM-GCC-64-9.2.0\bin\g++.exe" -o hello.exe hello.cpp -Os -s -flto -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections

C:\crossdev\tests>dir hello.exe
 Volume in drive C has no label.
 Volume Serial Number is EC0D-4807

 Directory of C:\crossdev\tests

05/20/2021  06:19 PM           920,064 hello.exe