]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: pass in overlaid paths for .s files
authorMichael Matloob <matloob@golang.org>
Thu, 29 Oct 2020 23:28:07 +0000 (19:28 -0400)
committerMichael Matloob <matloob@golang.org>
Thu, 12 Nov 2020 21:21:29 +0000 (21:21 +0000)
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>
src/cmd/go/internal/work/gc.go
src/cmd/go/internal/work/gccgo.go
src/cmd/go/testdata/script/build_overlay.txt

index 56711b52d87a465cb8f3b0f5fa6a923e2d49c983..3a53c714e3702969a0104fa22ad6366362fb6e88 100644 (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.
index 6be3821f75a1c2a6aa5b3e2e877cb8fd2a1c87e0..01d2b891590d242d1f3c08457b9affff315cbe18 100644 (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)
index 58c0de9a553d5672eb8c4bdf806fc507586f810a..2e558874fd992ef935c02b34cda81feb621405eb 100644 (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