blob: 6634352a20bc7835ac8365a31ec6b9e146581cb2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
H. Peter Anvinc889ba82013-04-16 16:02:58 -07002#include "relocs.h"
3
4void die(char *fmt, ...)
5{
6 va_list ap;
7 va_start(ap, fmt);
8 vfprintf(stderr, fmt, ap);
9 va_end(ap);
10 exit(1);
11}
12
13static void usage(void)
14{
Michael Davidson214a8872014-01-21 12:32:23 -080015 die("relocs [--abs-syms|--abs-relocs|--reloc-info|--text|--realmode]" \
16 " vmlinux\n");
H. Peter Anvinc889ba82013-04-16 16:02:58 -070017}
18
19int main(int argc, char **argv)
20{
Michael Davidson214a8872014-01-21 12:32:23 -080021 int show_absolute_syms, show_absolute_relocs, show_reloc_info;
H. Peter Anvinc889ba82013-04-16 16:02:58 -070022 int as_text, use_real_mode;
23 const char *fname;
24 FILE *fp;
25 int i;
26 unsigned char e_ident[EI_NIDENT];
27
28 show_absolute_syms = 0;
29 show_absolute_relocs = 0;
Michael Davidson214a8872014-01-21 12:32:23 -080030 show_reloc_info = 0;
H. Peter Anvinc889ba82013-04-16 16:02:58 -070031 as_text = 0;
32 use_real_mode = 0;
33 fname = NULL;
34 for (i = 1; i < argc; i++) {
35 char *arg = argv[i];
36 if (*arg == '-') {
37 if (strcmp(arg, "--abs-syms") == 0) {
38 show_absolute_syms = 1;
39 continue;
40 }
41 if (strcmp(arg, "--abs-relocs") == 0) {
42 show_absolute_relocs = 1;
43 continue;
44 }
Michael Davidson214a8872014-01-21 12:32:23 -080045 if (strcmp(arg, "--reloc-info") == 0) {
46 show_reloc_info = 1;
47 continue;
48 }
H. Peter Anvinc889ba82013-04-16 16:02:58 -070049 if (strcmp(arg, "--text") == 0) {
50 as_text = 1;
51 continue;
52 }
53 if (strcmp(arg, "--realmode") == 0) {
54 use_real_mode = 1;
55 continue;
56 }
57 }
58 else if (!fname) {
59 fname = arg;
60 continue;
61 }
62 usage();
63 }
64 if (!fname) {
65 usage();
66 }
67 fp = fopen(fname, "r");
68 if (!fp) {
69 die("Cannot open %s: %s\n", fname, strerror(errno));
70 }
71 if (fread(&e_ident, 1, EI_NIDENT, fp) != EI_NIDENT) {
72 die("Cannot read %s: %s", fname, strerror(errno));
73 }
74 rewind(fp);
75 if (e_ident[EI_CLASS] == ELFCLASS64)
76 process_64(fp, use_real_mode, as_text,
Michael Davidson214a8872014-01-21 12:32:23 -080077 show_absolute_syms, show_absolute_relocs,
78 show_reloc_info);
H. Peter Anvinc889ba82013-04-16 16:02:58 -070079 else
80 process_32(fp, use_real_mode, as_text,
Michael Davidson214a8872014-01-21 12:32:23 -080081 show_absolute_syms, show_absolute_relocs,
82 show_reloc_info);
H. Peter Anvinc889ba82013-04-16 16:02:58 -070083 fclose(fp);
84 return 0;
85}