Skip to content

Commit 3d57c79

Browse files
committed
[ELF] Migrate away from global ctx
1 parent 47928ab commit 3d57c79

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

lld/ELF/EhFrame.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "EhFrame.h"
1919
#include "Config.h"
20+
#include "InputFiles.h"
2021
#include "InputSection.h"
2122
#include "Relocations.h"
2223
#include "Target.h"
@@ -41,6 +42,7 @@ class EhReader {
4142

4243
private:
4344
template <class P> void failOn(const P *loc, const Twine &msg) {
45+
Ctx &ctx = isec->file->ctx;
4446
Fatal(ctx) << "corrupted .eh_frame: " << msg << "\n>>> defined in "
4547
<< isec->getObjMsg((const uint8_t *)loc -
4648
isec->content().data());

lld/ELF/InputSection.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
7777
// longer supported.
7878
if (flags & SHF_COMPRESSED) {
7979
Ctx &ctx = file->ctx;
80-
invokeELFT(parseCompressedHeader,);
80+
invokeELFT(parseCompressedHeader, ctx);
8181
}
8282
}
8383

@@ -251,7 +251,8 @@ OutputSection *SectionBase::getOutputSection() {
251251
// When a section is compressed, `rawData` consists with a header followed
252252
// by zlib-compressed data. This function parses a header to initialize
253253
// `uncompressedSize` member and remove the header from `rawData`.
254-
template <typename ELFT> void InputSectionBase::parseCompressedHeader() {
254+
template <typename ELFT>
255+
void InputSectionBase::parseCompressedHeader(Ctx &ctx) {
255256
flags &= ~(uint64_t)SHF_COMPRESSED;
256257

257258
// New-style header
@@ -639,7 +640,7 @@ static uint64_t getARMStaticBase(const Symbol &sym) {
639640
//
640641
// This function returns the R_RISCV_PCREL_HI20 relocation from the
641642
// R_RISCV_PCREL_LO12 relocation.
642-
static Relocation *getRISCVPCRelHi20(const InputSectionBase *loSec,
643+
static Relocation *getRISCVPCRelHi20(Ctx &ctx, const InputSectionBase *loSec,
643644
const Relocation &loReloc) {
644645
uint64_t addend = loReloc.addend;
645646
Symbol *sym = loReloc.sym;
@@ -850,7 +851,7 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
850851
return getAArch64Page(val) - getAArch64Page(p);
851852
}
852853
case R_RISCV_PC_INDIRECT: {
853-
if (const Relocation *hiRel = getRISCVPCRelHi20(this, r))
854+
if (const Relocation *hiRel = getRISCVPCRelHi20(ctx, this, r))
854855
return getRelocTargetVA(ctx, *hiRel, r.sym->getVA(ctx));
855856
return 0;
856857
}
@@ -1369,8 +1370,9 @@ void EhInputSection::split(ArrayRef<RelTy> rels) {
13691370
d = d.slice(size);
13701371
}
13711372
if (msg)
1372-
Err(ctx) << "corrupted .eh_frame: " << Twine(msg) << "\n>>> defined in "
1373-
<< getObjMsg(d.data() - content().data());
1373+
Err(file->ctx) << "corrupted .eh_frame: " << Twine(msg)
1374+
<< "\n>>> defined in "
1375+
<< getObjMsg(d.data() - content().data());
13741376
}
13751377

13761378
// Return the offset in an output section for a given input offset.

lld/ELF/InputSection.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ class InputSectionBase : public SectionBase {
287287
}
288288

289289
protected:
290-
template <typename ELFT>
291-
void parseCompressedHeader();
290+
template <typename ELFT> void parseCompressedHeader(Ctx &);
292291
void decompress() const;
293292
};
294293

lld/ELF/LinkerScript.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ void LinkerScript::recordError(const Twine &msg) {
17661766
msg.toVector(str);
17671767
}
17681768

1769-
static void checkMemoryRegion(const MemoryRegion *region,
1769+
static void checkMemoryRegion(Ctx &ctx, const MemoryRegion *region,
17701770
const OutputSection *osec, uint64_t addr) {
17711771
uint64_t osecEnd = addr + osec->size;
17721772
uint64_t regionEnd = region->getOrigin() + region->getLength();
@@ -1782,9 +1782,9 @@ void LinkerScript::checkFinalScriptConditions() const {
17821782
Err(ctx) << err;
17831783
for (const OutputSection *sec : ctx.outputSections) {
17841784
if (const MemoryRegion *memoryRegion = sec->memRegion)
1785-
checkMemoryRegion(memoryRegion, sec, sec->addr);
1785+
checkMemoryRegion(ctx, memoryRegion, sec, sec->addr);
17861786
if (const MemoryRegion *lmaRegion = sec->lmaRegion)
1787-
checkMemoryRegion(lmaRegion, sec, sec->getLMA());
1787+
checkMemoryRegion(ctx, lmaRegion, sec, sec->getLMA());
17881788
}
17891789
}
17901790

lld/ELF/Relocations.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class OffsetGetter {
430430
// Translates offsets in input sections to offsets in output sections.
431431
// Given offset must increase monotonically. We assume that Piece is
432432
// sorted by inputOff.
433-
uint64_t get(uint64_t off) {
433+
uint64_t get(Ctx &ctx, uint64_t off) {
434434
if (cies.empty())
435435
return off;
436436

@@ -1466,7 +1466,7 @@ void RelocationScanner::scanOne(typename Relocs<RelTy>::const_iterator &i) {
14661466
}
14671467
}
14681468
// Get an offset in an output section this relocation is applied to.
1469-
uint64_t offset = getter.get(rel.r_offset);
1469+
uint64_t offset = getter.get(ctx, rel.r_offset);
14701470
if (offset == uint64_t(-1))
14711471
return;
14721472

@@ -1587,10 +1587,11 @@ static void checkPPC64TLSRelax(InputSectionBase &sec, Relocs<RelTy> rels) {
15871587
}
15881588
if (hasGDLD) {
15891589
sec.file->ppc64DisableTLSRelax = true;
1590-
Warn(ctx) << sec.file
1591-
<< ": disable TLS relaxation due to R_PPC64_GOT_TLS* relocations "
1592-
"without "
1593-
"R_PPC64_TLSGD/R_PPC64_TLSLD relocations";
1590+
Warn(sec.file->ctx)
1591+
<< sec.file
1592+
<< ": disable TLS relaxation due to R_PPC64_GOT_TLS* relocations "
1593+
"without "
1594+
"R_PPC64_TLSGD/R_PPC64_TLSLD relocations";
15941595
}
15951596
}
15961597

0 commit comments

Comments
 (0)