Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

unwind: skip FDEs with initial address of 0 #287

Merged
merged 1 commit into from
Nov 25, 2021
Merged

unwind: skip FDEs with initial address of 0 #287

merged 1 commit into from
Nov 25, 2021

Conversation

jonas-schievink
Copy link
Contributor

The panic example in the app-template can cause a broken backtrace like this:

stack backtrace:
   0: 0x00001450 @ HardFaultTrampoline
      <exception entry>
   1: 0x000008d4 @ lib::inline::__udf
        at ./asm/inline.rs:172:5
   2: 0x000008d4 @ __udf
        at ./asm/lib.rs:49:17
   3: 0x000001ba @ cortex_m::asm::udf
        at [...]/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/cortex-m-0.7.3/src/asm.rs:43:5
   4: 0x000001c4 @ _defmt_panic
        at [...]/src/lib.rs:13:5
   5: 0x000001b0 @ defmt::export::panic
        at [...]/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/defmt-0.3.0/src/export/mod.rs:125:14
   6: 0x000001b0 @ panic::__cortex_m_rt_main
        at [...]/src/bin/panic.rs:10:5
   7: 0x00000168 @ main
        at [...]/src/bin/panic.rs:6:1
   8: 0x00000144 @ Reset
   9: 0x00000100 @ Reset
  10: 0x52205244 @ __sheap

This appeared to have a different cause from #277, since the fix for that didn't fix the backtrace here.

After a lot of investigation, it turned out that what was going on is that there are multiple frame description entries (FDEs) in the debuginfo that claim to apply to some addresses, and we happened to pick the wrong one while unwinding from Reset in frame 8, causing us to restore registers incorrectly and then attempting to jump to a nonsense address.

This seems to be limited to FDEs describing presumably dead code, whose base address gets reset to 0 when they're included in the final ELF, so this PR fixes it by ignoring any FDEs that claim to apply to address 0.

Copy link
Contributor

@jonathanpallant jonathanpallant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwind_info_for_address being a method on both UnwindSection and FrameDescriptionEntry threw me for a loop there ... but this LGTM now I understand what's going on in the diff!

@jonathanpallant
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 25, 2021

Build succeeded:

@bors bors bot merged commit 4d830b6 into knurling-rs:main Nov 25, 2021
@jonas-schievink jonas-schievink deleted the skip-fdes-at-zero branch November 25, 2021 17:54
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants