]> Cypherpunks repositories - gostls13.git/commitdiff
ld: fix dwarf decoding of strings for struct's fieldnames
authorLuuk van Dijk <lvd@golang.org>
Mon, 11 Apr 2011 20:38:37 +0000 (16:38 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 11 Apr 2011 20:38:37 +0000 (16:38 -0400)
Moved Sym printing to Yconv.
Fixed warning in data.c

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

src/cmd/ld/data.c
src/cmd/ld/dwarf.c
src/cmd/ld/lib.c
src/cmd/ld/lib.h

index 32dba459640fe8261b9dbc7155c1edd8c3b1e489..d27416dac12623cdcd3eeb4753ed4862ecc1f261 100644 (file)
@@ -722,7 +722,7 @@ addsize(Sym *s, Sym *t)
 void
 dodata(void)
 {
-       int32 h, t, datsize;
+       int32 t, datsize;
        Section *sect;
        Sym *s, *last, **l;
 
index bfdb1e7989e56c6ced4f313c72c09eacb5acee36..d0b64077964e0c30b86c66dff1f6be325093dc0f 100644 (file)
@@ -6,7 +6,6 @@
 //   - eliminate DW_CLS_ if not used
 //   - package info in compilation units
 //   - assign global variables and types to their packages
-//   - (upstream) type info for C parts of runtime
 //   - gdb uses c syntax, meaning clumsy quoting is needed for go identifiers. eg
 //     ptype struct '[]uint8' and qualifiers need to be quoted away
 //   - lexical scoping is lost, so gdb gets confused as to which 'main.i' you mean.
@@ -943,14 +942,16 @@ enum {
 static char*
 decodetype_structfieldname(Sym *s, int i)
 {
+       Reloc *r;
+
        // go.string."foo"  0x28 / 0x40
        s = decode_reloc_sym(s, CommonSize + PtrSize + 2*4 + i*StructFieldSize);
        if (s == nil)                   // embedded structs have a nil name.
                return nil;
-       s = decode_reloc_sym(s, 0);     // string."foo"
-       if (s == nil)                   // shouldn't happen.
+       r = decode_reloc(s, 0);         // s has a pointer to the string data at offset 0
+       if (r == nil)                   // shouldn't happen.
                return nil;
-       return (char*)s->p;             // the c-string
+       return (char*) r->sym->p + r->add;      // the c-string
 }
 
 static Sym*
@@ -1021,22 +1022,8 @@ defgotype(Sym *gotype)
        if (die != nil)
                return die;
 
-       if (0 && debug['v'] > 2) {
-               print("new type: %s @0x%08x [%d]", gotype->name, gotype->value, gotype->size);
-               for (i = 0; i < gotype->size; i++) {
-                       if (!(i%8)) print("\n\t%04x ", i);
-                       print("%02x ", gotype->p[i]);
-               }
-               print("\n");
-               for (i = 0; i < gotype->nr; i++) {
-                       print("\t0x%02x[%x] %d %s[%llx]\n",
-                             gotype->r[i].off,
-                             gotype->r[i].siz,
-                             gotype->r[i].type,
-                             gotype->r[i].sym->name,
-                             (vlong)gotype->r[i].add);
-               }
-       }
+       if (0 && debug['v'] > 2)
+               print("new type: %Y\n", gotype);
 
        kind = decodetype_kind(gotype);
        bytesize = decodetype_size(gotype);
@@ -2321,7 +2308,7 @@ dwarfemitdebugsections(void)
 {
        vlong infoe;
        DWDie* die;
-return;
+
        // For diagnostic messages.
        newattr(&dwtypes, DW_AT_name, DW_CLS_STRING, strlen("dwtypes"), "dwtypes");
 
index 75776bbc24156fd15946b49720dfc2958c791688..8cd570463c8dd70fd2d309b964cb37ceb868f5ec 100644 (file)
@@ -61,6 +61,7 @@ void
 libinit(void)
 {
        fmtinstall('i', iconv);
+       fmtinstall('Y', Yconv);
        mywhatsys();    // get goroot, goarch, goos
        if(strcmp(goarch, thestring) != 0)
                print("goarch is not known: %s\n", goarch);
@@ -847,7 +848,7 @@ unmal(void *v, uint32 n)
 // Copied from ../gc/subr.c:/^pathtoprefix; must stay in sync.
 /*
  * Convert raw string to the prefix that will be used in the symbol table.
- * Invalid bytes turn into %xx.  Right now the only bytes that need
+ * Invalid bytes turn into %xx.         Right now the only bytes that need
  * escaping are %, ., and ", but we escape all control characters too.
  */
 static char*
@@ -1122,7 +1123,7 @@ static Sym *newstack;
 enum
 {
        HasLinkRegister = (thechar == '5'),
-       CallSize = (!HasLinkRegister)*PtrSize,  // bytes of stack required for a call
+       CallSize = (!HasLinkRegister)*PtrSize,  // bytes of stack required for a call
 };
 
 void
@@ -1148,7 +1149,7 @@ dostkcheck(void)
        
        // Check calling contexts.
        // Some nosplits get called a little further down,
-       // like newproc and deferproc.  We could hard-code
+       // like newproc and deferproc.  We could hard-code
        // that knowledge but it's more robust to look at
        // the actual call sites.
        for(s = textp; s != nil; s = s->next) {
@@ -1307,3 +1308,38 @@ undef(void)
                if(s->type == SXREF)
                        diag("%s(%d): not defined", s->name, s->version);
 }
+
+int
+Yconv(Fmt *fp)
+{
+       Sym *s;
+       Fmt fmt;
+       int i;
+       char *str;
+
+       s = va_arg(fp->args, Sym*);
+       if (s == S) {
+               fmtprint(fp, "<nil>");
+       } else {
+               fmtstrinit(&fmt);
+               fmtprint(&fmt, "%s @0x%08x [%d]", s->name, s->value, s->size);
+               for (i = 0; i < s->size; i++) {
+                       if (!(i%8)) fmtprint(&fmt,  "\n\t0x%04x ", i);
+                       fmtprint(&fmt, "%02x ", s->p[i]);
+               }
+               fmtprint(&fmt, "\n");
+               for (i = 0; i < s->nr; i++) {
+                       fmtprint(&fmt, "\t0x%04x[%x] %d %s[%llx]\n",
+                             s->r[i].off,
+                             s->r[i].siz,
+                             s->r[i].type,
+                             s->r[i].sym->name,
+                             (vlong)s->r[i].add);
+               }
+               str = fmtstrflush(&fmt);
+               fmtstrcpy(fp, str);
+               free(str);
+       }
+
+       return 0;
+}
index df90923612c344849a59b9802877610d685beee9..646aeb53565ab1a4a73273de2c069475af570a2a 100644 (file)
@@ -274,3 +274,6 @@ EXTERN      char*   headstring;
 extern Header  headers[];
 
 int    headtype(char*);
+
+int    Yconv(Fmt*);
+#pragma        varargck        type    "Y"     Sym*