[llvm-readobj] - Refactor how the code dumps relocations.
There is a strange "feature" of the code: it handles all relocations as `Elf_Rela`.
For handling `Elf_Rel` it converts them to `Elf_Rela` and passes `bool IsRela` to
specify the real type everywhere.
A related issue is that the
`decode_relrs` helper in lib/Object has to return `Expected<std::vector<Elf_Rela>>`
because of that, though it could return a vector of `Elf_Rel`.
I think we should just start using templates for relocation types, it makes the code
cleaner and shorter. This patch does it.
Differential revision: https://reviews.llvm.org/D83871
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 2515695..7a67594 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -278,7 +278,7 @@
}
template <class ELFT>
-Expected<std::vector<typename ELFT::Rela>>
+Expected<std::vector<typename ELFT::Rel>>
ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
// This function decodes the contents of an SHT_RELR packed relocation
// section.
@@ -310,11 +310,10 @@
// even means address, odd means bitmap.
// 2. Just a simple list of addresses is a valid encoding.
- Elf_Rela Rela;
- Rela.r_info = 0;
- Rela.r_addend = 0;
- Rela.setType(getRelativeRelocationType(), false);
- std::vector<Elf_Rela> Relocs;
+ Elf_Rel Rel;
+ Rel.r_info = 0;
+ Rel.setType(getRelativeRelocationType(), false);
+ std::vector<Elf_Rel> Relocs;
// Word type: uint32_t for Elf32, and uint64_t for Elf64.
typedef typename ELFT::uint Word;
@@ -331,8 +330,8 @@
Word Entry = R;
if ((Entry&1) == 0) {
// Even entry: encodes the offset for next relocation.
- Rela.r_offset = Entry;
- Relocs.push_back(Rela);
+ Rel.r_offset = Entry;
+ Relocs.push_back(Rel);
// Set base offset for subsequent bitmap entries.
Base = Entry + WordSize;
continue;
@@ -343,8 +342,8 @@
while (Entry != 0) {
Entry >>= 1;
if ((Entry&1) != 0) {
- Rela.r_offset = Offset;
- Relocs.push_back(Rela);
+ Rel.r_offset = Offset;
+ Relocs.push_back(Rel);
}
Offset += WordSize;
}