[PATCH] D49240: [libc++] Introduce _LIBCPP_HIDE_FROM_ABI to replace _LIBCPP_INLINE_VISIBILITY

Louis Dionne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 12 08:08:24 PDT 2018


ldionne created this revision.
ldionne added a reviewer: EricWF.
Herald added subscribers: llvm-commits, dexonsmith, christof.
ldionne planned changes to this revision.

This commit introduces a new macro, _LIBCPP_HIDE_FROM_ABI, whose goal is to
mark functions that shouldn't be part of libc++'s ABI. It marks the functions
as being hidden for dylib visibility purposes, and as having internal linkage
using Clang's __attribute__((internal_linkage)) when available, and
__always_inline__ otherwise.

It replaces _LIBCPP_INLINE_VISIBILITY, which was always using __always_inline__
to achieve similar goals, but suffered from debuggability and code size problems.
The full proposal, along with more background information, can be found here:

  http://lists.llvm.org/pipermail/cfe-dev/2018-July/058419.html

This commit does not rename uses of _LIBCPP_INLINE_VISIBILITY to
_LIBCPP_HIDE_FROM_ABI: this wide reaching but mechanical change can
be done later when we've confirmed we're happy with the new macro.

In the future, it would be nice if we could optionally allow dropping
any internal_linkage or __always_inline__ attribute, which could result
in code size improvements. However, this is currently impossible for
reasons explained here: http://lists.llvm.org/pipermail/cfe-dev/2018-July/058450.html


Repository:
  rL LLVM

https://reviews.llvm.org/D49240

Files:
  libcxx/docs/DesignDocs/VisibilityMacros.rst
  libcxx/include/__config


Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -671,10 +671,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 +759,32 @@
 #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
+#if __has_attribute(__always_inline__)
+#  define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
+#elif _LIBCPP_COMPILER_MSVC
+#  define _LIBCPP_ALWAYS_INLINE __forceinline
+#else
+#  error "This compiler doesn't support any form of always_inline attribute"
+#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__))
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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49240.155185.patch
Type: text/x-patch
Size: 2852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180712/1d458915/attachment.bin>


More information about the llvm-commits mailing list