Skip to content

Commit 08be6fe

Browse files
committed
[libc++] Re-introduce _LIBCPP_DISABLE_AVAILABILITY
The _LIBCPP_DISABLE_AVAILABILITY macro was removed in afae1a5 as an intended no-op. It turns out that some projects are making use of that macro to work around a Clang bug with availability annotations that still exists: llvm#134151. Since that Clang bug still hasn't been fixed, I feel that we must sill honor that unfortunate macro until we've figured out how to get rid of it without breaking code.
1 parent 3a5d776 commit 08be6fe

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

libcxx/docs/ReleaseNotes/20.rst

-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ Deprecations and Removals
153153
headers as an extension and only deprecates them. The ``_LIBCPP_DISABLE_DEPRECATION_WARNINGS`` macro can be defined to
154154
suppress deprecation for these headers.
155155

156-
- The ``_LIBCPP_DISABLE_AVAILABILITY`` macro that was used to force-disable availability markup has now been removed.
157-
Whether availability markup is used by the library is now solely controlled at configuration-time.
158-
159156
- The pointer safety functions ``declare_reachable``, ``declare_no_pointers``, ``undeclare_no_pointers`` and
160157
``__undeclare_reachable`` have been removed from the library. These functions were never implemented in a non-trivial
161158
way, making it very unlikely that any binary depends on them.

libcxx/include/__configuration/availability.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@
6969

7070
// Availability markup is disabled when building the library, or when a non-Clang
7171
// compiler is used because only Clang supports the necessary attributes.
72-
#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED)
72+
//
73+
// We also allow users to force-disable availability markup via the `_LIBCPP_DISABLE_AVAILABILITY`
74+
// macro because that is the only way to work around a Clang bug related to availability
75+
// attributes: https://github.com/llvm/llvm-project/issues/134151.
76+
// Once that bug has been fixed, we should remove the macro.
77+
#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || \
78+
!defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_DISABLE_AVAILABILITY)
7379
# undef _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
7480
# define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0
7581
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: stdlib=apple-libc++
10+
11+
// This test ensures that we retain a way to disable availability markup on Apple platforms
12+
// in order to work around Clang bug https://github.com/llvm/llvm-project/issues/134151.
13+
//
14+
// Once that bug has been fixed or once we've made changes to libc++'s use of availability
15+
// that render that workaround unnecessary, the macro and this test can be removed.
16+
//
17+
// The test works by creating a final linked image that refers to a function marked with
18+
// both an availability attribute and with _LIBCPP_HIDE_FROM_ABI. We then check that this
19+
// generates a weak reference to the function -- without the bug, we'd expect a strong
20+
// reference or no reference at all instead.
21+
22+
// First, test the test. Make sure that we do (incorrectly) produce a weak definition when we
23+
// don't define _LIBCPP_DISABLE_AVAILABILITY. Otherwise, something may have changed in libc++
24+
// and this test might not work anymore.
25+
// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -shared -o %t.1.dylib
26+
// RUN: nm -omg %t.1.dylib | c++filt | grep value | grep weak
27+
28+
// Now, make sure that 'weak' goes away when we define _LIBCPP_DISABLE_AVAILABILITY.
29+
// In fact, all references to the function might go away, so we just check that we don't emit
30+
// any weak reference.
31+
// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -D_LIBCPP_DISABLE_AVAILABILITY -shared -o %t.2.dylib
32+
// RUN: nm -omg %t.2.dylib | c++filt | grep -v weak
33+
34+
#include <version>
35+
36+
template <class T>
37+
struct optional {
38+
T val_;
39+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE T value() const { return val_; }
40+
};
41+
42+
using PMF = int (optional<int>::*)() const;
43+
PMF f() { return &optional<int>::value; }

0 commit comments

Comments
 (0)