diff --git a/go/tools/builders/asm.go b/go/tools/builders/asm.go index 3d64c9ba37..6704be70f6 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,13 @@ 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, however, go build has been + // emitting -p for both symabi and actual assembly since at least Go1.19 + if packagePath != "" && isGo119OrHigher() { + asmargs = append(asmargs, "-p", packagePath) + } asmargs = append(asmargs, ASM_DEFINES...) asmargs = append(asmargs, "-gensymabis", "-o", symabisName, "--") for _, sFile := range sFiles { diff --git a/go/tools/builders/compilepkg.go b/go/tools/builders/compilepkg.go index 360f69fe0d..b909fa86e0 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)