diff --git a/go/tools/builders/BUILD.bazel b/go/tools/builders/BUILD.bazel index ec45446d1a..b180632d75 100644 --- a/go/tools/builders/BUILD.bazel +++ b/go/tools/builders/BUILD.bazel @@ -42,6 +42,8 @@ filegroup( srcs = [ "ar.go", "asm.go", + "asm_go1.go", + "asm_go119.go", "builder.go", "cgo2.go", "compile.go", diff --git a/go/tools/builders/asm.go b/go/tools/builders/asm.go index 1e3a8ba58d..98d24cb0b1 100644 --- a/go/tools/builders/asm.go +++ b/go/tools/builders/asm.go @@ -60,7 +60,10 @@ func asm(args []string) error { } // Build source with the assembler. - return asmFile(goenv, source, asmFlags, outPath) + // Note: As of Go 1.19, this would require a valid package path to work. + // But since this functionality is only used by the deprecated action API, + // we won't fix this. + return asmFile(goenv, source, "", asmFlags, outPath) } // buildSymabisFile generates a file from assembly files that is consumed @@ -137,9 +140,10 @@ func buildSymabisFile(goenv *env, sFiles, hFiles []fileInfo, asmhdr string) (str return symabisName, err } -func asmFile(goenv *env, srcPath string, asmFlags []string, outPath string) error { +func asmFile(goenv *env, srcPath, packagePath string, asmFlags []string, outPath string) error { args := goenv.goTool("asm") args = append(args, asmFlags...) + args = asmAddPackagePathArg(args, packagePath) args = append(args, "-trimpath", ".") args = append(args, "-o", outPath) args = append(args, "--", srcPath) diff --git a/go/tools/builders/asm_go1.go b/go/tools/builders/asm_go1.go new file mode 100644 index 0000000000..5e2964c2f1 --- /dev/null +++ b/go/tools/builders/asm_go1.go @@ -0,0 +1,8 @@ +//go:build !go1.19 + +package main + +func asmAddPackagePathArg(args []string, packagePath string) []string { + // go tool asm does neither support nor require the -p arg in Go < 1.19. + return args +} diff --git a/go/tools/builders/asm_go119.go b/go/tools/builders/asm_go119.go new file mode 100644 index 0000000000..b1b5b82a71 --- /dev/null +++ b/go/tools/builders/asm_go119.go @@ -0,0 +1,10 @@ +//go:build go1.19 + +package main + +func asmAddPackagePathArg(args []string, packagePath string) []string { + if packagePath != "" { + args = append(args, "-p", packagePath) + } + return args +} diff --git a/go/tools/builders/compilepkg.go b/go/tools/builders/compilepkg.go index 6104bb8feb..bc2fc2954f 100644 --- a/go/tools/builders/compilepkg.go +++ b/go/tools/builders/compilepkg.go @@ -474,7 +474,7 @@ func compileArchive( } for i, sSrc := range srcs.sSrcs { obj := filepath.Join(workDir, fmt.Sprintf("s%d.o", i)) - if err := asmFile(goenv, sSrc.filename, asmFlags, obj); err != nil { + if err := asmFile(goenv, sSrc.filename, packagePath, asmFlags, obj); err != nil { return err } objFiles = append(objFiles, obj)