From: Rémy Oudompheng Date: Wed, 9 Jan 2013 21:02:53 +0000 (+0100) Subject: cmd/gc: add space to export data to match linker expectations X-Git-Tag: go1.1rc2~1438 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8fff2525cb37a71703b2e54efd3cfc74f7b96414;p=gostls13.git cmd/gc: add space to export data to match linker expectations The linker split PKGDEF into (prefix, name, def) pairs, and defines def to begin after a space following the identifier. This is totally wrong for the following export data: func "".FunctionName() var SomethingCompletelyUnrelated int The linker would parse name=`"".FunctionName()\n\tvar` def=`SomethingCompletelyUnrelated int` since there is no space after FunctionName. R=minux.ma, rsc CC=golang-dev https://golang.org/cl/7068051 --- diff --git a/src/cmd/gc/export.c b/src/cmd/gc/export.c index 4d0368ef09..b235f676cd 100644 --- a/src/cmd/gc/export.c +++ b/src/cmd/gc/export.c @@ -220,10 +220,11 @@ dumpexportvar(Sym *s) // currently that can leave unresolved ONONAMEs in import-dot-ed packages in the wrong package if(debug['l'] < 2) typecheckinl(n); - Bprint(bout, "\tfunc %#S%#hT { %#H }\n", s, t, n->inl); + // NOTE: The space after %#S here is necessary for ld's export data parser. + Bprint(bout, "\tfunc %#S %#hT { %#H }\n", s, t, n->inl); reexportdeplist(n->inl); } else - Bprint(bout, "\tfunc %#S%#hT\n", s, t); + Bprint(bout, "\tfunc %#S %#hT\n", s, t); } else Bprint(bout, "\tvar %#S %#T\n", s, t); } @@ -282,10 +283,10 @@ dumpexporttype(Type *t) // currently that can leave unresolved ONONAMEs in import-dot-ed packages in the wrong package if(debug['l'] < 2) typecheckinl(f->type->nname); - Bprint(bout, "\tfunc (%#T) %#hhS%#hT { %#H }\n", getthisx(f->type)->type, f->sym, f->type, f->type->nname->inl); + Bprint(bout, "\tfunc (%#T) %#hhS %#hT { %#H }\n", getthisx(f->type)->type, f->sym, f->type, f->type->nname->inl); reexportdeplist(f->type->nname->inl); } else - Bprint(bout, "\tfunc (%#T) %#hhS%#hT\n", getthisx(f->type)->type, f->sym, f->type); + Bprint(bout, "\tfunc (%#T) %#hhS %#hT\n", getthisx(f->type)->type, f->sym, f->type); } } diff --git a/test/fixedbugs/bug472.dir/p1.go b/test/fixedbugs/bug472.dir/p1.go new file mode 100644 index 0000000000..9d47fd84a7 --- /dev/null +++ b/test/fixedbugs/bug472.dir/p1.go @@ -0,0 +1,17 @@ +// 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 p1 + +import "runtime" + +func E() func() int { return runtime.NumCPU } + +func F() func() { return runtime.Gosched } + +func G() func() string { return runtime.GOROOT } + +func H() func() { return runtime.GC } + +func I() func() string { return runtime.Version } diff --git a/test/fixedbugs/bug472.dir/p2.go b/test/fixedbugs/bug472.dir/p2.go new file mode 100644 index 0000000000..34a3f0487a --- /dev/null +++ b/test/fixedbugs/bug472.dir/p2.go @@ -0,0 +1,17 @@ +// 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 p2 + +import "runtime" + +func E() func() int { return runtime.NumCPU } + +func F() func() { return runtime.GC } + +func G() func() string { return runtime.GOROOT } + +func H() func() { return runtime.Gosched } + +func I() func() string { return runtime.Version } diff --git a/test/fixedbugs/bug472.dir/z.go b/test/fixedbugs/bug472.dir/z.go new file mode 100644 index 0000000000..6c29dd08c6 --- /dev/null +++ b/test/fixedbugs/bug472.dir/z.go @@ -0,0 +1,13 @@ +// 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 ( + _ "./p1" + _ "./p2" +) + +func main() { +} diff --git a/test/fixedbugs/bug472.go b/test/fixedbugs/bug472.go new file mode 100644 index 0000000000..c79c64ca1f --- /dev/null +++ b/test/fixedbugs/bug472.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. + +// Linker would incorrectly parse export data and think +// definitions are inconsistent. + +package ignored