From 817d897b57c7f37d04c2a28153316efe3ae59ada Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 7 Feb 2022 14:52:17 -0500 Subject: [PATCH] [libc++] Remove _LIBCPP_ABI_UNSTABLE Previously, _LIBCPP_ABI_UNSTABLE would be used interchangeably with _LIBCPP_ABI_VERSION >= 2. This was confusing and creating unnecessary complexity. This patch removes _LIBCPP_ABI_UNSTABLE -- instead, the LIBCXX_ABI_UNSTABLE CMake option will result in the LIBCXX_ABI_VERSION being set to '2', the current unstable ABI. As a result, in the code, we only have _LIBCPP_ABI_VERSION to check in order to query the current ABI version. As a fly-by, this also defines the ABI namespace during CMake configuration to reduce complexity in __config. I believe it was previously done this way because we used to try to use __config_site as seldom as possible. Now that we always ship a __config_site, it doesn't really matter and I think being explicit about how the library is configured in the __config_site is actually a feature. Differential Revision: https://reviews.llvm.org/D119173 --- libcxx/CMakeLists.txt | 29 ++++++++++------------ libcxx/docs/BuildingLibcxx.rst | 6 ++--- libcxx/docs/ReleaseNotes.rst | 6 +++++ libcxx/include/__config | 15 ----------- libcxx/include/__config_site.in | 3 +-- .../pairs.pair/non_trivial_copy_move_ABI.pass.cpp | 15 +++-------- .../pairs.pair/trivial_copy_move_ABI.pass.cpp | 11 ++------ libcxx/utils/gdb/libcxx/printers.py | 3 +-- libcxx/utils/libcxx/test/features.py | 1 - 9 files changed, 29 insertions(+), 60 deletions(-) diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index 3c6bd0f..390c149 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -179,9 +179,17 @@ cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY "Install libc++experimental.a" ON "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF) -set(LIBCXX_ABI_VERSION "1" CACHE STRING "ABI version of libc++. Can be either 1 or 2, where 2 is currently not stable. Defaults to 1.") -set(LIBCXX_ABI_NAMESPACE "" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.") -option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) +option(LIBCXX_ABI_UNSTABLE "Use the unstable ABI of libc++. This is equivalent to specifying LIBCXX_ABI_VERSION=n, where n is the not-yet-stable version." OFF) +if (LIBCXX_ABI_UNSTABLE) + set(abi_version "2") +else() + set(abi_version "1") +endif() +set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI. Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.") +set(LIBCXX_ABI_NAMESPACE "__${LIBCXX_ABI_VERSION}" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.") +if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*") + message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier.") +endif() option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.") option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") @@ -858,19 +866,8 @@ function(cxx_add_windows_flags target) endfunction() # Configuration file flags ===================================================== -if (NOT LIBCXX_ABI_VERSION EQUAL 1) - config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) -endif() -if (NOT LIBCXX_ABI_NAMESPACE STREQUAL "") - if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*") - message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier.") - endif() - if (LIBCXX_ABI_NAMESPACE MATCHES "__[0-9]+$") - message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE '${LIBCXX_ABI_NAMESPACE}' is reserved for use by libc++.") - endif() - config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE) -endif() -config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) +config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) +config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE) config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM) config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT) config_define_if(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT) diff --git a/libcxx/docs/BuildingLibcxx.rst b/libcxx/docs/BuildingLibcxx.rst index b84bf8c..8c0d007 100644 --- a/libcxx/docs/BuildingLibcxx.rst +++ b/libcxx/docs/BuildingLibcxx.rst @@ -443,10 +443,10 @@ The following options allow building libc++ for a different ABI version. with other libc++ versions. .. warning:: - When providing a custom namespace, it's the users responsibility to ensure the name won't cause + When providing a custom namespace, it's the user's responsibility to ensure the name won't cause conflicts with other names defined by libc++, both now and in the future. In particular, inline - namespaces of the form ``__[0-9]+`` are strictly reserved by libc++ and may not be used by users. - Doing otherwise could cause conflicts and hinder libc++ ABI evolution. + namespaces of the form ``__[0-9]+`` could cause conflicts with future versions of the library, + and so should be avoided. .. option:: LIBCXX_ABI_DEFINES:STRING diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst index 6ad7fe9..9bb06cf 100644 --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -41,6 +41,12 @@ New Features API Changes ----------- +- The ``_LIBCPP_ABI_UNSTABLE`` macro has been removed in favour of setting + ``_LIBCPP_ABI_VERSION=2``. This should not have any impact on users because + they were not supposed to set ``_LIBCPP_ABI_UNSTABLE`` manually, however we + still feel that it is worth mentioning in the release notes in case some users + had been doing it. + ABI Changes ----------- diff --git a/libcxx/include/__config b/libcxx/include/__config index 55bb6d6..2f0e8d4 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -26,14 +26,6 @@ #define _LIBCPP_VERSION 15000 -#ifdef _LIBCPP_ABI_UNSTABLE -# define _LIBCPP_ABI_VERSION 2 -#endif - -#ifndef _LIBCPP_ABI_VERSION -# define _LIBCPP_ABI_VERSION 1 -#endif - #if __STDC_HOSTED__ == 0 # define _LIBCPP_FREESTANDING #endif @@ -150,13 +142,6 @@ # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION #endif -#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y -#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) - -#ifndef _LIBCPP_ABI_NAMESPACE -# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) -#endif - #if __cplusplus < 201103L #define _LIBCPP_CXX03_LANG #endif diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in index 59ca229..a1a08a5 100644 --- a/libcxx/include/__config_site.in +++ b/libcxx/include/__config_site.in @@ -10,7 +10,7 @@ #define _LIBCPP_CONFIG_SITE #cmakedefine _LIBCPP_ABI_VERSION @_LIBCPP_ABI_VERSION@ -#cmakedefine _LIBCPP_ABI_UNSTABLE +#cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@ #cmakedefine _LIBCPP_ABI_FORCE_ITANIUM #cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT #cmakedefine _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT @@ -25,7 +25,6 @@ #cmakedefine _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS #cmakedefine _LIBCPP_NO_VCRUNTIME #cmakedefine _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION @_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION@ -#cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@ #cmakedefine _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY #cmakedefine _LIBCPP_HAS_PARALLEL_ALGORITHMS #cmakedefine _LIBCPP_HAS_NO_RANDOM_DEVICE diff --git a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp index acf557d..ddd2c2b 100644 --- a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp +++ b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp @@ -14,14 +14,9 @@ // template struct pair -// Test that we properly provide the trivial copy operations by default. - -// FreeBSD provides the old ABI. This test checks the new ABI so we need -// to manually turn it on. -#undef _LIBCPP_ABI_UNSTABLE -#undef _LIBCPP_ABI_VERSION -#define _LIBCPP_ABI_VERSION 1 -#define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR +// Test that we provide the non-trivial copy operations when _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR +// is specified. +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR #include #include @@ -31,10 +26,6 @@ #include "test_macros.h" -#if !defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) -#error trivial ctor ABI macro defined -#endif - template struct HasNonTrivialABI : std::integral_constant::value diff --git a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp index 1357157..013b79b 100644 --- a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp +++ b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp @@ -12,11 +12,8 @@ // Test that we properly provide the trivial copy operations by default. -// FreeBSD provides the old ABI. This test checks the new ABI so we need -// to manually turn it on. -#if defined(__FreeBSD__) -#define _LIBCPP_ABI_UNSTABLE -#endif +// FreeBSD still provides the old ABI for std::pair. +// XFAIL: freebsd #include #include @@ -26,10 +23,6 @@ #include "test_macros.h" -#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) -#error Non-trivial ctor ABI macro defined -#endif - template struct HasTrivialABI : std::integral_constant::value diff --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py index 3f13b1f..acf77b6 100644 --- a/libcxx/utils/gdb/libcxx/printers.py +++ b/libcxx/utils/gdb/libcxx/printers.py @@ -7,8 +7,7 @@ #===----------------------------------------------------------------------===## """GDB pretty-printers for libc++. -These should work for objects compiled when _LIBCPP_ABI_UNSTABLE is defined -and when it is undefined. +These should work for objects compiled with either the stable ABI or the unstable ABI. """ from __future__ import print_function diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py index 54f318e..5ddc47c 100644 --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -119,7 +119,6 @@ macros = { '_LIBCPP_HAS_THREAD_API_PTHREAD': 'libcpp-has-thread-api-pthread', '_LIBCPP_NO_VCRUNTIME': 'libcpp-no-vcruntime', '_LIBCPP_ABI_VERSION': 'libcpp-abi-version', - '_LIBCPP_ABI_UNSTABLE': 'libcpp-abi-unstable', '_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY': 'libcpp-has-no-filesystem-library', '_LIBCPP_HAS_NO_RANDOM_DEVICE': 'libcpp-has-no-random-device', '_LIBCPP_HAS_NO_LOCALIZATION': 'libcpp-has-no-localization', -- 2.7.4