[lld] r218083 - Fix buggy Twine storage in ELFLinkingContext::searchLibrary()
Rui Ueyama
ruiu at google.com
Thu Sep 18 15:05:37 PDT 2014
Author: ruiu
Date: Thu Sep 18 17:05:37 2014
New Revision: 218083
URL: http://llvm.org/viewvc/llvm-project?rev=218083&view=rev
Log:
Fix buggy Twine storage in ELFLinkingContext::searchLibrary()
This patch fixes a forbidden use of Twine. It should only be used
as an intermediary value, but never stored.
This caused a bug in lld when running on Linux and compiled with
optimizations - it couldn't properly search libs.
Patch from Rafael Auler!
Modified:
lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=218083&r1=218082&r2=218083&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Thu Sep 18 17:05:37 2014
@@ -169,22 +169,22 @@ static void buildSearchPath(SmallString<
ErrorOr<StringRef> ELFLinkingContext::searchLibrary(StringRef libName) const {
bool hasColonPrefix = libName[0] == ':';
- Twine soName =
- hasColonPrefix ? libName.drop_front() : Twine("lib", libName) + ".so";
- Twine archiveName =
- hasColonPrefix ? libName.drop_front() : Twine("lib", libName) + ".a";
SmallString<128> path;
for (StringRef dir : _inputSearchPaths) {
// Search for dynamic library
if (!_isStaticExecutable) {
buildSearchPath(path, dir, _sysrootPath);
- llvm::sys::path::append(path, soName);
+ llvm::sys::path::append(path, hasColonPrefix
+ ? libName.drop_front()
+ : Twine("lib", libName) + ".so");
if (llvm::sys::fs::exists(path.str()))
return StringRef(*new (_allocator) std::string(path.str()));
}
// Search for static libraries too
buildSearchPath(path, dir, _sysrootPath);
- llvm::sys::path::append(path, archiveName);
+ llvm::sys::path::append(path, hasColonPrefix
+ ? libName.drop_front()
+ : Twine("lib", libName) + ".a");
if (llvm::sys::fs::exists(path.str()))
return StringRef(*new (_allocator) std::string(path.str()));
}
More information about the llvm-commits
mailing list