Commit d704bb0d authored by Alex Brainman's avatar Alex Brainman

cmd/ld: do not assume that only pe section names start with '.'

Our current pe object reader assumes that every symbol starting with
'.' is section. It appeared to be true, until now gcc 4.9.1 generates
some symbols with '.' at the front. Change that logic to check other
symbol fields in addition to checking for '.'. I am not an expert
here, but it seems reasonable to me.

Added test, but it is only good, if tested with gcc 4.9.1. Otherwise
the test PASSes regardless.

Fixes #8811.
Fixes #8856.

LGTM=jfrederich, iant, stephen.gutekanst
R=golang-codereviews, jfrederich, stephen.gutekanst, iant
CC=alex.brainman, golang-codereviews
https://golang.org/cl/152410043
parent d0ee959a
...@@ -59,6 +59,7 @@ func Test8092(t *testing.T) { test8092(t) } ...@@ -59,6 +59,7 @@ func Test8092(t *testing.T) { test8092(t) }
func Test7978(t *testing.T) { test7978(t) } func Test7978(t *testing.T) { test7978(t) }
func Test8694(t *testing.T) { test8694(t) } func Test8694(t *testing.T) { test8694(t) }
func Test8517(t *testing.T) { test8517(t) } func Test8517(t *testing.T) { test8517(t) }
func Test8811(t *testing.T) { test8811(t) }
func TestReturnAfterGrow(t *testing.T) { testReturnAfterGrow(t) } func TestReturnAfterGrow(t *testing.T) { testReturnAfterGrow(t) }
func TestReturnAfterGrowFromGo(t *testing.T) { testReturnAfterGrowFromGo(t) } func TestReturnAfterGrowFromGo(t *testing.T) { testReturnAfterGrowFromGo(t) }
......
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
int issue8811Initialized = 0;
void issue8811Init() {
}
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cgotest
/*
extern int issue8811Initialized;
extern void issue8811Init();
void issue8811Execute() {
if(!issue8811Initialized)
issue8811Init();
}
*/
import "C"
import "testing"
func test8811(t *testing.T) {
C.issue8811Execute()
}
...@@ -128,6 +128,7 @@ struct PeObj { ...@@ -128,6 +128,7 @@ struct PeObj {
}; };
static int map(PeObj *obj, PeSect *sect); static int map(PeObj *obj, PeSect *sect);
static int issect(PeSym *s);
static int readsym(PeObj *obj, int i, PeSym **sym); static int readsym(PeObj *obj, int i, PeSym **sym);
void void
...@@ -318,7 +319,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn) ...@@ -318,7 +319,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
// ld -r could generate multiple section symbols for the // ld -r could generate multiple section symbols for the
// same section but with different values, we have to take // same section but with different values, we have to take
// that into account // that into account
if (obj->pesym[symindex].name[0] == '.') if(issect(&obj->pesym[symindex]))
rp->add += obj->pesym[symindex].value; rp->add += obj->pesym[symindex].value;
} }
qsort(r, rsect->sh.NumberOfRelocations, sizeof r[0], rbyoff); qsort(r, rsect->sh.NumberOfRelocations, sizeof r[0], rbyoff);
...@@ -332,7 +333,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn) ...@@ -332,7 +333,7 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn)
for(i=0; i<obj->npesym; i++) { for(i=0; i<obj->npesym; i++) {
if(obj->pesym[i].name == 0) if(obj->pesym[i].name == 0)
continue; continue;
if(obj->pesym[i].name[0] == '.') //skip section if(issect(&obj->pesym[i]))
continue; continue;
if(obj->pesym[i].sectnum > 0) { if(obj->pesym[i].sectnum > 0) {
sect = &obj->sect[obj->pesym[i].sectnum-1]; sect = &obj->sect[obj->pesym[i].sectnum-1];
...@@ -430,6 +431,12 @@ map(PeObj *obj, PeSect *sect) ...@@ -430,6 +431,12 @@ map(PeObj *obj, PeSect *sect)
return 0; return 0;
} }
static int
issect(PeSym *s)
{
return s->sclass == IMAGE_SYM_CLASS_STATIC && s->type == 0 && s->name[0] == '.';
}
static int static int
readsym(PeObj *obj, int i, PeSym **y) readsym(PeObj *obj, int i, PeSym **y)
{ {
...@@ -445,7 +452,7 @@ readsym(PeObj *obj, int i, PeSym **y) ...@@ -445,7 +452,7 @@ readsym(PeObj *obj, int i, PeSym **y)
sym = &obj->pesym[i]; sym = &obj->pesym[i];
*y = sym; *y = sym;
if(sym->name[0] == '.') // .section if(issect(sym))
name = obj->sect[sym->sectnum-1].sym->name; name = obj->sect[sym->sectnum-1].sym->name;
else { else {
name = sym->name; name = sym->name;
......
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