Skip to content

Commit 1dd9a56

Browse files
committed
[ELF] Replace config-> with ctx.arg. in Arch/
1 parent 49ec508 commit 1dd9a56

File tree

11 files changed

+120
-120
lines changed

11 files changed

+120
-120
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void AArch64::writeGotPlt(uint8_t *buf, const Symbol &) const {
326326
}
327327

328328
void AArch64::writeIgotPlt(uint8_t *buf, const Symbol &s) const {
329-
if (config->writeAddends)
329+
if (ctx.arg.writeAddends)
330330
write64(buf, s.getVA());
331331
}
332332

@@ -719,7 +719,7 @@ void AArch64::relaxTlsIeToLe(uint8_t *loc, const Relocation &rel,
719719
}
720720

721721
AArch64Relaxer::AArch64Relaxer(ArrayRef<Relocation> relocs) {
722-
if (!config->relax)
722+
if (!ctx.arg.relax)
723723
return;
724724
// Check if R_AARCH64_ADR_GOT_PAGE and R_AARCH64_LD64_GOT_LO12_NC
725725
// always appear in pairs.
@@ -749,7 +749,7 @@ bool AArch64Relaxer::tryRelaxAdrpAdd(const Relocation &adrpRel,
749749
// to
750750
// NOP
751751
// ADR xn, sym
752-
if (!config->relax || adrpRel.type != R_AARCH64_ADR_PREL_PG_HI21 ||
752+
if (!ctx.arg.relax || adrpRel.type != R_AARCH64_ADR_PREL_PG_HI21 ||
753753
addRel.type != R_AARCH64_ADD_ABS_LO12_NC)
754754
return false;
755755
// Check if the relocations apply to consecutive instructions.
@@ -836,7 +836,7 @@ bool AArch64Relaxer::tryRelaxAdrpLdr(const Relocation &adrpRel,
836836
// GOT references to absolute symbols can't be relaxed to use ADRP/ADD in
837837
// position-independent code because these instructions produce a relative
838838
// address.
839-
if (config->isPic && !cast<Defined>(sym).section)
839+
if (ctx.arg.isPic && !cast<Defined>(sym).section)
840840
return false;
841841
// Check if the address difference is within 4GB range.
842842
int64_t val =
@@ -972,7 +972,7 @@ class AArch64BtiPac final : public AArch64 {
972972
} // namespace
973973

974974
AArch64BtiPac::AArch64BtiPac() {
975-
btiHeader = (config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI);
975+
btiHeader = (ctx.arg.andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI);
976976
// A BTI (Branch Target Indicator) Plt Entry is only required if the
977977
// address of the PLT entry can be taken by the program, which permits an
978978
// indirect jump to the PLT entry. This can happen when the address
@@ -982,7 +982,7 @@ AArch64BtiPac::AArch64BtiPac() {
982982
// relocations.
983983
// The PAC PLT entries require dynamic loader support and this isn't known
984984
// from properties in the objects, so we use the command line flag.
985-
pacEntry = config->zPacPlt;
985+
pacEntry = ctx.arg.zPacPlt;
986986

987987
if (btiHeader || pacEntry) {
988988
pltEntrySize = 24;
@@ -1074,8 +1074,8 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym,
10741074
}
10751075

10761076
static TargetInfo *getTargetInfo() {
1077-
if ((config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ||
1078-
config->zPacPlt) {
1077+
if ((ctx.arg.andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ||
1078+
ctx.arg.zPacPlt) {
10791079
static AArch64BtiPac t;
10801080
return &t;
10811081
}
@@ -1175,7 +1175,7 @@ void lld::elf::createTaggedSymbols(const SmallVector<ELFFileBase *, 0> &files) {
11751175
// `addTaggedSymbolReferences` has already checked that we have RELA
11761176
// relocations, the only other way to get written addends is with
11771177
// --apply-dynamic-relocs.
1178-
if (!taggedSymbolReferenceCount.empty() && config->writeAddends)
1178+
if (!taggedSymbolReferenceCount.empty() && ctx.arg.writeAddends)
11791179
error("--apply-dynamic-relocs cannot be used with MTE globals");
11801180

11811181
// Now, `taggedSymbolReferenceCount` should only contain symbols that are

lld/ELF/Arch/ARM.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ uint32_t ARM::calcEFlags() const {
8181
// with BE-8 code.
8282
uint32_t armBE8 = 0;
8383

84-
if (config->armVFPArgs == ARMVFPArgKind::Base ||
85-
config->armVFPArgs == ARMVFPArgKind::Default)
84+
if (ctx.arg.armVFPArgs == ARMVFPArgKind::Base ||
85+
ctx.arg.armVFPArgs == ARMVFPArgKind::Default)
8686
abiFloatType = EF_ARM_ABI_FLOAT_SOFT;
87-
else if (config->armVFPArgs == ARMVFPArgKind::VFP)
87+
else if (ctx.arg.armVFPArgs == ARMVFPArgKind::VFP)
8888
abiFloatType = EF_ARM_ABI_FLOAT_HARD;
8989

90-
if (!config->isLE && config->armBe8)
90+
if (!ctx.arg.isLE && ctx.arg.armBe8)
9191
armBE8 = EF_ARM_BE8;
9292

9393
// We don't currently use any features incompatible with EF_ARM_EABI_VER5,
@@ -134,11 +134,11 @@ RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
134134
case R_ARM_SBREL32:
135135
return R_ARM_SBREL;
136136
case R_ARM_TARGET1:
137-
return config->target1Rel ? R_PC : R_ABS;
137+
return ctx.arg.target1Rel ? R_PC : R_ABS;
138138
case R_ARM_TARGET2:
139-
if (config->target2 == Target2Policy::Rel)
139+
if (ctx.arg.target2 == Target2Policy::Rel)
140140
return R_PC;
141-
if (config->target2 == Target2Policy::Abs)
141+
if (ctx.arg.target2 == Target2Policy::Abs)
142142
return R_ABS;
143143
return R_GOT_PC;
144144
case R_ARM_TLS_GD32:
@@ -198,7 +198,7 @@ RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
198198
}
199199

200200
RelType ARM::getDynRel(RelType type) const {
201-
if ((type == R_ARM_ABS32) || (type == R_ARM_TARGET1 && !config->target1Rel))
201+
if ((type == R_ARM_ABS32) || (type == R_ARM_TARGET1 && !ctx.arg.target1Rel))
202202
return R_ARM_ABS32;
203203
return R_ARM_NONE;
204204
}
@@ -231,7 +231,7 @@ static void writePltHeaderLong(uint8_t *buf) {
231231
// True if we should use Thumb PLTs, which currently require Thumb2, and are
232232
// only used if the target does not have the ARM ISA.
233233
static bool useThumbPLTs() {
234-
return config->armHasThumb2ISA && !config->armHasArmISA;
234+
return ctx.arg.armHasThumb2ISA && !ctx.arg.armHasArmISA;
235235
}
236236

237237
// The default PLT header requires the .got.plt to be within 128 Mb of the
@@ -407,7 +407,7 @@ bool ARM::needsThunk(RelExpr expr, RelType type, const InputFile *file,
407407
case R_ARM_CALL: {
408408
uint64_t dst = (expr == R_PLT_PC) ? s.getPltVA() : s.getVA();
409409
return !inBranchRange(type, branchAddr, dst + a) ||
410-
(!config->armHasBlx && (s.getVA() & 1));
410+
(!ctx.arg.armHasBlx && (s.getVA() & 1));
411411
}
412412
case R_ARM_THM_JUMP19:
413413
case R_ARM_THM_JUMP24:
@@ -420,7 +420,7 @@ bool ARM::needsThunk(RelExpr expr, RelType type, const InputFile *file,
420420
case R_ARM_THM_CALL: {
421421
uint64_t dst = (expr == R_PLT_PC) ? s.getPltVA() : s.getVA();
422422
return !inBranchRange(type, branchAddr, dst + a) ||
423-
(!config->armHasBlx && (s.getVA() & 1) == 0);;
423+
(!ctx.arg.armHasBlx && (s.getVA() & 1) == 0);;
424424
}
425425
}
426426
return false;
@@ -456,7 +456,7 @@ uint32_t ARM::getThunkSectionSpacing() const {
456456
// range. On earlier Architectures such as ARMv4, ARMv5 and ARMv6 (except
457457
// ARMv6T2) the range is +/- 4MiB.
458458

459-
return (config->armJ1J2BranchEncoding) ? 0x1000000 - 0x30000
459+
return (ctx.arg.armJ1J2BranchEncoding) ? 0x1000000 - 0x30000
460460
: 0x400000 - 0x7500;
461461
}
462462

@@ -481,7 +481,7 @@ bool ARM::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
481481
return llvm::isInt<21>(offset);
482482
case R_ARM_THM_JUMP24:
483483
case R_ARM_THM_CALL:
484-
return config->armJ1J2BranchEncoding ? llvm::isInt<25>(offset)
484+
return ctx.arg.armJ1J2BranchEncoding ? llvm::isInt<25>(offset)
485485
: llvm::isInt<23>(offset);
486486
default:
487487
return true;
@@ -697,7 +697,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
697697
} else {
698698
write16(loc + 2, (read16(loc + 2) & ~0x1000) | 1 << 12);
699699
}
700-
if (!config->armJ1J2BranchEncoding) {
700+
if (!ctx.arg.armJ1J2BranchEncoding) {
701701
// Older Arm architectures do not support R_ARM_THM_JUMP24 and have
702702
// different encoding rules and range due to J1 and J2 always being 1.
703703
checkInt(loc, val, 23, rel);
@@ -909,7 +909,7 @@ int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {
909909
((lo & 0x07ff) << 1)); // imm11:0
910910
}
911911
case R_ARM_THM_CALL:
912-
if (!config->armJ1J2BranchEncoding) {
912+
if (!ctx.arg.armJ1J2BranchEncoding) {
913913
// Older Arm architectures do not support R_ARM_THM_JUMP24 and have
914914
// different encoding rules and range due to J1 and J2 always being 1.
915915
uint16_t hi = read16(buf);
@@ -1261,7 +1261,7 @@ static std::string checkCmseSymAttributes(Symbol *acleSeSym, Symbol *sym) {
12611261
// Both these symbols are Thumb function symbols with external linkage.
12621262
// <sym> may be redefined in .gnu.sgstubs.
12631263
void elf::processArmCmseSymbols() {
1264-
if (!config->cmseImplib)
1264+
if (!ctx.arg.cmseImplib)
12651265
return;
12661266
// Only symbols with external linkage end up in symtab, so no need to do
12671267
// linkage checks. Only check symbol type.
@@ -1270,9 +1270,9 @@ void elf::processArmCmseSymbols() {
12701270
continue;
12711271
// If input object build attributes do not support CMSE, error and disable
12721272
// further scanning for <sym>, __acle_se_<sym> pairs.
1273-
if (!config->armCMSESupport) {
1273+
if (!ctx.arg.armCMSESupport) {
12741274
error("CMSE is only supported by ARMv8-M architecture or later");
1275-
config->cmseImplib = false;
1275+
ctx.arg.cmseImplib = false;
12761276
break;
12771277
}
12781278

@@ -1348,7 +1348,7 @@ ArmCmseSGSection::ArmCmseSGSection()
13481348
"' from CMSE import library is not present in secure application");
13491349
}
13501350

1351-
if (!symtab.cmseImportLib.empty() && config->cmseOutputLib.empty()) {
1351+
if (!symtab.cmseImportLib.empty() && ctx.arg.cmseOutputLib.empty()) {
13521352
for (auto &[_, entryFunc] : symtab.cmseSymMap) {
13531353
Symbol *sym = entryFunc.sym;
13541354
if (!symtab.inCMSEOutImpLib.count(sym->getName()))
@@ -1476,17 +1476,17 @@ template <typename ELFT> void elf::writeARMCmseImportLib() {
14761476
off = osec->offset + osec->size;
14771477
}
14781478

1479-
const uint64_t sectionHeaderOff = alignToPowerOf2(off, config->wordsize);
1479+
const uint64_t sectionHeaderOff = alignToPowerOf2(off, ctx.arg.wordsize);
14801480
const auto shnum = osIsPairs.size() + 1;
14811481
const uint64_t fileSize =
14821482
sectionHeaderOff + shnum * sizeof(typename ELFT::Shdr);
14831483
const unsigned flags =
1484-
config->mmapOutputFile ? 0 : (unsigned)FileOutputBuffer::F_no_mmap;
1485-
unlinkAsync(config->cmseOutputLib);
1484+
ctx.arg.mmapOutputFile ? 0 : (unsigned)FileOutputBuffer::F_no_mmap;
1485+
unlinkAsync(ctx.arg.cmseOutputLib);
14861486
Expected<std::unique_ptr<FileOutputBuffer>> bufferOrErr =
1487-
FileOutputBuffer::create(config->cmseOutputLib, fileSize, flags);
1487+
FileOutputBuffer::create(ctx.arg.cmseOutputLib, fileSize, flags);
14881488
if (!bufferOrErr) {
1489-
error("failed to open " + config->cmseOutputLib + ": " +
1489+
error("failed to open " + ctx.arg.cmseOutputLib + ": " +
14901490
llvm::toString(bufferOrErr.takeError()));
14911491
return;
14921492
}
@@ -1500,13 +1500,13 @@ template <typename ELFT> void elf::writeARMCmseImportLib() {
15001500
eHdr->e_entry = 0;
15011501
eHdr->e_shoff = sectionHeaderOff;
15021502
eHdr->e_ident[EI_CLASS] = ELFCLASS32;
1503-
eHdr->e_ident[EI_DATA] = config->isLE ? ELFDATA2LSB : ELFDATA2MSB;
1503+
eHdr->e_ident[EI_DATA] = ctx.arg.isLE ? ELFDATA2LSB : ELFDATA2MSB;
15041504
eHdr->e_ident[EI_VERSION] = EV_CURRENT;
1505-
eHdr->e_ident[EI_OSABI] = config->osabi;
1505+
eHdr->e_ident[EI_OSABI] = ctx.arg.osabi;
15061506
eHdr->e_ident[EI_ABIVERSION] = 0;
15071507
eHdr->e_machine = EM_ARM;
15081508
eHdr->e_version = EV_CURRENT;
1509-
eHdr->e_flags = config->eflags;
1509+
eHdr->e_flags = ctx.arg.eflags;
15101510
eHdr->e_ehsize = sizeof(typename ELFT::Ehdr);
15111511
eHdr->e_phnum = 0;
15121512
eHdr->e_shentsize = sizeof(typename ELFT::Shdr);

lld/ELF/Arch/LoongArch.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ LoongArch::LoongArch() {
188188
relativeRel = R_LARCH_RELATIVE;
189189
iRelativeRel = R_LARCH_IRELATIVE;
190190

191-
if (config->is64) {
191+
if (ctx.arg.is64) {
192192
symbolicRel = R_LARCH_64;
193193
tlsModuleIndexRel = R_LARCH_TLS_DTPMOD64;
194194
tlsOffsetRel = R_LARCH_TLS_DTPREL64;
@@ -213,7 +213,7 @@ LoongArch::LoongArch() {
213213
}
214214

215215
static uint32_t getEFlags(const InputFile *f) {
216-
if (config->is64)
216+
if (ctx.arg.is64)
217217
return cast<ObjFile<ELF64LE>>(f)->getObj().getHeader().e_flags;
218218
return cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
219219
}
@@ -294,7 +294,7 @@ int64_t LoongArch::getImplicitAddend(const uint8_t *buf, RelType type) const {
294294
return read64le(buf);
295295
case R_LARCH_RELATIVE:
296296
case R_LARCH_IRELATIVE:
297-
return config->is64 ? read64le(buf) : read32le(buf);
297+
return ctx.arg.is64 ? read64le(buf) : read32le(buf);
298298
case R_LARCH_NONE:
299299
case R_LARCH_JUMP_SLOT:
300300
// These relocations are defined as not having an implicit addend.
@@ -307,15 +307,15 @@ int64_t LoongArch::getImplicitAddend(const uint8_t *buf, RelType type) const {
307307
}
308308

309309
void LoongArch::writeGotPlt(uint8_t *buf, const Symbol &s) const {
310-
if (config->is64)
310+
if (ctx.arg.is64)
311311
write64le(buf, ctx.in.plt->getVA());
312312
else
313313
write32le(buf, ctx.in.plt->getVA());
314314
}
315315

316316
void LoongArch::writeIgotPlt(uint8_t *buf, const Symbol &s) const {
317-
if (config->writeAddends) {
318-
if (config->is64)
317+
if (ctx.arg.writeAddends) {
318+
if (ctx.arg.is64)
319319
write64le(buf, s.getVA());
320320
else
321321
write32le(buf, s.getVA());
@@ -342,18 +342,18 @@ void LoongArch::writePltHeader(uint8_t *buf) const {
342342
// ld.[wd] $t0, $t0, Wordsize ; t0 = link_map
343343
// jr $t3
344344
uint32_t offset = ctx.in.gotPlt->getVA() - ctx.in.plt->getVA();
345-
uint32_t sub = config->is64 ? SUB_D : SUB_W;
346-
uint32_t ld = config->is64 ? LD_D : LD_W;
347-
uint32_t addi = config->is64 ? ADDI_D : ADDI_W;
348-
uint32_t srli = config->is64 ? SRLI_D : SRLI_W;
345+
uint32_t sub = ctx.arg.is64 ? SUB_D : SUB_W;
346+
uint32_t ld = ctx.arg.is64 ? LD_D : LD_W;
347+
uint32_t addi = ctx.arg.is64 ? ADDI_D : ADDI_W;
348+
uint32_t srli = ctx.arg.is64 ? SRLI_D : SRLI_W;
349349
write32le(buf + 0, insn(PCADDU12I, R_T2, hi20(offset), 0));
350350
write32le(buf + 4, insn(sub, R_T1, R_T1, R_T3));
351351
write32le(buf + 8, insn(ld, R_T3, R_T2, lo12(offset)));
352352
write32le(buf + 12,
353353
insn(addi, R_T1, R_T1, lo12(-ctx.target->pltHeaderSize - 12)));
354354
write32le(buf + 16, insn(addi, R_T0, R_T2, lo12(offset)));
355-
write32le(buf + 20, insn(srli, R_T1, R_T1, config->is64 ? 1 : 2));
356-
write32le(buf + 24, insn(ld, R_T0, R_T0, config->wordsize));
355+
write32le(buf + 20, insn(srli, R_T1, R_T1, ctx.arg.is64 ? 1 : 2));
356+
write32le(buf + 24, insn(ld, R_T0, R_T0, ctx.arg.wordsize));
357357
write32le(buf + 28, insn(JIRL, R_ZERO, R_T3, 0));
358358
}
359359

@@ -369,7 +369,7 @@ void LoongArch::writePlt(uint8_t *buf, const Symbol &sym,
369369
uint32_t offset = sym.getGotPltVA() - pltEntryAddr;
370370
write32le(buf + 0, insn(PCADDU12I, R_T3, hi20(offset), 0));
371371
write32le(buf + 4,
372-
insn(config->is64 ? LD_D : LD_W, R_T3, R_T3, lo12(offset)));
372+
insn(ctx.arg.is64 ? LD_D : LD_W, R_T3, R_T3, lo12(offset)));
373373
write32le(buf + 8, insn(JIRL, R_T1, R_T3, 0));
374374
write32le(buf + 12, insn(ANDI, R_ZERO, R_ZERO, 0));
375375
}
@@ -496,7 +496,7 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
496496
return R_TLSGD_GOT;
497497
case R_LARCH_TLS_LE_ADD_R:
498498
case R_LARCH_RELAX:
499-
return config->relax ? R_RELAX_HINT : R_NONE;
499+
return ctx.arg.relax ? R_RELAX_HINT : R_NONE;
500500
case R_LARCH_ALIGN:
501501
return R_RELAX_HINT;
502502
case R_LARCH_TLS_DESC_PC_HI20:
@@ -821,7 +821,7 @@ static bool relax(InputSection &sec) {
821821
// change in section sizes can have cascading effect and require another
822822
// relaxation pass.
823823
bool LoongArch::relaxOnce(int pass) const {
824-
if (config->relocatable)
824+
if (ctx.arg.relocatable)
825825
return false;
826826

827827
if (pass == 0)

0 commit comments

Comments
 (0)