aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Quirke <jqr@jquirke.com.au>2024-02-07 02:05:42 -0800
committerGitHub <noreply@github.com>2024-02-07 10:05:42 +0000
commitfe5c2e2b0c26742e3ea856bb512e9f8be8db9b27 (patch)
tree17d352c98e9d2316f9fa74254570a1878d2dab6c
parent07317c7ce2ae6e6cda269c0c3ec7eac171363936 (diff)
downloadbazelbuild-rules_go-fe5c2e2b0c26742e3ea856bb512e9f8be8db9b27.tar.gz
Fix invocation of assembler for go1.22 (#3756)
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.
-rw-r--r--go/tools/builders/asm.go9
-rw-r--r--go/tools/builders/compilepkg.go2
2 files changed, 9 insertions, 2 deletions
diff --git a/go/tools/builders/asm.go b/go/tools/builders/asm.go
index 3d64c9ba..6704be70 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 360f69fe..b909fa86 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)