@@ -48,6 +48,19 @@ set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
4848set (LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "" )
4949set (LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "" )
5050set (LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "" )
51+
52+ # This option enables linking stage2 clang statically with the runtimes
53+ # (libc++ and compiler-rt) from stage1. In theory this will give the
54+ # binaries better performance and make them more portable. However,
55+ # this configuration is not well tested and causes build failures with
56+ # the flang-rt tests cases, since the -stclib=libc++ flag does not
57+ # get propagated to the runtimes build. There is also a separate
58+ # issue on Darwin where clang will use the local libc++ headers, but
59+ # link with system libc++ which can cause some incompatibilities.
60+ # See https://github.com/llvm/llvm-project/issues/77653
61+ # Because of these problems, this option will default to OFF.
62+ set (LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES OFF CACHE BOOL "" )
63+
5164# Note we don't need to add install here, since it is one of the pre-defined
5265# steps.
5366set (LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "" )
@@ -59,8 +72,12 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
5972
6073set (STAGE1_PROJECTS "clang" )
6174
75+ # Need to build compiler-rt in order to use PGO for later stages.
76+ set (STAGE1_RUNTIMES "compiler-rt" )
6277# Build all runtimes so we can statically link them into the stage2 compiler.
63- set (STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" )
78+ if (LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
79+ list (APPEND STAGE1_RUNTIMES "libcxx;libcxxabi;libunwind" )
80+ endif ()
6481
6582if (LLVM_RELEASE_ENABLE_PGO)
6683 list (APPEND STAGE1_PROJECTS "lld" )
@@ -122,21 +139,25 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}"
122139if (LLVM_RELEASE_ENABLE_LTO)
123140 set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL )
124141endif ()
125- set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL )
126- set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL )
127- set (RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind" )
128- if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin" )
129- set (RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc" )
142+ if (LLVM_RELEASE_ENABLE_LINK_LOCAL_RUNTIMES)
143+ set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL )
144+ set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL )
145+ set (RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind" )
146+ if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin" )
147+ set (RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc" )
148+ endif ()
130149endif ()
131150
132151# Set flags for bolt
133152if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux" )
134153 set (RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow" )
135154endif ()
136155
137- set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
138- set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
139- set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
156+ if (RELEASE_LINKER_FLAGS)
157+ set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
158+ set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
159+ set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING )
160+ endif ()
140161
141162# Final Stage Config (stage2)
142163set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES} " STRING )
0 commit comments