Loading...
Loading...
Resource optimization skill for constrained embedded targets. Use when reducing flash/RAM usage, analyzing stack depth, reading linker map files, or tuning size vs speed on MCUs. Activates on queries about firmware size optimization, linker map, stack usage, -Os, flash RAM budget, or bloat analysis.
npx skill4agent add mohitmishra786/low-level-dev-skills resource-optimization-lowend-Os-O2.rodata.bssarm-none-eabi-size -A firmware.elf
arm-none-eabi-objdump -h firmware.elf
nm --size-sort -S firmware.elf | tail -20/* linker.ld */
OUTPUT_FORMAT("elf32-littlearm")
ENTRY(Reset_Handler)
SECTIONS
{
/* ... */
}
/* Generate map */
/* gcc ... -Wl,-Map=firmware.map */grep -E '\.text|\.rodata|\.data|\.bss' firmware.map | head| Flag | Effect |
|---|---|
| Size-first optimization |
| Per-symbol sections |
| Drop unused sections |
| Cross-TU dead code elimination |
| Smaller newlib (GCC ARM) |
CFLAGS += -Os -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections -Wl,--print-memory-usage# Static (if built with -fstack-usage)
find . -name '*.su' -exec cat {} \;
# Linker stack symbol
grep _estack firmware.map0xDEADBEEFuxTaskGetStackHighWaterMark| Section | Tactic |
|---|---|
| Shrink buffers; pool allocators |
| Move const to flash ( |
| Heap | Avoid malloc; fixed pools |
| Stack | Reduce nesting; smaller ISR stacks |
Hot path in ISR or 1 kHz loop?
├── Yes → -O2 for that file (#pragma GCC optimize)
└── No → -Os globally/resource-optimization-lowend Find top 10 flash consumers in firmware.map and suggest -gc-sections fixes| Symptom | Cause | Fix |
|---|---|---|
| printf pulls 20+ KB | Full newlib printf | |
| Section collected | |
| Stack overflow late | Deep call + IRQ nest | Measure HW stack; increase |
| RAM zero but big ELF | | Check VMA/LMA |
| LTO link fail | Mixed compiler versions | Same GCC for all objects |
skills/embedded/linker-scriptsskills/baremetal/baremetal-startupskills/baremetal/low-power-embeddedskills/compilers/gccskills/rust/rust-no-std