Commit aad06da2 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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: default avatarDavid Crawshaw <crawshaw@golang.org>
parent be9dcfec
...@@ -1080,7 +1080,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) { ...@@ -1080,7 +1080,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) {
epcs = s epcs = s
dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version)) dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
dsym.Attr |= AttrHidden dsym.Attr |= AttrHidden | AttrReachable
dsym.Type = obj.SDWARFINFO dsym.Type = obj.SDWARFINFO
for _, r := range dsym.R { for _, r := range dsym.R {
if r.Type == obj.R_DWARFREF && r.Sym.Size == 0 { if r.Type == obj.R_DWARFREF && r.Sym.Size == 0 {
......
...@@ -7,6 +7,7 @@ package runtime_test ...@@ -7,6 +7,7 @@ package runtime_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"go/build"
"internal/testenv" "internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
...@@ -67,7 +68,6 @@ func checkGdbPython(t *testing.T) { ...@@ -67,7 +68,6 @@ func checkGdbPython(t *testing.T) {
} }
const helloSource = ` const helloSource = `
package main
import "fmt" import "fmt"
var gslice []string var gslice []string
func main() { func main() {
...@@ -85,9 +85,20 @@ func main() { ...@@ -85,9 +85,20 @@ func main() {
` `
func TestGdbPython(t *testing.T) { 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" { if runtime.GOARCH == "mips64" {
testenv.SkipFlaky(t, 18173) testenv.SkipFlaky(t, 18173)
} }
if cgo && !build.Default.CgoEnabled {
t.Skip("skipping because cgo is not enabled")
}
t.Parallel() t.Parallel()
checkGdbEnvironment(t) checkGdbEnvironment(t)
...@@ -100,8 +111,15 @@ func TestGdbPython(t *testing.T) { ...@@ -100,8 +111,15 @@ func TestGdbPython(t *testing.T) {
} }
defer os.RemoveAll(dir) 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") src := filepath.Join(dir, "main.go")
err = ioutil.WriteFile(src, []byte(helloSource), 0644) err = ioutil.WriteFile(src, buf.Bytes(), 0644)
if err != nil { if err != nil {
t.Fatalf("failed to create file: %v", err) t.Fatalf("failed to create file: %v", err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment