Skip to content

fix: prevent LTO from breaking settingGet/settingGetIndex round-trip#11577

Merged
sensei-hacker merged 2 commits into
iNavFlight:maintenance-9.xfrom
sensei-hacker:fix/settings-lto-mspv2setting-index
May 22, 2026
Merged

fix: prevent LTO from breaking settingGet/settingGetIndex round-trip#11577
sensei-hacker merged 2 commits into
iNavFlight:maintenance-9.xfrom
sensei-hacker:fix/settings-lto-mspv2setting-index

Conversation

@sensei-hacker
Copy link
Copy Markdown
Member

Summary

Under INTERPROCEDURAL_OPTIMIZATION (LTO), the compiler inlines settingGet and settingGetIndex at their respective call sites with potentially divergent views of settingsTable's base address. The result is that settingGetIndex(ptr) returns index X, but settingGet(X) does not return the same entry — breaking the round-trip.

Symptom: MSPV2_SETTING returns the wrong value size (e.g. 1 byte) for some settings, while MSP2_COMMON_SETTING_INFO for the same setting name correctly returns the expected size and value. SITL builds are not affected because SITL is excluded from LTO.

Fix: Mark settingGet and settingGetIndex as noinline, forcing LTO to use a single, consistent reference to settingsTable across all call sites.

Changes

  • src/main/fc/settings.c: add __attribute__((noinline)) to settingGet and settingGetIndex

Testing

  • SITL build compiles cleanly with the change applied

Under INTERPROCEDURAL_OPTIMIZATION, the compiler inlines settingGet and
settingGetIndex with divergent static settingsTable base addresses,
causing MSPV2_SETTING to return wrong data for some settings while
MSP2_COMMON_SETTING_INFO (name lookup) is correct.
@qodo-code-review
Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Test firmware build ready — commit 44c5934

Download firmware for PR #11577

234 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

- Improve comment accuracy: describe observed behavior rather than the
  inferred mechanism; note why raw attribute is used instead of NOINLINE
  macro (NOINLINE is empty on non-F7/H7 targets but bug affects all LTO
  release builds)
- Add noinline to settingGetPgn which has identical pointer arithmetic
  against settingsTable and is called from settingGetValuePointer
- Add brief comments above settingGetIndex and settingGetPgn pointing
  back to the main explanation on settingGet
@sensei-hacker sensei-hacker merged commit cfc0033 into iNavFlight:maintenance-9.x May 22, 2026
23 checks passed
@daijoubu
Copy link
Copy Markdown
Contributor

This is the bugfix I was trying to recall. My friend could not set the Idle Throttle using the gui on his Matekf405 wing but his other boards work.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants