forked from OSchip/llvm-project
[Gnu] -L paths is not positional.
Looks like -L paths are not positional. They need to be added to a list of search paths and those needs to be searched when lld looks for a library. llvm-svn: 195594
This commit is contained in:
parent
ffbf4c39cc
commit
a27fe1c918
|
@ -28,16 +28,12 @@ namespace lld {
|
|||
/// \brief Represents a ELF File
|
||||
class ELFFileNode : public FileNode {
|
||||
public:
|
||||
ELFFileNode(ELFLinkingContext &ctx, StringRef path,
|
||||
std::vector<StringRef> searchPath, int64_t ordinal = -1,
|
||||
ELFFileNode(ELFLinkingContext &ctx, StringRef path, int64_t ordinal = -1,
|
||||
bool isWholeArchive = false, bool asNeeded = false,
|
||||
bool dashlPrefix = false)
|
||||
: FileNode(path, ordinal), _elfLinkingContext(ctx),
|
||||
_isWholeArchive(isWholeArchive), _asNeeded(asNeeded),
|
||||
_isDashlPrefix(dashlPrefix) {
|
||||
std::copy(searchPath.begin(), searchPath.end(),
|
||||
std::back_inserter(_libraryPaths));
|
||||
}
|
||||
_isDashlPrefix(dashlPrefix) {}
|
||||
|
||||
static inline bool classof(const InputElement *a) {
|
||||
return a->kind() == InputElement::Kind::File;
|
||||
|
@ -64,10 +60,6 @@ public:
|
|||
<< ((_isWholeArchive) ? "true" : "false") << "\n";
|
||||
diagnostics << " - asNeeded : " << ((_asNeeded) ? "true" : "false")
|
||||
<< "\n";
|
||||
diagnostics << " contextPath : " << ((_libraryPaths.size()) ? "" : "None")
|
||||
<< "\n";
|
||||
for (auto path : _libraryPaths)
|
||||
diagnostics << " - " << path << "\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -103,7 +95,6 @@ private:
|
|||
bool _isWholeArchive;
|
||||
bool _asNeeded;
|
||||
bool _isDashlPrefix;
|
||||
std::vector<StringRef> _libraryPaths;
|
||||
std::unique_ptr<FileArchive> _archiveFile;
|
||||
};
|
||||
|
||||
|
|
|
@ -155,9 +155,7 @@ public:
|
|||
virtual void setNoAllowDynamicLibraries() { _noAllowDynamicLibraries = true; }
|
||||
|
||||
/// Searches directories for a match on the input File
|
||||
ErrorOr<StringRef>
|
||||
searchLibrary(StringRef libName,
|
||||
const std::vector<StringRef> &searchPath) const;
|
||||
ErrorOr<StringRef> searchLibrary(StringRef libName) const;
|
||||
|
||||
/// Get the entry symbol name
|
||||
virtual StringRef entrySymbolName() const;
|
||||
|
@ -220,6 +218,12 @@ public:
|
|||
return x;
|
||||
}
|
||||
|
||||
// add search path to list.
|
||||
virtual bool addSearchPath(StringRef ref) {
|
||||
_inputSearchPaths.push_back(ref);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
ELFLinkingContext() LLVM_DELETED_FUNCTION;
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ public:
|
|||
|
||||
// Get the Input file magic for creating appropriate InputGraph nodes.
|
||||
error_code getFileMagic(ELFLinkingContext &ctx, StringRef path,
|
||||
std::vector<StringRef> &searchPaths,
|
||||
llvm::sys::fs::file_magic &magic) {
|
||||
error_code ec = llvm::sys::fs::identify_magic(path, magic);
|
||||
if (ec)
|
||||
|
@ -91,7 +90,7 @@ error_code getFileMagic(ELFLinkingContext &ctx, StringRef path,
|
|||
llvm::ErrorOr<StringRef> ELFFileNode::getPath(const LinkingContext &) const {
|
||||
if (!_isDashlPrefix)
|
||||
return _path;
|
||||
return _elfLinkingContext.searchLibrary(_path, _libraryPaths);
|
||||
return _elfLinkingContext.searchLibrary(_path);
|
||||
}
|
||||
|
||||
std::string ELFFileNode::errStr(error_code errc) {
|
||||
|
@ -155,7 +154,6 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
std::stack<InputElement *> controlNodeStack;
|
||||
|
||||
// Positional options for an Input File
|
||||
std::vector<StringRef> searchPath;
|
||||
bool isWholeArchive = false;
|
||||
bool asNeeded = false;
|
||||
bool _outputOptionSet = false;
|
||||
|
@ -168,6 +166,16 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
|
||||
int index = 0;
|
||||
|
||||
// Set sys root path.
|
||||
if (llvm::opt::Arg *sysRootPath = parsedArgs->getLastArg(OPT_sysroot))
|
||||
ctx->setSysroot(sysRootPath->getValue());
|
||||
|
||||
// Add all search paths.
|
||||
for (auto it = parsedArgs->filtered_begin(OPT_L),
|
||||
ie = parsedArgs->filtered_end();
|
||||
it != ie; ++it)
|
||||
ctx->addSearchPath((*it)->getValue());
|
||||
|
||||
// Process all the arguments and create Input Elements
|
||||
for (auto inputArg : *parsedArgs) {
|
||||
switch (inputArg->getOption().getID()) {
|
||||
|
@ -259,18 +267,18 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
case OPT_no_whole_archive:
|
||||
isWholeArchive = false;
|
||||
break;
|
||||
|
||||
case OPT_whole_archive:
|
||||
isWholeArchive = true;
|
||||
break;
|
||||
|
||||
case OPT_as_needed:
|
||||
asNeeded = true;
|
||||
break;
|
||||
|
||||
case OPT_no_as_needed:
|
||||
asNeeded = false;
|
||||
break;
|
||||
case OPT_L:
|
||||
searchPath.push_back(inputArg->getValue());
|
||||
break;
|
||||
|
||||
case OPT_start_group: {
|
||||
std::unique_ptr<InputElement> controlStart(new ELFGroup(*ctx, index++));
|
||||
|
@ -295,8 +303,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
// If the path was referred to by using a -l argument, lets search
|
||||
// for the file in the search path.
|
||||
if (isDashlPrefix) {
|
||||
ErrorOr<StringRef> resolvedPath =
|
||||
ctx->searchLibrary(userPath, searchPath);
|
||||
ErrorOr<StringRef> resolvedPath = ctx->searchLibrary(userPath);
|
||||
if (!resolvedPath) {
|
||||
diagnostics << " Unable to find library -l" << userPath << "\n";
|
||||
return false;
|
||||
|
@ -304,7 +311,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
resolvedInputPath = resolvedPath->str();
|
||||
}
|
||||
llvm::sys::fs::file_magic magic = llvm::sys::fs::file_magic::unknown;
|
||||
error_code ec = getFileMagic(*ctx, resolvedInputPath, searchPath, magic);
|
||||
error_code ec = getFileMagic(*ctx, resolvedInputPath, magic);
|
||||
if (ec) {
|
||||
diagnostics << "lld: unknown input file format for file " << userPath
|
||||
<< "\n";
|
||||
|
@ -316,8 +323,8 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
|
||||
FileNode *inputNode = nullptr;
|
||||
if (isELFFileNode)
|
||||
inputNode = new ELFFileNode(*ctx, userPath, searchPath, index++,
|
||||
isWholeArchive, asNeeded, isDashlPrefix);
|
||||
inputNode = new ELFFileNode(*ctx, userPath, index++, isWholeArchive,
|
||||
asNeeded, isDashlPrefix);
|
||||
else {
|
||||
inputNode = new ELFGNULdScript(*ctx, resolvedInputPath, index++);
|
||||
ec = inputNode->parse(*ctx, diagnostics);
|
||||
|
@ -352,10 +359,6 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
break;
|
||||
}
|
||||
|
||||
case OPT_sysroot:
|
||||
ctx->setSysroot(inputArg->getValue());
|
||||
break;
|
||||
|
||||
case OPT_soname:
|
||||
ctx->setSharedObjectName(inputArg->getValue());
|
||||
break;
|
||||
|
|
|
@ -87,7 +87,6 @@ error_code GNULdScript::parse(const LinkingContext &ctx,
|
|||
error_code ELFGNULdScript::parse(const LinkingContext &ctx,
|
||||
raw_ostream &diagnostics) {
|
||||
int64_t index = 0;
|
||||
std::vector<StringRef> searchPath;
|
||||
if (error_code ec = GNULdScript::parse(ctx, diagnostics))
|
||||
return ec;
|
||||
for (const auto &c : _linkerScript->_commands) {
|
||||
|
@ -95,10 +94,10 @@ error_code ELFGNULdScript::parse(const LinkingContext &ctx,
|
|||
std::unique_ptr<InputElement> controlStart(
|
||||
new ELFGroup(_elfLinkingContext, index++));
|
||||
for (auto &path : group->getPaths()) {
|
||||
// TODO : Propagate SearchPath, Set WholeArchive/dashlPrefix
|
||||
// TODO : Propagate Set WholeArchive/dashlPrefix
|
||||
auto inputNode = new ELFFileNode(
|
||||
_elfLinkingContext, _elfLinkingContext.allocateString(path._path),
|
||||
searchPath, index++, false, path._asNeeded, false);
|
||||
index++, false, path._asNeeded, false);
|
||||
std::unique_ptr<InputElement> inputFile(inputNode);
|
||||
dyn_cast<ControlNode>(controlStart.get())
|
||||
->processInputElement(std::move(inputFile));
|
||||
|
|
|
@ -132,12 +132,11 @@ ELFLinkingContext::create(llvm::Triple triple) {
|
|||
}
|
||||
}
|
||||
|
||||
ErrorOr<StringRef> ELFLinkingContext::searchLibrary(
|
||||
StringRef libName, const std::vector<StringRef> &searchPath) const {
|
||||
ErrorOr<StringRef> ELFLinkingContext::searchLibrary(StringRef libName) const {
|
||||
bool foundFile = false;
|
||||
StringRef pathref;
|
||||
SmallString<128> path;
|
||||
for (StringRef dir : searchPath) {
|
||||
for (StringRef dir : _inputSearchPaths) {
|
||||
// Search for dynamic library
|
||||
if (!_isStaticExecutable) {
|
||||
path.clear();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
RUN: not lld -flavor gnu -t -L%p/../elf/Inputs -lfnarchive 2> %t.err
|
||||
RUN: not lld -flavor gnu -t -lfnarchive -L%p/../elf/Inputs 2> %t.err
|
||||
RUN: FileCheck %s < %t.err
|
||||
|
||||
# run linker with -t mode to dump full paths to input files
|
||||
|
|
|
@ -13,8 +13,6 @@ CHECK: Ordinal : 0
|
|||
CHECK: Attributes :
|
||||
CHECK: - wholeArchive : false
|
||||
CHECK: - asNeeded : false
|
||||
CHECK: contextPath :
|
||||
CHECK: - {{[^ ]+}}elf/Inputs
|
||||
|
||||
WHOLEARCHIVE: Name : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a
|
||||
WHOLEARCHIVE: Type : ELF File
|
||||
|
@ -22,8 +20,6 @@ WHOLEARCHIVE: Ordinal : 0
|
|||
WHOLEARCHIVE: Attributes :
|
||||
WHOLEARCHIVE: - wholeArchive : true
|
||||
WHOLEARCHIVE: - asNeeded : false
|
||||
WHOLEARCHIVE: contextPath :
|
||||
WHOLEARCHIVE: - {{[^ ]+}}elf/Inputs
|
||||
|
||||
ASNEEDED: Name : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a
|
||||
ASNEEDED: Type : ELF File
|
||||
|
@ -31,8 +27,6 @@ ASNEEDED: Ordinal : 0
|
|||
ASNEEDED: Attributes :
|
||||
ASNEEDED: - wholeArchive : true
|
||||
ASNEEDED: - asNeeded : true
|
||||
ASNEEDED: contextPath :
|
||||
ASNEEDED: - {{[^ ]+}}elf/Inputs
|
||||
|
||||
SYSROOT: Name : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a
|
||||
SYSROOT: Type : ELF File
|
||||
|
@ -40,5 +34,3 @@ SYSROOT: Ordinal : 0
|
|||
SYSROOT: Attributes :
|
||||
SYSROOT: - wholeArchive : false
|
||||
SYSROOT: - asNeeded : false
|
||||
SYSROOT: contextPath :
|
||||
SYSROOT: - =/Inputs
|
||||
|
|
Loading…
Reference in New Issue