]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: add space to export data to match linker expectations
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 9 Jan 2013 21:02:53 +0000 (22:02 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 9 Jan 2013 21:02:53 +0000 (22:02 +0100)
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

src/cmd/gc/export.c
test/fixedbugs/bug472.dir/p1.go [new file with mode: 0644]
test/fixedbugs/bug472.dir/p2.go [new file with mode: 0644]
test/fixedbugs/bug472.dir/z.go [new file with mode: 0644]
test/fixedbugs/bug472.go [new file with mode: 0644]

index 4d0368ef0974055c62efe4c7623ddfe9db9e39e4..b235f676cdc13e01d3cb71848af842e8f2969143 100644 (file)
@@ -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 (file)
index 0000000..9d47fd8
--- /dev/null
@@ -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 (file)
index 0000000..34a3f04
--- /dev/null
@@ -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 (file)
index 0000000..6c29dd0
--- /dev/null
@@ -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 (file)
index 0000000..c79c64c
--- /dev/null
@@ -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