golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.43k stars 17.59k forks source link

fork/exec: pkg/tool/solaris_amd64/compile: bad address #60045

Closed Toasterson closed 1 year ago

Toasterson commented 1 year ago

What version of Go are you using (go version)?

$ go version
go version go1.19.9 illumos/amd64

Does this issue reproduce with the latest release?

Yes I am trying to build golang 1.20 but cannot do so. Thus 1.19 is the latest release I am able to build

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/ws/toasty/.cache/go-build"
GOENV="/ws/toasty/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="illumos"
GOINSECURE=""
GOMODCACHE="/ws/toasty/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="illumos"
GOPATH="/ws/toasty/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/golang/1.19"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/1.19/pkg/tool/illumos_amd64"
GOVCS=""
GOVERSION="go1.19.9"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="/usr/gcc/10/bin/gcc"
CXX="/usr/gcc/10/bin/g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1777881768=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run ./make.bash to compile golang 1.20

What did you expect to see?

Golang 1.20 compiling

What did you see instead?

go: error obtaining buildID for go tool compile: fork/exec /ws/toasty/oi-userland/components/developer/golang-120/build/amd64/pkg/tool/solaris_amd64/compile: bad address

seankhliao commented 1 year ago

cc @golang/illumos

bcmills commented 1 year ago

I don't understand why the error would refer to /ws/toasty/oi-userland/components/developer/golang-120/build/amd64/pkg/tool/solaris_amd64/compile at all — it should refer to pkg/tool/illumos_amd64/compile instead.

@Toasterson, what environment did you have set when running ./make.bash?

What other output did make.bash produce?

Toasterson commented 1 year ago

The thing with the solaris name being produced is quite normal actually. All golang versions try to detect the OS, see SunOS and then switch to solaris. We have to switch to illumos manually.

Full build log and command
toasty@oibuild:~/oi-userland/components/developer/golang-120$ gmake clean sample-manifest
/bin/rm -f -r golang-1.20.4 required-pkgs.mk /ws/toasty/oi-userland/components/developer/golang-120/build/mkgeneric-perl /ws/toasty/oi-userland/components/developer/golang-120/build/mkgeneric-python /ws/toasty/oi-userland/components/developer/golang-120/build/mkgeneric-ruby
/bin/rm -f -r /ws/toasty/oi-userland/components/developer/golang-120/build /ws/toasty/oi-userland/components/developer/golang-120/build/prototype/i386
/bin/rm -f -r /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4
/usr/bin/env RUBY_VERSION=2.3 /ws/toasty/oi-userland/tools/userland-unpack  /ws/toasty/oi-userland/archives/go1.20.4.src.tar.gz
/bin/mv -f go golang-1.20.4
/usr/bin/touch /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4/.unpacked
/usr/gnu/bin/patch -d /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4 --strip=1 --backup --version-control=numbered < patches/01-golang-gdb-python-test.patch
patching file src/runtime/runtime-gdb_test.go
Hunk #1 succeeded at 87 with fuzz 1 (offset 27 lines).
/usr/bin/touch /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4/.patched-01-golang-gdb-python-test.patch
/usr/gnu/bin/patch -d /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4 --strip=1 --backup --version-control=numbered < patches/02_Dup2_golang10.patch
patching file src/syscall/zsyscall_solaris_amd64.go
Hunk #1 succeeded at 23 (offset 2 lines).
Hunk #2 succeeded at 112 (offset 6 lines).
Hunk #3 succeeded at 204 (offset 10 lines).
Hunk #4 succeeded at 476 with fuzz 2 (offset 63 lines).
/usr/bin/touch /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4/.patched-02_Dup2_golang10.patch
/usr/bin/touch /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4/.patched
/usr/bin/touch /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4/.prep
/bin/rm -f -r /ws/toasty/oi-userland/components/developer/golang-120/build/amd64 ; /bin/mkdir -p /ws/toasty/oi-userland/components/developer/golang-120/build/amd64
/usr/bin/env CLONEY_MODE="copy" /ws/toasty/oi-userland/tools/cloney /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4 /ws/toasty/oi-userland/components/developer/golang-120/build/amd64
copy cloning /ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4 to /ws/toasty/oi-userland/components/developer/golang-120/build/amd64
(cd /ws/toasty/oi-userland/components/developer/golang-120/build/amd64/src; /usr/bin/env LD_OPTIONS="-M /usr/lib/ld/map.noexstk -M /usr/lib/ld/map.noexdata -M /usr/lib/ld/map.pagealign -Bdirect -z ignore" LD_EXEC_OPTIONS="-z aslr=disable" PATH="/usr/openssl/1.1/bin:/usr/bin/amd64:/usr/bin:/usr/gnu/bin:/usr/sbin/amd64:/usr/sbin:/usr/perl5/5.36/bin"  GOROOT_FINAL="/usr/lib/golang/1.20" GOEXPERIMENT="" GOOS="illumos" GOCACHE="/ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4/gocache" GOPATH="/ws/toasty/oi-userland/components/developer/golang-120/golang-1.20.4/gopath" GO_LDSO=/lib/64/ld.so.1 CC="/usr/gcc/10/bin/gcc" CXX="/usr/gcc/10/bin/g++" CFLAGS="-m64 -O3" CXXFLAGS="-m64 -O3" LDFLAGS="-m64" ./make.bash)
Building Go cmd/dist using /usr/lib/golang/1.19. (go1.19.9 solaris/amd64)
Building Go toolchain1 using /usr/lib/golang/1.19.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
go: error obtaining buildID for go tool compile: fork/exec /ws/toasty/oi-userland/components/developer/golang-120/build/amd64/pkg/tool/solaris_amd64/compile: bad address
internal/goarch: open /tmp/go-build1667221411/b006/importcfg: no such file or directory
go tool dist: FAILED: /ws/toasty/oi-userland/components/developer/golang-120/build/amd64/pkg/tool/solaris_amd64/go_bootstrap install cmd/asm cmd/cgo cmd/compile cmd/link: exit status 1
gmake: *** [/ws/toasty/oi-userland/make-rules/justmake.mk:62: /ws/toasty/oi-userland/components/developer/golang-120/build/amd64/.built] Error 2
jclulow commented 1 year ago
Building Go cmd/dist using /usr/lib/golang/1.19. (go1.19.9 solaris/amd64)

This seems unusual to me -- if you're on illumos, I would expect it to say, e.g.,

$ go version
go version go1.19.5 illumos/amd64
Toasterson commented 1 year ago

Yep, but it does that while packaging from oi-userland. Always has. I never got it to recognize it's on illumos. I have no idea how to get that.

Also note that I am using the illumos version of go which is built as cross-compiled go toolchain by default

bcmills commented 1 year ago

For comparison, the illumos builder for the Go project says (https://build.golang.org/log/dbf7e4d2062af5353899fac86db04cd447b4ec80):

:: Running /var/tmp/workdir-host-illumos-amd64-jclulow/go/src/make.bash with args ["/var/tmp/workdir-host-illumos-amd64-jclulow/go/src/make.bash"] and env ["_=*9*/opt/go/build/bin/stage0" "GO_BUILDER_ENV=host-illumos-amd64-jclulow" "HOME=/home/gobuild" "LANG=en_US.UTF-8" "LOGNAME=gobuild" "PATH=/usr/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/opt/go/bootstrap/bin" "SHLVL=1" "SMF_FMRI=svc:/site/buildlet:default" "SMF_METHOD=start" "SMF_RESTARTER=svc:/system/svc/restarter:default" "SMF_ZONENAME=global" "TZ=UTC" "USER=gobuild" "A__z=\"*SHLVL" "GO_STAGE0_NET_DELAY=300ms" "GO_STAGE0_DL_DELAY=1.9s" "WORKDIR=/var/tmp/workdir-host-illumos-amd64-jclulow" "GOROOT_BOOTSTRAP=/var/tmp/workdir-host-illumos-amd64-jclulow/go1.4" "GO_BUILDER_NAME=illumos-amd64" "GOBIN=" "TMPDIR=/var/tmp/workdir-host-illumos-amd64-jclulow/tmp" "GOCACHE=/var/tmp/workdir-host-illumos-amd64-jclulow/gocache" "PWD=/var/tmp/workdir-host-illumos-amd64-jclulow/go/src"] in dir /var/tmp/workdir-host-illumos-amd64-jclulow/go/src

Building Go cmd/dist using /var/tmp/workdir-host-illumos-amd64-jclulow/go1.4. (go1.17.13 illumos/amd64)
Building Go toolchain1 using /var/tmp/workdir-host-illumos-amd64-jclulow/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for illumos/amd64.
---
Installed Go for illumos/amd64 in /var/tmp/workdir-host-illumos-amd64-jclulow/go
Installed commands in /var/tmp/workdir-host-illumos-amd64-jclulow/go/bin
*** You need to add /var/tmp/workdir-host-illumos-amd64-jclulow/go/bin to your PATH.

So this looks to me like maybe something specific to oi-userland?

Toasterson commented 1 year ago

The thing is whenever we try to build golang /usr/lib/golang/1.X/bin/go always end up being the solaris/amd64 version

toasty@oibuild:~/oi-userland/components/developer/golang-120/build/amd64/src$ /usr/lib/golang/1.19/bin/go version
go version go1.19.9 solaris/amd64

The illumos version always ends up in /usr/lib/golang/1.X/bin/illumos_amd64/go

toasty@oibuild:~/oi-userland/components/developer/golang-120/build/amd64/src$ /usr/lib/golang/1.19/bin/illumos_amd64/go version
go version go1.19.9 illumos/amd64

I never managed to tell golang to put the illumos version under bin directly. And Moving it after the fact in the packaging broke things the last time. /usr/bin/go however is linked to the illumos version. /usr/bin/go -> ../lib/golang/1.19/bin/illumos_amd64/go

So somehow the build is always using the /usr/lib/golang version directly or keeps detecting the solaris OS somewhere in the build bash scripts. building normal golang apps correctly uses the illumos/amd64 version.

jclulow commented 1 year ago

Can you grab one of the stock builds I have put up, e.g., https://illumos.org/downloads/go1.19.5.illumos-amd64.tar.gz and try to use that for GOROOT_BOOTSTRAP instead of the previous OI build?

Toasterson commented 1 year ago

@jclulow That worked. So somehow the go version in illumos was faulty?

jclulow commented 1 year ago

I'm not sure what's up with whatever binaries you had in /usr/lib/golang/1.19, but it feels like they were built for GOOS=solaris and not GOOS=illumos. It seems like when you were using that toolchain to try to build GOOS=illumos binaries, they were showing up under the OS/arch-specific directory which is what happens when you cross-compile a toolchain, I think?

Part of our goal with splitting solaris and illumos was to allow us to cope with the increasingly less subtle differences between illumos and Oracle's proprietary fork over the last decade. I would not be surprised to find there is at least one subtle difference between a solaris and an illumos toolchain that would lead to confusing failures like this one -- it is definitely not correct to run a Solaris binary on illumos at this point, etc.

If you take your newly working build, boot-strapped with the binaries I linked, and publish that to the package repository, hopefully subsequent builds which use that new package for GOROOT_BOOTSTRAP work correctly and also continue to natively produce illumos/amd64 binaries?

Toasterson commented 1 year ago

That is my hope too. I made openindiana/oi-userland#12021 with that but I need to find a bit more of an intelligent bootstrap downloader again. Let's see if it future releases now do the right thing and are fully illumos native in the builds. (One can hope) Otherwise I'll open a new ticket with golang 1.21 to fix that based on this new bootstrap :)

Thanks for the help. Closing as solved.