relocs_common.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "relocs.h"
  2. void die(char *fmt, ...)
  3. {
  4. va_list ap;
  5. va_start(ap, fmt);
  6. vfprintf(stderr, fmt, ap);
  7. va_end(ap);
  8. exit(1);
  9. }
  10. static void usage(void)
  11. {
  12. die("relocs [--abs-syms|--abs-relocs|--reloc-info|--text|--realmode]" \
  13. " vmlinux\n");
  14. }
  15. int main(int argc, char **argv)
  16. {
  17. int show_absolute_syms, show_absolute_relocs, show_reloc_info;
  18. int as_text, use_real_mode;
  19. const char *fname;
  20. FILE *fp;
  21. int i;
  22. unsigned char e_ident[EI_NIDENT];
  23. show_absolute_syms = 0;
  24. show_absolute_relocs = 0;
  25. show_reloc_info = 0;
  26. as_text = 0;
  27. use_real_mode = 0;
  28. fname = NULL;
  29. for (i = 1; i < argc; i++) {
  30. char *arg = argv[i];
  31. if (*arg == '-') {
  32. if (strcmp(arg, "--abs-syms") == 0) {
  33. show_absolute_syms = 1;
  34. continue;
  35. }
  36. if (strcmp(arg, "--abs-relocs") == 0) {
  37. show_absolute_relocs = 1;
  38. continue;
  39. }
  40. if (strcmp(arg, "--reloc-info") == 0) {
  41. show_reloc_info = 1;
  42. continue;
  43. }
  44. if (strcmp(arg, "--text") == 0) {
  45. as_text = 1;
  46. continue;
  47. }
  48. if (strcmp(arg, "--realmode") == 0) {
  49. use_real_mode = 1;
  50. continue;
  51. }
  52. }
  53. else if (!fname) {
  54. fname = arg;
  55. continue;
  56. }
  57. usage();
  58. }
  59. if (!fname) {
  60. usage();
  61. }
  62. fp = fopen(fname, "r");
  63. if (!fp) {
  64. die("Cannot open %s: %s\n", fname, strerror(errno));
  65. }
  66. if (fread(&e_ident, 1, EI_NIDENT, fp) != EI_NIDENT) {
  67. die("Cannot read %s: %s", fname, strerror(errno));
  68. }
  69. rewind(fp);
  70. if (e_ident[EI_CLASS] == ELFCLASS64)
  71. process_64(fp, use_real_mode, as_text,
  72. show_absolute_syms, show_absolute_relocs,
  73. show_reloc_info);
  74. else
  75. process_32(fp, use_real_mode, as_text,
  76. show_absolute_syms, show_absolute_relocs,
  77. show_reloc_info);
  78. fclose(fp);
  79. return 0;
  80. }