mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 19:17:47 +00:00
907d90105a
Instead of always starting a new goroutine for the main goroutine, run
the main goroutine on the system stack.
The system stack is not occupied with scheduling, instead each goroutine
that wants to pause itself calls into the scheduler which will switch to
the next task (goroutine) to run, or sleeps.
There are various advantages of this over the previous system:
* When the program doesn't start a goroutine, the code size and RAM
consumption is close to what you'd get with `-scheduler=none`.
* When the program does start a goroutine, there is still a reduction
in RAM consumption because only one extra stack is needed.
* Because tasks directly switch to the next task to run, only a single
task switch is needed instead of two (goroutine -> scheduler ->
goroutine). This should improve task switching performance.
I kept the current behavior for WebAssembly/Asyncify. I looked into how
the same benefits can be realized for WebAssembly but couldn't easily
find how to do that. Maybe this can be done separately, or maybe we'll
just wait for the stack switching proposal to finish.
The code for Cortex-M is currently more complicated than I'd like, and
therefore can sometimes result in a slight increase in code size. I'd
like to fix this eventually but am still looking into good ways to do
this. I still think this change is generally beneficial because many
programs see big reductions in code size when compiling for Cortex-M.
73 lines
1.7 KiB
Plaintext
73 lines
1.7 KiB
Plaintext
|
|
/* Unused, but here to silence a linker warning. */
|
|
ENTRY(Reset_Handler)
|
|
|
|
/* define output sections */
|
|
SECTIONS
|
|
{
|
|
/* Program code and read-only data goes to FLASH_TEXT. */
|
|
.text :
|
|
{
|
|
KEEP(*(.isr_vector))
|
|
*(.text)
|
|
*(.text.*)
|
|
*(.rodata)
|
|
*(.rodata.*)
|
|
. = ALIGN(4);
|
|
} >FLASH_TEXT
|
|
|
|
.tinygo_stacksizes :
|
|
{
|
|
*(.tinygo_stacksizes)
|
|
} > FLASH_TEXT
|
|
|
|
/* Put the stack at the bottom of RAM, so that the application will
|
|
* crash on stack overflow instead of silently corrupting memory.
|
|
* See: http://blog.japaric.io/stack-overflow-protection/ */
|
|
.stack (NOLOAD) :
|
|
{
|
|
. = ALIGN(4);
|
|
_stack_bottom = .;
|
|
. += _stack_size;
|
|
_stack_top = .;
|
|
} >RAM
|
|
|
|
/* Start address (in flash) of .data, used by startup code. */
|
|
_sidata = LOADADDR(.data);
|
|
|
|
/* Globals with initial value */
|
|
.data :
|
|
{
|
|
. = ALIGN(4);
|
|
_sdata = .; /* used by startup code */
|
|
*(.data)
|
|
*(.data.*)
|
|
. = ALIGN(4);
|
|
_edata = .; /* used by startup code */
|
|
} >RAM AT>FLASH_TEXT
|
|
|
|
/* Zero-initialized globals */
|
|
.bss :
|
|
{
|
|
. = ALIGN(4);
|
|
_sbss = .; /* used by startup code */
|
|
*(.bss)
|
|
*(.bss.*)
|
|
*(COMMON)
|
|
. = ALIGN(4);
|
|
_ebss = .; /* used by startup code */
|
|
} >RAM
|
|
|
|
/DISCARD/ :
|
|
{
|
|
*(.ARM.exidx) /* causes 'no memory region specified' error in lld */
|
|
*(.ARM.exidx.*) /* causes spurious 'undefined reference' errors */
|
|
}
|
|
}
|
|
|
|
/* For the memory allocator. */
|
|
_heap_start = _ebss;
|
|
_heap_end = ORIGIN(RAM) + LENGTH(RAM);
|
|
_globals_start = _sdata;
|
|
_globals_end = _ebss;
|