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

Side by Side Diff: tools/relocation_packer/src/main.cc

Issue 410933004: Extend relocation packing to cover arm64. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Script 'golden' test data generation 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 // Tool to pack and unpack ARM relative relocations in a shared library. 5 // Tool to pack and unpack relative relocations in a shared library.
6 // 6 //
7 // Packing removes ARM relative relocations from .rel.dyn and writes them 7 // Packing removes relative relocations from .rel.dyn and writes them
8 // in a more compact form to .android.rel.dyn. Unpacking does the reverse. 8 // in a more compact form to .android.rel.dyn. Unpacking does the reverse.
9 // 9 //
10 // Invoke with -v to trace actions taken when packing or unpacking. 10 // Invoke with -v to trace actions taken when packing or unpacking.
11 // Invoke with -p to pad removed relocations with R_*_NONE. Suppresses 11 // Invoke with -p to pad removed relocations with R_*_NONE. Suppresses
12 // shrinking of .rel.dyn. 12 // shrinking of .rel.dyn.
13 // See PrintUsage() below for full usage details. 13 // See PrintUsage() below for full usage details.
14 // 14 //
15 // NOTE: Breaks with libelf 0.152, which is buggy. libelf 0.158 works. 15 // NOTE: Breaks with libelf 0.152, which is buggy. libelf 0.158 works.
16 16
17 #include <errno.h> 17 #include <errno.h>
(...skipping 13 matching lines...) Expand all
31 31
32 void PrintUsage(const char* argv0) { 32 void PrintUsage(const char* argv0) {
33 std::string temporary = argv0; 33 std::string temporary = argv0;
34 const size_t last_slash = temporary.find_last_of("/"); 34 const size_t last_slash = temporary.find_last_of("/");
35 if (last_slash != temporary.npos) { 35 if (last_slash != temporary.npos) {
36 temporary.erase(0, last_slash + 1); 36 temporary.erase(0, last_slash + 1);
37 } 37 }
38 const char* basename = temporary.c_str(); 38 const char* basename = temporary.c_str();
39 39
40 printf( 40 printf(
41 "Usage: %s [-u] [-v] [-p] file\n" 41 "Usage: %s [-u] [-v] [-p] file\n\n"
42 "Pack or unpack ARM relative relocations in a shared library.\n\n" 42 "Pack or unpack relative relocations in a shared library.\n\n"
43 " -u, --unpack unpack previously packed ARM relative relocations\n" 43 " -u, --unpack unpack previously packed relative relocations\n"
44 " -v, --verbose trace object file modifications (for debugging)\n" 44 " -v, --verbose trace object file modifications (for debugging)\n"
45 " -p, --pad do not shrink .rel.dyn, but pad (for debugging)\n\n" 45 " -p, --pad do not shrink relocations, but pad (for debugging)\n\n",
46 "Extracts ARM relative relocations from the .rel.dyn section, packs\n" 46 basename);
47 "them into a more compact format, and stores the packed relocations in\n" 47
48 ".android.rel.dyn. Expands .android.rel.dyn to hold the packed data,\n" 48 if (ELF::kMachine == EM_ARM) {
49 "and shrinks .rel.dyn by the amount of unpacked data removed from it.\n\n" 49 printf(
50 "Before being packed, a shared library needs to be prepared by adding\n" 50 "Extracts relative relocations from the .rel.dyn section, packs them\n"
51 "a null .android.rel.dyn section. A complete packing process is:\n\n" 51 "into a more compact format, and stores the packed relocations in\n"
52 " echo -n 'NULL' >/tmp/small\n" 52 ".android.rel.dyn. Expands .android.rel.dyn to hold the packed\n"
53 " arm-linux-gnueabi-objcopy \\\n" 53 "data, and shrinks .rel.dyn by the amount of unpacked data removed\n"
54 " --add-section .android.rel.dyn=/tmp/small \\\n" 54 "from it.\n\n"
55 " libchrome.<version>.so\n" 55 "Before being packed, a shared library needs to be prepared by adding\n"
56 " rm /tmp/small\n" 56 "a null .android.rel.dyn section.\n\n"
57 " %s libchrome.<version>.so\n\n" 57 "To pack relocations in a shared library:\n\n"
58 "To unpack and restore the shared library to its original state:\n\n" 58 " echo -n 'NULL' >/tmp/small\n"
59 " %s -u libchrome.<version>.so\n" 59 " arm-linux-androideabi-objcopy \\\n"
60 " arm-linux-gnueabi-objcopy \\\n" 60 " --add-section .android.rel.dyn=/tmp/small \\\n"
61 " --remove-section=.android.rel.dyn libchrome.<version>.so\n\n" 61 " libchrome.<version>.so\n"
62 " rm /tmp/small\n"
63 " %s libchrome.<version>.so\n\n"
64 "To unpack and restore the shared library to its original state:\n\n"
65 " %s -u libchrome.<version>.so\n"
66 " arm-linux-androideabi-objcopy \\\n"
67 " --remove-section=.android.rel.dyn libchrome.<version>.so\n\n",
68 basename, basename);
69 } else if (ELF::kMachine == EM_AARCH64) {
70 printf(
71 "Extracts relative relocations from the .rela.dyn section, packs them\n"
72 "into a more compact format, and stores the packed relocations in\n"
73 ".android.rela.dyn. Expands .android.rela.dyn to hold the packed\n"
74 "data, and shrinks .rela.dyn by the amount of unpacked data removed\n"
75 "from it.\n\n"
76 "Before being packed, a shared library needs to be prepared by adding\n"
77 "a null .android.rela.dyn section.\n\n"
78 "To pack relocations in a shared library:\n\n"
79 " echo -n 'NULL' >/tmp/small\n"
80 " aarch64-linux-android-objcopy \\\n"
81 " --add-section .android.rela.dyn=/tmp/small \\\n"
82 " libchrome.<version>.so\n"
83 " rm /tmp/small\n"
84 " %s libchrome.<version>.so\n\n"
85 "To unpack and restore the shared library to its original state:\n\n"
86 " %s -u libchrome.<version>.so\n"
87 " aarch64-linux-android-objcopy \\\n"
88 " --remove-section=.android.rela.dyn libchrome.<version>.so\n\n",
89 basename, basename);
90 } else {
91 NOTREACHED();
92 }
93
94 printf(
62 "Debug sections are not handled, so packing should not be used on\n" 95 "Debug sections are not handled, so packing should not be used on\n"
63 "shared libraries compiled for debugging or otherwise unstripped.\n", 96 "shared libraries compiled for debugging or otherwise unstripped.\n");
64 basename, basename, basename);
65 } 97 }
66 98
67 } // namespace 99 } // namespace
68 100
69 int main(int argc, char* argv[]) { 101 int main(int argc, char* argv[]) {
70 bool is_unpacking = false; 102 bool is_unpacking = false;
71 bool is_verbose = false; 103 bool is_verbose = false;
72 bool is_padding = false; 104 bool is_padding = false;
73 105
74 static const option options[] = { 106 static const option options[] = {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 165
134 close(fd); 166 close(fd);
135 167
136 if (!status) { 168 if (!status) {
137 LOG(ERROR) << file << ": failed to pack/unpack file"; 169 LOG(ERROR) << file << ": failed to pack/unpack file";
138 return 1; 170 return 1;
139 } 171 }
140 172
141 return 0; 173 return 0;
142 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698