Skip to content

Commit 6f48201

Browse files
committed
[ELF] Replace config-> with ctx.arg.
1 parent eb8d865 commit 6f48201

File tree

6 files changed

+47
-47
lines changed

6 files changed

+47
-47
lines changed

lld/ELF/CallGraphSort.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ using SectionPair =
112112
// Symbols, and generate a graph between InputSections with the provided
113113
// weights.
114114
CallGraphSort::CallGraphSort() {
115-
MapVector<SectionPair, uint64_t> &profile = config->callGraphProfile;
115+
MapVector<SectionPair, uint64_t> &profile = ctx.arg.callGraphProfile;
116116
DenseMap<const InputSectionBase *, int> secToCluster;
117117

118118
auto getOrCreateNode = [&](const InputSectionBase *isec) -> int {
@@ -243,11 +243,11 @@ DenseMap<const InputSectionBase *, int> CallGraphSort::run() {
243243
break;
244244
}
245245
}
246-
if (!config->printSymbolOrder.empty()) {
246+
if (!ctx.arg.printSymbolOrder.empty()) {
247247
std::error_code ec;
248-
raw_fd_ostream os(config->printSymbolOrder, ec, sys::fs::OF_None);
248+
raw_fd_ostream os(ctx.arg.printSymbolOrder, ec, sys::fs::OF_None);
249249
if (ec) {
250-
error("cannot open " + config->printSymbolOrder + ": " + ec.message());
250+
error("cannot open " + ctx.arg.printSymbolOrder + ": " + ec.message());
251251
return orderMap;
252252
}
253253

@@ -294,7 +294,7 @@ DenseMap<const InputSectionBase *, int> elf::computeCacheDirectedSortOrder() {
294294
};
295295

296296
// Create the graph.
297-
for (std::pair<SectionPair, uint64_t> &c : config->callGraphProfile) {
297+
for (std::pair<SectionPair, uint64_t> &c : ctx.arg.callGraphProfile) {
298298
const InputSectionBase *fromSB = cast<InputSectionBase>(c.first.first);
299299
const InputSectionBase *toSB = cast<InputSectionBase>(c.first.second);
300300
// Ignore edges between input sections belonging to different sections.
@@ -337,7 +337,7 @@ DenseMap<const InputSectionBase *, int> elf::computeCacheDirectedSortOrder() {
337337
// This first builds a call graph based on the profile data then merges sections
338338
// according either to the C³ or Cache-Directed-Sort ordering algorithm.
339339
DenseMap<const InputSectionBase *, int> elf::computeCallGraphProfileOrder() {
340-
if (config->callGraphProfileSort == CGProfileSortKind::Cdsort)
340+
if (ctx.arg.callGraphProfileSort == CGProfileSortKind::Cdsort)
341341
return computeCacheDirectedSortOrder();
342342
return CallGraphSort().run();
343343
}

lld/ELF/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ LLVM_LIBRARY_VISIBILITY extern Ctx ctx;
670670
// The first two elements of versionDefinitions represent VER_NDX_LOCAL and
671671
// VER_NDX_GLOBAL. This helper returns other elements.
672672
static inline ArrayRef<VersionDefinition> namedVersionDefs() {
673-
return llvm::ArrayRef(config->versionDefinitions).slice(2);
673+
return llvm::ArrayRef(ctx.arg.versionDefinitions).slice(2);
674674
}
675675

676676
void errorOrWarn(const Twine &msg);

lld/ELF/MapFile.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static constexpr char indent16[] = " "; // 16 spaces
4646
// Print out the first three columns of a line.
4747
static void writeHeader(raw_ostream &os, uint64_t vma, uint64_t lma,
4848
uint64_t size, uint64_t align) {
49-
if (config->is64)
49+
if (ctx.arg.is64)
5050
os << format("%16llx %16llx %8llx %5lld ", vma, lma, size, align);
5151
else
5252
os << format("%8llx %8llx %8llx %5lld ", vma, lma, size, align);
@@ -153,7 +153,7 @@ static void writeMapFile(raw_fd_ostream &os) {
153153
DenseMap<Symbol *, std::string> symStr = getSymbolStrings(syms);
154154

155155
// Print out the header line.
156-
int w = config->is64 ? 16 : 8;
156+
int w = ctx.arg.is64 ? 16 : 8;
157157
os << right_justify("VMA", w) << ' ' << right_justify("LMA", w)
158158
<< " Size Align Out In Symbol\n";
159159

@@ -257,22 +257,22 @@ static void writeCref(raw_fd_ostream &os) {
257257
}
258258

259259
void elf::writeMapAndCref() {
260-
if (config->mapFile.empty() && !config->cref)
260+
if (ctx.arg.mapFile.empty() && !ctx.arg.cref)
261261
return;
262262

263263
llvm::TimeTraceScope timeScope("Write map file");
264264

265265
// Open a map file for writing.
266266
std::error_code ec;
267-
StringRef mapFile = config->mapFile.empty() ? "-" : config->mapFile;
267+
StringRef mapFile = ctx.arg.mapFile.empty() ? "-" : ctx.arg.mapFile;
268268
raw_fd_ostream os = ctx.openAuxiliaryFile(mapFile, ec);
269269
if (ec) {
270270
error("cannot open " + mapFile + ": " + ec.message());
271271
return;
272272
}
273273

274-
if (!config->mapFile.empty())
274+
if (!ctx.arg.mapFile.empty())
275275
writeMapFile(os);
276-
if (config->cref)
276+
if (ctx.arg.cref)
277277
writeCref(os);
278278
}

lld/ELF/MarkLive.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ template <class ELFT>
7676
static uint64_t getAddend(InputSectionBase &sec,
7777
const typename ELFT::Rel &rel) {
7878
return ctx.target->getImplicitAddend(sec.content().begin() + rel.r_offset,
79-
rel.getType(config->isMips64EL));
79+
rel.getType(ctx.arg.isMips64EL));
8080
}
8181

8282
template <class ELFT>
@@ -229,10 +229,10 @@ template <class ELFT> void MarkLive<ELFT>::run() {
229229
return;
230230
}
231231

232-
markSymbol(symtab.find(config->entry));
233-
markSymbol(symtab.find(config->init));
234-
markSymbol(symtab.find(config->fini));
235-
for (StringRef s : config->undefined)
232+
markSymbol(symtab.find(ctx.arg.entry));
233+
markSymbol(symtab.find(ctx.arg.init));
234+
markSymbol(symtab.find(ctx.arg.fini));
235+
for (StringRef s : ctx.arg.undefined)
236236
markSymbol(symtab.find(s));
237237
for (StringRef s : ctx.script->referencedSymbols)
238238
markSymbol(symtab.find(s));
@@ -295,7 +295,7 @@ template <class ELFT> void MarkLive<ELFT>::run() {
295295
// script KEEP command.
296296
if (isReserved(sec) || ctx.script->shouldKeep(sec)) {
297297
enqueue(sec, 0);
298-
} else if ((!config->zStartStopGC || sec->name.starts_with("__libc_")) &&
298+
} else if ((!ctx.arg.zStartStopGC || sec->name.starts_with("__libc_")) &&
299299
isValidCIdentifier(sec->name)) {
300300
// As a workaround for glibc libc.a before 2.34
301301
// (https://sourceware.org/PR27492), retain __libc_atexit and similar
@@ -364,7 +364,7 @@ template <class ELFT> void MarkLive<ELFT>::moveToMain() {
364364
template <class ELFT> void elf::markLive() {
365365
llvm::TimeTraceScope timeScope("markLive");
366366
// If --gc-sections is not given, retain all input sections.
367-
if (!config->gcSections) {
367+
if (!ctx.arg.gcSections) {
368368
// If a DSO defines a symbol referenced in a regular object, it is needed.
369369
for (Symbol *sym : symtab.getSymbols())
370370
if (auto *s = dyn_cast<SharedSymbol>(sym))
@@ -387,7 +387,7 @@ template <class ELFT> void elf::markLive() {
387387
MarkLive<ELFT>(1).moveToMain();
388388

389389
// Report garbage-collected sections.
390-
if (config->printGcSections)
390+
if (ctx.arg.printGcSections)
391391
for (InputSectionBase *sec : ctx.inputSections)
392392
if (!sec->isLive())
393393
message("removing unused section " + toString(sec));

lld/ELF/OutputSections.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using namespace lld::elf;
4242

4343
uint32_t OutputSection::getPhdrFlags() const {
4444
uint32_t ret = 0;
45-
if (config->emachine != EM_ARM || !(flags & SHF_ARM_PURECODE))
45+
if (ctx.arg.emachine != EM_ARM || !(flags & SHF_ARM_PURECODE))
4646
ret |= PF_R;
4747
if (flags & SHF_WRITE)
4848
ret |= PF_W;
@@ -82,7 +82,7 @@ static bool canMergeToProgbits(unsigned type) {
8282
return type == SHT_NOBITS || type == SHT_PROGBITS || type == SHT_INIT_ARRAY ||
8383
type == SHT_PREINIT_ARRAY || type == SHT_FINI_ARRAY ||
8484
type == SHT_NOTE ||
85-
(type == SHT_X86_64_UNWIND && config->emachine == EM_X86_64);
85+
(type == SHT_X86_64_UNWIND && ctx.arg.emachine == EM_X86_64);
8686
}
8787

8888
// Record that isec will be placed in the OutputSection. isec does not become
@@ -130,9 +130,9 @@ void OutputSection::commitSection(InputSection *isec) {
130130
if (type != SHT_NOBITS) {
131131
errorOrWarn("section type mismatch for " + isec->name + "\n>>> " +
132132
toString(isec) + ": " +
133-
getELFSectionTypeName(config->emachine, isec->type) +
133+
getELFSectionTypeName(ctx.arg.emachine, isec->type) +
134134
"\n>>> output section " + name + ": " +
135-
getELFSectionTypeName(config->emachine, type));
135+
getELFSectionTypeName(ctx.arg.emachine, type));
136136
}
137137
}
138138
if (!typeIsSet)
@@ -155,7 +155,7 @@ void OutputSection::commitSection(InputSection *isec) {
155155

156156
isec->parent = this;
157157
uint64_t andMask =
158-
config->emachine == EM_ARM ? (uint64_t)SHF_ARM_PURECODE : 0;
158+
ctx.arg.emachine == EM_ARM ? (uint64_t)SHF_ARM_PURECODE : 0;
159159
uint64_t orMask = ~andMask;
160160
uint64_t andFlags = (flags & isec->flags) & andMask;
161161
uint64_t orFlags = (flags | isec->flags) & orMask;
@@ -176,7 +176,7 @@ static MergeSyntheticSection *createMergeSynthetic(StringRef name,
176176
uint32_t type,
177177
uint64_t flags,
178178
uint32_t addralign) {
179-
if ((flags & SHF_STRINGS) && config->optimize >= 2)
179+
if ((flags & SHF_STRINGS) && ctx.arg.optimize >= 2)
180180
return make<MergeTailSection>(name, type, flags, addralign);
181181
return make<MergeNoTailSection>(name, type, flags, addralign);
182182
}
@@ -261,7 +261,7 @@ static void sortByOrder(MutableArrayRef<InputSection *> in,
261261
}
262262

263263
uint64_t elf::getHeaderSize() {
264-
if (config->oFormatBinary)
264+
if (ctx.arg.oFormatBinary)
265265
return 0;
266266
return ctx.out.elfHeader->size + ctx.out.programHeaders->size;
267267
}
@@ -348,10 +348,10 @@ template <class ELFT> void OutputSection::maybeCompress() {
348348
DebugCompressionType ctype = DebugCompressionType::None;
349349
size_t compressedSize = sizeof(Elf_Chdr);
350350
unsigned level = 0; // default compression level
351-
if (!(flags & SHF_ALLOC) && config->compressDebugSections &&
351+
if (!(flags & SHF_ALLOC) && ctx.arg.compressDebugSections &&
352352
name.starts_with(".debug_"))
353-
ctype = *config->compressDebugSections;
354-
for (auto &[glob, t, l] : config->compressSections)
353+
ctype = *ctx.arg.compressDebugSections;
354+
for (auto &[glob, t, l] : ctx.arg.compressSections)
355355
if (glob.match(name))
356356
std::tie(ctype, level) = {t, l};
357357
if (ctype == DebugCompressionType::None)
@@ -529,7 +529,7 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
529529

530530
// When in Arm BE8 mode, the linker has to convert the big-endian
531531
// instructions to little-endian, leaving the data big-endian.
532-
if (config->emachine == EM_ARM && !config->isLE && config->armBe8 &&
532+
if (ctx.arg.emachine == EM_ARM && !ctx.arg.isLE && ctx.arg.armBe8 &&
533533
(flags & SHF_EXECINSTR))
534534
convertArmInstructionstoBE8(isec, buf + isec->outSecOff);
535535

@@ -661,7 +661,7 @@ static size_t relToCrel(raw_svector_ostream &os, Elf_Crel<ELFT::Is64Bits> &out,
661661
for (auto rel : rels) {
662662
encodeOneCrel<typename ELFT::uint>(
663663
os, out, sec->getVA(rel.r_offset), file.getRelocTargetSym(rel),
664-
rel.getType(config->isMips64EL), getAddend<ELFT>(rel));
664+
rel.getType(ctx.arg.isMips64EL), getAddend<ELFT>(rel));
665665
}
666666
return rels.size();
667667
}
@@ -690,10 +690,10 @@ template <bool is64> void OutputSection::finalizeNonAllocCrel() {
690690

691691
// Convert REL[A] to CREL.
692692
if constexpr (is64) {
693-
totalCount += config->isLE ? relToCrel<ELF64LE>(os, out, relSec, sec)
693+
totalCount += ctx.arg.isLE ? relToCrel<ELF64LE>(os, out, relSec, sec)
694694
: relToCrel<ELF64BE>(os, out, relSec, sec);
695695
} else {
696-
totalCount += config->isLE ? relToCrel<ELF32LE>(os, out, relSec, sec)
696+
totalCount += ctx.arg.isLE ? relToCrel<ELF32LE>(os, out, relSec, sec)
697697
: relToCrel<ELF32BE>(os, out, relSec, sec);
698698
}
699699
}
@@ -722,7 +722,7 @@ void OutputSection::finalize() {
722722
return;
723723
}
724724

725-
if (!config->copyRelocs || !isStaticRelSecType(type))
725+
if (!ctx.arg.copyRelocs || !isStaticRelSecType(type))
726726
return;
727727

728728
// Skip if 'first' is synthetic, i.e. not a section created by --emit-relocs.
@@ -740,7 +740,7 @@ void OutputSection::finalize() {
740740
flags |= SHF_INFO_LINK;
741741
// Finalize the content of non-alloc CREL.
742742
if (type == SHT_CREL) {
743-
if (config->is64)
743+
if (ctx.arg.is64)
744744
finalizeNonAllocCrel<true>();
745745
else
746746
finalizeNonAllocCrel<false>();
@@ -863,7 +863,7 @@ std::array<uint8_t, 4> OutputSection::getFiller() {
863863
}
864864

865865
void OutputSection::checkDynRelAddends(const uint8_t *bufStart) {
866-
assert(config->writeAddends && config->checkDynamicRelocs);
866+
assert(ctx.arg.writeAddends && ctx.arg.checkDynamicRelocs);
867867
assert(isStaticRelSecType(type));
868868
SmallVector<InputSection *, 0> storage;
869869
ArrayRef<InputSection *> sections = getInputSections(*this, storage);
@@ -881,7 +881,7 @@ void OutputSection::checkDynRelAddends(const uint8_t *bufStart) {
881881
assert(relOsec != nullptr && "missing output section for relocation");
882882
// Some targets have NOBITS synthetic sections with dynamic relocations
883883
// with non-zero addends. Skip such sections.
884-
if (is_contained({EM_PPC, EM_PPC64}, config->emachine) &&
884+
if (is_contained({EM_PPC, EM_PPC64}, ctx.arg.emachine) &&
885885
(rel.inputSec == ctx.in.ppc64LongBranchTarget.get() ||
886886
rel.inputSec == ctx.in.igotPlt.get()))
887887
continue;

lld/ELF/Target.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ using namespace lld;
3939
using namespace lld::elf;
4040

4141
std::string lld::toString(RelType type) {
42-
StringRef s = getELFRelocationTypeName(elf::config->emachine, type);
42+
StringRef s = getELFRelocationTypeName(elf::ctx.arg.emachine, type);
4343
if (s == "Unknown")
4444
return ("Unknown (" + Twine(type) + ")").str();
4545
return std::string(s);
4646
}
4747

4848
TargetInfo *elf::getTarget() {
49-
switch (config->emachine) {
49+
switch (ctx.arg.emachine) {
5050
case EM_386:
5151
case EM_IAMCU:
5252
return getX86TargetInfo();
@@ -63,7 +63,7 @@ TargetInfo *elf::getTarget() {
6363
case EM_LOONGARCH:
6464
return getLoongArchTargetInfo();
6565
case EM_MIPS:
66-
switch (config->ekind) {
66+
switch (ctx.arg.ekind) {
6767
case ELF32LEKind:
6868
return getMipsTargetInfo<ELF32LE>();
6969
case ELF32BEKind:
@@ -90,7 +90,7 @@ TargetInfo *elf::getTarget() {
9090
case EM_X86_64:
9191
return getX86_64TargetInfo();
9292
default:
93-
fatal("unsupported e_machine value: " + Twine(config->emachine));
93+
fatal("unsupported e_machine value: " + Twine(ctx.arg.emachine));
9494
}
9595
}
9696

@@ -156,7 +156,7 @@ RelExpr TargetInfo::adjustGotPcExpr(RelType type, int64_t addend,
156156
}
157157

158158
void TargetInfo::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
159-
const unsigned bits = config->is64 ? 64 : 32;
159+
const unsigned bits = ctx.arg.is64 ? 64 : 32;
160160
uint64_t secAddr = sec.getOutputSection()->addr;
161161
if (auto *s = dyn_cast<InputSection>(&sec))
162162
secAddr += s->outSecOff;
@@ -175,7 +175,7 @@ void TargetInfo::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
175175

176176
uint64_t TargetInfo::getImageBase() const {
177177
// Use --image-base if set. Fall back to the target default if not.
178-
if (config->imageBase)
179-
return *config->imageBase;
180-
return config->isPic ? 0 : defaultImageBase;
178+
if (ctx.arg.imageBase)
179+
return *ctx.arg.imageBase;
180+
return ctx.arg.isPic ? 0 : defaultImageBase;
181181
}

0 commit comments

Comments
 (0)