1 1.1 mrg /* DWARF2 exception handling and frame unwind runtime interface routines. 2 1.11 mrg Copyright (C) 1997-2024 Free Software Foundation, Inc. 3 1.1 mrg 4 1.1 mrg This file is part of GCC. 5 1.1 mrg 6 1.1 mrg GCC is free software; you can redistribute it and/or modify it 7 1.1 mrg under the terms of the GNU General Public License as published by 8 1.1 mrg the Free Software Foundation; either version 3, or (at your option) 9 1.1 mrg any later version. 10 1.1 mrg 11 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT 12 1.1 mrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14 1.1 mrg License for more details. 15 1.1 mrg 16 1.1 mrg Under Section 7 of GPL version 3, you are granted additional 17 1.1 mrg permissions described in the GCC Runtime Library Exception, version 18 1.1 mrg 3.1, as published by the Free Software Foundation. 19 1.1 mrg 20 1.1 mrg You should have received a copy of the GNU General Public License and 21 1.1 mrg a copy of the GCC Runtime Library Exception along with this program; 22 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 1.1 mrg <http://www.gnu.org/licenses/>. */ 24 1.1 mrg 25 1.1 mrg #include "tconfig.h" 26 1.1 mrg #include "tsystem.h" 27 1.1 mrg #include "coretypes.h" 28 1.1 mrg #include "tm.h" 29 1.1 mrg #include "libgcc_tm.h" 30 1.1 mrg #include "dwarf2.h" 31 1.1 mrg #include "unwind.h" 32 1.1 mrg #ifdef __USING_SJLJ_EXCEPTIONS__ 33 1.1 mrg # define NO_SIZE_OF_ENCODED_VALUE 34 1.1 mrg #endif 35 1.1 mrg #include "unwind-pe.h" 36 1.1 mrg #include "unwind-dw2-fde.h" 37 1.1 mrg #include "gthr.h" 38 1.1 mrg #include "unwind-dw2.h" 39 1.11 mrg #include <stddef.h> 40 1.1 mrg 41 1.1 mrg #ifdef HAVE_SYS_SDT_H 42 1.1 mrg #include <sys/sdt.h> 43 1.1 mrg #endif 44 1.1 mrg 45 1.1 mrg #ifndef __USING_SJLJ_EXCEPTIONS__ 46 1.1 mrg 47 1.4 mrg #ifndef __LIBGCC_STACK_GROWS_DOWNWARD__ 48 1.4 mrg #define __LIBGCC_STACK_GROWS_DOWNWARD__ 0 49 1.1 mrg #else 50 1.4 mrg #undef __LIBGCC_STACK_GROWS_DOWNWARD__ 51 1.4 mrg #define __LIBGCC_STACK_GROWS_DOWNWARD__ 1 52 1.1 mrg #endif 53 1.1 mrg 54 1.1 mrg /* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */ 55 1.1 mrg #ifndef PRE_GCC3_DWARF_FRAME_REGISTERS 56 1.4 mrg #define PRE_GCC3_DWARF_FRAME_REGISTERS __LIBGCC_DWARF_FRAME_REGISTERS__ 57 1.1 mrg #endif 58 1.1 mrg 59 1.1 mrg /* ??? For the public function interfaces, we tend to gcc_assert that the 60 1.1 mrg column numbers are in range. For the dwarf2 unwind info this does happen, 61 1.1 mrg although so far in a case that doesn't actually matter. 62 1.1 mrg 63 1.1 mrg See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores 64 1.1 mrg the call-saved xmm registers and annotates them. We havn't bothered 65 1.1 mrg providing support for the xmm registers for the x86_64 port primarily 66 1.1 mrg because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or 67 1.1 mrg SEH instead. Adding the support for unix targets would generally be a 68 1.1 mrg waste. However, some runtime libraries supplied with ICC do contain such 69 1.1 mrg an unorthodox transition, as well as the unwind info to match. This loss 70 1.1 mrg of register restoration doesn't matter in practice, because the exception 71 1.1 mrg is caught in the native unix abi, where all of the xmm registers are 72 1.1 mrg call clobbered. 73 1.1 mrg 74 1.1 mrg Ideally, we'd record some bit to notice when we're failing to restore some 75 1.1 mrg register recorded in the unwind info, but to do that we need annotation on 76 1.1 mrg the unix->ms abi edge, so that we know when the register data may be 77 1.1 mrg discarded. And since this edge is also within the ICC library, we're 78 1.1 mrg unlikely to be able to get the new annotation. 79 1.1 mrg 80 1.1 mrg Barring a magic solution to restore the ms abi defined 128-bit xmm registers 81 1.1 mrg (as distictly opposed to the full runtime width) without causing extra 82 1.1 mrg overhead for normal unix abis, the best solution seems to be to simply 83 1.1 mrg ignore unwind data for unknown columns. */ 84 1.1 mrg 85 1.1 mrg #define UNWIND_COLUMN_IN_RANGE(x) \ 86 1.4 mrg __builtin_expect((x) <= __LIBGCC_DWARF_FRAME_REGISTERS__, 1) 87 1.1 mrg 88 1.1 mrg #ifdef REG_VALUE_IN_UNWIND_CONTEXT 89 1.1 mrg typedef _Unwind_Word _Unwind_Context_Reg_Val; 90 1.1 mrg 91 1.1 mrg #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT 92 1.1 mrg #define ASSUME_EXTENDED_UNWIND_CONTEXT 1 93 1.1 mrg #endif 94 1.1 mrg 95 1.1 mrg static inline _Unwind_Word 96 1.1 mrg _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val) 97 1.1 mrg { 98 1.1 mrg return val; 99 1.1 mrg } 100 1.1 mrg 101 1.1 mrg static inline _Unwind_Context_Reg_Val 102 1.1 mrg _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val) 103 1.1 mrg { 104 1.1 mrg return val; 105 1.1 mrg } 106 1.1 mrg #else 107 1.1 mrg typedef void *_Unwind_Context_Reg_Val; 108 1.1 mrg 109 1.1 mrg static inline _Unwind_Word 110 1.1 mrg _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val) 111 1.1 mrg { 112 1.1 mrg return (_Unwind_Word) (_Unwind_Internal_Ptr) val; 113 1.1 mrg } 114 1.1 mrg 115 1.1 mrg static inline _Unwind_Context_Reg_Val 116 1.1 mrg _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val) 117 1.1 mrg { 118 1.1 mrg return (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) val; 119 1.1 mrg } 120 1.1 mrg #endif 121 1.1 mrg 122 1.1 mrg #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT 123 1.1 mrg #define ASSUME_EXTENDED_UNWIND_CONTEXT 0 124 1.1 mrg #endif 125 1.1 mrg 126 1.1 mrg /* This is the register and unwind state for a particular frame. This 127 1.1 mrg provides the information necessary to unwind up past a frame and return 128 1.1 mrg to its caller. */ 129 1.1 mrg struct _Unwind_Context 130 1.1 mrg { 131 1.4 mrg _Unwind_Context_Reg_Val reg[__LIBGCC_DWARF_FRAME_REGISTERS__+1]; 132 1.1 mrg void *cfa; 133 1.1 mrg void *ra; 134 1.1 mrg void *lsda; 135 1.1 mrg struct dwarf_eh_bases bases; 136 1.1 mrg /* Signal frame context. */ 137 1.1 mrg #define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1) 138 1.1 mrg /* Context which has version/args_size/by_value fields. */ 139 1.1 mrg #define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1) 140 1.1 mrg _Unwind_Word flags; 141 1.1 mrg /* 0 for now, can be increased when further fields are added to 142 1.1 mrg struct _Unwind_Context. */ 143 1.1 mrg _Unwind_Word version; 144 1.1 mrg _Unwind_Word args_size; 145 1.4 mrg char by_value[__LIBGCC_DWARF_FRAME_REGISTERS__+1]; 146 1.1 mrg }; 147 1.1 mrg 148 1.1 mrg /* Byte size of every register managed by these routines. */ 149 1.4 mrg static unsigned char dwarf_reg_size_table[__LIBGCC_DWARF_FRAME_REGISTERS__+1]; 150 1.1 mrg 151 1.1 mrg 152 1.1 mrg /* Read unaligned data from the instruction buffer. */ 154 1.1 mrg 155 1.1 mrg union unaligned 156 1.1 mrg { 157 1.1 mrg void *p; 158 1.1 mrg unsigned u2 __attribute__ ((mode (HI))); 159 1.1 mrg unsigned u4 __attribute__ ((mode (SI))); 160 1.1 mrg unsigned u8 __attribute__ ((mode (DI))); 161 1.1 mrg signed s2 __attribute__ ((mode (HI))); 162 1.1 mrg signed s4 __attribute__ ((mode (SI))); 163 1.1 mrg signed s8 __attribute__ ((mode (DI))); 164 1.1 mrg } __attribute__ ((packed)); 165 1.1 mrg 166 1.1 mrg static void uw_update_context (struct _Unwind_Context *, _Unwind_FrameState *); 167 1.1 mrg static _Unwind_Reason_Code uw_frame_state_for (struct _Unwind_Context *, 168 1.1 mrg _Unwind_FrameState *); 169 1.1 mrg 170 1.1 mrg static inline void * 171 1.1 mrg read_pointer (const void *p) { const union unaligned *up = p; return up->p; } 172 1.1 mrg 173 1.1 mrg static inline int 174 1.1 mrg read_1u (const void *p) { return *(const unsigned char *) p; } 175 1.1 mrg 176 1.1 mrg static inline int 177 1.1 mrg read_1s (const void *p) { return *(const signed char *) p; } 178 1.1 mrg 179 1.1 mrg static inline int 180 1.1 mrg read_2u (const void *p) { const union unaligned *up = p; return up->u2; } 181 1.1 mrg 182 1.1 mrg static inline int 183 1.1 mrg read_2s (const void *p) { const union unaligned *up = p; return up->s2; } 184 1.1 mrg 185 1.1 mrg static inline unsigned int 186 1.1 mrg read_4u (const void *p) { const union unaligned *up = p; return up->u4; } 187 1.1 mrg 188 1.1 mrg static inline int 189 1.1 mrg read_4s (const void *p) { const union unaligned *up = p; return up->s4; } 190 1.1 mrg 191 1.1 mrg static inline unsigned long 192 1.1 mrg read_8u (const void *p) { const union unaligned *up = p; return up->u8; } 193 1.1 mrg 194 1.1 mrg static inline unsigned long 195 1.1 mrg read_8s (const void *p) { const union unaligned *up = p; return up->s8; } 196 1.1 mrg 197 1.1 mrg static inline _Unwind_Word 199 1.1 mrg _Unwind_IsSignalFrame (struct _Unwind_Context *context) 200 1.1 mrg { 201 1.1 mrg return (context->flags & SIGNAL_FRAME_BIT) ? 1 : 0; 202 1.1 mrg } 203 1.1 mrg 204 1.1 mrg static inline void 205 1.1 mrg _Unwind_SetSignalFrame (struct _Unwind_Context *context, int val) 206 1.1 mrg { 207 1.1 mrg if (val) 208 1.1 mrg context->flags |= SIGNAL_FRAME_BIT; 209 1.1 mrg else 210 1.1 mrg context->flags &= ~SIGNAL_FRAME_BIT; 211 1.1 mrg } 212 1.1 mrg 213 1.1 mrg static inline _Unwind_Word 214 1.1 mrg _Unwind_IsExtendedContext (struct _Unwind_Context *context) 215 1.1 mrg { 216 1.1 mrg return (ASSUME_EXTENDED_UNWIND_CONTEXT 217 1.1 mrg || (context->flags & EXTENDED_CONTEXT_BIT)); 218 1.7 mrg } 219 1.1 mrg 220 1.1 mrg /* Get the value of register REGNO as saved in CONTEXT. */ 222 1.1 mrg 223 1.7 mrg inline _Unwind_Word 224 1.1 mrg _Unwind_GetGR (struct _Unwind_Context *context, int regno) 225 1.1 mrg { 226 1.1 mrg int size, index; 227 1.7 mrg _Unwind_Context_Reg_Val val; 228 1.1 mrg 229 1.1 mrg #ifdef DWARF_ZERO_REG 230 1.1 mrg if (regno == DWARF_ZERO_REG) 231 1.7 mrg return 0; 232 1.1 mrg #endif 233 1.1 mrg 234 1.1 mrg index = DWARF_REG_TO_UNWIND_COLUMN (regno); 235 1.1 mrg gcc_assert (index < (int) sizeof(dwarf_reg_size_table)); 236 1.1 mrg size = dwarf_reg_size_table[index]; 237 1.1 mrg val = context->reg[index]; 238 1.1 mrg 239 1.7 mrg if (_Unwind_IsExtendedContext (context) && context->by_value[index]) 240 1.7 mrg return _Unwind_Get_Unwind_Word (val); 241 1.7 mrg 242 1.7 mrg #ifdef DWARF_LAZY_REGISTER_VALUE 243 1.7 mrg { 244 1.7 mrg _Unwind_Word value; 245 1.7 mrg if (DWARF_LAZY_REGISTER_VALUE (regno, &value)) 246 1.7 mrg return value; 247 1.1 mrg } 248 1.1 mrg #endif 249 1.1 mrg 250 1.1 mrg /* This will segfault if the register hasn't been saved. */ 251 1.1 mrg if (size == sizeof(_Unwind_Ptr)) 252 1.1 mrg return * (_Unwind_Ptr *) (_Unwind_Internal_Ptr) val; 253 1.1 mrg else 254 1.1 mrg { 255 1.1 mrg gcc_assert (size == sizeof(_Unwind_Word)); 256 1.1 mrg return * (_Unwind_Word *) (_Unwind_Internal_Ptr) val; 257 1.1 mrg } 258 1.1 mrg } 259 1.1 mrg 260 1.1 mrg static inline void * 261 1.1 mrg _Unwind_GetPtr (struct _Unwind_Context *context, int index) 262 1.1 mrg { 263 1.1 mrg return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index); 264 1.1 mrg } 265 1.1 mrg 266 1.1 mrg /* Get the value of the CFA as saved in CONTEXT. */ 267 1.1 mrg 268 1.1 mrg _Unwind_Word 269 1.1 mrg _Unwind_GetCFA (struct _Unwind_Context *context) 270 1.1 mrg { 271 1.1 mrg return (_Unwind_Ptr) context->cfa; 272 1.1 mrg } 273 1.1 mrg 274 1.1 mrg /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */ 275 1.1 mrg 276 1.1 mrg inline void 277 1.1 mrg _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val) 278 1.1 mrg { 279 1.1 mrg int size; 280 1.1 mrg void *ptr; 281 1.1 mrg 282 1.1 mrg index = DWARF_REG_TO_UNWIND_COLUMN (index); 283 1.1 mrg gcc_assert (index < (int) sizeof(dwarf_reg_size_table)); 284 1.1 mrg size = dwarf_reg_size_table[index]; 285 1.1 mrg 286 1.1 mrg if (_Unwind_IsExtendedContext (context) && context->by_value[index]) 287 1.1 mrg { 288 1.1 mrg context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val); 289 1.1 mrg return; 290 1.1 mrg } 291 1.1 mrg 292 1.1 mrg ptr = (void *) (_Unwind_Internal_Ptr) context->reg[index]; 293 1.1 mrg 294 1.1 mrg if (size == sizeof(_Unwind_Ptr)) 295 1.1 mrg * (_Unwind_Ptr *) ptr = val; 296 1.1 mrg else 297 1.1 mrg { 298 1.1 mrg gcc_assert (size == sizeof(_Unwind_Word)); 299 1.1 mrg * (_Unwind_Word *) ptr = val; 300 1.1 mrg } 301 1.1 mrg } 302 1.1 mrg 303 1.1 mrg /* Get the pointer to a register INDEX as saved in CONTEXT. */ 304 1.1 mrg 305 1.1 mrg static inline void * 306 1.1 mrg _Unwind_GetGRPtr (struct _Unwind_Context *context, int index) 307 1.1 mrg { 308 1.1 mrg index = DWARF_REG_TO_UNWIND_COLUMN (index); 309 1.1 mrg if (_Unwind_IsExtendedContext (context) && context->by_value[index]) 310 1.1 mrg return &context->reg[index]; 311 1.1 mrg return (void *) (_Unwind_Internal_Ptr) context->reg[index]; 312 1.1 mrg } 313 1.1 mrg 314 1.1 mrg /* Set the pointer to a register INDEX as saved in CONTEXT. */ 315 1.1 mrg 316 1.1 mrg static inline void 317 1.1 mrg _Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p) 318 1.1 mrg { 319 1.1 mrg index = DWARF_REG_TO_UNWIND_COLUMN (index); 320 1.1 mrg if (_Unwind_IsExtendedContext (context)) 321 1.1 mrg context->by_value[index] = 0; 322 1.1 mrg context->reg[index] = (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) p; 323 1.1 mrg } 324 1.1 mrg 325 1.1 mrg /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */ 326 1.1 mrg 327 1.1 mrg static inline void 328 1.1 mrg _Unwind_SetGRValue (struct _Unwind_Context *context, int index, 329 1.1 mrg _Unwind_Word val) 330 1.1 mrg { 331 1.1 mrg index = DWARF_REG_TO_UNWIND_COLUMN (index); 332 1.1 mrg gcc_assert (index < (int) sizeof(dwarf_reg_size_table)); 333 1.1 mrg /* Return column size may be smaller than _Unwind_Context_Reg_Val. */ 334 1.1 mrg gcc_assert (dwarf_reg_size_table[index] <= sizeof (_Unwind_Context_Reg_Val)); 335 1.1 mrg 336 1.1 mrg context->by_value[index] = 1; 337 1.1 mrg context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val); 338 1.1 mrg } 339 1.1 mrg 340 1.1 mrg /* Return nonzero if register INDEX is stored by value rather than 341 1.1 mrg by reference. */ 342 1.1 mrg 343 1.1 mrg static inline int 344 1.1 mrg _Unwind_GRByValue (struct _Unwind_Context *context, int index) 345 1.1 mrg { 346 1.1 mrg index = DWARF_REG_TO_UNWIND_COLUMN (index); 347 1.1 mrg return context->by_value[index]; 348 1.1 mrg } 349 1.1 mrg 350 1.1 mrg /* Retrieve the return address for CONTEXT. */ 351 1.1 mrg 352 1.1 mrg inline _Unwind_Ptr 353 1.1 mrg _Unwind_GetIP (struct _Unwind_Context *context) 354 1.1 mrg { 355 1.1 mrg return (_Unwind_Ptr) context->ra; 356 1.1 mrg } 357 1.1 mrg 358 1.1 mrg /* Retrieve the return address and flag whether that IP is before 359 1.1 mrg or after first not yet fully executed instruction. */ 360 1.1 mrg 361 1.1 mrg inline _Unwind_Ptr 362 1.1 mrg _Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn) 363 1.1 mrg { 364 1.1 mrg *ip_before_insn = _Unwind_IsSignalFrame (context); 365 1.1 mrg return (_Unwind_Ptr) context->ra; 366 1.1 mrg } 367 1.1 mrg 368 1.1 mrg /* Overwrite the return address for CONTEXT with VAL. */ 369 1.1 mrg 370 1.1 mrg inline void 371 1.1 mrg _Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val) 372 1.1 mrg { 373 1.2 joerg context->ra = (void *) val; 374 1.1 mrg } 375 1.1 mrg 376 1.3 joerg _Unwind_Ptr 377 1.1 mrg _Unwind_GetLanguageSpecificData (struct _Unwind_Context *context) 378 1.1 mrg { 379 1.1 mrg return (_Unwind_Ptr) context->lsda; 380 1.1 mrg } 381 1.1 mrg 382 1.1 mrg _Unwind_Ptr 383 1.1 mrg _Unwind_GetRegionStart (struct _Unwind_Context *context) 384 1.1 mrg { 385 1.1 mrg return (_Unwind_Ptr) context->bases.func; 386 1.1 mrg } 387 1.1 mrg 388 1.1 mrg void * 389 1.1 mrg _Unwind_FindEnclosingFunction (void *pc) 390 1.1 mrg { 391 1.1 mrg struct dwarf_eh_bases bases; 392 1.1 mrg const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases); 393 1.1 mrg if (fde) 394 1.1 mrg return bases.func; 395 1.1 mrg else 396 1.1 mrg return NULL; 397 1.1 mrg } 398 1.1 mrg 399 1.1 mrg #ifndef __ia64__ 400 1.1 mrg _Unwind_Ptr 401 1.1 mrg _Unwind_GetDataRelBase (struct _Unwind_Context *context) 402 1.1 mrg { 403 1.1 mrg return (_Unwind_Ptr) context->bases.dbase; 404 1.1 mrg } 405 1.1 mrg 406 1.1 mrg _Unwind_Ptr 407 1.1 mrg _Unwind_GetTextRelBase (struct _Unwind_Context *context) 408 1.1 mrg { 409 1.1 mrg return (_Unwind_Ptr) context->bases.tbase; 410 1.1 mrg } 411 1.1 mrg #endif 412 1.1 mrg 413 1.1 mrg #include "md-unwind-support.h" 414 1.1 mrg 415 1.1 mrg /* Extract any interesting information from the CIE for the translation 417 1.1 mrg unit F belongs to. Return a pointer to the byte after the augmentation, 418 1.1 mrg or NULL if we encountered an undecipherable augmentation. */ 419 1.1 mrg 420 1.1 mrg static const unsigned char * 421 1.1 mrg extract_cie_info (const struct dwarf_cie *cie, struct _Unwind_Context *context, 422 1.1 mrg _Unwind_FrameState *fs) 423 1.1 mrg { 424 1.1 mrg const unsigned char *aug = cie->augmentation; 425 1.1 mrg const unsigned char *p = aug + strlen ((const char *)aug) + 1; 426 1.1 mrg const unsigned char *ret = NULL; 427 1.1 mrg _uleb128_t utmp; 428 1.1 mrg _sleb128_t stmp; 429 1.1 mrg 430 1.1 mrg /* g++ v2 "eh" has pointer immediately following augmentation string, 431 1.1 mrg so it must be handled first. */ 432 1.1 mrg if (aug[0] == 'e' && aug[1] == 'h') 433 1.1 mrg { 434 1.1 mrg fs->eh_ptr = read_pointer (p); 435 1.1 mrg p += sizeof (void *); 436 1.1 mrg aug += 2; 437 1.1 mrg } 438 1.1 mrg 439 1.1 mrg /* After the augmentation resp. pointer for "eh" augmentation 440 1.1 mrg follows for CIE version >= 4 address size byte and 441 1.1 mrg segment size byte. */ 442 1.1 mrg if (__builtin_expect (cie->version >= 4, 0)) 443 1.1 mrg { 444 1.1 mrg if (p[0] != sizeof (void *) || p[1] != 0) 445 1.1 mrg return NULL; 446 1.1 mrg p += 2; 447 1.1 mrg } 448 1.1 mrg /* Immediately following this are the code and 449 1.1 mrg data alignment and return address column. */ 450 1.1 mrg p = read_uleb128 (p, &utmp); 451 1.1 mrg fs->code_align = (_Unwind_Word)utmp; 452 1.1 mrg p = read_sleb128 (p, &stmp); 453 1.1 mrg fs->data_align = (_Unwind_Sword)stmp; 454 1.1 mrg if (cie->version == 1) 455 1.1 mrg fs->retaddr_column = *p++; 456 1.1 mrg else 457 1.1 mrg { 458 1.1 mrg p = read_uleb128 (p, &utmp); 459 1.1 mrg fs->retaddr_column = (_Unwind_Word)utmp; 460 1.1 mrg } 461 1.1 mrg fs->lsda_encoding = DW_EH_PE_omit; 462 1.1 mrg 463 1.1 mrg /* If the augmentation starts with 'z', then a uleb128 immediately 464 1.1 mrg follows containing the length of the augmentation field following 465 1.1 mrg the size. */ 466 1.1 mrg if (*aug == 'z') 467 1.1 mrg { 468 1.1 mrg p = read_uleb128 (p, &utmp); 469 1.1 mrg ret = p + utmp; 470 1.1 mrg 471 1.1 mrg fs->saw_z = 1; 472 1.1 mrg ++aug; 473 1.1 mrg } 474 1.1 mrg 475 1.1 mrg /* Iterate over recognized augmentation subsequences. */ 476 1.1 mrg while (*aug != '\0') 477 1.1 mrg { 478 1.1 mrg /* "L" indicates a byte showing how the LSDA pointer is encoded. */ 479 1.1 mrg if (aug[0] == 'L') 480 1.1 mrg { 481 1.1 mrg fs->lsda_encoding = *p++; 482 1.1 mrg aug += 1; 483 1.1 mrg } 484 1.1 mrg 485 1.1 mrg /* "R" indicates a byte indicating how FDE addresses are encoded. */ 486 1.1 mrg else if (aug[0] == 'R') 487 1.1 mrg { 488 1.1 mrg fs->fde_encoding = *p++; 489 1.1 mrg aug += 1; 490 1.1 mrg } 491 1.1 mrg 492 1.1 mrg /* "P" indicates a personality routine in the CIE augmentation. */ 493 1.1 mrg else if (aug[0] == 'P') 494 1.1 mrg { 495 1.1 mrg _Unwind_Ptr personality; 496 1.1 mrg 497 1.1 mrg p = read_encoded_value (context, *p, p + 1, &personality); 498 1.1 mrg fs->personality = (_Unwind_Personality_Fn) personality; 499 1.1 mrg aug += 1; 500 1.1 mrg } 501 1.1 mrg 502 1.1 mrg /* "S" indicates a signal frame. */ 503 1.1 mrg else if (aug[0] == 'S') 504 1.9 mrg { 505 1.9 mrg fs->signal_frame = 1; 506 1.9 mrg aug += 1; 507 1.9 mrg } 508 1.9 mrg /* aarch64 B-key pointer authentication. */ 509 1.1 mrg else if (aug[0] == 'B') 510 1.1 mrg { 511 1.1 mrg aug += 1; 512 1.1 mrg } 513 1.1 mrg 514 1.1 mrg /* Otherwise we have an unknown augmentation string. 515 1.1 mrg Bail unless we saw a 'z' prefix. */ 516 1.1 mrg else 517 1.1 mrg return ret; 518 1.1 mrg } 519 1.1 mrg 520 1.1 mrg return ret ? ret : p; 521 1.1 mrg } 522 1.1 mrg 523 1.1 mrg 524 1.1 mrg /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL 525 1.1 mrg onto the stack to start. */ 526 1.1 mrg 527 1.1 mrg static _Unwind_Word 528 1.1 mrg execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end, 529 1.1 mrg struct _Unwind_Context *context, _Unwind_Word initial) 530 1.1 mrg { 531 1.1 mrg _Unwind_Word stack[64]; /* ??? Assume this is enough. */ 532 1.1 mrg int stack_elt; 533 1.1 mrg 534 1.1 mrg stack[0] = initial; 535 1.1 mrg stack_elt = 1; 536 1.1 mrg 537 1.1 mrg while (op_ptr < op_end) 538 1.1 mrg { 539 1.1 mrg enum dwarf_location_atom op = *op_ptr++; 540 1.1 mrg _Unwind_Word result; 541 1.1 mrg _uleb128_t reg, utmp; 542 1.1 mrg _sleb128_t offset, stmp; 543 1.1 mrg 544 1.1 mrg switch (op) 545 1.1 mrg { 546 1.1 mrg case DW_OP_lit0: 547 1.1 mrg case DW_OP_lit1: 548 1.1 mrg case DW_OP_lit2: 549 1.1 mrg case DW_OP_lit3: 550 1.1 mrg case DW_OP_lit4: 551 1.1 mrg case DW_OP_lit5: 552 1.1 mrg case DW_OP_lit6: 553 1.1 mrg case DW_OP_lit7: 554 1.1 mrg case DW_OP_lit8: 555 1.1 mrg case DW_OP_lit9: 556 1.1 mrg case DW_OP_lit10: 557 1.1 mrg case DW_OP_lit11: 558 1.1 mrg case DW_OP_lit12: 559 1.1 mrg case DW_OP_lit13: 560 1.1 mrg case DW_OP_lit14: 561 1.1 mrg case DW_OP_lit15: 562 1.1 mrg case DW_OP_lit16: 563 1.1 mrg case DW_OP_lit17: 564 1.1 mrg case DW_OP_lit18: 565 1.1 mrg case DW_OP_lit19: 566 1.1 mrg case DW_OP_lit20: 567 1.1 mrg case DW_OP_lit21: 568 1.1 mrg case DW_OP_lit22: 569 1.1 mrg case DW_OP_lit23: 570 1.1 mrg case DW_OP_lit24: 571 1.1 mrg case DW_OP_lit25: 572 1.1 mrg case DW_OP_lit26: 573 1.1 mrg case DW_OP_lit27: 574 1.1 mrg case DW_OP_lit28: 575 1.1 mrg case DW_OP_lit29: 576 1.1 mrg case DW_OP_lit30: 577 1.1 mrg case DW_OP_lit31: 578 1.1 mrg result = op - DW_OP_lit0; 579 1.1 mrg break; 580 1.1 mrg 581 1.1 mrg case DW_OP_addr: 582 1.1 mrg result = (_Unwind_Word) (_Unwind_Ptr) read_pointer (op_ptr); 583 1.1 mrg op_ptr += sizeof (void *); 584 1.1 mrg break; 585 1.1 mrg 586 1.1 mrg case DW_OP_GNU_encoded_addr: 587 1.1 mrg { 588 1.1 mrg _Unwind_Ptr presult; 589 1.1 mrg op_ptr = read_encoded_value (context, *op_ptr, op_ptr+1, &presult); 590 1.1 mrg result = presult; 591 1.1 mrg } 592 1.1 mrg break; 593 1.1 mrg 594 1.1 mrg case DW_OP_const1u: 595 1.1 mrg result = read_1u (op_ptr); 596 1.1 mrg op_ptr += 1; 597 1.1 mrg break; 598 1.1 mrg case DW_OP_const1s: 599 1.1 mrg result = read_1s (op_ptr); 600 1.1 mrg op_ptr += 1; 601 1.1 mrg break; 602 1.1 mrg case DW_OP_const2u: 603 1.1 mrg result = read_2u (op_ptr); 604 1.1 mrg op_ptr += 2; 605 1.1 mrg break; 606 1.1 mrg case DW_OP_const2s: 607 1.1 mrg result = read_2s (op_ptr); 608 1.1 mrg op_ptr += 2; 609 1.1 mrg break; 610 1.1 mrg case DW_OP_const4u: 611 1.1 mrg result = read_4u (op_ptr); 612 1.1 mrg op_ptr += 4; 613 1.1 mrg break; 614 1.1 mrg case DW_OP_const4s: 615 1.1 mrg result = read_4s (op_ptr); 616 1.1 mrg op_ptr += 4; 617 1.1 mrg break; 618 1.1 mrg case DW_OP_const8u: 619 1.1 mrg result = read_8u (op_ptr); 620 1.1 mrg op_ptr += 8; 621 1.1 mrg break; 622 1.1 mrg case DW_OP_const8s: 623 1.1 mrg result = read_8s (op_ptr); 624 1.1 mrg op_ptr += 8; 625 1.1 mrg break; 626 1.1 mrg case DW_OP_constu: 627 1.1 mrg op_ptr = read_uleb128 (op_ptr, &utmp); 628 1.1 mrg result = (_Unwind_Word)utmp; 629 1.1 mrg break; 630 1.1 mrg case DW_OP_consts: 631 1.1 mrg op_ptr = read_sleb128 (op_ptr, &stmp); 632 1.1 mrg result = (_Unwind_Sword)stmp; 633 1.1 mrg break; 634 1.1 mrg 635 1.1 mrg case DW_OP_reg0: 636 1.1 mrg case DW_OP_reg1: 637 1.1 mrg case DW_OP_reg2: 638 1.1 mrg case DW_OP_reg3: 639 1.1 mrg case DW_OP_reg4: 640 1.1 mrg case DW_OP_reg5: 641 1.1 mrg case DW_OP_reg6: 642 1.1 mrg case DW_OP_reg7: 643 1.1 mrg case DW_OP_reg8: 644 1.1 mrg case DW_OP_reg9: 645 1.1 mrg case DW_OP_reg10: 646 1.1 mrg case DW_OP_reg11: 647 1.1 mrg case DW_OP_reg12: 648 1.1 mrg case DW_OP_reg13: 649 1.1 mrg case DW_OP_reg14: 650 1.1 mrg case DW_OP_reg15: 651 1.1 mrg case DW_OP_reg16: 652 1.1 mrg case DW_OP_reg17: 653 1.1 mrg case DW_OP_reg18: 654 1.1 mrg case DW_OP_reg19: 655 1.1 mrg case DW_OP_reg20: 656 1.1 mrg case DW_OP_reg21: 657 1.1 mrg case DW_OP_reg22: 658 1.1 mrg case DW_OP_reg23: 659 1.1 mrg case DW_OP_reg24: 660 1.1 mrg case DW_OP_reg25: 661 1.1 mrg case DW_OP_reg26: 662 1.1 mrg case DW_OP_reg27: 663 1.1 mrg case DW_OP_reg28: 664 1.1 mrg case DW_OP_reg29: 665 1.1 mrg case DW_OP_reg30: 666 1.1 mrg case DW_OP_reg31: 667 1.1 mrg result = _Unwind_GetGR (context, op - DW_OP_reg0); 668 1.1 mrg break; 669 1.1 mrg case DW_OP_regx: 670 1.1 mrg op_ptr = read_uleb128 (op_ptr, ®); 671 1.1 mrg result = _Unwind_GetGR (context, reg); 672 1.1 mrg break; 673 1.1 mrg 674 1.1 mrg case DW_OP_breg0: 675 1.1 mrg case DW_OP_breg1: 676 1.1 mrg case DW_OP_breg2: 677 1.1 mrg case DW_OP_breg3: 678 1.1 mrg case DW_OP_breg4: 679 1.1 mrg case DW_OP_breg5: 680 1.1 mrg case DW_OP_breg6: 681 1.1 mrg case DW_OP_breg7: 682 1.1 mrg case DW_OP_breg8: 683 1.1 mrg case DW_OP_breg9: 684 1.1 mrg case DW_OP_breg10: 685 1.1 mrg case DW_OP_breg11: 686 1.1 mrg case DW_OP_breg12: 687 1.1 mrg case DW_OP_breg13: 688 1.1 mrg case DW_OP_breg14: 689 1.1 mrg case DW_OP_breg15: 690 1.1 mrg case DW_OP_breg16: 691 1.1 mrg case DW_OP_breg17: 692 1.1 mrg case DW_OP_breg18: 693 1.1 mrg case DW_OP_breg19: 694 1.1 mrg case DW_OP_breg20: 695 1.1 mrg case DW_OP_breg21: 696 1.1 mrg case DW_OP_breg22: 697 1.1 mrg case DW_OP_breg23: 698 1.1 mrg case DW_OP_breg24: 699 1.1 mrg case DW_OP_breg25: 700 1.1 mrg case DW_OP_breg26: 701 1.1 mrg case DW_OP_breg27: 702 1.1 mrg case DW_OP_breg28: 703 1.1 mrg case DW_OP_breg29: 704 1.1 mrg case DW_OP_breg30: 705 1.1 mrg case DW_OP_breg31: 706 1.1 mrg op_ptr = read_sleb128 (op_ptr, &offset); 707 1.1 mrg result = _Unwind_GetGR (context, op - DW_OP_breg0) + offset; 708 1.1 mrg break; 709 1.1 mrg case DW_OP_bregx: 710 1.1 mrg op_ptr = read_uleb128 (op_ptr, ®); 711 1.1 mrg op_ptr = read_sleb128 (op_ptr, &offset); 712 1.1 mrg result = _Unwind_GetGR (context, reg) + (_Unwind_Word)offset; 713 1.1 mrg break; 714 1.1 mrg 715 1.1 mrg case DW_OP_dup: 716 1.1 mrg gcc_assert (stack_elt); 717 1.1 mrg result = stack[stack_elt - 1]; 718 1.1 mrg break; 719 1.1 mrg 720 1.1 mrg case DW_OP_drop: 721 1.1 mrg gcc_assert (stack_elt); 722 1.1 mrg stack_elt -= 1; 723 1.1 mrg goto no_push; 724 1.1 mrg 725 1.1 mrg case DW_OP_pick: 726 1.1 mrg offset = *op_ptr++; 727 1.1 mrg gcc_assert (offset < stack_elt - 1); 728 1.1 mrg result = stack[stack_elt - 1 - offset]; 729 1.1 mrg break; 730 1.1 mrg 731 1.1 mrg case DW_OP_over: 732 1.1 mrg gcc_assert (stack_elt >= 2); 733 1.1 mrg result = stack[stack_elt - 2]; 734 1.1 mrg break; 735 1.1 mrg 736 1.1 mrg case DW_OP_swap: 737 1.1 mrg { 738 1.1 mrg _Unwind_Word t; 739 1.1 mrg gcc_assert (stack_elt >= 2); 740 1.1 mrg t = stack[stack_elt - 1]; 741 1.1 mrg stack[stack_elt - 1] = stack[stack_elt - 2]; 742 1.1 mrg stack[stack_elt - 2] = t; 743 1.1 mrg goto no_push; 744 1.1 mrg } 745 1.1 mrg 746 1.1 mrg case DW_OP_rot: 747 1.1 mrg { 748 1.1 mrg _Unwind_Word t1, t2, t3; 749 1.1 mrg 750 1.1 mrg gcc_assert (stack_elt >= 3); 751 1.1 mrg t1 = stack[stack_elt - 1]; 752 1.1 mrg t2 = stack[stack_elt - 2]; 753 1.1 mrg t3 = stack[stack_elt - 3]; 754 1.1 mrg stack[stack_elt - 1] = t2; 755 1.1 mrg stack[stack_elt - 2] = t3; 756 1.1 mrg stack[stack_elt - 3] = t1; 757 1.1 mrg goto no_push; 758 1.1 mrg } 759 1.1 mrg 760 1.1 mrg case DW_OP_deref: 761 1.1 mrg case DW_OP_deref_size: 762 1.1 mrg case DW_OP_abs: 763 1.1 mrg case DW_OP_neg: 764 1.1 mrg case DW_OP_not: 765 1.1 mrg case DW_OP_plus_uconst: 766 1.1 mrg /* Unary operations. */ 767 1.1 mrg gcc_assert (stack_elt); 768 1.1 mrg stack_elt -= 1; 769 1.1 mrg 770 1.1 mrg result = stack[stack_elt]; 771 1.1 mrg 772 1.1 mrg switch (op) 773 1.1 mrg { 774 1.1 mrg case DW_OP_deref: 775 1.1 mrg { 776 1.1 mrg void *ptr = (void *) (_Unwind_Ptr) result; 777 1.1 mrg result = (_Unwind_Ptr) read_pointer (ptr); 778 1.1 mrg } 779 1.1 mrg break; 780 1.1 mrg 781 1.1 mrg case DW_OP_deref_size: 782 1.1 mrg { 783 1.1 mrg void *ptr = (void *) (_Unwind_Ptr) result; 784 1.1 mrg switch (*op_ptr++) 785 1.1 mrg { 786 1.1 mrg case 1: 787 1.1 mrg result = read_1u (ptr); 788 1.1 mrg break; 789 1.1 mrg case 2: 790 1.1 mrg result = read_2u (ptr); 791 1.1 mrg break; 792 1.1 mrg case 4: 793 1.1 mrg result = read_4u (ptr); 794 1.1 mrg break; 795 1.1 mrg case 8: 796 1.1 mrg result = read_8u (ptr); 797 1.1 mrg break; 798 1.1 mrg default: 799 1.1 mrg gcc_unreachable (); 800 1.1 mrg } 801 1.1 mrg } 802 1.1 mrg break; 803 1.1 mrg 804 1.1 mrg case DW_OP_abs: 805 1.1 mrg if ((_Unwind_Sword) result < 0) 806 1.1 mrg result = -result; 807 1.1 mrg break; 808 1.1 mrg case DW_OP_neg: 809 1.1 mrg result = -result; 810 1.1 mrg break; 811 1.1 mrg case DW_OP_not: 812 1.1 mrg result = ~result; 813 1.1 mrg break; 814 1.1 mrg case DW_OP_plus_uconst: 815 1.1 mrg op_ptr = read_uleb128 (op_ptr, &utmp); 816 1.1 mrg result += (_Unwind_Word)utmp; 817 1.1 mrg break; 818 1.1 mrg 819 1.1 mrg default: 820 1.1 mrg gcc_unreachable (); 821 1.1 mrg } 822 1.1 mrg break; 823 1.1 mrg 824 1.1 mrg case DW_OP_and: 825 1.1 mrg case DW_OP_div: 826 1.1 mrg case DW_OP_minus: 827 1.1 mrg case DW_OP_mod: 828 1.1 mrg case DW_OP_mul: 829 1.1 mrg case DW_OP_or: 830 1.1 mrg case DW_OP_plus: 831 1.1 mrg case DW_OP_shl: 832 1.1 mrg case DW_OP_shr: 833 1.1 mrg case DW_OP_shra: 834 1.1 mrg case DW_OP_xor: 835 1.1 mrg case DW_OP_le: 836 1.1 mrg case DW_OP_ge: 837 1.1 mrg case DW_OP_eq: 838 1.1 mrg case DW_OP_lt: 839 1.1 mrg case DW_OP_gt: 840 1.1 mrg case DW_OP_ne: 841 1.1 mrg { 842 1.1 mrg /* Binary operations. */ 843 1.1 mrg _Unwind_Word first, second; 844 1.1 mrg gcc_assert (stack_elt >= 2); 845 1.1 mrg stack_elt -= 2; 846 1.1 mrg 847 1.1 mrg second = stack[stack_elt]; 848 1.1 mrg first = stack[stack_elt + 1]; 849 1.1 mrg 850 1.1 mrg switch (op) 851 1.1 mrg { 852 1.1 mrg case DW_OP_and: 853 1.1 mrg result = second & first; 854 1.1 mrg break; 855 1.1 mrg case DW_OP_div: 856 1.1 mrg result = (_Unwind_Sword) second / (_Unwind_Sword) first; 857 1.1 mrg break; 858 1.1 mrg case DW_OP_minus: 859 1.1 mrg result = second - first; 860 1.1 mrg break; 861 1.1 mrg case DW_OP_mod: 862 1.1 mrg result = second % first; 863 1.1 mrg break; 864 1.1 mrg case DW_OP_mul: 865 1.1 mrg result = second * first; 866 1.1 mrg break; 867 1.1 mrg case DW_OP_or: 868 1.1 mrg result = second | first; 869 1.1 mrg break; 870 1.1 mrg case DW_OP_plus: 871 1.1 mrg result = second + first; 872 1.1 mrg break; 873 1.1 mrg case DW_OP_shl: 874 1.1 mrg result = second << first; 875 1.1 mrg break; 876 1.1 mrg case DW_OP_shr: 877 1.1 mrg result = second >> first; 878 1.1 mrg break; 879 1.1 mrg case DW_OP_shra: 880 1.1 mrg result = (_Unwind_Sword) second >> first; 881 1.1 mrg break; 882 1.1 mrg case DW_OP_xor: 883 1.1 mrg result = second ^ first; 884 1.1 mrg break; 885 1.1 mrg case DW_OP_le: 886 1.1 mrg result = (_Unwind_Sword) second <= (_Unwind_Sword) first; 887 1.1 mrg break; 888 1.1 mrg case DW_OP_ge: 889 1.1 mrg result = (_Unwind_Sword) second >= (_Unwind_Sword) first; 890 1.1 mrg break; 891 1.1 mrg case DW_OP_eq: 892 1.1 mrg result = (_Unwind_Sword) second == (_Unwind_Sword) first; 893 1.1 mrg break; 894 1.1 mrg case DW_OP_lt: 895 1.1 mrg result = (_Unwind_Sword) second < (_Unwind_Sword) first; 896 1.1 mrg break; 897 1.1 mrg case DW_OP_gt: 898 1.1 mrg result = (_Unwind_Sword) second > (_Unwind_Sword) first; 899 1.1 mrg break; 900 1.1 mrg case DW_OP_ne: 901 1.1 mrg result = (_Unwind_Sword) second != (_Unwind_Sword) first; 902 1.1 mrg break; 903 1.1 mrg 904 1.1 mrg default: 905 1.1 mrg gcc_unreachable (); 906 1.1 mrg } 907 1.1 mrg } 908 1.1 mrg break; 909 1.1 mrg 910 1.1 mrg case DW_OP_skip: 911 1.1 mrg offset = read_2s (op_ptr); 912 1.1 mrg op_ptr += 2; 913 1.1 mrg op_ptr += offset; 914 1.1 mrg goto no_push; 915 1.1 mrg 916 1.1 mrg case DW_OP_bra: 917 1.1 mrg gcc_assert (stack_elt); 918 1.1 mrg stack_elt -= 1; 919 1.1 mrg 920 1.1 mrg offset = read_2s (op_ptr); 921 1.1 mrg op_ptr += 2; 922 1.1 mrg if (stack[stack_elt] != 0) 923 1.1 mrg op_ptr += offset; 924 1.1 mrg goto no_push; 925 1.1 mrg 926 1.1 mrg case DW_OP_nop: 927 1.1 mrg goto no_push; 928 1.1 mrg 929 1.1 mrg default: 930 1.1 mrg gcc_unreachable (); 931 1.1 mrg } 932 1.1 mrg 933 1.1 mrg /* Most things push a result value. */ 934 1.1 mrg gcc_assert ((size_t) stack_elt < sizeof(stack)/sizeof(*stack)); 935 1.1 mrg stack[stack_elt++] = result; 936 1.1 mrg no_push:; 937 1.1 mrg } 938 1.1 mrg 939 1.1 mrg /* We were executing this program to get a value. It should be 940 1.1 mrg at top of stack. */ 941 1.1 mrg gcc_assert (stack_elt); 942 1.1 mrg stack_elt -= 1; 943 1.1 mrg return stack[stack_elt]; 944 1.1 mrg } 945 1.1 mrg 946 1.1 mrg 947 1.11 mrg /* Decode DWARF 2 call frame information. Takes pointers the 948 1.11 mrg instruction sequence to decode, current register information and 949 1.11 mrg CIE info, and the PC range to evaluate. */ 950 1.11 mrg 951 1.11 mrg static void __attribute__ ((__noinline__)) 952 1.11 mrg execute_cfa_program_generic (const unsigned char *insn_ptr, 953 1.11 mrg const unsigned char *insn_end, 954 1.11 mrg struct _Unwind_Context *context, 955 1.11 mrg _Unwind_FrameState *fs) 956 1.11 mrg { 957 1.11 mrg #define DATA_ALIGN fs->data_align 958 1.11 mrg #define CODE_ALIGN fs->code_align 959 1.11 mrg #include "unwind-dw2-execute_cfa.h" 960 1.11 mrg } 961 1.11 mrg 962 1.11 mrg static inline void 963 1.11 mrg execute_cfa_program_specialized (const unsigned char *insn_ptr, 964 1.11 mrg const unsigned char *insn_end, 965 1.11 mrg struct _Unwind_Context *context, 966 1.11 mrg _Unwind_FrameState *fs) 967 1.11 mrg { 968 1.11 mrg #define DATA_ALIGN __LIBGCC_DWARF_CIE_DATA_ALIGNMENT__ 969 1.11 mrg /* GCC always uses 1 even on architectures with a fixed instruction 970 1.11 mrg width. */ 971 1.1 mrg #define CODE_ALIGN 1 972 1.1 mrg #include "unwind-dw2-execute_cfa.h" 973 1.1 mrg } 974 1.1 mrg 975 1.1 mrg static void 976 1.1 mrg execute_cfa_program (const unsigned char *insn_ptr, 977 1.11 mrg const unsigned char *insn_end, 978 1.11 mrg struct _Unwind_Context *context, 979 1.11 mrg _Unwind_FrameState *fs) 980 1.11 mrg { 981 1.11 mrg if (fs->data_align == __LIBGCC_DWARF_CIE_DATA_ALIGNMENT__ 982 1.11 mrg && fs->code_align == 1) 983 1.1 mrg execute_cfa_program_specialized (insn_ptr, insn_end, context, fs); 984 1.1 mrg else 985 1.1 mrg execute_cfa_program_generic (insn_ptr, insn_end, context, fs); 986 1.1 mrg } 987 1.1 mrg 988 1.1 mrg 989 1.1 mrg /* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for 991 1.1 mrg its caller and decode it into FS. This function also sets the 992 1.1 mrg args_size and lsda members of CONTEXT, as they are really information 993 1.1 mrg about the caller's frame. */ 994 1.1 mrg 995 1.1 mrg static _Unwind_Reason_Code 996 1.1 mrg uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs) 997 1.11 mrg { 998 1.11 mrg const struct dwarf_fde *fde; 999 1.1 mrg const struct dwarf_cie *cie; 1000 1.1 mrg const unsigned char *aug, *insn, *end; 1001 1.1 mrg 1002 1.1 mrg memset (&fs->regs.how[0], 0, 1003 1.1 mrg sizeof (*fs) - offsetof (_Unwind_FrameState, regs.how[0])); 1004 1.1 mrg context->args_size = 0; 1005 1.1 mrg context->lsda = 0; 1006 1.1 mrg 1007 1.1 mrg if (context->ra == 0) 1008 1.1 mrg return _URC_END_OF_STACK; 1009 1.1 mrg 1010 1.1 mrg fde = _Unwind_Find_FDE (context->ra + _Unwind_IsSignalFrame (context) - 1, 1011 1.1 mrg &context->bases); 1012 1.1 mrg if (fde == NULL) 1013 1.1 mrg { 1014 1.1 mrg #ifdef MD_FALLBACK_FRAME_STATE_FOR 1015 1.1 mrg /* Couldn't find frame unwind info for this function. Try a 1016 1.1 mrg target-specific fallback mechanism. This will necessarily 1017 1.1 mrg not provide a personality routine or LSDA. */ 1018 1.1 mrg return MD_FALLBACK_FRAME_STATE_FOR (context, fs); 1019 1.1 mrg #else 1020 1.1 mrg return _URC_END_OF_STACK; 1021 1.1 mrg #endif 1022 1.1 mrg } 1023 1.1 mrg 1024 1.1 mrg fs->pc = context->bases.func; 1025 1.1 mrg 1026 1.1 mrg cie = get_cie (fde); 1027 1.1 mrg insn = extract_cie_info (cie, context, fs); 1028 1.1 mrg if (insn == NULL) 1029 1.1 mrg /* CIE contained unknown augmentation. */ 1030 1.1 mrg return _URC_FATAL_PHASE1_ERROR; 1031 1.1 mrg 1032 1.1 mrg /* First decode all the insns in the CIE. */ 1033 1.1 mrg end = (const unsigned char *) next_fde ((const struct dwarf_fde *) cie); 1034 1.1 mrg execute_cfa_program (insn, end, context, fs); 1035 1.1 mrg 1036 1.1 mrg /* Locate augmentation for the fde. */ 1037 1.1 mrg aug = (const unsigned char *) fde + sizeof (*fde); 1038 1.1 mrg aug += 2 * size_of_encoded_value (fs->fde_encoding); 1039 1.1 mrg insn = NULL; 1040 1.1 mrg if (fs->saw_z) 1041 1.1 mrg { 1042 1.1 mrg _uleb128_t i; 1043 1.1 mrg aug = read_uleb128 (aug, &i); 1044 1.1 mrg insn = aug + i; 1045 1.1 mrg } 1046 1.1 mrg if (fs->lsda_encoding != DW_EH_PE_omit) 1047 1.1 mrg { 1048 1.1 mrg _Unwind_Ptr lsda; 1049 1.1 mrg 1050 1.1 mrg aug = read_encoded_value (context, fs->lsda_encoding, aug, &lsda); 1051 1.1 mrg context->lsda = (void *) lsda; 1052 1.1 mrg } 1053 1.1 mrg 1054 1.1 mrg /* Then the insns in the FDE up to our target PC. */ 1055 1.1 mrg if (insn == NULL) 1056 1.1 mrg insn = aug; 1057 1.1 mrg end = (const unsigned char *) next_fde (fde); 1058 1.1 mrg execute_cfa_program (insn, end, context, fs); 1059 1.1 mrg 1060 1.1 mrg return _URC_NO_REASON; 1061 1.1 mrg } 1062 1.1 mrg 1063 1.1 mrg typedef struct frame_state 1065 1.1 mrg { 1066 1.1 mrg void *cfa; 1067 1.1 mrg void *eh_ptr; 1068 1.1 mrg long cfa_offset; 1069 1.1 mrg long args_size; 1070 1.1 mrg long reg_or_offset[PRE_GCC3_DWARF_FRAME_REGISTERS+1]; 1071 1.1 mrg unsigned short cfa_reg; 1072 1.1 mrg unsigned short retaddr_column; 1073 1.1 mrg char saved[PRE_GCC3_DWARF_FRAME_REGISTERS+1]; 1074 1.1 mrg } frame_state; 1075 1.1 mrg 1076 1.1 mrg struct frame_state * __frame_state_for (void *, struct frame_state *); 1077 1.1 mrg 1078 1.1 mrg /* Called from pre-G++ 3.0 __throw to find the registers to restore for 1079 1.1 mrg a given PC_TARGET. The caller should allocate a local variable of 1080 1.1 mrg `struct frame_state' and pass its address to STATE_IN. */ 1081 1.1 mrg 1082 1.1 mrg struct frame_state * 1083 1.1 mrg __frame_state_for (void *pc_target, struct frame_state *state_in) 1084 1.1 mrg { 1085 1.1 mrg struct _Unwind_Context context; 1086 1.1 mrg _Unwind_FrameState fs; 1087 1.1 mrg int reg; 1088 1.1 mrg 1089 1.1 mrg memset (&context, 0, sizeof (struct _Unwind_Context)); 1090 1.1 mrg if (!ASSUME_EXTENDED_UNWIND_CONTEXT) 1091 1.1 mrg context.flags = EXTENDED_CONTEXT_BIT; 1092 1.1 mrg context.ra = pc_target + 1; 1093 1.1 mrg 1094 1.1 mrg if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON) 1095 1.1 mrg return 0; 1096 1.1 mrg 1097 1.1 mrg /* We have no way to pass a location expression for the CFA to our 1098 1.11 mrg caller. It wouldn't understand it anyway. */ 1099 1.1 mrg if (fs.regs.cfa_how == CFA_EXP) 1100 1.1 mrg return 0; 1101 1.1 mrg 1102 1.1 mrg for (reg = 0; reg < PRE_GCC3_DWARF_FRAME_REGISTERS + 1; reg++) 1103 1.1 mrg { 1104 1.1 mrg state_in->saved[reg] = fs.regs.how[reg]; 1105 1.1 mrg switch (state_in->saved[reg]) 1106 1.1 mrg { 1107 1.1 mrg case REG_SAVED_REG: 1108 1.1 mrg state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.reg; 1109 1.1 mrg break; 1110 1.1 mrg case REG_SAVED_OFFSET: 1111 1.1 mrg state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.offset; 1112 1.1 mrg break; 1113 1.1 mrg default: 1114 1.1 mrg state_in->reg_or_offset[reg] = 0; 1115 1.1 mrg break; 1116 1.1 mrg } 1117 1.1 mrg } 1118 1.1 mrg 1119 1.1 mrg state_in->cfa_offset = fs.regs.cfa_offset; 1120 1.1 mrg state_in->cfa_reg = fs.regs.cfa_reg; 1121 1.1 mrg state_in->retaddr_column = fs.retaddr_column; 1122 1.1 mrg state_in->args_size = context.args_size; 1123 1.1 mrg state_in->eh_ptr = fs.eh_ptr; 1124 1.1 mrg 1125 1.1 mrg return state_in; 1126 1.1 mrg } 1127 1.1 mrg 1128 1.1 mrg typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp; 1130 1.1 mrg 1131 1.1 mrg static inline void 1132 1.1 mrg _Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa, 1133 1.1 mrg _Unwind_SpTmp *tmp_sp) 1134 1.1 mrg { 1135 1.1 mrg int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()]; 1136 1.1 mrg 1137 1.1 mrg if (size == sizeof(_Unwind_Ptr)) 1138 1.1 mrg tmp_sp->ptr = (_Unwind_Ptr) cfa; 1139 1.1 mrg else 1140 1.1 mrg { 1141 1.1 mrg gcc_assert (size == sizeof(_Unwind_Word)); 1142 1.1 mrg tmp_sp->word = (_Unwind_Ptr) cfa; 1143 1.1 mrg } 1144 1.1 mrg _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp); 1145 1.1 mrg } 1146 1.1 mrg 1147 1.4 mrg static void 1148 1.1 mrg uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs) 1149 1.1 mrg { 1150 1.1 mrg struct _Unwind_Context orig_context = *context; 1151 1.1 mrg void *cfa; 1152 1.1 mrg long i; 1153 1.1 mrg 1154 1.1 mrg #ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__ 1155 1.1 mrg /* Special handling here: Many machines do not use a frame pointer, 1156 1.1 mrg and track the CFA only through offsets from the stack pointer from 1157 1.1 mrg one frame to the next. In this case, the stack pointer is never 1158 1.1 mrg stored, so it has no saved address in the context. What we do 1159 1.1 mrg have is the CFA from the previous stack frame. 1160 1.1 mrg 1161 1.1 mrg In very special situations (such as unwind info for signal return), 1162 1.1 mrg there may be location expressions that use the stack pointer as well. 1163 1.1 mrg 1164 1.1 mrg Do this conditionally for one frame. This allows the unwind info 1165 1.1 mrg for one frame to save a copy of the stack pointer from the previous 1166 1.1 mrg frame, and be able to use much easier CFA mechanisms to do it. 1167 1.1 mrg Always zap the saved stack pointer value for the next frame; carrying 1168 1.1 mrg the value over from one frame to another doesn't make sense. */ 1169 1.1 mrg 1170 1.1 mrg _Unwind_SpTmp tmp_sp; 1171 1.1 mrg 1172 1.1 mrg if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ())) 1173 1.1 mrg _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp); 1174 1.1 mrg _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL); 1175 1.1 mrg #endif 1176 1.1 mrg 1177 1.1 mrg /* Compute this frame's CFA. */ 1178 1.1 mrg switch (fs->regs.cfa_how) 1179 1.1 mrg { 1180 1.1 mrg case CFA_REG_OFFSET: 1181 1.1 mrg cfa = _Unwind_GetPtr (&orig_context, fs->regs.cfa_reg); 1182 1.1 mrg cfa += fs->regs.cfa_offset; 1183 1.1 mrg break; 1184 1.1 mrg 1185 1.1 mrg case CFA_EXP: 1186 1.1 mrg { 1187 1.1 mrg const unsigned char *exp = fs->regs.cfa_exp; 1188 1.1 mrg _uleb128_t len; 1189 1.1 mrg 1190 1.1 mrg exp = read_uleb128 (exp, &len); 1191 1.1 mrg cfa = (void *) (_Unwind_Ptr) 1192 1.1 mrg execute_stack_op (exp, exp + len, &orig_context, 0); 1193 1.1 mrg break; 1194 1.1 mrg } 1195 1.4 mrg 1196 1.11 mrg default: 1197 1.1 mrg gcc_unreachable (); 1198 1.1 mrg } 1199 1.1 mrg context->cfa = cfa; 1200 1.11 mrg 1201 1.1 mrg /* Compute the addresses of all registers saved in this frame. */ 1202 1.1 mrg for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__ + 1; ++i) 1203 1.1 mrg switch (fs->regs.how[i]) 1204 1.1 mrg { 1205 1.1 mrg case REG_UNSAVED: 1206 1.1 mrg case REG_UNDEFINED: 1207 1.1 mrg case REG_UNSAVED_ARCHEXT: 1208 1.1 mrg break; 1209 1.1 mrg 1210 1.1 mrg case REG_SAVED_OFFSET: 1211 1.1 mrg _Unwind_SetGRPtr (context, i, 1212 1.1 mrg (void *) (cfa + fs->regs.reg[i].loc.offset)); 1213 1.1 mrg break; 1214 1.1 mrg 1215 1.1 mrg case REG_SAVED_REG: 1216 1.1 mrg if (_Unwind_GRByValue (&orig_context, fs->regs.reg[i].loc.reg)) 1217 1.1 mrg _Unwind_SetGRValue (context, i, 1218 1.1 mrg _Unwind_GetGR (&orig_context, 1219 1.1 mrg fs->regs.reg[i].loc.reg)); 1220 1.1 mrg else 1221 1.1 mrg _Unwind_SetGRPtr (context, i, 1222 1.1 mrg _Unwind_GetGRPtr (&orig_context, 1223 1.1 mrg fs->regs.reg[i].loc.reg)); 1224 1.1 mrg break; 1225 1.1 mrg 1226 1.1 mrg case REG_SAVED_EXP: 1227 1.1 mrg { 1228 1.1 mrg const unsigned char *exp = fs->regs.reg[i].loc.exp; 1229 1.1 mrg _uleb128_t len; 1230 1.1 mrg _Unwind_Ptr val; 1231 1.1 mrg 1232 1.1 mrg exp = read_uleb128 (exp, &len); 1233 1.1 mrg val = execute_stack_op (exp, exp + len, &orig_context, 1234 1.1 mrg (_Unwind_Ptr) cfa); 1235 1.1 mrg _Unwind_SetGRPtr (context, i, (void *) val); 1236 1.1 mrg } 1237 1.1 mrg break; 1238 1.1 mrg 1239 1.1 mrg case REG_SAVED_VAL_OFFSET: 1240 1.1 mrg _Unwind_SetGRValue (context, i, 1241 1.1 mrg (_Unwind_Internal_Ptr) 1242 1.1 mrg (cfa + fs->regs.reg[i].loc.offset)); 1243 1.1 mrg break; 1244 1.1 mrg 1245 1.1 mrg case REG_SAVED_VAL_EXP: 1246 1.1 mrg { 1247 1.1 mrg const unsigned char *exp = fs->regs.reg[i].loc.exp; 1248 1.1 mrg _uleb128_t len; 1249 1.1 mrg _Unwind_Ptr val; 1250 1.1 mrg 1251 1.1 mrg exp = read_uleb128 (exp, &len); 1252 1.1 mrg val = execute_stack_op (exp, exp + len, &orig_context, 1253 1.1 mrg (_Unwind_Ptr) cfa); 1254 1.1 mrg _Unwind_SetGRValue (context, i, val); 1255 1.1 mrg } 1256 1.1 mrg break; 1257 1.1 mrg } 1258 1.1 mrg 1259 1.1 mrg _Unwind_SetSignalFrame (context, fs->signal_frame); 1260 1.1 mrg 1261 1.1 mrg #ifdef MD_FROB_UPDATE_CONTEXT 1262 1.1 mrg MD_FROB_UPDATE_CONTEXT (context, fs); 1263 1.1 mrg #endif 1264 1.1 mrg } 1265 1.1 mrg 1266 1.1 mrg /* CONTEXT describes the unwind state for a frame, and FS describes the FDE 1267 1.1 mrg of its caller. Update CONTEXT to refer to the caller as well. Note 1268 1.1 mrg that the args_size and lsda members are not updated here, but later in 1269 1.1 mrg uw_frame_state_for. */ 1270 1.1 mrg 1271 1.1 mrg static void 1272 1.1 mrg uw_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs) 1273 1.1 mrg { 1274 1.1 mrg uw_update_context_1 (context, fs); 1275 1.11 mrg 1276 1.1 mrg /* In general this unwinder doesn't make any distinction between 1277 1.1 mrg undefined and same_value rule. Call-saved registers are assumed 1278 1.1 mrg to have same_value rule by default and explicit undefined 1279 1.1 mrg rule is handled like same_value. The only exception is 1280 1.1 mrg DW_CFA_undefined on retaddr_column which is supposed to 1281 1.6 mrg mark outermost frame in DWARF 3. */ 1282 1.6 mrg if (fs->regs.how[DWARF_REG_TO_UNWIND_COLUMN (fs->retaddr_column)] 1283 1.6 mrg == REG_UNDEFINED) 1284 1.9 mrg /* uw_frame_state_for uses context->ra == 0 check to find outermost 1285 1.9 mrg stack frame. */ 1286 1.9 mrg context->ra = 0; 1287 1.9 mrg else 1288 1.9 mrg { 1289 1.9 mrg /* Compute the return address now, since the return address column 1290 1.6 mrg can change from frame to frame. */ 1291 1.9 mrg void *ret_addr; 1292 1.6 mrg #ifdef MD_DEMANGLE_RETURN_ADDR 1293 1.1 mrg _Unwind_Word ra = _Unwind_GetGR (context, fs->retaddr_column); 1294 1.1 mrg ret_addr = MD_DEMANGLE_RETURN_ADDR (context, fs, ra); 1295 1.1 mrg #else 1296 1.1 mrg ret_addr = _Unwind_GetPtr (context, fs->retaddr_column); 1297 1.1 mrg #endif 1298 1.1 mrg context->ra = __builtin_extract_return_addr (ret_addr); 1299 1.1 mrg } 1300 1.1 mrg } 1301 1.1 mrg 1302 1.1 mrg static void 1303 1.1 mrg uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs) 1304 1.1 mrg { 1305 1.1 mrg uw_update_context (context, fs); 1306 1.1 mrg } 1307 1.1 mrg 1308 1.1 mrg /* Fill in CONTEXT for top-of-stack. The only valid registers at this 1310 1.1 mrg level will be the return address and the CFA. */ 1311 1.1 mrg 1312 1.1 mrg #define uw_init_context(CONTEXT) \ 1313 1.1 mrg do \ 1314 1.1 mrg { \ 1315 1.1 mrg /* Do any necessary initialization to access arbitrary stack frames. \ 1316 1.1 mrg On the SPARC, this means flushing the register windows. */ \ 1317 1.1 mrg __builtin_unwind_init (); \ 1318 1.1 mrg uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \ 1319 1.1 mrg __builtin_return_address (0)); \ 1320 1.1 mrg } \ 1321 1.1 mrg while (0) 1322 1.1 mrg 1323 1.1 mrg static inline void 1324 1.1 mrg init_dwarf_reg_size_table (void) 1325 1.1 mrg { 1326 1.1 mrg __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table); 1327 1.1 mrg } 1328 1.1 mrg 1329 1.1 mrg static void __attribute__((noinline)) 1330 1.1 mrg uw_init_context_1 (struct _Unwind_Context *context, 1331 1.1 mrg void *outer_cfa, void *outer_ra) 1332 1.1 mrg { 1333 1.1 mrg void *ra = __builtin_extract_return_addr (__builtin_return_address (0)); 1334 1.1 mrg _Unwind_FrameState fs; 1335 1.1 mrg _Unwind_SpTmp sp_slot; 1336 1.1 mrg _Unwind_Reason_Code code; 1337 1.1 mrg 1338 1.1 mrg memset (context, 0, sizeof (struct _Unwind_Context)); 1339 1.1 mrg context->ra = ra; 1340 1.1 mrg if (!ASSUME_EXTENDED_UNWIND_CONTEXT) 1341 1.1 mrg context->flags = EXTENDED_CONTEXT_BIT; 1342 1.1 mrg 1343 1.1 mrg code = uw_frame_state_for (context, &fs); 1344 1.1 mrg gcc_assert (code == _URC_NO_REASON); 1345 1.1 mrg 1346 1.1 mrg #if __GTHREADS 1347 1.1 mrg { 1348 1.1 mrg static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT; 1349 1.1 mrg if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0 1350 1.1 mrg && dwarf_reg_size_table[0] == 0) 1351 1.1 mrg init_dwarf_reg_size_table (); 1352 1.1 mrg } 1353 1.1 mrg #else 1354 1.1 mrg if (dwarf_reg_size_table[0] == 0) 1355 1.1 mrg init_dwarf_reg_size_table (); 1356 1.1 mrg #endif 1357 1.1 mrg 1358 1.1 mrg /* Force the frame state to use the known cfa value. */ 1359 1.1 mrg _Unwind_SetSpColumn (context, outer_cfa, &sp_slot); 1360 1.1 mrg fs.regs.cfa_how = CFA_REG_OFFSET; 1361 1.1 mrg fs.regs.cfa_reg = __builtin_dwarf_sp_column (); 1362 1.1 mrg fs.regs.cfa_offset = 0; 1363 1.1 mrg 1364 1.1 mrg uw_update_context_1 (context, &fs); 1365 1.1 mrg 1366 1.1 mrg /* If the return address column was saved in a register in the 1367 1.1 mrg initialization context, then we can't see it in the given 1368 1.1 mrg call frame data. So have the initialization context tell us. */ 1369 1.1 mrg context->ra = __builtin_extract_return_addr (outer_ra); 1370 1.1 mrg } 1371 1.1 mrg 1372 1.1 mrg static void _Unwind_DebugHook (void *, void *) 1373 1.1 mrg __attribute__ ((__noinline__, __used__, __noclone__)); 1374 1.1 mrg 1375 1.1 mrg /* This function is called during unwinding. It is intended as a hook 1376 1.1 mrg for a debugger to intercept exceptions. CFA is the CFA of the 1377 1.1 mrg target frame. HANDLER is the PC to which control will be 1378 1.1 mrg transferred. */ 1379 1.1 mrg static void 1380 1.1 mrg _Unwind_DebugHook (void *cfa __attribute__ ((__unused__)), 1381 1.1 mrg void *handler __attribute__ ((__unused__))) 1382 1.1 mrg { 1383 1.1 mrg /* We only want to use stap probes starting with v3. Earlier 1384 1.1 mrg versions added too much startup cost. */ 1385 1.1 mrg #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3 1386 1.7 mrg STAP_PROBE2 (libgcc, unwind, cfa, handler); 1387 1.7 mrg #else 1388 1.7 mrg asm (""); 1389 1.7 mrg #endif 1390 1.1 mrg } 1391 1.7 mrg 1392 1.1 mrg /* Install TARGET into CURRENT so that we can return to it. This is a 1393 1.1 mrg macro because __builtin_eh_return must be invoked in the context of 1394 1.1 mrg our caller. FRAMES is a number of frames to be unwind. 1395 1.9 mrg _Unwind_Frames_Extra is a macro to do additional work during unwinding 1396 1.1 mrg if needed, for example shadow stack pointer adjustment for Intel CET 1397 1.7 mrg technology. */ 1398 1.1 mrg 1399 1.1 mrg #define uw_install_context(CURRENT, TARGET, FRAMES) \ 1400 1.1 mrg do \ 1401 1.1 mrg { \ 1402 1.1 mrg long offset = uw_install_context_1 ((CURRENT), (TARGET)); \ 1403 1.1 mrg void *handler = __builtin_frob_return_addr ((TARGET)->ra); \ 1404 1.1 mrg _Unwind_DebugHook ((TARGET)->cfa, handler); \ 1405 1.1 mrg _Unwind_Frames_Extra (FRAMES); \ 1406 1.1 mrg __builtin_eh_return (offset, handler); \ 1407 1.1 mrg } \ 1408 1.1 mrg while (0) 1409 1.1 mrg 1410 1.1 mrg static long 1411 1.1 mrg uw_install_context_1 (struct _Unwind_Context *current, 1412 1.1 mrg struct _Unwind_Context *target) 1413 1.1 mrg { 1414 1.4 mrg long i; 1415 1.1 mrg _Unwind_SpTmp sp_slot; 1416 1.1 mrg 1417 1.1 mrg /* If the target frame does not have a saved stack pointer, 1418 1.1 mrg then set up the target's CFA. */ 1419 1.1 mrg if (!_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ())) 1420 1.1 mrg _Unwind_SetSpColumn (target, target->cfa, &sp_slot); 1421 1.1 mrg 1422 1.1 mrg for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__; ++i) 1423 1.1 mrg { 1424 1.1 mrg void *c = (void *) (_Unwind_Internal_Ptr) current->reg[i]; 1425 1.1 mrg void *t = (void *) (_Unwind_Internal_Ptr)target->reg[i]; 1426 1.1 mrg 1427 1.1 mrg gcc_assert (current->by_value[i] == 0); 1428 1.1 mrg if (target->by_value[i] && c) 1429 1.1 mrg { 1430 1.1 mrg _Unwind_Word w; 1431 1.1 mrg _Unwind_Ptr p; 1432 1.1 mrg if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word)) 1433 1.1 mrg { 1434 1.1 mrg w = (_Unwind_Internal_Ptr) t; 1435 1.1 mrg memcpy (c, &w, sizeof (_Unwind_Word)); 1436 1.1 mrg } 1437 1.1 mrg else 1438 1.1 mrg { 1439 1.1 mrg gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr)); 1440 1.1 mrg p = (_Unwind_Internal_Ptr) t; 1441 1.1 mrg memcpy (c, &p, sizeof (_Unwind_Ptr)); 1442 1.1 mrg } 1443 1.1 mrg } 1444 1.1 mrg else if (t && c && t != c) 1445 1.1 mrg memcpy (c, t, dwarf_reg_size_table[i]); 1446 1.1 mrg } 1447 1.1 mrg 1448 1.1 mrg /* If the current frame doesn't have a saved stack pointer, then we 1449 1.1 mrg need to rely on EH_RETURN_STACKADJ_RTX to get our target stack 1450 1.4 mrg pointer value reloaded. */ 1451 1.1 mrg if (!_Unwind_GetGRPtr (current, __builtin_dwarf_sp_column ())) 1452 1.1 mrg { 1453 1.1 mrg void *target_cfa; 1454 1.1 mrg 1455 1.1 mrg target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ()); 1456 1.1 mrg 1457 1.1 mrg /* We adjust SP by the difference between CURRENT and TARGET's CFA. */ 1458 1.1 mrg if (__LIBGCC_STACK_GROWS_DOWNWARD__) 1459 1.1 mrg return target_cfa - current->cfa + target->args_size; 1460 1.1 mrg else 1461 1.1 mrg return current->cfa - target_cfa - target->args_size; 1462 1.1 mrg } 1463 1.1 mrg return 0; 1464 1.4 mrg } 1465 1.1 mrg 1466 1.1 mrg static inline _Unwind_Ptr 1467 1.1 mrg uw_identify_context (struct _Unwind_Context *context) 1468 1.1 mrg { 1469 1.1 mrg /* The CFA is not sufficient to disambiguate the context of a function 1470 1.1 mrg interrupted by a signal before establishing its frame and the context 1471 1.1 mrg of the signal itself. */ 1472 1.1 mrg if (__LIBGCC_STACK_GROWS_DOWNWARD__) 1473 1.1 mrg return _Unwind_GetCFA (context) - _Unwind_IsSignalFrame (context); 1474 1.1 mrg else 1475 1.1 mrg return _Unwind_GetCFA (context) + _Unwind_IsSignalFrame (context); 1476 1.1 mrg } 1477 1.1 mrg 1478 1.1 mrg 1479 1.1 mrg #include "unwind.inc" 1480 1.1 mrg 1481 1.1 mrg #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS) 1482 1.1 mrg alias (_Unwind_Backtrace); 1483 1.1 mrg alias (_Unwind_DeleteException); 1484 1.1 mrg alias (_Unwind_FindEnclosingFunction); 1485 1.1 mrg alias (_Unwind_ForcedUnwind); 1486 1.1 mrg alias (_Unwind_GetDataRelBase); 1487 1.1 mrg alias (_Unwind_GetTextRelBase); 1488 1.1 mrg alias (_Unwind_GetCFA); 1489 1.1 mrg alias (_Unwind_GetGR); 1490 1.1 mrg alias (_Unwind_GetIP); 1491 1.1 mrg alias (_Unwind_GetLanguageSpecificData); 1492 1.1 mrg alias (_Unwind_GetRegionStart); 1493 alias (_Unwind_RaiseException); 1494 alias (_Unwind_Resume); 1495 alias (_Unwind_Resume_or_Rethrow); 1496 alias (_Unwind_SetGR); 1497 alias (_Unwind_SetIP); 1498 #endif 1499 1500 #endif /* !USING_SJLJ_EXCEPTIONS */ 1501