[PATCH] D21599: [Libcxx][MIPS] Use LLVM CheckAtomic.cmake module to figure out whether we need to link with libatomic.

Nitesh Jain via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 22 00:45:21 PDT 2016


nitesh.jain created this revision.
nitesh.jain added reviewers: dsanders, vkalintiris, joerg, jroelofs, EricWF, mclow.lists.
nitesh.jain added subscribers: jaydeep, bhushan, slthakur, mohit.bhakkad, zturner, cfe-commits.
nitesh.jain set the repository for this revision to rL LLVM.

The patch http://reviews.llvm.org/D20896 add check for 64 bit atomic operations in LLVM CheckAtomic.cmake module. We can than used this module to figure out whether we need to link with libatomic.

Repository:
  rL LLVM

http://reviews.llvm.org/D21599

Files:
  cmake/Modules/CheckLibcxxAtomic.cmake
  cmake/config-ix.cmake
  lib/CMakeLists.txt
  test/CMakeLists.txt
  test/lit.site.cfg.in

Index: test/lit.site.cfg.in
===================================================================
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -22,7 +22,7 @@
 config.target_info              = "@LIBCXX_TARGET_INFO@"
 config.executor                 = "@LIBCXX_EXECUTOR@"
 config.llvm_unwinder            = "@LIBCXXABI_USE_LLVM_UNWINDER@"
-config.use_libatomic            = "@LIBCXX_HAS_ATOMIC_LIB@"
+config.use_libatomic            = "@HAVE_CXX_LIBATOMICS64@"
 config.libcxxabi_shared         = "@LIBCXXABI_ENABLE_SHARED@"
 
 # Let the main config do the real work.
Index: test/CMakeLists.txt
===================================================================
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -18,7 +18,7 @@
 pythonize_bool(LIBCXX_GENERATE_COVERAGE)
 pythonize_bool(LIBCXXABI_ENABLE_SHARED)
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
-pythonize_bool(LIBCXX_HAS_ATOMIC_LIB)
+pythonize_bool(HAVE_CXX_LIBATOMICS64)
 
 # The tests shouldn't link to any ABI library when it has been linked into
 # libc++ statically or via a linker script.
Index: lib/CMakeLists.txt
===================================================================
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -79,7 +79,7 @@
 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)
-add_library_flags_if(LIBCXX_HAS_ATOMIC_LIB atomic)
+add_library_flags_if(HAVE_CXX_LIBATOMICS64 atomic)
 
 # Setup flags.
 add_flags_if_supported(-fPIC)
Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -1,6 +1,5 @@
 include(CheckLibraryExists)
 include(CheckCXXCompilerFlag)
-include(CheckLibcxxAtomic)
 
 # Check compiler flags
 
Index: cmake/Modules/CheckLibcxxAtomic.cmake
===================================================================
--- cmake/Modules/CheckLibcxxAtomic.cmake
+++ /dev/null
@@ -1,41 +0,0 @@
-INCLUDE(CheckCXXSourceCompiles)
-
-# Sometimes linking against libatomic is required for atomic ops, if
-# the platform doesn't support lock-free atomics.
-#
-# We could modify LLVM's CheckAtomic module and have it check for 64-bit
-# atomics instead. However, we would like to avoid careless uses of 64-bit
-# atomics inside LLVM over time on 32-bit platforms.
-
-function(check_cxx_atomics varname)
-  set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-  set(CMAKE_REQUIRED_FLAGS "-std=c++11 -nostdinc++ -isystem ${LIBCXX_SOURCE_DIR}/include")
-  if (${LIBCXX_GCC_TOOLCHAIN})
-    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")
-  endif()
-  check_cxx_source_compiles("
-#include <cstdint>
-#include <atomic>
-std::atomic<uintptr_t> x;
-std::atomic<uintmax_t> y;
-int main() {
-  return x + y;
-}
-" ${varname})
-  set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
-endfunction(check_cxx_atomics)
-
-check_cxx_atomics(LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB)
-# If not, check if the library exists, and atomics work with it.
-if(NOT LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB)
-  check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
-  if(LIBCXX_HAS_ATOMIC_LIB)
-    list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
-    check_cxx_atomics(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
-    if (NOT LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
-      message(WARNING "Host compiler must support std::atomic!")
-    endif()
-  else()
-    message(WARNING "Host compiler appears to require libatomic, but cannot find it.")
-  endif()
-endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21599.61510.patch
Type: text/x-patch
Size: 3558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160622/6469127d/attachment.bin>


More information about the cfe-commits mailing list