]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: call objabi.PathToPrefix when emitting abstract fn
authorThan McIntosh <thanm@google.com>
Tue, 10 Jul 2018 16:23:31 +0000 (12:23 -0400)
committerThan McIntosh <thanm@google.com>
Tue, 10 Jul 2018 18:54:39 +0000 (18:54 +0000)
When generating an abstract function DIE, call objabi.PathToPrefix on
the import path so as to be consistent with how the linker handles
import paths. This is intended to resolve another problem with DWARF
inline info generation in which there are multiple inconsistent
versions of an abstract function DIE for a function whose package path
is rewritten/canonicalized by objabi.PathToPrefix.

Fixes #26237

Change-Id: I4b64c090ae43a1ad87f47587a1a71f19bc5fc8e8
Reviewed-on: https://go-review.googlesource.com/123036
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/dwarf/dwarf.go
src/cmd/link/internal/ld/dwarf_test.go
src/cmd/link/internal/ld/testdata/issue26237/src/b.dir/b.go [new file with mode: 0644]
src/cmd/link/internal/ld/testdata/issue26237/src/main/main.go [new file with mode: 0644]

index edb84498f90183f7a71d82d762dc68ad4866c5c5..96fb2b765b8eb567fa95d9c0d97d0c868d2578b2 100644 (file)
@@ -8,6 +8,7 @@
 package dwarf
 
 import (
+       "cmd/internal/objabi"
        "errors"
        "fmt"
        "sort"
@@ -1096,7 +1097,7 @@ func PutAbstractFunc(ctxt Context, s *FnState) error {
                // be rewritten, since it would change the offsets of the
                // child DIEs (which we're relying on in order for abstract
                // origin references to work).
-               fullname = s.Importpath + "." + s.Name[3:]
+               fullname = objabi.PathToPrefix(s.Importpath) + "." + s.Name[3:]
        }
        putattr(ctxt, s.Absfn, abbrev, DW_FORM_string, DW_CLS_STRING, int64(len(fullname)), fullname)
 
index b4e328bc2a3136dbb273ce943414c442608c03e6..ea89b72cadc52529f3dc94739429589fb892f2f3 100644 (file)
@@ -830,6 +830,23 @@ func TestAbstractOriginSanityIssue25459(t *testing.T) {
        }
 }
 
+func TestAbstractOriginSanityIssue26237(t *testing.T) {
+       testenv.MustHaveGoBuild(t)
+
+       if runtime.GOOS == "plan9" {
+               t.Skip("skipping on plan9; no DWARF symbol table in executables")
+       }
+       if runtime.GOOS == "solaris" || runtime.GOOS == "darwin" {
+               t.Skip("skipping on solaris and darwin, pending resolution of issue #23168")
+       }
+       if wd, err := os.Getwd(); err == nil {
+               gopathdir := filepath.Join(wd, "testdata", "issue26237")
+               abstractOriginSanity(t, gopathdir, DefaultOpt)
+       } else {
+               t.Fatalf("os.Getwd() failed %v", err)
+       }
+}
+
 func TestRuntimeTypeAttr(t *testing.T) {
        testenv.MustHaveGoBuild(t)
 
diff --git a/src/cmd/link/internal/ld/testdata/issue26237/src/b.dir/b.go b/src/cmd/link/internal/ld/testdata/issue26237/src/b.dir/b.go
new file mode 100644 (file)
index 0000000..ca57749
--- /dev/null
@@ -0,0 +1,16 @@
+package b
+
+var q int
+
+func Top(x int) int {
+       q += 1
+       if q != x {
+               return 3
+       }
+       return 4
+}
+
+func OOO(x int) int {
+       defer func() { q += x & 7 }()
+       return Top(x + 1)
+}
diff --git a/src/cmd/link/internal/ld/testdata/issue26237/src/main/main.go b/src/cmd/link/internal/ld/testdata/issue26237/src/main/main.go
new file mode 100644 (file)
index 0000000..6fdaa0b
--- /dev/null
@@ -0,0 +1,16 @@
+package main
+
+import (
+       "fmt"
+
+       b "b.dir"
+)
+
+var skyx int
+
+func main() {
+       skyx += b.OOO(skyx)
+       if b.Top(1) == 99 {
+               fmt.Printf("Beware the Jabberwock, my son!\n")
+       }
+}