1 /* .eh_frame section optimization.
2 Copyright 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3 Written by Jakub Jelinek <jakub@redhat.com>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program 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 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 #include "elf/dwarf2.h"
27 #define EH_FRAME_HDR_SIZE 8
33 unsigned char version
;
34 char augmentation
[20];
36 bfd_signed_vma data_align
;
38 bfd_vma augmentation_size
;
39 struct elf_link_hash_entry
*personality
;
41 struct eh_cie_fde
*cie_inf
;
42 unsigned char per_encoding
;
43 unsigned char lsda_encoding
;
44 unsigned char fde_encoding
;
45 unsigned char initial_insn_length
;
46 unsigned char make_relative
;
47 unsigned char make_lsda_relative
;
48 unsigned char initial_instructions
[50];
53 /* If *ITER hasn't reached END yet, read the next byte into *RESULT and
54 move onto the next byte. Return true on success. */
56 static inline bfd_boolean
57 read_byte (bfd_byte
**iter
, bfd_byte
*end
, unsigned char *result
)
61 *result
= *((*iter
)++);
65 /* Move *ITER over LENGTH bytes, or up to END, whichever is closer.
66 Return true it was possible to move LENGTH bytes. */
68 static inline bfd_boolean
69 skip_bytes (bfd_byte
**iter
, bfd_byte
*end
, bfd_size_type length
)
71 if ((bfd_size_type
) (end
- *iter
) < length
)
80 /* Move *ITER over an leb128, stopping at END. Return true if the end
81 of the leb128 was found. */
84 skip_leb128 (bfd_byte
**iter
, bfd_byte
*end
)
88 if (!read_byte (iter
, end
, &byte
))
94 /* Like skip_leb128, but treat the leb128 as an unsigned value and
95 store it in *VALUE. */
98 read_uleb128 (bfd_byte
**iter
, bfd_byte
*end
, bfd_vma
*value
)
103 if (!skip_leb128 (iter
, end
))
109 *value
= (*value
<< 7) | (*--p
& 0x7f);
114 /* Like read_uleb128, but for signed values. */
117 read_sleb128 (bfd_byte
**iter
, bfd_byte
*end
, bfd_signed_vma
*value
)
122 if (!skip_leb128 (iter
, end
))
126 *value
= ((*--p
& 0x7f) ^ 0x40) - 0x40;
128 *value
= (*value
<< 7) | (*--p
& 0x7f);
133 /* Return 0 if either encoding is variable width, or not yet known to bfd. */
136 int get_DW_EH_PE_width (int encoding
, int ptr_size
)
138 /* DW_EH_PE_ values of 0x60 and 0x70 weren't defined at the time .eh_frame
140 if ((encoding
& 0x60) == 0x60)
143 switch (encoding
& 7)
145 case DW_EH_PE_udata2
: return 2;
146 case DW_EH_PE_udata4
: return 4;
147 case DW_EH_PE_udata8
: return 8;
148 case DW_EH_PE_absptr
: return ptr_size
;
156 #define get_DW_EH_PE_signed(encoding) (((encoding) & DW_EH_PE_signed) != 0)
158 /* Read a width sized value from memory. */
161 read_value (bfd
*abfd
, bfd_byte
*buf
, int width
, int is_signed
)
169 value
= bfd_get_signed_16 (abfd
, buf
);
171 value
= bfd_get_16 (abfd
, buf
);
175 value
= bfd_get_signed_32 (abfd
, buf
);
177 value
= bfd_get_32 (abfd
, buf
);
181 value
= bfd_get_signed_64 (abfd
, buf
);
183 value
= bfd_get_64 (abfd
, buf
);
193 /* Store a width sized value to memory. */
196 write_value (bfd
*abfd
, bfd_byte
*buf
, bfd_vma value
, int width
)
200 case 2: bfd_put_16 (abfd
, value
, buf
); break;
201 case 4: bfd_put_32 (abfd
, value
, buf
); break;
202 case 8: bfd_put_64 (abfd
, value
, buf
); break;
203 default: BFD_FAIL ();
207 /* Return one if C1 and C2 CIEs can be merged. */
210 cie_eq (const void *e1
, const void *e2
)
212 const struct cie
*c1
= e1
;
213 const struct cie
*c2
= e2
;
215 if (c1
->hash
== c2
->hash
216 && c1
->length
== c2
->length
217 && c1
->version
== c2
->version
218 && strcmp (c1
->augmentation
, c2
->augmentation
) == 0
219 && strcmp (c1
->augmentation
, "eh") != 0
220 && c1
->code_align
== c2
->code_align
221 && c1
->data_align
== c2
->data_align
222 && c1
->ra_column
== c2
->ra_column
223 && c1
->augmentation_size
== c2
->augmentation_size
224 && c1
->personality
== c2
->personality
225 && c1
->output_sec
== c2
->output_sec
226 && c1
->per_encoding
== c2
->per_encoding
227 && c1
->lsda_encoding
== c2
->lsda_encoding
228 && c1
->fde_encoding
== c2
->fde_encoding
229 && c1
->initial_insn_length
== c2
->initial_insn_length
230 && memcmp (c1
->initial_instructions
,
231 c2
->initial_instructions
,
232 c1
->initial_insn_length
) == 0)
239 cie_hash (const void *e
)
241 const struct cie
*c
= e
;
246 cie_compute_hash (struct cie
*c
)
249 h
= iterative_hash_object (c
->length
, h
);
250 h
= iterative_hash_object (c
->version
, h
);
251 h
= iterative_hash (c
->augmentation
, strlen (c
->augmentation
) + 1, h
);
252 h
= iterative_hash_object (c
->code_align
, h
);
253 h
= iterative_hash_object (c
->data_align
, h
);
254 h
= iterative_hash_object (c
->ra_column
, h
);
255 h
= iterative_hash_object (c
->augmentation_size
, h
);
256 h
= iterative_hash_object (c
->personality
, h
);
257 h
= iterative_hash_object (c
->output_sec
, h
);
258 h
= iterative_hash_object (c
->per_encoding
, h
);
259 h
= iterative_hash_object (c
->lsda_encoding
, h
);
260 h
= iterative_hash_object (c
->fde_encoding
, h
);
261 h
= iterative_hash_object (c
->initial_insn_length
, h
);
262 h
= iterative_hash (c
->initial_instructions
, c
->initial_insn_length
, h
);
267 /* Return the number of extra bytes that we'll be inserting into
268 ENTRY's augmentation string. */
270 static INLINE
unsigned int
271 extra_augmentation_string_bytes (struct eh_cie_fde
*entry
)
273 unsigned int size
= 0;
276 if (entry
->add_augmentation_size
)
278 if (entry
->add_fde_encoding
)
284 /* Likewise ENTRY's augmentation data. */
286 static INLINE
unsigned int
287 extra_augmentation_data_bytes (struct eh_cie_fde
*entry
)
289 unsigned int size
= 0;
292 if (entry
->add_augmentation_size
)
294 if (entry
->add_fde_encoding
)
299 if (entry
->cie_inf
->add_augmentation_size
)
305 /* Return the size that ENTRY will have in the output. ALIGNMENT is the
306 required alignment of ENTRY in bytes. */
309 size_of_output_cie_fde (struct eh_cie_fde
*entry
, unsigned int alignment
)
313 if (entry
->size
== 4)
316 + extra_augmentation_string_bytes (entry
)
317 + extra_augmentation_data_bytes (entry
)
318 + alignment
- 1) & -alignment
;
321 /* Assume that the bytes between *ITER and END are CFA instructions.
322 Try to move *ITER past the first instruction and return true on
323 success. ENCODED_PTR_WIDTH gives the width of pointer entries. */
326 skip_cfa_op (bfd_byte
**iter
, bfd_byte
*end
, unsigned int encoded_ptr_width
)
331 if (!read_byte (iter
, end
, &op
))
334 switch (op
& 0xc0 ? op
& 0xc0 : op
)
337 case DW_CFA_advance_loc
:
339 case DW_CFA_remember_state
:
340 case DW_CFA_restore_state
:
341 case DW_CFA_GNU_window_save
:
346 case DW_CFA_restore_extended
:
347 case DW_CFA_undefined
:
348 case DW_CFA_same_value
:
349 case DW_CFA_def_cfa_register
:
350 case DW_CFA_def_cfa_offset
:
351 case DW_CFA_def_cfa_offset_sf
:
352 case DW_CFA_GNU_args_size
:
353 /* One leb128 argument. */
354 return skip_leb128 (iter
, end
);
356 case DW_CFA_val_offset
:
357 case DW_CFA_val_offset_sf
:
358 case DW_CFA_offset_extended
:
359 case DW_CFA_register
:
361 case DW_CFA_offset_extended_sf
:
362 case DW_CFA_GNU_negative_offset_extended
:
363 case DW_CFA_def_cfa_sf
:
364 /* Two leb128 arguments. */
365 return (skip_leb128 (iter
, end
)
366 && skip_leb128 (iter
, end
));
368 case DW_CFA_def_cfa_expression
:
369 /* A variable-length argument. */
370 return (read_uleb128 (iter
, end
, &length
)
371 && skip_bytes (iter
, end
, length
));
373 case DW_CFA_expression
:
374 case DW_CFA_val_expression
:
375 /* A leb128 followed by a variable-length argument. */
376 return (skip_leb128 (iter
, end
)
377 && read_uleb128 (iter
, end
, &length
)
378 && skip_bytes (iter
, end
, length
));
381 return skip_bytes (iter
, end
, encoded_ptr_width
);
383 case DW_CFA_advance_loc1
:
384 return skip_bytes (iter
, end
, 1);
386 case DW_CFA_advance_loc2
:
387 return skip_bytes (iter
, end
, 2);
389 case DW_CFA_advance_loc4
:
390 return skip_bytes (iter
, end
, 4);
392 case DW_CFA_MIPS_advance_loc8
:
393 return skip_bytes (iter
, end
, 8);
400 /* Try to interpret the bytes between BUF and END as CFA instructions.
401 If every byte makes sense, return a pointer to the first DW_CFA_nop
402 padding byte, or END if there is no padding. Return null otherwise.
403 ENCODED_PTR_WIDTH is as for skip_cfa_op. */
406 skip_non_nops (bfd_byte
*buf
, bfd_byte
*end
, unsigned int encoded_ptr_width
,
407 unsigned int *set_loc_count
)
413 if (*buf
== DW_CFA_nop
)
417 if (*buf
== DW_CFA_set_loc
)
419 if (!skip_cfa_op (&buf
, end
, encoded_ptr_width
))
426 /* This function is called for each input file before the .eh_frame
427 section is relocated. It discards duplicate CIEs and FDEs for discarded
428 functions. The function returns TRUE iff any entries have been
432 _bfd_elf_discard_section_eh_frame
433 (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
434 bfd_boolean (*reloc_symbol_deleted_p
) (bfd_vma
, void *),
435 struct elf_reloc_cookie
*cookie
)
437 #define REQUIRE(COND) \
440 goto free_no_table; \
443 bfd_byte
*ehbuf
= NULL
, *buf
;
445 struct eh_cie_fde
*ent
, *this_inf
;
446 unsigned int hdr_length
, hdr_id
;
451 unsigned int usage_count
;
453 } *ecies
= NULL
, *ecie
;
454 unsigned int ecie_count
= 0, ecie_alloced
= 0;
456 struct elf_link_hash_table
*htab
;
457 struct eh_frame_hdr_info
*hdr_info
;
458 struct eh_frame_sec_info
*sec_info
= NULL
;
460 unsigned int ptr_size
;
461 unsigned int entry_alloced
;
465 /* This file does not contain .eh_frame information. */
469 if (bfd_is_abs_section (sec
->output_section
))
471 /* At least one of the sections is being discarded from the
472 link, so we should just ignore them. */
476 htab
= elf_hash_table (info
);
477 hdr_info
= &htab
->eh_info
;
479 if (hdr_info
->cies
== NULL
&& !info
->relocatable
)
480 hdr_info
->cies
= htab_try_create (1, cie_hash
, cie_eq
, free
);
482 /* Read the frame unwind information from abfd. */
484 REQUIRE (bfd_malloc_and_get_section (abfd
, sec
, &ehbuf
));
487 && bfd_get_32 (abfd
, ehbuf
) == 0
488 && cookie
->rel
== cookie
->relend
)
490 /* Empty .eh_frame section. */
495 /* If .eh_frame section size doesn't fit into int, we cannot handle
496 it (it would need to use 64-bit .eh_frame format anyway). */
497 REQUIRE (sec
->size
== (unsigned int) sec
->size
);
499 ptr_size
= (get_elf_backend_data (abfd
)
500 ->elf_backend_eh_frame_address_size (abfd
, sec
));
501 REQUIRE (ptr_size
!= 0);
504 sec_info
= bfd_zmalloc (sizeof (struct eh_frame_sec_info
)
505 + 99 * sizeof (struct eh_cie_fde
));
510 #define ENSURE_NO_RELOCS(buf) \
511 REQUIRE (!(cookie->rel < cookie->relend \
512 && (cookie->rel->r_offset \
513 < (bfd_size_type) ((buf) - ehbuf)) \
514 && cookie->rel->r_info != 0))
516 #define SKIP_RELOCS(buf) \
517 while (cookie->rel < cookie->relend \
518 && (cookie->rel->r_offset \
519 < (bfd_size_type) ((buf) - ehbuf))) \
522 #define GET_RELOC(buf) \
523 ((cookie->rel < cookie->relend \
524 && (cookie->rel->r_offset \
525 == (bfd_size_type) ((buf) - ehbuf))) \
526 ? cookie->rel : NULL)
531 bfd_byte
*start
, *end
, *insns
, *insns_end
;
532 bfd_size_type length
;
533 unsigned int set_loc_count
;
535 if (sec_info
->count
== entry_alloced
)
537 sec_info
= bfd_realloc (sec_info
,
538 sizeof (struct eh_frame_sec_info
)
539 + ((entry_alloced
+ 99)
540 * sizeof (struct eh_cie_fde
)));
543 memset (&sec_info
->entry
[entry_alloced
], 0,
544 100 * sizeof (struct eh_cie_fde
));
545 entry_alloced
+= 100;
548 this_inf
= sec_info
->entry
+ sec_info
->count
;
551 if ((bfd_size_type
) (buf
- ehbuf
) == sec
->size
)
554 /* Read the length of the entry. */
555 REQUIRE (skip_bytes (&buf
, ehbuf
+ sec
->size
, 4));
556 hdr_length
= bfd_get_32 (abfd
, buf
- 4);
558 /* 64-bit .eh_frame is not supported. */
559 REQUIRE (hdr_length
!= 0xffffffff);
561 /* The CIE/FDE must be fully contained in this input section. */
562 REQUIRE ((bfd_size_type
) (buf
- ehbuf
) + hdr_length
<= sec
->size
);
563 end
= buf
+ hdr_length
;
565 this_inf
->offset
= last_fde
- ehbuf
;
566 this_inf
->size
= 4 + hdr_length
;
570 /* A zero-length CIE should only be found at the end of
572 REQUIRE ((bfd_size_type
) (buf
- ehbuf
) == sec
->size
);
573 ENSURE_NO_RELOCS (buf
);
578 REQUIRE (skip_bytes (&buf
, end
, 4));
579 hdr_id
= bfd_get_32 (abfd
, buf
- 4);
583 unsigned int initial_insn_length
;
588 if (ecie_count
== ecie_alloced
)
590 ecies
= bfd_realloc (ecies
,
591 (ecie_alloced
+ 20) * sizeof (*ecies
));
593 memset (&ecies
[ecie_alloced
], 0, 20 * sizeof (*ecies
));
597 cie
= &ecies
[ecie_count
].cie
;
598 ecies
[ecie_count
].offset
= this_inf
->offset
;
599 ecies
[ecie_count
++].entry
= sec_info
->count
;
600 cie
->length
= hdr_length
;
602 REQUIRE (read_byte (&buf
, end
, &cie
->version
));
604 /* Cannot handle unknown versions. */
605 REQUIRE (cie
->version
== 1 || cie
->version
== 3);
606 REQUIRE (strlen ((char *) buf
) < sizeof (cie
->augmentation
));
608 strcpy (cie
->augmentation
, (char *) buf
);
609 buf
= (bfd_byte
*) strchr ((char *) buf
, '\0') + 1;
610 ENSURE_NO_RELOCS (buf
);
611 if (buf
[0] == 'e' && buf
[1] == 'h')
613 /* GCC < 3.0 .eh_frame CIE */
614 /* We cannot merge "eh" CIEs because __EXCEPTION_TABLE__
615 is private to each CIE, so we don't need it for anything.
617 REQUIRE (skip_bytes (&buf
, end
, ptr_size
));
620 REQUIRE (read_uleb128 (&buf
, end
, &cie
->code_align
));
621 REQUIRE (read_sleb128 (&buf
, end
, &cie
->data_align
));
622 if (cie
->version
== 1)
625 cie
->ra_column
= *buf
++;
628 REQUIRE (read_uleb128 (&buf
, end
, &cie
->ra_column
));
629 ENSURE_NO_RELOCS (buf
);
630 cie
->lsda_encoding
= DW_EH_PE_omit
;
631 cie
->fde_encoding
= DW_EH_PE_omit
;
632 cie
->per_encoding
= DW_EH_PE_omit
;
633 aug
= cie
->augmentation
;
634 if (aug
[0] != 'e' || aug
[1] != 'h')
639 REQUIRE (read_uleb128 (&buf
, end
, &cie
->augmentation_size
));
640 ENSURE_NO_RELOCS (buf
);
647 REQUIRE (read_byte (&buf
, end
, &cie
->lsda_encoding
));
648 ENSURE_NO_RELOCS (buf
);
649 REQUIRE (get_DW_EH_PE_width (cie
->lsda_encoding
, ptr_size
));
652 REQUIRE (read_byte (&buf
, end
, &cie
->fde_encoding
));
653 ENSURE_NO_RELOCS (buf
);
654 REQUIRE (get_DW_EH_PE_width (cie
->fde_encoding
, ptr_size
));
662 REQUIRE (read_byte (&buf
, end
, &cie
->per_encoding
));
663 per_width
= get_DW_EH_PE_width (cie
->per_encoding
,
666 if ((cie
->per_encoding
& 0xf0) == DW_EH_PE_aligned
)
668 length
= -(buf
- ehbuf
) & (per_width
- 1);
669 REQUIRE (skip_bytes (&buf
, end
, length
));
671 ENSURE_NO_RELOCS (buf
);
672 /* Ensure we have a reloc here, against
674 if (GET_RELOC (buf
) != NULL
)
676 unsigned long r_symndx
;
680 r_symndx
= ELF64_R_SYM (cookie
->rel
->r_info
);
683 r_symndx
= ELF32_R_SYM (cookie
->rel
->r_info
);
684 if (r_symndx
>= cookie
->locsymcount
)
686 struct elf_link_hash_entry
*h
;
688 r_symndx
-= cookie
->extsymoff
;
689 h
= cookie
->sym_hashes
[r_symndx
];
691 while (h
->root
.type
== bfd_link_hash_indirect
692 || h
->root
.type
== bfd_link_hash_warning
)
693 h
= (struct elf_link_hash_entry
*)
696 cie
->personality
= h
;
698 /* Cope with MIPS-style composite relocations. */
701 while (GET_RELOC (buf
) != NULL
);
703 REQUIRE (skip_bytes (&buf
, end
, per_width
));
704 REQUIRE (cie
->personality
);
708 /* Unrecognized augmentation. Better bail out. */
713 /* For shared libraries, try to get rid of as many RELATIVE relocs
716 && (get_elf_backend_data (abfd
)
717 ->elf_backend_can_make_relative_eh_frame
720 if ((cie
->fde_encoding
& 0xf0) == DW_EH_PE_absptr
)
721 cie
->make_relative
= 1;
722 /* If the CIE doesn't already have an 'R' entry, it's fairly
723 easy to add one, provided that there's no aligned data
724 after the augmentation string. */
725 else if (cie
->fde_encoding
== DW_EH_PE_omit
726 && (cie
->per_encoding
& 0xf0) != DW_EH_PE_aligned
)
728 if (*cie
->augmentation
== 0)
729 this_inf
->add_augmentation_size
= 1;
730 this_inf
->add_fde_encoding
= 1;
731 cie
->make_relative
= 1;
736 && (get_elf_backend_data (abfd
)
737 ->elf_backend_can_make_lsda_relative_eh_frame
739 && (cie
->lsda_encoding
& 0xf0) == DW_EH_PE_absptr
)
740 cie
->make_lsda_relative
= 1;
742 /* If FDE encoding was not specified, it defaults to
744 if (cie
->fde_encoding
== DW_EH_PE_omit
)
745 cie
->fde_encoding
= DW_EH_PE_absptr
;
747 initial_insn_length
= end
- buf
;
748 if (initial_insn_length
<= sizeof (cie
->initial_instructions
))
750 cie
->initial_insn_length
= initial_insn_length
;
751 memcpy (cie
->initial_instructions
, buf
, initial_insn_length
);
754 buf
+= initial_insn_length
;
755 ENSURE_NO_RELOCS (buf
);
759 /* Find the corresponding CIE. */
760 unsigned int cie_offset
= this_inf
->offset
+ 4 - hdr_id
;
761 for (ecie
= ecies
; ecie
< ecies
+ ecie_count
; ++ecie
)
762 if (cie_offset
== ecie
->offset
)
765 /* Ensure this FDE references one of the CIEs in this input
767 REQUIRE (ecie
!= ecies
+ ecie_count
);
770 ENSURE_NO_RELOCS (buf
);
771 REQUIRE (GET_RELOC (buf
));
773 if ((*reloc_symbol_deleted_p
) (buf
- ehbuf
, cookie
))
774 /* This is a FDE against a discarded section. It should
776 this_inf
->removed
= 1;
780 && (((cie
->fde_encoding
& 0xf0) == DW_EH_PE_absptr
781 && cie
->make_relative
== 0)
782 || (cie
->fde_encoding
& 0xf0) == DW_EH_PE_aligned
))
784 /* If a shared library uses absolute pointers
785 which we cannot turn into PC relative,
786 don't create the binary search table,
787 since it is affected by runtime relocations. */
788 hdr_info
->table
= FALSE
;
791 hdr_info
->fde_count
++;
792 this_inf
->cie_inf
= (void *) (ecie
- ecies
);
795 /* Skip the initial location and address range. */
797 length
= get_DW_EH_PE_width (cie
->fde_encoding
, ptr_size
);
798 REQUIRE (skip_bytes (&buf
, end
, 2 * length
));
800 /* Skip the augmentation size, if present. */
801 if (cie
->augmentation
[0] == 'z')
802 REQUIRE (read_uleb128 (&buf
, end
, &length
));
806 /* Of the supported augmentation characters above, only 'L'
807 adds augmentation data to the FDE. This code would need to
808 be adjusted if any future augmentations do the same thing. */
809 if (cie
->lsda_encoding
!= DW_EH_PE_omit
)
811 this_inf
->lsda_offset
= buf
- start
;
812 /* If there's no 'z' augmentation, we don't know where the
813 CFA insns begin. Assume no padding. */
814 if (cie
->augmentation
[0] != 'z')
818 /* Skip over the augmentation data. */
819 REQUIRE (skip_bytes (&buf
, end
, length
));
822 buf
= last_fde
+ 4 + hdr_length
;
826 /* Try to interpret the CFA instructions and find the first
827 padding nop. Shrink this_inf's size so that it doesn't
828 include the padding. */
829 length
= get_DW_EH_PE_width (cie
->fde_encoding
, ptr_size
);
831 insns_end
= skip_non_nops (insns
, end
, length
, &set_loc_count
);
832 /* If we don't understand the CFA instructions, we can't know
833 what needs to be adjusted there. */
834 if (insns_end
== NULL
835 /* For the time being we don't support DW_CFA_set_loc in
837 || (set_loc_count
&& this_inf
->cie
))
839 this_inf
->size
-= end
- insns_end
;
840 if (insns_end
!= end
&& this_inf
->cie
)
842 cie
->initial_insn_length
-= end
- insns_end
;
843 cie
->length
-= end
- insns_end
;
846 && ((cie
->fde_encoding
& 0xf0) == DW_EH_PE_pcrel
847 || cie
->make_relative
))
852 this_inf
->set_loc
= bfd_malloc ((set_loc_count
+ 1)
853 * sizeof (unsigned int));
854 REQUIRE (this_inf
->set_loc
);
855 this_inf
->set_loc
[0] = set_loc_count
;
860 if (*p
== DW_CFA_set_loc
)
861 this_inf
->set_loc
[++cnt
] = p
+ 1 - start
;
862 REQUIRE (skip_cfa_op (&p
, end
, length
));
866 this_inf
->fde_encoding
= cie
->fde_encoding
;
867 this_inf
->lsda_encoding
= cie
->lsda_encoding
;
871 elf_section_data (sec
)->sec_info
= sec_info
;
872 sec
->sec_info_type
= ELF_INFO_TYPE_EH_FRAME
;
874 /* Look at all CIEs in this section and determine which can be
875 removed as unused, which can be merged with previous duplicate
876 CIEs and which need to be kept. */
877 for (ecie
= ecies
; ecie
< ecies
+ ecie_count
; ++ecie
)
879 if (ecie
->usage_count
== 0)
881 sec_info
->entry
[ecie
->entry
].removed
= 1;
884 ecie
->cie
.output_sec
= sec
->output_section
;
885 ecie
->cie
.cie_inf
= sec_info
->entry
+ ecie
->entry
;
886 cie_compute_hash (&ecie
->cie
);
887 if (hdr_info
->cies
!= NULL
)
889 void **loc
= htab_find_slot_with_hash (hdr_info
->cies
, &ecie
->cie
,
890 ecie
->cie
.hash
, INSERT
);
893 if (*loc
!= HTAB_EMPTY_ENTRY
)
895 sec_info
->entry
[ecie
->entry
].removed
= 1;
896 ecie
->cie
.cie_inf
= ((struct cie
*) *loc
)->cie_inf
;
900 *loc
= malloc (sizeof (struct cie
));
902 *loc
= HTAB_DELETED_ENTRY
;
904 memcpy (*loc
, &ecie
->cie
, sizeof (struct cie
));
907 ecie
->cie
.cie_inf
->make_relative
= ecie
->cie
.make_relative
;
908 ecie
->cie
.cie_inf
->make_lsda_relative
= ecie
->cie
.make_lsda_relative
;
909 ecie
->cie
.cie_inf
->per_encoding_relative
910 = (ecie
->cie
.per_encoding
& 0x70) == DW_EH_PE_pcrel
;
913 /* Ok, now we can assign new offsets. */
915 for (ent
= sec_info
->entry
; ent
< sec_info
->entry
+ sec_info
->count
; ++ent
)
920 ecie
= ecies
+ (unsigned long) ent
->cie_inf
;
921 ent
->cie_inf
= ecie
->cie
.cie_inf
;
923 ent
->new_offset
= offset
;
924 offset
+= size_of_output_cie_fde (ent
, ptr_size
);
927 /* Resize the sec as needed. */
928 sec
->rawsize
= sec
->size
;
934 return offset
!= sec
->rawsize
;
943 hdr_info
->table
= FALSE
;
949 /* This function is called for .eh_frame_hdr section after
950 _bfd_elf_discard_section_eh_frame has been called on all .eh_frame
951 input sections. It finalizes the size of .eh_frame_hdr section. */
954 _bfd_elf_discard_section_eh_frame_hdr (bfd
*abfd
, struct bfd_link_info
*info
)
956 struct elf_link_hash_table
*htab
;
957 struct eh_frame_hdr_info
*hdr_info
;
960 htab
= elf_hash_table (info
);
961 hdr_info
= &htab
->eh_info
;
963 if (hdr_info
->cies
!= NULL
)
965 htab_delete (hdr_info
->cies
);
966 hdr_info
->cies
= NULL
;
969 sec
= hdr_info
->hdr_sec
;
973 sec
->size
= EH_FRAME_HDR_SIZE
;
975 sec
->size
+= 4 + hdr_info
->fde_count
* 8;
977 elf_tdata (abfd
)->eh_frame_hdr
= sec
;
981 /* This function is called from size_dynamic_sections.
982 It needs to decide whether .eh_frame_hdr should be output or not,
983 because when the dynamic symbol table has been sized it is too late
984 to strip sections. */
987 _bfd_elf_maybe_strip_eh_frame_hdr (struct bfd_link_info
*info
)
991 struct elf_link_hash_table
*htab
;
992 struct eh_frame_hdr_info
*hdr_info
;
994 htab
= elf_hash_table (info
);
995 hdr_info
= &htab
->eh_info
;
996 if (hdr_info
->hdr_sec
== NULL
)
999 if (bfd_is_abs_section (hdr_info
->hdr_sec
->output_section
))
1001 hdr_info
->hdr_sec
= NULL
;
1006 if (info
->eh_frame_hdr
)
1007 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link_next
)
1009 /* Count only sections which have at least a single CIE or FDE.
1010 There cannot be any CIE or FDE <= 8 bytes. */
1011 o
= bfd_get_section_by_name (abfd
, ".eh_frame");
1012 if (o
&& o
->size
> 8 && !bfd_is_abs_section (o
->output_section
))
1018 hdr_info
->hdr_sec
->flags
|= SEC_EXCLUDE
;
1019 hdr_info
->hdr_sec
= NULL
;
1023 hdr_info
->table
= TRUE
;
1027 /* Adjust an address in the .eh_frame section. Given OFFSET within
1028 SEC, this returns the new offset in the adjusted .eh_frame section,
1029 or -1 if the address refers to a CIE/FDE which has been removed
1030 or to offset with dynamic relocation which is no longer needed. */
1033 _bfd_elf_eh_frame_section_offset (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1034 struct bfd_link_info
*info
,
1038 struct eh_frame_sec_info
*sec_info
;
1039 struct elf_link_hash_table
*htab
;
1040 struct eh_frame_hdr_info
*hdr_info
;
1041 unsigned int lo
, hi
, mid
;
1043 if (sec
->sec_info_type
!= ELF_INFO_TYPE_EH_FRAME
)
1045 sec_info
= elf_section_data (sec
)->sec_info
;
1047 if (offset
>= sec
->rawsize
)
1048 return offset
- sec
->rawsize
+ sec
->size
;
1050 htab
= elf_hash_table (info
);
1051 hdr_info
= &htab
->eh_info
;
1052 if (hdr_info
->offsets_adjusted
)
1053 offset
+= sec
->output_offset
;
1056 hi
= sec_info
->count
;
1060 mid
= (lo
+ hi
) / 2;
1061 if (offset
< sec_info
->entry
[mid
].offset
)
1064 >= sec_info
->entry
[mid
].offset
+ sec_info
->entry
[mid
].size
)
1070 BFD_ASSERT (lo
< hi
);
1072 /* FDE or CIE was removed. */
1073 if (sec_info
->entry
[mid
].removed
)
1074 return (bfd_vma
) -1;
1076 /* If converting to DW_EH_PE_pcrel, there will be no need for run-time
1077 relocation against FDE's initial_location field. */
1078 if (!sec_info
->entry
[mid
].cie
1079 && sec_info
->entry
[mid
].cie_inf
->make_relative
1080 && offset
== sec_info
->entry
[mid
].offset
+ 8)
1081 return (bfd_vma
) -2;
1083 /* If converting LSDA pointers to DW_EH_PE_pcrel, there will be no need
1084 for run-time relocation against LSDA field. */
1085 if (!sec_info
->entry
[mid
].cie
1086 && sec_info
->entry
[mid
].cie_inf
->make_lsda_relative
1087 && (offset
== (sec_info
->entry
[mid
].offset
+ 8
1088 + sec_info
->entry
[mid
].lsda_offset
))
1089 && (sec_info
->entry
[mid
].cie_inf
->need_lsda_relative
1090 || !hdr_info
->offsets_adjusted
))
1092 sec_info
->entry
[mid
].cie_inf
->need_lsda_relative
= 1;
1093 return (bfd_vma
) -2;
1096 /* If converting to DW_EH_PE_pcrel, there will be no need for run-time
1097 relocation against DW_CFA_set_loc's arguments. */
1098 if (sec_info
->entry
[mid
].set_loc
1099 && (sec_info
->entry
[mid
].cie
1100 ? sec_info
->entry
[mid
].make_relative
1101 : sec_info
->entry
[mid
].cie_inf
->make_relative
)
1102 && (offset
>= sec_info
->entry
[mid
].offset
+ 8
1103 + sec_info
->entry
[mid
].set_loc
[1]))
1107 for (cnt
= 1; cnt
<= sec_info
->entry
[mid
].set_loc
[0]; cnt
++)
1108 if (offset
== sec_info
->entry
[mid
].offset
+ 8
1109 + sec_info
->entry
[mid
].set_loc
[cnt
])
1110 return (bfd_vma
) -2;
1113 if (hdr_info
->offsets_adjusted
)
1114 offset
-= sec
->output_offset
;
1115 /* Any new augmentation bytes go before the first relocation. */
1116 return (offset
+ sec_info
->entry
[mid
].new_offset
1117 - sec_info
->entry
[mid
].offset
1118 + extra_augmentation_string_bytes (sec_info
->entry
+ mid
)
1119 + extra_augmentation_data_bytes (sec_info
->entry
+ mid
));
1122 /* Write out .eh_frame section. This is called with the relocated
1126 _bfd_elf_write_section_eh_frame (bfd
*abfd
,
1127 struct bfd_link_info
*info
,
1131 struct eh_frame_sec_info
*sec_info
;
1132 struct elf_link_hash_table
*htab
;
1133 struct eh_frame_hdr_info
*hdr_info
;
1134 unsigned int ptr_size
;
1135 struct eh_cie_fde
*ent
;
1137 if (sec
->sec_info_type
!= ELF_INFO_TYPE_EH_FRAME
)
1138 return bfd_set_section_contents (abfd
, sec
->output_section
, contents
,
1139 sec
->output_offset
, sec
->size
);
1141 ptr_size
= (get_elf_backend_data (abfd
)
1142 ->elf_backend_eh_frame_address_size (abfd
, sec
));
1143 BFD_ASSERT (ptr_size
!= 0);
1145 sec_info
= elf_section_data (sec
)->sec_info
;
1146 htab
= elf_hash_table (info
);
1147 hdr_info
= &htab
->eh_info
;
1149 /* First convert all offsets to output section offsets, so that a
1150 CIE offset is valid if the CIE is used by a FDE from some other
1151 section. This can happen when duplicate CIEs are deleted in
1152 _bfd_elf_discard_section_eh_frame. We do all sections here because
1153 this function might not be called on sections in the same order as
1154 _bfd_elf_discard_section_eh_frame. */
1155 if (!hdr_info
->offsets_adjusted
)
1159 struct eh_frame_sec_info
*eh_inf
;
1161 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1163 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1164 || (ibfd
->flags
& DYNAMIC
) != 0)
1167 eh
= bfd_get_section_by_name (ibfd
, ".eh_frame");
1168 if (eh
== NULL
|| eh
->sec_info_type
!= ELF_INFO_TYPE_EH_FRAME
)
1171 eh_inf
= elf_section_data (eh
)->sec_info
;
1172 for (ent
= eh_inf
->entry
; ent
< eh_inf
->entry
+ eh_inf
->count
; ++ent
)
1174 ent
->offset
+= eh
->output_offset
;
1175 ent
->new_offset
+= eh
->output_offset
;
1178 hdr_info
->offsets_adjusted
= TRUE
;
1181 if (hdr_info
->table
&& hdr_info
->array
== NULL
)
1183 = bfd_malloc (hdr_info
->fde_count
* sizeof(*hdr_info
->array
));
1184 if (hdr_info
->array
== NULL
)
1187 /* The new offsets can be bigger or smaller than the original offsets.
1188 We therefore need to make two passes over the section: one backward
1189 pass to move entries up and one forward pass to move entries down.
1190 The two passes won't interfere with each other because entries are
1192 for (ent
= sec_info
->entry
+ sec_info
->count
; ent
-- != sec_info
->entry
;)
1193 if (!ent
->removed
&& ent
->new_offset
> ent
->offset
)
1194 memmove (contents
+ ent
->new_offset
- sec
->output_offset
,
1195 contents
+ ent
->offset
- sec
->output_offset
, ent
->size
);
1197 for (ent
= sec_info
->entry
; ent
< sec_info
->entry
+ sec_info
->count
; ++ent
)
1198 if (!ent
->removed
&& ent
->new_offset
< ent
->offset
)
1199 memmove (contents
+ ent
->new_offset
- sec
->output_offset
,
1200 contents
+ ent
->offset
- sec
->output_offset
, ent
->size
);
1202 for (ent
= sec_info
->entry
; ent
< sec_info
->entry
+ sec_info
->count
; ++ent
)
1204 unsigned char *buf
, *end
;
1205 unsigned int new_size
;
1212 /* Any terminating FDE must be at the end of the section. */
1213 BFD_ASSERT (ent
== sec_info
->entry
+ sec_info
->count
- 1);
1217 buf
= contents
+ ent
->new_offset
- sec
->output_offset
;
1218 end
= buf
+ ent
->size
;
1219 new_size
= size_of_output_cie_fde (ent
, ptr_size
);
1221 /* Update the size. It may be shrinked. */
1222 bfd_put_32 (abfd
, new_size
- 4, buf
);
1224 /* Filling the extra bytes with DW_CFA_nops. */
1225 if (new_size
!= ent
->size
)
1226 memset (end
, 0, new_size
- ent
->size
);
1231 if (ent
->make_relative
1232 || ent
->need_lsda_relative
1233 || ent
->per_encoding_relative
)
1236 unsigned int action
, extra_string
, extra_data
;
1237 unsigned int per_width
, per_encoding
;
1239 /* Need to find 'R' or 'L' augmentation's argument and modify
1240 DW_EH_PE_* value. */
1241 action
= ((ent
->make_relative
? 1 : 0)
1242 | (ent
->need_lsda_relative
? 2 : 0)
1243 | (ent
->per_encoding_relative
? 4 : 0));
1244 extra_string
= extra_augmentation_string_bytes (ent
);
1245 extra_data
= extra_augmentation_data_bytes (ent
);
1247 /* Skip length, id and version. */
1250 buf
+= strlen (aug
) + 1;
1251 skip_leb128 (&buf
, end
);
1252 skip_leb128 (&buf
, end
);
1253 skip_leb128 (&buf
, end
);
1256 /* The uleb128 will always be a single byte for the kind
1257 of augmentation strings that we're prepared to handle. */
1258 *buf
++ += extra_data
;
1262 /* Make room for the new augmentation string and data bytes. */
1263 memmove (buf
+ extra_string
+ extra_data
, buf
, end
- buf
);
1264 memmove (aug
+ extra_string
, aug
, buf
- (bfd_byte
*) aug
);
1265 buf
+= extra_string
;
1266 end
+= extra_string
+ extra_data
;
1268 if (ent
->add_augmentation_size
)
1271 *buf
++ = extra_data
- 1;
1273 if (ent
->add_fde_encoding
)
1275 BFD_ASSERT (action
& 1);
1277 *buf
++ = DW_EH_PE_pcrel
;
1287 BFD_ASSERT (*buf
== ent
->lsda_encoding
);
1288 *buf
|= DW_EH_PE_pcrel
;
1294 per_encoding
= *buf
++;
1295 per_width
= get_DW_EH_PE_width (per_encoding
, ptr_size
);
1296 BFD_ASSERT (per_width
!= 0);
1297 BFD_ASSERT (((per_encoding
& 0x70) == DW_EH_PE_pcrel
)
1298 == ent
->per_encoding_relative
);
1299 if ((per_encoding
& 0xf0) == DW_EH_PE_aligned
)
1301 + ((buf
- contents
+ per_width
- 1)
1302 & ~((bfd_size_type
) per_width
- 1)));
1307 val
= read_value (abfd
, buf
, per_width
,
1308 get_DW_EH_PE_signed (per_encoding
));
1309 val
+= ent
->offset
- ent
->new_offset
;
1310 val
-= extra_string
+ extra_data
;
1311 write_value (abfd
, buf
, val
, per_width
);
1319 BFD_ASSERT (*buf
== ent
->fde_encoding
);
1320 *buf
|= DW_EH_PE_pcrel
;
1335 bfd_vma value
, address
;
1341 value
= ent
->new_offset
+ 4 - ent
->cie_inf
->new_offset
;
1342 bfd_put_32 (abfd
, value
, buf
);
1344 width
= get_DW_EH_PE_width (ent
->fde_encoding
, ptr_size
);
1345 value
= read_value (abfd
, buf
, width
,
1346 get_DW_EH_PE_signed (ent
->fde_encoding
));
1350 switch (ent
->fde_encoding
& 0xf0)
1352 case DW_EH_PE_indirect
:
1353 case DW_EH_PE_textrel
:
1354 BFD_ASSERT (hdr_info
== NULL
);
1356 case DW_EH_PE_datarel
:
1358 asection
*got
= bfd_get_section_by_name (abfd
, ".got");
1360 BFD_ASSERT (got
!= NULL
);
1361 address
+= got
->vma
;
1364 case DW_EH_PE_pcrel
:
1365 value
+= ent
->offset
- ent
->new_offset
;
1366 address
+= sec
->output_section
->vma
+ ent
->offset
+ 8;
1369 if (ent
->cie_inf
->make_relative
)
1370 value
-= sec
->output_section
->vma
+ ent
->new_offset
+ 8;
1371 write_value (abfd
, buf
, value
, width
);
1378 hdr_info
->array
[hdr_info
->array_count
].initial_loc
= address
;
1379 hdr_info
->array
[hdr_info
->array_count
++].fde
1380 = sec
->output_section
->vma
+ ent
->new_offset
;
1383 if ((ent
->lsda_encoding
& 0xf0) == DW_EH_PE_pcrel
1384 || ent
->cie_inf
->need_lsda_relative
)
1386 buf
+= ent
->lsda_offset
;
1387 width
= get_DW_EH_PE_width (ent
->lsda_encoding
, ptr_size
);
1388 value
= read_value (abfd
, buf
, width
,
1389 get_DW_EH_PE_signed (ent
->lsda_encoding
));
1392 if ((ent
->lsda_encoding
& 0xf0) == DW_EH_PE_pcrel
)
1393 value
+= ent
->offset
- ent
->new_offset
;
1394 else if (ent
->cie_inf
->need_lsda_relative
)
1395 value
-= (sec
->output_section
->vma
+ ent
->new_offset
+ 8
1396 + ent
->lsda_offset
);
1397 write_value (abfd
, buf
, value
, width
);
1400 else if (ent
->cie_inf
->add_augmentation_size
)
1402 /* Skip the PC and length and insert a zero byte for the
1403 augmentation size. */
1405 memmove (buf
+ 1, buf
, end
- buf
);
1411 /* Adjust DW_CFA_set_loc. */
1412 unsigned int cnt
, width
;
1415 width
= get_DW_EH_PE_width (ent
->fde_encoding
, ptr_size
);
1416 new_offset
= ent
->new_offset
+ 8
1417 + extra_augmentation_string_bytes (ent
)
1418 + extra_augmentation_data_bytes (ent
);
1420 for (cnt
= 1; cnt
<= ent
->set_loc
[0]; cnt
++)
1423 buf
= start
+ ent
->set_loc
[cnt
];
1425 value
= read_value (abfd
, buf
, width
,
1426 get_DW_EH_PE_signed (ent
->fde_encoding
));
1430 if ((ent
->fde_encoding
& 0xf0) == DW_EH_PE_pcrel
)
1431 value
+= ent
->offset
+ 8 - new_offset
;
1432 if (ent
->cie_inf
->make_relative
)
1433 value
-= sec
->output_section
->vma
+ new_offset
1434 + ent
->set_loc
[cnt
];
1435 write_value (abfd
, buf
, value
, width
);
1441 /* We don't align the section to its section alignment since the
1442 runtime library only expects all CIE/FDE records aligned at
1443 the pointer size. _bfd_elf_discard_section_eh_frame should
1444 have padded CIE/FDE records to multiple of pointer size with
1445 size_of_output_cie_fde. */
1446 if ((sec
->size
% ptr_size
) != 0)
1449 return bfd_set_section_contents (abfd
, sec
->output_section
,
1450 contents
, (file_ptr
) sec
->output_offset
,
1454 /* Helper function used to sort .eh_frame_hdr search table by increasing
1455 VMA of FDE initial location. */
1458 vma_compare (const void *a
, const void *b
)
1460 const struct eh_frame_array_ent
*p
= a
;
1461 const struct eh_frame_array_ent
*q
= b
;
1462 if (p
->initial_loc
> q
->initial_loc
)
1464 if (p
->initial_loc
< q
->initial_loc
)
1469 /* Write out .eh_frame_hdr section. This must be called after
1470 _bfd_elf_write_section_eh_frame has been called on all input
1472 .eh_frame_hdr format:
1473 ubyte version (currently 1)
1474 ubyte eh_frame_ptr_enc (DW_EH_PE_* encoding of pointer to start of
1476 ubyte fde_count_enc (DW_EH_PE_* encoding of total FDE count
1477 number (or DW_EH_PE_omit if there is no
1478 binary search table computed))
1479 ubyte table_enc (DW_EH_PE_* encoding of binary search table,
1480 or DW_EH_PE_omit if not present.
1481 DW_EH_PE_datarel is using address of
1482 .eh_frame_hdr section start as base)
1483 [encoded] eh_frame_ptr (pointer to start of .eh_frame section)
1484 optionally followed by:
1485 [encoded] fde_count (total number of FDEs in .eh_frame section)
1486 fde_count x [encoded] initial_loc, fde
1487 (array of encoded pairs containing
1488 FDE initial_location field and FDE address,
1489 sorted by increasing initial_loc). */
1492 _bfd_elf_write_section_eh_frame_hdr (bfd
*abfd
, struct bfd_link_info
*info
)
1494 struct elf_link_hash_table
*htab
;
1495 struct eh_frame_hdr_info
*hdr_info
;
1498 asection
*eh_frame_sec
;
1501 bfd_vma encoded_eh_frame
;
1503 htab
= elf_hash_table (info
);
1504 hdr_info
= &htab
->eh_info
;
1505 sec
= hdr_info
->hdr_sec
;
1509 size
= EH_FRAME_HDR_SIZE
;
1510 if (hdr_info
->array
&& hdr_info
->array_count
== hdr_info
->fde_count
)
1511 size
+= 4 + hdr_info
->fde_count
* 8;
1512 contents
= bfd_malloc (size
);
1513 if (contents
== NULL
)
1516 eh_frame_sec
= bfd_get_section_by_name (abfd
, ".eh_frame");
1517 if (eh_frame_sec
== NULL
)
1523 memset (contents
, 0, EH_FRAME_HDR_SIZE
);
1524 contents
[0] = 1; /* Version. */
1525 contents
[1] = get_elf_backend_data (abfd
)->elf_backend_encode_eh_address
1526 (abfd
, info
, eh_frame_sec
, 0, sec
, 4,
1527 &encoded_eh_frame
); /* .eh_frame offset. */
1529 if (hdr_info
->array
&& hdr_info
->array_count
== hdr_info
->fde_count
)
1531 contents
[2] = DW_EH_PE_udata4
; /* FDE count encoding. */
1532 contents
[3] = DW_EH_PE_datarel
| DW_EH_PE_sdata4
; /* Search table enc. */
1536 contents
[2] = DW_EH_PE_omit
;
1537 contents
[3] = DW_EH_PE_omit
;
1539 bfd_put_32 (abfd
, encoded_eh_frame
, contents
+ 4);
1541 if (contents
[2] != DW_EH_PE_omit
)
1545 bfd_put_32 (abfd
, hdr_info
->fde_count
, contents
+ EH_FRAME_HDR_SIZE
);
1546 qsort (hdr_info
->array
, hdr_info
->fde_count
, sizeof (*hdr_info
->array
),
1548 for (i
= 0; i
< hdr_info
->fde_count
; i
++)
1551 hdr_info
->array
[i
].initial_loc
1552 - sec
->output_section
->vma
,
1553 contents
+ EH_FRAME_HDR_SIZE
+ i
* 8 + 4);
1555 hdr_info
->array
[i
].fde
- sec
->output_section
->vma
,
1556 contents
+ EH_FRAME_HDR_SIZE
+ i
* 8 + 8);
1560 retval
= bfd_set_section_contents (abfd
, sec
->output_section
,
1561 contents
, (file_ptr
) sec
->output_offset
,
1567 /* Return the width of FDE addresses. This is the default implementation. */
1570 _bfd_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec ATTRIBUTE_UNUSED
)
1572 return elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
? 8 : 4;
1575 /* Decide whether we can use a PC-relative encoding within the given
1576 EH frame section. This is the default implementation. */
1579 _bfd_elf_can_make_relative (bfd
*input_bfd ATTRIBUTE_UNUSED
,
1580 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1581 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
1586 /* Select an encoding for the given address. Preference is given to
1587 PC-relative addressing modes. */
1590 _bfd_elf_encode_eh_address (bfd
*abfd ATTRIBUTE_UNUSED
,
1591 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1592 asection
*osec
, bfd_vma offset
,
1593 asection
*loc_sec
, bfd_vma loc_offset
,
1596 *encoded
= osec
->vma
+ offset
-
1597 (loc_sec
->output_section
->vma
+ loc_sec
->output_offset
+ loc_offset
);
1598 return DW_EH_PE_pcrel
| DW_EH_PE_sdata4
;