]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/5l: support -Z (zero stack frame at function entry)
authorShenghou Ma <minux.ma@gmail.com>
Fri, 11 Jan 2013 04:24:28 +0000 (12:24 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Fri, 11 Jan 2013 04:24:28 +0000 (12:24 +0800)
also added appropriate docs to cmd/ld/doc.go
(largely copied from Russ's CL 6938073).

R=rsc
CC=golang-dev
https://golang.org/cl/7004049

src/cmd/5l/l.h
src/cmd/5l/obj.c
src/cmd/5l/pass.c
src/cmd/ld/doc.go

index 5b05932fddbe7bd5630ef984cdb43c2fe29b88b7..0ceafdd11225cc722b7073cc1ffa0a79362adeb4 100644 (file)
@@ -420,8 +420,9 @@ int32       immaddr(int32);
 int32  opbra(int, int);
 int    brextra(Prog*);
 int    isbranch(Prog*);
-void fnptrs(void);
+void   fnptrs(void);
 void   doelf(void);
+void   dozerostk(void); // used by -Z
 
 vlong          addaddr(Sym *s, Sym *t);
 vlong          addsize(Sym *s, Sym *t);
index a99f67d94919409dee60eda9c0b92086e3b57c5a..6a95a5e5729570a997802fb356ee398191ec7251 100644 (file)
@@ -255,7 +255,12 @@ main(int argc, char *argv[])
        doelf();
        follow();
        softfloat();
-       noops();
+       // 5l -Z means zero the stack frame on entry.
+       // This slows down function calls but can help avoid
+       // false positives in garbage collection.
+       if(debug['Z'])
+               dozerostk();
+       noops(); // generate stack split prolog, handle div/mod, etc.
        dostkcheck();
        span();
        addexport();
index 50593ced972b6c1d44280afdb83754b17145f2f2..c22b86085823f95e410df759fa6350d06b409966 100644 (file)
@@ -333,3 +333,70 @@ rnd(int32 v, int32 r)
        v -= c;
        return v;
 }
+
+void
+dozerostk(void)
+{
+       Prog *p, *pl;
+       int32 autoffset;
+
+       for(cursym = textp; cursym != nil; cursym = cursym->next) {
+               if(cursym->text == nil || cursym->text->link == nil)
+                       continue;                               
+               p = cursym->text;
+               autoffset = p->to.offset;
+               if(autoffset < 0)
+                       autoffset = 0;
+               if(autoffset && !(p->reg&NOSPLIT)) {
+                       // MOVW $4(R13), R1
+                       p = appendp(p);
+                       p->as = AMOVW;
+                       p->from.type = D_CONST;
+                       p->from.reg = 13;
+                       p->from.offset = 4;
+                       p->to.type = D_REG;
+                       p->to.reg = 1;
+
+                       // MOVW $n(R13), R2
+                       p = appendp(p);
+                       p->as = AMOVW;
+                       p->from.type = D_CONST;
+                       p->from.reg = 13;
+                       p->from.offset = 4 + autoffset;
+                       p->to.type = D_REG;
+                       p->to.reg = 2;
+
+                       // MOVW $0, R3
+                       p = appendp(p);
+                       p->as = AMOVW;
+                       p->from.type = D_CONST;
+                       p->from.offset = 0;
+                       p->to.type = D_REG;
+                       p->to.reg = 3;
+
+                       // L:
+                       //      MOVW.P R3, 0(R1) +4
+                       //      CMP R1, R2
+                       //      BNE L
+                       p = pl = appendp(p);
+                       p->as = AMOVW;
+                       p->from.type = D_REG;
+                       p->from.reg = 3;
+                       p->to.type = D_OREG;
+                       p->to.reg = 1;
+                       p->to.offset = 4;
+                       p->scond |= C_PBIT;
+
+                       p = appendp(p);
+                       p->as = ACMP;
+                       p->from.type = D_REG;
+                       p->from.reg = 1;
+                       p->reg = 2;
+
+                       p = appendp(p);
+                       p->as = ABNE;
+                       p->to.type = D_BRANCH;
+                       p->cond = pl;
+               }
+       }
+}
index 7fc22983db7a8ae228d27b38d35047dd3068f346..357505f0b2c6a8ea92d6f177f0c293be09c68535 100644 (file)
@@ -61,5 +61,13 @@ Options new in this version:
        -B value
                Add a NT_GNU_BUILD_ID note when using ELF.  The value
                should start with 0x and be an even number of hex digits.
+       -Z
+               Zero stack on function entry. This is expensive but it might
+               be useful in cases where you are suffering from false positives
+               during garbage collection and are willing to trade the CPU time
+               for getting rid of the false positives.
+               NOTE: it only eliminates false positives caused by other function
+               calls, not false positives caused by dead temporaries stored in
+               the current function call.
 */
 package documentation