[llvm] r303335 - [DWARF] - Simplify RelocVisitor implementation.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu May 18 01:25:11 PDT 2017
Author: grimar
Date: Thu May 18 03:25:11 2017
New Revision: 303335
URL: http://llvm.org/viewvc/llvm-project?rev=303335&view=rev
Log:
[DWARF] - Simplify RelocVisitor implementation.
We do not need to store relocation width field.
Patch removes relative code, that simplifies implementation.
Differential revision: https://reviews.llvm.org/D33274
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h
llvm/trunk/include/llvm/Object/RelocVisitor.h
llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h?rev=303335&r1=303334&r2=303335&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h Thu May 18 03:25:11 2017
@@ -17,7 +17,7 @@
namespace llvm {
struct RelocAddrEntry {
- int64_t Value;
+ uint64_t Value;
};
/// In place of applying the relocations to the data we've read from disk we use
Modified: llvm/trunk/include/llvm/Object/RelocVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/RelocVisitor.h?rev=303335&r1=303334&r2=303335&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/RelocVisitor.h (original)
+++ llvm/trunk/include/llvm/Object/RelocVisitor.h Thu May 18 03:25:11 2017
@@ -32,18 +32,6 @@
namespace llvm {
namespace object {
-struct RelocToApply {
- // The computed value after applying the relevant relocations.
- int64_t Value = 0;
-
- // The width of the value; how many bytes to touch when applying the
- // relocation.
- char Width = 0;
-
- RelocToApply() = default;
- RelocToApply(int64_t Value, char Width) : Value(Value), Width(Width) {}
-};
-
/// @brief Base class for object file relocation visitors.
class RelocVisitor {
public:
@@ -52,7 +40,7 @@ public:
// TODO: Should handle multiple applied relocations via either passing in the
// previously computed value or just count paired relocations as a single
// visit.
- RelocToApply visit(uint32_t RelocType, RelocationRef R, uint64_t Value = 0) {
+ uint64_t visit(uint32_t RelocType, RelocationRef R, uint64_t Value = 0) {
if (isa<ELFObjectFileBase>(ObjToVisit))
return visitELF(RelocType, R, Value);
if (isa<COFFObjectFile>(ObjToVisit))
@@ -61,7 +49,7 @@ public:
return visitMachO(RelocType, R, Value);
HasError = true;
- return RelocToApply();
+ return 0;
}
bool error() { return HasError; }
@@ -70,7 +58,7 @@ private:
const ObjectFile &ObjToVisit;
bool HasError = false;
- RelocToApply visitELF(uint32_t RelocType, RelocationRef R, uint64_t Value) {
+ uint64_t visitELF(uint32_t RelocType, RelocationRef R, uint64_t Value) {
if (ObjToVisit.getBytesInAddress() == 8) { // 64-bit object file
switch (ObjToVisit.getArch()) {
case Triple::x86_64:
@@ -87,7 +75,7 @@ private:
return visitELF_X86_64_32S(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::aarch64:
case Triple::aarch64_be:
@@ -98,7 +86,7 @@ private:
return visitELF_AARCH64_ABS64(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::bpfel:
case Triple::bpfeb:
@@ -109,7 +97,7 @@ private:
return visitELF_BPF_64_32(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::mips64el:
case Triple::mips64:
@@ -120,7 +108,7 @@ private:
return visitELF_MIPS64_64(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::ppc64le:
case Triple::ppc64:
@@ -131,7 +119,7 @@ private:
return visitELF_PPC64_ADDR64(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::systemz:
switch (RelocType) {
@@ -141,7 +129,7 @@ private:
return visitELF_390_64(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::sparcv9:
switch (RelocType) {
@@ -153,7 +141,7 @@ private:
return visitELF_SPARCV9_64(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::amdgcn:
switch (RelocType) {
@@ -163,11 +151,11 @@ private:
return visitELF_AMDGPU_ABS64(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
} else if (ObjToVisit.getBytesInAddress() == 4) { // 32-bit object file
switch (ObjToVisit.getArch()) {
@@ -181,7 +169,7 @@ private:
return visitELF_386_PC32(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::ppc:
switch (RelocType) {
@@ -189,14 +177,14 @@ private:
return visitELF_PPC_ADDR32(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::arm:
case Triple::armeb:
switch (RelocType) {
default:
HasError = true;
- return RelocToApply();
+ return 0;
case ELF::R_ARM_ABS32:
return visitELF_ARM_ABS32(R, Value);
}
@@ -206,7 +194,7 @@ private:
return visitELF_Lanai_32(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::mipsel:
case Triple::mips:
@@ -215,7 +203,7 @@ private:
return visitELF_MIPS_32(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::sparc:
switch (RelocType) {
@@ -224,7 +212,7 @@ private:
return visitELF_SPARC_32(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
case Triple::hexagon:
switch (RelocType) {
@@ -232,18 +220,18 @@ private:
return visitELF_HEX_32(R, Value);
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
default:
HasError = true;
- return RelocToApply();
+ return 0;
}
} else {
report_fatal_error("Invalid word size in object file");
}
}
- RelocToApply visitCOFF(uint32_t RelocType, RelocationRef R, uint64_t Value) {
+ uint64_t visitCOFF(uint32_t RelocType, RelocationRef R, uint64_t Value) {
switch (ObjToVisit.getArch()) {
case Triple::x86:
switch (RelocType) {
@@ -263,10 +251,10 @@ private:
break;
}
HasError = true;
- return RelocToApply();
+ return 0;
}
- RelocToApply visitMachO(uint32_t RelocType, RelocationRef R, uint64_t Value) {
+ uint64_t visitMachO(uint32_t RelocType, RelocationRef R, uint64_t Value) {
switch (ObjToVisit.getArch()) {
default: break;
case Triple::x86_64:
@@ -277,7 +265,7 @@ private:
}
}
HasError = true;
- return RelocToApply();
+ return 0;
}
int64_t getELFAddend(RelocationRef R) {
@@ -287,108 +275,88 @@ private:
return *AddendOrErr;
}
- uint8_t getLengthMachO64(RelocationRef R) {
- const MachOObjectFile *Obj = cast<MachOObjectFile>(R.getObject());
- return Obj->getRelocationLength(R.getRawDataRefImpl());
- }
-
/// Operations
/// 386-ELF
- RelocToApply visitELF_386_NONE(RelocationRef R) {
- return RelocToApply(0, 0);
+ uint64_t visitELF_386_NONE(RelocationRef R) {
+ return 0;
}
// Ideally the Addend here will be the addend in the data for
// the relocation. It's not actually the case for Rel relocations.
- RelocToApply visitELF_386_32(RelocationRef R, uint64_t Value) {
- return RelocToApply(Value, 4);
+ uint64_t visitELF_386_32(RelocationRef R, uint64_t Value) {
+ return Value;
}
- RelocToApply visitELF_386_PC32(RelocationRef R, uint64_t Value) {
- uint64_t Address = R.getOffset();
- return RelocToApply(Value - Address, 4);
+ uint64_t visitELF_386_PC32(RelocationRef R, uint64_t Value) {
+ return Value - R.getOffset();
}
/// X86-64 ELF
- RelocToApply visitELF_X86_64_NONE(RelocationRef R) {
- return RelocToApply(0, 0);
+ uint64_t visitELF_X86_64_NONE(RelocationRef R) {
+ return 0;
}
- RelocToApply visitELF_X86_64_64(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 8);
+
+ uint64_t visitELF_X86_64_64(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R);
}
- RelocToApply visitELF_X86_64_PC32(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- uint64_t Address = R.getOffset();
- return RelocToApply(Value + Addend - Address, 4);
+
+ uint64_t visitELF_X86_64_PC32(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R) - R.getOffset();
}
- RelocToApply visitELF_X86_64_32(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+
+ uint64_t visitELF_X86_64_32(RelocationRef R, uint64_t Value) {
+ return (Value + getELFAddend(R)) & 0xFFFFFFFF;
}
- RelocToApply visitELF_X86_64_32S(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- int32_t Res = (Value + Addend) & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+
+ uint64_t visitELF_X86_64_32S(RelocationRef R, uint64_t Value) {
+ return (Value + getELFAddend(R)) & 0xFFFFFFFF;
}
/// BPF ELF
- RelocToApply visitELF_BPF_64_32(RelocationRef R, uint64_t Value) {
- uint32_t Res = Value & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+ uint64_t visitELF_BPF_64_32(RelocationRef R, uint64_t Value) {
+ return Value & 0xFFFFFFFF;
}
- RelocToApply visitELF_BPF_64_64(RelocationRef R, uint64_t Value) {
- return RelocToApply(Value, 8);
+
+ uint64_t visitELF_BPF_64_64(RelocationRef R, uint64_t Value) {
+ return Value;
}
/// PPC64 ELF
- RelocToApply visitELF_PPC64_ADDR32(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+ uint64_t visitELF_PPC64_ADDR32(RelocationRef R, uint64_t Value) {
+ return (Value + getELFAddend(R)) & 0xFFFFFFFF;
}
- RelocToApply visitELF_PPC64_ADDR64(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 8);
+
+ uint64_t visitELF_PPC64_ADDR64(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R);
}
/// PPC32 ELF
- RelocToApply visitELF_PPC_ADDR32(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+ uint64_t visitELF_PPC_ADDR32(RelocationRef R, uint64_t Value) {
+ return (Value + getELFAddend(R)) & 0xFFFFFFFF;
}
/// Lanai ELF
- RelocToApply visitELF_Lanai_32(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+ uint64_t visitELF_Lanai_32(RelocationRef R, uint64_t Value) {
+ return (Value + getELFAddend(R)) & 0xFFFFFFFF;
}
/// MIPS ELF
- RelocToApply visitELF_MIPS_32(RelocationRef R, uint64_t Value) {
- uint32_t Res = Value & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+ uint64_t visitELF_MIPS_32(RelocationRef R, uint64_t Value) {
+ return Value & 0xFFFFFFFF;
}
/// MIPS64 ELF
- RelocToApply visitELF_MIPS64_32(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
- return RelocToApply(Res, 4);
+ uint64_t visitELF_MIPS64_32(RelocationRef R, uint64_t Value) {
+ return (Value + getELFAddend(R)) & 0xFFFFFFFF;
}
- RelocToApply visitELF_MIPS64_64(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- uint64_t Res = (Value + Addend);
- return RelocToApply(Res, 8);
+ uint64_t visitELF_MIPS64_64(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R);
}
// AArch64 ELF
- RelocToApply visitELF_AARCH64_ABS32(RelocationRef R, uint64_t Value) {
+ uint64_t visitELF_AARCH64_ABS32(RelocationRef R, uint64_t Value) {
int64_t Addend = getELFAddend(R);
int64_t Res = Value + Addend;
@@ -396,16 +364,15 @@ private:
if (Res < INT32_MIN || Res > UINT32_MAX)
HasError = true;
- return RelocToApply(static_cast<uint32_t>(Res), 4);
+ return static_cast<uint32_t>(Res);
}
- RelocToApply visitELF_AARCH64_ABS64(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 8);
+ uint64_t visitELF_AARCH64_ABS64(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R);
}
// SystemZ ELF
- RelocToApply visitELF_390_32(RelocationRef R, uint64_t Value) {
+ uint64_t visitELF_390_32(RelocationRef R, uint64_t Value) {
int64_t Addend = getELFAddend(R);
int64_t Res = Value + Addend;
@@ -413,77 +380,71 @@ private:
if (Res < INT32_MIN || Res > UINT32_MAX)
HasError = true;
- return RelocToApply(static_cast<uint32_t>(Res), 4);
+ return static_cast<uint32_t>(Res);
}
- RelocToApply visitELF_390_64(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 8);
+ uint64_t visitELF_390_64(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R);
}
- RelocToApply visitELF_SPARC_32(RelocationRef R, uint32_t Value) {
- int32_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 4);
+ uint64_t visitELF_SPARC_32(RelocationRef R, uint32_t Value) {
+ return Value + getELFAddend(R);
}
- RelocToApply visitELF_SPARCV9_32(RelocationRef R, uint64_t Value) {
- int32_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 4);
+ uint64_t visitELF_SPARCV9_32(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R);
}
- RelocToApply visitELF_SPARCV9_64(RelocationRef R, uint64_t Value) {
- int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 8);
+ uint64_t visitELF_SPARCV9_64(RelocationRef R, uint64_t Value) {
+ return Value + getELFAddend(R);
}
- RelocToApply visitELF_ARM_ABS32(RelocationRef R, uint64_t Value) {
+ uint64_t visitELF_ARM_ABS32(RelocationRef R, uint64_t Value) {
int64_t Res = Value;
// Overflow check allows for both signed and unsigned interpretation.
if (Res < INT32_MIN || Res > UINT32_MAX)
HasError = true;
- return RelocToApply(static_cast<uint32_t>(Res), 4);
+ return static_cast<uint32_t>(Res);
}
- RelocToApply visitELF_HEX_32(RelocationRef R, uint64_t Value) {
+ uint64_t visitELF_HEX_32(RelocationRef R, uint64_t Value) {
int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 4);
+ return Value + Addend;
}
- RelocToApply visitELF_AMDGPU_ABS32(RelocationRef R, uint64_t Value) {
+ uint64_t visitELF_AMDGPU_ABS32(RelocationRef R, uint64_t Value) {
int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 4);
+ return Value + Addend;
}
- RelocToApply visitELF_AMDGPU_ABS64(RelocationRef R, uint64_t Value) {
+ uint64_t visitELF_AMDGPU_ABS64(RelocationRef R, uint64_t Value) {
int64_t Addend = getELFAddend(R);
- return RelocToApply(Value + Addend, 8);
+ return Value + Addend;
}
/// I386 COFF
- RelocToApply visitCOFF_I386_SECREL(RelocationRef R, uint64_t Value) {
- return RelocToApply(static_cast<uint32_t>(Value), /*Width=*/4);
+ uint64_t visitCOFF_I386_SECREL(RelocationRef R, uint64_t Value) {
+ return static_cast<uint32_t>(Value);
}
- RelocToApply visitCOFF_I386_DIR32(RelocationRef R, uint64_t Value) {
- return RelocToApply(static_cast<uint32_t>(Value), /*Width=*/4);
+ uint64_t visitCOFF_I386_DIR32(RelocationRef R, uint64_t Value) {
+ return static_cast<uint32_t>(Value);
}
/// AMD64 COFF
- RelocToApply visitCOFF_AMD64_SECREL(RelocationRef R, uint64_t Value) {
- return RelocToApply(static_cast<uint32_t>(Value), /*Width=*/4);
+ uint64_t visitCOFF_AMD64_SECREL(RelocationRef R, uint64_t Value) {
+ return static_cast<uint32_t>(Value);
}
- RelocToApply visitCOFF_AMD64_ADDR64(RelocationRef R, uint64_t Value) {
- return RelocToApply(Value, /*Width=*/8);
+ uint64_t visitCOFF_AMD64_ADDR64(RelocationRef R, uint64_t Value) {
+ return Value;
}
// X86_64 MachO
- RelocToApply visitMACHO_X86_64_UNSIGNED(RelocationRef R, uint64_t Value) {
- uint8_t Length = getLengthMachO64(R);
- Length = 1<<Length;
- return RelocToApply(Value, Length);
+ uint64_t visitMACHO_X86_64_UNSIGNED(RelocationRef R, uint64_t Value) {
+ return Value;
}
};
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=303335&r1=303334&r2=303335&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Thu May 18 03:25:11 2017
@@ -1104,14 +1104,14 @@ DWARFContextInMemory::DWARFContextInMemo
}
object::RelocVisitor V(Obj);
- object::RelocToApply R(V.visit(Reloc.getType(), Reloc, *SymAddrOrErr));
+ uint64_t Val = V.visit(Reloc.getType(), Reloc, *SymAddrOrErr);
if (V.error()) {
SmallString<32> Name;
Reloc.getTypeName(Name);
errs() << "error: failed to compute relocation: " << Name << "\n";
continue;
}
- Map->insert({Reloc.getOffset(), {R.Value}});
+ Map->insert({Reloc.getOffset(), {Val}});
}
}
}
More information about the llvm-commits
mailing list