]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/5g, cmd/5l, cmd/6l, cmd/8l, cmd/gc, cmd/ld, runtime: accurate args and locals...
authorCarl Shapiro <cshapiro@google.com>
Thu, 21 Feb 2013 20:52:26 +0000 (12:52 -0800)
committerCarl Shapiro <cshapiro@google.com>
Thu, 21 Feb 2013 20:52:26 +0000 (12:52 -0800)
Previously, the func structure contained an inaccurate value for
the args member and a 0 value for the locals member.

This change populates the func structure with args and locals
values computed by the compiler.  The number of args was
already available in the ATEXT instruction.  The number of
locals is now passed through in the new ALOCALS instruction.

This change also switches the unit of args and locals to be
bytes, just like the frame member, instead of 32-bit words.

R=golang-dev, bradfitz, cshapiro, dave, rsc
CC=golang-dev
https://golang.org/cl/7399045

20 files changed:
src/cmd/5g/peep.c
src/cmd/5l/5.out.h
src/cmd/5l/l.h
src/cmd/5l/obj.c
src/cmd/5l/span.c
src/cmd/6l/6.out.h
src/cmd/6l/l.h
src/cmd/6l/obj.c
src/cmd/6l/optab.c
src/cmd/8l/8.out.h
src/cmd/8l/l.h
src/cmd/8l/obj.c
src/cmd/8l/optab.c
src/cmd/gc/pgen.c
src/cmd/ld/lib.c
src/pkg/runtime/extern.go
src/pkg/runtime/runtime.h
src/pkg/runtime/symtab.c
src/pkg/runtime/traceback_arm.c
src/pkg/runtime/traceback_x86.c

index 4e35cf75a7414797b205dbc81fbc6b0865a64c07..1fcdd3dd67b8372c0be47226235f084ae174dd81 100644 (file)
@@ -1189,6 +1189,9 @@ copyu(Prog *p, Adr *v, Adr *s)
                        if(v->reg == (uchar)REGARG)
                                return 3;
                return 0;
+
+       case ALOCALS:   /* funny */
+               return 0;
        }
 }
 
index c9870017772b4c49f57e0cced39794ebd35ced73..1ffe9dc85e17a9f4b9caba8b9412088dfb4da29b 100644 (file)
@@ -197,6 +197,7 @@ enum        as
        AMULAWB,
        
        AUSEFIELD,
+       ALOCALS,
 
        ALAST,
 };
index 0a04559e9a47eb688d2f54a662b3577412e794f7..ce4f720126407fcd570a87d115db0b866ab742d6 100644 (file)
@@ -147,6 +147,8 @@ struct      Sym
        int32   size;
        int32   align;  // if non-zero, required alignment in bytes
        int32   elfsym;
+       int32   locals; // size of stack frame locals area
+       int32   args;   // size of stack frame incoming arguments area
        uchar   special;
        uchar   fnptr;  // used as fn ptr
        uchar   stkcheck;
index 10c33f25d69c174dfd169fd69c94a7ca124eb5bd..c9e38dc3894bc67f5c3ac621300bb2ba30dd374e 100644 (file)
@@ -573,6 +573,11 @@ loop:
                pc++;
                break;
 
+       case ALOCALS:
+               cursym->locals = p->to.offset;
+               pc++;
+               break;
+
        case ATEXT:
                if(cursym != nil && cursym->text) {
                        histtoauto();
@@ -610,6 +615,7 @@ loop:
                s->type = STEXT;
                s->text = p;
                s->value = pc;
+               s->args = p->to.offset2;
                lastp = p;
                p->pc = pc;
                pc++;
index ece1ff89ce9511c3ec1bdea542f6063bc74c04bb..fd30e91a523c046257e1132895dcbccd1fcef8ad 100644 (file)
@@ -830,6 +830,7 @@ buildop(void)
                case ARFE:
                case ATEXT:
                case AUSEFIELD:
+               case ALOCALS:
                case ACASE:
                case ABCASE:
                        break;
index 3946861de458a74b5591e8ef97f3cf65b80369bb..d348c1304e08c74b9318db0e62e4d37556cdf9c6 100644 (file)
@@ -758,6 +758,7 @@ enum        as
        APSHUFD,
        
        AUSEFIELD,
+       ALOCALS,
 
        ALAST
 };
index b8b79133080459fd8d831009547890e8248ada3d..ffb8a45522e41d0fd9f68aea1c6cfb7b9e0c1e25 100644 (file)
@@ -154,6 +154,8 @@ struct      Sym
        int32   got;
        int32   align;  // if non-zero, required alignment in bytes
        int32   elfsym;
+       int32   locals; // size of stack frame locals area
+       int32   args;   // size of stack frame incoming arguments area
        Sym*    hash;   // in hash table
        Sym*    allsym; // in all symbol list
        Sym*    next;   // in text or data list
index 1cb4bd2aaa660d7bae76571a0f1b32ab01ee3bdf..e90a66e5dc9e4cf3ae86ff3dbabb3c6b06db1bd3 100644 (file)
@@ -586,6 +586,11 @@ loop:
                pc++;
                goto loop;
 
+       case ALOCALS:
+               cursym->locals = p->to.offset;
+               pc++;
+               goto loop;
+
        case ATEXT:
                s = p->from.sym;
                if(s->text != nil) {
@@ -629,6 +634,7 @@ loop:
                }
                s->type = STEXT;
                s->value = pc;
+               s->args = p->to.offset >> 32;
                lastp = p;
                p->pc = pc++;
                goto loop;
index 4f8406637c91089ef333918e5336aa8198c21cc3..43f34d9747ca6e41594749d5d80ddd106860c091 100644 (file)
@@ -1316,6 +1316,7 @@ Optab optab[] =
        { APSHUFD,      yaes2,  Pq,     0x70,(0) },
 
        { AUSEFIELD,    ynop,   Px, 0,0 },
+       { ALOCALS },
 
        { AEND },
        0
index 6a2d46c62ed38a583fb939d64e6b78c879295739..ae1397dd8d369c1fb6b3b4f99c0ee5646a41b0da 100644 (file)
@@ -568,6 +568,7 @@ enum        as
        AXORPS,
        
        AUSEFIELD,
+       ALOCALS,
 
        ALAST
 };
index 8b172f40473a57346e9305f398ea3d473be30930..f88f058e35f4569c01e5fd844c75445c636730d1 100644 (file)
@@ -138,6 +138,8 @@ struct      Sym
        int32   got;
        int32   align;  // if non-zero, required alignment in bytes
        int32   elfsym;
+       int32   locals; // size of stack frame locals area
+       int32   args;   // size of stack frame incoming arguments area
        Sym*    hash;   // in hash table
        Sym*    allsym; // in all symbol list
        Sym*    next;   // in text or data list
index 5704acd5ded113b9bf06d0093ec4ec477525544a..bd5684a3508e45fd67badbc8f93195dfa2d9804d 100644 (file)
@@ -595,6 +595,11 @@ loop:
                pc++;
                goto loop;
 
+       case ALOCALS:
+               cursym->locals = p->to.offset;
+               pc++;
+               goto loop;
+
        case ATEXT:
                s = p->from.sym;
                if(s->text != nil) {
@@ -633,6 +638,7 @@ loop:
                }
                s->type = STEXT;
                s->value = pc;
+               s->args = p->to.offset2;
                lastp = p;
                p->pc = pc++;
                goto loop;
index 865871ce5ce8d323b4406e6e35fd5f89d4a2886d..ae808ec77037d11ec8ab796bd6e7c262186b38ee 100644 (file)
@@ -961,6 +961,7 @@ Optab optab[] =
        { AXORPS,       yxm,    Pm, 0x57 },
 
        { AUSEFIELD,    ynop,   Px, 0,0 },
+       { ALOCALS },
 
        0
 };
index a07ad773425c99c89c199e4fb5cd6fe9dfb1dedf..23c71ae0e5c0c886c1c9a42cb6938ba410c2d6ed 100644 (file)
@@ -14,7 +14,7 @@ compile(Node *fn)
 {
        Plist *pl;
        Node nod1, *n;
-       Prog *ptxt;
+       Prog *plocals, *ptxt;
        int32 lno;
        Type *t;
        Iter save;
@@ -87,6 +87,8 @@ compile(Node *fn)
 
        ginit();
 
+       plocals = gins(ALOCALS, N, N);
+
        for(t=curfn->paramfld; t; t=t->down)
                gtrack(tracksym(t->type));
 
@@ -132,6 +134,9 @@ compile(Node *fn)
 
        oldstksize = stksize;
        allocauto(ptxt);
+
+       plocals->to.offset = stksize;
+
        if(0)
                print("allocauto: %lld to %lld\n", oldstksize, (vlong)stksize);
 
index d388236996fe8b44119d33176ed15bc2ec847fc5..4f0b87466b8b6b845304dbd0e4383b96a434f980 100644 (file)
@@ -1626,8 +1626,10 @@ genasmsym(void (*put)(Sym*, char*, int, vlong, vlong, int, Sym*))
 
                put(s, s->name, 'T', s->value, s->size, s->version, s->gotype);
 
-               /* frame, auto and param after */
+               /* frame, locals, args, auto and param after */
                put(nil, ".frame", 'm', s->text->to.offset+PtrSize, 0, 0, 0);
+               put(nil, ".locals", 'm', s->locals, 0, 0, 0);
+               put(nil, ".args", 'm', s->args, 0, 0, 0);
 
                for(a=s->autom; a; a=a->link)
                        if(a->type == D_AUTO)
index 8df005f952eb6ed05fe72f41ab646acef3eab527..fbaffd1d56b86fa2a630e6b0959f504f7d2a9c57 100644 (file)
@@ -42,8 +42,8 @@ type Func struct { // Keep in sync with runtime.h:struct Func
        pc0    uintptr // starting pc, ln for table
        ln0    int32
        frame  int32 // stack frame size
-       args   int32 // number of 32-bit in/out args
-       locals int32 // number of 32-bit locals
+       args   int32 // in/out args size
+       locals int32 // locals size
 }
 
 // FuncForPC returns a *Func describing the function that contains the
index 4ca7cc7dc9dfb49ff86f71dab90ae045588cb8b3..75a3d047d705e691a110c446f3251ba95ef791c4 100644 (file)
@@ -353,8 +353,8 @@ struct      Func
        uintptr pc0;    // starting pc, ln for table
        int32   ln0;
        int32   frame;  // stack frame size
-       int32   args;   // number of 32-bit in/out args
-       int32   locals; // number of 32-bit locals
+       int32   args;   // in/out args size
+       int32   locals; // locals size
 };
 
 // layout of Itab known to compilers
index 2cb7263ee775e36433317046b4c42701189064a6..85a1096d10053f5c492f6c717a0489bb768297db 100644 (file)
@@ -124,17 +124,17 @@ dofunc(Sym *sym)
                        f->frame = -sizeof(uintptr);
                break;
        case 'm':
-               if(nfunc > 0 && func != nil)
-                       func[nfunc-1].frame += sym->value;
-               break;
-       case 'p':
-               if(nfunc > 0 && func != nil) {
-                       f = &func[nfunc-1];
-                       // args counts 32-bit words.
-                       // sym->value is the arg's offset.
-                       // don't know width of this arg, so assume it is 64 bits.
-                       if(f->args < sym->value/4 + 2)
-                               f->args = sym->value/4 + 2;
+               if(nfunc <= 0 || func == nil)
+                       break;
+               if(runtime·strcmp(sym->name, (byte*)".frame") == 0)
+                       func[nfunc-1].frame = sym->value;
+               else if(runtime·strcmp(sym->name, (byte*)".locals") == 0)
+                       func[nfunc-1].locals = sym->value;
+               else if(runtime·strcmp(sym->name, (byte*)".args") == 0)
+                       func[nfunc-1].args = sym->value;
+               else {
+                       runtime·printf("invalid 'm' symbol named '%s'\n", sym->name);
+                       runtime·throw("mangled symbol table");
                }
                break;
        case 'f':
index 8ce000c1fe682afabfdd9d1a4383c2cba18e4218..5c831685e4d0265d6bddf1ef1a48654bfc8c58cd 100644 (file)
@@ -128,7 +128,7 @@ runtime·gentraceback(byte *pc0, byte *sp, byte *lr0, G *gp, int32 skip, uintptr
                                if(m->throwing && gp == m->curg)
                                        runtime·printf("[fp=%p] ", fp);
                                runtime·printf("%S(", f->name);
-                               for(i = 0; i < f->args; i++) {
+                               for(i = 0; i < f->args/sizeof(uintptr); i++) {
                                        if(i != 0)
                                                runtime·prints(", ");
                                        runtime·printhex(((uintptr*)fp)[1+i]);
index a11df6b781030c5ef77de65a5d0a6d460546092b..f5d8f2a3ffa5a7737065e0b179b3ab64977cf3e5 100644 (file)
@@ -130,7 +130,7 @@ runtime·gentraceback(byte *pc0, byte *sp, byte *lr0, G *gp, int32 skip, uintptr
                                if(m->throwing && gp == m->curg)
                                        runtime·printf("[fp=%p] ", fp);
                                runtime·printf("%S(", f->name);
-                               for(i = 0; i < f->args; i++) {
+                               for(i = 0; i < f->args/sizeof(uintptr); i++) {
                                        if(i != 0)
                                                runtime·prints(", ");
                                        runtime·printhex(((uintptr*)fp)[i]);