[PATCH] D24642: Use __attribute__((internal_linkage)) when available.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 15 19:30:55 PDT 2016


EricWF updated this revision to Diff 71590.
EricWF added a comment.

- Add `always_inline` to _LIBCPP_INLINE_VISIBILITY. In future I think only _LIBCPP_ALWAYS_INLINE should actually apply `always_inline`, but I'll make that change separately.
- Change `_LIBCPP_ALWAYS_INLINE` to use `internal_linkage` as well.


https://reviews.llvm.org/D24642

Files:
  include/__config
  src/string.cpp

Index: src/string.cpp
===================================================================
--- src/string.cpp
+++ src/string.cpp
@@ -29,6 +29,29 @@
     string
     operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
 
+// These external instantiations are required to maintain dylib compatibility
+// for ABI v1 when using __attribute__((internal_linkage)) as opposed to
+// __attribute__((visibility("hidden"), always_inline)).
+#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1
+template basic_string<char>::iterator
+basic_string<char>::insert(basic_string<char>::const_iterator,
+                           char const *, char const *);
+
+template basic_string<wchar_t>::iterator
+basic_string<wchar_t>::insert(basic_string<wchar_t>::const_iterator,
+                              wchar_t const *, wchar_t const *);
+
+template basic_string<char> &
+basic_string<char>::replace(basic_string<char>::const_iterator,
+                               basic_string<char>::const_iterator,
+                               char const *, char const *);
+
+template basic_string<wchar_t> &
+basic_string<wchar_t>::replace(basic_string<wchar_t>::const_iterator,
+                               basic_string<wchar_t>::const_iterator,
+                               wchar_t const *, wchar_t const *);
+#endif // _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION
+
 namespace
 {
 
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -34,6 +34,7 @@
 #endif
 
 #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 2
 // Change short string representation so that string data starts at offset 0,
 // improving its alignment in some cases.
 #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
@@ -49,6 +50,7 @@
 #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
 #define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
 #elif _LIBCPP_ABI_VERSION == 1
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 1
 // Feature macros for disabling pre ABI v1 features. All of these options
 // are deprecated.
 #if defined(__FreeBSD__)
@@ -610,11 +612,19 @@
 #endif
 
 #ifndef _LIBCPP_INLINE_VISIBILITY
-#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))
+# if __has_attribute(__internal_linkage__)
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__((__internal_linkage__, __always_inline__))
+# else
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))
+# endif
 #endif
 
 #ifndef _LIBCPP_ALWAYS_INLINE
-#define _LIBCPP_ALWAYS_INLINE  __attribute__ ((__visibility__("hidden"), __always_inline__))
+# if __has_attribute(__internal_linkage__)
+#   define _LIBCPP_ALWAYS_INLINE __attribute__((__internal_linkage__, __always_inline__))
+# else
+#   define _LIBCPP_ALWAYS_INLINE  __attribute__ ((__visibility__("hidden"), __always_inline__))
+# endif
 #endif
 
 #ifndef _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24642.71590.patch
Type: text/x-patch
Size: 3032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160916/78528096/attachment.bin>


More information about the cfe-commits mailing list