<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Courier New;color: #000000;font-size: 10pt;">
Hi Eric,<br>
<br>
Your changes work fine for me. Out of curiosity, the correctness issue you mentioned was about the lines you removed from config-ix.cmake, right?<br>
<br>
- Vasileios<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF433687"><font color="#000000" size="2" face="Tahoma"><b>From:</b> Eric Fiselier [eric@efcs.ca]<br>
<b>Sent:</b> 11 February 2016 15:11<br>
<b>To:</b> Vasileios Kalintiris<br>
<b>Cc:</b> cfe-commits<br>
<b>Subject:</b> Re: [libcxx] r260515 - Re-commit "Introduce a cmake module to figure out whether we need to link with libatomic."<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">Hi Vasileios,
<div><br>
</div>
<div>This patch doesn't quite work correctly. I've committed a follow up fix to it as r260524.</div>
<div><br>
</div>
<div>Let me know if you have any issues.</div>
<div><br>
</div>
<div>/Eric</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Feb 11, 2016 at 5:43 AM, Vasileios Kalintiris via cfe-commits
<span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
Author: vkalintiris<br>
Date: Thu Feb 11 06:43:04 2016<br>
New Revision: 260515<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=260515&view=rev" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=260515&view=rev</a><br>
Log:<br>
Re-commit "Introduce a cmake module to figure out whether we need to link with libatomic."<br>
<br>
This re-applies commit r260235. However, this time we add -gcc-toolchain<br>
to the compiler's flags when the user has specified the LIBCXX_GCC_TOOLCHAIN<br>
variable.<br>
<br>
Added:<br>
    libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake<br>
Modified:<br>
    libcxx/trunk/cmake/config-ix.cmake<br>
    libcxx/trunk/lib/CMakeLists.txt<br>
    libcxx/trunk/test/CMakeLists.txt<br>
    libcxx/trunk/test/libcxx/test/target_info.py<br>
    libcxx/trunk/test/<a href="http://lit.site.cfg.in" rel="noreferrer" target="_blank">lit.site.cfg.in</a><br>
<br>
Added: libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake?rev=260515&view=auto" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake?rev=260515&view=auto</a><br>
==============================================================================<br>
--- libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake (added)<br>
+++ libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake Thu Feb 11 06:43:04 2016<br>
@@ -0,0 +1,41 @@<br>
+INCLUDE(CheckCXXSourceCompiles)<br>
+<br>
+# Sometimes linking against libatomic is required for atomic ops, if<br>
+# the platform doesn't support lock-free atomics.<br>
+#<br>
+# We could modify LLVM's CheckAtomic module and have it check for 64-bit<br>
+# atomics instead. However, we would like to avoid careless uses of 64-bit<br>
+# atomics inside LLVM over time on 32-bit platforms.<br>
+<br>
+function(check_cxx_atomics varname)<br>
+  set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})<br>
+  set(CMAKE_REQUIRED_FLAGS "-std=c++11")<br>
+  if (${LIBCXX_GCC_TOOLCHAIN})<br>
+    set(CMAKE_REQUIRED_FLAGS "-std=c++11 --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")<br>
+  endif()<br>
+  check_cxx_source_compiles("<br>
+#include <cstdint><br>
+#include <atomic><br>
+std::atomic<uintptr_t> x;<br>
+std::atomic<uintmax_t> y;<br>
+int main() {<br>
+  return x + y;<br>
+}<br>
+" ${varname})<br>
+  set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})<br>
+endfunction(check_cxx_atomics)<br>
+<br>
+check_cxx_atomics(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)<br>
+# If not, check if the library exists, and atomics work with it.<br>
+if(NOT LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)<br>
+  check_library_exists(atomic __atomic_fetch_add_8 "" HAVE_LIBATOMIC)<br>
+  if(HAVE_LIBATOMIC)<br>
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")<br>
+    check_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)<br>
+    if (NOT HAVE_CXX_ATOMICS_WITH_LIB)<br>
+      message(FATAL_ERROR "Host compiler must support std::atomic!")<br>
+    endif()<br>
+  else()<br>
+    message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")<br>
+  endif()<br>
+endif()<br>
<br>
Modified: libcxx/trunk/cmake/config-ix.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/config-ix.cmake?rev=260515&r1=260514&r2=260515&view=diff" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/config-ix.cmake?rev=260515&r1=260514&r2=260515&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/cmake/config-ix.cmake (original)<br>
+++ libcxx/trunk/cmake/config-ix.cmake Thu Feb 11 06:43:04 2016<br>
@@ -1,5 +1,6 @@<br>
 include(CheckLibraryExists)<br>
 include(CheckCXXCompilerFlag)<br>
+include(CheckLibcxxAtomic)<br>
<br>
 # Check compiler flags<br>
<br>
@@ -17,3 +18,7 @@ check_library_exists(c fopen "" LIBCXX_H<br>
 check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)<br>
 check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)<br>
 check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB)<br>
+<br>
+if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)<br>
+  set(LIBCXX_HAS_ATOMIC_LIB True)<br>
+endif()<br>
<br>
Modified: libcxx/trunk/lib/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=260515&r1=260514&r2=260515&view=diff" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=260515&r1=260514&r2=260515&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/lib/CMakeLists.txt (original)<br>
+++ libcxx/trunk/lib/CMakeLists.txt Thu Feb 11 06:43:04 2016<br>
@@ -79,6 +79,7 @@ add_library_flags_if(LIBCXX_HAS_C_LIB c)<br>
 add_library_flags_if(LIBCXX_HAS_M_LIB m)<br>
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)<br>
 add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)<br>
+add_library_flags_if(LIBCXX_HAS_ATOMIC_LIB atomic)<br>
<br>
 # Setup flags.<br>
 add_flags_if_supported(-fPIC)<br>
<br>
Modified: libcxx/trunk/test/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=260515&r1=260514&r2=260515&view=diff" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=260515&r1=260514&r2=260515&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/CMakeLists.txt (original)<br>
+++ libcxx/trunk/test/CMakeLists.txt Thu Feb 11 06:43:04 2016<br>
@@ -15,6 +15,7 @@ pythonize_bool(LIBCXX_ENABLE_SHARED)<br>
 pythonize_bool(LIBCXX_BUILD_32_BITS)<br>
 pythonize_bool(LIBCXX_GENERATE_COVERAGE)<br>
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)<br>
+pythonize_bool(LIBCXX_HAS_ATOMIC_LIB)<br>
<br>
 # The tests shouldn't link to any ABI library when it has been linked into<br>
 # libc++ statically or via a linker script.<br>
<br>
Modified: libcxx/trunk/test/libcxx/test/target_info.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/target_info.py?rev=260515&r1=260514&r2=260515&view=diff" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/target_info.py?rev=260515&r1=260514&r2=260515&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/libcxx/test/target_info.py (original)<br>
+++ libcxx/trunk/test/libcxx/test/target_info.py Thu Feb 11 06:43:04 2016<br>
@@ -172,6 +172,9 @@ class LinuxLocalTI(DefaultTargetInfo):<br>
             flags += ['-lunwind', '-ldl']<br>
         else:<br>
             flags += ['-lgcc_s', '-lgcc']<br>
+        use_libatomic = self.full_config.get_lit_bool('use_libatomic', False)<br>
+        if use_libatomic:<br>
+            flags += ['-latomic']<br>
         san = self.full_config.get_lit_conf('use_sanitizer', '').strip()<br>
         if san:<br>
             # The libraries and their order are taken from the<br>
<br>
Modified: libcxx/trunk/test/<a href="http://lit.site.cfg.in" rel="noreferrer" target="_blank">lit.site.cfg.in</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/lit.site.cfg.in?rev=260515&r1=260514&r2=260515&view=diff" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/lit.site.cfg.in?rev=260515&r1=260514&r2=260515&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/<a href="http://lit.site.cfg.in" rel="noreferrer" target="_blank">lit.site.cfg.in</a> (original)<br>
+++ libcxx/trunk/test/<a href="http://lit.site.cfg.in" rel="noreferrer" target="_blank">lit.site.cfg.in</a> Thu Feb 11 06:43:04 2016<br>
@@ -20,6 +20,7 @@ config.generate_coverage        = "@LIBC<br>
 config.target_info              = "@LIBCXX_TARGET_INFO@"<br>
 config.executor                 = "@LIBCXX_EXECUTOR@"<br>
 config.llvm_unwinder            = "@LIBCXXABI_USE_LLVM_UNWINDER@"<br>
+config.use_libatomic            = "@LIBCXX_HAS_ATOMIC_LIB@"<br>
<br>
 # Let the main config do the real work.<br>
 lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>