Linux 3.12.28
[linux/fpc-iii.git] / arch / x86 / tools / relocs_common.c
blob44d396823a53095ace215c49815cdb9cfa3614ed
1 #include "relocs.h"
3 void die(char *fmt, ...)
5 va_list ap;
6 va_start(ap, fmt);
7 vfprintf(stderr, fmt, ap);
8 va_end(ap);
9 exit(1);
12 static void usage(void)
14 die("relocs [--abs-syms|--abs-relocs|--text|--realmode] vmlinux\n");
17 int main(int argc, char **argv)
19 int show_absolute_syms, show_absolute_relocs;
20 int as_text, use_real_mode;
21 const char *fname;
22 FILE *fp;
23 int i;
24 unsigned char e_ident[EI_NIDENT];
26 show_absolute_syms = 0;
27 show_absolute_relocs = 0;
28 as_text = 0;
29 use_real_mode = 0;
30 fname = NULL;
31 for (i = 1; i < argc; i++) {
32 char *arg = argv[i];
33 if (*arg == '-') {
34 if (strcmp(arg, "--abs-syms") == 0) {
35 show_absolute_syms = 1;
36 continue;
38 if (strcmp(arg, "--abs-relocs") == 0) {
39 show_absolute_relocs = 1;
40 continue;
42 if (strcmp(arg, "--text") == 0) {
43 as_text = 1;
44 continue;
46 if (strcmp(arg, "--realmode") == 0) {
47 use_real_mode = 1;
48 continue;
51 else if (!fname) {
52 fname = arg;
53 continue;
55 usage();
57 if (!fname) {
58 usage();
60 fp = fopen(fname, "r");
61 if (!fp) {
62 die("Cannot open %s: %s\n", fname, strerror(errno));
64 if (fread(&e_ident, 1, EI_NIDENT, fp) != EI_NIDENT) {
65 die("Cannot read %s: %s", fname, strerror(errno));
67 rewind(fp);
68 if (e_ident[EI_CLASS] == ELFCLASS64)
69 process_64(fp, use_real_mode, as_text,
70 show_absolute_syms, show_absolute_relocs);
71 else
72 process_32(fp, use_real_mode, as_text,
73 show_absolute_syms, show_absolute_relocs);
74 fclose(fp);
75 return 0;