diff options
37 files changed, 272 insertions, 297 deletions
diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h index 12ba52a38f3..14228ac0f36 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h @@ -19,7 +19,7 @@ namespace elf { template <class ELFT> class AArch64DynamicLibraryWriter : public DynamicLibraryWriter<ELFT> { public: - AArch64DynamicLibraryWriter(AArch64LinkingContext &context, + AArch64DynamicLibraryWriter(AArch64LinkingContext &ctx, AArch64TargetLayout<ELFT> &layout); protected: @@ -42,16 +42,15 @@ private: }; std::unique_ptr<GOTFile> _gotFile; - AArch64LinkingContext &_context; + AArch64LinkingContext &_ctx; AArch64TargetLayout<ELFT> &_AArch64Layout; }; template <class ELFT> AArch64DynamicLibraryWriter<ELFT>::AArch64DynamicLibraryWriter( - AArch64LinkingContext &context, AArch64TargetLayout<ELFT> &layout) - : DynamicLibraryWriter<ELFT>(context, layout), - _gotFile(new GOTFile(context)), _context(context), - _AArch64Layout(layout) {} + AArch64LinkingContext &ctx, AArch64TargetLayout<ELFT> &layout) + : DynamicLibraryWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)), + _ctx(ctx), _AArch64Layout(layout) {} template <class ELFT> bool AArch64DynamicLibraryWriter<ELFT>::createImplicitFiles( diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h index 73963f56ef7..5db1a39acee 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h @@ -18,7 +18,7 @@ namespace elf { template <class ELFT> class AArch64ExecutableWriter : public ExecutableWriter<ELFT> { public: - AArch64ExecutableWriter(AArch64LinkingContext &context, + AArch64ExecutableWriter(AArch64LinkingContext &ctx, AArch64TargetLayout<ELFT> &layout); protected: @@ -41,22 +41,22 @@ private: }; std::unique_ptr<GOTFile> _gotFile; - AArch64LinkingContext &_context; + AArch64LinkingContext &_ctx; AArch64TargetLayout<ELFT> &_AArch64Layout; }; template <class ELFT> AArch64ExecutableWriter<ELFT>::AArch64ExecutableWriter( - AArch64LinkingContext &context, AArch64TargetLayout<ELFT> &layout) - : ExecutableWriter<ELFT>(context, layout), _gotFile(new GOTFile(context)), - _context(context), _AArch64Layout(layout) {} + AArch64LinkingContext &ctx, AArch64TargetLayout<ELFT> &layout) + : ExecutableWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)), + _ctx(ctx), _AArch64Layout(layout) {} template <class ELFT> bool AArch64ExecutableWriter<ELFT>::createImplicitFiles( std::vector<std::unique_ptr<File>> &result) { ExecutableWriter<ELFT>::createImplicitFiles(result); _gotFile->addAtom(*new (_gotFile->_alloc) GLOBAL_OFFSET_TABLEAtom(*_gotFile)); - if (_context.isDynamic()) + if (_ctx.isDynamic()) _gotFile->addAtom(*new (_gotFile->_alloc) DYNAMICAtom(*_gotFile)); result.push_back(std::move(_gotFile)); return true; diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp b/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp index 81566a11f07..a68a1f3ca41 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp @@ -16,9 +16,9 @@ using namespace lld; using namespace elf; -AArch64TargetHandler::AArch64TargetHandler(AArch64LinkingContext &context) - : _context(context), - _AArch64TargetLayout(new AArch64TargetLayout<AArch64ELFType>(context)), +AArch64TargetHandler::AArch64TargetHandler(AArch64LinkingContext &ctx) + : _ctx(ctx), + _AArch64TargetLayout(new AArch64TargetLayout<AArch64ELFType>(ctx)), _AArch64RelocationHandler(new AArch64TargetRelocationHandler()) {} void AArch64TargetHandler::registerRelocationNames(Registry ®istry) { @@ -27,13 +27,13 @@ void AArch64TargetHandler::registerRelocationNames(Registry ®istry) { } std::unique_ptr<Writer> AArch64TargetHandler::getWriter() { - switch (this->_context.getOutputELFType()) { + switch (this->_ctx.getOutputELFType()) { case llvm::ELF::ET_EXEC: return llvm::make_unique<AArch64ExecutableWriter<AArch64ELFType>>( - _context, *_AArch64TargetLayout.get()); + _ctx, *_AArch64TargetLayout.get()); case llvm::ELF::ET_DYN: return llvm::make_unique<AArch64DynamicLibraryWriter<AArch64ELFType>>( - _context, *_AArch64TargetLayout.get()); + _ctx, *_AArch64TargetLayout.get()); case llvm::ELF::ET_REL: llvm_unreachable("TODO: support -r mode"); default: diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h index 4eb6786cdf1..901e315ee69 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h @@ -23,13 +23,12 @@ class AArch64LinkingContext; template <class ELFT> class AArch64TargetLayout : public TargetLayout<ELFT> { public: - AArch64TargetLayout(AArch64LinkingContext &context) - : TargetLayout<ELFT>(context) {} + AArch64TargetLayout(AArch64LinkingContext &ctx) : TargetLayout<ELFT>(ctx) {} }; class AArch64TargetHandler final : public DefaultTargetHandler<AArch64ELFType> { public: - AArch64TargetHandler(AArch64LinkingContext &context); + AArch64TargetHandler(AArch64LinkingContext &ctx); AArch64TargetLayout<AArch64ELFType> &getTargetLayout() override { return *(_AArch64TargetLayout.get()); @@ -42,18 +41,18 @@ public: } std::unique_ptr<Reader> getObjReader() override { - return std::unique_ptr<Reader>(new AArch64ELFObjectReader(_context)); + return std::unique_ptr<Reader>(new AArch64ELFObjectReader(_ctx)); } std::unique_ptr<Reader> getDSOReader() override { - return std::unique_ptr<Reader>(new AArch64ELFDSOReader(_context)); + return std::unique_ptr<Reader>(new AArch64ELFDSOReader(_ctx)); } std::unique_ptr<Writer> getWriter() override; private: static const Registry::KindStrings kindStrings[]; - AArch64LinkingContext &_context; + AArch64LinkingContext &_ctx; std::unique_ptr<AArch64TargetLayout<AArch64ELFType>> _AArch64TargetLayout; std::unique_ptr<AArch64TargetRelocationHandler> _AArch64RelocationHandler; }; diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h b/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h index 19311d516e4..401bc33d851 100644 --- a/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h @@ -24,8 +24,7 @@ namespace elf { template <class ELFT> class ARMExecutableWriter : public ExecutableWriter<ELFT> { public: - ARMExecutableWriter(ARMLinkingContext &context, - ARMTargetLayout<ELFT> &layout); + ARMExecutableWriter(ARMLinkingContext &ctx, ARMTargetLayout<ELFT> &layout); protected: // Add any runtime files and their atoms to the output @@ -47,15 +46,14 @@ protected: std::error_code setELFHeader() override; private: - ARMLinkingContext &_context; + ARMLinkingContext &_ctx; ARMTargetLayout<ELFT> &_armLayout; }; template <class ELFT> -ARMExecutableWriter<ELFT>::ARMExecutableWriter(ARMLinkingContext &context, +ARMExecutableWriter<ELFT>::ARMExecutableWriter(ARMLinkingContext &ctx, ARMTargetLayout<ELFT> &layout) - : ExecutableWriter<ELFT>(context, layout), _context(context), - _armLayout(layout) {} + : ExecutableWriter<ELFT>(ctx, layout), _ctx(ctx), _armLayout(layout) {} template <class ELFT> bool ARMExecutableWriter<ELFT>::createImplicitFiles( @@ -85,7 +83,7 @@ template <class ELFT> unique_bump_ptr<SymbolTable<ELFT>> ARMExecutableWriter<ELFT>::createSymbolTable() { return unique_bump_ptr<SymbolTable<ELFT>>( - new (this->_alloc) ARMSymbolTable<ELFT>(this->_context)); + new (this->_alloc) ARMSymbolTable<ELFT>(this->_ctx)); } template <class ELFT> @@ -105,7 +103,7 @@ std::error_code ARMExecutableWriter<ELFT>::setELFHeader() { return ec; // Fixup entry point for Thumb code. - StringRef entryName = _context.entrySymbolName(); + StringRef entryName = _ctx.entrySymbolName(); if (const AtomLayout *al = _armLayout.findAtomLayoutByName(entryName)) { const auto *ea = dyn_cast<DefinedAtom>(al->_atom); if (ea && ea->codeModel() == DefinedAtom::codeARMThumb) diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMSymbolTable.h b/lld/lib/ReaderWriter/ELF/ARM/ARMSymbolTable.h index 5c9fec5d550..0655c7fe437 100644 --- a/lld/lib/ReaderWriter/ELF/ARM/ARMSymbolTable.h +++ b/lld/lib/ReaderWriter/ELF/ARM/ARMSymbolTable.h @@ -19,15 +19,15 @@ class ARMSymbolTable : public SymbolTable<ELFT> { public: typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym; - ARMSymbolTable(const ELFLinkingContext &context); + ARMSymbolTable(const ELFLinkingContext &ctx); void addDefinedAtom(Elf_Sym &sym, const DefinedAtom *da, int64_t addr) override; }; template <class ELFT> -ARMSymbolTable<ELFT>::ARMSymbolTable(const ELFLinkingContext &context) - : SymbolTable<ELFT>(context, ".symtab", +ARMSymbolTable<ELFT>::ARMSymbolTable(const ELFLinkingContext &ctx) + : SymbolTable<ELFT>(ctx, ".symtab", DefaultLayout<ELFT>::ORDER_SYMBOL_TABLE) {} template <class ELFT> diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.cpp index 98ada6050ce..c9deacb7378 100644 --- a/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.cpp @@ -15,11 +15,10 @@ using namespace lld; using namespace elf; -ARMTargetHandler::ARMTargetHandler(ARMLinkingContext &context) - : _context(context), _armTargetLayout( - new ARMTargetLayout<ARMELFType>(context)), - _armRelocationHandler(new ARMTargetRelocationHandler( - *_armTargetLayout.get())) {} +ARMTargetHandler::ARMTargetHandler(ARMLinkingContext &ctx) + : _ctx(ctx), _armTargetLayout(new ARMTargetLayout<ARMELFType>(ctx)), + _armRelocationHandler( + new ARMTargetRelocationHandler(*_armTargetLayout.get())) {} void ARMTargetHandler::registerRelocationNames(Registry ®istry) { registry.addKindTable(Reference::KindNamespace::ELF, Reference::KindArch::ARM, @@ -27,10 +26,10 @@ void ARMTargetHandler::registerRelocationNames(Registry ®istry) { } std::unique_ptr<Writer> ARMTargetHandler::getWriter() { - switch (this->_context.getOutputELFType()) { + switch (this->_ctx.getOutputELFType()) { case llvm::ELF::ET_EXEC: return llvm::make_unique<ARMExecutableWriter<ARMELFType>>( - _context, *_armTargetLayout.get()); + _ctx, *_armTargetLayout.get()); default: llvm_unreachable("unsupported output type"); } diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h b/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h index 10641954da2..518779984ab 100644 --- a/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h @@ -27,8 +27,7 @@ class ARMLinkingContext; template <class ELFT> class ARMTargetLayout : public TargetLayout<ELFT> { public: - ARMTargetLayout(ARMLinkingContext &context) - : TargetLayout<ELFT>(context) {} + ARMTargetLayout(ARMLinkingContext &ctx) : TargetLayout<ELFT>(ctx) {} uint64_t getTPOffset() { if (_tpOff.hasValue()) @@ -53,7 +52,7 @@ private: class ARMTargetHandler final : public DefaultTargetHandler<ARMELFType> { public: - ARMTargetHandler(ARMLinkingContext &context); + ARMTargetHandler(ARMLinkingContext &ctx); ARMTargetLayout<ARMELFType> &getTargetLayout() override { return *(_armTargetLayout.get()); @@ -66,18 +65,18 @@ public: } std::unique_ptr<Reader> getObjReader() override { - return std::unique_ptr<Reader>(new ARMELFObjectReader(_context)); + return std::unique_ptr<Reader>(new ARMELFObjectReader(_ctx)); } std::unique_ptr<Reader> getDSOReader() override { - return std::unique_ptr<Reader>(new ARMELFDSOReader(_context)); + return std::unique_ptr<Reader>(new ARMELFDSOReader(_ctx)); } std::unique_ptr<Writer> getWriter() override; private: static const Registry::KindStrings kindStrings[]; - ARMLinkingContext &_context; + ARMLinkingContext &_ctx; std::unique_ptr<ARMTargetLayout<ARMELFType>> _armTargetLayout; std::unique_ptr<ARMTargetRelocationHandler> _armRelocationHandler; }; diff --git a/lld/lib/ReaderWriter/ELF/Chunk.h b/lld/lib/ReaderWriter/ELF/Chunk.h index 2658d023b3a..bcd7cb5011a 100644 --- a/lld/lib/ReaderWriter/ELF/Chunk.h +++ b/lld/lib/ReaderWriter/ELF/Chunk.h @@ -45,9 +45,9 @@ public: /// \brief the ContentType of the chunk enum ContentType : uint8_t{ Unknown, Header, Code, Data, Note, TLS }; - Chunk(StringRef name, Kind kind, const ELFLinkingContext &context) - : _name(name), _kind(kind), _fsize(0), _msize(0), _alignment(0), _order(0), - _ordinal(1), _start(0), _fileoffset(0), _context(context) {} + Chunk(StringRef name, Kind kind, const ELFLinkingContext &ctx) + : _name(name), _kind(kind), _fsize(0), _msize(0), _alignment(0), + _order(0), _ordinal(1), _start(0), _fileoffset(0), _ctx(ctx) {} virtual ~Chunk() {} // The name of the chunk StringRef name() const { return _name; } @@ -93,7 +93,7 @@ protected: uint64_t _ordinal; uint64_t _start; uint64_t _fileoffset; - const ELFLinkingContext &_context; + const ELFLinkingContext &_ctx; }; } // end namespace elf diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index 9af3b8eb8dc..f1d95630df4 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -170,8 +170,8 @@ public: typedef llvm::DenseSet<const Atom *> AtomSetT; - DefaultLayout(ELFLinkingContext &context) - : _context(context), _linkerScriptSema(context.linkerScriptSema()) {} + DefaultLayout(ELFLinkingContext &ctx) + : _ctx(ctx), _linkerScriptSema(ctx.linkerScriptSema()) {} /// \brief Return the section order for a input section SectionOrder getSectionOrder(StringRef name, int32_t contentType, @@ -283,7 +283,7 @@ public: RelocationTable<ELFT> *getDynamicRelocationTable() { if (!_dynamicRelocationTable) { _dynamicRelocationTable = std::move(createRelocationTable( - _context.isRelaOutputFormat() ? ".rela.dyn" : ".rel.dyn", + _ctx.isRelaOutputFormat() ? ".rela.dyn" : ".rel.dyn", ORDER_DYNAMIC_RELOCS)); addSection(_dynamicRelocationTable.get()); } @@ -294,7 +294,7 @@ public: RelocationTable<ELFT> *getPLTRelocationTable() { if (!_pltRelocationTable) { _pltRelocationTable = std::move(createRelocationTable( - _context.isRelaOutputFormat() ? ".rela.plt" : ".rel.plt", + _ctx.isRelaOutputFormat() ? ".rela.plt" : ".rel.plt", ORDER_DYNAMIC_PLT_RELOCS)); addSection(_pltRelocationTable.get()); } @@ -335,7 +335,7 @@ protected: virtual unique_bump_ptr<RelocationTable<ELFT>> createRelocationTable(StringRef name, int32_t order) { return unique_bump_ptr<RelocationTable<ELFT>>( - new (_allocator) RelocationTable<ELFT>(_context, name, order)); + new (_allocator) RelocationTable<ELFT>(_ctx, name, order)); } private: @@ -358,7 +358,7 @@ protected: std::vector<lld::AtomLayout *> _absoluteAtoms; AtomSetT _referencedDynAtoms; llvm::StringSet<> _copiedDynSymNames; - ELFLinkingContext &_context; + ELFLinkingContext &_ctx; script::Sema &_linkerScriptSema; }; @@ -570,7 +570,7 @@ template <class ELFT> AtomSection<ELFT> *DefaultLayout<ELFT>::createSection( StringRef sectionName, int32_t contentType, DefinedAtom::ContentPermissions permissions, SectionOrder sectionOrder) { - return new (_allocator) AtomSection<ELFT>(_context, sectionName, contentType, + return new (_allocator) AtomSection<ELFT>(_ctx, sectionName, contentType, permissions, sectionOrder); } @@ -617,10 +617,10 @@ DefaultLayout<ELFT>::addAtom(const Atom *atom) { // Add runtime relocations to the .rela section. for (const auto &reloc : *definedAtom) { bool isLocalReloc = true; - if (_context.isDynamicRelocation(*reloc)) { + if (_ctx.isDynamicRelocation(*reloc)) { getDynamicRelocationTable()->addRelocation(*definedAtom, *reloc); isLocalReloc = false; - } else if (_context.isPLTRelocation(*reloc)) { + } else if (_ctx.isPLTRelocation(*reloc)) { getPLTRelocationTable()->addRelocation(*definedAtom, *reloc); isLocalReloc = false; } @@ -632,7 +632,7 @@ DefaultLayout<ELFT>::addAtom(const Atom *atom) { if (isa<UndefinedAtom>(reloc->target()) && isLocalReloc) continue; - if (_context.isCopyRelocation(*reloc)) { + if (_ctx.isCopyRelocation(*reloc)) { _copiedDynSymNames.insert(definedAtom->name()); continue; } @@ -716,7 +716,7 @@ void DefaultLayout<ELFT>::sortOutputSectionByPriority( template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() { ScopedTask task(getDefaultDomain(), "assignSectionsToSegments"); - ELFLinkingContext::OutputMagic outputMagic = _context.getOutputMagic(); + ELFLinkingContext::OutputMagic outputMagic = _ctx.getOutputMagic(); // sort the sections by their order as defined by the layout sortInputSections(); @@ -752,7 +752,7 @@ template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() { int64_t lookupSectionFlag = osi->flags(); if ((!(lookupSectionFlag & llvm::ELF::SHF_WRITE)) && - (_context.mergeRODataToTextSegment())) + (_ctx.mergeRODataToTextSegment())) lookupSectionFlag &= ~llvm::ELF::SHF_EXECINSTR; // Merge string sections into Data segment itself @@ -774,8 +774,8 @@ template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() { if (!additionalSegmentInsert.second) { segment = additionalSegmentInsert.first->second; } else { - segment = new (_allocator) - Segment<ELFT>(_context, segmentName, segmentType); + segment = + new (_allocator) Segment<ELFT>(_ctx, segmentName, segmentType); additionalSegmentInsert.first->second = segment; _segments.push_back(segment); } @@ -802,7 +802,7 @@ template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() { segment = segmentInsert.first->second; } else { segment = new (_allocator) - Segment<ELFT>(_context, "PT_LOAD", llvm::ELF::PT_LOAD); + Segment<ELFT>(_ctx, "PT_LOAD", llvm::ELF::PT_LOAD); segmentInsert.first->second = segment; _segments.push_back(segment); } @@ -815,9 +815,8 @@ template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() { } } } - if (_context.isDynamic() && !_context.isDynamicLibrary()) { - Segment<ELFT> *segment = - new (_allocator) ProgramHeaderSegment<ELFT>(_context); + if (_ctx.isDynamic() && !_ctx.isDynamicLibrary()) { + Segment<ELFT> *segment = new (_allocator) ProgramHeaderSegment<ELFT>(_ctx); _segments.push_back(segment); segment->append(_elfHeader); segment->append(_programHeader); @@ -832,7 +831,7 @@ DefaultLayout<ELFT>::assignVirtualAddress() { std::sort(_segments.begin(), _segments.end(), Segment<ELFT>::compareSegments); - uint64_t baseAddress = _context.getBaseAddress(); + uint64_t baseAddress = _ctx.getBaseAddress(); // HACK: This is a super dirty hack. The elf header and program header are // not part of a section, but we need them to be loaded at the base address @@ -1039,7 +1038,7 @@ void DefaultLayout<ELFT>::addExtraChunksToSegment(Segment<ELFT> *segment, _linkerScriptSema.getExprs({archivePath, memberPath, sectionName}); for (auto expr : exprs) { auto expChunk = - new (this->_allocator) ExpressionChunk<ELFT>(this->_context, expr); + new (this->_allocator) ExpressionChunk<ELFT>(this->_ctx, expr); segment->append(expChunk); } } diff --git a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h index f97514b525c..88211660200 100644 --- a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h @@ -25,9 +25,9 @@ class DynamicLibraryWriter; template<class ELFT> class DynamicLibraryWriter : public OutputELFWriter<ELFT> { public: - DynamicLibraryWriter(ELFLinkingContext &context, TargetLayout<ELFT> &layout) - : OutputELFWriter<ELFT>(context, layout), - _runtimeFile(new RuntimeFile<ELFT>(context, "C runtime")) {} + DynamicLibraryWriter(ELFLinkingContext &ctx, TargetLayout<ELFT> &layout) + : OutputELFWriter<ELFT>(ctx, layout), + _runtimeFile(new RuntimeFile<ELFT>(ctx, "C runtime")) {} protected: virtual void buildDynamicSymbolTable(const File &file); diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index cdfbec9208a..7d42668b55f 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -445,8 +445,8 @@ protected: template <class ELFT> class RuntimeFile : public ELFFile<ELFT> { public: typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym; - RuntimeFile(ELFLinkingContext &context, StringRef name) - : ELFFile<ELFT>(name, context) {} + RuntimeFile(ELFLinkingContext &ctx, StringRef name) + : ELFFile<ELFT>(name, ctx) {} /// \brief add a global absolute atom virtual Atom *addAbsoluteAtom(StringRef symbolName) { diff --git a/lld/lib/ReaderWriter/ELF/ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/ExecutableWriter.h index 477e3920aba..4e227d1f952 100644 --- a/lld/lib/ReaderWriter/ELF/ExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/ExecutableWriter.h @@ -25,9 +25,9 @@ class ExecutableWriter; template<class ELFT> class ExecutableWriter : public OutputELFWriter<ELFT> { public: - ExecutableWriter(ELFLinkingContext &context, TargetLayout<ELFT> &layout) - : OutputELFWriter<ELFT>(context, layout), - _runtimeFile(new RuntimeFile<ELFT>(context, "C runtime")) {} + ExecutableWriter(ELFLinkingContext &ctx, TargetLayout<ELFT> &layout) + : OutputELFWriter<ELFT>(ctx, layout), + _runtimeFile(new RuntimeFile<ELFT>(ctx, "C runtime")) {} protected: virtual void buildDynamicSymbolTable(const File &file); @@ -56,8 +56,8 @@ void ExecutableWriter<ELFT>::buildDynamicSymbolTable(const File &file) { if (!da) continue; if (da->dynamicExport() != DefinedAtom::dynamicExportAlways && - !this->_context.isDynamicallyExportedSymbol(da->name()) && - !(this->_context.shouldExportDynamic() && + !this->_ctx.isDynamicallyExportedSymbol(da->name()) && + !(this->_ctx.shouldExportDynamic() && da->scope() == Atom::Scope::scopeGlobal)) continue; this->_dynamicSymbolTable->addSymbol(atom->_atom, section->ordinal(), @@ -65,7 +65,7 @@ void ExecutableWriter<ELFT>::buildDynamicSymbolTable(const File &file) { } // Put weak symbols in the dynamic symbol table. - if (this->_context.isDynamic()) { + if (this->_ctx.isDynamic()) { for (const UndefinedAtom *a : file.undefined()) { if (this->_layout.isReferencedByDefinedAtom(a) && a->canBeNull() != UndefinedAtom::canBeNullNever) @@ -81,7 +81,7 @@ void ExecutableWriter<ELFT>::buildDynamicSymbolTable(const File &file) { template<class ELFT> void ExecutableWriter<ELFT>::addDefaultAtoms() { OutputELFWriter<ELFT>::addDefaultAtoms(); - _runtimeFile->addUndefinedAtom(this->_context.entrySymbolName()); + _runtimeFile->addUndefinedAtom(this->_ctx.entrySymbolName()); _runtimeFile->addAbsoluteAtom("__bss_start"); _runtimeFile->addAbsoluteAtom("__bss_end"); _runtimeFile->addAbsoluteAtom("_end"); @@ -90,7 +90,7 @@ void ExecutableWriter<ELFT>::addDefaultAtoms() { _runtimeFile->addAbsoluteAtom("__preinit_array_end"); _runtimeFile->addAbsoluteAtom("__init_array_start"); _runtimeFile->addAbsoluteAtom("__init_array_end"); - if (this->_context.isRelaOutputFormat()) { + if (this->_ctx.isRelaOutputFormat()) { _runtimeFile->addAbsoluteAtom("__rela_iplt_start"); _runtimeFile->addAbsoluteAtom("__rela_iplt_end"); } else { @@ -114,10 +114,10 @@ bool ExecutableWriter<ELFT>::createImplicitFiles( template <class ELFT> void ExecutableWriter<ELFT>::createDefaultSections() { OutputELFWriter<ELFT>::createDefaultSections(); - if (this->_context.isDynamic()) { + if (this->_ctx.isDynamic()) { _interpSection.reset(new (this->_alloc) InterpSection<ELFT>( - this->_context, ".interp", DefaultLayout<ELFT>::ORDER_INTERP, - this->_context.getInterpreter())); + this->_ctx, ".interp", DefaultLayout<ELFT>::ORDER_INTERP, + this->_ctx.getInterpreter())); this->_layout.addSection(_interpSection.get()); } } @@ -148,7 +148,7 @@ template <class ELFT> void ExecutableWriter<ELFT>::finalizeDefaultAtomValues() { startEnd("preinit_array", ".preinit_array"); startEnd("init_array", ".init_array"); - if (this->_context.isRelaOutputFormat()) + if (this->_ctx.isRelaOutputFormat()) startEnd("rela_iplt", ".rela.plt"); else startEnd("rel_iplt", ".rel.plt"); diff --git a/lld/lib/ReaderWriter/ELF/HeaderChunks.h b/lld/lib/ReaderWriter/ELF/HeaderChunks.h index eab132b9b2f..534cf2b198c 100644 --- a/lld/lib/ReaderWriter/ELF/HeaderChunks.h +++ b/lld/lib/ReaderWriter/ELF/HeaderChunks.h @@ -63,8 +63,8 @@ public: (ELFT::TargetEndianness == llvm::support::little) ? llvm::ELF::ELFDATA2LSB : llvm::ELF::ELFDATA2MSB; - _eh.e_type = this->_context.getOutputELFType(); - _eh.e_machine = this->_context.getOutputMachine(); + _eh.e_type = this->_ctx.getOutputELFType(); + _eh.e_machine = this->_ctx.getOutputMachine(); } private: @@ -72,8 +72,8 @@ private: }; template <class ELFT> -ELFHeader<ELFT>::ELFHeader(const ELFLinkingContext &context) - : Chunk<ELFT>("elfhdr", Chunk<ELFT>::Kind::ELFHeader, context) { +ELFHeader<ELFT>::ELFHeader(const ELFLinkingContext &ctx) + : Chunk<ELFT>("elfhdr", Chunk<ELFT>::Kind::ELFHeader, ctx) { this->_alignment = ELFT::Is64Bits ? 8 : 4; this->_fsize = sizeof(Elf_Ehdr); this->_msize = sizeof(Elf_Ehdr); @@ -124,8 +124,8 @@ public: uint64_t _flagsClear; }; - ProgramHeader(const ELFLinkingContext &context) - : Chunk<ELFT>("elfphdr", Chunk<ELFT>::Kind::ProgramHeader, context) { + ProgramHeader(const ELFLinkingContext &ctx) + : Chunk<ELFT>("elfphdr", Chunk<ELFT>::Kind::ProgramHeader, ctx) { this->_alignment = ELFT::Is64Bits ? 8 : 4; resetProgramHeaders(); } @@ -197,7 +197,7 @@ private: template <class ELFT> bool ProgramHeader<ELFT>::addSegment(Segment<ELFT> *segment) { bool allocatedNew = false; - ELFLinkingContext::OutputMagic outputMagic = this->_context.getOutputMagic(); + ELFLinkingContext::OutputMagic outputMagic = this->_ctx.getOutputMagic(); // For segments that are not a loadable segment, we // just pick the values directly from the segment as there // wouldnt be any slices within that @@ -300,9 +300,8 @@ private: }; template <class ELFT> -SectionHeader<ELFT>::SectionHeader(const ELFLinkingContext &context, - int32_t order) - : Chunk<ELFT>("shdr", Chunk<ELFT>::Kind::SectionHeader, context) { +SectionHeader<ELFT>::SectionHeader(const ELFLinkingContext &ctx, int32_t order) + : Chunk<ELFT>("shdr", Chunk<ELFT>::Kind::SectionHeader, ctx) { this->_fsize = 0; this->_alignment = 8; this->setOrder(order); diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h index e2d3193045b..b8e5a31afd4 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h @@ -22,7 +22,7 @@ template <class ELFT> class HexagonDynamicLibraryWriter : public DynamicLibraryWriter<ELFT>, public HexagonELFWriter<ELFT> { public: - HexagonDynamicLibraryWriter(HexagonLinkingContext &context, + HexagonDynamicLibraryWriter(HexagonLinkingContext &ctx, HexagonTargetLayout<ELFT> &layout); protected: @@ -43,18 +43,18 @@ private: _hexagonRuntimeFile->addAbsoluteAtom("_DYNAMIC"); } - HexagonLinkingContext &_hexagonLinkingContext; + HexagonLinkingContext &_ctx; HexagonTargetLayout<ELFT> &_hexagonTargetLayout; std::unique_ptr<HexagonRuntimeFile<ELFT>> _hexagonRuntimeFile; }; template <class ELFT> HexagonDynamicLibraryWriter<ELFT>::HexagonDynamicLibraryWriter( - HexagonLinkingContext &context, HexagonTargetLayout<ELFT> &layout) - : DynamicLibraryWriter<ELFT>(context, layout), - HexagonELFWriter<ELFT>(context, layout), _hexagonLinkingContext(context), + HexagonLinkingContext &ctx, HexagonTargetLayout<ELFT> &layout) + : DynamicLibraryWriter<ELFT>(ctx, layout), + HexagonELFWriter<ELFT>(ctx, layout), _ctx(ctx), _hexagonTargetLayout(layout), - _hexagonRuntimeFile(new HexagonRuntimeFile<ELFT>(context)) {} + _hexagonRuntimeFile(new HexagonRuntimeFile<ELFT>(ctx)) {} template <class ELFT> bool HexagonDynamicLibraryWriter<ELFT>::createImplicitFiles( diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h index 96c74f72222..757237fff61 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFWriters.h @@ -20,9 +20,9 @@ template <class ELFT> class HexagonTargetLayout; template <typename ELFT> class HexagonELFWriter { public: - HexagonELFWriter(HexagonLinkingContext &context, + HexagonELFWriter(HexagonLinkingContext &ctx, HexagonTargetLayout<ELFT> &targetLayout) - : _hexagonLinkingContext(context), _hexagonTargetLayout(targetLayout) {} + : _ctx(ctx), _hexagonTargetLayout(targetLayout) {} protected: bool setELFHeader(ELFHeader<ELFT> &elfHeader) { @@ -34,7 +34,7 @@ protected: } void finalizeHexagonRuntimeAtomValues() { - if (_hexagonLinkingContext.isDynamic()) { + if (_ctx.isDynamic()) { auto gotAtomIter = _hexagonTargetLayout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_"); auto gotpltSection = _hexagonTargetLayout.findOutputSection(".got.plt"); @@ -52,7 +52,7 @@ protected: } private: - HexagonLinkingContext &_hexagonLinkingContext; + HexagonLinkingContext &_ctx; HexagonTargetLayout<ELFT> &_hexagonTargetLayout; }; diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h index a2505aa460c..9e5c125c34e 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h @@ -20,8 +20,8 @@ class HexagonLinkingContext; template <class HexagonELFType> class HexagonRuntimeFile : public RuntimeFile<HexagonELFType> { public: - HexagonRuntimeFile(HexagonLinkingContext &context) - : RuntimeFile<HexagonELFType>(context, "Hexagon runtime file") {} + HexagonRuntimeFile(HexagonLinkingContext &ctx) + : RuntimeFile<HexagonELFType>(ctx, "Hexagon runtime file") {} }; } // elf } // lld diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h index 0848e64166f..d52fb328f4a 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h @@ -23,7 +23,7 @@ template <class ELFT> class HexagonExecutableWriter : public ExecutableWriter<ELFT>, public HexagonELFWriter<ELFT> { public: - HexagonExecutableWriter(HexagonLinkingContext &context, + HexagonExecutableWriter(HexagonLinkingContext &ctx, HexagonTargetLayout<ELFT> &layout); protected: @@ -41,24 +41,23 @@ protected: private: void addDefaultAtoms() { _hexagonRuntimeFile->addAbsoluteAtom("_SDA_BASE_"); - if (this->_context.isDynamic()) { + if (this->_ctx.isDynamic()) { _hexagonRuntimeFile->addAbsoluteAtom("_GLOBAL_OFFSET_TABLE_"); _hexagonRuntimeFile->addAbsoluteAtom("_DYNAMIC"); } } - HexagonLinkingContext &_hexagonLinkingContext; + HexagonLinkingContext &_ctx; HexagonTargetLayout<ELFT> &_hexagonTargetLayout; std::unique_ptr<HexagonRuntimeFile<ELFT>> _hexagonRuntimeFile; }; template <class ELFT> HexagonExecutableWriter<ELFT>::HexagonExecutableWriter( - HexagonLinkingContext &context, HexagonTargetLayout<ELFT> &layout) - : ExecutableWriter<ELFT>(context, layout), - HexagonELFWriter<ELFT>(context, layout), _hexagonLinkingContext(context), - _hexagonTargetLayout(layout), - _hexagonRuntimeFile(new HexagonRuntimeFile<ELFT>(context)) {} + HexagonLinkingContext &ctx, HexagonTargetLayout<ELFT> &layout) + : ExecutableWriter<ELFT>(ctx, layout), HexagonELFWriter<ELFT>(ctx, layout), + _ctx(ctx), _hexagonTargetLayout(layout), + _hexagonRuntimeFile(new HexagonRuntimeFile<ELFT>(ctx)) {} template <class ELFT> bool HexagonExecutableWriter<ELFT>::createImplicitFiles( diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h index 7a91f9704a5..be66e74a1c2 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.h @@ -20,9 +20,9 @@ class HexagonLinkingContext; template <class HexagonELFType> class SDataSection : public AtomSection<HexagonELFType> { public: - SDataSection(const HexagonLinkingContext &context) + SDataSection(const HexagonLinkingContext &ctx) : AtomSection<HexagonELFType>( - context, ".sdata", DefinedAtom::typeDataFast, 0, + ctx, ".sdata", DefinedAtom::typeDataFast, 0, HexagonTargetLayout<HexagonELFType>::ORDER_SDATA) { this->_type = SHT_PROGBITS; this->_flags = SHF_ALLOC | SHF_WRITE; diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp index 44bfdef9af4..8ff4367c4f6 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp @@ -18,21 +18,21 @@ using namespace llvm::ELF; using llvm::makeArrayRef; -HexagonTargetHandler::HexagonTargetHandler(HexagonLinkingContext &context) - : _hexagonLinkingContext(context), - _hexagonRuntimeFile(new HexagonRuntimeFile<HexagonELFType>(context)), - _hexagonTargetLayout(new HexagonTargetLayout<HexagonELFType>(context)), - _hexagonRelocationHandler(new HexagonTargetRelocationHandler( - *_hexagonTargetLayout.get())) {} +HexagonTargetHandler::HexagonTargetHandler(HexagonLinkingContext &ctx) + : _ctx(ctx), + _hexagonRuntimeFile(new HexagonRuntimeFile<HexagonELFType>(ctx)), + _hexagonTargetLayout(new HexagonTargetLayout<HexagonELFType>(ctx)), + _hexagonRelocationHandler( + new HexagonTargetRelocationHandler(*_hexagonTargetLayout.get())) {} std::unique_ptr<Writer> HexagonTargetHandler::getWriter() { - switch (_hexagonLinkingContext.getOutputELFType()) { + switch (_ctx.getOutputELFType()) { case llvm::ELF::ET_EXEC: return llvm::make_unique<HexagonExecutableWriter<HexagonELFType>>( - _hexagonLinkingContext, *_hexagonTargetLayout.get()); + _ctx, *_hexagonTargetLayout.get()); case llvm::ELF::ET_DYN: return llvm::make_unique<HexagonDynamicLibraryWriter<HexagonELFType>>( - _hexagonLinkingContext, *_hexagonTargetLayout.get()); + _ctx, *_hexagonTargetLayout.get()); case llvm::ELF::ET_REL: llvm_unreachable("TODO: support -r mode"); default: diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h index f4315f710ec..454d60d26f9 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h @@ -118,13 +118,11 @@ public: } std::unique_ptr<Reader> getObjReader() override { - return std::unique_ptr<Reader>( - new HexagonELFObjectReader(_hexagonLinkingContext)); + return std::unique_ptr<Reader>(new HexagonELFObjectReader(_ctx)); } std::unique_ptr<Reader> getDSOReader() override { - return std::unique_ptr<Reader>( - new HexagonELFDSOReader(_hexagonLinkingContext)); + return std::unique_ptr<Reader>(new HexagonELFDSOReader(_ctx)); } std::unique_ptr<Writer> getWriter() override; @@ -132,7 +130,7 @@ public: private: llvm::BumpPtrAllocator _alloc; static const Registry::KindStrings kindStrings[]; - HexagonLinkingContext &_hexagonLinkingContext; + HexagonLinkingContext &_ctx; std::unique_ptr<HexagonRuntimeFile<HexagonELFType> > _hexagonRuntimeFile; std::unique_ptr<HexagonTargetLayout<HexagonELFType>> _hexagonTargetLayout; std::unique_ptr<HexagonTargetRelocationHandler> _hexagonRelocationHandler; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h index 30b5b0ba6da..d1c80ff0e50 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h @@ -74,16 +74,16 @@ void MipsDynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues() { template <class ELFT> unique_bump_ptr<SymbolTable<ELFT>> MipsDynamicLibraryWriter<ELFT>::createSymbolTable() { - return unique_bump_ptr<SymbolTable<ELFT>>(new ( - this->_alloc) MipsSymbolTable<ELFT>(this->_context)); + return unique_bump_ptr<SymbolTable<ELFT>>( + new (this->_alloc) MipsSymbolTable<ELFT>(this->_ctx)); } /// \brief create dynamic table template <class ELFT> unique_bump_ptr<DynamicTable<ELFT>> MipsDynamicLibraryWriter<ELFT>::createDynamicTable() { - return unique_bump_ptr<DynamicTable<ELFT>>(new ( - this->_alloc) MipsDynamicTable<ELFT>(this->_context, _mipsTargetLayout)); + return unique_bump_ptr<DynamicTable<ELFT>>( + new (this->_alloc) MipsDynamicTable<ELFT>(this->_ctx, _mipsTargetLayout)); } /// \brief create dynamic symbol table @@ -91,8 +91,8 @@ template <class ELFT> unique_bump_ptr<DynamicSymbolTable<ELFT>> MipsDynamicLibraryWriter<ELFT>::createDynamicSymbolTable() { return unique_bump_ptr<DynamicSymbolTable<ELFT>>( - new (this->_alloc) MipsDynamicSymbolTable<ELFT>( - this->_context, _mipsTargetLayout)); + new (this->_alloc) + MipsDynamicSymbolTable<ELFT>(this->_ctx, _mipsTargetLayout)); } } // namespace elf diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h b/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h index 1a85bba3bd0..bf84c217c2d 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h @@ -56,7 +56,7 @@ std::error_code MipsExecutableWriter<ELFT>::setELFHeader() { if (ec) return ec; - StringRef entryName = this->_context.entrySymbolName(); + StringRef entryName = this->_ctx.entrySymbolName(); if (const AtomLayout *al = this->_layout.findAtomLayoutByName(entryName)) { const auto *ea = cast<DefinedAtom>(al->_atom); if (ea->codeModel() == DefinedAtom::codeMipsMicro || @@ -87,8 +87,8 @@ void MipsExecutableWriter<ELFT>::buildDynamicSymbolTable(const File &file) { continue; if (da->dynamicExport() != DefinedAtom::dynamicExportAlways && - !this->_context.isDynamicallyExportedSymbol(da->name()) && - !(this->_context.shouldExportDynamic() && + !this->_ctx.isDynamicallyExportedSymbol(da->name()) && + !(this->_ctx.shouldExportDynamic() && da->scope() == Atom::Scope::scopeGlobal)) continue; @@ -127,16 +127,16 @@ void MipsExecutableWriter<ELFT>::finalizeDefaultAtomValues() { template <class ELFT> unique_bump_ptr<SymbolTable<ELFT>> MipsExecutableWriter<ELFT>::createSymbolTable() { - return unique_bump_ptr<SymbolTable<ELFT>>(new ( - this->_alloc) MipsSymbolTable<ELFT>(this->_context)); + return unique_bump_ptr<SymbolTable<ELFT>>( + new (this->_alloc) MipsSymbolTable<ELFT>(this->_ctx)); } /// \brief create dynamic table template <class ELFT> unique_bump_ptr<DynamicTable<ELFT>> MipsExecutableWriter<ELFT>::createDynamicTable() { - return unique_bump_ptr<DynamicTable<ELFT>>(new ( - this->_alloc) MipsDynamicTable<ELFT>(this->_context, _mipsTargetLayout)); + return unique_bump_ptr<DynamicTable<ELFT>>( + new (this->_alloc) MipsDynamicTable<ELFT>(this->_ctx, _mipsTargetLayout)); } /// \brief create dynamic symbol table @@ -144,8 +144,8 @@ template <class ELFT> unique_bump_ptr<DynamicSymbolTable<ELFT>> MipsExecutableWriter<ELFT>::createDynamicSymbolTable() { return unique_bump_ptr<DynamicSymbolTable<ELFT>>( - new (this->_alloc) MipsDynamicSymbolTable<ELFT>( - this->_context, _mipsTargetLayout)); + new (this->_alloc) + MipsDynamicSymbolTable<ELFT>(this->_ctx, _mipsTargetLayout)); } } // namespace elf diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h b/lld/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h index de9390f2b30..fce2a15e8c9 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h @@ -139,9 +139,9 @@ template <class ELFT> class MipsRelocationTable : public RelocationTable<ELFT> { ELFT::Is64Bits && ELFT::TargetEndianness == llvm::support::little; public: - MipsRelocationTable(const ELFLinkingContext &context, StringRef str, + MipsRelocationTable(const ELFLinkingContext &ctx, StringRef str, int32_t order) - : RelocationTable<ELFT>(context, str, order) {} + : RelocationTable<ELFT>(ctx, str, order) {} protected: void writeRela(ELFWriter *writer, Elf_Rela &r, const DefinedAtom &atom, @@ -150,7 +150,7 @@ protected: r.setSymbolAndType(this->getSymbolIndex(ref.target()), rType, _isMips64EL); r.r_offset = writer->addressOfAtom(&atom) + ref.offsetInAtom(); // The addend is used only by relative relocations - if (this->_context.isRelativeReloc(ref)) + if (this->_ctx.isRelativeReloc(ref)) r.r_addend = writer->addressOfAtom(ref.target()) + ref.addend(); else r.r_addend = 0; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h index 41f85ac9236..3451d1a404b 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h @@ -77,9 +77,8 @@ public: protected: unique_bump_ptr<RelocationTable<ELFT>> createRelocationTable(StringRef name, int32_t order) override { - return unique_bump_ptr<RelocationTable<ELFT>>( - new (this->_allocator) - MipsRelocationTable<ELFT>(this->_context, name, order)); + return unique_bump_ptr<RelocationTable<ELFT>>(new ( + this->_allocator) MipsRelocationTable<ELFT>(this->_ctx, name, order)); } private: diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h index c137905b936..dc4e11d707c 100644 --- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h +++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h @@ -35,9 +35,9 @@ namespace { template<class ELFT> class SymbolFile : public RuntimeFile<ELFT> { public: - SymbolFile(ELFLinkingContext &context) - : RuntimeFile<ELFT>(context, "Dynamic absolute symbols"), - _atomsAdded(false) {} + SymbolFile(ELFLinkingContext &ctx) + : RuntimeFile<ELFT>(ctx, "Dynamic absolute symbols"), _atomsAdded(false) { + } Atom *addAbsoluteAtom(StringRef symbolName) override { auto *a = RuntimeFile<ELFT>::addAbsoluteAtom(symbolName); @@ -59,13 +59,13 @@ template<class ELFT> class DynamicSymbolFile : public SimpleArchiveLibraryFile { typedef std::function<void(StringRef, RuntimeFile<ELFT> &)> Resolver; public: - DynamicSymbolFile(ELFLinkingContext &context, Resolver resolver) + DynamicSymbolFile(ELFLinkingContext &ctx, Resolver resolver) : SimpleArchiveLibraryFile("Dynamically added runtime symbols"), - _context(context), _resolver(resolver) {} + _ctx(ctx), _resolver(resolver) {} File *find(StringRef sym, bool dataSymbolOnly) override { if (!_file) - _file.reset(new (_alloc) SymbolFile<ELFT>(_context)); + _file.reset(new (_alloc) SymbolFile<ELFT>(_ctx)); assert(!_file->hasAtoms() && "The file shouldn't have atoms yet"); _resolver(sym, *_file); @@ -74,7 +74,7 @@ public: } private: - ELFLinkingContext &_context; + ELFLinkingContext &_ctx; Resolver _resolver; // The allocator should go before bump pointers because of @@ -99,7 +99,7 @@ public: typedef Elf_Sym_Impl<ELFT> Elf_Sym; typedef Elf_Dyn_Impl<ELFT> Elf_Dyn; - OutputELFWriter(ELFLinkingContext &context, TargetLayout<ELFT> &layout); + OutputELFWriter(ELFLinkingContext &ctx, TargetLayout<ELFT> &layout); protected: // build the sections that need to be created @@ -184,7 +184,7 @@ protected: llvm::BumpPtrAllocator _alloc; - ELFLinkingContext &_context; + ELFLinkingContext &_ctx; TargetHandler<ELFT> &_targetHandler; typedef llvm::DenseMap<const Atom *, uint64_t> AtomToAddress; @@ -215,11 +215,10 @@ private: // OutputELFWriter //===----------------------------------------------------------------------===// template <class ELFT> -OutputELFWriter<ELFT>::OutputELFWriter(ELFLinkingContext &context, +OutputELFWriter<ELFT>::OutputELFWriter(ELFLinkingContext &ctx, TargetLayout<ELFT> &layout) - : _context(context), _targetHandler(context.getTargetHandler<ELFT>()), - _layout(layout), - _scriptFile(new RuntimeFile<ELFT>(context, "Linker script runtime")) {} + : _ctx(ctx), _targetHandler(ctx.getTargetHandler<ELFT>()), _layout(layout), + _scriptFile(new RuntimeFile<ELFT>(ctx, "Linker script runtime")) {} template <class ELFT> void OutputELFWriter<ELFT>::buildChunks(const File &file) { @@ -274,20 +273,20 @@ void OutputELFWriter<ELFT>::buildDynamicSymbolTable(const File &file) { if (isNeededTagRequired(sla)) _soNeeded.insert(sla->loadName()); } - for (const std::unique_ptr<Node> &node : _context.getNodes()) { + for (const std::unique_ptr<Node> &node : _ctx.getNodes()) { StringRef soname = maybeGetSOName(node.get()); if (!soname.empty()) _soNeeded.insert(soname); } // Never mark the dynamic linker as DT_NEEDED - _soNeeded.erase(sys::path::filename(_context.getInterpreter())); + _soNeeded.erase(sys::path::filename(_ctx.getInterpreter())); for (const auto &loadName : _soNeeded) { Elf_Dyn dyn; dyn.d_tag = DT_NEEDED; dyn.d_un.d_val = _dynamicStringTable->addString(loadName.getKey()); _dynamicTable->addEntry(dyn); } - const auto &rpathList = _context.getRpathList(); + const auto &rpathList = _ctx.getRpathList(); if (!rpathList.empty()) { auto rpath = new (_alloc) std::string(join(rpathList.begin(), rpathList.end(), ":")); @@ -296,8 +295,8 @@ void OutputELFWriter<ELFT>::buildDynamicSymbolTable(const File &file) { dyn.d_un.d_val = _dynamicStringTable->addString(*rpath); _dynamicTable->addEntry(dyn); } - StringRef soname = _context.sharedObjectName(); - if (!soname.empty() && _context.getOutputELFType() == llvm::ELF::ET_DYN) { + StringRef soname = _ctx.sharedObjectName(); + if (!soname.empty() && _ctx.getOutputELFType() == llvm::ELF::ET_DYN) { Elf_Dyn dyn; dyn.d_tag = DT_SONAME; dyn.d_un.d_val = _dynamicStringTable->addString(soname); @@ -367,7 +366,7 @@ void OutputELFWriter<ELFT>::assignSectionsWithNoSegments() { template <class ELFT> void OutputELFWriter<ELFT>::addDefaultAtoms() { const llvm::StringSet<> &symbols = - _context.linkerScriptSema().getScriptDefinedSymbols(); + _ctx.linkerScriptSema().getScriptDefinedSymbols(); for (auto &sym : symbols) _scriptFile->addAbsoluteAtom(sym.getKey()); } @@ -380,7 +379,7 @@ bool OutputELFWriter<ELFT>::createImplicitFiles( auto callback = [this](StringRef sym, RuntimeFile<ELFT> &file) { processUndefinedSymbol(sym, file); }; - auto &ctx = const_cast<ELFLinkingContext &>(_context); + auto &ctx = const_cast<ELFLinkingContext &>(_ctx); ctx.setUndefinesResolver( llvm::make_unique<DynamicSymbolFile<ELFT>>(ctx, std::move(callback))); // Add script defined symbols @@ -391,28 +390,28 @@ bool OutputELFWriter<ELFT>::createImplicitFiles( template <class ELFT> void OutputELFWriter<ELFT>::finalizeDefaultAtomValues() { const llvm::StringSet<> &symbols = - _context.linkerScriptSema().getScriptDefinedSymbols(); + _ctx.linkerScriptSema().getScriptDefinedSymbols(); for (auto &sym : symbols) { uint64_t res = - _context.linkerScriptSema().getLinkerScriptExprValue(sym.getKey()); + _ctx.linkerScriptSema().getLinkerScriptExprValue(sym.getKey()); auto a = _layout.findAbsoluteAtom(sym.getKey()); (*a)->_virtualAddr = res; } } template <class ELFT> void OutputELFWriter<ELFT>::createDefaultSections() { - _elfHeader.reset(new (_alloc) ELFHeader<ELFT>(_context)); - _programHeader.reset(new (_alloc) ProgramHeader<ELFT>(_context)); + _elfHeader.reset(new (_alloc) ELFHeader<ELFT>(_ctx)); + _programHeader.reset(new (_alloc) ProgramHeader<ELFT>(_ctx)); _layout.setHeader(_elfHeader.get()); _layout.setProgramHeader(_programHeader.get()); _symtab = std::move(this->createSymbolTable()); _strtab.reset(new (_alloc) StringTable<ELFT>( - _context, ".strtab", DefaultLayout<ELFT>::ORDER_STRING_TABLE)); + _ctx, ".strtab", DefaultLayout<ELFT>::ORDER_STRING_TABLE)); _shstrtab.reset(new (_alloc) StringTable<ELFT>( - _context, ".shstrtab", DefaultLayout<ELFT>::ORDER_SECTION_STRINGS)); + _ctx, ".shstrtab", DefaultLayout<ELFT>::ORDER_SECTION_STRINGS)); _shdrtab.reset(new (_alloc) SectionHeader<ELFT>( - _context, DefaultLayout<ELFT>::ORDER_SECTION_HEADERS)); + _ctx, DefaultLayout<ELFT>::ORDER_SECTION_HEADERS)); _layout.addSection(_symtab.get()); _layout.addSection(_strtab.get()); _layout.addSection(_shstrtab.get()); @@ -426,19 +425,19 @@ template <class ELFT> void OutputELFWriter<ELFT>::createDefaultSections() { if (!section || section->outputSectionName() != ".eh_frame") continue; _ehFrameHeader.reset(new (_alloc) EHFrameHeader<ELFT>( - _context, ".eh_frame_hdr", _layout, + _ctx, ".eh_frame_hdr", _layout, DefaultLayout<ELFT>::ORDER_EH_FRAMEHDR)); _layout.addSection(_ehFrameHeader.get()); break; } - if (_context.isDynamic()) { + if (_ctx.isDynamic()) { _dynamicTable = std::move(createDynamicTable()); _dynamicStringTable.reset(new (_alloc) StringTable<ELFT>( - _context, ".dynstr", DefaultLayout<ELFT>::ORDER_DYNAMIC_STRINGS, true)); + _ctx, ".dynstr", DefaultLayout<ELFT>::ORDER_DYNAMIC_STRINGS, true)); _dynamicSymbolTable = std::move(createDynamicSymbolTable()); _hashTable.reset(new (_alloc) HashSection<ELFT>( - _context, ".hash", DefaultLayout<ELFT>::ORDER_HASH)); + _ctx, ".hash", DefaultLayout<ELFT>::ORDER_HASH)); // Set the hash table in the dynamic symbol table so that the entries in the // hash table can be created _dynamicSymbolTable->setHashTable(_hashTable.get()); @@ -463,16 +462,15 @@ template <class ELFT> unique_bump_ptr<SymbolTable<ELFT>> OutputELFWriter<ELFT>::createSymbolTable() { return unique_bump_ptr<SymbolTable<ELFT>>(new (_alloc) SymbolTable<ELFT>( - this->_context, ".symtab", DefaultLayout<ELFT>::ORDER_SYMBOL_TABLE)); + this->_ctx, ".symtab", DefaultLayout<ELFT>::ORDER_SYMBOL_TABLE)); } /// \brief create dynamic table template <class ELFT> unique_bump_ptr<DynamicTable<ELFT>> OutputELFWriter<ELFT>::createDynamicTable() { - return unique_bump_ptr<DynamicTable<ELFT>>( - new (_alloc) DynamicTable<ELFT>( - this->_context, _layout, ".dynamic", DefaultLayout<ELFT>::ORDER_DYNAMIC)); + return unique_bump_ptr<DynamicTable<ELFT>>(new (_alloc) DynamicTable<ELFT>( + this->_ctx, _layout, ".dynamic", DefaultLayout<ELFT>::ORDER_DYNAMIC)); } /// \brief create dynamic symbol table @@ -480,9 +478,9 @@ template <class ELFT> unique_bump_ptr<DynamicSymbolTable<ELFT>> OutputELFWriter<ELFT>::createDynamicSymbolTable() { return unique_bump_ptr<DynamicSymbolTable<ELFT>>( - new (_alloc) DynamicSymbolTable<ELFT>( - this->_context, _layout, ".dynsym", - DefaultLayout<ELFT>::ORDER_DYNAMIC_SYMBOLS)); + new (_alloc) + DynamicSymbolTable<ELFT>(this->_ctx, _layout, ".dynsym", + DefaultLayout<ELFT>::ORDER_DYNAMIC_SYMBOLS)); } template <class ELFT> @@ -498,7 +496,7 @@ std::error_code OutputELFWriter<ELFT>::buildOutput(const File &file) { _layout.assignSectionsToSegments(); // Create the dynamic table entries - if (_context.isDynamic()) { + if (_ctx.isDynamic()) { _dynamicTable->createDefaultEntries(); buildDynamicSymbolTable(file); } @@ -517,7 +515,7 @@ std::error_code OutputELFWriter<ELFT>::buildOutput(const File &file) { // Create symbol table and section string table // Do it only if -s is not specified. - if (!_context.stripSymbols()) + if (!_ctx.stripSymbols()) buildStaticSymbolTable(file); // Finalize the layout by calling the finalize() functions @@ -530,15 +528,15 @@ std::error_code OutputELFWriter<ELFT>::buildOutput(const File &file) { // for sections with no segments assignSectionsWithNoSegments(); - if (_context.isDynamic()) + if (_ctx.isDynamic()) _dynamicTable->updateDynamicTable(); return std::error_code(); } template <class ELFT> std::error_code OutputELFWriter<ELFT>::setELFHeader() { - _elfHeader->e_type(_context.getOutputELFType()); - _elfHeader->e_machine(_context.getOutputMachine()); + _elfHeader->e_type(_ctx.getOutputELFType()); + _elfHeader->e_machine(_ctx.getOutputMachine()); _elfHeader->e_ident(ELF::EI_VERSION, 1); _elfHeader->e_ident(ELF::EI_OSABI, 0); _elfHeader->e_version(1); @@ -549,7 +547,7 @@ template <class ELFT> std::error_code OutputELFWriter<ELFT>::setELFHeader() { _elfHeader->e_shentsize(_shdrtab->entsize()); _elfHeader->e_shnum(_shdrtab->numHeaders()); _elfHeader->e_shstrndx(_shstrtab->ordinal()); - if (const auto *al = _layout.findAtomLayoutByName(_context.entrySymbolName())) + if (const auto *al = _layout.findAtomLayoutByName(_ctx.entrySymbolName())) _elfHeader->e_entry(al->_virtualAddr); else _elfHeader->e_entry(0); diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h index 26e40f0cf31..6508549dca2 100644 --- a/lld/lib/ReaderWriter/ELF/SectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h @@ -39,10 +39,10 @@ template <class ELFT> class Segment; /// \brief An ELF section. template <class ELFT> class Section : public Chunk<ELFT> { public: - Section(const ELFLinkingContext &context, StringRef sectionName, + Section(const ELFLinkingContext &ctx, StringRef sectionName, StringRef chunkName, typename Chunk<ELFT>::Kind k = Chunk<ELFT>::Kind::ELFSection) - : Chunk<ELFT>(chunkName, k, context), _outputSection(nullptr), _flags(0), + : Chunk<ELFT>(chunkName, k, ctx), _outputSection(nullptr), _flags(0), _entSize(0), _type(0), _link(0), _info(0), _isFirstSectionInOutputSection(false), _segmentType(SHT_NULL), _inputSectionName(sectionName), _outputSectionName(sectionName) {} @@ -159,9 +159,9 @@ protected: /// \brief A section containing atoms. template <class ELFT> class AtomSection : public Section<ELFT> { public: - AtomSection(const ELFLinkingContext &context, StringRef sectionName, + AtomSection(const ELFLinkingContext &ctx, StringRef sectionName, int32_t contentType, int32_t permissions, int32_t order) - : Section<ELFT>(context, sectionName, "AtomSection", + : Section<ELFT>(ctx, sectionName, "AtomSection", Chunk<ELFT>::Kind::AtomSection), _contentType(contentType), _contentPermissions(permissions), _isLoadedInMemory(true) { @@ -283,10 +283,8 @@ protected: void printError(const std::string &errorStr, const AtomLayout &atom, const Reference &ref) const { StringRef kindValStr; - if (!this->_context.registry().referenceKindToString(ref.kindNamespace(), - ref.kindArch(), - ref.kindValue(), - kindValStr)) { + if (!this->_ctx.registry().referenceKindToString( + ref.kindNamespace(), ref.kindArch(), ref.kindValue(), kindValStr)) { kindValStr = "unknown"; } @@ -429,7 +427,7 @@ void AtomSection<ELFT>::write(ELFWriter *writer, TargetLayout<ELFT> &layout, uint8_t *atomContent = chunkBuffer + ai->_fileOffset; std::memcpy(atomContent, content.data(), contentSize); const TargetRelocationHandler &relHandler = - this->_context.template getTargetHandler<ELFT>().getRelocationHandler(); + this->_ctx.template getTargetHandler<ELFT>().getRelocationHandler(); for (const auto ref : *definedAtom) { if (std::error_code ec = relHandler.applyRelocation(*writer, buffer, *ai, *ref)) { @@ -599,9 +597,9 @@ private: }; template <class ELFT> -StringTable<ELFT>::StringTable(const ELFLinkingContext &context, - const char *str, int32_t order, bool dynamic) - : Section<ELFT>(context, str, "StringTable") { +StringTable<ELFT>::StringTable(const ELFLinkingContext &ctx, const char *str, + int32_t order, bool dynamic) + : Section<ELFT>(ctx, str, "StringTable") { // the string table has a NULL entry for which // add an empty string _strings.push_back(""); @@ -653,7 +651,7 @@ class SymbolTable : public Section<ELFT> { public: typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym; - SymbolTable(const ELFLinkingContext &context, const char *str, int32_t order); + SymbolTable(const ELFLinkingContext &ctx, const char *str, int32_t order); /// \brief set the number of entries that would exist in the symbol /// table for the current link @@ -723,9 +721,9 @@ protected: /// ELF Symbol Table template <class ELFT> -SymbolTable<ELFT>::SymbolTable(const ELFLinkingContext &context, - const char *str, int32_t order) - : Section<ELFT>(context, str, "SymbolTable") { +SymbolTable<ELFT>::SymbolTable(const ELFLinkingContext &ctx, const char *str, + int32_t order) + : Section<ELFT>(ctx, str, "SymbolTable") { this->setOrder(order); Elf_Sym symbol; std::memset(&symbol, 0, sizeof(Elf_Sym)); @@ -907,9 +905,9 @@ template <class ELFT> class HashSection; template <class ELFT> class DynamicSymbolTable : public SymbolTable<ELFT> { public: - DynamicSymbolTable(const ELFLinkingContext &context, - TargetLayout<ELFT> &layout, const char *str, int32_t order) - : SymbolTable<ELFT>(context, str, order), _hashTable(nullptr), + DynamicSymbolTable(const ELFLinkingContext &ctx, TargetLayout<ELFT> &layout, + const char *str, int32_t order) + : SymbolTable<ELFT>(ctx, str, order), _hashTable(nullptr), _layout(layout) { this->_type = SHT_DYNSYM; this->_flags = SHF_ALLOC; @@ -956,14 +954,13 @@ public: typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel; typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela; - RelocationTable(const ELFLinkingContext &context, StringRef str, - int32_t order) - : Section<ELFT>(context, str, "RelocationTable"), _symbolTable(nullptr) { + RelocationTable(const ELFLinkingContext &ctx, StringRef str, int32_t order) + : Section<ELFT>(ctx, str, "RelocationTable"), _symbolTable(nullptr) { this->setOrder(order); this->_flags = SHF_ALLOC; // Set the alignment properly depending on the target architecture this->_alignment = ELFT::Is64Bits ? 8 : 4; - if (context.isRelaOutputFormat()) { + if (ctx.isRelaOutputFormat()) { this->_entSize = sizeof(Elf_Rela); this->_type = SHT_RELA; } else { @@ -1019,7 +1016,7 @@ public: uint8_t *chunkBuffer = buffer.getBufferStart(); uint8_t *dest = chunkBuffer + this->fileOffset(); for (const auto &rel : _relocs) { - if (this->_context.isRelaOutputFormat()) { + if (this->_ctx.isRelaOutputFormat()) { auto &r = *reinterpret_cast<Elf_Rela *>(dest); writeRela(writer, r, *rel.first, *rel.second); DEBUG_WITH_TYPE("ELFRelocationTable", @@ -1049,7 +1046,7 @@ protected: r.setSymbolAndType(getSymbolIndex(ref.target()), ref.kindValue(), false); r.r_offset = writer->addressOfAtom(&atom) + ref.offsetInAtom(); // The addend is used only by relative relocations - if (this->_context.isRelativeReloc(ref)) + if (this->_ctx.isRelativeReloc(ref)) r.r_addend = writer->addressOfAtom(ref.target()) + ref.addend(); else r.r_addend = 0; @@ -1077,9 +1074,9 @@ public: typedef llvm::object::Elf_Dyn_Impl<ELFT> Elf_Dyn; typedef std::vector<Elf_Dyn> EntriesT; - DynamicTable(const ELFLinkingContext &context, TargetLayout<ELFT> &layout, + DynamicTable(const ELFLinkingContext &ctx, TargetLayout<ELFT> &layout, StringRef str, int32_t order) - : Section<ELFT>(context, str, "DynamicSection"), _layout(layout) { + : Section<ELFT>(ctx, str, "DynamicSection"), _layout(layout) { this->setOrder(order); this->_entSize = sizeof(Elf_Dyn); this->_alignment = ELFT::Is64Bits ? 8 : 4; @@ -1113,7 +1110,7 @@ public: } virtual void createDefaultEntries() { - bool isRela = this->_context.isRelaOutputFormat(); + bool isRela = this->_ctx.isRelaOutputFormat(); Elf_Dyn dyn; dyn.d_un.d_val = 0; @@ -1280,14 +1277,14 @@ private: HashSection<ELFT> *_hashTable; const AtomLayout *getInitAtomLayout() { - auto al = _layout.findAtomLayoutByName(this->_context.initFunction()); + auto al = _layout.findAtomLayoutByName(this->_ctx.initFunction()); if (al && isa<DefinedAtom>(al->_atom)) return al; return nullptr; } const AtomLayout *getFiniAtomLayout() { - auto al = _layout.findAtomLayoutByName(this->_context.finiFunction()); + auto al = _layout.findAtomLayoutByName(this->_ctx.finiFunction()); if (al && isa<DefinedAtom>(al->_atom)) return al; return nullptr; @@ -1296,9 +1293,9 @@ private: template <class ELFT> class InterpSection : public Section<ELFT> { public: - InterpSection(const ELFLinkingContext &context, StringRef str, int32_t order, + InterpSection(const ELFLinkingContext &ctx, StringRef str, int32_t order, StringRef interp) - : Section<ELFT>(context, str, "Dynamic:Interp"), _interp(interp) { + : Section<ELFT>(ctx, str, "Dynamic:Interp"), _interp(interp) { this->setOrder(order); this->_alignment = 1; // + 1 for null term. @@ -1346,8 +1343,8 @@ template <class ELFT> class HashSection : public Section<ELFT> { }; public: - HashSection(const ELFLinkingContext &context, StringRef name, int32_t order) - : Section<ELFT>(context, name, "Dynamic:Hash"), _symbolTable(nullptr) { + HashSection(const ELFLinkingContext &ctx, StringRef name, int32_t order) + : Section<ELFT>(ctx, name, "Dynamic:Hash"), _symbolTable(nullptr) { this->setOrder(order); this->_entSize = 4; this->_type = SHT_HASH; @@ -1449,9 +1446,9 @@ private: template <class ELFT> class EHFrameHeader : public Section<ELFT> { public: - EHFrameHeader(const ELFLinkingContext &context, StringRef name, + EHFrameHeader(const ELFLinkingContext &ctx, StringRef name, TargetLayout<ELFT> &layout, int32_t order) - : Section<ELFT>(context, name, "EHFrameHeader"), _ehFrameOffset(0), + : Section<ELFT>(ctx, name, "EHFrameHeader"), _ehFrameOffset(0), _layout(layout) { this->setOrder(order); this->_entSize = 0; diff --git a/lld/lib/ReaderWriter/ELF/SegmentChunks.h b/lld/lib/ReaderWriter/ELF/SegmentChunks.h index f2a975aaeed..7f6727940e8 100644 --- a/lld/lib/ReaderWriter/ELF/SegmentChunks.h +++ b/lld/lib/ReaderWriter/ELF/SegmentChunks.h @@ -100,7 +100,7 @@ public: typedef typename std::vector<SegmentSlice<ELFT> *>::iterator SliceIter; typedef typename std::vector<Chunk<ELFT> *>::iterator SectionIter; - Segment(const ELFLinkingContext &context, StringRef name, + Segment(const ELFLinkingContext &ctx, StringRef name, const Layout::SegmentType type); /// \brief the Order of segments that appear in the output file @@ -209,7 +209,7 @@ public: } } - int pageSize() const { return this->_context.getPageSize(); } + int pageSize() const { return this->_ctx.getPageSize(); } int rawflags() const { return _atomflags; } @@ -304,8 +304,8 @@ private: /// The segment doesn't contain any slice template <class ELFT> class ProgramHeaderSegment : public Segment<ELFT> { public: - ProgramHeaderSegment(const ELFLinkingContext &context) - : Segment<ELFT>(context, "PHDR", llvm::ELF::PT_PHDR) { + ProgramHeaderSegment(const ELFLinkingContext &ctx) + : Segment<ELFT>(ctx, "PHDR", llvm::ELF::PT_PHDR) { this->_alignment = 8; this->_flags = (llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR); } @@ -326,13 +326,13 @@ public: }; template <class ELFT> -Segment<ELFT>::Segment(const ELFLinkingContext &context, StringRef name, +Segment<ELFT>::Segment(const ELFLinkingContext &ctx, StringRef name, const Layout::SegmentType type) - : Chunk<ELFT>(name, Chunk<ELFT>::Kind::ELFSegment, context), - _segmentType(type), _flags(0), _atomflags(0) { + : Chunk<ELFT>(name, Chunk<ELFT>::Kind::ELFSegment, ctx), _segmentType(type), + _flags(0), _atomflags(0) { this->_alignment = 0; this->_fsize = 0; - _outputMagic = context.getOutputMagic(); + _outputMagic = ctx.getOutputMagic(); } // This function actually is used, but not in all instantiations of Segment. @@ -419,8 +419,8 @@ void Segment<ELFT>::assignFileOffsets(uint64_t startOffset) { uint64_t fileOffset = startOffset; uint64_t curSliceFileOffset = fileOffset; bool isDataPageAlignedForNMagic = false; - bool alignSegments = this->_context.alignSegments(); - uint64_t p_align = this->_context.getPageSize(); + bool alignSegments = this->_ctx.alignSegments(); + uint64_t p_align = this->_ctx.getPageSize(); uint64_t lastVirtualAddress = 0; this->setFileOffset(startOffset); @@ -455,7 +455,7 @@ void Segment<ELFT>::assignFileOffsets(uint64_t startOffset) { } } else if (!isDataPageAlignedForNMagic && needAlign(section)) { fileOffset = - llvm::RoundUpToAlignment(fileOffset, this->_context.getPageSize()); + llvm::RoundUpToAlignment(fileOffset, this->_ctx.getPageSize()); isDataPageAlignedForNMagic = true; } if (isFirstSection) { @@ -493,7 +493,7 @@ template <class ELFT> void Segment<ELFT>::assignVirtualAddress(uint64_t addr) { uint64_t startAddr = addr; SegmentSlice<ELFT> *slice = nullptr; uint64_t tlsStartAddr = 0; - bool alignSegments = this->_context.alignSegments(); + bool alignSegments = this->_ctx.alignSegments(); StringRef prevOutputSectionName = StringRef(); for (auto si = _sections.begin(); si != _sections.end(); ++si) { @@ -508,12 +508,12 @@ template <class ELFT> void Segment<ELFT>::assignVirtualAddress(uint64_t addr) { // Align to a page only if the output is not // OutputMagic::NMAGIC/OutputMagic::OMAGIC startAddr = - llvm::RoundUpToAlignment(startAddr, this->_context.getPageSize()); + llvm::RoundUpToAlignment(startAddr, this->_ctx.getPageSize()); else if (!isDataPageAlignedForNMagic && needAlign(*si)) { // If the linker outputmagic is set to OutputMagic::NMAGIC, align the // Data to a page boundary. startAddr = - llvm::RoundUpToAlignment(startAddr, this->_context.getPageSize()); + llvm::RoundUpToAlignment(startAddr, this->_ctx.getPageSize()); isDataPageAlignedForNMagic = true; } // align the startOffset to the section alignment @@ -549,8 +549,7 @@ template <class ELFT> void Segment<ELFT>::assignVirtualAddress(uint64_t addr) { // If the linker outputmagic is set to OutputMagic::NMAGIC, align the // Data // to a page boundary - curAddr = - llvm::RoundUpToAlignment(curAddr, this->_context.getPageSize()); + curAddr = llvm::RoundUpToAlignment(curAddr, this->_ctx.getPageSize()); isDataPageAlignedForNMagic = true; } uint64_t newAddr = llvm::RoundUpToAlignment(curAddr, (*si)->alignment()); @@ -577,8 +576,7 @@ template <class ELFT> void Segment<ELFT>::assignVirtualAddress(uint64_t addr) { // a separate segment, so that memory is not used up while running. // Dont create a slice, if the new section falls in the same output // section as the previous section. - if (autoCreateSlice && - ((newAddr - curAddr) > this->_context.getPageSize()) && + if (autoCreateSlice && ((newAddr - curAddr) > this->_ctx.getPageSize()) && (_outputMagic != ELFLinkingContext::OutputMagic::NMAGIC && _outputMagic != ELFLinkingContext::OutputMagic::OMAGIC)) { auto sliceIter = diff --git a/lld/lib/ReaderWriter/ELF/TargetLayout.h b/lld/lib/ReaderWriter/ELF/TargetLayout.h index ab7a7890a27..1bb0363eb16 100644 --- a/lld/lib/ReaderWriter/ELF/TargetLayout.h +++ b/lld/lib/ReaderWriter/ELF/TargetLayout.h @@ -20,7 +20,7 @@ namespace elf { /// be changed in the final layout template <class ELFT> class TargetLayout : public DefaultLayout<ELFT> { public: - TargetLayout(ELFLinkingContext &context) : DefaultLayout<ELFT>(context) {} + TargetLayout(ELFLinkingContext &ctx) : DefaultLayout<ELFT>(ctx) {} }; } // end namespace elf } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h index 86376295bec..185d45b971a 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h @@ -18,7 +18,7 @@ namespace elf { template <class ELFT> class X86DynamicLibraryWriter : public DynamicLibraryWriter<ELFT> { public: - X86DynamicLibraryWriter(X86LinkingContext &context, + X86DynamicLibraryWriter(X86LinkingContext &ctx, X86TargetLayout<ELFT> &layout); protected: @@ -41,15 +41,15 @@ private: }; std::unique_ptr<GOTFile> _gotFile; - X86LinkingContext &_context; + X86LinkingContext &_ctx; X86TargetLayout<ELFT> &_x86Layout; }; template <class ELFT> X86DynamicLibraryWriter<ELFT>::X86DynamicLibraryWriter( - X86LinkingContext &context, X86TargetLayout<ELFT> &layout) - : DynamicLibraryWriter<ELFT>(context, layout), - _gotFile(new GOTFile(context)), _context(context), _x86Layout(layout) {} + X86LinkingContext &ctx, X86TargetLayout<ELFT> &layout) + : DynamicLibraryWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)), + _ctx(ctx), _x86Layout(layout) {} template <class ELFT> bool X86DynamicLibraryWriter<ELFT>::createImplicitFiles( diff --git a/lld/lib/ReaderWriter/ELF/X86/X86ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/X86/X86ExecutableWriter.h index 68acc06c226..cfbe5f42202 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86ExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86ExecutableWriter.h @@ -18,8 +18,7 @@ namespace elf { template <class ELFT> class X86ExecutableWriter : public ExecutableWriter<ELFT> { public: - X86ExecutableWriter(X86LinkingContext &context, - X86TargetLayout<ELFT> &layout); + X86ExecutableWriter(X86LinkingContext &ctx, X86TargetLayout<ELFT> &layout); protected: // Add any runtime files and their atoms to the output @@ -34,15 +33,14 @@ protected: } private: - X86LinkingContext &_context; + X86LinkingContext &_ctx; X86TargetLayout<ELFT> &_x86Layout; }; template <class ELFT> -X86ExecutableWriter<ELFT>::X86ExecutableWriter(X86LinkingContext &context, +X86ExecutableWriter<ELFT>::X86ExecutableWriter(X86LinkingContext &ctx, X86TargetLayout<ELFT> &layout) - : ExecutableWriter<ELFT>(context, layout), _context(context), - _x86Layout(layout) {} + : ExecutableWriter<ELFT>(ctx, layout), _ctx(ctx), _x86Layout(layout) {} template <class ELFT> bool X86ExecutableWriter<ELFT>::createImplicitFiles( diff --git a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp index 211671e8741..bf9fed63e9d 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.cpp @@ -19,13 +19,13 @@ using namespace elf; using namespace llvm::ELF; std::unique_ptr<Writer> X86TargetHandler::getWriter() { - switch (_x86LinkingContext.getOutputELFType()) { + switch (_ctx.getOutputELFType()) { case llvm::ELF::ET_EXEC: return llvm::make_unique<X86ExecutableWriter<X86ELFType>>( - _x86LinkingContext, *_x86TargetLayout.get()); + _ctx, *_x86TargetLayout.get()); case llvm::ELF::ET_DYN: return llvm::make_unique<X86DynamicLibraryWriter<X86ELFType>>( - _x86LinkingContext, *_x86TargetLayout.get()); + _ctx, *_x86TargetLayout.get()); case llvm::ELF::ET_REL: llvm_unreachable("TODO: support -r mode"); default: @@ -47,7 +47,6 @@ void X86TargetHandler::registerRelocationNames(Registry ®istry) { kindStrings); } -X86TargetHandler::X86TargetHandler(X86LinkingContext &context) - : _x86LinkingContext(context), - _x86TargetLayout(new X86TargetLayout<X86ELFType>(context)), +X86TargetHandler::X86TargetHandler(X86LinkingContext &ctx) + : _ctx(ctx), _x86TargetLayout(new X86TargetLayout<X86ELFType>(ctx)), _x86RelocationHandler(new X86TargetRelocationHandler()) {} diff --git a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h index 931f0b7e4fd..dbf25e8f23a 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h @@ -23,13 +23,13 @@ class X86LinkingContext; template <class ELFT> class X86TargetLayout : public TargetLayout<ELFT> { public: - X86TargetLayout(X86LinkingContext &context) : TargetLayout<ELFT>(context) {} + X86TargetLayout(X86LinkingContext &ctx) : TargetLayout<ELFT>(ctx) {} }; class X86TargetHandler final : public DefaultTargetHandler<X86ELFType> { public: - X86TargetHandler(X86LinkingContext &context); + X86TargetHandler(X86LinkingContext &ctx); X86TargetLayout<X86ELFType> &getTargetLayout() override { return *(_x86TargetLayout.get()); @@ -42,18 +42,18 @@ public: } std::unique_ptr<Reader> getObjReader() override { - return llvm::make_unique<X86ELFObjectReader>(_x86LinkingContext); + return llvm::make_unique<X86ELFObjectReader>(_ctx); } std::unique_ptr<Reader> getDSOReader() override { - return llvm::make_unique<X86ELFDSOReader>(_x86LinkingContext); + return llvm::make_unique<X86ELFDSOReader>(_ctx); } std::unique_ptr<Writer> getWriter() override; protected: static const Registry::KindStrings kindStrings[]; - X86LinkingContext &_x86LinkingContext; + X86LinkingContext &_ctx; std::unique_ptr<X86TargetLayout<X86ELFType>> _x86TargetLayout; std::unique_ptr<X86TargetRelocationHandler> _x86RelocationHandler; }; diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h index b996186115b..44af61180dd 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h @@ -19,7 +19,7 @@ namespace elf { class X86_64DynamicLibraryWriter : public DynamicLibraryWriter<X86_64ELFType> { public: - X86_64DynamicLibraryWriter(X86_64LinkingContext &context, + X86_64DynamicLibraryWriter(X86_64LinkingContext &ctx, X86_64TargetLayout &layout); protected: @@ -45,8 +45,8 @@ private: }; X86_64DynamicLibraryWriter::X86_64DynamicLibraryWriter( - X86_64LinkingContext &context, X86_64TargetLayout &layout) - : DynamicLibraryWriter(context, layout), _gotFile(new GOTFile(context)) {} + X86_64LinkingContext &ctx, X86_64TargetLayout &layout) + : DynamicLibraryWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {} bool X86_64DynamicLibraryWriter::createImplicitFiles( std::vector<std::unique_ptr<File>> &result) { diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h index f549ed6dcfc..166b9f21314 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h @@ -18,10 +18,8 @@ namespace elf { class X86_64ExecutableWriter : public ExecutableWriter<X86_64ELFType> { public: - X86_64ExecutableWriter(X86_64LinkingContext &context, - X86_64TargetLayout &layout) - : ExecutableWriter(context, layout), _gotFile(new GOTFile(context)), - _context(context) {} + X86_64ExecutableWriter(X86_64LinkingContext &ctx, X86_64TargetLayout &layout) + : ExecutableWriter(ctx, layout), _gotFile(new GOTFile(ctx)), _ctx(ctx) {} protected: // Add any runtime files and their atoms to the output @@ -30,7 +28,7 @@ protected: ExecutableWriter::createImplicitFiles(result); _gotFile->addAtom(*new (_gotFile->_alloc) GLOBAL_OFFSET_TABLEAtom(*_gotFile)); - if (_context.isDynamic()) + if (_ctx.isDynamic()) _gotFile->addAtom(*new (_gotFile->_alloc) DYNAMICAtom(*_gotFile)); result.push_back(std::move(_gotFile)); return true; @@ -52,7 +50,7 @@ private: }; std::unique_ptr<GOTFile> _gotFile; - X86_64LinkingContext &_context; + X86_64LinkingContext &_ctx; }; } // namespace elf diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp index 21cb5915db9..5c0b13b7535 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp @@ -16,8 +16,8 @@ using namespace lld; using namespace elf; -X86_64TargetHandler::X86_64TargetHandler(X86_64LinkingContext &context) - : _context(context), _x86_64TargetLayout(new X86_64TargetLayout(context)), +X86_64TargetHandler::X86_64TargetHandler(X86_64LinkingContext &ctx) + : _ctx(ctx), _x86_64TargetLayout(new X86_64TargetLayout(ctx)), _x86_64RelocationHandler( new X86_64TargetRelocationHandler(*_x86_64TargetLayout.get())) {} @@ -27,13 +27,13 @@ void X86_64TargetHandler::registerRelocationNames(Registry ®istry) { } std::unique_ptr<Writer> X86_64TargetHandler::getWriter() { - switch (this->_context.getOutputELFType()) { + switch (this->_ctx.getOutputELFType()) { case llvm::ELF::ET_EXEC: return llvm::make_unique<X86_64ExecutableWriter>( - _context, *_x86_64TargetLayout.get()); + _ctx, *_x86_64TargetLayout.get()); case llvm::ELF::ET_DYN: return llvm::make_unique<X86_64DynamicLibraryWriter>( - _context, *_x86_64TargetLayout.get()); + _ctx, *_x86_64TargetLayout.get()); case llvm::ELF::ET_REL: llvm_unreachable("TODO: support -r mode"); default: diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h index 8094aef8a36..68ec566f9a9 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h @@ -22,8 +22,7 @@ namespace lld { namespace elf { class X86_64TargetLayout : public TargetLayout<X86_64ELFType> { public: - X86_64TargetLayout(X86_64LinkingContext &context) - : TargetLayout(context) {} + X86_64TargetLayout(X86_64LinkingContext &ctx) : TargetLayout(ctx) {} void finalizeOutputSectionLayout() override { sortOutputSectionByPriority(".init_array", ".init_array"); @@ -34,7 +33,7 @@ public: class X86_64TargetHandler : public DefaultTargetHandler<X86_64ELFType> { public: - X86_64TargetHandler(X86_64LinkingContext &context); + X86_64TargetHandler(X86_64LinkingContext &ctx); X86_64TargetLayout &getTargetLayout() override { return *(_x86_64TargetLayout.get()); @@ -47,18 +46,18 @@ public: } std::unique_ptr<Reader> getObjReader() override { - return llvm::make_unique<X86_64ELFObjectReader>(_context); + return llvm::make_unique<X86_64ELFObjectReader>(_ctx); } std::unique_ptr<Reader> getDSOReader() override { - return llvm::make_unique<X86_64ELFDSOReader>(_context); + return llvm::make_unique<X86_64ELFDSOReader>(_ctx); } std::unique_ptr<Writer> getWriter() override; protected: static const Registry::KindStrings kindStrings[]; - X86_64LinkingContext &_context; + X86_64LinkingContext &_ctx; std::unique_ptr<X86_64TargetLayout> _x86_64TargetLayout; std::unique_ptr<X86_64TargetRelocationHandler> _x86_64RelocationHandler; }; |

