golang / go

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

runtime: crash in copyabletopsegment for defer of nil func #8047

Closed dvyukov closed 9 years ago

dvyukov commented 10 years ago
go version devel +fb7122476042 Tue May 20 11:42:25 2014 -0400 linux/amd64

The attached reproducer crashes as:

fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x0 pc=0x4175e7]

runtime stack:
runtime.throw(0x45b3a5)
    src/pkg/runtime/panic.c:520 +0x69 fp=0x7fff63f1f420
runtime.sigpanic()
    src/pkg/runtime/os_linux.c:222 +0x3d fp=0x7fff63f1f438
copyabletopsegment(0xc208002120)
    src/pkg/runtime/stack.c:347 +0x107 fp=0x7fff63f1f4c8
runtime.newstack()
    src/pkg/runtime/stack.c:746 +0x3f2 fp=0x7fff63f1f610
runtime: unexpected return pc for runtime.newstackcall called from 0x45ebe8
runtime.newstackcall(0x41fb77, 0x1)
    src/pkg/runtime/asm_amd64.s:275 +0x68 fp=0x7fff63f1f618

goroutine 16 [stack growth]:
runtime.newstackcall(0x440098, 0xc208026028)
    src/pkg/runtime/asm_amd64.s:239 fp=0x7fb65354cd30
runtime.panic(0x42a460, 0x45b453)
    src/pkg/runtime/panic.c:248 +0x18d fp=0x7fb65354cdc8
runtime.panicstring(0x45b453)
    src/pkg/runtime/panic.c:552 +0x12d fp=0x7fb65354cdf0
runtime.sigpanic()
    src/pkg/runtime/os_linux.c:237 +0x10e fp=0x7fb65354ce08
main.id7(0x3ff199999999999a, 0x0, 0x0)
    0.go:33 +0xbb fp=0x7fb65354ce90
main.id3(0x0, 0x0, 0x415500, 0xc20801096c)
    0.go:20 +0x31 fp=0x7fb65354ced0
main.init()
    0.go:18 +0x62 fp=0x7fb65354cf50
runtime.main()
    src/pkg/runtime/proc.c:240 +0xda fp=0x7fb65354cfa8

Attachments:

  1. 0.go (4563 bytes)
rsc commented 10 years ago

Comment 1:

Labels changed: added release-go1.3maybe.

Status changed to Accepted.

randall77 commented 10 years ago

Comment 2:

Easier repro:
package main
func stackit(n int) {
    if n == 0 {
        return
    }
    stackit(n - 1)
}
func main() {
    defer ((func())(nil))()
    stackit(1000)
}
It's deferring a call to a nil object.  The stack copier barfs when it comes upon such a
defer record.  The defer hasn't executed yet.
It's easy enough to make the stack copier ignore such defers.  But shouldn't we panic on
such a defer as soon as it is requested?
This is related to issue #8045.  "defer nil()" should do the same thing as "go nil()".

Owner changed to @randall77.

randall77 commented 10 years ago

Comment 3:

I'm leading towards rejecting these defers at creation time.  During a panic they can
only lead to a panic on top of that panic.  That gets really ugly, really fast.
randall77 commented 10 years ago

Comment 4:

Issue #8046 has been merged into this issue.

rsc commented 10 years ago

Comment 6:

Labels changed: added release-go1.3, removed release-go1.3maybe.

gopherbot commented 10 years ago

Comment 7:

CL https://golang.org/cl/101800043 mentions this issue.
randall77 commented 10 years ago

Comment 8:

This issue was closed by revision 3d1c3e1e262d8f6d7ad2be52af7d226a6fb88cc.

Status changed to Fixed.

dvyukov commented 10 years ago

Comment 9:

The test from the merged issue #8046 still fatal errors.
cl/101800043 does not contain test for 8047, so it's unclear whether 8047 is fixed as
well.

Status changed to Accepted.

gopherbot commented 10 years ago

Comment 10:

CL https://golang.org/cl/108840043 mentions this issue.
randall77 commented 10 years ago

Comment 11:

This issue was closed by revision aa04caa7594506d805f82b7d7abed35a3a8fbec.

Status changed to Fixed.

rsc commented 10 years ago

Comment 12:

This issue was closed by revision bfc80b43b7ff.

dvyukov commented 10 years ago

Comment 13:

Sorry, it still crashes:
go version devel +1282e1d59a81 Wed Jun 11 22:52:01 2014 -0700 darwin/amd64
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x0 pc=0x1a6d7]
runtime stack:
runtime: unexpected return pc for runtime.newstackcall called from 0x5e708
runtime.throw(0x5bad6)
        src/pkg/runtime/panic.c:520 +0x69
runtime.sigpanic()
        src/pkg/runtime/os_darwin.c:439 +0x3d
runtime.gostartcallfn(0x7fff5fbff940, 0x0)
        src/pkg/runtime/stack.c:859 +0x27
runtime.newstack()
        src/pkg/runtime/stack.c:843 +0x6e4
runtime: unexpected return pc for runtime.newstackcall called from 0x5e708
runtime.newstackcall(0x235f7, 0x7fff00000001)
        src/pkg/runtime/asm_amd64.s:275 +0x68

Status changed to Accepted.

gopherbot commented 10 years ago

Comment 14:

CL https://golang.org/cl/105140044 mentions this issue.
rsc commented 10 years ago

Comment 15:

Owner changed to @rsc.

rsc commented 10 years ago

Comment 16:

This issue was closed by revision 36207a91d3c97a9c64984572af8972749531046.

Status changed to Fixed.

gopherbot commented 10 years ago

Comment 17:

CL https://golang.org/cl/103370044 mentions this issue.
rsc commented 10 years ago

Comment 18:

This issue was closed by revision 3825729c6921.

gopherbot commented 10 years ago

Comment 19:

CL https://golang.org/cl/105120044 mentions this issue.
rsc commented 10 years ago

Comment 20:

This issue was closed by revision 060a988011b34ded3e002e1a4cb138b7ed21b17.

gopherbot commented 10 years ago

Comment 21:

CL https://golang.org/cl/108890045 mentions this issue.
rsc commented 10 years ago

Comment 22:

This issue was closed by revision 67de4afa60e7.