Skip to content

simd/archsimd: importing simd/archsimd without goexperiment.simd build tag fails compiler build with cryptic error message #78556

Description

@ArsenySamoylov

Go version

go version go1.26.1 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/asamoylov/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/asamoylov/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2071395869=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/asamoylov/GOROOT/src/go.mod'
GOMODCACHE='/home/asamoylov/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/asamoylov/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/asamoylov/GOROOT'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/asamoylov/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/asamoylov/GOROOT/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

While working on CL 753740 (rewriting memhash functions using simd/archsimd intrinsics), I encountered a confusing build failure.

If you forget to add //go:build goexperiment.simd to the file in a compiler source code that imports the simd/archsimd package, then the compiler build fails with a cryptic error.

Here is simple reproducer

diff --git a/src/runtime/import_simd.go b/src/runtime/import_simd.go
new file mode 100644
index 0000000000..97e6fa6b14
--- /dev/null
+++ b/src/runtime/import_simd.go
@@ -0,0 +1,3 @@
+package runtime
+
+import _ "simd/archsimd"
\ No newline at end of file

Run:

./make.bash
# or 
GOEXPERIMENT=simd ./make.bash

What did you see happen?

Outputs:

Building Go cmd/dist using /home/asamoylov/go_bootstrap/. (go1.25.7 linux/amd64)
Building Go toolchain1 using /home/asamoylov/go_bootstrap/.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
usage: compile [options] file.go...
  -%    debug non-static initializers
  -+    compiling runtime
  -B    disable bounds checking
  -C    disable printing of columns in error messages
  -D path
        set relative path for local imports
  -E    debug symbol export
  -I directory
        add directory to import search path
  -K    debug missing line numbers
  -L    also show actual source file names in error messages for positions affected by //line directives
  -N    disable optimizations
  -S    print assembly listing
  -V    print version and exit
  -W    debug parse tree after type checking
  -asan
        build code compatible with C/C++ address sanitizer
  -asmhdr file
        write assembly header to file
  -bench file
        append benchmark times to file
  -blockprofile file
        write block profile to file
  -buildid id
        record id as the build id in the export metadata
  -c int
        concurrency during compilation (1 means no concurrency) (default 80)
  -clobberdead
        clobber dead stack slots (for debugging)
  -clobberdeadreg
        clobber dead registers (for debugging)
  -complete
        compiling complete package (no C or assembly)
  -coveragecfg file
        read coverage configuration from file
  -cpuprofile file
        write cpu profile to file
  -d value
        enable debugging settings; try -d help
  -dwarf
        generate DWARF symbols (default true)
  -dwarfbasentries
        use base address selection entries in DWARF (default true)
  -dwarflocationlists
        add location lists to DWARF in optimized mode (default true)
  -dynlink
        support references to Go symbols defined in other shared libraries
  -e    no limit on number of errors reported
  -embedcfg file
        read go:embed configuration from file
  -env definition
        add definition of the form key=value to environment
  -errorurl
        print explanatory URL with error message if applicable
  -gendwarfinl int
        generate DWARF inline info records (default 2)
  -goversion string
        required version of the runtime
  -h    halt on error
  -importcfg file
        read import configuration from file
  -installsuffix suffix
        set pkg directory suffix
  -j    debug runtime-initialized variables
  -json string
        version,file for JSON compiler/optimizer detail output
  -l    disable inlining
  -lang string
        Go language version source code expects
  -linkobj file
        write linker-specific object to file
  -linkshared
        generate code that will be linked against Go shared libraries
  -live
        debug liveness analysis
  -m    print optimization decisions
  -memprofile file
        write memory profile to file
  -memprofilerate rate
        set runtime.MemProfileRate to rate
  -msan
        build code compatible with C/C++ memory sanitizer
  -mutexprofile file
        write mutex profile to file
  -nolocalimports
        reject local (relative) imports
  -o file
        write output to file
  -p path
        set expected package import path
  -pack
        write to file.a instead of file.o
  -pgoprofile file
        read profile or pre-process profile from file
  -r    debug generated wrappers
  -race
        enable race detector
  -shared
        generate code that can be linked into a shared library
  -smallframes
        reduce the size limit for stack allocated objects
  -spectre list
        enable spectre mitigations in list (all, index, ret)
  -std
        compiling standard library
  -symabis file
        read symbol ABIs from file
  -t    enable tracing for debugging the compiler
  -traceprofile file
        write an execution trace to file
  -trimpath prefix
        remove prefix from recorded source file paths
  -v    increase debug verbosity
  -w    debug type checking
  -wb
        enable write barrier (default true)

go tool dist: FAILED: /home/asamoylov/GOROOT/pkg/tool/linux_amd64/compile -std -pack -o /tmp/go-tool-dist-3652736594/simd/archsimd/_go_.a -p simd/archsimd -importcfg /tmp/go-tool-dist-3652736594/simd/archsimd/importcfg -asmhdr /tmp/go-tool-dist-3652736594/simd/archsimd/go_asm.h -symabis /tmp/go-tool-dist-3652736594/simd/archsimd/symabis: exit status 2

What did you expect to see?

Something like

package simd/archsimd requires goexperiment.simd (missing //go:build tag?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions