| 1 | /* dw2gencfi.c - Support for generating Dwarf2 CFI information. |
| 2 | Copyright (C) 2003-2019 Free Software Foundation, Inc. |
| 3 | Contributed by Michal Ludvig <mludvig@suse.cz> |
| 4 | |
| 5 | This file is part of GAS, the GNU Assembler. |
| 6 | |
| 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) |
| 10 | any later version. |
| 11 | |
| 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. |
| 16 | |
| 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 |
| 20 | 02110-1301, USA. */ |
| 21 | |
| 22 | #include "as.h" |
| 23 | #include "dw2gencfi.h" |
| 24 | #include "subsegs.h" |
| 25 | #include "dwarf2dbg.h" |
| 26 | |
| 27 | #ifdef TARGET_USE_CFIPOP |
| 28 | |
| 29 | /* By default, use difference expressions if DIFF_EXPR_OK is defined. */ |
| 30 | #ifndef CFI_DIFF_EXPR_OK |
| 31 | # ifdef DIFF_EXPR_OK |
| 32 | # define CFI_DIFF_EXPR_OK 1 |
| 33 | # else |
| 34 | # define CFI_DIFF_EXPR_OK 0 |
| 35 | # endif |
| 36 | #endif |
| 37 | |
| 38 | #ifndef CFI_DIFF_LSDA_OK |
| 39 | #define CFI_DIFF_LSDA_OK CFI_DIFF_EXPR_OK |
| 40 | #endif |
| 41 | |
| 42 | #if CFI_DIFF_EXPR_OK == 1 && CFI_DIFF_LSDA_OK == 0 |
| 43 | # error "CFI_DIFF_EXPR_OK should imply CFI_DIFF_LSDA_OK" |
| 44 | #endif |
| 45 | |
| 46 | /* We re-use DWARF2_LINE_MIN_INSN_LENGTH for the code alignment field |
| 47 | of the CIE. Default to 1 if not otherwise specified. */ |
| 48 | #ifndef DWARF2_LINE_MIN_INSN_LENGTH |
| 49 | #define DWARF2_LINE_MIN_INSN_LENGTH 1 |
| 50 | #endif |
| 51 | |
| 52 | /* By default, use 32-bit relocations from .eh_frame into .text. */ |
| 53 | #ifndef DWARF2_FDE_RELOC_SIZE |
| 54 | #define DWARF2_FDE_RELOC_SIZE 4 |
| 55 | #endif |
| 56 | |
| 57 | /* By default, use a read-only .eh_frame section. */ |
| 58 | #ifndef DWARF2_EH_FRAME_READ_ONLY |
| 59 | #define DWARF2_EH_FRAME_READ_ONLY SEC_READONLY |
| 60 | #endif |
| 61 | |
| 62 | #ifndef EH_FRAME_ALIGNMENT |
| 63 | #define EH_FRAME_ALIGNMENT (bfd_get_arch_size (stdoutput) == 64 ? 3 : 2) |
| 64 | #endif |
| 65 | |
| 66 | #ifndef tc_cfi_frame_initial_instructions |
| 67 | #define tc_cfi_frame_initial_instructions() ((void)0) |
| 68 | #endif |
| 69 | |
| 70 | #ifndef tc_cfi_startproc |
| 71 | # define tc_cfi_startproc() ((void)0) |
| 72 | #endif |
| 73 | |
| 74 | #ifndef tc_cfi_endproc |
| 75 | # define tc_cfi_endproc(fde) ((void) (fde)) |
| 76 | #endif |
| 77 | |
| 78 | #define EH_FRAME_LINKONCE (SUPPORT_FRAME_LINKONCE || compact_eh) |
| 79 | |
| 80 | #ifndef DWARF2_FORMAT |
| 81 | #define DWARF2_FORMAT(SEC) dwarf2_format_32bit |
| 82 | #endif |
| 83 | |
| 84 | #ifndef DWARF2_ADDR_SIZE |
| 85 | #define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8) |
| 86 | #endif |
| 87 | |
| 88 | #if MULTIPLE_FRAME_SECTIONS |
| 89 | #define CUR_SEG(structp) structp->cur_seg |
| 90 | #define SET_CUR_SEG(structp, seg) structp->cur_seg = seg |
| 91 | #define HANDLED(structp) structp->handled |
| 92 | #define SET_HANDLED(structp, val) structp->handled = val |
| 93 | #else |
| 94 | #define CUR_SEG(structp) NULL |
| 95 | #define SET_CUR_SEG(structp, seg) (void) (0 && seg) |
| 96 | #define HANDLED(structp) 0 |
| 97 | #define SET_HANDLED(structp, val) (void) (0 && val) |
| 98 | #endif |
| 99 | |
| 100 | #ifndef tc_cfi_reloc_for_encoding |
| 101 | #define tc_cfi_reloc_for_encoding(e) BFD_RELOC_NONE |
| 102 | #endif |
| 103 | |
| 104 | /* Private segment collection list. */ |
| 105 | struct dwcfi_seg_list |
| 106 | { |
| 107 | segT seg; |
| 108 | int subseg; |
| 109 | char * seg_name; |
| 110 | }; |
| 111 | |
| 112 | #ifdef SUPPORT_COMPACT_EH |
| 113 | static bfd_boolean compact_eh; |
| 114 | #else |
| 115 | #define compact_eh 0 |
| 116 | #endif |
| 117 | |
| 118 | static struct hash_control *dwcfi_hash; |
| 119 | \f |
| 120 | /* Emit a single byte into the current segment. */ |
| 121 | |
| 122 | static inline void |
| 123 | out_one (int byte) |
| 124 | { |
| 125 | FRAG_APPEND_1_CHAR (byte); |
| 126 | } |
| 127 | |
| 128 | /* Emit a two-byte word into the current segment. */ |
| 129 | |
| 130 | static inline void |
| 131 | out_two (int data) |
| 132 | { |
| 133 | md_number_to_chars (frag_more (2), data, 2); |
| 134 | } |
| 135 | |
| 136 | /* Emit a four byte word into the current segment. */ |
| 137 | |
| 138 | static inline void |
| 139 | out_four (int data) |
| 140 | { |
| 141 | md_number_to_chars (frag_more (4), data, 4); |
| 142 | } |
| 143 | |
| 144 | /* Emit an unsigned "little-endian base 128" number. */ |
| 145 | |
| 146 | static void |
| 147 | out_uleb128 (addressT value) |
| 148 | { |
| 149 | output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0); |
| 150 | } |
| 151 | |
| 152 | /* Emit an unsigned "little-endian base 128" number. */ |
| 153 | |
| 154 | static void |
| 155 | out_sleb128 (offsetT value) |
| 156 | { |
| 157 | output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1); |
| 158 | } |
| 159 | |
| 160 | static unsigned int |
| 161 | encoding_size (unsigned char encoding) |
| 162 | { |
| 163 | if (encoding == DW_EH_PE_omit) |
| 164 | return 0; |
| 165 | switch (encoding & 0x7) |
| 166 | { |
| 167 | case 0: |
| 168 | return bfd_get_arch_size (stdoutput) == 64 ? 8 : 4; |
| 169 | case DW_EH_PE_udata2: |
| 170 | return 2; |
| 171 | case DW_EH_PE_udata4: |
| 172 | return 4; |
| 173 | case DW_EH_PE_udata8: |
| 174 | return 8; |
| 175 | default: |
| 176 | abort (); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /* Emit expression EXP in ENCODING. If EMIT_ENCODING is true, first |
| 181 | emit a byte containing ENCODING. */ |
| 182 | |
| 183 | static void |
| 184 | emit_expr_encoded (expressionS *exp, int encoding, bfd_boolean emit_encoding) |
| 185 | { |
| 186 | unsigned int size = encoding_size (encoding); |
| 187 | bfd_reloc_code_real_type code; |
| 188 | |
| 189 | if (encoding == DW_EH_PE_omit) |
| 190 | return; |
| 191 | |
| 192 | if (emit_encoding) |
| 193 | out_one (encoding); |
| 194 | |
| 195 | code = tc_cfi_reloc_for_encoding (encoding); |
| 196 | if (code != BFD_RELOC_NONE) |
| 197 | { |
| 198 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code); |
| 199 | char *p = frag_more (size); |
| 200 | gas_assert (size == (unsigned) howto->bitsize / 8); |
| 201 | md_number_to_chars (p, 0, size); |
| 202 | fix_new (frag_now, p - frag_now->fr_literal, size, exp->X_add_symbol, |
| 203 | exp->X_add_number, howto->pc_relative, code); |
| 204 | } |
| 205 | else if ((encoding & 0x70) == DW_EH_PE_pcrel) |
| 206 | { |
| 207 | #if CFI_DIFF_EXPR_OK |
| 208 | expressionS tmp = *exp; |
| 209 | tmp.X_op = O_subtract; |
| 210 | tmp.X_op_symbol = symbol_temp_new_now (); |
| 211 | emit_expr (&tmp, size); |
| 212 | #elif defined (tc_cfi_emit_pcrel_expr) |
| 213 | tc_cfi_emit_pcrel_expr (exp, size); |
| 214 | #else |
| 215 | abort (); |
| 216 | #endif |
| 217 | } |
| 218 | else |
| 219 | emit_expr (exp, size); |
| 220 | } |
| 221 | \f |
| 222 | /* Build based on segment the derived .debug_... |
| 223 | segment name containing origin segment's postfix name part. */ |
| 224 | |
| 225 | static char * |
| 226 | get_debugseg_name (segT seg, const char *base_name) |
| 227 | { |
| 228 | const char * name; |
| 229 | const char * dollar; |
| 230 | const char * dot; |
| 231 | |
| 232 | if (!seg) |
| 233 | return concat (base_name, NULL); |
| 234 | |
| 235 | name = bfd_section_name (seg); |
| 236 | |
| 237 | if (name == NULL || *name == 0) |
| 238 | return concat (base_name, NULL); |
| 239 | |
| 240 | dollar = strchr (name, '$'); |
| 241 | dot = strchr (name + 1, '.'); |
| 242 | |
| 243 | if (!dollar && !dot) |
| 244 | { |
| 245 | if (!strcmp (base_name, ".eh_frame_entry") |
| 246 | && strcmp (name, ".text") != 0) |
| 247 | return concat (base_name, ".", name, NULL); |
| 248 | |
| 249 | name = ""; |
| 250 | } |
| 251 | else if (!dollar) |
| 252 | name = dot; |
| 253 | else if (!dot) |
| 254 | name = dollar; |
| 255 | else if (dot < dollar) |
| 256 | name = dot; |
| 257 | else |
| 258 | name = dollar; |
| 259 | |
| 260 | return concat (base_name, name, NULL); |
| 261 | } |
| 262 | |
| 263 | /* Allocate a dwcfi_seg_list structure. */ |
| 264 | |
| 265 | static struct dwcfi_seg_list * |
| 266 | alloc_debugseg_item (segT seg, int subseg, char *name) |
| 267 | { |
| 268 | struct dwcfi_seg_list *r; |
| 269 | |
| 270 | r = (struct dwcfi_seg_list *) |
| 271 | xmalloc (sizeof (struct dwcfi_seg_list) + strlen (name)); |
| 272 | r->seg = seg; |
| 273 | r->subseg = subseg; |
| 274 | r->seg_name = name; |
| 275 | return r; |
| 276 | } |
| 277 | |
| 278 | static segT |
| 279 | is_now_linkonce_segment (void) |
| 280 | { |
| 281 | if (compact_eh) |
| 282 | return now_seg; |
| 283 | |
| 284 | if ((bfd_section_flags (now_seg) |
| 285 | & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD |
| 286 | | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE |
| 287 | | SEC_LINK_DUPLICATES_SAME_CONTENTS)) != 0) |
| 288 | return now_seg; |
| 289 | return NULL; |
| 290 | } |
| 291 | |
| 292 | /* Generate debug... segment with same linkonce properties |
| 293 | of based segment. */ |
| 294 | |
| 295 | static segT |
| 296 | make_debug_seg (segT cseg, char *name, int sflags) |
| 297 | { |
| 298 | segT save_seg = now_seg; |
| 299 | int save_subseg = now_subseg; |
| 300 | segT r; |
| 301 | flagword flags; |
| 302 | |
| 303 | r = subseg_new (name, 0); |
| 304 | |
| 305 | /* Check if code segment is marked as linked once. */ |
| 306 | if (!cseg) |
| 307 | flags = 0; |
| 308 | else |
| 309 | flags = (bfd_section_flags (cseg) |
| 310 | & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD |
| 311 | | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE |
| 312 | | SEC_LINK_DUPLICATES_SAME_CONTENTS)); |
| 313 | |
| 314 | /* Add standard section flags. */ |
| 315 | flags |= sflags; |
| 316 | |
| 317 | /* Apply possibly linked once flags to new generated segment, too. */ |
| 318 | if (!bfd_set_section_flags (r, flags)) |
| 319 | as_bad (_("bfd_set_section_flags: %s"), |
| 320 | bfd_errmsg (bfd_get_error ())); |
| 321 | |
| 322 | /* Restore to previous segment. */ |
| 323 | if (save_seg != NULL) |
| 324 | subseg_set (save_seg, save_subseg); |
| 325 | return r; |
| 326 | } |
| 327 | |
| 328 | static void |
| 329 | dwcfi_hash_insert (const char *name, struct dwcfi_seg_list *item) |
| 330 | { |
| 331 | const char *error_string; |
| 332 | |
| 333 | if ((error_string = hash_jam (dwcfi_hash, name, (char *) item))) |
| 334 | as_fatal (_("Inserting \"%s\" into structure table failed: %s"), |
| 335 | name, error_string); |
| 336 | } |
| 337 | |
| 338 | static struct dwcfi_seg_list * |
| 339 | dwcfi_hash_find (char *name) |
| 340 | { |
| 341 | return (struct dwcfi_seg_list *) hash_find (dwcfi_hash, name); |
| 342 | } |
| 343 | |
| 344 | static struct dwcfi_seg_list * |
| 345 | dwcfi_hash_find_or_make (segT cseg, const char *base_name, int flags) |
| 346 | { |
| 347 | struct dwcfi_seg_list *item; |
| 348 | char *name; |
| 349 | |
| 350 | /* Initialize dwcfi_hash once. */ |
| 351 | if (!dwcfi_hash) |
| 352 | dwcfi_hash = hash_new (); |
| 353 | |
| 354 | name = get_debugseg_name (cseg, base_name); |
| 355 | |
| 356 | item = dwcfi_hash_find (name); |
| 357 | if (!item) |
| 358 | { |
| 359 | item = alloc_debugseg_item (make_debug_seg (cseg, name, flags), 0, name); |
| 360 | |
| 361 | dwcfi_hash_insert (item->seg_name, item); |
| 362 | } |
| 363 | else |
| 364 | free (name); |
| 365 | |
| 366 | return item; |
| 367 | } |
| 368 | |
| 369 | /* ??? Share this with dwarf2cfg.c. */ |
| 370 | #ifndef TC_DWARF2_EMIT_OFFSET |
| 371 | #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset |
| 372 | |
| 373 | /* Create an offset to .dwarf2_*. */ |
| 374 | |
| 375 | static void |
| 376 | generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
| 377 | { |
| 378 | expressionS exp; |
| 379 | |
| 380 | exp.X_op = O_symbol; |
| 381 | exp.X_add_symbol = symbol; |
| 382 | exp.X_add_number = 0; |
| 383 | emit_expr (&exp, size); |
| 384 | } |
| 385 | #endif |
| 386 | |
| 387 | struct cfi_escape_data |
| 388 | { |
| 389 | struct cfi_escape_data *next; |
| 390 | expressionS exp; |
| 391 | }; |
| 392 | |
| 393 | struct cie_entry |
| 394 | { |
| 395 | struct cie_entry *next; |
| 396 | #if MULTIPLE_FRAME_SECTIONS |
| 397 | segT cur_seg; |
| 398 | #endif |
| 399 | symbolS *start_address; |
| 400 | unsigned int return_column; |
| 401 | unsigned int signal_frame; |
| 402 | unsigned char fde_encoding; |
| 403 | unsigned char per_encoding; |
| 404 | unsigned char lsda_encoding; |
| 405 | expressionS personality; |
| 406 | #ifdef tc_cie_entry_extras |
| 407 | tc_cie_entry_extras |
| 408 | #endif |
| 409 | struct cfi_insn_data *first, *last; |
| 410 | }; |
| 411 | |
| 412 | /* List of FDE entries. */ |
| 413 | |
| 414 | struct fde_entry *all_fde_data; |
| 415 | static struct fde_entry **last_fde_data = &all_fde_data; |
| 416 | |
| 417 | /* List of CIEs so that they could be reused. */ |
| 418 | static struct cie_entry *cie_root; |
| 419 | |
| 420 | /* Construct a new FDE structure and add it to the end of the fde list. */ |
| 421 | |
| 422 | static struct fde_entry * |
| 423 | alloc_fde_entry (void) |
| 424 | { |
| 425 | struct fde_entry *fde = XCNEW (struct fde_entry); |
| 426 | |
| 427 | frchain_now->frch_cfi_data = XCNEW (struct frch_cfi_data); |
| 428 | frchain_now->frch_cfi_data->cur_fde_data = fde; |
| 429 | *last_fde_data = fde; |
| 430 | last_fde_data = &fde->next; |
| 431 | SET_CUR_SEG (fde, is_now_linkonce_segment ()); |
| 432 | SET_HANDLED (fde, 0); |
| 433 | fde->last = &fde->data; |
| 434 | fde->return_column = DWARF2_DEFAULT_RETURN_COLUMN; |
| 435 | fde->per_encoding = DW_EH_PE_omit; |
| 436 | fde->lsda_encoding = DW_EH_PE_omit; |
| 437 | fde->eh_header_type = EH_COMPACT_UNKNOWN; |
| 438 | #ifdef tc_fde_entry_init_extra |
| 439 | tc_fde_entry_init_extra (fde) |
| 440 | #endif |
| 441 | |
| 442 | return fde; |
| 443 | } |
| 444 | |
| 445 | /* The following functions are available for a backend to construct its |
| 446 | own unwind information, usually from legacy unwind directives. */ |
| 447 | |
| 448 | /* Construct a new INSN structure and add it to the end of the insn list |
| 449 | for the currently active FDE. */ |
| 450 | |
| 451 | static bfd_boolean cfi_sections_set = FALSE; |
| 452 | static int cfi_sections = CFI_EMIT_eh_frame; |
| 453 | int all_cfi_sections = 0; |
| 454 | static struct fde_entry *last_fde; |
| 455 | |
| 456 | static struct cfi_insn_data * |
| 457 | alloc_cfi_insn_data (void) |
| 458 | { |
| 459 | struct cfi_insn_data *insn = XCNEW (struct cfi_insn_data); |
| 460 | struct fde_entry *cur_fde_data = frchain_now->frch_cfi_data->cur_fde_data; |
| 461 | |
| 462 | *cur_fde_data->last = insn; |
| 463 | cur_fde_data->last = &insn->next; |
| 464 | SET_CUR_SEG (insn, is_now_linkonce_segment ()); |
| 465 | return insn; |
| 466 | } |
| 467 | |
| 468 | /* Construct a new FDE structure that begins at LABEL. */ |
| 469 | |
| 470 | void |
| 471 | cfi_new_fde (symbolS *label) |
| 472 | { |
| 473 | struct fde_entry *fde = alloc_fde_entry (); |
| 474 | fde->start_address = label; |
| 475 | frchain_now->frch_cfi_data->last_address = label; |
| 476 | } |
| 477 | |
| 478 | /* End the currently open FDE. */ |
| 479 | |
| 480 | void |
| 481 | cfi_end_fde (symbolS *label) |
| 482 | { |
| 483 | frchain_now->frch_cfi_data->cur_fde_data->end_address = label; |
| 484 | free (frchain_now->frch_cfi_data); |
| 485 | frchain_now->frch_cfi_data = NULL; |
| 486 | } |
| 487 | |
| 488 | /* Set the return column for the current FDE. */ |
| 489 | |
| 490 | void |
| 491 | cfi_set_return_column (unsigned regno) |
| 492 | { |
| 493 | frchain_now->frch_cfi_data->cur_fde_data->return_column = regno; |
| 494 | } |
| 495 | |
| 496 | void |
| 497 | cfi_set_sections (void) |
| 498 | { |
| 499 | frchain_now->frch_cfi_data->cur_fde_data->sections = all_cfi_sections; |
| 500 | cfi_sections_set = TRUE; |
| 501 | } |
| 502 | |
| 503 | /* Universal functions to store new instructions. */ |
| 504 | |
| 505 | static void |
| 506 | cfi_add_CFA_insn (int insn) |
| 507 | { |
| 508 | struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data (); |
| 509 | |
| 510 | insn_ptr->insn = insn; |
| 511 | } |
| 512 | |
| 513 | static void |
| 514 | cfi_add_CFA_insn_reg (int insn, unsigned regno) |
| 515 | { |
| 516 | struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data (); |
| 517 | |
| 518 | insn_ptr->insn = insn; |
| 519 | insn_ptr->u.r = regno; |
| 520 | } |
| 521 | |
| 522 | static void |
| 523 | cfi_add_CFA_insn_offset (int insn, offsetT offset) |
| 524 | { |
| 525 | struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data (); |
| 526 | |
| 527 | insn_ptr->insn = insn; |
| 528 | insn_ptr->u.i = offset; |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | cfi_add_CFA_insn_reg_reg (int insn, unsigned reg1, unsigned reg2) |
| 533 | { |
| 534 | struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data (); |
| 535 | |
| 536 | insn_ptr->insn = insn; |
| 537 | insn_ptr->u.rr.reg1 = reg1; |
| 538 | insn_ptr->u.rr.reg2 = reg2; |
| 539 | } |
| 540 | |
| 541 | static void |
| 542 | cfi_add_CFA_insn_reg_offset (int insn, unsigned regno, offsetT offset) |
| 543 | { |
| 544 | struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data (); |
| 545 | |
| 546 | insn_ptr->insn = insn; |
| 547 | insn_ptr->u.ri.reg = regno; |
| 548 | insn_ptr->u.ri.offset = offset; |
| 549 | } |
| 550 | |
| 551 | /* Add a CFI insn to advance the PC from the last address to LABEL. */ |
| 552 | |
| 553 | void |
| 554 | cfi_add_advance_loc (symbolS *label) |
| 555 | { |
| 556 | struct cfi_insn_data *insn = alloc_cfi_insn_data (); |
| 557 | |
| 558 | insn->insn = DW_CFA_advance_loc; |
| 559 | insn->u.ll.lab1 = frchain_now->frch_cfi_data->last_address; |
| 560 | insn->u.ll.lab2 = label; |
| 561 | |
| 562 | frchain_now->frch_cfi_data->last_address = label; |
| 563 | } |
| 564 | |
| 565 | /* Add a CFI insn to label the current position in the CFI segment. */ |
| 566 | |
| 567 | void |
| 568 | cfi_add_label (const char *name) |
| 569 | { |
| 570 | unsigned int len = strlen (name) + 1; |
| 571 | struct cfi_insn_data *insn = alloc_cfi_insn_data (); |
| 572 | |
| 573 | insn->insn = CFI_label; |
| 574 | obstack_grow (¬es, name, len); |
| 575 | insn->u.sym_name = (char *) obstack_finish (¬es); |
| 576 | } |
| 577 | |
| 578 | /* Add a DW_CFA_offset record to the CFI data. */ |
| 579 | |
| 580 | void |
| 581 | cfi_add_CFA_offset (unsigned regno, offsetT offset) |
| 582 | { |
| 583 | unsigned int abs_data_align; |
| 584 | |
| 585 | gas_assert (DWARF2_CIE_DATA_ALIGNMENT != 0); |
| 586 | cfi_add_CFA_insn_reg_offset (DW_CFA_offset, regno, offset); |
| 587 | |
| 588 | abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0 |
| 589 | ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT); |
| 590 | if (offset % abs_data_align) |
| 591 | as_bad (_("register save offset not a multiple of %u"), abs_data_align); |
| 592 | } |
| 593 | |
| 594 | /* Add a DW_CFA_val_offset record to the CFI data. */ |
| 595 | |
| 596 | void |
| 597 | cfi_add_CFA_val_offset (unsigned regno, offsetT offset) |
| 598 | { |
| 599 | unsigned int abs_data_align; |
| 600 | |
| 601 | gas_assert (DWARF2_CIE_DATA_ALIGNMENT != 0); |
| 602 | cfi_add_CFA_insn_reg_offset (DW_CFA_val_offset, regno, offset); |
| 603 | |
| 604 | abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0 |
| 605 | ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT); |
| 606 | if (offset % abs_data_align) |
| 607 | as_bad (_("register save offset not a multiple of %u"), abs_data_align); |
| 608 | } |
| 609 | |
| 610 | /* Add a DW_CFA_def_cfa record to the CFI data. */ |
| 611 | |
| 612 | void |
| 613 | cfi_add_CFA_def_cfa (unsigned regno, offsetT offset) |
| 614 | { |
| 615 | cfi_add_CFA_insn_reg_offset (DW_CFA_def_cfa, regno, offset); |
| 616 | frchain_now->frch_cfi_data->cur_cfa_offset = offset; |
| 617 | } |
| 618 | |
| 619 | /* Add a DW_CFA_register record to the CFI data. */ |
| 620 | |
| 621 | void |
| 622 | cfi_add_CFA_register (unsigned reg1, unsigned reg2) |
| 623 | { |
| 624 | cfi_add_CFA_insn_reg_reg (DW_CFA_register, reg1, reg2); |
| 625 | } |
| 626 | |
| 627 | /* Add a DW_CFA_def_cfa_register record to the CFI data. */ |
| 628 | |
| 629 | void |
| 630 | cfi_add_CFA_def_cfa_register (unsigned regno) |
| 631 | { |
| 632 | cfi_add_CFA_insn_reg (DW_CFA_def_cfa_register, regno); |
| 633 | } |
| 634 | |
| 635 | /* Add a DW_CFA_def_cfa_offset record to the CFI data. */ |
| 636 | |
| 637 | void |
| 638 | cfi_add_CFA_def_cfa_offset (offsetT offset) |
| 639 | { |
| 640 | cfi_add_CFA_insn_offset (DW_CFA_def_cfa_offset, offset); |
| 641 | frchain_now->frch_cfi_data->cur_cfa_offset = offset; |
| 642 | } |
| 643 | |
| 644 | void |
| 645 | cfi_add_CFA_restore (unsigned regno) |
| 646 | { |
| 647 | cfi_add_CFA_insn_reg (DW_CFA_restore, regno); |
| 648 | } |
| 649 | |
| 650 | void |
| 651 | cfi_add_CFA_undefined (unsigned regno) |
| 652 | { |
| 653 | cfi_add_CFA_insn_reg (DW_CFA_undefined, regno); |
| 654 | } |
| 655 | |
| 656 | void |
| 657 | cfi_add_CFA_same_value (unsigned regno) |
| 658 | { |
| 659 | cfi_add_CFA_insn_reg (DW_CFA_same_value, regno); |
| 660 | } |
| 661 | |
| 662 | void |
| 663 | cfi_add_CFA_remember_state (void) |
| 664 | { |
| 665 | struct cfa_save_data *p; |
| 666 | |
| 667 | cfi_add_CFA_insn (DW_CFA_remember_state); |
| 668 | |
| 669 | p = XNEW (struct cfa_save_data); |
| 670 | p->cfa_offset = frchain_now->frch_cfi_data->cur_cfa_offset; |
| 671 | p->next = frchain_now->frch_cfi_data->cfa_save_stack; |
| 672 | frchain_now->frch_cfi_data->cfa_save_stack = p; |
| 673 | } |
| 674 | |
| 675 | void |
| 676 | cfi_add_CFA_restore_state (void) |
| 677 | { |
| 678 | struct cfa_save_data *p; |
| 679 | |
| 680 | cfi_add_CFA_insn (DW_CFA_restore_state); |
| 681 | |
| 682 | p = frchain_now->frch_cfi_data->cfa_save_stack; |
| 683 | if (p) |
| 684 | { |
| 685 | frchain_now->frch_cfi_data->cur_cfa_offset = p->cfa_offset; |
| 686 | frchain_now->frch_cfi_data->cfa_save_stack = p->next; |
| 687 | free (p); |
| 688 | } |
| 689 | else |
| 690 | as_bad (_("CFI state restore without previous remember")); |
| 691 | } |
| 692 | |
| 693 | \f |
| 694 | /* Parse CFI assembler directives. */ |
| 695 | |
| 696 | static void dot_cfi (int); |
| 697 | static void dot_cfi_escape (int); |
| 698 | static void dot_cfi_sections (int); |
| 699 | static void dot_cfi_startproc (int); |
| 700 | static void dot_cfi_endproc (int); |
| 701 | static void dot_cfi_fde_data (int); |
| 702 | static void dot_cfi_personality (int); |
| 703 | static void dot_cfi_personality_id (int); |
| 704 | static void dot_cfi_lsda (int); |
| 705 | static void dot_cfi_val_encoded_addr (int); |
| 706 | static void dot_cfi_inline_lsda (int); |
| 707 | static void dot_cfi_label (int); |
| 708 | |
| 709 | const pseudo_typeS cfi_pseudo_table[] = |
| 710 | { |
| 711 | { "cfi_sections", dot_cfi_sections, 0 }, |
| 712 | { "cfi_startproc", dot_cfi_startproc, 0 }, |
| 713 | { "cfi_endproc", dot_cfi_endproc, 0 }, |
| 714 | { "cfi_fde_data", dot_cfi_fde_data, 0 }, |
| 715 | { "cfi_def_cfa", dot_cfi, DW_CFA_def_cfa }, |
| 716 | { "cfi_def_cfa_register", dot_cfi, DW_CFA_def_cfa_register }, |
| 717 | { "cfi_def_cfa_offset", dot_cfi, DW_CFA_def_cfa_offset }, |
| 718 | { "cfi_adjust_cfa_offset", dot_cfi, CFI_adjust_cfa_offset }, |
| 719 | { "cfi_offset", dot_cfi, DW_CFA_offset }, |
| 720 | { "cfi_rel_offset", dot_cfi, CFI_rel_offset }, |
| 721 | { "cfi_register", dot_cfi, DW_CFA_register }, |
| 722 | { "cfi_return_column", dot_cfi, CFI_return_column }, |
| 723 | { "cfi_restore", dot_cfi, DW_CFA_restore }, |
| 724 | { "cfi_undefined", dot_cfi, DW_CFA_undefined }, |
| 725 | { "cfi_same_value", dot_cfi, DW_CFA_same_value }, |
| 726 | { "cfi_remember_state", dot_cfi, DW_CFA_remember_state }, |
| 727 | { "cfi_restore_state", dot_cfi, DW_CFA_restore_state }, |
| 728 | { "cfi_window_save", dot_cfi, DW_CFA_GNU_window_save }, |
| 729 | { "cfi_escape", dot_cfi_escape, 0 }, |
| 730 | { "cfi_signal_frame", dot_cfi, CFI_signal_frame }, |
| 731 | { "cfi_personality", dot_cfi_personality, 0 }, |
| 732 | { "cfi_personality_id", dot_cfi_personality_id, 0 }, |
| 733 | { "cfi_lsda", dot_cfi_lsda, 0 }, |
| 734 | { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr, 0 }, |
| 735 | { "cfi_inline_lsda", dot_cfi_inline_lsda, 0 }, |
| 736 | { "cfi_label", dot_cfi_label, 0 }, |
| 737 | { "cfi_val_offset", dot_cfi, DW_CFA_val_offset }, |
| 738 | { NULL, NULL, 0 } |
| 739 | }; |
| 740 | |
| 741 | static void |
| 742 | cfi_parse_separator (void) |
| 743 | { |
| 744 | SKIP_WHITESPACE (); |
| 745 | if (*input_line_pointer == ',') |
| 746 | input_line_pointer++; |
| 747 | else |
| 748 | as_bad (_("missing separator")); |
| 749 | } |
| 750 | |
| 751 | #ifndef tc_parse_to_dw2regnum |
| 752 | static void |
| 753 | tc_parse_to_dw2regnum (expressionS *exp) |
| 754 | { |
| 755 | # ifdef tc_regname_to_dw2regnum |
| 756 | SKIP_WHITESPACE (); |
| 757 | if (is_name_beginner (*input_line_pointer) |
| 758 | || (*input_line_pointer == '%' |
| 759 | && is_name_beginner (*++input_line_pointer))) |
| 760 | { |
| 761 | char *name, c; |
| 762 | |
| 763 | c = get_symbol_name (& name); |
| 764 | |
| 765 | exp->X_op = O_constant; |
| 766 | exp->X_add_number = tc_regname_to_dw2regnum (name); |
| 767 | |
| 768 | restore_line_pointer (c); |
| 769 | } |
| 770 | else |
| 771 | # endif |
| 772 | expression_and_evaluate (exp); |
| 773 | } |
| 774 | #endif |
| 775 | |
| 776 | static unsigned |
| 777 | cfi_parse_reg (void) |
| 778 | { |
| 779 | int regno; |
| 780 | expressionS exp; |
| 781 | |
| 782 | tc_parse_to_dw2regnum (&exp); |
| 783 | switch (exp.X_op) |
| 784 | { |
| 785 | case O_register: |
| 786 | case O_constant: |
| 787 | regno = exp.X_add_number; |
| 788 | break; |
| 789 | |
| 790 | default: |
| 791 | regno = -1; |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | if (regno < 0) |
| 796 | { |
| 797 | as_bad (_("bad register expression")); |
| 798 | regno = 0; |
| 799 | } |
| 800 | |
| 801 | return regno; |
| 802 | } |
| 803 | |
| 804 | static offsetT |
| 805 | cfi_parse_const (void) |
| 806 | { |
| 807 | return get_absolute_expression (); |
| 808 | } |
| 809 | |
| 810 | static void |
| 811 | dot_cfi (int arg) |
| 812 | { |
| 813 | offsetT offset; |
| 814 | unsigned reg1, reg2; |
| 815 | |
| 816 | if (frchain_now->frch_cfi_data == NULL) |
| 817 | { |
| 818 | as_bad (_("CFI instruction used without previous .cfi_startproc")); |
| 819 | ignore_rest_of_line (); |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | /* If the last address was not at the current PC, advance to current. */ |
| 824 | if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now |
| 825 | || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address) |
| 826 | != frag_now_fix ())) |
| 827 | cfi_add_advance_loc (symbol_temp_new_now ()); |
| 828 | |
| 829 | switch (arg) |
| 830 | { |
| 831 | case DW_CFA_offset: |
| 832 | reg1 = cfi_parse_reg (); |
| 833 | cfi_parse_separator (); |
| 834 | offset = cfi_parse_const (); |
| 835 | cfi_add_CFA_offset (reg1, offset); |
| 836 | break; |
| 837 | |
| 838 | case DW_CFA_val_offset: |
| 839 | reg1 = cfi_parse_reg (); |
| 840 | cfi_parse_separator (); |
| 841 | offset = cfi_parse_const (); |
| 842 | cfi_add_CFA_val_offset (reg1, offset); |
| 843 | break; |
| 844 | |
| 845 | case CFI_rel_offset: |
| 846 | reg1 = cfi_parse_reg (); |
| 847 | cfi_parse_separator (); |
| 848 | offset = cfi_parse_const (); |
| 849 | cfi_add_CFA_offset (reg1, |
| 850 | offset - frchain_now->frch_cfi_data->cur_cfa_offset); |
| 851 | break; |
| 852 | |
| 853 | case DW_CFA_def_cfa: |
| 854 | reg1 = cfi_parse_reg (); |
| 855 | cfi_parse_separator (); |
| 856 | offset = cfi_parse_const (); |
| 857 | cfi_add_CFA_def_cfa (reg1, offset); |
| 858 | break; |
| 859 | |
| 860 | case DW_CFA_register: |
| 861 | reg1 = cfi_parse_reg (); |
| 862 | cfi_parse_separator (); |
| 863 | reg2 = cfi_parse_reg (); |
| 864 | cfi_add_CFA_register (reg1, reg2); |
| 865 | break; |
| 866 | |
| 867 | case DW_CFA_def_cfa_register: |
| 868 | reg1 = cfi_parse_reg (); |
| 869 | cfi_add_CFA_def_cfa_register (reg1); |
| 870 | break; |
| 871 | |
| 872 | case DW_CFA_def_cfa_offset: |
| 873 | offset = cfi_parse_const (); |
| 874 | cfi_add_CFA_def_cfa_offset (offset); |
| 875 | break; |
| 876 | |
| 877 | case CFI_adjust_cfa_offset: |
| 878 | offset = cfi_parse_const (); |
| 879 | cfi_add_CFA_def_cfa_offset (frchain_now->frch_cfi_data->cur_cfa_offset |
| 880 | + offset); |
| 881 | break; |
| 882 | |
| 883 | case DW_CFA_restore: |
| 884 | for (;;) |
| 885 | { |
| 886 | reg1 = cfi_parse_reg (); |
| 887 | cfi_add_CFA_restore (reg1); |
| 888 | SKIP_WHITESPACE (); |
| 889 | if (*input_line_pointer != ',') |
| 890 | break; |
| 891 | ++input_line_pointer; |
| 892 | } |
| 893 | break; |
| 894 | |
| 895 | case DW_CFA_undefined: |
| 896 | for (;;) |
| 897 | { |
| 898 | reg1 = cfi_parse_reg (); |
| 899 | cfi_add_CFA_undefined (reg1); |
| 900 | SKIP_WHITESPACE (); |
| 901 | if (*input_line_pointer != ',') |
| 902 | break; |
| 903 | ++input_line_pointer; |
| 904 | } |
| 905 | break; |
| 906 | |
| 907 | case DW_CFA_same_value: |
| 908 | reg1 = cfi_parse_reg (); |
| 909 | cfi_add_CFA_same_value (reg1); |
| 910 | break; |
| 911 | |
| 912 | case CFI_return_column: |
| 913 | reg1 = cfi_parse_reg (); |
| 914 | cfi_set_return_column (reg1); |
| 915 | break; |
| 916 | |
| 917 | case DW_CFA_remember_state: |
| 918 | cfi_add_CFA_remember_state (); |
| 919 | break; |
| 920 | |
| 921 | case DW_CFA_restore_state: |
| 922 | cfi_add_CFA_restore_state (); |
| 923 | break; |
| 924 | |
| 925 | case DW_CFA_GNU_window_save: |
| 926 | cfi_add_CFA_insn (DW_CFA_GNU_window_save); |
| 927 | break; |
| 928 | |
| 929 | case CFI_signal_frame: |
| 930 | frchain_now->frch_cfi_data->cur_fde_data->signal_frame = 1; |
| 931 | break; |
| 932 | |
| 933 | default: |
| 934 | abort (); |
| 935 | } |
| 936 | |
| 937 | demand_empty_rest_of_line (); |
| 938 | } |
| 939 | |
| 940 | static void |
| 941 | dot_cfi_escape (int ignored ATTRIBUTE_UNUSED) |
| 942 | { |
| 943 | struct cfi_escape_data *head, **tail, *e; |
| 944 | struct cfi_insn_data *insn; |
| 945 | |
| 946 | if (frchain_now->frch_cfi_data == NULL) |
| 947 | { |
| 948 | as_bad (_("CFI instruction used without previous .cfi_startproc")); |
| 949 | ignore_rest_of_line (); |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | /* If the last address was not at the current PC, advance to current. */ |
| 954 | if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now |
| 955 | || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address) |
| 956 | != frag_now_fix ())) |
| 957 | cfi_add_advance_loc (symbol_temp_new_now ()); |
| 958 | |
| 959 | tail = &head; |
| 960 | do |
| 961 | { |
| 962 | e = XNEW (struct cfi_escape_data); |
| 963 | do_parse_cons_expression (&e->exp, 1); |
| 964 | *tail = e; |
| 965 | tail = &e->next; |
| 966 | } |
| 967 | while (*input_line_pointer++ == ','); |
| 968 | *tail = NULL; |
| 969 | |
| 970 | insn = alloc_cfi_insn_data (); |
| 971 | insn->insn = CFI_escape; |
| 972 | insn->u.esc = head; |
| 973 | |
| 974 | --input_line_pointer; |
| 975 | demand_empty_rest_of_line (); |
| 976 | } |
| 977 | |
| 978 | static void |
| 979 | dot_cfi_personality (int ignored ATTRIBUTE_UNUSED) |
| 980 | { |
| 981 | struct fde_entry *fde; |
| 982 | offsetT encoding; |
| 983 | |
| 984 | if (frchain_now->frch_cfi_data == NULL) |
| 985 | { |
| 986 | as_bad (_("CFI instruction used without previous .cfi_startproc")); |
| 987 | ignore_rest_of_line (); |
| 988 | return; |
| 989 | } |
| 990 | |
| 991 | fde = frchain_now->frch_cfi_data->cur_fde_data; |
| 992 | encoding = cfi_parse_const (); |
| 993 | if (encoding == DW_EH_PE_omit) |
| 994 | { |
| 995 | demand_empty_rest_of_line (); |
| 996 | fde->per_encoding = encoding; |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | if ((encoding & 0xff) != encoding |
| 1001 | || ((((encoding & 0x70) != 0 |
| 1002 | #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr |
| 1003 | && (encoding & 0x70) != DW_EH_PE_pcrel |
| 1004 | #endif |
| 1005 | ) |
| 1006 | /* leb128 can be handled, but does something actually need it? */ |
| 1007 | || (encoding & 7) == DW_EH_PE_uleb128 |
| 1008 | || (encoding & 7) > DW_EH_PE_udata8) |
| 1009 | && tc_cfi_reloc_for_encoding (encoding) == BFD_RELOC_NONE)) |
| 1010 | { |
| 1011 | as_bad (_("invalid or unsupported encoding in .cfi_personality")); |
| 1012 | ignore_rest_of_line (); |
| 1013 | return; |
| 1014 | } |
| 1015 | |
| 1016 | if (*input_line_pointer++ != ',') |
| 1017 | { |
| 1018 | as_bad (_(".cfi_personality requires encoding and symbol arguments")); |
| 1019 | ignore_rest_of_line (); |
| 1020 | return; |
| 1021 | } |
| 1022 | |
| 1023 | expression_and_evaluate (&fde->personality); |
| 1024 | switch (fde->personality.X_op) |
| 1025 | { |
| 1026 | case O_symbol: |
| 1027 | break; |
| 1028 | case O_constant: |
| 1029 | if ((encoding & 0x70) == DW_EH_PE_pcrel) |
| 1030 | encoding = DW_EH_PE_omit; |
| 1031 | break; |
| 1032 | default: |
| 1033 | encoding = DW_EH_PE_omit; |
| 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | fde->per_encoding = encoding; |
| 1038 | |
| 1039 | if (encoding == DW_EH_PE_omit) |
| 1040 | { |
| 1041 | as_bad (_("wrong second argument to .cfi_personality")); |
| 1042 | ignore_rest_of_line (); |
| 1043 | return; |
| 1044 | } |
| 1045 | |
| 1046 | demand_empty_rest_of_line (); |
| 1047 | } |
| 1048 | |
| 1049 | static void |
| 1050 | dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED) |
| 1051 | { |
| 1052 | struct fde_entry *fde; |
| 1053 | offsetT encoding; |
| 1054 | |
| 1055 | if (frchain_now->frch_cfi_data == NULL) |
| 1056 | { |
| 1057 | as_bad (_("CFI instruction used without previous .cfi_startproc")); |
| 1058 | ignore_rest_of_line (); |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | fde = frchain_now->frch_cfi_data->cur_fde_data; |
| 1063 | encoding = cfi_parse_const (); |
| 1064 | if (encoding == DW_EH_PE_omit) |
| 1065 | { |
| 1066 | demand_empty_rest_of_line (); |
| 1067 | fde->lsda_encoding = encoding; |
| 1068 | return; |
| 1069 | } |
| 1070 | |
| 1071 | if ((encoding & 0xff) != encoding |
| 1072 | || ((((encoding & 0x70) != 0 |
| 1073 | #if CFI_DIFF_LSDA_OK || defined tc_cfi_emit_pcrel_expr |
| 1074 | && (encoding & 0x70) != DW_EH_PE_pcrel |
| 1075 | #endif |
| 1076 | ) |
| 1077 | /* leb128 can be handled, but does something actually need it? */ |
| 1078 | || (encoding & 7) == DW_EH_PE_uleb128 |
| 1079 | || (encoding & 7) > DW_EH_PE_udata8) |
| 1080 | && tc_cfi_reloc_for_encoding (encoding) == BFD_RELOC_NONE)) |
| 1081 | { |
| 1082 | as_bad (_("invalid or unsupported encoding in .cfi_lsda")); |
| 1083 | ignore_rest_of_line (); |
| 1084 | return; |
| 1085 | } |
| 1086 | |
| 1087 | if (*input_line_pointer++ != ',') |
| 1088 | { |
| 1089 | as_bad (_(".cfi_lsda requires encoding and symbol arguments")); |
| 1090 | ignore_rest_of_line (); |
| 1091 | return; |
| 1092 | } |
| 1093 | |
| 1094 | fde->lsda_encoding = encoding; |
| 1095 | |
| 1096 | expression_and_evaluate (&fde->lsda); |
| 1097 | switch (fde->lsda.X_op) |
| 1098 | { |
| 1099 | case O_symbol: |
| 1100 | break; |
| 1101 | case O_constant: |
| 1102 | if ((encoding & 0x70) == DW_EH_PE_pcrel) |
| 1103 | encoding = DW_EH_PE_omit; |
| 1104 | break; |
| 1105 | default: |
| 1106 | encoding = DW_EH_PE_omit; |
| 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | fde->lsda_encoding = encoding; |
| 1111 | |
| 1112 | if (encoding == DW_EH_PE_omit) |
| 1113 | { |
| 1114 | as_bad (_("wrong second argument to .cfi_lsda")); |
| 1115 | ignore_rest_of_line (); |
| 1116 | return; |
| 1117 | } |
| 1118 | |
| 1119 | demand_empty_rest_of_line (); |
| 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED) |
| 1124 | { |
| 1125 | struct cfi_insn_data *insn_ptr; |
| 1126 | offsetT encoding; |
| 1127 | |
| 1128 | if (frchain_now->frch_cfi_data == NULL) |
| 1129 | { |
| 1130 | as_bad (_("CFI instruction used without previous .cfi_startproc")); |
| 1131 | ignore_rest_of_line (); |
| 1132 | return; |
| 1133 | } |
| 1134 | |
| 1135 | /* If the last address was not at the current PC, advance to current. */ |
| 1136 | if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now |
| 1137 | || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address) |
| 1138 | != frag_now_fix ())) |
| 1139 | cfi_add_advance_loc (symbol_temp_new_now ()); |
| 1140 | |
| 1141 | insn_ptr = alloc_cfi_insn_data (); |
| 1142 | insn_ptr->insn = CFI_val_encoded_addr; |
| 1143 | |
| 1144 | insn_ptr->u.ea.reg = cfi_parse_reg (); |
| 1145 | |
| 1146 | cfi_parse_separator (); |
| 1147 | encoding = cfi_parse_const (); |
| 1148 | if ((encoding & 0xff) != encoding |
| 1149 | || ((encoding & 0x70) != 0 |
| 1150 | #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr |
| 1151 | && (encoding & 0x70) != DW_EH_PE_pcrel |
| 1152 | #endif |
| 1153 | ) |
| 1154 | /* leb128 can be handled, but does something actually need it? */ |
| 1155 | || (encoding & 7) == DW_EH_PE_uleb128 |
| 1156 | || (encoding & 7) > DW_EH_PE_udata8) |
| 1157 | { |
| 1158 | as_bad (_("invalid or unsupported encoding in .cfi_lsda")); |
| 1159 | encoding = DW_EH_PE_omit; |
| 1160 | } |
| 1161 | |
| 1162 | cfi_parse_separator (); |
| 1163 | expression_and_evaluate (&insn_ptr->u.ea.exp); |
| 1164 | switch (insn_ptr->u.ea.exp.X_op) |
| 1165 | { |
| 1166 | case O_symbol: |
| 1167 | break; |
| 1168 | case O_constant: |
| 1169 | if ((encoding & 0x70) != DW_EH_PE_pcrel) |
| 1170 | break; |
| 1171 | /* Fall through. */ |
| 1172 | default: |
| 1173 | encoding = DW_EH_PE_omit; |
| 1174 | break; |
| 1175 | } |
| 1176 | |
| 1177 | insn_ptr->u.ea.encoding = encoding; |
| 1178 | if (encoding == DW_EH_PE_omit) |
| 1179 | { |
| 1180 | as_bad (_("wrong third argument to .cfi_val_encoded_addr")); |
| 1181 | ignore_rest_of_line (); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | demand_empty_rest_of_line (); |
| 1186 | } |
| 1187 | |
| 1188 | static void |
| 1189 | dot_cfi_label (int ignored ATTRIBUTE_UNUSED) |
| 1190 | { |
| 1191 | char *name; |
| 1192 | |
| 1193 | if (frchain_now->frch_cfi_data == NULL) |
| 1194 | { |
| 1195 | as_bad (_("CFI instruction used without previous .cfi_startproc")); |
| 1196 | ignore_rest_of_line (); |
| 1197 | return; |
| 1198 | } |
| 1199 | |
| 1200 | name = read_symbol_name (); |
| 1201 | if (name == NULL) |
| 1202 | return; |
| 1203 | |
| 1204 | /* If the last address was not at the current PC, advance to current. */ |
| 1205 | if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now |
| 1206 | || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address) |
| 1207 | != frag_now_fix ())) |
| 1208 | cfi_add_advance_loc (symbol_temp_new_now ()); |
| 1209 | |
| 1210 | cfi_add_label (name); |
| 1211 | free (name); |
| 1212 | |
| 1213 | demand_empty_rest_of_line (); |
| 1214 | } |
| 1215 | |
| 1216 | static void |
| 1217 | dot_cfi_sections (int ignored ATTRIBUTE_UNUSED) |
| 1218 | { |
| 1219 | int sections = 0; |
| 1220 | |
| 1221 | SKIP_WHITESPACE (); |
| 1222 | if (is_name_beginner (*input_line_pointer) || *input_line_pointer == '"') |
| 1223 | while (1) |
| 1224 | { |
| 1225 | char * saved_ilp; |
| 1226 | char *name, c; |
| 1227 | |
| 1228 | saved_ilp = input_line_pointer; |
| 1229 | c = get_symbol_name (& name); |
| 1230 | |
| 1231 | if (strncmp (name, ".eh_frame", sizeof ".eh_frame") == 0 |
| 1232 | && name[9] != '_') |
| 1233 | sections |= CFI_EMIT_eh_frame; |
| 1234 | else if (strncmp (name, ".debug_frame", sizeof ".debug_frame") == 0) |
| 1235 | sections |= CFI_EMIT_debug_frame; |
| 1236 | #if SUPPORT_COMPACT_EH |
| 1237 | else if (strncmp (name, ".eh_frame_entry", |
| 1238 | sizeof ".eh_frame_entry") == 0) |
| 1239 | { |
| 1240 | compact_eh = TRUE; |
| 1241 | sections |= CFI_EMIT_eh_frame_compact; |
| 1242 | } |
| 1243 | #endif |
| 1244 | #ifdef tc_cfi_section_name |
| 1245 | else if (strcmp (name, tc_cfi_section_name) == 0) |
| 1246 | sections |= CFI_EMIT_target; |
| 1247 | #endif |
| 1248 | else |
| 1249 | { |
| 1250 | *input_line_pointer = c; |
| 1251 | input_line_pointer = saved_ilp; |
| 1252 | break; |
| 1253 | } |
| 1254 | |
| 1255 | *input_line_pointer = c; |
| 1256 | SKIP_WHITESPACE_AFTER_NAME (); |
| 1257 | if (*input_line_pointer == ',') |
| 1258 | { |
| 1259 | name = input_line_pointer++; |
| 1260 | SKIP_WHITESPACE (); |
| 1261 | if (!is_name_beginner (*input_line_pointer) |
| 1262 | && *input_line_pointer != '"') |
| 1263 | { |
| 1264 | input_line_pointer = name; |
| 1265 | break; |
| 1266 | } |
| 1267 | } |
| 1268 | else if (is_name_beginner (*input_line_pointer) |
| 1269 | || *input_line_pointer == '"') |
| 1270 | break; |
| 1271 | } |
| 1272 | |
| 1273 | demand_empty_rest_of_line (); |
| 1274 | if (cfi_sections_set |
| 1275 | && (sections & (CFI_EMIT_eh_frame | CFI_EMIT_eh_frame_compact)) |
| 1276 | && ((cfi_sections & (CFI_EMIT_eh_frame | CFI_EMIT_eh_frame_compact)) |
| 1277 | != (sections & (CFI_EMIT_eh_frame | CFI_EMIT_eh_frame_compact)))) |
| 1278 | as_bad (_("inconsistent uses of .cfi_sections")); |
| 1279 | cfi_sections = sections; |
| 1280 | } |
| 1281 | |
| 1282 | static void |
| 1283 | dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED) |
| 1284 | { |
| 1285 | int simple = 0; |
| 1286 | |
| 1287 | if (frchain_now->frch_cfi_data != NULL) |
| 1288 | { |
| 1289 | as_bad (_("previous CFI entry not closed (missing .cfi_endproc)")); |
| 1290 | ignore_rest_of_line (); |
| 1291 | return; |
| 1292 | } |
| 1293 | |
| 1294 | cfi_new_fde (symbol_temp_new_now ()); |
| 1295 | |
| 1296 | SKIP_WHITESPACE (); |
| 1297 | if (is_name_beginner (*input_line_pointer) || *input_line_pointer == '"') |
| 1298 | { |
| 1299 | char * saved_ilp = input_line_pointer; |
| 1300 | char *name, c; |
| 1301 | |
| 1302 | c = get_symbol_name (& name); |
| 1303 | |
| 1304 | if (strcmp (name, "simple") == 0) |
| 1305 | { |
| 1306 | simple = 1; |
| 1307 | restore_line_pointer (c); |
| 1308 | } |
| 1309 | else |
| 1310 | input_line_pointer = saved_ilp; |
| 1311 | } |
| 1312 | demand_empty_rest_of_line (); |
| 1313 | |
| 1314 | cfi_sections_set = TRUE; |
| 1315 | all_cfi_sections |= cfi_sections; |
| 1316 | cfi_set_sections (); |
| 1317 | frchain_now->frch_cfi_data->cur_cfa_offset = 0; |
| 1318 | if (!simple) |
| 1319 | tc_cfi_frame_initial_instructions (); |
| 1320 | |
| 1321 | if ((cfi_sections & CFI_EMIT_target) != 0) |
| 1322 | tc_cfi_startproc (); |
| 1323 | } |
| 1324 | |
| 1325 | static void |
| 1326 | dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED) |
| 1327 | { |
| 1328 | if (frchain_now->frch_cfi_data == NULL) |
| 1329 | { |
| 1330 | as_bad (_(".cfi_endproc without corresponding .cfi_startproc")); |
| 1331 | ignore_rest_of_line (); |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | last_fde = frchain_now->frch_cfi_data->cur_fde_data; |
| 1336 | |
| 1337 | cfi_end_fde (symbol_temp_new_now ()); |
| 1338 | |
| 1339 | demand_empty_rest_of_line (); |
| 1340 | |
| 1341 | cfi_sections_set = TRUE; |
| 1342 | if ((cfi_sections & CFI_EMIT_target) != 0) |
| 1343 | tc_cfi_endproc (last_fde); |
| 1344 | } |
| 1345 | |
| 1346 | static segT |
| 1347 | get_cfi_seg (segT cseg, const char *base, flagword flags, int align) |
| 1348 | { |
| 1349 | /* Exclude .debug_frame sections for Compact EH. */ |
| 1350 | if (SUPPORT_FRAME_LINKONCE || ((flags & SEC_DEBUGGING) == 0 && compact_eh)) |
| 1351 | { |
| 1352 | struct dwcfi_seg_list *l; |
| 1353 | |
| 1354 | l = dwcfi_hash_find_or_make (cseg, base, flags); |
| 1355 | |
| 1356 | cseg = l->seg; |
| 1357 | subseg_set (cseg, l->subseg); |
| 1358 | } |
| 1359 | else |
| 1360 | { |
| 1361 | cseg = subseg_new (base, 0); |
| 1362 | bfd_set_section_flags (cseg, flags); |
| 1363 | } |
| 1364 | record_alignment (cseg, align); |
| 1365 | return cseg; |
| 1366 | } |
| 1367 | |
| 1368 | #if SUPPORT_COMPACT_EH |
| 1369 | static void |
| 1370 | dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED) |
| 1371 | { |
| 1372 | struct fde_entry *fde; |
| 1373 | |
| 1374 | if (frchain_now->frch_cfi_data == NULL) |
| 1375 | { |
| 1376 | as_bad (_("CFI instruction used without previous .cfi_startproc")); |
| 1377 | ignore_rest_of_line (); |
| 1378 | return; |
| 1379 | } |
| 1380 | |
| 1381 | fde = frchain_now->frch_cfi_data->cur_fde_data; |
| 1382 | fde->personality_id = cfi_parse_const (); |
| 1383 | demand_empty_rest_of_line (); |
| 1384 | |
| 1385 | if (fde->personality_id == 0 || fde->personality_id > 3) |
| 1386 | { |
| 1387 | as_bad (_("wrong argument to .cfi_personality_id")); |
| 1388 | return; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | static void |
| 1393 | dot_cfi_fde_data (int ignored ATTRIBUTE_UNUSED) |
| 1394 | { |
| 1395 | if (frchain_now->frch_cfi_data == NULL) |
| 1396 | { |
| 1397 | as_bad (_(".cfi_fde_data without corresponding .cfi_startproc")); |
| 1398 | ignore_rest_of_line (); |
| 1399 | return; |
| 1400 | } |
| 1401 | |
| 1402 | last_fde = frchain_now->frch_cfi_data->cur_fde_data; |
| 1403 | |
| 1404 | cfi_sections_set = TRUE; |
| 1405 | if ((cfi_sections & CFI_EMIT_target) != 0 |
| 1406 | || (cfi_sections & CFI_EMIT_eh_frame_compact) != 0) |
| 1407 | { |
| 1408 | struct cfi_escape_data *head, **tail, *e; |
| 1409 | int num_ops = 0; |
| 1410 | |
| 1411 | tail = &head; |
| 1412 | if (!is_it_end_of_statement ()) |
| 1413 | { |
| 1414 | num_ops = 0; |
| 1415 | do |
| 1416 | { |
| 1417 | e = XNEW (struct cfi_escape_data); |
| 1418 | do_parse_cons_expression (&e->exp, 1); |
| 1419 | *tail = e; |
| 1420 | tail = &e->next; |
| 1421 | num_ops++; |
| 1422 | } |
| 1423 | while (*input_line_pointer++ == ','); |
| 1424 | --input_line_pointer; |
| 1425 | } |
| 1426 | *tail = NULL; |
| 1427 | |
| 1428 | if (last_fde->lsda_encoding != DW_EH_PE_omit) |
| 1429 | last_fde->eh_header_type = EH_COMPACT_HAS_LSDA; |
| 1430 | else if (num_ops <= 3 && last_fde->per_encoding == DW_EH_PE_omit) |
| 1431 | last_fde->eh_header_type = EH_COMPACT_INLINE; |
| 1432 | else |
| 1433 | last_fde->eh_header_type = EH_COMPACT_OUTLINE; |
| 1434 | |
| 1435 | if (last_fde->eh_header_type == EH_COMPACT_INLINE) |
| 1436 | num_ops = 3; |
| 1437 | |
| 1438 | last_fde->eh_data_size = num_ops; |
| 1439 | last_fde->eh_data = XNEWVEC (bfd_byte, num_ops); |
| 1440 | num_ops = 0; |
| 1441 | while (head) |
| 1442 | { |
| 1443 | e = head; |
| 1444 | head = e->next; |
| 1445 | last_fde->eh_data[num_ops++] = e->exp.X_add_number; |
| 1446 | free (e); |
| 1447 | } |
| 1448 | if (last_fde->eh_header_type == EH_COMPACT_INLINE) |
| 1449 | while (num_ops < 3) |
| 1450 | last_fde->eh_data[num_ops++] = tc_compact_eh_opcode_stop; |
| 1451 | } |
| 1452 | |
| 1453 | demand_empty_rest_of_line (); |
| 1454 | } |
| 1455 | |
| 1456 | /* Function to emit the compact unwinding opcodes stored in the |
| 1457 | fde's eh_data field. The end of the opcode data will be |
| 1458 | padded to the value in align. */ |
| 1459 | |
| 1460 | static void |
| 1461 | output_compact_unwind_data (struct fde_entry *fde, int align) |
| 1462 | { |
| 1463 | int data_size = fde->eh_data_size + 2; |
| 1464 | int align_padding; |
| 1465 | int amask; |
| 1466 | char *p; |
| 1467 | |
| 1468 | fde->eh_loc = symbol_temp_new_now (); |
| 1469 | |
| 1470 | p = frag_more (1); |
| 1471 | if (fde->personality_id != 0) |
| 1472 | *p = fde->personality_id; |
| 1473 | else if (fde->per_encoding != DW_EH_PE_omit) |
| 1474 | { |
| 1475 | *p = 0; |
| 1476 | emit_expr_encoded (&fde->personality, fde->per_encoding, FALSE); |
| 1477 | data_size += encoding_size (fde->per_encoding); |
| 1478 | } |
| 1479 | else |
| 1480 | *p = 1; |
| 1481 | |
| 1482 | amask = (1 << align) - 1; |
| 1483 | align_padding = ((data_size + amask) & ~amask) - data_size; |
| 1484 | |
| 1485 | p = frag_more (fde->eh_data_size + 1 + align_padding); |
| 1486 | memcpy (p, fde->eh_data, fde->eh_data_size); |
| 1487 | p += fde->eh_data_size; |
| 1488 | |
| 1489 | while (align_padding-- > 0) |
| 1490 | *(p++) = tc_compact_eh_opcode_pad; |
| 1491 | |
| 1492 | *(p++) = tc_compact_eh_opcode_stop; |
| 1493 | fde->eh_header_type = EH_COMPACT_OUTLINE_DONE; |
| 1494 | } |
| 1495 | |
| 1496 | /* Handle the .cfi_inline_lsda directive. */ |
| 1497 | static void |
| 1498 | dot_cfi_inline_lsda (int ignored ATTRIBUTE_UNUSED) |
| 1499 | { |
| 1500 | segT ccseg; |
| 1501 | int align; |
| 1502 | long max_alignment = 28; |
| 1503 | |
| 1504 | if (!last_fde) |
| 1505 | { |
| 1506 | as_bad (_("unexpected .cfi_inline_lsda")); |
| 1507 | ignore_rest_of_line (); |
| 1508 | return; |
| 1509 | } |
| 1510 | |
| 1511 | if ((last_fde->sections & CFI_EMIT_eh_frame_compact) == 0) |
| 1512 | { |
| 1513 | as_bad (_(".cfi_inline_lsda not valid for this frame")); |
| 1514 | ignore_rest_of_line (); |
| 1515 | return; |
| 1516 | } |
| 1517 | |
| 1518 | if (last_fde->eh_header_type != EH_COMPACT_UNKNOWN |
| 1519 | && last_fde->eh_header_type != EH_COMPACT_HAS_LSDA) |
| 1520 | { |
| 1521 | as_bad (_(".cfi_inline_lsda seen for frame without .cfi_lsda")); |
| 1522 | ignore_rest_of_line (); |
| 1523 | return; |
| 1524 | } |
| 1525 | |
| 1526 | #ifdef md_flush_pending_output |
| 1527 | md_flush_pending_output (); |
| 1528 | #endif |
| 1529 | |
| 1530 | align = get_absolute_expression (); |
| 1531 | if (align > max_alignment) |
| 1532 | { |
| 1533 | align = max_alignment; |
| 1534 | as_bad (_("Alignment too large: %d. assumed."), align); |
| 1535 | } |
| 1536 | else if (align < 0) |
| 1537 | { |
| 1538 | as_warn (_("Alignment negative: 0 assumed.")); |
| 1539 | align = 0; |
| 1540 | } |
| 1541 | |
| 1542 | demand_empty_rest_of_line (); |
| 1543 | ccseg = CUR_SEG (last_fde); |
| 1544 | |
| 1545 | /* Open .gnu_extab section. */ |
| 1546 | get_cfi_seg (ccseg, ".gnu_extab", |
| 1547 | (SEC_ALLOC | SEC_LOAD | SEC_DATA |
| 1548 | | DWARF2_EH_FRAME_READ_ONLY), |
| 1549 | 1); |
| 1550 | |
| 1551 | frag_align (align, 0, 0); |
| 1552 | record_alignment (now_seg, align); |
| 1553 | if (last_fde->eh_header_type == EH_COMPACT_HAS_LSDA) |
| 1554 | output_compact_unwind_data (last_fde, align); |
| 1555 | |
| 1556 | last_fde = NULL; |
| 1557 | |
| 1558 | return; |
| 1559 | } |
| 1560 | #else /* !SUPPORT_COMPACT_EH */ |
| 1561 | static void |
| 1562 | dot_cfi_inline_lsda (int ignored ATTRIBUTE_UNUSED) |
| 1563 | { |
| 1564 | as_bad (_(".cfi_inline_lsda is not supported for this target")); |
| 1565 | ignore_rest_of_line (); |
| 1566 | } |
| 1567 | |
| 1568 | static void |
| 1569 | dot_cfi_fde_data (int ignored ATTRIBUTE_UNUSED) |
| 1570 | { |
| 1571 | as_bad (_(".cfi_fde_data is not supported for this target")); |
| 1572 | ignore_rest_of_line (); |
| 1573 | } |
| 1574 | |
| 1575 | static void |
| 1576 | dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED) |
| 1577 | { |
| 1578 | as_bad (_(".cfi_personality_id is not supported for this target")); |
| 1579 | ignore_rest_of_line (); |
| 1580 | } |
| 1581 | #endif |
| 1582 | \f |
| 1583 | static void |
| 1584 | output_cfi_insn (struct cfi_insn_data *insn) |
| 1585 | { |
| 1586 | offsetT offset; |
| 1587 | unsigned int regno; |
| 1588 | |
| 1589 | switch (insn->insn) |
| 1590 | { |
| 1591 | case DW_CFA_advance_loc: |
| 1592 | { |
| 1593 | symbolS *from = insn->u.ll.lab1; |
| 1594 | symbolS *to = insn->u.ll.lab2; |
| 1595 | |
| 1596 | if (symbol_get_frag (to) == symbol_get_frag (from)) |
| 1597 | { |
| 1598 | addressT delta = S_GET_VALUE (to) - S_GET_VALUE (from); |
| 1599 | addressT scaled = delta / DWARF2_LINE_MIN_INSN_LENGTH; |
| 1600 | |
| 1601 | if (scaled <= 0x3F) |
| 1602 | out_one (DW_CFA_advance_loc + scaled); |
| 1603 | else if (scaled <= 0xFF) |
| 1604 | { |
| 1605 | out_one (DW_CFA_advance_loc1); |
| 1606 | out_one (scaled); |
| 1607 | } |
| 1608 | else if (scaled <= 0xFFFF) |
| 1609 | { |
| 1610 | out_one (DW_CFA_advance_loc2); |
| 1611 | out_two (scaled); |
| 1612 | } |
| 1613 | else |
| 1614 | { |
| 1615 | out_one (DW_CFA_advance_loc4); |
| 1616 | out_four (scaled); |
| 1617 | } |
| 1618 | } |
| 1619 | else |
| 1620 | { |
| 1621 | expressionS exp; |
| 1622 | |
| 1623 | exp.X_op = O_subtract; |
| 1624 | exp.X_add_symbol = to; |
| 1625 | exp.X_op_symbol = from; |
| 1626 | exp.X_add_number = 0; |
| 1627 | |
| 1628 | /* The code in ehopt.c expects that one byte of the encoding |
| 1629 | is already allocated to the frag. This comes from the way |
| 1630 | that it scans the .eh_frame section looking first for the |
| 1631 | .byte DW_CFA_advance_loc4. */ |
| 1632 | *frag_more (1) = DW_CFA_advance_loc4; |
| 1633 | |
| 1634 | frag_var (rs_cfa, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH << 3, |
| 1635 | make_expr_symbol (&exp), frag_now_fix () - 1, |
| 1636 | (char *) frag_now); |
| 1637 | } |
| 1638 | } |
| 1639 | break; |
| 1640 | |
| 1641 | case DW_CFA_def_cfa: |
| 1642 | offset = insn->u.ri.offset; |
| 1643 | if (offset < 0) |
| 1644 | { |
| 1645 | out_one (DW_CFA_def_cfa_sf); |
| 1646 | out_uleb128 (insn->u.ri.reg); |
| 1647 | out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT); |
| 1648 | } |
| 1649 | else |
| 1650 | { |
| 1651 | out_one (DW_CFA_def_cfa); |
| 1652 | out_uleb128 (insn->u.ri.reg); |
| 1653 | out_uleb128 (offset); |
| 1654 | } |
| 1655 | break; |
| 1656 | |
| 1657 | case DW_CFA_def_cfa_register: |
| 1658 | case DW_CFA_undefined: |
| 1659 | case DW_CFA_same_value: |
| 1660 | out_one (insn->insn); |
| 1661 | out_uleb128 (insn->u.r); |
| 1662 | break; |
| 1663 | |
| 1664 | case DW_CFA_def_cfa_offset: |
| 1665 | offset = insn->u.i; |
| 1666 | if (offset < 0) |
| 1667 | { |
| 1668 | out_one (DW_CFA_def_cfa_offset_sf); |
| 1669 | out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT); |
| 1670 | } |
| 1671 | else |
| 1672 | { |
| 1673 | out_one (DW_CFA_def_cfa_offset); |
| 1674 | out_uleb128 (offset); |
| 1675 | } |
| 1676 | break; |
| 1677 | |
| 1678 | case DW_CFA_restore: |
| 1679 | regno = insn->u.r; |
| 1680 | if (regno <= 0x3F) |
| 1681 | { |
| 1682 | out_one (DW_CFA_restore + regno); |
| 1683 | } |
| 1684 | else |
| 1685 | { |
| 1686 | out_one (DW_CFA_restore_extended); |
| 1687 | out_uleb128 (regno); |
| 1688 | } |
| 1689 | break; |
| 1690 | |
| 1691 | case DW_CFA_offset: |
| 1692 | regno = insn->u.ri.reg; |
| 1693 | offset = insn->u.ri.offset / DWARF2_CIE_DATA_ALIGNMENT; |
| 1694 | if (offset < 0) |
| 1695 | { |
| 1696 | out_one (DW_CFA_offset_extended_sf); |
| 1697 | out_uleb128 (regno); |
| 1698 | out_sleb128 (offset); |
| 1699 | } |
| 1700 | else if (regno <= 0x3F) |
| 1701 | { |
| 1702 | out_one (DW_CFA_offset + regno); |
| 1703 | out_uleb128 (offset); |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | out_one (DW_CFA_offset_extended); |
| 1708 | out_uleb128 (regno); |
| 1709 | out_uleb128 (offset); |
| 1710 | } |
| 1711 | break; |
| 1712 | |
| 1713 | case DW_CFA_val_offset: |
| 1714 | regno = insn->u.ri.reg; |
| 1715 | offset = insn->u.ri.offset / DWARF2_CIE_DATA_ALIGNMENT; |
| 1716 | if (offset < 0) |
| 1717 | { |
| 1718 | out_one (DW_CFA_val_offset_sf); |
| 1719 | out_uleb128 (regno); |
| 1720 | out_sleb128 (offset); |
| 1721 | } |
| 1722 | else |
| 1723 | { |
| 1724 | out_one (DW_CFA_val_offset); |
| 1725 | out_uleb128 (regno); |
| 1726 | out_uleb128 (offset); |
| 1727 | } |
| 1728 | break; |
| 1729 | |
| 1730 | case DW_CFA_register: |
| 1731 | out_one (DW_CFA_register); |
| 1732 | out_uleb128 (insn->u.rr.reg1); |
| 1733 | out_uleb128 (insn->u.rr.reg2); |
| 1734 | break; |
| 1735 | |
| 1736 | case DW_CFA_remember_state: |
| 1737 | case DW_CFA_restore_state: |
| 1738 | out_one (insn->insn); |
| 1739 | break; |
| 1740 | |
| 1741 | case DW_CFA_GNU_window_save: |
| 1742 | out_one (DW_CFA_GNU_window_save); |
| 1743 | break; |
| 1744 | |
| 1745 | case CFI_escape: |
| 1746 | { |
| 1747 | struct cfi_escape_data *e; |
| 1748 | for (e = insn->u.esc; e ; e = e->next) |
| 1749 | emit_expr (&e->exp, 1); |
| 1750 | break; |
| 1751 | } |
| 1752 | |
| 1753 | case CFI_val_encoded_addr: |
| 1754 | { |
| 1755 | unsigned encoding = insn->u.ea.encoding; |
| 1756 | offsetT enc_size; |
| 1757 | |
| 1758 | if (encoding == DW_EH_PE_omit) |
| 1759 | break; |
| 1760 | out_one (DW_CFA_val_expression); |
| 1761 | out_uleb128 (insn->u.ea.reg); |
| 1762 | |
| 1763 | switch (encoding & 0x7) |
| 1764 | { |
| 1765 | case DW_EH_PE_absptr: |
| 1766 | enc_size = DWARF2_ADDR_SIZE (stdoutput); |
| 1767 | break; |
| 1768 | case DW_EH_PE_udata2: |
| 1769 | enc_size = 2; |
| 1770 | break; |
| 1771 | case DW_EH_PE_udata4: |
| 1772 | enc_size = 4; |
| 1773 | break; |
| 1774 | case DW_EH_PE_udata8: |
| 1775 | enc_size = 8; |
| 1776 | break; |
| 1777 | default: |
| 1778 | abort (); |
| 1779 | } |
| 1780 | |
| 1781 | /* If the user has requested absolute encoding, |
| 1782 | then use the smaller DW_OP_addr encoding. */ |
| 1783 | if (insn->u.ea.encoding == DW_EH_PE_absptr) |
| 1784 | { |
| 1785 | out_uleb128 (1 + enc_size); |
| 1786 | out_one (DW_OP_addr); |
| 1787 | } |
| 1788 | else |
| 1789 | { |
| 1790 | out_uleb128 (1 + 1 + enc_size); |
| 1791 | out_one (DW_OP_GNU_encoded_addr); |
| 1792 | out_one (encoding); |
| 1793 | |
| 1794 | if ((encoding & 0x70) == DW_EH_PE_pcrel) |
| 1795 | { |
| 1796 | #if CFI_DIFF_EXPR_OK |
| 1797 | insn->u.ea.exp.X_op = O_subtract; |
| 1798 | insn->u.ea.exp.X_op_symbol = symbol_temp_new_now (); |
| 1799 | #elif defined (tc_cfi_emit_pcrel_expr) |
| 1800 | tc_cfi_emit_pcrel_expr (&insn->u.ea.exp, enc_size); |
| 1801 | break; |
| 1802 | #else |
| 1803 | abort (); |
| 1804 | #endif |
| 1805 | } |
| 1806 | } |
| 1807 | emit_expr (&insn->u.ea.exp, enc_size); |
| 1808 | } |
| 1809 | break; |
| 1810 | |
| 1811 | case CFI_label: |
| 1812 | colon (insn->u.sym_name); |
| 1813 | break; |
| 1814 | |
| 1815 | default: |
| 1816 | abort (); |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | static void |
| 1821 | output_cie (struct cie_entry *cie, bfd_boolean eh_frame, int align) |
| 1822 | { |
| 1823 | symbolS *after_size_address, *end_address; |
| 1824 | expressionS exp; |
| 1825 | struct cfi_insn_data *i; |
| 1826 | offsetT augmentation_size; |
| 1827 | int enc; |
| 1828 | enum dwarf2_format fmt = DWARF2_FORMAT (now_seg); |
| 1829 | |
| 1830 | cie->start_address = symbol_temp_new_now (); |
| 1831 | after_size_address = symbol_temp_make (); |
| 1832 | end_address = symbol_temp_make (); |
| 1833 | |
| 1834 | exp.X_op = O_subtract; |
| 1835 | exp.X_add_symbol = end_address; |
| 1836 | exp.X_op_symbol = after_size_address; |
| 1837 | exp.X_add_number = 0; |
| 1838 | |
| 1839 | if (eh_frame || fmt == dwarf2_format_32bit) |
| 1840 | emit_expr (&exp, 4); /* Length. */ |
| 1841 | else |
| 1842 | { |
| 1843 | if (fmt == dwarf2_format_64bit) |
| 1844 | out_four (-1); |
| 1845 | emit_expr (&exp, 8); /* Length. */ |
| 1846 | } |
| 1847 | symbol_set_value_now (after_size_address); |
| 1848 | if (eh_frame) |
| 1849 | out_four (0); /* CIE id. */ |
| 1850 | else |
| 1851 | { |
| 1852 | out_four (-1); /* CIE id. */ |
| 1853 | if (fmt != dwarf2_format_32bit) |
| 1854 | out_four (-1); |
| 1855 | } |
| 1856 | out_one (DW_CIE_VERSION); /* Version. */ |
| 1857 | if (eh_frame) |
| 1858 | { |
| 1859 | out_one ('z'); /* Augmentation. */ |
| 1860 | if (cie->per_encoding != DW_EH_PE_omit) |
| 1861 | out_one ('P'); |
| 1862 | if (cie->lsda_encoding != DW_EH_PE_omit) |
| 1863 | out_one ('L'); |
| 1864 | out_one ('R'); |
| 1865 | #ifdef tc_output_cie_extra |
| 1866 | tc_output_cie_extra (cie); |
| 1867 | #endif |
| 1868 | } |
| 1869 | if (cie->signal_frame) |
| 1870 | out_one ('S'); |
| 1871 | out_one (0); |
| 1872 | out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH); /* Code alignment. */ |
| 1873 | out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT); /* Data alignment. */ |
| 1874 | if (DW_CIE_VERSION == 1) /* Return column. */ |
| 1875 | out_one (cie->return_column); |
| 1876 | else |
| 1877 | out_uleb128 (cie->return_column); |
| 1878 | if (eh_frame) |
| 1879 | { |
| 1880 | augmentation_size = 1 + (cie->lsda_encoding != DW_EH_PE_omit); |
| 1881 | if (cie->per_encoding != DW_EH_PE_omit) |
| 1882 | augmentation_size += 1 + encoding_size (cie->per_encoding); |
| 1883 | out_uleb128 (augmentation_size); /* Augmentation size. */ |
| 1884 | |
| 1885 | emit_expr_encoded (&cie->personality, cie->per_encoding, TRUE); |
| 1886 | |
| 1887 | if (cie->lsda_encoding != DW_EH_PE_omit) |
| 1888 | out_one (cie->lsda_encoding); |
| 1889 | } |
| 1890 | |
| 1891 | switch (DWARF2_FDE_RELOC_SIZE) |
| 1892 | { |
| 1893 | case 2: |
| 1894 | enc = DW_EH_PE_sdata2; |
| 1895 | break; |
| 1896 | case 4: |
| 1897 | enc = DW_EH_PE_sdata4; |
| 1898 | break; |
| 1899 | case 8: |
| 1900 | enc = DW_EH_PE_sdata8; |
| 1901 | break; |
| 1902 | default: |
| 1903 | abort (); |
| 1904 | } |
| 1905 | #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr |
| 1906 | enc |= DW_EH_PE_pcrel; |
| 1907 | #endif |
| 1908 | #ifdef DWARF2_FDE_RELOC_ENCODING |
| 1909 | /* Allow target to override encoding. */ |
| 1910 | enc = DWARF2_FDE_RELOC_ENCODING (enc); |
| 1911 | #endif |
| 1912 | cie->fde_encoding = enc; |
| 1913 | if (eh_frame) |
| 1914 | out_one (enc); |
| 1915 | |
| 1916 | if (cie->first) |
| 1917 | { |
| 1918 | for (i = cie->first; i != cie->last; i = i->next) |
| 1919 | { |
| 1920 | if (CUR_SEG (i) != CUR_SEG (cie)) |
| 1921 | continue; |
| 1922 | output_cfi_insn (i); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | frag_align (align, DW_CFA_nop, 0); |
| 1927 | symbol_set_value_now (end_address); |
| 1928 | } |
| 1929 | |
| 1930 | static void |
| 1931 | output_fde (struct fde_entry *fde, struct cie_entry *cie, |
| 1932 | bfd_boolean eh_frame, struct cfi_insn_data *first, |
| 1933 | int align) |
| 1934 | { |
| 1935 | symbolS *after_size_address, *end_address; |
| 1936 | expressionS exp; |
| 1937 | offsetT augmentation_size; |
| 1938 | enum dwarf2_format fmt = DWARF2_FORMAT (now_seg); |
| 1939 | unsigned int offset_size; |
| 1940 | unsigned int addr_size; |
| 1941 | |
| 1942 | after_size_address = symbol_temp_make (); |
| 1943 | end_address = symbol_temp_make (); |
| 1944 | |
| 1945 | exp.X_op = O_subtract; |
| 1946 | exp.X_add_symbol = end_address; |
| 1947 | exp.X_op_symbol = after_size_address; |
| 1948 | exp.X_add_number = 0; |
| 1949 | if (eh_frame || fmt == dwarf2_format_32bit) |
| 1950 | offset_size = 4; |
| 1951 | else |
| 1952 | { |
| 1953 | if (fmt == dwarf2_format_64bit) |
| 1954 | out_four (-1); |
| 1955 | offset_size = 8; |
| 1956 | } |
| 1957 | emit_expr (&exp, offset_size); /* Length. */ |
| 1958 | symbol_set_value_now (after_size_address); |
| 1959 | |
| 1960 | if (eh_frame) |
| 1961 | { |
| 1962 | exp.X_op = O_subtract; |
| 1963 | exp.X_add_symbol = after_size_address; |
| 1964 | exp.X_op_symbol = cie->start_address; |
| 1965 | exp.X_add_number = 0; |
| 1966 | emit_expr (&exp, offset_size); /* CIE offset. */ |
| 1967 | } |
| 1968 | else |
| 1969 | { |
| 1970 | TC_DWARF2_EMIT_OFFSET (cie->start_address, offset_size); |
| 1971 | } |
| 1972 | |
| 1973 | exp.X_op = O_symbol; |
| 1974 | if (eh_frame) |
| 1975 | { |
| 1976 | bfd_reloc_code_real_type code |
| 1977 | = tc_cfi_reloc_for_encoding (cie->fde_encoding); |
| 1978 | addr_size = DWARF2_FDE_RELOC_SIZE; |
| 1979 | if (code != BFD_RELOC_NONE) |
| 1980 | { |
| 1981 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code); |
| 1982 | char *p = frag_more (addr_size); |
| 1983 | gas_assert (addr_size == (unsigned) howto->bitsize / 8); |
| 1984 | md_number_to_chars (p, 0, addr_size); |
| 1985 | fix_new (frag_now, p - frag_now->fr_literal, addr_size, |
| 1986 | fde->start_address, 0, howto->pc_relative, code); |
| 1987 | } |
| 1988 | else |
| 1989 | { |
| 1990 | exp.X_op = O_subtract; |
| 1991 | exp.X_add_number = 0; |
| 1992 | #if CFI_DIFF_EXPR_OK |
| 1993 | exp.X_add_symbol = fde->start_address; |
| 1994 | exp.X_op_symbol = symbol_temp_new_now (); |
| 1995 | emit_expr (&exp, addr_size); /* Code offset. */ |
| 1996 | #else |
| 1997 | exp.X_op = O_symbol; |
| 1998 | exp.X_add_symbol = fde->start_address; |
| 1999 | |
| 2000 | #if defined(tc_cfi_emit_pcrel_expr) |
| 2001 | tc_cfi_emit_pcrel_expr (&exp, addr_size); /* Code offset. */ |
| 2002 | #else |
| 2003 | emit_expr (&exp, addr_size); /* Code offset. */ |
| 2004 | #endif |
| 2005 | #endif |
| 2006 | } |
| 2007 | } |
| 2008 | else |
| 2009 | { |
| 2010 | exp.X_add_number = 0; |
| 2011 | exp.X_add_symbol = fde->start_address; |
| 2012 | addr_size = DWARF2_ADDR_SIZE (stdoutput); |
| 2013 | emit_expr (&exp, addr_size); |
| 2014 | } |
| 2015 | |
| 2016 | exp.X_op = O_subtract; |
| 2017 | exp.X_add_symbol = fde->end_address; |
| 2018 | exp.X_op_symbol = fde->start_address; /* Code length. */ |
| 2019 | exp.X_add_number = 0; |
| 2020 | emit_expr (&exp, addr_size); |
| 2021 | |
| 2022 | augmentation_size = encoding_size (fde->lsda_encoding); |
| 2023 | if (eh_frame) |
| 2024 | out_uleb128 (augmentation_size); /* Augmentation size. */ |
| 2025 | |
| 2026 | emit_expr_encoded (&fde->lsda, cie->lsda_encoding, FALSE); |
| 2027 | |
| 2028 | for (; first; first = first->next) |
| 2029 | if (CUR_SEG (first) == CUR_SEG (fde)) |
| 2030 | output_cfi_insn (first); |
| 2031 | |
| 2032 | frag_align (align, DW_CFA_nop, 0); |
| 2033 | symbol_set_value_now (end_address); |
| 2034 | } |
| 2035 | |
| 2036 | static struct cie_entry * |
| 2037 | select_cie_for_fde (struct fde_entry *fde, bfd_boolean eh_frame, |
| 2038 | struct cfi_insn_data **pfirst, int align) |
| 2039 | { |
| 2040 | struct cfi_insn_data *i, *j; |
| 2041 | struct cie_entry *cie; |
| 2042 | |
| 2043 | for (cie = cie_root; cie; cie = cie->next) |
| 2044 | { |
| 2045 | if (CUR_SEG (cie) != CUR_SEG (fde)) |
| 2046 | continue; |
| 2047 | #ifdef tc_cie_fde_equivalent_extra |
| 2048 | if (!tc_cie_fde_equivalent_extra (cie, fde)) |
| 2049 | continue; |
| 2050 | #endif |
| 2051 | if (cie->return_column != fde->return_column |
| 2052 | || cie->signal_frame != fde->signal_frame |
| 2053 | || cie->per_encoding != fde->per_encoding |
| 2054 | || cie->lsda_encoding != fde->lsda_encoding) |
| 2055 | continue; |
| 2056 | if (cie->per_encoding != DW_EH_PE_omit) |
| 2057 | { |
| 2058 | if (cie->personality.X_op != fde->personality.X_op |
| 2059 | || (cie->personality.X_add_number |
| 2060 | != fde->personality.X_add_number)) |
| 2061 | continue; |
| 2062 | switch (cie->personality.X_op) |
| 2063 | { |
| 2064 | case O_constant: |
| 2065 | if (cie->personality.X_unsigned != fde->personality.X_unsigned) |
| 2066 | continue; |
| 2067 | break; |
| 2068 | case O_symbol: |
| 2069 | if (cie->personality.X_add_symbol |
| 2070 | != fde->personality.X_add_symbol) |
| 2071 | continue; |
| 2072 | break; |
| 2073 | default: |
| 2074 | abort (); |
| 2075 | } |
| 2076 | } |
| 2077 | for (i = cie->first, j = fde->data; |
| 2078 | i != cie->last && j != NULL; |
| 2079 | i = i->next, j = j->next) |
| 2080 | { |
| 2081 | if (i->insn != j->insn) |
| 2082 | goto fail; |
| 2083 | switch (i->insn) |
| 2084 | { |
| 2085 | case DW_CFA_advance_loc: |
| 2086 | case DW_CFA_remember_state: |
| 2087 | /* We reached the first advance/remember in the FDE, |
| 2088 | but did not reach the end of the CIE list. */ |
| 2089 | goto fail; |
| 2090 | |
| 2091 | case DW_CFA_offset: |
| 2092 | case DW_CFA_def_cfa: |
| 2093 | if (i->u.ri.reg != j->u.ri.reg) |
| 2094 | goto fail; |
| 2095 | if (i->u.ri.offset != j->u.ri.offset) |
| 2096 | goto fail; |
| 2097 | break; |
| 2098 | |
| 2099 | case DW_CFA_register: |
| 2100 | if (i->u.rr.reg1 != j->u.rr.reg1) |
| 2101 | goto fail; |
| 2102 | if (i->u.rr.reg2 != j->u.rr.reg2) |
| 2103 | goto fail; |
| 2104 | break; |
| 2105 | |
| 2106 | case DW_CFA_def_cfa_register: |
| 2107 | case DW_CFA_restore: |
| 2108 | case DW_CFA_undefined: |
| 2109 | case DW_CFA_same_value: |
| 2110 | if (i->u.r != j->u.r) |
| 2111 | goto fail; |
| 2112 | break; |
| 2113 | |
| 2114 | case DW_CFA_def_cfa_offset: |
| 2115 | if (i->u.i != j->u.i) |
| 2116 | goto fail; |
| 2117 | break; |
| 2118 | |
| 2119 | case CFI_escape: |
| 2120 | case CFI_val_encoded_addr: |
| 2121 | case CFI_label: |
| 2122 | /* Don't bother matching these for now. */ |
| 2123 | goto fail; |
| 2124 | |
| 2125 | default: |
| 2126 | abort (); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | /* Success if we reached the end of the CIE list, and we've either |
| 2131 | run out of FDE entries or we've encountered an advance, |
| 2132 | remember, or escape. */ |
| 2133 | if (i == cie->last |
| 2134 | && (!j |
| 2135 | || j->insn == DW_CFA_advance_loc |
| 2136 | || j->insn == DW_CFA_remember_state |
| 2137 | || j->insn == CFI_escape |
| 2138 | || j->insn == CFI_val_encoded_addr |
| 2139 | || j->insn == CFI_label)) |
| 2140 | { |
| 2141 | *pfirst = j; |
| 2142 | return cie; |
| 2143 | } |
| 2144 | |
| 2145 | fail:; |
| 2146 | } |
| 2147 | |
| 2148 | cie = XNEW (struct cie_entry); |
| 2149 | cie->next = cie_root; |
| 2150 | cie_root = cie; |
| 2151 | SET_CUR_SEG (cie, CUR_SEG (fde)); |
| 2152 | cie->return_column = fde->return_column; |
| 2153 | cie->signal_frame = fde->signal_frame; |
| 2154 | cie->per_encoding = fde->per_encoding; |
| 2155 | cie->lsda_encoding = fde->lsda_encoding; |
| 2156 | cie->personality = fde->personality; |
| 2157 | cie->first = fde->data; |
| 2158 | #ifdef tc_cie_entry_init_extra |
| 2159 | tc_cie_entry_init_extra (cie, fde) |
| 2160 | #endif |
| 2161 | |
| 2162 | for (i = cie->first; i ; i = i->next) |
| 2163 | if (i->insn == DW_CFA_advance_loc |
| 2164 | || i->insn == DW_CFA_remember_state |
| 2165 | || i->insn == CFI_escape |
| 2166 | || i->insn == CFI_val_encoded_addr |
| 2167 | || i->insn == CFI_label) |
| 2168 | break; |
| 2169 | |
| 2170 | cie->last = i; |
| 2171 | *pfirst = i; |
| 2172 | |
| 2173 | output_cie (cie, eh_frame, align); |
| 2174 | |
| 2175 | return cie; |
| 2176 | } |
| 2177 | |
| 2178 | #ifdef md_reg_eh_frame_to_debug_frame |
| 2179 | static void |
| 2180 | cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg) |
| 2181 | { |
| 2182 | for (; insn; insn = insn->next) |
| 2183 | { |
| 2184 | if (CUR_SEG (insn) != ccseg) |
| 2185 | continue; |
| 2186 | switch (insn->insn) |
| 2187 | { |
| 2188 | case DW_CFA_advance_loc: |
| 2189 | case DW_CFA_def_cfa_offset: |
| 2190 | case DW_CFA_remember_state: |
| 2191 | case DW_CFA_restore_state: |
| 2192 | case DW_CFA_GNU_window_save: |
| 2193 | case CFI_escape: |
| 2194 | case CFI_label: |
| 2195 | break; |
| 2196 | |
| 2197 | case DW_CFA_def_cfa: |
| 2198 | case DW_CFA_offset: |
| 2199 | insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg); |
| 2200 | break; |
| 2201 | |
| 2202 | case DW_CFA_def_cfa_register: |
| 2203 | case DW_CFA_undefined: |
| 2204 | case DW_CFA_same_value: |
| 2205 | case DW_CFA_restore: |
| 2206 | insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r); |
| 2207 | break; |
| 2208 | |
| 2209 | case DW_CFA_register: |
| 2210 | insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1); |
| 2211 | insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2); |
| 2212 | break; |
| 2213 | |
| 2214 | case CFI_val_encoded_addr: |
| 2215 | insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg); |
| 2216 | break; |
| 2217 | |
| 2218 | default: |
| 2219 | abort (); |
| 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | #else |
| 2224 | #define cfi_change_reg_numbers(insn, cseg) do { } while (0) |
| 2225 | #endif |
| 2226 | |
| 2227 | #if SUPPORT_COMPACT_EH |
| 2228 | static void |
| 2229 | cfi_emit_eh_header (symbolS *sym, bfd_vma addend) |
| 2230 | { |
| 2231 | expressionS exp; |
| 2232 | |
| 2233 | exp.X_add_number = addend; |
| 2234 | exp.X_add_symbol = sym; |
| 2235 | emit_expr_encoded (&exp, DW_EH_PE_sdata4 | DW_EH_PE_pcrel, FALSE); |
| 2236 | } |
| 2237 | |
| 2238 | static void |
| 2239 | output_eh_header (struct fde_entry *fde) |
| 2240 | { |
| 2241 | char *p; |
| 2242 | bfd_vma addend; |
| 2243 | |
| 2244 | if (fde->eh_header_type == EH_COMPACT_INLINE) |
| 2245 | addend = 0; |
| 2246 | else |
| 2247 | addend = 1; |
| 2248 | |
| 2249 | cfi_emit_eh_header (fde->start_address, addend); |
| 2250 | |
| 2251 | if (fde->eh_header_type == EH_COMPACT_INLINE) |
| 2252 | { |
| 2253 | p = frag_more (4); |
| 2254 | /* Inline entries always use PR1. */ |
| 2255 | *(p++) = 1; |
| 2256 | memcpy(p, fde->eh_data, 3); |
| 2257 | } |
| 2258 | else |
| 2259 | { |
| 2260 | if (fde->eh_header_type == EH_COMPACT_LEGACY) |
| 2261 | addend = 1; |
| 2262 | else if (fde->eh_header_type == EH_COMPACT_OUTLINE |
| 2263 | || fde->eh_header_type == EH_COMPACT_OUTLINE_DONE) |
| 2264 | addend = 0; |
| 2265 | else |
| 2266 | abort (); |
| 2267 | cfi_emit_eh_header (fde->eh_loc, addend); |
| 2268 | } |
| 2269 | } |
| 2270 | #endif |
| 2271 | |
| 2272 | void |
| 2273 | cfi_finish (void) |
| 2274 | { |
| 2275 | struct cie_entry *cie, *cie_next; |
| 2276 | segT cfi_seg, ccseg; |
| 2277 | struct fde_entry *fde; |
| 2278 | struct cfi_insn_data *first; |
| 2279 | int save_flag_traditional_format, seek_next_seg; |
| 2280 | |
| 2281 | if (all_fde_data == 0) |
| 2282 | return; |
| 2283 | |
| 2284 | cfi_sections_set = TRUE; |
| 2285 | if ((all_cfi_sections & CFI_EMIT_eh_frame) != 0 |
| 2286 | || (all_cfi_sections & CFI_EMIT_eh_frame_compact) != 0) |
| 2287 | { |
| 2288 | /* Make sure check_eh_frame doesn't do anything with our output. */ |
| 2289 | save_flag_traditional_format = flag_traditional_format; |
| 2290 | flag_traditional_format = 1; |
| 2291 | |
| 2292 | if (!EH_FRAME_LINKONCE) |
| 2293 | { |
| 2294 | /* Open .eh_frame section. */ |
| 2295 | cfi_seg = get_cfi_seg (NULL, ".eh_frame", |
| 2296 | (SEC_ALLOC | SEC_LOAD | SEC_DATA |
| 2297 | | DWARF2_EH_FRAME_READ_ONLY), |
| 2298 | EH_FRAME_ALIGNMENT); |
| 2299 | #ifdef md_fix_up_eh_frame |
| 2300 | md_fix_up_eh_frame (cfi_seg); |
| 2301 | #else |
| 2302 | (void) cfi_seg; |
| 2303 | #endif |
| 2304 | } |
| 2305 | |
| 2306 | do |
| 2307 | { |
| 2308 | ccseg = NULL; |
| 2309 | seek_next_seg = 0; |
| 2310 | |
| 2311 | for (cie = cie_root; cie; cie = cie_next) |
| 2312 | { |
| 2313 | cie_next = cie->next; |
| 2314 | free ((void *) cie); |
| 2315 | } |
| 2316 | cie_root = NULL; |
| 2317 | |
| 2318 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2319 | { |
| 2320 | if ((fde->sections & CFI_EMIT_eh_frame) == 0 |
| 2321 | && (fde->sections & CFI_EMIT_eh_frame_compact) == 0) |
| 2322 | continue; |
| 2323 | |
| 2324 | #if SUPPORT_COMPACT_EH |
| 2325 | /* Emit a LEGACY format header if we have processed all |
| 2326 | of the .cfi directives without encountering either inline or |
| 2327 | out-of-line compact unwinding opcodes. */ |
| 2328 | if (fde->eh_header_type == EH_COMPACT_HAS_LSDA |
| 2329 | || fde->eh_header_type == EH_COMPACT_UNKNOWN) |
| 2330 | fde->eh_header_type = EH_COMPACT_LEGACY; |
| 2331 | |
| 2332 | if (fde->eh_header_type != EH_COMPACT_LEGACY) |
| 2333 | continue; |
| 2334 | #endif |
| 2335 | if (EH_FRAME_LINKONCE) |
| 2336 | { |
| 2337 | if (HANDLED (fde)) |
| 2338 | continue; |
| 2339 | if (seek_next_seg && CUR_SEG (fde) != ccseg) |
| 2340 | { |
| 2341 | seek_next_seg = 2; |
| 2342 | continue; |
| 2343 | } |
| 2344 | if (!seek_next_seg) |
| 2345 | { |
| 2346 | ccseg = CUR_SEG (fde); |
| 2347 | /* Open .eh_frame section. */ |
| 2348 | cfi_seg = get_cfi_seg (ccseg, ".eh_frame", |
| 2349 | (SEC_ALLOC | SEC_LOAD | SEC_DATA |
| 2350 | | DWARF2_EH_FRAME_READ_ONLY), |
| 2351 | EH_FRAME_ALIGNMENT); |
| 2352 | #ifdef md_fix_up_eh_frame |
| 2353 | md_fix_up_eh_frame (cfi_seg); |
| 2354 | #else |
| 2355 | (void) cfi_seg; |
| 2356 | #endif |
| 2357 | seek_next_seg = 1; |
| 2358 | } |
| 2359 | SET_HANDLED (fde, 1); |
| 2360 | } |
| 2361 | |
| 2362 | if (fde->end_address == NULL) |
| 2363 | { |
| 2364 | as_bad (_("open CFI at the end of file; " |
| 2365 | "missing .cfi_endproc directive")); |
| 2366 | fde->end_address = fde->start_address; |
| 2367 | } |
| 2368 | |
| 2369 | cie = select_cie_for_fde (fde, TRUE, &first, 2); |
| 2370 | fde->eh_loc = symbol_temp_new_now (); |
| 2371 | output_fde (fde, cie, TRUE, first, |
| 2372 | fde->next == NULL ? EH_FRAME_ALIGNMENT : 2); |
| 2373 | } |
| 2374 | } |
| 2375 | while (EH_FRAME_LINKONCE && seek_next_seg == 2); |
| 2376 | |
| 2377 | if (EH_FRAME_LINKONCE) |
| 2378 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2379 | SET_HANDLED (fde, 0); |
| 2380 | |
| 2381 | #if SUPPORT_COMPACT_EH |
| 2382 | if (compact_eh) |
| 2383 | { |
| 2384 | /* Create remaining out of line table entries. */ |
| 2385 | do |
| 2386 | { |
| 2387 | ccseg = NULL; |
| 2388 | seek_next_seg = 0; |
| 2389 | |
| 2390 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2391 | { |
| 2392 | if ((fde->sections & CFI_EMIT_eh_frame) == 0 |
| 2393 | && (fde->sections & CFI_EMIT_eh_frame_compact) == 0) |
| 2394 | continue; |
| 2395 | |
| 2396 | if (fde->eh_header_type != EH_COMPACT_OUTLINE) |
| 2397 | continue; |
| 2398 | if (HANDLED (fde)) |
| 2399 | continue; |
| 2400 | if (seek_next_seg && CUR_SEG (fde) != ccseg) |
| 2401 | { |
| 2402 | seek_next_seg = 2; |
| 2403 | continue; |
| 2404 | } |
| 2405 | if (!seek_next_seg) |
| 2406 | { |
| 2407 | ccseg = CUR_SEG (fde); |
| 2408 | /* Open .gnu_extab section. */ |
| 2409 | get_cfi_seg (ccseg, ".gnu_extab", |
| 2410 | (SEC_ALLOC | SEC_LOAD | SEC_DATA |
| 2411 | | DWARF2_EH_FRAME_READ_ONLY), |
| 2412 | 1); |
| 2413 | seek_next_seg = 1; |
| 2414 | } |
| 2415 | SET_HANDLED (fde, 1); |
| 2416 | |
| 2417 | frag_align (1, 0, 0); |
| 2418 | record_alignment (now_seg, 1); |
| 2419 | output_compact_unwind_data (fde, 1); |
| 2420 | } |
| 2421 | } |
| 2422 | while (EH_FRAME_LINKONCE && seek_next_seg == 2); |
| 2423 | |
| 2424 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2425 | SET_HANDLED (fde, 0); |
| 2426 | |
| 2427 | /* Create index table fragments. */ |
| 2428 | do |
| 2429 | { |
| 2430 | ccseg = NULL; |
| 2431 | seek_next_seg = 0; |
| 2432 | |
| 2433 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2434 | { |
| 2435 | if ((fde->sections & CFI_EMIT_eh_frame) == 0 |
| 2436 | && (fde->sections & CFI_EMIT_eh_frame_compact) == 0) |
| 2437 | continue; |
| 2438 | |
| 2439 | if (HANDLED (fde)) |
| 2440 | continue; |
| 2441 | if (seek_next_seg && CUR_SEG (fde) != ccseg) |
| 2442 | { |
| 2443 | seek_next_seg = 2; |
| 2444 | continue; |
| 2445 | } |
| 2446 | if (!seek_next_seg) |
| 2447 | { |
| 2448 | ccseg = CUR_SEG (fde); |
| 2449 | /* Open .eh_frame_entry section. */ |
| 2450 | cfi_seg = get_cfi_seg (ccseg, ".eh_frame_entry", |
| 2451 | (SEC_ALLOC | SEC_LOAD | SEC_DATA |
| 2452 | | DWARF2_EH_FRAME_READ_ONLY), |
| 2453 | 2); |
| 2454 | seek_next_seg = 1; |
| 2455 | } |
| 2456 | SET_HANDLED (fde, 1); |
| 2457 | |
| 2458 | output_eh_header (fde); |
| 2459 | } |
| 2460 | } |
| 2461 | while (seek_next_seg == 2); |
| 2462 | |
| 2463 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2464 | SET_HANDLED (fde, 0); |
| 2465 | } |
| 2466 | #endif /* SUPPORT_COMPACT_EH */ |
| 2467 | |
| 2468 | flag_traditional_format = save_flag_traditional_format; |
| 2469 | } |
| 2470 | |
| 2471 | cfi_sections_set = TRUE; |
| 2472 | if ((all_cfi_sections & CFI_EMIT_debug_frame) != 0) |
| 2473 | { |
| 2474 | int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1; |
| 2475 | |
| 2476 | if (!SUPPORT_FRAME_LINKONCE) |
| 2477 | get_cfi_seg (NULL, ".debug_frame", |
| 2478 | SEC_READONLY | SEC_DEBUGGING, |
| 2479 | alignment); |
| 2480 | |
| 2481 | do |
| 2482 | { |
| 2483 | ccseg = NULL; |
| 2484 | seek_next_seg = 0; |
| 2485 | |
| 2486 | for (cie = cie_root; cie; cie = cie_next) |
| 2487 | { |
| 2488 | cie_next = cie->next; |
| 2489 | free ((void *) cie); |
| 2490 | } |
| 2491 | cie_root = NULL; |
| 2492 | |
| 2493 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2494 | { |
| 2495 | if ((fde->sections & CFI_EMIT_debug_frame) == 0) |
| 2496 | continue; |
| 2497 | |
| 2498 | if (SUPPORT_FRAME_LINKONCE) |
| 2499 | { |
| 2500 | if (HANDLED (fde)) |
| 2501 | continue; |
| 2502 | if (seek_next_seg && CUR_SEG (fde) != ccseg) |
| 2503 | { |
| 2504 | seek_next_seg = 2; |
| 2505 | continue; |
| 2506 | } |
| 2507 | if (!seek_next_seg) |
| 2508 | { |
| 2509 | ccseg = CUR_SEG (fde); |
| 2510 | /* Open .debug_frame section. */ |
| 2511 | get_cfi_seg (ccseg, ".debug_frame", |
| 2512 | SEC_READONLY | SEC_DEBUGGING, |
| 2513 | alignment); |
| 2514 | seek_next_seg = 1; |
| 2515 | } |
| 2516 | SET_HANDLED (fde, 1); |
| 2517 | } |
| 2518 | if (fde->end_address == NULL) |
| 2519 | { |
| 2520 | as_bad (_("open CFI at the end of file; " |
| 2521 | "missing .cfi_endproc directive")); |
| 2522 | fde->end_address = fde->start_address; |
| 2523 | } |
| 2524 | |
| 2525 | fde->per_encoding = DW_EH_PE_omit; |
| 2526 | fde->lsda_encoding = DW_EH_PE_omit; |
| 2527 | cfi_change_reg_numbers (fde->data, ccseg); |
| 2528 | cie = select_cie_for_fde (fde, FALSE, &first, alignment); |
| 2529 | output_fde (fde, cie, FALSE, first, alignment); |
| 2530 | } |
| 2531 | } |
| 2532 | while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2); |
| 2533 | |
| 2534 | if (SUPPORT_FRAME_LINKONCE) |
| 2535 | for (fde = all_fde_data; fde ; fde = fde->next) |
| 2536 | SET_HANDLED (fde, 0); |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | #else /* TARGET_USE_CFIPOP */ |
| 2541 | |
| 2542 | /* Emit an intelligible error message for missing support. */ |
| 2543 | |
| 2544 | static void |
| 2545 | dot_cfi_dummy (int ignored ATTRIBUTE_UNUSED) |
| 2546 | { |
| 2547 | as_bad (_("CFI is not supported for this target")); |
| 2548 | ignore_rest_of_line (); |
| 2549 | } |
| 2550 | |
| 2551 | const pseudo_typeS cfi_pseudo_table[] = |
| 2552 | { |
| 2553 | { "cfi_sections", dot_cfi_dummy, 0 }, |
| 2554 | { "cfi_startproc", dot_cfi_dummy, 0 }, |
| 2555 | { "cfi_endproc", dot_cfi_dummy, 0 }, |
| 2556 | { "cfi_fde_data", dot_cfi_dummy, 0 }, |
| 2557 | { "cfi_def_cfa", dot_cfi_dummy, 0 }, |
| 2558 | { "cfi_def_cfa_register", dot_cfi_dummy, 0 }, |
| 2559 | { "cfi_def_cfa_offset", dot_cfi_dummy, 0 }, |
| 2560 | { "cfi_adjust_cfa_offset", dot_cfi_dummy, 0 }, |
| 2561 | { "cfi_offset", dot_cfi_dummy, 0 }, |
| 2562 | { "cfi_rel_offset", dot_cfi_dummy, 0 }, |
| 2563 | { "cfi_register", dot_cfi_dummy, 0 }, |
| 2564 | { "cfi_return_column", dot_cfi_dummy, 0 }, |
| 2565 | { "cfi_restore", dot_cfi_dummy, 0 }, |
| 2566 | { "cfi_undefined", dot_cfi_dummy, 0 }, |
| 2567 | { "cfi_same_value", dot_cfi_dummy, 0 }, |
| 2568 | { "cfi_remember_state", dot_cfi_dummy, 0 }, |
| 2569 | { "cfi_restore_state", dot_cfi_dummy, 0 }, |
| 2570 | { "cfi_window_save", dot_cfi_dummy, 0 }, |
| 2571 | { "cfi_escape", dot_cfi_dummy, 0 }, |
| 2572 | { "cfi_signal_frame", dot_cfi_dummy, 0 }, |
| 2573 | { "cfi_personality", dot_cfi_dummy, 0 }, |
| 2574 | { "cfi_personality_id", dot_cfi_dummy, 0 }, |
| 2575 | { "cfi_lsda", dot_cfi_dummy, 0 }, |
| 2576 | { "cfi_val_encoded_addr", dot_cfi_dummy, 0 }, |
| 2577 | { "cfi_label", dot_cfi_dummy, 0 }, |
| 2578 | { "cfi_inline_lsda", dot_cfi_dummy, 0 }, |
| 2579 | { "cfi_val_offset", dot_cfi_dummy, 0 }, |
| 2580 | { NULL, NULL, 0 } |
| 2581 | }; |
| 2582 | |
| 2583 | void |
| 2584 | cfi_finish (void) |
| 2585 | { |
| 2586 | } |
| 2587 | #endif /* TARGET_USE_CFIPOP */ |