[libcxx] r260515 - Re-commit "Introduce a cmake module to figure out whether we need to link with libatomic."

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 11 08:02:55 PST 2016


There were a couple of correctness issues. 'LIBCXX_HAS_ATOMIC_WITHOUT_LIB'
was accidentally typo-ed '_WITH_' in a couple of places and
'LIBCXX_HAS_ATOMIC_LIB' was not originally a cache variable like it
probably should have been.

I just used 'LIBCXX_HAS_ATOMIC_LIB' directly in 'check_library_exists' and
everything works better :-)

/Eric

On Thu, Feb 11, 2016 at 8:54 AM, Vasileios Kalintiris <
Vasileios.Kalintiris at imgtec.com> wrote:

> Hi Eric,
>
> 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?
>
> - Vasileios
> ------------------------------
> *From:* Eric Fiselier [eric at efcs.ca]
> *Sent:* 11 February 2016 15:11
> *To:* Vasileios Kalintiris
> *Cc:* cfe-commits
> *Subject:* Re: [libcxx] r260515 - Re-commit "Introduce a cmake module to
> figure out whether we need to link with libatomic."
>
> Hi Vasileios,
>
> This patch doesn't quite work correctly. I've committed a follow up fix to
> it as r260524.
>
> Let me know if you have any issues.
>
> /Eric
>
> On Thu, Feb 11, 2016 at 5:43 AM, Vasileios Kalintiris via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
>
>> Author: vkalintiris
>> Date: Thu Feb 11 06:43:04 2016
>> New Revision: 260515
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=260515&view=rev
>> Log:
>> Re-commit "Introduce a cmake module to figure out whether we need to link
>> with libatomic."
>>
>> This re-applies commit r260235. However, this time we add -gcc-toolchain
>> to the compiler's flags when the user has specified the
>> LIBCXX_GCC_TOOLCHAIN
>> variable.
>>
>> Added:
>>     libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake
>> Modified:
>>     libcxx/trunk/cmake/config-ix.cmake
>>     libcxx/trunk/lib/CMakeLists.txt
>>     libcxx/trunk/test/CMakeLists.txt
>>     libcxx/trunk/test/libcxx/test/target_info.py
>>     libcxx/trunk/test/lit.site.cfg.in
>>
>> Added: libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake?rev=260515&view=auto
>>
>> ==============================================================================
>> --- libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake (added)
>> +++ libcxx/trunk/cmake/Modules/CheckLibcxxAtomic.cmake Thu Feb 11
>> 06:43:04 2016
>> @@ -0,0 +1,41 @@
>> +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")
>> +  if (${LIBCXX_GCC_TOOLCHAIN})
>> +    set(CMAKE_REQUIRED_FLAGS "-std=c++11
>> --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_WITH_LIB)
>> +# If not, check if the library exists, and atomics work with it.
>> +if(NOT LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
>> +  check_library_exists(atomic __atomic_fetch_add_8 "" HAVE_LIBATOMIC)
>> +  if(HAVE_LIBATOMIC)
>> +    list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
>> +    check_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
>> +    if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
>> +      message(FATAL_ERROR "Host compiler must support std::atomic!")
>> +    endif()
>> +  else()
>> +    message(FATAL_ERROR "Host compiler appears to require libatomic, but
>> cannot find it.")
>> +  endif()
>> +endif()
>>
>> Modified: libcxx/trunk/cmake/config-ix.cmake
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/config-ix.cmake?rev=260515&r1=260514&r2=260515&view=diff
>>
>> ==============================================================================
>> --- libcxx/trunk/cmake/config-ix.cmake (original)
>> +++ libcxx/trunk/cmake/config-ix.cmake Thu Feb 11 06:43:04 2016
>> @@ -1,5 +1,6 @@
>>  include(CheckLibraryExists)
>>  include(CheckCXXCompilerFlag)
>> +include(CheckLibcxxAtomic)
>>
>>  # Check compiler flags
>>
>> @@ -17,3 +18,7 @@ check_library_exists(c fopen "" LIBCXX_H
>>  check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
>>  check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
>>  check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB)
>> +
>> +if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
>> +  set(LIBCXX_HAS_ATOMIC_LIB True)
>> +endif()
>>
>> Modified: libcxx/trunk/lib/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=260515&r1=260514&r2=260515&view=diff
>>
>> ==============================================================================
>> --- libcxx/trunk/lib/CMakeLists.txt (original)
>> +++ libcxx/trunk/lib/CMakeLists.txt Thu Feb 11 06:43:04 2016
>> @@ -79,6 +79,7 @@ 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)
>> +add_library_flags_if(LIBCXX_HAS_ATOMIC_LIB atomic)
>>
>>  # Setup flags.
>>  add_flags_if_supported(-fPIC)
>>
>> Modified: libcxx/trunk/test/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=260515&r1=260514&r2=260515&view=diff
>>
>> ==============================================================================
>> --- libcxx/trunk/test/CMakeLists.txt (original)
>> +++ libcxx/trunk/test/CMakeLists.txt Thu Feb 11 06:43:04 2016
>> @@ -15,6 +15,7 @@ pythonize_bool(LIBCXX_ENABLE_SHARED)
>>  pythonize_bool(LIBCXX_BUILD_32_BITS)
>>  pythonize_bool(LIBCXX_GENERATE_COVERAGE)
>>  pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
>> +pythonize_bool(LIBCXX_HAS_ATOMIC_LIB)
>>
>>  # The tests shouldn't link to any ABI library when it has been linked
>> into
>>  # libc++ statically or via a linker script.
>>
>> Modified: libcxx/trunk/test/libcxx/test/target_info.py
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/target_info.py?rev=260515&r1=260514&r2=260515&view=diff
>>
>> ==============================================================================
>> --- libcxx/trunk/test/libcxx/test/target_info.py (original)
>> +++ libcxx/trunk/test/libcxx/test/target_info.py Thu Feb 11 06:43:04 2016
>> @@ -172,6 +172,9 @@ class LinuxLocalTI(DefaultTargetInfo):
>>              flags += ['-lunwind', '-ldl']
>>          else:
>>              flags += ['-lgcc_s', '-lgcc']
>> +        use_libatomic = self.full_config.get_lit_bool('use_libatomic',
>> False)
>> +        if use_libatomic:
>> +            flags += ['-latomic']
>>          san = self.full_config.get_lit_conf('use_sanitizer', '').strip()
>>          if san:
>>              # The libraries and their order are taken from the
>>
>> Modified: libcxx/trunk/test/lit.site.cfg.in
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/lit.site.cfg.in?rev=260515&r1=260514&r2=260515&view=diff
>>
>> ==============================================================================
>> --- libcxx/trunk/test/lit.site.cfg.in (original)
>> +++ libcxx/trunk/test/lit.site.cfg.in Thu Feb 11 06:43:04 2016
>> @@ -20,6 +20,7 @@ config.generate_coverage        = "@LIBC
>>  config.target_info              = "@LIBCXX_TARGET_INFO@"
>>  config.executor                 = "@LIBCXX_EXECUTOR@"
>>  config.llvm_unwinder            = "@LIBCXXABI_USE_LLVM_UNWINDER@"
>> +config.use_libatomic            = "@LIBCXX_HAS_ATOMIC_LIB@"
>>
>>  # Let the main config do the real work.
>>  lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160211/d0cec7f2/attachment.html>


More information about the cfe-commits mailing list