blob: acab636bcb348191794e0b8a4343c1874daa45a1 [file] [log] [blame]
H. Peter Anvinc889ba82013-04-16 16:02:58 -07001#include "relocs.h"
2
3void 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
12static void usage(void)
13{
Michael Davidson214a8872014-01-21 12:32:23 -080014 die("relocs [--abs-syms|--abs-relocs|--reloc-info|--text|--realmode]" \
15 " vmlinux\n");
H. Peter Anvinc889ba82013-04-16 16:02:58 -070016}
17
18int main(int argc, char **argv)
19{
Michael Davidson214a8872014-01-21 12:32:23 -080020 int show_absolute_syms, show_absolute_relocs, show_reloc_info;
H. Peter Anvinc889ba82013-04-16 16:02:58 -070021 int as_text, use_real_mode;
22 const char *fname;
23 FILE *fp;
24 int i;
25 unsigned char e_ident[EI_NIDENT];
26
27 show_absolute_syms = 0;
28 show_absolute_relocs = 0;
Michael Davidson214a8872014-01-21 12:32:23 -080029 show_reloc_info = 0;
H. Peter Anvinc889ba82013-04-16 16:02:58 -070030 as_text = 0;
31 use_real_mode = 0;
32 fname = NULL;
33 for (i = 1; i < argc; i++) {
34 char *arg = argv[i];
35 if (*arg == '-') {
36 if (strcmp(arg, "--abs-syms") == 0) {
37 show_absolute_syms = 1;
38 continue;
39 }
40 if (strcmp(arg, "--abs-relocs") == 0) {
41 show_absolute_relocs = 1;
42 continue;
43 }
Michael Davidson214a8872014-01-21 12:32:23 -080044 if (strcmp(arg, "--reloc-info") == 0) {
45 show_reloc_info = 1;
46 continue;
47 }
H. Peter Anvinc889ba82013-04-16 16:02:58 -070048 if (strcmp(arg, "--text") == 0) {
49 as_text = 1;
50 continue;
51 }
52 if (strcmp(arg, "--realmode") == 0) {
53 use_real_mode = 1;
54 continue;
55 }
56 }
57 else if (!fname) {
58 fname = arg;
59 continue;
60 }
61 usage();
62 }
63 if (!fname) {
64 usage();
65 }
66 fp = fopen(fname, "r");
67 if (!fp) {
68 die("Cannot open %s: %s\n", fname, strerror(errno));
69 }
70 if (fread(&e_ident, 1, EI_NIDENT, fp) != EI_NIDENT) {
71 die("Cannot read %s: %s", fname, strerror(errno));
72 }
73 rewind(fp);
74 if (e_ident[EI_CLASS] == ELFCLASS64)
75 process_64(fp, use_real_mode, as_text,
Michael Davidson214a8872014-01-21 12:32:23 -080076 show_absolute_syms, show_absolute_relocs,
77 show_reloc_info);
H. Peter Anvinc889ba82013-04-16 16:02:58 -070078 else
79 process_32(fp, use_real_mode, as_text,
Michael Davidson214a8872014-01-21 12:32:23 -080080 show_absolute_syms, show_absolute_relocs,
81 show_reloc_info);
H. Peter Anvinc889ba82013-04-16 16:02:58 -070082 fclose(fp);
83 return 0;
84}