Skip to content

Commit c66d0b0

Browse files
committed
[libc++] Recategorize additional instantiations in the dylib as availability macros
Adding additional instantiations to the dylib isn't actually an ABI break as long as programs targeting an older dylib don't start to depend on them. Making additional instantiations a matter of availability allows us to add them without an ABI break. Reviewed By: #libc, ldionne, Mordante Spies: arichardson, ldionne, Mordante, libcxx-commits Differential Revision: https://reviews.llvm.org/D154796
1 parent e1f90b5 commit c66d0b0

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

libcxx/include/__availability

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@
179179
// # define _LIBCPP_AVAILABILITY_HAS_NO_TZDB
180180
# define _LIBCPP_AVAILABILITY_TZDB
181181

182+
// Enable additional explicit instantiations of iostreams components. This
183+
// reduces the number of weak definitions generated in programs that use
184+
// iostreams by providing a single strong definition in the shared library.
185+
//
186+
// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation,
187+
// or once libc++ doesn't use the attribute anymore.
188+
// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed.
189+
#if defined(_LIBCPP_COMPILER_GCC) || defined(_WIN32)
190+
# define _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
191+
#endif
192+
182193
#elif defined(__APPLE__)
183194

184195
// shared_mutex and shared_timed_mutex
@@ -356,6 +367,12 @@
356367
# define _LIBCPP_AVAILABILITY_HAS_NO_TZDB
357368
# define _LIBCPP_AVAILABILITY_TZDB __attribute__((unavailable))
358369

370+
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120000) || \
371+
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \
372+
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) || \
373+
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80000)
374+
# define _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
375+
# endif
359376
#else
360377

361378
// ...New vendors can add availability markup here...

libcxx/include/__config

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@
193193
# endif
194194

195195
# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
196-
// Enable additional explicit instantiations of iostreams components. This
197-
// reduces the number of weak definitions generated in programs that use
198-
// iostreams by providing a single strong definition in the shared library.
199-
# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
200-
201196
// Define a key function for `bad_function_call` in the library, to centralize
202197
// its vtable and typeinfo to libc++ rather than having all other libraries
203198
// using that class define their own copies.

libcxx/include/fstream

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ basic_fstream<_CharT, _Traits>::close()
17341734
this->setstate(ios_base::failbit);
17351735
}
17361736

1737-
#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1)
1737+
#ifndef _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
17381738
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream<char>;
17391739
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream<char>;
17401740
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>;

libcxx/include/sstream

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
11921192
__x.swap(__y);
11931193
}
11941194

1195-
#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1)
1195+
#ifndef _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
11961196
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>;
11971197
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>;
11981198
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>;

libcxx/src/ios.instantiations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
3131
#endif
3232

3333
// Additional instantiations added later. Whether programs rely on these being
34-
// available is protected by _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1.
34+
// available is protected by _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1.
3535
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringbuf<char>;
3636
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringstream<char>;
3737
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostringstream<char>;

0 commit comments

Comments
 (0)