Skip to content

Commit 5bde900

Browse files
committed
[libc++] Add visibility annotations to the std namespace with GCC
1 parent 8abca17 commit 5bde900

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ Improvements and New Features
6060

6161
- Updated formatting library to Unicode 16.0.0.
6262

63+
- When using GCC, the ``std`` namespace is now annotated with ``[[gnu::visibility("default")]]``. This may cause changes
64+
in the symbols exported from shared libraries when building with ``-fvisibility=hidden``. This also fixes RTTI
65+
comparison between shared libraries, since all RTTI has the correct visibility now.
66+
6367
Deprecations and Removals
6468
-------------------------
6569

libcxx/include/__config

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ typedef __char32_t char32_t;
391391
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
392392
# define _LIBCPP_TEMPLATE_VIS
393393
# define _LIBCPP_TEMPLATE_DATA_VIS
394-
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
394+
# define _LIBCPP_NAMESPACE_VISIBILITY
395395

396396
# else
397397

@@ -419,17 +419,16 @@ typedef __char32_t char32_t;
419419
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
420420
# endif
421421

422-
// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
423-
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
424-
# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
425-
# else
426-
# define _LIBCPP_TEMPLATE_VIS
427-
# endif
422+
// This is kept to avoid a huge library-wide diff in the first step.
423+
// TODO: Remove this in a follow-up patch
424+
# define _LIBCPP_TEMPLATE_VIS
428425

429426
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
430-
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
427+
# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default")))
428+
# elif defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
429+
# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default")))
431430
# else
432-
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
431+
# define _LIBCPP_NAMESPACE_VISIBILITY
433432
# endif
434433

435434
# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
@@ -588,7 +587,7 @@ typedef __char32_t char32_t;
588587
// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
589588
// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
590589
# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \
591-
_LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {
590+
_LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
592591

593592
# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
594593

0 commit comments

Comments
 (0)