1 /* seh pdata/xdata coff object file format
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 There are at the moment three different function entry formats preset.
24 The first is the MIPS one. The second version
25 is for ARM, PPC, SH3, and SH4 mainly for Windows CE.
26 The third is the IA64 and x64 version. Note, the IA64 isn't implemented yet,
27 but to find information about it, please see specification about IA64 on
28 http://download.intel.com/design/Itanium/Downloads/245358.pdf file.
30 The first version has just entries in the pdata section: BeginAddress,
31 EndAddress, ExceptionHandler, HandlerData, and PrologueEndAddress. Each
32 value is a pointer to the corresponding data and has size of 4 bytes.
34 The second variant has the following entries in the pdata section.
35 BeginAddress, PrologueLength (8 bits), EndAddress (22 bits),
36 Use-32-bit-instruction (1 bit), and Exception-Handler-Exists (1 bit).
37 If the FunctionLength is zero, or the Exception-Handler-Exists bit
38 is true, a PDATA_EH block is placed directly before function entry.
40 The third version has a function entry block of BeginAddress (RVA),
41 EndAddress (RVA), and UnwindData (RVA). The description of the
42 prologue, excepetion-handler, and additional SEH data is stored
43 within the UNWIND_DATA field in the xdata section.
48 .seh_handler <handler>[,@unwind][,@except] (x64)
49 .seh_handler <handler>[,<handler_data>] (others)
54 .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_handlerdata", obj_coff_seh_handlerdata, 0},
79 /* Type definitions. */
81 typedef struct seh_prologue_element
87 } seh_prologue_element
;
89 typedef struct seh_context
91 struct seh_context
*next
;
93 /* Initial code-segment. */
104 symbolS
*endprologue_addr
;
105 /* ExceptionHandler. */
107 /* ExceptionHandlerData. (arm, mips) */
108 expressionS handler_data
;
110 /* ARM .seh_eh directive seen. */
113 /* WinCE specific data. */
114 int use_instruction_32
;
115 /* Was record already processed. */
118 /* x64 flags for the xdata header. */
122 /* x64 framereg and frame offset information. */
126 /* Information about x64 specific unwind data fields. */
129 seh_prologue_element
*elems
;
132 typedef enum seh_kind
{
133 seh_kind_unknown
= 0,
134 seh_kind_mips
= 1, /* Used for MIPS and x86 pdata generation. */
135 seh_kind_arm
= 2, /* Used for ARM, PPC, SH3, and SH4 pdata (PDATA_EH) generation. */
136 seh_kind_x64
= 3 /* Used for IA64 and x64 pdata/xdata generation. */
139 /* Forward declarations. */
140 static void obj_coff_seh_stackalloc (int);
141 static void obj_coff_seh_setframe (int);
142 static void obj_coff_seh_endprologue (int);
143 static void obj_coff_seh_save (int);
144 static void obj_coff_seh_pushreg (int);
145 static void obj_coff_seh_pushframe (int);
146 static void obj_coff_seh_endproc (int);
147 static void obj_coff_seh_eh (int);
148 static void obj_coff_seh_32 (int);
149 static void obj_coff_seh_proc (int);
150 static void obj_coff_seh_handler (int);
151 static void obj_coff_seh_handlerdata (int);
153 #define UNDSEC (asection *) &bfd_und_section
155 /* Check if x64 UNW_... macros are already defined. */
156 #ifndef PEX64_FLAG_NHANDLER
157 /* We can't include here coff/pe.h header. So we have to copy macros
158 from coff/pe.h here. */
159 #define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf)
160 #define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf)
162 /* The unwind info. */
163 #define UNW_FLAG_NHANDLER 0
164 #define UNW_FLAG_EHANDLER 1
165 #define UNW_FLAG_UHANDLER 2
166 #define UNW_FLAG_FHANDLER 3
167 #define UNW_FLAG_CHAININFO 4
169 #define UNW_FLAG_MASK 0x1f
171 /* The unwind codes. */
172 #define UWOP_PUSH_NONVOL 0
173 #define UWOP_ALLOC_LARGE 1
174 #define UWOP_ALLOC_SMALL 2
175 #define UWOP_SET_FPREG 3
176 #define UWOP_SAVE_NONVOL 4
177 #define UWOP_SAVE_NONVOL_FAR 5
178 #define UWOP_SAVE_XMM 6
179 #define UWOP_SAVE_XMM_FAR 7
180 #define UWOP_SAVE_XMM128 8
181 #define UWOP_SAVE_XMM128_FAR 9
182 #define UWOP_PUSH_MACHFRAME 10
184 #define PEX64_UWI_VERSION(VAL) ((VAL) & 7)
185 #define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f)
186 #define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf)
187 #define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf)
188 #define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \
189 ((((VAL) + 1) & ~1) * 2)
191 #define PEX64_OFFSET_TO_UNWIND_CODE 0x4
193 #define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \
194 (PEX64_OFFSET_TO_UNWIND_CODE + \
195 PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES))
197 #define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \
198 (PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4)
200 #define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \
201 (PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \
202 PEX64_SCOPE_ENTRY_SIZE * (IDX))
This page took 0.033143 seconds and 4 git commands to generate.