comparison ticoff/tables.c @ 73:10f3fbff5e97

tiobjd: symbol table parsing implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 25 Mar 2014 18:34:03 +0000
parents c15cd3d695c0
children 2eef88395908
comparison
equal deleted inserted replaced
72:2bec477178fc 73:10f3fbff5e97
91 printf("\t%u reloc, %u line entries\n", 91 printf("\t%u reloc, %u line entries\n",
92 inf->nreloc, inf->nlineent); 92 inf->nreloc, inf->nlineent);
93 } 93 }
94 exit(0); 94 exit(0);
95 } 95 }
96
97 get_int_symbol_table()
98 {
99 unsigned n;
100 struct internal_syment *in;
101
102 symtab = malloc(sizeof(struct internal_syment *) * nsymtab);
103 if (!symtab) {
104 perror("malloc");
105 exit(1);
106 }
107 for (n = 0; n < nsymtab; ) {
108 in = malloc(sizeof(struct internal_syment));
109 if (!in) {
110 perror("malloc");
111 exit(1);
112 }
113 symtab[n] = in;
114 in->name = get_secorsym_name(symtab_raw[n].e_name);
115 in->value = get_u32(symtab_raw[n].e_value);
116 in->scnum = get_s16(symtab_raw[n].e_scnum);
117 if (in->scnum < -2 || in->scnum > nsections) {
118 fprintf(stderr,
119 "symtab entry #%u: scnum out of range\n", n);
120 exit(1);
121 }
122 in->type = get_u16(symtab_raw[n].e_type);
123 in->class = symtab_raw[n].e_sclass;
124 switch (symtab_raw[n++].e_numaux) {
125 case 0:
126 in->aux = 0;
127 continue;
128 case 1:
129 if (n >= nsymtab) {
130 fprintf(stderr,
131 "error: last symbol's aux spills over\n");
132 exit(1);
133 }
134 symtab[n] = 0;
135 in->aux = (u_char *)(symtab_raw + n);
136 n++;
137 continue;
138 default:
139 n--;
140 fprintf(stderr, "symtab entry #%u: invalid numaux\n",
141 n);
142 exit(1);
143 }
144 }
145 }