I am studying the assembly output of unoptimized go build. There is a function that returns nil no matter what. During runtime go panics as expected due to nil. How does go call the runtime.panic* functions as defined in assembly source? I dont see any calls to them, just some couple of tests.
Source code:
package main
type Some struct {
a int
}
func getSome() *Some {
some := 23
if some == 40 {
return &Some{}
} else {
return nil
}
}
func main() {
some := getSome()
some.a = 13
}
Assembly fragment:
0000000000457660 <main.getSome>:
457660: 55 push %rbp
457661: 48 89 e5 mov %rsp,%rbp
457664: 48 83 ec 10 sub $0x10,%rsp
457668: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp)
45766f: 00 00
457671: 48 c7 04 24 17 00 00 movq $0x17,(%rsp)
457678: 00
457679: eb 00 jmp 45767b <main.getSome+0x1b>
45767b: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp)
457682: 00 00
457684: 31 c0 xor %eax,%eax
457686: 48 83 c4 10 add $0x10,%rsp
45768a: 5d pop %rbp
45768b: c3 ret
45768c: cc int3
45768d: cc int3
45768e: cc int3
45768f: cc int3
457690: cc int3
457691: cc int3
457692: cc int3
457693: cc int3
457694: cc int3
457695: cc int3
457696: cc int3
457697: cc int3
457698: cc int3
457699: cc int3
45769a: cc int3
45769b: cc int3
45769c: cc int3
45769d: cc int3
45769e: cc int3
45769f: cc int3
00000000004576a0 <main.main>:
4576a0: 49 3b 66 10 cmp 0x10(%r14),%rsp
4576a4: 76 20 jbe 4576c6 <main.main+0x26>
4576a6: 55 push %rbp
4576a7: 48 89 e5 mov %rsp,%rbp
4576aa: 48 83 ec 08 sub $0x8,%rsp
4576ae: e8 ad ff ff ff call 457660 <main.getSome>
4576b3: 48 89 04 24 mov %rax,(%rsp)
4576b7: 84 00 test %al,(%rax)
4576b9: 48 c7 00 0d 00 00 00 movq $0xd,(%rax)
4576c0: 48 83 c4 08 add $0x8,%rsp
4576c4: 5d pop %rbp
4576c5: c3 ret
4576c6: e8 f5 ce ff ff call 4545c0 <runtime.morestack_noctxt.abi0>
4576cb: eb d3 jmp 4576a0 <main.main>