Repository navigation
fix(sam): root the SAM3X reset handler so the sketch reaches firmware.elf - #1941
Merged
Merged
Conversation
….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)`.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1939.
Symptom
bash compile sam3x8e_due --examples Apa102(FastLED) reported success, butfirmware.elfwas ~22 KB /firmware.bin5.08 KB with nosetup,loopormainin its symbol table, whilesrc/main*.cpp.odid define them.Root cause
Atmel's classic-SAM
variants/<v>/linker_scripts/gcc/flash.lddeclares noENTRY(), and the SAM3X link line supplied no entry either. So:crt0.o_startas the entry (0x80000),Reset_Handler, sostartup_sam3xa.owas never extractedfrom
libsam_sam3x8e_gcc_rel.a(that is why.vectorsis empty),--gc-sectionsthen discardedmain,setup,loopand 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_Handlerand-Wl,--undefined=Reset_Handler— the sameentry Arduino's own SAM
platform.txtuses; the--undefinedhalf makes amissing startup a link error rather than a silent empty image.
SamMcuConfiggainsrequired_link_symbols(serde-defaulted, so every otherconfig is unchanged).
SamLinkerverifies those symbols exist in the linkedELF 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, realARM GCC + Arduino SAM core, mirrors
samd_acceptance): builds the Duefixture and requires
Reset_Handler,main,setup,loopto be definedwith non-zero size.
due: firmware.elf must define 'Reset_Handler'; a build success is not a link.required_link_symbolskept):
link succeeded but firmware.elf is missing symbol (Reset_Handler). ... this image would boot into nothing.sam_linkerunit tests (+4): the SAM3X config roots and requiresReset_Handler;missing_required_symbolsreports 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 preparetoolchainmismatch), so CI's dylint lanes are the authority; no new file introduces a
banned pattern.