Makefile: fix generation of .debug_frame DWARF section #396
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.
To properly work with debug information, debuggers often need to unwind the stack. They generally rely on Call Frame Information (CFI) records provided by the compiler to facilitate this task. Currently, the GCC compiler offers two mechanisms:
.debug_framesection (as described in the DWARF specification)..eh_framesections (as described in the LSB documents).The latter (
.eh_frame) supports stack unwinding at runtime, providing a framework for C++ exceptions or enabling backtrace generation using libraries like libunwind. However, a downside of this approach is that these sections must be part of loadable segments.The former (
.debug_frame) is simply an ordinary debug section.Starting from GCC 13, Linux targets enable the
-fasynchronous-unwind-tablesand-funwind-tablesflags by default. Relevant commit:When these flags are active, the compiler generates
.eh_framesections instead of.debug_frame. Since OpenSBI is built using the Linux toolchain, this behavior applies to OpenSBI as well.The problem arises because the SBI build system uses
-Wl,--gc-sections, which discards the.eh_framesection.Possible Fixes:
.debug_framegeneration – Modify compiler flags to generate.debug_frameinstead of.eh_frame..eh_framein the linker script – AddKEEP(*(.eh_frame))to ensure the section is not discarded.I chose Option 1 because it avoids any runtime overhead.