[lld] r178838 - This fixes a SIGSEGV failure in ReaderArchive while trying to trace what

Shankar Easwaran shankare at codeaurora.org
Thu Apr 4 20:56:22 PDT 2013


Also adds functionality to search for libraries with .so extension. This 
functionality was present earlier in a different location.

Sorry for mixing the patches as as there was some issue with svn when I 
tried initially and tried to commit again, mixed both the patches.

Thanks

Shankar Easwaran

On 4/4/2013 10:50 PM, Shankar Easwaran wrote:
> Author: shankare
> Date: Thu Apr  4 22:50:15 2013
> New Revision: 178838
>
> URL: http://llvm.org/viewvc/llvm-project?rev=178838&view=rev
> Log:
> 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.
>
> Modified:
>      lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
>      lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp?rev=178838&r1=178837&r2=178838&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp Thu Apr  4 22:50:15 2013
> @@ -67,7 +67,7 @@ bool ELFTargetInfo::validate(raw_ostream
>         _entrySymbolName = "_start";
>       }
>     }
> -
> +
>     if (_inputFiles.empty()) {
>       diagnostics << "No input files\n";
>       return true;
> @@ -144,14 +144,31 @@ std::unique_ptr<ELFTargetInfo> ELFTarget
>   }
>   
>   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));
>
> Modified: lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ReaderArchive.cpp?rev=178838&r1=178837&r2=178838&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ReaderArchive.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/ReaderArchive.cpp Thu Apr  4 22:50:15 2013
> @@ -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
>   
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation




More information about the llvm-commits mailing list