Index: libcxx/CMakeLists.txt =================================================================== --- libcxx/CMakeLists.txt +++ libcxx/CMakeLists.txt @@ -120,6 +120,7 @@ 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_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") +option(LIBCXX_ABI_HIDDEN_USE_INTERNAL_LINKAGE "Give internal linkage to symbols that are not part of the ABI" OFF) set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.") option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) @@ -662,6 +663,7 @@ 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_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT) +config_define_if(LIBCXX_ABI_HIDDEN_USE_INTERNAL_LINKAGE _LIBCPP_ABI_HIDDEN_USE_INTERNAL_LINKAGE) config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) Index: libcxx/docs/BuildingLibcxx.rst =================================================================== --- libcxx/docs/BuildingLibcxx.rst +++ libcxx/docs/BuildingLibcxx.rst @@ -351,6 +351,15 @@ Build the "unstable" ABI version of libc++. Includes all ABI changing features on top of the current stable version. +.. option:: LIBCXX_ABI_HIDDEN_USE_INTERNAL_LINKAGE:BOOL + + **Default**: ``OFF`` + + Give internal linkage to all symbols that are not part of the ABI. This + allows linking translation units built with different versions of libc++ + together, at the cost of code bloat (because non exported functions are + duplicated in each TU). + .. option:: LIBCXX_ABI_DEFINES:STRING **Default**: ``""`` Index: libcxx/docs/DesignDocs/VisibilityMacros.rst =================================================================== --- libcxx/docs/DesignDocs/VisibilityMacros.rst +++ libcxx/docs/DesignDocs/VisibilityMacros.rst @@ -42,9 +42,7 @@ **_LIBCPP_HIDE_FROM_ABI** Mark a function as not being part of the ABI of any final linked image that - uses it, and also as being internal to each TU that uses that function. In - other words, the address of a function marked with this attribute is not - guaranteed to be the same across translation units. + uses it. **_LIBCPP_HIDE_FROM_ABI_AFTER_V1** Mark a function as being hidden from the ABI (per `_LIBCPP_HIDE_FROM_ABI`) @@ -61,6 +59,21 @@ ABI, we should create a new _LIBCPP_HIDE_FROM_ABI_AFTER_XXX macro, and we can use it to start removing symbols from the ABI after that stable version. +**_LIBCPP_ABI_HIDDEN_USE_INTERNAL_LINKAGE** + This macro controls whether symbols hidden from the ABI with `_LIBCPP_HIDE_FROM_ABI` + are local to each translation unit in addition to being local to each final + linked image. When enabled, this means that translation units compiled + with different versions of libc++ can be linked together, since all non + ABI-facing functions are local to each translation unit. This allows static + archives built with different versions of libc++ to be linked together. This + also means that functions marked with `_LIBCPP_HIDE_FROM_ABI` are not guaranteed + to have the same address across translation unit boundaries. + + When the macro is not defined (the default), there is no guarantee that + translation units compiled with different versions of libc++ can interoperate. + However, this leads to code size improvements, since non ABI-facing functions + can be deduplicated across translation unit boundaries. + **_LIBCPP_TYPE_VIS** Mark a type's typeinfo, vtable and members as having default visibility. This attribute cannot be used on class templates. Index: libcxx/include/__config =================================================================== --- libcxx/include/__config +++ libcxx/include/__config @@ -796,7 +796,11 @@ #endif #ifndef _LIBCPP_HIDE_FROM_ABI -# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE +# ifdef _LIBCPP_ABI_HIDDEN_USE_INTERNAL_LINKAGE +# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE +# else +# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_ALWAYS_INLINE +# endif #endif #ifdef _LIBCPP_BUILDING_LIBRARY Index: libcxx/include/__config_site.in =================================================================== --- libcxx/include/__config_site.in +++ libcxx/include/__config_site.in @@ -14,6 +14,7 @@ #cmakedefine _LIBCPP_ABI_UNSTABLE #cmakedefine _LIBCPP_ABI_FORCE_ITANIUM #cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT +#cmakedefine _LIBCPP_ABI_HIDDEN_USE_INTERNAL_LINKAGE #cmakedefine _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE #cmakedefine _LIBCPP_HAS_NO_STDIN #cmakedefine _LIBCPP_HAS_NO_STDOUT