Skip to content

Commit 19a7fff

Browse files
authored
Merge pull request swiftlang#16742 from apple/revert-16677-fix-static-stripped-error-bridging
Revert "[Runtime] Look up Error bridging symbols indirectly through special symbols that won't be stripped in static builds."
2 parents ee899f0 + 2e6c7ee commit 19a7fff

File tree

6 files changed

+10
-75
lines changed

6 files changed

+10
-75
lines changed

stdlib/public/SDK/Foundation/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
2626
NSCoder.swift
2727
NSDate.swift
2828
NSDictionary.swift
29-
NSError.c
3029
NSError.swift
3130
NSExpression.swift
3231
NSFastEnumeration.swift

stdlib/public/SDK/Foundation/NSError.c

Lines changed: 0 additions & 34 deletions
This file was deleted.

stdlib/public/runtime/ErrorObject.mm

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,6 @@ static Class getSwiftNativeNSErrorClass() {
220220
object_dispose((id)error);
221221
}
222222

223-
/// Look up a symbol that points to something else. Treats the symbol as
224-
/// a void** and dereferences it if it's non-NULL. Returns NULL if the
225-
/// symbol can't be found or if the value is NULL.
226-
static void *dynamicLookupSymbol(const char *name) {
227-
void **ptr = reinterpret_cast<void **>(dlsym(RTLD_DEFAULT, name));
228-
if (!ptr) return nullptr;
229-
return *ptr;
230-
}
231-
232-
/// Look up an indirect pointer to a mangled Swift symbol, automatically
233-
/// prepending the ErrorObjectLookup_ prefix. Used to find the various
234-
/// Foundation overlay symbols for Error bridging.
235-
#define DYNAMIC_LOOKUP_SYMBOL(symbol) \
236-
dynamicLookupSymbol("ErrorObjectLookup_" MANGLE_AS_STRING(MANGLE_SYM(symbol)))
237-
238223
static const WitnessTable *getNSErrorConformanceToError() {
239224
// CFError and NSError are toll-free-bridged, so we can use either type's
240225
// witness table interchangeably. CFError's is potentially slightly more
@@ -243,7 +228,8 @@ static Class getSwiftNativeNSErrorClass() {
243228
// to assume that that's been linked in if a user is using NSError in their
244229
// Swift source.
245230

246-
auto TheWitnessTable = SWIFT_LAZY_CONSTANT(DYNAMIC_LOOKUP_SYMBOL(So10CFErrorRefas5Error10FoundationWa));
231+
auto TheWitnessTable = SWIFT_LAZY_CONSTANT(dlsym(RTLD_DEFAULT,
232+
MANGLE_AS_STRING(MANGLE_SYM(So10CFErrorRefas5Error10FoundationWa))));
247233
assert(TheWitnessTable &&
248234
"Foundation overlay not loaded, or 'CFError : Error' conformance "
249235
"not available");
@@ -252,7 +238,8 @@ static Class getSwiftNativeNSErrorClass() {
252238
}
253239

254240
static const HashableWitnessTable *getNSErrorConformanceToHashable() {
255-
auto TheWitnessTable = SWIFT_LAZY_CONSTANT(DYNAMIC_LOOKUP_SYMBOL(So8NSObjectCs8Hashable10ObjectiveCWa));
241+
auto TheWitnessTable = SWIFT_LAZY_CONSTANT(dlsym(RTLD_DEFAULT,
242+
MANGLE_AS_STRING(MANGLE_SYM(So8NSObjectCs8Hashable10ObjectiveCWa))));
256243
assert(TheWitnessTable &&
257244
"ObjectiveC overlay not loaded, or 'NSObject : Hashable' conformance "
258245
"not available");
@@ -392,7 +379,8 @@ typedef SWIFT_CC(swift)
392379
// public func Foundation._getErrorDefaultUserInfo<T: Error>(_ error: T)
393380
// -> AnyObject?
394381
auto foundationGetDefaultUserInfo = SWIFT_LAZY_CONSTANT(
395-
reinterpret_cast<GetDefaultFn*> (DYNAMIC_LOOKUP_SYMBOL(10Foundation24_getErrorDefaultUserInfoyyXlSgxs0C0RzlF)));
382+
reinterpret_cast<GetDefaultFn*> (dlsym(RTLD_DEFAULT,
383+
MANGLE_AS_STRING(MANGLE_SYM(10Foundation24_getErrorDefaultUserInfoyyXlSgxs0C0RzlF)))));
396384
if (!foundationGetDefaultUserInfo) {
397385
SWIFT_CC_PLUSONE_GUARD(T->vw_destroy(error));
398386
return nullptr;
@@ -521,10 +509,12 @@ typedef SWIFT_CC(swift)
521509
bool BridgeFn(NSError *, OpaqueValue*, const Metadata *,
522510
const WitnessTable *);
523511
auto bridgeNSErrorToError = SWIFT_LAZY_CONSTANT(
524-
reinterpret_cast<BridgeFn*>(DYNAMIC_LOOKUP_SYMBOL(10Foundation21_bridgeNSErrorToError_3outSbSo0C0C_SpyxGtAA021_ObjectiveCBridgeableE0RzlF)));
512+
reinterpret_cast<BridgeFn*>(dlsym(RTLD_DEFAULT,
513+
MANGLE_AS_STRING(MANGLE_SYM(10Foundation21_bridgeNSErrorToError_3outSbSo0C0C_SpyxGtAA021_ObjectiveCBridgeableE0RzlF)))));
525514
// protocol _ObjectiveCBridgeableError
526515
auto TheObjectiveCBridgeableError = SWIFT_LAZY_CONSTANT(
527-
reinterpret_cast<const ProtocolDescriptor *>(DYNAMIC_LOOKUP_SYMBOL(10Foundation26_ObjectiveCBridgeableErrorMp)));
516+
reinterpret_cast<const ProtocolDescriptor *>(dlsym(RTLD_DEFAULT,
517+
MANGLE_AS_STRING(MANGLE_SYM(10Foundation26_ObjectiveCBridgeableErrorMp)))));
528518

529519
// If the Foundation overlay isn't loaded, then arbitrary NSErrors can't be
530520
// bridged.

test/stdlib/ErrorBridgedStatic.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ class Bar: Foo {
1414
override func foo(_ x: Int32) throws {
1515
try super.foo(5)
1616
}
17-
18-
override func foothrows(_ x: Int32) throws {
19-
try super.foothrows(5)
20-
}
2117
}
2218

2319
var ErrorBridgingStaticTests = TestSuite("ErrorBridging with static libs")
@@ -28,14 +24,4 @@ ErrorBridgingStaticTests.test("round-trip Swift override of ObjC method") {
2824
} catch { }
2925
}
3026

31-
ErrorBridgingStaticTests.test("round-trip Swift override of throwing ObjC method") {
32-
do {
33-
try (Bar() as Foo).foothrows(5)
34-
} catch {
35-
print(error)
36-
expectEqual(error._domain, "abcd")
37-
expectEqual(error._code, 1234)
38-
}
39-
}
40-
4127
runAllTests()

test/stdlib/Inputs/ErrorBridgedStaticImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
@interface Foo: NSObject
44

55
- (BOOL)foo:(int)x error:(NSError**)error;
6-
- (BOOL)foothrows:(int)x error:(NSError**)error;
76

87
@end

test/stdlib/Inputs/ErrorBridgedStaticImpl.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,5 @@ - (BOOL)foo:(int)x error:(NSError**)error {
77
return NO;
88
}
99

10-
- (BOOL)foothrows:(int)x error:(NSError**)error {
11-
*error = [NSError errorWithDomain: @"abcd" code: 1234 userInfo: nil];
12-
return NO;
13-
}
14-
1510
@end
1611

0 commit comments

Comments
 (0)