Index: include/lld/Core/File.h =================================================================== --- include/lld/Core/File.h +++ include/lld/Core/File.h @@ -45,7 +45,8 @@ /// \brief Kinds of files that are supported. enum Kind { - kindObject, ///< object file (.o) + kindUnknownObject, ///< object file (.o) + kindMachObject, ///< MachO object file (.o) kindSharedLibrary, ///< shared library (.so) kindArchiveLibrary ///< archive (.a) }; @@ -190,7 +191,7 @@ class ErrorFile : public File { public: ErrorFile(StringRef path, std::error_code ec) - : File(path, kindObject), _ec(ec) {} + : File(path, kindUnknownObject), _ec(ec) {} std::error_code doParse() override { return _ec; } Index: include/lld/Core/Simple.h =================================================================== --- include/lld/Core/Simple.h +++ 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::kindUnknownObject) + : File(path, kind) {} void addAtom(const DefinedAtom &a) { _defined.push_back(&a); } void addAtom(const UndefinedAtom &a) { _undefined.push_back(&a); } Index: lib/Core/Resolver.cpp =================================================================== --- lib/Core/Resolver.cpp +++ lib/Core/Resolver.cpp @@ -339,7 +339,8 @@ file->beforeLink(); updatePreloadArchiveMap(); switch (file->kind()) { - case File::kindObject: { + case File::kindUnknownObject: + case File::kindMachObject: { // 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: lib/ReaderWriter/MachO/File.h =================================================================== --- lib/ReaderWriter/MachO/File.h +++ 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, @@ -193,6 +194,11 @@ MachOLinkingContext::OS OS() const { return _os; } void setOS(MachOLinkingContext::OS os) { _os = os; } + /// 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: lib/ReaderWriter/MachO/SectCreateFile.h =================================================================== --- lib/ReaderWriter/MachO/SectCreateFile.h +++ lib/ReaderWriter/MachO/SectCreateFile.h @@ -59,7 +59,7 @@ std::unique_ptr _content; }; - SectCreateFile() : File("sectcreate", kindObject) {} + SectCreateFile() : File("sectcreate", kindUnknownObject) {} void addSection(StringRef seg, StringRef sect, std::unique_ptr content) { Index: lib/ReaderWriter/YAML/ReaderWriterYAML.cpp =================================================================== --- lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ 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, "object", lld::File::kindUnknownObject); + 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("", kindUnknownObject), _io(io), _rnb(nullptr) {} NormalizedFile(IO &io, const lld::File *file) - : File(file->path(), kindObject), _io(io), + : File(file->path(), kindUnknownObject), _io(io), _rnb(new RefNameBuilder(*file)), _path(file->path()) { for (const lld::DefinedAtom *a : file->defined()) _definedAtoms._atoms.push_back(a);