[cmake] Use -ffunction-sections and -Wl,--gc-sections on MinGW targets
authorMartin Storsjö <martin@martin.st>
Wed, 21 Apr 2021 05:35:40 +0000 (08:35 +0300)
committerMartin Storsjö <martin@martin.st>
Fri, 30 Apr 2021 07:53:40 +0000 (10:53 +0300)
commitb11a2f2544e880602b539c85c4445468d14b63a1
tree77abf51451a735bc157d283799294dcf6ad11f22
parentc81ec19fba27ec308607aac2e44234eee8e190d1
[cmake] Use -ffunction-sections and -Wl,--gc-sections on MinGW targets

If compiling with GCC or linking with ld.bfd, these options have little
effect, but if built with Clang and linked with LLD, they provide a
quite notable size decrease - this shrinks an entire llvm-mingw
distribution package by 22%.

If building with BUILD_SHARED_LIBS or LLVM_BUILD_LLVM_DYLIB with LLD,
this requires a version of LLD that contains a fix for auto exporting
symbols from comdats, 2b01a417d7ccb001ccc1185ef5fdc967c9fac8d7.

Differential Revision: https://reviews.llvm.org/D101568
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/HandleLLVMOptions.cmake