Skip to content

Commit aecb8f3

Browse files
authored
Merge pull request swiftlang#36872 from jckarter/faster-main-exe-check-in-compat-hook
Compatibility50: Use __dso_handle for cheaper main executable check.
2 parents 76b2f0b + 13e6566 commit aecb8f3

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

stdlib/toolchain/Compatibility50/Overrides.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,13 @@ using mach_header_platform = mach_header;
8686

8787
__attribute__((constructor))
8888
static void installGetClassHook_untrusted() {
89+
extern char __dso_handle[];
90+
8991
// swiftCompatibility* might be linked into multiple dynamic libraries because
9092
// of build system reasons, but the copy in the main executable is the only
9193
// one that should count. Bail early unless we're running out of the main
9294
// executable.
93-
//
94-
// Newer versions of dyld add additional API that can determine this more
95-
// efficiently, but we have to support back to OS X 10.9/iOS 7, so dladdr
96-
// is the only API that reaches back that far.
97-
Dl_info dlinfo;
98-
if (dladdr((const void*)(uintptr_t)installGetClassHook_untrusted, &dlinfo) == 0)
99-
return;
100-
auto machHeader = (const mach_header_platform *)dlinfo.dli_fbase;
95+
auto machHeader = (const mach_header_platform *)__dso_handle;
10196
if (machHeader->filetype != MH_EXECUTE)
10297
return;
10398

0 commit comments

Comments
 (0)