@@ -860,14 +860,37 @@ static DylibFile *loadDylib(StringRef path, DylibFile *umbrella) {
860
860
// files.
861
861
static DylibFile *findDylib (StringRef path, DylibFile *umbrella,
862
862
const InterfaceFile *currentTopLevelTapi) {
863
+ // Search order:
864
+ // 1. Install name basename in -F / -L directories.
865
+ {
866
+ StringRef stem = path::stem (path);
867
+ SmallString<128 > frameworkName;
868
+ path::append (frameworkName, stem + " .framework" , stem);
869
+ bool isFramework = path.endswith (frameworkName);
870
+ if (isFramework) {
871
+ for (StringRef dir : config->frameworkSearchPaths ) {
872
+ SmallString<128 > candidate = dir;
873
+ path::append (candidate, frameworkName);
874
+ if (Optional<std::string> dylibPath = resolveDylibPath (candidate))
875
+ return loadDylib (*dylibPath, umbrella);
876
+ }
877
+ } else if (Optional<StringRef> dylibPath = findPathCombination (
878
+ stem, config->librarySearchPaths , {" .tbd" , " .dylib" }))
879
+ return loadDylib (*dylibPath, umbrella);
880
+ }
881
+
882
+ // 2. As absolute path.
863
883
if (path::is_absolute (path, path::Style::posix))
864
884
for (StringRef root : config->systemLibraryRoots )
865
885
if (Optional<std::string> dylibPath =
866
886
resolveDylibPath ((root + path).str ()))
867
887
return loadDylib (*dylibPath, umbrella);
868
888
889
+ // 3. As relative path.
890
+
869
891
// TODO: Handle -dylib_file
870
892
893
+ // Replace @executable_path, @loader_path, @rpath prefixes in install name.
871
894
SmallString<128 > newPath;
872
895
if (config->outputType == MH_EXECUTE &&
873
896
path.consume_front (" @executable_path/" )) {
@@ -894,6 +917,7 @@ static DylibFile *findDylib(StringRef path, DylibFile *umbrella,
894
917
}
895
918
}
896
919
920
+ // FIXME: Should this be further up?
897
921
if (currentTopLevelTapi) {
898
922
for (InterfaceFile &child :
899
923
make_pointee_range (currentTopLevelTapi->documents ())) {
0 commit comments