Annotation of researchv10no/cmd/adb/68v/syminit.c, revision 1.1.1.1

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: long           A6base;
                     15: 
                     16: syminit(h)
                     17: struct exec *h;
                     18: {
                     19:        register Sym *q;
                     20:        register n, m;
                     21:        Sym space[BIGBUF/sizeof(Sym)];
                     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 = swal(h->a_text) + swal(h->a_data);
                     34: #if NOTDEF
                     35:        if ((swal(h->a_flag) & 01) == 0)
                     36:                off += off;     /* space for reloc data */
                     37: #endif
                     38:        lseek(fsym, off + sizeof(*h), 0);
                     39:        curgbl = sbuf = cur = NULL;
                     40:        for (n = swal(h->a_syms); n > 0 ;) {
                     41:                m = read(fsym, (char *)space, min(n, sizeof(space)));
                     42:                if (m <= 0)
                     43:                        break;
                     44:                n -= m;
                     45:                for (q = space; m > 0; q++, m-= sizeof(space[0])) {
                     46:                        switch (q->type) {
                     47:                        case 'T':
                     48:                        case 't':
                     49:                                type = S_TEXT;
                     50:                                break;
                     51: 
                     52:                        case 'D':
                     53:                        case 'd':
                     54:                        case 'B':
                     55:                        case 'b':
                     56:                                type = S_DATA;
                     57:                                break;
                     58: 
                     59:                        default:
                     60:                                continue;
                     61:                        }
                     62:                        if (sbuf == NULL || ++cur >= sbuf + NSYMS) {
                     63:                                if ((sbuf = (struct sym *)malloc(sizeof(struct sym) * NSYMS)) == NULL) {
                     64:                                        printf("out of mem for syms\n");
                     65:                                        return;
                     66:                                }
                     67:                                cur = sbuf;
                     68:                        }
                     69:                        cur->y_type = type;
                     70:                        cur->y_ltype = ltype;
                     71:                        cur->y_value = swal(q->value);
                     72:                        cur->y_name = savename(q->name, sizeof(q->name));
                     73:                        if (strcmp(cur->y_name, "a6base") == 0)
                     74:                                A6base = swal(q->value);
                     75:                        cur->y_locals = NULL;
                     76:                        if (cur->y_type == S_TEXT && q->name[0] == '~') {
                     77:                                cur->y_next = curgbl;
                     78:                                curgbl = cur;
                     79:                        }
                     80:                        else if (cur->y_type == S_STAB) {
                     81:                                if (curgbl == NULL)
                     82:                                        continue;
                     83:                                cur->y_next = curgbl->y_locals;
                     84:                                curgbl->y_locals = cur;
                     85:                        }
                     86:                        else {
                     87:                                cur->y_next = symtab;
                     88:                                symtab = cur;
                     89:                        }
                     90:                }
                     91:        }
                     92:        for (; curgbl; curgbl = curgbl->y_next) {
                     93:                if (curgbl->y_locals == NULL)
                     94:                        continue;
                     95:                for (cur = symtab; cur; cur = cur->y_next) {
                     96:                        if (cur->y_type != S_TEXT)
                     97:                                continue;
                     98:                        if (cur->y_value == curgbl->y_value) {
                     99:                                cur->y_locals = curgbl->y_locals;
                    100:                                break;
                    101:                        }
                    102:                }
                    103:        }
                    104: }
                    105: 
                    106: static char *
                    107: savename(n, sz)
                    108: char *n;
                    109: register int sz;
                    110: {
                    111:        char *p;
                    112:        char *malloc();
                    113: 
                    114:        if ((p = malloc(sz+1)) == NULL)
                    115:                return ("");
                    116:        strncpy(p, n, sz);
                    117:        p[sz] = 0;
                    118:        return (p);
                    119: }
                    120: 
                    121: eqsym(sp, n)
                    122: struct sym *sp;
                    123: char *n;
                    124: {
                    125: 
                    126:        return (strncmp(sp->y_name, n, NNAME) == 0);
                    127: }
                    128: 
                    129: min(a, b)
                    130: {
                    131:        if (a < b)
                    132:                return (a);
                    133:        else
                    134:                return (b);
                    135: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.