From b11a2f2544e880602b539c85c4445468d14b63a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Storsj=C3=B6?= Date: Wed, 21 Apr 2021 08:35:40 +0300 Subject: [PATCH] [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 | 2 +- llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 9bfef6d..ce728ac 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -242,7 +242,7 @@ function(add_link_opts target_name) 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") diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake index ee91386..43cd88b 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -898,7 +898,7 @@ endif() # 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) -- 2.7.4