invalid instruction: 00105

313 views
Skip to first unread message

Jan Mercl

unread,
Sep 30, 2020, 7:18:41 AM9/30/20
to golang-dev
Observation:

jnml@e5-1650:~/tmp/csmith$ go version
go version go1.15.2 linux/amd64
jnml@e5-1650:~/tmp/csmith$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jnml/.cache/go-build"
GOENV="/home/jnml/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jnml/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jnml"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/jnml/src/go.googlesource.com/go/goroot"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/jnml/src/go.googlesource.com/go/goroot/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build571607678=/tmp/go-build -gno-record-gcc-switches"
jnml@e5-1650:~/tmp/csmith$ cat main.go
package foo

import "modernc.org/libc"

func safe_div_func_int16_t_s_s(tls *libc.TLS, si1 int16, si2 int16) int16 {
        if (int32(si2) == 0) || ((int32(si1) == (-32767 - 1)) && (int32(si2) == (-1))) {
                return si1
        }
        return (int16(int32(si1) / int32(si2)))
}

func safe_lshift_func_int16_t_s_u(tls *libc.TLS, left int16, right uint32) int16 {
        if ((int32(left) < 0) || ((right) >= uint32(32))) || (int32(left) > (int32((32767)) >> (right))) {
                return left
        }
        return (int16(int32(left) << (right)))
}

func safe_sub_func_int32_t_s_s(tls *libc.TLS, si1 int32, si2 int32) int32 {
        if ((si1 ^ si2) & (((si1 ^ ((si1 ^ si2) & (^int32(libc.Int32FromInt32(2147483647))))) - si2) ^ si2)) < 0 {
                return si1
        }
        return (si1 - si2)
}

func safe_unary_minus_func_int64_t_s(tls *libc.TLS, si int64) int64 {
        if si == (-9223372036854775807 - int64(1)) {
                return si
        }
        return -si
}

func safe_sub_func_uint16_t_u_u(tls *libc.TLS, ui1 uint16, ui2 uint16) uint16 {
        return (uint16(int32(ui1) - int32(ui2)))
}

func func_44(tls *libc.TLS) uint16 {
        return safe_sub_func_uint16_t_u_u(tls, (uint16((int32(safe_div_func_int16_t_s_s(tls, 0, int16(safe_sub_func_int32_t_s_s(tls, 1, int32(safe_lshift_func_int16_t_s_u(tls, int16(0x1504), uint32(safe_unary_minus_func_int64_t_s(tls, int64(libc.Bool32(true))))))))))))), 0)
}
jnml@e5-1650:~/tmp/csmith$ go build main.go
# command-line-arguments
./main.go:38:2: invalid instruction: 00105 (/home/jnml/tmp/csmith/main.go:38)   MOVL    $11553462026240, AX
jnml@e5-1650:~/tmp/csmith$ 



I was not able to minimize further. There's another reproducer, not yet minimized, that fails with:

./main.go:3135:5: invalid instruction: 00023 (/tmp/ccgo-test-818897172/main.go:2833) ORL $-2147483649, DX

Let me know when needed as well.

Austin Clements

unread,
Sep 30, 2020, 9:27:19 AM9/30/20
to Jan Mercl, golang-dev
Hi Jan. This looks like a real bug, so could you post an issue to the issue tracker? The compiler shouldn't produce a 32-bit MOV of an immediate that's larger than 32 bits.

(Coincidentally, the "00105" isn't the invalid instruction, that's just the relative PC of the instruction. So "cmd/compile: invalid instruction: MOVL $11553462026240, AX" is probably a better issue title.)

Thanks!

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/CAA40n-XD%2BNM3MrAdPM_NAsv7nDKGQ%2Bb6c%2Bq5VNCz6wr%2Br-RzYQ%40mail.gmail.com.

Jan Mercl

unread,
Sep 30, 2020, 9:43:40 AM9/30/20
to Austin Clements, golang-dev
On Wed, Sep 30, 2020 at 3:27 PM Austin Clements <aus...@google.com> wrote:

> This looks like a real bug, so could you post an issue to the issue tracker? The compiler shouldn't produce a 32-bit MOV of an immediate that's larger than 32 bits.
>
> (Coincidentally, the "00105" isn't the invalid instruction, that's just the relative PC of the instruction. So "cmd/compile: invalid instruction: MOVL $11553462026240, AX" is probably a better issue title.)

I don't have a Github account, but please find enclosed the filled-in
issue template. Please post it to the issue tracker, thank you.
issue

Alberto Donizetti

unread,
Sep 30, 2020, 9:47:49 AM9/30/20
to Jan Mercl, Austin Clements, golang-dev
I've filed this as https://github.com/golang/go/issues/41711.
> --
> You received this message because you are subscribed to the Google Groups "golang-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/CAA40n-XKGJjKtxRYxcQK_Dx47DoBc1tLB7JQTLkNBnY3Gkj%3DgA%40mail.gmail.com.

Jan Mercl

unread,
Nov 20, 2020, 2:11:10 PM11/20/20
to golang-dev
---------- Forwarded message ---------
From: Jan Mercl <0xj...@gmail.com>
Date: Wed, Sep 30, 2020 at 1:17 PM
Subject: invalid instruction: 00105
To: golang-dev <golan...@googlegroups.com>


> jnml@e5-1650:~/tmp/csmith$ go build main.go
> # command-line-arguments
> ./main.go:38:2: invalid instruction: 00105 (/home/jnml/tmp/csmith/main.go:38) MOVL $11553462026240, AX
> jnml@e5-1650:~/tmp/csmith$

This one seems to be now fixed, thanks.

> There's another reproducer, not yet minimized, that fails with:
>
> ./main.go:3135:5: invalid instruction: 00023 (/tmp/ccgo-test-818897172/main.go:2833) ORL $-2147483649, DX
>
> Let me know when needed as well.

Only today I finally revisited this using go version go1.15.5
linux/amd64 and sadly the failure still seems to exist.

Please let me know if more input is needed, thanks.

Keith Randall

unread,
Nov 20, 2020, 2:59:06 PM11/20/20
to Jan Mercl, golang-dev
On Fri, Nov 20, 2020 at 11:11 AM Jan Mercl <0xj...@gmail.com> wrote:
---------- Forwarded message ---------
From: Jan Mercl <0xj...@gmail.com>
Date: Wed, Sep 30, 2020 at 1:17 PM
Subject: invalid instruction: 00105
To: golang-dev <golan...@googlegroups.com>


> jnml@e5-1650:~/tmp/csmith$ go build main.go
> # command-line-arguments
> ./main.go:38:2: invalid instruction: 00105 (/home/jnml/tmp/csmith/main.go:38)   MOVL    $11553462026240, AX
> jnml@e5-1650:~/tmp/csmith$

This one seems to be now fixed, thanks.

> There's another reproducer, not yet minimized, that fails with:
>
> ./main.go:3135:5: invalid instruction: 00023 (/tmp/ccgo-test-818897172/main.go:2833) ORL $-2147483649, DX
>

Can you post the source code that generated this error? I don't see it in this thread anywhere.
 
> Let me know when needed as well.

Only today I finally revisited this using go version go1.15.5
linux/amd64 and sadly the failure still seems to exist.

Please let me know if more input is needed, thanks.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.

Jan Mercl

unread,
Nov 20, 2020, 3:09:50 PM11/20/20
to Keith Randall, golang-dev
On Fri, Nov 20, 2020 at 8:58 PM Keith Randall <k...@google.com> wrote:

> Can you post the source code that generated this error? I don't see it in this thread anywhere.

Sure. But it's a multi-thousand line Go file generated from a random
program generated by CSmith. If you're fine with that, let me know and
I'll attach it in an archive.

If you want it minimized, the problem is that I'm not sure when I can
find the free hours to do that. It may take a few days...

What's your choice?

-j

Keith Randall

unread,
Nov 20, 2020, 3:10:28 PM11/20/20
to Jan Mercl, golang-dev
A giant dump is fine.

Jan Mercl

unread,
Nov 20, 2020, 3:19:34 PM11/20/20
to Keith Randall, golang-dev
On Fri, Nov 20, 2020 at 9:10 PM Keith Randall <k...@google.com> wrote:

> A giant dump is fine.

Please see the attached file.

----

jnml@3900x:~/tmp/csmith$ go version
go version go1.15.5 linux/amd64
jnml@3900x:~/tmp/csmith$ go build main.go
# command-line-arguments
./main.go:3134:5: invalid instruction: 00023
(/home/jnml/tmp/csmith/main.go:2832) ORL $-2147483649, DX
jnml@3900x:~/tmp/csmith$

-j
main.go.tar.gz

Keith Randall

unread,
Nov 20, 2020, 5:13:40 PM11/20/20
to Jan Mercl, golang-dev
Ok, fixes winging their way through Gerrit.

Jan Mercl

unread,
Nov 20, 2020, 5:22:30 PM11/20/20
to Keith Randall, golang-dev
Great, thanks! 
Reply all
Reply to author
Forward
0 new messages