Skip to content

Commit aad06da

Browse files
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Crawshaw <[email protected]>
1 parent be9dcfe commit aad06da

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/cmd/link/internal/ld/dwarf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) {
10801080
epcs = s
10811081

10821082
dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
1083-
dsym.Attr |= AttrHidden
1083+
dsym.Attr |= AttrHidden | AttrReachable
10841084
dsym.Type = obj.SDWARFINFO
10851085
for _, r := range dsym.R {
10861086
if r.Type == obj.R_DWARFREF && r.Sym.Size == 0 {

src/runtime/runtime-gdb_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package runtime_test
77
import (
88
"bytes"
99
"fmt"
10+
"go/build"
1011
"internal/testenv"
1112
"io/ioutil"
1213
"os"
@@ -67,7 +68,6 @@ func checkGdbPython(t *testing.T) {
6768
}
6869

6970
const helloSource = `
70-
package main
7171
import "fmt"
7272
var gslice []string
7373
func main() {
@@ -85,9 +85,20 @@ func main() {
8585
`
8686

8787
func TestGdbPython(t *testing.T) {
88+
testGdbPython(t, false)
89+
}
90+
91+
func TestGdbPythonCgo(t *testing.T) {
92+
testGdbPython(t, true)
93+
}
94+
95+
func testGdbPython(t *testing.T, cgo bool) {
8896
if runtime.GOARCH == "mips64" {
8997
testenv.SkipFlaky(t, 18173)
9098
}
99+
if cgo && !build.Default.CgoEnabled {
100+
t.Skip("skipping because cgo is not enabled")
101+
}
91102

92103
t.Parallel()
93104
checkGdbEnvironment(t)
@@ -100,8 +111,15 @@ func TestGdbPython(t *testing.T) {
100111
}
101112
defer os.RemoveAll(dir)
102113

114+
var buf bytes.Buffer
115+
buf.WriteString("package main\n")
116+
if cgo {
117+
buf.WriteString(`import "C"` + "\n")
118+
}
119+
buf.WriteString(helloSource)
120+
103121
src := filepath.Join(dir, "main.go")
104-
err = ioutil.WriteFile(src, []byte(helloSource), 0644)
122+
err = ioutil.WriteFile(src, buf.Bytes(), 0644)
105123
if err != nil {
106124
t.Fatalf("failed to create file: %v", err)
107125
}

0 commit comments

Comments
 (0)