File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
stdlib/toolchain/Compatibility50 Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 18
18
#include " ../../public/runtime/CompatibilityOverride.h"
19
19
20
20
#include < dlfcn.h>
21
+ #include < mach-o/dyld.h>
22
+ #include < mach-o/getsect.h>
21
23
22
24
using namespace swift ;
23
25
@@ -70,8 +72,29 @@ getObjCClassByMangledName_untrusted(const char * _Nonnull typeName,
70
72
return NO;
71
73
}
72
74
75
+ #if __POINTER_WIDTH__ == 64
76
+ using mach_header_platform = mach_header_64;
77
+ #else
78
+ using mach_header_platform = mach_header;
79
+ #endif
80
+
73
81
__attribute__ ((constructor))
74
82
static void installGetClassHook_untrusted() {
83
+ // swiftCompatibility* might be linked into multiple dynamic libraries because
84
+ // of build system reasons, but the copy in the main executable is the only
85
+ // one that should count. Bail early unless we're running out of the main
86
+ // executable.
87
+ //
88
+ // Newer versions of dyld add additional API that can determine this more
89
+ // efficiently, but we have to support back to OS X 10.9/iOS 7, so dladdr
90
+ // is the only API that reaches back that far.
91
+ Dl_info dlinfo;
92
+ if (dladdr ((const void *)(uintptr_t )installGetClassHook_untrusted, &dlinfo) == 0 )
93
+ return ;
94
+ auto machHeader = (const mach_header_platform *)dlinfo.dli_fbase ;
95
+ if (machHeader->filetype != MH_EXECUTE)
96
+ return ;
97
+
75
98
// FIXME: delete this #if and dlsym once we don't
76
99
// need to build with older libobjc headers
77
100
#if !OBJC_GETCLASSHOOK_DEFINED
You can’t perform that action at this time.
0 commit comments