Skip to content

fix(sam): root the SAM3X reset handler so the sketch reaches firmware.elf - #1941

Merged
zackees merged 1 commit into
mainfrom
agent/sam3x-reset-entry
Nov 7, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/sam3x-reset-entry

Conversation

@zackees

@zackees zackees commented Nov 7, 2026

Copy link
Copy Markdown
Member

Fixes #1939.

Symptom

bash compile sam3x8e_due --examples Apa102 (FastLED) reported success, but
firmware.elf was ~22 KB / firmware.bin 5.08 KB with no setup, loop or
main in its symbol table, while src/main*.cpp.o did define them.

Root cause

Atmel's classic-SAM variants/<v>/linker_scripts/gcc/flash.ld declares no
ENTRY()
, and the SAM3X link line supplied no entry either. So:

  1. GNU ld fell back to newlib's crt0.o _start as the entry (0x80000),
  2. nothing referenced Reset_Handler, so startup_sam3xa.o was never extracted
    from libsam_sam3x8e_gcc_rel.a (that is why .vectors is empty),
  3. --gc-sections then discarded main, setup, loop and the whole sketch.

The gcc driver exits 0 in this situation, so "build succeeded" said nothing
about whether the application had been linked. Adafruit's SAMD/SAME5x scripts
do declare ENTRY(Reset_Handler), which is why only classic SAM was affected.

Fix

  • crates/fbuild-build-arm/src/sam/configs/sam3x.json: pass
    -Wl,--entry=Reset_Handler and -Wl,--undefined=Reset_Handler — the same
    entry Arduino's own SAM platform.txt uses; the --undefined half makes a
    missing startup a link error rather than a silent empty image.
  • SamMcuConfig gains required_link_symbols (serde-defaulted, so every other
    config is unchanged). SamLinker verifies those symbols exist in the linked
    ELF and fails the build naming what is missing, so a zero-exit inert image
    can never again be reported as success. SAMD/SAME5x declare none and pay no
    extra work.

Tests

  • sam3x_acceptance::sam3x_due_sketch_reaches_the_linked_image (ignored, real
    ARM GCC + Arduino SAM core, mirrors samd_acceptance): builds the Due
    fixture and requires Reset_Handler, main, setup, loop to be defined
    with non-zero size.
    • RED before the fix: due: firmware.elf must define 'Reset_Handler'; a build success is not a link.
    • GREEN after: pass.
    • RED for the new guard (entry flags removed, required_link_symbols
      kept): link succeeded but firmware.elf is missing symbol (Reset_Handler). ... this image would boot into nothing.
  • sam_linker unit tests (+4): the SAM3X config roots and requires
    Reset_Handler; missing_required_symbols reports only absent symbols;
    SAMD/SAME5x configs declare none.

Real gate output

  • soldr test -p fbuild-build-arm sam::: 32 passed (was 28).
  • bash test -p fbuild-build-arm: 252 passed, 0 failed, 2 ignored.
  • bash test -p fbuild-build: 21 + 2 + 22 passed, 0 failed.
  • soldr cargo clippy --workspace --all-targets -- -D warnings: clean.
  • soldr fmt --check: clean. ci/check_test_layout.py: ok (8 categories).

Dylint could not run on this host (known local soldr dylint prepare toolchain
mismatch), so CI's dylint lanes are the authority; no new file introduces a
banned pattern.

….elf

A Due build reported success and produced a ~5 KB firmware.elf with no
`setup`, no `loop` and no `main`. Atmel's classic-SAM `flash.ld` declares no
`ENTRY()`, so with no entry on the link line GNU ld defaulted to newlib's
`crt0.o` `_start`; nothing referenced `Reset_Handler`, `libsam`'s startup
object was never extracted from `libsam_sam3x8e_gcc_rel.a`, and
`--gc-sections` discarded the sketch, the startup code and the vector table.
The gcc driver still exited 0, so the whole loss was invisible.

- `sam3x.json` now passes `-Wl,--entry=Reset_Handler` (what Arduino's own SAM
  `platform.txt` does) and `-Wl,--undefined=Reset_Handler`, which turns a
  missing startup into a link error instead of a silent empty image.
- `SamMcuConfig` gains `required_link_symbols`; `SamLinker` verifies the
  declared symbols exist in the linked ELF, so a zero-exit link that produced
  an inert image fails the build with the missing symbol named. SAMD/SAME5x
  scripts declare `ENTRY()` themselves and declare no required symbols, so
  they are unchanged.

Verified with the real ARM toolchain (fbuild-build#1939): before the fix
`firmware.elf` had no `Reset_Handler`/`main`/`setup`/`loop`; after it all four
are defined and the link guard turns a flag regression into
`link succeeded but firmware.elf is missing symbol (Reset_Handler)`.
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees
zackees added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 9928f7c Nov 7, 2026
38 checks passed
@zackees
zackees deleted the agent/sam3x-reset-entry branch November 7, 2026 01:17
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

atmelsam Due (sam3x8e_due): linked firmware.elf omits the sketch (no setup/loop)

1 participant