[lld] be5dad0 - [ELF] Replace internalLinkerError(getErrorLoc(ctx, buf) + ...) with InternalErr(ctx, buf)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 16 13:07:22 PST 2024
Author: Fangrui Song
Date: 2024-11-16T13:07:17-08:00
New Revision: be5dad012eb75d61935f6c76034a8867f7443731
URL: https://github.com/llvm/llvm-project/commit/be5dad012eb75d61935f6c76034a8867f7443731
DIFF: https://github.com/llvm/llvm-project/commit/be5dad012eb75d61935f6c76034a8867f7443731.diff
LOG: [ELF] Replace internalLinkerError(getErrorLoc(ctx, buf) + ...) with InternalErr(ctx, buf)
and simplify `+ toStr(ctx, x)` to `<< x`.
The trailing '\n' << llvm::getBugReportMsg() is not very useful and
therefore removed.
Added:
Modified:
lld/ELF/Arch/AArch64.cpp
lld/ELF/Arch/AMDGPU.cpp
lld/ELF/Arch/ARM.cpp
lld/ELF/Arch/Hexagon.cpp
lld/ELF/Arch/LoongArch.cpp
lld/ELF/Arch/Mips.cpp
lld/ELF/Arch/PPC.cpp
lld/ELF/Arch/PPC64.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/Arch/SystemZ.cpp
lld/ELF/Arch/X86.cpp
lld/ELF/Arch/X86_64.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/OutputSections.cpp
lld/ELF/Target.cpp
lld/include/lld/Common/ErrorHandler.h
Removed:
################################################################################
diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 3d048e81fa7fb4..e66982ce52afd1 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -348,9 +348,7 @@ int64_t AArch64::getImplicitAddend(const uint8_t *buf, RelType type) const {
return SignExtend64<28>(getBits(read32le(buf), 0, 25) << 2);
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/AMDGPU.cpp b/lld/ELF/Arch/AMDGPU.cpp
index 4dd085d2f719f3..fb85291fd77c25 100644
--- a/lld/ELF/Arch/AMDGPU.cpp
+++ b/lld/ELF/Arch/AMDGPU.cpp
@@ -213,9 +213,7 @@ int64_t AMDGPU::getImplicitAddend(const uint8_t *buf, RelType type) const {
case R_AMDGPU_RELATIVE64:
return read64(ctx, buf);
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index b797be9359c077..fa07fb6b537db5 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -875,9 +875,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
case R_ARM_ABS32:
case R_ARM_BASE_PREL:
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 9657c5d098a690..b9e1eeffc07aaf 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -411,9 +411,7 @@ int64_t Hexagon::getImplicitAddend(const uint8_t *buf, RelType type) const {
case R_HEX_TPREL_32:
return SignExtend64<32>(read32(ctx, buf));
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 669cd6103e1da9..7e3e6ee88aae47 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -279,9 +279,7 @@ uint32_t LoongArch::calcEFlags() const {
int64_t LoongArch::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
case R_LARCH_32:
case R_LARCH_TLS_DTPMOD32:
diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp
index 6e8be75da5cc77..b60c9c159e0bb2 100644
--- a/lld/ELF/Arch/Mips.cpp
+++ b/lld/ELF/Arch/Mips.cpp
@@ -475,9 +475,7 @@ int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *buf, RelType type) const {
// These relocations are defined as not having an implicit addend.
return 0;
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/PPC.cpp b/lld/ELF/Arch/PPC.cpp
index 4af2aed73bc456..7f46656521d21a 100644
--- a/lld/ELF/Arch/PPC.cpp
+++ b/lld/ELF/Arch/PPC.cpp
@@ -296,9 +296,7 @@ int64_t PPC::getImplicitAddend(const uint8_t *buf, RelType type) const {
case R_PPC_TPREL32:
return SignExtend64<32>(read32(ctx, buf));
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index e5be461fcfacbb..984e0d3aac9ed6 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -1130,9 +1130,7 @@ int64_t PPC64::getImplicitAddend(const uint8_t *buf, RelType type) const {
case R_PPC64_TPREL64:
return read64(ctx, buf);
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 581c0c16da3004..442bcb055c3b31 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -172,9 +172,7 @@ uint32_t RISCV::calcEFlags() const {
int64_t RISCV::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
case R_RISCV_32:
case R_RISCV_TLS_DTPMOD32:
diff --git a/lld/ELF/Arch/SystemZ.cpp b/lld/ELF/Arch/SystemZ.cpp
index 50534808487932..ddea201dd7f7f1 100644
--- a/lld/ELF/Arch/SystemZ.cpp
+++ b/lld/ELF/Arch/SystemZ.cpp
@@ -261,9 +261,7 @@ int64_t SystemZ::getImplicitAddend(const uint8_t *buf, RelType type) const {
// These relocations are defined as not having an implicit addend.
return 0;
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/X86.cpp b/lld/ELF/Arch/X86.cpp
index 2d6b6c80da683e..d37be54d6a3123 100644
--- a/lld/ELF/Arch/X86.cpp
+++ b/lld/ELF/Arch/X86.cpp
@@ -280,9 +280,7 @@ int64_t X86::getImplicitAddend(const uint8_t *buf, RelType type) const {
// These relocations are defined as not having an implicit addend.
return 0;
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index f4f5b1f077edf7..42448d5edf26be 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -768,9 +768,7 @@ int64_t X86_64::getImplicitAddend(const uint8_t *buf, RelType type) const {
// These relocations are defined as not having an implicit addend.
return 0;
default:
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " +
- toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
}
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index f7da272ab9bc4e..1072b7540f498d 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -674,10 +674,6 @@ static inline ArrayRef<VersionDefinition> namedVersionDefs(Ctx &ctx) {
return llvm::ArrayRef(ctx.arg.versionDefinitions).slice(2);
}
-void errorOrWarn(const Twine &msg);
-
-void internalLinkerError(StringRef loc, const Twine &msg);
-
struct ELFSyncStream : SyncStream {
Ctx &ctx;
ELFSyncStream(Ctx &ctx, DiagLevel level)
@@ -721,6 +717,8 @@ ELFSyncStream Fatal(Ctx &ctx);
uint64_t errCount(Ctx &ctx);
+ELFSyncStream InternalErr(Ctx &ctx, const uint8_t *buf);
+
#define CHECK2(E, S) lld::check2((E), [&] { return toStr(ctx, S); })
} // namespace lld::elf
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index d913ffd8f0b6aa..a0c95df1ff1f6a 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -93,9 +93,10 @@ ELFSyncStream elf::ErrAlways(Ctx &ctx) { return {ctx, DiagLevel::Err}; }
ELFSyncStream elf::Fatal(Ctx &ctx) { return {ctx, DiagLevel::Fatal}; }
uint64_t elf::errCount(Ctx &ctx) { return ctx.errHandler->errorCount; }
-void elf::internalLinkerError(StringRef loc, const Twine &msg) {
- ELFSyncStream(ctx, DiagLevel::Err) << "internal linker error: " << msg << '\n'
- << llvm::getBugReportMsg();
+ELFSyncStream elf::InternalErr(Ctx &ctx, const uint8_t *buf) {
+ ELFSyncStream s(ctx, DiagLevel::Err);
+ s << "internal linker error: ";
+ return s;
}
Ctx::Ctx() : driver(*this) {}
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index bb785ab9bbcc21..8ab0fd1ebd6ff8 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -908,13 +908,12 @@ void OutputSection::checkDynRelAddends(Ctx &ctx) {
? 0
: ctx.target->getImplicitAddend(relocTarget, rel.type);
if (addend != writtenAddend)
- internalLinkerError(
- getErrorLoc(ctx, relocTarget),
- "wrote incorrect addend value 0x" + utohexstr(writtenAddend) +
- " instead of 0x" + utohexstr(addend) +
- " for dynamic relocation " + toStr(ctx, rel.type) +
- " at offset 0x" + utohexstr(rel.getOffset()) +
- (rel.sym ? " against symbol " + toStr(ctx, *rel.sym) : ""));
+ InternalErr(ctx, relocTarget)
+ << "wrote incorrect addend value 0x" << utohexstr(writtenAddend)
+ << " instead of 0x" << utohexstr(addend)
+ << " for dynamic relocation " << rel.type << " at offset 0x"
+ << utohexstr(rel.getOffset())
+ << (rel.sym ? " against symbol " + rel.sym->getName() : "");
}
});
}
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index d9c40385f2b987..203252dbac122e 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -46,11 +46,7 @@ std::string elf::toStr(Ctx &ctx, RelType type) {
}
const ELFSyncStream &elf::operator<<(const ELFSyncStream &s, RelType type) {
- StringRef buf = getELFRelocationTypeName(s.ctx.arg.emachine, type);
- if (buf == "Unknown")
- s << "Unknown (" << type << ')';
- else
- s << buf;
+ s << toStr(s.ctx, type);
return s;
}
@@ -122,8 +118,7 @@ ErrorPlace elf::getErrorPlace(Ctx &ctx, const uint8_t *loc) {
TargetInfo::~TargetInfo() {}
int64_t TargetInfo::getImplicitAddend(const uint8_t *buf, RelType type) const {
- internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toStr(ctx, type));
+ InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
return 0;
}
diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index b9858b0e26ece9..996eeae423c933 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -164,6 +164,7 @@ class SyncStream {
public:
mutable llvm::raw_string_ostream os{buf};
SyncStream(ErrorHandler &e, DiagLevel level) : e(e), level(level) {}
+ SyncStream(SyncStream &&o) : e(o.e), level(o.level), buf(std::move(o.buf)) {}
~SyncStream();
};
More information about the llvm-commits
mailing list