[lld] 3e7a86e - [lld-macho] Fall back to raw path if we don't find anything under syslibroot

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 19:26:52 PDT 2020


Author: Jez Ng
Date: 2020-08-26T19:20:35-07:00
New Revision: 3e7a86e3664a118924bae7306e7f9a7fadf45648

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

LOG: [lld-macho] Fall back to raw path if we don't find anything under syslibroot

This matches ld64's behavior

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

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/test/MachO/syslibroot.test

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 2ffedaaf42c4..1ab2ec6ae48c 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -148,7 +148,7 @@ static TargetInfo *createTargetInfo(opt::InputArgList &args) {
   }
 }
 
-static bool isDirectory(StringRef option, StringRef path) {
+static bool warnIfNotDirectory(StringRef option, StringRef path) {
   if (!fs::exists(path)) {
     warn("directory not found for option -" + option + path);
     return false;
@@ -163,21 +163,23 @@ static void getSearchPaths(std::vector<StringRef> &paths, unsigned optionCode,
                            opt::InputArgList &args,
                            const std::vector<StringRef> &roots,
                            const SmallVector<StringRef, 2> &systemPaths) {
-  StringRef optionLetter{(optionCode == OPT_F ? "F" : "L")};
-  for (auto const &path : args::getStrings(args, optionCode)) {
+  StringRef optionLetter{optionCode == OPT_F ? "F" : "L"};
+  for (StringRef path : args::getStrings(args, optionCode)) {
     // NOTE: only absolute paths are re-rooted to syslibroot(s)
-    if (llvm::sys::path::is_absolute(path, llvm::sys::path::Style::posix)) {
+    bool found = false;
+    if (path::is_absolute(path, path::Style::posix)) {
       for (StringRef root : roots) {
         SmallString<261> buffer(root);
-        llvm::sys::path::append(buffer, path);
+        path::append(buffer, path);
         // Do not warn about paths that are computed via the syslib roots
-        if (llvm::sys::fs::is_directory(buffer))
+        if (fs::is_directory(buffer)) {
           paths.push_back(saver.save(buffer.str()));
+          found = true;
+        }
       }
-    } else {
-      if (isDirectory(optionLetter, path))
-        paths.push_back(path);
     }
+    if (!found && warnIfNotDirectory(optionLetter, path))
+      paths.push_back(path);
   }
 
   // `-Z` suppresses the standard "system" search paths.
@@ -187,8 +189,8 @@ static void getSearchPaths(std::vector<StringRef> &paths, unsigned optionCode,
   for (auto const &path : systemPaths) {
     for (auto root : roots) {
       SmallString<261> buffer(root);
-      llvm::sys::path::append(buffer, path);
-      if (isDirectory(optionLetter, buffer))
+      path::append(buffer, path);
+      if (warnIfNotDirectory(optionLetter, buffer))
         paths.push_back(saver.save(buffer.str()));
     }
   }

diff  --git a/lld/test/MachO/syslibroot.test b/lld/test/MachO/syslibroot.test
index e9d87abd0cc1..0d2d822273e4 100644
--- a/lld/test/MachO/syslibroot.test
+++ b/lld/test/MachO/syslibroot.test
@@ -18,6 +18,10 @@ CHECK-ABSOLUTE-PATH-REROOTED: Library search paths:
 CHECK-ABSOLUTE-PATH-REROOTED: [[ROOT]]/Library/libxml2-development
 CHECK-ABSOLUTE-PATH-REROOTED: [[ROOT]]/usr/lib
 
+RUN: lld -flavor darwinnew -v -Z -syslibroot %t -L %t/Library/libxml2-development | FileCheck %s -check-prefix CHECK-PATH-WITHOUT-REROOT -DPATH=%t/Library/libxml2-development
+CHECK-PATH-WITHOUT-REROOT:      Library search paths:
+CHECK-PATH-WITHOUT-REROOT-NEXT: [[PATH]]
+
 # NOTE: the match here is fuzzy because the default search paths exist on Linux
 # and macOS, but not on Windows (that is we ignore `/var/empty`).  This allows
 # us to run the test uniformly on all the platforms.


        


More information about the llvm-commits mailing list