Skip to content

Commit 777329d

Browse files
committed
[ELF] Replace config-> with ctx.arg. in Driver.cpp and Target.h
1 parent f5ec00b commit 777329d

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

lld/ELF/Driver.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args);
8585
static void readConfigs(Ctx &ctx, opt::InputArgList &args);
8686

8787
void elf::errorOrWarn(const Twine &msg) {
88-
if (config->noinhibitExec)
88+
if (ctx.arg.noinhibitExec)
8989
warn(msg);
9090
else
9191
error(msg);
@@ -172,7 +172,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
172172
ctx.partitions.clear();
173173
ctx.partitions.emplace_back();
174174

175-
config->progName = args[0];
175+
ctx.arg.progName = args[0];
176176

177177
ctx.driver.linkerMain(args);
178178

@@ -853,7 +853,7 @@ static ICFLevel getICF(opt::InputArgList &args) {
853853
static StripPolicy getStrip(opt::InputArgList &args) {
854854
if (args.hasArg(OPT_relocatable))
855855
return StripPolicy::None;
856-
if (!config->zSectionHeader)
856+
if (!ctx.arg.zSectionHeader)
857857
return StripPolicy::All;
858858

859859
auto *arg = args.getLastArg(OPT_strip_all, OPT_strip_debug);
@@ -964,7 +964,7 @@ static void readCallGraph(MemoryBufferRef mb) {
964964
auto findSection = [&](StringRef name) -> InputSectionBase * {
965965
Symbol *sym = map.lookup(name);
966966
if (!sym) {
967-
if (config->warnSymbolOrdering)
967+
if (ctx.arg.warnSymbolOrdering)
968968
warn(mb.getBufferIdentifier() + ": no such symbol: " + name);
969969
return nullptr;
970970
}
@@ -987,7 +987,7 @@ static void readCallGraph(MemoryBufferRef mb) {
987987

988988
if (InputSectionBase *from = findSection(fields[0]))
989989
if (InputSectionBase *to = findSection(fields[1]))
990-
config->callGraphProfile[std::make_pair(from, to)] += count;
990+
ctx.arg.callGraphProfile[std::make_pair(from, to)] += count;
991991
}
992992
}
993993

@@ -1025,14 +1025,14 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
10251025
ArrayRef<typename ELFT::Rela> relas =
10261026
CHECK(obj.relas(sec), "could not retrieve cg profile rela section");
10271027
for (const typename ELFT::Rela &rel : relas)
1028-
symbolIndices.push_back(rel.getSymbol(config->isMips64EL));
1028+
symbolIndices.push_back(rel.getSymbol(ctx.arg.isMips64EL));
10291029
break;
10301030
}
10311031
if (sec.sh_type == SHT_REL) {
10321032
ArrayRef<typename ELFT::Rel> rels =
10331033
CHECK(obj.rels(sec), "could not retrieve cg profile rel section");
10341034
for (const typename ELFT::Rel &rel : rels)
1035-
symbolIndices.push_back(rel.getSymbol(config->isMips64EL));
1035+
symbolIndices.push_back(rel.getSymbol(ctx.arg.isMips64EL));
10361036
break;
10371037
}
10381038
}
@@ -1065,7 +1065,7 @@ template <class ELFT> static void readCallGraphsFromObjectFiles() {
10651065
auto *from = dyn_cast_or_null<InputSectionBase>(fromSym->section);
10661066
auto *to = dyn_cast_or_null<InputSectionBase>(toSym->section);
10671067
if (from && to)
1068-
config->callGraphProfile[{from, to}] += cgpe.cgp_weight;
1068+
ctx.arg.callGraphProfile[{from, to}] += cgpe.cgp_weight;
10691069
}
10701070
}
10711071
}
@@ -1188,7 +1188,7 @@ getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
11881188
static SmallVector<StringRef, 0> getSymbolOrderingFile(MemoryBufferRef mb) {
11891189
SetVector<StringRef, SmallVector<StringRef, 0>> names;
11901190
for (StringRef s : args::getLines(mb))
1191-
if (!names.insert(s) && config->warnSymbolOrdering)
1191+
if (!names.insert(s) && ctx.arg.warnSymbolOrdering)
11921192
warn(mb.getBufferIdentifier() + ": duplicate ordered symbol: " + s);
11931193

11941194
return names.takeVector();
@@ -1198,7 +1198,7 @@ static bool getIsRela(opt::InputArgList &args) {
11981198
// The psABI specifies the default relocation entry format.
11991199
bool rela = is_contained({EM_AARCH64, EM_AMDGPU, EM_HEXAGON, EM_LOONGARCH,
12001200
EM_PPC, EM_PPC64, EM_RISCV, EM_S390, EM_X86_64},
1201-
config->emachine);
1201+
ctx.arg.emachine);
12021202
// If -z rel or -z rela is specified, use the last option.
12031203
for (auto *arg : args.filtered(OPT_z)) {
12041204
StringRef s(arg->getValue());
@@ -1217,7 +1217,7 @@ static void parseClangOption(StringRef opt, const Twine &msg) {
12171217
std::string err;
12181218
raw_string_ostream os(err);
12191219

1220-
const char *argv[] = {config->progName.data(), opt.data()};
1220+
const char *argv[] = {ctx.arg.progName.data(), opt.data()};
12211221
if (cl::ParseCommandLineOptions(2, argv, "", &os))
12221222
return;
12231223
error(msg + ": " + StringRef(err).trim());
@@ -1237,9 +1237,9 @@ static bool remapInputs(StringRef line, const Twine &location) {
12371237
return true;
12381238
}
12391239
if (!hasWildcard(fields[0]))
1240-
config->remapInputs[fields[0]] = fields[1];
1240+
ctx.arg.remapInputs[fields[0]] = fields[1];
12411241
else if (Expected<GlobPattern> pat = GlobPattern::create(fields[0]))
1242-
config->remapInputsWildcards.emplace_back(std::move(*pat), fields[1]);
1242+
ctx.arg.remapInputsWildcards.emplace_back(std::move(*pat), fields[1]);
12431243
else {
12441244
error(location + ": " + toString(pat.takeError()) + ": " + fields[0]);
12451245
return true;
@@ -2093,14 +2093,14 @@ static uint64_t getCommonPageSize(Ctx &ctx, opt::InputArgList &args) {
20932093
error("common-page-size: value isn't a power of 2");
20942094
return ctx.target->defaultCommonPageSize;
20952095
}
2096-
if (config->nmagic || config->omagic) {
2096+
if (ctx.arg.nmagic || ctx.arg.omagic) {
20972097
if (val != ctx.target->defaultCommonPageSize)
20982098
warn("-z common-page-size set, but paging disabled by omagic or nmagic");
20992099
return 1;
21002100
}
21012101
// commonPageSize can't be larger than maxPageSize.
2102-
if (val > config->maxPageSize)
2103-
val = config->maxPageSize;
2102+
if (val > ctx.arg.maxPageSize)
2103+
val = ctx.arg.maxPageSize;
21042104
return val;
21052105
}
21062106

@@ -2381,7 +2381,7 @@ static void markAddrsig(Symbol *s) {
23812381
if (d->section)
23822382
// We don't need to keep text sections unique under --icf=all even if they
23832383
// are address-significant.
2384-
if (config->icf == ICFLevel::Safe || !(d->section->flags & SHF_EXECINSTR))
2384+
if (ctx.arg.icf == ICFLevel::Safe || !(d->section->flags & SHF_EXECINSTR))
23852385
d->section->keepUnique = true;
23862386
}
23872387

@@ -2477,10 +2477,10 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
24772477
if (ctx.script->hasPhdrsCommands())
24782478
error(toString(s->file) +
24792479
": partitions cannot be used with the PHDRS command");
2480-
if (!config->sectionStartMap.empty())
2480+
if (!ctx.arg.sectionStartMap.empty())
24812481
error(toString(s->file) + ": partitions cannot be used with "
24822482
"--section-start, -Ttext, -Tdata or -Tbss");
2483-
if (config->emachine == EM_MIPS)
2483+
if (ctx.arg.emachine == EM_MIPS)
24842484
error(toString(s->file) + ": partitions cannot be used on this target");
24852485

24862486
// Impose a limit of no more than 254 partitions. This limit comes from the
@@ -2651,7 +2651,7 @@ static void combineVersionedSymbol(Symbol &sym,
26512651
sym.isUsedInRegularObj = false;
26522652
} else if (auto *sym1 = dyn_cast<Defined>(&sym)) {
26532653
if (sym2->versionId > VER_NDX_GLOBAL
2654-
? config->versionDefinitions[sym2->versionId].name == suffix1 + 1
2654+
? ctx.arg.versionDefinitions[sym2->versionId].name == suffix1 + 1
26552655
: sym1->section == sym2->section && sym1->value == sym2->value) {
26562656
// Due to an assembler design flaw, if foo is defined, .symver foo,
26572657
// foo@v1 defines both foo and foo@v1. Unless foo is bound to a
@@ -2728,14 +2728,14 @@ static void checkAndReportMissingFeature(StringRef config, uint32_t features,
27282728
// match. Missing info for some object files with matching info for remaining
27292729
// ones can be allowed (see -z pauth-report).
27302730
static void readSecurityNotes() {
2731-
if (config->emachine != EM_386 && config->emachine != EM_X86_64 &&
2732-
config->emachine != EM_AARCH64)
2731+
if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 &&
2732+
ctx.arg.emachine != EM_AARCH64)
27332733
return;
27342734

2735-
config->andFeatures = -1;
2735+
ctx.arg.andFeatures = -1;
27362736

27372737
StringRef referenceFileName;
2738-
if (config->emachine == EM_AARCH64) {
2738+
if (ctx.arg.emachine == EM_AARCH64) {
27392739
auto it = llvm::find_if(ctx.objectFiles, [](const ELFFileBase *f) {
27402740
return !f->aarch64PauthAbiCoreInfo.empty();
27412741
});
@@ -2749,49 +2749,49 @@ static void readSecurityNotes() {
27492749
uint32_t features = f->andFeatures;
27502750

27512751
checkAndReportMissingFeature(
2752-
config->zBtiReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_BTI,
2752+
ctx.arg.zBtiReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_BTI,
27532753
toString(f) + ": -z bti-report: file does not have "
27542754
"GNU_PROPERTY_AARCH64_FEATURE_1_BTI property");
27552755

27562756
checkAndReportMissingFeature(
2757-
config->zGcsReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_GCS,
2757+
ctx.arg.zGcsReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_GCS,
27582758
toString(f) + ": -z gcs-report: file does not have "
27592759
"GNU_PROPERTY_AARCH64_FEATURE_1_GCS property");
27602760

27612761
checkAndReportMissingFeature(
2762-
config->zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_IBT,
2762+
ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_IBT,
27632763
toString(f) + ": -z cet-report: file does not have "
27642764
"GNU_PROPERTY_X86_FEATURE_1_IBT property");
27652765

27662766
checkAndReportMissingFeature(
2767-
config->zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_SHSTK,
2767+
ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_SHSTK,
27682768
toString(f) + ": -z cet-report: file does not have "
27692769
"GNU_PROPERTY_X86_FEATURE_1_SHSTK property");
27702770

2771-
if (config->zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
2771+
if (ctx.arg.zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
27722772
features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
2773-
if (config->zBtiReport == "none")
2773+
if (ctx.arg.zBtiReport == "none")
27742774
warn(toString(f) + ": -z force-bti: file does not have "
27752775
"GNU_PROPERTY_AARCH64_FEATURE_1_BTI property");
2776-
} else if (config->zForceIbt &&
2776+
} else if (ctx.arg.zForceIbt &&
27772777
!(features & GNU_PROPERTY_X86_FEATURE_1_IBT)) {
2778-
if (config->zCetReport == "none")
2778+
if (ctx.arg.zCetReport == "none")
27792779
warn(toString(f) + ": -z force-ibt: file does not have "
27802780
"GNU_PROPERTY_X86_FEATURE_1_IBT property");
27812781
features |= GNU_PROPERTY_X86_FEATURE_1_IBT;
27822782
}
2783-
if (config->zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
2783+
if (ctx.arg.zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
27842784
warn(toString(f) + ": -z pac-plt: file does not have "
27852785
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property");
27862786
features |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
27872787
}
2788-
config->andFeatures &= features;
2788+
ctx.arg.andFeatures &= features;
27892789

27902790
if (ctx.aarch64PauthAbiCoreInfo.empty())
27912791
continue;
27922792

27932793
if (f->aarch64PauthAbiCoreInfo.empty()) {
2794-
reportMissingFeature(config->zPauthReport,
2794+
reportMissingFeature(ctx.arg.zPauthReport,
27952795
toString(f) +
27962796
": -z pauth-report: file does not have AArch64 "
27972797
"PAuth core info while '" +
@@ -2808,14 +2808,14 @@ static void readSecurityNotes() {
28082808
}
28092809

28102810
// Force enable Shadow Stack.
2811-
if (config->zShstk)
2812-
config->andFeatures |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
2811+
if (ctx.arg.zShstk)
2812+
ctx.arg.andFeatures |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
28132813

28142814
// Force enable/disable GCS
2815-
if (config->zGcs == GcsPolicy::Always)
2816-
config->andFeatures |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
2817-
else if (config->zGcs == GcsPolicy::Never)
2818-
config->andFeatures &= ~GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
2815+
if (ctx.arg.zGcs == GcsPolicy::Always)
2816+
ctx.arg.andFeatures |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
2817+
else if (ctx.arg.zGcs == GcsPolicy::Never)
2818+
ctx.arg.andFeatures &= ~GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
28192819
}
28202820

28212821
static void initSectionsAndLocalSyms(ELFFileBase *file, bool ignoreComdats) {
@@ -2869,7 +2869,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
28692869

28702870
// Handle -u/--undefined before input files. If both a.a and b.so define foo,
28712871
// -u foo a.a b.so will extract a.a.
2872-
for (StringRef name : config->undefined)
2872+
for (StringRef name : ctx.arg.undefined)
28732873
symtab.addUnusedUndefined(name)->referenced = true;
28742874

28752875
parseFiles(files, armCmseImpLib);

lld/ELF/Target.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class TargetInfo {
132132
RelType tlsGotRel;
133133
RelType tlsModuleIndexRel;
134134
RelType tlsOffsetRel;
135-
unsigned gotEntrySize = config->wordsize;
135+
unsigned gotEntrySize = ctx.arg.wordsize;
136136
unsigned pltEntrySize;
137137
unsigned pltHeaderSize;
138138
unsigned ipltEntrySize;
@@ -282,27 +282,27 @@ inline void checkAlignment(uint8_t *loc, uint64_t v, int n,
282282

283283
// Endianness-aware read/write.
284284
inline uint16_t read16(const void *p) {
285-
return llvm::support::endian::read16(p, config->endianness);
285+
return llvm::support::endian::read16(p, ctx.arg.endianness);
286286
}
287287

288288
inline uint32_t read32(const void *p) {
289-
return llvm::support::endian::read32(p, config->endianness);
289+
return llvm::support::endian::read32(p, ctx.arg.endianness);
290290
}
291291

292292
inline uint64_t read64(const void *p) {
293-
return llvm::support::endian::read64(p, config->endianness);
293+
return llvm::support::endian::read64(p, ctx.arg.endianness);
294294
}
295295

296296
inline void write16(void *p, uint16_t v) {
297-
llvm::support::endian::write16(p, v, config->endianness);
297+
llvm::support::endian::write16(p, v, ctx.arg.endianness);
298298
}
299299

300300
inline void write32(void *p, uint32_t v) {
301-
llvm::support::endian::write32(p, v, config->endianness);
301+
llvm::support::endian::write32(p, v, ctx.arg.endianness);
302302
}
303303

304304
inline void write64(void *p, uint64_t v) {
305-
llvm::support::endian::write64(p, v, config->endianness);
305+
llvm::support::endian::write64(p, v, ctx.arg.endianness);
306306
}
307307

308308
// Overwrite a ULEB128 value and keep the original length.
@@ -321,7 +321,7 @@ inline uint64_t overwriteULEB128(uint8_t *bufLoc, uint64_t val) {
321321
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
322322
#endif
323323
#define invokeELFT(f, ...) \
324-
switch (config->ekind) { \
324+
switch (ctx.arg.ekind) { \
325325
case lld::elf::ELF32LEKind: \
326326
f<llvm::object::ELF32LE>(__VA_ARGS__); \
327327
break; \
@@ -335,7 +335,7 @@ inline uint64_t overwriteULEB128(uint8_t *bufLoc, uint64_t val) {
335335
f<llvm::object::ELF64BE>(__VA_ARGS__); \
336336
break; \
337337
default: \
338-
llvm_unreachable("unknown config->ekind"); \
338+
llvm_unreachable("unknown ctx.arg.ekind"); \
339339
}
340340

341341
#endif

0 commit comments

Comments
 (0)