
The only architecture that actually needs special support for scanning the stack is WebAssembly. All others allow raw access to the stack with a small bit of assembly. Therefore, don't manually keep track of all these objects on the stack manually and instead just use conservative stack scanning. This results in a massive code size decrease in the affected targets (only tested linux/amd64 for code size) - sometimes around 33%. It also allows for future improvements such as using proper stackful goroutines.
22 строки
640 Б
ArmAsm
22 строки
640 Б
ArmAsm
.section .text.tinygo_scanCurrentStack
|
|
.global tinygo_scanCurrentStack
|
|
.type tinygo_scanCurrentStack, %function
|
|
tinygo_scanCurrentStack:
|
|
// Sources:
|
|
// * https://stackoverflow.com/questions/18024672/what-registers-are-preserved-through-a-linux-x86-64-function-call
|
|
// * https://godbolt.org/z/q7e8dn
|
|
|
|
// Save callee-saved registers.
|
|
pushl %ebx
|
|
pushl %esi
|
|
pushl %edi
|
|
pushl %ebp
|
|
|
|
// Scan the stack.
|
|
pushl %esp
|
|
calll tinygo_scanstack
|
|
|
|
// Restore the stack pointer. Registers do not need to be restored as they
|
|
// were only pushed to be discoverable by the GC.
|
|
addl $20, %esp
|
|
retl
|