relocs_common.c 1.7 KB

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