Index: lld/trunk/include/lld/Core/File.h =================================================================== --- lld/trunk/include/lld/Core/File.h +++ lld/trunk/include/lld/Core/File.h @@ -45,9 +45,19 @@ /// \brief Kinds of files that are supported. enum Kind { - kindObject, ///< object file (.o) - kindSharedLibrary, ///< shared library (.so) - kindArchiveLibrary ///< archive (.a) + kindErrorObject, ///< a error object file (.o) + kindNormalizedObject, ///< a normalized file (.o) + kindMachObject, ///< a MachO object file (.o) + kindELFObject, ///< a ELF object file (.o) + kindCEntryObject, ///< a file for CEntries + kindEntryObject, ///< a file for the entry + kindUndefinedSymsObject, ///< a file for undefined symbols + kindAliasSymsObject, ///< a file for alias symbols + kindStubHelperObject, ///< a file for stub helpers + kindResolverMergedObject, ///< the resolver merged file. + kindSectCreateObject, ///< a sect create object file (.o) + kindSharedLibrary, ///< shared library (.so) + kindArchiveLibrary ///< archive (.a) }; /// \brief Returns file kind. Need for dyn_cast<> on File objects. @@ -190,7 +200,7 @@ class ErrorFile : public File { public: ErrorFile(StringRef path, std::error_code ec) - : File(path, kindObject), _ec(ec) {} + : File(path, kindErrorObject), _ec(ec) {} std::error_code doParse() override { return _ec; } Index: lld/trunk/include/lld/Core/Resolver.h =================================================================== --- lld/trunk/include/lld/Core/Resolver.h +++ lld/trunk/include/lld/Core/Resolver.h @@ -83,7 +83,7 @@ class MergedFile : public SimpleFile { public: - MergedFile() : SimpleFile("") {} + MergedFile() : SimpleFile("", kindResolverMergedObject) {} void addAtoms(std::vector& atoms); }; Index: lld/trunk/include/lld/Core/Simple.h =================================================================== --- lld/trunk/include/lld/Core/Simple.h +++ lld/trunk/include/lld/Core/Simple.h @@ -29,7 +29,8 @@ class SimpleFile : public File { public: - SimpleFile(StringRef path) : File(path, kindObject) {} + SimpleFile(StringRef path, File::Kind kind) + : File(path, kind) {} void addAtom(const DefinedAtom &a) { _defined.push_back(&a); } void addAtom(const UndefinedAtom &a) { _undefined.push_back(&a); } Index: lld/trunk/lib/Core/LinkingContext.cpp =================================================================== --- lld/trunk/lib/Core/LinkingContext.cpp +++ lld/trunk/lib/Core/LinkingContext.cpp @@ -50,7 +50,8 @@ LinkingContext::createEntrySymbolFile(StringRef filename) const { if (entrySymbolName().empty()) return nullptr; - std::unique_ptr entryFile(new SimpleFile(filename)); + std::unique_ptr entryFile(new SimpleFile(filename, + File::kindEntryObject)); entryFile->addAtom( *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName()))); return std::move(entryFile); @@ -64,7 +65,8 @@ LinkingContext::createUndefinedSymbolFile(StringRef filename) const { if (_initialUndefinedSymbols.empty()) return nullptr; - std::unique_ptr undefinedSymFile(new SimpleFile(filename)); + std::unique_ptr undefinedSymFile( + new SimpleFile(filename, File::kindUndefinedSymsObject)); for (StringRef undefSym : _initialUndefinedSymbols) undefinedSymFile->addAtom(*(new (_allocator) SimpleUndefinedAtom( *undefinedSymFile, undefSym))); @@ -74,7 +76,8 @@ std::unique_ptr LinkingContext::createAliasSymbolFile() const { if (getAliases().empty()) return nullptr; - std::unique_ptr file(new SimpleFile("")); + std::unique_ptr file( + new SimpleFile("", File::kindUndefinedSymsObject)); for (const auto &i : getAliases()) { StringRef from = i.first; StringRef to = i.second; Index: lld/trunk/lib/Core/Resolver.cpp =================================================================== --- lld/trunk/lib/Core/Resolver.cpp +++ lld/trunk/lib/Core/Resolver.cpp @@ -338,7 +338,17 @@ file->beforeLink(); updatePreloadArchiveMap(); switch (file->kind()) { - case File::kindObject: { + case File::kindErrorObject: + case File::kindNormalizedObject: + case File::kindMachObject: + case File::kindELFObject: + case File::kindCEntryObject: + case File::kindEntryObject: + case File::kindUndefinedSymsObject: + case File::kindAliasSymsObject: + case File::kindStubHelperObject: + case File::kindResolverMergedObject: + case File::kindSectCreateObject: { // The same file may be visited more than once if the file is // in --start-group and --end-group. Only library files should // be processed more than once. Index: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h +++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h @@ -33,7 +33,7 @@ void AArch64DynamicLibraryWriter::createImplicitFiles( std::vector> &result) { DynamicLibraryWriter::createImplicitFiles(result); - auto gotFile = llvm::make_unique("GOTFile"); + auto gotFile = llvm::make_unique("GOTFile", File::kindELFObject); gotFile->addAtom(*new (gotFile->allocator()) GlobalOffsetTableAtom(*gotFile)); gotFile->addAtom(*new (gotFile->allocator()) DynamicAtom(*gotFile)); result.push_back(std::move(gotFile)); Index: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp +++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp @@ -22,7 +22,7 @@ void AArch64ExecutableWriter::createImplicitFiles( std::vector> &result) { ExecutableWriter::createImplicitFiles(result); - auto gotFile = llvm::make_unique("GOTFile"); + auto gotFile = llvm::make_unique("GOTFile", File::kindELFObject); gotFile->addAtom(*new (gotFile->allocator()) GlobalOffsetTableAtom(*gotFile)); if (this->_ctx.isDynamic()) gotFile->addAtom(*new (gotFile->allocator()) DynamicAtom(*gotFile)); Index: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp +++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp @@ -129,7 +129,8 @@ class ELFPassFile : public SimpleFile { public: - ELFPassFile(const ELFLinkingContext &eti) : SimpleFile("ELFPassFile") { + ELFPassFile(const ELFLinkingContext &eti) + : SimpleFile("ELFPassFile", kindELFObject) { setOrdinal(eti.getNextOrdinalAndIncrement()); } Index: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp +++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp @@ -314,7 +314,8 @@ class ELFPassFile : public SimpleFile { public: - ELFPassFile(const ELFLinkingContext &eti) : SimpleFile("ELFPassFile") { + ELFPassFile(const ELFLinkingContext &eti) + : SimpleFile("ELFPassFile", kindELFObject) { setOrdinal(eti.getNextOrdinalAndIncrement()); } Index: lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp +++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp @@ -16,14 +16,15 @@ template ELFFile::ELFFile(StringRef name, ELFLinkingContext &ctx) - : SimpleFile(name), _ordinal(0), _doStringsMerge(ctx.mergeCommonStrings()), - _useWrap(false), _ctx(ctx) { + : SimpleFile(name, kindELFObject), _ordinal(0), + _doStringsMerge(ctx.mergeCommonStrings()), _useWrap(false), _ctx(ctx) { setLastError(std::error_code()); } template ELFFile::ELFFile(std::unique_ptr mb, ELFLinkingContext &ctx) - : SimpleFile(mb->getBufferIdentifier()), _mb(std::move(mb)), _ordinal(0), + : SimpleFile(mb->getBufferIdentifier(), kindELFObject), + _mb(std::move(mb)), _ordinal(0), _doStringsMerge(ctx.mergeCommonStrings()), _useWrap(ctx.wrapCalls().size()), _ctx(ctx) {} Index: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -170,7 +170,7 @@ void ELFLinkingContext::createInternalFiles( std::vector> &files) const { std::unique_ptr file( - new SimpleFile("")); + new SimpleFile("", File::kindELFObject)); for (auto &i : getAbsoluteSymbols()) { StringRef sym = i.first; uint64_t val = i.second; @@ -191,7 +191,7 @@ if (_initialUndefinedSymbols.empty()) return nullptr; std::unique_ptr undefinedSymFile( - new SimpleFile("command line option -u")); + new SimpleFile("command line option -u", File::kindELFObject)); for (auto undefSymStr : _initialUndefinedSymbols) undefinedSymFile->addAtom(*(new (_allocator) CommandLineUndefinedAtom( *undefinedSymFile, undefSymStr))); Index: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp +++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp @@ -117,7 +117,8 @@ class ELFPassFile : public SimpleFile { public: - ELFPassFile(const ELFLinkingContext &eti) : SimpleFile("ELFPassFile") { + ELFPassFile(const ELFLinkingContext &eti) + : SimpleFile("ELFPassFile", kindELFObject) { setOrdinal(eti.getNextOrdinalAndIncrement()); } Index: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp +++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp @@ -492,7 +492,7 @@ class RelocationPassFile : public SimpleFile { public: RelocationPassFile(const ELFLinkingContext &ctx) - : SimpleFile("RelocationPassFile") { + : SimpleFile("RelocationPassFile", kindELFObject) { setOrdinal(ctx.getNextOrdinalAndIncrement()); } Index: lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h +++ lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h @@ -32,7 +32,7 @@ void X86DynamicLibraryWriter::createImplicitFiles( std::vector> &result) { DynamicLibraryWriter::createImplicitFiles(result); - auto gotFile = llvm::make_unique("GOTFile"); + auto gotFile = llvm::make_unique("GOTFile", File::kindELFObject); gotFile->addAtom(*new (gotFile->allocator()) GlobalOffsetTableAtom(*gotFile)); gotFile->addAtom(*new (gotFile->allocator()) DynamicAtom(*gotFile)); result.push_back(std::move(gotFile)); Index: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h @@ -33,7 +33,7 @@ void X86_64DynamicLibraryWriter::createImplicitFiles( std::vector> &result) { DynamicLibraryWriter::createImplicitFiles(result); - auto gotFile = llvm::make_unique("GOTFile"); + auto gotFile = llvm::make_unique("GOTFile", File::kindELFObject); gotFile->addAtom(*new (gotFile->allocator()) GlobalOffsetTableAtom(*gotFile)); gotFile->addAtom(*new (gotFile->allocator()) DynamicAtom(*gotFile)); result.push_back(std::move(gotFile)); Index: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h @@ -25,7 +25,8 @@ void createImplicitFiles(std::vector> &result) override { ExecutableWriter::createImplicitFiles(result); - auto gotFile = llvm::make_unique("GOTFile"); + auto gotFile = llvm::make_unique("GOTFile", + File::kindELFObject); gotFile->addAtom(*new (gotFile->allocator()) GlobalOffsetTableAtom(*gotFile)); if (this->_ctx.isDynamic()) Index: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp +++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp @@ -93,7 +93,8 @@ class ELFPassFile : public SimpleFile { public: - ELFPassFile(const ELFLinkingContext &eti) : SimpleFile("ELFPassFile") { + ELFPassFile(const ELFLinkingContext &eti) + : SimpleFile("ELFPassFile", kindELFObject) { setOrdinal(eti.getNextOrdinalAndIncrement()); } Index: lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h =================================================================== --- lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h +++ lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h @@ -34,7 +34,7 @@ class CEntryFile : public SimpleFile { public: CEntryFile(const MachOLinkingContext &context) - : SimpleFile("C entry"), + : SimpleFile("C entry", kindCEntryObject), _undefMain(*this, context.entrySymbolName()) { this->addAtom(_undefMain); } @@ -51,7 +51,7 @@ class StubHelperFile : public SimpleFile { public: StubHelperFile(const MachOLinkingContext &context) - : SimpleFile("stub runtime"), + : SimpleFile("stub runtime", kindStubHelperObject), _undefBinder(*this, context.binderSymbolName()) { this->addAtom(_undefBinder); } Index: lld/trunk/lib/ReaderWriter/MachO/File.h =================================================================== --- lld/trunk/lib/ReaderWriter/MachO/File.h +++ lld/trunk/lib/ReaderWriter/MachO/File.h @@ -25,9 +25,10 @@ class MachOFile : public SimpleFile { public: MachOFile(std::unique_ptr mb, MachOLinkingContext *ctx) - : SimpleFile(mb->getBufferIdentifier()), _mb(std::move(mb)), _ctx(ctx) {} + : SimpleFile(mb->getBufferIdentifier(), File::kindMachObject), + _mb(std::move(mb)), _ctx(ctx) {} - MachOFile(StringRef path) : SimpleFile(path) {} + MachOFile(StringRef path) : SimpleFile(path, File::kindMachObject) {} void addDefinedAtom(StringRef name, Atom::Scope scope, DefinedAtom::ContentType type, DefinedAtom::Merge merge, @@ -187,6 +188,11 @@ visitor(offAndAtom.atom, offAndAtom.offset); } + /// Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const File *F) { + return F->kind() == File::kindMachObject; + } + protected: std::error_code doParse() override { // Convert binary file to normalized mach-o. Index: lld/trunk/lib/ReaderWriter/MachO/SectCreateFile.h =================================================================== --- lld/trunk/lib/ReaderWriter/MachO/SectCreateFile.h +++ lld/trunk/lib/ReaderWriter/MachO/SectCreateFile.h @@ -59,7 +59,7 @@ std::unique_ptr _content; }; - SectCreateFile() : File("sectcreate", kindObject) {} + SectCreateFile() : File("sectcreate", kindSectCreateObject) {} void addSection(StringRef seg, StringRef sect, std::unique_ptr content) { Index: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp =================================================================== --- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -294,7 +294,8 @@ template <> struct ScalarEnumerationTraits { static void enumeration(IO &io, lld::File::Kind &value) { - io.enumCase(value, "object", lld::File::kindObject); + io.enumCase(value, "error-object", lld::File::kindErrorObject); + io.enumCase(value, "object", lld::File::kindMachObject); io.enumCase(value, "shared-library", lld::File::kindSharedLibrary); io.enumCase(value, "static-library", lld::File::kindArchiveLibrary); } @@ -630,9 +631,10 @@ class NormalizedFile : public lld::File { public: - NormalizedFile(IO &io) : File("", kindObject), _io(io), _rnb(nullptr) {} + NormalizedFile(IO &io) + : File("", kindNormalizedObject), _io(io), _rnb(nullptr) {} NormalizedFile(IO &io, const lld::File *file) - : File(file->path(), kindObject), _io(io), + : File(file->path(), kindNormalizedObject), _io(io), _rnb(new RefNameBuilder(*file)), _path(file->path()) { for (const lld::DefinedAtom *a : file->defined()) _definedAtoms._atoms.push_back(a);