scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

 1#include <ctype.h>
 2#include <stdio.h>
 3#include <string.h>
 4
 5#include <scc/mach.h>
 6#include <scc/coff32.h>
 7
 8#include "../libmach.h"
 9#include "fun.h"
10
11static int
12gettype(Coff32 *coff, SYMENT *ent)
13{
14	int c;
15	SCNHDR *scn;
16
17	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];
29
30		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	}
51
52	if (ent->n_sclass == C_EXT)
53		c = toupper(c);
54
55	return c;
56}
57
58Symbol *
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;
66
67	if ((hdr->f_flags & F_LSYMS) != 0 || n >= coff->hdr.f_nsyms)
68		return NULL;
69
70	ep = &coff->ents[n];
71	if (ep->type != SYM_ENT)
72		return NULL;
73	ent = &ep->u.sym;
74
75	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;
82
83	return sym;
84}