1
0
mirror of https://github.com/golang/go synced 2024-09-25 13:20:13 -06:00

symbol bugs.

do not emit unreachable data symbols.

R=austin
DELTA=103  (71 added, 4 deleted, 28 changed)
OCL=33325
CL=33622
This commit is contained in:
Russ Cox 2009-08-20 17:33:28 -07:00
parent bd4161fcba
commit 7b29dbb866
16 changed files with 99 additions and 32 deletions

View 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;

View 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'])

View 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;

View 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[] =

View 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];

View 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++)

View 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);

View File

@ -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;

View 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;

View 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[] =

View 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];

View 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++)

View 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);

View 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

View 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;
}

View 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);