summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp33
-rw-r--r--lld/lib/ReaderWriter/ReaderArchive.cpp4
2 files changed, 27 insertions, 10 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp b/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
index 338096d3a2c..577f5a86107 100644
--- a/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
+++ b/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
@@ -67,7 +67,7 @@ bool ELFTargetInfo::validate(raw_ostream &diagnostics) {
_entrySymbolName = "_start";
}
}
-
+
if (_inputFiles.empty()) {
diagnostics << "No input files\n";
return true;
@@ -144,14 +144,31 @@ std::unique_ptr<ELFTargetInfo> ELFTargetInfo::create(llvm::Triple triple) {
}
bool ELFTargetInfo::appendLibrary(StringRef libName) {
- SmallString<128> fullPath;
+ bool foundFile = false;
+ StringRef pathref;
for (StringRef dir : _inputSearchPaths) {
- // FIXME: need to handle other extensions, like .so
- fullPath.assign(dir);
- llvm::sys::path::append(fullPath, Twine("lib") + libName + ".a");
- StringRef pathref = fullPath.str();
- unsigned pathlen = pathref.size();
- if (llvm::sys::fs::exists(pathref)) {
+ // Search for dynamic library
+ if (!_isStaticExecutable) {
+ SmallString<128> dynlibPath;
+ dynlibPath.assign(dir);
+ llvm::sys::path::append(dynlibPath, Twine("lib") + libName + ".so");
+ pathref = dynlibPath.str();
+ if (llvm::sys::fs::exists(pathref)) {
+ foundFile = true;
+ }
+ }
+ // Search for static libraries too
+ if (!foundFile) {
+ SmallString<128> archivefullPath;
+ archivefullPath.assign(dir);
+ llvm::sys::path::append(archivefullPath, Twine("lib") + libName + ".a");
+ pathref = archivefullPath.str();
+ if (llvm::sys::fs::exists(pathref)) {
+ foundFile = true;
+ }
+ }
+ if (foundFile) {
+ unsigned pathlen = pathref.size();
char *x = _extraStrings.Allocate<char>(pathlen);
memcpy(x, pathref.data(), pathlen);
appendInputFile(StringRef(x,pathlen));
diff --git a/lld/lib/ReaderWriter/ReaderArchive.cpp b/lld/lib/ReaderWriter/ReaderArchive.cpp
index d3287dd429d..1928e2fa0f7 100644
--- a/lld/lib/ReaderWriter/ReaderArchive.cpp
+++ b/lld/lib/ReaderWriter/ReaderArchive.cpp
@@ -45,9 +45,9 @@ public:
OwningPtr<MemoryBuffer> buff;
if (ci->getMemoryBuffer(buff, true))
return nullptr;
- std::unique_ptr<MemoryBuffer> mb(buff.take());
if (_targetInfo.logInputFiles())
llvm::outs() << buff->getBufferIdentifier() << "\n";
+ std::unique_ptr<MemoryBuffer> mb(buff.take());
if (_targetInfo.parseFile(mb, result))
return nullptr;
@@ -153,7 +153,7 @@ public:
}
}
- std::unordered_map<StringRef,
+ std::unordered_map<StringRef,
llvm::object::Archive::child_iterator> _symbolMemberMap;
}; // class FileArchive
OpenPOWER on IntegriCloud