Skip to content

Commit 58a971f

Browse files
committed
[ELF] Replace contex-less toString(x) with toStr(ctx, x)
so that we can remove the global `ctx` from toString implementations. Rename lld::toString (to lld::elf::toStr) to simplify name lookup (we have many llvm::toString and another lld::toString(const llvm::opt::Arg &)).
1 parent 549413f commit 58a971f

28 files changed

+131
-119
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ int64_t AArch64::getImplicitAddend(const uint8_t *buf, RelType type) const {
349349

350350
default:
351351
internalLinkerError(getErrorLoc(ctx, buf),
352-
"cannot read addend for relocation " + toString(type));
352+
"cannot read addend for relocation " +
353+
toStr(ctx, type));
353354
return 0;
354355
}
355356
}

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ int64_t AMDGPU::getImplicitAddend(const uint8_t *buf, RelType type) const {
214214
return read64(ctx, buf);
215215
default:
216216
internalLinkerError(getErrorLoc(ctx, buf),
217-
"cannot read addend for relocation " + toString(type));
217+
"cannot read addend for relocation " +
218+
toStr(ctx, type));
218219
return 0;
219220
}
220221
}

lld/ELF/Arch/ARM.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,8 @@ int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {
876876
switch (type) {
877877
default:
878878
internalLinkerError(getErrorLoc(ctx, buf),
879-
"cannot read addend for relocation " + toString(type));
879+
"cannot read addend for relocation " +
880+
toStr(ctx, type));
880881
return 0;
881882
case R_ARM_ABS32:
882883
case R_ARM_BASE_PREL:
@@ -1199,7 +1200,7 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
11991200
ArrayRef<Elf_Sym> eSyms = getELFSyms<ELFT>();
12001201
// Error for local symbols. The symbol at index 0 is LOCAL. So skip it.
12011202
for (size_t i = 1, end = firstGlobal; i != end; ++i) {
1202-
Err(ctx) << "CMSE symbol '" << CHECK(eSyms[i].getName(stringTable), this)
1203+
Err(ctx) << "CMSE symbol '" << CHECK2(eSyms[i].getName(stringTable), this)
12031204
<< "' in import library '" << this << "' is not global";
12041205
}
12051206

@@ -1209,7 +1210,7 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
12091210

12101211
// Initialize symbol fields.
12111212
memset(static_cast<void *>(sym), 0, sizeof(Symbol));
1212-
sym->setName(CHECK(eSyms[i].getName(stringTable), this));
1213+
sym->setName(CHECK2(eSyms[i].getName(stringTable), this));
12131214
sym->value = eSym.st_value;
12141215
sym->size = eSym.st_size;
12151216
sym->type = eSym.getType();
@@ -1248,15 +1249,16 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
12481249

12491250
// Check symbol attributes of the acleSeSym, sym pair.
12501251
// Both symbols should be global/weak Thumb code symbol definitions.
1251-
static std::string checkCmseSymAttributes(Symbol *acleSeSym, Symbol *sym) {
1252-
auto check = [](Symbol *s, StringRef type) -> std::optional<std::string> {
1252+
static std::string checkCmseSymAttributes(Ctx &ctx, Symbol *acleSeSym,
1253+
Symbol *sym) {
1254+
auto check = [&](Symbol *s, StringRef type) -> std::optional<std::string> {
12531255
auto d = dyn_cast_or_null<Defined>(s);
12541256
if (!(d && d->isFunc() && (d->value & 1)))
1255-
return (Twine(toString(s->file)) + ": cmse " + type + " symbol '" +
1257+
return (Twine(toStr(ctx, s->file)) + ": cmse " + type + " symbol '" +
12561258
s->getName() + "' is not a Thumb function definition")
12571259
.str();
12581260
if (!d->section)
1259-
return (Twine(toString(s->file)) + ": cmse " + type + " symbol '" +
1261+
return (Twine(toStr(ctx, s->file)) + ": cmse " + type + " symbol '" +
12601262
s->getName() + "' cannot be an absolute symbol")
12611263
.str();
12621264
return std::nullopt;
@@ -1305,7 +1307,7 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
13051307
continue;
13061308
}
13071309

1308-
std::string errMsg = checkCmseSymAttributes(acleSeSym, sym);
1310+
std::string errMsg = checkCmseSymAttributes(ctx, acleSeSym, sym);
13091311
if (!errMsg.empty()) {
13101312
ErrAlways(ctx) << errMsg;
13111313
continue;

lld/ELF/Arch/Hexagon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ int64_t Hexagon::getImplicitAddend(const uint8_t *buf, RelType type) const {
412412
return SignExtend64<32>(read32(ctx, buf));
413413
default:
414414
internalLinkerError(getErrorLoc(ctx, buf),
415-
"cannot read addend for relocation " + toString(type));
415+
"cannot read addend for relocation " +
416+
toStr(ctx, type));
416417
return 0;
417418
}
418419
}

lld/ELF/Arch/LoongArch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ int64_t LoongArch::getImplicitAddend(const uint8_t *buf, RelType type) const {
280280
switch (type) {
281281
default:
282282
internalLinkerError(getErrorLoc(ctx, buf),
283-
"cannot read addend for relocation " + toString(type));
283+
"cannot read addend for relocation " +
284+
toStr(ctx, type));
284285
return 0;
285286
case R_LARCH_32:
286287
case R_LARCH_TLS_DTPMOD32:

lld/ELF/Arch/Mips.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *buf, RelType type) const {
476476
return 0;
477477
default:
478478
internalLinkerError(getErrorLoc(ctx, buf),
479-
"cannot read addend for relocation " + toString(type));
479+
"cannot read addend for relocation " +
480+
toStr(ctx, type));
480481
return 0;
481482
}
482483
}

lld/ELF/Arch/PPC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ int64_t PPC::getImplicitAddend(const uint8_t *buf, RelType type) const {
297297
return SignExtend64<32>(read32(ctx, buf));
298298
default:
299299
internalLinkerError(getErrorLoc(ctx, buf),
300-
"cannot read addend for relocation " + toString(type));
300+
"cannot read addend for relocation " +
301+
toStr(ctx, type));
301302
return 0;
302303
}
303304
}

lld/ELF/Arch/PPC64.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,8 @@ int64_t PPC64::getImplicitAddend(const uint8_t *buf, RelType type) const {
11311131
return read64(ctx, buf);
11321132
default:
11331133
internalLinkerError(getErrorLoc(ctx, buf),
1134-
"cannot read addend for relocation " + toString(type));
1134+
"cannot read addend for relocation " +
1135+
toStr(ctx, type));
11351136
return 0;
11361137
}
11371138
}
@@ -1618,7 +1619,7 @@ void PPC64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
16181619
rel.sym->file != sec.file) {
16191620
// Use substr(6) to remove the "__plt_" prefix.
16201621
Err(ctx) << getErrorLoc(ctx, loc) << "call to "
1621-
<< lld::toString(*rel.sym).substr(6)
1622+
<< toStr(ctx, *rel.sym).substr(6)
16221623
<< " lacks nop, can't restore toc";
16231624
break;
16241625
}

lld/ELF/Arch/RISCV.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ int64_t RISCV::getImplicitAddend(const uint8_t *buf, RelType type) const {
173173
switch (type) {
174174
default:
175175
internalLinkerError(getErrorLoc(ctx, buf),
176-
"cannot read addend for relocation " + toString(type));
176+
"cannot read addend for relocation " +
177+
toStr(ctx, type));
177178
return 0;
178179
case R_RISCV_32:
179180
case R_RISCV_TLS_DTPMOD32:

lld/ELF/Arch/SystemZ.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ int64_t SystemZ::getImplicitAddend(const uint8_t *buf, RelType type) const {
262262
return 0;
263263
default:
264264
internalLinkerError(getErrorLoc(ctx, buf),
265-
"cannot read addend for relocation " + toString(type));
265+
"cannot read addend for relocation " +
266+
toStr(ctx, type));
266267
return 0;
267268
}
268269
}

0 commit comments

Comments
 (0)