[lld] 3d57c79 - [ELF] Migrate away from global ctx
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 14 22:50:59 PST 2024
Author: Fangrui Song
Date: 2024-11-14T22:50:53-08:00
New Revision: 3d57c79728968e291df4929b377b3580d16af7b9
URL: https://github.com/llvm/llvm-project/commit/3d57c79728968e291df4929b377b3580d16af7b9
DIFF: https://github.com/llvm/llvm-project/commit/3d57c79728968e291df4929b377b3580d16af7b9.diff
LOG: [ELF] Migrate away from global ctx
Added:
Modified:
lld/ELF/EhFrame.cpp
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/ELF/LinkerScript.cpp
lld/ELF/Relocations.cpp
Removed:
################################################################################
diff --git a/lld/ELF/EhFrame.cpp b/lld/ELF/EhFrame.cpp
index 9539585d5ecea8..6e0120e14988b4 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 @@ class EhReader {
private:
template <class P> 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 48e59ad2780328..932c327388102d 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 <typename ELFT> void InputSectionBase::parseCompressedHeader() {
+template <typename ELFT>
+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<RelTy> 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 5511bb5e2c44d5..482d63cfb610af 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -287,8 +287,7 @@ class InputSectionBase : public SectionBase {
}
protected:
- template <typename ELFT>
- void parseCompressedHeader();
+ template <typename ELFT> void parseCompressedHeader(Ctx &);
void decompress() const;
};
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 46efb530af6381..ca4877b25a1f11 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 bd2cfcc7f8fb45..261ef9f832d9c2 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -430,7 +430,7 @@ class OffsetGetter {
// 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<RelTy>::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<RelTy> 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";
}
}
More information about the llvm-commits
mailing list