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

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

Issue 392653002: Upgrade logging to resemble base/logging.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for review feedback 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
« no previous file with comments | « tools/relocation_packer/src/elf_file.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 R_ARM_RELATIVE relocations in a shared library. 5 // Tool to pack and unpack R_ARM_RELATIVE relocations in a shared library.
6 // 6 //
7 // Packing removes R_ARM_RELATIVE relocations from .rel.dyn and writes them 7 // Packing removes R_ARM_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.
(...skipping 11 matching lines...) Expand all
22 #include <stdio.h> 22 #include <stdio.h>
23 #include <stdlib.h> 23 #include <stdlib.h>
24 #include <string.h> 24 #include <string.h>
25 #include <sys/types.h> 25 #include <sys/types.h>
26 #include <unistd.h> 26 #include <unistd.h>
27 #include <string> 27 #include <string>
28 28
29 #include "debug.h" 29 #include "debug.h"
30 #include "elf_file.h" 30 #include "elf_file.h"
31 #include "libelf.h" 31 #include "libelf.h"
32 #include "packer.h" 32
33 namespace {
33 34
34 void PrintUsage(const char* argv0) { 35 void PrintUsage(const char* argv0) {
35 std::string temporary = argv0; 36 std::string temporary = argv0;
36 const size_t last_slash = temporary.find_last_of("/"); 37 const size_t last_slash = temporary.find_last_of("/");
37 if (last_slash != temporary.npos) { 38 if (last_slash != temporary.npos) {
38 temporary.erase(0, last_slash + 1); 39 temporary.erase(0, last_slash + 1);
39 } 40 }
40 const char* basename = temporary.c_str(); 41 const char* basename = temporary.c_str();
41 42
42 printf( 43 printf(
(...skipping 16 matching lines...) Expand all
59 " %s libchrome.<version>.so\n\n" 60 " %s libchrome.<version>.so\n\n"
60 "To unpack and restore the shared library to its original state:\n\n" 61 "To unpack and restore the shared library to its original state:\n\n"
61 " %s -u libchrome.<version>.so\n" 62 " %s -u libchrome.<version>.so\n"
62 " arm-linux-gnueabi-objcopy \\\n" 63 " arm-linux-gnueabi-objcopy \\\n"
63 " --remove-section=.android.rel.dyn libchrome.<version>.so\n\n" 64 " --remove-section=.android.rel.dyn libchrome.<version>.so\n\n"
64 "Debug sections are not handled, so packing should not be used on\n" 65 "Debug sections are not handled, so packing should not be used on\n"
65 "shared libraries compiled for debugging or otherwise unstripped.\n", 66 "shared libraries compiled for debugging or otherwise unstripped.\n",
66 basename, basename, basename); 67 basename, basename, basename);
67 } 68 }
68 69
70 } // namespace
71
69 int main(int argc, char* argv[]) { 72 int main(int argc, char* argv[]) {
70 bool is_unpacking = false; 73 bool is_unpacking = false;
71 bool is_verbose = false; 74 bool is_verbose = false;
72 bool is_padding = false; 75 bool is_padding = false;
73 76
74 static const option options[] = { 77 static const option options[] = {
75 {"unpack", 0, 0, 'u'}, {"verbose", 0, 0, 'v'}, {"pad", 0, 0, 'p'}, 78 {"unpack", 0, 0, 'u'}, {"verbose", 0, 0, 'v'}, {"pad", 0, 0, 'p'},
76 {"help", 0, 0, 'h'}, {NULL, 0, 0, 0} 79 {"help", 0, 0, 'h'}, {NULL, 0, 0, 0}
77 }; 80 };
78 bool has_options = true; 81 bool has_options = true;
79 while (has_options) { 82 while (has_options) {
80 int c = getopt_long(argc, argv, "uvph", options, NULL); 83 int c = getopt_long(argc, argv, "uvph", options, NULL);
81 switch (c) { 84 switch (c) {
82 case 'u': 85 case 'u':
83 is_unpacking = true; 86 is_unpacking = true;
84 break; 87 break;
85 case 'v': 88 case 'v':
86 is_verbose = true; 89 is_verbose = true;
87 break; 90 break;
88 case 'p': 91 case 'p':
89 is_padding = true; 92 is_padding = true;
90 break; 93 break;
91 case 'h': 94 case 'h':
92 PrintUsage(argv[0]); 95 PrintUsage(argv[0]);
93 return 0; 96 return 0;
94 case '?': 97 case '?':
95 LOG("Try '%s --help' for more information.\n", argv[0]); 98 LOG(INFO) << "Try '" << argv[0] << " --help' for more information.";
96 return 1; 99 return 1;
97 case -1: 100 case -1:
98 has_options = false; 101 has_options = false;
99 break; 102 break;
100 default: 103 default:
101 NOTREACHED(); 104 NOTREACHED();
102 } 105 }
103 } 106 }
104 if (optind != argc - 1) { 107 if (optind != argc - 1) {
105 LOG("Try '%s --help' for more information.\n", argv[0]); 108 LOG(INFO) << "Try '" << argv[0] << " --help' for more information.";
106 return 1; 109 return 1;
107 } 110 }
108 111
109 if (elf_version(EV_CURRENT) == EV_NONE) { 112 if (elf_version(EV_CURRENT) == EV_NONE) {
110 LOG("WARNING: Elf Library is out of date!\n"); 113 LOG(WARNING) << "Elf Library is out of date!";
111 } 114 }
112 115
113 const char* file = argv[argc - 1]; 116 const char* file = argv[argc - 1];
114 const int fd = open(file, O_RDWR); 117 const int fd = open(file, O_RDWR);
115 if (fd == -1) { 118 if (fd == -1) {
116 LOG("%s: %s\n", file, strerror(errno)); 119 LOG(ERROR) << file << ": " << strerror(errno);
117 return 1; 120 return 1;
118 } 121 }
119 122
120 relocation_packer::Logger::SetVerbose(is_verbose); 123 if (is_verbose)
124 relocation_packer::Logger::SetVerbose(1);
121 125
122 relocation_packer::ElfFile elf_file(fd); 126 relocation_packer::ElfFile elf_file(fd);
123 elf_file.SetPadding(is_padding); 127 elf_file.SetPadding(is_padding);
124 128
125 bool status; 129 bool status;
126 if (is_unpacking) 130 if (is_unpacking)
127 status = elf_file.UnpackRelocations(); 131 status = elf_file.UnpackRelocations();
128 else 132 else
129 status = elf_file.PackRelocations(); 133 status = elf_file.PackRelocations();
130 134
131 close(fd); 135 close(fd);
132 136
133 if (!status) { 137 if (!status) {
134 LOG("ERROR: %s: failed to pack/unpack file\n", file); 138 LOG(ERROR) << file << ": failed to pack/unpack file";
135 return 1; 139 return 1;
136 } 140 }
137 141
138 return 0; 142 return 0;
139 } 143 }
OLDNEW
« no previous file with comments | « tools/relocation_packer/src/elf_file.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698