Annotation of researchv10no/cmd/adb/68v/Xsyminit.c, revision 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: 
        !            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 = swal(h->a_text) + swal(h->a_data);
        !            33:        if ((swal(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 = swal(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_ABS:
        !            61:                                ltype = S_LSYM;
        !            62:                                type = S_STAB;
        !            63:                                break;
        !            64: 
        !            65:                        default:
        !            66:                                continue;
        !            67:                        }
        !            68:                        if (sbuf == NULL || ++cur >= sbuf + NSYMS) {
        !            69:                                if ((sbuf = (struct sym *)malloc(sizeof(struct sym) * NSYMS)) == NULL) {
        !            70:                                        printf("out of mem for syms\n");
        !            71:                                        return;
        !            72:                                }
        !            73:                                cur = sbuf;
        !            74:                        }
        !            75:                        cur->y_type = type;
        !            76:                        cur->y_ltype = ltype;
        !            77:                        cur->y_value = swal(q->n_value);
        !            78:                        cur->y_name = savename(q->n_name, sizeof(q->n_name));
        !            79:                        cur->y_locals = NULL;
        !            80:                        if (cur->y_type == S_TEXT && q->n_name[0] == '~') {
        !            81:                                cur->y_next = curgbl;
        !            82:                                curgbl = cur;
        !            83:                        }
        !            84:                        else if (cur->y_type == S_STAB) {
        !            85:                                if (curgbl == NULL)
        !            86:                                        continue;
        !            87:                                cur->y_next = curgbl->y_locals;
        !            88:                                curgbl->y_locals = cur;
        !            89:                        }
        !            90:                        else {
        !            91:                                cur->y_next = symtab;
        !            92:                                symtab = cur;
        !            93:                        }
        !            94:                }
        !            95:        }
        !            96:        for (; curgbl; curgbl = curgbl->y_next) {
        !            97:                if (curgbl->y_locals == NULL)
        !            98:                        continue;
        !            99:                for (cur = symtab; cur; cur = cur->y_next) {
        !           100:                        if (cur->y_type != S_TEXT)
        !           101:                                continue;
        !           102:                        if (cur->y_value == curgbl->y_value) {
        !           103:                                cur->y_locals = curgbl->y_locals;
        !           104:                                break;
        !           105:                        }
        !           106:                }
        !           107:        }
        !           108: }
        !           109: 
        !           110: static char *
        !           111: savename(n, sz)
        !           112: char *n;
        !           113: register int sz;
        !           114: {
        !           115:        char *p;
        !           116:        char *malloc();
        !           117: 
        !           118:        if ((p = malloc(sz+1)) == NULL)
        !           119:                return ("");
        !           120:        strncpy(p, n, sz);
        !           121:        p[sz] = 0;
        !           122:        return (p);
        !           123: }
        !           124: 
        !           125: eqsym(sp, n)
        !           126: struct sym *sp;
        !           127: char *n;
        !           128: {
        !           129: 
        !           130:        return (strncmp(sp->y_name, n, 16) == 0);
        !           131: }
        !           132: 
        !           133: min(a, b)
        !           134: {
        !           135:        if (a < b)
        !           136:                return (a);
        !           137:        else
        !           138:                return (b);
        !           139: }

unix.superglobalmegacorp.com

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