Skip to content

[libc++] Re-introduce _LIBCPP_DISABLE_AVAILABILITY #134158

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
merged 3 commits into from
May 5, 2025

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Apr 2, 2025

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.

@ldionne ldionne added this to the LLVM 20.X Release milestone Apr 2, 2025
@ldionne ldionne requested a review from a team as a code owner April 2, 2025 21:43
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Apr 2, 2025
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Apr 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2025

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/134158.diff

3 Files Affected:

  • (modified) libcxx/docs/ReleaseNotes/20.rst (-3)
  • (modified) libcxx/include/__configuration/availability.h (+7-1)
  • (added) libcxx/test/libcxx/vendor/apple/disable-availability.sh.cpp (+43)
diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 57ab0c167544b..399a991cf7891 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -153,9 +153,6 @@ Deprecations and Removals
   headers as an extension and only deprecates them. The ``_LIBCPP_DISABLE_DEPRECATION_WARNINGS`` macro can be defined to
   suppress deprecation for these headers.
 
-- The ``_LIBCPP_DISABLE_AVAILABILITY`` macro that was used to force-disable availability markup has now been removed.
-  Whether availability markup is used by the library is now solely controlled at configuration-time.
-
 - The pointer safety functions ``declare_reachable``, ``declare_no_pointers``, ``undeclare_no_pointers`` and
   ``__undeclare_reachable`` have been removed from the library. These functions were never implemented in a non-trivial
   way, making it very unlikely that any binary depends on them.
diff --git a/libcxx/include/__configuration/availability.h b/libcxx/include/__configuration/availability.h
index 7e2ad79378ccf..ba4a292efe1d4 100644
--- a/libcxx/include/__configuration/availability.h
+++ b/libcxx/include/__configuration/availability.h
@@ -69,7 +69,13 @@
 
 // Availability markup is disabled when building the library, or when a non-Clang
 // compiler is used because only Clang supports the necessary attributes.
-#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED)
+//
+// We also allow users to force-disable availability markup via the `_LIBCPP_DISABLE_AVAILABILITY`
+// macro because that is the only way to work around a Clang bug related to availability
+// attributes: https://github.com/llvm/llvm-project/issues/134151.
+// Once that bug has been fixed, we should remove the macro.
+#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) ||                                       \
+    !defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_DISABLE_AVAILABILITY)
 #  undef _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
 #  define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0
 #endif
diff --git a/libcxx/test/libcxx/vendor/apple/disable-availability.sh.cpp b/libcxx/test/libcxx/vendor/apple/disable-availability.sh.cpp
new file mode 100644
index 0000000000000..a7e0a804634b6
--- /dev/null
+++ b/libcxx/test/libcxx/vendor/apple/disable-availability.sh.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: stdlib=apple-libc++
+
+// This test ensures that we retain a way to disable availability markup on Apple platforms
+// in order to work around Clang bug https://github.com/llvm/llvm-project/issues/134151.
+//
+// Once that bug has been fixed or once we've made changes to libc++'s use of availability
+// that render that workaround unnecessary, the macro and this test can be removed.
+//
+// The test works by creating a final linked image that refers to a function marked with
+// both an availability attribute and with _LIBCPP_HIDE_FROM_ABI. We then check that this
+// generates a weak reference to the function -- without the bug, we'd expect a strong
+// reference or no reference at all instead.
+
+// First, test the test. Make sure that we do (incorrectly) produce a weak definition when we
+// don't define _LIBCPP_DISABLE_AVAILABILITY. Otherwise, something may have changed in libc++
+// and this test might not work anymore.
+// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -shared -o %t.1.dylib
+// RUN: nm -omg %t.1.dylib | c++filt | grep value | grep weak
+
+// Now, make sure that 'weak' goes away when we define _LIBCPP_DISABLE_AVAILABILITY.
+// In fact, all references to the function might go away, so we just check that we don't emit
+// any weak reference.
+// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -D_LIBCPP_DISABLE_AVAILABILITY -shared -o %t.2.dylib
+// RUN: nm -omg %t.2.dylib | c++filt | grep -v weak
+
+#include <version>
+
+template <class T>
+struct optional {
+  T val_;
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE T value() const { return val_; }
+};
+
+using PMF = int (optional<int>::*)() const;
+PMF f() { return &optional<int>::value; }

@ldionne ldionne force-pushed the review/revert-disable-availability branch from 2aaaf27 to 58c789b Compare April 8, 2025 16:50
@tstellar tstellar moved this from Needs Triage to Needs Review in LLVM Release Status Apr 11, 2025
@tstellar tstellar moved this from Needs Review to Needs Test Fix in LLVM Release Status Apr 14, 2025
@tstellar
Copy link
Collaborator

Are these real test failures?

@h-vetinari
Copy link
Contributor

Gentle ping @ldionne

@ldionne
Copy link
Member Author

ldionne commented May 5, 2025

The failures are real and need to be addressed. I was out of office which is why I didn't reply until now.

ldionne added 3 commits May 5, 2025 10:10
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.
@ldionne ldionne force-pushed the review/revert-disable-availability branch from 58c789b to b75ab8f Compare May 5, 2025 14:40
@github-project-automation github-project-automation bot moved this from Needs Test Fix to Needs Merge in LLVM Release Status May 5, 2025
@var-const var-const merged commit 25fc52e into llvm:main May 5, 2025
83 checks passed
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status May 5, 2025
@ldionne ldionne deleted the review/revert-disable-availability branch May 6, 2025 11:08
@ldionne
Copy link
Member Author

ldionne commented May 6, 2025

/cherry-pick 25fc52e

@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

/pull-request #138674

GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
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.
swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request May 9, 2025
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.

(cherry picked from commit 25fc52e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
Development

Successfully merging this pull request may close these issues.

5 participants