1#include <ctype.h>2#include <stdio.h>3#include <string.h>45#include <scc/mach.h>6#include <scc/coff32.h>78#include "../libmach.h"9#include "fun.h"1011static int12gettype(Coff32 *coff, SYMENT *ent)13{14 int c;15 SCNHDR *scn;1617 switch (ent->n_scnum) {18 case N_DEBUG:19 c = 'N';20 break;21 case N_ABS:22 c = 'a';23 break;24 case N_UNDEF:25 c = (ent->n_value != 0) ? 'C' : 'U';26 break;27 default:28 scn = &coff->scns[ent->n_scnum-1];2930 switch (scn->s_flags) {31 case STYP_TEXT:32 c = 't';33 break;34 case STYP_DATA:35 c = 'd';36 break;37 case STYP_BSS:38 c = 'b';39 break;40 case STYP_INFO:41 c = 'N';42 break;43 case STYP_LIT:44 c = 'r';45 break;46 default:47 c = '?';48 break;49 }50 }5152 if (ent->n_sclass == C_EXT)53 c = toupper(c);5455 return c;56}5758Symbol *59coff32getsym(Obj *obj, int *idx, Symbol *sym)60{61 int n = *idx;62 Entry *ep;63 SYMENT *ent;64 Coff32 *coff = obj->data;65 FILHDR *hdr = &coff->hdr;6667 if ((hdr->f_flags & F_LSYMS) != 0 || n >= coff->hdr.f_nsyms)68 return NULL;6970 ep = &coff->ents[n];71 if (ep->type != SYM_ENT)72 return NULL;73 ent = &ep->u.sym;7475 sym->name = coff32str(coff, ent);76 sym->type = gettype(coff, ent);77 sym->stype = SYMOBJECT;78 sym->value = ent->n_value;79 sym->size = (sym->type == 'C') ? ent->n_value : 0;80 sym->index = n;81 *idx += ent->n_numaux;8283 return sym;84}