Skip to content

Commit 4d62c52

Browse files
committed
[Runtime] Avoid dlsym of objc_isUniquelyReferenced.
We attempted to use the declaration if it exists, and fall back to dlsym. This didn't actually work and we always call dlsym. Include the right header (when available) and add a weak check to the direct call. rdar://127116080
1 parent c936202 commit 4d62c52

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

stdlib/public/runtime/SwiftObject.mm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <objc/runtime.h>
2323
#include <objc/message.h>
2424
#include <objc/objc.h>
25+
#if __has_include(<objc/objc-internal.h>)
26+
#include <objc/objc-internal.h>
27+
#endif
2528
#endif
2629
#include "llvm/ADT/StringRef.h"
2730
#include "swift/Basic/Lazy.h"
@@ -1474,11 +1477,11 @@ static bool usesNativeSwiftReferenceCounting_nonNull(
14741477
}
14751478

14761479
#if SWIFT_OBJC_INTEROP
1477-
// It would be nice to weak link instead of doing this, but we can't do that
1478-
// until the new API is in the versions of libobjc that we're linking against.
14791480
static bool isUniquelyReferenced(id object) {
14801481
#if OBJC_ISUNIQUELYREFERENCED_DEFINED
1481-
return objc_isUniquelyReferenced(object);
1482+
if (!SWIFT_RUNTIME_WEAK_CHECK(objc_isUniquelyReferenced))
1483+
return false;
1484+
return SWIFT_RUNTIME_WEAK_USE(objc_isUniquelyReferenced(object));
14821485
#else
14831486
auto objcIsUniquelyRefd = SWIFT_LAZY_CONSTANT(reinterpret_cast<bool (*)(id)>(
14841487
dlsym(RTLD_NEXT, "objc_isUniquelyReferenced")));

0 commit comments

Comments
 (0)