1
0
mirror of https://github.com/golang/go synced 2024-11-26 01:07:57 -07:00

cmd/go: pass in overlaid paths for .s files

This change adds support for adding overlays on assembly files.

For #39958

Change-Id: I1a328656199cc836f48e16de1ffd944fdd07fb39
Reviewed-on: https://go-review.googlesource.com/c/go/+/266417
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Michael Matloob 2020-10-29 19:28:07 -04:00
parent 60b1253293
commit f016172dbe
3 changed files with 22 additions and 3 deletions

View File

@ -370,9 +370,10 @@ func (gcToolchain) asm(b *Builder, a *Action, sfiles []string) ([]string, error)
var ofiles []string
for _, sfile := range sfiles {
overlayPath, _ := fsys.OverlayPath(mkAbs(p.Dir, sfile))
ofile := a.Objdir + sfile[:len(sfile)-len(".s")] + ".o"
ofiles = append(ofiles, ofile)
args1 := append(args, "-o", ofile, mkAbs(p.Dir, sfile))
args1 := append(args, "-o", ofile, overlayPath)
if err := b.run(a, p.Dir, p.ImportPath, nil, args1...); err != nil {
return nil, err
}
@ -388,7 +389,8 @@ func (gcToolchain) symabis(b *Builder, a *Action, sfiles []string) (string, erro
if p.ImportPath == "runtime/cgo" && strings.HasPrefix(sfile, "gcc_") {
continue
}
args = append(args, mkAbs(p.Dir, sfile))
op, _ := fsys.OverlayPath(mkAbs(p.Dir, sfile))
args = append(args, op)
}
// Supply an empty go_asm.h as if the compiler had been run.

View File

@ -199,7 +199,7 @@ func (tools gccgoToolchain) asm(b *Builder, a *Action, sfiles []string) ([]strin
base := filepath.Base(sfile)
ofile := a.Objdir + base[:len(base)-len(".s")] + ".o"
ofiles = append(ofiles, ofile)
sfile = mkAbs(p.Dir, sfile)
sfile, _ = fsys.OverlayPath(mkAbs(p.Dir, sfile))
defs := []string{"-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch}
if pkgpath := tools.gccgoCleanPkgpath(b, p); pkgpath != "" {
defs = append(defs, `-D`, `GOPKGPATH=`+pkgpath)

View File

@ -43,6 +43,10 @@ go build -overlay overlay.json -o main_cgo_angle$GOEXE ./cgo_hello_angle
exec ./main_cgo_angle$GOEXE
stdout '^hello cgo\r?\n'
go build -overlay overlay.json -o main_call_asm$GOEXE ./call_asm
exec ./main_call_asm$GOEXE
! stdout .
go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace
cp stdout compiled_cgo_sources.txt
go run ../print_line_comments.go compiled_cgo_sources.txt
@ -79,6 +83,10 @@ go build -compiler=gccgo -overlay overlay.json -o main_cgo_angle_gccgo$GOEXE ./
exec ./main_cgo_angle_gccgo$GOEXE
stdout '^hello cgo\r?\n'
go build -compiler=gccgo -overlay overlay.json -o main_call_asm_gccgo$GOEXE ./call_asm
exec ./main_call_asm_gccgo$GOEXE
! stdout .
-- m/go.mod --
// TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
module m
@ -105,6 +113,7 @@ the actual code is in the overlay
"dir2/i.go": "overlay/dir2_i.go",
"printpath/main.go": "overlay/printpath.go",
"printpath/other.go": "overlay2/printpath2.go",
"call_asm/asm.s": "overlay/asm_file.s",
"cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
"cgo_hello_replace/hello.c": "overlay/hello.c",
"cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
@ -139,6 +148,14 @@ import "m/dir2"
func main() {
dir2.PrintMessage()
}
-- m/call_asm/main.go --
package main
func foo() // There will be a "missing function body" error if the assembly file isn't found.
func main() {
foo()
}
-- m/overlay/dir_g.go --
package dir