From cf78f96244ec8e3a69f10069fb43dd720f1556b0 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Tue, 6 May 2014 11:40:43 +1000 Subject: [PATCH] cmd/ld: correct pe section number in symbol table Update #7899 LGTM=iant R=golang-codereviews, rsc, iant CC=golang-codereviews https://golang.org/cl/97920044 --- src/cmd/ld/pe.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/cmd/ld/pe.c b/src/cmd/ld/pe.c index 27c5574363..c26cd5264a 100644 --- a/src/cmd/ld/pe.c +++ b/src/cmd/ld/pe.c @@ -84,6 +84,7 @@ struct COFFSym LSym* sym; int strtbloff; int sect; + vlong value; }; static COFFSym* coffsym; @@ -476,6 +477,7 @@ newPEDWARFSection(char *name, vlong size) static void addsym(LSym *s, char *name, int type, vlong addr, vlong size, int ver, LSym *gotype) { + COFFSym *cs; USED(name); USED(addr); USED(size); @@ -498,28 +500,25 @@ addsym(LSym *s, char *name, int type, vlong addr, vlong size, int ver, LSym *got } if(coffsym) { - coffsym[ncoffsym].sym = s; + cs = &coffsym[ncoffsym]; + cs->sym = s; if(strlen(s->name) > 8) - coffsym[ncoffsym].strtbloff = strtbladd(s->name); - if(type == 'T') - coffsym[ncoffsym].sect = textsect; - else - coffsym[ncoffsym].sect = datasect; + cs->strtbloff = strtbladd(s->name); + if(s->value >= segdata.vaddr) { + cs->value = s->value - segdata.vaddr; + cs->sect = datasect; + } else if(s->value >= segtext.vaddr) { + cs->value = s->value - segtext.vaddr; + cs->sect = textsect; + } else { + cs->value = 0; + cs->sect = 0; + diag("addsym %#llx", addr); + } } ncoffsym++; } -static vlong -datoffsect(vlong addr) -{ - if(addr >= segdata.vaddr) - return addr - segdata.vaddr; - if(addr >= segtext.vaddr) - return addr - segtext.vaddr; - diag("datoff %#llx", addr); - return 0; -} - static void addsymtable(void) { @@ -551,7 +550,7 @@ addsymtable(void) lputl(0); lputl(s->strtbloff); } - lputl(datoffsect(s->sym->value)); + lputl(s->value); wputl(s->sect); wputl(0x0308); // "array of structs" cput(2); // storage class: external -- 2.50.0