Commit 74321da8
74321da8eb6dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Make the GC root stack and symbol-intern pool sizes overridable
The two dominant static buffers in a Spinel binary are fixed at compile time: sp_gc_roots (SP_GC_STACK_MAX = 65536 entries, a 512 KB .bss array) and the generated sp_dyn_syms runtime symbol-intern pool (8192 entries, 64 KB). Both are sized for desktop headroom, but they are the bulk of a minimal program's static footprint -- the motivating concern for the embedded / microcontroller target.
Wrap both sizes in #ifndef so an embedded build can shrink them: -DSP_GC_STACK_MAX= (build lib/sp_gc.c and the TU with the same value) -DSP_DYN_SYMS_MAX= (the generated TU consults SP_DYN_SYMS_MAX) The defaults are unchanged, so desktop builds are byte-identical.
Codegen emits sp_dyn_syms[SP_DYN_SYMS_MAX] instead of a literal 8192.
964 test (gcc + clang) / 57 bench / optcarrot 59662 unchanged; a TU built with -DSP_DYN_SYMS_MAX=64 compiles and runs.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 74321da8eb6d
- Parent
- 531010622676
lib/sp_gc.hmodifiedView file
* Only the globals touched by both the kept hot path (sp_gc_alloc, the * SP_GC_ROOT macros, GC.stat, the fiber root hook) and the moved cold * body are extern; the rest stay static on whichever side owns them. *//* Capacity of the stack-resident GC root array (sp_gc_roots). At 8 bytes/entry the default is a 512 KB static buffer -- ample for desktop, but the dominant static allocation in a minimal binary. Embedded targets can shrink it with -DSP_GC_STACK_MAX=<n> (pass the SAME value when building lib/sp_gc.c and the generated TU -- both consult this for the array and the SP_GC_ROOT bound). Too small overflows silently into a dropped root (UAF), so size it to the program's deepest live-root nesting. */#ifndef SP_GC_STACK_MAX#define SP_GC_STACK_MAX 65536#endif#define SP_GC_FULL_INTERVAL 8extern void **sp_gc_roots[SP_GC_STACK_MAX];extern int sp_gc_nroots;lib/sp_runtime.hmodifiedView file
Loading diff…
src/codegen.cmodifiedView file
Loading diff…