From 5db3c8f1fd93b63236be0c4fe35e6f704582fbe1 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Fri, 7 Feb 2020 14:00:26 -0500 Subject: [PATCH] cmd/link: fix for package name attr testpoint in dwarf_test.go 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 TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller Reviewed-by: Cherry Zhang --- src/cmd/link/internal/ld/dwarf_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/dwarf_test.go b/src/cmd/link/internal/ld/dwarf_test.go index c2b6121c00..cf6bec8053 100644 --- a/src/cmd/link/internal/ld/dwarf_test.go +++ b/src/cmd/link/internal/ld/dwarf_test.go @@ -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) { -- 2.50.0