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;