Commit cf78f962 authored by Alex Brainman's avatar Alex Brainman

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
parent 0462d091
...@@ -84,6 +84,7 @@ struct COFFSym ...@@ -84,6 +84,7 @@ struct COFFSym
LSym* sym; LSym* sym;
int strtbloff; int strtbloff;
int sect; int sect;
vlong value;
}; };
static COFFSym* coffsym; static COFFSym* coffsym;
...@@ -476,6 +477,7 @@ newPEDWARFSection(char *name, vlong size) ...@@ -476,6 +477,7 @@ newPEDWARFSection(char *name, vlong size)
static void static void
addsym(LSym *s, char *name, int type, vlong addr, vlong size, int ver, LSym *gotype) addsym(LSym *s, char *name, int type, vlong addr, vlong size, int ver, LSym *gotype)
{ {
COFFSym *cs;
USED(name); USED(name);
USED(addr); USED(addr);
USED(size); USED(size);
...@@ -498,28 +500,25 @@ addsym(LSym *s, char *name, int type, vlong addr, vlong size, int ver, LSym *got ...@@ -498,28 +500,25 @@ addsym(LSym *s, char *name, int type, vlong addr, vlong size, int ver, LSym *got
} }
if(coffsym) { if(coffsym) {
coffsym[ncoffsym].sym = s; cs = &coffsym[ncoffsym];
cs->sym = s;
if(strlen(s->name) > 8) if(strlen(s->name) > 8)
coffsym[ncoffsym].strtbloff = strtbladd(s->name); cs->strtbloff = strtbladd(s->name);
if(type == 'T') if(s->value >= segdata.vaddr) {
coffsym[ncoffsym].sect = textsect; cs->value = s->value - segdata.vaddr;
else cs->sect = datasect;
coffsym[ncoffsym].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++; 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 static void
addsymtable(void) addsymtable(void)
{ {
...@@ -551,7 +550,7 @@ addsymtable(void) ...@@ -551,7 +550,7 @@ addsymtable(void)
lputl(0); lputl(0);
lputl(s->strtbloff); lputl(s->strtbloff);
} }
lputl(datoffsect(s->sym->value)); lputl(s->value);
wputl(s->sect); wputl(s->sect);
wputl(0x0308); // "array of structs" wputl(0x0308); // "array of structs"
cput(2); // storage class: external cput(2); // storage class: external
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment