annotate leo-obj/tool/symtab.c @ 130:87b82398a08b

leo-obj project subtree started, tiobjd tool moved into it
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 06 Apr 2014 22:14:39 +0000
parents ticoff/symtab.c@fb1e47bebe00
children ed533d469838
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Code for working with the symbol table
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
79
8f4996bff904 tiobjd: profile operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 78
diff changeset
7 #include <stdlib.h>
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include "filestruct.h"
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include "intstruct.h"
78
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
10 #include "coffconst.h"
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "globals.h"
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
78
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
13 static struct classmap {
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
14 int code;
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
15 char *str;
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
16 } classtab[] = {
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
17 {C_NULL, "NULL"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
18 {C_AUTO, "AUTO"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
19 {C_EXT, "EXT"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
20 {C_STAT, "STAT"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
21 {C_REG, "REG"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
22 {C_EXTREF, "EXTREF"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
23 {C_LABEL, "LABEL"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
24 {C_ULABEL, "ULABEL"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
25 {C_MOS, "MOS"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
26 {C_ARG, "ARG"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
27 {C_STRTAG, "STRTAG"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
28 {C_MOU, "MOU"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
29 {C_UNTAG, "UNTAG"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
30 {C_TPDEF, "TPDEF"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
31 {C_USTATIC, "USTATIC"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
32 {C_ENTAG, "ENTAG"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
33 {C_MOE, "MOE"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
34 {C_REGPARM, "REGPARM"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
35 {C_FIELD, "FIELD"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
36 {C_UEXT, "UEXT"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
37 {C_STATLAB, "STATLAB"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
38 {C_EXTLAB, "EXTLAB"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
39 {C_SYSTEM, "SYSTEM"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
40 {C_VARARG, "VARARG"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
41 {C_BLOCK, "BLOCK"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
42 {C_FCN, "FCN"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
43 {C_EOS, "EOS"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
44 {C_FILE, "FILE"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
45 {C_LINE, "LINE"},
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
46 {0, 0}
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
47 };
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
48
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
49 char *
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
50 storage_class_to_string(code, numbuf)
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
51 char *numbuf;
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
52 {
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
53 struct classmap *tp;
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
54
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
55 for (tp = classtab; tp->str; tp++)
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
56 if (tp->code == code)
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
57 return(tp->str);
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
58 sprintf(numbuf, "%d", code);
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
59 return(numbuf);
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
60 }
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
61
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 dump_symtab()
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 {
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 unsigned n;
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 struct internal_syment *sym;
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 char *sec, secstr[8];
78
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
67 char *class, classbuf[8];
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68
78
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
69 printf("%-5s %-30s %-4s %-7s %-12s %-8s\n",
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 "Num", "Name", "Type", "Class", "Section", "Value");
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 for (n = 0; n < nsymtab; n++) {
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 sym = symtab[n];
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (!sym)
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 continue;
80
da103b9377e3 tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 79
diff changeset
75 if (sym->section)
da103b9377e3 tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 79
diff changeset
76 sec = sym->section->name;
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 else {
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 sprintf(secstr, "%d", sym->scnum);
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 sec = secstr;
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 }
78
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
81 class = storage_class_to_string(sym->class, classbuf);
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
82 printf("%-5u %-30s %04X %-7s %-12s %08X%s\n",
c2445afce514 tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 77
diff changeset
83 n, sym->name, sym->type, class,
77
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 sec, sym->value, sym->aux ? " Aux" : "");
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 }
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 return(0);
590396e27e96 tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 }
79
8f4996bff904 tiobjd: profile operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 78
diff changeset
88
81
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
89 static void
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
90 initial_fill_for_sort(sec)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
91 struct internal_scnhdr *sec;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
92 {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
93 unsigned n, m;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
94 struct internal_syment *sym;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
95
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
96 m = 0;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
97 for (n = 0; n < nsymtab; n++) {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
98 sym = symtab[n];
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
99 if (!sym)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
100 continue;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
101 if (sym->section != sec)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
102 continue;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
103 sec->sorted_symbols[m++] = sym;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
104 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
105 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
106
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
107 static int
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
108 compare_for_sort(p1, p2)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
109 struct internal_syment **p1, **p2;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
110 {
116
5f4141ee175b tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
111 /* sort by value first */
81
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
112 if ((*p1)->value < (*p2)->value)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
113 return(-1);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
114 if ((*p1)->value > (*p2)->value)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
115 return(1);
116
5f4141ee175b tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
116 /* if same value, retain the original symtab order */
5f4141ee175b tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
117 if ((*p1)->number < (*p2)->number)
5f4141ee175b tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
118 return(-1);
5f4141ee175b tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
119 if ((*p1)->number > (*p2)->number)
5f4141ee175b tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 81
diff changeset
120 return(1);
81
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
121 else
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
122 return(0);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
123 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
124
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
125 void
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
126 sort_symbols_of_sec(sec)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
127 struct internal_scnhdr *sec;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
128 {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
129 if (sec->sorted_symbols)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
130 return;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
131 if (!sec->nsymbols) {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
132 fprintf(stderr,
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
133 "BUG: sort_symbols_of_sec() called for section \"%s\" w/o symbols\n",
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
134 sec->name);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
135 exit(1);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
136 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
137 sec->sorted_symbols = malloc(sizeof(void *) * sec->nsymbols);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
138 if (!sec->sorted_symbols) {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
139 perror("malloc");
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
140 exit(1);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
141 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
142 initial_fill_for_sort(sec);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
143 qsort(sec->sorted_symbols, sec->nsymbols, sizeof(void *),
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
144 compare_for_sort);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
145 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
146
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
147 void
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
148 sort_symbols_of_all_sec()
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
149 {
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
150 unsigned n;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
151 struct internal_scnhdr *sec;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
152
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
153 for (n = 0; n < nsections; n++) {
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
154 sec = sections + n;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
155 if (!sec->nsymbols)
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
156 continue;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
157 sort_symbols_of_sec(sec);
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
158 }
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
159 }
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 116
diff changeset
160
81
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
161 cmd_nm()
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
162 {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
163 unsigned n, m;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
164 struct internal_scnhdr *sec;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
165 struct internal_syment *sym;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
166 char classbuf[8];
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
167
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
168 get_int_section_table();
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
169 get_int_symbol_table();
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
170 for (n = 0; n < nsections; n++) {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
171 sec = sections + n;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
172 if (!sec->nsymbols)
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
173 continue;
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
174 printf("%s:\n\n", sec->name);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
175 sort_symbols_of_sec(sec);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
176 for (m = 0; m < sec->nsymbols; m++) {
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
177 sym = sec->sorted_symbols[m];
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
178 printf("%08X %-7s %s\n", sym->value,
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
179 storage_class_to_string(sym->class, classbuf),
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
180 sym->name);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
181 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
182 putchar('\n');
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
183 }
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
184 exit(0);
192da19c7506 tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 80
diff changeset
185 }