for i := range s.FuncInfo.File {
f := s.FuncInfo.File[i]
- if i := strings.Index(f.Name, "runtime/runtime.go"); i >= 0 {
+ if i := strings.Index(f.Name, "runtime/debug.go"); i >= 0 {
gdbscript = f.Name[:i] + "runtime/runtime-gdb.py"
break
}
}
func writegdbscript(ctxt *Link, syms []*Symbol) []*Symbol {
- if Linkmode == LinkExternal && Headtype == objabi.Hwindows {
+ if Linkmode == LinkExternal && Headtype == objabi.Hwindows && Buildmode == BuildmodeCArchive {
// gcc on Windows places .debug_gdb_scripts in the wrong location, which
// causes the program not to run. See https://golang.org/issue/20183
+ // Non c-archives can avoid this issue via a linker script
+ // (see fix near writeGDBLinkerScript).
+ // c-archive users would need to specify the linker script manually.
+ // For UX it's better not to deal with this.
return syms
}
return paths
}
+// writeGDBLinkerScript creates gcc linker script file in temp
+// directory. writeGDBLinkerScript returns created file path.
+// The script is used to work around gcc bug
+// (see https://golang.org/issue/20183 for details).
+func writeGDBLinkerScript() string {
+ name := "fix_debug_gdb_scripts.ld"
+ path := filepath.Join(*flagTmpdir, name)
+ src := `SECTIONS
+{
+ .debug_gdb_scripts BLOCK(__section_alignment__) (NOLOAD) :
+ {
+ *(.debug_gdb_scripts)
+ }
+}
+INSERT AFTER .debug_types;
+`
+ err := ioutil.WriteFile(path, []byte(src), 0666)
+ if err != nil {
+ Errorf(nil, "WriteFile %s failed: %v", name, err)
+ }
+ return path
+}
+
// archive builds a .a archive from the hostobj object files.
func (ctxt *Link) archive() {
if Buildmode != BuildmodeCArchive {
}
}
if Headtype == objabi.Hwindows {
+ // use gcc linker script to work around gcc bug
+ // (see https://golang.org/issue/20183 for details).
+ p := writeGDBLinkerScript()
+ argv = append(argv, "-Wl,-T,"+p)
// libmingw32 and libmingwex have some inter-dependencies,
// so must use linker groups.
argv = append(argv, "-Wl,--start-group", "-lmingwex", "-lmingw32", "-Wl,--end-group")
}
defer f.Close()
+ var foundDebugGDBScriptsSection bool
+ for _, sect := range f.Sections {
+ if sect.Name == ".debug_gdb_scripts" {
+ foundDebugGDBScriptsSection = true
+ }
+ }
+ if !foundDebugGDBScriptsSection {
+ t.Error(".debug_gdb_scripts section is not found")
+ }
+
d, err := f.DWARF()
if err != nil {
t.Fatal(err)