Index: tools/relocation_packer/src/run_length_encoder.cc |
diff --git a/tools/relocation_packer/src/run_length_encoder.cc b/tools/relocation_packer/src/run_length_encoder.cc |
index 78949a9ee646af3b74c8821018a1a8d3ab1c6606..2d68bf4c1e892e4a4ea35a192bfad76428f6d931 100644 |
--- a/tools/relocation_packer/src/run_length_encoder.cc |
+++ b/tools/relocation_packer/src/run_length_encoder.cc |
@@ -2,29 +2,26 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// TODO(simonb): Extend for 64-bit target libraries. |
- |
#include "run_length_encoder.h" |
-#include <string.h> |
-#include <string> |
#include <vector> |
#include "debug.h" |
+#include "elf_traits.h" |
namespace relocation_packer { |
namespace { |
// Generate a vector of deltas between the r_offset fields of adjacent |
-// R_ARM_RELATIVE relocations. |
-void GetDeltas(const std::vector<Elf32_Rel>& relocations, |
- std::vector<Elf32_Addr>* deltas) { |
+// ARM relative relocations. |
+void GetDeltas(const std::vector<ELF::Rel>& relocations, |
+ std::vector<ELF::Addr>* deltas) { |
CHECK(relocations.size() >= 2); |
for (size_t i = 0; i < relocations.size() - 1; ++i) { |
- const Elf32_Addr first = relocations[i].r_offset; |
- const Elf32_Addr second = relocations[i + 1].r_offset; |
+ const ELF::Addr first = relocations[i].r_offset; |
+ const ELF::Addr second = relocations[i + 1].r_offset; |
// Requires that offsets are 'strictly increasing'. The packing |
// algorithm fails if this does not hold. |
CHECK(second > first); |
@@ -35,15 +32,15 @@ void GetDeltas(const std::vector<Elf32_Rel>& relocations, |
// Condense a set of r_offset deltas into a run-length encoded packing. |
// Represented as count-delta pairs, where count is the run length and |
// delta the common difference between adjacent r_offsets. |
-void Condense(const std::vector<Elf32_Addr>& deltas, |
- std::vector<Elf32_Word>* packed) { |
+void Condense(const std::vector<ELF::Addr>& deltas, |
+ std::vector<ELF::Xword>* packed) { |
CHECK(!deltas.empty()); |
size_t count = 0; |
- Elf32_Addr current = deltas[0]; |
+ ELF::Addr current = deltas[0]; |
// Identify spans of identically valued deltas. |
for (size_t i = 0; i < deltas.size(); ++i) { |
- const Elf32_Addr delta = deltas[i]; |
+ const ELF::Addr delta = deltas[i]; |
if (delta == current) { |
count++; |
} else { |
@@ -63,26 +60,30 @@ void Condense(const std::vector<Elf32_Addr>& deltas, |
// Uncondense a set of r_offset deltas from a run-length encoded packing. |
// The initial address for uncondensing, the start index for the first |
// condensed slot in packed, and the count of pairs are provided. |
-void Uncondense(Elf32_Addr addr, |
- const std::vector<Elf32_Word>& packed, |
+void Uncondense(ELF::Addr addr, |
+ const std::vector<ELF::Xword>& packed, |
size_t start_index, |
size_t end_index, |
- std::vector<Elf32_Rel>* relocations) { |
+ std::vector<ELF::Rel>* relocations) { |
// The first relocation is just one created from the initial address. |
- const Elf32_Rel initial = {addr, R_ARM_RELATIVE}; |
+ ELF::Rel initial; |
+ initial.r_offset = addr; |
+ initial.r_info = ELF_R_INFO(0, ELF::kRelativeRelocationCode); |
relocations->push_back(initial); |
// Read each count and delta pair, beginning at the start index and |
// finishing at the end index. |
for (size_t i = start_index; i < end_index; i += 2) { |
size_t count = packed[i]; |
- const Elf32_Addr delta = packed[i + 1]; |
+ const ELF::Addr delta = packed[i + 1]; |
CHECK(count > 0 && delta > 0); |
// Generate relocations for this count and delta pair. |
while (count) { |
addr += delta; |
- const Elf32_Rel relocation = {addr, R_ARM_RELATIVE}; |
+ ELF::Rel relocation; |
+ relocation.r_offset = addr; |
+ relocation.r_info = ELF_R_INFO(0, ELF::kRelativeRelocationCode); |
relocations->push_back(relocation); |
count--; |
} |
@@ -91,16 +92,16 @@ void Uncondense(Elf32_Addr addr, |
} // namespace |
-// Encode R_ARM_RELATIVE relocations into a run-length encoded (packed) |
+// Encode ARM relative relocations into a run-length encoded (packed) |
// representation. |
-void RelocationRunLengthCodec::Encode(const std::vector<Elf32_Rel>& relocations, |
- std::vector<Elf32_Word>* packed) { |
+void RelocationRunLengthCodec::Encode(const std::vector<ELF::Rel>& relocations, |
+ std::vector<ELF::Xword>* packed) { |
// If we have zero or one relocation only then there is no packing |
// possible; a run-length encoding needs a run. |
if (relocations.size() < 2) |
return; |
- std::vector<Elf32_Addr> deltas; |
+ std::vector<ELF::Addr> deltas; |
GetDeltas(relocations, &deltas); |
// Reserve space for the element count. |
@@ -115,13 +116,13 @@ void RelocationRunLengthCodec::Encode(const std::vector<Elf32_Rel>& relocations, |
packed->at(0) = (packed->size() - 2) >> 1; |
} |
-// Decode R_ARM_RELATIVE reloctions from a run-length encoded (packed) |
+// Decode ARM relative relocations from a run-length encoded (packed) |
// representation. |
-void RelocationRunLengthCodec::Decode(const std::vector<Elf32_Word>& packed, |
- std::vector<Elf32_Rel>* relocations) { |
- // We need at least one packed pair after the packed pair count to be |
- // able to unpack. |
- if (packed.size() < 3) |
+void RelocationRunLengthCodec::Decode(const std::vector<ELF::Xword>& packed, |
+ std::vector<ELF::Rel>* relocations) { |
+ // We need at least one packed pair after the packed pair count and start |
+ // address to be able to unpack. |
+ if (packed.size() < 4) |
return; |
// Ensure that the packed data offers enough pairs. There may be zero |
@@ -132,7 +133,7 @@ void RelocationRunLengthCodec::Decode(const std::vector<Elf32_Word>& packed, |
// initial address. Start uncondensing pairs at the third, and finish |
// at the end of the pairs data. |
const size_t pairs_count = packed[0]; |
- const Elf32_Addr addr = packed[1]; |
+ const ELF::Addr addr = packed[1]; |
Uncondense(addr, packed, 2, 2 + (pairs_count << 1), relocations); |
} |