aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuuk van Dijk <lvd@golang.org>2011-04-11 16:38:37 -0400
committerRuss Cox <rsc@golang.org>2011-04-11 16:38:37 -0400
commit0cc055e8f78d3e7c790fdcf4fb44f2d2c4eea396 (patch)
tree48ff94be7f19867723facf28c50d3a06dd745413
parentd36271a3e5ae67b3a25a9bfaab71f5a91269402d (diff)
downloadgo-0cc055e8f78d3e7c790fdcf4fb44f2d2c4eea396.tar.gz
go-0cc055e8f78d3e7c790fdcf4fb44f2d2c4eea396.zip
ld: fix dwarf decoding of strings for struct's fieldnames
Moved Sym printing to Yconv. Fixed warning in data.c R=rsc CC=golang-dev https://golang.org/cl/4378052
-rw-r--r--src/cmd/ld/data.c2
-rw-r--r--src/cmd/ld/dwarf.c29
-rw-r--r--src/cmd/ld/lib.c42
-rw-r--r--src/cmd/ld/lib.h3
4 files changed, 51 insertions, 25 deletions
diff --git a/src/cmd/ld/data.c b/src/cmd/ld/data.c
index 32dba45964..d27416dac1 100644
--- a/src/cmd/ld/data.c
+++ b/src/cmd/ld/data.c
@@ -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;
diff --git a/src/cmd/ld/dwarf.c b/src/cmd/ld/dwarf.c
index bfdb1e7989..d0b6407796 100644
--- a/src/cmd/ld/dwarf.c
+++ b/src/cmd/ld/dwarf.c
@@ -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");
diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c
index 75776bbc24..8cd570463c 100644
--- a/src/cmd/ld/lib.c
+++ b/src/cmd/ld/lib.c
@@ -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;
+}
diff --git a/src/cmd/ld/lib.h b/src/cmd/ld/lib.h
index df90923612..646aeb5356 100644
--- a/src/cmd/ld/lib.h
+++ b/src/cmd/ld/lib.h
@@ -274,3 +274,6 @@ EXTERN char* headstring;
extern Header headers[];
int headtype(char*);
+
+int Yconv(Fmt*);
+#pragma varargck type "Y" Sym*