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.
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"
14
15namespace relocation_packer {
16
17// A RelocationPacker packs vectors of relocations into more
18// compact forms, and unpacks them to reproduce the pre-packed data.
19template <typename ELF>
20class RelocationPacker {
21 public:
22  // Pack relocations into a more compact form.
23  // |relocations| is a vector of relocation structs.
24  // |packed| is the vector of packed bytes into which relocations are packed.
25  static void PackRelocations(const std::vector<typename ELF::Rela>& relocations,
26                              std::vector<uint8_t>* packed);
27
28  // Unpack relocations from their more compact form.
29  // |packed| is the vector of packed relocations.
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);
33};
34
35}  // namespace relocation_packer
36
37#endif  // TOOLS_RELOCATION_PACKER_SRC_PACKER_H_
38