icexin / eggos

A Go unikernel running on x86 bare metal
http://eggos.icexin.com
MIT License
2.23k stars 113 forks source link

add support for go1.17 #100

Open icexin opened 2 years ago

icexin commented 2 years ago

Go 1.17 implements a new way of passing function arguments and results using registers instead of the stack.

This issue is used to track affected modules and corresponding PRs.

mewmew commented 2 years ago

I tried generating a "hello world" eggos kernel using Go 1.17, to debug the boot process.

Unexpectedly, it crashes quite early due to ABI changes introduced in Go 1.17.

In particular, the crash occurs in an autogenerated wrapper for kernel.preinit (NOTE: the autogenerated wrapper function is not present in Go 1.16):

Dump of assembler code for function github.com/icexin/eggos/kernel.preinit<autogenerated>:
   0x00000000002bbe40 <+0>: sub    $0x18,%rsp
   0x00000000002bbe44 <+4>: mov    %rbp,0x10(%rsp)
   0x00000000002bbe49 <+9>: lea    0x10(%rsp),%rbp
   0x00000000002bbe4e <+14>:    mov    0x20(%rsp),%rax
   0x00000000002bbe53 <+19>:    mov    0x28(%rsp),%rbx
=> 0x00000000002bbe58 <+24>:    xorps  %xmm15,%xmm15
   0x00000000002bbe5c <+28>:    mov    %fs:0xfffffffffffffff8,%r14
   0x00000000002bbe65 <+37>:    call   0x2b6c40 <github.com/icexin/eggos/kernel.preinit>
   0x00000000002bbe6a <+42>:    mov    0x10(%rsp),%rbp
   0x00000000002bbe6f <+47>:    add    $0x18,%rsp
   0x00000000002bbe73 <+51>:    ret    
End of assembler dump.
(gdb) si
[Inferior 1 (process 1) exited normally]
(gdb) 

The reason for the crash is most likely that the FPU has not yet been initialized; thus causing the instruction xorps %xmm15,%xmm15 to crash.

mewmew commented 2 years ago

Notes on the new register-based calling convention introduced Go 1.17 ("ABIInternal"), and how gVisor handles it:

https://github.com/google/gvisor/commit/108410638aa8480e82933870ba8279133f543d2b