]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: fix for package name attr testpoint in dwarf_test.go
authorThan McIntosh <thanm@google.com>
Fri, 7 Feb 2020 19:00:26 +0000 (14:00 -0500)
committerThan McIntosh <thanm@google.com>
Tue, 10 Mar 2020 19:41:44 +0000 (19:41 +0000)
Tighten up a testpoint that looks for the compile unit
DW_AT_go_package_name attribute. The linker code that injects this
attribute was accidentally broken on the dev.link branch, but in a way
that wasn't detected by the test (attr was generated, but always with
an empty string). The new test will fail if the attr is an empty
string, or if we can't find the attribute for the runtime package.

Change-Id: I8b065e7eb3486646364d0eaf48a73db6acffbd18
Reviewed-on: https://go-review.googlesource.com/c/go/+/218483
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/ld/dwarf_test.go

index c2b6121c003f736ea8ddc3f57e4a5ddf069e2119..cf6bec80535b51360f91d2e0a2e7bfdb8fa3f267 100644 (file)
@@ -1239,6 +1239,7 @@ func TestPackageNameAttr(t *testing.T) {
        }
 
        rdr := d.Reader()
+       runtimeUnitSeen := false
        for {
                e, err := rdr.Next()
                if err != nil {
@@ -1254,12 +1255,26 @@ func TestPackageNameAttr(t *testing.T) {
                        continue
                }
 
-               _, ok := e.Val(dwarfAttrGoPackageName).(string)
+               pn, ok := e.Val(dwarfAttrGoPackageName).(string)
                if !ok {
                        name, _ := e.Val(dwarf.AttrName).(string)
                        t.Errorf("found compile unit without package name: %s", name)
+
+               }
+               if pn == "" {
+                       name, _ := e.Val(dwarf.AttrName).(string)
+                       t.Errorf("found compile unit with empty package name: %s", name)
+               } else {
+                       if pn == "runtime" {
+                               runtimeUnitSeen = true
+                       }
                }
        }
+
+       // Something is wrong if there's no runtime compilation unit.
+       if !runtimeUnitSeen {
+               t.Errorf("no package name for runtime unit")
+       }
 }
 
 func TestMachoIssue32233(t *testing.T) {