Skip to content

Commit 09c2c5e

Browse files
committed
[ELF] Replace error(...) with ErrAlways or Err
Most are migrated to ErrAlways mechanically. In the future we should change most to Err.
1 parent 63c6fe4 commit 09c2c5e

32 files changed

+440
-376
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
213213
case R_AARCH64_NONE:
214214
return R_NONE;
215215
default:
216-
error(getErrorLoc(ctx, loc) + "unknown relocation (" + Twine(type) +
217-
") against symbol " + toString(s));
216+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
217+
<< ") against symbol " << &s;
218218
return R_NONE;
219219
}
220220
}
@@ -1113,7 +1113,8 @@ addTaggedSymbolReferences(InputSectionBase &sec,
11131113

11141114
const RelsOrRelas<ELFT> rels = sec.relsOrRelas<ELFT>();
11151115
if (rels.areRelocsRel())
1116-
error("non-RELA relocations are not allowed with memtag globals");
1116+
ErrAlways(ctx)
1117+
<< "non-RELA relocations are not allowed with memtag globals";
11171118

11181119
for (const typename ELFT::Rela &rel : rels.relas) {
11191120
Symbol &sym = sec.file->getRelocTargetSym(rel);
@@ -1196,7 +1197,7 @@ void elf::createTaggedSymbols(Ctx &ctx) {
11961197
// relocations, the only other way to get written addends is with
11971198
// --apply-dynamic-relocs.
11981199
if (!taggedSymbolReferenceCount.empty() && ctx.arg.writeAddends)
1199-
error("--apply-dynamic-relocs cannot be used with MTE globals");
1200+
ErrAlways(ctx) << "--apply-dynamic-relocs cannot be used with MTE globals";
12001201

12011202
// Now, `taggedSymbolReferenceCount` should only contain symbols that are
12021203
// defined as tagged exactly the same amount as it's referenced, meaning all

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ uint32_t AMDGPU::calcEFlagsV3() const {
5656
for (InputFile *f : ArrayRef(ctx.objectFiles).slice(1)) {
5757
if (ret == getEFlags(f))
5858
continue;
59-
error("incompatible e_flags: " + toString(f));
59+
ErrAlways(ctx) << "incompatible e_flags: " << f;
6060
return 0;
6161
}
6262
return ret;
@@ -73,7 +73,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
7373
// features in the same category are either ANY, ANY and ON, or ANY and OFF).
7474
for (InputFile *f : ArrayRef(ctx.objectFiles).slice(1)) {
7575
if (retMach != (getEFlags(f) & EF_AMDGPU_MACH)) {
76-
error("incompatible mach: " + toString(f));
76+
ErrAlways(ctx) << "incompatible mach: " << f;
7777
return 0;
7878
}
7979

@@ -82,7 +82,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
8282
(getEFlags(f) & EF_AMDGPU_FEATURE_XNACK_V4)
8383
!= EF_AMDGPU_FEATURE_XNACK_ANY_V4)) {
8484
if (retXnack != (getEFlags(f) & EF_AMDGPU_FEATURE_XNACK_V4)) {
85-
error("incompatible xnack: " + toString(f));
85+
ErrAlways(ctx) << "incompatible xnack: " << f;
8686
return 0;
8787
}
8888
} else {
@@ -95,7 +95,7 @@ uint32_t AMDGPU::calcEFlagsV4() const {
9595
(getEFlags(f) & EF_AMDGPU_FEATURE_SRAMECC_V4) !=
9696
EF_AMDGPU_FEATURE_SRAMECC_ANY_V4)) {
9797
if (retSramEcc != (getEFlags(f) & EF_AMDGPU_FEATURE_SRAMECC_V4)) {
98-
error("incompatible sramecc: " + toString(f));
98+
ErrAlways(ctx) << "incompatible sramecc: " << f;
9999
return 0;
100100
}
101101
} else {
@@ -116,7 +116,7 @@ uint32_t AMDGPU::calcEFlagsV6() const {
116116
// Verify that all input files have compatible generic version.
117117
for (InputFile *f : ArrayRef(ctx.objectFiles).slice(1)) {
118118
if (genericVersion != (getEFlags(f) & EF_AMDGPU_GENERIC_VERSION)) {
119-
error("incompatible generic version: " + toString(f));
119+
ErrAlways(ctx) << "incompatible generic version: " << f;
120120
return 0;
121121
}
122122
}
@@ -143,7 +143,7 @@ uint32_t AMDGPU::calcEFlags() const {
143143
case ELFABIVERSION_AMDGPU_HSA_V6:
144144
return calcEFlagsV6();
145145
default:
146-
error("unknown abi version: " + Twine(abiVersion));
146+
ErrAlways(ctx) << "unknown abi version: " << Twine(abiVersion);
147147
return 0;
148148
}
149149
}
@@ -193,8 +193,8 @@ RelExpr AMDGPU::getRelExpr(RelType type, const Symbol &s,
193193
case R_AMDGPU_GOTPCREL32_HI:
194194
return R_GOT_PC;
195195
default:
196-
error(getErrorLoc(ctx, loc) + "unknown relocation (" + Twine(type) +
197-
") against symbol " + toString(s));
196+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
197+
<< ") against symbol " << &s;
198198
return R_NONE;
199199
}
200200
}

lld/ELF/Arch/ARM.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
195195
// not ARMv4 output, we can just ignore it.
196196
return R_NONE;
197197
default:
198-
error(getErrorLoc(ctx, loc) + "unknown relocation (" + Twine(type) +
199-
") against symbol " + toString(s));
198+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
199+
<< ") against symbol " << &s;
200200
return R_NONE;
201201
}
202202
}
@@ -556,8 +556,8 @@ void ARM::encodeAluGroup(uint8_t *loc, const Relocation &rel, uint64_t val,
556556
rot = (lz + 8) << 7;
557557
}
558558
if (check && imm > 0xff)
559-
error(getErrorLoc(ctx, loc) + "unencodeable immediate " + Twine(val).str() +
560-
" for relocation " + toString(rel.type));
559+
Err(ctx) << getErrorLoc(ctx, loc) << "unencodeable immediate "
560+
<< Twine(val).str() << " for relocation " << rel.type;
561561
write32(ctx, loc,
562562
(read32(ctx, loc) & 0xff3ff000) | opcode | rot | (imm & 0xff));
563563
}
@@ -1216,20 +1216,22 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
12161216
sym->stOther = eSym.st_other;
12171217

12181218
if (eSym.st_shndx != SHN_ABS) {
1219-
error("CMSE symbol '" + sym->getName() + "' in import library '" +
1220-
toString(this) + "' is not absolute");
1219+
ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
1220+
<< "' in import library '" << this << "' is not absolute";
12211221
continue;
12221222
}
12231223

12241224
if (!(eSym.st_value & 1) || (eSym.getType() != STT_FUNC)) {
1225-
error("CMSE symbol '" + sym->getName() + "' in import library '" +
1226-
toString(this) + "' is not a Thumb function definition");
1225+
ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
1226+
<< "' in import library '" << this
1227+
<< "' is not a Thumb function definition";
12271228
continue;
12281229
}
12291230

12301231
if (ctx.symtab->cmseImportLib.count(sym->getName())) {
1231-
error("CMSE symbol '" + sym->getName() +
1232-
"' is multiply defined in import library '" + toString(this) + "'");
1232+
ErrAlways(ctx) << "CMSE symbol '" << sym->getName()
1233+
<< "' is multiply defined in import library '" << this
1234+
<< "'";
12331235
continue;
12341236
}
12351237

@@ -1283,7 +1285,8 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
12831285
// If input object build attributes do not support CMSE, error and disable
12841286
// further scanning for <sym>, __acle_se_<sym> pairs.
12851287
if (!ctx.arg.armCMSESupport) {
1286-
error("CMSE is only supported by ARMv8-M architecture or later");
1288+
ErrAlways(ctx)
1289+
<< "CMSE is only supported by ARMv8-M architecture or later";
12871290
ctx.arg.cmseImplib = false;
12881291
break;
12891292
}
@@ -1293,16 +1296,17 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
12931296
StringRef name = acleSeSym->getName().substr(std::strlen(ACLESESYM_PREFIX));
12941297
Symbol *sym = ctx.symtab->find(name);
12951298
if (!sym) {
1296-
error(toString(acleSeSym->file) + ": cmse special symbol '" +
1297-
acleSeSym->getName() +
1298-
"' detected, but no associated entry function definition '" + name +
1299-
"' with external linkage found");
1299+
ErrAlways(ctx)
1300+
<< acleSeSym->file << ": cmse special symbol '"
1301+
<< acleSeSym->getName()
1302+
<< "' detected, but no associated entry function definition '" << name
1303+
<< "' with external linkage found";
13001304
continue;
13011305
}
13021306

13031307
std::string errMsg = checkCmseSymAttributes(acleSeSym, sym);
13041308
if (!errMsg.empty()) {
1305-
error(errMsg);
1309+
ErrAlways(ctx) << errMsg;
13061310
continue;
13071311
}
13081312

@@ -1432,7 +1436,8 @@ void ArmCmseSGSection::finalizeContents() {
14321436
// Check if the start address of '.gnu.sgstubs' correspond to the
14331437
// linker-synthesized veneer with the lowest address.
14341438
if ((getVA() & ~1) != (addr & ~1)) {
1435-
error("start address of '.gnu.sgstubs' is different from previous link");
1439+
ErrAlways(ctx)
1440+
<< "start address of '.gnu.sgstubs' is different from previous link";
14361441
return;
14371442
}
14381443

@@ -1500,8 +1505,8 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
15001505
Expected<std::unique_ptr<FileOutputBuffer>> bufferOrErr =
15011506
FileOutputBuffer::create(ctx.arg.cmseOutputLib, fileSize, flags);
15021507
if (!bufferOrErr) {
1503-
error("failed to open " + ctx.arg.cmseOutputLib + ": " +
1504-
llvm::toString(bufferOrErr.takeError()));
1508+
ErrAlways(ctx) << "failed to open " << ctx.arg.cmseOutputLib << ": "
1509+
<< llvm::toString(bufferOrErr.takeError());
15051510
return;
15061511
}
15071512

lld/ELF/Arch/AVR.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ RelExpr AVR::getRelExpr(RelType type, const Symbol &s,
9393
case R_AVR_13_PCREL:
9494
return R_PC;
9595
default:
96-
error(getErrorLoc(ctx, loc) + "unknown relocation (" + Twine(type) +
97-
") against symbol " + toString(s));
96+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
97+
<< ") against symbol " << &s;
9898
return R_NONE;
9999
}
100100
}
@@ -282,8 +282,8 @@ uint32_t AVR::calcEFlags() const {
282282
for (InputFile *f : ArrayRef(ctx.objectFiles).slice(1)) {
283283
uint32_t objFlags = getEFlags(f);
284284
if ((objFlags & EF_AVR_ARCH_MASK) != (flags & EF_AVR_ARCH_MASK))
285-
error(toString(f) +
286-
": cannot link object files with incompatible target ISA");
285+
ErrAlways(ctx)
286+
<< f << ": cannot link object files with incompatible target ISA";
287287
if (!(objFlags & EF_AVR_LINKRELAX_PREPARED))
288288
hasLinkRelaxFlag = false;
289289
}

lld/ELF/Arch/Hexagon.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s,
153153
case R_HEX_TPREL_LO16:
154154
return R_TPREL;
155155
default:
156-
error(getErrorLoc(ctx, loc) + "unknown relocation (" + Twine(type) +
157-
") against symbol " + toString(s));
156+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
157+
<< ") against symbol " << &s;
158158
return R_NONE;
159159
}
160160
}
@@ -198,8 +198,8 @@ static uint32_t findMaskR6(uint32_t insn) {
198198
if ((0xff000000 & insn) == i.cmpMask)
199199
return i.relocMask;
200200

201-
error("unrecognized instruction for 6_X relocation: 0x" +
202-
utohexstr(insn));
201+
ErrAlways(ctx) << "unrecognized instruction for 6_X relocation: 0x"
202+
<< utohexstr(insn);
203203
return 0;
204204
}
205205

@@ -246,8 +246,8 @@ static uint32_t findMaskR16(uint32_t insn) {
246246
if ((0xff000000 & insn) == i.cmpMask)
247247
return i.relocMask;
248248

249-
error("unrecognized instruction for 16_X type: 0x" +
250-
utohexstr(insn));
249+
ErrAlways(ctx) << "unrecognized instruction for 16_X type: 0x"
250+
<< utohexstr(insn);
251251
return 0;
252252
}
253253

lld/ELF/Arch/LoongArch.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ uint32_t LoongArch::calcEFlags() const {
250250

251251
if ((flags & EF_LOONGARCH_ABI_MODIFIER_MASK) !=
252252
(target & EF_LOONGARCH_ABI_MODIFIER_MASK))
253-
error(toString(f) +
254-
": cannot link object files with different ABI from " +
255-
toString(targetFile));
253+
ErrAlways(ctx) << f
254+
<< ": cannot link object files with different ABI from "
255+
<< targetFile;
256256

257257
// We cannot process psABI v1.x / object ABI v0 files (containing stack
258258
// relocations), unlike ld.bfd.
@@ -270,7 +270,7 @@ uint32_t LoongArch::calcEFlags() const {
270270
// and the few impacted users are advised to simply rebuild world or
271271
// reinstall a recent system.
272272
if ((flags & EF_LOONGARCH_OBJABI_MASK) != EF_LOONGARCH_OBJABI_V1)
273-
error(toString(f) + ": unsupported object file ABI version");
273+
ErrAlways(ctx) << f << ": unsupported object file ABI version";
274274
}
275275

276276
return target;
@@ -528,8 +528,8 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
528528
//
529529
// [1]: https://web.archive.org/web/20230709064026/https://github.com/loongson/LoongArch-Documentation/issues/51
530530
default:
531-
error(getErrorLoc(ctx, loc) + "unknown relocation (" + Twine(type) +
532-
") against symbol " + toString(s));
531+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
532+
<< ") against symbol " << &s;
533533
return R_NONE;
534534
}
535535
}

lld/ELF/Arch/MSP430.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ void MSP430::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
8383
break;
8484
}
8585
default:
86-
error(getErrorLoc(ctx, loc) + "unrecognized relocation " +
87-
toString(rel.type));
86+
Err(ctx) << getErrorLoc(ctx, loc) << "unrecognized relocation " << rel.type;
8887
}
8988
}
9089

lld/ELF/Arch/Mips.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,
191191
case R_MIPS_NONE:
192192
return R_NONE;
193193
default:
194-
error(getErrorLoc(ctx, loc) + "unknown relocation (" + Twine(type) +
195-
") against symbol " + toString(s));
194+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
195+
<< ") against symbol " << &s;
196196
return R_NONE;
197197
}
198198
}
@@ -503,8 +503,8 @@ calculateMipsRelChain(Ctx &ctx, uint8_t *loc, RelType type, uint64_t val) {
503503
return std::make_pair(type2, val);
504504
if (type2 == R_MIPS_SUB && (type3 == R_MIPS_HI16 || type3 == R_MIPS_LO16))
505505
return std::make_pair(type3, -val);
506-
error(getErrorLoc(ctx, loc) + "unsupported relocations combination " +
507-
Twine(type));
506+
Err(ctx) << getErrorLoc(ctx, loc) << "unsupported relocations combination "
507+
<< Twine(type);
508508
return std::make_pair(type & 0xff, val);
509509
}
510510

@@ -562,9 +562,10 @@ static uint64_t fixupCrossModeJump(Ctx &ctx, uint8_t *loc, RelType type,
562562
llvm_unreachable("unexpected jump/branch relocation");
563563
}
564564

565-
error(getErrorLoc(ctx, loc) +
566-
"unsupported jump/branch instruction between ISA modes referenced by " +
567-
toString(type) + " relocation");
565+
ErrAlways(ctx)
566+
<< getErrorLoc(ctx, loc)
567+
<< "unsupported jump/branch instruction between ISA modes referenced by "
568+
<< type << " relocation";
568569
return val;
569570
}
570571

lld/ELF/Arch/MipsArchTree.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,24 @@ static void checkFlags(Ctx &ctx, ArrayRef<FileFlags> files) {
7272

7373
for (const FileFlags &f : files) {
7474
if (ctx.arg.is64 && f.flags & EF_MIPS_MICROMIPS)
75-
error(toString(f.file) + ": microMIPS 64-bit is not supported");
75+
ErrAlways(ctx) << f.file << ": microMIPS 64-bit is not supported";
7676

7777
uint32_t abi2 = f.flags & (EF_MIPS_ABI | EF_MIPS_ABI2);
7878
if (abi != abi2)
79-
error(toString(f.file) + ": ABI '" + getAbiName(abi2) +
80-
"' is incompatible with target ABI '" + getAbiName(abi) + "'");
79+
ErrAlways(ctx) << f.file << ": ABI '" << getAbiName(abi2)
80+
<< "' is incompatible with target ABI '" << getAbiName(abi)
81+
<< "'";
8182

8283
bool nan2 = f.flags & EF_MIPS_NAN2008;
8384
if (nan != nan2)
84-
error(toString(f.file) + ": -mnan=" + getNanName(nan2) +
85-
" is incompatible with target -mnan=" + getNanName(nan));
85+
ErrAlways(ctx) << f.file << ": -mnan=" << getNanName(nan2)
86+
<< " is incompatible with target -mnan="
87+
<< getNanName(nan);
8688

8789
bool fp2 = f.flags & EF_MIPS_FP64;
8890
if (fp != fp2)
89-
error(toString(f.file) + ": -mfp" + getFpName(fp2) +
90-
" is incompatible with target -mfp" + getFpName(fp));
91+
ErrAlways(ctx) << f.file << ": -mfp" << getFpName(fp2)
92+
<< " is incompatible with target -mfp" << getFpName(fp);
9193
}
9294
}
9395

@@ -284,9 +286,9 @@ static uint32_t getArchFlags(ArrayRef<FileFlags> files) {
284286
if (isArchMatched(newFlags, ret))
285287
continue;
286288
if (!isArchMatched(ret, newFlags)) {
287-
error("incompatible target ISA:\n>>> " + toString(files[0].file) + ": " +
288-
getFullArchName(ret) + "\n>>> " + toString(f.file) + ": " +
289-
getFullArchName(newFlags));
289+
ErrAlways(ctx) << "incompatible target ISA:\n>>> " << files[0].file
290+
<< ": " << getFullArchName(ret) << "\n>>> " << f.file
291+
<< ": " << getFullArchName(newFlags);
290292
return 0;
291293
}
292294
ret = newFlags;
@@ -355,9 +357,10 @@ uint8_t elf::getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag,
355357
if (compareMipsFpAbi(newFlag, oldFlag) >= 0)
356358
return newFlag;
357359
if (compareMipsFpAbi(oldFlag, newFlag) < 0)
358-
error(fileName + ": floating point ABI '" + getMipsFpAbiName(newFlag) +
359-
"' is incompatible with target floating point ABI '" +
360-
getMipsFpAbiName(oldFlag) + "'");
360+
ErrAlways(ctx) << fileName << ": floating point ABI '"
361+
<< getMipsFpAbiName(newFlag)
362+
<< "' is incompatible with target floating point ABI '"
363+
<< getMipsFpAbiName(oldFlag) << "'";
361364
return oldFlag;
362365
}
363366

0 commit comments

Comments
 (0)