From 9add729a1f537f05941d80a10818cf1562a7ea6b Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Wed, 18 Sep 2013 22:27:25 -0400 Subject: [PATCH] cmd/ld: handle duplicate static symbols in COFF and Mach-O files. Fixes #5740. R=iant, rsc, luisbebop CC=gobot, golang-dev https://golang.org/cl/10345046 --- misc/cgo/test/issue5740.go | 15 +++++++++++++++ misc/cgo/test/issue5740a.c | 9 +++++++++ misc/cgo/test/issue5740b.c | 9 +++++++++ src/cmd/ld/ldmacho.c | 2 ++ src/cmd/ld/ldpe.c | 1 + 5 files changed, 36 insertions(+) create mode 100644 misc/cgo/test/issue5740.go create mode 100644 misc/cgo/test/issue5740a.c create mode 100644 misc/cgo/test/issue5740b.c diff --git a/misc/cgo/test/issue5740.go b/misc/cgo/test/issue5740.go new file mode 100644 index 00000000000..25c86153fd5 --- /dev/null +++ b/misc/cgo/test/issue5740.go @@ -0,0 +1,15 @@ +// Copyright 2013 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 + +// int test5740a(void), test5740b(void); +import "C" +import "testing" + +func test5740(t *testing.T) { + if v := C.test5740a() + C.test5740b(); v != 5 { + t.Errorf("expected 5, got %v", v) + } +} diff --git a/misc/cgo/test/issue5740a.c b/misc/cgo/test/issue5740a.c new file mode 100644 index 00000000000..25f18e2a455 --- /dev/null +++ b/misc/cgo/test/issue5740a.c @@ -0,0 +1,9 @@ +// Copyright 2013 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. + +static int volatile val = 2; + +int test5740a() { + return val; +} diff --git a/misc/cgo/test/issue5740b.c b/misc/cgo/test/issue5740b.c new file mode 100644 index 00000000000..22893f35bd8 --- /dev/null +++ b/misc/cgo/test/issue5740b.c @@ -0,0 +1,9 @@ +// Copyright 2013 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. + +static int volatile val = 3; + +int test5740b() { + return val; +} diff --git a/src/cmd/ld/ldmacho.c b/src/cmd/ld/ldmacho.c index 98a4eeac3ca..e0f5405f69c 100644 --- a/src/cmd/ld/ldmacho.c +++ b/src/cmd/ld/ldmacho.c @@ -611,6 +611,8 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn) if(!(sym->type&N_EXT)) v = version; s = lookup(name, v); + if(!(sym->type&N_EXT)) + s->dupok = 1; sym->sym = s; if(sym->sectnum == 0) // undefined continue; diff --git a/src/cmd/ld/ldpe.c b/src/cmd/ld/ldpe.c index 033e522f277..6ed861d7f0c 100644 --- a/src/cmd/ld/ldpe.c +++ b/src/cmd/ld/ldpe.c @@ -469,6 +469,7 @@ readsym(PeObj *obj, int i, PeSym **y) case IMAGE_SYM_CLASS_NULL: case IMAGE_SYM_CLASS_STATIC: s = lookup(name, version); + s->dupok = 1; break; default: werrstr("%s: invalid symbol binding %d", sym->name, sym->sclass);