diff options
60 files changed, 629 insertions, 749 deletions
diff --git a/lld/include/lld/Core/ArchiveLibraryFile.h b/lld/include/lld/Core/ArchiveLibraryFile.h index 2fec074fa5c..e85f7886515 100644 --- a/lld/include/lld/Core/ArchiveLibraryFile.h +++ b/lld/include/lld/Core/ArchiveLibraryFile.h @@ -33,14 +33,12 @@ public: /// specified name and return the File object for that member, or nullptr. virtual const File *find(StringRef name, bool dataSymbolOnly) const = 0; - virtual error_code parseAllMembers( - std::vector<std::unique_ptr<File>> &result) const = 0; + virtual error_code + parseAllMembers(std::vector<std::unique_ptr<File>> &result) const = 0; protected: /// only subclasses of ArchiveLibraryFile can be instantiated - ArchiveLibraryFile(StringRef path) - : File(path, kindArchiveLibrary) {} - + ArchiveLibraryFile(StringRef path) : File(path, kindArchiveLibrary) {} }; } // namespace lld diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h index 3aa7efe09d2..17eaec0fb29 100644 --- a/lld/include/lld/Core/File.h +++ b/lld/include/lld/Core/File.h @@ -234,8 +234,7 @@ public: protected: /// \brief only subclasses of MutableFile can be instantiated - MutableFile(StringRef p) - : File(p, kindObject){} + MutableFile(StringRef p) : File(p, kindObject) {} }; } // end namespace lld diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index 2c4ba44006d..d6f7bea0362 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -312,9 +312,9 @@ public: /// Return the next ordinal and Increment it. virtual uint64_t getNextOrdinalAndIncrement() const { return _nextOrdinal++; } - + /// @} - + protected: LinkingContext(); // Must be subclassed @@ -347,7 +347,7 @@ protected: mutable llvm::BumpPtrAllocator _allocator; InputElement *_currentInputElement; mutable uint64_t _nextOrdinal; - Registry _registry; + Registry _registry; private: /// Validate the subclass bits. Only called by validate. diff --git a/lld/include/lld/Core/Reference.h b/lld/include/lld/Core/Reference.h index 12fc39b0e4f..c08f8586f4b 100644 --- a/lld/include/lld/Core/Reference.h +++ b/lld/include/lld/Core/Reference.h @@ -31,52 +31,54 @@ class Atom; /// another), marking data-in-code (jump tables or ARM constants), etc. /// /// The "kind" of a reference is a tuple of <namespace, arch, value>. This -/// enable us to re-use existing relocation types definded for various +/// enable us to re-use existing relocation types definded for various /// file formats and architectures. For instance, in ELF the relocation type 10 -/// means R_X86_64_32 for x86_64, and R_386_GOTPC for i386. For PE/COFF -/// relocation 10 means IMAGE_REL_AMD64_SECTION. +/// means R_X86_64_32 for x86_64, and R_386_GOTPC for i386. For PE/COFF +/// relocation 10 means IMAGE_REL_AMD64_SECTION. /// class Reference { public: - /// Which universe defines the kindValue(). - enum class KindNamespace { - all = 0, + /// Which universe defines the kindValue(). + enum class KindNamespace { + all = 0, testing = 1, - ELF = 2, - COFF = 3, - mach_o = 4, + ELF = 2, + COFF = 3, + mach_o = 4, }; KindNamespace kindNamespace() const { return (KindNamespace)_kindNamespace; } void setKindNamespace(KindNamespace ns) { _kindNamespace = (uint8_t)ns; } - // Which architecture the kind value is for. - enum class KindArch { - all = 0, - x86_64 = 1, - x86 = 2, - ARM = 3, - PowerPC = 4, - Hexagon = 5, - Mips = 6 + // Which architecture the kind value is for. + enum class KindArch { + all = 0, + x86_64 = 1, + x86 = 2, + ARM = 3, + PowerPC = 4, + Hexagon = 5, + Mips = 6 }; - + KindArch kindArch() const { return (KindArch)_kindArch; } void setKindArch(KindArch a) { _kindArch = (uint8_t)a; } typedef uint16_t KindValue; - + KindValue kindValue() const { return _kindValue; } - - /// setKindValue() is needed because during linking, some optimizations may + + /// setKindValue() is needed because during linking, some optimizations may /// change the codegen and hence the reference kind. - void setKindValue(KindValue value) { _kindValue = value; }; + void setKindValue(KindValue value) { + _kindValue = value; + }; /// KindValues used with KindNamespace::all and KindArch::all. enum { - kindInGroup = 1, - kindLayoutAfter = 2, - kindLayoutBefore = 3 + kindInGroup = 1, + kindLayoutAfter = 2, + kindLayoutBefore = 3 }; // A value to be added to the value of a target @@ -102,8 +104,8 @@ public: protected: /// Reference is an abstract base class. Only subclasses can use constructor. - Reference(KindNamespace ns, KindArch a, KindValue value) - : _kindValue(value), _kindNamespace((uint8_t)ns), _kindArch((uint8_t)a) {} + Reference(KindNamespace ns, KindArch a, KindValue value) + : _kindValue(value), _kindNamespace((uint8_t)ns), _kindArch((uint8_t)a) {} /// The memory for Reference objects is always managed by the owning File /// object. Therefore, no one but the owning File object should call @@ -112,8 +114,8 @@ protected: virtual ~Reference() {} KindValue _kindValue; - uint8_t _kindNamespace; - uint8_t _kindArch; + uint8_t _kindNamespace; + uint8_t _kindArch; }; } // namespace lld diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h index c4f0fac372f..53bce19a12a 100644 --- a/lld/include/lld/Core/Resolver.h +++ b/lld/include/lld/Core/Resolver.h @@ -37,9 +37,8 @@ public: }; Resolver(LinkingContext &context) - : _context(context), _symbolTable(context), - _result(new MergedFile()), _haveLLVMObjs(false), - _addToFinalSection(false) {} + : _context(context), _symbolTable(context), _result(new MergedFile()), + _haveLLVMObjs(false), _addToFinalSection(false) {} virtual ~Resolver() {} @@ -84,9 +83,8 @@ private: class MergedFile : public MutableFile { public: - MergedFile() - : MutableFile("<linker-internal>") {} - + MergedFile() : MutableFile("<linker-internal>") {} + virtual const atom_collection<DefinedAtom> &defined() const { return _definedAtoms; } diff --git a/lld/include/lld/Driver/DarwinInputGraph.h b/lld/include/lld/Driver/DarwinInputGraph.h index a6859b99909..03ae1640c80 100644 --- a/lld/include/lld/Driver/DarwinInputGraph.h +++ b/lld/include/lld/Driver/DarwinInputGraph.h @@ -56,7 +56,8 @@ public: return ec; assert(parsedFiles.size() == 1); std::unique_ptr<File> f(parsedFiles[0].release()); - if (auto archive = reinterpret_cast<const ArchiveLibraryFile*>(f.get())) { + if (auto archive = + reinterpret_cast<const ArchiveLibraryFile *>(f.get())) { // FIXME: something needs to own archive File //_files.push_back(std::move(archive)); return archive->parseAllMembers(_files); diff --git a/lld/include/lld/ReaderWriter/CoreLinkingContext.h b/lld/include/lld/ReaderWriter/CoreLinkingContext.h index 6b276abe8e4..4cc7d0fb42a 100644 --- a/lld/include/lld/ReaderWriter/CoreLinkingContext.h +++ b/lld/include/lld/ReaderWriter/CoreLinkingContext.h @@ -18,19 +18,18 @@ namespace lld { - class CoreLinkingContext : public LinkingContext { public: CoreLinkingContext(); enum { - TEST_RELOC_CALL32 = 1, - TEST_RELOC_PCREL32 = 2, - TEST_RELOC_GOT_LOAD32 = 3, - TEST_RELOC_GOT_USE32 = 4, + TEST_RELOC_CALL32 = 1, + TEST_RELOC_PCREL32 = 2, + TEST_RELOC_GOT_LOAD32 = 3, + TEST_RELOC_GOT_USE32 = 4, TEST_RELOC_LEA32_WAS_GOT = 5, }; - + virtual bool validateImpl(raw_ostream &diagnostics); virtual void addPasses(PassManager &pm); diff --git a/lld/include/lld/ReaderWriter/ELFLinkingContext.h b/lld/include/lld/ReaderWriter/ELFLinkingContext.h index 49acba6a613..302854fe269 100644 --- a/lld/include/lld/ReaderWriter/ELFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/ELFLinkingContext.h @@ -39,8 +39,6 @@ public: virtual void registerRelocationNames(Registry &) = 0; }; - - class ELFLinkingContext : public LinkingContext { public: @@ -130,9 +128,7 @@ public: return static_cast<lld::elf::TargetHandler<ELFT> &>(*_targetHandler.get()); } - TargetHandlerBase *targetHandler() const { - return _targetHandler.get(); - } + TargetHandlerBase *targetHandler() const { return _targetHandler.get(); } virtual void addPasses(PassManager &pm); void setTriple(llvm::Triple trip) { _triple = trip; } diff --git a/lld/include/lld/ReaderWriter/Reader.h b/lld/include/lld/ReaderWriter/Reader.h index 841715848b0..65cf669dbfc 100644 --- a/lld/include/lld/ReaderWriter/Reader.h +++ b/lld/include/lld/ReaderWriter/Reader.h @@ -28,7 +28,6 @@ class LinkingContext; class PECOFFLinkingContext; class TargetHandlerBase; - /// \brief An abstract class for reading object files, library files, and /// executable files. /// @@ -42,7 +41,7 @@ public: /// The method is called with: /// 1) the file_magic enumeration returned by identify_magic() /// 2) the file extension (e.g. ".obj") - /// 3) the whole file content buffer if the above is not enough. + /// 3) the whole file content buffer if the above is not enough. virtual bool canParse(file_magic magic, StringRef fileExtension, const MemoryBuffer &mb) const = 0; @@ -52,36 +51,35 @@ public: /// The resulting File object may take ownership of the MemoryBuffer. virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, - std::vector<std::unique_ptr<File> > &result) const = 0; + std::vector<std::unique_ptr<File>> &result) const = 0; }; - /// A registry to hold the list of currently registered Readers and /// tables which map Reference kind values to strings. /// The linker does not directly invoke Readers. Instead, it registers /// Readers based on it configuration and command line options, then calls -/// the Registry object to parse files. +/// the Registry object to parse files. class Registry { public: Registry(); - + /// Walk the list of registered Readers and find one that can parse the /// supplied file and parse it. error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, std::vector<std::unique_ptr<File>> &result) const; - + /// Walk the list of registered kind tables to convert a Reference Kind /// name to a value. bool referenceKindFromString(StringRef inputStr, Reference::KindNamespace &ns, - Reference::KindArch &a, + Reference::KindArch &a, Reference::KindValue &value) const; - + /// Walk the list of registered kind tables to convert a Reference Kind /// value to a string. - bool referenceKindToString(Reference::KindNamespace ns, Reference::KindArch a, + bool referenceKindToString(Reference::KindNamespace ns, Reference::KindArch a, Reference::KindValue value, StringRef &) const; - - // These methods are called to dynamically add support for various file + + // These methods are called to dynamically add support for various file // formats. The methods are also implemented in the appropriate lib*.a // library, so that the code for handling a format is only linked in, if this // method is used. Any options that a Reader might need must be passed @@ -98,26 +96,29 @@ public: /// To convert between kind values and names, the registry walks the list /// of registered kind tables. Each table is a zero terminated array of - /// KindStrings elements. - struct KindStrings { Reference::KindValue value; StringRef name; }; + /// KindStrings elements. + struct KindStrings { + Reference::KindValue value; + StringRef name; + }; - /// A Reference Kind value is a tuple of <namespace, arch, value>. All + /// A Reference Kind value is a tuple of <namespace, arch, value>. All /// entries in a conversion table have the same <namespace, arch>. The /// array then contains the value/name pairs. void addKindTable(Reference::KindNamespace ns, Reference::KindArch arch, const KindStrings array[]); private: - struct KindEntry { - Reference::KindNamespace ns; - Reference::KindArch arch; - const KindStrings *array; + struct KindEntry { + Reference::KindNamespace ns; + Reference::KindArch arch; + const KindStrings *array; }; - + void add(std::unique_ptr<Reader>); - - std::vector<std::unique_ptr<Reader>> _readers; - std::vector<KindEntry> _kindEntries; + + std::vector<std::unique_ptr<Reader>> _readers; + std::vector<KindEntry> _kindEntries; }; // Utilities for building a KindString table. For instance: @@ -126,9 +127,10 @@ private: // LLD_KIND_STRING_ENTRY(R_VAX_DATA16), // LLD_KIND_STRING_END // }; -#define LLD_KIND_STRING_ENTRY(name) { name, #name } -#define LLD_KIND_STRING_END {0, ""} - +#define LLD_KIND_STRING_ENTRY(name) \ + { name, #name } +#define LLD_KIND_STRING_END \ + { 0, "" } } // end namespace lld diff --git a/lld/include/lld/ReaderWriter/Simple.h b/lld/include/lld/ReaderWriter/Simple.h index 709916ccad9..2699101958e 100644 --- a/lld/include/lld/ReaderWriter/Simple.h +++ b/lld/include/lld/ReaderWriter/Simple.h @@ -23,8 +23,7 @@ namespace lld { class SimpleFile : public MutableFile { public: - SimpleFile(StringRef path) - : MutableFile(path) {} + SimpleFile(StringRef path) : MutableFile(path) {} virtual void addAtom(const Atom &atom) { if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(&atom)) { @@ -63,10 +62,10 @@ public: } protected: - atom_collection_vector<DefinedAtom> _definedAtoms; - atom_collection_vector<UndefinedAtom> _undefinedAtoms; + atom_collection_vector<DefinedAtom> _definedAtoms; + atom_collection_vector<UndefinedAtom> _undefinedAtoms; atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms; - atom_collection_vector<AbsoluteAtom> _absoluteAtoms; + atom_collection_vector<AbsoluteAtom> _absoluteAtoms; }; class FileToMutable : public SimpleFile { @@ -86,7 +85,7 @@ public: class SimpleReference : public Reference { public: - SimpleReference(Reference::KindNamespace ns, Reference::KindArch arch, + SimpleReference(Reference::KindNamespace ns, Reference::KindArch arch, Reference::KindValue value, uint64_t off, const Atom *t, Reference::Addend a) : Reference(ns, arch, value), _target(t), _offsetInAtom(off), _addend(a) { @@ -167,8 +166,8 @@ public: it = reinterpret_cast<const void *>(index); } - void addReference(Reference::KindNamespace ns, Reference::KindArch arch, - Reference::KindValue kindValue, uint64_t off, + void addReference(Reference::KindNamespace ns, Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t off, const Atom *target, Reference::Addend a) { _references.push_back(SimpleReference(ns, arch, kindValue, off, target, a)); } diff --git a/lld/include/lld/ReaderWriter/YamlContext.h b/lld/include/lld/ReaderWriter/YamlContext.h index ef4e58229f8..fa39185f70f 100644 --- a/lld/include/lld/ReaderWriter/YamlContext.h +++ b/lld/include/lld/ReaderWriter/YamlContext.h @@ -17,14 +17,14 @@ #include <vector> namespace lld { - class File; - class LinkingContext; - namespace mach_o { - namespace normalized { - struct NormalizedFile; - } - } - +class File; +class LinkingContext; +namespace mach_o { +namespace normalized { +struct NormalizedFile; +} +} + using lld::mach_o::normalized::NormalizedFile; /// When YAML I/O is used in lld, the yaml context always holds a YamlContext @@ -32,17 +32,15 @@ using lld::mach_o::normalized::NormalizedFile; /// different context info. This struct supports all clients. struct YamlContext { YamlContext() - : _linkingContext(nullptr), _registry(nullptr), _file(nullptr), - _normalizeMachOFile(nullptr){} + : _linkingContext(nullptr), _registry(nullptr), _file(nullptr), + _normalizeMachOFile(nullptr) {} - const LinkingContext *_linkingContext; - const Registry *_registry; - File *_file; - NormalizedFile *_normalizeMachOFile; + const LinkingContext *_linkingContext; + const Registry *_registry; + File *_file; + NormalizedFile *_normalizeMachOFile; }; } // end namespace lld #endif // LLD_READER_WRITER_YAML_CONTEXT_H - - diff --git a/lld/lib/Driver/CoreDriver.cpp b/lld/lib/Driver/CoreDriver.cpp index ade7a0663a3..44b11e4d5cc 100644 --- a/lld/lib/Driver/CoreDriver.cpp +++ b/lld/lib/Driver/CoreDriver.cpp @@ -67,28 +67,25 @@ public: namespace lld { static const Registry::KindStrings coreKindStrings[] = { - { CoreLinkingContext::TEST_RELOC_CALL32, "call32" }, - { CoreLinkingContext::TEST_RELOC_PCREL32, "pcrel32" }, - { CoreLinkingContext::TEST_RELOC_GOT_LOAD32, "gotLoad32" }, - { CoreLinkingContext::TEST_RELOC_GOT_USE32, "gotUse32" }, + { CoreLinkingContext::TEST_RELOC_CALL32, "call32" }, + { CoreLinkingContext::TEST_RELOC_PCREL32, "pcrel32" }, + { CoreLinkingContext::TEST_RELOC_GOT_LOAD32, "gotLoad32" }, + { CoreLinkingContext::TEST_RELOC_GOT_USE32, "gotUse32" }, { CoreLinkingContext::TEST_RELOC_LEA32_WAS_GOT, "lea32wasGot" }, LLD_KIND_STRING_END }; - bool CoreDriver::link(int argc, const char *argv[], raw_ostream &diagnostics) { CoreLinkingContext ctx; if (!parse(argc, argv, ctx)) return false; - + // Register possible input file parsers. ctx.registry().addSupportNativeObjects(); ctx.registry().addSupportYamlFiles(); - - ctx.registry().addKindTable(Reference::KindNamespace::testing, - Reference::KindArch::all, - coreKindStrings); + ctx.registry().addKindTable(Reference::KindNamespace::testing, + Reference::KindArch::all, coreKindStrings); return Driver::link(ctx); } diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 4ac6099201f..86899dbf668 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -77,7 +77,7 @@ bool DarwinLdDriver::linkMachO(int argc, const char *argv[], return false; if (ctx.doNothing()) return true; - + // Register possible input file parsers. ctx.registry().addSupportMachOObjects(ctx.archName()); ctx.registry().addSupportArchives(ctx.logInputFiles()); diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index b5f20417112..ff9b9e89935 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -111,14 +111,14 @@ bool GnuLdDriver::linkELF(int argc, const char *argv[], return true; // Register possible input file parsers. - options->registry().addSupportELFObjects(options->mergeCommonStrings(), + options->registry().addSupportELFObjects(options->mergeCommonStrings(), options->targetHandler()); options->registry().addSupportArchives(options->logInputFiles()); options->registry().addSupportYamlFiles(); options->registry().addSupportNativeObjects(); if (options->allowLinkWithDynamicLibraries()) options->registry().addSupportELFDynamicSharedObjects( - options->useShlibUndefines()); + options->useShlibUndefines()); return link(*options, diagnostics); } diff --git a/lld/lib/Driver/GnuLdInputGraph.cpp b/lld/lib/Driver/GnuLdInputGraph.cpp index 382e8d04f18..9a5bab4331c 100644 --- a/lld/lib/Driver/GnuLdInputGraph.cpp +++ b/lld/lib/Driver/GnuLdInputGraph.cpp @@ -32,14 +32,13 @@ error_code ELFFileNode::parse(const LinkingContext &ctx, return ec; assert(parsedFiles.size() == 1); std::unique_ptr<File> f(parsedFiles[0].release()); - if (auto archive = reinterpret_cast<const ArchiveLibraryFile*>(f.get())) { + if (auto archive = reinterpret_cast<const ArchiveLibraryFile *>(f.get())) { // Have this node own the FileArchive object. _archiveFile.reset(archive); f.release(); // Add all members to _files vector return archive->parseAllMembers(_files); - } - else { + } else { // if --whole-archive is around non-archive, just use it as normal. _files.push_back(std::move(f)); return error_code::success(); diff --git a/lld/lib/Passes/LayoutPass.cpp b/lld/lib/Passes/LayoutPass.cpp index d6e5cb09239..d58fbcf3a96 100644 --- a/lld/lib/Passes/LayoutPass.cpp +++ b/lld/lib/Passes/LayoutPass.cpp @@ -70,7 +70,7 @@ static void showCycleDetectedError(AtomToAtomT &followOnNexts, do { llvm::dbgs() << " " << atomToDebugString(atom) << "\n"; for (const Reference *ref : *atom) { - llvm::dbgs() << " " << atomToDebugString(ref->target()) << "\n"; + llvm::dbgs() << " " << atomToDebugString(ref->target()) << "\n"; } atom = followOnNexts[atom]; } while (atom != start); diff --git a/lld/lib/Passes/RoundTripNativePass.cpp b/lld/lib/Passes/RoundTripNativePass.cpp index d1e4e661baf..2cba6527649 100644 --- a/lld/lib/Passes/RoundTripNativePass.cpp +++ b/lld/lib/Passes/RoundTripNativePass.cpp @@ -43,7 +43,7 @@ void RoundTripNativePass::perform(std::unique_ptr<MutableFile> &mergedFile) { error_code ec = _context.registry().parseFile(mb, _nativeFile); if (ec) { // Note: we need a way for Passes to report errors. - llvm_unreachable("native reader not registered or read error"); + llvm_unreachable("native reader not registered or read error"); } File *objFile = _nativeFile[0].get(); mergedFile.reset(new FileToMutable(_context, *objFile)); diff --git a/lld/lib/Passes/RoundTripYAMLPass.cpp b/lld/lib/Passes/RoundTripYAMLPass.cpp index 739ad7e5e10..61a7c9cdef9 100644 --- a/lld/lib/Passes/RoundTripYAMLPass.cpp +++ b/lld/lib/Passes/RoundTripYAMLPass.cpp @@ -48,7 +48,7 @@ void RoundTripYAMLPass::perform(std::unique_ptr<MutableFile> &mergedFile) { error_code ec = _context.registry().parseFile(mb, _yamlFile); if (ec) { // Note: we need a way for Passes to report errors. - llvm_unreachable("yaml reader not registered or read error"); + llvm_unreachable("yaml reader not registered or read error"); } File *objFile = _yamlFile[0].get(); mergedFile.reset(new FileToMutable(_context, *objFile)); diff --git a/lld/lib/ReaderWriter/CoreLinkingContext.cpp b/lld/lib/ReaderWriter/CoreLinkingContext.cpp index 0d4fb993445..2e4d45dea48 100644 --- a/lld/lib/ReaderWriter/CoreLinkingContext.cpp +++ b/lld/lib/ReaderWriter/CoreLinkingContext.cpp @@ -153,8 +153,7 @@ private: class TestingPassFile : public SimpleFile { public: - TestingPassFile(const LinkingContext &ctx) - : SimpleFile("Testing pass") {} + TestingPassFile(const LinkingContext &ctx) : SimpleFile("Testing pass") {} virtual void addAtom(const Atom &atom) { if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(&atom)) @@ -238,10 +237,10 @@ public: } virtual void updateReferenceToGOT(const Reference *ref, bool targetIsNowGOT) { - const_cast<Reference *>(ref)->setKindValue(targetIsNowGOT ? - CoreLinkingContext::TEST_RELOC_PCREL32 : - CoreLinkingContext::TEST_RELOC_LEA32_WAS_GOT); - } + const_cast<Reference *>(ref)->setKindValue( + targetIsNowGOT ? CoreLinkingContext::TEST_RELOC_PCREL32 + : CoreLinkingContext::TEST_RELOC_LEA32_WAS_GOT); + } virtual const DefinedAtom *makeGOTEntry(const Atom &target) { return new TestingGOTAtom(_file, target); diff --git a/lld/lib/ReaderWriter/ELF/Atoms.h b/lld/lib/ReaderWriter/ELF/Atoms.h index 8e2d1caf269..382e071335d 100644 --- a/lld/lib/ReaderWriter/ELF/Atoms.h +++ b/lld/lib/ReaderWriter/ELF/Atoms.h @@ -40,27 +40,22 @@ template <class ELFT> class ELFReference LLVM_FINAL : public Reference { typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel; typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela; public: - - ELFReference(const Elf_Rela *rela, uint64_t off, Reference::KindArch arch, - uint16_t relocType, uint32_t idx) - : Reference(Reference::KindNamespace::ELF, arch, relocType), - _target(nullptr), _targetSymbolIndex(idx), - _offsetInAtom(off), _addend(rela->r_addend) { - } - - ELFReference(const Elf_Rel *rel, uint64_t off, Reference::KindArch arch, - uint16_t relocType, uint32_t idx) - : Reference(Reference::KindNamespace::ELF, arch, relocType), - _target(nullptr), _targetSymbolIndex(idx), - _offsetInAtom(off), _addend(0) { - } + ELFReference(const Elf_Rela *rela, uint64_t off, Reference::KindArch arch, + uint16_t relocType, uint32_t idx) + : Reference(Reference::KindNamespace::ELF, arch, relocType), + _target(nullptr), _targetSymbolIndex(idx), _offsetInAtom(off), + _addend(rela->r_addend) {} + + ELFReference(const Elf_Rel *rel, uint64_t off, Reference::KindArch arch, + uint16_t relocType, uint32_t idx) + : Reference(Reference::KindNamespace::ELF, arch, relocType), + _target(nullptr), _targetSymbolIndex(idx), _offsetInAtom(off), + _addend(0) {} ELFReference(uint32_t edgeKind) - : Reference(Reference::KindNamespace::all, - Reference::KindArch::all, edgeKind), - _target(nullptr), _targetSymbolIndex(0), - _offsetInAtom(0), _addend(0) { - } + : Reference(Reference::KindNamespace::all, Reference::KindArch::all, + edgeKind), + _target(nullptr), _targetSymbolIndex(0), _offsetInAtom(0), _addend(0) {} virtual uint64_t offsetInAtom() const { return _offsetInAtom; } @@ -169,33 +164,19 @@ class ELFDefinedAtom LLVM_FINAL : public DefinedAtom { typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr; public: - ELFDefinedAtom(const ELFFile<ELFT> &file, - StringRef symbolName, - StringRef sectionName, - const Elf_Sym *symbol, - const Elf_Shdr *section, - ArrayRef<uint8_t> contentData, - unsigned int referenceStart, - unsigned int referenceEnd, - std::vector<ELFReference<ELFT>*> &referenceList) - - : _owningFile(file) - , _symbolName(symbolName) - , _sectionName(sectionName) - , _symbol(symbol) - , _section(section) - , _contentData(contentData) - , _referenceStartIndex(referenceStart) - , _referenceEndIndex(referenceEnd) - , _referenceList(referenceList) - , _targetAtomHandler(nullptr) - , _contentType(typeUnknown) - , _permissions(permUnknown) { - } + ELFDefinedAtom(const ELFFile<ELFT> &file, StringRef symbolName, + StringRef sectionName, const Elf_Sym *symbol, + const Elf_Shdr *section, ArrayRef<uint8_t> contentData, + unsigned int referenceStart, unsigned int referenceEnd, + std::vector<ELFReference<ELFT> *> &referenceList) + : _owningFile(file), _symbolName(symbolName), _sectionName(sectionName), + _symbol(symbol), _section(section), _contentData(contentData), + _referenceStartIndex(referenceStart), _referenceEndIndex(referenceEnd), + _referenceList(referenceList), _targetAtomHandler(nullptr), + _contentType(typeUnknown), _permissions(permUnknown) {} + + ~ELFDefinedAtom() {} - ~ELFDefinedAtom() { - } - virtual const ELFFile<ELFT> &file() const { return _owningFile; } @@ -219,7 +200,7 @@ public: // Treat target defined common symbols if ((_symbol->st_shndx > llvm::ELF::SHN_LOPROC && _symbol->st_shndx < llvm::ELF::SHN_HIPROC)) { - if (!_targetAtomHandler) + if (!_targetAtomHandler) _targetAtomHandler = &_owningFile.targetHandler()->targetAtomHandler(); if (_targetAtomHandler->getType(_symbol) == llvm::ELF::STT_COMMON) return (uint64_t) _symbol->st_size; @@ -255,7 +236,7 @@ public: // mergeTentative if ((_symbol->st_shndx > llvm::ELF::SHN_LOPROC && _symbol->st_shndx < llvm::ELF::SHN_HIPROC)) { - if (!_targetAtomHandler) + if (!_targetAtomHandler) _targetAtomHandler = &_owningFile.targetHandler()->targetAtomHandler(); if (_targetAtomHandler->getType(_symbol) == llvm::ELF::STT_COMMON) return mergeAsTentative; @@ -664,8 +645,8 @@ public: virtual ContentType contentType() const { if (_symbol->st_shndx >= llvm::ELF::SHN_LORESERVE && _symbol->st_shndx <= llvm::ELF::SHN_HIOS) - return _owningFile.targetHandler()->targetAtomHandler(). - contentType(nullptr, _symbol); + return _owningFile.targetHandler()->targetAtomHandler().contentType( + nullptr, _symbol); return typeZeroFill; } @@ -788,41 +769,38 @@ private: const Elf_Sym *_symbol; }; - class SimpleELFDefinedAtom : public SimpleDefinedAtom { public: - SimpleELFDefinedAtom(const File &f) : SimpleDefinedAtom(f) { } + SimpleELFDefinedAtom(const File &f) : SimpleDefinedAtom(f) {} - void addReferenceELF(Reference::KindArch arch, - uint16_t kindValue, uint64_t off, const Atom *target, - Reference::Addend addend) { - this->addReference(Reference::KindNamespace::ELF, arch, kindValue, - off, target, addend); + void addReferenceELF(Reference::KindArch arch, uint16_t kindValue, + uint64_t off, const Atom *target, + Reference::Addend addend) { + this->addReference(Reference::KindNamespace::ELF, arch, kindValue, off, + target, addend); } - + void addReferenceELF_Hexagon(uint16_t relocType, uint64_t off, const Atom *t, - Reference::Addend a) { + Reference::Addend a) { this->addReferenceELF(Reference::KindArch::Hexagon, relocType, off, t, a); } - + void addReferenceELF_x86_64(uint16_t relocType, uint64_t off, const Atom *t, Reference::Addend a) { this->addReferenceELF(Reference::KindArch::x86_64, relocType, off, t, a); } - + void addReferenceELF_PowerPC(uint16_t relocType, uint64_t off, const Atom *t, Reference::Addend a) { this->addReferenceELF(Reference::KindArch::PowerPC, relocType, off, t, a); } - + void addReferenceELF_Mips(uint16_t relocType, uint64_t off, const Atom *t, - Reference::Addend a) { + Reference::Addend a) { this->addReferenceELF(Reference::KindArch::Mips, relocType, off, t, a); } }; - - /// \brief Atom which represents an object for which a COPY relocation will be /// generated. class ObjectAtom : public SimpleELFDefinedAtom { @@ -861,8 +839,7 @@ class GOTAtom : public SimpleELFDefinedAtom { public: GOTAtom(const File &f, StringRef secName) - : SimpleELFDefinedAtom(f), _section(secName) { - } + : SimpleELFDefinedAtom(f), _section(secName) {} virtual Scope scope() const { return scopeTranslationUnit; } @@ -897,8 +874,7 @@ class PLTAtom : public SimpleELFDefinedAtom { public: PLTAtom(const File &f, StringRef secName) - : SimpleELFDefinedAtom(f), _section(secName) { - } + : SimpleELFDefinedAtom(f), _section(secName) {} virtual Scope scope() const { return scopeTranslationUnit; } @@ -1020,8 +996,7 @@ class InitFiniAtom : public SimpleELFDefinedAtom { public: InitFiniAtom(const File &f, StringRef secName) - : SimpleELFDefinedAtom(f), _section(secName) { - } + : SimpleELFDefinedAtom(f), _section(secName) {} virtual Scope scope() const { return scopeGlobal; } diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index adce4b41925..93a6a40d697 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -332,12 +332,12 @@ Layout::SectionOrder DefaultLayout<ELFT>::getSectionOrder( case DefinedAtom::typeResolver: case DefinedAtom::typeCode: return llvm::StringSwitch<Layout::SectionOrder>(name) - .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) - .StartsWith(".eh_frame", ORDER_EH_FRAME) - .StartsWith(".init", ORDER_INIT) - .StartsWith(".fini", ORDER_FINI) - .StartsWith(".hash", ORDER_HASH) - .Default(ORDER_TEXT); + .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) + .StartsWith(".eh_frame", ORDER_EH_FRAME) + .StartsWith(".init", ORDER_INIT) + .StartsWith(".fini", ORDER_FINI) + .StartsWith(".hash", ORDER_HASH) + .Default(ORDER_TEXT); case DefinedAtom::typeConstant: return ORDER_RODATA; @@ -355,8 +355,8 @@ Layout::SectionOrder DefaultLayout<ELFT>::getSectionOrder( case DefinedAtom::typeGOT: return llvm::StringSwitch<Layout::SectionOrder>(name) - .StartsWith(".got.plt", ORDER_GOT_PLT) - .Default(ORDER_GOT); + .StartsWith(".got.plt", ORDER_GOT_PLT) + .Default(ORDER_GOT); case DefinedAtom::typeStub: return ORDER_PLT; diff --git a/lld/lib/ReaderWriter/ELF/DynamicFile.h b/lld/lib/ReaderWriter/ELF/DynamicFile.h index cd0f0d5b4f1..2ba6dfdaa50 100644 --- a/lld/lib/ReaderWriter/ELF/DynamicFile.h +++ b/lld/lib/ReaderWriter/ELF/DynamicFile.h @@ -24,7 +24,7 @@ namespace lld { namespace elf { template <class ELFT> class DynamicFile LLVM_FINAL : public SharedLibraryFile { public: - static ErrorOr<std::unique_ptr<DynamicFile> > + static ErrorOr<std::unique_ptr<DynamicFile>> create(std::unique_ptr<llvm::MemoryBuffer> mb, bool useShlibUndefines) { std::unique_ptr<DynamicFile> file( new DynamicFile(mb->getBufferIdentifier())); @@ -104,8 +104,7 @@ public: } private: - DynamicFile(StringRef name) - : SharedLibraryFile(name) {} + DynamicFile(StringRef name) : SharedLibraryFile(name) {} mutable llvm::BumpPtrAllocator _alloc; std::unique_ptr<llvm::object::ELFFile<ELFT>> _objFile; diff --git a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp index f7fd148f07f..d660ca9f621 100644 --- a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -35,8 +35,8 @@ public: } }; -ELFLinkingContext::ELFLinkingContext(llvm::Triple triple, - std::unique_ptr<TargetHandlerBase> targetHandler) +ELFLinkingContext::ELFLinkingContext( + llvm::Triple triple, std::unique_ptr<TargetHandlerBase> targetHandler) : _outputELFType(elf::ET_EXEC), _triple(triple), _targetHandler(std::move(targetHandler)), _baseAddress(0), _isStaticExecutable(false), _noInhibitExec(false), diff --git a/lld/lib/ReaderWriter/ELF/File.h b/lld/lib/ReaderWriter/ELF/File.h index 619a09c011c..dbf8a6f747a 100644 --- a/lld/lib/ReaderWriter/ELF/File.h +++ b/lld/lib/ReaderWriter/ELF/File.h @@ -119,14 +119,14 @@ template <class ELFT> class ELFFile : public File { public: ELFFile(StringRef name) - : File(name, kindObject), _ordinal(0), - _doStringsMerge(false), _targetHandler(nullptr) {} + : File(name, kindObject), _ordinal(0), _doStringsMerge(false), + _targetHandler(nullptr) {} ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings, TargetHandlerBase *handler, error_code &ec) - : File(mb->getBufferIdentifier(), kindObject), - _ordinal(0), _doStringsMerge(atomizeStrings), - _targetHandler(reinterpret_cast<TargetHandler<ELFT>*>(handler)) { + : File(mb->getBufferIdentifier(), kindObject), _ordinal(0), + _doStringsMerge(atomizeStrings), + _targetHandler(reinterpret_cast<TargetHandler<ELFT> *>(handler)) { _objFile.reset(new llvm::object::ELFFile<ELFT>(mb.release(), ec)); if (ec) @@ -162,23 +162,22 @@ public: Reference::KindArch kindArch() { switch (_objFile->getHeader()->e_machine) { - case llvm::ELF::EM_X86_64: - return Reference::KindArch::x86_64; - case llvm::ELF::EM_386: - return Reference::KindArch::x86; - case llvm::ELF::EM_ARM: - return Reference::KindArch::ARM; - case llvm::ELF::EM_PPC: - return Reference::KindArch::PowerPC; - case llvm::ELF::EM_HEXAGON: - return Reference::KindArch::Hexagon; - case llvm::ELF::EM_MIPS: - return Reference::KindArch::Mips; + case llvm::ELF::EM_X86_64: + return Reference::KindArch::x86_64; + case llvm::ELF::EM_386: + return Reference::KindArch::x86; + case llvm::ELF::EM_ARM: + return Reference::KindArch::ARM; + case llvm::ELF::EM_PPC: + return Reference::KindArch::PowerPC; + case llvm::ELF::EM_HEXAGON: + return Reference::KindArch::Hexagon; + case llvm::ELF::EM_MIPS: + return Reference::KindArch::Mips; } llvm_unreachable("unsupported e_machine value"); } - /// \brief Read input sections and populate necessary data structures /// to read them later and create atoms error_code createAtomizableSections() { @@ -510,9 +509,7 @@ public: return _absoluteAtoms; } - TargetHandler<ELFT> *targetHandler() const { - return _targetHandler; - } + TargetHandler<ELFT> *targetHandler() const { return _targetHandler; } Atom *findAtom(const Elf_Sym *symbol) { return _symbolToAtomMapping.lookup(symbol); @@ -536,9 +533,9 @@ private: continue; bool isMips64EL = _objFile->isMips64EL(); uint32_t symbolIndex = rai.getSymbol(isMips64EL); - auto *ERef = new (_readerStorage) - ELFReference<ELFT>(&rai, rai.r_offset - symbol->st_value, - kindArch(), rai.getType(isMips64EL), symbolIndex); + auto *ERef = new (_readerStorage) ELFReference<ELFT>( + &rai, rai.r_offset - symbol->st_value, kindArch(), + rai.getType(isMips64EL), symbolIndex); _references.push_back(ERef); } } @@ -552,9 +549,9 @@ private: continue; bool isMips64EL = _objFile->isMips64EL(); uint32_t symbolIndex = ri.getSymbol(isMips64EL); - auto *ERef = new (_readerStorage) - ELFReference<ELFT>(&ri, ri.r_offset - symbol->st_value, - kindArch(), ri.getType(isMips64EL), symbolIndex); + auto *ERef = new (_readerStorage) ELFReference<ELFT>( + &ri, ri.r_offset - symbol->st_value, kindArch(), + ri.getType(isMips64EL), symbolIndex); // Read the addend from the section contents // TODO : We should move the way lld reads relocations totally from // ELFFile @@ -576,7 +573,7 @@ private: /// cached value of target relocation handler assert(_targetHandler); const TargetRelocationHandler<ELFT> &targetRelocationHandler = - _targetHandler->getRelocationHandler(); + _targetHandler->getRelocationHandler(); for (auto &ri : _references) { if (ri->kindNamespace() == lld::Reference::KindNamespace::ELF) { @@ -689,7 +686,8 @@ private: // not. Let the TargetHandler to make a decision if that's the case. if (isTargetSpecificAtom(nullptr, symbol)) { assert(_targetHandler); - TargetAtomHandler<ELFT> &atomHandler = _targetHandler->targetAtomHandler(); + TargetAtomHandler<ELFT> &atomHandler = + _targetHandler->targetAtomHandler(); return atomHandler.getType(symbol) == llvm::ELF::STT_COMMON; } return symbol->getType() == llvm::ELF::STT_COMMON || diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.cpp index 8ab100b4889..6fb956fcba7 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.cpp @@ -77,7 +77,8 @@ public: Atom *finiFunctionAtom = new (_allocator) SimpleUndefinedAtom(*this, name); HexagonFiniAtom *finiAtom = (new (_allocator) HexagonFiniAtom(*this, name)); - finiAtom->addReferenceELF_Hexagon(llvm::ELF::R_HEX_32, 0, finiFunctionAtom, 0); + finiAtom->addReferenceELF_Hexagon(llvm::ELF::R_HEX_32, 0, finiFunctionAtom, + 0); finiAtom->setOrdinal(_ordinal++); addAtom(*finiFunctionAtom); addAtom(*finiAtom); diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h index c97d70d0e67..85eba3595cf 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.h @@ -31,8 +31,8 @@ public: virtual error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, const lld::AtomLayout &, const Reference &) const; - - private: + +private: const HexagonTargetHandler &_targetHandler; const HexagonTargetLayout<HexagonELFType> &_targetLayout; }; diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp index cfa17b00f94..6edd214f0c5 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp @@ -108,8 +108,7 @@ public: class ELFPassFile : public SimpleFile { public: - ELFPassFile(const ELFLinkingContext &eti) - : SimpleFile("ELFPassFile") { + ELFPassFile(const ELFLinkingContext &eti) : SimpleFile("ELFPassFile") { setOrdinal(eti.getNextOrdinalAndIncrement()); } @@ -291,8 +290,8 @@ public: error_code handlePLT32(const Reference &ref) { // Turn this into a PC32 to the PLT entry. - assert(ref.kindNamespace() == Reference::KindNamespace::ELF); - assert(ref.kindArch() == Reference::KindArch::Hexagon); + assert(ref.kindNamespace() == Reference::KindNamespace::ELF); + assert(ref.kindArch() == Reference::KindArch::Hexagon); const_cast<Reference &>(ref).setKindValue(R_HEX_B22_PCREL); const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target())); return error_code::success(); @@ -307,9 +306,8 @@ void elf::HexagonLinkingContext::addPasses(PassManager &pm) { } void HexagonTargetHandler::registerRelocationNames(Registry ®istry) { - registry.addKindTable(Reference::KindNamespace::ELF, - Reference::KindArch::Hexagon, - kindStrings); + registry.addKindTable(Reference::KindNamespace::ELF, + Reference::KindArch::Hexagon, kindStrings); } const Registry::KindStrings HexagonTargetHandler::kindStrings[] = { @@ -407,4 +405,3 @@ const Registry::KindStrings HexagonTargetHandler::kindStrings[] = { LLD_KIND_STRING_ENTRY(R_HEX_TPREL_11_X), LLD_KIND_STRING_END }; - diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp index 64cce0dd879..2a3c8967ea8 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp @@ -175,20 +175,13 @@ void MipsTargetHandler::finalizeSymbolValues() { } void MipsTargetHandler::registerRelocationNames(Registry ®istry) { - registry.addKindTable(Reference::KindNamespace::ELF, - Reference::KindArch::Mips, - kindStrings); + registry.addKindTable(Reference::KindNamespace::ELF, + Reference::KindArch::Mips, kindStrings); } - const Registry::KindStrings MipsTargetHandler::kindStrings[] = { - LLD_KIND_STRING_ENTRY(R_MIPS_NONE), - LLD_KIND_STRING_ENTRY(R_MIPS_32), - LLD_KIND_STRING_ENTRY(R_MIPS_HI16), - LLD_KIND_STRING_ENTRY(R_MIPS_LO16), - LLD_KIND_STRING_ENTRY(R_MIPS_GOT16), - LLD_KIND_STRING_ENTRY(R_MIPS_CALL16), - LLD_KIND_STRING_ENTRY(R_MIPS_JALR), - LLD_KIND_STRING_END + LLD_KIND_STRING_ENTRY(R_MIPS_NONE), LLD_KIND_STRING_ENTRY(R_MIPS_32), + LLD_KIND_STRING_ENTRY(R_MIPS_HI16), LLD_KIND_STRING_ENTRY(R_MIPS_LO16), + LLD_KIND_STRING_ENTRY(R_MIPS_GOT16), LLD_KIND_STRING_ENTRY(R_MIPS_CALL16), + LLD_KIND_STRING_ENTRY(R_MIPS_JALR), LLD_KIND_STRING_END }; -
\ No newline at end of file diff --git a/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp index 7f72c8c3936..d5a94803864 100644 --- a/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.cpp @@ -67,11 +67,9 @@ PPCTargetHandler::PPCTargetHandler(PPCLinkingContext &targetInfo) : DefaultTargetHandler(targetInfo), _relocationHandler(targetInfo), _targetLayout(targetInfo) {} - void PPCTargetHandler::registerRelocationNames(Registry ®istry) { - registry.addKindTable(Reference::KindNamespace::ELF, - Reference::KindArch::PowerPC, - kindStrings); + registry.addKindTable(Reference::KindNamespace::ELF, + Reference::KindArch::PowerPC, kindStrings); } const Registry::KindStrings PPCTargetHandler::kindStrings[] = { @@ -130,6 +128,3 @@ const Registry::KindStrings PPCTargetHandler::kindStrings[] = { LLD_KIND_STRING_ENTRY(R_PPC_REL16_HA), LLD_KIND_STRING_END }; - - - diff --git a/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h index 426a76ca056..8f1de5c3349 100644 --- a/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetHandler.h @@ -35,10 +35,8 @@ public: PPCTargetHandler(PPCLinkingContext &targetInfo); virtual void registerRelocationNames(Registry ®istry); - - virtual TargetLayout<PPCELFType> &targetLayout() { - return _targetLayout; - } + + virtual TargetLayout<PPCELFType> &targetLayout() { return _targetLayout; } virtual const PPCTargetRelocationHandler &getRelocationHandler() const { return _relocationHandler; diff --git a/lld/lib/ReaderWriter/ELF/Reader.cpp b/lld/lib/ReaderWriter/ELF/Reader.cpp index 43993ca51ca..ccfd8ab80f2 100644 --- a/lld/lib/ReaderWriter/ELF/Reader.cpp +++ b/lld/lib/ReaderWriter/ELF/Reader.cpp @@ -56,8 +56,8 @@ struct DynamicFileCreateELFTraits { typedef llvm::ErrorOr<std::unique_ptr<lld::SharedLibraryFile>> result_type; template <class ELFT> - static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb, - bool useUndefines) { + static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb, + bool useUndefines) { return lld::elf::DynamicFile<ELFT>::create(std::move(mb), useUndefines); } }; @@ -67,81 +67,81 @@ struct ELFFileCreateELFTraits { template <class ELFT> static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb, - bool atomizeStrings, - TargetHandlerBase *handler, + bool atomizeStrings, TargetHandlerBase *handler, lld::error_code &ec) { - return std::unique_ptr<lld::File>( - new lld::elf::ELFFile<ELFT>(std::move(mb), atomizeStrings, handler,ec)); + return std::unique_ptr<lld::File>(new lld::elf::ELFFile<ELFT>( + std::move(mb), atomizeStrings, handler, ec)); } }; class ELFObjectReader : public Reader { public: - ELFObjectReader(bool atomizeStrings, TargetHandlerBase* handler) - : _atomizeStrings(atomizeStrings), _handler(handler) { } + ELFObjectReader(bool atomizeStrings, TargetHandlerBase *handler) + : _atomizeStrings(atomizeStrings), _handler(handler) {} - virtual bool canParse(file_magic magic, StringRef,const MemoryBuffer&) const { + virtual bool canParse(file_magic magic, StringRef, + const MemoryBuffer &) const { return (magic == llvm::sys::fs::file_magic::elf_relocatable); } - + virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const { error_code ec; std::size_t maxAlignment = - 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); + 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); std::unique_ptr<File> f(createELF<ELFFileCreateELFTraits>( - getElfArchType(&*mb), maxAlignment, std::move(mb), - _atomizeStrings, _handler, ec)); + getElfArchType(&*mb), maxAlignment, std::move(mb), _atomizeStrings, + _handler, ec)); if (ec) return ec; result.push_back(std::move(f)); return error_code::success(); } + private: - bool _atomizeStrings; + bool _atomizeStrings; TargetHandlerBase *_handler; }; - class ELFDSOReader : public Reader { public: - ELFDSOReader(bool useUndefines) : _useUndefines(useUndefines) { } + ELFDSOReader(bool useUndefines) : _useUndefines(useUndefines) {} - virtual bool canParse(file_magic magic, StringRef, const MemoryBuffer&) const{ + virtual bool canParse(file_magic magic, StringRef, + const MemoryBuffer &) const { return (magic == llvm::sys::fs::file_magic::elf_shared_object); } - + virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const { std::size_t maxAlignment = - 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); - auto f = createELF<DynamicFileCreateELFTraits>( - getElfArchType(&*mb), maxAlignment, - std::move(mb), _useUndefines); + 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); + auto f = createELF<DynamicFileCreateELFTraits>( + getElfArchType(&*mb), maxAlignment, std::move(mb), _useUndefines); if (!f) - return f; + return f; result.push_back(std::move(*f)); return error_code::success(); } + private: bool _useUndefines; }; } // anonymous - -// This dynamic registration of a handler causes support for all ELF -// architectures to be pulled into the linker. If we want to support making a +// This dynamic registration of a handler causes support for all ELF +// architectures to be pulled into the linker. If we want to support making a // linker that only supports one ELF architecture, we'd need to change this // to have a different registration method for each architecture. -void Registry::addSupportELFObjects(bool atomizeStrings, - TargetHandlerBase *handler) { +void Registry::addSupportELFObjects(bool atomizeStrings, + TargetHandlerBase *handler) { // Tell registry about the ELF object file parser. add(std::unique_ptr<Reader>(new ELFObjectReader(atomizeStrings, handler))); - + // Tell registry about the relocation name to number mapping for this arch. handler->registerRelocationNames(*this); } @@ -150,5 +150,4 @@ void Registry::addSupportELFDynamicSharedObjects(bool useShlibUndefines) { add(std::unique_ptr<Reader>(new ELFDSOReader(useShlibUndefines))); } - } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h index ae7fed26697..bcdcd909dd1 100644 --- a/lld/lib/ReaderWriter/ELF/SectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h @@ -42,7 +42,7 @@ template <class ELFT> class Section : public Chunk<ELFT> { public: Section(const ELFLinkingContext &context, StringRef name, typename Chunk<ELFT>::Kind k = Chunk<ELFT>::Kind::ELFSection) - : Chunk<ELFT>(name, k, context), _parent(nullptr), _flags(0), _entSize(0), + : Chunk<ELFT>(name, k, context), _parent(nullptr), _flags(0), _entSize(0), _type(0), _link(0), _info(0), _segmentType(SHT_NULL) {} /// \brief Modify the section contents before assigning virtual addresses @@ -961,12 +961,12 @@ public: r->r_addend = writer->addressOfAtom(rel.second->target()) + rel.second->addend(); dest += sizeof(Elf_Rela); - DEBUG_WITH_TYPE( - "ELFRelocationTable", - llvm::dbgs() << rel.second->kindValue() << " relocation at " - << rel.first->name() << "@" << r->r_offset << " to " - << rel.second->target()->name() << "@" << r->r_addend - << "\n";); + DEBUG_WITH_TYPE("ELFRelocationTable", + llvm::dbgs() << rel.second->kindValue() + << " relocation at " << rel.first->name() + << "@" << r->r_offset << " to " + << rel.second->target()->name() << "@" + << r->r_addend << "\n";); } } diff --git a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp index 3e64a7314e9..ba66416ae28 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp @@ -31,8 +31,6 @@ static int relocPC32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { return 0; } - - const Registry::KindStrings X86TargetHandler::kindStrings[] = { LLD_KIND_STRING_ENTRY(R_386_NONE), LLD_KIND_STRING_ENTRY(R_386_32), @@ -79,8 +77,7 @@ const Registry::KindStrings X86TargetHandler::kindStrings[] = { }; void X86TargetHandler::registerRelocationNames(Registry ®istry) { - registry.addKindTable(Reference::KindNamespace::ELF, - Reference::KindArch::x86, + registry.addKindTable(Reference::KindNamespace::ELF, Reference::KindArch::x86, kindStrings); } diff --git a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h index 137190d0ce5..86fbeacf8e9 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h @@ -29,9 +29,8 @@ public: virtual error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, const lld::AtomLayout &, const Reference &) const; - - static const Registry::KindStrings kindStrings[]; + static const Registry::KindStrings kindStrings[]; }; class X86TargetHandler LLVM_FINAL @@ -41,9 +40,7 @@ public: virtual void registerRelocationNames(Registry ®istry); - virtual TargetLayout<X86ELFType> &targetLayout() { - return _targetLayout; - } + virtual TargetLayout<X86ELFType> &targetLayout() { return _targetLayout; } virtual const X86TargetRelocationHandler &getRelocationHandler() const { return _relocationHandler; diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp index 056a3eabb04..69e7924c447 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp @@ -69,7 +69,7 @@ public: Atom *initFunctionAtom = new (_allocator) SimpleUndefinedAtom(*this, name); X86_64InitAtom *initAtom = (new (_allocator) X86_64InitAtom(*this, name)); - initAtom->addReferenceELF_x86_64(llvm::ELF::R_X86_64_64, 0, + initAtom->addReferenceELF_x86_64(llvm::ELF::R_X86_64_64, 0, initFunctionAtom, 0); initAtom->setOrdinal(_ordinal++); addAtom(*initFunctionAtom); @@ -80,8 +80,8 @@ public: Atom *finiFunctionAtom = new (_allocator) SimpleUndefinedAtom(*this, name); X86_64FiniAtom *finiAtom = (new (_allocator) X86_64FiniAtom(*this, name)); - finiAtom->addReferenceELF_x86_64(llvm::ELF::R_X86_64_64, 0, - finiFunctionAtom, 0); + finiAtom->addReferenceELF_x86_64(llvm::ELF::R_X86_64_64, 0, + finiFunctionAtom, 0); finiAtom->setOrdinal(_ordinal++); addAtom(*finiFunctionAtom); addAtom(*finiAtom); diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp index a8f703a2f5f..bab665c8d00 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp @@ -47,8 +47,6 @@ static void reloc32S(uint8_t *location, uint64_t P, uint64_t S, int64_t A) { // TODO: Make sure that the result sign extends to the 64bit value. } - - int64_t X86_64TargetRelocationHandler::relocAddend(const Reference &ref) const { if (ref.kindNamespace() != Reference::KindNamespace::ELF) return false; @@ -94,7 +92,7 @@ error_code X86_64TargetRelocationHandler::applyRelocation( case R_X86_64_TPOFF32: { _tlsSize = _context.getTargetHandler<X86_64ELFType>().targetLayout().getTLSSize(); - if (ref.kindValue() == R_X86_64_TPOFF32 || + if (ref.kindValue() == R_X86_64_TPOFF32 || ref.kindValue() == R_X86_64_DTPOFF32) { int32_t result = (int32_t)(targetVAddress - _tlsSize); *reinterpret_cast<llvm::support::little32_t *>(location) = result; diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp index c9b2bec8e70..a553b2dd22f 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp @@ -29,9 +29,8 @@ bool X86_64TargetHandler::createImplicitFiles( } void X86_64TargetHandler::registerRelocationNames(Registry ®istry) { - registry.addKindTable(Reference::KindNamespace::ELF, - Reference::KindArch::x86_64, - kindStrings); + registry.addKindTable(Reference::KindNamespace::ELF, + Reference::KindArch::x86_64, kindStrings); } const Registry::KindStrings X86_64TargetHandler::kindStrings[] = { @@ -76,4 +75,3 @@ const Registry::KindStrings X86_64TargetHandler::kindStrings[] = { LLD_KIND_STRING_ENTRY(LLD_R_X86_64_GOTRELINDEX), LLD_KIND_STRING_END }; - diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp index 471916d0ff8..f28cc4e7963 100644 --- a/lld/lib/ReaderWriter/FileArchive.cpp +++ b/lld/lib/ReaderWriter/FileArchive.cpp @@ -34,20 +34,19 @@ namespace { /// \brief The FileArchive class represents an Archive Library file class FileArchive : public lld::ArchiveLibraryFile { public: - - virtual ~FileArchive() { } + virtual ~FileArchive() {} /// \brief Check if any member of the archive contains an Atom with the /// specified name and return the File object for that member, or nullptr. virtual const File *find(StringRef name, bool dataSymbolOnly) const { auto member = _symbolMemberMap.find(name); - if (member == _symbolMemberMap.end()) + if (member == _symbolMemberMap.end()) return nullptr; Archive::child_iterator ci = member->second; - // Don't return a member already returned + // Don't return a member already returned const char *memberStart = ci->getBuffer().data(); - if (_membersInstantiated.count(memberStart)) + if (_membersInstantiated.count(memberStart)) return nullptr; if (dataSymbolOnly) { @@ -72,10 +71,10 @@ public: /// \brief parse each member virtual error_code - parseAllMembers(std::vector<std::unique_ptr<File>> &result) const { - for (auto mf = _archive->begin_children(), - me = _archive->end_children(); mf != me; ++mf) { - if (error_code ec=instantiateMember(mf, result)) + parseAllMembers(std::vector<std::unique_ptr<File>> &result) const { + for (auto mf = _archive->begin_children(), me = _archive->end_children(); + mf != me; ++mf) { + if (error_code ec = instantiateMember(mf, result)) return ec; } return error_code::success(); @@ -98,10 +97,11 @@ public: } protected: - error_code instantiateMember(Archive::child_iterator member, - std::vector<std::unique_ptr<File>> &result) const { + error_code + instantiateMember(Archive::child_iterator member, + std::vector<std::unique_ptr<File>> &result) const { OwningPtr<MemoryBuffer> buff; - if (error_code ec=member->getMemoryBuffer(buff, true)) + if (error_code ec = member->getMemoryBuffer(buff, true)) return ec; if (_logLoading) llvm::outs() << buff->getBufferIdentifier() << "\n"; @@ -112,10 +112,8 @@ protected: return error_code::success(); } - error_code isDataSymbol(MemoryBuffer *mb, StringRef symbol) const { - std::unique_ptr<ObjectFile> - obj(ObjectFile::createObjectFile(mb)); + std::unique_ptr<ObjectFile> obj(ObjectFile::createObjectFile(mb)); error_code ec; SymbolRef::Type symtype; uint32_t symflags; @@ -124,22 +122,26 @@ protected: StringRef symbolname; for (symbol_iterator i = ibegin; i != iend; i.increment(ec)) { - if (ec) return ec; + if (ec) + return ec; // Get symbol name - if ((ec = (i->getName(symbolname)))) return ec; + if ((ec = (i->getName(symbolname)))) + return ec; if (symbolname != symbol) - continue; + continue; // Get symbol flags - if ((ec = (i->getFlags(symflags)))) return ec; + if ((ec = (i->getFlags(symflags)))) + return ec; if (symflags <= SymbolRef::SF_Undefined) - continue; + continue; // Get Symbol Type - if ((ec = (i->getType(symtype)))) return ec; + if ((ec = (i->getType(symtype)))) + return ec; if (symtype == SymbolRef::ST_Data) { return error_code::success(); @@ -149,40 +151,34 @@ protected: } private: - typedef std::unordered_map<StringRef,Archive::child_iterator> MemberMap; - typedef std::set<const char*> InstantiatedSet; - - const Registry &_registry; - std::unique_ptr<Archive> _archive; - mutable MemberMap _symbolMemberMap; - mutable InstantiatedSet _membersInstantiated; - atom_collection_vector<DefinedAtom> _definedAtoms; - atom_collection_vector<UndefinedAtom> _undefinedAtoms; + typedef std::unordered_map<StringRef, Archive::child_iterator> MemberMap; + typedef std::set<const char *> InstantiatedSet; + + const Registry &_registry; + std::unique_ptr<Archive> _archive; + mutable MemberMap _symbolMemberMap; + mutable InstantiatedSet _membersInstantiated; + atom_collection_vector<DefinedAtom> _definedAtoms; + atom_collection_vector<UndefinedAtom> _undefinedAtoms; atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms; - atom_collection_vector<AbsoluteAtom> _absoluteAtoms; - bool _isWholeArchive; - bool _logLoading; + atom_collection_vector<AbsoluteAtom> _absoluteAtoms; + bool _isWholeArchive; + bool _logLoading; public: /// only subclasses of ArchiveLibraryFile can be instantiated - FileArchive(const Registry ®istry, - Archive* archive, - StringRef path, - bool isWholeArchive, - bool logLoading) - : ArchiveLibraryFile(path), - _registry(registry), - _archive(std::move(archive)), - _isWholeArchive(isWholeArchive), - _logLoading(logLoading) { - } + FileArchive(const Registry ®istry, Archive *archive, StringRef path, + bool isWholeArchive, bool logLoading) + : ArchiveLibraryFile(path), _registry(registry), + _archive(std::move(archive)), _isWholeArchive(isWholeArchive), + _logLoading(logLoading) {} error_code buildTableOfContents() { - DEBUG_WITH_TYPE("FileArchive", - llvm::dbgs() << "Table of contents for archive '" - << _archive->getFileName() << "':\n"); + DEBUG_WITH_TYPE("FileArchive", llvm::dbgs() + << "Table of contents for archive '" + << _archive->getFileName() << "':\n"); for (auto i = _archive->begin_symbols(), e = _archive->end_symbols(); - i != e; ++i) { + i != e; ++i) { StringRef name; error_code ec; Archive::child_iterator member; @@ -190,56 +186,55 @@ public: return ec; if ((ec = i->getMember(member))) return ec; - DEBUG_WITH_TYPE("FileArchive", - llvm::dbgs() << llvm::format("0x%08llX ", member->getBuffer().data()) - << "'" << name << "'\n"); + DEBUG_WITH_TYPE( + "FileArchive", + llvm::dbgs() << llvm::format("0x%08llX ", member->getBuffer().data()) + << "'" << name << "'\n"); _symbolMemberMap[name] = member; } - return error_code::success(); + return error_code::success(); } }; // class FileArchive - - class ArchiveReader : public Reader { public: - ArchiveReader(bool logLoading) : _logLoading(logLoading) { } - - virtual bool canParse(file_magic magic, StringRef, const MemoryBuffer&) const{ + ArchiveReader(bool logLoading) : _logLoading(logLoading) {} + + virtual bool canParse(file_magic magic, StringRef, + const MemoryBuffer &) const { return (magic == llvm::sys::fs::file_magic::archive); } - + virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®, std::vector<std::unique_ptr<File>> &result) const { // Make Archive object which will be owned by FileArchive object. error_code ec; - Archive* archive = new Archive(mb.get(), ec); + Archive *archive = new Archive(mb.get(), ec); if (ec) return ec; StringRef path = mb->getBufferIdentifier(); // Construct FileArchive object. - std::unique_ptr<FileArchive> file(new FileArchive(reg, archive, - path, false, _logLoading)); + std::unique_ptr<FileArchive> file( + new FileArchive(reg, archive, path, false, _logLoading)); ec = file->buildTableOfContents(); if (ec) return ec; - + // Transfer ownership of memory buffer to Archive object. mb.release(); - + result.push_back(std::move(file)); - return error_code::success(); + return error_code::success(); } + private: - bool _logLoading; + bool _logLoading; }; - } // anonymous namespace - void Registry::addSupportArchives(bool logLoading) { add(std::unique_ptr<Reader>(new ArchiveReader(logLoading))); } diff --git a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp index ecc89f3bc5d..144baf7a562 100644 --- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp +++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp @@ -29,9 +29,8 @@ namespace mach_o { // class CRuntimeFile : public SimpleFile { public: - CRuntimeFile(const MachOLinkingContext &context) - : SimpleFile("C runtime"), - _undefMain(*this, context.entrySymbolName()) { + CRuntimeFile(const MachOLinkingContext &context) + : SimpleFile("C runtime"), _undefMain(*this, context.entrySymbolName()) { // only main executables need _main if (context.outputFileType() == llvm::MachO::MH_EXECUTE) { this->addAtom(_undefMain); diff --git a/lld/lib/ReaderWriter/MachO/GOTPass.hpp b/lld/lib/ReaderWriter/MachO/GOTPass.hpp index af8fce71cb9..4342b3e0c04 100644 --- a/lld/lib/ReaderWriter/MachO/GOTPass.hpp +++ b/lld/lib/ReaderWriter/MachO/GOTPass.hpp @@ -29,7 +29,7 @@ public: return true; } - virtual bool isGOTAccess(const Reference&, bool& canBypassGOT) { + virtual bool isGOTAccess(const Reference &, bool &canBypassGOT) { return false; } diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 6f29a4d704e..1c916098acb 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -100,7 +100,6 @@ StringRef MachOLinkingContext::nameFromArch(Arch arch) { return "<unknown>"; } - uint32_t MachOLinkingContext::cpuTypeFromArch(Arch arch) { assert(arch != arch_unknown); for (ArchInfo *info = _s_archInfos; !info->archName.empty(); ++info) { diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h index 211f3374115..f2f6cf86184 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h @@ -259,7 +259,7 @@ writeYaml(const NormalizedFile &file, raw_ostream &out); /// Takes in-memory normalized dylib or object and parses it into lld::File -ErrorOr<std::unique_ptr<lld::File>> +ErrorOr<std::unique_ptr<lld::File>> normalizedToAtoms(const NormalizedFile &normalizedFile, StringRef path); /// Takes atoms and generates a normalized macho-o view. diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp index 8baac9a1421..5fb28024283 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp @@ -312,20 +312,17 @@ void Registry::addSupportMachOObjects(StringRef archName) { MachOLinkingContext::Arch arch = MachOLinkingContext::archFromName(archName); switch (arch) { case MachOLinkingContext::arch_x86_64: - addKindTable(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, + addKindTable(Reference::KindNamespace::mach_o, Reference::KindArch::x86_64, mach_o::KindHandler_x86_64::kindStrings); break; case MachOLinkingContext::arch_x86: - addKindTable(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, + addKindTable(Reference::KindNamespace::mach_o, Reference::KindArch::x86, mach_o::KindHandler_x86::kindStrings); break; case MachOLinkingContext::arch_armv6: case MachOLinkingContext::arch_armv7: case MachOLinkingContext::arch_armv7s: - addKindTable(Reference::KindNamespace::mach_o, - Reference::KindArch::ARM, + addKindTable(Reference::KindNamespace::mach_o, Reference::KindArch::ARM, mach_o::KindHandler_arm::kindStrings); break; default: diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index 34e3f3160c7..847018b69f5 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -436,10 +436,9 @@ void Util::appendSection(SectionInfo *si, NormalizedFile &file) { if ( ref->target() != nullptr ) targetAddress = _atomToAddress[ref->target()]; uint64_t fixupAddress = _atomToAddress[ai.atom] + offset; - _context.kindHandler().applyFixup(ref->kindNamespace(), ref->kindArch(), - ref->kindValue(), ref->addend(), - &atomContent[offset], fixupAddress, - targetAddress); + _context.kindHandler().applyFixup( + ref->kindNamespace(), ref->kindArch(), ref->kindValue(), + ref->addend(), &atomContent[offset], fixupAddress, targetAddress); } } } diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp index d49fbb3cbce..e5c4a8b188e 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp @@ -304,7 +304,7 @@ struct MappingTraits<Relocation> { template <> struct ScalarEnumerationTraits<RelocationInfoType> { static void enumeration(IO &io, RelocationInfoType &value) { - YamlContext *info = reinterpret_cast<YamlContext*>(io.getContext()); + YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); NormalizedFile *file = info->_normalizeMachOFile; assert(file != nullptr); diff --git a/lld/lib/ReaderWriter/MachO/ReferenceKinds.cpp b/lld/lib/ReaderWriter/MachO/ReferenceKinds.cpp index 8d2515089e5..0e87fb579d4 100644 --- a/lld/lib/ReaderWriter/MachO/ReferenceKinds.cpp +++ b/lld/lib/ReaderWriter/MachO/ReferenceKinds.cpp @@ -55,22 +55,21 @@ KindHandler::create(MachOLinkingContext::Arch arch) { KindHandler_x86_64::~KindHandler_x86_64() { } - const Registry::KindStrings KindHandler_x86_64::kindStrings[] = { - LLD_KIND_STRING_ENTRY(X86_64_RELOC_UNSIGNED), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_BRANCH), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED_1), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED_2), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED_4), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_GOT_LOAD), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_GOT), - LLD_KIND_STRING_ENTRY(X86_64_RELOC_TLV), - LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_GOT_LOAD_NOW_LEA), - LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_TLV_NOW_LEA), - LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_LAZY_TARGET), - LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_LAZY_IMMEDIATE), - LLD_KIND_STRING_END + LLD_KIND_STRING_ENTRY(X86_64_RELOC_UNSIGNED), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_BRANCH), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED_1), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED_2), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_SIGNED_4), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_GOT_LOAD), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_GOT), + LLD_KIND_STRING_ENTRY(X86_64_RELOC_TLV), + LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_GOT_LOAD_NOW_LEA), + LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_TLV_NOW_LEA), + LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_LAZY_TARGET), + LLD_KIND_STRING_ENTRY(LLD_X86_64_RELOC_LAZY_IMMEDIATE), + LLD_KIND_STRING_END }; bool KindHandler_x86_64::isCallSite(const Reference &ref) { @@ -89,54 +88,53 @@ bool KindHandler_x86_64::isLazyTarget(const Reference &ref) { return (ref.kindValue() == LLD_X86_64_RELOC_LAZY_TARGET); } - -void KindHandler_x86_64::applyFixup(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue kindValue, - uint64_t addend, - uint8_t *location, uint64_t fixupAddress, +void KindHandler_x86_64::applyFixup(Reference::KindNamespace ns, + Reference::KindArch arch, + Reference::KindValue kindValue, + uint64_t addend, uint8_t *location, + uint64_t fixupAddress, uint64_t targetAddress) { if (ns != Reference::KindNamespace::mach_o) return; assert(arch == Reference::KindArch::x86_64); int32_t *loc32 = reinterpret_cast<int32_t*>(location); uint64_t* loc64 = reinterpret_cast<uint64_t*>(location); - switch ( kindValue ) { - case X86_64_RELOC_BRANCH: - case X86_64_RELOC_SIGNED: - case X86_64_RELOC_GOT_LOAD: - case X86_64_RELOC_GOT: - case X86_64_RELOC_TLV: + switch (kindValue) { + case X86_64_RELOC_BRANCH: + case X86_64_RELOC_SIGNED: + case X86_64_RELOC_GOT_LOAD: + case X86_64_RELOC_GOT: + case X86_64_RELOC_TLV: *loc32 = (targetAddress - (fixupAddress+4)) + addend; break; - case X86_64_RELOC_UNSIGNED: + case X86_64_RELOC_UNSIGNED: *loc64 = targetAddress + addend; break; - case X86_64_RELOC_SIGNED_1: + case X86_64_RELOC_SIGNED_1: *loc32 = (targetAddress - (fixupAddress+5)) + addend; break; - case X86_64_RELOC_SIGNED_2: + case X86_64_RELOC_SIGNED_2: *loc32 = (targetAddress - (fixupAddress+6)) + addend; break; - case X86_64_RELOC_SIGNED_4: + case X86_64_RELOC_SIGNED_4: *loc32 = (targetAddress - (fixupAddress+8)) + addend; break; - case LLD_X86_64_RELOC_SIGNED_32: + case LLD_X86_64_RELOC_SIGNED_32: *loc32 = (targetAddress - fixupAddress) + addend; break; - case LLD_X86_64_RELOC_GOT_LOAD_NOW_LEA: - case LLD_X86_64_RELOC_TLV_NOW_LEA: + case LLD_X86_64_RELOC_GOT_LOAD_NOW_LEA: + case LLD_X86_64_RELOC_TLV_NOW_LEA: // Change MOVQ to LEA assert(location[-2] == 0x8B); location[-2] = 0x8D; *loc32 = (targetAddress - (fixupAddress+4)) + addend; break; - case LLD_X86_64_RELOC_LAZY_TARGET: - case LLD_X86_64_RELOC_LAZY_IMMEDIATE: + case LLD_X86_64_RELOC_LAZY_TARGET: + case LLD_X86_64_RELOC_LAZY_IMMEDIATE: // do nothing break; - default: - llvm_unreachable("invalid x86_64 Reference Kind"); + default: + llvm_unreachable("invalid x86_64 Reference Kind"); break; } } @@ -150,13 +148,13 @@ KindHandler_x86::~KindHandler_x86() { } const Registry::KindStrings KindHandler_x86::kindStrings[] = { - LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_BRANCH32), - LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_ABS32), - LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_FUNC_REL32), - LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_POINTER32), - LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_LAZY_TARGET), - LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_LAZY_IMMEDIATE), - LLD_KIND_STRING_END + LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_BRANCH32), + LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_ABS32), + LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_FUNC_REL32), + LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_POINTER32), + LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_LAZY_TARGET), + LLD_KIND_STRING_ENTRY(LLD_X86_RELOC_LAZY_IMMEDIATE), + LLD_KIND_STRING_END }; bool KindHandler_x86::isCallSite(const Reference &ref) { @@ -167,44 +165,41 @@ bool KindHandler_x86::isPointer(const Reference &ref) { return (ref.kindValue() == LLD_X86_RELOC_POINTER32); } - bool KindHandler_x86::isLazyImmediate(const Reference &ref) { return (ref.kindValue() == LLD_X86_RELOC_LAZY_TARGET); } - bool KindHandler_x86::isLazyTarget(const Reference &ref) { return (ref.kindValue() == LLD_X86_RELOC_LAZY_TARGET); } - -void KindHandler_x86::applyFixup(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue kindValue, +void KindHandler_x86::applyFixup(Reference::KindNamespace ns, + Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t addend, uint8_t *location, - uint64_t fixupAddress, + uint64_t fixupAddress, uint64_t targetAddress) { if (ns != Reference::KindNamespace::mach_o) return; assert(arch == Reference::KindArch::x86); int32_t *loc32 = reinterpret_cast<int32_t*>(location); switch (kindValue) { - case LLD_X86_RELOC_BRANCH32: + case LLD_X86_RELOC_BRANCH32: *loc32 = (targetAddress - (fixupAddress+4)) + addend; break; - case LLD_X86_RELOC_POINTER32: - case LLD_X86_RELOC_ABS32: + case LLD_X86_RELOC_POINTER32: + case LLD_X86_RELOC_ABS32: *loc32 = targetAddress + addend; break; - case LLD_X86_RELOC_FUNC_REL32: + case LLD_X86_RELOC_FUNC_REL32: *loc32 = targetAddress + addend; break; - case LLD_X86_RELOC_LAZY_TARGET: - case LLD_X86_RELOC_LAZY_IMMEDIATE: + case LLD_X86_RELOC_LAZY_TARGET: + case LLD_X86_RELOC_LAZY_IMMEDIATE: // do nothing break; - default: - llvm_unreachable("invalid x86 Reference Kind"); + default: + llvm_unreachable("invalid x86 Reference Kind"); break; } } @@ -218,21 +213,21 @@ KindHandler_arm::~KindHandler_arm() { } const Registry::KindStrings KindHandler_arm::kindStrings[] = { - LLD_KIND_STRING_ENTRY(ARM_RELOC_BR24), - LLD_KIND_STRING_ENTRY(ARM_THUMB_RELOC_BR22), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_ABS_LO16), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_ABS_HI16), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_REL_LO16), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_REL_HI16), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_ABS32), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_POINTER32), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_LAZY_TARGET), - LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_LAZY_IMMEDIATE), - LLD_KIND_STRING_END + LLD_KIND_STRING_ENTRY(ARM_RELOC_BR24), + LLD_KIND_STRING_ENTRY(ARM_THUMB_RELOC_BR22), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_ABS_LO16), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_ABS_HI16), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_REL_LO16), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_THUMB_REL_HI16), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_ABS32), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_POINTER32), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_LAZY_TARGET), + LLD_KIND_STRING_ENTRY(LLD_ARM_RELOC_LAZY_IMMEDIATE), + LLD_KIND_STRING_END }; bool KindHandler_arm::isCallSite(const Reference &ref) { - return (ref.kindValue() == ARM_THUMB_RELOC_BR22) || + return (ref.kindValue() == ARM_THUMB_RELOC_BR22) || (ref.kindValue() == ARM_RELOC_BR24); } @@ -240,58 +235,55 @@ bool KindHandler_arm::isPointer(const Reference &ref) { return (ref.kindValue() == LLD_ARM_RELOC_POINTER32); } - bool KindHandler_arm::isLazyImmediate(const Reference &ref) { return (ref.kindValue() == LLD_ARM_RELOC_LAZY_IMMEDIATE); } - bool KindHandler_arm::isLazyTarget(const Reference &ref) { return (ref.kindValue() == LLD_ARM_RELOC_LAZY_TARGET); } - -void KindHandler_arm::applyFixup(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue kindValue, +void KindHandler_arm::applyFixup(Reference::KindNamespace ns, + Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t addend, uint8_t *location, - uint64_t fixupAddress, + uint64_t fixupAddress, uint64_t targetAddress) { if (ns != Reference::KindNamespace::mach_o) return; assert(arch == Reference::KindArch::ARM); //int32_t *loc32 = reinterpret_cast<int32_t*>(location); - switch ( kindValue ) { - case ARM_THUMB_RELOC_BR22: + switch (kindValue) { + case ARM_THUMB_RELOC_BR22: // FIXME break; - case ARM_RELOC_BR24: + case ARM_RELOC_BR24: // FIXME break; - case LLD_ARM_RELOC_THUMB_ABS_LO16: + case LLD_ARM_RELOC_THUMB_ABS_LO16: // FIXME break; - case LLD_ARM_RELOC_THUMB_ABS_HI16: + case LLD_ARM_RELOC_THUMB_ABS_HI16: // FIXME break; - case LLD_ARM_RELOC_THUMB_REL_LO16: + case LLD_ARM_RELOC_THUMB_REL_LO16: // FIXME break; - case LLD_ARM_RELOC_THUMB_REL_HI16: + case LLD_ARM_RELOC_THUMB_REL_HI16: // FIXME break; - case LLD_ARM_RELOC_ABS32: + case LLD_ARM_RELOC_ABS32: // FIXME break; - case LLD_ARM_RELOC_POINTER32: + case LLD_ARM_RELOC_POINTER32: // FIXME break; - case LLD_ARM_RELOC_LAZY_TARGET: - case LLD_ARM_RELOC_LAZY_IMMEDIATE: + case LLD_ARM_RELOC_LAZY_TARGET: + case LLD_ARM_RELOC_LAZY_IMMEDIATE: // do nothing break; - default: - llvm_unreachable("invalid ARM Reference Kind"); + default: + llvm_unreachable("invalid ARM Reference Kind"); break; } } diff --git a/lld/lib/ReaderWriter/MachO/ReferenceKinds.h b/lld/lib/ReaderWriter/MachO/ReferenceKinds.h index 159bbc61cc7..ce1601eedf6 100644 --- a/lld/lib/ReaderWriter/MachO/ReferenceKinds.h +++ b/lld/lib/ReaderWriter/MachO/ReferenceKinds.h @@ -23,29 +23,29 @@ namespace mach_o { // Additional Reference Kind values used internally. enum { LLD_X86_64_RELOC_GOT_LOAD_NOW_LEA = 100, - LLD_X86_64_RELOC_TLV_NOW_LEA = 101, - LLD_X86_64_RELOC_LAZY_TARGET = 102, - LLD_X86_64_RELOC_LAZY_IMMEDIATE = 103, - LLD_X86_64_RELOC_SIGNED_32 = 104, + LLD_X86_64_RELOC_TLV_NOW_LEA = 101, + LLD_X86_64_RELOC_LAZY_TARGET = 102, + LLD_X86_64_RELOC_LAZY_IMMEDIATE = 103, + LLD_X86_64_RELOC_SIGNED_32 = 104, }; enum { - LLD_X86_RELOC_BRANCH32 = 100, // CALL or JMP 32-bit pc-rel - LLD_X86_RELOC_ABS32 = 101, // 32-bit absolute addr in instruction - LLD_X86_RELOC_FUNC_REL32 = 102, // 32-bit target from start of func - LLD_X86_RELOC_POINTER32 = 103, // 32-bit data pointer - LLD_X86_RELOC_LAZY_TARGET = 104, - LLD_X86_RELOC_LAZY_IMMEDIATE = 105 + LLD_X86_RELOC_BRANCH32 = 100, // CALL or JMP 32-bit pc-rel + LLD_X86_RELOC_ABS32 = 101, // 32-bit absolute addr in instruction + LLD_X86_RELOC_FUNC_REL32 = 102, // 32-bit target from start of func + LLD_X86_RELOC_POINTER32 = 103, // 32-bit data pointer + LLD_X86_RELOC_LAZY_TARGET = 104, + LLD_X86_RELOC_LAZY_IMMEDIATE = 105 }; enum { - LLD_ARM_RELOC_THUMB_ABS_LO16 = 100, // thumb movw of absolute address - LLD_ARM_RELOC_THUMB_ABS_HI16 = 101, // thumb movt of absolute address - LLD_ARM_RELOC_THUMB_REL_LO16 = 102, // thumb movw of (target - pc) - LLD_ARM_RELOC_THUMB_REL_HI16 = 103, // thumb movt of (target - pc) - LLD_ARM_RELOC_ABS32 = 104, // 32-bit constant pointer - LLD_ARM_RELOC_POINTER32 = 105, // 32-bit data pointer - LLD_ARM_RELOC_LAZY_TARGET = 106, - LLD_ARM_RELOC_LAZY_IMMEDIATE = 107, -}; + LLD_ARM_RELOC_THUMB_ABS_LO16 = 100, // thumb movw of absolute address + LLD_ARM_RELOC_THUMB_ABS_HI16 = 101, // thumb movt of absolute address + LLD_ARM_RELOC_THUMB_REL_LO16 = 102, // thumb movw of (target - pc) + LLD_ARM_RELOC_THUMB_REL_HI16 = 103, // thumb movt of (target - pc) + LLD_ARM_RELOC_ABS32 = 104, // 32-bit constant pointer + LLD_ARM_RELOC_POINTER32 = 105, // 32-bit data pointer + LLD_ARM_RELOC_LAZY_TARGET = 106, + LLD_ARM_RELOC_LAZY_IMMEDIATE = 107, +}; /// /// The KindHandler class is the abstract interface to Reference::Kind @@ -58,16 +58,14 @@ public: static std::unique_ptr<mach_o::KindHandler> create(MachOLinkingContext::Arch); virtual ~KindHandler(); - virtual bool isCallSite(const Reference&) = 0; - virtual bool isPointer(const Reference&) = 0; - virtual bool isLazyImmediate(const Reference&) = 0; - virtual bool isLazyTarget(const Reference&) = 0; - virtual void applyFixup(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue kindValue, - uint64_t addend, uint8_t *location, - uint64_t fixupAddress, - uint64_t targetAddress) = 0; + virtual bool isCallSite(const Reference &) = 0; + virtual bool isPointer(const Reference &) = 0; + virtual bool isLazyImmediate(const Reference &) = 0; + virtual bool isLazyTarget(const Reference &) = 0; + virtual void applyFixup(Reference::KindNamespace ns, Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t addend, + uint8_t *location, uint64_t fixupAddress, + uint64_t targetAddress) = 0; protected: KindHandler(); @@ -77,56 +75,48 @@ protected: class KindHandler_x86_64 : public KindHandler { public: - static const Registry::KindStrings kindStrings[]; - + virtual ~KindHandler_x86_64(); - virtual bool isCallSite(const Reference&); - virtual bool isPointer(const Reference&); - virtual bool isLazyImmediate(const Reference&); - virtual bool isLazyTarget(const Reference&); - virtual void applyFixup(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue kindValue, - uint64_t addend, uint8_t *location, - uint64_t fixupAddress, uint64_t targetAddress); + virtual bool isCallSite(const Reference &); + virtual bool isPointer(const Reference &); + virtual bool isLazyImmediate(const Reference &); + virtual bool isLazyTarget(const Reference &); + virtual void applyFixup(Reference::KindNamespace ns, Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t addend, + uint8_t *location, uint64_t fixupAddress, + uint64_t targetAddress); }; class KindHandler_x86 : public KindHandler { public: - static const Registry::KindStrings kindStrings[]; virtual ~KindHandler_x86(); - virtual bool isCallSite(const Reference&); - virtual bool isPointer(const Reference&); - virtual bool isLazyImmediate(const Reference&); - virtual bool isLazyTarget(const Reference&); - virtual void applyFixup(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue kindValue, - uint64_t addend, uint8_t *location, - uint64_t fixupAddress, uint64_t targetAddress); - + virtual bool isCallSite(const Reference &); + virtual bool isPointer(const Reference &); + virtual bool isLazyImmediate(const Reference &); + virtual bool isLazyTarget(const Reference &); + virtual void applyFixup(Reference::KindNamespace ns, Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t addend, + uint8_t *location, uint64_t fixupAddress, + uint64_t targetAddress); }; class KindHandler_arm : public KindHandler { public: - static const Registry::KindStrings kindStrings[]; virtual ~KindHandler_arm(); - virtual bool isCallSite(const Reference&); - virtual bool isPointer(const Reference&); - virtual bool isLazyImmediate(const Reference&); - virtual bool isLazyTarget(const Reference&); - virtual void applyFixup(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue kindValue, - uint64_t addend, uint8_t *location, - uint64_t fixupAddress, uint64_t targetAddress); - + virtual bool isCallSite(const Reference &); + virtual bool isPointer(const Reference &); + virtual bool isLazyImmediate(const Reference &); + virtual bool isLazyTarget(const Reference &); + virtual void applyFixup(Reference::KindNamespace ns, Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t addend, + uint8_t *location, uint64_t fixupAddress, + uint64_t targetAddress); }; diff --git a/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp b/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp index 480600a6549..31a2c2e1ce0 100644 --- a/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp +++ b/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp @@ -31,9 +31,9 @@ class X86StubAtom : public SimpleDefinedAtom { public: X86StubAtom(const File &file, const Atom &lazyPointer) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_ABS32, 2, &lazyPointer, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_ABS32, 2, + &lazyPointer, 0); } virtual ContentType contentType() const { @@ -65,12 +65,12 @@ public: X86StubHelperCommonAtom(const File &file, const Atom &cache, const Atom &binder) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_ABS32, 1, &cache, 0); - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_ABS32, 7, &binder, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_ABS32, 1, &cache, + 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_ABS32, 7, + &binder, 0); } virtual ContentType contentType() const { @@ -103,12 +103,12 @@ class X86StubHelperAtom : public SimpleDefinedAtom { public: X86StubHelperAtom(const File &file, const Atom &helperCommon) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_LAZY_IMMEDIATE, 1, this, 0); - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_BRANCH32, 6, &helperCommon, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_LAZY_IMMEDIATE, + 1, this, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_BRANCH32, 6, + &helperCommon, 0); } virtual ContentType contentType() const { @@ -140,12 +140,12 @@ class X86LazyPointerAtom : public SimpleDefinedAtom { public: X86LazyPointerAtom(const File &file, const Atom &helper, const Atom &shlib) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_POINTER32, 0, &helper, 0); - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_LAZY_TARGET, 0, &shlib, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_POINTER32, 0, + &helper, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_LAZY_TARGET, 0, + &shlib, 0); } virtual ContentType contentType() const { @@ -181,9 +181,9 @@ public: X86NonLazyPointerAtom(const File &file, const Atom &shlib) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86, - LLD_X86_RELOC_POINTER32, 0, &shlib, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86, LLD_X86_RELOC_POINTER32, 0, + &shlib, 0); } virtual ContentType contentType() const { diff --git a/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp b/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp index 6832736cd70..cd857dd5030 100644 --- a/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp +++ b/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp @@ -32,9 +32,9 @@ class X86_64StubAtom : public SimpleDefinedAtom { public: X86_64StubAtom(const File &file, const Atom &lazyPointer) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, - X86_64_RELOC_SIGNED, 2, &lazyPointer, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, X86_64_RELOC_SIGNED, 2, + &lazyPointer, 0); } virtual ContentType contentType() const { @@ -65,12 +65,12 @@ public: X86_64StubHelperCommonAtom(const File &file, const Atom &cache, const Atom &binder) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, - X86_64_RELOC_SIGNED, 3, &cache, 0); - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, - X86_64_RELOC_SIGNED, 11, &binder, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, X86_64_RELOC_SIGNED, 3, + &cache, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, X86_64_RELOC_SIGNED, 11, + &binder, 0); } virtual ContentType contentType() const { @@ -103,12 +103,12 @@ class X86_64StubHelperAtom : public SimpleDefinedAtom { public: X86_64StubHelperAtom(const File &file, const Atom &helperCommon) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, LLD_X86_64_RELOC_LAZY_IMMEDIATE, 1, this, 0); - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, - X86_64_RELOC_SIGNED, 6, &helperCommon, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, X86_64_RELOC_SIGNED, 6, + &helperCommon, 0); } virtual ContentType contentType() const { @@ -140,11 +140,11 @@ public: X86_64LazyPointerAtom(const File &file, const Atom &helper, const Atom &shlib) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, - X86_64_RELOC_UNSIGNED, 0, &helper, 0); - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, X86_64_RELOC_UNSIGNED, 0, + &helper, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, LLD_X86_64_RELOC_LAZY_TARGET, 0, &shlib, 0); } @@ -181,9 +181,9 @@ public: X86_64NonLazyPointerAtom(const File &file, const Atom &shlib) : SimpleDefinedAtom(file) { - this->addReference(Reference::KindNamespace::mach_o, - Reference::KindArch::x86_64, - X86_64_RELOC_UNSIGNED, 0, &shlib, 0); + this->addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::x86_64, X86_64_RELOC_UNSIGNED, 0, + &shlib, 0); } virtual ContentType contentType() const { diff --git a/lld/lib/ReaderWriter/MachO/StubsPass.hpp b/lld/lib/ReaderWriter/MachO/StubsPass.hpp index ae9bf066949..b3924305da3 100644 --- a/lld/lib/ReaderWriter/MachO/StubsPass.hpp +++ b/lld/lib/ReaderWriter/MachO/StubsPass.hpp @@ -149,11 +149,10 @@ private: class File : public SimpleFile { public: - File(const MachOLinkingContext &context) - : SimpleFile("MachO Stubs pass") {} + File(const MachOLinkingContext &context) : SimpleFile("MachO Stubs pass") {} }; - const MachOLinkingContext &_context; + const MachOLinkingContext &_context; mach_o::KindHandler &_kindHandler; File _file; llvm::DenseMap<const Atom*, const DefinedAtom*> _targetToStub; diff --git a/lld/lib/ReaderWriter/Native/NativeFileFormat.h b/lld/lib/ReaderWriter/Native/NativeFileFormat.h index 0f58e0ab8b1..f1e798a8be6 100644 --- a/lld/lib/ReaderWriter/Native/NativeFileFormat.h +++ b/lld/lib/ReaderWriter/Native/NativeFileFormat.h @@ -202,10 +202,10 @@ struct NativeReferenceIvarsV1 { enum { noTarget = UINT16_MAX }; - uint32_t offsetInAtom; - uint16_t kindValue; - uint8_t kindNamespace; - uint8_t kindArch; + uint32_t offsetInAtom; + uint16_t kindValue; + uint8_t kindNamespace; + uint8_t kindArch; uint16_t targetIndex; uint16_t addendIndex; }; @@ -220,9 +220,9 @@ struct NativeReferenceIvarsV2 { }; uint64_t offsetInAtom; int64_t addend; - uint16_t kindValue; - uint8_t kindNamespace; - uint8_t kindArch; + uint16_t kindValue; + uint8_t kindNamespace; + uint8_t kindArch; uint32_t targetIndex; }; diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp index d7fc44f5d16..afe0bfee835 100644 --- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp +++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp @@ -213,11 +213,10 @@ private: // class NativeReferenceV1 : public Reference { public: - NativeReferenceV1(const File& f, const NativeReferenceIvarsV1* ivarData) - : Reference((KindNamespace)ivarData->kindNamespace, - (KindArch)ivarData->kindArch, ivarData->kindValue), - _file(&f), _ivarData(ivarData) { - } + NativeReferenceV1(const File &f, const NativeReferenceIvarsV1 *ivarData) + : Reference((KindNamespace)ivarData->kindNamespace, + (KindArch)ivarData->kindArch, ivarData->kindValue), + _file(&f), _ivarData(ivarData) {} virtual uint64_t offsetInAtom() const { return _ivarData->offsetInAtom; @@ -240,11 +239,10 @@ private: // class NativeReferenceV2 : public Reference { public: - NativeReferenceV2(const File& f, const NativeReferenceIvarsV2* ivarData) - : Reference((KindNamespace)ivarData->kindNamespace, - (KindArch)ivarData->kindArch, ivarData->kindValue), - _file(&f), _ivarData(ivarData) { - } + NativeReferenceV2(const File &f, const NativeReferenceIvarsV2 *ivarData) + : Reference((KindNamespace)ivarData->kindNamespace, + (KindArch)ivarData->kindArch, ivarData->kindValue), + _file(&f), _ivarData(ivarData) {} virtual uint64_t offsetInAtom() const { return _ivarData->offsetInAtom; @@ -270,7 +268,7 @@ public: /// Instantiates a File object from a native object file. Ownership /// of the MemoryBuffer is transferred to the resulting File object. static error_code make(std::unique_ptr<MemoryBuffer> mb, - std::vector<std::unique_ptr<lld::File> > &result) { + std::vector<std::unique_ptr<lld::File>> &result) { const uint8_t *const base = reinterpret_cast<const uint8_t *>(mb->getBufferStart()); StringRef path(mb->getBufferIdentifier()); @@ -842,8 +840,7 @@ private: uint32_t elementCount; }; - - std::unique_ptr<MemoryBuffer> _buffer; + std::unique_ptr<MemoryBuffer> _buffer; const NativeFileHeader* _header; AtomArray<DefinedAtom> _definedAtoms; AtomArray<UndefinedAtom> _undefinedAtoms; @@ -860,9 +857,9 @@ private: const char* _strings; uint32_t _stringsMaxOffset; const Reference::Addend* _addends; - uint32_t _addendsMaxIndex; - const uint8_t *_contentStart; - const uint8_t *_contentEnd; + uint32_t _addendsMaxIndex; + const uint8_t *_contentStart; + const uint8_t *_contentEnd; }; inline const lld::File &NativeDefinedAtomV1::file() const { @@ -1001,19 +998,18 @@ inline void NativeReferenceV2::setAddend(Addend a) { } // end namespace native - namespace { class NativeReader : public Reader { public: - virtual bool canParse(file_magic magic, StringRef, - const MemoryBuffer& mb) const { + virtual bool canParse(file_magic magic, StringRef, + const MemoryBuffer &mb) const { const NativeFileHeader *const header = - reinterpret_cast<const NativeFileHeader *>(mb.getBufferStart()); - return (memcmp(header->magic, NATIVE_FILE_HEADER_MAGIC, - sizeof(header->magic)) == 0); + reinterpret_cast<const NativeFileHeader *>(mb.getBufferStart()); + return (memcmp(header->magic, NATIVE_FILE_HEADER_MAGIC, + sizeof(header->magic)) == 0); } - + virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const { @@ -1021,12 +1017,10 @@ public: return error_code::success(); } }; - - } void Registry::addSupportNativeObjects() { - add(std::unique_ptr<Reader>(new NativeReader())); + add(std::unique_ptr<Reader>(new NativeReader())); } } // end namespace lld diff --git a/lld/lib/ReaderWriter/PECOFF/Atoms.h b/lld/lib/ReaderWriter/PECOFF/Atoms.h index 2057dd5bb42..0748e95ac07 100644 --- a/lld/lib/ReaderWriter/PECOFF/Atoms.h +++ b/lld/lib/ReaderWriter/PECOFF/Atoms.h @@ -28,11 +28,10 @@ class COFFDefinedAtom; class COFFReference LLVM_FINAL : public Reference { public: COFFReference(const Atom *target, uint32_t offsetInAtom, uint16_t relocType, - Reference::KindNamespace ns=Reference::KindNamespace::COFF, - Reference::KindArch arch=Reference::KindArch::x86) - : Reference(ns, arch, relocType), - _target(target), _offsetInAtom(offsetInAtom) { - } + Reference::KindNamespace ns = Reference::KindNamespace::COFF, + Reference::KindArch arch = Reference::KindArch::x86) + : Reference(ns, arch, relocType), _target(target), + _offsetInAtom(offsetInAtom) {} virtual const Atom *target() const { return _target; } virtual void setTarget(const Atom *newAtom) { _target = newAtom; } @@ -343,7 +342,7 @@ private: template <typename T, typename U> void addLayoutEdge(T *a, U *b, uint32_t which) { auto ref = new COFFReference(nullptr, 0, which, Reference::KindNamespace::all, - Reference::KindArch::all); + Reference::KindArch::all); ref->setTarget(b); a->addReference(std::unique_ptr<COFFReference>(ref)); } diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp index 251812e386b..a4fc74354df 100644 --- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp @@ -235,8 +235,7 @@ uint32_t PECOFFLinkingContext::getSectionAttributes(StringRef sectionName, uint32_t clearMask = (ci == _sectionClearMask.end()) ? 0 : ci->second; return (flags | setMask) & ~clearMask; } - - + void PECOFFLinkingContext::addPasses(PassManager &pm) { pm.add(std::unique_ptr<Pass>(new pecoff::SetSubsystemPass(*this))); pm.add(std::unique_ptr<Pass>(new pecoff::EdataPass(*this))); diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index bc5c7cc8f10..e07a553124e 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -58,8 +58,8 @@ private: typedef vector<const coff_symbol *> SymbolVectorT; typedef std::map<const coff_section *, SymbolVectorT> SectionToSymbolsT; typedef std::map<const StringRef, Atom *> SymbolNameToAtomT; - typedef std::map<const coff_section *, vector<COFFDefinedFileAtom *> > - SectionToAtomsT; + typedef std::map<const coff_section *, vector<COFFDefinedFileAtom *>> + SectionToAtomsT; public: typedef const std::map<std::string, std::string> StringMap; @@ -86,7 +86,6 @@ public: StringRef getLinkerDirectives() const { return _directives; } private: - error_code readSymbolTable(vector<const coff_symbol *> &result); void createAbsoluteAtoms(const SymbolVectorT &symbols, @@ -102,10 +101,10 @@ private: error_code cacheSectionAttributes(); error_code - AtomizeDefinedSymbolsInSection(const coff_section *section, - StringMap &altNames, - vector<const coff_symbol *> &symbols, - vector<COFFDefinedFileAtom *> &atoms); + AtomizeDefinedSymbolsInSection(const coff_section *section, + StringMap &altNames, + vector<const coff_symbol *> &symbols, + vector<COFFDefinedFileAtom *> &atoms); error_code AtomizeDefinedSymbols(SectionToSymbolsT &definedSymbols, StringMap &altNames, @@ -156,8 +155,8 @@ private: // A sorted map to find an atom from a section and an offset within // the section. std::map<const coff_section *, - std::map<uint32_t, std::vector<COFFDefinedAtom *> > > - _definedAtomLocations; + std::map<uint32_t, std::vector<COFFDefinedAtom *>>> + _definedAtomLocations; mutable llvm::BumpPtrAllocator _alloc; uint64_t _ordinal; @@ -530,16 +529,15 @@ FileCOFF::AtomizeDefinedSymbolsInSection(const coff_section *section, StringMap &altNames, vector<const coff_symbol *> &symbols, vector<COFFDefinedFileAtom *> &atoms) { - // Sort symbols by position. + // Sort symbols by position. std::stable_sort( symbols.begin(), symbols.end(), // For some reason MSVC fails to allow the lambda in this context with a // "illegal use of local type in type instantiation". MSVC is clearly // wrong here. Force a conversion to function pointer to work around. - static_cast<bool(*)(const coff_symbol *, const coff_symbol *)>( - [](const coff_symbol * a, const coff_symbol * b)->bool { - return a->Value < b->Value; - })); + static_cast<bool (*)(const coff_symbol *, const coff_symbol *)>([]( + const coff_symbol * a, + const coff_symbol * b)->bool { return a->Value < b->Value; })); StringRef sectionName; if (error_code ec = _obj->getSectionName(section, sectionName)) @@ -808,7 +806,7 @@ public: virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, - std::vector<std::unique_ptr<File> > &result) const { + std::vector<std::unique_ptr<File>> &result) const { // Convert RC file to COFF ErrorOr<std::string> coffPath = convertResourceFileToCOFF(std::move(mb)); if (!coffPath) @@ -909,7 +907,7 @@ public: virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®istry, - std::vector<std::unique_ptr<File> > &result) const { + std::vector<std::unique_ptr<File>> &result) const { // Parse the memory buffer as PECOFF file. error_code ec; std::unique_ptr<FileCOFF> file( @@ -982,7 +980,8 @@ const Registry::KindStrings kindStringsI386[] = { LLD_KIND_STRING_ENTRY(IMAGE_REL_I386_SECREL), LLD_KIND_STRING_ENTRY(IMAGE_REL_I386_TOKEN), LLD_KIND_STRING_ENTRY(IMAGE_REL_I386_SECREL7), - LLD_KIND_STRING_ENTRY(IMAGE_REL_I386_REL32), LLD_KIND_STRING_END + LLD_KIND_STRING_ENTRY(IMAGE_REL_I386_REL32), + LLD_KIND_STRING_END }; const Registry::KindStrings kindStringsAMD64[] = { @@ -1002,7 +1001,8 @@ const Registry::KindStrings kindStringsAMD64[] = { LLD_KIND_STRING_ENTRY(IMAGE_REL_AMD64_TOKEN), LLD_KIND_STRING_ENTRY(IMAGE_REL_AMD64_SREL32), LLD_KIND_STRING_ENTRY(IMAGE_REL_AMD64_PAIR), - LLD_KIND_STRING_ENTRY(IMAGE_REL_AMD64_SSPAN32), LLD_KIND_STRING_END + LLD_KIND_STRING_ENTRY(IMAGE_REL_AMD64_SSPAN32), + LLD_KIND_STRING_END }; } // end namespace anonymous @@ -1020,5 +1020,4 @@ void Registry::addSupportCOFFObjects(PECOFFLinkingContext &ctx) { void Registry::addSupportWindowsResourceFiles() { add(std::unique_ptr<Reader>(new ResourceFileReader())); } - } diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp index a6ad676546a..10312c48671 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp @@ -181,7 +181,7 @@ public: // The size of the string that follows the header. uint32_t dataSize = *reinterpret_cast<const support::ulittle32_t *>( - buf + offsetof(COFF::ImportHeader, SizeOfData)); + buf + offsetof(COFF::ImportHeader, SizeOfData)); // Check if the total size is valid. if (end - buf != sizeof(COFF::ImportHeader) + dataSize) { @@ -190,14 +190,14 @@ public: } uint16_t hint = *reinterpret_cast<const support::ulittle16_t *>( - buf + offsetof(COFF::ImportHeader, OrdinalHint)); + buf + offsetof(COFF::ImportHeader, OrdinalHint)); StringRef symbolName(buf + sizeof(COFF::ImportHeader)); StringRef dllName(buf + sizeof(COFF::ImportHeader) + symbolName.size() + 1); // TypeInfo is a bitfield. The least significant 2 bits are import // type, followed by 3 bit import name type. uint16_t typeInfo = *reinterpret_cast<const support::ulittle16_t *>( - buf + offsetof(COFF::ImportHeader, TypeInfo)); + buf + offsetof(COFF::ImportHeader, TypeInfo)); int type = typeInfo & 0x3; int nameType = (typeInfo >> 2) & 0x7; @@ -301,7 +301,7 @@ public: virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, - std::vector<std::unique_ptr<File> > &result) const { + std::vector<std::unique_ptr<File>> &result) const { error_code ec; auto file = std::unique_ptr<File>(new FileImportLibrary(std::move(mb), ec)); if (ec) @@ -309,7 +309,6 @@ public: result.push_back(std::move(file)); return error_code::success(); } - }; } // end anonymous namespace diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index a1b81894208..d280be52573 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -106,7 +106,7 @@ public: : HeaderChunk(), _context(ctx) { // Minimum size of DOS stub is 64 bytes. The next block (PE header) needs to // be aligned on 8 byte boundary. - size_t size = std::max(_context.getDosStub().size(), (size_t) 64); + size_t size = std::max(_context.getDosStub().size(), (size_t)64); _size = llvm::RoundUpToAlignment(size, 8); } @@ -303,8 +303,8 @@ private: // Create the content of a relocation block. std::vector<uint8_t> - createBaseRelocBlock(uint64_t pageAddr, - const std::vector<uint16_t> &offsets) const; + createBaseRelocBlock(uint64_t pageAddr, + const std::vector<uint16_t> &offsets) const; std::vector<uint8_t> _contents; }; @@ -752,7 +752,7 @@ private: void setImageSizeOnDisk(); void setAddressOfEntryPoint(AtomChunk *text, PEHeaderChunk *peHeader); uint64_t - calcSectionSize(llvm::COFF::SectionCharacteristics sectionType) const; + calcSectionSize(llvm::COFF::SectionCharacteristics sectionType) const; uint64_t calcSizeOfInitializedData() const { return calcSectionSize(llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA); diff --git a/lld/lib/ReaderWriter/Reader.cpp b/lld/lib/ReaderWriter/Reader.cpp index 69c5c34e073..8bfe109e0da 100644 --- a/lld/lib/ReaderWriter/Reader.cpp +++ b/lld/lib/ReaderWriter/Reader.cpp @@ -25,9 +25,9 @@ void Registry::add(std::unique_ptr<Reader> reader) { _readers.push_back(std::move(reader)); } -error_code +error_code Registry::parseFile(std::unique_ptr<MemoryBuffer> &mb, - std::vector<std::unique_ptr<File>> &result) const { + std::vector<std::unique_ptr<File>> &result) const { // Get file type. StringRef content(mb->getBufferStart(), mb->getBufferSize()); llvm::sys::fs::file_magic fileType = llvm::sys::fs::identify_magic(content); @@ -39,36 +39,36 @@ Registry::parseFile(std::unique_ptr<MemoryBuffer> &mb, if (reader->canParse(fileType, extension, *mb)) return reader->parseFile(mb, *this, result); } - - // No Reader could parse this file. + + // No Reader could parse this file. return llvm::make_error_code(llvm::errc::executable_format_error); } static const Registry::KindStrings kindStrings[] = { - { Reference::kindInGroup, "in-group" }, - { Reference::kindLayoutAfter, "layout-after" }, - { Reference::kindLayoutBefore, "layout-before" }, + { Reference::kindInGroup, "in-group" }, + { Reference::kindLayoutAfter, "layout-after" }, + { Reference::kindLayoutBefore, "layout-before" }, LLD_KIND_STRING_END }; Registry::Registry() { - addKindTable(Reference::KindNamespace::all, Reference::KindArch::all, - kindStrings); + addKindTable(Reference::KindNamespace::all, Reference::KindArch::all, + kindStrings); } -void Registry::addKindTable(Reference::KindNamespace ns, +void Registry::addKindTable(Reference::KindNamespace ns, Reference::KindArch arch, const KindStrings array[]) { - KindEntry entry = {ns, arch, array}; + KindEntry entry = { ns, arch, array }; _kindEntries.push_back(entry); } -bool Registry::referenceKindFromString(StringRef inputStr, +bool Registry::referenceKindFromString(StringRef inputStr, Reference::KindNamespace &ns, - Reference::KindArch &arch, + Reference::KindArch &arch, Reference::KindValue &value) const { for (const KindEntry &entry : _kindEntries) { - for (const KindStrings *pair=entry.array; !pair->name.empty(); ++pair) { + for (const KindStrings *pair = entry.array; !pair->name.empty(); ++pair) { if (!inputStr.equals(pair->name)) continue; ns = entry.ns; @@ -80,17 +80,16 @@ bool Registry::referenceKindFromString(StringRef inputStr, return false; } - -bool Registry::referenceKindToString(Reference::KindNamespace ns, - Reference::KindArch arch, - Reference::KindValue value, +bool Registry::referenceKindToString(Reference::KindNamespace ns, + Reference::KindArch arch, + Reference::KindValue value, StringRef &str) const { for (const KindEntry &entry : _kindEntries) { if (entry.ns != ns) continue; if (entry.arch != arch) continue; - for (const KindStrings *pair=entry.array; !pair->name.empty(); ++pair) { + for (const KindStrings *pair = entry.array; !pair->name.empty(); ++pair) { if (pair->value != value) continue; str = pair->name; @@ -100,5 +99,4 @@ bool Registry::referenceKindToString(Reference::KindNamespace ns, return false; } - } // end namespace lld diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index e5356e758dc..1ec9a029d5c 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -253,8 +253,8 @@ LLVM_YAML_STRONG_TYPEDEF(bool, ShlibCanBeNull) // For yaml, we just want one string that encapsulates the tuple. struct RefKind { Reference::KindNamespace ns; - Reference::KindArch arch; - uint16_t value; + Reference::KindArch arch; + uint16_t value; }; } // namespace anon @@ -274,8 +274,8 @@ template <> struct ScalarTraits<RefKind> { YamlContext *info = reinterpret_cast<YamlContext *>(ctxt); assert(info->_registry); StringRef str; - if (info->_registry->referenceKindToString(kind.ns, kind.arch, kind.value, - str)) + if (info->_registry->referenceKindToString(kind.ns, kind.arch, kind.value, + str)) out << str; else out << (int)(kind.ns) << "-" << (int)(kind.arch) << "-" << kind.value; @@ -285,8 +285,8 @@ template <> struct ScalarTraits<RefKind> { assert(ctxt != nullptr); YamlContext *info = reinterpret_cast<YamlContext *>(ctxt); assert(info->_registry); - if (info->_registry->referenceKindFromString(scalar, kind.ns, kind.arch, - kind.value)) + if (info->_registry->referenceKindFromString(scalar, kind.ns, kind.arch, + kind.value)) return StringRef(); return StringRef("unknown reference kind"); } @@ -564,8 +564,7 @@ template <> struct MappingTraits<const lld::File *> { class NormArchiveFile : public lld::ArchiveLibraryFile { public: - NormArchiveFile(IO &io) - : ArchiveLibraryFile(""), _path() {} + NormArchiveFile(IO &io) : ArchiveLibraryFile(""), _path() {} NormArchiveFile(IO &io, const lld::File *file) : ArchiveLibraryFile(file->path()), _path(file->path()) { // If we want to support writing archives, this constructor would @@ -606,11 +605,11 @@ template <> struct MappingTraits<const lld::File *> { return nullptr; } - virtual error_code parseAllMembers( - std::vector<std::unique_ptr<File>> &result) const { + virtual error_code + parseAllMembers(std::vector<std::unique_ptr<File>> &result) const { return error_code::success(); } - + StringRef _path; std::vector<ArchMember> _members; }; @@ -717,13 +716,13 @@ template <> struct MappingTraits<const lld::Reference *> { class NormalizedReference : public lld::Reference { public: NormalizedReference(IO &io) - : lld::Reference(lld::Reference::KindNamespace::all, + : lld::Reference(lld::Reference::KindNamespace::all, lld::Reference::KindArch::all, 0), - _target(nullptr), _targetName(), _offset(0), _addend(0) {} + _target(nullptr), _targetName(), _offset(0), _addend(0) {} NormalizedReference(IO &io, const lld::Reference *ref) - : lld::Reference(ref->kindNamespace(), ref->kindArch(), - ref->kindValue()), + : lld::Reference(ref->kindNamespace(), ref->kindArch(), + ref->kindValue()), _target(nullptr), _targetName(targetName(io, ref)), _offset(ref->offsetInAtom()), _addend(ref->addend()) { _mappedKind.ns = ref->kindNamespace(); @@ -735,8 +734,7 @@ template <> struct MappingTraits<const lld::Reference *> { YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile; - NormalizedFile *f = - reinterpret_cast<NormalizedFile *>(info->_file); + NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file); if (!_targetName.empty()) _targetName = f->copyString(_targetName); DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() @@ -809,8 +807,7 @@ template <> struct MappingTraits<const lld::DefinedAtom *> { YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile; - NormalizedFile *f = - reinterpret_cast<NormalizedFile *>(info->_file); + NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file); if (!_name.empty()) _name = f->copyString(_name); if (!_refName.empty()) @@ -905,8 +902,7 @@ template <> struct MappingTraits<const lld::DefinedAtom *> { typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile; YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); - NormalizedFile *f = - reinterpret_cast<NormalizedFile *>(info->_file); + NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file); assert(f); assert(f->_rnb); if (f->_rnb->hasRefName(atom)) { @@ -959,8 +955,7 @@ template <> struct MappingTraits<const lld::UndefinedAtom *> { YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile; - NormalizedFile *f = - reinterpret_cast<NormalizedFile *>(info->_file); + NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file); if (!_name.empty()) _name = f->copyString(_name); @@ -1019,8 +1014,7 @@ template <> struct MappingTraits<const lld::SharedLibraryAtom *> { YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile; - NormalizedFile *f = - reinterpret_cast<NormalizedFile *>(info->_file); + NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file); if (!_name.empty()) _name = f->copyString(_name); if (!_loadName.empty()) @@ -1083,8 +1077,7 @@ template <> struct MappingTraits<const lld::AbsoluteAtom *> { YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile; - NormalizedFile *f = - reinterpret_cast<NormalizedFile *>(info->_file); + NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file); if (!_name.empty()) _name = f->copyString(_name); @@ -1122,8 +1115,7 @@ template <> struct MappingTraits<const lld::AbsoluteAtom *> { typedef MappingTraits<const lld::File *>::NormalizedFile NormalizedFile; YamlContext *info = reinterpret_cast<YamlContext *>(io.getContext()); assert(info != nullptr); - NormalizedFile *f = - reinterpret_cast<NormalizedFile *>(info->_file); + NormalizedFile *f = reinterpret_cast<NormalizedFile *>(info->_file); assert(f); assert(f->_rnb); if (f->_rnb->hasRefName(atom)) { @@ -1249,12 +1241,12 @@ namespace { class YAMLReader : public Reader { public: - YAMLReader(const Registry ®istry) : _registry(registry) { } + YAMLReader(const Registry ®istry) : _registry(registry) {} - virtual bool canParse(file_magic, StringRef ext, const MemoryBuffer&) const { + virtual bool canParse(file_magic, StringRef ext, const MemoryBuffer &) const { return (ext.equals(".objtxt") || ext.equals(".yaml")); } - + virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, std::vector<std::unique_ptr<File>> &result) const { @@ -1285,10 +1277,10 @@ public: } return make_error_code(lld::YamlReaderError::success); } + private: const Registry &_registry; -}; - +}; } // anonymous namespace @@ -1296,7 +1288,6 @@ void Registry::addSupportYamlFiles() { add(std::unique_ptr<Reader>(new YAMLReader(*this))); } - std::unique_ptr<Writer> createWriterYAML(const LinkingContext &context) { return std::unique_ptr<Writer>(new lld::yaml::Writer(context)); } diff --git a/lld/unittests/DriverTests/InputGraphTest.cpp b/lld/unittests/DriverTests/InputGraphTest.cpp index d03684310e4..81bf06b9720 100644 --- a/lld/unittests/DriverTests/InputGraphTest.cpp +++ b/lld/unittests/DriverTests/InputGraphTest.cpp @@ -116,8 +116,7 @@ private: class MyObjFile : public SimpleFile { public: - MyObjFile(LinkingContext &context, StringRef path) - : SimpleFile(path) {} + MyObjFile(LinkingContext &context, StringRef path) : SimpleFile(path) {} }; class InputGraphTest : public testing::Test { |

