Skip to content

Commit 942928f

Browse files
committed
[ELF] Migrate away from global ctx
1 parent dde802b commit 942928f

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

lld/ELF/Arch/X86_64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ static void relaxGot(uint8_t *loc, const Relocation &rel, uint64_t val) {
10021002
if (op != 0xff) {
10031003
// We are relaxing a rip relative to an absolute, so compensate
10041004
// for the old -4 addend.
1005-
assert(!ctx.arg.isPic);
1005+
assert(!rel.sym->file || !rel.sym->file->ctx.arg.isPic);
10061006
relaxGotNoPic(loc, val + 4, op, modRm, rel.type == R_X86_64_REX2_GOTPCRELX);
10071007
return;
10081008
}

lld/ELF/DriverUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ELFOptTable::ELFOptTable() : GenericOptTable(optInfo) {}
5252

5353
// Set color diagnostics according to --color-diagnostics={auto,always,never}
5454
// or --no-color-diagnostics flags.
55-
static void handleColorDiagnostics(opt::InputArgList &args) {
55+
static void handleColorDiagnostics(Ctx &ctx, opt::InputArgList &args) {
5656
auto *arg = args.getLastArg(OPT_color_diagnostics);
5757
if (!arg)
5858
return;
@@ -121,7 +121,7 @@ opt::InputArgList ELFOptTable::parse(Ctx &ctx, ArrayRef<const char *> argv) {
121121
concatLTOPluginOptions(vec);
122122
args = this->ParseArgs(vec, missingIndex, missingCount);
123123

124-
handleColorDiagnostics(args);
124+
handleColorDiagnostics(ctx, args);
125125
if (missingCount)
126126
ErrAlways(ctx) << Twine(args.getArgString(missingIndex))
127127
<< ": missing argument";

lld/ELF/InputFiles.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const ELFSyncStream &elf::operator<<(const ELFSyncStream &s,
7171
return s << toString(f);
7272
}
7373

74-
static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
74+
static ELFKind getELFKind(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName) {
7575
unsigned char size;
7676
unsigned char endian;
7777
std::tie(size, endian) = getElfArchType(mb.getBuffer());
@@ -1350,7 +1350,7 @@ static bool isNonCommonDef(Ctx &ctx, ELFKind ekind, MemoryBufferRef mb,
13501350

13511351
static bool isNonCommonDef(Ctx &ctx, MemoryBufferRef mb, StringRef symName,
13521352
StringRef archiveName) {
1353-
switch (getELFKind(mb, archiveName)) {
1353+
switch (getELFKind(ctx, mb, archiveName)) {
13541354
case ELF32LEKind:
13551355
return isNonCommonDef<ELF32LE>(ctx, ELF32LEKind, mb, symName, archiveName);
13561356
case ELF32BEKind:
@@ -1367,8 +1367,8 @@ static bool isNonCommonDef(Ctx &ctx, MemoryBufferRef mb, StringRef symName,
13671367
unsigned SharedFile::vernauxNum;
13681368

13691369
SharedFile::SharedFile(Ctx &ctx, MemoryBufferRef m, StringRef defaultSoName)
1370-
: ELFFileBase(ctx, SharedKind, getELFKind(m, ""), m), soName(defaultSoName),
1371-
isNeeded(!ctx.arg.asNeeded) {}
1370+
: ELFFileBase(ctx, SharedKind, getELFKind(ctx, m, ""), m),
1371+
soName(defaultSoName), isNeeded(!ctx.arg.asNeeded) {}
13721372

13731373
// Parse the version definitions in the object file if present, and return a
13741374
// vector whose nth element contains a pointer to the Elf_Verdef for version
@@ -1641,7 +1641,8 @@ static ELFKind getBitcodeELFKind(const Triple &t) {
16411641
return t.isArch64Bit() ? ELF64BEKind : ELF32BEKind;
16421642
}
16431643

1644-
static uint16_t getBitcodeMachineKind(StringRef path, const Triple &t) {
1644+
static uint16_t getBitcodeMachineKind(Ctx &ctx, StringRef path,
1645+
const Triple &t) {
16451646
switch (t.getArch()) {
16461647
case Triple::aarch64:
16471648
case Triple::aarch64_be:
@@ -1732,7 +1733,7 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17321733

17331734
Triple t(obj->getTargetTriple());
17341735
ekind = getBitcodeELFKind(t);
1735-
emachine = getBitcodeMachineKind(mb.getBufferIdentifier(), t);
1736+
emachine = getBitcodeMachineKind(ctx, mb.getBufferIdentifier(), t);
17361737
osabi = getOsAbi(t);
17371738
}
17381739

@@ -1883,7 +1884,7 @@ InputFile *elf::createInternalFile(Ctx &ctx, StringRef name) {
18831884
ELFFileBase *elf::createObjFile(Ctx &ctx, MemoryBufferRef mb,
18841885
StringRef archiveName, bool lazy) {
18851886
ELFFileBase *f;
1886-
switch (getELFKind(mb, archiveName)) {
1887+
switch (getELFKind(ctx, mb, archiveName)) {
18871888
case ELF32LEKind:
18881889
f = make<ObjFile<ELF32LE>>(ctx, ELF32LEKind, mb, archiveName);
18891890
break;

lld/ELF/InputSection.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
6464
// sections are smaller than 4 GiB, which is not an unreasonable
6565
// assumption as of 2017.
6666
if (sectionKind == SectionBase::Merge && content().size() > UINT32_MAX)
67-
ErrAlways(ctx) << this << ": section too large";
67+
ErrAlways(getCtx()) << this << ": section too large";
6868

6969
// The ELF spec states that a value of 0 means the section has
7070
// no alignment constraints.
7171
uint32_t v = std::max<uint32_t>(addralign, 1);
7272
if (!isPowerOf2_64(v))
73-
Fatal(ctx) << this << ": sh_addralign is not a power of 2";
73+
Fatal(getCtx()) << this << ": sh_addralign is not a power of 2";
7474
this->addralign = v;
7575

7676
// If SHF_COMPRESSED is set, parse the header. The legacy .zdebug format is no
@@ -103,7 +103,7 @@ InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
103103
// they are allowed by the spec. I think 4GB is a reasonable limitation.
104104
// We might want to relax this in the future.
105105
if (hdr.sh_addralign > UINT32_MAX)
106-
Fatal(ctx) << &file << ": section sh_addralign is too large";
106+
Fatal(getCtx()) << &file << ": section sh_addralign is too large";
107107
}
108108

109109
size_t InputSectionBase::getSize() const {
@@ -629,8 +629,8 @@ static uint64_t getRISCVUndefinedRelativeWeakVA(uint64_t type, uint64_t p) {
629629
static uint64_t getARMStaticBase(const Symbol &sym) {
630630
OutputSection *os = sym.getOutputSection();
631631
if (!os || !os->ptLoad || !os->ptLoad->firstSec)
632-
Fatal(ctx) << "SBREL relocation to " << sym.getName()
633-
<< " without static base";
632+
Fatal(os->ctx) << "SBREL relocation to " << sym.getName()
633+
<< " without static base";
634634
return os->ptLoad->firstSec->addr;
635635
}
636636

@@ -1405,7 +1405,7 @@ void MergeInputSection::splitStrings(StringRef s, size_t entSize) {
14051405
const bool live = !(flags & SHF_ALLOC) || !getCtx().arg.gcSections;
14061406
const char *p = s.data(), *end = s.data() + s.size();
14071407
if (!std::all_of(end - entSize, end, [](char c) { return c == 0; }))
1408-
Fatal(ctx) << this << ": string is not null terminated";
1408+
Fatal(getCtx()) << this << ": string is not null terminated";
14091409
if (entSize == 1) {
14101410
// Optimize the common case.
14111411
do {
@@ -1465,7 +1465,7 @@ void MergeInputSection::splitIntoPieces() {
14651465

14661466
SectionPiece &MergeInputSection::getSectionPiece(uint64_t offset) {
14671467
if (content().size() <= offset)
1468-
Fatal(ctx) << this << ": offset is outside the section";
1468+
Fatal(getCtx()) << this << ": offset is outside the section";
14691469
return partition_point(
14701470
pieces, [=](SectionPiece p) { return p.inputOff <= offset; })[-1];
14711471
}

lld/ELF/OutputSections.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ static void fill(uint8_t *buf, size_t size,
308308
}
309309

310310
#if LLVM_ENABLE_ZLIB
311-
static SmallVector<uint8_t, 0> deflateShard(ArrayRef<uint8_t> in, int level,
312-
int flush) {
311+
static SmallVector<uint8_t, 0> deflateShard(Ctx &ctx, ArrayRef<uint8_t> in,
312+
int level, int flush) {
313313
// 15 and 8 are default. windowBits=-15 is negative to generate raw deflate
314314
// data with no zlib header or trailer.
315315
z_stream s = {};
@@ -432,7 +432,7 @@ template <class ELFT> void OutputSection::maybeCompress(Ctx &ctx) {
432432
// concatenated with the next shard.
433433
auto shardsAdler = std::make_unique<uint32_t[]>(numShards);
434434
parallelFor(0, numShards, [&](size_t i) {
435-
shardsOut[i] = deflateShard(shardsIn[i], level,
435+
shardsOut[i] = deflateShard(ctx, shardsIn[i], level,
436436
i != numShards - 1 ? Z_SYNC_FLUSH : Z_FINISH);
437437
shardsAdler[i] = adler32(1, shardsIn[i].data(), shardsIn[i].size());
438438
});

0 commit comments

Comments
 (0)