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!

llvm-svn: 218083
This commit is contained in:
Rui Ueyama 2014-09-18 22:05:37 +00:00
parent e867e422e2
commit 1f684518c8
1 changed files with 6 additions and 6 deletions

View File

@ -169,22 +169,22 @@ static void buildSearchPath(SmallString<128> &path, StringRef dir,
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()));
}