Index: COFF/InputFiles.h =================================================================== --- COFF/InputFiles.h +++ COFF/InputFiles.h @@ -12,14 +12,24 @@ #include "lld/Core/LLVM.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/LLVMContext.h" #include "llvm/LTO/legacy/LTOModule.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/COFF.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/StringSaver.h" +#include +#include +#include +#include #include #include #include +#include #include namespace lld { @@ -45,8 +55,10 @@ class InputFile { public: enum Kind { ArchiveKind, ObjectKind, ImportKind, BitcodeKind }; + + virtual ~InputFile() = default; + Kind kind() const { return FileKind; } - virtual ~InputFile() {} // Returns the filename. StringRef getName() { return MB.getBufferIdentifier(); } @@ -92,7 +104,9 @@ class ArchiveFile : public InputFile { public: explicit ArchiveFile(MemoryBufferRef M); + static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; } + void parse() override; // Returns a memory buffer for a given symbol. An empty memory buffer @@ -118,7 +132,9 @@ class ObjectFile : public InputFile { public: explicit ObjectFile(MemoryBufferRef M) : InputFile(ObjectKind, M) {} + static bool classof(const InputFile *F) { return F->kind() == ObjectKind; } + void parse() override; MachineTypes getMachineType() override; std::vector &getChunks() { return Chunks; } @@ -181,7 +197,9 @@ public: explicit ImportFile(MemoryBufferRef M) : InputFile(ImportKind, M), StringAlloc(StringAllocAux) {} + static bool classof(const InputFile *F) { return F->kind() == ImportKind; } + std::vector &getSymbols() override { return SymbolBodies; } DefinedImportData *ImpSym = nullptr; @@ -201,7 +219,9 @@ class BitcodeFile : public InputFile { public: explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {} + static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } + std::vector &getSymbols() override { return SymbolBodies; } MachineTypes getMachineType() override; std::unique_ptr takeModule() { return std::move(M); } @@ -217,7 +237,7 @@ static std::mutex Mu; }; -} // namespace coff -} // namespace lld +} // end namespace coff +} // end namespace lld -#endif +#endif // LLD_COFF_INPUT_FILES_H Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -25,17 +25,23 @@ //===----------------------------------------------------------------------===// #include "Target.h" +#include "Config.h" #include "Error.h" -#include "InputFiles.h" #include "OutputSections.h" #include "Symbols.h" -#include "Thunks.h" -#include "Writer.h" - -#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/Twine.h" #include "llvm/Object/ELF.h" -#include "llvm/Support/Endian.h" +#include "llvm/Object/ELFTypes.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" +#include +#include +#include +#include +#include using namespace llvm; using namespace llvm::object; @@ -80,9 +86,11 @@ } namespace { + class X86TargetInfo final : public TargetInfo { public: X86TargetInfo(); + RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override; void writeGotPltHeader(uint8_t *Buf) const override; @@ -107,6 +115,7 @@ template class X86_64TargetInfo final : public TargetInfo { public: X86_64TargetInfo(); + RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; uint32_t getDynRel(uint32_t Type) const override; bool isTlsLocalDynamicRel(uint32_t Type) const override; @@ -135,6 +144,7 @@ class PPCTargetInfo final : public TargetInfo { public: PPCTargetInfo(); + void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; }; @@ -142,6 +152,7 @@ class PPC64TargetInfo final : public TargetInfo { public: PPC64TargetInfo(); + RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; @@ -151,6 +162,7 @@ class AArch64TargetInfo final : public TargetInfo { public: AArch64TargetInfo(); + RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; uint32_t getDynRel(uint32_t Type) const override; bool isTlsInitialExecRel(uint32_t Type) const override; @@ -170,6 +182,7 @@ class AMDGPUTargetInfo final : public TargetInfo { public: AMDGPUTargetInfo(); + void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; }; @@ -177,6 +190,7 @@ class ARMTargetInfo final : public TargetInfo { public: ARMTargetInfo(); + RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; uint32_t getDynRel(uint32_t Type) const override; uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override; @@ -195,6 +209,7 @@ template class MipsTargetInfo final : public TargetInfo { public: MipsTargetInfo(); + RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override; uint32_t getDynRel(uint32_t Type) const override; @@ -209,7 +224,8 @@ void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; bool usesOnlyLowPageBits(uint32_t Type) const override; }; -} // anonymous namespace + +} // end anonymous namespace TargetInfo *createTarget() { switch (Config->EMachine) { @@ -247,7 +263,7 @@ fatal("unknown target machine"); } -TargetInfo::~TargetInfo() {} +TargetInfo::~TargetInfo() = default; uint64_t TargetInfo::getImplicitAddend(const uint8_t *Buf, uint32_t Type) const { @@ -956,7 +972,7 @@ static uint16_t applyPPCHighest(uint64_t V) { return V >> 48; } static uint16_t applyPPCHighesta(uint64_t V) { return (V + 0x8000) >> 48; } -PPCTargetInfo::PPCTargetInfo() {} +PPCTargetInfo::PPCTargetInfo() = default; void PPCTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { @@ -2260,5 +2276,6 @@ bool MipsTargetInfo::usesOnlyLowPageBits(uint32_t Type) const { return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST; } -} -} + +} // end namespace elf +} // end namespace lld Index: lib/ReaderWriter/MachO/ArchHandler.cpp =================================================================== --- lib/ReaderWriter/MachO/ArchHandler.cpp +++ lib/ReaderWriter/MachO/ArchHandler.cpp @@ -7,14 +7,12 @@ // //===----------------------------------------------------------------------===// - #include "ArchHandler.h" #include "Atoms.h" #include "MachONormalizedFileBinaryUtils.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/ADT/Triple.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MachO.h" +#include using namespace llvm::MachO; using namespace lld::mach_o::normalized; @@ -22,12 +20,9 @@ namespace lld { namespace mach_o { +ArchHandler::ArchHandler() = default; -ArchHandler::ArchHandler() { -} - -ArchHandler::~ArchHandler() { -} +ArchHandler::~ArchHandler() = default; std::unique_ptr ArchHandler::create( MachOLinkingContext::Arch arch) { @@ -47,7 +42,6 @@ } } - bool ArchHandler::isLazyPointer(const Reference &ref) { // A lazy bind entry is needed for a lazy pointer. const StubInfo &info = stubInfo(); @@ -58,7 +52,6 @@ return (ref.kindValue() == info.lazyPointerReferenceToFinal.kind); } - ArchHandler::RelocPattern ArchHandler::relocPattern(const Relocation &reloc) { assert((reloc.type & 0xFFF0) == 0); uint16_t result = reloc.type; @@ -136,7 +129,7 @@ return read32(addr, isBig); } - int64_t ArchHandler::readS64(const uint8_t *addr, bool isBig) { +int64_t ArchHandler::readS64(const uint8_t *addr, bool isBig) { return read64(addr, isBig); } @@ -165,8 +158,5 @@ return nullptr; } -} // namespace mach_o -} // namespace lld - - - +} // end namespace mach_o +} // end namespace lld Index: lib/ReaderWriter/MachO/MachOLinkingContext.cpp =================================================================== --- lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -15,21 +15,44 @@ #include "MachOPasses.h" #include "SectCreateFile.h" #include "lld/Core/ArchiveLibraryFile.h" -#include "lld/Core/PassManager.h" +#include "lld/Core/DefinedAtom.h" +#include "lld/Core/Error.h" +#include "lld/Core/File.h" +#include "lld/Core/LLVM.h" +#include "lld/Core/Node.h" #include "lld/Core/Reader.h" +#include "lld/Core/SharedLibraryFile.h" #include "lld/Core/Writer.h" -#include "lld/Driver/Driver.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/Triple.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" #include "llvm/Config/config.h" #include "llvm/Demangle/Demangle.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/Errc.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ErrorOr.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/MachO.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" #include +#include +#include +#include +#include +#include +#include +#include +#include using lld::mach_o::ArchHandler; using lld::mach_o::MachOFile; @@ -166,7 +189,7 @@ return mach_o::normalized::sliceFromFatFile(mb, _arch, offset, size); } -MachOLinkingContext::MachOLinkingContext() {} +MachOLinkingContext::MachOLinkingContext() = default; MachOLinkingContext::~MachOLinkingContext() { // Atoms are allocated on BumpPtrAllocator's on File's. @@ -804,7 +827,6 @@ void MachOLinkingContext::addSectCreateSection( StringRef seg, StringRef sect, std::unique_ptr content) { - if (!_sectCreateFile) { auto sectCreateFile = llvm::make_unique(); _sectCreateFile = sectCreateFile.get(); Index: lib/ReaderWriter/YAML/ReaderWriterYAML.cpp =================================================================== --- lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -638,8 +638,7 @@ _absoluteAtomsRef(file->absolute()) { } - ~NormalizedFile() override { - } + ~NormalizedFile() override = default; const lld::File *denormalize(IO &io);