cmd/compile: replace GOROOT in //line directives

The compiler replaces any path of the form /path/to/goroot/src/net/port.go
with GOROOT/src/net/port.go so that the same object file is
produced if the GOROOT is moved. It was skipping this transformation
for any absolute path into the GOROOT that came from //line directives,
such as those generated by cmd/cgo.

Fixes #21373
Fixes #21720
Fixes #21825

Change-Id: I2784c701b4391cfb92e23efbcb091a84957d61dd
Reviewed-on: https://go-review.googlesource.com/63693
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
David Crawshaw 2017-09-13 19:04:25 -04:00
parent af86083812
commit 27e80f7c4d
7 changed files with 43 additions and 18 deletions

View file

@ -16,9 +16,10 @@ const debug = false
const trace = false
type parser struct {
base *src.PosBase
errh ErrorHandler
mode Mode
base *src.PosBase
errh ErrorHandler
fileh FilenameHandler
mode Mode
scanner
first error // first error encountered
@ -29,9 +30,10 @@ type parser struct {
indent []byte // tracing support
}
func (p *parser) init(base *src.PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, mode Mode) {
func (p *parser) init(base *src.PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, fileh FilenameHandler, mode Mode) {
p.base = base
p.errh = errh
p.fileh = fileh
p.mode = mode
p.scanner.init(
r,
@ -76,7 +78,11 @@ func (p *parser) updateBase(line, col uint, text string) {
p.error_at(p.pos_at(line, col+uint(i+1)), "invalid line number: "+nstr)
return
}
p.base = src.NewLinePragmaBase(src.MakePos(p.base.Pos().Base(), line, col), text[:i], uint(n))
absFile := text[:i]
if p.fileh != nil {
absFile = p.fileh(absFile)
}
p.base = src.NewLinePragmaBase(src.MakePos(p.base.Pos().Base(), line, col), absFile, uint(n))
}
func (p *parser) got(tok token) bool {