[英]Is the `runtime.deferreturn` ever called in go defer
At the bottom of a Go func with defer, the assembly looks like this:在带有 defer 的 Go 函数的底部,程序集如下所示:
0x000000000047e1a0 <+256>: callq *%rsi
0x000000000047e1a2 <+258>: movb $0x0,0x7(%rsp)
0x000000000047e1a7 <+263>: mov 0x748(%rsp),%rdx
0x000000000047e1af <+271>: mov (%rdx),%rbx
0x000000000047e1b2 <+274>: callq *%rbx
0x000000000047e1b4 <+276>: mov 0x750(%rsp),%rbp
0x000000000047e1bc <+284>: add $0x758,%rsp
0x000000000047e1c3 <+291>: retq
0x000000000047e1c4 <+292>: callq 0x42ea40 <runtime.deferreturn>
0x000000000047e1c9 <+297>: mov 0x750(%rsp),%rbp
0x000000000047e1d1 <+305>: add $0x758,%rsp
0x000000000047e1d8 <+312>: retq
0x000000000047e1d9 <+313>: callq 0x458900 <runtime.morestack>
As we can see, there is a retq
before call runtime.deferreturn
.正如我们所见,在调用runtime.deferreturn
之前有一个retq
。 So, it seems that the deferreturn
will never be called.因此,似乎永远不会调用deferreturn
。 Do I understand this right?我理解对吗?
As we can see, there is a retq before call runtime.deferreturn.我们可以看到,在调用 runtime.deferreturn 之前有一个 retq。 So, it seems that the deferreturn will never be called.因此,似乎永远不会调用延迟返回。 Do I understand this right?我理解对吗?
No. The code may be used by the Go runtime, for example, while panicking.不可以。例如,在恐慌时,Go 运行时可能会使用该代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.