Skip to content

Commit 8e1d532

Browse files
committed
[Object] Simplify RELR decoding
1 parent 746dd6a commit 8e1d532

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

llvm/lib/Object/ELF.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -336,40 +336,26 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
336336
std::vector<Elf_Rel> Relocs;
337337

338338
// Word type: uint32_t for Elf32, and uint64_t for Elf64.
339-
typedef typename ELFT::uint Word;
339+
using Addr = typename ELFT::uint;
340340

341-
// Word size in number of bytes.
342-
const size_t WordSize = sizeof(Word);
343-
344-
// Number of bits used for the relocation offsets bitmap.
345-
// These many relative relocations can be encoded in a single entry.
346-
const size_t NBits = 8*WordSize - 1;
347-
348-
Word Base = 0;
349-
for (const Elf_Relr &R : relrs) {
350-
Word Entry = R;
351-
if ((Entry&1) == 0) {
341+
Addr Base = 0;
342+
for (Elf_Relr R : relrs) {
343+
typename ELFT::uint Entry = R;
344+
if ((Entry & 1) == 0) {
352345
// Even entry: encodes the offset for next relocation.
353346
Rel.r_offset = Entry;
354347
Relocs.push_back(Rel);
355348
// Set base offset for subsequent bitmap entries.
356-
Base = Entry + WordSize;
357-
continue;
358-
}
359-
360-
// Odd entry: encodes bitmap for relocations starting at base.
361-
Word Offset = Base;
362-
while (Entry != 0) {
363-
Entry >>= 1;
364-
if ((Entry&1) != 0) {
365-
Rel.r_offset = Offset;
366-
Relocs.push_back(Rel);
367-
}
368-
Offset += WordSize;
349+
Base = Entry + sizeof(Addr);
350+
} else {
351+
// Odd entry: encodes bitmap for relocations starting at base.
352+
for (Addr Offset = Base; (Entry >>= 1) != 0; Offset += sizeof(Addr))
353+
if ((Entry & 1) != 0) {
354+
Rel.r_offset = Offset;
355+
Relocs.push_back(Rel);
356+
}
357+
Base += (CHAR_BIT * sizeof(Entry) - 1) * sizeof(Addr);
369358
}
370-
371-
// Advance base offset by NBits words.
372-
Base += NBits * WordSize;
373359
}
374360

375361
return Relocs;

0 commit comments

Comments
 (0)