This fixes a SIGSEGV failure in ReaderArchive while trying to trace what
InputFile is being pulled from the Archive library to resolve a symbol.
The buffer which was being used was already being handed over to the
MemoryBuffer object and was being accessed after the hand over.
Moving it before the buffer is handed over.
llvm-svn: 178838
diff --git a/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp b/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
index 338096d..577f5a8 100644
--- a/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
+++ b/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
@@ -67,7 +67,7 @@
_entrySymbolName = "_start";
}
}
-
+
if (_inputFiles.empty()) {
diagnostics << "No input files\n";
return true;
@@ -144,14 +144,31 @@
}
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 d3287dd..1928e2f 100644
--- a/lld/lib/ReaderWriter/ReaderArchive.cpp
+++ b/lld/lib/ReaderWriter/ReaderArchive.cpp
@@ -45,9 +45,9 @@
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 @@
}
}
- std::unordered_map<StringRef,
+ std::unordered_map<StringRef,
llvm::object::Archive::child_iterator> _symbolMemberMap;
}; // class FileArchive