Skip to content

Commit 0c010db

Browse files
committed
[CMAKE] Enable FatLTO as a build option for LLVM
1 parent 8157847 commit 0c010db

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
1111

1212
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
1313
set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
14+
set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
1415
set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
1516
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
1617
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
16211621
# The runtime benefits of LTO don't outweight the compile time costs for tests.
16221622
if(LLVM_ENABLE_LTO)
16231623
if((UNIX OR MINGW) AND LINKER_IS_LLD)
1624-
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
1625-
LINK_FLAGS " -Wl,--lto-O0")
1624+
if(LLVM_ENABLE_FATLTO)
1625+
# When using FatLTO, just use relocatable linking.
1626+
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
1627+
LINK_FLAGS " -Wl,--no-fat-lto-objects")
1628+
set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS " -fno-lto")
1629+
else()
1630+
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
1631+
LINK_FLAGS " -Wl,--lto-O0")
1632+
endif()
16261633
elseif(LINKER_IS_LLD_LINK)
16271634
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
16281635
LINK_FLAGS " /opt:lldlto=0")

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif()
3232
set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO")
3333
string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
3434

35+
option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
36+
3537
# Ninja Job Pool support
3638
# The following only works with the Ninja generator in CMake >= 3.0.
3739
set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1259,6 +1261,10 @@ elseif(LLVM_ENABLE_LTO)
12591261
endif()
12601262
endif()
12611263

1264+
if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
1265+
append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1266+
endif()
1267+
12621268
# Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we are
12631269
# doing dynamic linking (see below).
12641270
set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

0 commit comments

Comments
 (0)