]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: handle weak symbols
authorShenghou Ma <minux.ma@gmail.com>
Tue, 30 Oct 2012 15:58:43 +0000 (23:58 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Tue, 30 Oct 2012 15:58:43 +0000 (23:58 +0800)
compiler_rt introduces a weak and hidden symbol compilerrt_abort_impl
into our pre-linked _all.o object, we have to handle it.

Fixes #4273.

R=iant, rsc, r
CC=golang-dev
https://golang.org/cl/6783050

misc/cgo/test/issue4273.c [new file with mode: 0644]
misc/cgo/test/issue4273b.c [new file with mode: 0644]
src/cmd/ld/ldelf.c

diff --git a/misc/cgo/test/issue4273.c b/misc/cgo/test/issue4273.c
new file mode 100644 (file)
index 0000000..a3fcf3b
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2012 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.
+
+#ifdef __ELF__
+__attribute__((weak))
+__attribute__((visibility("hidden")))
+void _compilerrt_abort_impl(const char *file, int line, const char *func) {
+}
+#endif
diff --git a/misc/cgo/test/issue4273b.c b/misc/cgo/test/issue4273b.c
new file mode 100644 (file)
index 0000000..93e2f4f
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2012 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.
+
+#ifdef __ELF__
+extern void _compilerrt_abort_impl(const char *file, int line, const char *func);
+
+void __my_abort(const char *file, int line, const char *func) {
+       _compilerrt_abort_impl(file, line, func);
+}
+#endif
index e0f989c065aaf15c8ed9c8b0edb0f0f3fd733968..19c582b00745e0da8b0d28966dbc62df077dcd36 100644 (file)
@@ -807,6 +807,13 @@ readsym(ElfObj *obj, int i, ElfSym *sym, int needSym)
                                        s->type = SHIDDEN;
                                }
                        break;
+               case ElfSymBindWeak:
+                       if(needSym) {
+                               s = newsym(sym->name, 0);
+                               if(sym->other == 2)
+                                       s->type = SHIDDEN;
+                       }
+                       break;
                default:
                        werrstr("%s: invalid symbol binding %d", sym->name, sym->bind);
                        return -1;