Skip to content

Commit c59d3a2

Browse files
authored
[libc++] Add visibility annotations to the std namespace with GCC (#133233)
This allows us to remove the need for `_LIBCPP_TEMPLATE_VIS` and fixes a bunch of missing annotations for RTTI when used across dylib boundaries. `_LIBCPP_TEMPLATE_VIS` itself will be removed in a separate patch, since it touches a lot of code. This patch is a no-op for Clang. Only GCC is affected.
1 parent fb0e7b5 commit c59d3a2

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ LLVM 22
7777
ABI Affecting Changes
7878
---------------------
7979

80-
- TODO
80+
- When using GCC, the ``std`` namespace is now annotated with ``[[gnu::visibility("default")]]``. This may cause more
81+
symbols to be exported from shared libraries when building with ``-fvisibility=hidden``. This also fixes RTTI
82+
comparison between shared libraries, since all RTTI has the correct visibility now. There is no behaviour change on
83+
Clang.
8184

8285

8386
Build System Changes

libcxx/include/__config

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ typedef __char32_t char32_t;
386386
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
387387
# define _LIBCPP_TEMPLATE_VIS
388388
# define _LIBCPP_TEMPLATE_DATA_VIS
389-
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
389+
# define _LIBCPP_NAMESPACE_VISIBILITY
390390

391391
# else
392392

@@ -414,17 +414,16 @@ typedef __char32_t char32_t;
414414
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
415415
# endif
416416

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

424421
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
425-
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
422+
# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default")))
423+
# elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
424+
# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default")))
426425
# else
427-
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
426+
# define _LIBCPP_NAMESPACE_VISIBILITY
428427
# endif
429428

430429
# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
@@ -583,7 +582,7 @@ typedef __char32_t char32_t;
583582
// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
584583
// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
585584
# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \
586-
_LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {
585+
_LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
587586

588587
# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
589588

0 commit comments

Comments
 (0)