FreeCalypso > hg > freecalypso-reveng
annotate objgrep/frontend.c @ 327:b5b8df53aa51
frbl/reconst/command.c: missing break in switch case
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 06 Mar 2020 04:10:21 +0000 |
parents | 928ed52930aa |
children |
rev | line source |
---|---|
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This program is a front-end to objgrep. It takes an ASCII text file as |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * input that lists the modules and sections to be grepped for, and it |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * invokes objgrep via popen() for each listed section, all on the same |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 * unknown binary. We collect the symbol addresses printed by objgrep |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 * via our pipe, and then we sort them to produce the final report. |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 */ |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdio.h> |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdlib.h> |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <ctype.h> |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <string.h> |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include <strings.h> |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include <unistd.h> |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 #define RAM_BOUNDARY 0x800000 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 #define SYMFLAG_AMBIG 8 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 #define SYMSRC_TEXTMATCH 4 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 #define SYMSRC_EXTRELOC 2 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 #define SYMSRC_INTRELOC 1 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 struct symbol { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 char *name; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 unsigned value; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 int flags; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 struct symbol *next; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 }; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 struct symbol *flash_symbols, *ram_symbols; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 unsigned num_flash_symbols, num_ram_symbols; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 char *binfilename; |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
33 int verbose; |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 enter_symbol(name, valstr, symsrc) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 char *name, *valstr; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 struct symbol *newsym; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 newsym = malloc(sizeof(struct symbol) + strlen(name) + 1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (!newsym) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 perror("malloc"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 exit(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 newsym->name = (char *)(newsym + 1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 strcpy(newsym->name, name); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 newsym->value = strtoul(valstr, 0, 16); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 newsym->flags = symsrc; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 if (newsym->value < RAM_BOUNDARY) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 newsym->next = flash_symbols; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 flash_symbols = newsym; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 num_flash_symbols++; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } else { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 newsym->next = ram_symbols; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 ram_symbols = newsym; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 num_ram_symbols++; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 process_section(objfile, secname) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 char *objfile, *secname; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 char cmdline[1024], linebuf[512], *cp, *fields[3]; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 FILE *f; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 int symsrc, i; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 static char headline_textmatch[] = "This source section's symbols:"; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 static char headline_extreloc[] = "Externals deduced from relocs:"; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 static char headline_intreloc[] = |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 "This module's symbols deduced from section relocs:"; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 sprintf(cmdline, "objgrep -rs %s %s %s", objfile, secname, binfilename); |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
72 if (verbose) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
73 printf("Running %s\n", cmdline); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 f = popen(cmdline, "r"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 if (!f) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 perror("popen"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 exit(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 symsrc = 0; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 while (fgets(linebuf, sizeof linebuf, f)) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 cp = index(linebuf, '\n'); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 if (!cp) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 fprintf(stderr, |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 "error: objgrep output line has no terminating newline\n"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 exit(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 *cp = '\0'; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 if (!strcmp(linebuf, headline_textmatch)) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 symsrc = SYMSRC_TEXTMATCH; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 if (!strcmp(linebuf, headline_extreloc)) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 symsrc = SYMSRC_EXTRELOC; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 if (!strcmp(linebuf, headline_intreloc)) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 symsrc = SYMSRC_INTRELOC; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 cp = linebuf; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 for (i = 0; ; i++) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 while (isspace(*cp)) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 cp++; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 if (!*cp) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 break; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 if (i == 3) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 i++; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 break; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 for (fields[i] = cp; *cp && !isspace(*cp); cp++) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 ; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 if (*cp) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 *cp++ = '\0'; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 if (i != 3) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 if (fields[1][0] != '=' || fields[1][1]) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 if (!symsrc) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 fprintf(stderr, |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 "error: symbol output from objgrep w/o source indication\n"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 exit(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 enter_symbol(fields[0], fields[2], symsrc); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 pclose(f); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 process_list_file(listfilename) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 char *listfilename; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 FILE *f; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 char linebuf[512], *objname, *cp, *np; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 int lineno; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 f = fopen(listfilename, "r"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 if (!f) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 perror(listfilename); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 exit(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 for (cp = linebuf; isspace(*cp); cp++) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 ; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 if (*cp == '\0' || *cp == '#') |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 for (objname = cp; *cp && !isspace(*cp); cp++) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 ; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 if (*cp) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 *cp++ = '\0'; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 while (isspace(*cp)) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 cp++; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 if (*cp == '\0' || *cp == '#') { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 process_section(objname, ".text"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 while (*cp && *cp != '#') { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 for (np = cp; *cp && !isspace(*cp); cp++) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 ; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 if (*cp) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 *cp++ = '\0'; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 process_section(objname, np); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 while (isspace(*cp)) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 cp++; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 fclose(f); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 sort_by_value(sym1, sym2) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 struct symbol **sym1, **sym2; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 if ((*sym1)->value < (*sym2)->value) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 return(-1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
174 if ((*sym1)->value > (*sym2)->value) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
175 return(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 return(0); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 sort_by_name(sym1, sym2) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 struct symbol **sym1, **sym2; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 int i; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 i = strcmp((*sym1)->name, (*sym2)->name); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 if (i) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 return i; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 else |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 return sort_by_value(sym1, sym2); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 fill_input_array(head, buf) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 struct symbol *head, **buf; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 struct symbol *sym, **p; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 p = buf; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 for (sym = head; sym; sym = sym->next) |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
198 *p++ = sym; |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 unsigned |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 dedup_symbols(inbuf, outbuf, total) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 struct symbol **inbuf, **outbuf; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
204 unsigned total; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
205 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
206 struct symbol **ip, **op, **input_end, *nsym; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 op = outbuf; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 input_end = inbuf + total; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 for (ip = inbuf; ip < input_end; ip++) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 nsym = *ip; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 if (op == outbuf || strcmp(nsym->name, op[-1]->name)) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 *op++ = nsym; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
215 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
216 if (nsym->value == op[-1]->value) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
217 op[-1]->flags |= nsym->flags; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
218 continue; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
219 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
220 op[-1]->flags |= SYMFLAG_AMBIG; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
221 nsym->flags |= SYMFLAG_AMBIG; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
222 *op++ = nsym; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
223 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
224 return(op - outbuf); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
225 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
226 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
227 emit_final_symbols(buf, total) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
228 struct symbol **buf; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
229 unsigned total; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
230 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
231 struct symbol **p, **endbuf, *sym; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
232 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
233 endbuf = buf + total; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
234 for (p = buf; p < endbuf; p++) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
235 sym = *p; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
236 printf("%08X %s (", sym->value, sym->name); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
237 if (sym->flags & SYMSRC_TEXTMATCH) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
238 putchar('S'); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
239 if (sym->flags & SYMSRC_EXTRELOC) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
240 putchar('R'); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
241 if (sym->flags & SYMSRC_INTRELOC) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
242 putchar('r'); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
243 if (sym->flags & SYMFLAG_AMBIG) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
244 fputs(", ambiguous", stdout); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
245 putchar(')'); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
246 putchar('\n'); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
247 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
248 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
249 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
250 sort_and_emit_symbols(head, total) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
251 struct symbol *head; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
252 unsigned total; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
253 { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
254 struct symbol **input, **output; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
255 unsigned final_count; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
256 |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
257 if (verbose) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
258 printf("Total symbols to process: %u\n", total); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
259 input = malloc(sizeof(void *) * total); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
260 if (!input) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
261 perror("malloc"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
262 exit(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
263 } |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
264 if (verbose) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
265 printf("Turning linked list into linear array\n"); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
266 fill_input_array(head, input); |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
267 if (verbose) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
268 printf("Sorting by name\n"); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
269 qsort(input, total, sizeof(void *), sort_by_name); |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
270 if (verbose) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
271 printf("Allocating output array\n"); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
272 output = malloc(sizeof(void *) * total); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
273 if (!output) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
274 perror("malloc"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
275 exit(1); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
276 } |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
277 if (verbose) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
278 printf("Processing duplicates\n"); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
279 final_count = dedup_symbols(input, output, total); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
280 free(input); |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
281 if (verbose) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
282 printf("%u symbols left, sorting by value\n", final_count); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
283 qsort(output, final_count, sizeof(void *), sort_by_value); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
284 emit_final_symbols(output, final_count); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
285 free(output); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
286 putchar('\n'); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
287 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
288 |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
289 main(argc, argv) |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
290 char **argv; |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
291 { |
175
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
292 int c; |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
293 extern int optind; |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
294 |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
295 while ((c = getopt(argc, argv, "v")) != EOF) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
296 switch (c) { |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
297 case 'v': |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
298 verbose++; |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
299 continue; |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
300 default: |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
301 usage: |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
302 fprintf(stderr, "usage: %s [-v] listfile binfile\n", |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
303 argv[0]); |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
304 exit(1); |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
305 } |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
306 if (argc - optind != 2) |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
307 goto usage; |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
308 |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
309 binfilename = argv[optind+1]; |
928ed52930aa
objgrep-fe: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
310 process_list_file(argv[optind]); |
174
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
311 if (flash_symbols) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
312 printf("Flash symbols:\n\n"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
313 sort_and_emit_symbols(flash_symbols, num_flash_symbols); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
314 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
315 if (ram_symbols) { |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
316 printf("RAM symbols:\n\n"); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
317 sort_and_emit_symbols(ram_symbols, num_ram_symbols); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
318 } |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
319 exit(0); |
10c0cdc18208
objgrep-fe written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
320 } |