mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-15 04:29:42 +00:00
[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
This commit is contained in:
parent
525c7d8cda
commit
d50f44a2f7
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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 ret;
|
||||
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);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
@ -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]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user