From d815a147187c0237a81e84e39035f6275b3fee42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Oudompheng?= Date: Mon, 25 Mar 2013 22:09:55 +0100 Subject: [PATCH] cmd/5l, cmd/6l, cmd/8l: fix segfault on reading LOCALS for a duplicate definition. Fixes #5105. R=golang-dev, dave, daniel.morsing, rsc CC=golang-dev https://golang.org/cl/7965043 --- src/cmd/5l/obj.c | 4 ++++ src/cmd/6l/obj.c | 4 ++++ src/cmd/8l/obj.c | 4 ++++ test/fixedbugs/issue5105.dir/a.go | 7 +++++++ test/fixedbugs/issue5105.dir/b.go | 15 +++++++++++++++ test/fixedbugs/issue5105.go | 10 ++++++++++ 6 files changed, 44 insertions(+) create mode 100644 test/fixedbugs/issue5105.dir/a.go create mode 100644 test/fixedbugs/issue5105.dir/b.go create mode 100644 test/fixedbugs/issue5105.go diff --git a/src/cmd/5l/obj.c b/src/cmd/5l/obj.c index d38da204a37..f5128c6780f 100644 --- a/src/cmd/5l/obj.c +++ b/src/cmd/5l/obj.c @@ -608,11 +608,15 @@ loop: break; case ALOCALS: + if(skip) + goto casedef; cursym->locals = p->to.offset; pc++; break; case ATYPE: + if(skip) + goto casedef; pc++; goto loop; diff --git a/src/cmd/6l/obj.c b/src/cmd/6l/obj.c index 3775df9de5c..ab8b22e231b 100644 --- a/src/cmd/6l/obj.c +++ b/src/cmd/6l/obj.c @@ -597,11 +597,15 @@ loop: goto loop; case ALOCALS: + if(skip) + goto casdef; cursym->locals = p->to.offset; pc++; goto loop; case ATYPE: + if(skip) + goto casdef; pc++; goto loop; diff --git a/src/cmd/8l/obj.c b/src/cmd/8l/obj.c index 306e288a357..fda96d09caa 100644 --- a/src/cmd/8l/obj.c +++ b/src/cmd/8l/obj.c @@ -607,11 +607,15 @@ loop: goto loop; case ALOCALS: + if(skip) + goto casdef; cursym->locals = p->to.offset; pc++; goto loop; case ATYPE: + if(skip) + goto casdef; pc++; goto loop; diff --git a/test/fixedbugs/issue5105.dir/a.go b/test/fixedbugs/issue5105.dir/a.go new file mode 100644 index 00000000000..f20abb98bfa --- /dev/null +++ b/test/fixedbugs/issue5105.dir/a.go @@ -0,0 +1,7 @@ +// 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 a + +var A = [2]string{"hello", "world"} diff --git a/test/fixedbugs/issue5105.dir/b.go b/test/fixedbugs/issue5105.dir/b.go new file mode 100644 index 00000000000..b12e739e33a --- /dev/null +++ b/test/fixedbugs/issue5105.dir/b.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 main + +import "./a" + +var B = [2]string{"world", "hello"} + +func main() { + if a.A[0] != B[1] { + panic("bad hello") + } +} diff --git a/test/fixedbugs/issue5105.go b/test/fixedbugs/issue5105.go new file mode 100644 index 00000000000..e3e5e5caa46 --- /dev/null +++ b/test/fixedbugs/issue5105.go @@ -0,0 +1,10 @@ +// rundir + +// 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. + +// Issue 5105: linker segfaults on duplicate definition +// of a type..hash.* function. + +package ignored