diff options
| author | Austin Clements <austin@google.com> | 2018-11-01 14:34:21 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2018-11-12 20:27:20 +0000 |
| commit | 571236543f222e9fcb8ddfaa3151505a7de4d6f0 (patch) | |
| tree | 94e6e8e1bcfe8c477f48e5ec689da9a62cefd5b9 /src/debug | |
| parent | af1bfe0aa39091a4103bd29d8659f6267aad9df0 (diff) | |
| download | go-571236543f222e9fcb8ddfaa3151505a7de4d6f0.tar.xz | |
debug/gosym: use "go build" instead of hand-running asm and link
Currently, TestPCLine manually invokes asm and link on its test data.
Once we introduce symbol ABIs this is going to become problematic
because the test program defines main.main and main.init in assembly
so they use ABI0, but the runtime expects to find them with the
internal ABI.
There are various ways we could solve this. This CL moves main.main
and main.init into Go code and switches to using "go build" to compile
and link the test binary. This has the added advantage of simplifying
this test.
For #27539.
Change-Id: I4c0cf6467f7a39e6b1500eca6ad2620b5ef2b73c
Reviewed-on: https://go-review.googlesource.com/c/146857
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/gosym/pclntab_test.go | 38 | ||||
| -rw-r--r-- | src/debug/gosym/testdata/main.go | 10 | ||||
| -rw-r--r-- | src/debug/gosym/testdata/pclinetest.h (renamed from src/debug/gosym/pclinetest.h) | 0 | ||||
| -rw-r--r-- | src/debug/gosym/testdata/pclinetest.s (renamed from src/debug/gosym/pclinetest.asm) | 14 |
4 files changed, 19 insertions, 43 deletions
diff --git a/src/debug/gosym/pclntab_test.go b/src/debug/gosym/pclntab_test.go index 7e7cee6793..d21f0e24a8 100644 --- a/src/debug/gosym/pclntab_test.go +++ b/src/debug/gosym/pclntab_test.go @@ -5,7 +5,6 @@ package gosym import ( - "bytes" "debug/elf" "internal/testenv" "io/ioutil" @@ -33,33 +32,10 @@ func dotest(t *testing.T) { if err != nil { t.Fatal(err) } - // This command builds pclinetest from pclinetest.asm; - // the resulting binary looks like it was built from pclinetest.s, - // but we have renamed it to keep it away from the go tool. pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest") - cmd := exec.Command(testenv.GoToolPath(t), "tool", "asm", "-o", pclinetestBinary+".o", "pclinetest.asm") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { - t.Fatal(err) - } - - // stamp .o file as being 'package main' so that go tool link will accept it - data, err := ioutil.ReadFile(pclinetestBinary + ".o") - if err != nil { - t.Fatal(err) - } - i := bytes.IndexByte(data, '\n') - if i < 0 { - t.Fatal("bad binary") - } - data = append(append(data[:i:i], "\nmain"...), data[i:]...) - if err := ioutil.WriteFile(pclinetestBinary+".o", data, 0666); err != nil { - t.Fatal(err) - } - - cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-H", "linux", - "-o", pclinetestBinary, pclinetestBinary+".o") + cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", pclinetestBinary) + cmd.Dir = "testdata" + cmd.Env = append(os.Environ(), "GOOS=linux") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { @@ -232,7 +208,7 @@ func TestPCLine(t *testing.T) { } // Test PCToLine - sym := tab.LookupFunc("linefrompc") + sym := tab.LookupFunc("main.linefrompc") wantLine := 0 for pc := sym.Entry; pc < sym.End; pc++ { off := pc - text.Addr // TODO(rsc): should not need off; bug in 8g @@ -244,13 +220,13 @@ func TestPCLine(t *testing.T) { file, line, fn := tab.PCToLine(pc) if fn == nil { t.Errorf("failed to get line of PC %#x", pc) - } else if !strings.HasSuffix(file, "pclinetest.asm") || line != wantLine || fn != sym { - t.Errorf("PCToLine(%#x) = %s:%d (%s), want %s:%d (%s)", pc, file, line, fn.Name, "pclinetest.asm", wantLine, sym.Name) + } else if !strings.HasSuffix(file, "pclinetest.s") || line != wantLine || fn != sym { + t.Errorf("PCToLine(%#x) = %s:%d (%s), want %s:%d (%s)", pc, file, line, fn.Name, "pclinetest.s", wantLine, sym.Name) } } // Test LineToPC - sym = tab.LookupFunc("pcfromline") + sym = tab.LookupFunc("main.pcfromline") lookupline := -1 wantLine = 0 off := uint64(0) // TODO(rsc): should not need off; bug in 8g diff --git a/src/debug/gosym/testdata/main.go b/src/debug/gosym/testdata/main.go new file mode 100644 index 0000000000..b7702184cd --- /dev/null +++ b/src/debug/gosym/testdata/main.go @@ -0,0 +1,10 @@ +package main + +func linefrompc() +func pcfromline() + +func main() { + // Prevent GC of our test symbols + linefrompc() + pcfromline() +} diff --git a/src/debug/gosym/pclinetest.h b/src/debug/gosym/testdata/pclinetest.h index 156c0b87b0..156c0b87b0 100644 --- a/src/debug/gosym/pclinetest.h +++ b/src/debug/gosym/testdata/pclinetest.h diff --git a/src/debug/gosym/pclinetest.asm b/src/debug/gosym/testdata/pclinetest.s index b9ee9c0a50..53461cdfc1 100644 --- a/src/debug/gosym/pclinetest.asm +++ b/src/debug/gosym/testdata/pclinetest.s @@ -1,4 +1,4 @@ -TEXT linefrompc(SB),4,$0 // Each byte stores its line delta +TEXT ·linefrompc(SB),4,$0 // Each byte stores its line delta BYTE $2; BYTE $1; BYTE $1; BYTE $0; @@ -28,7 +28,7 @@ BYTE $2; BYTE $2; BYTE $255; -TEXT pcfromline(SB),4,$0 // Each record stores its line delta, then n, then n more bytes +TEXT ·pcfromline(SB),4,$0 // Each record stores its line delta, then n, then n more bytes BYTE $32; BYTE $0; BYTE $1; BYTE $1; BYTE $0; BYTE $1; BYTE $0; @@ -46,13 +46,3 @@ BYTE $3; BYTE $3; BYTE $0; BYTE $0; BYTE $0; BYTE $4; BYTE $3; BYTE $0; BYTE $0; BYTE $0; BYTE $255; - -// Keep the linker happy -TEXT main·main(SB),4,$0 - RET - -TEXT main·init(SB),4,$0 - // Prevent GC of our test symbols - CALL linefrompc(SB) - CALL pcfromline(SB) - RET |
