Commit ae0b7353 authored by Jeremy Faller's avatar Jeremy Faller

cmd/compile: emit only '/' in DWARF file names

Make file names consistent, using only forward slashes in the path.

Fixes #36495

Change-Id: I337119d6dff233ab9d4bfe757147ec25961ae021
Reviewed-on: https://go-review.googlesource.com/c/go/+/214286
Run-TryBot: Jeremy Faller <jeremy@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 6988e6d5
......@@ -106,7 +106,7 @@ func WriteObjFile(ctxt *Link, bout *bio.Writer, pkgpath string) {
fileTable := ctxt.PosTable.DebugLinesFileTable()
w.writeInt(int64(len(fileTable)))
for _, str := range fileTable {
w.writeString(str)
w.writeString(filepath.ToSlash(str))
}
// Symbol references
......
......@@ -8,9 +8,11 @@ import (
intdwarf "cmd/internal/dwarf"
objfilepkg "cmd/internal/objfile" // renamed to avoid conflict with objfile function
"debug/dwarf"
"debug/pe"
"errors"
"fmt"
"internal/testenv"
"io"
"io/ioutil"
"os"
"os/exec"
......@@ -1282,3 +1284,67 @@ func TestMachoIssue32233(t *testing.T) {
f := gobuildTestdata(t, tmpdir, pdir, DefaultOpt)
f.Close()
}
func TestWindowsIssue36495(t *testing.T) {
testenv.MustHaveGoBuild(t)
if runtime.GOOS != "windows" {
t.Skip("skipping: test only on windows")
}
dir, err := ioutil.TempDir("", "TestEmbeddedStructMarker")
if err != nil {
t.Fatalf("could not create directory: %v", err)
}
defer os.RemoveAll(dir)
prog := `
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}`
f := gobuild(t, dir, prog, NoOpt)
exe, err := pe.Open(f.path)
if err != nil {
t.Fatalf("error opening pe file: %v", err)
}
dw, err := exe.DWARF()
if err != nil {
t.Fatalf("error parsing DWARF: %v", err)
}
rdr := dw.Reader()
for {
e, err := rdr.Next()
if err != nil {
t.Fatalf("error reading DWARF: %v", err)
}
if e == nil {
break
}
if e.Tag != dwarf.TagCompileUnit {
continue
}
lnrdr, err := dw.LineReader(e)
if err != nil {
t.Fatalf("error creating DWARF line reader: %v", err)
}
if lnrdr != nil {
var lne dwarf.LineEntry
for {
err := lnrdr.Next(&lne)
if err == io.EOF {
break
}
if err != nil {
t.Fatalf("error reading next DWARF line: %v", err)
}
if strings.Contains(lne.File.Name, `\`) {
t.Errorf("filename should not contain backslash: %v", lne.File.Name)
}
}
}
rdr.SkipChildren()
}
}
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