Commit c6a41a35 authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/6g, cmd/8g: disable Duff's device on NaCl.

Native Client forbids jumps/calls to arbitrary locations and
enforces a particular alignement, which makes the Duff's device
ineffective.

LGTM=khr
R=rsc, dave, khr
CC=golang-codereviews
https://golang.org/cl/84400043
parent e25d73d7
...@@ -1448,7 +1448,7 @@ sgen(Node *n, Node *ns, int64 w) ...@@ -1448,7 +1448,7 @@ sgen(Node *n, Node *ns, int64 w)
gins(ACLD, N, N); gins(ACLD, N, N);
} else { } else {
// normal direction // normal direction
if(q > 128) { if(q > 128 || (nacl && q >= 4)) {
gconreg(movptr, q, D_CX); gconreg(movptr, q, D_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(AMOVSQ, N, N); // MOVQ *(SI)+,*(DI)+ gins(AMOVSQ, N, N); // MOVQ *(SI)+,*(DI)+
......
...@@ -77,7 +77,7 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax) ...@@ -77,7 +77,7 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax)
for(i = 0; i < cnt; i += widthreg) { for(i = 0; i < cnt; i += widthreg) {
p = appendpp(p, AMOVQ, D_AX, 0, D_SP+D_INDIR, frame+lo+i); p = appendpp(p, AMOVQ, D_AX, 0, D_SP+D_INDIR, frame+lo+i);
} }
} else if(cnt <= 128*widthreg) { } else if(!nacl && (cnt <= 128*widthreg)) {
p = appendpp(p, leaptr, D_SP+D_INDIR, frame+lo, D_DI, 0); p = appendpp(p, leaptr, D_SP+D_INDIR, frame+lo, D_DI, 0);
p = appendpp(p, ADUFFZERO, D_NONE, 0, D_ADDR, 2*(128-cnt/widthreg)); p = appendpp(p, ADUFFZERO, D_NONE, 0, D_ADDR, 2*(128-cnt/widthreg));
p->to.sym = linksym(pkglookup("duffzero", runtimepkg)); p->to.sym = linksym(pkglookup("duffzero", runtimepkg));
...@@ -1119,7 +1119,7 @@ clearfat(Node *nl) ...@@ -1119,7 +1119,7 @@ clearfat(Node *nl)
savex(D_AX, &ax, &oldax, N, types[tptr]); savex(D_AX, &ax, &oldax, N, types[tptr]);
gconreg(AMOVL, 0, D_AX); gconreg(AMOVL, 0, D_AX);
if(q > 128) { if(q > 128 || (q >= 4 && nacl)) {
gconreg(movptr, q, D_CX); gconreg(movptr, q, D_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(ASTOSQ, N, N); // STOQ AL,*(DI)+ gins(ASTOSQ, N, N); // STOQ AL,*(DI)+
......
...@@ -1315,7 +1315,7 @@ sgen(Node *n, Node *res, int64 w) ...@@ -1315,7 +1315,7 @@ sgen(Node *n, Node *res, int64 w)
} else { } else {
gins(ACLD, N, N); // paranoia. TODO(rsc): remove? gins(ACLD, N, N); // paranoia. TODO(rsc): remove?
// normal direction // normal direction
if(q > 128) { if(q > 128 || (q >= 4 && nacl)) {
gconreg(AMOVL, q, D_CX); gconreg(AMOVL, q, D_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(AMOVSL, N, N); // MOVL *(SI)+,*(DI)+ gins(AMOVSL, N, N); // MOVL *(SI)+,*(DI)+
......
...@@ -75,7 +75,7 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax) ...@@ -75,7 +75,7 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax)
for(i = 0; i < cnt; i += widthreg) { for(i = 0; i < cnt; i += widthreg) {
p = appendpp(p, AMOVL, D_AX, 0, D_SP+D_INDIR, frame+lo+i); p = appendpp(p, AMOVL, D_AX, 0, D_SP+D_INDIR, frame+lo+i);
} }
} else if(cnt <= 128*widthreg) { } else if(!nacl && cnt <= 128*widthreg) {
p = appendpp(p, ALEAL, D_SP+D_INDIR, frame+lo, D_DI, 0); p = appendpp(p, ALEAL, D_SP+D_INDIR, frame+lo, D_DI, 0);
p = appendpp(p, ADUFFZERO, D_NONE, 0, D_ADDR, 1*(128-cnt/widthreg)); p = appendpp(p, ADUFFZERO, D_NONE, 0, D_ADDR, 1*(128-cnt/widthreg));
p->to.sym = linksym(pkglookup("duffzero", runtimepkg)); p->to.sym = linksym(pkglookup("duffzero", runtimepkg));
...@@ -176,7 +176,7 @@ clearfat(Node *nl) ...@@ -176,7 +176,7 @@ clearfat(Node *nl)
agen(nl, &n1); agen(nl, &n1);
gconreg(AMOVL, 0, D_AX); gconreg(AMOVL, 0, D_AX);
if(q > 128) { if(q > 128 || (q >= 4 && nacl)) {
gconreg(AMOVL, q, D_CX); gconreg(AMOVL, q, D_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(ASTOSL, N, N); // STOL AL,*(DI)+ gins(ASTOSL, N, N); // STOL AL,*(DI)+
......
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