relocs.c 15 KB

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