skills/qemu/resource-optimization-lowend/SKILL.md
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 skillsauth add mohitmishra786/low-level-dev-skills resource-optimization-lowendInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide agents through flash and RAM optimization on constrained devices: compiler size flags, linker map analysis, stack usage measurement, dead code elimination, and size-vs-speed tradeoffs — for bare-metal and small RTOS images.
-Os vs -O2 on MCU.rodata or .bss growtharm-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
Identify largest symbols and unexpected library pull-in.
| Flag | Effect |
|------|--------|
| -Os | Size-first optimization |
| -ffunction-sections -fdata-sections | Per-symbol sections |
| -Wl,--gc-sections | Drop unused sections |
| -flto | Cross-TU dead code elimination |
| -specs=nano.specs | 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.map
Runtime: fill stack with pattern (0xDEADBEEF), run tests, scan high-water mark. FreeRTOS: uxTaskGetStackHighWaterMark.
| Section | Tactic |
|---------|--------|
| .bss | Shrink buffers; pool allocators |
| .data | Move const to flash (const → .rodata) |
| 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 | _write retarget; tiny printf |
| --gc-sections broke IRQ | Section collected | KEEP() in linker script |
| Stack overflow late | Deep call + IRQ nest | Measure HW stack; increase _estack |
| RAM zero but big ELF | .data not loaded | Check VMA/LMA |
| LTO link fail | Mixed compiler versions | Same GCC for all objects |
skills/embedded/linker-scripts — MEMORY/Sections layoutskills/baremetal/baremetal-startup — stack symbolskills/baremetal/low-power-embedded — RAM retentionskills/compilers/gcc — optimization flagsskills/rust/rust-no-std — embedded Rust size patternsdevelopment
QEMU/KVM skill for virtualization and kernel development. Use when running qemu-system-x86_64 with KVM, configuring virtio devices, VFIO passthrough, QMP monitor, libvirt, or booting custom kernels. Activates on queries about QEMU, KVM, virtio, VFIO, virsh, virt-install, or -kernel -append.
development
Hardware virtualization internals skill for Intel VT-x and AMD-V. Use when studying VMCS/VMCB, EPT/NPT page tables, VMEXIT handling, APIC virtualization, or building minimal hypervisors. Activates on queries about VMX, SVM, VMCS, EPT, NPT, VMEXIT, or type-1 hypervisor.
testing
Linux containers internals skill for namespaces, cgroups, and OCI. Use when understanding clone/unshare namespaces, cgroups v2 limits, overlayfs, runc, seccomp profiles, capabilities, or escape mitigations. Activates on queries about namespaces, cgroups, overlayfs, runc, seccomp-bpf, OCI spec, or container escape.
tools
Reverse engineering skill for binary analysis. Use when decompiling with Ghidra, analyzing with radare2, scripting RE tools, triaging with strings/file/xxd, or diffing binaries. Activates on queries about Ghidra, radare2, r2, decompiler, Binary Ninja, Diaphora, or stripped binary analysis.