diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -148,7 +148,7 @@ } } -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 @@ opt::InputArgList &args, const std::vector &roots, const SmallVector &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 @@ 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 --- a/lld/test/MachO/syslibroot.test +++ b/lld/test/MachO/syslibroot.test @@ -18,6 +18,10 @@ 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.