Skip to content

Commit f016172

Browse files
committed
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 <[email protected]> Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 60b1253 commit f016172

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/cmd/go/internal/work/gc.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,10 @@ func (gcToolchain) asm(b *Builder, a *Action, sfiles []string) ([]string, error)
370370

371371
var ofiles []string
372372
for _, sfile := range sfiles {
373+
overlayPath, _ := fsys.OverlayPath(mkAbs(p.Dir, sfile))
373374
ofile := a.Objdir + sfile[:len(sfile)-len(".s")] + ".o"
374375
ofiles = append(ofiles, ofile)
375-
args1 := append(args, "-o", ofile, mkAbs(p.Dir, sfile))
376+
args1 := append(args, "-o", ofile, overlayPath)
376377
if err := b.run(a, p.Dir, p.ImportPath, nil, args1...); err != nil {
377378
return nil, err
378379
}
@@ -388,7 +389,8 @@ func (gcToolchain) symabis(b *Builder, a *Action, sfiles []string) (string, erro
388389
if p.ImportPath == "runtime/cgo" && strings.HasPrefix(sfile, "gcc_") {
389390
continue
390391
}
391-
args = append(args, mkAbs(p.Dir, sfile))
392+
op, _ := fsys.OverlayPath(mkAbs(p.Dir, sfile))
393+
args = append(args, op)
392394
}
393395

394396
// Supply an empty go_asm.h as if the compiler had been run.

src/cmd/go/internal/work/gccgo.go

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

src/cmd/go/testdata/script/build_overlay.txt

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ go build -overlay overlay.json -o main_cgo_angle$GOEXE ./cgo_hello_angle
4343
exec ./main_cgo_angle$GOEXE
4444
stdout '^hello cgo\r?\n'
4545

46+
go build -overlay overlay.json -o main_call_asm$GOEXE ./call_asm
47+
exec ./main_call_asm$GOEXE
48+
! stdout .
49+
4650
go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace
4751
cp stdout compiled_cgo_sources.txt
4852
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 ./
7983
exec ./main_cgo_angle_gccgo$GOEXE
8084
stdout '^hello cgo\r?\n'
8185

86+
go build -compiler=gccgo -overlay overlay.json -o main_call_asm_gccgo$GOEXE ./call_asm
87+
exec ./main_call_asm_gccgo$GOEXE
88+
! stdout .
89+
8290
-- m/go.mod --
8391
// TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
8492
module m
@@ -105,6 +113,7 @@ the actual code is in the overlay
105113
"dir2/i.go": "overlay/dir2_i.go",
106114
"printpath/main.go": "overlay/printpath.go",
107115
"printpath/other.go": "overlay2/printpath2.go",
116+
"call_asm/asm.s": "overlay/asm_file.s",
108117
"cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
109118
"cgo_hello_replace/hello.c": "overlay/hello.c",
110119
"cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
@@ -139,6 +148,14 @@ import "m/dir2"
139148
func main() {
140149
dir2.PrintMessage()
141150
}
151+
-- m/call_asm/main.go --
152+
package main
153+
154+
func foo() // There will be a "missing function body" error if the assembly file isn't found.
155+
156+
func main() {
157+
foo()
158+
}
142159
-- m/overlay/dir_g.go --
143160
package dir
144161

0 commit comments

Comments
 (0)