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