]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/6l, cmd/8l: add -Z flag to zero stack frame on entry
authorRuss Cox <rsc@golang.org>
Sat, 22 Dec 2012 16:20:17 +0000 (11:20 -0500)
committerRuss Cox <rsc@golang.org>
Sat, 22 Dec 2012 16:20:17 +0000 (11:20 -0500)
Replacement for GOEXPERIMENT=zerostack, easier to use.
Does not require a separate toolchain.

R=ken2
CC=golang-dev
https://golang.org/cl/6996051

src/cmd/6l/pass.c
src/cmd/8l/pass.c

index 043048e8a06807a26d461db692f203cf1b72389b..0054b329f498996f26e3d22d8bc9b31c9ed27559 100644 (file)
@@ -653,6 +653,34 @@ dostkoff(void)
                        q1->pcond = p;
                }
                
+               if(debug['Z'] && autoffset && !(cursym->text->from.scale&NOSPLIT)) {
+                       // 6l -Z means zero the stack frame on entry.
+                       // This slows down function calls but can help avoid
+                       // false positives in garbage collection.
+                       p = appendp(p);
+                       p->as = AMOVQ;
+                       p->from.type = D_SP;
+                       p->to.type = D_DI;
+                       
+                       p = appendp(p);
+                       p->as = AMOVQ;
+                       p->from.type = D_CONST;
+                       p->from.offset = autoffset/8;
+                       p->to.type = D_CX;
+                       
+                       p = appendp(p);
+                       p->as = AMOVQ;
+                       p->from.type = D_CONST;
+                       p->from.offset = 0;
+                       p->to.type = D_AX;
+                       
+                       p = appendp(p);
+                       p->as = AREP;
+                       
+                       p = appendp(p);
+                       p->as = ASTOSQ;
+               }
+               
                for(; p != P; p = p->link) {
                        pcsize = p->mode/8;
                        a = p->from.type;
index 6cf3009e2cc8f284989ba320d928115ce4cfb7d9..03292a5b3f8cbf99642bb89f8bce7de759a9f84c 100644 (file)
@@ -593,6 +593,34 @@ dostkoff(void)
                }
                deltasp = autoffset;
                
+               if(debug['Z'] && autoffset && !(cursym->text->from.scale&NOSPLIT)) {
+                       // 8l -Z means zero the stack frame on entry.
+                       // This slows down function calls but can help avoid
+                       // false positives in garbage collection.
+                       p = appendp(p);
+                       p->as = AMOVL;
+                       p->from.type = D_SP;
+                       p->to.type = D_DI;
+                       
+                       p = appendp(p);
+                       p->as = AMOVL;
+                       p->from.type = D_CONST;
+                       p->from.offset = autoffset/4;
+                       p->to.type = D_CX;
+                       
+                       p = appendp(p);
+                       p->as = AMOVL;
+                       p->from.type = D_CONST;
+                       p->from.offset = 0;
+                       p->to.type = D_AX;
+                       
+                       p = appendp(p);
+                       p->as = AREP;
+                       
+                       p = appendp(p);
+                       p->as = ASTOSL;
+               }
+               
                for(; p != P; p = p->link) {
                        a = p->from.type;
                        if(a == D_AUTO)