1 From 5b69e3572d1ee8e8e6e1991fd07f87a96c48746d Mon Sep 17 00:00:00 2001
2 From: Alan Modra <amodra@gmail.com>
3 Date: Mon, 13 Oct 2014 15:18:21 +1030
4 Subject: [PATCH] Run eh_frame optimisation for relocatable link
6 The idea here is to drop .eh_frame FDEs corresponding to dropped
7 comdat group sections or linkonce sections, but not perform changes in
12 * elf-eh-frame.c (ENSURE_NO_RELOCS): Don't stop at first NONE reloc.
13 (_bfd_elf_parse_eh_frame): When relocatable output, don't set
14 flags enabling conversion of CIEs and FDEs to use relative encoding.
15 (find_merged_cie): Similarly.
16 (_bfd_elf_write_section_eh_frame): Don't edit FDEs when
17 relocatable, except for CIE pointer.
18 * elflink.c (bfd_elf_reloc_symbol_deleted_p): Return true for
19 relocs against symbols in dropped comdat group sections.
20 (bfd_elf_discard_info): Do some eh_frame optimisation when
23 * ldlang.c (lang_add_section): Set up map_head.s and map_tail.s when
26 bfd/ChangeLog | 14 ++++++++++++++
27 bfd/elf-eh-frame.c | 25 +++++++++++++++++--------
28 bfd/elflink.c | 14 +++++++-------
29 ld/ChangeLog | 5 +++++
31 5 files changed, 44 insertions(+), 17 deletions(-)
33 diff --git a/bfd/ChangeLog b/bfd/ChangeLog
34 index aa2f3ef..be3ae38 100644
38 +2014-10-13 Alan Modra <amodra@gmail.com>
41 + * elf-eh-frame.c (ENSURE_NO_RELOCS): Don't stop at first NONE reloc.
42 + (_bfd_elf_parse_eh_frame): When relocatable output, don't set
43 + flags enabling conversion of CIEs and FDEs to use relative encoding.
44 + (find_merged_cie): Similarly.
45 + (_bfd_elf_write_section_eh_frame): Don't edit FDEs when
46 + relocatable, except for CIE pointer.
47 + * elflink.c (bfd_elf_reloc_symbol_deleted_p): Return true for
48 + relocs against symbols in dropped comdat group sections.
49 + (bfd_elf_discard_info): Do some eh_frame optimisation when
52 2014-10-04 Alan Modra <amodra@gmail.com>
55 diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
56 index 331570a..e481f34 100644
57 --- a/bfd/elf-eh-frame.c
58 +++ b/bfd/elf-eh-frame.c
59 @@ -556,10 +556,13 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info,
61 /* FIXME: octets_per_byte. */
62 #define ENSURE_NO_RELOCS(buf) \
63 - REQUIRE (!(cookie->rel < cookie->relend \
64 - && (cookie->rel->r_offset \
65 - < (bfd_size_type) ((buf) - ehbuf)) \
66 - && cookie->rel->r_info != 0))
67 + while (cookie->rel < cookie->relend \
68 + && (cookie->rel->r_offset \
69 + < (bfd_size_type) ((buf) - ehbuf))) \
71 + REQUIRE (cookie->rel->r_info == 0); \
75 /* FIXME: octets_per_byte. */
76 #define SKIP_RELOCS(buf) \
77 @@ -726,6 +729,7 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info,
78 /* For shared libraries, try to get rid of as many RELATIVE relocs
81 + && !info->relocatable
82 && (get_elf_backend_data (abfd)
83 ->elf_backend_can_make_relative_eh_frame
85 @@ -763,10 +767,12 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info,
86 ENSURE_NO_RELOCS (buf);
88 if (!info->relocatable)
89 - /* Keep info for merging cies. */
90 - this_inf->u.cie.u.full_cie = cie;
91 - this_inf->u.cie.per_encoding_relative
92 - = (cie->per_encoding & 0x70) == DW_EH_PE_pcrel;
94 + /* Keep info for merging cies. */
95 + this_inf->u.cie.u.full_cie = cie;
96 + this_inf->u.cie.per_encoding_relative
97 + = (cie->per_encoding & 0x70) == DW_EH_PE_pcrel;
102 @@ -1071,6 +1077,7 @@ find_merged_cie (bfd *abfd, struct bfd_link_info *info, asection *sec,
106 + && !info->relocatable
107 && (cie->per_encoding & 0x70) == DW_EH_PE_absptr
108 && (get_elf_backend_data (abfd)
109 ->elf_backend_can_make_relative_eh_frame (abfd, info, sec)))
110 @@ -1577,6 +1584,8 @@ _bfd_elf_write_section_eh_frame (bfd *abfd,
111 value = ((ent->new_offset + sec->output_offset + 4)
112 - (cie->new_offset + cie->u.cie.u.sec->output_offset));
113 bfd_put_32 (abfd, value, buf);
114 + if (info->relocatable)
117 width = get_DW_EH_PE_width (ent->fde_encoding, ptr_size);
118 value = read_value (abfd, buf, width,
119 diff --git a/bfd/elflink.c b/bfd/elflink.c
120 index d33efe0..c8068c0 100644
123 @@ -12602,10 +12602,10 @@ bfd_elf_reloc_symbol_deleted_p (bfd_vma offset, void *cookie)
125 if ((h->root.type == bfd_link_hash_defined
126 || h->root.type == bfd_link_hash_defweak)
127 - && discarded_section (h->root.u.def.section))
128 + && (h->root.u.def.section->owner != rcookie->abfd
129 + || h->root.u.def.section->kept_section != NULL
130 + || discarded_section (h->root.u.def.section)))
137 @@ -12618,7 +12618,9 @@ bfd_elf_reloc_symbol_deleted_p (bfd_vma offset, void *cookie)
138 /* Need to: get the symbol; get the section. */
139 isym = &rcookie->locsyms[r_symndx];
140 isec = bfd_section_from_elf_index (rcookie->abfd, isym->st_shndx);
141 - if (isec != NULL && discarded_section (isec))
143 + && (isec->kept_section != NULL
144 + || discarded_section (isec)))
148 @@ -12672,9 +12674,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
153 - if (!info->relocatable)
154 - o = bfd_get_section_by_name (output_bfd, ".eh_frame");
155 + o = bfd_get_section_by_name (output_bfd, ".eh_frame");
159 diff --git a/ld/ChangeLog b/ld/ChangeLog
160 index ca27cc2..effacb0 100644
164 +2014-10-13 Alan Modra <amodra@gmail.com>
166 + * ldlang.c (lang_add_section): Set up map_head.s and map_tail.s when
169 2014-09-16 Kuan-Lin Chen <kuanlinchentw@gmail.com>
171 * emultempl/nds32elf.em (nds32_elf_after_open): Do not keep
172 diff --git a/ld/ldlang.c b/ld/ldlang.c
173 index 899f710..5960e5c 100644
176 @@ -2411,8 +2411,7 @@ lang_add_section (lang_statement_list_type *ptr,
178 section->output_section = output->bfd_section;
180 - if (!link_info.relocatable
181 - && !map_head_is_link_order)
182 + if (!map_head_is_link_order)
184 asection *s = output->bfd_section->map_tail.s;
185 output->bfd_section->map_tail.s = section;