Closed sAnjAy060897 closed 7 months ago
Strange. This looks like somehow your program is not being initialized correctly (or at all). I suspect a corrupt installation. Maybe you installed 1.21.6 overtop 1.18.9? Nevertheless, try blowing away your 1.21.6 and reinstalling fresh.
Thanks for your response @randall77 .
We tried 1.20.13 and that works fine and all go programs in our product came up fine. When we tried 1.21.0, it failed with the above mentioned error.
Is there a way to verify the installation after the toolchain is upgraded? The go env seems ok. Any other way to check?
Build a hello world that prints os.Args[0]
and see if that works. That's one of the expressions your program crashed on that should never fail.
@randall77 Thanks for your suggestion. Tried the same and the programs seems to run fine on the target.
./hello-world
Hello World printing args[0]
1 [./hello-world]
We see the programs (our most programs do) importing sha1, md5 and flag packages are exiting with the above mentioned index out of range error.
Try adding import _ "flag"
to your hello world program?
Frankly, I'm at a loss for what this could be. Clearly something is getting screwed up very early in initialization. Can you share a program on which this occurs?
Are you doing anything nonstandard, like using a Go program called from a C library?
A bunch of your environment variables look odd to me, maybe try unsetting them to see if that helps? GOROOT
, CGO_CFLAGS
, CGO_LDFLAGS
, etc.
Might also try go clean -cache
.
After importing flag package, program did not start with the same error.
No. We are not using go program from C library. Unsetting env variables and cleaning cache did not help either.
So this program
package main
import (
_ "flag"
"fmt"
)
func main() {
fmt.Println("hello world")
}
Builds ok but crashes when you try to run it?
That's correct.
And FYI - we used the yocto patches available at https://patchwork.yoctoproject.org/project/oe-core/patch/20231207100712.67076-1-jose.quaresma@foundries.io/ to build go 1.21 toolchain
Try without those patches.
We were not able to get rid of the patches (it would take a lot of effort to redefine the build instruction for go programs) as the go programs in our product depend on yocto build system to compile and go toolchain is built differently in yocto (https://blog.gopheracademy.com/advent-2015/go-in-a-yocto-project/).
We are able to build the go 1.21.6 toolchain in yocto build system and the programs are running fine on the target after using the patches provided by yocto contributions here https://patchwork.yoctoproject.org/project/oe-core/list/?series=22831.
I guess yocto will soon align with upstream go release (1.22.x) soon and these run time panic may not be seen with the official recipes and patches.
I'm going to close this as I don't think there's anything here for the Go project to do.
Go version
go version go1.21.6 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Upgraded go toolchain in our product from go 1.18.9 to go1.21.6 and ran the image in the target. We use yocto build system to compile our product modules. go1.21.6 is built from source.
What did you see happen?
All go programs failed to start with index out of range in one of the sha1, md5 and flag packages.
panic: runtime error: index out of range [3] with length 0
goroutine 1 [running]: crypto.RegisterHash(...) /usr/lib/go/src/crypto/crypto.go:149 crypto/sha1.init.0() /usr/lib/go/src/crypto/sha1/sha1.go:19 +0x65
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]: flag.init() /usr/lib/go/src/flag/flag.go:1199 +0xf9
What did you expect to see?
Go programs to start normally.