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

@@ -37,7 +37,16 @@
3737 * Only the globals touched by both the kept hot path (sp_gc_alloc, the
3838 * SP_GC_ROOT macros, GC.stat, the fiber root hook) and the moved cold
3939 * body are extern; the rest stay static on whichever side owns them. */
40+/* Capacity of the stack-resident GC root array (sp_gc_roots). At 8 bytes/entry
41+ the default is a 512 KB static buffer -- ample for desktop, but the dominant
42+ static allocation in a minimal binary. Embedded targets can shrink it with
43+ -DSP_GC_STACK_MAX=<n> (pass the SAME value when building lib/sp_gc.c and the
44+ generated TU -- both consult this for the array and the SP_GC_ROOT bound).
45+ Too small overflows silently into a dropped root (UAF), so size it to the
46+ program's deepest live-root nesting. */
47+#ifndef SP_GC_STACK_MAX
4048 #define SP_GC_STACK_MAX 65536
49+#endif
4150 #define SP_GC_FULL_INTERVAL 8
4251 extern void **sp_gc_roots[SP_GC_STACK_MAX];
4352 extern int sp_gc_nroots;