toolchain: binutils: backport patch to fix mipsel_24kc_24kf
[openwrt/staging/nbd.git] / toolchain / binutils / patches / 2.38 / 002-PR-30569-delete-_bfd_mips_elf_early_size_sections.patch
1 From 3c6c32951e292a51ede70b8087bb0308d7dbc4fc Mon Sep 17 00:00:00 2001
2 From: Alan Modra <amodra@gmail.com>
3 Date: Thu, 28 Mar 2024 20:33:32 +1030
4 Subject: [PATCH 2/2] PR 30569, delete _bfd_mips_elf_early_size_sections
5
6 PR30569 was triggered by a patch of mine 6540edd52cc0 moving the call
7 to always_size_sections in bfd_elf_size_dynamic_sections earlier, made
8 to support the x86 DT_RELR implementation. This broke mips16 code
9 handling stubs when --export-dynamic is passed to the linker, because
10 numerous symbols then became dynamic after always_size_sections. The
11 mips backend fiddles with symbols in its always_size_sections. Maciej
12 in 902e9fc76a0e had moved the call to always_size_sections to after
13 the export-dynamic code. Prior to that, Nathan in 04c3a75556c0 moved
14 it before the exec stack code, back to the start of
15 bfd_elf_size_dynamic_sections which was where Ian put it originally
16 in ff12f303355b. So the call has moved around a little. I'm leaving
17 it where it is, and instead calling mips_elf_check_symbols from
18 late_size_sections (the old size_dynamic_sections) which is now always
19 called. In fact, the whole of _bfd_mips_elf_early_size_sections can
20 be merged into _bfd_mips_elf_late_size_sections.
21 ---
22 bfd/elf32-mips.c | 1 -
23 bfd/elf64-mips.c | 2 --
24 bfd/elfn32-mips.c | 1 -
25 bfd/elfxx-mips.c | 84 +++++++++++++++++++----------------------------
26 bfd/elfxx-mips.h | 2 --
27 5 files changed, 34 insertions(+), 56 deletions(-)
28
29 --- a/bfd/elf32-mips.c
30 +++ b/bfd/elf32-mips.c
31 @@ -2526,7 +2526,6 @@ static const struct ecoff_debug_swap mip
32 #define elf_backend_get_target_dtag _bfd_mips_elf_get_target_dtag
33 #define elf_backend_adjust_dynamic_symbol \
34 _bfd_mips_elf_adjust_dynamic_symbol
35 -#define elf_backend_early_size_sections _bfd_mips_elf_early_size_sections
36 #define elf_backend_late_size_sections _bfd_mips_elf_late_size_sections
37 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
38 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
39 --- a/bfd/elf64-mips.c
40 +++ b/bfd/elf64-mips.c
41 @@ -4741,8 +4741,6 @@ const struct elf_size_info mips_elf64_si
42 #define elf_backend_get_target_dtag _bfd_mips_elf_get_target_dtag
43 #define elf_backend_adjust_dynamic_symbol \
44 _bfd_mips_elf_adjust_dynamic_symbol
45 -#define elf_backend_early_size_sections \
46 - _bfd_mips_elf_early_size_sections
47 #define elf_backend_late_size_sections \
48 _bfd_mips_elf_late_size_sections
49 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
50 --- a/bfd/elfn32-mips.c
51 +++ b/bfd/elfn32-mips.c
52 @@ -4127,7 +4127,6 @@ static const struct ecoff_debug_swap mip
53 #define elf_backend_get_target_dtag _bfd_mips_elf_get_target_dtag
54 #define elf_backend_adjust_dynamic_symbol \
55 _bfd_mips_elf_adjust_dynamic_symbol
56 -#define elf_backend_early_size_sections _bfd_mips_elf_early_size_sections
57 #define elf_backend_late_size_sections _bfd_mips_elf_late_size_sections
58 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
59 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
60 --- a/bfd/elfxx-mips.c
61 +++ b/bfd/elfxx-mips.c
62 @@ -9545,48 +9545,6 @@ _bfd_mips_elf_adjust_dynamic_symbol (str
63 return _bfd_elf_adjust_dynamic_copy (info, h, s);
64 }
65 \f
66 -/* This function is called after all the input files have been read,
67 - and the input sections have been assigned to output sections. We
68 - check for any mips16 stub sections that we can discard. */
69 -
70 -bool
71 -_bfd_mips_elf_early_size_sections (bfd *output_bfd,
72 - struct bfd_link_info *info)
73 -{
74 - asection *sect;
75 - struct mips_elf_link_hash_table *htab;
76 - struct mips_htab_traverse_info hti;
77 -
78 - htab = mips_elf_hash_table (info);
79 - BFD_ASSERT (htab != NULL);
80 -
81 - /* The .reginfo section has a fixed size. */
82 - sect = bfd_get_section_by_name (output_bfd, ".reginfo");
83 - if (sect != NULL)
84 - {
85 - bfd_set_section_size (sect, sizeof (Elf32_External_RegInfo));
86 - sect->flags |= SEC_FIXED_SIZE | SEC_HAS_CONTENTS;
87 - }
88 -
89 - /* The .MIPS.abiflags section has a fixed size. */
90 - sect = bfd_get_section_by_name (output_bfd, ".MIPS.abiflags");
91 - if (sect != NULL)
92 - {
93 - bfd_set_section_size (sect, sizeof (Elf_External_ABIFlags_v0));
94 - sect->flags |= SEC_FIXED_SIZE | SEC_HAS_CONTENTS;
95 - }
96 -
97 - hti.info = info;
98 - hti.output_bfd = output_bfd;
99 - hti.error = false;
100 - mips_elf_link_hash_traverse (mips_elf_hash_table (info),
101 - mips_elf_check_symbols, &hti);
102 - if (hti.error)
103 - return false;
104 -
105 - return true;
106 -}
107 -
108 /* If the link uses a GOT, lay it out and work out its size. */
109
110 static bool
111 @@ -9891,7 +9849,8 @@ mips_elf_set_plt_sym_value (struct mips_
112 return true;
113 }
114
115 -/* Set the sizes of the dynamic sections. */
116 +/* Set the sizes of the dynamic sections, some mips non-dynamic sections,
117 + and check for any mips16 stub sections that we can discard. */
118
119 bool
120 _bfd_mips_elf_late_size_sections (bfd *output_bfd,
121 @@ -9901,14 +9860,39 @@ _bfd_mips_elf_late_size_sections (bfd *o
122 asection *s, *sreldyn;
123 bool reltext;
124 struct mips_elf_link_hash_table *htab;
125 + struct mips_htab_traverse_info hti;
126
127 htab = mips_elf_hash_table (info);
128 BFD_ASSERT (htab != NULL);
129 - dynobj = elf_hash_table (info)->dynobj;
130 +
131 + /* The .reginfo section has a fixed size. */
132 + s = bfd_get_section_by_name (output_bfd, ".reginfo");
133 + if (s != NULL)
134 + {
135 + bfd_set_section_size (s, sizeof (Elf32_External_RegInfo));
136 + s->flags |= SEC_FIXED_SIZE | SEC_HAS_CONTENTS;
137 + }
138 +
139 + /* The .MIPS.abiflags section has a fixed size. */
140 + s = bfd_get_section_by_name (output_bfd, ".MIPS.abiflags");
141 + if (s != NULL)
142 + {
143 + bfd_set_section_size (s, sizeof (Elf_External_ABIFlags_v0));
144 + s->flags |= SEC_FIXED_SIZE | SEC_HAS_CONTENTS;
145 + }
146 +
147 + hti.info = info;
148 + hti.output_bfd = output_bfd;
149 + hti.error = false;
150 + mips_elf_link_hash_traverse (htab, mips_elf_check_symbols, &hti);
151 + if (hti.error)
152 + return false;
153 +
154 + dynobj = htab->root.dynobj;
155 if (dynobj == NULL)
156 return true;
157
158 - if (elf_hash_table (info)->dynamic_sections_created)
159 + if (htab->root.dynamic_sections_created)
160 {
161 /* Set the contents of the .interp section to the interpreter. */
162 if (bfd_link_executable (info) && !info->nointerp)
163 @@ -10048,7 +10032,7 @@ _bfd_mips_elf_late_size_sections (bfd *o
164 }
165 }
166 else if (bfd_link_executable (info)
167 - && ! mips_elf_hash_table (info)->use_rld_obj_head
168 + && !htab->use_rld_obj_head
169 && startswith (name, ".rld_map"))
170 {
171 /* We add a room for __rld_map. It will be filled in by the
172 @@ -10057,7 +10041,7 @@ _bfd_mips_elf_late_size_sections (bfd *o
173 }
174 else if (SGI_COMPAT (output_bfd)
175 && startswith (name, ".compact_rel"))
176 - s->size += mips_elf_hash_table (info)->compact_rel_size;
177 + s->size += htab->compact_rel_size;
178 else if (s == htab->root.splt)
179 {
180 /* If the last PLT entry has a branch delay slot, allocate
181 @@ -10097,7 +10081,7 @@ _bfd_mips_elf_late_size_sections (bfd *o
182 }
183 }
184
185 - if (elf_hash_table (info)->dynamic_sections_created)
186 + if (htab->root.dynamic_sections_created)
187 {
188 /* Add some entries to the .dynamic section. We fill in the
189 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
190 @@ -14825,7 +14809,7 @@ _bfd_mips_elf_final_link (bfd *abfd, str
191 input_section->flags &= ~SEC_HAS_CONTENTS;
192 }
193
194 - /* Size has been set in _bfd_mips_elf_early_size_sections. */
195 + /* Size has been set in _bfd_mips_elf_late_size_sections. */
196 BFD_ASSERT(o->size == sizeof (Elf_External_ABIFlags_v0));
197
198 /* Skip this section later on (I don't think this currently
199 @@ -14884,7 +14868,7 @@ _bfd_mips_elf_final_link (bfd *abfd, str
200 input_section->flags &= ~SEC_HAS_CONTENTS;
201 }
202
203 - /* Size has been set in _bfd_mips_elf_early_size_sections. */
204 + /* Size has been set in _bfd_mips_elf_late_size_sections. */
205 BFD_ASSERT(o->size == sizeof (Elf32_External_RegInfo));
206
207 /* Skip this section later on (I don't think this currently
208 --- a/bfd/elfxx-mips.h
209 +++ b/bfd/elfxx-mips.h
210 @@ -52,8 +52,6 @@ extern bool _bfd_mips_elf_check_relocs
211 (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
212 extern bool _bfd_mips_elf_adjust_dynamic_symbol
213 (struct bfd_link_info *, struct elf_link_hash_entry *);
214 -extern bool _bfd_mips_elf_early_size_sections
215 - (bfd *, struct bfd_link_info *);
216 extern bool _bfd_mips_elf_late_size_sections
217 (bfd *, struct bfd_link_info *);
218 extern int _bfd_mips_elf_relocate_section