diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-01-23 17:30:41 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2017-01-24 03:37:56 +0000 |
commit | aad06da2b9b293fd245626fc8e116e3b56654dae (patch) | |
tree | 2bbab3fcfaa9e342220214c13679d2f4f5175212 | |
parent | be9dcfec293854bfb4a13737ba09801769daccbf (diff) | |
download | go-aad06da2b9b293fd245626fc8e116e3b56654dae.tar.gz go-aad06da2b9b293fd245626fc8e116e3b56654dae.zip |
cmd/link: mark DWARF function symbols as reachable
Otherwise we don't emit any required ELF relocations when doing an
external link, because elfrelocsect skips unreachable symbols.
Fixes #18745.
Change-Id: Ia3583c41bb6c5ebb7579abd26ed8689370311cd6
Reviewed-on: https://go-review.googlesource.com/35590
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
-rw-r--r-- | src/cmd/link/internal/ld/dwarf.go | 2 | ||||
-rw-r--r-- | src/runtime/runtime-gdb_test.go | 22 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 61d3e4fb72..22d2c548c3 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -1080,7 +1080,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) { epcs = s dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version)) - dsym.Attr |= AttrHidden + dsym.Attr |= AttrHidden | AttrReachable dsym.Type = obj.SDWARFINFO for _, r := range dsym.R { if r.Type == obj.R_DWARFREF && r.Sym.Size == 0 { diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index c2844375f7..f886961d6a 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -7,6 +7,7 @@ package runtime_test import ( "bytes" "fmt" + "go/build" "internal/testenv" "io/ioutil" "os" @@ -67,7 +68,6 @@ func checkGdbPython(t *testing.T) { } const helloSource = ` -package main import "fmt" var gslice []string func main() { @@ -85,9 +85,20 @@ func main() { ` func TestGdbPython(t *testing.T) { + testGdbPython(t, false) +} + +func TestGdbPythonCgo(t *testing.T) { + testGdbPython(t, true) +} + +func testGdbPython(t *testing.T, cgo bool) { if runtime.GOARCH == "mips64" { testenv.SkipFlaky(t, 18173) } + if cgo && !build.Default.CgoEnabled { + t.Skip("skipping because cgo is not enabled") + } t.Parallel() checkGdbEnvironment(t) @@ -100,8 +111,15 @@ func TestGdbPython(t *testing.T) { } defer os.RemoveAll(dir) + var buf bytes.Buffer + buf.WriteString("package main\n") + if cgo { + buf.WriteString(`import "C"` + "\n") + } + buf.WriteString(helloSource) + src := filepath.Join(dir, "main.go") - err = ioutil.WriteFile(src, []byte(helloSource), 0644) + err = ioutil.WriteFile(src, buf.Bytes(), 0644) if err != nil { t.Fatalf("failed to create file: %v", err) } |