[libunwind] [libunwind] Faster handling of frames with missed FDE records. (PR #167849)
Vyacheslav Chigrin via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 28 07:07:19 PST 2025
vchigrin wrote:
Sorry. Just discovered that this patch can not be applied "as is" since it breaks stack unwinding when some FDE has zero size. Here is example test program:
```c++
#include <iostream>
void BadGuy() {
__builtin_unreachable();
}
void Thrower() {
throw 1;
}
int main(int, char*[]) {
try {
Thrower();
} catch(const int&) {
std::cout << "Catched" << std::endl;
}
return 0;
}
```
If compiled with `-O2` and linked with `lld` linker, resulting ELF will have two FDE-s, one of which describes zero range of address space. Unfortunatelly, `.eh_frame_hdr` has reference to first one (with zero range), so this patch in present form will break stack unwinding and that test program will crash. Here is output of analyzing resulting ELF file
```
$ nm ./a.out.lld | grep 0000000000200bf0
0000000000200bf0 T _Z6BadGuyv
0000000000200bf0 T _Z7Throwerv
$ elf a.out.lld section .eh_frame | grep 00200bf0
│ │ ├╴ PC range │ 0x00000000'00200bf0..0x00000000'00200bf0
│ │ ├╴ PC range │ 0x00000000'00200bf0..0x00000000'00200c12
```
When linking the same object file using GNU ld linker there are no duplicates (seems thats why their stack unwinding code can skip linear scan of .eh_frame in runtime). Here is how looks ELF file produced by them:
```
$ nm ./a.out.ld | grep 004011a0
00000000004011a0 T _Z6BadGuyv
00000000004011a0 T _Z7Throwerv
$ elf a.out.ld section .eh_frame | grep 004011a0
│ │ ├╴ PC range │ 0x00000000'004011a0..0x00000000'004011c2
```
(In the this example I used `elf` utility from this site https://crates.io/crates/elf-info)
In my opinion, for good solution code in `lld` linker must be changed first, to exclude empty FDEs in the same way as `ld` does. And then this patch can be applied.
I can research this further, but first want to know what do you think about this approach? Did I go in the right direction, or these patches will be rejected anyway?
https://github.com/llvm/llvm-project/pull/167849
More information about the cfe-commits
mailing list