mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/objfile: correct file table reading for Go object file
Apparently I never actually understood the new file table in Go object files. The PC value stream actually encodes the file index in the per-CU table. I thought it was indexing into a per-function table, which then contains index to the per-CU table. Remove the extra indirection. Change-Id: I0aea5629f7b3888ebe3a04fea437aa15ce89519e Reviewed-on: https://go-review.googlesource.com/c/go/+/262779 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
771f5f2e48
commit
20819440fc
6 changed files with 63 additions and 3 deletions
|
|
@ -267,13 +267,11 @@ func (f *goobjFile) PCToLine(pc uint64) (string, int, *gosym.Func) {
|
||||||
}
|
}
|
||||||
b := r.BytesAt(r.DataOff(isym), r.DataSize(isym))
|
b := r.BytesAt(r.DataOff(isym), r.DataSize(isym))
|
||||||
var info *goobj.FuncInfo
|
var info *goobj.FuncInfo
|
||||||
lengths := info.ReadFuncInfoLengths(b)
|
|
||||||
pcline := getSymData(info.ReadPcline(b))
|
pcline := getSymData(info.ReadPcline(b))
|
||||||
line := int(pcValue(pcline, pc-addr, f.arch))
|
line := int(pcValue(pcline, pc-addr, f.arch))
|
||||||
pcfile := getSymData(info.ReadPcfile(b))
|
pcfile := getSymData(info.ReadPcfile(b))
|
||||||
fileID := pcValue(pcfile, pc-addr, f.arch)
|
fileID := pcValue(pcfile, pc-addr, f.arch)
|
||||||
globalFileID := info.ReadFile(b, lengths.FileOff, uint32(fileID))
|
fileName := r.File(int(fileID))
|
||||||
fileName := r.File(int(globalFileID))
|
|
||||||
// Note: we provide only the name in the Func structure.
|
// Note: we provide only the name in the Func structure.
|
||||||
// We could provide more if needed.
|
// We could provide more if needed.
|
||||||
return fileName, line, &gosym.Func{Sym: &gosym.Sym{Name: osym.Name(r)}}
|
return fileName, line, &gosym.Func{Sym: &gosym.Sym{Name: osym.Name(r)}}
|
||||||
|
|
|
||||||
|
|
@ -333,3 +333,41 @@ func TestDisasmGoobj(t *testing.T) {
|
||||||
t.Logf("full disassembly:\n%s", text)
|
t.Logf("full disassembly:\n%s", text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoobjFileNumber(t *testing.T) {
|
||||||
|
// Test that file table in Go object file is parsed correctly.
|
||||||
|
testenv.MustHaveGoBuild(t)
|
||||||
|
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "TestGoobjFileNumber")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
obj := filepath.Join(tmpdir, "p.a")
|
||||||
|
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", obj)
|
||||||
|
cmd.Dir = filepath.Join("testdata/testfilenum")
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("build failed: %v\n%s", err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command(exe, obj)
|
||||||
|
out, err = cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("objdump failed: %v\n%s", err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
text := string(out)
|
||||||
|
for _, s := range []string{"a.go", "b.go", "c.go"} {
|
||||||
|
if !strings.Contains(text, s) {
|
||||||
|
t.Errorf("output missing '%s'", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.Failed() {
|
||||||
|
t.Logf("output:\n%s", text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
7
src/cmd/objdump/testdata/testfilenum/a.go
vendored
Normal file
7
src/cmd/objdump/testdata/testfilenum/a.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
// Copyright 2020 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 p
|
||||||
|
|
||||||
|
func A() {}
|
||||||
7
src/cmd/objdump/testdata/testfilenum/b.go
vendored
Normal file
7
src/cmd/objdump/testdata/testfilenum/b.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
// Copyright 2020 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 p
|
||||||
|
|
||||||
|
func B() {}
|
||||||
7
src/cmd/objdump/testdata/testfilenum/c.go
vendored
Normal file
7
src/cmd/objdump/testdata/testfilenum/c.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
// Copyright 2020 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 p
|
||||||
|
|
||||||
|
func C() {}
|
||||||
3
src/cmd/objdump/testdata/testfilenum/go.mod
vendored
Normal file
3
src/cmd/objdump/testdata/testfilenum/go.mod
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module objdumptest
|
||||||
|
|
||||||
|
go 1.16
|
||||||
Loading…
Add table
Add a link
Reference in a new issue