diff options
author | Fangrui Song <i@maskray.me> | 2021-10-16 15:03:14 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2021-10-16 15:03:14 -0700 |
commit | 8e1d532707fdf590da6dee53f33cca8a79d133e5 (patch) | |
tree | 213ede50ee20cb14272f406862a9aba4a5d20fbb /llvm/lib/Object/ELF.cpp | |
parent | 746dd6a700931988dd9021d3d04718f1929885a5 (diff) | |
download | llvm-8e1d532707fdf590da6dee53f33cca8a79d133e5.zip llvm-8e1d532707fdf590da6dee53f33cca8a79d133e5.tar.gz llvm-8e1d532707fdf590da6dee53f33cca8a79d133e5.tar.bz2 |
[Object] Simplify RELR decoding
Diffstat (limited to 'llvm/lib/Object/ELF.cpp')
-rw-r--r-- | llvm/lib/Object/ELF.cpp | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp index cd9f881..1eabc29a 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -336,40 +336,26 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const { std::vector<Elf_Rel> Relocs; // Word type: uint32_t for Elf32, and uint64_t for Elf64. - typedef typename ELFT::uint Word; + using Addr = typename ELFT::uint; - // Word size in number of bytes. - const size_t WordSize = sizeof(Word); - - // Number of bits used for the relocation offsets bitmap. - // These many relative relocations can be encoded in a single entry. - const size_t NBits = 8*WordSize - 1; - - Word Base = 0; - for (const Elf_Relr &R : relrs) { - Word Entry = R; - if ((Entry&1) == 0) { + Addr Base = 0; + for (Elf_Relr R : relrs) { + typename ELFT::uint Entry = R; + if ((Entry & 1) == 0) { // Even entry: encodes the offset for next relocation. Rel.r_offset = Entry; Relocs.push_back(Rel); // Set base offset for subsequent bitmap entries. - Base = Entry + WordSize; - continue; - } - - // Odd entry: encodes bitmap for relocations starting at base. - Word Offset = Base; - while (Entry != 0) { - Entry >>= 1; - if ((Entry&1) != 0) { - Rel.r_offset = Offset; - Relocs.push_back(Rel); - } - Offset += WordSize; + Base = Entry + sizeof(Addr); + } else { + // Odd entry: encodes bitmap for relocations starting at base. + for (Addr Offset = Base; (Entry >>= 1) != 0; Offset += sizeof(Addr)) + if ((Entry & 1) != 0) { + Rel.r_offset = Offset; + Relocs.push_back(Rel); + } + Base += (CHAR_BIT * sizeof(Entry) - 1) * sizeof(Addr); } - - // Advance base offset by NBits words. - Base += NBits * WordSize; } return Relocs; |