Commit ddba96ae authored by Ken Thompson's avatar Ken Thompson

stack offset

SVN=123521
parent f997bc6e
......@@ -32,7 +32,7 @@
#define NSNAME 8
#define NOPROF (1<<0)
#define DUPOK (1<<1)
#define SOFmark (11)
#define SOFmark "\xa7\xf1\xd9\x2a\x82\xc8\xd8\xfe"
/*
* amd64
......
......@@ -138,8 +138,7 @@ asmb(void)
for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT)
curtext = p;
if(p->pc != pc)
if(p->as != ATEXT || p->pc != pc+SOFmark) {
if(p->pc != pc) {
if(!debug['a'])
print("%P\n", curp);
diag("phase error %llux sb %llux in %s", p->pc, pc, TNAME);
......
......@@ -217,7 +217,6 @@ enum
Zaut_r,
Zo_m,
Zo_m64,
Ztext,
Zpseudo,
Zr_m,
Zr_m_xm,
......@@ -388,6 +387,7 @@ void export(void);
int find1(long, int);
int find2(long, int);
void follow(void);
void addstachmark(void);
void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
......
......@@ -400,6 +400,7 @@ main(int argc, char *argv[])
doprof1();
else
doprof2();
addstackmark();
span();
doinit();
asmb();
......@@ -925,9 +926,9 @@ loop:
sig = 1729;
if(sig != 0){
if(s->sig != 0 && s->sig != sig)
diag("incompatible type signatures %lux(%s)"
"and %lux(%s) for %s", s->sig,
filen[s->file], sig, pn, s->name);
diag("incompatible type signatures"
"%lux(%s) and %lux(%s) for %s",
s->sig, filen[s->file], sig, pn, s->name);
s->sig = sig;
s->file = files-1;
}
......
......@@ -37,7 +37,7 @@ uchar ynone[] =
};
uchar ytext[] =
{
Ymb, Yi32, Ztext, 1,
Ymb, Yi32, Zpseudo,1,
0
};
uchar ynop[] =
......
......@@ -281,6 +281,112 @@ loop:
goto loop;
}
Prog*
byteq(int v)
{
Prog *p;
p = prg();
p->as = ABYTE;
p->from.type = D_CONST;
p->from.offset = v&0xff;
return p;
}
void
markstk(Prog *l)
{
Prog *p0, *p, *q, *r;
long i, n, line;
Sym *s;
version++;
s = lookup(l->from.sym->name, version);
s->type = STEXT;
line = l->line;
// start with fake copy of ATEXT
p0 = prg();
p = p0;
*p = *l; // note this gets p->pcond and p->line
p->from.type = D_STATIC;
p->from.sym = s;
p->to.offset = 0;
// put out magic sequence
n = strlen(SOFmark);
for(i=0; i<n; i++) {
q = byteq(SOFmark[i]);
q->line = line;
p->link = q;
p = q;
}
// put out stack offset
n = l->to.offset;
if(n < 0)
n = 0;
for(i=0; i<3; i++) {
q = byteq(n);
q->line = line;
p->link = q;
p = q;
n = n>>8;
}
// put out null terminated name
for(i=0;; i++) {
n = s->name[i];
q = byteq(n);
q->line = line;
p->link = q;
p = q;
if(n == 0)
break;
}
// put out return instruction
q = prg();
q->as = ARET;
q->line = line;
p->link = q;
p = q;
r = l->pcond;
l->pcond = p0;
p->link = r;
p0->pcond = r;
// hard part is linking end of
// the text body to my fake ATEXT
for(p=l;; p=q) {
q = p->link;
if(q == r) {
p->link = p0;
return;
}
}
}
void
addstackmark(void)
{
Prog *p;
if(debug['v'])
Bprint(&bso, "%5.2f stkmark\n", cputime());
Bflush(&bso);
for(p=textp; p!=P; p=p->pcond) {
markstk(p); // splice in new body
p = p->pcond; // skip the one we just put in
}
// for(p=textp; p!=P; p=p->pcond)
// print("%P\n", p);
}
int
relinv(int a)
{
......@@ -344,6 +450,7 @@ patch(void)
if(debug['v'])
Bprint(&bso, "%5.2f patch\n", cputime());
Bflush(&bso);
s = lookup("exit", 0);
vexit = s->value;
for(p = firstp; p != P; p = p->link) {
......
......@@ -83,8 +83,6 @@ start:
p->pc = c;
asmins(p);
p->pc = c;
if(p->as == ATEXT)
p->pc += SOFmark; // skip the stack marker
m = andptr-and;
p->mark = m;
c += m;
......@@ -115,8 +113,6 @@ loop:
}
}
p->pc = c;
if(p->as == ATEXT)
p->pc += SOFmark; // skip the stack marker
c += p->mark;
}
if(again) {
......@@ -273,7 +269,7 @@ asmlc(void)
Prog *p;
long oldlc, v, s;
oldpc = INITTEXT+SOFmark;
oldpc = INITTEXT;
oldlc = 0;
for(p = firstp; p != P; p = p->link) {
if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
......@@ -1124,19 +1120,6 @@ found:
diag("asmins: unknown z %d %P", t[2], p);
return;
case Ztext:
v = p->to.offset;
if(v < 0)
v = 0;
// eleven bytes of buried stack offset
*andptr++ = v>>3;
*andptr++ = v>>11;
*andptr++ = v>>19;
for(v=0; v<SOFmark-3; v++)
*andptr++ = "\xa7\xf1\xd9\x2a\x82\xc8\xd8\xfe"[v];
break;
case Zpseudo:
break;
......
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