From b672071ba51ef6b64651a62bcfaf78bdfdb7d3d4 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 6 Oct 2024 18:09:52 -0700 Subject: [ELF] Pass Ctx & to InputFile --- lld/ELF/InputFiles.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'lld/ELF/InputFiles.cpp') diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index d2ba5b2e4f8f..39a78a65bd7c 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -202,8 +202,8 @@ static void updateSupportedARMFeatures(Ctx &ctx, ctx.arg.armHasThumb2ISA |= thumb && *thumb >= ARMBuildAttrs::AllowThumb32; } -InputFile::InputFile(Kind k, MemoryBufferRef m) - : mb(m), groupId(ctx.driver.nextGroupId), fileKind(k) { +InputFile::InputFile(Ctx &ctx, Kind k, MemoryBufferRef m) + : ctx(ctx), mb(m), groupId(ctx.driver.nextGroupId), fileKind(k) { // All files within the same --{start,end}-group get the same group ID. // Otherwise, a new file will get a new group ID. if (!ctx.driver.isInGroup) @@ -509,8 +509,8 @@ ObjFile::getDILineInfo(const InputSectionBase *s, uint64_t offset) { return getDwarf()->getDILineInfo(offset, sectionIndex); } -ELFFileBase::ELFFileBase(Kind k, ELFKind ekind, MemoryBufferRef mb) - : InputFile(k, mb) { +ELFFileBase::ELFFileBase(Ctx &ctx, Kind k, ELFKind ekind, MemoryBufferRef mb) + : InputFile(ctx, k, mb) { this->ekind = ekind; } @@ -950,7 +950,8 @@ void ObjFile::initializeSections(bool ignoreComdats, // hardware-assisted call flow control; // - AArch64 PAuth ABI core info (16 bytes). template -void readGnuProperty(const InputSection &sec, ObjFile &f) { +static void readGnuProperty(Ctx &ctx, const InputSection &sec, + ObjFile &f) { using Elf_Nhdr = typename ELFT::Nhdr; using Elf_Note = typename ELFT::Note; @@ -1070,7 +1071,7 @@ InputSectionBase *ObjFile::createInputSection(uint32_t idx, // .note.gnu.property containing a single AND'ed bitmap, we discard an input // file's .note.gnu.property section. if (name == ".note.gnu.property") { - readGnuProperty(InputSection(*this, sec, name), *this); + readGnuProperty(ctx, InputSection(*this, sec, name), *this); return &InputSection::discarded; } @@ -1127,10 +1128,10 @@ void ObjFile::initializeSymbols(const object::ELFFile &obj) { } // Some entries have been filled by LazyObjFile. + auto *symtab = ctx.symtab.get(); for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i) if (!symbols[i]) - symbols[i] = - ctx.symtab->insert(CHECK(eSyms[i].getName(stringTable), this)); + symbols[i] = symtab->insert(CHECK(eSyms[i].getName(stringTable), this)); // Perform symbol resolution on non-local symbols. SmallVector undefineds; @@ -1325,7 +1326,7 @@ static bool isBitcodeNonCommonDef(MemoryBufferRef mb, StringRef symName, template static bool isNonCommonDef(ELFKind ekind, MemoryBufferRef mb, StringRef symName, StringRef archiveName) { - ObjFile *obj = make>(ekind, mb, archiveName); + ObjFile *obj = make>(ctx, ekind, mb, archiveName); obj->init(); StringRef stringtable = obj->getStringTable(); @@ -1357,7 +1358,7 @@ static bool isNonCommonDef(MemoryBufferRef mb, StringRef symName, unsigned SharedFile::vernauxNum; SharedFile::SharedFile(Ctx &ctx, MemoryBufferRef m, StringRef defaultSoName) - : ELFFileBase(SharedKind, getELFKind(m, ""), m), soName(defaultSoName), + : ELFFileBase(ctx, SharedKind, getELFKind(m, ""), m), soName(defaultSoName), isNeeded(!ctx.arg.asNeeded) {} // Parse the version definitions in the object file if present, and return a @@ -1697,7 +1698,7 @@ static uint8_t getOsAbi(const Triple &t) { BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName, uint64_t offsetInArchive, bool lazy) - : InputFile(BitcodeKind, mb) { + : InputFile(ctx, BitcodeKind, mb) { this->archiveName = archiveName; this->lazy = lazy; @@ -1859,30 +1860,30 @@ void BinaryFile::parse() { data.size(), 0, nullptr}); } -InputFile *elf::createInternalFile(StringRef name) { +InputFile *elf::createInternalFile(Ctx &ctx, StringRef name) { auto *file = - make(InputFile::InternalKind, MemoryBufferRef("", name)); + make(ctx, InputFile::InternalKind, MemoryBufferRef("", name)); // References from an internal file do not lead to --warn-backrefs // diagnostics. file->groupId = 0; return file; } -ELFFileBase *elf::createObjFile(MemoryBufferRef mb, StringRef archiveName, - bool lazy) { +ELFFileBase *elf::createObjFile(Ctx &ctx, MemoryBufferRef mb, + StringRef archiveName, bool lazy) { ELFFileBase *f; switch (getELFKind(mb, archiveName)) { case ELF32LEKind: - f = make>(ELF32LEKind, mb, archiveName); + f = make>(ctx, ELF32LEKind, mb, archiveName); break; case ELF32BEKind: - f = make>(ELF32BEKind, mb, archiveName); + f = make>(ctx, ELF32BEKind, mb, archiveName); break; case ELF64LEKind: - f = make>(ELF64LEKind, mb, archiveName); + f = make>(ctx, ELF64LEKind, mb, archiveName); break; case ELF64BEKind: - f = make>(ELF64BEKind, mb, archiveName); + f = make>(ctx, ELF64BEKind, mb, archiveName); break; default: llvm_unreachable("getELFKind"); -- cgit v1.2.3