Commit 5a67ea38 authored by Russ Cox's avatar Russ Cox

6g: simplify trampoline by postponing load.

	TEXT tramp
		MOVQ 8(SP), AX
		ADDQ $40, AX
		MOVQ AX, 8(SP)
		JMP oldfunc

	is now

	TEXT tramp
		ADDQ $40, 8(SP)
		JMP oldfunc

	and if s/40/0/, then it simplifies to

	TEXT tramp
		JMP oldfunc

	(the tramp is still needed to satisfy
	symbol references from other object files)

R=ken
OCL=28377
CL=28381
parent e508c557
......@@ -553,7 +553,7 @@ void
genembedtramp(Type *t, Sig *b)
{
Sym *e;
int c, d, o;
int c, d, o, loaded;
Prog *p;
Type *f;
......@@ -566,9 +566,6 @@ genembedtramp(Type *t, Sig *b)
fatal("genembedtramp %T.%s", t, b->name);
out:
if(d == 0)
return;
// print("genembedtramp %d\n", d);
// print(" t = %lT\n", t);
// print(" name = %s\n", b->name);
......@@ -587,6 +584,15 @@ out:
p->from.scale = 7;
//print("1. %P\n", p);
loaded = 0;
o = 0;
for(c=d-1; c>=0; c--) {
f = dotlist[c].field;
o += f->width;
if(!isptr[f->type->etype])
continue;
if(!loaded) {
loaded = 1;
//MOVQ 8(SP), AX
p = pc;
gins(AMOVQ, N, N);
......@@ -594,13 +600,8 @@ out:
p->from.offset = 8;
p->to.type = D_AX;
//print("2. %P\n", p);
}
o = 0;
for(c=d-1; c>=0; c--) {
f = dotlist[c].field;
o += f->width;
if(!isptr[f->type->etype])
continue;
//MOVQ o(AX), AX
p = pc;
gins(AMOVQ, N, N);
......@@ -616,17 +617,31 @@ out:
gins(AADDQ, N, N);
p->from.type = D_CONST;
p->from.offset = o;
if(loaded)
p->to.type = D_AX;
else {
p->to.type = D_INDIR+D_SP;
p->to.offset = 8;
}
//print("4. %P\n", p);
}
//MOVQ AX, 8(SP)
if(loaded) {
p = pc;
gins(AMOVQ, N, N);
p->from.type = D_AX;
p->to.type = D_INDIR+D_SP;
p->to.offset = 8;
//print("5. %P\n", p);
} else {
// TODO(rsc): obviously this is unnecessary,
// but 6l has a bug, and it can't handle
// JMP instructions too close to the top of
// a new function.
p = pc;
gins(ANOP, N, N);
}
f = dotlist[0].field;
//JMP main·*Sub_test2(SB)
......
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