Skip to content
Skills Library
Programming · Analysis

resource-optimization-lowend

/resource-optimization-lowend

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.

Licence
MIT
Last repository change
27.06.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.06.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

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.

Original author description

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.

How it works

  1. Purpose
  2. When to Use
  3. Workflow
  4. Common Problems
  5. Related Skills
Original SKILL.md headings · 113 lines, 439 words
SKILL.md preview
---
name: resource-optimization-lowend
description: 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.
---

# Resource Optimization (Low-End Systems)

## Purpose

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.

## When to Use

- Firmware exceeds flash budget
- Stack overflow in production only
- Choosing `-Os` vs `-O2` on MCU
- Finding unexpected `.rodata` or `.bss` growth

## Workflow

### 1. Size measurement toolchain

```bash
arm-none-eabi-size -A firmware.elf
arm-none-eabi-objdump -h firmware.elf
nm --size-sort -S firmware.elf | tail -20
```

### 2. Linker map file

```ld
/* linker.ld */
OUTPUT_FORMAT("elf32-littlearm")
ENTRY(Reset_Handler)

SECTIONS
{
  /* ... */
}

/* Generate map */
/* gcc ... -Wl,-Map=firmware.map */
```

```bash
grep -E '\.text|\.rodata|\.data|\.bss' firmware.map | head
```

Identify largest symbols and unexpected library pull-in.

### 3. Compiler flags

| 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) |

```makefile
CFLAGS += -Os -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections -Wl,--print-memory-usage
```

### 4. Stack analysis

```bash
# 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`.

### 5. RAM categories

| 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 |

### 6. Size vs speed decision

```
Hot path in ISR or 1 kHz loop?
├── Yes → -O2 for that file (#pragma GCC optimize)
└── No  → -Os globally
```

### 7. Agent usage

```
/resource-optimization-lowend Find top 10 flash consumers in firmware.map and suggest -gc-sections fixes
```

## Common Problems

| 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 |

## Related Skills

- `skills/embedded/linker-scripts` — MEMORY/Sections layout
- `skills/baremetal/baremetal-startup` — stack symbol
- `skills/baremetal/low-power-embedded` — RAM retention
- `skills/compilers/gcc` — optimization flags
- `skills/rust/rust-no-std` — embedded Rust size patterns

Versions

RepositoryScoreLicence
This page · mohitmishra786/low-level-dev-skills100MIT
OutlineDriven/outline-driven-development100Apache-2.0

Database snapshot: 13.11.2026 · package version 5577f75e4f21 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90esp32-linker-map-review
    Use when designing, reviewing, debugging or validating linker map review for ESP32 firmware; apply target-specific constraints, failure analysis and measurable verification before release.
  • 100linker-scripts
    Linker script skill for embedded bare-metal targets. Use when writing or modifying GNU ld linker scripts, placing code and data in specific flash or RAM regions, understanding VMA vs LMA, configuring startup .bss/.data initialization, using MEMORY and SECTIONS commands, or…
  • 100linker-scripts
    Use when writing a GNU ld script for a bare-metal target, placing code in a flash or RAM region, wiring .data and .bss startup, or fixing a region overflowed error. Not for LTO: use linkers-lto.
  • 90esp32-linker-script-change-review
    Use when designing, reviewing, debugging or validating linker script change review for ESP32 firmware; apply target-specific constraints, failure analysis and measurable verification before release.
  • 90embedded-memory-constraints
    Fit firmware into kilobytes with static allocation, measured stack sizing, and linker-map budgeting. Use when developing on microcontrollers or debugging overflows and fragmentation on-device.
  • 95fw-analyzer
    Binary-level firmware analyzer, single engine AxFInspector, read-only. Input is one .axf/ELF (with DWARF debug info); it answers "what did the compiler actually produce, where did the crash land, what occupies memory, how big is a function's stack frame and how deep can a call…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.