Skip to content

Commit

Permalink
[lld/mac] Search .tbd before binary for framework files too
Browse files Browse the repository at this point in the history
This matters for example for the iPhoneSimulator14.0.sdk, which has
a System/Library/Frameworks/UIKit.framework/UIKit that has
LC_BUILD_VERSION with minos of 14.0, so linking against that file
will produce warnings like:

   .../iPhoneSimulator14.0.sdk/System/Library/Frameworks/UIKit.framework/UIKit
   has version 14.0.0, which is newer than target minimum of 12.0.0

when targeting x86_64-apple-ios12.0-simulator. That doens't happen when
linking against UIKit.tbd instead, obviously.

Linking with RC_TRACE_DYLIB_SEARCHING=1 shows that ld64 also searches
the tbd file first, and we already get that right for non-framework
dylibs.

Fixes crbug.com/1249456.

Differential Revision: https://reviews.llvm.org/D109768
  • Loading branch information
nico committed Sep 14, 2021
1 parent 8cbbd7e commit ed2f0ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lld/MachO/DriverUtils.cpp
Expand Up @@ -186,17 +186,17 @@ static void searchedDylib(const Twine &path, bool found) {
Optional<std::string> macho::resolveDylibPath(StringRef dylibPath) {
// TODO: if a tbd and dylib are both present, we should check to make sure
// they are consistent.
bool dylibExists = fs::exists(dylibPath);
searchedDylib(dylibPath, dylibExists);
if (dylibExists)
return std::string(dylibPath);

SmallString<261> tbdPath = dylibPath;
path::replace_extension(tbdPath, ".tbd");
bool tbdExists = fs::exists(tbdPath);
searchedDylib(tbdPath, tbdExists);
if (tbdExists)
return std::string(tbdPath);

bool dylibExists = fs::exists(dylibPath);
searchedDylib(dylibPath, dylibExists);
if (dylibExists)
return std::string(dylibPath);
return {};
}

Expand Down
7 changes: 7 additions & 0 deletions lld/test/MachO/link-search-order.s
Expand Up @@ -48,6 +48,10 @@
# RUN: -L%tD -L%t -lhello -lgoodbye -lSystem %t/test.o -search_dylibs_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=DYLIB %s

################ Test that we try the tbd file before the binary for frameworks too.
# RUN: not %lld -dylib -F %t -framework Foo -o %t --print-dylib-search \
# RUN: | FileCheck --check-prefix=FRAMEWORKSEARCH -DPATH=%t %s

# DYLIB: @executable_path/libhello.dylib
# DYLIB: @executable_path/libgoodbye.dylib
# DYLIB: /usr/lib/libSystem.dylib
Expand All @@ -72,6 +76,9 @@
# ARCHIVESEARCH: searched [[PATH]]{{[/\\]}}libhello.dylib, found
# ARCHIVESEARCH: searched [[PATH]]A{{[/\\]}}libgoodbye.a, found

# FRAMEWORKSEARCH: searched [[PATH]]{{[/\\]}}Foo.framework{{[/\\]}}Foo.tbd, not found
# FRAMEWORKSEARCH-NEXT: searched [[PATH]]{{[/\\]}}Foo.framework{{[/\\]}}Foo, not found

.section __TEXT,__text
.global _main

Expand Down

0 comments on commit ed2f0ad

Please sign in to comment.