Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 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. |
| 4 | |
| 5 | // Pack relative relocations into a more compact form. |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 6 | |
| 7 | #ifndef TOOLS_RELOCATION_PACKER_SRC_PACKER_H_ |
| 8 | #define TOOLS_RELOCATION_PACKER_SRC_PACKER_H_ |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "elf.h" |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 14 | |
| 15 | namespace relocation_packer { |
| 16 | |
Dmitriy Ivanov | f8ff6b1 | 2015-01-27 19:32:56 -0800 | [diff] [blame] | 17 | // A RelocationPacker packs vectors of relocations into more |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 18 | // compact forms, and unpacks them to reproduce the pre-packed data. |
Dmitriy Ivanov | f8ff6b1 | 2015-01-27 19:32:56 -0800 | [diff] [blame] | 19 | template <typename ELF> |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 20 | class RelocationPacker { |
| 21 | public: |
Dmitriy Ivanov | f8ff6b1 | 2015-01-27 19:32:56 -0800 | [diff] [blame] | 22 | // Pack relocations into a more compact form. |
| 23 | // |relocations| is a vector of relocation structs. |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 24 | // |packed| is the vector of packed bytes into which relocations are packed. |
Dmitriy Ivanov | f8ff6b1 | 2015-01-27 19:32:56 -0800 | [diff] [blame] | 25 | static void PackRelocations(const std::vector<typename ELF::Rela>& relocations, |
| 26 | std::vector<uint8_t>* packed); |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 27 | |
Dmitriy Ivanov | f8ff6b1 | 2015-01-27 19:32:56 -0800 | [diff] [blame] | 28 | // Unpack relocations from their more compact form. |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 29 | // |packed| is the vector of packed relocations. |
Dmitriy Ivanov | f8ff6b1 | 2015-01-27 19:32:56 -0800 | [diff] [blame] | 30 | // |relocations| is a vector of unpacked relocation structs. |
| 31 | static void UnpackRelocations(const std::vector<uint8_t>& packed, |
| 32 | std::vector<typename ELF::Rela>* relocations); |
Dmitriy Ivanov | 87a0617 | 2015-02-06 10:56:28 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | } // namespace relocation_packer |
| 36 | |
| 37 | #endif // TOOLS_RELOCATION_PACKER_SRC_PACKER_H_ |