Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: tools/relocation_packer/src/run_length_encoder.h

Issue 404553003: Create builds configured for ARM and AARCH64. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename DT tags to DT_ANDROID_REL_XXX Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Run-length encode and decode R_ARM_RELATIVE relocations. 5 // Run-length encode and decode ARM relative relocations.
6 // 6 //
7 // R_ARM_RELATIVE relocations are the bulk of dynamic relocations (the 7 // ARM relative relocations are the bulk of dynamic relocations (the
8 // .rel.dyn section) in libchrome<version>.so, and the ELF standard 8 // .rel.dyn section) in libchrome<version>.so, and the ELF standard
9 // representation of them is wasteful. 9 // representation of them is wasteful.
10 // 10 //
11 // A relocation is 8 bytes (16 bytes on 64 bit plaforms), split into offset 11 // A relocation is 8 bytes (16 bytes on 64 bit plaforms), split into offset
12 // and info fields. Offsets strictly increase, and each is commonly a 12 // and info fields. Offsets strictly increase, and each is commonly a
13 // few bytes different from its predecessor. There are long runs where 13 // few bytes different from its predecessor. There are long runs where
14 // the difference does not change. The info field is always 0x17. Example, 14 // the difference does not change. The info field is always 0x17. Example,
15 // from 'readelf -x4 libchrome.<version>.so': 15 // from 'readelf -x4 libchrome.<version>.so':
16 // 16 //
17 // offset info offset info 17 // offset info offset info
18 // 808fef01 17000000 848fef01 17000000 ................ 18 // 808fef01 17000000 848fef01 17000000 ................
19 // 888fef01 17000000 8c8fef01 17000000 ................ 19 // 888fef01 17000000 8c8fef01 17000000 ................
20 // 908fef01 17000000 948fef01 17000000 ................ 20 // 908fef01 17000000 948fef01 17000000 ................
21 // 21 //
22 // Run length encoding packs this data more efficiently, by representing it 22 // Run length encoding packs this data more efficiently, by representing it
23 // as a delta and a count of entries each differing from its predecessor 23 // as a delta and a count of entries each differing from its predecessor
24 // by this delta. The above can be represented as a start address followed 24 // by this delta. The above can be represented as a start address followed
25 // by an encoded count of 6 and offset difference of 4: 25 // by an encoded count of 6 and offset difference of 4:
26 // 26 //
27 // start count diff 27 // start count diff
28 // 808fef01 00000006 00000004 28 // 808fef01 00000006 00000004
29 // 29 //
30 // Because R_ARM_RELATIVE relocation offsets strictly increase, the complete 30 // Because ARM relative relocation offsets strictly increase, the complete
31 // set of R_ARM_RELATIVE relocations in libchrome.<version>.so can be 31 // set of ARM relative relocations in libchrome.<version>.so can be
32 // represented by a single start address followed by one or more difference 32 // represented by a single start address followed by one or more difference
33 // and count encoded word pairs: 33 // and count encoded word pairs:
34 // 34 //
35 // start run1 count run1 diff run2 count run2 diff 35 // start run1 count run1 diff run2 count run2 diff
36 // 808fef01 00000006 00000004 00000010 00000008 ... 36 // 808fef01 00000006 00000004 00000010 00000008 ...
37 // 37 //
38 // Decoding regenerates R_ARM_RELATIVE relocations beginning at address 38 // Decoding regenerates ARM relative relocations beginning at address
39 // 'start' and for each encoded run, incrementing the address by 'difference' 39 // 'start' and for each encoded run, incrementing the address by 'difference'
40 // for 'count' iterations and emitting a new R_ARM_RELATIVE relocation. 40 // for 'count' iterations and emitting a new ARM relative relocation.
41 // 41 //
42 // Once encoded, data is prefixed by a single word count of packed delta and 42 // Once encoded, data is prefixed by a single word count of packed delta and
43 // count pairs. A final run-length encoded R_ARM_RELATIVE relocations vector 43 // count pairs. A final run-length encoded ARM relative relocations vector
44 // might therefore look something like: 44 // might therefore look something like:
45 // 45 //
46 // pairs start run 1 run 2 ... run 15 46 // pairs start run 1 run 2 ... run 15
47 // 0000000f 808fef01 00000006 00000004 00000010 00000008 ... 47 // 0000000f 808fef01 00000006 00000004 00000010 00000008 ...
48 // Interpreted as: 48 // Interpreted as:
49 // pairs=15 start=.. count=6,delta=4 count=16,delta=8 49 // pairs=15 start=.. count=6,delta=4 count=16,delta=8
50 50
51 #ifndef TOOLS_RELOCATION_PACKER_SRC_RUN_LENGTH_ENCODER_H_ 51 #ifndef TOOLS_RELOCATION_PACKER_SRC_RUN_LENGTH_ENCODER_H_
52 #define TOOLS_RELOCATION_PACKER_SRC_RUN_LENGTH_ENCODER_H_ 52 #define TOOLS_RELOCATION_PACKER_SRC_RUN_LENGTH_ENCODER_H_
53 53
54 #include <stdint.h>
55 #include <string.h>
56 #include <vector> 54 #include <vector>
57 55
58 #include "elf.h" 56 #include "elf.h"
57 #include "elf_traits.h"
59 58
60 namespace relocation_packer { 59 namespace relocation_packer {
61 60
62 // A RelocationRunLengthCodec packs vectors of R_ARM_RELATIVE relocations 61 // A RelocationRunLengthCodec packs vectors of ARM relative relocations
63 // into more compact forms, and unpacks them to reproduce the pre-packed data. 62 // into more compact forms, and unpacks them to reproduce the pre-packed data.
64 class RelocationRunLengthCodec { 63 class RelocationRunLengthCodec {
65 public: 64 public:
66 // Encode R_ARM_RELATIVE relocations into a more compact form. 65 // Encode ARM relative relocations into a more compact form.
67 // |relocations| is a vector of R_ARM_RELATIVE relocation structs. 66 // |relocations| is a vector of ARM relative relocation structs.
68 // |packed| is the vector of packed words into which relocations are packed. 67 // |packed| is the vector of packed words into which relocations are packed.
69 static void Encode(const std::vector<Elf32_Rel>& relocations, 68 static void Encode(const std::vector<ELF::Rel>& relocations,
70 std::vector<Elf32_Word>* packed); 69 std::vector<ELF::Xword>* packed);
71 70
72 // Decode R_ARM_RELATIVE relocations from their more compact form. 71 // Decode ARM relative relocations from their more compact form.
73 // |packed| is the vector of packed relocations. 72 // |packed| is the vector of packed relocations.
74 // |relocations| is a vector of unpacked R_ARM_RELATIVE relocation structs. 73 // |relocations| is a vector of unpacked ARM relative relocation structs.
75 static void Decode(const std::vector<Elf32_Word>& packed, 74 static void Decode(const std::vector<ELF::Xword>& packed,
76 std::vector<Elf32_Rel>* relocations); 75 std::vector<ELF::Rel>* relocations);
77 }; 76 };
78 77
79 } // namespace relocation_packer 78 } // namespace relocation_packer
80 79
81 #endif // TOOLS_RELOCATION_PACKER_SRC_RUN_LENGTH_ENCODER_H_ 80 #endif // TOOLS_RELOCATION_PACKER_SRC_RUN_LENGTH_ENCODER_H_
OLDNEW
« no previous file with comments | « tools/relocation_packer/src/packer_unittest.cc ('k') | tools/relocation_packer/src/run_length_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698