[PATCH] D106842: [lld/mac] When loading reexports, look for basename in -F / -L first

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 26 17:45:37 PDT 2021


thakis updated this revision to Diff 361868.
thakis added a comment.

tweak test comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106842/new/

https://reviews.llvm.org/D106842

Files:
  lld/MachO/InputFiles.cpp
  lld/test/MachO/sub-library.s


Index: lld/test/MachO/sub-library.s
===================================================================
--- lld/test/MachO/sub-library.s
+++ lld/test/MachO/sub-library.s
@@ -86,6 +86,36 @@
 # RUN:   -o %t/libgoodbye.dylib 2>&1 | FileCheck %s --check-prefix=MISSING-FRAMEWORK
 # MISSING-FRAMEWORK: error: -sub_umbrella libhello does not match a supplied dylib
 
+
+## Check that -F (but not -L) can override the search path in install_name for
+## frameworks.
+# RUN: mkdir -p %t/Hello2.framework
+# RUN: %lld -dylib %t/libhello.o \
+# RUN:   -install_name /path/to/Hello2.framework/Hello2 \
+# RUN:   -o %t/Hello2.framework/Hello2
+# RUN: %lld -dylib -o %t/libgoodbye4.dylib %t/libgoodbye.o \
+# RUN:   -reexport_library %t/Hello2.framework/Hello2
+# RUN: not %lld -lSystem -o %t/hello %t/libgoodbye4.dylib %t/sub-library.o 2>&1 \
+# RUN:   FileCheck %s --check-prefix=NOTFOUND
+# RUN: not %lld -lSystem -o %t/hello -L%t %t/libgoodbye4.dylib %t/sub-library.o 2>&1 \
+# RUN:   FileCheck %s --check-prefix=NOTFOUND
+# NOTFOUND: unable to locate re-export with install name /path/to/Hello2.framework/Hello2
+# RUN: %lld -lSystem -o %t/hello -F%t %t/libgoodbye4.dylib %t/sub-library.o
+
+## Check that -L (but not -F) can override the search path in install_name for
+## libraries.
+# RUN: %lld -dylib %t/libhello.o \
+# RUN:   -install_name /Users/thakis/to/libhello2.dylib \
+# RUN:   -o %t/libhello2.dylib
+# RUN: %lld -dylib -o %t/libgoodbye5.dylib %t/libgoodbye.o \
+# RUN:   -reexport_library %t/libhello2.dylib
+# RUN: not %lld -lSystem -o %t/hello %t/libgoodbye5.dylib %t/sub-library.o 2>&1 \
+# RUN:   FileCheck %s --check-prefix=NOTFOUND2
+# RUN: not %lld -lSystem -o %t/hello -F%t %t/libgoodbye5.dylib %t/sub-library.o 2>&1 \
+# RUN:   FileCheck %s --check-prefix=NOTFOUND2
+# NOTFOUND2: unable to locate re-export with install name /path/to/libhello2.dylib
+# RUN: %lld -lSystem -o %t/hello -L%t %t/libgoodbye5.dylib %t/sub-library.o
+
 .text
 .globl _main
 
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -860,14 +860,37 @@
 // files.
 static DylibFile *findDylib(StringRef path, DylibFile *umbrella,
                             const InterfaceFile *currentTopLevelTapi) {
+  // Search order:
+  // 1. Install name basename in -F / -L directories.
+  {
+    StringRef basename = path::filename(path);
+    SmallString<128> frameworkName;
+    path::append(frameworkName, basename + ".framework", basename);
+    bool isFramework = path.endswith(frameworkName);
+    if (isFramework) {
+      for (StringRef dir : config->frameworkSearchPaths) {
+        SmallString<128> candidate = dir;
+        path::append(candidate, frameworkName);
+        if (Optional<std::string> dylibPath = resolveDylibPath(candidate))
+          return loadDylib(*dylibPath, umbrella);
+      }
+    } else if (Optional<StringRef> dylibPath = findPathCombination(
+                   basename, config->librarySearchPaths, {".tbd", ".dylib"}))
+      return loadDylib(*dylibPath, umbrella);
+  }
+
+  // 2. As absolute path.
   if (path::is_absolute(path, path::Style::posix))
     for (StringRef root : config->systemLibraryRoots)
       if (Optional<std::string> dylibPath =
               resolveDylibPath((root + path).str()))
         return loadDylib(*dylibPath, umbrella);
 
+  // 3. As relative path.
+
   // TODO: Handle -dylib_file
 
+  // Replace @executable_path, @loader_path, @rpath prefixes in install name.
   SmallString<128> newPath;
   if (config->outputType == MH_EXECUTE &&
       path.consume_front("@executable_path/")) {
@@ -894,6 +917,7 @@
     }
   }
 
+  // FIXME: Should this be further up?
   if (currentTopLevelTapi) {
     for (InterfaceFile &child :
          make_pointee_range(currentTopLevelTapi->documents())) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106842.361868.patch
Type: text/x-patch
Size: 3849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210727/a74b7c75/attachment.bin>


More information about the llvm-commits mailing list