forked from OSchip/llvm-project
Make libc++'s versioning namespace customizable
Summary: This patch makes the versioning namespace libc++ uses customizable by the user using `-DLIBCXX_ABI_NAMESPACE=__foo`. This allows users to build custom versions of libc++ which can be linked into binaries with other libc++ versions without causing symbol conflicts or ODR issues. Reviewers: mclow.lists, ldionne Reviewed By: ldionne Subscribers: kristina, smeenai, mgorny, phosek, libcxx-commits Differential Revision: https://reviews.llvm.org/D53879 llvm-svn: 345657
This commit is contained in:
parent
c8d94f3847
commit
fe13c13cc2
|
@ -117,6 +117,7 @@ cmake_dependent_option(LIBCXX_INSTALL_FILESYSTEM_LIBRARY
|
||||||
"LIBCXX_ENABLE_FILESYSTEM;LIBCXX_INSTALL_LIBRARY" OFF)
|
"LIBCXX_ENABLE_FILESYSTEM;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_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 "Unstable ABI of libc++." OFF)
|
||||||
option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.")
|
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.")
|
option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.")
|
||||||
|
@ -680,6 +681,15 @@ endif()
|
||||||
if (NOT LIBCXX_ABI_VERSION EQUAL 1)
|
if (NOT LIBCXX_ABI_VERSION EQUAL 1)
|
||||||
config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
|
config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION)
|
||||||
endif()
|
endif()
|
||||||
|
if (NOT LIBCXX_ABI_NAMESPACE STREQUAL "")
|
||||||
|
if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*")
|
||||||
|
message(WARNING "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_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE)
|
||||||
config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
|
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_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
|
||||||
|
|
|
@ -360,6 +360,18 @@ The following options allow building libc++ for a different ABI version.
|
||||||
Build the "unstable" ABI version of libc++. Includes all ABI changing features
|
Build the "unstable" ABI version of libc++. Includes all ABI changing features
|
||||||
on top of the current stable version.
|
on top of the current stable version.
|
||||||
|
|
||||||
|
.. option:: LIBCXX_ABI_NAMESPACE:STRING
|
||||||
|
|
||||||
|
**Default**: ``__n`` where ``n`` is the current ABI version.
|
||||||
|
|
||||||
|
This option defines the name of the inline ABI versioning namespace. It can be used for building
|
||||||
|
custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues
|
||||||
|
with other libc++ versions.
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
When providing a custom namespace, it's the users responsibility to ensure the name won't cause
|
||||||
|
conflicts with other names defined by libc++, both now and in the future.
|
||||||
|
|
||||||
.. option:: LIBCXX_ABI_DEFINES:STRING
|
.. option:: LIBCXX_ABI_DEFINES:STRING
|
||||||
|
|
||||||
**Default**: ``""``
|
**Default**: ``""``
|
||||||
|
|
|
@ -119,7 +119,9 @@
|
||||||
#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
|
#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
|
||||||
#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
|
#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
|
||||||
|
|
||||||
#define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
|
#ifndef _LIBCPP_ABI_NAMESPACE
|
||||||
|
# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if __cplusplus < 201103L
|
#if __cplusplus < 201103L
|
||||||
#define _LIBCPP_CXX03_LANG
|
#define _LIBCPP_CXX03_LANG
|
||||||
|
@ -791,9 +793,9 @@ typedef __char32_t char32_t;
|
||||||
#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
|
#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
|
||||||
|
|
||||||
// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
|
// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
|
||||||
#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_NAMESPACE {
|
#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
|
||||||
#define _LIBCPP_END_NAMESPACE_STD } }
|
#define _LIBCPP_END_NAMESPACE_STD } }
|
||||||
#define _VSTD std::_LIBCPP_NAMESPACE
|
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
|
||||||
|
|
||||||
#if _LIBCPP_STD_VER >= 17
|
#if _LIBCPP_STD_VER >= 17
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
|
#cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
|
||||||
#cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
|
#cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
|
||||||
#cmakedefine _LIBCPP_NO_VCRUNTIME
|
#cmakedefine _LIBCPP_NO_VCRUNTIME
|
||||||
|
#cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@
|
||||||
|
|
||||||
@_LIBCPP_ABI_DEFINES@
|
@_LIBCPP_ABI_DEFINES@
|
||||||
|
|
||||||
|
|
|
@ -13,21 +13,21 @@
|
||||||
|
|
||||||
#define _str(s) #s
|
#define _str(s) #s
|
||||||
#define str(s) _str(s)
|
#define str(s) _str(s)
|
||||||
#define _LIBCPP_NAMESPACE_STR str(_LIBCPP_NAMESPACE)
|
#define _LIBCPP_ABI_NAMESPACE_STR str(_LIBCPP_ABI_NAMESPACE)
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_STDIN
|
#ifndef _LIBCPP_HAS_NO_STDIN
|
||||||
_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
|
_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?cin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
|
_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
|
||||||
static mbstate_t mb_cin;
|
static mbstate_t mb_cin;
|
||||||
_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
|
_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?wcin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
|
_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
|
||||||
|
@ -37,14 +37,14 @@ static mbstate_t mb_wcin;
|
||||||
#ifndef _LIBCPP_HAS_NO_STDOUT
|
#ifndef _LIBCPP_HAS_NO_STDOUT
|
||||||
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
|
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?cout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
|
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
|
||||||
static mbstate_t mb_cout;
|
static mbstate_t mb_cout;
|
||||||
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
|
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?wcout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
|
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
|
||||||
|
@ -53,14 +53,14 @@ static mbstate_t mb_wcout;
|
||||||
|
|
||||||
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
|
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?cerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
|
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
|
||||||
static mbstate_t mb_cerr;
|
static mbstate_t mb_cerr;
|
||||||
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
|
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?wcerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
|
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
|
||||||
|
@ -68,12 +68,12 @@ static mbstate_t mb_wcerr;
|
||||||
|
|
||||||
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
|
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?clog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
|
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
|
||||||
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
|
||||||
__asm__("?wclog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
|
__asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue