Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: miscompilation of some arithmetic and conditionals on arm [1.15 backport] #42930

Closed
gopherbot opened this issue Dec 1, 2020 · 3 comments
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge
Milestone

Comments

@gopherbot
Copy link

@zx2c4 requested issue #42876 to be considered for backport to the next 1.15 minor release.

@gopherbot please backport this because compiler bugs in bitmath seem worrisome

@gopherbot gopherbot added the CherryPickCandidate Used during the release process for point releases label Dec 1, 2020
@gopherbot gopherbot added this to the Go1.15.6 milestone Dec 1, 2020
@cagedmantis cagedmantis modified the milestones: Go1.15.6, Go1.15.7 Dec 3, 2020
@toothrot toothrot added the CherryPickApproved Used during the release process for point releases label Jan 7, 2021
@toothrot
Copy link
Contributor

toothrot commented Jan 7, 2021

Approving as a serious issue with no workaround.

@gopherbot gopherbot removed the CherryPickCandidate Used during the release process for point releases label Jan 7, 2021
@gopherbot
Copy link
Author

Change https://golang.org/cl/282432 mentions this issue: [release-branch.go1.15] cmd/compile: do not assume TST and TEQ set V on arm

@dmitshur dmitshur modified the milestones: Go1.15.7, Go1.15.8 Jan 19, 2021
@cagedmantis cagedmantis modified the milestones: Go1.15.8, Go1.15.9 Feb 4, 2021
@gopherbot
Copy link
Author

Closed by merging d9b4ef5 to release-branch.go1.15.

gopherbot pushed a commit that referenced this issue Mar 1, 2021
…on arm

These replacement rules assume that TST and TEQ set V. But TST and
TEQ do not set V. This is a problem because instructions like LT are
actually checking for N!=V. But with TST and TEQ not setting V, LT
doesn't do anything meaningful. It's possible to construct trivial
miscompilations from this, such as:

    package main

    var x = [4]int32{-0x7fffffff, 0x7fffffff, 2, 4}

    func main() {
        if x[0] > x[1] {
            panic("fail 1")
        }
        if x[2]&x[3] < 0 {
            panic("fail 2") // Fails here
        }
    }

That first comparison sets V, via the CMP that subtracts the values
causing the overflow. Then the second comparison operation thinks that
it uses the result of TST, when it actually uses the V from CMP.

Before this fix:

    TST             R0, R1
    BLT             loc_6C164

After this fix:

    TST             R0, R1
    BMI             loc_6C164

The BMI instruction checks the N flag, which TST sets.  This commit
fixes the issue by using [LG][TE]noov instead of vanilla [LG][TE], and
also adds a test case for the direct issue.

Updates #42876.
Fixes #42930.

Change-Id: I13c62c88d18574247ad002b671b38d2d0b0fc6fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/282432
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
@toothrot toothrot modified the milestones: Go1.15.9, Go1.15.10 Mar 10, 2021
dweomer added a commit to dweomer/k3s that referenced this issue Mar 19, 2021
See golang/go#42930 which addresses an issue
on arm.

Signed-off-by: Jacob Blain Christen <jacob@rancher.com>
@golang golang locked and limited conversation to collaborators Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

5 participants
@toothrot @cagedmantis @dmitshur @gopherbot and others