diff --git a/go/tools/builders/asm.go b/go/tools/builders/asm.go index 3d64c9ba37..8bf51ff936 100644 --- a/go/tools/builders/asm.go +++ b/go/tools/builders/asm.go @@ -35,7 +35,7 @@ var ASM_DEFINES = []string{ // by the compiler. This is only needed in go1.12+ when there is at least one // .s file. If the symabis file is not needed, no file will be generated, // and "", nil will be returned. -func buildSymabisFile(goenv *env, sFiles, hFiles []fileInfo, asmhdr string) (string, error) { +func buildSymabisFile(goenv *env, packagePath string, sFiles, hFiles []fileInfo, asmhdr string) (string, error) { if len(sFiles) == 0 { return "", nil } @@ -94,6 +94,12 @@ func buildSymabisFile(goenv *env, sFiles, hFiles []fileInfo, asmhdr string) (str seenHdrDirs[hdrDir] = true } } + // The package path has to be specified as of Go 1.22 or the resulting + // object will be unlinkable, but the -p flag is only required in + // preparing symabis since Go1.22 + if packagePath != "" && isGoMinorVersionEqualHigher(22) { + asmargs = append(asmargs, "-p", packagePath) + } asmargs = append(asmargs, ASM_DEFINES...) asmargs = append(asmargs, "-gensymabis", "-o", symabisName, "--") for _, sFile := range sFiles { @@ -110,7 +116,7 @@ func asmFile(goenv *env, srcPath, packagePath string, asmFlags []string, outPath // 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() { + if packagePath != "" && isGoMinorVersionEqualHigher(19) { args = append(args, "-p", packagePath) } args = append(args, ASM_DEFINES...) @@ -123,16 +129,16 @@ func asmFile(goenv *env, srcPath, packagePath string, asmFlags []string, outPath var goMinorVersionRegexp = regexp.MustCompile(`^go1\.(\d+)`) -func isGo119OrHigher() bool { +func isGoMinorVersionEqualHigher(requiredMinor int) bool { match := goMinorVersionRegexp.FindStringSubmatch(runtime.Version()) if match == nil { // Developer version or something with an unparseable version string, - // assume Go 1.19 or higher. + // assume it matches the conditions return true } minorVersion, err := strconv.Atoi(match[1]) if err != nil { return true } - return minorVersion >= 19 + return minorVersion >= requiredMinor } diff --git a/go/tools/builders/compilepkg.go b/go/tools/builders/compilepkg.go index b3a6d283a9..b0cb0dbfa0 100644 --- a/go/tools/builders/compilepkg.go +++ b/go/tools/builders/compilepkg.go @@ -471,7 +471,7 @@ func compileArchive( } var symabisPath string if !haveCgo { - symabisPath, err = buildSymabisFile(goenv, srcs.sSrcs, srcs.hSrcs, asmHdrPath) + symabisPath, err = buildSymabisFile(goenv, packagePath, srcs.sSrcs, srcs.hSrcs, asmHdrPath) if symabisPath != "" { if !goenv.shouldPreserveWorkDir { defer os.Remove(symabisPath)