Эх сурвалжийг харах

[CMake][libcxx] Use builtins rather than gcc_s when compiler-rt is requested

When compiler-rt is requested, we should attempt to link compiler-rt
builtins library rather than gcc_s.

Differential Revision: https://reviews.llvm.org/D31617

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@299599 91177308-0d34-0410-b5e6-96231b3b80d8
Petr Hosek 8 жил өмнө
parent
commit
1662a857db

+ 4 - 1
cmake/Modules/HandleCompilerRT.cmake

@@ -3,8 +3,11 @@ function(find_compiler_rt_library name dest)
     message(FATAL_ERROR "LIBCXX_COMPILE_FLAGS must be defined when using this function")
   endif()
   set(dest "" PARENT_SCOPE)
-  set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS}
+  set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${TARGET_TRIPLE} ${LIBCXX_COMPILE_FLAGS}
       "--rtlib=compiler-rt" "--print-libgcc-file-name")
+  if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET)
+    list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}")
+  endif()
   execute_process(
       COMMAND ${CLANG_COMMAND}
       RESULT_VARIABLE HAD_ERROR

+ 3 - 1
cmake/config-ix.cmake

@@ -31,7 +31,9 @@ if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
   if (LIBCXX_USE_COMPILER_RT)
-    list(APPEND CMAKE_REQUIRED_LIBRARIES -rtlib=compiler-rt)
+    list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
+    find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXX_BUILTINS_LIBRARY}")
   elseif (LIBCXX_HAS_GCC_S_LIB)
     list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
   endif ()

+ 6 - 1
lib/CMakeLists.txt

@@ -83,7 +83,12 @@ add_library_flags_if(LIBCXX_HAS_PTHREAD_LIB pthread)
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+if (LIBCXX_USE_COMPILER_RT)
+  find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
+  add_library_flags_if(LIBCXX_BUILTINS_LIBRARY "${LIBCXX_BUILTINS_LIBRARY}")
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+endif()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.