relocs.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8. #include <elf.h>
  9. #include <byteswap.h>
  10. #define USE_BSD
  11. #include <endian.h>
  12. #define MAX_SHDRS 100
  13. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  14. static Elf32_Ehdr ehdr;
  15. static Elf32_Shdr shdr[MAX_SHDRS];
  16. static Elf32_Sym *symtab[MAX_SHDRS];
  17. static Elf32_Rel *reltab[MAX_SHDRS];
  18. static char *strtab[MAX_SHDRS];
  19. static unsigned long reloc_count, reloc_idx;
  20. static unsigned long *relocs;
  21. /*
  22. * Following symbols have been audited. There values are constant and do
  23. * not change if bzImage is loaded at a different physical address than
  24. * the address for which it has been compiled. Don't warn user about
  25. * absolute relocations present w.r.t these symbols.
  26. */
  27. static const char* safe_abs_relocs[] = {
  28. "xen_irq_disable_direct_reloc",
  29. "xen_save_fl_direct_reloc",
  30. };
  31. static int is_safe_abs_reloc(const char* sym_name)
  32. {
  33. int i;
  34. for(i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
  35. if (!strcmp(sym_name, safe_abs_relocs[i]))
  36. /* Match found */
  37. return 1;
  38. }
  39. if (strncmp(sym_name, "VDSO", 4) == 0)
  40. return 1;
  41. if (strncmp(sym_name, "__crc_", 6) == 0)
  42. return 1;
  43. return 0;
  44. }
  45. static void die(char *fmt, ...)
  46. {
  47. va_list ap;
  48. va_start(ap, fmt);
  49. vfprintf(stderr, fmt, ap);
  50. va_end(ap);
  51. exit(1);
  52. }
  53. static const char *sym_type(unsigned type)
  54. {
  55. static const char *type_name[] = {
  56. #define SYM_TYPE(X) [X] = #X
  57. SYM_TYPE(STT_NOTYPE),
  58. SYM_TYPE(STT_OBJECT),
  59. SYM_TYPE(STT_FUNC),
  60. SYM_TYPE(STT_SECTION),
  61. SYM_TYPE(STT_FILE),
  62. SYM_TYPE(STT_COMMON),
  63. SYM_TYPE(STT_TLS),
  64. #undef SYM_TYPE
  65. };
  66. const char *name = "unknown sym type name";
  67. if (type < ARRAY_SIZE(type_name)) {
  68. name = type_name[type];
  69. }
  70. return name;
  71. }
  72. static const char *sym_bind(unsigned bind)
  73. {
  74. static const char *bind_name[] = {
  75. #define SYM_BIND(X) [X] = #X
  76. SYM_BIND(STB_LOCAL),
  77. SYM_BIND(STB_GLOBAL),
  78. SYM_BIND(STB_WEAK),
  79. #undef SYM_BIND
  80. };
  81. const char *name = "unknown sym bind name";
  82. if (bind < ARRAY_SIZE(bind_name)) {
  83. name = bind_name[bind];
  84. }
  85. return name;
  86. }
  87. static const char *sym_visibility(unsigned visibility)
  88. {
  89. static const char *visibility_name[] = {
  90. #define SYM_VISIBILITY(X) [X] = #X
  91. SYM_VISIBILITY(STV_DEFAULT),
  92. SYM_VISIBILITY(STV_INTERNAL),
  93. SYM_VISIBILITY(STV_HIDDEN),
  94. SYM_VISIBILITY(STV_PROTECTED),
  95. #undef SYM_VISIBILITY
  96. };
  97. const char *name = "unknown sym visibility name";
  98. if (visibility < ARRAY_SIZE(visibility_name)) {
  99. name = visibility_name[visibility];
  100. }
  101. return name;
  102. }
  103. static const char *rel_type(unsigned type)
  104. {
  105. static const char *type_name[] = {
  106. #define REL_TYPE(X) [X] = #X
  107. REL_TYPE(R_386_NONE),
  108. REL_TYPE(R_386_32),
  109. REL_TYPE(R_386_PC32),
  110. REL_TYPE(R_386_GOT32),
  111. REL_TYPE(R_386_PLT32),
  112. REL_TYPE(R_386_COPY),
  113. REL_TYPE(R_386_GLOB_DAT),
  114. REL_TYPE(R_386_JMP_SLOT),
  115. REL_TYPE(R_386_RELATIVE),
  116. REL_TYPE(R_386_GOTOFF),
  117. REL_TYPE(R_386_GOTPC),
  118. #undef REL_TYPE
  119. };
  120. const char *name = "unknown type rel type name";
  121. if (type < ARRAY_SIZE(type_name)) {
  122. name = type_name[type];
  123. }
  124. return name;
  125. }
  126. static const char *sec_name(unsigned shndx)
  127. {
  128. const char *sec_strtab;
  129. const char *name;
  130. sec_strtab = strtab[ehdr.e_shstrndx];
  131. name = "<noname>";
  132. if (shndx < ehdr.e_shnum) {
  133. name = sec_strtab + shdr[shndx].sh_name;
  134. }
  135. else if (shndx == SHN_ABS) {
  136. name = "ABSOLUTE";
  137. }
  138. else if (shndx == SHN_COMMON) {
  139. name = "COMMON";
  140. }
  141. return name;
  142. }
  143. static const char *sym_name(const char *sym_strtab, Elf32_Sym *sym)
  144. {
  145. const char *name;
  146. name = "<noname>";
  147. if (sym->st_name) {
  148. name = sym_strtab + sym->st_name;
  149. }
  150. else {
  151. name = sec_name(shdr[sym->st_shndx].sh_name);
  152. }
  153. return name;
  154. }
  155. #if BYTE_ORDER == LITTLE_ENDIAN
  156. #define le16_to_cpu(val) (val)
  157. #define le32_to_cpu(val) (val)
  158. #endif
  159. #if BYTE_ORDER == BIG_ENDIAN
  160. #define le16_to_cpu(val) bswap_16(val)
  161. #define le32_to_cpu(val) bswap_32(val)
  162. #endif
  163. static uint16_t elf16_to_cpu(uint16_t val)
  164. {
  165. return le16_to_cpu(val);
  166. }
  167. static uint32_t elf32_to_cpu(uint32_t val)
  168. {
  169. return le32_to_cpu(val);
  170. }
  171. static void read_ehdr(FILE *fp)
  172. {
  173. if (fread(&ehdr, sizeof(ehdr), 1, fp) != 1) {
  174. die("Cannot read ELF header: %s\n",
  175. strerror(errno));
  176. }
  177. if (memcmp(ehdr.e_ident, ELFMAG, 4) != 0) {
  178. die("No ELF magic\n");
  179. }
  180. if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
  181. die("Not a 32 bit executable\n");
  182. }
  183. if (ehdr.e_ident[EI_DATA] != ELFDATA2LSB) {
  184. die("Not a LSB ELF executable\n");
  185. }
  186. if (ehdr.e_ident[EI_VERSION] != EV_CURRENT) {
  187. die("Unknown ELF version\n");
  188. }
  189. /* Convert the fields to native endian */
  190. ehdr.e_type = elf16_to_cpu(ehdr.e_type);
  191. ehdr.e_machine = elf16_to_cpu(ehdr.e_machine);
  192. ehdr.e_version = elf32_to_cpu(ehdr.e_version);
  193. ehdr.e_entry = elf32_to_cpu(ehdr.e_entry);
  194. ehdr.e_phoff = elf32_to_cpu(ehdr.e_phoff);
  195. ehdr.e_shoff = elf32_to_cpu(ehdr.e_shoff);
  196. ehdr.e_flags = elf32_to_cpu(ehdr.e_flags);
  197. ehdr.e_ehsize = elf16_to_cpu(ehdr.e_ehsize);
  198. ehdr.e_phentsize = elf16_to_cpu(ehdr.e_phentsize);
  199. ehdr.e_phnum = elf16_to_cpu(ehdr.e_phnum);
  200. ehdr.e_shentsize = elf16_to_cpu(ehdr.e_shentsize);
  201. ehdr.e_shnum = elf16_to_cpu(ehdr.e_shnum);
  202. ehdr.e_shstrndx = elf16_to_cpu(ehdr.e_shstrndx);
  203. if ((ehdr.e_type != ET_EXEC) && (ehdr.e_type != ET_DYN)) {
  204. die("Unsupported ELF header type\n");
  205. }
  206. if (ehdr.e_machine != EM_386) {
  207. die("Not for x86\n");
  208. }
  209. if (ehdr.e_version != EV_CURRENT) {
  210. die("Unknown ELF version\n");
  211. }
  212. if (ehdr.e_ehsize != sizeof(Elf32_Ehdr)) {
  213. die("Bad Elf header size\n");
  214. }
  215. if (ehdr.e_phentsize != sizeof(Elf32_Phdr)) {
  216. die("Bad program header entry\n");
  217. }
  218. if (ehdr.e_shentsize != sizeof(Elf32_Shdr)) {
  219. die("Bad section header entry\n");
  220. }
  221. if (ehdr.e_shstrndx >= ehdr.e_shnum) {
  222. die("String table index out of bounds\n");
  223. }
  224. }
  225. static void read_shdrs(FILE *fp)
  226. {
  227. int i;
  228. if (ehdr.e_shnum > MAX_SHDRS) {
  229. die("%d section headers supported: %d\n",
  230. ehdr.e_shnum, MAX_SHDRS);
  231. }
  232. if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) {
  233. die("Seek to %d failed: %s\n",
  234. ehdr.e_shoff, strerror(errno));
  235. }
  236. if (fread(&shdr, sizeof(shdr[0]), ehdr.e_shnum, fp) != ehdr.e_shnum) {
  237. die("Cannot read ELF section headers: %s\n",
  238. strerror(errno));
  239. }
  240. for(i = 0; i < ehdr.e_shnum; i++) {
  241. shdr[i].sh_name = elf32_to_cpu(shdr[i].sh_name);
  242. shdr[i].sh_type = elf32_to_cpu(shdr[i].sh_type);
  243. shdr[i].sh_flags = elf32_to_cpu(shdr[i].sh_flags);
  244. shdr[i].sh_addr = elf32_to_cpu(shdr[i].sh_addr);
  245. shdr[i].sh_offset = elf32_to_cpu(shdr[i].sh_offset);
  246. shdr[i].sh_size = elf32_to_cpu(shdr[i].sh_size);
  247. shdr[i].sh_link = elf32_to_cpu(shdr[i].sh_link);
  248. shdr[i].sh_info = elf32_to_cpu(shdr[i].sh_info);
  249. shdr[i].sh_addralign = elf32_to_cpu(shdr[i].sh_addralign);
  250. shdr[i].sh_entsize = elf32_to_cpu(shdr[i].sh_entsize);
  251. }
  252. }
  253. static void read_strtabs(FILE *fp)
  254. {
  255. int i;
  256. for(i = 0; i < ehdr.e_shnum; i++) {
  257. if (shdr[i].sh_type != SHT_STRTAB) {
  258. continue;
  259. }
  260. strtab[i] = malloc(shdr[i].sh_size);
  261. if (!strtab[i]) {
  262. die("malloc of %d bytes for strtab failed\n",
  263. shdr[i].sh_size);
  264. }
  265. if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
  266. die("Seek to %d failed: %s\n",
  267. shdr[i].sh_offset, strerror(errno));
  268. }
  269. if (fread(strtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
  270. die("Cannot read symbol table: %s\n",
  271. strerror(errno));
  272. }
  273. }
  274. }
  275. static void read_symtabs(FILE *fp)
  276. {
  277. int i,j;
  278. for(i = 0; i < ehdr.e_shnum; i++) {
  279. if (shdr[i].sh_type != SHT_SYMTAB) {
  280. continue;
  281. }
  282. symtab[i] = malloc(shdr[i].sh_size);
  283. if (!symtab[i]) {
  284. die("malloc of %d bytes for symtab failed\n",
  285. shdr[i].sh_size);
  286. }
  287. if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
  288. die("Seek to %d failed: %s\n",
  289. shdr[i].sh_offset, strerror(errno));
  290. }
  291. if (fread(symtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
  292. die("Cannot read symbol table: %s\n",
  293. strerror(errno));
  294. }
  295. for(j = 0; j < shdr[i].sh_size/sizeof(symtab[i][0]); j++) {
  296. symtab[i][j].st_name = elf32_to_cpu(symtab[i][j].st_name);
  297. symtab[i][j].st_value = elf32_to_cpu(symtab[i][j].st_value);
  298. symtab[i][j].st_size = elf32_to_cpu(symtab[i][j].st_size);
  299. symtab[i][j].st_shndx = elf16_to_cpu(symtab[i][j].st_shndx);
  300. }
  301. }
  302. }
  303. static void read_relocs(FILE *fp)
  304. {
  305. int i,j;
  306. for(i = 0; i < ehdr.e_shnum; i++) {
  307. if (shdr[i].sh_type != SHT_REL) {
  308. continue;
  309. }
  310. reltab[i] = malloc(shdr[i].sh_size);
  311. if (!reltab[i]) {
  312. die("malloc of %d bytes for relocs failed\n",
  313. shdr[i].sh_size);
  314. }
  315. if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
  316. die("Seek to %d failed: %s\n",
  317. shdr[i].sh_offset, strerror(errno));
  318. }
  319. if (fread(reltab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
  320. die("Cannot read symbol table: %s\n",
  321. strerror(errno));
  322. }
  323. for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
  324. reltab[i][j].r_offset = elf32_to_cpu(reltab[i][j].r_offset);
  325. reltab[i][j].r_info = elf32_to_cpu(reltab[i][j].r_info);
  326. }
  327. }
  328. }
  329. static void print_absolute_symbols(void)
  330. {
  331. int i;
  332. printf("Absolute symbols\n");
  333. printf(" Num: Value Size Type Bind Visibility Name\n");
  334. for(i = 0; i < ehdr.e_shnum; i++) {
  335. char *sym_strtab;
  336. Elf32_Sym *sh_symtab;
  337. int j;
  338. if (shdr[i].sh_type != SHT_SYMTAB) {
  339. continue;
  340. }
  341. sh_symtab = symtab[i];
  342. sym_strtab = strtab[shdr[i].sh_link];
  343. for(j = 0; j < shdr[i].sh_size/sizeof(symtab[0][0]); j++) {
  344. Elf32_Sym *sym;
  345. const char *name;
  346. sym = &symtab[i][j];
  347. name = sym_name(sym_strtab, sym);
  348. if (sym->st_shndx != SHN_ABS) {
  349. continue;
  350. }
  351. printf("%5d %08x %5d %10s %10s %12s %s\n",
  352. j, sym->st_value, sym->st_size,
  353. sym_type(ELF32_ST_TYPE(sym->st_info)),
  354. sym_bind(ELF32_ST_BIND(sym->st_info)),
  355. sym_visibility(ELF32_ST_VISIBILITY(sym->st_other)),
  356. name);
  357. }
  358. }
  359. printf("\n");
  360. }
  361. static void print_absolute_relocs(void)
  362. {
  363. int i, printed = 0;
  364. for(i = 0; i < ehdr.e_shnum; i++) {
  365. char *sym_strtab;
  366. Elf32_Sym *sh_symtab;
  367. unsigned sec_applies, sec_symtab;
  368. int j;
  369. if (shdr[i].sh_type != SHT_REL) {
  370. continue;
  371. }
  372. sec_symtab = shdr[i].sh_link;
  373. sec_applies = shdr[i].sh_info;
  374. if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) {
  375. continue;
  376. }
  377. sh_symtab = symtab[sec_symtab];
  378. sym_strtab = strtab[shdr[sec_symtab].sh_link];
  379. for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
  380. Elf32_Rel *rel;
  381. Elf32_Sym *sym;
  382. const char *name;
  383. rel = &reltab[i][j];
  384. sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
  385. name = sym_name(sym_strtab, sym);
  386. if (sym->st_shndx != SHN_ABS) {
  387. continue;
  388. }
  389. /* Absolute symbols are not relocated if bzImage is
  390. * loaded at a non-compiled address. Display a warning
  391. * to user at compile time about the absolute
  392. * relocations present.
  393. *
  394. * User need to audit the code to make sure
  395. * some symbols which should have been section
  396. * relative have not become absolute because of some
  397. * linker optimization or wrong programming usage.
  398. *
  399. * Before warning check if this absolute symbol
  400. * relocation is harmless.
  401. */
  402. if (is_safe_abs_reloc(name))
  403. continue;
  404. if (!printed) {
  405. printf("WARNING: Absolute relocations"
  406. " present\n");
  407. printf("Offset Info Type Sym.Value "
  408. "Sym.Name\n");
  409. printed = 1;
  410. }
  411. printf("%08x %08x %10s %08x %s\n",
  412. rel->r_offset,
  413. rel->r_info,
  414. rel_type(ELF32_R_TYPE(rel->r_info)),
  415. sym->st_value,
  416. name);
  417. }
  418. }
  419. if (printed)
  420. printf("\n");
  421. }
  422. static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
  423. {
  424. int i;
  425. /* Walk through the relocations */
  426. for(i = 0; i < ehdr.e_shnum; i++) {
  427. char *sym_strtab;
  428. Elf32_Sym *sh_symtab;
  429. unsigned sec_applies, sec_symtab;
  430. int j;
  431. if (shdr[i].sh_type != SHT_REL) {
  432. continue;
  433. }
  434. sec_symtab = shdr[i].sh_link;
  435. sec_applies = shdr[i].sh_info;
  436. if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) {
  437. continue;
  438. }
  439. sh_symtab = symtab[sec_symtab];
  440. sym_strtab = strtab[shdr[sec_symtab].sh_link];
  441. for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
  442. Elf32_Rel *rel;
  443. Elf32_Sym *sym;
  444. unsigned r_type;
  445. rel = &reltab[i][j];
  446. sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
  447. r_type = ELF32_R_TYPE(rel->r_info);
  448. /* Don't visit relocations to absolute symbols */
  449. if (sym->st_shndx == SHN_ABS) {
  450. continue;
  451. }
  452. if (r_type == R_386_PC32) {
  453. /* PC relative relocations don't need to be adjusted */
  454. }
  455. else if (r_type == R_386_32) {
  456. /* Visit relocations that need to be adjusted */
  457. visit(rel, sym);
  458. }
  459. else {
  460. die("Unsupported relocation type: %d\n", r_type);
  461. }
  462. }
  463. }
  464. }
  465. static void count_reloc(Elf32_Rel *rel, Elf32_Sym *sym)
  466. {
  467. reloc_count += 1;
  468. }
  469. static void collect_reloc(Elf32_Rel *rel, Elf32_Sym *sym)
  470. {
  471. /* Remember the address that needs to be adjusted. */
  472. relocs[reloc_idx++] = rel->r_offset;
  473. }
  474. static int cmp_relocs(const void *va, const void *vb)
  475. {
  476. const unsigned long *a, *b;
  477. a = va; b = vb;
  478. return (*a == *b)? 0 : (*a > *b)? 1 : -1;
  479. }
  480. static void emit_relocs(int as_text)
  481. {
  482. int i;
  483. /* Count how many relocations I have and allocate space for them. */
  484. reloc_count = 0;
  485. walk_relocs(count_reloc);
  486. relocs = malloc(reloc_count * sizeof(relocs[0]));
  487. if (!relocs) {
  488. die("malloc of %d entries for relocs failed\n",
  489. reloc_count);
  490. }
  491. /* Collect up the relocations */
  492. reloc_idx = 0;
  493. walk_relocs(collect_reloc);
  494. /* Order the relocations for more efficient processing */
  495. qsort(relocs, reloc_count, sizeof(relocs[0]), cmp_relocs);
  496. /* Print the relocations */
  497. if (as_text) {
  498. /* Print the relocations in a form suitable that
  499. * gas will like.
  500. */
  501. printf(".section \".data.reloc\",\"a\"\n");
  502. printf(".balign 4\n");
  503. for(i = 0; i < reloc_count; i++) {
  504. printf("\t .long 0x%08lx\n", relocs[i]);
  505. }
  506. printf("\n");
  507. }
  508. else {
  509. unsigned char buf[4];
  510. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  511. /* Print a stop */
  512. printf("%c%c%c%c", buf[0], buf[1], buf[2], buf[3]);
  513. /* Now print each relocation */
  514. for(i = 0; i < reloc_count; i++) {
  515. buf[0] = (relocs[i] >> 0) & 0xff;
  516. buf[1] = (relocs[i] >> 8) & 0xff;
  517. buf[2] = (relocs[i] >> 16) & 0xff;
  518. buf[3] = (relocs[i] >> 24) & 0xff;
  519. printf("%c%c%c%c", buf[0], buf[1], buf[2], buf[3]);
  520. }
  521. }
  522. }
  523. static void usage(void)
  524. {
  525. die("relocs [--abs-syms |--abs-relocs | --text] vmlinux\n");
  526. }
  527. int main(int argc, char **argv)
  528. {
  529. int show_absolute_syms, show_absolute_relocs;
  530. int as_text;
  531. const char *fname;
  532. FILE *fp;
  533. int i;
  534. show_absolute_syms = 0;
  535. show_absolute_relocs = 0;
  536. as_text = 0;
  537. fname = NULL;
  538. for(i = 1; i < argc; i++) {
  539. char *arg = argv[i];
  540. if (*arg == '-') {
  541. if (strcmp(argv[1], "--abs-syms") == 0) {
  542. show_absolute_syms = 1;
  543. continue;
  544. }
  545. if (strcmp(argv[1], "--abs-relocs") == 0) {
  546. show_absolute_relocs = 1;
  547. continue;
  548. }
  549. else if (strcmp(argv[1], "--text") == 0) {
  550. as_text = 1;
  551. continue;
  552. }
  553. }
  554. else if (!fname) {
  555. fname = arg;
  556. continue;
  557. }
  558. usage();
  559. }
  560. if (!fname) {
  561. usage();
  562. }
  563. fp = fopen(fname, "r");
  564. if (!fp) {
  565. die("Cannot open %s: %s\n",
  566. fname, strerror(errno));
  567. }
  568. read_ehdr(fp);
  569. read_shdrs(fp);
  570. read_strtabs(fp);
  571. read_symtabs(fp);
  572. read_relocs(fp);
  573. if (show_absolute_syms) {
  574. print_absolute_symbols();
  575. return 0;
  576. }
  577. if (show_absolute_relocs) {
  578. print_absolute_relocs();
  579. return 0;
  580. }
  581. emit_relocs(as_text);
  582. return 0;
  583. }