Index: libcxx/docs/DesignDocs/VisibilityMacros.rst =================================================================== --- libcxx/docs/DesignDocs/VisibilityMacros.rst +++ libcxx/docs/DesignDocs/VisibilityMacros.rst @@ -40,7 +40,7 @@ this macro therefore expands to `__declspec(dllexport)` when building the library and has an empty definition otherwise. -**_LIBCPP_INLINE_VISIBILITY** +**_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 Index: libcxx/include/__config =================================================================== --- libcxx/include/__config +++ libcxx/include/__config @@ -481,6 +481,8 @@ #define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS #endif +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) + #elif defined(_LIBCPP_COMPILER_GCC) #define _ALIGNAS(x) __attribute__((__aligned__(x))) @@ -572,6 +574,8 @@ #define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS #endif +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) + #elif defined(_LIBCPP_COMPILER_MSVC) #define _LIBCPP_TOSTRING2(x) #x @@ -604,6 +608,8 @@ #define _LIBCPP_HAS_NO_ASAN +#define _LIBCPP_ALWAYS_INLINE __forceinline + #elif defined(_LIBCPP_COMPILER_IBM) #define _ALIGNAS(x) __attribute__((__aligned__(x))) @@ -634,6 +640,8 @@ #define _LIBCPP_HAS_NO_ASAN +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) + #endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM] #if defined(_LIBCPP_OBJECT_FORMAT_COFF) @@ -671,10 +679,8 @@ #define _LIBCPP_ENUM_VIS #if defined(_LIBCPP_COMPILER_MSVC) -# define _LIBCPP_INLINE_VISIBILITY __forceinline # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __forceinline #else -# define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__)) # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __attribute__ ((__always_inline__)) #endif @@ -761,14 +767,24 @@ #define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS #endif -#ifndef _LIBCPP_INLINE_VISIBILITY -# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) -# define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__)) -# else -# define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__)) -# endif +// _LIBCPP_INTERNAL_LINKAGE tries its best to give internal linkage (i.e. +// the `static` keyword in C) to the function it is applied to. When the +// `internal_linkage` attribute is not available, we fall back to forcing +// the function to be inlined, which approximates internal linkage since +// an externally visible symbol is never generated for that function. +#if __has_attribute(internal_linkage) +# define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage)) +#else +# define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE #endif +#ifndef _LIBCPP_HIDE_FROM_ABI +# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE +#endif + +// Just so we can migrate to _LIBCPP_HIDE_FROM_ABI gradually. +#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI + #ifndef _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __attribute__((__visibility__("default"), __always_inline__))