-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Add visibility annotations to the std namespace with GCC #133233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesThis allows us to remove the need for Full diff: https://github.com/llvm/llvm-project/pull/133233.diff 2 Files Affected:
diff --git a/libcxx/docs/ReleaseNotes/21.rst b/libcxx/docs/ReleaseNotes/21.rst
index 877aa06f8b7e4..c1adb8b7c114b 100644
--- a/libcxx/docs/ReleaseNotes/21.rst
+++ b/libcxx/docs/ReleaseNotes/21.rst
@@ -60,6 +60,10 @@ Improvements and New Features
- Updated formatting library to Unicode 16.0.0.
+- When using GCC, the ``std`` namespace is now annotated with ``[[gnu::visibility("default")]]``. This may cause changes
+ in the symbols exported from shared libraries when building with ``-fvisibility=hidden``. This also fixes RTTI
+ comparison between shared libraries, since all RTTI has the correct visibility now.
+
Deprecations and Removals
-------------------------
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 070298301b0d3..3899016847803 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -391,7 +391,7 @@ typedef __char32_t char32_t;
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
# define _LIBCPP_TEMPLATE_VIS
# define _LIBCPP_TEMPLATE_DATA_VIS
-# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
+# define _LIBCPP_NAMESPACE_VISIBILITY
# else
@@ -419,17 +419,16 @@ typedef __char32_t char32_t;
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
# endif
-// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
-# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
-# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
-# else
-# define _LIBCPP_TEMPLATE_VIS
-# endif
+// This is kept to avoid a huge library-wide diff in the first step.
+// TODO: Remove this in a follow-up patch
+# define _LIBCPP_TEMPLATE_VIS
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
-# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
+# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default")))
+# elif defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
+# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default")))
# else
-# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
+# define _LIBCPP_NAMESPACE_VISIBILITY
# endif
# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
@@ -588,7 +587,7 @@ typedef __char32_t char32_t;
// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \
- _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {
+ _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
|
5bde900
to
fdd2d69
Compare
ldionne
approved these changes
Apr 2, 2025
ldionne
reviewed
Apr 2, 2025
fdd2d69
to
32039f1
Compare
philnik777
added a commit
that referenced
this pull request
Apr 9, 2025
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
AllinLeeYL
pushed a commit
to AllinLeeYL/llvm-project
that referenced
this pull request
Apr 10, 2025
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in llvm#133233.
H-G-Hristov
added a commit
to H-G-Hristov/llvm-project
that referenced
this pull request
May 16, 2025
H-G-Hristov
added a commit
to H-G-Hristov/llvm-project
that referenced
this pull request
May 16, 2025
H-G-Hristov
added a commit
to H-G-Hristov/llvm-project
that referenced
this pull request
May 17, 2025
H-G-Hristov
added a commit
to H-G-Hristov/llvm-project
that referenced
this pull request
Jul 22, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.