[lld] r272975 - Make a switch-case a function for the sake of simplicity.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 16 16:28:08 PDT 2016
Author: ruiu
Date: Thu Jun 16 18:28:08 2016
New Revision: 272975
URL: http://llvm.org/viewvc/llvm-project?rev=272975&view=rev
Log:
Make a switch-case a function for the sake of simplicity.
Modified:
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=272975&r1=272974&r2=272975&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Jun 16 18:28:08 2016
@@ -1007,21 +1007,24 @@ void PPC64TargetInfo::writePlt(uint8_t *
write32be(Buf + 28, 0x4e800420); // bctr
}
+static std::pair<uint32_t, uint64_t> toAddr16Rel(uint32_t Type, uint64_t Val) {
+ uint64_t V = Val - PPC64TocOffset;
+ switch (Type) {
+ case R_PPC64_TOC16: return {R_PPC64_ADDR16, V};
+ case R_PPC64_TOC16_DS: return {R_PPC64_ADDR16_DS, V};
+ case R_PPC64_TOC16_HA: return {R_PPC64_ADDR16_HA, V};
+ case R_PPC64_TOC16_HI: return {R_PPC64_ADDR16_HI, V};
+ case R_PPC64_TOC16_LO: return {R_PPC64_ADDR16_LO, V};
+ case R_PPC64_TOC16_LO_DS: return {R_PPC64_ADDR16_LO_DS, V};
+ default: return {Type, Val};
+ }
+}
+
void PPC64TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
uint64_t Val) const {
- uint64_t TO = PPC64TocOffset;
-
- // For a TOC-relative relocation, proceed in terms of the corresponding
+ // For a TOC-relative relocation, proceed in terms of the corresponding
// ADDR16 relocation type.
- switch (Type) {
- case R_PPC64_TOC16: Type = R_PPC64_ADDR16; Val -= TO; break;
- case R_PPC64_TOC16_DS: Type = R_PPC64_ADDR16_DS; Val -= TO; break;
- case R_PPC64_TOC16_HA: Type = R_PPC64_ADDR16_HA; Val -= TO; break;
- case R_PPC64_TOC16_HI: Type = R_PPC64_ADDR16_HI; Val -= TO; break;
- case R_PPC64_TOC16_LO: Type = R_PPC64_ADDR16_LO; Val -= TO; break;
- case R_PPC64_TOC16_LO_DS: Type = R_PPC64_ADDR16_LO_DS; Val -= TO; break;
- default: break;
- }
+ std::tie(Type, Val) = toAddr16Rel(Type, Val);
switch (Type) {
case R_PPC64_ADDR14: {
More information about the llvm-commits
mailing list