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: open-coded defers are broken on riscv64 #36786

4a6f656c opened this issue Jan 26, 2020 · 4 comments

cmd/compile: open-coded defers are broken on riscv64 #36786

4a6f656c opened this issue Jan 26, 2020 · 4 comments


Copy link

@4a6f656c 4a6f656c commented Jan 26, 2020

Open-coded defers are currently broken on riscv64 - this is noticeable with a failure of runtime/TestRecursivePanic2 and hangs/missing defer execution in net/http and time/TestConcurrentTimerReset tests.

The following code (from the TestRecursivePanic2 test):

package main

import "fmt"

func blah(){
        func() {
                defer func() {
                var x [8192]byte
                func(x [8192]byte) {
                        defer func() {
                                panic("second panic")
                        defer func() {
                        panic("first panic")
        panic("third panic")

func main() {

Results in:

first panic
runtime: unexpected return pc for main.blah.func1.2 called from 0x1
stack: frame={sp:0x202807bf20, fp:0x202807bf50} stack=[0x2028078000,0x2028080000)
000000202807be20:  000000202804a0c0  00000020280160a0
000000202807be30:  000000000009a710 <sync.(*Pool).Put+72>  000000000019ec88
000000202807be40:  0000000000000004  0000000000000000
000000202807be50:  0000000000000000  00000000000c00e8 <fmt.(*pp).free+240>
000000202807be60:  000000000019ec80  0000002028080000
000000202807be70:  0000000000000000  00000000000c0444 <fmt.Fprintln+180>
000000202807be80:  000000000019ec80  00000000000f61e0
000000202807be90:  000000202805a820  00000000000c7f4c <main.blah.func1.1+140>
000000202807bea0:  000000202805a820  00000020280160a0
000000202807beb0:  0000000000000006  0000000000000010
000000202807bec0:  0000000000000006  0000000000000000
000000202807bed0:  0000000000000000  0000000000000000
000000202807bee0:  0000000000000006  000000202805a820
000000202807bef0:  0000000000000000  00000000000c81cc <main.blah.func1+252>
000000202807bf00:  0000000000118b20  000000202800c018
000000202807bf10:  000000202807bf40  0000000000000001
000000202807bf20: <0000000000000001  0000000000000006
000000202807bf30:  0000000000000000  0000000000000000
000000202807bf40:  0000000000000000  0000000000000000
000000202807bf50: >00000000000c7e5c <main.blah+44>  0000000000000000
000000202807bf60:  0000000000000000  0000000000000000
000000202807bf70:  0000000000000000  0000000000000000
000000202807bf80:  0000000000000000  0000000000000000
000000202807bf90:  0000000000000000  0000000000000000
000000202807bfa0:  0000000000000000  0000000000000000
000000202807bfb0:  0000000000000000  0000000000000000
000000202807bfc0:  0000000000000000  0000000000000000
000000202807bfd0:  0000000000000000  0000000000000000
000000202807bfe0:  0000000000000000  0000000000000000
000000202807bff0:  0000000000000000  0000000000000000
000000202807c000:  0000000000000000  0000000000000000
000000202807c010:  0000000000000000  0000000000000000
000000202807c020:  0000000000000000  0000000000000000
000000202807c030:  0000000000000000  0000000000000000
000000202807c040:  0000000000000000  0000000000000000
fatal error: unknown caller pc
runtime stack:
runtime.throw(0xfe763, 0x11)
        /home/gopher/src/go/src/runtime/panic.go:1112 +0x88
runtime.gentraceback(0xc80b4, 0x202807bf20, 0x0, 0x2028000180, 0x0, 0x0, 0x7fffffff, 0x3fffc48620, 0x0, 0x0, ...)
        /home/gopher/src/go/src/runtime/traceback.go:273 +0x1e48
        /home/gopher/src/go/src/runtime/panic.go:719 +0xac
        /home/gopher/src/go/src/runtime/asm_riscv64.s:137 +0x80

goroutine 1 [running]:
        /home/gopher/src/go/src/runtime/asm_riscv64.s:91 +0x8 fp=0x202807fe90 sp=0x202807fe88 pc=0x87590
runtime.addOneOpenDeferFrame(0x2028000180, 0x0, 0x0)
        /home/gopher/src/go/src/runtime/panic.go:718 +0x88 fp=0x202807fec8 sp=0x202807fe90 pc=0x4e8b8
panic(0xdd5c0, 0x117330)
        /home/gopher/src/go/src/runtime/panic.go:969 +0x420 fp=0x202807ff68 sp=0x202807fec8 pc=0x4f468
        /home/gopher/p.go:21 +0x50 fp=0x202807ff80 sp=0x202807ff68 pc=0xc7e80
        /home/gopher/p.go:25 +0x2c fp=0x202807ff88 sp=0x202807ff80 pc=0xc7eb4
        /home/gopher/src/go/src/runtime/proc.go:203 +0x298 fp=0x202807ffd8 sp=0x202807ff88 pc=0x52a18
        /home/gopher/src/go/src/runtime/asm_riscv64.s:451 +0x4 fp=0x202807ffd8 sp=0x202807ffd8 pc=0x89594

This appears to be a result of an incorrect funcspdelta() value being applied during gentraceback of main.blah. It is worth noting that the actual LR address appears to be 32 bytes further down (i.e. SP should be pointing at 0x202807bf00 rather than 0x202807bf20). This may some how be related to the fact that an epilogue does not exist for main.blah, since it is calling runtime.gopanic and will obviously be terminal.

Copy link

@gopherbot gopherbot commented Jan 26, 2020

Change mentions this issue: cmd/compile: disable open-coded defers on riscv64

@bradfitz bradfitz added this to the Backlog milestone Jan 26, 2020
gopherbot pushed a commit that referenced this issue Jan 28, 2020
Open-coded defers are currently broken on riscv64 - disable them for the
time being. All of the standard package tests now pass on linux/riscv64.

Updates issue #27532 and #36786

Change-Id: I20fc25ce91dfad48be32409ba5c64ca9a6acef1d
Reviewed-by: Brad Fitzpatrick <>
Reviewed-by: Dan Scales <>
Run-TryBot: Brad Fitzpatrick <>
TryBot-Result: Gobot Gobot <>
Copy link

@gopherbot gopherbot commented Jan 29, 2020

Change mentions this issue: test: disable the live test on riscv64

gopherbot pushed a commit that referenced this issue Jan 29, 2020
This test expects that open-coded defers are enabled, which is not currently
the case on riscv64.

Updates issue #27532 and #36786.

Change-Id: I94bb558c5b0734b4cfe5ae12873be81026009bcf
Reviewed-by: Brad Fitzpatrick <>
Run-TryBot: Brad Fitzpatrick <>
TryBot-Result: Gobot Gobot <>
Copy link

@gopherbot gopherbot commented Jan 29, 2020

Change mentions this issue: cmd/compile,cmd/link: fix and re-enable open-coded defers on riscv64

@gopherbot gopherbot closed this in 2e4f490 Jan 29, 2020
Copy link

@gopherbot gopherbot commented Feb 25, 2020

Change mentions this issue: test: re-enable open-coded defer test on riscv64

gopherbot pushed a commit that referenced this issue Feb 26, 2020
Open-coded defers were fixed and re-enabled on riscv64, however this test was
inadvertantly left disabled.

Updates #36786

Change-Id: I128fc84baa3d51f50d173e19e52051dc4d9a07c3
Run-TryBot: Ian Lance Taylor <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Ian Lance Taylor <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.