Skip to content

Commit aa221f2

Browse files
committed
kallsyms: take the input file instead of reading stdin
This gets rid of the pipe operator connected with 'cat'. Also use getopt_long() to parse the command line. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent a2833d1 commit aa221f2

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

scripts/kallsyms.c

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*
1919
*/
2020

21+
#include <getopt.h>
2122
#include <stdbool.h>
2223
#include <stdio.h>
2324
#include <stdlib.h>
@@ -71,7 +72,7 @@ static unsigned char best_table_len[256];
7172
static void usage(void)
7273
{
7374
fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] "
74-
"[--base-relative] < in.map > out.S\n");
75+
"[--base-relative] in.map > out.S\n");
7576
exit(1);
7677
}
7778

@@ -310,12 +311,19 @@ static void shrink_table(void)
310311
}
311312
}
312313

313-
static void read_map(FILE *in)
314+
static void read_map(const char *in)
314315
{
316+
FILE *fp;
315317
struct sym_entry *sym;
316318

317-
while (!feof(in)) {
318-
sym = read_symbol(in);
319+
fp = fopen(in, "r");
320+
if (!fp) {
321+
perror(in);
322+
exit(1);
323+
}
324+
325+
while (!feof(fp)) {
326+
sym = read_symbol(fp);
319327
if (!sym)
320328
continue;
321329

@@ -326,12 +334,15 @@ static void read_map(FILE *in)
326334
table = realloc(table, sizeof(*table) * table_size);
327335
if (!table) {
328336
fprintf(stderr, "out of memory\n");
337+
fclose(fp);
329338
exit (1);
330339
}
331340
}
332341

333342
table[table_cnt++] = sym;
334343
}
344+
345+
fclose(fp);
335346
}
336347

337348
static void output_label(const char *label)
@@ -762,22 +773,26 @@ static void record_relative_base(void)
762773

763774
int main(int argc, char **argv)
764775
{
765-
if (argc >= 2) {
766-
int i;
767-
for (i = 1; i < argc; i++) {
768-
if(strcmp(argv[i], "--all-symbols") == 0)
769-
all_symbols = 1;
770-
else if (strcmp(argv[i], "--absolute-percpu") == 0)
771-
absolute_percpu = 1;
772-
else if (strcmp(argv[i], "--base-relative") == 0)
773-
base_relative = 1;
774-
else
775-
usage();
776-
}
777-
} else if (argc != 1)
776+
while (1) {
777+
static struct option long_options[] = {
778+
{"all-symbols", no_argument, &all_symbols, 1},
779+
{"absolute-percpu", no_argument, &absolute_percpu, 1},
780+
{"base-relative", no_argument, &base_relative, 1},
781+
{},
782+
};
783+
784+
int c = getopt_long(argc, argv, "", long_options, NULL);
785+
786+
if (c == -1)
787+
break;
788+
if (c != 0)
789+
usage();
790+
}
791+
792+
if (optind >= argc)
778793
usage();
779794

780-
read_map(stdin);
795+
read_map(argv[optind]);
781796
shrink_table();
782797
if (absolute_percpu)
783798
make_percpus_absolute();

scripts/link-vmlinux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ kallsyms()
157157
fi
158158

159159
info KSYMS ${2}
160-
cat ${1} | scripts/kallsyms ${kallsymopt} > ${2}
160+
scripts/kallsyms ${kallsymopt} ${1} > ${2}
161161
}
162162

163163
# Perform one step in kallsyms generation, including temporary linking of

0 commit comments

Comments
 (0)