Skip to content

Commit 8dc4747

Browse files
committed
Fix invocation of assembler for go1.22
In go1.19 through go1.22-devel (as of golang/go@6382893) a series of changes were made to the way assembly files' symabis are produced. https://go-review.googlesource.com/c/go/+/523337 Most significantly, the packagename now must be passed to the assembler via the -p flag, even when generating only the symabis. The go build system does this, but Bazel Go rules have not, and this finally breaks in go1.22-devel as the compatibility code is removed. Without specifying -p to the assembler, the output symabis file will contain something like: ``` def <unlinkable>.s2Decode ABI0 ``` instead of ``` def github.com/klauspost/compress/s2.s2Decode ABI0 ``` The result is that the compiler will default to using ABIInternal instead of ABI0 if it cannot resolve a match in symabis, which will cause a link failure: ``` Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging github.com/klauspost/compress/s2.Decode: relocation target github.com/klauspost/compress/s2.s2Decode not defined for ABIInternal (but is defined for ABI0) link: error running subcommand external/go_sdk/pkg/tool/darwin_arm64/link: exit status 2 ``` We conservatively only do this for go minor releases later than 1.21.
1 parent c009a2b commit 8dc4747

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

go/tools/builders/asm.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var ASM_DEFINES = []string{
3535
// by the compiler. This is only needed in go1.12+ when there is at least one
3636
// .s file. If the symabis file is not needed, no file will be generated,
3737
// and "", nil will be returned.
38-
func buildSymabisFile(goenv *env, sFiles, hFiles []fileInfo, asmhdr string) (string, error) {
38+
func buildSymabisFile(goenv *env, packagePath string, sFiles, hFiles []fileInfo, asmhdr string) (string, error) {
3939
if len(sFiles) == 0 {
4040
return "", nil
4141
}
@@ -94,6 +94,13 @@ func buildSymabisFile(goenv *env, sFiles, hFiles []fileInfo, asmhdr string) (str
9494
seenHdrDirs[hdrDir] = true
9595
}
9696
}
97+
// The package path has to be specified as of Go 1.22 or the resulting
98+
// object will be unlinkable, but the -p flag is only required in
99+
// preparing symabis since Go1.22, however, go build has been
100+
// emitting -p for both symabi and actual assembly since at least Go1.19
101+
if packagePath != "" && isGo119OrHigher() {
102+
asmargs = append(asmargs, "-p", packagePath)
103+
}
97104
asmargs = append(asmargs, ASM_DEFINES...)
98105
asmargs = append(asmargs, "-gensymabis", "-o", symabisName, "--")
99106
for _, sFile := range sFiles {

go/tools/builders/compilepkg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ func compileArchive(
471471
}
472472
var symabisPath string
473473
if !haveCgo {
474-
symabisPath, err = buildSymabisFile(goenv, srcs.sSrcs, srcs.hSrcs, asmHdrPath)
474+
symabisPath, err = buildSymabisFile(goenv, packagePath, srcs.sSrcs, srcs.hSrcs, asmHdrPath)
475475
if symabisPath != "" {
476476
if !goenv.shouldPreserveWorkDir {
477477
defer os.Remove(symabisPath)

0 commit comments

Comments
 (0)