Skip to content

Commit c1a6def

Browse files
committed
[ELF] Make RelType a struct type
otherwise operator<<(const ELFSyncStream &s, RelType type) applies to non-reloc-type uint32_t, which can be confusing.
1 parent e57331e commit c1a6def

18 files changed

+34
-30
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
213213
case R_AARCH64_NONE:
214214
return R_NONE;
215215
default:
216-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
216+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
217217
<< ") against symbol " << &s;
218218
return R_NONE;
219219
}

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ RelExpr AMDGPU::getRelExpr(RelType type, const Symbol &s,
193193
case R_AMDGPU_GOTPCREL32_HI:
194194
return R_GOT_PC;
195195
default:
196-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
196+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
197197
<< ") against symbol " << &s;
198198
return R_NONE;
199199
}

lld/ELF/Arch/ARM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
195195
// not ARMv4 output, we can just ignore it.
196196
return R_NONE;
197197
default:
198-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
198+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
199199
<< ") against symbol " << &s;
200200
return R_NONE;
201201
}

lld/ELF/Arch/AVR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ RelExpr AVR::getRelExpr(RelType type, const Symbol &s,
9393
case R_AVR_13_PCREL:
9494
return R_PC;
9595
default:
96-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
96+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
9797
<< ") against symbol " << &s;
9898
return R_NONE;
9999
}

lld/ELF/Arch/Hexagon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s,
153153
case R_HEX_TPREL_LO16:
154154
return R_TPREL;
155155
default:
156-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
156+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
157157
<< ") against symbol " << &s;
158158
return R_NONE;
159159
}

lld/ELF/Arch/LoongArch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
527527
//
528528
// [1]: https://web.archive.org/web/20230709064026/https://github.com/loongson/LoongArch-Documentation/issues/51
529529
default:
530-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
530+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
531531
<< ") against symbol " << &s;
532532
return R_NONE;
533533
}

lld/ELF/Arch/Mips.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,
7878
const uint8_t *loc) const {
7979
// See comment in the calculateMipsRelChain.
8080
if (ELFT::Is64Bits || ctx.arg.mipsN32Abi)
81-
type &= 0xff;
81+
type.v &= 0xff;
8282

8383
switch (type) {
8484
case R_MIPS_JALR:
@@ -191,7 +191,7 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,
191191
case R_MIPS_NONE:
192192
return R_NONE;
193193
default:
194-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
194+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
195195
<< ") against symbol " << &s;
196196
return R_NONE;
197197
}
@@ -481,7 +481,7 @@ int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *buf, RelType type) const {
481481
}
482482

483483
static std::pair<uint32_t, uint64_t>
484-
calculateMipsRelChain(Ctx &ctx, uint8_t *loc, RelType type, uint64_t val) {
484+
calculateMipsRelChain(Ctx &ctx, uint8_t *loc, uint32_t type, uint64_t val) {
485485
// MIPS N64 ABI packs multiple relocations into the single relocation
486486
// record. In general, all up to three relocations can have arbitrary
487487
// types. In fact, Clang and GCC uses only a few combinations. For now,
@@ -494,8 +494,8 @@ calculateMipsRelChain(Ctx &ctx, uint8_t *loc, RelType type, uint64_t val) {
494494
// relocations used to modify result of the first one: extend it to
495495
// 64-bit, extract high or low part etc. For details, see part 2.9 Relocation
496496
// at the https://dmz-portal.mips.com/mw/images/8/82/007-4658-001.pdf
497-
RelType type2 = (type >> 8) & 0xff;
498-
RelType type3 = (type >> 16) & 0xff;
497+
uint32_t type2 = (type >> 8) & 0xff;
498+
uint32_t type3 = (type >> 16) & 0xff;
499499
if (type2 == R_MIPS_NONE && type3 == R_MIPS_NONE)
500500
return std::make_pair(type, val);
501501
if (type2 == R_MIPS_64 && type3 == R_MIPS_NONE)

lld/ELF/Arch/PPC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ RelExpr PPC::getRelExpr(RelType type, const Symbol &s,
269269
case R_PPC_TPREL16_HI:
270270
return R_TPREL;
271271
default:
272-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
272+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
273273
<< ") against symbol " << &s;
274274
return R_NONE;
275275
}

lld/ELF/Arch/PPC64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ uint32_t PPC64::calcEFlags() const {
644644
if (flag == 1)
645645
ErrAlways(ctx) << f << ": ABI version 1 is not supported";
646646
else if (flag > 2)
647-
ErrAlways(ctx) << f << ": unrecognized e_flags: " << Twine(flag);
647+
ErrAlways(ctx) << f << ": unrecognized e_flags: " << flag;
648648
}
649649
return 2;
650650
}
@@ -1100,7 +1100,7 @@ RelExpr PPC64::getRelExpr(RelType type, const Symbol &s,
11001100
case R_PPC64_TLS:
11011101
return R_TLSIE_HINT;
11021102
default:
1103-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
1103+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
11041104
<< ") against symbol " << &s;
11051105
return R_NONE;
11061106
}

lld/ELF/Arch/RISCV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s,
324324
case R_RISCV_SUB_ULEB128:
325325
return R_RISCV_LEB128;
326326
default:
327-
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << Twine(type)
327+
Err(ctx) << getErrorLoc(ctx, loc) << "unknown relocation (" << type.v
328328
<< ") against symbol " << &s;
329329
return R_NONE;
330330
}

0 commit comments

Comments
 (0)