Unwind and ARM.exidx that can't be shaken off

Brief

  • I'm trying to develop an application with Rust on an RTOS. I'm using armv7a-none-eabi as the target, but I've found that the compiled output always has a lot of ARM.exidx segments, which is related to unwind. I set panic = abort, and as expected, there should be no unwind-related segments in the compiled output.
  • This also caused my compilation results to be extremely bloated. Only a static library with the simplest add function had a binary size of 900kb.

Version

nightly-x86_64-unknown-linux-gnu - rustc 1.81.0-nightly (8fcd4dd08 2024-06-18)

You probably need to mark it as discard in the linker script using something like the following in the SECTIONS block:

/DISCARD/ :
{
  *(.ARM.exidx .ARM.exidx.* .ARM.extab.*);
}

See cortex-m/cortex-m-rt/link.x.in at f3f85e683f98d0f44ddadcb725e6e05c51c978b1 · rust-embedded/cortex-m · GitHub

If you are using the cortex-m-rt crate an appropriate linker script should be generated automatically and it can be enabled by passing -C link-arg=-Tlink.x to rustc. It may not be appropriate for use with an RTOS though. If your RTOS provides a linker script for applications to use, make sure to pass it to the linker and add the DISCARD block if it isn't there already.

So It can't be done by rustc automatically by passing some arguments? Do you think it sounds great to implement a similar mechanism in Rust? I think this is an implicit behavior and should be replaced by a more explicit behavior.

The target specification for armv7a-none-eabi declares panic=abort and doesn't force unwind tables, so it seems to be LLVM which decided to emit unwind tables despite nothing forcing them to be present.

1 Like

I found a discussion here : [llvm-dev] Is it possible to remove ARM.exidx section?. It seems that pass arguments -fno-exceptions -fno-unwind-tables -Os can remove ARM.exidx section, but I can't find out such a way to pass it to llvm in rust

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.