Commit 8cdee790 authored by Shenghou Ma's avatar Shenghou Ma

libmach, cmd/5a, cmd/5c, cmd/5g, cmd/5l: enable DWARF type info for Linux/ARM

Fixes #3747.

Update #4912
This CL adds gotype into .5 object file.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7376054
parent b6e322dc
...@@ -505,6 +505,7 @@ zaddr(Gen *a, int s) ...@@ -505,6 +505,7 @@ zaddr(Gen *a, int s)
Bputc(&obuf, a->reg); Bputc(&obuf, a->reg);
Bputc(&obuf, s); Bputc(&obuf, s);
Bputc(&obuf, a->name); Bputc(&obuf, a->name);
Bputc(&obuf, 0);
switch(a->type) { switch(a->type) {
default: default:
print("unknown type %d\n", a->type); print("unknown type %d\n", a->type);
......
...@@ -601,7 +601,8 @@ zaddr(char *bp, Adr *a, int s) ...@@ -601,7 +601,8 @@ zaddr(char *bp, Adr *a, int s)
bp[1] = a->reg; bp[1] = a->reg;
bp[2] = s; bp[2] = s;
bp[3] = a->name; bp[3] = a->name;
bp += 4; bp[4] = 0;
bp += 5;
switch(a->type) { switch(a->type) {
default: default:
diag(Z, "unknown type %d in zaddr", a->type); diag(Z, "unknown type %d in zaddr", a->type);
......
...@@ -166,7 +166,7 @@ int Rconv(Fmt*); ...@@ -166,7 +166,7 @@ int Rconv(Fmt*);
int Yconv(Fmt*); int Yconv(Fmt*);
void listinit(void); void listinit(void);
void zaddr(Biobuf*, Addr*, int); void zaddr(Biobuf*, Addr*, int, int);
#pragma varargck type "D" Addr* #pragma varargck type "D" Addr*
#pragma varargck type "M" Addr* #pragma varargck type "M" Addr*
...@@ -65,17 +65,17 @@ zhist(Biobuf *b, int line, vlong offset) ...@@ -65,17 +65,17 @@ zhist(Biobuf *b, int line, vlong offset)
Bputc(b, line>>8); Bputc(b, line>>8);
Bputc(b, line>>16); Bputc(b, line>>16);
Bputc(b, line>>24); Bputc(b, line>>24);
zaddr(b, &zprog.from, 0); zaddr(b, &zprog.from, 0, 0);
a = zprog.to; a = zprog.to;
if(offset != 0) { if(offset != 0) {
a.offset = offset; a.offset = offset;
a.type = D_CONST; a.type = D_CONST;
} }
zaddr(b, &a, 0); zaddr(b, &a, 0, 0);
} }
void void
zaddr(Biobuf *b, Addr *a, int s) zaddr(Biobuf *b, Addr *a, int s, int gotype)
{ {
int32 l; int32 l;
uint64 e; uint64 e;
...@@ -95,6 +95,7 @@ zaddr(Biobuf *b, Addr *a, int s) ...@@ -95,6 +95,7 @@ zaddr(Biobuf *b, Addr *a, int s)
Bputc(b, a->reg); Bputc(b, a->reg);
Bputc(b, s); Bputc(b, s);
Bputc(b, a->name); Bputc(b, a->name);
Bputc(b, gotype);
} }
switch(a->type) { switch(a->type) {
...@@ -167,20 +168,66 @@ zaddr(Biobuf *b, Addr *a, int s) ...@@ -167,20 +168,66 @@ zaddr(Biobuf *b, Addr *a, int s)
} }
} }
static struct {
struct { Sym *sym; short type; } h[NSYM];
int sym;
} z;
static void
zsymreset(void)
{
for(z.sym=0; z.sym<NSYM; z.sym++) {
z.h[z.sym].sym = S;
z.h[z.sym].type = 0;
}
z.sym = 1;
}
static int
zsym(Sym *s, int t, int *new)
{
int i;
*new = 0;
if(s == S)
return 0;
i = s->sym;
if(i < 0 || i >= NSYM)
i = 0;
if(z.h[i].type == t && z.h[i].sym == s)
return i;
i = z.sym;
s->sym = i;
zname(bout, s, t);
z.h[i].sym = s;
z.h[i].type = t;
if(++z.sym >= NSYM)
z.sym = 1;
*new = 1;
return i;
}
static int
zsymaddr(Addr *a, int *new)
{
int t;
t = a->name;
if(t == D_ADDR)
t = a->name;
return zsym(a->sym, t, new);
}
void void
dumpfuncs(void) dumpfuncs(void)
{ {
Plist *pl; Plist *pl;
int sf, st, t, sym; int sf, st, gf, gt, new;
struct { Sym *sym; short type; } h[NSYM];
Sym *s; Sym *s;
Prog *p; Prog *p;
for(sym=0; sym<NSYM; sym++) { zsymreset();
h[sym].sym = S;
h[sym].type = 0;
}
sym = 1;
// fix up pc // fix up pc
pcloc = 0; pcloc = 0;
...@@ -210,53 +257,20 @@ dumpfuncs(void) ...@@ -210,53 +257,20 @@ dumpfuncs(void)
} }
for(p=pl->firstpc; p!=P; p=p->link) { for(p=pl->firstpc; p!=P; p=p->link) {
jackpot: for(;;) {
sf = 0; sf = zsymaddr(&p->from, &new);
s = p->from.sym; gf = zsym(p->from.gotype, D_EXTERN, &new);
while(s != S) { if(new && sf == gf)
sf = s->sym; continue;
if(sf < 0 || sf >= NSYM) st = zsymaddr(&p->to, &new);
sf = 0; if(new && (st == sf || st == gf))
t = p->from.name; continue;
if(t == D_ADDR) gt = zsym(p->to.gotype, D_EXTERN, &new);
t = p->from.name; if(new && (gt == sf || gt == gf || gt == st))
if(h[sf].type == t) continue;
if(h[sf].sym == s)
break;
s->sym = sym;
zname(bout, s, t);
h[sym].sym = s;
h[sym].type = t;
sf = sym;
sym++;
if(sym >= NSYM)
sym = 1;
break;
}
st = 0;
s = p->to.sym;
while(s != S) {
st = s->sym;
if(st < 0 || st >= NSYM)
st = 0;
t = p->to.name;
if(t == D_ADDR)
t = p->to.name;
if(h[st].type == t)
if(h[st].sym == s)
break;
s->sym = sym;
zname(bout, s, t);
h[sym].sym = s;
h[sym].type = t;
st = sym;
sym++;
if(sym >= NSYM)
sym = 1;
if(st == sf)
goto jackpot;
break; break;
} }
Bputc(bout, p->as); Bputc(bout, p->as);
Bputc(bout, p->scond); Bputc(bout, p->scond);
Bputc(bout, p->reg); Bputc(bout, p->reg);
...@@ -264,8 +278,8 @@ dumpfuncs(void) ...@@ -264,8 +278,8 @@ dumpfuncs(void)
Bputc(bout, p->lineno>>8); Bputc(bout, p->lineno>>8);
Bputc(bout, p->lineno>>16); Bputc(bout, p->lineno>>16);
Bputc(bout, p->lineno>>24); Bputc(bout, p->lineno>>24);
zaddr(bout, &p->from, sf); zaddr(bout, &p->from, sf, gf);
zaddr(bout, &p->to, st); zaddr(bout, &p->to, st, gt);
} }
} }
} }
......
...@@ -1214,6 +1214,7 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -1214,6 +1214,7 @@ naddr(Node *n, Addr *a, int canemitcode)
a->type = D_NONE; a->type = D_NONE;
a->name = D_NONE; a->name = D_NONE;
a->reg = NREG; a->reg = NREG;
a->gotype = S;
a->node = N; a->node = N;
a->etype = 0; a->etype = 0;
if(n == N) if(n == N)
......
...@@ -321,6 +321,8 @@ EXTERN int dtype; ...@@ -321,6 +321,8 @@ EXTERN int dtype;
EXTERN int tlsoffset; EXTERN int tlsoffset;
EXTERN int armsize; EXTERN int armsize;
EXTERN int goarm; EXTERN int goarm;
EXTERN Sym* adrgotype; // type symbol on last Adr read
EXTERN Sym* fromgotype; // type symbol on last p->from read
extern char* anames[]; extern char* anames[];
extern Optab optab[]; extern Optab optab[];
......
...@@ -280,8 +280,21 @@ main(int argc, char *argv[]) ...@@ -280,8 +280,21 @@ main(int argc, char *argv[])
errorexit(); errorexit();
} }
static Sym*
zsym(char *pn, Biobuf *f, Sym *h[])
{
int o;
o = BGETC(f);
if(o == 0)
return S;
if(o < 0 || o >= NSYM || h[o] == nil)
mangle(pn);
return h[o];
}
static void static void
zaddr(Biobuf *f, Adr *a, Sym *h[]) zaddr(char *pn, Biobuf *f, Adr *a, Sym *h[])
{ {
int i, c; int i, c;
int32 l; int32 l;
...@@ -298,6 +311,7 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -298,6 +311,7 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
} }
a->sym = h[c]; a->sym = h[c];
a->name = BGETC(f); a->name = BGETC(f);
adrgotype = zsym(pn, f, h);
if((schar)a->reg < 0 || a->reg > NREG) { if((schar)a->reg < 0 || a->reg > NREG) {
print("register out of range %d\n", a->reg); print("register out of range %d\n", a->reg);
...@@ -358,8 +372,11 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -358,8 +372,11 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
if(s == S) if(s == S)
return; return;
i = a->name; i = a->name;
if(i != D_AUTO && i != D_PARAM) if(i != D_AUTO && i != D_PARAM) {
if(s && adrgotype)
s->gotype = adrgotype;
return; return;
}
l = a->offset; l = a->offset;
for(u=curauto; u; u=u->link) for(u=curauto; u; u=u->link)
...@@ -367,6 +384,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -367,6 +384,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
if(u->type == i) { if(u->type == i) {
if(u->aoffset > l) if(u->aoffset > l)
u->aoffset = l; u->aoffset = l;
if(adrgotype)
u->gotype = adrgotype;
return; return;
} }
...@@ -376,6 +395,7 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -376,6 +395,7 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
u->asym = s; u->asym = s;
u->aoffset = l; u->aoffset = l;
u->type = i; u->type = i;
u->gotype = adrgotype;
} }
void void
...@@ -484,8 +504,9 @@ loop: ...@@ -484,8 +504,9 @@ loop:
p->reg = BGETC(f); p->reg = BGETC(f);
p->line = Bget4(f); p->line = Bget4(f);
zaddr(f, &p->from, h); zaddr(pn, f, &p->from, h);
zaddr(f, &p->to, h); fromgotype = adrgotype;
zaddr(pn, f, &p->to, h);
if(p->as != ATEXT && p->as != AGLOBL && p->reg > NREG) if(p->as != ATEXT && p->as != AGLOBL && p->reg > NREG)
diag("register out of range %A %d", p->as, p->reg); diag("register out of range %A %d", p->as, p->reg);
...@@ -611,6 +632,11 @@ loop: ...@@ -611,6 +632,11 @@ loop:
etextp->next = s; etextp->next = s;
else else
textp = s; textp = s;
if(fromgotype) {
if(s->gotype && s->gotype != fromgotype)
diag("%s: type mismatch for %s", pn, s->name);
s->gotype = fromgotype;
}
etextp = s; etextp = s;
p->align = 4; p->align = 4;
autosize = (p->to.offset+3L) & ~3L; autosize = (p->to.offset+3L) & ~3L;
......
...@@ -42,6 +42,7 @@ struct Addr ...@@ -42,6 +42,7 @@ struct Addr
char type; char type;
char sym; char sym;
char name; char name;
char gotype;
}; };
static Addr addr(Biobuf*); static Addr addr(Biobuf*);
static char type2char(int); static char type2char(int);
...@@ -115,6 +116,7 @@ addr(Biobuf *bp) ...@@ -115,6 +116,7 @@ addr(Biobuf *bp)
skip(bp,1); /* reg */ skip(bp,1); /* reg */
a.sym = Bgetc(bp); /* sym index */ a.sym = Bgetc(bp); /* sym index */
a.name = Bgetc(bp); /* sym type */ a.name = Bgetc(bp); /* sym type */
a.gotype = Bgetc(bp); /* go type */
switch(a.type){ switch(a.type){
default: default:
case D_NONE: case D_NONE:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment