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

Side by Side Diff: ports/nacl-spawn/elf_reader.cc

Issue 1553053002: Update pnacl toolchain build (Closed) Base URL: https://chromium.googlesource.com/webports.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | ports/nacl-spawn/include/nacl_spawn.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2014 The Native Client 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 #include "elf_reader.h" 5 #include "elf_reader.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <elf.h> 8 #include <elf.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <stdarg.h> 10 #include <stdarg.h>
(...skipping 15 matching lines...) Expand all
26 FILE* get() { return fp_; } 26 FILE* get() { return fp_; }
27 27
28 private: 28 private:
29 FILE* fp_; 29 FILE* fp_;
30 }; 30 };
31 31
32 ElfReader::ElfReader(const char* filename) 32 ElfReader::ElfReader(const char* filename)
33 : filename_(filename), is_valid_(false), is_static_(false) { 33 : filename_(filename), is_valid_(false), is_static_(false) {
34 ScopedFile fp(fopen(filename, "rb")); 34 ScopedFile fp(fopen(filename, "rb"));
35 if (!fp.get()) { 35 if (!fp.get()) {
36 PrintError("failed to open file"); 36 PrintError("failed to open file: %s", strerror(errno));
37 return; 37 return;
38 } 38 }
39 39
40 std::vector<Elf64_Phdr> phdrs; 40 std::vector<Elf64_Phdr> phdrs;
41 if (!ReadHeaders(fp.get(), &phdrs)) 41 if (!ReadHeaders(fp.get(), &phdrs))
42 return; 42 return;
43 43
44 Elf64_Addr straddr = 0; 44 Elf64_Addr straddr = 0;
45 size_t strsize = 0; 45 size_t strsize = 0;
46 std::vector<int> neededs; 46 std::vector<int> neededs;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 void ElfReader::PrintError(const char* fmt, ...) { 240 void ElfReader::PrintError(const char* fmt, ...) {
241 static const int kBufSize = 256; 241 static const int kBufSize = 256;
242 char buf[kBufSize]; 242 char buf[kBufSize];
243 va_list ap; 243 va_list ap;
244 va_start(ap, fmt); 244 va_start(ap, fmt);
245 int written = vsnprintf(buf, kBufSize - 1, fmt, ap); 245 int written = vsnprintf(buf, kBufSize - 1, fmt, ap);
246 assert(written < kBufSize); 246 assert(written < kBufSize);
247 if (written >= kBufSize) 247 if (written >= kBufSize)
248 buf[kBufSize-1] = '\0'; 248 buf[kBufSize-1] = '\0';
249 249
250 if (errno) 250 fprintf(stderr, "%s: %s\n", filename_, buf);
251 fprintf(stderr, "%s: %s: %s\n", filename_, buf, strerror(errno));
252 else
253 fprintf(stderr, "%s: %s\n", filename_, buf);
254 } 251 }
255 252
256 #if defined(DEFINE_ELF_READER_MAIN) 253 #if defined(DEFINE_ELF_READER_MAIN)
257 254
258 int main(int argc, char* argv[]) { 255 int main(int argc, char* argv[]) {
259 if (argc < 2) { 256 if (argc < 2) {
260 fprintf(stderr, "Usage: %s <elf>\n", argv[0]); 257 fprintf(stderr, "Usage: %s <elf>\n", argv[0]);
261 return 1; 258 return 1;
262 } 259 }
263 260
264 // For test. 261 // For test.
265 if (!getenv("LD_LIBRARY_PATH")) 262 if (!getenv("LD_LIBRARY_PATH"))
266 setenv("LD_LIBRARY_PATH", ".", 1); 263 setenv("LD_LIBRARY_PATH", ".", 1);
267 264
268 ElfReader elf_reader(argv[1]); 265 ElfReader elf_reader(argv[1]);
269 if (!elf_reader.is_valid()) 266 if (!elf_reader.is_valid())
270 return 1; 267 return 1;
271 268
272 for (size_t i = 0; i < elf_reader.neededs().size(); i++) { 269 for (size_t i = 0; i < elf_reader.neededs().size(); i++) {
273 if (i) 270 if (i)
274 printf(" "); 271 printf(" ");
275 printf("%s", elf_reader.neededs()[i].c_str()); 272 printf("%s", elf_reader.neededs()[i].c_str());
276 } 273 }
277 } 274 }
278 275
279 #endif // DEFINE_ELF_READER_MAIN 276 #endif // DEFINE_ELF_READER_MAIN
OLDNEW
« no previous file with comments | « no previous file | ports/nacl-spawn/include/nacl_spawn.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698