from http://www.x86-64.org/pipermail/discuss/attachments/20040816/914f9b7c/attachment.txt EH_FRAME sections ================= The call frame information needed for unwinding the stack is output in an ELF section(s) of type SHT_AMD64_UNWIND. In the simplest case there will be one such section per object file and it will be named ".eh_frame". An .eh_frame section consists of one or more subsections. Each subsection contains a CIE (Common Information Entry) followed by varying number of FDEs (Frame Descriptor Entry). A FDE corresponds to an explicit or compiler generated function in a compilation unit, all FDEs can access the CIE that begins their subsection for data. <<If the code for a function is not one contiguous block, there will be a separate FDE for each contiguous sub-piece>> If an object file contains C++ template instantiations there shall be a separate CIE immediately preceding each FDE corresponding to an instantiation. <<Proposed standards and existing practice differs considerably in the area of linker processing to eliminate duplicate instantiations. - TBD>> Using the preferred encoding specified below, the .eh_frame section can be entirely resolved at link time and thus can become part of the text segment. .eh_frame Section Layout ------------------------ EH_PE encoding below refers to the pointer encoding as specified in the enhanced LSB Chapter 7 for Eh_Frame_Hdr. Common Information Entry (CIE) ------------------------------ CIE has the following format: Length in Field Byte Description ----- ------ ----------- 1. Length 4 Length of CIE (not including this 4-byte field). 2. CIE id 4 Value Zero (0) for .eh_frame (used to distinguish CIEs and FDEs when scanning the section) 3. Version 1 Value One (1) 4. CIE Augmentation string Null-terminated string with legal values being "" or 'z' optionally followed by single occurrances of 'P', 'L', or 'R' in any order. String The presence of character(s) in the string dictates the content of field 8, the Augmentation Section. Each character has one or two associated operands in the AS. Operand order depends on position in the string ('z' must be first). 5. Code Align Factor uleb128 To be multiplied with the "Advance Location" instructions in the Call Frame Instructions 6. Data Align Factor sleb128 To be multiplied with all offset in the Call Frame Instructions 7. Ret Address Reg 1 A "virtual' register representation of the return address. In Dwarf V2, this is a byte, otherwise it is uleb128. It is a byte in gcc 3.3.x 8. Optional CIE varying Present if Augmentation String in Augmentation Section field 4 is not 0. z: size uleb128 Length of the remainder of the Augmentation Section P: personality_enc 1 Encoding specifier - preferred value is a pc-relative, signed 4-byte personality routine (encoded) Encoded pointer to personality routine (actually to the PLT entry for the personality routine) R: code_enc 1 Non-default encoding for the code-pointers (FDE members "initial_location" and "address_range" and the operand for DW_CFA_set_loc) - preferred value is pc-relative, signed 4-byte. L: lsda_enc 1 FDE augmentation bodies may contain LSDA pointers. If so they are encoded as specified here - preferred value is pc-relative, signed 4-byte possibly indirect thru a GOT entry. 9. Optional Call Frame varying Instructions The size of the optional call frame instruction area must be computed based on the overall size and the offset reached while scanning the preceding fields of the CIE. Frame Descriptor Entry (FDE) ---------------------------- FDE has the following format: Length in Field Byte Description ----- ------ ----------- 1. Length 4 Length of remainder of this FDE 2. CIE Pointer 4 Distance from this field to the nearest preceding CIE (the value is subtracted from the current address). This value can never be zero and thus can be used to distinguish CIE's and FDE's when scanning the .eh_frame section 3. Initial Location varying Reference to the function code corresponding to this FDE. If 'R' is missing from the CIE Augmentation String, the field is an 8-byte absolute pointer. Otherwise, the corresponding EH_PE encoding in the CIE Augmentation Section is used to interpret the reference. 4. Address Range varying Size of the function code corresponding to this FDE. If 'R' is missing from the CIE Augmentation String, the field is an 8-byte unsigned number. Otherwise, the size is determined by the corresponding EH_PE encoding in the CIE Augmentation Section (the value is always absolute). 5. Optional FDE varying present if CIE augmentation Augmentation Section string is non-empty. 'z': length uleb128 length of the remainder of the FDE augmentation section 'L' (and length > 0): LSDA varying LSDA pointer, encoded in the format specified by the corresponding operand in the CIE's augmentation body. 6. Optional Call varying Frame Instructions The size of the optional call frame instruction area must be computed based on the overall size and the offset reached while scanning the preceding fields of the FDE. The overall size of a .eh_frame section is given in the ELF section header. The only way to determine the number of entries is to scan the section till the end and count.