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