]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: handle duplicate static symbols in COFF and Mach-O files.
authorShenghou Ma <minux.ma@gmail.com>
Thu, 19 Sep 2013 02:27:25 +0000 (22:27 -0400)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 19 Sep 2013 02:27:25 +0000 (22:27 -0400)
Fixes #5740.

R=iant, rsc, luisbebop
CC=gobot, golang-dev
https://golang.org/cl/10345046

misc/cgo/test/issue5740.go [new file with mode: 0644]
misc/cgo/test/issue5740a.c [new file with mode: 0644]
misc/cgo/test/issue5740b.c [new file with mode: 0644]
src/cmd/ld/ldmacho.c
src/cmd/ld/ldpe.c

diff --git a/misc/cgo/test/issue5740.go b/misc/cgo/test/issue5740.go
new file mode 100644 (file)
index 0000000..25c8615
--- /dev/null
@@ -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 (file)
index 0000000..25f18e2
--- /dev/null
@@ -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 (file)
index 0000000..22893f3
--- /dev/null
@@ -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;
+}
index 98a4eeac3ca07b73ac6d04e4c6bbf575899330a5..e0f5405f69cae0d795e67fdb92317657e5e230ce 100644 (file)
@@ -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;
index 033e522f277eb9e78262687dd8129849f65167fc..6ed861d7f0cd0aa31373f4a7b975e9aa8e600f3a 100644 (file)
@@ -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);