Skip to content

Commit d846ac4

Browse files
tstellaraokblast
authored andcommitted
[CMake][Release] Stop linking against stage1 runtimes (llvm#164017)
This was causing a build failure on Darwin and a test failure on Linux. This config is not widely used or well tested, so I don't think the potential and likely small performance gains and the portability from this are worth the maintenance costs.
1 parent b0741e6 commit d846ac4

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

clang/cmake/caches/Release.cmake

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
4444
set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
4545
set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")
4646
set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")
47+
48+
# This option enables linking stage2 clang statically with the runtimes
49+
# (libc++ and compiler-rt) from stage1. In theory this will give the
50+
# binaries better performance and make them more portable. However,
51+
# this configuration is not well tested and causes build failures with
52+
# the flang-rt tests cases, since the -stclib=libc++ flag does not
53+
# get propagated to the runtimes build. There is also a separate
54+
# issue on Darwin where clang will use the local libc++ headers, but
55+
# link with system libc++ which can cause some incompatibilities.
56+
# See https://github.com/llvm/llvm-project/issues/77653
57+
# Because of these problems, this option will default to OFF.
58+
set(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES OFF CACHE BOOL "")
59+
4760
# Note we don't need to add install here, since it is one of the pre-defined
4861
# steps.
4962
set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
@@ -55,8 +68,12 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
5568

5669
set(STAGE1_PROJECTS "clang")
5770

71+
# Need to build compiler-rt in order to use PGO for later stages.
72+
set(STAGE1_RUNTIMES "compiler-rt")
5873
# Build all runtimes so we can statically link them into the stage2 compiler.
59-
set(STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind")
74+
if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
75+
list(APPEND STAGE1_RUNTIMES "libcxx;libcxxabi;libunwind")
76+
endif()
6077

6178
if (LLVM_RELEASE_ENABLE_PGO)
6279
list(APPEND STAGE1_PROJECTS "lld")
@@ -118,21 +135,25 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}"
118135
if (LLVM_RELEASE_ENABLE_LTO)
119136
set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)
120137
endif()
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")
138+
if(LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
139+
set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)
140+
set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)
141+
set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")
142+
if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
143+
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
144+
endif()
126145
endif()
127146

128147
# Set flags for bolt
129148
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
130149
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow")
131150
endif()
132151

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)
152+
if (RELEASE_LINKER_FLAGS)
153+
set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
154+
set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
155+
set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
156+
endif()
136157

137158
# Final Stage Config (stage2)
138159
set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)

0 commit comments

Comments
 (0)