Skip to content

Commit 9b058bb

Browse files
committed
[ELF] Replace errorOrWarn(...) with Err
1 parent f8bae3a commit 9b058bb

16 files changed

+174
-178
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,8 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
11991199
ArrayRef<Elf_Sym> eSyms = getELFSyms<ELFT>();
12001200
// Error for local symbols. The symbol at index 0 is LOCAL. So skip it.
12011201
for (size_t i = 1, end = firstGlobal; i != end; ++i) {
1202-
errorOrWarn("CMSE symbol '" + CHECK(eSyms[i].getName(stringTable), this) +
1203-
"' in import library '" + toString(this) + "' is not global");
1202+
Err(ctx) << "CMSE symbol '" << CHECK(eSyms[i].getName(stringTable), this)
1203+
<< "' in import library '" << this << "' is not global";
12041204
}
12051205

12061206
for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i) {

lld/ELF/Arch/LoongArch.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static void handleUleb128(Ctx &ctx, uint8_t *loc, uint64_t val) {
165165
const char *error = nullptr;
166166
uint64_t orig = decodeULEB128(loc, &count, nullptr, &error);
167167
if (count > maxcount || (count == maxcount && error))
168-
errorOrWarn(getErrorLoc(ctx, loc) + "extra space for uleb128");
168+
Err(ctx) << getErrorLoc(ctx, loc) << "extra space for uleb128";
169169
uint64_t mask = count < maxcount ? (1ULL << 7 * count) - 1 : -1ULL;
170170
encodeULEB128((orig + val) & mask, loc, count);
171171
}
@@ -774,10 +774,10 @@ static bool relax(Ctx &ctx, InputSection &sec) {
774774
remove = allBytes - curBytes;
775775
// If we can't satisfy this alignment, we've found a bad input.
776776
if (LLVM_UNLIKELY(static_cast<int32_t>(remove) < 0)) {
777-
errorOrWarn(getErrorLoc(ctx, (const uint8_t *)loc) +
778-
"insufficient padding bytes for " + lld::toString(r.type) +
779-
": " + Twine(allBytes) + " bytes available for " +
780-
"requested alignment of " + Twine(align) + " bytes");
777+
Err(ctx) << getErrorLoc(ctx, (const uint8_t *)loc)
778+
<< "insufficient padding bytes for " << lld::toString(r.type)
779+
<< ": " << Twine(allBytes) << " bytes available for "
780+
<< "requested alignment of " << Twine(align) << " bytes";
781781
remove = 0;
782782
}
783783
break;

lld/ELF/Arch/PPC64.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,9 @@ void PPC64::relaxGot(uint8_t *loc, const Relocation &rel, uint64_t val) const {
694694
// to ensure we don't miss these opportunities in real code. It can be
695695
// removed at a later date.
696696
if (pcRelInsn == UINT64_C(-1)) {
697-
errorOrWarn(
698-
"unrecognized instruction for R_PPC64_PCREL_OPT relaxation: 0x" +
699-
Twine::utohexstr(accessInsn));
697+
Err(ctx)
698+
<< "unrecognized instruction for R_PPC64_PCREL_OPT relaxation: 0x"
699+
<< Twine::utohexstr(accessInsn);
700700
break;
701701
}
702702

@@ -770,7 +770,7 @@ void PPC64::relaxTlsGdToLe(uint8_t *loc, const Relocation &rel,
770770
} else if (locAsInt % 4 == 1) {
771771
write32(ctx, loc - 1, NOP);
772772
} else {
773-
errorOrWarn("R_PPC64_TLSGD has unexpected byte alignment");
773+
Err(ctx) << "R_PPC64_TLSGD has unexpected byte alignment";
774774
}
775775
break;
776776
}
@@ -826,7 +826,7 @@ void PPC64::relaxTlsLdToLe(uint8_t *loc, const Relocation &rel,
826826
} else if (locAsInt % 4 == 1) {
827827
write32(ctx, loc - 1, NOP);
828828
} else {
829-
errorOrWarn("R_PPC64_TLSLD has unexpected byte alignment");
829+
Err(ctx) << "R_PPC64_TLSLD has unexpected byte alignment";
830830
}
831831
break;
832832
}
@@ -956,7 +956,7 @@ void PPC64::relaxTlsIeToLe(uint8_t *loc, const Relocation &rel,
956956
uint32_t tlsInstr = read32(ctx, loc - 1);
957957
uint32_t primaryOp = getPrimaryOpCode(tlsInstr);
958958
if (primaryOp != 31)
959-
errorOrWarn("unrecognized instruction for IE to LE R_PPC64_TLS");
959+
Err(ctx) << "unrecognized instruction for IE to LE R_PPC64_TLS";
960960
uint32_t secondaryOp = (tlsInstr & 0x000007FE) >> 1; // bits 21-30
961961
// The add is a special case and should be turned into a nop. The paddi
962962
// that comes before it will already have computed the address of the
@@ -977,13 +977,13 @@ void PPC64::relaxTlsIeToLe(uint8_t *loc, const Relocation &rel,
977977
if (dFormOp == 0) { // Expecting a DS-Form instruction.
978978
dFormOp = getPPCDSFormOp(secondaryOp);
979979
if (dFormOp == 0)
980-
errorOrWarn("unrecognized instruction for IE to LE R_PPC64_TLS");
980+
Err(ctx) << "unrecognized instruction for IE to LE R_PPC64_TLS";
981981
}
982982
write32(ctx, loc - 1, (dFormOp | (tlsInstr & 0x03ff0000)));
983983
}
984984
} else {
985-
errorOrWarn("R_PPC64_TLS must be either 4 byte aligned or one byte "
986-
"offset from 4 byte aligned");
985+
Err(ctx) << "R_PPC64_TLS must be either 4 byte aligned or one byte "
986+
"offset from 4 byte aligned";
987987
}
988988
break;
989989
}
@@ -1556,7 +1556,7 @@ void PPC64::relaxTlsGdToIe(uint8_t *loc, const Relocation &rel,
15561556
// bl __tls_get_addr(sym@tlsgd) --> add r3, r3, r13
15571557
write32(ctx, loc - 1, 0x7c636a14);
15581558
} else {
1559-
errorOrWarn("R_PPC64_TLSGD has unexpected byte alignment");
1559+
Err(ctx) << "R_PPC64_TLSGD has unexpected byte alignment";
15601560
}
15611561
return;
15621562
}
@@ -1617,9 +1617,9 @@ void PPC64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
16171617
read32(ctx, loc + 4) != 0x60000000) &&
16181618
rel.sym->file != sec.file) {
16191619
// Use substr(6) to remove the "__plt_" prefix.
1620-
errorOrWarn(getErrorLoc(ctx, loc) + "call to " +
1621-
lld::toString(*rel.sym).substr(6) +
1622-
" lacks nop, can't restore toc");
1620+
Err(ctx) << getErrorLoc(ctx, loc) << "call to "
1621+
<< lld::toString(*rel.sym).substr(6)
1622+
<< " lacks nop, can't restore toc";
16231623
break;
16241624
}
16251625
write32(ctx, loc + 4, 0xe8410018); // ld %r2, 24(%r1)

lld/ELF/Arch/RISCV.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -660,15 +660,15 @@ void RISCV::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
660660
auto val = rel.sym->getVA(ctx, rel.addend) -
661661
rel1.sym->getVA(ctx, rel1.addend);
662662
if (overwriteULEB128(loc, val) >= 0x80)
663-
errorOrWarn(sec.getLocation(rel.offset) + ": ULEB128 value " +
664-
Twine(val) + " exceeds available space; references '" +
665-
lld::toString(*rel.sym) + "'");
663+
Err(ctx) << sec.getLocation(rel.offset) << ": ULEB128 value "
664+
<< Twine(val) << " exceeds available space; references '"
665+
<< lld::toString(*rel.sym) << "'";
666666
++i;
667667
continue;
668668
}
669669
}
670-
errorOrWarn(sec.getLocation(rel.offset) +
671-
": R_RISCV_SET_ULEB128 not paired with R_RISCV_SUB_SET128");
670+
Err(ctx) << sec.getLocation(rel.offset)
671+
<< ": R_RISCV_SET_ULEB128 not paired with R_RISCV_SUB_SET128";
672672
return;
673673
default:
674674
break;
@@ -832,12 +832,12 @@ static bool relax(Ctx &ctx, InputSection &sec) {
832832
remove = nextLoc - ((loc + align - 1) & -align);
833833
// If we can't satisfy this alignment, we've found a bad input.
834834
if (LLVM_UNLIKELY(static_cast<int32_t>(remove) < 0)) {
835-
errorOrWarn(getErrorLoc(ctx, (const uint8_t *)loc) +
836-
"insufficient padding bytes for " + lld::toString(r.type) +
837-
": " + Twine(r.addend) +
838-
" bytes available "
839-
"for requested alignment of " +
840-
Twine(align) + " bytes");
835+
Err(ctx) << getErrorLoc(ctx, (const uint8_t *)loc)
836+
<< "insufficient padding bytes for " << lld::toString(r.type)
837+
<< ": " << Twine(r.addend)
838+
<< " bytes available "
839+
"for requested alignment of "
840+
<< Twine(align) << " bytes";
841841
remove = 0;
842842
}
843843
break;
@@ -1064,8 +1064,8 @@ static void mergeArch(RISCVISAUtils::OrderedExtensionMap &mergedExts,
10641064
StringRef s) {
10651065
auto maybeInfo = RISCVISAInfo::parseNormalizedArchString(s);
10661066
if (!maybeInfo) {
1067-
errorOrWarn(toString(sec) + ": " + s + ": " +
1068-
llvm::toString(maybeInfo.takeError()));
1067+
Err(ctx) << sec << ": " << s << ": "
1068+
<< llvm::toString(maybeInfo.takeError());
10691069
return;
10701070
}
10711071

@@ -1097,11 +1097,11 @@ static void mergeAtomic(DenseMap<unsigned, unsigned>::iterator it,
10971097
return;
10981098

10991099
auto reportAbiError = [&]() {
1100-
errorOrWarn("atomic abi mismatch for " + oldSection->name + "\n>>> " +
1101-
toString(oldSection) +
1102-
": atomic_abi=" + Twine(static_cast<unsigned>(oldTag)) +
1103-
"\n>>> " + toString(newSection) +
1104-
": atomic_abi=" + Twine(static_cast<unsigned>(newTag)));
1100+
Err(ctx) << "atomic abi mismatch for " << oldSection->name << "\n>>> "
1101+
<< oldSection
1102+
<< ": atomic_abi=" << Twine(static_cast<unsigned>(oldTag))
1103+
<< "\n>>> " << newSection
1104+
<< ": atomic_abi=" << Twine(static_cast<unsigned>(newTag));
11051105
};
11061106

11071107
auto reportUnknownAbiError = [](const InputSectionBase *section,
@@ -1113,9 +1113,8 @@ static void mergeAtomic(DenseMap<unsigned, unsigned>::iterator it,
11131113
case RISCVAtomicAbiTag::A7:
11141114
return;
11151115
};
1116-
errorOrWarn("unknown atomic abi for " + section->name + "\n>>> " +
1117-
toString(section) +
1118-
": atomic_abi=" + Twine(static_cast<unsigned>(tag)));
1116+
Err(ctx) << "unknown atomic abi for " << section->name << "\n>>> "
1117+
<< section << ": atomic_abi=" << Twine(static_cast<unsigned>(tag));
11191118
};
11201119
switch (oldTag) {
11211120
case RISCVAtomicAbiTag::UNKNOWN:
@@ -1200,9 +1199,9 @@ mergeAttributesSection(Ctx &ctx,
12001199
firstStackAlign = sec;
12011200
firstStackAlignValue = *i;
12021201
} else if (r.first->second != *i) {
1203-
errorOrWarn(toString(sec) + " has stack_align=" + Twine(*i) +
1204-
" but " + toString(firstStackAlign) +
1205-
" has stack_align=" + Twine(firstStackAlignValue));
1202+
Err(ctx) << sec << " has stack_align=" << Twine(*i) << " but "
1203+
<< firstStackAlign
1204+
<< " has stack_align=" << Twine(firstStackAlignValue);
12061205
}
12071206
}
12081207
continue;
@@ -1262,7 +1261,7 @@ mergeAttributesSection(Ctx &ctx,
12621261
merged.strAttr.try_emplace(RISCVAttrs::ARCH,
12631262
saver().save((*result)->toString()));
12641263
} else {
1265-
errorOrWarn(llvm::toString(result.takeError()));
1264+
Err(ctx) << llvm::toString(result.takeError());
12661265
}
12671266
}
12681267

lld/ELF/Arch/X86_64.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,9 @@ void X86_64::relaxTlsGdToLe(uint8_t *loc, const Relocation &rel,
490490
// Convert leaq x@tlsdesc(%rip), %REG to movq $x@tpoff, %REG.
491491
if ((loc[-3] & 0xfb) != 0x48 || loc[-2] != 0x8d ||
492492
(loc[-1] & 0xc7) != 0x05) {
493-
errorOrWarn(getErrorLoc(ctx, loc - 3) +
494-
"R_X86_64_GOTPC32_TLSDESC must be used "
495-
"in leaq x@tlsdesc(%rip), %REG");
493+
Err(ctx) << getErrorLoc(ctx, loc - 3)
494+
<< "R_X86_64_GOTPC32_TLSDESC must be used "
495+
"in leaq x@tlsdesc(%rip), %REG";
496496
return;
497497
}
498498
loc[-3] = 0x48 | ((loc[-3] >> 2) & 1);
@@ -532,9 +532,9 @@ void X86_64::relaxTlsGdToIe(uint8_t *loc, const Relocation &rel,
532532
assert(rel.type == R_X86_64_GOTPC32_TLSDESC);
533533
if ((loc[-3] & 0xfb) != 0x48 || loc[-2] != 0x8d ||
534534
(loc[-1] & 0xc7) != 0x05) {
535-
errorOrWarn(getErrorLoc(ctx, loc - 3) +
536-
"R_X86_64_GOTPC32_TLSDESC must be used "
537-
"in leaq x@tlsdesc(%rip), %REG");
535+
Err(ctx) << getErrorLoc(ctx, loc - 3)
536+
<< "R_X86_64_GOTPC32_TLSDESC must be used "
537+
"in leaq x@tlsdesc(%rip), %REG";
538538
return;
539539
}
540540
loc[-2] = 0x8b;

lld/ELF/Driver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,11 +2851,11 @@ static void readSecurityNotes(Ctx &ctx) {
28512851
}
28522852

28532853
if (ctx.aarch64PauthAbiCoreInfo != f->aarch64PauthAbiCoreInfo)
2854-
errorOrWarn("incompatible values of AArch64 PAuth core info found\n>>> " +
2855-
referenceFileName + ": 0x" +
2856-
toHex(ctx.aarch64PauthAbiCoreInfo, /*LowerCase=*/true) +
2857-
"\n>>> " + toString(f) + ": 0x" +
2858-
toHex(f->aarch64PauthAbiCoreInfo, /*LowerCase=*/true));
2854+
Err(ctx) << "incompatible values of AArch64 PAuth core info found\n>>> "
2855+
<< referenceFileName << ": 0x"
2856+
<< toHex(ctx.aarch64PauthAbiCoreInfo, /*LowerCase=*/true)
2857+
<< "\n>>> " << f << ": 0x"
2858+
<< toHex(f->aarch64PauthAbiCoreInfo, /*LowerCase=*/true);
28592859
}
28602860

28612861
// Force enable Shadow Stack.

lld/ELF/InputFiles.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,8 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
863863
ctx.hasSympart.store(true, std::memory_order_relaxed);
864864
else if (ctx.arg.rejectMismatch &&
865865
!isKnownSpecificSectionType(type, sec.sh_flags))
866-
errorOrWarn(toString(this->sections[i]) + ": unknown section type 0x" +
867-
Twine::utohexstr(type));
866+
Err(ctx) << this->sections[i] << ": unknown section type 0x"
867+
<< Twine::utohexstr(type);
868868
break;
869869
}
870870
}
@@ -1247,17 +1247,17 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
12471247
uint8_t binding = eSym.getBinding();
12481248
if (LLVM_UNLIKELY(binding != STB_GLOBAL && binding != STB_WEAK &&
12491249
binding != STB_GNU_UNIQUE))
1250-
errorOrWarn(toString(this) + ": symbol (" + Twine(i) +
1251-
") has invalid binding: " + Twine((int)binding));
1250+
Err(ctx) << this << ": symbol (" << Twine(i)
1251+
<< ") has invalid binding: " << Twine((int)binding);
12521252

12531253
// st_value of STT_TLS represents the assigned offset, not the actual
12541254
// address which is used by STT_FUNC and STT_OBJECT. STT_TLS symbols can
12551255
// only be referenced by special TLS relocations. It is usually an error if
12561256
// a STT_TLS symbol is replaced by a non-STT_TLS symbol, vice versa.
12571257
if (LLVM_UNLIKELY(sym.isTls()) && eSym.getType() != STT_TLS &&
12581258
eSym.getType() != STT_NOTYPE)
1259-
errorOrWarn("TLS attribute mismatch: " + toString(sym) + "\n>>> in " +
1260-
toString(sym.file) + "\n>>> in " + toString(this));
1259+
Err(ctx) << "TLS attribute mismatch: " << &sym << "\n>>> in " << sym.file
1260+
<< "\n>>> in " << this;
12611261

12621262
// Handle non-COMMON defined symbol below. !sym.file allows a symbol
12631263
// assignment to redefine a symbol without an error.
@@ -1563,8 +1563,8 @@ template <class ELFT> void SharedFile::parse() {
15631563
// symbol, that's a violation of the spec.
15641564
StringRef name = CHECK(sym.getName(stringTable), this);
15651565
if (sym.getBinding() == STB_LOCAL) {
1566-
errorOrWarn(toString(this) + ": invalid local symbol '" + name +
1567-
"' in global part of symbol table");
1566+
Err(ctx) << this << ": invalid local symbol '" << name
1567+
<< "' in global part of symbol table";
15681568
continue;
15691569
}
15701570

lld/ELF/InputSection.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -646,19 +646,18 @@ static Relocation *getRISCVPCRelHi20(const InputSectionBase *loSec,
646646

647647
const Defined *d = cast<Defined>(sym);
648648
if (!d->section) {
649-
errorOrWarn(
650-
loSec->getLocation(loReloc.offset) +
651-
": R_RISCV_PCREL_LO12 relocation points to an absolute symbol: " +
652-
sym->getName());
649+
Err(ctx) << loSec->getLocation(loReloc.offset)
650+
<< ": R_RISCV_PCREL_LO12 relocation points to an absolute symbol: "
651+
<< sym->getName();
653652
return nullptr;
654653
}
655654
InputSection *hiSec = cast<InputSection>(d->section);
656655

657656
if (hiSec != loSec)
658-
errorOrWarn(loSec->getLocation(loReloc.offset) +
659-
": R_RISCV_PCREL_LO12 relocation points to a symbol '" +
660-
sym->getName() + "' in a different section '" + hiSec->name +
661-
"'");
657+
Err(ctx) << loSec->getLocation(loReloc.offset)
658+
<< ": R_RISCV_PCREL_LO12 relocation points to a symbol '"
659+
<< sym->getName() << "' in a different section '" << hiSec->name
660+
<< "'";
662661

663662
if (addend != 0)
664663
Warn(ctx) << loSec->getLocation(loReloc.offset)
@@ -680,10 +679,10 @@ static Relocation *getRISCVPCRelHi20(const InputSectionBase *loSec,
680679
it->type == R_RISCV_TLS_GD_HI20 || it->type == R_RISCV_TLS_GOT_HI20)
681680
return &*it;
682681

683-
errorOrWarn(loSec->getLocation(loReloc.offset) +
684-
": R_RISCV_PCREL_LO12 relocation points to " +
685-
hiSec->getObjMsg(d->value) +
686-
" without an associated R_RISCV_PCREL_HI20 relocation");
682+
Err(ctx) << loSec->getLocation(loReloc.offset)
683+
<< ": R_RISCV_PCREL_LO12 relocation points to "
684+
<< hiSec->getObjMsg(d->value)
685+
<< " without an associated R_RISCV_PCREL_HI20 relocation";
687686
return nullptr;
688687
}
689688

@@ -1031,13 +1030,13 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
10311030
(f->getRelocTargetSym(*it).getVA(ctx) + getAddend<ELFT>(*it));
10321031
}
10331032
if (overwriteULEB128(bufLoc, val) >= 0x80)
1034-
errorOrWarn(getLocation(offset) + ": ULEB128 value " + Twine(val) +
1035-
" exceeds available space; references '" +
1036-
lld::toString(sym) + "'");
1033+
Err(ctx) << getLocation(offset) << ": ULEB128 value " << Twine(val)
1034+
<< " exceeds available space; references '"
1035+
<< lld::toString(sym) << "'";
10371036
continue;
10381037
}
1039-
errorOrWarn(getLocation(offset) +
1040-
": R_RISCV_SET_ULEB128 not paired with R_RISCV_SUB_SET128");
1038+
Err(ctx) << getLocation(offset)
1039+
<< ": R_RISCV_SET_ULEB128 not paired with R_RISCV_SUB_SET128";
10411040
return;
10421041
}
10431042

@@ -1109,7 +1108,7 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
11091108
toString(type) + " against symbol '" + toString(sym) +
11101109
"'";
11111110
if (expr != R_PC && !(emachine == EM_386 && type == R_386_GOTPC)) {
1112-
errorOrWarn(msg);
1111+
Err(ctx) << msg;
11131112
return;
11141113
}
11151114

@@ -1369,8 +1368,8 @@ void EhInputSection::split(ArrayRef<RelTy> rels) {
13691368
d = d.slice(size);
13701369
}
13711370
if (msg)
1372-
errorOrWarn("corrupted .eh_frame: " + Twine(msg) + "\n>>> defined in " +
1373-
getObjMsg(d.data() - content().data()));
1371+
Err(ctx) << "corrupted .eh_frame: " << Twine(msg) << "\n>>> defined in "
1372+
<< getObjMsg(d.data() - content().data());
13741373
}
13751374

13761375
// Return the offset in an output section for a given input offset.

0 commit comments

Comments
 (0)