Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asm: Pass package path with -p #3231

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions go/tools/builders/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -60,7 +61,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,12 +141,34 @@ 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...)
// The package path has to be specified as of Go 1.19 or the resulting
// object will be unlinkable, but the -p flag is also only available
// since Go 1.19.
if packagePath != "" && isGo119OrHigher() {
args = append(args, "-p", packagePath)
}
fmeum marked this conversation as resolved.
Show resolved Hide resolved
args = append(args, "-trimpath", ".")
args = append(args, "-o", outPath)
args = append(args, "--", srcPath)
absArgs(args, []string{"-I", "-o", "-trimpath"})
return goenv.runCommand(args)
}

var goMinorVersionRegexp = regexp.MustCompile(`^go1\.(\d+)`)

func isGo119OrHigher() bool {
match := goMinorVersionRegexp.FindStringSubmatch(runtime.Version())
if match == nil {
// Developer version or something with an unparseable version string,
// assume Go 1.19 or higher.
return true
}
minorVersion, err := strconv.Atoi(match[1])
if err != nil {
return true
}
return minorVersion >= 19
}
fmeum marked this conversation as resolved.
Show resolved Hide resolved
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