Skip to content

Commit be87564

Browse files
ldionnellvmbot
authored andcommitted
[libc++] Re-introduce _LIBCPP_DISABLE_AVAILABILITY (#134158)
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: #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. (cherry picked from commit 25fc52e)
1 parent ebfae55 commit be87564

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-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,49 @@
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 is dependent on the code generated by the compiler, and it doesn't
12+
// work properly with older AppleClangs.
13+
// UNSUPPORTED: apple-clang-15
14+
15+
// This test ensures that we retain a way to disable availability markup on Apple platforms
16+
// in order to work around Clang bug https://github.com/llvm/llvm-project/issues/134151.
17+
//
18+
// Once that bug has been fixed or once we've made changes to libc++'s use of availability
19+
// that render that workaround unnecessary, the macro and this test can be removed.
20+
//
21+
// The test works by creating a final linked image that refers to a function marked with
22+
// both an availability attribute and with _LIBCPP_HIDE_FROM_ABI. We then check that this
23+
// generates a weak reference to the function -- without the bug, we'd expect a strong
24+
// reference or no reference at all instead.
25+
26+
// First, test the test. Make sure that we do (incorrectly) produce a weak definition when we
27+
// don't define _LIBCPP_DISABLE_AVAILABILITY. Otherwise, something may have changed in libc++
28+
// and this test might not work anymore.
29+
// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -shared -o %t.1.dylib
30+
// RUN: nm -m %t.1.dylib | c++filt | grep value > %t.1.symbols
31+
// RUN: grep weak %t.1.symbols
32+
33+
// Now, make sure that 'weak' goes away when we define _LIBCPP_DISABLE_AVAILABILITY.
34+
// In fact, all references to the function might go away, so we just check that we don't emit
35+
// any weak reference.
36+
// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -D_LIBCPP_DISABLE_AVAILABILITY -shared -o %t.2.dylib
37+
// RUN: nm -m %t.2.dylib | c++filt | grep value > %t.2.symbols
38+
// RUN: not grep weak %t.2.symbols
39+
40+
#include <version>
41+
42+
template <class T>
43+
struct optional {
44+
T val_;
45+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE T value() const { return val_; }
46+
};
47+
48+
using PMF = int (optional<int>::*)() const;
49+
PMF f() { return &optional<int>::value; }

0 commit comments

Comments
 (0)