eggos icon indicating copy to clipboard operation
eggos copied to clipboard

add support for go1.17

Open icexin opened this issue 2 years ago • 2 comments

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

  • https://go.googlesource.com/proposal/+/master/design/40724-register-calling.md
  • https://go.googlesource.com/go/+/refs/heads/dev.regabi/src/cmd/compile/internal-abi.md

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

icexin avatar Feb 06 '22 12:02 icexin

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 avatar Feb 10 '22 03:02 mewmew

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

mewmew avatar Feb 10 '22 14:02 mewmew