Skip to content

Commit 3583bf3

Browse files
committed
[libc++] Make everything in namespace std have default type visibility and hidden visibility and remove _LIBCPP_ENUM_VIS
This avoids having to add `_LIBCPP_ENUM_VIS`, since that is handled through `type_visibility` and GCC always makes the visibility of enums default. It also fixes and missing `_LIBCPP_EXPORTED_FROM_ABI` on classes when using Clang. Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D153658
1 parent 46eded7 commit 3583bf3

17 files changed

+40
-41
lines changed

libcxx/.clang-format

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ AttributeMacros: [
3030
'_LIBCPP_DEPRECATED_IN_CXX20',
3131
'_LIBCPP_DEPRECATED',
3232
'_LIBCPP_DISABLE_EXTENTSION_WARNING',
33-
'_LIBCPP_ENUM_VIS',
3433
'_LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION',
3534
'_LIBCPP_EXPORTED_FROM_ABI',
3635
'_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS',

libcxx/docs/DesignDocs/VisibilityMacros.rst

+7-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Libc++ uses various "visibility" macros in order to provide a stable ABI in
1414
both the library and the headers. These macros work by changing the
1515
visibility and inlining characteristics of the symbols they are applied to.
1616

17+
The std namespace also has visibility attributes applied to avoid having to
18+
add visibility macros in as many places. Namespace std has default
19+
type_visibility to export RTTI and other type-specific information. Note that
20+
type_visibility is only supported by Clang, so this doesn't replace
21+
type-specific attributes. The only exception are enums, which GCC always gives
22+
default visibility, thus removing the need for any annotations.
23+
1724
Visibility Macros
1825
=================
1926

@@ -72,19 +79,6 @@ Visibility Macros
7279
**Windows Behavior**: DLLs do not support dllimport/export on class templates.
7380
The macro has an empty definition on this platform.
7481

75-
76-
**_LIBCPP_ENUM_VIS**
77-
Mark the typeinfo of an enum as having default visibility. This attribute
78-
should be applied to all enum declarations.
79-
80-
**Windows Behavior**: DLLs do not support importing or exporting enumeration
81-
typeinfo. The macro has an empty definition on this platform.
82-
83-
**GCC Behavior**: GCC un-hides the typeinfo for enumerations by default, even
84-
if `-fvisibility=hidden` is specified. Additionally applying a visibility
85-
attribute to an enum class results in a warning. The macro has an empty
86-
definition with GCC.
87-
8882
**_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS**
8983
Mark the member functions, typeinfo, and vtable of the type named in
9084
an extern template declaration as being exported by the libc++ library.

libcxx/docs/ReleaseNotes/18.rst

+8
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,13 @@ ABI Affecting Changes
7777
- The symbol of a non-visible function part of ``std::system_error`` was removed.
7878
This is not a breaking change as the private function ``__init`` was never referenced internally outside of the dylib
7979

80+
- This release of libc++ added missing visibility annotations on some types in the library. Users compiling with
81+
``-fvisbility=hidden`` may notice that additional type infos from libc++ are being exported from their ABI. This is
82+
the correct behavior in almost all cases since exporting the RTTI is required for these types to work properly with
83+
dynamic_cast, exceptions and other mechanisms across binaries. However, if you intend to use libc++ purely as an
84+
internal implementation detail (i.e. you use libc++ as a static archive and never export libc++ symbols from your ABI)
85+
and you notice changes to your exported symbols list, then this means that you were not properly preventing libc++
86+
symbols from being part of your ABI.
87+
8088
Build System Changes
8189
--------------------

libcxx/include/__charconv/chars_format.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
#if _LIBCPP_STD_VER >= 17
2323

24-
enum class _LIBCPP_ENUM_VIS chars_format { scientific = 0x1, fixed = 0x2, hex = 0x4, general = fixed | scientific };
24+
enum class chars_format { scientific = 0x1, fixed = 0x2, hex = 0x4, general = fixed | scientific };
2525

2626
inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format operator~(chars_format __x) {
2727
return chars_format(~std::__to_underlying(__x));

libcxx/include/__compare/ordering.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222
#if _LIBCPP_STD_VER >= 20
2323

2424
// exposition only
25-
enum class _LIBCPP_ENUM_VIS _OrdResult : signed char {
25+
enum class _OrdResult : signed char {
2626
__less = -1,
2727
__equiv = 0,
2828
__greater = 1
2929
};
3030

31-
enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {
31+
enum class _NCmpResult : signed char {
3232
__unordered = -127
3333
};
3434

libcxx/include/__config

+9-11
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ typedef __char32_t char32_t;
685685
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
686686
# define _LIBCPP_TEMPLATE_VIS
687687
# define _LIBCPP_TEMPLATE_DATA_VIS
688-
# define _LIBCPP_ENUM_VIS
688+
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
689689

690690
# else
691691

@@ -713,20 +713,17 @@ typedef __char32_t char32_t;
713713
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
714714
# endif
715715

716-
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
717-
# if __has_attribute(__type_visibility__)
718-
# define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default")))
719-
# else
720-
# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
721-
# endif
716+
// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
717+
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
718+
# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
722719
# else
723720
# define _LIBCPP_TEMPLATE_VIS
724721
# endif
725722

726723
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
727-
# define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default")))
724+
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
728725
# else
729-
# define _LIBCPP_ENUM_VIS
726+
# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
730727
# endif
731728

732729
# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
@@ -800,7 +797,8 @@ typedef __char32_t char32_t;
800797

801798
// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
802799
// clang-format off
803-
# define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
800+
# define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
801+
inline namespace _LIBCPP_ABI_NAMESPACE {
804802
# define _LIBCPP_END_NAMESPACE_STD }}
805803
# define _VSTD std
806804

@@ -853,7 +851,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
853851
// clang-format on
854852

855853
# else // _LIBCPP_CXX03_LANG
856-
# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
854+
# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
857855
# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
858856
# endif // _LIBCPP_CXX03_LANG
859857

libcxx/include/__filesystem/copy_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2323

24-
enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
24+
enum class copy_options : unsigned short {
2525
none = 0,
2626
skip_existing = 1,
2727
overwrite_existing = 2,

libcxx/include/__filesystem/directory_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2323

24-
enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
24+
enum class directory_options : unsigned char {
2525
none = 0,
2626
follow_directory_symlink = 1,
2727
skip_permission_denied = 2

libcxx/include/__filesystem/file_type.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2323

2424
// On Windows, the library never identifies files as block, character, fifo
2525
// or socket.
26-
enum class _LIBCPP_ENUM_VIS file_type : signed char {
26+
enum class file_type : signed char {
2727
none = 0,
2828
not_found = -1,
2929
regular = 1,

libcxx/include/__filesystem/path.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path {
465465
typedef basic_string<value_type> string_type;
466466
typedef basic_string_view<value_type> __string_view;
467467

468-
enum _LIBCPP_ENUM_VIS format : unsigned char {
468+
enum format : unsigned char {
469469
auto_format,
470470
native_format,
471471
generic_format

libcxx/include/__filesystem/perm_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2323

24-
enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
24+
enum class perm_options : unsigned char {
2525
replace = 1,
2626
add = 2,
2727
remove = 4,

libcxx/include/__filesystem/perms.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2525
// file, and the executable bit is always returned as set. When setting
2626
// permissions, as long as the write bit is set for either owner, group or
2727
// others, the readonly flag is cleared.
28-
enum class _LIBCPP_ENUM_VIS perms : unsigned {
28+
enum class perms : unsigned {
2929
none = 0,
3030

3131
owner_read = 0400,

libcxx/include/__format/format_arg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace __format {
5353
/// handle to satisfy the user observable behaviour. The internal function
5454
/// __visit_format_arg doesn't do this wrapping. So in the format functions
5555
/// this function is used to avoid unneeded overhead.
56-
enum class _LIBCPP_ENUM_VIS __arg_t : uint8_t {
56+
enum class __arg_t : uint8_t {
5757
__none,
5858
__boolean,
5959
__char_type,

libcxx/include/__format/parser_std_format_spec.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ inline constexpr __fields __fields_range{.__use_range_fill_ = true, .__clear_bra
176176
inline constexpr __fields __fields_fill_align_width{};
177177
# endif
178178

179-
enum class _LIBCPP_ENUM_VIS __alignment : uint8_t {
179+
enum class __alignment : uint8_t {
180180
/// No alignment is set in the format string.
181181
__default,
182182
__left,
@@ -185,7 +185,7 @@ enum class _LIBCPP_ENUM_VIS __alignment : uint8_t {
185185
__zero_padding
186186
};
187187

188-
enum class _LIBCPP_ENUM_VIS __sign : uint8_t {
188+
enum class __sign : uint8_t {
189189
/// No sign is set in the format string.
190190
///
191191
/// The sign isn't allowed for certain format-types. By using this value
@@ -197,7 +197,7 @@ enum class _LIBCPP_ENUM_VIS __sign : uint8_t {
197197
__space
198198
};
199199

200-
enum class _LIBCPP_ENUM_VIS __type : uint8_t {
200+
enum class __type : uint8_t {
201201
__default = 0,
202202
__string,
203203
__binary_lower_case,

libcxx/include/__format/write_escaped.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ template <class _CharT>
118118
return static_cast<make_unsigned_t<_CharT>>(__value);
119119
}
120120

121-
enum class _LIBCPP_ENUM_VIS __escape_quotation_mark { __apostrophe, __double_quote };
121+
enum class __escape_quotation_mark { __apostrophe, __double_quote };
122122

123123
// [format.string.escaped]/2
124124
template <class _CharT>

libcxx/include/__fwd/subrange.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323

2424
namespace ranges {
2525

26-
enum class _LIBCPP_ENUM_VIS subrange_kind : bool { unsized, sized };
26+
enum class subrange_kind : bool { unsized, sized };
2727

2828
template <input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent, subrange_kind _Kind>
2929
requires(_Kind == subrange_kind::sized || !sized_sentinel_for<_Sent, _Iter>)

libcxx/include/new

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void __throw_bad_array_new_length()
185185
#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \
186186
!defined(_LIBCPP_ABI_VCRUNTIME)
187187
#ifndef _LIBCPP_CXX03_LANG
188-
enum class _LIBCPP_ENUM_VIS align_val_t : size_t { };
188+
enum class align_val_t : size_t { };
189189
#else
190190
enum align_val_t { __zero = 0, __max = (size_t)-1 };
191191
#endif

0 commit comments

Comments
 (0)