linker-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…
от mohitmishra786★ 307 звёзд на GitHubОб этом скилле
Linker Scripts
Purpose
Guide agents through writing and modifying GNU ld linker scripts for embedded targets: MEMORY and SECTIONS commands, VMA vs LMA for code relocation, startup .bss/.data initialization, placing sections in specific regions, and using PROVIDE/KEEP/ALIGN directives.
Triggers
- "How do I write a linker script for my MCU?"
- "How do I place a function in a specific flash/RAM region?"
- "What's the difference between VMA and LMA in a linker script?"
- "How does .bss and .data initialization work at startup?"
- "Linker error: region 'FLASH' overflowed"
- "How do I use weak symbols in a linker script?"
Workflow
1. Linker script anatomy
/* Minimal Cortex-M linker script (works with newlib and C++) */
ENTRY(Reset_Handler) /* entry point symbol */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
}
SECTIONS
{
.text : /* code section */
{
KEEP(*(.isr_vector)) /* interrupt vector must be first */
*(.text)
*(.text.*)
*(.rodata)
*(.rodata.*)
KEEP(*(.init)) /* newlib/crt0 prologue/epilogue */
KEEP(*(.fini))
*(.ARM.extab* .gnu.linkonce.armextab.*) /* unwind data */
. = ALIGN(4);
} > FLASH
.ARM.exidx : /* unwind tables (C++ exceptions, backtraces) */
{
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} > FLASH
.init_array : /* static constructors, run by __libc_init_array() */
{
PROVIDE_HIDDEN(__preinit_array_start = .);
KEEP(*(.preinit_array*))
PROVIDE_HIDDEN(__preinit_array_end = .);
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array*))
PROVIDE_HIDDEN(__init_array_end = .);
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array*))
PROVIDE_HIDDEN(__fini_array_end = .);
. = ALIGN(4);
_etext = .; /* end of flash code/constants */
} > FLASH
.data : /* VMA = RAM, LMA = FLASH */
{
_sdata = .;
*(.data)
*(.data.*)
. = ALIGN(4);
_edata = .;
} > RAM AT > FLASH
_sidata = LOADADDR(.data); /* LMA of .data, used by startup copy loop */
.bss (NOLOAD) :
{
_sbss = .;
__bss_start__ = _sbss; /* name newlib crt0 expects */
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
__bss_end__ = _ebss;
} > RAM
PROVIDE(end = _ebss); /* heap start for newlib _sbrk */
/* Stack at top of RAM */
_estack = ORIGIN(RAM) + LENGTH(RAM);
}
The .init/.fini, .ARM.exidx/.ARM.extab and .init_array rules are needed as soon as newlib,
libstdc++ or C++ exceptions are linked in. Without them those sections become orphans after .text
and overlap the load address of .data. __bss_start__, __bss_end__ and end are the names newlib's
crt0 and _sbrk expect.
2. VMA vs LMA
- VMA (Virtual Memory Address): where the section runs at runtime
- LMA (Load Memory Address): where the section is stored in the image (flash)
For .data: stored in flash (LMA), copied to RAM at startup (VMA).
/* VMA in RAM, LMA in the next free spot of FLASH */
.data :
{
_sdata = .;
*(.data)
_edata = .;
} > RAM AT > FLASH
_sidata = LOADADDR(.data); /* where startup code copies from */
Prefer > RAM AT > FLASH over AT(_etext) or AT(ADDR(.text) + SIZEOF(.text)). The region form puts the
LMA after every section already placed in FLASH (.ARM.exidx, .init_array, ...). A fixed address
ignores them, and they end up overlapping .data.
3. Startup .bss / .data initialization
The C runtime must copy .data from flash to RAM and zero .bss before main():
// startup.c or startup.s equivalent in C
extern uint32_t _sdata, _edata, _sidata; // _sidata = LMA of .data
extern uint32_t _sbss, _ebss;
void Reset_Handler(void) {
// Copy .data from flash to RAM
uint32_t *src = &_sidata;
uint32_t *dst = &_sdata;
while (dst < &_edata) *dst++ = *src++;
// Zero-initialize .bss
dst = &_sbss;
while (dst < &_ebss) *dst++ = 0;
// Call C++ constructors
// (call __libc_init_array() if using newlib)
main();
for (;;); // should never return
}
The linker script provides _sidata with _sidata = LOADADDR(.data);, as in section 1.
4. Placing code in specific regions
/* Place time-critical code in RAM for faster execution */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
RAM (rwx): ORIGIN = 0x20000000, LENGTH = 128K
CCM (rw) : ORIGIN = 0x10000000, LENGTH = 64K /* STM32F4 CCM: data only */
}
.fast_code :
{
. = ALIGN(4);
_sfast = .;
*(.f
Установить linker-scripts в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл linker-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 debugging linker errors about regions. Activates on queries about linker scripts, MEMORY command, SECTIONS command, .bss init, VMA vs LMA, weak symbols, or placing functions in specific memory regions.
Как установить скилл linker-scripts?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл linker-scripts запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic