Skip to content

Commit 489868f

Browse files
derekparkergopherbot
authored andcommitted
cmd/link: scope test to linux & net.sendFile
Limits the scope of new test added in 71c2bf5. Discussion: https://go-review.googlesource.com/c/go/+/684377. Change-Id: I0e8f513eb564aae277ba8a80ebdad469eb1e6e6a GitHub-Last-Rev: add2b2e GitHub-Pull-Request: #74720 Reviewed-on: https://go-review.googlesource.com/c/go/+/689916 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@google.com>
1 parent 71c2bf5 commit 489868f

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/cmd/compile/internal/dwarfgen/dwarf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
278278
base.Fatalf("invalid heap allocated var without Heapaddr")
279279
}
280280
debug := fn.DebugInfo.(*ssa.FuncDebug)
281-
list := createHeapDerefLocationList(n, fnsym, debug.EntryID, ssa.FuncEnd.ID)
281+
list := createHeapDerefLocationList(n, debug.EntryID)
282282
dvar.PutLocationList = func(listSym, startPC dwarf.Sym) {
283283
debug.PutLocationList(list, base.Ctxt, listSym.(*obj.LSym), startPC.(*obj.LSym))
284284
}
@@ -558,7 +558,7 @@ func createComplexVar(fnsym *obj.LSym, fn *ir.Func, varID ssa.VarID, closureVars
558558

559559
// createHeapDerefLocationList creates a location list for a heap-escaped variable
560560
// that describes "dereference pointer at stack offset"
561-
func createHeapDerefLocationList(n *ir.Name, fnsym *obj.LSym, entryID, prologEndID ssa.ID) []byte {
561+
func createHeapDerefLocationList(n *ir.Name, entryID ssa.ID) []byte {
562562
// Get the stack offset where the heap pointer is stored
563563
heapPtrOffset := n.Heapaddr.FrameOffset()
564564
if base.Ctxt.Arch.FixedFrameSize == 0 {

src/cmd/link/dwarf_test.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,18 @@ func TestDWARFiOS(t *testing.T) {
257257
})
258258
}
259259

260+
// This test ensures that variables promoted to the heap, specifically
261+
// function return parameters, have correct location lists generated.
262+
//
263+
// TODO(deparker): This test is intentionally limited to GOOS=="linux"
264+
// and scoped to net.sendFile, which was the function reported originally in
265+
// issue #65405. There is relevant discussion in https://go-review.googlesource.com/c/go/+/684377
266+
// pertaining to these limitations. There are other missing location lists which must be fixed
267+
// particularly in functions where `linkname` is involved.
260268
func TestDWARFLocationList(t *testing.T) {
269+
if runtime.GOOS != "linux" {
270+
t.Skip("skipping test on non-linux OS")
271+
}
261272
testenv.MustHaveCGO(t)
262273
testenv.MustHaveGoBuild(t)
263274

@@ -305,22 +316,10 @@ func TestDWARFLocationList(t *testing.T) {
305316
// Look for the net.sendFile subprogram
306317
if entry.Tag == dwarf.TagSubprogram {
307318
fnName, ok := entry.Val(dwarf.AttrName).(string)
308-
if !ok {
319+
if !ok || fnName != "net.sendFile" {
320+
reader.SkipChildren()
309321
continue
310322
}
311-
if strings.Contains(fnName, ".eq") || // Ignore autogenerated equality funcs
312-
strings.HasPrefix(fnName, "internal/") || // Ignore internal/runtime package TODO(deparker): Fix these too (likely same issue as other ignored packages below).
313-
strings.HasPrefix(fnName, "runtime.") || // Ignore runtime package which contain funcs implemented in assembly or exposed through linkname which seems to not generate location lists correctly (most likely linkname causing this). TODO(deparker) Fix these too.
314-
strings.HasPrefix(fnName, "reflect.") || // Ignore reflect package. TODO(deparker) Fix these too.
315-
strings.HasPrefix(fnName, "time.") { // Ignore funcs in time package which are exposed through linkname and seem to not generate location lists correctly TODO(deparker) Fix these too.
316-
continue
317-
}
318-
if fnName == "syscall.compileCallback" || fnName == "maps.clone" {
319-
continue // Ignore for now, possibly caused by linkname usage. TODO(deparker) Fix this too.
320-
}
321-
if runtime.GOOS == "windows" && strings.HasPrefix(fnName, "syscall.") {
322-
continue // Ignore, caused by linkname usage. TODO(deparker) Fix these too.
323-
}
324323

325324
for {
326325
paramEntry, err := reader.Next()
@@ -332,13 +331,8 @@ func TestDWARFLocationList(t *testing.T) {
332331
}
333332

334333
if paramEntry.Tag == dwarf.TagFormalParameter {
335-
paramName, hasName := paramEntry.Val(dwarf.AttrName).(string)
336-
if !hasName {
337-
continue
338-
}
339-
if paramName[0] == '~' {
340-
continue
341-
}
334+
paramName, _ := paramEntry.Val(dwarf.AttrName).(string)
335+
342336
// Check if this parameter has a location attribute
343337
if loc := paramEntry.Val(dwarf.AttrLocation); loc != nil {
344338
switch locData := loc.(type) {

0 commit comments

Comments
 (0)