|
|
1.1 ! root 1: /* ! 2: * init the symbol table ! 3: * symbol values in vax order?? ! 4: */ ! 5: ! 6: #include "defs.h" ! 7: #include "sym.h" ! 8: #include "a.out.h" ! 9: #include <sys/types.h> ! 10: ! 11: #define NSYMS 300 ! 12: #define BIGBUF (4*4096) ! 13: ! 14: extern struct sym *symtab; ! 15: ! 16: syminit(h) ! 17: struct exec *h; ! 18: { ! 19: register struct nlist *q; ! 20: register n, m; ! 21: struct nlist space[BIGBUF/sizeof(struct nlist)]; ! 22: struct sym *sbuf; ! 23: register struct sym *cur; ! 24: struct sym *curgbl; ! 25: register int type, ltype; ! 26: off_t off; ! 27: char *malloc(); ! 28: char *savename(); ! 29: ! 30: symtab = NULL; ! 31: if (h->a_syms == 0) ! 32: return; /* stripped */ ! 33: off = h->a_text + h->a_data; ! 34: if ((h->a_flag & 01) == 0) ! 35: off += off; /* space for reloc data */ ! 36: lseek(fsym, off + sizeof(*h), 0); ! 37: curgbl = sbuf = cur = NULL; ! 38: for (n = h->a_syms; n > 0 ;) { ! 39: m = read(fsym, (char *)space, min(n, sizeof(space))); ! 40: if (m <= 0) ! 41: break; ! 42: n -= m; ! 43: for (q = space; m > 0; q++, m-= sizeof(space[0])) { ! 44: switch (q->n_type) { ! 45: case N_ABS|N_EXT: ! 46: type = S_ABS; ! 47: break; ! 48: ! 49: case N_TEXT: ! 50: case N_TEXT|N_EXT: ! 51: type = S_TEXT; ! 52: break; ! 53: ! 54: case N_DATA: ! 55: case N_BSS: /* ?? file statics ?? */ ! 56: case N_DATA|N_EXT: ! 57: case N_BSS|N_EXT: ! 58: type = S_DATA; ! 59: break; ! 60: ! 61: case N_ABS: ! 62: ltype = S_LSYM; ! 63: type = S_STAB; ! 64: break; ! 65: ! 66: default: ! 67: continue; ! 68: } ! 69: if (sbuf == NULL || ++cur >= sbuf + NSYMS) { ! 70: if ((sbuf = (struct sym *)malloc(sizeof(struct sym) * NSYMS)) == NULL) { ! 71: printf("out of mem for syms\n"); ! 72: return; ! 73: } ! 74: cur = sbuf; ! 75: } ! 76: cur->y_type = type; ! 77: cur->y_ltype = ltype; ! 78: cur->y_value = q->n_value; ! 79: cur->y_name = savename(q->n_name, sizeof(q->n_name)); ! 80: cur->y_locals = NULL; ! 81: if (cur->y_type == S_TEXT && q->n_name[0] == '~') { ! 82: cur->y_next = curgbl; ! 83: curgbl = cur; ! 84: } ! 85: else if (cur->y_type == S_STAB) { ! 86: if (curgbl == NULL) ! 87: continue; ! 88: cur->y_next = curgbl->y_locals; ! 89: curgbl->y_locals = cur; ! 90: } ! 91: else { ! 92: cur->y_next = symtab; ! 93: symtab = cur; ! 94: } ! 95: } ! 96: } ! 97: for (; curgbl; curgbl = curgbl->y_next) { ! 98: if (curgbl->y_locals == NULL) ! 99: continue; ! 100: for (cur = symtab; cur; cur = cur->y_next) { ! 101: if (cur->y_type != S_TEXT) ! 102: continue; ! 103: if (cur->y_value == curgbl->y_value) { ! 104: cur->y_locals = curgbl->y_locals; ! 105: break; ! 106: } ! 107: } ! 108: } ! 109: } ! 110: ! 111: static char * ! 112: savename(n, sz) ! 113: char *n; ! 114: register int sz; ! 115: { ! 116: char *p; ! 117: char *malloc(); ! 118: ! 119: if ((p = malloc(sz+1)) == NULL) ! 120: return (""); ! 121: strncpy(p, n, sz); ! 122: p[sz] = 0; ! 123: return (p); ! 124: } ! 125: ! 126: eqsym(sp, n) ! 127: struct sym *sp; ! 128: char *n; ! 129: { ! 130: ! 131: return (strcmp(sp->y_name, n) == 0); ! 132: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.