Skip to content

Commit

Permalink
asm: Pass package path with -p
Browse files Browse the repository at this point in the history
This is required to produce linkable objects as of Go 1.19.
  • Loading branch information
fmeum committed Jul 7, 2022
1 parent df02d01 commit de2063a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions go/tools/builders/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ filegroup(
srcs = [
"ar.go",
"asm.go",
"asm_go1.go",
"asm_go119.go",
"builder.go",
"cgo2.go",
"compile.go",
Expand Down
8 changes: 6 additions & 2 deletions go/tools/builders/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions go/tools/builders/asm_go1.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions go/tools/builders/asm_go119.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion go/tools/builders/compilepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit de2063a

Please sign in to comment.