Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -184,20 +184,18 @@ error("attempted static link of dynamic object " + Path); return; } - Files.push_back(createSharedFile(MBRef)); // DSOs usually have DT_SONAME tags in their ELF headers, and the - // sonames are used to identify DSOs. But if they are missing, - // they are identified by filenames. We don't know whether the new - // file has a DT_SONAME or not because we haven't parsed it yet. - // Here, we set the default soname for the file because we might - // need it later. + // sonames are used to identify DSOs. But if they are missing + // (which is relatively rare), they are identified by filenames. + // We are passing the default soname to createSharedFile, but that + // string will end up not being used in most cases. // // If a file was specified by -lfoo, the directory part is not // significant, as a user did not specify it. This behavior is // compatible with GNU. - Files.back()->DefaultSoName = - WithLOption ? sys::path::filename(Path) : Path; + Files.push_back(createSharedFile( + MBRef, WithLOption ? sys::path::filename(Path) : Path)); return; default: if (InLib) Index: lld/ELF/InputFiles.h =================================================================== --- lld/ELF/InputFiles.h +++ lld/ELF/InputFiles.h @@ -93,10 +93,6 @@ uint16_t EMachine = llvm::ELF::EM_NONE; uint8_t OSABI = 0; - // For SharedKind inputs, the string to use in DT_NEEDED when the library - // has no soname. - std::string DefaultSoName; - // Cache for toString(). Only toString() should use this member. mutable std::string ToStringCache; @@ -160,7 +156,7 @@ ArrayRef getSymbols(); ArrayRef getLocalSymbols(); - explicit ObjectFile(MemoryBufferRef M); + ObjectFile(MemoryBufferRef M, StringRef ArchiveName); void parse(llvm::DenseSet &ComdatGroups); InputSectionBase *getSection(const Elf_Sym &Sym) const; @@ -296,7 +292,7 @@ return F->kind() == Base::SharedKind; } - explicit SharedFile(MemoryBufferRef M); + SharedFile(MemoryBufferRef M, StringRef DefaultSoName); void parseSoName(); void parseRest(); @@ -314,6 +310,9 @@ // data structures in the output file. std::map VerdefMap; + // The string to use in DT_NEEDED when the library has no soname. + std::string DefaultSoName; + // Used for --as-needed bool AsNeeded = false; bool IsUsed = false; @@ -329,7 +328,7 @@ InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "", uint64_t OffsetInArchive = 0); -InputFile *createSharedFile(MemoryBufferRef MB); +InputFile *createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName); } // namespace elf } // namespace lld Index: lld/ELF/InputFiles.cpp =================================================================== --- lld/ELF/InputFiles.cpp +++ lld/ELF/InputFiles.cpp @@ -174,8 +174,10 @@ } template -elf::ObjectFile::ObjectFile(MemoryBufferRef M) - : ELFFileBase(Base::ObjectKind, M) {} +elf::ObjectFile::ObjectFile(MemoryBufferRef M, StringRef ArchiveName) + : ELFFileBase(Base::ObjectKind, M) { + this->ArchiveName = ArchiveName; +} template ArrayRef elf::ObjectFile::getLocalSymbols() { @@ -608,8 +610,9 @@ } template -SharedFile::SharedFile(MemoryBufferRef M) - : ELFFileBase(Base::SharedKind, M), AsNeeded(Config->AsNeeded) {} +SharedFile::SharedFile(MemoryBufferRef M, StringRef DefaultSoName) + : ELFFileBase(Base::SharedKind, M), DefaultSoName(DefaultSoName), + AsNeeded(Config->AsNeeded) {} template const typename ELFT::Shdr * @@ -867,34 +870,24 @@ Symbols.push_back(createBitcodeSymbol(KeptComdats, ObjSym, this)); } -template