blob: 63f50e2496a6ba4a8d46a2fca151021cadd80ed4 [file] [log] [blame]
Dmitriy Ivanov87a06172015-02-06 10:56:28 -08001// 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 Ivanov87a06172015-02-06 10:56:28 -08006
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 Ivanov87a06172015-02-06 10:56:28 -080014
15namespace relocation_packer {
16
Dmitriy Ivanovf8ff6b12015-01-27 19:32:56 -080017// A RelocationPacker packs vectors of relocations into more
Dmitriy Ivanov87a06172015-02-06 10:56:28 -080018// compact forms, and unpacks them to reproduce the pre-packed data.
Dmitriy Ivanovf8ff6b12015-01-27 19:32:56 -080019template <typename ELF>
Dmitriy Ivanov87a06172015-02-06 10:56:28 -080020class RelocationPacker {
21 public:
Dmitriy Ivanovf8ff6b12015-01-27 19:32:56 -080022 // Pack relocations into a more compact form.
23 // |relocations| is a vector of relocation structs.
Dmitriy Ivanov87a06172015-02-06 10:56:28 -080024 // |packed| is the vector of packed bytes into which relocations are packed.
Dmitriy Ivanovf8ff6b12015-01-27 19:32:56 -080025 static void PackRelocations(const std::vector<typename ELF::Rela>& relocations,
26 std::vector<uint8_t>* packed);
Dmitriy Ivanov87a06172015-02-06 10:56:28 -080027
Dmitriy Ivanovf8ff6b12015-01-27 19:32:56 -080028 // Unpack relocations from their more compact form.
Dmitriy Ivanov87a06172015-02-06 10:56:28 -080029 // |packed| is the vector of packed relocations.
Dmitriy Ivanovf8ff6b12015-01-27 19:32:56 -080030 // |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 Ivanov87a06172015-02-06 10:56:28 -080033};
34
35} // namespace relocation_packer
36
37#endif // TOOLS_RELOCATION_PACKER_SRC_PACKER_H_