Skip to content

fix(linker): correct cross-toolchain memory map inconsistencies#24

Open
94xhn wants to merge 1 commit into
STMicroelectronics:masterfrom
94xhn:fix/linker-cross-toolchain-audit
Open

fix(linker): correct cross-toolchain memory map inconsistencies#24
94xhn wants to merge 1 commit into
STMicroelectronics:masterfrom
94xhn:fix/linker-cross-toolchain-audit

Conversation

@94xhn

@94xhn 94xhn commented Jul 11, 2026

Copy link
Copy Markdown

Not tied to a specific existing issue - found by systematically cross-checking each example's GCC (SW4STM32)/IAR (EWARM)/Keil (MDK-ARM) linker scripts against each other and against known-good Templates sibling projects for the same chip, following the same methodology already used for STM32CubeG4, STM32CubeWB, STM32CubeWL, STM32CubeU5, STM32CubeF7, STM32CubeF4, STM32CubeL4, STM32CubeH7, STM32CubeF1, and STM32CubeL0 in this repo family.

1. Applications/USB_Device/DFU_Standalone/Binary/binary_template (STM32072B_EVAL, STM32F072VBTx, 128K flash) - GCC and Keil both offset the start but forget to shrink the length

Both GCC's .ld and Keil's .uvprojx correctly offset the app's flash start address to 0x08007000 to leave room for the bootloader, but neither shrinks the length to compensate - both still declare 128K as if starting from 0x08000000, running 28K past the chip's actual end of flash. IAR's .icf correctly uses 100K (0x08007000-0x0801FFFF).

This is a "2-of-3-toolchains-wrong" case - a naive majority vote here would have picked the wrong answer, similar to what was already found in STM32CubeWB/F7/F4/H7/F1/L0. Fixed GCC's .ld and Keil's OCR_RVCT4 Size to 100K (0x19000), matching IAR.

2. Applications/USB_Device/DFU_Standalone/Binary/binary_template (STM32F072B-Discovery, STM32F072RBTx, 128K flash) - identical bug, same board family

Same exact pattern as finding #1: GCC's .ld and Keil's OCR_RVCT4 both declare 128K flash length starting from the bootloader-offset address 0x08007000 instead of the correct 100K. Fixed identically.

3. Examples/IWDG/IWDG_WindowMode (STM32F070RB-Nucleo, STM32F070RB, 128K flash / 16K RAM) - IAR alone at half capacity

IAR's .icf declares only 64K flash (0x08000000-0x0800FFFF) and 8K RAM (0x20000000-0x20001FFF) - exactly half of the chip's actual capacity. GCC's .ld, Keil's OCR_RVCT4, and this board's own Templates project all agree on the correct 128K flash / 16K RAM. Fixed IAR's .icf region-end symbols to 0x0801FFFF (128K) and 0x20003FFF (16K).

Test plan

No local ARM toolchain (arm-none-eabi-gcc/IAR/Keil) available to compile/link-test these, so verification relied on address-arithmetic cross-referencing against multiple independent references per finding: Templates gold standards, sibling toolchain files of the same project, and the Keil <Device> tag naming the actual target chip.

Disclosure

Generative AI (Claude) was used to help investigate this (systematic cross-toolchain linker script comparison) and implement/verify the fixes. All changes were reviewed by me before submission.

Found by cross-checking each example's GCC (SW4STM32)/IAR (EWARM)/Keil
(MDK-ARM) linker scripts against each other and against known-good
Templates sibling projects, following the same audit already done for
STM32CubeG4/WB/WL/U5/F7/F4/L4/H7/F1/L0 in this repo family.

1. Applications/USB_Device/DFU_Standalone/Binary/binary_template
   (STM32072B_EVAL, STM32F072VBTx, 128K flash): GCC's .ld and Keil's
   .uvprojx both correctly offset the app's flash start address to
   0x08007000 to leave room for the bootloader, but neither shrinks
   the length to compensate - both still declare 128K as if starting
   from 0x08000000, running 28K past the chip's actual end of flash.
   IAR's .icf correctly uses 100K (0x08007000-0x0801FFFF). Fixed
   GCC's .ld and Keil's OCR_RVCT4 Size to 100K (0x19000), matching
   IAR.

2. Applications/USB_Device/DFU_Standalone/Binary/binary_template
   (STM32F072B-Discovery, STM32F072RBTx, 128K flash): identical bug
   as STMicroelectronics#1 above, same board family, same fix (128K -> 100K on GCC's
   .ld and Keil's OCR_RVCT4 Size).

3. Examples/IWDG/IWDG_WindowMode (STM32F070RB-Nucleo, STM32F070RB,
   128K flash / 16K RAM): IAR's .icf alone declares only 64K flash
   and 8K RAM - half of the chip's actual capacity, and half of what
   GCC's .ld, Keil's OCR_RVCT4, and this board's own Templates
   project all agree on. Fixed IAR's .icf region end symbols to
   0x0801FFFF (128K flash) and 0x20003FFF (16K RAM).

No local ARM toolchain (arm-none-eabi-gcc/IAR/Keil) available to
compile/link-test these changes; verification relied on
address-arithmetic cross-referencing against multiple independent
references per finding (Templates gold standards, sibling toolchain
files of the same project, and the Keil <Device> tag naming the
actual target chip).

Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com>
@ALABSTM ALABSTM added bug Something isn't working projects Projects-related (demos, applications, examples) issue or pull-request. labels Jul 13, 2026
@MKISTM MKISTM moved this from To do to Analyzed in stm32cube-mcu-fw-dashboard Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working projects Projects-related (demos, applications, examples) issue or pull-request.

Projects

Development

Successfully merging this pull request may close these issues.

3 participants