diff --git a/lld/ELF/EhFrame.cpp b/lld/ELF/EhFrame.cpp index 9539585d5ece..6e0120e14988 100644 --- a/lld/ELF/EhFrame.cpp +++ b/lld/ELF/EhFrame.cpp @@ -17,6 +17,7 @@ #include "EhFrame.h" #include "Config.h" +#include "InputFiles.h" #include "InputSection.h" #include "Relocations.h" #include "Target.h" @@ -41,6 +42,7 @@ public: private: template void failOn(const P *loc, const Twine &msg) { + Ctx &ctx = isec->file->ctx; Fatal(ctx) << "corrupted .eh_frame: " << msg << "\n>>> defined in " << isec->getObjMsg((const uint8_t *)loc - isec->content().data()); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 48e59ad27803..932c32738810 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -77,7 +77,7 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags, // longer supported. if (flags & SHF_COMPRESSED) { Ctx &ctx = file->ctx; - invokeELFT(parseCompressedHeader,); + invokeELFT(parseCompressedHeader, ctx); } } @@ -251,7 +251,8 @@ OutputSection *SectionBase::getOutputSection() { // When a section is compressed, `rawData` consists with a header followed // by zlib-compressed data. This function parses a header to initialize // `uncompressedSize` member and remove the header from `rawData`. -template void InputSectionBase::parseCompressedHeader() { +template +void InputSectionBase::parseCompressedHeader(Ctx &ctx) { flags &= ~(uint64_t)SHF_COMPRESSED; // New-style header @@ -639,7 +640,7 @@ static uint64_t getARMStaticBase(const Symbol &sym) { // // This function returns the R_RISCV_PCREL_HI20 relocation from the // R_RISCV_PCREL_LO12 relocation. -static Relocation *getRISCVPCRelHi20(const InputSectionBase *loSec, +static Relocation *getRISCVPCRelHi20(Ctx &ctx, const InputSectionBase *loSec, const Relocation &loReloc) { uint64_t addend = loReloc.addend; Symbol *sym = loReloc.sym; @@ -850,7 +851,7 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r, return getAArch64Page(val) - getAArch64Page(p); } case R_RISCV_PC_INDIRECT: { - if (const Relocation *hiRel = getRISCVPCRelHi20(this, r)) + if (const Relocation *hiRel = getRISCVPCRelHi20(ctx, this, r)) return getRelocTargetVA(ctx, *hiRel, r.sym->getVA(ctx)); return 0; } @@ -1369,8 +1370,9 @@ void EhInputSection::split(ArrayRef rels) { d = d.slice(size); } if (msg) - Err(ctx) << "corrupted .eh_frame: " << Twine(msg) << "\n>>> defined in " - << getObjMsg(d.data() - content().data()); + Err(file->ctx) << "corrupted .eh_frame: " << Twine(msg) + << "\n>>> defined in " + << getObjMsg(d.data() - content().data()); } // Return the offset in an output section for a given input offset. diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 5511bb5e2c44..482d63cfb610 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -287,8 +287,7 @@ public: } protected: - template - void parseCompressedHeader(); + template void parseCompressedHeader(Ctx &); void decompress() const; }; diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 46efb530af63..ca4877b25a1f 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -1766,7 +1766,7 @@ void LinkerScript::recordError(const Twine &msg) { msg.toVector(str); } -static void checkMemoryRegion(const MemoryRegion *region, +static void checkMemoryRegion(Ctx &ctx, const MemoryRegion *region, const OutputSection *osec, uint64_t addr) { uint64_t osecEnd = addr + osec->size; uint64_t regionEnd = region->getOrigin() + region->getLength(); @@ -1782,9 +1782,9 @@ void LinkerScript::checkFinalScriptConditions() const { Err(ctx) << err; for (const OutputSection *sec : ctx.outputSections) { if (const MemoryRegion *memoryRegion = sec->memRegion) - checkMemoryRegion(memoryRegion, sec, sec->addr); + checkMemoryRegion(ctx, memoryRegion, sec, sec->addr); if (const MemoryRegion *lmaRegion = sec->lmaRegion) - checkMemoryRegion(lmaRegion, sec, sec->getLMA()); + checkMemoryRegion(ctx, lmaRegion, sec, sec->getLMA()); } } diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index bd2cfcc7f8fb..261ef9f832d9 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -430,7 +430,7 @@ public: // Translates offsets in input sections to offsets in output sections. // Given offset must increase monotonically. We assume that Piece is // sorted by inputOff. - uint64_t get(uint64_t off) { + uint64_t get(Ctx &ctx, uint64_t off) { if (cies.empty()) return off; @@ -1466,7 +1466,7 @@ void RelocationScanner::scanOne(typename Relocs::const_iterator &i) { } } // Get an offset in an output section this relocation is applied to. - uint64_t offset = getter.get(rel.r_offset); + uint64_t offset = getter.get(ctx, rel.r_offset); if (offset == uint64_t(-1)) return; @@ -1587,10 +1587,11 @@ static void checkPPC64TLSRelax(InputSectionBase &sec, Relocs rels) { } if (hasGDLD) { sec.file->ppc64DisableTLSRelax = true; - Warn(ctx) << sec.file - << ": disable TLS relaxation due to R_PPC64_GOT_TLS* relocations " - "without " - "R_PPC64_TLSGD/R_PPC64_TLSLD relocations"; + Warn(sec.file->ctx) + << sec.file + << ": disable TLS relaxation due to R_PPC64_GOT_TLS* relocations " + "without " + "R_PPC64_TLSGD/R_PPC64_TLSLD relocations"; } }