@@ -29,14 +29,21 @@ endfunction()
2929# cache file to CMake via -C. e.g.
3030#
3131# cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake
32+
33+ set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir;flang" )
34+ # bolt only supports ELF, so only enable it for Linux.
35+ if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux" )
36+ list (APPEND DEFAULT_PROJECTS "bolt" )
37+ endif ()
38+
3239set (DEFAULT_RUNTIMES "compiler-rt;libcxx" )
3340if (NOT WIN32 )
3441 list (APPEND DEFAULT_RUNTIMES "libcxxabi" "libunwind" )
3542endif ()
3643set (LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "" )
3744set (LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "" )
3845set (LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "" )
39- set (LLVM_RELEASE_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "" )
46+ set (LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "" )
4047# Note we don't need to add install here, since it is one of the pre-defined
4148# steps.
4249set (LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "" )
@@ -48,10 +55,8 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
4855
4956set (STAGE1_PROJECTS "clang" )
5057
51- # Building Flang on Windows requires compiler-rt, so we need to build it in
52- # stage1. compiler-rt is also required for building the Flang tests on
53- # macOS.
54- set (STAGE1_RUNTIMES "compiler-rt" )
58+ # Build all runtimes so we can statically link them into the stage2 compiler.
59+ set (STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" )
5560
5661if (LLVM_RELEASE_ENABLE_PGO)
5762 list (APPEND STAGE1_PROJECTS "lld" )
@@ -90,9 +95,20 @@ else()
9095 set (CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "" )
9196endif ()
9297
98+ if (LLVM_RELEASE_ENABLE_LTO)
99+ # Enable LTO for the runtimes. We need to configure stage1 clang to default
100+ # to using lld as the linker because the stage1 toolchain will be used to
101+ # build and link the runtimes.
102+ # FIXME: We can't use LLVM_ENABLE_LTO=Thin here, because it causes the CMake
103+ # step for the libcxx build to fail. CMAKE_INTERPROCEDURAL_OPTIMIZATION does
104+ # enable ThinLTO, though.
105+ set (RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DLLVM_ENABLE_LLD=ON" CACHE STRING "" )
106+ endif ()
107+
93108# Stage 1 Common Config
94109set (LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "" )
95110set (LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "" )
111+ set (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "" )
96112
97113# stage2-instrumented and Final Stage Config:
98114# Options that need to be set in both the instrumented stage (if we are doing
@@ -102,13 +118,29 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}"
102118if (LLVM_RELEASE_ENABLE_LTO)
103119 set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL )
104120endif ()
121+ set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL )
122+ set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL )
123+ set (RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind" )
124+ if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin" )
125+ set (RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc" )
126+ endif ()
127+
128+ # Set flags for bolt
129+ if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux" )
130+ set (RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow" )
131+ endif ()
132+
133+ set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
134+ set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
135+ set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
105136
106137# Final Stage Config (stage2)
107138set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES} " STRING )
108139set_final_stage_var(LLVM_ENABLE_PROJECTS "${LLVM_RELEASE_ENABLE_PROJECTS} " STRING )
140+ if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux" )
141+ set_final_stage_var(CLANG_BOLT "INSTRUMENT" STRING )
142+ endif ()
109143set_final_stage_var(CPACK_GENERATOR "TXZ" STRING )
110144set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING )
111145
112- if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin" )
113- set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL )
114- endif ()
146+ set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL )
0 commit comments