Merge tag 'usb-5.11-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[linux/fpc-iii.git] / arch / mips / boot / tools / relocs_main.c
blobe2453a564b119e05c4b276c7a98a7dae0ab4b90a
1 // SPDX-License-Identifier: GPL-2.0
3 #include <stdio.h>
4 #include <stdint.h>
5 #include <stdarg.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <errno.h>
9 #include <endian.h>
10 #include <elf.h>
12 #include "relocs.h"
14 void die(char *fmt, ...)
16 va_list ap;
18 va_start(ap, fmt);
19 vfprintf(stderr, fmt, ap);
20 va_end(ap);
21 exit(1);
24 static void usage(void)
26 die("relocs [--reloc-info|--text|--bin|--keep] vmlinux\n");
29 int main(int argc, char **argv)
31 int show_reloc_info, as_text, as_bin, keep_relocs;
32 const char *fname;
33 FILE *fp;
34 int i;
35 unsigned char e_ident[EI_NIDENT];
37 show_reloc_info = 0;
38 as_text = 0;
39 as_bin = 0;
40 keep_relocs = 0;
41 fname = NULL;
42 for (i = 1; i < argc; i++) {
43 char *arg = argv[i];
45 if (*arg == '-') {
46 if (strcmp(arg, "--reloc-info") == 0) {
47 show_reloc_info = 1;
48 continue;
50 if (strcmp(arg, "--text") == 0) {
51 as_text = 1;
52 continue;
54 if (strcmp(arg, "--bin") == 0) {
55 as_bin = 1;
56 continue;
58 if (strcmp(arg, "--keep") == 0) {
59 keep_relocs = 1;
60 continue;
62 } else if (!fname) {
63 fname = arg;
64 continue;
66 usage();
68 if (!fname)
69 usage();
71 fp = fopen(fname, "r+");
72 if (!fp)
73 die("Cannot open %s: %s\n", fname, strerror(errno));
75 if (fread(&e_ident, 1, EI_NIDENT, fp) != EI_NIDENT)
76 die("Cannot read %s: %s", fname, strerror(errno));
78 rewind(fp);
79 if (e_ident[EI_CLASS] == ELFCLASS64)
80 process_64(fp, as_text, as_bin, show_reloc_info, keep_relocs);
81 else
82 process_32(fp, as_text, as_bin, show_reloc_info, keep_relocs);
83 fclose(fp);
84 return 0;