From 7b29dbb866540b7308f94f9fab319412969c6cb6 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 20 Aug 2009 17:33:28 -0700 Subject: [PATCH] symbol bugs. do not emit unreachable data symbols. R=austin DELTA=103 (71 added, 4 deleted, 28 changed) OCL=33325 CL=33622 --- src/cmd/6g/gsubr.c | 4 +--- src/cmd/6g/reg.c | 2 ++ src/cmd/6l/asm.c | 2 ++ src/cmd/6l/list.c | 6 +++++- src/cmd/6l/obj.c | 14 +++++++------- src/cmd/6l/pass.c | 10 +++++++++- src/cmd/6l/span.c | 25 ++++++++++++++++++++----- src/cmd/8g/gsubr.c | 4 +--- src/cmd/8l/asm.c | 2 ++ src/cmd/8l/list.c | 5 ++++- src/cmd/8l/obj.c | 14 +++++++------- src/cmd/8l/pass.c | 8 +++++++- src/cmd/8l/span.c | 19 ++++++++++++++++--- src/cmd/gc/go.h | 2 ++ src/cmd/gc/subr.c | 10 ++++++++++ src/cmd/ld/go.c | 4 ++++ 16 files changed, 99 insertions(+), 32 deletions(-) diff --git a/src/cmd/6g/gsubr.c b/src/cmd/6g/gsubr.c index aec4cb1bd3..e2fdceff48 100644 --- a/src/cmd/6g/gsubr.c +++ b/src/cmd/6g/gsubr.c @@ -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; diff --git a/src/cmd/6g/reg.c b/src/cmd/6g/reg.c index 4f7ce069fe..d017c62ab3 100644 --- a/src/cmd/6g/reg.c +++ b/src/cmd/6g/reg.c @@ -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']) diff --git a/src/cmd/6l/asm.c b/src/cmd/6l/asm.c index 5acaaae5f1..fb0f361de7 100644 --- a/src/cmd/6l/asm.c +++ b/src/cmd/6l/asm.c @@ -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; diff --git a/src/cmd/6l/list.c b/src/cmd/6l/list.c index 000c6fa378..2acd36e67b 100644 --- a/src/cmd/6l/list.c +++ b/src/cmd/6l/list.c @@ -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[] = diff --git a/src/cmd/6l/obj.c b/src/cmd/6l/obj.c index 98318d94b1..1deee18f59 100644 --- a/src/cmd/6l/obj.c +++ b/src/cmd/6l/obj.c @@ -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]; diff --git a/src/cmd/6l/pass.c b/src/cmd/6l/pass.c index 540063568f..fcce23971a 100644 --- a/src/cmd/6l/pass.c +++ b/src/cmd/6l/pass.c @@ -67,6 +67,8 @@ dodata(void) datsize = 0; for(i=0; ilink) { + 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; ilink) { + 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; ilink) { + if(!s->reachable) + continue; if(s->type != SBSS) continue; t = s->value; @@ -137,6 +143,8 @@ dobss(void) bsssize = 0; for(i=0; ilink) { + 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++) diff --git a/src/cmd/6l/span.c b/src/cmd/6l/span.c index 3fe80622fe..f8f6f445f5 100644 --- a/src/cmd/6l/span.c +++ b/src/cmd/6l/span.c @@ -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; hlink) + for(h=0; hlink) { 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); diff --git a/src/cmd/8g/gsubr.c b/src/cmd/8g/gsubr.c index a0d2f6eb7e..c5b71597cb 100755 --- a/src/cmd/8g/gsubr.c +++ b/src/cmd/8g/gsubr.c @@ -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; diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c index e65d48def6..cba1b4ee73 100644 --- a/src/cmd/8l/asm.c +++ b/src/cmd/8l/asm.c @@ -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; diff --git a/src/cmd/8l/list.c b/src/cmd/8l/list.c index 79777d8b1f..2c8ccf9d71 100644 --- a/src/cmd/8l/list.c +++ b/src/cmd/8l/list.c @@ -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[] = diff --git a/src/cmd/8l/obj.c b/src/cmd/8l/obj.c index a359bfca2a..fc15a83e7a 100644 --- a/src/cmd/8l/obj.c +++ b/src/cmd/8l/obj.c @@ -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]; diff --git a/src/cmd/8l/pass.c b/src/cmd/8l/pass.c index 8a45f40a62..bf52b913a6 100644 --- a/src/cmd/8l/pass.c +++ b/src/cmd/8l/pass.c @@ -66,6 +66,8 @@ dodata(void) datsize = 0; for(i=0; ilink) { + if(!s->reachable) + continue; if(s->type != SDATA) if(s->type != SBSS) continue; @@ -105,6 +107,8 @@ dodata(void) u -= datsize; for(i=0; ilink) { + if(!s->reachable) + continue; if(s->type != SBSS) continue; t = s->value; @@ -122,6 +126,8 @@ dodata(void) bsssize = 0; for(i=0; ilink) { + 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++) diff --git a/src/cmd/8l/span.c b/src/cmd/8l/span.c index c1621fd74a..a1da9d6c26 100644 --- a/src/cmd/8l/span.c +++ b/src/cmd/8l/span.c @@ -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); diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h index d709c3974f..09b8da7695 100644 --- a/src/cmd/gc/go.h +++ b/src/cmd/gc/go.h @@ -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 diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index d4e62e6f97..3c4aaf2fee 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -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; +} diff --git a/src/cmd/ld/go.c b/src/cmd/ld/go.c index b3e4119282..b739f6027f 100644 --- a/src/cmd/ld/go.c +++ b/src/cmd/ld/go.c @@ -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);