Skip to content

Commit be5dad0

Browse files
committed
[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.
1 parent 7642759 commit be5dad0

File tree

17 files changed

+27
-57
lines changed

17 files changed

+27
-57
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,7 @@ int64_t AArch64::getImplicitAddend(const uint8_t *buf, RelType type) const {
348348
return SignExtend64<28>(getBits(read32le(buf), 0, 25) << 2);
349349

350350
default:
351-
internalLinkerError(getErrorLoc(ctx, buf),
352-
"cannot read addend for relocation " +
353-
toStr(ctx, type));
351+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
354352
return 0;
355353
}
356354
}

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ int64_t AMDGPU::getImplicitAddend(const uint8_t *buf, RelType type) const {
213213
case R_AMDGPU_RELATIVE64:
214214
return read64(ctx, buf);
215215
default:
216-
internalLinkerError(getErrorLoc(ctx, buf),
217-
"cannot read addend for relocation " +
218-
toStr(ctx, type));
216+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
219217
return 0;
220218
}
221219
}

lld/ELF/Arch/ARM.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
875875
int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {
876876
switch (type) {
877877
default:
878-
internalLinkerError(getErrorLoc(ctx, buf),
879-
"cannot read addend for relocation " +
880-
toStr(ctx, type));
878+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
881879
return 0;
882880
case R_ARM_ABS32:
883881
case R_ARM_BASE_PREL:

lld/ELF/Arch/Hexagon.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,7 @@ int64_t Hexagon::getImplicitAddend(const uint8_t *buf, RelType type) const {
411411
case R_HEX_TPREL_32:
412412
return SignExtend64<32>(read32(ctx, buf));
413413
default:
414-
internalLinkerError(getErrorLoc(ctx, buf),
415-
"cannot read addend for relocation " +
416-
toStr(ctx, type));
414+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
417415
return 0;
418416
}
419417
}

lld/ELF/Arch/LoongArch.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ uint32_t LoongArch::calcEFlags() const {
279279
int64_t LoongArch::getImplicitAddend(const uint8_t *buf, RelType type) const {
280280
switch (type) {
281281
default:
282-
internalLinkerError(getErrorLoc(ctx, buf),
283-
"cannot read addend for relocation " +
284-
toStr(ctx, type));
282+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
285283
return 0;
286284
case R_LARCH_32:
287285
case R_LARCH_TLS_DTPMOD32:

lld/ELF/Arch/Mips.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,7 @@ int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *buf, RelType type) const {
475475
// These relocations are defined as not having an implicit addend.
476476
return 0;
477477
default:
478-
internalLinkerError(getErrorLoc(ctx, buf),
479-
"cannot read addend for relocation " +
480-
toStr(ctx, type));
478+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
481479
return 0;
482480
}
483481
}

lld/ELF/Arch/PPC.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ int64_t PPC::getImplicitAddend(const uint8_t *buf, RelType type) const {
296296
case R_PPC_TPREL32:
297297
return SignExtend64<32>(read32(ctx, buf));
298298
default:
299-
internalLinkerError(getErrorLoc(ctx, buf),
300-
"cannot read addend for relocation " +
301-
toStr(ctx, type));
299+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
302300
return 0;
303301
}
304302
}

lld/ELF/Arch/PPC64.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,9 +1130,7 @@ int64_t PPC64::getImplicitAddend(const uint8_t *buf, RelType type) const {
11301130
case R_PPC64_TPREL64:
11311131
return read64(ctx, buf);
11321132
default:
1133-
internalLinkerError(getErrorLoc(ctx, buf),
1134-
"cannot read addend for relocation " +
1135-
toStr(ctx, type));
1133+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
11361134
return 0;
11371135
}
11381136
}

lld/ELF/Arch/RISCV.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ uint32_t RISCV::calcEFlags() const {
172172
int64_t RISCV::getImplicitAddend(const uint8_t *buf, RelType type) const {
173173
switch (type) {
174174
default:
175-
internalLinkerError(getErrorLoc(ctx, buf),
176-
"cannot read addend for relocation " +
177-
toStr(ctx, type));
175+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
178176
return 0;
179177
case R_RISCV_32:
180178
case R_RISCV_TLS_DTPMOD32:

lld/ELF/Arch/SystemZ.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ int64_t SystemZ::getImplicitAddend(const uint8_t *buf, RelType type) const {
261261
// These relocations are defined as not having an implicit addend.
262262
return 0;
263263
default:
264-
internalLinkerError(getErrorLoc(ctx, buf),
265-
"cannot read addend for relocation " +
266-
toStr(ctx, type));
264+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
267265
return 0;
268266
}
269267
}

lld/ELF/Arch/X86.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ int64_t X86::getImplicitAddend(const uint8_t *buf, RelType type) const {
280280
// These relocations are defined as not having an implicit addend.
281281
return 0;
282282
default:
283-
internalLinkerError(getErrorLoc(ctx, buf),
284-
"cannot read addend for relocation " +
285-
toStr(ctx, type));
283+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
286284
return 0;
287285
}
288286
}

lld/ELF/Arch/X86_64.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,7 @@ int64_t X86_64::getImplicitAddend(const uint8_t *buf, RelType type) const {
768768
// These relocations are defined as not having an implicit addend.
769769
return 0;
770770
default:
771-
internalLinkerError(getErrorLoc(ctx, buf),
772-
"cannot read addend for relocation " +
773-
toStr(ctx, type));
771+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
774772
return 0;
775773
}
776774
}

lld/ELF/Config.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,6 @@ static inline ArrayRef<VersionDefinition> namedVersionDefs(Ctx &ctx) {
674674
return llvm::ArrayRef(ctx.arg.versionDefinitions).slice(2);
675675
}
676676

677-
void errorOrWarn(const Twine &msg);
678-
679-
void internalLinkerError(StringRef loc, const Twine &msg);
680-
681677
struct ELFSyncStream : SyncStream {
682678
Ctx &ctx;
683679
ELFSyncStream(Ctx &ctx, DiagLevel level)
@@ -721,6 +717,8 @@ ELFSyncStream Fatal(Ctx &ctx);
721717

722718
uint64_t errCount(Ctx &ctx);
723719

720+
ELFSyncStream InternalErr(Ctx &ctx, const uint8_t *buf);
721+
724722
#define CHECK2(E, S) lld::check2((E), [&] { return toStr(ctx, S); })
725723

726724
} // namespace lld::elf

lld/ELF/Driver.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ ELFSyncStream elf::ErrAlways(Ctx &ctx) { return {ctx, DiagLevel::Err}; }
9393
ELFSyncStream elf::Fatal(Ctx &ctx) { return {ctx, DiagLevel::Fatal}; }
9494
uint64_t elf::errCount(Ctx &ctx) { return ctx.errHandler->errorCount; }
9595

96-
void elf::internalLinkerError(StringRef loc, const Twine &msg) {
97-
ELFSyncStream(ctx, DiagLevel::Err) << "internal linker error: " << msg << '\n'
98-
<< llvm::getBugReportMsg();
96+
ELFSyncStream elf::InternalErr(Ctx &ctx, const uint8_t *buf) {
97+
ELFSyncStream s(ctx, DiagLevel::Err);
98+
s << "internal linker error: ";
99+
return s;
99100
}
100101

101102
Ctx::Ctx() : driver(*this) {}

lld/ELF/OutputSections.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,12 @@ void OutputSection::checkDynRelAddends(Ctx &ctx) {
908908
? 0
909909
: ctx.target->getImplicitAddend(relocTarget, rel.type);
910910
if (addend != writtenAddend)
911-
internalLinkerError(
912-
getErrorLoc(ctx, relocTarget),
913-
"wrote incorrect addend value 0x" + utohexstr(writtenAddend) +
914-
" instead of 0x" + utohexstr(addend) +
915-
" for dynamic relocation " + toStr(ctx, rel.type) +
916-
" at offset 0x" + utohexstr(rel.getOffset()) +
917-
(rel.sym ? " against symbol " + toStr(ctx, *rel.sym) : ""));
911+
InternalErr(ctx, relocTarget)
912+
<< "wrote incorrect addend value 0x" << utohexstr(writtenAddend)
913+
<< " instead of 0x" << utohexstr(addend)
914+
<< " for dynamic relocation " << rel.type << " at offset 0x"
915+
<< utohexstr(rel.getOffset())
916+
<< (rel.sym ? " against symbol " + rel.sym->getName() : "");
918917
}
919918
});
920919
}

lld/ELF/Target.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ std::string elf::toStr(Ctx &ctx, RelType type) {
4646
}
4747

4848
const ELFSyncStream &elf::operator<<(const ELFSyncStream &s, RelType type) {
49-
StringRef buf = getELFRelocationTypeName(s.ctx.arg.emachine, type);
50-
if (buf == "Unknown")
51-
s << "Unknown (" << type << ')';
52-
else
53-
s << buf;
49+
s << toStr(s.ctx, type);
5450
return s;
5551
}
5652

@@ -122,8 +118,7 @@ ErrorPlace elf::getErrorPlace(Ctx &ctx, const uint8_t *loc) {
122118
TargetInfo::~TargetInfo() {}
123119

124120
int64_t TargetInfo::getImplicitAddend(const uint8_t *buf, RelType type) const {
125-
internalLinkerError(getErrorLoc(ctx, buf),
126-
"cannot read addend for relocation " + toStr(ctx, type));
121+
InternalErr(ctx, buf) << "cannot read addend for relocation " << type;
127122
return 0;
128123
}
129124

lld/include/lld/Common/ErrorHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class SyncStream {
164164
public:
165165
mutable llvm::raw_string_ostream os{buf};
166166
SyncStream(ErrorHandler &e, DiagLevel level) : e(e), level(level) {}
167+
SyncStream(SyncStream &&o) : e(o.e), level(o.level), buf(std::move(o.buf)) {}
167168
~SyncStream();
168169
};
169170

0 commit comments

Comments
 (0)