[lld] d50f44a - [lld-macho] Handle framework search path, alongside library search path
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 17 20:42:01 PDT 2020
Author: Greg McGary
Date: 2020-06-17T20:41:28-07:00
New Revision: d50f44a2f771b0872f6555cc3023cc5e9cfacabd
URL: https://github.com/llvm/llvm-project/commit/d50f44a2f771b0872f6555cc3023cc5e9cfacabd
DIFF: https://github.com/llvm/llvm-project/commit/d50f44a2f771b0872f6555cc3023cc5e9cfacabd.diff
LOG: [lld-macho] Handle framework search path, alongside library search path
Summary:
Add front-end support for `lld::macho::Configuration::frameworkSearchPath`.
Depends on D80582.
Reviewers: ruiu, pcc, MaskRay, smeenai, int3, Ktwu, alexshap, christylee
Reviewed By: int3
Subscribers: ormris, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D80677
Added:
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/test/MachO/search-paths.test
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 39839d57d4ac..79812a433563 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -29,7 +29,9 @@ struct Configuration {
llvm::StringRef outputFile;
llvm::MachO::Architecture arch;
llvm::MachO::HeaderFileType outputType;
- std::vector<llvm::StringRef> searchPaths;
+ std::vector<llvm::StringRef> librarySearchPaths;
+ // TODO: use the framework search paths
+ std::vector<llvm::StringRef> frameworkSearchPaths;
llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;
};
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 84e31be1bd68..f4531e42ad13 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -30,6 +30,7 @@
#include "llvm/Object/Archive.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
@@ -86,7 +87,7 @@ static Optional<std::string> findLibrary(StringRef name) {
std::string archive = (llvm::Twine("lib") + name + ".a").str();
llvm::SmallString<260> location;
- for (StringRef dir : config->searchPaths) {
+ for (StringRef dir : config->librarySearchPaths) {
for (StringRef library : {stub, shared, archive}) {
location = dir;
llvm::sys::path::append(location, library);
@@ -110,13 +111,42 @@ static TargetInfo *createTargetInfo(opt::InputArgList &args) {
}
}
-static std::vector<StringRef> getSearchPaths(opt::InputArgList &args) {
- std::vector<StringRef> ret{args::getStrings(args, OPT_L)};
- if (!args.hasArg(OPT_Z)) {
- ret.push_back("/usr/lib");
- ret.push_back("/usr/local/lib");
+static bool isDirectory(StringRef option, StringRef path) {
+ if (!fs::exists(path)) {
+ warn("directory not found for option -" + option + path);
+ return false;
+ } else if (!fs::is_directory(path)) {
+ warn("option -" + option + path + " references a non-directory path");
+ return false;
+ }
+ return true;
+}
+
+static void getSearchPaths(std::vector<StringRef> &paths, unsigned optionCode,
+ opt::InputArgList &args,
+ const SmallVector<StringRef, 2> &systemPaths) {
+ StringRef optionLetter{(optionCode == OPT_F ? "F" : "L")};
+ for (auto const &path : args::getStrings(args, optionCode)) {
+ if (isDirectory(optionLetter, path))
+ paths.push_back(path);
}
- return ret;
+ if (!args.hasArg(OPT_Z) && Triple(sys::getProcessTriple()).isOSDarwin()) {
+ for (auto const &path : systemPaths) {
+ if (isDirectory(optionLetter, path))
+ paths.push_back(path);
+ }
+ }
+}
+
+static void getLibrarySearchPaths(std::vector<StringRef> &paths,
+ opt::InputArgList &args) {
+ getSearchPaths(paths, OPT_L, args, {"/usr/lib", "/usr/local/lib"});
+}
+
+static void getFrameworkSearchPaths(std::vector<StringRef> &paths,
+ opt::InputArgList &args) {
+ getSearchPaths(paths, OPT_F, args,
+ {"/Library/Frameworks", "/System/Library/Frameworks"});
}
static void addFile(StringRef path) {
@@ -330,14 +360,20 @@ bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
config->outputFile = args.getLastArgValue(OPT_o, "a.out");
config->installName =
args.getLastArgValue(OPT_install_name, config->outputFile);
- config->searchPaths = getSearchPaths(args);
+ getLibrarySearchPaths(config->librarySearchPaths, args);
+ getFrameworkSearchPaths(config->frameworkSearchPaths, args);
config->outputType = args.hasArg(OPT_dylib) ? MH_DYLIB : MH_EXECUTE;
if (args.hasArg(OPT_v)) {
message(getLLDVersion());
- std::vector<StringRef> &searchPaths = config->searchPaths;
- message("Library search paths:\n" +
- llvm::join(searchPaths.begin(), searchPaths.end(), "\n"));
+ message(StringRef("Library search paths:") +
+ (config->librarySearchPaths.size()
+ ? "\n\t" + llvm::join(config->librarySearchPaths, "\n\t")
+ : ""));
+ message(StringRef("Framework search paths:") +
+ (config->frameworkSearchPaths.size()
+ ? "\n\t" + llvm::join(config->frameworkSearchPaths, "\n\t")
+ : ""));
freeArena();
return !errorCount();
}
diff --git a/lld/test/MachO/search-paths.test b/lld/test/MachO/search-paths.test
index 84e8ba93c616..124a2a080b6d 100644
--- a/lld/test/MachO/search-paths.test
+++ b/lld/test/MachO/search-paths.test
@@ -1,12 +1,15 @@
-RUN: mkdir -p %t
+UNSUPPORTED: darwin
-RUN: lld -flavor darwinnew -v -L%t 2>&1 | FileCheck -DDIR=%t %s
+RUN: mkdir -p %t1 %t2
+
+RUN: lld -flavor darwinnew -v -L%t1 -F%t2 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 %s
CHECK: Library search paths:
-CHECK-NEXT: [[DIR]]
-CHECK-NEXT: /usr/lib
-CHECK-NEXT: /usr/local/lib
+CHECK-NEXT: [[LDIR]]
+CHECK-NEXT: Framework search paths:
+CHECK-NEXT: [[FDIR]]
-RUN: lld -flavor darwinnew -v -L%t -Z 2>&1 | FileCheck -DDIR=%t --check-prefix=CHECK_Z %s
+RUN: lld -flavor darwinnew -v -L%t1 -F%t2 -Z 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 --check-prefix=CHECK_Z %s
CHECK_Z: Library search paths:
-CHECK_Z-NEXT: [[DIR]]
-CHECK_Z-NOT: /usr/
+CHECK_Z-NEXT: [[LDIR]]
+CHECK_Z-NEXT: Framework search paths:
+CHECK_Z-NEXT: [[FDIR]]
More information about the llvm-commits
mailing list