Linux Audio

Check our new training course

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