[PATCH] D101568: [cmake] Use -ffunction-sections and -Wl,--gc-sections on MinGW targets

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 29 13:44:44 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: rnk, mati865.
Herald added a subscriber: mgorny.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

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 with LLD, this requires a version
of LLD that contains a fix for auto exporting symbols from comdats,
2b01a417d7ccb001ccc1185ef5fdc967c9fac8d7 <https://reviews.llvm.org/rG2b01a417d7ccb001ccc1185ef5fdc967c9fac8d7>.

@mati865, do you use such builds in MSYS2, and will this be an issue
for you, if you'd upgrade to LLVM 13 and build it with LLVM/LLD 12?
(Then again, you can set LLVM_NO_DEAD_STRIP on the first build to
get an initial build of LLVM 13.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101568

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -898,7 +898,7 @@
 # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF?
 # But MinSizeRel seems to add that automatically, so maybe disable these
 # flags instead if LLVM_NO_DEAD_STRIP is set.
-if(NOT CYGWIN AND NOT WIN32)
+if(NOT CYGWIN AND NOT MSVC)
   if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND
      NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
     check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS)
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -242,7 +242,7 @@
           set_property(TARGET ${target_name} APPEND_STRING PROPERTY
                        LINK_FLAGS " -Wl,-z,discard-unused=sections")
         endif()
-      elseif(NOT WIN32 AND NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD|AIX|OS390")
+      elseif(NOT MSVC AND NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD|AIX|OS390")
         # TODO Revisit this later on z/OS.
         set_property(TARGET ${target_name} APPEND_STRING PROPERTY
                      LINK_FLAGS " -Wl,--gc-sections")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101568.341631.patch
Type: text/x-patch
Size: 1370 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210429/79cdcf83/attachment.bin>


More information about the llvm-commits mailing list