]> Cypherpunks repositories - gostls13.git/commitdiff
symbol bugs.
authorRuss Cox <rsc@golang.org>
Fri, 21 Aug 2009 00:33:28 +0000 (17:33 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 21 Aug 2009 00:33:28 +0000 (17:33 -0700)
do not emit unreachable data symbols.

R=austin
DELTA=103  (71 added, 4 deleted, 28 changed)
OCL=33325
CL=33622

16 files changed:
src/cmd/6g/gsubr.c
src/cmd/6g/reg.c
src/cmd/6l/asm.c
src/cmd/6l/list.c
src/cmd/6l/obj.c
src/cmd/6l/pass.c
src/cmd/6l/span.c
src/cmd/8g/gsubr.c
src/cmd/8l/asm.c
src/cmd/8l/list.c
src/cmd/8l/obj.c
src/cmd/8l/pass.c
src/cmd/8l/span.c
src/cmd/gc/go.h
src/cmd/gc/subr.c
src/cmd/ld/go.c

index aec4cb1bd39e93858d5a4bf0dcf6c6166817b992..e2fdceff48877f1e523a3249aeee2b7e3e293ec5 100644 (file)
@@ -939,9 +939,7 @@ naddr(Node *n, Addr *a)
                if(n->type != T) {
                        a->etype = simtype[n->type->etype];
                        a->width = n->type->width;
-                       if(n->sym != S && strncmp(n->sym->name, "autotmp_", 8) != 0)
-                       if(n->type->etype != TFUNC || n->type->thistuple == 0)
-                               a->gotype = typename(n->type)->left->sym;
+                       a->gotype = ngotype(n);
                }
                a->offset = n->xoffset;
                a->sym = n->sym;
index 4f7ce069fe4027f0a2f64fda20232c65dffa13b7..d017c62ab3a827b0f4f0a384ffe33273c911b0d5 100644 (file)
@@ -682,6 +682,7 @@ addmove(Reg *r, int bn, int rn, int f)
        a->offset = v->offset;
        a->etype = v->etype;
        a->type = v->name;
+       a->gotype = v->gotype;
 
        // need to clean this up with wptr and
        // some of the defaults
@@ -869,6 +870,7 @@ mkvar(Reg *r, Adr *a)
        v->sym = s;
        v->offset = o;
        v->name = n;
+       v->gotype = a->gotype;
        v->etype = et;
        v->width = w;
        if(debug['R'])
index 5acaaae5f1d392f09f1d3d6dafa7dfce785cd73f..fb0f361de77f1dc54d68abab80527602731a5e08 100644 (file)
@@ -738,6 +738,8 @@ datblk(int32 s, int32 n)
        memset(buf.dbuf, 0, n+Dbufslop);
        for(p = datap; p != P; p = p->link) {
                curp = p;
+               if(!p->from.sym->reachable)
+                       sysfatal("unreachable symbol in datblk - %s", p->from.sym->name);
                l = p->from.sym->value + p->from.offset - s;
                c = p->from.scale;
                i = 0;
index 000c6fa3783f53a4ff01c8a157428522d68b70a4..2acd36e67b9df4c969b77e9368f01bd654940d8e 100644 (file)
@@ -207,7 +207,11 @@ brk:
                strcat(str, s);
        }
 conv:
-       return fmtstrcpy(fp, str);
+       fmtstrcpy(fp, str);
+       if(a->gotype)
+               fmtprint(fp, "«%s»", a->gotype->name);
+       return 0;
+
 }
 
 char*  regstr[] =
index 98318d94b15ff3fb2e31dbd13397afbc911c11c0..1deee18f595b9ff46a96286dc808cef79e13e61a 100644 (file)
@@ -504,7 +504,7 @@ objfile(char *file)
         */
        Bseek(f, off, 0);
        cnt = esym - off;
-       start = malloc(cnt + 10);
+       start = mal(cnt + 10);
        cnt = Bread(f, start, cnt);
        if(cnt <= 0){
                Bterm(f);
@@ -713,10 +713,10 @@ addlib(char *src, char *obj)
                return;
        }
 
-       p = malloc(strlen(name) + 1);
+       p = mal(strlen(name) + 1);
        strcpy(p, name);
        library[libraryp] = p;
-       p = malloc(strlen(obj) + 1);
+       p = mal(strlen(obj) + 1);
        strcpy(p, obj);
        libraryobj[libraryp] = p;
        libraryp++;
@@ -745,9 +745,9 @@ addhist(int32 line, int type)
        Sym *s;
        int i, j, k;
 
-       u = malloc(sizeof(Auto));
-       s = malloc(sizeof(Sym));
-       s->name = malloc(2*(histfrogp+1) + 1);
+       u = mal(sizeof(Auto));
+       s = mal(sizeof(Sym));
+       s->name = mal(2*(histfrogp+1) + 1);
 
        u->asym = s;
        u->type = type;
@@ -1267,7 +1267,7 @@ lookup(char *symb, int v)
        if(debug['v'] > 1)
                Bprint(&bso, "lookup %s\n", symb);
 
-       s->name = malloc(l + 1);
+       s->name = mal(l + 1);
        memmove(s->name, symb, l);
 
        s->link = hash[h];
index 540063568fe28f38f25f2a2fe3ca48633fda4963..fcce23971ae063602691c7df1fc78e504b1d667d 100644 (file)
@@ -67,6 +67,8 @@ dodata(void)
        datsize = 0;
        for(i=0; i<NHASH; i++)
        for(s = hash[i]; s != S; s = s->link) {
+               if(!s->reachable)
+                       continue;
                if(s->type != SDATA)
                if(s->type != SBSS)
                        continue;
@@ -89,6 +91,8 @@ dodata(void)
        /* allocate the rest of the data */
        for(i=0; i<NHASH; i++)
        for(s = hash[i]; s != S; s = s->link) {
+               if(!s->reachable)
+                       continue;
                if(s->type != SDATA) {
                        if(s->type == SDATA1)
                                s->type = SDATA;
@@ -112,6 +116,8 @@ dodata(void)
                u -= datsize;
                for(i=0; i<NHASH; i++)
                for(s = hash[i]; s != S; s = s->link) {
+                       if(!s->reachable)
+                               continue;
                        if(s->type != SBSS)
                                continue;
                        t = s->value;
@@ -137,6 +143,8 @@ dobss(void)
        bsssize = 0;
        for(i=0; i<NHASH; i++)
        for(s = hash[i]; s != S; s = s->link) {
+               if(!s->reachable)
+                       continue;
                if(s->type != SBSS)
                        continue;
                t = s->value;
@@ -984,7 +992,7 @@ export(void)
                           s->type != SUNDEF &&
                           (nexports == 0 || s->subtype == SEXPORT))
                                n++;
-       esyms = malloc(n*sizeof(Sym*));
+       esyms = mal(n*sizeof(Sym*));
        ne = n;
        n = 0;
        for(i = 0; i < NHASH; i++)
index 3fe80622fed4fbd35b7cde9a7691a86afbe32563..f8f6f445f5ba92aedfe177f1d7670d0befb9abab 100644 (file)
@@ -183,8 +183,11 @@ putsymb(char *s, int t, vlong v, int ver, Sym *go)
                cput(0);
        }
        gv = 0;
-       if(go)
+       if(go) {
+               if(!go->reachable)
+                       sysfatal("unreachable type %s", go->name);
                gv = go->value+INITDAT;
+       }
        if(l == 8)
                lputb(gv>>32);
        lputb(gv);
@@ -219,18 +222,24 @@ asmsym(void)
        if(s->type == STEXT)
                putsymb(s->name, 'T', s->value, s->version, 0);
 
-       for(h=0; h<NHASH; h++)
-               for(s=hash[h]; s!=S; s=s->link)
+       for(h=0; h<NHASH; h++) {
+               for(s=hash[h]; s!=S; s=s->link) {
                        switch(s->type) {
                        case SCONST:
+                               if(!s->reachable)
+                                       continue;
                                putsymb(s->name, 'D', s->value, s->version, s->gotype);
                                continue;
 
                        case SDATA:
+                               if(!s->reachable)
+                                       continue;
                                putsymb(s->name, 'D', s->value+INITDAT, s->version, s->gotype);
                                continue;
 
                        case SBSS:
+                               if(!s->reachable)
+                                       continue;
                                putsymb(s->name, 'B', s->value+INITDAT, s->version, s->gotype);
                                continue;
 
@@ -238,6 +247,8 @@ asmsym(void)
                                putsymb(s->name, 'f', s->value, s->version, 0);
                                continue;
                        }
+               }
+       }
 
        for(p = textp; p != P; p = p->pcond) {
                s = p->from.sym;
@@ -685,11 +696,15 @@ vaddr(Adr *a)
                                ckoff(s, v);
                        case STEXT:
                        case SCONST:
+                               if(!s->reachable)
+                                       sysfatal("unreachable symbol in vaddr - %s", s->name);
                                if((uvlong)s->value < (uvlong)INITTEXT)
                                        v += INITTEXT;  /* TO DO */
                                v += s->value;
                                break;
                        default:
+                               if(!s->reachable)
+                                       sysfatal("unreachable symbol in vaddr - %s", s->name);
                                v += INITDAT + s->value;
                        }
                }
@@ -1662,8 +1677,8 @@ grow(Reloc *r)
        r->t += 64;
        m = r->m;
        a = r->a;
-       r->m = nm = malloc(r->t*sizeof(uchar));
-       r->a = na = malloc(r->t*sizeof(uint32));
+       r->m = nm = mal(r->t*sizeof(uchar));
+       r->a = na = mal(r->t*sizeof(uint32));
        memmove(nm, m, t*sizeof(uchar));
        memmove(na, a, t*sizeof(uint32));
        free(m);
index a0d2f6eb7e0b20caf02c8d6e2eb46166bd8984a2..c5b71597cb6805a43cc41e79c6fa55b077cab07b 100755 (executable)
@@ -1691,9 +1691,7 @@ naddr(Node *n, Addr *a)
                a->etype = 0;
                if(n->type != T) {
                        a->etype = simtype[n->type->etype];
-                       if(n->sym != S && strncmp(n->sym->name, "autotmp_", 8) != 0)
-                       if(n->type->etype != TFUNC || n->type->thistuple == 0)
-                               a->gotype = typename(n->type)->left->sym;
+                       a->gotype = ngotype(n);
                }
                a->offset = n->xoffset;
                a->sym = n->sym;
index e65d48def6d599db4b03f9c86eb54aca70a4681b..cba1b4ee73fa9642ea9bbf634b6349b8088799bd 100644 (file)
@@ -699,6 +699,8 @@ datblk(int32 s, int32 n)
        memset(buf.dbuf, 0, n+Dbufslop);
        for(p = datap; p != P; p = p->link) {
                curp = p;
+               if(!p->from.sym->reachable)
+                       sysfatal("unreachable symbol in datblk - %s", p->from.sym->name);
                l = p->from.sym->value + p->from.offset - s;
                c = p->from.scale;
                i = 0;
index 79777d8b1f300dcac4fc7ab5490f5e94be539d4f..2c8ccf9d713677bdb3188b89d86375144a179922 100644 (file)
@@ -177,7 +177,10 @@ brk:
                strcat(str, s);
        }
 conv:
-       return fmtstrcpy(fp, str);
+       fmtstrcpy(fp, str);
+       if(a->gotype)
+               fmtprint(fp, "«%s»", a->gotype->name);
+       return 0;
 }
 
 char*  regstr[] =
index a359bfca2ab1d319ccfaf37ae451bea23228d89e..fc15a83e7aa42b5da8c3972797fd70063998c583 100644 (file)
@@ -468,7 +468,7 @@ objfile(char *file)
         */
        Bseek(f, off, 0);
        cnt = esym - off;
-       start = malloc(cnt + 10);
+       start = mal(cnt + 10);
        cnt = Bread(f, start, cnt);
        if(cnt <= 0){
                Bterm(f);
@@ -677,10 +677,10 @@ addlib(char *src, char *obj)
                return;
        }
 
-       p = malloc(strlen(name) + 1);
+       p = mal(strlen(name) + 1);
        strcpy(p, name);
        library[libraryp] = p;
-       p = malloc(strlen(obj) + 1);
+       p = mal(strlen(obj) + 1);
        strcpy(p, obj);
        libraryobj[libraryp] = p;
        libraryp++;
@@ -709,9 +709,9 @@ addhist(int32 line, int type)
        Sym *s;
        int i, j, k;
 
-       u = malloc(sizeof(Auto));
-       s = malloc(sizeof(Sym));
-       s->name = malloc(2*(histfrogp+1) + 1);
+       u = mal(sizeof(Auto));
+       s = mal(sizeof(Sym));
+       s->name = mal(2*(histfrogp+1) + 1);
 
        u->asym = s;
        u->type = type;
@@ -1198,7 +1198,7 @@ lookup(char *symb, int v)
                        return s;
 
        s = mal(sizeof(Sym));
-       s->name = malloc(l + 1);
+       s->name = mal(l + 1);
        memmove(s->name, symb, l);
 
        s->link = hash[h];
index 8a45f40a629251257404a1e38f56c800707126c7..bf52b913a63cbc1a9cd3de64d4c83bb9bc9f1ff0 100644 (file)
@@ -66,6 +66,8 @@ dodata(void)
        datsize = 0;
        for(i=0; i<NHASH; i++)
        for(s = hash[i]; s != S; s = s->link) {
+               if(!s->reachable)
+                       continue;
                if(s->type != SDATA)
                if(s->type != SBSS)
                        continue;
@@ -105,6 +107,8 @@ dodata(void)
                u -= datsize;
                for(i=0; i<NHASH; i++)
                for(s = hash[i]; s != S; s = s->link) {
+                       if(!s->reachable)
+                               continue;
                        if(s->type != SBSS)
                                continue;
                        t = s->value;
@@ -122,6 +126,8 @@ dodata(void)
        bsssize = 0;
        for(i=0; i<NHASH; i++)
        for(s = hash[i]; s != S; s = s->link) {
+               if(!s->reachable)
+                       continue;
                if(s->type != SBSS)
                        continue;
                t = s->value;
@@ -855,7 +861,7 @@ export(void)
                for(s = hash[i]; s != S; s = s->link)
                        if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
                                n++;
-       esyms = malloc(n*sizeof(Sym*));
+       esyms = mal(n*sizeof(Sym*));
        ne = n;
        n = 0;
        for(i = 0; i < NHASH; i++)
index c1621fd74a4fc7566ce26b4947f4ad8aae74ea7d..a1da9d6c26dd97451e7a465d197fa9144a3b24ca 100644 (file)
@@ -174,8 +174,11 @@ putsymb(char *s, int t, int32 v, int ver, Sym *go)
                cput(0);
        }
        gv = 0;
-       if(go)
+       if(go) {
+               if(!go->reachable)
+                       sysfatal("unreachable type %s", go->name);
                gv = go->value+INITDAT;
+       }
        lput(gv);
 
        symsize += 4 + 1 + i+1 + 4;
@@ -213,14 +216,20 @@ asmsym(void)
                for(s=hash[h]; s!=S; s=s->link)
                        switch(s->type) {
                        case SCONST:
+                               if(!s->reachable)
+                                       continue;
                                putsymb(s->name, 'D', s->value, s->version, s->gotype);
                                continue;
 
                        case SDATA:
+                               if(!s->reachable)
+                                       continue;
                                putsymb(s->name, 'D', s->value+INITDAT, s->version, s->gotype);
                                continue;
 
                        case SBSS:
+                               if(!s->reachable)
+                                       continue;
                                putsymb(s->name, 'B', s->value+INITDAT, s->version, s->gotype);
                                continue;
 
@@ -591,9 +600,13 @@ vaddr(Adr *a)
                                ckoff(s, v);
                        case STEXT:
                        case SCONST:
+                               if(!s->reachable)
+                                       sysfatal("unreachable symbol in vaddr - %s", s->name);
                                v += s->value;
                                break;
                        default:
+                               if(!s->reachable)
+                                       sysfatal("unreachable symbol in vaddr - %s", s->name);
                                v += INITDAT + s->value;
                        }
                }
@@ -1332,8 +1345,8 @@ grow(Reloc *r)
        r->t += 64;
        m = r->m;
        a = r->a;
-       r->m = nm = malloc(r->t*sizeof(uchar));
-       r->a = na = malloc(r->t*sizeof(uint32));
+       r->m = nm = mal(r->t*sizeof(uchar));
+       r->a = na = mal(r->t*sizeof(uint32));
        memmove(nm, m, t*sizeof(uchar));
        memmove(na, a, t*sizeof(uint32));
        free(m);
index d709c3974f8536cc9fc47234dc2cfb9b84ae3ca7..09b8da76956b228fa5e9839dde4068213ebf1129 100644 (file)
@@ -485,6 +485,7 @@ struct      Var
 {
        vlong   offset;
        Sym*    sym;
+       Sym*    gotype;
        int     width;
        char    name;
        char    etype;
@@ -883,6 +884,7 @@ void        smagic(Magic*);
 void   umagic(Magic*);
 
 void   redeclare(Sym*, char*);
+Sym*   ngotype(Node*);
 
 /*
  *     dcl.c
index d4e62e6f97698a80fbe526e22001f336ed14ddff..3c4aaf2fee26c9845f7211de7bf1b8a8c13c0489 100644 (file)
@@ -3298,3 +3298,13 @@ umagic(Magic *m)
        m->um = q2+1;
        m->s = p-m->w;
 }
+
+Sym*
+ngotype(Node *n)
+{
+       if(n->sym != S && strncmp(n->sym->name, "autotmp_", 8) != 0)
+       if(n->type->etype != TFUNC || n->type->thistuple == 0)
+       if(n->type->etype != TSTRUCT || n->type->funarg == 0)
+               return typename(n->type)->left->sym;
+       return S;
+}
index b3e4119282153b8e0d14a41ffb9e94fb35ef25fa..b739f6027f7d27623a855627b59bbae4c403de57 100644 (file)
@@ -312,12 +312,16 @@ markdata(Prog *p, Sym *s)
 static void
 marktext(Prog *p)
 {
+       Auto *a;
+
        if(p == P)
                return;
        if(p->as != ATEXT) {
                diag("marktext: %P", p);
                return;
        }
+       for(a=p->to.autom; a; a=a->link)
+               mark(a->gotype);
        markdepth++;
        if(debug['v'] > 1)
                Bprint(&bso, "%d marktext %s\n", markdepth, p->from.sym->name);