Index: lld/COFF/Driver.h =================================================================== --- lld/COFF/Driver.h +++ lld/COFF/Driver.h @@ -74,7 +74,7 @@ // Used by ArchiveFile to enqueue members. void enqueueArchiveMember(const Archive::Child &C, StringRef SymName, - StringRef ParentName); + ArchiveFile *Parent); MemoryBufferRef takeBuffer(std::unique_ptr MB); @@ -119,7 +119,7 @@ void addBuffer(std::unique_ptr MB, bool WholeArchive); void addArchiveBuffer(MemoryBufferRef MBRef, StringRef SymName, - StringRef ParentName); + ArchiveFile *Parent); void enqueuePath(StringRef Path, bool WholeArchive); Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -142,7 +142,7 @@ CHECK(Archive::create(MBRef), Filename + ": failed to parse archive"); for (MemoryBufferRef M : getArchiveMembers(File.get())) - addArchiveBuffer(M, "", Filename); + addArchiveBuffer(M, "", nullptr); return; } Symtab->addFile(make(MBRef)); @@ -184,7 +184,7 @@ } void LinkerDriver::addArchiveBuffer(MemoryBufferRef MB, StringRef SymName, - StringRef ParentName) { + ArchiveFile *Parent) { file_magic Magic = identify_magic(MB.getBuffer()); if (Magic == file_magic::coff_import_library) { Symtab->addFile(make(MB)); @@ -201,19 +201,19 @@ return; } - Obj->ParentName = ParentName; + Obj->Parent = Parent; Symtab->addFile(Obj); log("Loaded " + toString(Obj) + " for " + SymName); } void LinkerDriver::enqueueArchiveMember(const Archive::Child &C, StringRef SymName, - StringRef ParentName) { + ArchiveFile *Parent) { if (!C.getParent()->isThin()) { MemoryBufferRef MB = CHECK( C.getMemoryBufferRef(), "could not get the buffer for the member defining symbol " + SymName); - enqueueTask([=]() { Driver->addArchiveBuffer(MB, SymName, ParentName); }); + enqueueTask([=]() { Driver->addArchiveBuffer(MB, SymName, Parent); }); return; } @@ -227,7 +227,7 @@ fatal("could not get the buffer for the member defining " + SymName + ": " + MBOrErr.second.message()); Driver->addArchiveBuffer(takeBuffer(std::move(MBOrErr.first)), SymName, - ParentName); + Parent); }); } @@ -738,12 +738,12 @@ // to MSVC before any archives, so that MSVC uses the same objects to satisfy // references. for (ObjFile *Obj : ObjFile::Instances) { - if (Obj->ParentName.empty()) + if (!Obj->Parent) continue; SmallString<128> S; int Fd; if (auto EC = sys::fs::createTemporaryFile( - "lld-" + sys::path::filename(Obj->ParentName), ".obj", Fd, S)) + "lld-" + sys::path::filename(Obj->Parent->getName()), ".obj", Fd, S)) fatal("cannot create a temporary file: " + EC.message()); raw_fd_ostream OS(Fd, /*shouldClose*/ true); OS << Obj->MB.getBuffer(); Index: lld/COFF/InputFiles.h =================================================================== --- lld/COFF/InputFiles.h +++ lld/COFF/InputFiles.h @@ -41,6 +41,7 @@ using llvm::object::coff_import_header; using llvm::object::coff_section; +class ArchiveFile; class Chunk; class Defined; class DefinedImportData; @@ -68,8 +69,8 @@ MemoryBufferRef MB; - // An archive file name if this file is created from an archive. - StringRef ParentName; + // An archive file if this file is created from an archive. + ArchiveFile *Parent = nullptr; // Returns .drectve section contents if exist. StringRef getDirectives() { return StringRef(Directives).trim(); } Index: lld/COFF/InputFiles.cpp =================================================================== --- lld/COFF/InputFiles.cpp +++ lld/COFF/InputFiles.cpp @@ -80,7 +80,7 @@ if (!Seen.insert(C.getChildOffset()).second) return; - Driver->enqueueArchiveMember(C, Sym->getName(), getName()); + Driver->enqueueArchiveMember(C, Sym->getName(), this); } std::vector getArchiveMembers(Archive *File) { @@ -435,6 +435,9 @@ } void BitcodeFile::parse() { + StringRef ParentName; + if (Parent) + ParentName = Parent->getName(); Obj = check(lto::InputFile::create(MemoryBufferRef( MB.getBuffer(), Saver.save(ParentName + MB.getBufferIdentifier())))); std::vector> Comdat(Obj->getComdatTable().size()); @@ -498,10 +501,10 @@ std::string lld::toString(const coff::InputFile *File) { if (!File) return ""; - if (File->ParentName.empty()) + if (!File->Parent) return File->getName(); - return (getBasename(File->ParentName) + "(" + getBasename(File->getName()) + + return (getBasename(File->Parent->getName()) + "(" + getBasename(File->getName()) + ")") .str(); } Index: lld/COFF/MinGW.cpp =================================================================== --- lld/COFF/MinGW.cpp +++ lld/COFF/MinGW.cpp @@ -115,12 +115,14 @@ if (!Sym->getFile()) return false; - StringRef LibName = sys::path::filename(Sym->getFile()->ParentName); + if (Sym->getFile()->Parent) { + StringRef LibName = sys::path::filename(Sym->getFile()->Parent->getName()); - // Drop the file extension. - LibName = LibName.substr(0, LibName.rfind('.')); - if (!LibName.empty()) - return !ExcludeLibs.count(LibName); + // Drop the file extension. + LibName = LibName.substr(0, LibName.rfind('.')); + if (!LibName.empty()) + return !ExcludeLibs.count(LibName); + } StringRef FileName = sys::path::filename(Sym->getFile()->getName()); return !ExcludeObjects.count(FileName); Index: lld/COFF/PDB.cpp =================================================================== --- lld/COFF/PDB.cpp +++ lld/COFF/PDB.cpp @@ -359,7 +359,7 @@ if (!ExpectedSession) { consumeError(ExpectedSession.takeError()); StringRef LocalPath = - !File->ParentName.empty() ? File->ParentName : File->getName(); + File->Parent ? File->Parent->getName() : File->getName(); SmallString<128> Path = sys::path::parent_path(LocalPath); sys::path::append( Path, sys::path::filename(TSPath, sys::path::Style::windows)); @@ -808,8 +808,8 @@ // path to the object into the PDB. If this is a plain object, we make its // path absolute. If it's an object in an archive, we make the archive path // absolute. - bool InArchive = !File->ParentName.empty(); - SmallString<128> Path = InArchive ? File->ParentName : File->getName(); + bool InArchive = File->Parent; + SmallString<128> Path = InArchive ? File->Parent->getName() : File->getName(); sys::fs::make_absolute(Path); sys::path::native(Path, sys::path::Style::windows); StringRef Name = InArchive ? File->getName() : StringRef(Path); Index: lld/test/COFF/pdb-comdat.test =================================================================== --- lld/test/COFF/pdb-comdat.test +++ lld/test/COFF/pdb-comdat.test @@ -49,8 +49,6 @@ CHECK-NEXT: module = 1, sum name = 0, offset = 208 CHECK-NEXT: 104 | S_GDATA32 [size = 24] `global` CHECK-NEXT: type = 0x0074 (int), addr = 0000:0000 -CHECK-NEXT: 168 | S_GDATA32 [size = 24] `global` -CHECK-NEXT: type = 0x0074 (int), addr = 0000:0000 CHECK: Symbols CHECK: ============================================================