cmd/link: actually generate .debug_gdb_scripts section on windows

Adjust finddebugruntimepath to look for runtime/debug.go file
instead of runtime/runtime.go. This actually finds runtime.GOMAXPROCS
in every Go executable (including windows).

I also included "-Wl,-T,fix_debug_gdb_scripts.ld" parameter to gcc
invocation on windows to work around gcc bug (see #20183 for details).

This CL only fixes windows -buildmode=exe, buildmode=c-archive
is still broken.

Thanks to Egon Elbre and Nick Clifton for investigation.

Fixes #20183
Fixes #20218

Change-Id: I5369a4db3913226aef3d9bd6317446856b0a1c34
Reviewed-on: https://go-review.googlesource.com/43331
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Alex Brainman 2017-05-11 11:55:59 +10:00
parent fca6ad45e2
commit 1d44c4e378
3 changed files with 43 additions and 2 deletions

View file

@ -986,6 +986,29 @@ func hostobjCopy() (paths []string) {
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 {
@ -1247,6 +1270,10 @@ func (l *Link) hostlink() {
}
}
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")