1 /* seh pdata/xdata coff object file format
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
4 This file is part of GAS.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 There are at the moment three different function entry formats preset.
23 The first is the MIPS one. The second version
24 is for ARM, PPC, SH3, and SH4 mainly for Windows CE.
25 The third is the IA64 and x64 version. Note, the IA64 isn't implemented yet,
26 but to find information about it, please see specification about IA64 on
27 http://download.intel.com/design/Itanium/Downloads/245358.pdf file.
29 The first version has just entries in the pdata section: BeginAddress,
30 EndAddress, ExceptionHandler, HandlerData, and PrologueEndAddress. Each
31 value is a pointer to the corresponding data and has size of 4 bytes.
33 The second variant has the following entries in the pdata section.
34 BeginAddress, PrologueLength (8 bits), EndAddress (22 bits),
35 Use-32-bit-instruction (1 bit), and Exception-Handler-Exists (1 bit).
36 If the FunctionLength is zero, or the Exception-Handler-Exists bit
37 is true, a PDATA_EH block is placed directly before function entry.
39 The third version has a function entry block of BeginAddress (RVA),
40 EndAddress (RVA), and UnwindData (RVA). The description of the
41 prologue, exception-handler, and additional SEH data is stored
42 within the UNWIND_DATA field in the xdata section.
47 .seh_handler <handler>[,@unwind][,@except] (x64)
48 .seh_handler <handler>[,<handler_data>] (others)
53 .seh_setframe <reg>,<offset>
62 /* architecture specific pdata/xdata handling. */
64 {"seh_proc", obj_coff_seh_proc, 0}, \
65 {"seh_endproc", obj_coff_seh_endproc, 0}, \
66 {"seh_pushreg", obj_coff_seh_pushreg, 0}, \
67 {"seh_savereg", obj_coff_seh_save, 1}, \
68 {"seh_savexmm", obj_coff_seh_save, 2}, \
69 {"seh_pushframe", obj_coff_seh_pushframe, 0}, \
70 {"seh_endprologue", obj_coff_seh_endprologue, 0}, \
71 {"seh_setframe", obj_coff_seh_setframe, 0}, \
72 {"seh_stackalloc", obj_coff_seh_stackalloc, 0}, \
73 {"seh_eh", obj_coff_seh_eh, 0}, \
74 {"seh_32", obj_coff_seh_32, 1}, \
75 {"seh_no32", obj_coff_seh_32, 0}, \
76 {"seh_handler", obj_coff_seh_handler, 0}, \
77 {"seh_code", obj_coff_seh_code, 0}, \
78 {"seh_handlerdata", obj_coff_seh_handlerdata, 0},
80 /* Type definitions. */
82 typedef struct seh_prologue_element
88 } seh_prologue_element
;
90 typedef struct seh_context
92 struct seh_context
*next
;
94 /* Initial code-segment. */
105 symbolS
*endprologue_addr
;
106 /* ExceptionHandler. */
108 /* ExceptionHandlerData. (arm, mips) */
109 expressionS handler_data
;
111 /* ARM .seh_eh directive seen. */
114 /* WinCE specific data. */
115 int use_instruction_32
;
116 /* Was record already processed. */
119 /* x64 flags for the xdata header. */
123 /* x64 framereg and frame offset information. */
127 /* Information about x64 specific unwind data fields. */
130 seh_prologue_element
*elems
;
133 typedef enum seh_kind
{
134 seh_kind_unknown
= 0,
135 seh_kind_mips
= 1, /* Used for MIPS and x86 pdata generation. */
136 seh_kind_arm
= 2, /* Used for ARM, PPC, SH3, and SH4 pdata (PDATA_EH) generation. */
137 seh_kind_x64
= 3 /* Used for IA64 and x64 pdata/xdata generation. */
140 /* Forward declarations. */
141 static void obj_coff_seh_stackalloc (int);
142 static void obj_coff_seh_setframe (int);
143 static void obj_coff_seh_endprologue (int);
144 static void obj_coff_seh_save (int);
145 static void obj_coff_seh_pushreg (int);
146 static void obj_coff_seh_pushframe (int);
147 static void obj_coff_seh_endproc (int);
148 static void obj_coff_seh_eh (int);
149 static void obj_coff_seh_32 (int);
150 static void obj_coff_seh_proc (int);
151 static void obj_coff_seh_handler (int);
152 static void obj_coff_seh_handlerdata (int);
153 static void obj_coff_seh_code (int);
155 #define UNDSEC bfd_und_section_ptr
157 /* Check if x64 UNW_... macros are already defined. */
158 #ifndef PEX64_FLAG_NHANDLER
159 /* We can't include here coff/pe.h header. So we have to copy macros
160 from coff/pe.h here. */
161 #define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf)
162 #define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf)
164 /* The unwind info. */
165 #define UNW_FLAG_NHANDLER 0
166 #define UNW_FLAG_EHANDLER 1
167 #define UNW_FLAG_UHANDLER 2
168 #define UNW_FLAG_FHANDLER 3
169 #define UNW_FLAG_CHAININFO 4
171 #define UNW_FLAG_MASK 0x1f
173 /* The unwind codes. */
174 #define UWOP_PUSH_NONVOL 0
175 #define UWOP_ALLOC_LARGE 1
176 #define UWOP_ALLOC_SMALL 2
177 #define UWOP_SET_FPREG 3
178 #define UWOP_SAVE_NONVOL 4
179 #define UWOP_SAVE_NONVOL_FAR 5
180 #define UWOP_SAVE_XMM 6
181 #define UWOP_SAVE_XMM_FAR 7
182 #define UWOP_SAVE_XMM128 8
183 #define UWOP_SAVE_XMM128_FAR 9
184 #define UWOP_PUSH_MACHFRAME 10
186 #define PEX64_UWI_VERSION(VAL) ((VAL) & 7)
187 #define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f)
188 #define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf)
189 #define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf)
190 #define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \
191 ((((VAL) + 1) & ~1) * 2)
193 #define PEX64_OFFSET_TO_UNWIND_CODE 0x4
195 #define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \
196 (PEX64_OFFSET_TO_UNWIND_CODE + \
197 PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES))
199 #define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \
200 (PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4)
202 #define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \
203 (PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \
204 PEX64_SCOPE_ENTRY_SIZE * (IDX))
This page took 0.035259 seconds and 4 git commands to generate.