[lld] f38f23b - [lld-macho] Add support for .so file discovery

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 13:52:28 PDT 2023


Author: Keith Smiley
Date: 2023-05-23T13:50:14-07:00
New Revision: f38f23bc9ec3d16ea7fd4ccfbfcce01e1413c808

URL: https://github.com/llvm/llvm-project/commit/f38f23bc9ec3d16ea7fd4ccfbfcce01e1413c808
DIFF: https://github.com/llvm/llvm-project/commit/f38f23bc9ec3d16ea7fd4ccfbfcce01e1413c808.diff

LOG: [lld-macho] Add support for .so file discovery

While not the recommended extension on macOS .so is supported by ld64.
This mirrors that behavior.

Related report: https://github.com/bazelbuild/bazel/issues/18464

Differential Revision: https://reviews.llvm.org/D151147

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/InputFiles.cpp
    lld/test/MachO/link-search-order.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 32f8ba4847a6f..d614df678080a 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -91,14 +91,15 @@ static std::optional<StringRef> findLibrary(StringRef name) {
 
   auto doFind = [&] {
     if (config->searchDylibsFirst) {
-      if (std::optional<StringRef> path = findPathCombination(
-              "lib" + name, config->librarySearchPaths, {".tbd", ".dylib"}))
+      if (std::optional<StringRef> path =
+              findPathCombination("lib" + name, config->librarySearchPaths,
+                                  {".tbd", ".dylib", ".so"}))
         return path;
       return findPathCombination("lib" + name, config->librarySearchPaths,
                                  {".a"});
     }
     return findPathCombination("lib" + name, config->librarySearchPaths,
-                               {".tbd", ".dylib", ".a"});
+                               {".tbd", ".dylib", ".so", ".a"});
   };
 
   std::optional<StringRef> path = doFind();

diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index d7401aa312f58..c66679100d4e6 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -1551,7 +1551,7 @@ static DylibFile *findDylib(StringRef path, DylibFile *umbrella,
           return loadDylib(*dylibPath, umbrella);
       }
     } else if (std::optional<StringRef> dylibPath = findPathCombination(
-                   stem, config->librarySearchPaths, {".tbd", ".dylib"}))
+                   stem, config->librarySearchPaths, {".tbd", ".dylib", ".so"}))
       return loadDylib(*dylibPath, umbrella);
   }
 

diff  --git a/lld/test/MachO/link-search-order.s b/lld/test/MachO/link-search-order.s
index 0331e200a971a..9bb97992cb271 100644
--- a/lld/test/MachO/link-search-order.s
+++ b/lld/test/MachO/link-search-order.s
@@ -58,6 +58,7 @@
 
 # DYLIBSEARCH:      searched {{.*}}/MacOSX.sdk/usr/lib{{[/\\]}}libhello.tbd, not found
 # DYLIBSEARCH-NEXT: searched {{.*}}/MacOSX.sdk/usr/lib{{[/\\]}}libhello.dylib, not found
+# DYLIBSEARCH-NEXT: searched {{.*}}/MacOSX.sdk/usr/lib{{[/\\]}}libhello.so, not found
 # DYLIBSEARCH-NEXT: searched [[PATH]]A{{[/\\]}}libhello.tbd, not found
 # DYLIBSEARCH-NEXT: searched [[PATH]]A{{[/\\]}}libhello.dylib, not found
 # DYLIBSEARCH:      searched [[PATH]]{{[/\\]}}libhello.dylib, found
@@ -69,9 +70,11 @@
 
 # ARCHIVESEARCH:      searched {{.*}}/MacOSX.sdk/usr/lib{{[/\\]}}libhello.tbd, not found
 # ARCHIVESEARCH-NEXT: searched {{.*}}/MacOSX.sdk/usr/lib{{[/\\]}}libhello.dylib, not found
+# ARCHIVESEARCH-NEXT: searched {{.*}}/MacOSX.sdk/usr/lib{{[/\\]}}libhello.so, not found
 # ARCHIVESEARCH-NEXT: searched {{.*}}/MacOSX.sdk/usr/lib{{[/\\]}}libhello.a, not found
 # ARCHIVESEARCH-NEXT: searched [[PATH]]A{{[/\\]}}libhello.tbd, not found
 # ARCHIVESEARCH-NEXT: searched [[PATH]]A{{[/\\]}}libhello.dylib, not found
+# ARCHIVESEARCH-NEXT: searched [[PATH]]A{{[/\\]}}libhello.so, not found
 # ARCHIVESEARCH-NEXT: searched [[PATH]]A{{[/\\]}}libhello.a, not found
 # ARCHIVESEARCH:      searched [[PATH]]{{[/\\]}}libhello.dylib, found
 # ARCHIVESEARCH:      searched [[PATH]]A{{[/\\]}}libgoodbye.a, found


        


More information about the llvm-commits mailing list