Skip to content

fix(firmware): prevent LTO from eliminating the ISR vector table#7369

Open
pfeerick wants to merge 1 commit into
mainfrom
pfeerick/fix-lto-isr-vector
Open

fix(firmware): prevent LTO from eliminating the ISR vector table#7369
pfeerick wants to merge 1 commit into
mainfrom
pfeerick/fix-lto-isr-vector

Conversation

@pfeerick
Copy link
Copy Markdown
Member

@pfeerick pfeerick commented May 15, 2026

Summary

  • With LTO (-flto) enabled (currently used for X9D+2019 builds), the linker discards _isr_vector[] because no C code references it directly — the hardware reads it via the VTOR register. KEEP() in the linker script prevents gc-sections from removing it, but LTO operates before that stage and eliminates the symbol entirely, resulting in an empty .isr_vector section.
  • This causes the firmware binary to have .fwversiondata (the version string) placed at the application start offset (BOOTLOADER_SIZE) instead of the ARM vector table, so isFirmwareStart() reads ASCII bytes instead of valid stack/ISR pointers and rejects the file as FC_ERROR.
  • Fix: add used to the ISR_VECTOR macro in cortex_m_isr.h, matching the same pattern already applied to BOOTSTRAP and init_hooks() in system_init.c as part of the LTO work.
  • Resolves regression introduced in feat(radio): add LTO option for complete firmware to reduce X9D+2019 #7255

Test plan

  • Build X9D+2019 firmware with LTO and confirm .isr_vector section is non-empty in firmware.map
  • Confirm valid firmware file is recognised in the bootloader (no longer shows FC_ERROR / "Invalid firmware")
  • Confirm firmware boots correctly on hardware
  • Verify non-LTO targets (X9D+, X9E, etc.) are unaffected

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Improved interrupt handler reliability by ensuring ISR vector entries are properly retained during compilation, preventing potential unintended removal by the linker.

Review Change Stack

With LTO (-flto), the linker can discard the _isr_vector[] array because
no C code references it directly (the hardware uses it via the VTOR
register). KEEP() in the linker script prevents gc-sections from removing
it, but LTO operates before that stage and can eliminate the symbol
entirely, resulting in an empty .isr_vector section.

Adding 'used' to ISR_VECTOR matches the same fix already applied to the
BOOTSTRAP macro and init_hooks() in system_init.c.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pfeerick pfeerick requested a review from raphaelcoeffic May 15, 2026 10:52
@pfeerick pfeerick added this to the 2.12.2 milestone May 15, 2026
@pfeerick pfeerick added the bug/regression ↩️ A new version of EdgeTX broke something label May 15, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

📝 Walkthrough

Walkthrough

The ISR vector table macro is updated to retain ISR entries in the final binary by adding the used attribute to the GCC section attribute, preventing the linker from discarding symbols that appear unreferenced.

Changes

ISR Vector Attribute Update

Layer / File(s) Summary
ISR_VECTOR macro with used attribute
radio/src/targets/common/arm/stm32/cortex_m_isr.h
ISR_VECTOR macro adds the used attribute alongside .isr_vector section placement to ensure ISR vector entries are retained by the linker.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: preventing LTO from eliminating the ISR vector table, which matches the core change in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description comprehensively explains the problem, solution, and includes a test plan with verification status.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pfeerick/fix-lto-isr-vector

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands and usage tips.

@pfeerick pfeerick added the compilation Related to compiling the firmware and firmware options label May 15, 2026
@philmoz
Copy link
Copy Markdown
Collaborator

philmoz commented May 16, 2026

Tested ok on T14.

@craigywsm
Copy link
Copy Markdown

tested on my FrSky X9D Plus 2019 and it now boots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug/regression ↩️ A new version of EdgeTX broke something compilation Related to compiling the firmware and firmware options

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants