Skip to content

Commit 188c7bd

Browse files
committed
Break link against compiler-rt
This patch replaces the platform version check with a dlsym to grab the symbol we need. If we're on a new enough platform, the symbol should be available and we can use it. Otherwise, it will be empty and we should return true. This breaks the link requirement for the platform version symbol.
1 parent 974a6bd commit 188c7bd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

stdlib/toolchain/Compatibility56/include/Concurrency/VoucherShims.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <cstdint>
2121
#include "swift/Runtime/Config.h"
2222

23+
#include "swift/Basic/Lazy.h"
24+
#include <dlfcn.h>
25+
2326
// swift-corelibs-libdispatch has os/voucher_private.h but it doesn't work for
2427
// us yet, so only look for it on Apple platforms.
2528
#if __APPLE__ && __has_include(<os/voucher_private.h>)
@@ -42,7 +45,7 @@
4245

4346
#if SWIFT_HAS_VOUCHER_HEADER
4447

45-
#else
48+
#else // SWIFT_HAS_VOUCHER_HEADER
4649

4750
// If the header isn't available, declare the necessary calls here.
4851

@@ -92,8 +95,14 @@ static inline bool voucher_needs_adopt(void * _Nullable voucher) {
9295

9396
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
9497
#if __APPLE__
95-
if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *))
96-
return voucher_needs_adopt(voucher);
98+
// _Z19voucher_needs_adoptP9voucher_s
99+
const auto voucherNeedsAdopt =
100+
reinterpret_cast<bool(*)(voucher_t)>(SWIFT_LAZY_CONSTANT(
101+
dlsym(RTLD_DEFAULT, "_Z19voucher_needs_adoptP9voucher_s")));
102+
103+
if (voucherNeedsAdopt) {
104+
return voucherNeedsAdopt(voucher);
105+
}
97106
return true;
98107
#else
99108
return voucher_needs_adopt(voucher);

0 commit comments

Comments
 (0)