1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Pack relative relocations into a more compact form.
8 // For relative relocations without addends (32 bit platforms)
9 // -----------------------------------------------------------
11 // Applies two packing strategies. The first is run-length encoding, which
12 // turns a large set of relative relocations into a much smaller set
13 // of delta-count pairs, prefixed with a two-word header comprising the
14 // count of pairs and the initial relocation offset. The second is LEB128
15 // encoding, which compresses the result of run-length encoding.
17 // Once packed, data is prefixed by an identifier that allows for any later
18 // versioning of packing strategies.
20 // A complete packed stream of relocations without addends might look
23 // "APR1" pairs init_offset count1 delta1 count2 delta2 ...
24 // 41505231 f2b003 b08ac716 e001 04 01 10 ...
27 // For relative relocations with addends (64 bit platforms)
28 // --------------------------------------------------------
30 // Applies two packing strategies. The first is delta encoding, which
31 // turns a large set of relative relocations into a smaller set
32 // of offset and addend delta pairs, prefixed with a header indicating the
33 // count of pairs. The second is signed LEB128 encoding, which compacts
34 // the result of delta encoding.
36 // Once packed, data is prefixed by an identifier that allows for any later
37 // versioning of packing strategies.
39 // A complete packed stream might look something like:
41 // "APA1" pairs offset_d1 addend_d1 offset_d2 addend_d2 ...
42 // 41505232 f2b018 04 28 08 9f01 ...
44 #ifndef TOOLS_RELOCATION_PACKER_SRC_PACKER_H_
45 #define TOOLS_RELOCATION_PACKER_SRC_PACKER_H_
51 #include "elf_traits.h"
53 namespace relocation_packer
{
55 // A RelocationPacker packs vectors of relative relocations into more
56 // compact forms, and unpacks them to reproduce the pre-packed data.
57 class RelocationPacker
{
59 // Pack relative relocations into a more compact form.
60 // |relocations| is a vector of relative relocation structs.
61 // |packed| is the vector of packed bytes into which relocations are packed.
62 static void PackRelativeRelocations(const std::vector
<ELF::Rel
>& relocations
,
63 std::vector
<uint8_t>* packed
);
64 static void PackRelativeRelocations(const std::vector
<ELF::Rela
>& relocations
,
65 std::vector
<uint8_t>* packed
);
67 // Unpack relative relocations from their more compact form.
68 // |packed| is the vector of packed relocations.
69 // |relocations| is a vector of unpacked relative relocation structs.
70 static void UnpackRelativeRelocations(const std::vector
<uint8_t>& packed
,
71 std::vector
<ELF::Rel
>* relocations
);
72 static void UnpackRelativeRelocations(const std::vector
<uint8_t>& packed
,
73 std::vector
<ELF::Rela
>* relocations
);
76 } // namespace relocation_packer
78 #endif // TOOLS_RELOCATION_PACKER_SRC_PACKER_H_