diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -56,6 +56,15 @@ related to missing declarations inside namespace ``std`` when updating libc++, you are probably missing ``#include `` in a file where you use algorithms. +- Users can now enable assertions inside libc++ by defining ``_LIBCPP_DEBUG=0`` on + the command-line, regardless of how the library was built (usually by a vendor). + Note that if the library was built with assertions disabled, any function that is + compiled into the library won't have assertions enabled, but functions compiled into + your own code (usually those defined in the headers) will have assertions enabled. + + This feature requires library support, so it is not enabled when deploying on + platforms that have not previously shipped with the ability to turn assertions on. + ABI Changes ----------- diff --git a/libcxx/include/__assert b/libcxx/include/__assert --- a/libcxx/include/__assert +++ b/libcxx/include/__assert @@ -10,6 +10,7 @@ #ifndef _LIBCPP___ASSERT #define _LIBCPP___ASSERT +#include <__availability> #include <__config> #include // for std::string @@ -40,6 +41,7 @@ __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m) : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {} + _LIBCPP_AVAILABILITY_ASSERTIONS _LIBCPP_FUNC_VIS string what() const; const char* __file_; @@ -53,15 +55,16 @@ /// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT /// fails. +_LIBCPP_AVAILABILITY_ASSERTIONS extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function; /// __libcpp_abort_debug_function - A debug handler that aborts when called. -_LIBCPP_NORETURN _LIBCPP_FUNC_VIS +_LIBCPP_AVAILABILITY_ASSERTIONS _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __libcpp_abort_debug_function(__libcpp_debug_info const&); /// __libcpp_set_debug_function - Set the debug handler to the specified /// function. -_LIBCPP_FUNC_VIS +_LIBCPP_AVAILABILITY_ASSERTIONS _LIBCPP_FUNC_VIS bool __libcpp_set_debug_function(__libcpp_debug_function_type __func); _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__availability b/libcxx/include/__availability --- a/libcxx/include/__availability +++ b/libcxx/include/__availability @@ -81,6 +81,10 @@ #if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) + // This controls whether users are allowed to turn on assertions + // when using the library. +# define _LIBCPP_AVAILABILITY_ASSERTIONS + // This controls the availability of std::shared_mutex and std::shared_timed_mutex, // which were added to the dylib later. # define _LIBCPP_AVAILABILITY_SHARED_MUTEX @@ -151,6 +155,9 @@ #elif defined(__APPLE__) +# define _LIBCPP_AVAILABILITY_ASSERTIONS \ + __attribute__((unavailable)) + # define _LIBCPP_AVAILABILITY_SHARED_MUTEX \ __attribute__((availability(macosx,strict,introduced=10.12))) \ __attribute__((availability(ios,strict,introduced=10.0))) \ diff --git a/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.nodebug.noincomplete.abilist b/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.nodebug.noincomplete.abilist --- a/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.nodebug.noincomplete.abilist +++ b/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.nodebug.noincomplete.abilist @@ -526,6 +526,7 @@ {'is_defined': True, 'name': '__ZNKSt3__117moneypunct_bynameIwLb1EE16do_thousands_sepEv', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNKSt3__118__time_get_storageIcE15__do_date_orderEv', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNKSt3__118__time_get_storageIwE15__do_date_orderEv', 'type': 'FUNC'} +{'is_defined': True, 'name': '__ZNKSt3__119__libcpp_debug_info4whatEv', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNKSt3__119__shared_weak_count13__get_deleterERKSt9type_info', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNKSt3__120__codecvt_utf8_utf16IDiE10do_unshiftER11__mbstate_tPcS4_RS4_', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNKSt3__120__codecvt_utf8_utf16IDiE11do_encodingEv', 'type': 'FUNC'} @@ -1533,6 +1534,7 @@ {'is_defined': True, 'name': '__ZNSt3__123__cxx_atomic_notify_oneEPVKv', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__123__libcpp_atomic_monitorEPVKNS_17__cxx_atomic_implIxNS_22__cxx_atomic_base_implIxEEEE', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__123__libcpp_atomic_monitorEPVKv', 'type': 'FUNC'} +{'is_defined': True, 'name': '__ZNSt3__123__libcpp_debug_functionE', 'size': 0, 'type': 'OBJECT'} {'is_defined': True, 'name': '__ZNSt3__125notify_all_at_thread_exitERNS_18condition_variableENS_11unique_lockINS_5mutexEEE', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__127__insertion_sort_incompleteIRNS_6__lessIaaEEPaEEbT0_S5_T_', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__127__insertion_sort_incompleteIRNS_6__lessIccEEPcEEbT0_S5_T_', 'type': 'FUNC'} @@ -1549,6 +1551,8 @@ {'is_defined': True, 'name': '__ZNSt3__127__insertion_sort_incompleteIRNS_6__lessIwwEEPwEEbT0_S5_T_', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__127__insertion_sort_incompleteIRNS_6__lessIxxEEPxEEbT0_S5_T_', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__127__insertion_sort_incompleteIRNS_6__lessIyyEEPyEEbT0_S5_T_', 'type': 'FUNC'} +{'is_defined': True, 'name': '__ZNSt3__127__libcpp_set_debug_functionEPFvRKNS_19__libcpp_debug_infoEE', 'type': 'FUNC'} +{'is_defined': True, 'name': '__ZNSt3__129__libcpp_abort_debug_functionERKNS_19__libcpp_debug_infoE', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__131__arrive_barrier_algorithm_baseEPNS_24__barrier_algorithm_baseEh', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__132__destroy_barrier_algorithm_baseEPNS_24__barrier_algorithm_baseE', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__134__construct_barrier_algorithm_baseERl', 'type': 'FUNC'} diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -4,6 +4,7 @@ set(LIBCXX_SOURCES algorithm.cpp any.cpp + assert.cpp atomic.cpp barrier.cpp bind.cpp @@ -65,7 +66,6 @@ if (LIBCXX_ENABLE_DEBUG_MODE_SUPPORT) list(APPEND LIBCXX_SOURCES - assert.cpp debug.cpp ) endif()