[llvm] 8e1d532 - [Object] Simplify RELR decoding
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 16 15:03:19 PDT 2021
Author: Fangrui Song
Date: 2021-10-16T15:03:14-07:00
New Revision: 8e1d532707fdf590da6dee53f33cca8a79d133e5
URL: https://github.com/llvm/llvm-project/commit/8e1d532707fdf590da6dee53f33cca8a79d133e5
DIFF: https://github.com/llvm/llvm-project/commit/8e1d532707fdf590da6dee53f33cca8a79d133e5.diff
LOG: [Object] Simplify RELR decoding
Added:
Modified:
llvm/lib/Object/ELF.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index cd9f8813e74c3..1eabc29ac5d45 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;
More information about the llvm-commits
mailing list