Format:DWARF/.eh frame
The call-frame information section .eh_frame (PT_GNU_EH_FRAME, .eh_frame_hdr) that the Itanium-ABI unwinder reads to unwind stacks: a sequence of length-prefixed CIE and FDE records, with an augmentation string that tells which extra fields follow.
Record layout
The section is a list of records: uint32 length (0 = terminator; 0xFFFFFFFF = 64-bit length follows), then the body. The first field of the body is the CIE id: 0 means this record is a CIE; any other value is an FDE and is the distance, counted back from this field's own position, to its CIE. (In DWARF's .debug_frame the CIE marker is 0xFFFFFFFF and the FDE field is a section offset instead.) Fact:DWARF/struct/CIE and FDE layout
CIE after the id: uint8 version (1, or 3 in newer producers), NUL-terminated augmentation string, ULEB128 code_alignment_factor, SLEB128 data_alignment_factor, return-address register (a byte in version 1, ULEB128 later), then augmentation data if the string starts with z (ULEB128 length first), then initial CFA instructions up to the record end. Version 4 (.debug_frame only) adds address_size and segment_size bytes after the augmentation string.
FDE after the id: initial location and address range, both encoded with the CIE's R encoding (the range uses only the value format, no pc-relative bit), then, if the CIE has a z, a ULEB128 augmentation length and data (the LSDA pointer when the CIE has L), then CFA instructions.
Augmentation string
z must come first: augmentation data with a length follows. L one byte: LSDA pointer encoding (stored per FDE). P one byte encoding plus a personality routine pointer. R one byte: encoding of FDE addresses (default DW_EH_PE_absptr). S signal frame. AArch64 additions: B (return addresses signed with the B key) and G (MTE tagged frame). An unknown letter makes a parser stop, because the data length of later letters is unknown. Fact:DWARF/behavior/Augmentation letters
Pointer encodings
A DW_EH_PE byte: low nibble is the format (0x00 absptr, 0x01 uleb128, 0x02 udata2, 0x03 udata4, 0x04 udata8, 0x09 sleb128, 0x0A sdata2, 0x0B sdata4, 0x0C sdata8), the high bits the base (0x10 pcrel, 0x20 textrel, 0x30 datarel, 0x40 funcrel, 0x50 aligned), 0x80 indirect; 0xFF means omitted. The usual x86-64 value is 0x1B (pcrel | sdata4). Fact:DWARF/enum/DW_EH_PE encodings See also Platform:Itanium C++ ABI/LSDA for the language-specific data these point at.
Reversing notes
- pcrel values are relative to the address of the encoded field itself, so a parser needs the section's virtual address.
- .eh_frame_hdr holds a sorted (initial location, FDE address) table for binary search; it is the quickest way to list every function start of a stripped ELF.