PageRenderTime 74ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/x86/boot/compressed/relocs.c

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