2026-06-11
Stack Overflow: View Question
Tags: memory-management, embedded, memory-address, nxp-microcontroller, harfbuzz
Score: 0 | Views: 88
The asker is porting HarfBuzz 8.3.0 + FreeType 2.13.2 + LVGL to an NXP i.MX RT1064 Cortex-M7 in a bare-metal configuration (no MMU-backed OS). Latin and simple scripts shape fine, but as soon as they feed an Indic script through HarfBuzz, the MCU hits a hard fault. Their suspicion is recursive GSUB lookups blowing the stack or dereferencing into invalid memory.
This is a deeply interesting embedded problem because it sits at the intersection of three painful constraints:
hb_buffer_t can grow well past what a typical embedded heap (often 32–128 KB) is sized for.Direction toward a solution:
SCB->CFSR, HFSR, MMFAR, BFAR in the HardFault handler. STKOF (stack overflow) bit in CFSR is the smoking gun on M7.hb_malloc_impl / replace via HB_CUSTOM_MALLOC and route to a dedicated, instrumented pool. Track high-water mark.HB_TINY / disable unused shapers, but keep HB_NO_BORING_EXPANSION off — Indic specifically needs the universal shaping engine.Coverage table dereference.Gotchas: FreeType's FT_Stream with custom I/O is a common silent failure — returning fewer bytes than requested makes HarfBuzz read garbage offsets. Also, HarfBuzz uses setjmp-free recursion; there's no graceful "out of stack" path, so detection must happen externally via MPU.
