]>
Commit | Line | Data |
---|---|---|
4e5ba5b7 | 1 | /* FRV-specific support for 32-bit ELF. |
66eb6687 | 2 | Copyright 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
4e5ba5b7 DB |
3 | |
4 | This file is part of BFD, the Binary File Descriptor library. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
3e110533 | 18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
4e5ba5b7 DB |
19 | |
20 | #include "bfd.h" | |
21 | #include "sysdep.h" | |
22 | #include "libbfd.h" | |
23 | #include "elf-bfd.h" | |
24 | #include "elf/frv.h" | |
ec3391e7 | 25 | #include "elf/dwarf2.h" |
51532845 | 26 | #include "hashtab.h" |
4e5ba5b7 DB |
27 | |
28 | /* Forward declarations. */ | |
29 | static bfd_reloc_status_type elf32_frv_relocate_lo16 | |
30 | PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
31 | static bfd_reloc_status_type elf32_frv_relocate_hi16 | |
32 | PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
33 | static bfd_reloc_status_type elf32_frv_relocate_label24 | |
34 | PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
35 | static bfd_reloc_status_type elf32_frv_relocate_gprel12 | |
b34976b6 AM |
36 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
37 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 | 38 | static bfd_reloc_status_type elf32_frv_relocate_gprelu12 |
b34976b6 AM |
39 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
40 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 | 41 | static bfd_reloc_status_type elf32_frv_relocate_gprello |
b34976b6 AM |
42 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
43 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 | 44 | static bfd_reloc_status_type elf32_frv_relocate_gprelhi |
b34976b6 AM |
45 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
46 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 DB |
47 | static reloc_howto_type *frv_reloc_type_lookup |
48 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
b34976b6 | 49 | static void frv_info_to_howto_rela |
947216bf | 50 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
b34976b6 AM |
51 | static bfd_boolean elf32_frv_relocate_section |
52 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
53 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
54 | static bfd_boolean elf32_frv_add_symbol_hook | |
555cd476 | 55 | PARAMS (( bfd *, struct bfd_link_info *, Elf_Internal_Sym *, |
b34976b6 | 56 | const char **, flagword *, asection **, bfd_vma *)); |
4e5ba5b7 | 57 | static bfd_reloc_status_type frv_final_link_relocate |
b34976b6 AM |
58 | PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, |
59 | Elf_Internal_Rela *, bfd_vma)); | |
60 | static bfd_boolean elf32_frv_gc_sweep_hook | |
61 | PARAMS ((bfd *, struct bfd_link_info *, asection *, const | |
62 | Elf_Internal_Rela *)); | |
4e5ba5b7 | 63 | static asection * elf32_frv_gc_mark_hook |
b34976b6 AM |
64 | PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
65 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | |
66 | static bfd_boolean elf32_frv_check_relocs | |
67 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
68 | const Elf_Internal_Rela *)); | |
69 | static int elf32_frv_machine | |
70 | PARAMS ((bfd *)); | |
71 | static bfd_boolean elf32_frv_object_p | |
72 | PARAMS ((bfd *)); | |
73 | static bfd_boolean frv_elf_set_private_flags | |
74 | PARAMS ((bfd *, flagword)); | |
75 | static bfd_boolean frv_elf_copy_private_bfd_data | |
76 | PARAMS ((bfd *, bfd *)); | |
77 | static bfd_boolean frv_elf_merge_private_bfd_data | |
78 | PARAMS ((bfd *, bfd *)); | |
79 | static bfd_boolean frv_elf_print_private_bfd_data | |
80 | PARAMS ((bfd *, PTR)); | |
888b45b8 KB |
81 | static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd, |
82 | Elf_Internal_Note * note); | |
83 | static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd, | |
84 | Elf_Internal_Note * note); | |
4e5ba5b7 DB |
85 | |
86 | static reloc_howto_type elf32_frv_howto_table [] = | |
87 | { | |
88 | /* This reloc does nothing. */ | |
89 | HOWTO (R_FRV_NONE, /* type */ | |
90 | 0, /* rightshift */ | |
91 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
92 | 32, /* bitsize */ | |
b34976b6 | 93 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
94 | 0, /* bitpos */ |
95 | complain_overflow_bitfield, /* complain_on_overflow */ | |
96 | bfd_elf_generic_reloc, /* special_function */ | |
97 | "R_FRV_NONE", /* name */ | |
b34976b6 | 98 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
99 | 0, /* src_mask */ |
100 | 0, /* dst_mask */ | |
b34976b6 | 101 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
102 | |
103 | /* A 32 bit absolute relocation. */ | |
104 | HOWTO (R_FRV_32, /* type */ | |
105 | 0, /* rightshift */ | |
106 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
107 | 32, /* bitsize */ | |
b34976b6 | 108 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
109 | 0, /* bitpos */ |
110 | complain_overflow_bitfield, /* complain_on_overflow */ | |
111 | bfd_elf_generic_reloc, /* special_function */ | |
112 | "R_FRV_32", /* name */ | |
b34976b6 | 113 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
114 | 0xffffffff, /* src_mask */ |
115 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 116 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
117 | |
118 | /* A 16 bit pc-relative relocation. */ | |
3b36f7e6 | 119 | HOWTO (R_FRV_LABEL16, /* type */ |
b15b52ef | 120 | 2, /* rightshift */ |
4e5ba5b7 DB |
121 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
122 | 16, /* bitsize */ | |
b34976b6 | 123 | TRUE, /* pc_relative */ |
4e5ba5b7 | 124 | 0, /* bitpos */ |
e6deed0a | 125 | complain_overflow_signed, /* complain_on_overflow */ |
4e5ba5b7 DB |
126 | bfd_elf_generic_reloc, /* special_function */ |
127 | "R_FRV_LABEL16", /* name */ | |
b34976b6 | 128 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
129 | 0xffff, /* src_mask */ |
130 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 131 | TRUE), /* pcrel_offset */ |
4e5ba5b7 DB |
132 | |
133 | /* A 24-bit pc-relative relocation. */ | |
3b36f7e6 | 134 | HOWTO (R_FRV_LABEL24, /* type */ |
4e5ba5b7 DB |
135 | 2, /* rightshift */ |
136 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
137 | 26, /* bitsize */ | |
b34976b6 | 138 | TRUE, /* pc_relative */ |
4e5ba5b7 DB |
139 | 0, /* bitpos */ |
140 | complain_overflow_bitfield, /* complain_on_overflow */ | |
141 | bfd_elf_generic_reloc, /* special_function */ | |
142 | "R_FRV_LABEL24", /* name */ | |
b34976b6 | 143 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
144 | 0x7e03ffff, /* src_mask */ |
145 | 0x7e03ffff, /* dst_mask */ | |
3b36f7e6 | 146 | TRUE), /* pcrel_offset */ |
4e5ba5b7 | 147 | |
3b36f7e6 | 148 | HOWTO (R_FRV_LO16, /* type */ |
4e5ba5b7 DB |
149 | 0, /* rightshift */ |
150 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
151 | 16, /* bitsize */ | |
b34976b6 | 152 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
153 | 0, /* bitpos */ |
154 | complain_overflow_dont, /* complain_on_overflow */ | |
155 | bfd_elf_generic_reloc, /* special_function */ | |
156 | "R_FRV_LO16", /* name */ | |
b34976b6 | 157 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
158 | 0xffff, /* src_mask */ |
159 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 160 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 161 | |
3b36f7e6 | 162 | HOWTO (R_FRV_HI16, /* type */ |
4e5ba5b7 DB |
163 | 0, /* rightshift */ |
164 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
165 | 16, /* bitsize */ | |
b34976b6 | 166 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
167 | 0, /* bitpos */ |
168 | complain_overflow_dont, /* complain_on_overflow */ | |
169 | bfd_elf_generic_reloc, /* special_function */ | |
170 | "R_FRV_HI16", /* name */ | |
b34976b6 | 171 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
172 | 0xffff, /* src_mask */ |
173 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 174 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 175 | |
3b36f7e6 | 176 | HOWTO (R_FRV_GPREL12, /* type */ |
4e5ba5b7 DB |
177 | 0, /* rightshift */ |
178 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
179 | 12, /* bitsize */ | |
b34976b6 | 180 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
181 | 0, /* bitpos */ |
182 | complain_overflow_dont, /* complain_on_overflow */ | |
183 | bfd_elf_generic_reloc, /* special_function */ | |
3b36f7e6 | 184 | "R_FRV_GPREL12", /* name */ |
b34976b6 | 185 | FALSE, /* partial_inplace */ |
3b36f7e6 AM |
186 | 0xfff, /* src_mask */ |
187 | 0xfff, /* dst_mask */ | |
188 | FALSE), /* pcrel_offset */ | |
4e5ba5b7 | 189 | |
3b36f7e6 | 190 | HOWTO (R_FRV_GPRELU12, /* type */ |
4e5ba5b7 DB |
191 | 0, /* rightshift */ |
192 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
193 | 12, /* bitsize */ | |
b34976b6 | 194 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
195 | 0, /* bitpos */ |
196 | complain_overflow_dont, /* complain_on_overflow */ | |
197 | bfd_elf_generic_reloc, /* special_function */ | |
3b36f7e6 | 198 | "R_FRV_GPRELU12", /* name */ |
b34976b6 | 199 | FALSE, /* partial_inplace */ |
3b36f7e6 AM |
200 | 0xfff, /* src_mask */ |
201 | 0x3f03f, /* dst_mask */ | |
202 | FALSE), /* pcrel_offset */ | |
4e5ba5b7 | 203 | |
3b36f7e6 | 204 | HOWTO (R_FRV_GPREL32, /* type */ |
4e5ba5b7 DB |
205 | 0, /* rightshift */ |
206 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
207 | 32, /* bitsize */ | |
b34976b6 | 208 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
209 | 0, /* bitpos */ |
210 | complain_overflow_dont, /* complain_on_overflow */ | |
211 | bfd_elf_generic_reloc, /* special_function */ | |
212 | "R_FRV_GPREL32", /* name */ | |
b34976b6 | 213 | FALSE, /* partial_inplace */ |
3b36f7e6 | 214 | 0xffffffff, /* src_mask */ |
4e5ba5b7 | 215 | 0xffffffff, /* dst_mask */ |
3b36f7e6 | 216 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 217 | |
3b36f7e6 | 218 | HOWTO (R_FRV_GPRELHI, /* type */ |
4e5ba5b7 DB |
219 | 0, /* rightshift */ |
220 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
221 | 16, /* bitsize */ | |
b34976b6 | 222 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
223 | 0, /* bitpos */ |
224 | complain_overflow_dont, /* complain_on_overflow */ | |
225 | bfd_elf_generic_reloc, /* special_function */ | |
226 | "R_FRV_GPRELHI", /* name */ | |
b34976b6 | 227 | FALSE, /* partial_inplace */ |
3b36f7e6 | 228 | 0xffff, /* src_mask */ |
4e5ba5b7 | 229 | 0xffff, /* dst_mask */ |
3b36f7e6 | 230 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 231 | |
3b36f7e6 | 232 | HOWTO (R_FRV_GPRELLO, /* type */ |
4e5ba5b7 DB |
233 | 0, /* rightshift */ |
234 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
235 | 16, /* bitsize */ | |
b34976b6 | 236 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
237 | 0, /* bitpos */ |
238 | complain_overflow_dont, /* complain_on_overflow */ | |
239 | bfd_elf_generic_reloc, /* special_function */ | |
240 | "R_FRV_GPRELLO", /* name */ | |
b34976b6 | 241 | FALSE, /* partial_inplace */ |
3b36f7e6 | 242 | 0xffff, /* src_mask */ |
4e5ba5b7 | 243 | 0xffff, /* dst_mask */ |
3b36f7e6 | 244 | FALSE), /* pcrel_offset */ |
51532845 AO |
245 | |
246 | /* A 12-bit signed operand with the GOT offset for the address of | |
247 | the symbol. */ | |
3b36f7e6 | 248 | HOWTO (R_FRV_GOT12, /* type */ |
51532845 AO |
249 | 0, /* rightshift */ |
250 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
251 | 12, /* bitsize */ | |
252 | FALSE, /* pc_relative */ | |
253 | 0, /* bitpos */ | |
254 | complain_overflow_signed, /* complain_on_overflow */ | |
255 | bfd_elf_generic_reloc, /* special_function */ | |
256 | "R_FRV_GOT12", /* name */ | |
257 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
258 | 0xfff, /* src_mask */ |
259 | 0xfff, /* dst_mask */ | |
260 | FALSE), /* pcrel_offset */ | |
51532845 AO |
261 | |
262 | /* The upper 16 bits of the GOT offset for the address of the | |
263 | symbol. */ | |
3b36f7e6 | 264 | HOWTO (R_FRV_GOTHI, /* type */ |
51532845 AO |
265 | 0, /* rightshift */ |
266 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
267 | 16, /* bitsize */ | |
268 | FALSE, /* pc_relative */ | |
269 | 0, /* bitpos */ | |
270 | complain_overflow_dont, /* complain_on_overflow */ | |
271 | bfd_elf_generic_reloc, /* special_function */ | |
272 | "R_FRV_GOTHI", /* name */ | |
273 | FALSE, /* partial_inplace */ | |
3b36f7e6 | 274 | 0xffff, /* src_mask */ |
51532845 | 275 | 0xffff, /* dst_mask */ |
3b36f7e6 | 276 | FALSE), /* pcrel_offset */ |
51532845 AO |
277 | |
278 | /* The lower 16 bits of the GOT offset for the address of the | |
279 | symbol. */ | |
3b36f7e6 | 280 | HOWTO (R_FRV_GOTLO, /* type */ |
51532845 AO |
281 | 0, /* rightshift */ |
282 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
283 | 16, /* bitsize */ | |
284 | FALSE, /* pc_relative */ | |
285 | 0, /* bitpos */ | |
286 | complain_overflow_dont, /* complain_on_overflow */ | |
287 | bfd_elf_generic_reloc, /* special_function */ | |
288 | "R_FRV_GOTLO", /* name */ | |
289 | FALSE, /* partial_inplace */ | |
290 | 0xffff, /* src_mask */ | |
291 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 292 | FALSE), /* pcrel_offset */ |
51532845 AO |
293 | |
294 | /* The 32-bit address of the canonical descriptor of a function. */ | |
295 | HOWTO (R_FRV_FUNCDESC, /* type */ | |
296 | 0, /* rightshift */ | |
297 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
298 | 32, /* bitsize */ | |
299 | FALSE, /* pc_relative */ | |
300 | 0, /* bitpos */ | |
301 | complain_overflow_bitfield, /* complain_on_overflow */ | |
302 | bfd_elf_generic_reloc, /* special_function */ | |
303 | "R_FRV_FUNCDESC", /* name */ | |
304 | FALSE, /* partial_inplace */ | |
305 | 0xffffffff, /* src_mask */ | |
306 | 0xffffffff, /* dst_mask */ | |
307 | FALSE), /* pcrel_offset */ | |
308 | ||
309 | /* A 12-bit signed operand with the GOT offset for the address of | |
310 | canonical descriptor of a function. */ | |
311 | HOWTO (R_FRV_FUNCDESC_GOT12, /* type */ | |
312 | 0, /* rightshift */ | |
313 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
314 | 12, /* bitsize */ | |
315 | FALSE, /* pc_relative */ | |
316 | 0, /* bitpos */ | |
317 | complain_overflow_signed, /* complain_on_overflow */ | |
318 | bfd_elf_generic_reloc, /* special_function */ | |
319 | "R_FRV_FUNCDESC_GOT12", /* name */ | |
320 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
321 | 0xfff, /* src_mask */ |
322 | 0xfff, /* dst_mask */ | |
323 | FALSE), /* pcrel_offset */ | |
51532845 AO |
324 | |
325 | /* The upper 16 bits of the GOT offset for the address of the | |
326 | canonical descriptor of a function. */ | |
327 | HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */ | |
328 | 0, /* rightshift */ | |
329 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
330 | 16, /* bitsize */ | |
331 | FALSE, /* pc_relative */ | |
332 | 0, /* bitpos */ | |
333 | complain_overflow_dont, /* complain_on_overflow */ | |
334 | bfd_elf_generic_reloc, /* special_function */ | |
335 | "R_FRV_FUNCDESC_GOTHI", /* name */ | |
336 | FALSE, /* partial_inplace */ | |
337 | 0xffff, /* src_mask */ | |
338 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 339 | FALSE), /* pcrel_offset */ |
51532845 AO |
340 | |
341 | /* The lower 16 bits of the GOT offset for the address of the | |
342 | canonical descriptor of a function. */ | |
343 | HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */ | |
344 | 0, /* rightshift */ | |
345 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
346 | 16, /* bitsize */ | |
347 | FALSE, /* pc_relative */ | |
348 | 0, /* bitpos */ | |
349 | complain_overflow_dont, /* complain_on_overflow */ | |
350 | bfd_elf_generic_reloc, /* special_function */ | |
351 | "R_FRV_FUNCDESC_GOTLO", /* name */ | |
352 | FALSE, /* partial_inplace */ | |
353 | 0xffff, /* src_mask */ | |
354 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 355 | FALSE), /* pcrel_offset */ |
51532845 | 356 | |
90219bd0 | 357 | /* The 64-bit descriptor of a function. */ |
51532845 AO |
358 | HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ |
359 | 0, /* rightshift */ | |
360 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
361 | 64, /* bitsize */ | |
362 | FALSE, /* pc_relative */ | |
363 | 0, /* bitpos */ | |
364 | complain_overflow_bitfield, /* complain_on_overflow */ | |
365 | bfd_elf_generic_reloc, /* special_function */ | |
366 | "R_FRV_FUNCDESC_VALUE", /* name */ | |
367 | FALSE, /* partial_inplace */ | |
368 | 0xffffffff, /* src_mask */ | |
369 | 0xffffffff, /* dst_mask */ | |
370 | FALSE), /* pcrel_offset */ | |
371 | ||
372 | /* A 12-bit signed operand with the GOT offset for the address of | |
373 | canonical descriptor of a function. */ | |
374 | HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */ | |
375 | 0, /* rightshift */ | |
376 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
377 | 12, /* bitsize */ | |
378 | FALSE, /* pc_relative */ | |
379 | 0, /* bitpos */ | |
380 | complain_overflow_signed, /* complain_on_overflow */ | |
381 | bfd_elf_generic_reloc, /* special_function */ | |
382 | "R_FRV_FUNCDESC_GOTOFF12", /* name */ | |
383 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
384 | 0xfff, /* src_mask */ |
385 | 0xfff, /* dst_mask */ | |
386 | FALSE), /* pcrel_offset */ | |
51532845 AO |
387 | |
388 | /* The upper 16 bits of the GOT offset for the address of the | |
389 | canonical descriptor of a function. */ | |
390 | HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */ | |
391 | 0, /* rightshift */ | |
392 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
393 | 16, /* bitsize */ | |
394 | FALSE, /* pc_relative */ | |
395 | 0, /* bitpos */ | |
396 | complain_overflow_dont, /* complain_on_overflow */ | |
397 | bfd_elf_generic_reloc, /* special_function */ | |
398 | "R_FRV_FUNCDESC_GOTOFFHI", /* name */ | |
399 | FALSE, /* partial_inplace */ | |
400 | 0xffff, /* src_mask */ | |
401 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 402 | FALSE), /* pcrel_offset */ |
51532845 AO |
403 | |
404 | /* The lower 16 bits of the GOT offset for the address of the | |
405 | canonical descriptor of a function. */ | |
406 | HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */ | |
407 | 0, /* rightshift */ | |
408 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
409 | 16, /* bitsize */ | |
410 | FALSE, /* pc_relative */ | |
411 | 0, /* bitpos */ | |
412 | complain_overflow_dont, /* complain_on_overflow */ | |
413 | bfd_elf_generic_reloc, /* special_function */ | |
414 | "R_FRV_FUNCDESC_GOTOFFLO", /* name */ | |
415 | FALSE, /* partial_inplace */ | |
416 | 0xffff, /* src_mask */ | |
417 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 418 | FALSE), /* pcrel_offset */ |
51532845 AO |
419 | |
420 | /* A 12-bit signed operand with the GOT offset for the address of | |
421 | the symbol. */ | |
3b36f7e6 | 422 | HOWTO (R_FRV_GOTOFF12, /* type */ |
51532845 AO |
423 | 0, /* rightshift */ |
424 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
425 | 12, /* bitsize */ | |
426 | FALSE, /* pc_relative */ | |
427 | 0, /* bitpos */ | |
428 | complain_overflow_signed, /* complain_on_overflow */ | |
429 | bfd_elf_generic_reloc, /* special_function */ | |
430 | "R_FRV_GOTOFF12", /* name */ | |
431 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
432 | 0xfff, /* src_mask */ |
433 | 0xfff, /* dst_mask */ | |
434 | FALSE), /* pcrel_offset */ | |
51532845 AO |
435 | |
436 | /* The upper 16 bits of the GOT offset for the address of the | |
437 | symbol. */ | |
3b36f7e6 | 438 | HOWTO (R_FRV_GOTOFFHI, /* type */ |
51532845 AO |
439 | 0, /* rightshift */ |
440 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
441 | 16, /* bitsize */ | |
442 | FALSE, /* pc_relative */ | |
443 | 0, /* bitpos */ | |
444 | complain_overflow_dont, /* complain_on_overflow */ | |
445 | bfd_elf_generic_reloc, /* special_function */ | |
446 | "R_FRV_GOTOFFHI", /* name */ | |
447 | FALSE, /* partial_inplace */ | |
448 | 0xffff, /* src_mask */ | |
449 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 450 | FALSE), /* pcrel_offset */ |
51532845 AO |
451 | |
452 | /* The lower 16 bits of the GOT offset for the address of the | |
453 | symbol. */ | |
454 | HOWTO (R_FRV_GOTOFFLO, /* type */ | |
455 | 0, /* rightshift */ | |
456 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
457 | 16, /* bitsize */ | |
458 | FALSE, /* pc_relative */ | |
459 | 0, /* bitpos */ | |
460 | complain_overflow_dont, /* complain_on_overflow */ | |
461 | bfd_elf_generic_reloc, /* special_function */ | |
462 | "R_FRV_GOTOFFLO", /* name */ | |
463 | FALSE, /* partial_inplace */ | |
464 | 0xffff, /* src_mask */ | |
465 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 466 | FALSE), /* pcrel_offset */ |
51532845 | 467 | |
90219bd0 AO |
468 | /* A 24-bit pc-relative relocation referencing the TLS PLT entry for |
469 | a thread-local symbol. If the symbol number is 0, it refers to | |
470 | the module. */ | |
471 | HOWTO (R_FRV_GETTLSOFF, /* type */ | |
472 | 2, /* rightshift */ | |
473 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
474 | 26, /* bitsize */ | |
475 | TRUE, /* pc_relative */ | |
476 | 0, /* bitpos */ | |
477 | complain_overflow_bitfield, /* complain_on_overflow */ | |
478 | bfd_elf_generic_reloc, /* special_function */ | |
479 | "R_FRV_GETTLSOFF", /* name */ | |
480 | FALSE, /* partial_inplace */ | |
481 | 0x7e03ffff, /* src_mask */ | |
482 | 0x7e03ffff, /* dst_mask */ | |
3b36f7e6 | 483 | TRUE), /* pcrel_offset */ |
90219bd0 AO |
484 | |
485 | /* A 64-bit TLS descriptor for a symbol. This relocation is only | |
486 | valid as a REL, dynamic relocation. */ | |
487 | HOWTO (R_FRV_TLSDESC_VALUE, /* type */ | |
488 | 0, /* rightshift */ | |
489 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
490 | 64, /* bitsize */ | |
491 | FALSE, /* pc_relative */ | |
492 | 0, /* bitpos */ | |
493 | complain_overflow_bitfield, /* complain_on_overflow */ | |
494 | bfd_elf_generic_reloc, /* special_function */ | |
495 | "R_FRV_TLSDESC_VALUE", /* name */ | |
496 | FALSE, /* partial_inplace */ | |
497 | 0xffffffff, /* src_mask */ | |
498 | 0xffffffff, /* dst_mask */ | |
499 | FALSE), /* pcrel_offset */ | |
500 | ||
501 | /* A 12-bit signed operand with the GOT offset for the TLS | |
502 | descriptor of the symbol. */ | |
3b36f7e6 | 503 | HOWTO (R_FRV_GOTTLSDESC12, /* type */ |
90219bd0 AO |
504 | 0, /* rightshift */ |
505 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
506 | 12, /* bitsize */ | |
507 | FALSE, /* pc_relative */ | |
508 | 0, /* bitpos */ | |
509 | complain_overflow_signed, /* complain_on_overflow */ | |
510 | bfd_elf_generic_reloc, /* special_function */ | |
511 | "R_FRV_GOTTLSDESC12", /* name */ | |
512 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
513 | 0xfff, /* src_mask */ |
514 | 0xfff, /* dst_mask */ | |
515 | FALSE), /* pcrel_offset */ | |
90219bd0 AO |
516 | |
517 | /* The upper 16 bits of the GOT offset for the TLS descriptor of the | |
518 | symbol. */ | |
3b36f7e6 | 519 | HOWTO (R_FRV_GOTTLSDESCHI, /* type */ |
90219bd0 AO |
520 | 0, /* rightshift */ |
521 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
522 | 16, /* bitsize */ | |
523 | FALSE, /* pc_relative */ | |
524 | 0, /* bitpos */ | |
525 | complain_overflow_dont, /* complain_on_overflow */ | |
526 | bfd_elf_generic_reloc, /* special_function */ | |
527 | "R_FRV_GOTTLSDESCHI", /* name */ | |
528 | FALSE, /* partial_inplace */ | |
529 | 0xffff, /* src_mask */ | |
530 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 531 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
532 | |
533 | /* The lower 16 bits of the GOT offset for the TLS descriptor of the | |
534 | symbol. */ | |
535 | HOWTO (R_FRV_GOTTLSDESCLO, /* type */ | |
536 | 0, /* rightshift */ | |
537 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
538 | 16, /* bitsize */ | |
539 | FALSE, /* pc_relative */ | |
540 | 0, /* bitpos */ | |
541 | complain_overflow_dont, /* complain_on_overflow */ | |
542 | bfd_elf_generic_reloc, /* special_function */ | |
543 | "R_FRV_GOTTLSDESCLO", /* name */ | |
544 | FALSE, /* partial_inplace */ | |
545 | 0xffff, /* src_mask */ | |
546 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 547 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
548 | |
549 | /* A 12-bit signed operand with the offset from the module base | |
550 | address to the thread-local symbol address. */ | |
3b36f7e6 | 551 | HOWTO (R_FRV_TLSMOFF12, /* type */ |
90219bd0 AO |
552 | 0, /* rightshift */ |
553 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
554 | 12, /* bitsize */ | |
555 | FALSE, /* pc_relative */ | |
556 | 0, /* bitpos */ | |
557 | complain_overflow_signed, /* complain_on_overflow */ | |
558 | bfd_elf_generic_reloc, /* special_function */ | |
559 | "R_FRV_TLSMOFF12", /* name */ | |
560 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
561 | 0xfff, /* src_mask */ |
562 | 0xfff, /* dst_mask */ | |
563 | FALSE), /* pcrel_offset */ | |
90219bd0 AO |
564 | |
565 | /* The upper 16 bits of the offset from the module base address to | |
566 | the thread-local symbol address. */ | |
3b36f7e6 | 567 | HOWTO (R_FRV_TLSMOFFHI, /* type */ |
90219bd0 AO |
568 | 0, /* rightshift */ |
569 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
570 | 16, /* bitsize */ | |
571 | FALSE, /* pc_relative */ | |
572 | 0, /* bitpos */ | |
573 | complain_overflow_dont, /* complain_on_overflow */ | |
574 | bfd_elf_generic_reloc, /* special_function */ | |
575 | "R_FRV_TLSMOFFHI", /* name */ | |
576 | FALSE, /* partial_inplace */ | |
577 | 0xffff, /* src_mask */ | |
578 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 579 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
580 | |
581 | /* The lower 16 bits of the offset from the module base address to | |
582 | the thread-local symbol address. */ | |
583 | HOWTO (R_FRV_TLSMOFFLO, /* type */ | |
584 | 0, /* rightshift */ | |
585 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
586 | 16, /* bitsize */ | |
587 | FALSE, /* pc_relative */ | |
588 | 0, /* bitpos */ | |
589 | complain_overflow_dont, /* complain_on_overflow */ | |
590 | bfd_elf_generic_reloc, /* special_function */ | |
591 | "R_FRV_TLSMOFFLO", /* name */ | |
592 | FALSE, /* partial_inplace */ | |
593 | 0xffff, /* src_mask */ | |
594 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 595 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
596 | |
597 | /* A 12-bit signed operand with the GOT offset for the TLSOFF entry | |
598 | for a symbol. */ | |
3b36f7e6 | 599 | HOWTO (R_FRV_GOTTLSOFF12, /* type */ |
90219bd0 AO |
600 | 0, /* rightshift */ |
601 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
602 | 12, /* bitsize */ | |
603 | FALSE, /* pc_relative */ | |
604 | 0, /* bitpos */ | |
605 | complain_overflow_signed, /* complain_on_overflow */ | |
606 | bfd_elf_generic_reloc, /* special_function */ | |
607 | "R_FRV_GOTTLSOFF12", /* name */ | |
608 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
609 | 0xfff, /* src_mask */ |
610 | 0xfff, /* dst_mask */ | |
611 | FALSE), /* pcrel_offset */ | |
90219bd0 AO |
612 | |
613 | /* The upper 16 bits of the GOT offset for the TLSOFF entry for a | |
614 | symbol. */ | |
3b36f7e6 | 615 | HOWTO (R_FRV_GOTTLSOFFHI, /* type */ |
90219bd0 AO |
616 | 0, /* rightshift */ |
617 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
618 | 16, /* bitsize */ | |
619 | FALSE, /* pc_relative */ | |
620 | 0, /* bitpos */ | |
621 | complain_overflow_dont, /* complain_on_overflow */ | |
622 | bfd_elf_generic_reloc, /* special_function */ | |
623 | "R_FRV_GOTTLSOFFHI", /* name */ | |
624 | FALSE, /* partial_inplace */ | |
625 | 0xffff, /* src_mask */ | |
626 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 627 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
628 | |
629 | /* The lower 16 bits of the GOT offset for the TLSOFF entry for a | |
630 | symbol. */ | |
631 | HOWTO (R_FRV_GOTTLSOFFLO, /* type */ | |
632 | 0, /* rightshift */ | |
633 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
634 | 16, /* bitsize */ | |
635 | FALSE, /* pc_relative */ | |
636 | 0, /* bitpos */ | |
637 | complain_overflow_dont, /* complain_on_overflow */ | |
638 | bfd_elf_generic_reloc, /* special_function */ | |
639 | "R_FRV_GOTTLSOFFLO", /* name */ | |
640 | FALSE, /* partial_inplace */ | |
641 | 0xffff, /* src_mask */ | |
642 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 643 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
644 | |
645 | /* The 32-bit offset from the thread pointer (not the module base | |
646 | address) to a thread-local symbol. */ | |
647 | HOWTO (R_FRV_TLSOFF, /* type */ | |
648 | 0, /* rightshift */ | |
649 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
650 | 32, /* bitsize */ | |
651 | FALSE, /* pc_relative */ | |
652 | 0, /* bitpos */ | |
653 | complain_overflow_dont, /* complain_on_overflow */ | |
654 | bfd_elf_generic_reloc, /* special_function */ | |
655 | "R_FRV_TLSOFF", /* name */ | |
656 | FALSE, /* partial_inplace */ | |
657 | 0xffffffff, /* src_mask */ | |
658 | 0xffffffff, /* dst_mask */ | |
659 | FALSE), /* pcrel_offset */ | |
660 | ||
661 | /* An annotation for linker relaxation, that denotes the | |
662 | symbol+addend whose TLS descriptor is referenced by the sum of | |
663 | the two input registers of an ldd instruction. */ | |
664 | HOWTO (R_FRV_TLSDESC_RELAX, /* type */ | |
665 | 0, /* rightshift */ | |
666 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
667 | 0, /* bitsize */ | |
668 | FALSE, /* pc_relative */ | |
669 | 0, /* bitpos */ | |
670 | complain_overflow_dont, /* complain_on_overflow */ | |
671 | bfd_elf_generic_reloc, /* special_function */ | |
672 | "R_FRV_TLSDESC_RELAX", /* name */ | |
673 | FALSE, /* partial_inplace */ | |
674 | 0, /* src_mask */ | |
675 | 0, /* dst_mask */ | |
676 | FALSE), /* pcrel_offset */ | |
677 | ||
678 | /* An annotation for linker relaxation, that denotes the | |
679 | symbol+addend whose TLS resolver entry point is given by the sum | |
680 | of the two register operands of an calll instruction. */ | |
681 | HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */ | |
682 | 0, /* rightshift */ | |
683 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
684 | 0, /* bitsize */ | |
685 | FALSE, /* pc_relative */ | |
686 | 0, /* bitpos */ | |
687 | complain_overflow_dont, /* complain_on_overflow */ | |
688 | bfd_elf_generic_reloc, /* special_function */ | |
689 | "R_FRV_GETTLSOFF_RELAX", /* name */ | |
690 | FALSE, /* partial_inplace */ | |
691 | 0, /* src_mask */ | |
692 | 0, /* dst_mask */ | |
693 | FALSE), /* pcrel_offset */ | |
694 | ||
695 | /* An annotation for linker relaxation, that denotes the | |
696 | symbol+addend whose TLS offset GOT entry is given by the sum of | |
697 | the two input registers of an ld instruction. */ | |
698 | HOWTO (R_FRV_TLSOFF_RELAX, /* type */ | |
699 | 0, /* rightshift */ | |
700 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
701 | 0, /* bitsize */ | |
702 | FALSE, /* pc_relative */ | |
703 | 0, /* bitpos */ | |
704 | complain_overflow_bitfield, /* complain_on_overflow */ | |
705 | bfd_elf_generic_reloc, /* special_function */ | |
706 | "R_FRV_TLSOFF_RELAX", /* name */ | |
707 | FALSE, /* partial_inplace */ | |
708 | 0, /* src_mask */ | |
709 | 0, /* dst_mask */ | |
710 | FALSE), /* pcrel_offset */ | |
711 | ||
712 | /* A 32-bit offset from the module base address to | |
713 | the thread-local symbol address. */ | |
3b36f7e6 | 714 | HOWTO (R_FRV_TLSMOFF, /* type */ |
90219bd0 AO |
715 | 0, /* rightshift */ |
716 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
717 | 32, /* bitsize */ | |
718 | FALSE, /* pc_relative */ | |
719 | 0, /* bitpos */ | |
720 | complain_overflow_dont, /* complain_on_overflow */ | |
721 | bfd_elf_generic_reloc, /* special_function */ | |
722 | "R_FRV_TLSMOFF", /* name */ | |
723 | FALSE, /* partial_inplace */ | |
724 | 0xffffffff, /* src_mask */ | |
725 | 0xffffffff, /* dst_mask */ | |
3b36f7e6 | 726 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
727 | }; |
728 | ||
729 | /* GNU extension to record C++ vtable hierarchy. */ | |
730 | static reloc_howto_type elf32_frv_vtinherit_howto = | |
3b36f7e6 AM |
731 | HOWTO (R_FRV_GNU_VTINHERIT, /* type */ |
732 | 0, /* rightshift */ | |
733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
734 | 0, /* bitsize */ | |
735 | FALSE, /* pc_relative */ | |
736 | 0, /* bitpos */ | |
737 | complain_overflow_dont, /* complain_on_overflow */ | |
738 | NULL, /* special_function */ | |
739 | "R_FRV_GNU_VTINHERIT", /* name */ | |
740 | FALSE, /* partial_inplace */ | |
741 | 0, /* src_mask */ | |
742 | 0, /* dst_mask */ | |
743 | FALSE); /* pcrel_offset */ | |
4e5ba5b7 DB |
744 | |
745 | /* GNU extension to record C++ vtable member usage. */ | |
746 | static reloc_howto_type elf32_frv_vtentry_howto = | |
3b36f7e6 AM |
747 | HOWTO (R_FRV_GNU_VTENTRY, /* type */ |
748 | 0, /* rightshift */ | |
749 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
750 | 0, /* bitsize */ | |
751 | FALSE, /* pc_relative */ | |
752 | 0, /* bitpos */ | |
753 | complain_overflow_dont, /* complain_on_overflow */ | |
754 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
755 | "R_FRV_GNU_VTENTRY", /* name */ | |
756 | FALSE, /* partial_inplace */ | |
757 | 0, /* src_mask */ | |
758 | 0, /* dst_mask */ | |
759 | FALSE); /* pcrel_offset */ | |
51532845 AO |
760 | |
761 | /* The following 3 relocations are REL. The only difference to the | |
762 | entries in the table above are that partial_inplace is TRUE. */ | |
763 | static reloc_howto_type elf32_frv_rel_32_howto = | |
764 | HOWTO (R_FRV_32, /* type */ | |
765 | 0, /* rightshift */ | |
766 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
767 | 32, /* bitsize */ | |
768 | FALSE, /* pc_relative */ | |
769 | 0, /* bitpos */ | |
770 | complain_overflow_bitfield, /* complain_on_overflow */ | |
771 | bfd_elf_generic_reloc, /* special_function */ | |
772 | "R_FRV_32", /* name */ | |
773 | TRUE, /* partial_inplace */ | |
774 | 0xffffffff, /* src_mask */ | |
775 | 0xffffffff, /* dst_mask */ | |
776 | FALSE); /* pcrel_offset */ | |
777 | ||
778 | static reloc_howto_type elf32_frv_rel_funcdesc_howto = | |
779 | HOWTO (R_FRV_FUNCDESC, /* type */ | |
780 | 0, /* rightshift */ | |
781 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
782 | 32, /* bitsize */ | |
783 | FALSE, /* pc_relative */ | |
784 | 0, /* bitpos */ | |
785 | complain_overflow_bitfield, /* complain_on_overflow */ | |
786 | bfd_elf_generic_reloc, /* special_function */ | |
787 | "R_FRV_FUNCDESC", /* name */ | |
788 | TRUE, /* partial_inplace */ | |
789 | 0xffffffff, /* src_mask */ | |
790 | 0xffffffff, /* dst_mask */ | |
791 | FALSE); /* pcrel_offset */ | |
792 | ||
793 | static reloc_howto_type elf32_frv_rel_funcdesc_value_howto = | |
794 | HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ | |
795 | 0, /* rightshift */ | |
796 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
797 | 64, /* bitsize */ | |
798 | FALSE, /* pc_relative */ | |
799 | 0, /* bitpos */ | |
800 | complain_overflow_bitfield, /* complain_on_overflow */ | |
801 | bfd_elf_generic_reloc, /* special_function */ | |
802 | "R_FRV_FUNCDESC_VALUE", /* name */ | |
803 | TRUE, /* partial_inplace */ | |
804 | 0xffffffff, /* src_mask */ | |
805 | 0xffffffff, /* dst_mask */ | |
806 | FALSE); /* pcrel_offset */ | |
807 | ||
90219bd0 AO |
808 | static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto = |
809 | /* A 64-bit TLS descriptor for a symbol. The first word resolves to | |
810 | an entry point, and the second resolves to a special argument. | |
811 | If the symbol turns out to be in static TLS, the entry point is a | |
812 | return instruction, and the special argument is the TLS offset | |
813 | for the symbol. If it's in dynamic TLS, the entry point is a TLS | |
814 | offset resolver, and the special argument is a pointer to a data | |
815 | structure allocated by the dynamic loader, containing the GOT | |
816 | address for the offset resolver, the module id, the offset within | |
817 | the module, and anything else the TLS offset resolver might need | |
818 | to determine the TLS offset for the symbol in the running | |
819 | thread. */ | |
820 | HOWTO (R_FRV_TLSDESC_VALUE, /* type */ | |
821 | 0, /* rightshift */ | |
822 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
823 | 64, /* bitsize */ | |
824 | FALSE, /* pc_relative */ | |
825 | 0, /* bitpos */ | |
826 | complain_overflow_bitfield, /* complain_on_overflow */ | |
827 | bfd_elf_generic_reloc, /* special_function */ | |
828 | "R_FRV_TLSDESC_VALUE", /* name */ | |
829 | TRUE, /* partial_inplace */ | |
830 | 0xffffffff, /* src_mask */ | |
831 | 0xffffffff, /* dst_mask */ | |
832 | FALSE); /* pcrel_offset */ | |
833 | ||
834 | static reloc_howto_type elf32_frv_rel_tlsoff_howto = | |
835 | /* The 32-bit offset from the thread pointer (not the module base | |
836 | address) to a thread-local symbol. */ | |
837 | HOWTO (R_FRV_TLSOFF, /* type */ | |
838 | 0, /* rightshift */ | |
839 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
840 | 32, /* bitsize */ | |
841 | FALSE, /* pc_relative */ | |
842 | 0, /* bitpos */ | |
843 | complain_overflow_bitfield, /* complain_on_overflow */ | |
844 | bfd_elf_generic_reloc, /* special_function */ | |
845 | "R_FRV_TLSOFF", /* name */ | |
846 | TRUE, /* partial_inplace */ | |
847 | 0xffffffff, /* src_mask */ | |
848 | 0xffffffff, /* dst_mask */ | |
849 | FALSE); /* pcrel_offset */ | |
850 | ||
851 | ||
4e5ba5b7 | 852 | \f |
43850d5b AO |
853 | extern const bfd_target bfd_elf32_frvfdpic_vec; |
854 | #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec) | |
4e5ba5b7 | 855 | |
51532845 AO |
856 | /* An extension of the elf hash table data structure, containing some |
857 | additional FRV-specific data. */ | |
43850d5b | 858 | struct frvfdpic_elf_link_hash_table |
4e5ba5b7 | 859 | { |
51532845 AO |
860 | struct elf_link_hash_table elf; |
861 | ||
862 | /* A pointer to the .got section. */ | |
863 | asection *sgot; | |
864 | /* A pointer to the .rel.got section. */ | |
865 | asection *sgotrel; | |
866 | /* A pointer to the .rofixup section. */ | |
867 | asection *sgotfixup; | |
868 | /* A pointer to the .plt section. */ | |
869 | asection *splt; | |
870 | /* A pointer to the .rel.plt section. */ | |
871 | asection *spltrel; | |
872 | /* GOT base offset. */ | |
873 | bfd_vma got0; | |
874 | /* Location of the first non-lazy PLT entry, i.e., the number of | |
90219bd0 AO |
875 | bytes taken by lazy PLT entries. If locally-bound TLS |
876 | descriptors require a ret instruction, it will be placed at this | |
877 | offset. */ | |
51532845 AO |
878 | bfd_vma plt0; |
879 | /* A hash table holding information about which symbols were | |
880 | referenced with which PIC-related relocations. */ | |
881 | struct htab *relocs_info; | |
90219bd0 AO |
882 | /* Summary reloc information collected by |
883 | _frvfdpic_count_got_plt_entries. */ | |
884 | struct _frvfdpic_dynamic_got_info *g; | |
51532845 | 885 | }; |
4e5ba5b7 | 886 | |
51532845 AO |
887 | /* Get the FRV ELF linker hash table from a link_info structure. */ |
888 | ||
43850d5b AO |
889 | #define frvfdpic_hash_table(info) \ |
890 | ((struct frvfdpic_elf_link_hash_table *) ((info)->hash)) | |
891 | ||
892 | #define frvfdpic_got_section(info) \ | |
893 | (frvfdpic_hash_table (info)->sgot) | |
894 | #define frvfdpic_gotrel_section(info) \ | |
895 | (frvfdpic_hash_table (info)->sgotrel) | |
896 | #define frvfdpic_gotfixup_section(info) \ | |
897 | (frvfdpic_hash_table (info)->sgotfixup) | |
898 | #define frvfdpic_plt_section(info) \ | |
899 | (frvfdpic_hash_table (info)->splt) | |
900 | #define frvfdpic_pltrel_section(info) \ | |
901 | (frvfdpic_hash_table (info)->spltrel) | |
902 | #define frvfdpic_relocs_info(info) \ | |
903 | (frvfdpic_hash_table (info)->relocs_info) | |
904 | #define frvfdpic_got_initial_offset(info) \ | |
905 | (frvfdpic_hash_table (info)->got0) | |
906 | #define frvfdpic_plt_initial_offset(info) \ | |
907 | (frvfdpic_hash_table (info)->plt0) | |
90219bd0 AO |
908 | #define frvfdpic_dynamic_got_plt_info(info) \ |
909 | (frvfdpic_hash_table (info)->g) | |
910 | ||
911 | /* Currently it's the same, but if some day we have a reason to change | |
912 | it, we'd better be using a different macro. | |
913 | ||
914 | FIXME: if there's any TLS PLT entry that uses local-exec or | |
915 | initial-exec models, we could use the ret at the end of any of them | |
916 | instead of adding one more. */ | |
917 | #define frvfdpic_plt_tls_ret_offset(info) \ | |
918 | (frvfdpic_plt_initial_offset (info)) | |
919 | ||
920 | /* The name of the dynamic interpreter. This is put in the .interp | |
921 | section. */ | |
922 | ||
923 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" | |
924 | ||
925 | #define DEFAULT_STACK_SIZE 0x20000 | |
926 | ||
927 | /* This structure is used to collect the number of entries present in | |
928 | each addressable range of the got. */ | |
929 | struct _frvfdpic_dynamic_got_info | |
930 | { | |
931 | /* Several bits of information about the current link. */ | |
932 | struct bfd_link_info *info; | |
933 | /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit | |
934 | ranges. */ | |
935 | bfd_vma got12, gotlos, gothilo; | |
936 | /* Total GOT size needed for function descriptor entries within the 12-, | |
937 | 16- or 32-bit ranges. */ | |
938 | bfd_vma fd12, fdlos, fdhilo; | |
939 | /* Total GOT size needed by function descriptor entries referenced | |
940 | in PLT entries, that would be profitable to place in offsets | |
941 | close to the PIC register. */ | |
942 | bfd_vma fdplt; | |
943 | /* Total PLT size needed by lazy PLT entries. */ | |
944 | bfd_vma lzplt; | |
945 | /* Total GOT size needed for TLS descriptor entries within the 12-, | |
946 | 16- or 32-bit ranges. */ | |
947 | bfd_vma tlsd12, tlsdlos, tlsdhilo; | |
948 | /* Total GOT size needed by TLS descriptors referenced in PLT | |
949 | entries, that would be profitable to place in offers close to the | |
950 | PIC register. */ | |
951 | bfd_vma tlsdplt; | |
952 | /* Total PLT size needed by TLS lazy PLT entries. */ | |
953 | bfd_vma tlslzplt; | |
954 | /* Number of relocations carried over from input object files. */ | |
955 | unsigned long relocs; | |
956 | /* Number of fixups introduced by relocations in input object files. */ | |
957 | unsigned long fixups; | |
958 | /* The number of fixups that reference the ret instruction added to | |
959 | the PLT for locally-resolved TLS descriptors. */ | |
960 | unsigned long tls_ret_refs; | |
961 | }; | |
962 | ||
963 | /* This structure is used to assign offsets to got entries, function | |
964 | descriptors, plt entries and lazy plt entries. */ | |
965 | ||
966 | struct _frvfdpic_dynamic_got_plt_info | |
967 | { | |
968 | /* Summary information collected with _frvfdpic_count_got_plt_entries. */ | |
969 | struct _frvfdpic_dynamic_got_info g; | |
970 | ||
971 | /* For each addressable range, we record a MAX (positive) and MIN | |
972 | (negative) value. CUR is used to assign got entries, and it's | |
973 | incremented from an initial positive value to MAX, then from MIN | |
974 | to FDCUR (unless FDCUR wraps around first). FDCUR is used to | |
975 | assign function descriptors, and it's decreased from an initial | |
976 | non-positive value to MIN, then from MAX down to CUR (unless CUR | |
977 | wraps around first). All of MIN, MAX, CUR and FDCUR always point | |
978 | to even words. ODD, if non-zero, indicates an odd word to be | |
979 | used for the next got entry, otherwise CUR is used and | |
980 | incremented by a pair of words, wrapping around when it reaches | |
981 | MAX. FDCUR is decremented (and wrapped) before the next function | |
982 | descriptor is chosen. FDPLT indicates the number of remaining | |
983 | slots that can be used for function descriptors used only by PLT | |
984 | entries. | |
985 | ||
986 | TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR | |
987 | starts as MAX, and grows up to TMAX, then wraps around to TMIN | |
988 | and grows up to MIN. TLSDPLT indicates the number of remaining | |
989 | slots that can be used for TLS descriptors used only by TLS PLT | |
990 | entries. */ | |
991 | struct _frvfdpic_dynamic_got_alloc_data | |
992 | { | |
993 | bfd_signed_vma max, cur, odd, fdcur, min; | |
994 | bfd_signed_vma tmax, tcur, tmin; | |
995 | bfd_vma fdplt, tlsdplt; | |
996 | } got12, gotlos, gothilo; | |
997 | }; | |
51532845 AO |
998 | |
999 | /* Create an FRV ELF linker hash table. */ | |
1000 | ||
1001 | static struct bfd_link_hash_table * | |
43850d5b | 1002 | frvfdpic_elf_link_hash_table_create (bfd *abfd) |
51532845 | 1003 | { |
43850d5b AO |
1004 | struct frvfdpic_elf_link_hash_table *ret; |
1005 | bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table); | |
4e5ba5b7 | 1006 | |
51532845 AO |
1007 | ret = bfd_zalloc (abfd, amt); |
1008 | if (ret == NULL) | |
1009 | return NULL; | |
4e5ba5b7 | 1010 | |
66eb6687 AM |
1011 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, |
1012 | _bfd_elf_link_hash_newfunc, | |
1013 | sizeof (struct elf_link_hash_entry))) | |
51532845 AO |
1014 | { |
1015 | free (ret); | |
1016 | return NULL; | |
1017 | } | |
4e5ba5b7 | 1018 | |
51532845 AO |
1019 | return &ret->elf.root; |
1020 | } | |
4e5ba5b7 | 1021 | |
51532845 AO |
1022 | /* Decide whether a reference to a symbol can be resolved locally or |
1023 | not. If the symbol is protected, we want the local address, but | |
1024 | its function descriptor must be assigned by the dynamic linker. */ | |
43850d5b | 1025 | #define FRVFDPIC_SYM_LOCAL(INFO, H) \ |
51532845 | 1026 | (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \ |
303e4c21 | 1027 | || ! elf_hash_table (INFO)->dynamic_sections_created) |
43850d5b | 1028 | #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \ |
51532845 AO |
1029 | ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created) |
1030 | ||
1031 | /* This structure collects information on what kind of GOT, PLT or | |
1032 | function descriptors are required by relocations that reference a | |
1033 | certain symbol. */ | |
43850d5b | 1034 | struct frvfdpic_relocs_info |
51532845 AO |
1035 | { |
1036 | /* The index of the symbol, as stored in the relocation r_info, if | |
1037 | we have a local symbol; -1 otherwise. */ | |
1038 | long symndx; | |
1039 | union | |
1040 | { | |
1041 | /* The input bfd in which the symbol is defined, if it's a local | |
1042 | symbol. */ | |
1043 | bfd *abfd; | |
1044 | /* If symndx == -1, the hash table entry corresponding to a global | |
1045 | symbol (even if it turns out to bind locally, in which case it | |
1046 | should ideally be replaced with section's symndx + addend). */ | |
1047 | struct elf_link_hash_entry *h; | |
1048 | } d; | |
1049 | /* The addend of the relocation that references the symbol. */ | |
1050 | bfd_vma addend; | |
1051 | ||
1052 | /* The fields above are used to identify an entry. The fields below | |
1053 | contain information on how an entry is used and, later on, which | |
1054 | locations it was assigned. */ | |
1055 | /* The following 3 fields record whether the symbol+addend above was | |
1056 | ever referenced with a GOT relocation. The 12 suffix indicates a | |
1057 | GOT12 relocation; los is used for GOTLO relocations that are not | |
1058 | matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI | |
1059 | pairs. */ | |
1060 | unsigned got12:1; | |
1061 | unsigned gotlos:1; | |
1062 | unsigned gothilo:1; | |
1063 | /* Whether a FUNCDESC relocation references symbol+addend. */ | |
1064 | unsigned fd:1; | |
1065 | /* Whether a FUNCDESC_GOT relocation references symbol+addend. */ | |
1066 | unsigned fdgot12:1; | |
1067 | unsigned fdgotlos:1; | |
1068 | unsigned fdgothilo:1; | |
1069 | /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */ | |
1070 | unsigned fdgoff12:1; | |
1071 | unsigned fdgofflos:1; | |
1072 | unsigned fdgoffhilo:1; | |
90219bd0 AO |
1073 | /* Whether a GETTLSOFF relocation references symbol+addend. */ |
1074 | unsigned tlsplt:1; | |
1075 | /* FIXME: we should probably add tlspltdesc, tlspltoff and | |
1076 | tlspltimm, to tell what kind of TLS PLT entry we're generating. | |
1077 | We might instead just pre-compute flags telling whether the | |
1078 | object is suitable for local exec, initial exec or general | |
1079 | dynamic addressing, and use that all over the place. We could | |
1080 | also try to do a better job of merging TLSOFF and TLSDESC entries | |
1081 | in main executables, but perhaps we can get rid of TLSDESC | |
1082 | entirely in them instead. */ | |
1083 | /* Whether a GOTTLSDESC relocation references symbol+addend. */ | |
1084 | unsigned tlsdesc12:1; | |
1085 | unsigned tlsdesclos:1; | |
1086 | unsigned tlsdeschilo:1; | |
1087 | /* Whether a GOTTLSOFF relocation references symbol+addend. */ | |
1088 | unsigned tlsoff12:1; | |
1089 | unsigned tlsofflos:1; | |
1090 | unsigned tlsoffhilo:1; | |
51532845 AO |
1091 | /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or |
1092 | GOTOFFHI relocations. The addend doesn't really matter, since we | |
1093 | envision that this will only be used to check whether the symbol | |
1094 | is mapped to the same segment as the got. */ | |
1095 | unsigned gotoff:1; | |
1096 | /* Whether symbol+addend is referenced by a LABEL24 relocation. */ | |
1097 | unsigned call:1; | |
1098 | /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE | |
1099 | relocation. */ | |
1100 | unsigned sym:1; | |
1101 | /* Whether we need a PLT entry for a symbol. Should be implied by | |
1102 | something like: | |
43850d5b | 1103 | (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */ |
51532845 AO |
1104 | unsigned plt:1; |
1105 | /* Whether a function descriptor should be created in this link unit | |
1106 | for symbol+addend. Should be implied by something like: | |
1107 | (plt || fdgotoff12 || fdgotofflos || fdgotofflohi | |
1108 | || ((fd || fdgot12 || fdgotlos || fdgothilo) | |
43850d5b | 1109 | && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */ |
51532845 AO |
1110 | unsigned privfd:1; |
1111 | /* Whether a lazy PLT entry is needed for this symbol+addend. | |
1112 | Should be implied by something like: | |
43850d5b | 1113 | (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h) |
51532845 AO |
1114 | && ! (info->flags & DF_BIND_NOW)) */ |
1115 | unsigned lazyplt:1; | |
1116 | /* Whether we've already emitted GOT relocations and PLT entries as | |
1117 | needed for this symbol. */ | |
1118 | unsigned done:1; | |
1119 | ||
90219bd0 AO |
1120 | /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and |
1121 | R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing | |
1122 | symbol+addend. */ | |
1123 | unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff; | |
51532845 | 1124 | |
3b712a1a AO |
1125 | /* The number of .rofixups entries and dynamic relocations allocated |
1126 | for this symbol, minus any that might have already been used. */ | |
1127 | unsigned fixups, dynrelocs; | |
1128 | ||
51532845 AO |
1129 | /* The offsets of the GOT entries assigned to symbol+addend, to the |
1130 | function descriptor's address, and to a function descriptor, | |
1131 | respectively. Should be zero if unassigned. The offsets are | |
1132 | counted from the value that will be assigned to the PIC register, | |
1133 | not from the beginning of the .got section. */ | |
1134 | bfd_signed_vma got_entry, fdgot_entry, fd_entry; | |
1135 | /* The offsets of the PLT entries assigned to symbol+addend, | |
1136 | non-lazy and lazy, respectively. If unassigned, should be | |
1137 | (bfd_vma)-1. */ | |
1138 | bfd_vma plt_entry, lzplt_entry; | |
90219bd0 AO |
1139 | /* The offsets of the GOT entries for TLS offset and TLS descriptor. */ |
1140 | bfd_signed_vma tlsoff_entry, tlsdesc_entry; | |
1141 | /* The offset of the TLS offset PLT entry. */ | |
1142 | bfd_vma tlsplt_entry; | |
51532845 | 1143 | }; |
4e5ba5b7 | 1144 | |
43850d5b | 1145 | /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */ |
51532845 | 1146 | static hashval_t |
43850d5b | 1147 | frvfdpic_relocs_info_hash (const void *entry_) |
51532845 | 1148 | { |
43850d5b | 1149 | const struct frvfdpic_relocs_info *entry = entry_; |
4e5ba5b7 | 1150 | |
51532845 | 1151 | return (entry->symndx == -1 |
5ff625e9 AM |
1152 | ? (long) entry->d.h->root.root.hash |
1153 | : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend; | |
4e5ba5b7 DB |
1154 | } |
1155 | ||
43850d5b | 1156 | /* Test whether the key fields of two frvfdpic_relocs_info entries are |
51532845 AO |
1157 | identical. */ |
1158 | static int | |
43850d5b | 1159 | frvfdpic_relocs_info_eq (const void *entry1, const void *entry2) |
51532845 | 1160 | { |
43850d5b AO |
1161 | const struct frvfdpic_relocs_info *e1 = entry1; |
1162 | const struct frvfdpic_relocs_info *e2 = entry2; | |
4e5ba5b7 | 1163 | |
51532845 AO |
1164 | return e1->symndx == e2->symndx && e1->addend == e2->addend |
1165 | && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd); | |
1166 | } | |
1167 | ||
1168 | /* Find or create an entry in a hash table HT that matches the key | |
1169 | fields of the given ENTRY. If it's not found, memory for a new | |
1170 | entry is allocated in ABFD's obstack. */ | |
43850d5b AO |
1171 | static struct frvfdpic_relocs_info * |
1172 | frvfdpic_relocs_info_find (struct htab *ht, | |
1173 | bfd *abfd, | |
1174 | const struct frvfdpic_relocs_info *entry, | |
1175 | enum insert_option insert) | |
4e5ba5b7 | 1176 | { |
43850d5b AO |
1177 | struct frvfdpic_relocs_info **loc = |
1178 | (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert); | |
3b712a1a AO |
1179 | |
1180 | if (! loc) | |
1181 | return NULL; | |
4e5ba5b7 | 1182 | |
51532845 AO |
1183 | if (*loc) |
1184 | return *loc; | |
4e5ba5b7 | 1185 | |
51532845 | 1186 | *loc = bfd_zalloc (abfd, sizeof (**loc)); |
b34976b6 | 1187 | |
51532845 AO |
1188 | if (! *loc) |
1189 | return *loc; | |
1190 | ||
1191 | (*loc)->symndx = entry->symndx; | |
1192 | (*loc)->d = entry->d; | |
1193 | (*loc)->addend = entry->addend; | |
1194 | (*loc)->plt_entry = (bfd_vma)-1; | |
1195 | (*loc)->lzplt_entry = (bfd_vma)-1; | |
90219bd0 | 1196 | (*loc)->tlsplt_entry = (bfd_vma)-1; |
51532845 AO |
1197 | |
1198 | return *loc; | |
1199 | } | |
1200 | ||
1201 | /* Obtain the address of the entry in HT associated with H's symbol + | |
1202 | addend, creating a new entry if none existed. ABFD is only used | |
1203 | for memory allocation purposes. */ | |
43850d5b AO |
1204 | inline static struct frvfdpic_relocs_info * |
1205 | frvfdpic_relocs_info_for_global (struct htab *ht, | |
1206 | bfd *abfd, | |
1207 | struct elf_link_hash_entry *h, | |
1208 | bfd_vma addend, | |
1209 | enum insert_option insert) | |
51532845 | 1210 | { |
43850d5b | 1211 | struct frvfdpic_relocs_info entry; |
51532845 AO |
1212 | |
1213 | entry.symndx = -1; | |
1214 | entry.d.h = h; | |
1215 | entry.addend = addend; | |
1216 | ||
43850d5b | 1217 | return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); |
51532845 AO |
1218 | } |
1219 | ||
1220 | /* Obtain the address of the entry in HT associated with the SYMNDXth | |
1221 | local symbol of the input bfd ABFD, plus the addend, creating a new | |
f12123c0 | 1222 | entry if none existed. */ |
43850d5b AO |
1223 | inline static struct frvfdpic_relocs_info * |
1224 | frvfdpic_relocs_info_for_local (struct htab *ht, | |
1225 | bfd *abfd, | |
1226 | long symndx, | |
1227 | bfd_vma addend, | |
1228 | enum insert_option insert) | |
51532845 | 1229 | { |
43850d5b | 1230 | struct frvfdpic_relocs_info entry; |
51532845 AO |
1231 | |
1232 | entry.symndx = symndx; | |
1233 | entry.d.abfd = abfd; | |
1234 | entry.addend = addend; | |
1235 | ||
43850d5b | 1236 | return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); |
3b712a1a AO |
1237 | } |
1238 | ||
1239 | /* Merge fields set by check_relocs() of two entries that end up being | |
1240 | mapped to the same (presumably global) symbol. */ | |
1241 | ||
1242 | inline static void | |
43850d5b AO |
1243 | frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2, |
1244 | struct frvfdpic_relocs_info const *e1) | |
3b712a1a AO |
1245 | { |
1246 | e2->got12 |= e1->got12; | |
1247 | e2->gotlos |= e1->gotlos; | |
1248 | e2->gothilo |= e1->gothilo; | |
1249 | e2->fd |= e1->fd; | |
1250 | e2->fdgot12 |= e1->fdgot12; | |
1251 | e2->fdgotlos |= e1->fdgotlos; | |
1252 | e2->fdgothilo |= e1->fdgothilo; | |
1253 | e2->fdgoff12 |= e1->fdgoff12; | |
1254 | e2->fdgofflos |= e1->fdgofflos; | |
1255 | e2->fdgoffhilo |= e1->fdgoffhilo; | |
90219bd0 AO |
1256 | e2->tlsplt |= e1->tlsplt; |
1257 | e2->tlsdesc12 |= e1->tlsdesc12; | |
1258 | e2->tlsdesclos |= e1->tlsdesclos; | |
1259 | e2->tlsdeschilo |= e1->tlsdeschilo; | |
1260 | e2->tlsoff12 |= e1->tlsoff12; | |
1261 | e2->tlsofflos |= e1->tlsofflos; | |
1262 | e2->tlsoffhilo |= e1->tlsoffhilo; | |
3b712a1a AO |
1263 | e2->gotoff |= e1->gotoff; |
1264 | e2->call |= e1->call; | |
1265 | e2->sym |= e1->sym; | |
51532845 AO |
1266 | } |
1267 | ||
1268 | /* Every block of 65535 lazy PLT entries shares a single call to the | |
1269 | resolver, inserted in the 32768th lazy PLT entry (i.e., entry # | |
1270 | 32767, counting from 0). All other lazy PLT entries branch to it | |
1271 | in a single instruction. */ | |
1272 | ||
43850d5b AO |
1273 | #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4) |
1274 | #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767) | |
51532845 AO |
1275 | |
1276 | /* Add a dynamic relocation to the SRELOC section. */ | |
1277 | ||
1278 | inline static bfd_vma | |
43850d5b AO |
1279 | _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset, |
1280 | int reloc_type, long dynindx, bfd_vma addend, | |
1281 | struct frvfdpic_relocs_info *entry) | |
51532845 AO |
1282 | { |
1283 | Elf_Internal_Rela outrel; | |
1284 | bfd_vma reloc_offset; | |
1285 | ||
1286 | outrel.r_offset = offset; | |
1287 | outrel.r_info = ELF32_R_INFO (dynindx, reloc_type); | |
1288 | outrel.r_addend = addend; | |
1289 | ||
1290 | reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel); | |
eea6121a | 1291 | BFD_ASSERT (reloc_offset < sreloc->size); |
51532845 AO |
1292 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, |
1293 | sreloc->contents + reloc_offset); | |
1294 | sreloc->reloc_count++; | |
1295 | ||
3f980e41 AO |
1296 | /* If the entry's index is zero, this relocation was probably to a |
1297 | linkonce section that got discarded. We reserved a dynamic | |
1298 | relocation, but it was for another entry than the one we got at | |
1299 | the time of emitting the relocation. Unfortunately there's no | |
1300 | simple way for us to catch this situation, since the relocation | |
1301 | is cleared right before calling relocate_section, at which point | |
1302 | we no longer know what the relocation used to point to. */ | |
1303 | if (entry->symndx) | |
1304 | { | |
1305 | BFD_ASSERT (entry->dynrelocs > 0); | |
1306 | entry->dynrelocs--; | |
1307 | } | |
3b712a1a | 1308 | |
51532845 AO |
1309 | return reloc_offset; |
1310 | } | |
1311 | ||
1312 | /* Add a fixup to the ROFIXUP section. */ | |
1313 | ||
1314 | static bfd_vma | |
43850d5b AO |
1315 | _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset, |
1316 | struct frvfdpic_relocs_info *entry) | |
51532845 AO |
1317 | { |
1318 | bfd_vma fixup_offset; | |
1319 | ||
1320 | if (rofixup->flags & SEC_EXCLUDE) | |
1321 | return -1; | |
1322 | ||
1323 | fixup_offset = rofixup->reloc_count * 4; | |
1324 | if (rofixup->contents) | |
1325 | { | |
eea6121a | 1326 | BFD_ASSERT (fixup_offset < rofixup->size); |
51532845 AO |
1327 | bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset); |
1328 | } | |
1329 | rofixup->reloc_count++; | |
3b712a1a | 1330 | |
3f980e41 | 1331 | if (entry && entry->symndx) |
3b712a1a | 1332 | { |
3f980e41 AO |
1333 | /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc |
1334 | above. */ | |
3b712a1a AO |
1335 | BFD_ASSERT (entry->fixups > 0); |
1336 | entry->fixups--; | |
1337 | } | |
1338 | ||
51532845 AO |
1339 | return fixup_offset; |
1340 | } | |
1341 | ||
1342 | /* Find the segment number in which OSEC, and output section, is | |
1343 | located. */ | |
1344 | ||
1345 | static unsigned | |
43850d5b | 1346 | _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec) |
51532845 AO |
1347 | { |
1348 | struct elf_segment_map *m; | |
1349 | Elf_Internal_Phdr *p; | |
1350 | ||
1351 | /* Find the segment that contains the output_section. */ | |
1352 | for (m = elf_tdata (output_bfd)->segment_map, | |
1353 | p = elf_tdata (output_bfd)->phdr; | |
1354 | m != NULL; | |
1355 | m = m->next, p++) | |
1356 | { | |
1357 | int i; | |
1358 | ||
1359 | for (i = m->count - 1; i >= 0; i--) | |
1360 | if (m->sections[i] == osec) | |
1361 | break; | |
1362 | ||
1363 | if (i >= 0) | |
1364 | break; | |
1365 | } | |
1366 | ||
1367 | return p - elf_tdata (output_bfd)->phdr; | |
1368 | } | |
1369 | ||
1370 | inline static bfd_boolean | |
43850d5b | 1371 | _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec) |
51532845 | 1372 | { |
43850d5b | 1373 | unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec); |
51532845 AO |
1374 | |
1375 | return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W); | |
1376 | } | |
1377 | ||
90219bd0 AO |
1378 | #define FRVFDPIC_TLS_BIAS (2048 - 16) |
1379 | ||
1380 | /* Return the base VMA address which should be subtracted from real addresses | |
1381 | when resolving TLSMOFF relocation. | |
1382 | This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */ | |
1383 | ||
1384 | static bfd_vma | |
1385 | tls_biased_base (struct bfd_link_info *info) | |
1386 | { | |
1387 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
1388 | if (elf_hash_table (info)->tls_sec == NULL) | |
1389 | return FRVFDPIC_TLS_BIAS; | |
1390 | return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS; | |
1391 | } | |
1392 | ||
51532845 AO |
1393 | /* Generate relocations for GOT entries, function descriptors, and |
1394 | code for PLT and lazy PLT entries. */ | |
1395 | ||
1396 | inline static bfd_boolean | |
43850d5b AO |
1397 | _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry, |
1398 | bfd *output_bfd, | |
1399 | struct bfd_link_info *info, | |
1400 | asection *sec, | |
1401 | Elf_Internal_Sym *sym, | |
1402 | bfd_vma addend) | |
f12123c0 | 1403 | |
51532845 AO |
1404 | { |
1405 | bfd_vma fd_lazy_rel_offset = (bfd_vma)-1; | |
1406 | int dynindx = -1; | |
1407 | ||
1408 | if (entry->done) | |
1409 | return TRUE; | |
1410 | entry->done = 1; | |
1411 | ||
90219bd0 AO |
1412 | if (entry->got_entry || entry->fdgot_entry || entry->fd_entry |
1413 | || entry->tlsoff_entry || entry->tlsdesc_entry) | |
51532845 AO |
1414 | { |
1415 | /* If the symbol is dynamic, consider it for dynamic | |
1416 | relocations, otherwise decay to section + offset. */ | |
1417 | if (entry->symndx == -1 && entry->d.h->dynindx != -1) | |
1418 | dynindx = entry->d.h->dynindx; | |
1419 | else | |
1420 | { | |
1421 | if (sec->output_section | |
1422 | && ! bfd_is_abs_section (sec->output_section) | |
1423 | && ! bfd_is_und_section (sec->output_section)) | |
1424 | dynindx = elf_section_data (sec->output_section)->dynindx; | |
1425 | else | |
1426 | dynindx = 0; | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | /* Generate relocation for GOT entry pointing to the symbol. */ | |
1431 | if (entry->got_entry) | |
1432 | { | |
1433 | int idx = dynindx; | |
1434 | bfd_vma ad = addend; | |
1435 | ||
1436 | /* If the symbol is dynamic but binds locally, use | |
1437 | section+offset. */ | |
43850d5b AO |
1438 | if (sec && (entry->symndx != -1 |
1439 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1440 | { |
1441 | if (entry->symndx == -1) | |
1442 | ad += entry->d.h->root.u.def.value; | |
1443 | else | |
1444 | ad += sym->st_value; | |
1445 | ad += sec->output_offset; | |
1446 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1447 | idx = elf_section_data (sec->output_section)->dynindx; | |
1448 | else | |
1449 | idx = 0; | |
1450 | } | |
1451 | ||
1452 | /* If we're linking an executable at a fixed address, we can | |
1453 | omit the dynamic relocation as long as the symbol is local to | |
1454 | this module. */ | |
1455 | if (info->executable && !info->pie | |
43850d5b AO |
1456 | && (entry->symndx != -1 |
1457 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1458 | { |
1459 | if (sec) | |
1460 | ad += sec->output_section->vma; | |
3b712a1a AO |
1461 | if (entry->symndx != -1 |
1462 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
43850d5b AO |
1463 | _frvfdpic_add_rofixup (output_bfd, |
1464 | frvfdpic_gotfixup_section (info), | |
1465 | frvfdpic_got_section (info)->output_section | |
1466 | ->vma | |
1467 | + frvfdpic_got_section (info)->output_offset | |
1468 | + frvfdpic_got_initial_offset (info) | |
1469 | + entry->got_entry, entry); | |
51532845 AO |
1470 | } |
1471 | else | |
43850d5b AO |
1472 | _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), |
1473 | _bfd_elf_section_offset | |
1474 | (output_bfd, info, | |
1475 | frvfdpic_got_section (info), | |
1476 | frvfdpic_got_initial_offset (info) | |
1477 | + entry->got_entry) | |
1478 | + frvfdpic_got_section (info) | |
1479 | ->output_section->vma | |
1480 | + frvfdpic_got_section (info)->output_offset, | |
1481 | R_FRV_32, idx, ad, entry); | |
f12123c0 | 1482 | |
51532845 | 1483 | bfd_put_32 (output_bfd, ad, |
43850d5b AO |
1484 | frvfdpic_got_section (info)->contents |
1485 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1486 | + entry->got_entry); |
1487 | } | |
1488 | ||
1489 | /* Generate relocation for GOT entry pointing to a canonical | |
1490 | function descriptor. */ | |
1491 | if (entry->fdgot_entry) | |
1492 | { | |
1493 | int reloc, idx; | |
072c8903 | 1494 | bfd_vma ad = 0; |
f12123c0 | 1495 | |
072c8903 AO |
1496 | if (! (entry->symndx == -1 |
1497 | && entry->d.h->root.type == bfd_link_hash_undefweak | |
43850d5b | 1498 | && FRVFDPIC_SYM_LOCAL (info, entry->d.h))) |
51532845 | 1499 | { |
072c8903 AO |
1500 | /* If the symbol is dynamic and there may be dynamic symbol |
1501 | resolution because we are, or are linked with, a shared | |
1502 | library, emit a FUNCDESC relocation such that the dynamic | |
1503 | linker will allocate the function descriptor. If the | |
1504 | symbol needs a non-local function descriptor but binds | |
1505 | locally (e.g., its visibility is protected, emit a | |
1506 | dynamic relocation decayed to section+offset. */ | |
43850d5b AO |
1507 | if (entry->symndx == -1 |
1508 | && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h) | |
1509 | && FRVFDPIC_SYM_LOCAL (info, entry->d.h) | |
072c8903 AO |
1510 | && !(info->executable && !info->pie)) |
1511 | { | |
1512 | reloc = R_FRV_FUNCDESC; | |
1513 | idx = elf_section_data (entry->d.h->root.u.def.section | |
1514 | ->output_section)->dynindx; | |
1515 | ad = entry->d.h->root.u.def.section->output_offset | |
1516 | + entry->d.h->root.u.def.value; | |
1517 | } | |
1518 | else if (entry->symndx == -1 | |
43850d5b | 1519 | && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)) |
072c8903 AO |
1520 | { |
1521 | reloc = R_FRV_FUNCDESC; | |
1522 | idx = dynindx; | |
1523 | ad = addend; | |
1524 | if (ad) | |
303e4c21 AO |
1525 | { |
1526 | (*info->callbacks->reloc_dangerous) | |
1527 | (info, _("relocation requires zero addend"), | |
1528 | elf_hash_table (info)->dynobj, | |
1529 | frvfdpic_got_section (info), | |
1530 | entry->fdgot_entry); | |
1531 | return FALSE; | |
1532 | } | |
072c8903 | 1533 | } |
51532845 | 1534 | else |
072c8903 AO |
1535 | { |
1536 | /* Otherwise, we know we have a private function descriptor, | |
1537 | so reference it directly. */ | |
1538 | if (elf_hash_table (info)->dynamic_sections_created) | |
1539 | BFD_ASSERT (entry->privfd); | |
1540 | reloc = R_FRV_32; | |
43850d5b | 1541 | idx = elf_section_data (frvfdpic_got_section (info) |
072c8903 | 1542 | ->output_section)->dynindx; |
43850d5b AO |
1543 | ad = frvfdpic_got_section (info)->output_offset |
1544 | + frvfdpic_got_initial_offset (info) + entry->fd_entry; | |
072c8903 AO |
1545 | } |
1546 | ||
1547 | /* If there is room for dynamic symbol resolution, emit the | |
1548 | dynamic relocation. However, if we're linking an | |
1549 | executable at a fixed location, we won't have emitted a | |
1550 | dynamic symbol entry for the got section, so idx will be | |
1551 | zero, which means we can and should compute the address | |
1552 | of the private descriptor ourselves. */ | |
1553 | if (info->executable && !info->pie | |
1554 | && (entry->symndx != -1 | |
43850d5b | 1555 | || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))) |
51532845 | 1556 | { |
43850d5b AO |
1557 | ad += frvfdpic_got_section (info)->output_section->vma; |
1558 | _frvfdpic_add_rofixup (output_bfd, | |
1559 | frvfdpic_gotfixup_section (info), | |
1560 | frvfdpic_got_section (info) | |
1561 | ->output_section->vma | |
1562 | + frvfdpic_got_section (info) | |
1563 | ->output_offset | |
1564 | + frvfdpic_got_initial_offset (info) | |
1565 | + entry->fdgot_entry, entry); | |
51532845 | 1566 | } |
072c8903 | 1567 | else |
43850d5b AO |
1568 | _frvfdpic_add_dyn_reloc (output_bfd, |
1569 | frvfdpic_gotrel_section (info), | |
1570 | _bfd_elf_section_offset | |
1571 | (output_bfd, info, | |
1572 | frvfdpic_got_section (info), | |
1573 | frvfdpic_got_initial_offset (info) | |
1574 | + entry->fdgot_entry) | |
1575 | + frvfdpic_got_section (info) | |
1576 | ->output_section->vma | |
1577 | + frvfdpic_got_section (info) | |
1578 | ->output_offset, | |
1579 | reloc, idx, ad, entry); | |
51532845 | 1580 | } |
51532845 AO |
1581 | |
1582 | bfd_put_32 (output_bfd, ad, | |
43850d5b AO |
1583 | frvfdpic_got_section (info)->contents |
1584 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1585 | + entry->fdgot_entry); |
1586 | } | |
1587 | ||
1588 | /* Generate relocation to fill in a private function descriptor in | |
1589 | the GOT. */ | |
1590 | if (entry->fd_entry) | |
1591 | { | |
1592 | int idx = dynindx; | |
1593 | bfd_vma ad = addend; | |
1594 | bfd_vma ofst; | |
1595 | long lowword, highword; | |
1596 | ||
1597 | /* If the symbol is dynamic but binds locally, use | |
1598 | section+offset. */ | |
43850d5b AO |
1599 | if (sec && (entry->symndx != -1 |
1600 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1601 | { |
1602 | if (entry->symndx == -1) | |
1603 | ad += entry->d.h->root.u.def.value; | |
1604 | else | |
1605 | ad += sym->st_value; | |
1606 | ad += sec->output_offset; | |
1607 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1608 | idx = elf_section_data (sec->output_section)->dynindx; | |
1609 | else | |
1610 | idx = 0; | |
1611 | } | |
1612 | ||
1613 | /* If we're linking an executable at a fixed address, we can | |
1614 | omit the dynamic relocation as long as the symbol is local to | |
1615 | this module. */ | |
1616 | if (info->executable && !info->pie | |
43850d5b | 1617 | && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) |
51532845 AO |
1618 | { |
1619 | if (sec) | |
1620 | ad += sec->output_section->vma; | |
1621 | ofst = 0; | |
3b712a1a AO |
1622 | if (entry->symndx != -1 |
1623 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
51532845 | 1624 | { |
43850d5b AO |
1625 | _frvfdpic_add_rofixup (output_bfd, |
1626 | frvfdpic_gotfixup_section (info), | |
1627 | frvfdpic_got_section (info) | |
1628 | ->output_section->vma | |
1629 | + frvfdpic_got_section (info) | |
1630 | ->output_offset | |
1631 | + frvfdpic_got_initial_offset (info) | |
1632 | + entry->fd_entry, entry); | |
1633 | _frvfdpic_add_rofixup (output_bfd, | |
1634 | frvfdpic_gotfixup_section (info), | |
1635 | frvfdpic_got_section (info) | |
1636 | ->output_section->vma | |
1637 | + frvfdpic_got_section (info) | |
1638 | ->output_offset | |
1639 | + frvfdpic_got_initial_offset (info) | |
1640 | + entry->fd_entry + 4, entry); | |
51532845 AO |
1641 | } |
1642 | } | |
1643 | else | |
1644 | { | |
1645 | ofst = | |
43850d5b AO |
1646 | _frvfdpic_add_dyn_reloc (output_bfd, |
1647 | entry->lazyplt | |
1648 | ? frvfdpic_pltrel_section (info) | |
1649 | : frvfdpic_gotrel_section (info), | |
1650 | _bfd_elf_section_offset | |
1651 | (output_bfd, info, | |
1652 | frvfdpic_got_section (info), | |
1653 | frvfdpic_got_initial_offset (info) | |
1654 | + entry->fd_entry) | |
1655 | + frvfdpic_got_section (info) | |
1656 | ->output_section->vma | |
1657 | + frvfdpic_got_section (info) | |
1658 | ->output_offset, | |
1659 | R_FRV_FUNCDESC_VALUE, idx, ad, entry); | |
51532845 AO |
1660 | } |
1661 | ||
1662 | /* If we've omitted the dynamic relocation, just emit the fixed | |
1663 | addresses of the symbol and of the local GOT base offset. */ | |
1664 | if (info->executable && !info->pie && sec && sec->output_section) | |
1665 | { | |
1666 | lowword = ad; | |
43850d5b AO |
1667 | highword = frvfdpic_got_section (info)->output_section->vma |
1668 | + frvfdpic_got_section (info)->output_offset | |
1669 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
1670 | } |
1671 | else if (entry->lazyplt) | |
1672 | { | |
1673 | if (ad) | |
303e4c21 AO |
1674 | { |
1675 | (*info->callbacks->reloc_dangerous) | |
1676 | (info, _("relocation requires zero addend"), | |
1677 | elf_hash_table (info)->dynobj, | |
1678 | frvfdpic_got_section (info), | |
1679 | entry->fd_entry); | |
1680 | return FALSE; | |
1681 | } | |
f12123c0 | 1682 | |
51532845 AO |
1683 | fd_lazy_rel_offset = ofst; |
1684 | ||
1685 | /* A function descriptor used for lazy or local resolving is | |
1686 | initialized such that its high word contains the output | |
1687 | section index in which the PLT entries are located, and | |
1688 | the low word contains the address of the lazy PLT entry | |
1689 | entry point, that must be within the memory region | |
1690 | assigned to that section. */ | |
1691 | lowword = entry->lzplt_entry + 4 | |
43850d5b AO |
1692 | + frvfdpic_plt_section (info)->output_offset |
1693 | + frvfdpic_plt_section (info)->output_section->vma; | |
f12123c0 | 1694 | highword = _frvfdpic_osec_to_segment |
43850d5b | 1695 | (output_bfd, frvfdpic_plt_section (info)->output_section); |
51532845 AO |
1696 | } |
1697 | else | |
1698 | { | |
1699 | /* A function descriptor for a local function gets the index | |
1700 | of the section. For a non-local function, it's | |
1701 | disregarded. */ | |
1702 | lowword = ad; | |
1703 | if (entry->symndx == -1 && entry->d.h->dynindx != -1 | |
1704 | && entry->d.h->dynindx == idx) | |
1705 | highword = 0; | |
1706 | else | |
43850d5b AO |
1707 | highword = _frvfdpic_osec_to_segment |
1708 | (output_bfd, sec->output_section); | |
51532845 AO |
1709 | } |
1710 | ||
1711 | bfd_put_32 (output_bfd, lowword, | |
43850d5b AO |
1712 | frvfdpic_got_section (info)->contents |
1713 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1714 | + entry->fd_entry); |
1715 | bfd_put_32 (output_bfd, highword, | |
43850d5b AO |
1716 | frvfdpic_got_section (info)->contents |
1717 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1718 | + entry->fd_entry + 4); |
1719 | } | |
1720 | ||
1721 | /* Generate code for the PLT entry. */ | |
1722 | if (entry->plt_entry != (bfd_vma) -1) | |
1723 | { | |
43850d5b AO |
1724 | bfd_byte *plt_code = frvfdpic_plt_section (info)->contents |
1725 | + entry->plt_entry; | |
51532845 AO |
1726 | |
1727 | BFD_ASSERT (entry->fd_entry); | |
1728 | ||
1729 | /* Figure out what kind of PLT entry we need, depending on the | |
1730 | location of the function descriptor within the GOT. */ | |
1731 | if (entry->fd_entry >= -(1 << (12 - 1)) | |
1732 | && entry->fd_entry < (1 << (12 - 1))) | |
1733 | { | |
1734 | /* lddi @(gr15, fd_entry), gr14 */ | |
1735 | bfd_put_32 (output_bfd, | |
1736 | 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)), | |
1737 | plt_code); | |
1738 | plt_code += 4; | |
1739 | } | |
1740 | else | |
1741 | { | |
1742 | if (entry->fd_entry >= -(1 << (16 - 1)) | |
1743 | && entry->fd_entry < (1 << (16 - 1))) | |
1744 | { | |
1745 | /* setlos lo(fd_entry), gr14 */ | |
1746 | bfd_put_32 (output_bfd, | |
1747 | 0x9cfc0000 | |
1748 | | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), | |
1749 | plt_code); | |
1750 | plt_code += 4; | |
1751 | } | |
1752 | else | |
1753 | { | |
1754 | /* sethi.p hi(fd_entry), gr14 | |
1755 | setlo lo(fd_entry), gr14 */ | |
1756 | bfd_put_32 (output_bfd, | |
1757 | 0x1cf80000 | |
1758 | | ((entry->fd_entry >> 16) | |
1759 | & (((bfd_vma)1 << 16) - 1)), | |
1760 | plt_code); | |
90219bd0 | 1761 | plt_code += 4; |
51532845 AO |
1762 | bfd_put_32 (output_bfd, |
1763 | 0x9cf40000 | |
1764 | | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), | |
1765 | plt_code); | |
90219bd0 | 1766 | plt_code += 4; |
51532845 AO |
1767 | } |
1768 | /* ldd @(gr14,gr15),gr14 */ | |
1769 | bfd_put_32 (output_bfd, 0x9c08e14f, plt_code); | |
1770 | plt_code += 4; | |
1771 | } | |
1772 | /* jmpl @(gr14,gr0) */ | |
1773 | bfd_put_32 (output_bfd, 0x8030e000, plt_code); | |
1774 | } | |
1775 | ||
1776 | /* Generate code for the lazy PLT entry. */ | |
1777 | if (entry->lzplt_entry != (bfd_vma) -1) | |
1778 | { | |
43850d5b | 1779 | bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents |
51532845 AO |
1780 | + entry->lzplt_entry; |
1781 | bfd_vma resolverStub_addr; | |
1782 | ||
1783 | bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code); | |
1784 | lzplt_code += 4; | |
1785 | ||
43850d5b AO |
1786 | resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE |
1787 | * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC; | |
1788 | if (resolverStub_addr >= frvfdpic_plt_initial_offset (info)) | |
1789 | resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12; | |
51532845 AO |
1790 | |
1791 | if (entry->lzplt_entry == resolverStub_addr) | |
1792 | { | |
1793 | /* This is a lazy PLT entry that includes a resolver call. */ | |
1794 | /* ldd @(gr15,gr0), gr4 | |
1795 | jmpl @(gr4,gr0) */ | |
1796 | bfd_put_32 (output_bfd, 0x8808f140, lzplt_code); | |
1797 | bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4); | |
1798 | } | |
1799 | else | |
1800 | { | |
90219bd0 AO |
1801 | /* bra resolverStub */ |
1802 | bfd_put_32 (output_bfd, | |
1803 | 0xc01a0000 | |
1804 | | (((resolverStub_addr - entry->lzplt_entry) | |
1805 | / 4) & (((bfd_vma)1 << 16) - 1)), | |
1806 | lzplt_code); | |
1807 | } | |
1808 | } | |
1809 | ||
1810 | /* Generate relocation for GOT entry holding the TLS offset. */ | |
1811 | if (entry->tlsoff_entry) | |
1812 | { | |
1813 | int idx = dynindx; | |
1814 | bfd_vma ad = addend; | |
1815 | ||
1816 | if (entry->symndx != -1 | |
1817 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h)) | |
1818 | { | |
1819 | /* If the symbol is dynamic but binds locally, use | |
1820 | section+offset. */ | |
1821 | if (sec) | |
1822 | { | |
1823 | if (entry->symndx == -1) | |
1824 | ad += entry->d.h->root.u.def.value; | |
1825 | else | |
1826 | ad += sym->st_value; | |
1827 | ad += sec->output_offset; | |
1828 | if (sec->output_section | |
1829 | && elf_section_data (sec->output_section)) | |
1830 | idx = elf_section_data (sec->output_section)->dynindx; | |
1831 | else | |
1832 | idx = 0; | |
1833 | } | |
1834 | } | |
1835 | ||
1836 | /* *ABS*+addend is special for TLS relocations, use only the | |
1837 | addend. */ | |
1838 | if (info->executable | |
1839 | && idx == 0 | |
1840 | && (bfd_is_abs_section (sec) | |
1841 | || bfd_is_und_section (sec))) | |
1842 | ; | |
1843 | /* If we're linking an executable, we can entirely omit the | |
1844 | dynamic relocation if the symbol is local to this module. */ | |
1845 | else if (info->executable | |
1846 | && (entry->symndx != -1 | |
1847 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
1848 | { | |
1849 | if (sec) | |
1850 | ad += sec->output_section->vma - tls_biased_base (info); | |
1851 | } | |
1852 | else | |
1853 | { | |
1854 | if (idx == 0 | |
1855 | && (bfd_is_abs_section (sec) | |
1856 | || bfd_is_und_section (sec))) | |
1857 | { | |
303e4c21 AO |
1858 | if (! elf_hash_table (info)->tls_sec) |
1859 | { | |
1860 | (*info->callbacks->undefined_symbol) | |
1861 | (info, "TLS section", elf_hash_table (info)->dynobj, | |
1862 | frvfdpic_got_section (info), entry->tlsoff_entry, TRUE); | |
1863 | return FALSE; | |
1864 | } | |
90219bd0 AO |
1865 | idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; |
1866 | ad += FRVFDPIC_TLS_BIAS; | |
1867 | } | |
1868 | _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), | |
1869 | _bfd_elf_section_offset | |
1870 | (output_bfd, info, | |
1871 | frvfdpic_got_section (info), | |
1872 | frvfdpic_got_initial_offset (info) | |
1873 | + entry->tlsoff_entry) | |
1874 | + frvfdpic_got_section (info) | |
1875 | ->output_section->vma | |
1876 | + frvfdpic_got_section (info) | |
1877 | ->output_offset, | |
1878 | R_FRV_TLSOFF, idx, ad, entry); | |
1879 | } | |
3b36f7e6 | 1880 | |
90219bd0 AO |
1881 | bfd_put_32 (output_bfd, ad, |
1882 | frvfdpic_got_section (info)->contents | |
1883 | + frvfdpic_got_initial_offset (info) | |
1884 | + entry->tlsoff_entry); | |
1885 | } | |
1886 | ||
1887 | if (entry->tlsdesc_entry) | |
1888 | { | |
1889 | int idx = dynindx; | |
1890 | bfd_vma ad = addend; | |
1891 | ||
1892 | /* If the symbol is dynamic but binds locally, use | |
1893 | section+offset. */ | |
1894 | if (sec && (entry->symndx != -1 | |
1895 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
1896 | { | |
1897 | if (entry->symndx == -1) | |
1898 | ad += entry->d.h->root.u.def.value; | |
1899 | else | |
1900 | ad += sym->st_value; | |
1901 | ad += sec->output_offset; | |
1902 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1903 | idx = elf_section_data (sec->output_section)->dynindx; | |
1904 | else | |
1905 | idx = 0; | |
1906 | } | |
1907 | ||
1908 | /* If we didn't set up a TLS offset entry, but we're linking an | |
1909 | executable and the symbol binds locally, we can use the | |
1910 | module offset in the TLS descriptor in relaxations. */ | |
1911 | if (info->executable && ! entry->tlsoff_entry) | |
1912 | entry->tlsoff_entry = entry->tlsdesc_entry + 4; | |
1913 | ||
1914 | if (info->executable && !info->pie | |
1915 | && ((idx == 0 | |
1916 | && (bfd_is_abs_section (sec) | |
1917 | || bfd_is_und_section (sec))) | |
1918 | || entry->symndx != -1 | |
1919 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
1920 | { | |
1921 | /* *ABS*+addend is special for TLS relocations, use only the | |
1922 | addend for the TLS offset, and take the module id as | |
1923 | 0. */ | |
1924 | if (idx == 0 | |
1925 | && (bfd_is_abs_section (sec) | |
1926 | || bfd_is_und_section (sec))) | |
1927 | ; | |
1928 | /* For other TLS symbols that bind locally, add the section | |
1929 | TLS offset to the addend. */ | |
1930 | else if (sec) | |
1931 | ad += sec->output_section->vma - tls_biased_base (info); | |
1932 | ||
1933 | bfd_put_32 (output_bfd, | |
1934 | frvfdpic_plt_section (info)->output_section->vma | |
1935 | + frvfdpic_plt_section (info)->output_offset | |
1936 | + frvfdpic_plt_tls_ret_offset (info), | |
1937 | frvfdpic_got_section (info)->contents | |
1938 | + frvfdpic_got_initial_offset (info) | |
1939 | + entry->tlsdesc_entry); | |
1940 | ||
1941 | _frvfdpic_add_rofixup (output_bfd, | |
1942 | frvfdpic_gotfixup_section (info), | |
1943 | frvfdpic_got_section (info) | |
1944 | ->output_section->vma | |
1945 | + frvfdpic_got_section (info) | |
1946 | ->output_offset | |
1947 | + frvfdpic_got_initial_offset (info) | |
1948 | + entry->tlsdesc_entry, entry); | |
1949 | ||
1950 | BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs); | |
1951 | ||
1952 | /* We've used one of the reserved fixups, so discount it so | |
1953 | that we can check at the end that we've used them | |
1954 | all. */ | |
1955 | frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--; | |
1956 | ||
1957 | /* While at that, make sure the ret instruction makes to the | |
1958 | right location in the PLT. We could do it only when we | |
1959 | got to 0, but since the check at the end will only print | |
1960 | a warning, make sure we have the ret in place in case the | |
1961 | warning is missed. */ | |
1962 | bfd_put_32 (output_bfd, 0xc03a4000, | |
1963 | frvfdpic_plt_section (info)->contents | |
1964 | + frvfdpic_plt_tls_ret_offset (info)); | |
1965 | } | |
1966 | else | |
1967 | { | |
1968 | if (idx == 0 | |
1969 | && (bfd_is_abs_section (sec) | |
1970 | || bfd_is_und_section (sec))) | |
1971 | { | |
303e4c21 AO |
1972 | if (! elf_hash_table (info)->tls_sec) |
1973 | { | |
1974 | (*info->callbacks->undefined_symbol) | |
1975 | (info, "TLS section", elf_hash_table (info)->dynobj, | |
1976 | frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE); | |
1977 | return FALSE; | |
1978 | } | |
90219bd0 AO |
1979 | idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; |
1980 | ad += FRVFDPIC_TLS_BIAS; | |
1981 | } | |
1982 | ||
1983 | _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), | |
1984 | _bfd_elf_section_offset | |
1985 | (output_bfd, info, | |
1986 | frvfdpic_got_section (info), | |
1987 | frvfdpic_got_initial_offset (info) | |
1988 | + entry->tlsdesc_entry) | |
1989 | + frvfdpic_got_section (info) | |
1990 | ->output_section->vma | |
1991 | + frvfdpic_got_section (info) | |
1992 | ->output_offset, | |
1993 | R_FRV_TLSDESC_VALUE, idx, ad, entry); | |
1994 | ||
1995 | bfd_put_32 (output_bfd, 0, | |
1996 | frvfdpic_got_section (info)->contents | |
1997 | + frvfdpic_got_initial_offset (info) | |
1998 | + entry->tlsdesc_entry); | |
1999 | } | |
2000 | ||
2001 | bfd_put_32 (output_bfd, ad, | |
2002 | frvfdpic_got_section (info)->contents | |
2003 | + frvfdpic_got_initial_offset (info) | |
2004 | + entry->tlsdesc_entry + 4); | |
2005 | } | |
2006 | ||
2007 | /* Generate code for the get-TLS-offset PLT entry. */ | |
2008 | if (entry->tlsplt_entry != (bfd_vma) -1) | |
2009 | { | |
2010 | bfd_byte *plt_code = frvfdpic_plt_section (info)->contents | |
2011 | + entry->tlsplt_entry; | |
3b36f7e6 | 2012 | |
90219bd0 AO |
2013 | if (info->executable |
2014 | && (entry->symndx != -1 | |
2015 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
2016 | { | |
2017 | int idx = dynindx; | |
2018 | bfd_vma ad = addend; | |
2019 | ||
2020 | /* sec may be NULL when referencing an undefweak symbol | |
2021 | while linking a static executable. */ | |
2022 | if (!sec) | |
2023 | { | |
2024 | BFD_ASSERT (entry->symndx == -1 | |
2025 | && entry->d.h->root.type == bfd_link_hash_undefweak); | |
2026 | } | |
2027 | else | |
2028 | { | |
2029 | if (entry->symndx == -1) | |
2030 | ad += entry->d.h->root.u.def.value; | |
2031 | else | |
2032 | ad += sym->st_value; | |
2033 | ad += sec->output_offset; | |
2034 | if (sec->output_section | |
2035 | && elf_section_data (sec->output_section)) | |
2036 | idx = elf_section_data (sec->output_section)->dynindx; | |
2037 | else | |
2038 | idx = 0; | |
2039 | } | |
3b36f7e6 | 2040 | |
90219bd0 AO |
2041 | /* *ABS*+addend is special for TLS relocations, use only the |
2042 | addend for the TLS offset, and take the module id as | |
2043 | 0. */ | |
2044 | if (idx == 0 | |
2045 | && (bfd_is_abs_section (sec) | |
2046 | || bfd_is_und_section (sec))) | |
2047 | ; | |
2048 | /* For other TLS symbols that bind locally, add the section | |
2049 | TLS offset to the addend. */ | |
2050 | else if (sec) | |
2051 | ad += sec->output_section->vma - tls_biased_base (info); | |
3b36f7e6 | 2052 | |
90219bd0 AO |
2053 | if ((bfd_signed_vma)ad >= -(1 << (16 - 1)) |
2054 | && (bfd_signed_vma)ad < (1 << (16 - 1))) | |
2055 | { | |
2056 | /* setlos lo(ad), gr9 */ | |
2057 | bfd_put_32 (output_bfd, | |
2058 | 0x92fc0000 | |
2059 | | (ad | |
2060 | & (((bfd_vma)1 << 16) - 1)), | |
2061 | plt_code); | |
2062 | plt_code += 4; | |
2063 | } | |
2064 | else | |
2065 | { | |
2066 | /* sethi.p hi(ad), gr9 | |
2067 | setlo lo(ad), gr9 */ | |
2068 | bfd_put_32 (output_bfd, | |
2069 | 0x12f80000 | |
2070 | | ((ad >> 16) | |
2071 | & (((bfd_vma)1 << 16) - 1)), | |
2072 | plt_code); | |
2073 | plt_code += 4; | |
2074 | bfd_put_32 (output_bfd, | |
2075 | 0x92f40000 | |
2076 | | (ad | |
2077 | & (((bfd_vma)1 << 16) - 1)), | |
2078 | plt_code); | |
2079 | plt_code += 4; | |
2080 | } | |
2081 | /* ret */ | |
2082 | bfd_put_32 (output_bfd, 0xc03a4000, plt_code); | |
2083 | } | |
2084 | else if (entry->tlsoff_entry) | |
2085 | { | |
2086 | /* Figure out what kind of PLT entry we need, depending on the | |
2087 | location of the TLS descriptor within the GOT. */ | |
2088 | if (entry->tlsoff_entry >= -(1 << (12 - 1)) | |
2089 | && entry->tlsoff_entry < (1 << (12 - 1))) | |
2090 | { | |
2091 | /* ldi @(gr15, tlsoff_entry), gr9 */ | |
2092 | bfd_put_32 (output_bfd, | |
2093 | 0x92c8f000 | (entry->tlsoff_entry | |
2094 | & ((1 << 12) - 1)), | |
2095 | plt_code); | |
2096 | plt_code += 4; | |
2097 | } | |
2098 | else | |
2099 | { | |
2100 | if (entry->tlsoff_entry >= -(1 << (16 - 1)) | |
2101 | && entry->tlsoff_entry < (1 << (16 - 1))) | |
2102 | { | |
2103 | /* setlos lo(tlsoff_entry), gr8 */ | |
2104 | bfd_put_32 (output_bfd, | |
2105 | 0x90fc0000 | |
2106 | | (entry->tlsoff_entry | |
2107 | & (((bfd_vma)1 << 16) - 1)), | |
2108 | plt_code); | |
2109 | plt_code += 4; | |
2110 | } | |
2111 | else | |
2112 | { | |
2113 | /* sethi.p hi(tlsoff_entry), gr8 | |
2114 | setlo lo(tlsoff_entry), gr8 */ | |
2115 | bfd_put_32 (output_bfd, | |
2116 | 0x10f80000 | |
2117 | | ((entry->tlsoff_entry >> 16) | |
2118 | & (((bfd_vma)1 << 16) - 1)), | |
2119 | plt_code); | |
2120 | plt_code += 4; | |
2121 | bfd_put_32 (output_bfd, | |
2122 | 0x90f40000 | |
2123 | | (entry->tlsoff_entry | |
2124 | & (((bfd_vma)1 << 16) - 1)), | |
2125 | plt_code); | |
2126 | plt_code += 4; | |
2127 | } | |
2128 | /* ld @(gr15,gr8),gr9 */ | |
2129 | bfd_put_32 (output_bfd, 0x9008f108, plt_code); | |
2130 | plt_code += 4; | |
2131 | } | |
2132 | /* ret */ | |
2133 | bfd_put_32 (output_bfd, 0xc03a4000, plt_code); | |
2134 | } | |
2135 | else | |
2136 | { | |
2137 | BFD_ASSERT (entry->tlsdesc_entry); | |
2138 | ||
2139 | /* Figure out what kind of PLT entry we need, depending on the | |
2140 | location of the TLS descriptor within the GOT. */ | |
2141 | if (entry->tlsdesc_entry >= -(1 << (12 - 1)) | |
2142 | && entry->tlsdesc_entry < (1 << (12 - 1))) | |
2143 | { | |
2144 | /* lddi @(gr15, tlsdesc_entry), gr8 */ | |
2145 | bfd_put_32 (output_bfd, | |
2146 | 0x90ccf000 | (entry->tlsdesc_entry | |
2147 | & ((1 << 12) - 1)), | |
2148 | plt_code); | |
2149 | plt_code += 4; | |
2150 | } | |
2151 | else | |
2152 | { | |
2153 | if (entry->tlsdesc_entry >= -(1 << (16 - 1)) | |
2154 | && entry->tlsdesc_entry < (1 << (16 - 1))) | |
2155 | { | |
2156 | /* setlos lo(tlsdesc_entry), gr8 */ | |
2157 | bfd_put_32 (output_bfd, | |
2158 | 0x90fc0000 | |
2159 | | (entry->tlsdesc_entry | |
2160 | & (((bfd_vma)1 << 16) - 1)), | |
2161 | plt_code); | |
2162 | plt_code += 4; | |
2163 | } | |
2164 | else | |
2165 | { | |
2166 | /* sethi.p hi(tlsdesc_entry), gr8 | |
2167 | setlo lo(tlsdesc_entry), gr8 */ | |
2168 | bfd_put_32 (output_bfd, | |
2169 | 0x10f80000 | |
2170 | | ((entry->tlsdesc_entry >> 16) | |
2171 | & (((bfd_vma)1 << 16) - 1)), | |
2172 | plt_code); | |
2173 | plt_code += 4; | |
2174 | bfd_put_32 (output_bfd, | |
2175 | 0x90f40000 | |
2176 | | (entry->tlsdesc_entry | |
2177 | & (((bfd_vma)1 << 16) - 1)), | |
2178 | plt_code); | |
2179 | plt_code += 4; | |
2180 | } | |
2181 | /* ldd @(gr15,gr8),gr8 */ | |
2182 | bfd_put_32 (output_bfd, 0x9008f148, plt_code); | |
2183 | plt_code += 4; | |
2184 | } | |
2185 | /* jmpl @(gr8,gr0) */ | |
2186 | bfd_put_32 (output_bfd, 0x80308000, plt_code); | |
51532845 AO |
2187 | } |
2188 | } | |
2189 | ||
2190 | return TRUE; | |
2191 | } | |
2192 | ||
2193 | /* Handle an FRV small data reloc. */ | |
2194 | ||
2195 | static bfd_reloc_status_type | |
2196 | elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation, | |
2197 | contents, value) | |
2198 | struct bfd_link_info *info; | |
2199 | bfd *input_bfd; | |
2200 | asection *input_section; | |
2201 | Elf_Internal_Rela *relocation; | |
2202 | bfd_byte *contents; | |
2203 | bfd_vma value; | |
2204 | { | |
2205 | bfd_vma insn; | |
2206 | bfd_vma gp; | |
2207 | struct bfd_link_hash_entry *h; | |
2208 | ||
2209 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); | |
2210 | ||
2211 | gp = (h->u.def.value | |
2212 | + h->u.def.section->output_section->vma | |
2213 | + h->u.def.section->output_offset); | |
2214 | ||
2215 | value -= input_section->output_section->vma; | |
2216 | value -= (gp - input_section->output_section->vma); | |
2217 | ||
2218 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2219 | ||
2220 | value += relocation->r_addend; | |
2221 | ||
2222 | if ((long) value > 0x7ff || (long) value < -0x800) | |
2223 | return bfd_reloc_overflow; | |
2224 | ||
2225 | bfd_put_32 (input_bfd, | |
2226 | (insn & 0xfffff000) | (value & 0xfff), | |
2227 | contents + relocation->r_offset); | |
2228 | ||
2229 | return bfd_reloc_ok; | |
2230 | } | |
2231 | ||
2232 | /* Handle an FRV small data reloc. for the u12 field. */ | |
2233 | ||
2234 | static bfd_reloc_status_type | |
2235 | elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation, | |
2236 | contents, value) | |
2237 | struct bfd_link_info *info; | |
2238 | bfd *input_bfd; | |
2239 | asection *input_section; | |
2240 | Elf_Internal_Rela *relocation; | |
2241 | bfd_byte *contents; | |
2242 | bfd_vma value; | |
2243 | { | |
2244 | bfd_vma insn; | |
2245 | bfd_vma gp; | |
2246 | struct bfd_link_hash_entry *h; | |
2247 | bfd_vma mask; | |
2248 | ||
2249 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); | |
2250 | ||
2251 | gp = (h->u.def.value | |
2252 | + h->u.def.section->output_section->vma | |
2253 | + h->u.def.section->output_offset); | |
2254 | ||
2255 | value -= input_section->output_section->vma; | |
2256 | value -= (gp - input_section->output_section->vma); | |
4e5ba5b7 DB |
2257 | |
2258 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2259 | ||
2260 | value += relocation->r_addend; | |
2261 | ||
2262 | if ((long) value > 0x7ff || (long) value < -0x800) | |
2263 | return bfd_reloc_overflow; | |
2264 | ||
2265 | /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */ | |
2266 | mask = 0x3f03f; | |
2267 | insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f); | |
2268 | ||
2269 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
2270 | ||
2271 | return bfd_reloc_ok; | |
2272 | } | |
2273 | ||
2274 | /* Handle an FRV ELF HI16 reloc. */ | |
2275 | ||
2276 | static bfd_reloc_status_type | |
2277 | elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value) | |
2278 | bfd *input_bfd; | |
2279 | Elf_Internal_Rela *relhi; | |
2280 | bfd_byte *contents; | |
2281 | bfd_vma value; | |
2282 | { | |
2283 | bfd_vma insn; | |
2284 | ||
2285 | insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); | |
2286 | ||
2287 | value += relhi->r_addend; | |
2288 | value = ((value >> 16) & 0xffff); | |
2289 | ||
2290 | insn = (insn & 0xffff0000) | value; | |
2291 | ||
2292 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2293 | return bfd_reloc_overflow; | |
2294 | ||
2295 | bfd_put_32 (input_bfd, insn, contents + relhi->r_offset); | |
2296 | return bfd_reloc_ok; | |
2297 | ||
2298 | } | |
2299 | static bfd_reloc_status_type | |
2300 | elf32_frv_relocate_lo16 (input_bfd, rello, contents, value) | |
2301 | bfd *input_bfd; | |
2302 | Elf_Internal_Rela *rello; | |
2303 | bfd_byte *contents; | |
2304 | bfd_vma value; | |
2305 | { | |
2306 | bfd_vma insn; | |
2307 | ||
2308 | insn = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
2309 | ||
2310 | value += rello->r_addend; | |
2311 | value = value & 0xffff; | |
2312 | ||
2313 | insn = (insn & 0xffff0000) | value; | |
2314 | ||
2315 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2316 | return bfd_reloc_overflow; | |
2317 | ||
2318 | bfd_put_32 (input_bfd, insn, contents + rello->r_offset); | |
2319 | return bfd_reloc_ok; | |
2320 | } | |
2321 | ||
2322 | /* Perform the relocation for the CALL label24 instruction. */ | |
2323 | ||
2324 | static bfd_reloc_status_type | |
2325 | elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value) | |
2326 | bfd *input_bfd; | |
2327 | asection *input_section; | |
2328 | Elf_Internal_Rela *rello; | |
2329 | bfd_byte *contents; | |
2330 | bfd_vma value; | |
2331 | { | |
2332 | bfd_vma insn; | |
2333 | bfd_vma label6; | |
2334 | bfd_vma label18; | |
2335 | ||
2336 | /* The format for the call instruction is: | |
2337 | ||
b34976b6 | 2338 | 0 000000 0001111 000000000000000000 |
4e5ba5b7 DB |
2339 | label6 opcode label18 |
2340 | ||
2341 | The branch calculation is: pc + (4*label24) | |
2342 | where label24 is the concatenation of label6 and label18. */ | |
2343 | ||
2344 | /* Grab the instruction. */ | |
2345 | insn = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
2346 | ||
2347 | value -= input_section->output_section->vma + input_section->output_offset; | |
2348 | value -= rello->r_offset; | |
2349 | value += rello->r_addend; | |
2350 | ||
2351 | value = value >> 2; | |
2352 | ||
2353 | label6 = value & 0xfc0000; | |
2354 | label6 = label6 << 7; | |
2355 | ||
2356 | label18 = value & 0x3ffff; | |
2357 | ||
2358 | insn = insn & 0x803c0000; | |
2359 | insn = insn | label6; | |
2360 | insn = insn | label18; | |
2361 | ||
2362 | bfd_put_32 (input_bfd, insn, contents + rello->r_offset); | |
2363 | ||
2364 | return bfd_reloc_ok; | |
2365 | } | |
2366 | ||
2367 | static bfd_reloc_status_type | |
b34976b6 AM |
2368 | elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation, |
2369 | contents, value) | |
4e5ba5b7 DB |
2370 | struct bfd_link_info *info; |
2371 | bfd *input_bfd; | |
2372 | asection *input_section; | |
2373 | Elf_Internal_Rela *relocation; | |
2374 | bfd_byte *contents; | |
2375 | bfd_vma value; | |
2376 | { | |
2377 | bfd_vma insn; | |
2378 | bfd_vma gp; | |
2379 | struct bfd_link_hash_entry *h; | |
2380 | ||
b34976b6 | 2381 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); |
4e5ba5b7 DB |
2382 | |
2383 | gp = (h->u.def.value | |
2384 | + h->u.def.section->output_section->vma | |
2385 | + h->u.def.section->output_offset); | |
2386 | ||
2387 | value -= input_section->output_section->vma; | |
2388 | value -= (gp - input_section->output_section->vma); | |
2389 | value += relocation->r_addend; | |
2390 | value = ((value >> 16) & 0xffff); | |
2391 | ||
2392 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2393 | return bfd_reloc_overflow; | |
2394 | ||
2395 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2396 | insn = (insn & 0xffff0000) | value; | |
2397 | ||
2398 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
2399 | return bfd_reloc_ok; | |
2400 | } | |
2401 | ||
2402 | static bfd_reloc_status_type | |
b34976b6 AM |
2403 | elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation, |
2404 | contents, value) | |
4e5ba5b7 DB |
2405 | struct bfd_link_info *info; |
2406 | bfd *input_bfd; | |
2407 | asection *input_section; | |
2408 | Elf_Internal_Rela *relocation; | |
2409 | bfd_byte *contents; | |
2410 | bfd_vma value; | |
2411 | { | |
2412 | bfd_vma insn; | |
2413 | bfd_vma gp; | |
2414 | struct bfd_link_hash_entry *h; | |
2415 | ||
b34976b6 | 2416 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); |
4e5ba5b7 DB |
2417 | |
2418 | gp = (h->u.def.value | |
2419 | + h->u.def.section->output_section->vma | |
2420 | + h->u.def.section->output_offset); | |
2421 | ||
2422 | value -= input_section->output_section->vma; | |
2423 | value -= (gp - input_section->output_section->vma); | |
2424 | value += relocation->r_addend; | |
2425 | value = value & 0xffff; | |
2426 | ||
2427 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2428 | return bfd_reloc_overflow; | |
2429 | ||
2430 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2431 | insn = (insn & 0xffff0000) | value; | |
2432 | ||
2433 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
2434 | ||
2435 | return bfd_reloc_ok; | |
2436 | } | |
2437 | ||
2438 | static reloc_howto_type * | |
2439 | frv_reloc_type_lookup (abfd, code) | |
b34976b6 | 2440 | bfd *abfd ATTRIBUTE_UNUSED; |
4e5ba5b7 DB |
2441 | bfd_reloc_code_real_type code; |
2442 | { | |
2443 | switch (code) | |
2444 | { | |
2445 | default: | |
2446 | break; | |
2447 | ||
2448 | case BFD_RELOC_NONE: | |
2449 | return &elf32_frv_howto_table[ (int) R_FRV_NONE]; | |
b34976b6 | 2450 | |
4e5ba5b7 | 2451 | case BFD_RELOC_32: |
51532845 AO |
2452 | if (elf_elfheader (abfd)->e_type == ET_EXEC |
2453 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2454 | return &elf32_frv_rel_32_howto; | |
2455 | /* Fall through. */ | |
4e5ba5b7 DB |
2456 | case BFD_RELOC_CTOR: |
2457 | return &elf32_frv_howto_table[ (int) R_FRV_32]; | |
2458 | ||
2459 | case BFD_RELOC_FRV_LABEL16: | |
2460 | return &elf32_frv_howto_table[ (int) R_FRV_LABEL16]; | |
2461 | ||
2462 | case BFD_RELOC_FRV_LABEL24: | |
2463 | return &elf32_frv_howto_table[ (int) R_FRV_LABEL24]; | |
2464 | ||
2465 | case BFD_RELOC_FRV_LO16: | |
2466 | return &elf32_frv_howto_table[ (int) R_FRV_LO16]; | |
2467 | ||
2468 | case BFD_RELOC_FRV_HI16: | |
2469 | return &elf32_frv_howto_table[ (int) R_FRV_HI16]; | |
2470 | ||
2471 | case BFD_RELOC_FRV_GPREL12: | |
2472 | return &elf32_frv_howto_table[ (int) R_FRV_GPREL12]; | |
2473 | ||
2474 | case BFD_RELOC_FRV_GPRELU12: | |
2475 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12]; | |
2476 | ||
2477 | case BFD_RELOC_FRV_GPREL32: | |
2478 | return &elf32_frv_howto_table[ (int) R_FRV_GPREL32]; | |
2479 | ||
2480 | case BFD_RELOC_FRV_GPRELHI: | |
2481 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI]; | |
2482 | ||
2483 | case BFD_RELOC_FRV_GPRELLO: | |
2484 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO]; | |
2485 | ||
51532845 AO |
2486 | case BFD_RELOC_FRV_GOT12: |
2487 | return &elf32_frv_howto_table[ (int) R_FRV_GOT12]; | |
2488 | ||
2489 | case BFD_RELOC_FRV_GOTHI: | |
2490 | return &elf32_frv_howto_table[ (int) R_FRV_GOTHI]; | |
2491 | ||
2492 | case BFD_RELOC_FRV_GOTLO: | |
2493 | return &elf32_frv_howto_table[ (int) R_FRV_GOTLO]; | |
2494 | ||
2495 | case BFD_RELOC_FRV_FUNCDESC: | |
2496 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2497 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2498 | return &elf32_frv_rel_funcdesc_howto; | |
2499 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC]; | |
2500 | ||
2501 | case BFD_RELOC_FRV_FUNCDESC_GOT12: | |
2502 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12]; | |
2503 | ||
2504 | case BFD_RELOC_FRV_FUNCDESC_GOTHI: | |
2505 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI]; | |
2506 | ||
2507 | case BFD_RELOC_FRV_FUNCDESC_GOTLO: | |
2508 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO]; | |
2509 | ||
2510 | case BFD_RELOC_FRV_FUNCDESC_VALUE: | |
2511 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2512 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2513 | return &elf32_frv_rel_funcdesc_value_howto; | |
2514 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE]; | |
2515 | ||
2516 | case BFD_RELOC_FRV_FUNCDESC_GOTOFF12: | |
2517 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12]; | |
2518 | ||
2519 | case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI: | |
2520 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI]; | |
2521 | ||
2522 | case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO: | |
2523 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO]; | |
2524 | ||
2525 | case BFD_RELOC_FRV_GOTOFF12: | |
2526 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12]; | |
2527 | ||
2528 | case BFD_RELOC_FRV_GOTOFFHI: | |
2529 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI]; | |
2530 | ||
2531 | case BFD_RELOC_FRV_GOTOFFLO: | |
2532 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO]; | |
2533 | ||
90219bd0 AO |
2534 | case BFD_RELOC_FRV_GETTLSOFF: |
2535 | return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF]; | |
2536 | ||
2537 | case BFD_RELOC_FRV_TLSDESC_VALUE: | |
2538 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2539 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2540 | return &elf32_frv_rel_tlsdesc_value_howto; | |
2541 | return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE]; | |
2542 | ||
2543 | case BFD_RELOC_FRV_GOTTLSDESC12: | |
2544 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12]; | |
2545 | ||
2546 | case BFD_RELOC_FRV_GOTTLSDESCHI: | |
2547 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI]; | |
2548 | ||
2549 | case BFD_RELOC_FRV_GOTTLSDESCLO: | |
2550 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO]; | |
2551 | ||
2552 | case BFD_RELOC_FRV_TLSMOFF12: | |
2553 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12]; | |
2554 | ||
2555 | case BFD_RELOC_FRV_TLSMOFFHI: | |
2556 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI]; | |
2557 | ||
2558 | case BFD_RELOC_FRV_TLSMOFFLO: | |
2559 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO]; | |
2560 | ||
2561 | case BFD_RELOC_FRV_GOTTLSOFF12: | |
2562 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12]; | |
2563 | ||
2564 | case BFD_RELOC_FRV_GOTTLSOFFHI: | |
2565 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI]; | |
2566 | ||
2567 | case BFD_RELOC_FRV_GOTTLSOFFLO: | |
2568 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO]; | |
2569 | ||
2570 | case BFD_RELOC_FRV_TLSOFF: | |
2571 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2572 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2573 | return &elf32_frv_rel_tlsoff_howto; | |
2574 | return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF]; | |
2575 | ||
2576 | case BFD_RELOC_FRV_TLSDESC_RELAX: | |
2577 | return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX]; | |
2578 | ||
2579 | case BFD_RELOC_FRV_GETTLSOFF_RELAX: | |
2580 | return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX]; | |
2581 | ||
2582 | case BFD_RELOC_FRV_TLSOFF_RELAX: | |
2583 | return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX]; | |
2584 | ||
2585 | case BFD_RELOC_FRV_TLSMOFF: | |
2586 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF]; | |
2587 | ||
4e5ba5b7 DB |
2588 | case BFD_RELOC_VTABLE_INHERIT: |
2589 | return &elf32_frv_vtinherit_howto; | |
2590 | ||
2591 | case BFD_RELOC_VTABLE_ENTRY: | |
2592 | return &elf32_frv_vtentry_howto; | |
2593 | } | |
2594 | ||
2595 | return NULL; | |
2596 | } | |
2597 | ||
2598 | /* Set the howto pointer for an FRV ELF reloc. */ | |
2599 | ||
2600 | static void | |
2601 | frv_info_to_howto_rela (abfd, cache_ptr, dst) | |
b34976b6 AM |
2602 | bfd *abfd ATTRIBUTE_UNUSED; |
2603 | arelent *cache_ptr; | |
2604 | Elf_Internal_Rela *dst; | |
4e5ba5b7 DB |
2605 | { |
2606 | unsigned int r_type; | |
2607 | ||
2608 | r_type = ELF32_R_TYPE (dst->r_info); | |
2609 | switch (r_type) | |
2610 | { | |
2611 | case R_FRV_GNU_VTINHERIT: | |
2612 | cache_ptr->howto = &elf32_frv_vtinherit_howto; | |
2613 | break; | |
2614 | ||
2615 | case R_FRV_GNU_VTENTRY: | |
2616 | cache_ptr->howto = &elf32_frv_vtentry_howto; | |
2617 | break; | |
2618 | ||
2619 | default: | |
2620 | cache_ptr->howto = & elf32_frv_howto_table [r_type]; | |
2621 | break; | |
2622 | } | |
2623 | } | |
51532845 AO |
2624 | |
2625 | /* Set the howto pointer for an FRV ELF REL reloc. */ | |
2626 | static void | |
43850d5b AO |
2627 | frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, |
2628 | arelent *cache_ptr, Elf_Internal_Rela *dst) | |
51532845 AO |
2629 | { |
2630 | unsigned int r_type; | |
2631 | ||
2632 | r_type = ELF32_R_TYPE (dst->r_info); | |
2633 | switch (r_type) | |
2634 | { | |
2635 | case R_FRV_32: | |
2636 | cache_ptr->howto = &elf32_frv_rel_32_howto; | |
2637 | break; | |
2638 | ||
2639 | case R_FRV_FUNCDESC: | |
2640 | cache_ptr->howto = &elf32_frv_rel_funcdesc_howto; | |
2641 | break; | |
2642 | ||
2643 | case R_FRV_FUNCDESC_VALUE: | |
2644 | cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto; | |
2645 | break; | |
2646 | ||
90219bd0 AO |
2647 | case R_FRV_TLSDESC_VALUE: |
2648 | cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto; | |
2649 | break; | |
2650 | ||
2651 | case R_FRV_TLSOFF: | |
2652 | cache_ptr->howto = &elf32_frv_rel_tlsoff_howto; | |
2653 | break; | |
2654 | ||
51532845 AO |
2655 | default: |
2656 | cache_ptr->howto = NULL; | |
2657 | break; | |
2658 | } | |
2659 | } | |
4e5ba5b7 DB |
2660 | \f |
2661 | /* Perform a single relocation. By default we use the standard BFD | |
2662 | routines, but a few relocs, we have to do them ourselves. */ | |
2663 | ||
2664 | static bfd_reloc_status_type | |
b34976b6 AM |
2665 | frv_final_link_relocate (howto, input_bfd, input_section, contents, rel, |
2666 | relocation) | |
2667 | reloc_howto_type *howto; | |
2668 | bfd *input_bfd; | |
2669 | asection *input_section; | |
2670 | bfd_byte *contents; | |
2671 | Elf_Internal_Rela *rel; | |
2672 | bfd_vma relocation; | |
4e5ba5b7 DB |
2673 | { |
2674 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
2675 | contents, rel->r_offset, relocation, | |
2676 | rel->r_addend); | |
2677 | } | |
2678 | ||
2679 | \f | |
2680 | /* Relocate an FRV ELF section. | |
4e5ba5b7 DB |
2681 | |
2682 | The RELOCATE_SECTION function is called by the new ELF backend linker | |
2683 | to handle the relocations for a section. | |
2684 | ||
2685 | The relocs are always passed as Rela structures; if the section | |
2686 | actually uses Rel structures, the r_addend field will always be | |
2687 | zero. | |
2688 | ||
2689 | This function is responsible for adjusting the section contents as | |
1049f94e | 2690 | necessary, and (if using Rela relocs and generating a relocatable |
4e5ba5b7 DB |
2691 | output file) adjusting the reloc addend as necessary. |
2692 | ||
2693 | This function does not have to worry about setting the reloc | |
2694 | address or the reloc symbol index. | |
2695 | ||
2696 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
2697 | ||
2698 | LOCAL_SECTIONS is an array giving the section in the input file | |
2699 | corresponding to the st_shndx field of each local symbol. | |
2700 | ||
2701 | The global hash table entry for the global symbols can be found | |
2702 | via elf_sym_hashes (input_bfd). | |
2703 | ||
1049f94e | 2704 | When generating relocatable output, this function must handle |
4e5ba5b7 DB |
2705 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
2706 | going to be the section symbol corresponding to the output | |
2707 | section, which means that the addend must be adjusted | |
2708 | accordingly. */ | |
2709 | ||
b34976b6 | 2710 | static bfd_boolean |
4e5ba5b7 | 2711 | elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section, |
de2d743e | 2712 | contents, relocs, local_syms, local_sections) |
b34976b6 AM |
2713 | bfd *output_bfd ATTRIBUTE_UNUSED; |
2714 | struct bfd_link_info *info; | |
2715 | bfd *input_bfd; | |
2716 | asection *input_section; | |
2717 | bfd_byte *contents; | |
2718 | Elf_Internal_Rela *relocs; | |
2719 | Elf_Internal_Sym *local_syms; | |
2720 | asection **local_sections; | |
4e5ba5b7 | 2721 | { |
b34976b6 AM |
2722 | Elf_Internal_Shdr *symtab_hdr; |
2723 | struct elf_link_hash_entry **sym_hashes; | |
2724 | Elf_Internal_Rela *rel; | |
2725 | Elf_Internal_Rela *relend; | |
90219bd0 | 2726 | unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment, |
51532845 AO |
2727 | check_segment[2]; |
2728 | int silence_segment_error = !(info->shared || info->pie); | |
90219bd0 | 2729 | unsigned long insn; |
4e5ba5b7 | 2730 | |
1049f94e | 2731 | if (info->relocatable) |
b34976b6 | 2732 | return TRUE; |
de2d743e | 2733 | |
4e5ba5b7 DB |
2734 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
2735 | sym_hashes = elf_sym_hashes (input_bfd); | |
2736 | relend = relocs + input_section->reloc_count; | |
2737 | ||
43850d5b AO |
2738 | isec_segment = _frvfdpic_osec_to_segment (output_bfd, |
2739 | input_section->output_section); | |
2740 | if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info)) | |
2741 | got_segment = _frvfdpic_osec_to_segment (output_bfd, | |
2742 | frvfdpic_got_section (info) | |
2743 | ->output_section); | |
51532845 AO |
2744 | else |
2745 | got_segment = -1; | |
43850d5b AO |
2746 | if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info)) |
2747 | gprel_segment = _frvfdpic_osec_to_segment (output_bfd, | |
2748 | frvfdpic_gotfixup_section (info) | |
2749 | ->output_section); | |
51532845 AO |
2750 | else |
2751 | gprel_segment = -1; | |
90219bd0 | 2752 | if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info)) |
43850d5b AO |
2753 | plt_segment = _frvfdpic_osec_to_segment (output_bfd, |
2754 | frvfdpic_plt_section (info) | |
2755 | ->output_section); | |
51532845 AO |
2756 | else |
2757 | plt_segment = -1; | |
90219bd0 AO |
2758 | if (elf_hash_table (info)->tls_sec) |
2759 | tls_segment = _frvfdpic_osec_to_segment (output_bfd, | |
2760 | elf_hash_table (info)->tls_sec); | |
2761 | else | |
2762 | tls_segment = -1; | |
51532845 | 2763 | |
4e5ba5b7 DB |
2764 | for (rel = relocs; rel < relend; rel ++) |
2765 | { | |
b34976b6 AM |
2766 | reloc_howto_type *howto; |
2767 | unsigned long r_symndx; | |
2768 | Elf_Internal_Sym *sym; | |
2769 | asection *sec; | |
2770 | struct elf_link_hash_entry *h; | |
2771 | bfd_vma relocation; | |
2772 | bfd_reloc_status_type r; | |
2773 | const char * name = NULL; | |
2774 | int r_type; | |
51532845 | 2775 | asection *osec; |
43850d5b | 2776 | struct frvfdpic_relocs_info *picrel; |
51532845 AO |
2777 | bfd_vma orig_addend = rel->r_addend; |
2778 | ||
2779 | r_type = ELF32_R_TYPE (rel->r_info); | |
2780 | ||
2781 | if ( r_type == R_FRV_GNU_VTINHERIT | |
2782 | || r_type == R_FRV_GNU_VTENTRY) | |
2783 | continue; | |
2784 | ||
2785 | /* This is a final link. */ | |
2786 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2787 | howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info); | |
2788 | h = NULL; | |
2789 | sym = NULL; | |
2790 | sec = NULL; | |
2791 | ||
2792 | if (r_symndx < symtab_hdr->sh_info) | |
2793 | { | |
2794 | sym = local_syms + r_symndx; | |
2795 | osec = sec = local_sections [r_symndx]; | |
2796 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
2797 | ||
2798 | name = bfd_elf_string_from_elf_section | |
2799 | (input_bfd, symtab_hdr->sh_link, sym->st_name); | |
2800 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; | |
2801 | } | |
2802 | else | |
2803 | { | |
2804 | h = sym_hashes [r_symndx - symtab_hdr->sh_info]; | |
2805 | ||
2806 | while (h->root.type == bfd_link_hash_indirect | |
2807 | || h->root.type == bfd_link_hash_warning) | |
2808 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
2809 | ||
2810 | name = h->root.root.string; | |
2811 | ||
2812 | if ((h->root.type == bfd_link_hash_defined | |
90219bd0 | 2813 | || h->root.type == bfd_link_hash_defweak)) |
51532845 | 2814 | { |
90219bd0 AO |
2815 | if (/* TLSMOFF forces local binding. */ |
2816 | r_type != R_FRV_TLSMOFF | |
2817 | && ! FRVFDPIC_SYM_LOCAL (info, h)) | |
2818 | { | |
2819 | sec = NULL; | |
2820 | relocation = 0; | |
2821 | } | |
2822 | else | |
2823 | { | |
2824 | sec = h->root.u.def.section; | |
2825 | relocation = (h->root.u.def.value | |
2826 | + sec->output_section->vma | |
2827 | + sec->output_offset); | |
2828 | } | |
51532845 AO |
2829 | } |
2830 | else if (h->root.type == bfd_link_hash_undefweak) | |
2831 | { | |
2832 | relocation = 0; | |
2833 | } | |
59c2e50f | 2834 | else if (info->unresolved_syms_in_objects == RM_IGNORE |
51532845 AO |
2835 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
2836 | relocation = 0; | |
2837 | else | |
2838 | { | |
2839 | if (! ((*info->callbacks->undefined_symbol) | |
2840 | (info, h->root.root.string, input_bfd, | |
59c2e50f L |
2841 | input_section, rel->r_offset, |
2842 | (info->unresolved_syms_in_objects == RM_GENERATE_ERROR | |
2843 | || ELF_ST_VISIBILITY (h->other))))) | |
51532845 | 2844 | return FALSE; |
90219bd0 AO |
2845 | relocation = 0; |
2846 | } | |
2847 | osec = sec; | |
2848 | } | |
2849 | ||
2850 | switch (r_type) | |
2851 | { | |
2852 | case R_FRV_LABEL24: | |
2853 | case R_FRV_32: | |
2854 | if (! IS_FDPIC (output_bfd)) | |
2855 | goto non_fdpic; | |
2856 | ||
2857 | case R_FRV_GOT12: | |
2858 | case R_FRV_GOTHI: | |
2859 | case R_FRV_GOTLO: | |
2860 | case R_FRV_FUNCDESC_GOT12: | |
2861 | case R_FRV_FUNCDESC_GOTHI: | |
2862 | case R_FRV_FUNCDESC_GOTLO: | |
2863 | case R_FRV_GOTOFF12: | |
2864 | case R_FRV_GOTOFFHI: | |
2865 | case R_FRV_GOTOFFLO: | |
2866 | case R_FRV_FUNCDESC_GOTOFF12: | |
2867 | case R_FRV_FUNCDESC_GOTOFFHI: | |
2868 | case R_FRV_FUNCDESC_GOTOFFLO: | |
2869 | case R_FRV_FUNCDESC: | |
2870 | case R_FRV_FUNCDESC_VALUE: | |
2871 | case R_FRV_GETTLSOFF: | |
2872 | case R_FRV_TLSDESC_VALUE: | |
2873 | case R_FRV_GOTTLSDESC12: | |
2874 | case R_FRV_GOTTLSDESCHI: | |
2875 | case R_FRV_GOTTLSDESCLO: | |
2876 | case R_FRV_TLSMOFF12: | |
2877 | case R_FRV_TLSMOFFHI: | |
2878 | case R_FRV_TLSMOFFLO: | |
2879 | case R_FRV_GOTTLSOFF12: | |
2880 | case R_FRV_GOTTLSOFFHI: | |
2881 | case R_FRV_GOTTLSOFFLO: | |
2882 | case R_FRV_TLSOFF: | |
2883 | case R_FRV_TLSDESC_RELAX: | |
2884 | case R_FRV_GETTLSOFF_RELAX: | |
2885 | case R_FRV_TLSOFF_RELAX: | |
2886 | case R_FRV_TLSMOFF: | |
2887 | if (h != NULL) | |
2888 | picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info | |
2889 | (info), input_bfd, h, | |
2890 | orig_addend, INSERT); | |
2891 | else | |
2892 | /* In order to find the entry we created before, we must | |
2893 | use the original addend, not the one that may have been | |
2894 | modified by _bfd_elf_rela_local_sym(). */ | |
2895 | picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info | |
2896 | (info), input_bfd, r_symndx, | |
2897 | orig_addend, INSERT); | |
2898 | if (! picrel) | |
2899 | return FALSE; | |
2900 | ||
2901 | if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info, | |
2902 | osec, sym, | |
2903 | rel->r_addend)) | |
2904 | { | |
2905 | (*_bfd_error_handler) | |
303e4c21 AO |
2906 | (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"), |
2907 | input_bfd, input_section, rel->r_offset, name, rel->r_addend); | |
90219bd0 | 2908 | return FALSE; |
90219bd0 AO |
2909 | } |
2910 | ||
2911 | break; | |
2912 | ||
2913 | default: | |
2914 | non_fdpic: | |
2915 | picrel = NULL; | |
2916 | if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) | |
2917 | { | |
2918 | info->callbacks->warning | |
2919 | (info, _("relocation references symbol not defined in the module"), | |
2920 | name, input_bfd, input_section, rel->r_offset); | |
2921 | return FALSE; | |
2922 | } | |
2923 | break; | |
2924 | } | |
2925 | ||
2926 | switch (r_type) | |
2927 | { | |
2928 | case R_FRV_GETTLSOFF: | |
2929 | case R_FRV_TLSDESC_VALUE: | |
2930 | case R_FRV_GOTTLSDESC12: | |
2931 | case R_FRV_GOTTLSDESCHI: | |
2932 | case R_FRV_GOTTLSDESCLO: | |
2933 | case R_FRV_TLSMOFF12: | |
2934 | case R_FRV_TLSMOFFHI: | |
2935 | case R_FRV_TLSMOFFLO: | |
2936 | case R_FRV_GOTTLSOFF12: | |
2937 | case R_FRV_GOTTLSOFFHI: | |
2938 | case R_FRV_GOTTLSOFFLO: | |
2939 | case R_FRV_TLSOFF: | |
2940 | case R_FRV_TLSDESC_RELAX: | |
2941 | case R_FRV_GETTLSOFF_RELAX: | |
2942 | case R_FRV_TLSOFF_RELAX: | |
2943 | case R_FRV_TLSMOFF: | |
2944 | if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec))) | |
2945 | relocation += tls_biased_base (info); | |
2946 | break; | |
2947 | ||
2948 | default: | |
2949 | break; | |
2950 | } | |
2951 | ||
2952 | /* Try to apply TLS relaxations. */ | |
2953 | if (1) | |
2954 | switch (r_type) | |
2955 | { | |
2956 | ||
2957 | #define LOCAL_EXEC_P(info, picrel) \ | |
2958 | ((info)->executable \ | |
2959 | && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h))) | |
2960 | #define INITIAL_EXEC_P(info, picrel) \ | |
2961 | (((info)->executable || (info)->flags & DF_STATIC_TLS) \ | |
2962 | && (picrel)->tlsoff_entry) | |
2963 | ||
2964 | #define IN_RANGE_FOR_OFST12_P(value) \ | |
2965 | ((bfd_vma)((value) + 2048) < (bfd_vma)4096) | |
2966 | #define IN_RANGE_FOR_SETLOS_P(value) \ | |
2967 | ((bfd_vma)((value) + 32768) < (bfd_vma)65536) | |
2968 | #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \ | |
2969 | (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info))) | |
2970 | ||
2971 | #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ | |
2972 | (LOCAL_EXEC_P ((info), (picrel)) \ | |
2973 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) | |
2974 | #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \ | |
2975 | (INITIAL_EXEC_P ((info), (picrel)) \ | |
2976 | && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry)) | |
2977 | ||
2978 | #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \ | |
2979 | (LOCAL_EXEC_P ((info), (picrel))) | |
2980 | #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \ | |
2981 | (INITIAL_EXEC_P ((info), (picrel))) | |
3b36f7e6 | 2982 | |
90219bd0 AO |
2983 | #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ |
2984 | (LOCAL_EXEC_P ((info), (picrel)) \ | |
2985 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) | |
2986 | ||
2987 | case R_FRV_GETTLSOFF: | |
2988 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
2989 | ||
2990 | /* Is this a call instruction? */ | |
2991 | if ((insn & (unsigned long)0x01fc0000) != 0x003c0000) | |
2992 | { | |
2993 | r = info->callbacks->warning | |
2994 | (info, | |
2995 | _("R_FRV_GETTLSOFF not applied to a call instruction"), | |
2996 | name, input_bfd, input_section, rel->r_offset); | |
2997 | return FALSE; | |
2998 | } | |
3b36f7e6 | 2999 | |
90219bd0 AO |
3000 | if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel, |
3001 | relocation + rel->r_addend)) | |
3002 | { | |
3003 | /* Replace the call instruction (except the packing bit) | |
3004 | with setlos #tlsmofflo(symbol+offset), gr9. */ | |
3005 | insn &= (unsigned long)0x80000000; | |
3006 | insn |= (unsigned long)0x12fc0000; | |
3007 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3008 | ||
3009 | r_type = R_FRV_TLSMOFFLO; | |
3010 | howto = elf32_frv_howto_table + r_type; | |
3011 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3012 | } | |
3013 | ||
3014 | else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel)) | |
3015 | { | |
3016 | /* Replace the call instruction (except the packing bit) | |
3017 | with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */ | |
3018 | insn &= (unsigned long)0x80000000; | |
3019 | insn |= (unsigned long)0x12c8f000; | |
3020 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3021 | ||
3022 | r_type = R_FRV_GOTTLSOFF12; | |
3023 | howto = elf32_frv_howto_table + r_type; | |
3024 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3025 | } | |
3026 | ||
3027 | break; | |
3028 | ||
3029 | case R_FRV_GOTTLSDESC12: | |
3030 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3031 | ||
3032 | /* Is this an lddi instruction? */ | |
3033 | if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000) | |
3034 | { | |
3035 | r = info->callbacks->warning | |
3036 | (info, | |
3037 | _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"), | |
3038 | name, input_bfd, input_section, rel->r_offset); | |
3039 | return FALSE; | |
3040 | } | |
3041 | ||
3042 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3043 | relocation + rel->r_addend) | |
3044 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3045 | info)) | |
3046 | { | |
3047 | /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC | |
3048 | with setlos #tlsmofflo(symbol+offset), gr<C+1>. | |
3049 | Preserve the packing bit. */ | |
3050 | insn = (insn & (unsigned long)0x80000000) | |
3051 | | ((insn + (unsigned long)0x02000000) | |
3052 | & (unsigned long)0x7e000000); | |
3053 | insn |= (unsigned long)0x00fc0000; | |
3054 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3055 | ||
3056 | r_type = R_FRV_TLSMOFFLO; | |
3057 | howto = elf32_frv_howto_table + r_type; | |
3058 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3059 | } | |
3060 | ||
3061 | else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3062 | relocation + rel->r_addend)) | |
3063 | { | |
3064 | /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC | |
3065 | with sethi #tlsmoffhi(symbol+offset), gr<C+1>. | |
3066 | Preserve the packing bit. */ | |
3067 | insn = (insn & (unsigned long)0x80000000) | |
3068 | | ((insn + (unsigned long)0x02000000) | |
3069 | & (unsigned long)0x7e000000); | |
3070 | insn |= (unsigned long)0x00f80000; | |
3071 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3072 | ||
3073 | r_type = R_FRV_TLSMOFFHI; | |
3074 | howto = elf32_frv_howto_table + r_type; | |
3075 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3076 | } | |
3077 | ||
3078 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3079 | { | |
3080 | /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC | |
3081 | with ldi @(grB, #gottlsoff12(symbol+offset), | |
3082 | gr<C+1>. Preserve the packing bit. If gottlsoff12 | |
3083 | overflows, we'll error out, but that's sort-of ok, | |
3084 | since we'd started with gottlsdesc12, that's actually | |
3085 | more demanding. Compiling with -fPIE instead of | |
3086 | -fpie would fix it; linking with --relax should fix | |
3087 | it as well. */ | |
3088 | insn = (insn & (unsigned long)0x80cbf000) | |
3089 | | ((insn + (unsigned long)0x02000000) | |
3090 | & (unsigned long)0x7e000000); | |
3091 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3092 | ||
3093 | r_type = R_FRV_GOTTLSOFF12; | |
3094 | howto = elf32_frv_howto_table + r_type; | |
3095 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3096 | } | |
3097 | ||
3098 | break; | |
3099 | ||
3100 | case R_FRV_GOTTLSDESCHI: | |
3101 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3102 | ||
3103 | /* Is this a sethi instruction? */ | |
3104 | if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) | |
3105 | { | |
3106 | r = info->callbacks->warning | |
3107 | (info, | |
3108 | _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"), | |
3109 | name, input_bfd, input_section, rel->r_offset); | |
3110 | return FALSE; | |
3111 | } | |
3112 | ||
3113 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3114 | relocation + rel->r_addend) | |
3115 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3116 | && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))) | |
3117 | { | |
3118 | /* Replace sethi with a nop. Preserve the packing bit. */ | |
3119 | insn &= (unsigned long)0x80000000; | |
3120 | insn |= (unsigned long)0x00880000; | |
3121 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3122 | ||
3123 | /* Nothing to relocate. */ | |
3124 | continue; | |
3125 | } | |
3126 | ||
3127 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3128 | { | |
3129 | /* Simply decay GOTTLSDESC to GOTTLSOFF. */ | |
3130 | r_type = R_FRV_GOTTLSOFFHI; | |
3131 | howto = elf32_frv_howto_table + r_type; | |
3132 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3133 | } | |
3134 | ||
3135 | break; | |
3b36f7e6 | 3136 | |
90219bd0 AO |
3137 | case R_FRV_GOTTLSDESCLO: |
3138 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3139 | ||
3140 | /* Is this a setlo or setlos instruction? */ | |
3141 | if ((insn & (unsigned long)0x01f70000) != 0x00f40000) | |
3142 | { | |
3143 | r = info->callbacks->warning | |
3144 | (info, | |
3145 | _("R_FRV_GOTTLSDESCLO" | |
3146 | " not applied to a setlo or setlos instruction"), | |
3147 | name, input_bfd, input_section, rel->r_offset); | |
3148 | return FALSE; | |
3149 | } | |
3150 | ||
3151 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3152 | relocation + rel->r_addend) | |
3153 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3154 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) | |
3155 | { | |
3156 | /* Replace setlo/setlos with a nop. Preserve the | |
3157 | packing bit. */ | |
3158 | insn &= (unsigned long)0x80000000; | |
3159 | insn |= (unsigned long)0x00880000; | |
3160 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3161 | ||
3162 | /* Nothing to relocate. */ | |
3163 | continue; | |
3164 | } | |
3165 | ||
3166 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3167 | { | |
3168 | /* If the corresponding sethi (if it exists) decayed | |
3169 | to a nop, make sure this becomes (or already is) a | |
3170 | setlos, not setlo. */ | |
3171 | if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)) | |
3172 | { | |
3173 | insn |= (unsigned long)0x00080000; | |
3174 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3175 | } | |
3176 | ||
3177 | /* Simply decay GOTTLSDESC to GOTTLSOFF. */ | |
3178 | r_type = R_FRV_GOTTLSOFFLO; | |
3179 | howto = elf32_frv_howto_table + r_type; | |
3180 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3181 | } | |
3182 | ||
3183 | break; | |
3b36f7e6 | 3184 | |
90219bd0 AO |
3185 | case R_FRV_TLSDESC_RELAX: |
3186 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3187 | ||
3188 | /* Is this an ldd instruction? */ | |
3189 | if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140) | |
3190 | { | |
3191 | r = info->callbacks->warning | |
3192 | (info, | |
3193 | _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"), | |
3194 | name, input_bfd, input_section, rel->r_offset); | |
3195 | return FALSE; | |
3196 | } | |
3197 | ||
3198 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3199 | relocation + rel->r_addend) | |
3200 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3201 | info)) | |
3202 | { | |
3203 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3204 | with setlos #tlsmofflo(symbol+offset), gr<C+1>. | |
3205 | Preserve the packing bit. */ | |
3206 | insn = (insn & (unsigned long)0x80000000) | |
3207 | | ((insn + (unsigned long)0x02000000) | |
3208 | & (unsigned long)0x7e000000); | |
3209 | insn |= (unsigned long)0x00fc0000; | |
3210 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3211 | ||
3212 | r_type = R_FRV_TLSMOFFLO; | |
3213 | howto = elf32_frv_howto_table + r_type; | |
3214 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3215 | } | |
3216 | ||
3217 | else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3218 | relocation + rel->r_addend)) | |
3219 | { | |
3220 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3221 | with sethi #tlsmoffhi(symbol+offset), gr<C+1>. | |
3222 | Preserve the packing bit. */ | |
3223 | insn = (insn & (unsigned long)0x80000000) | |
3224 | | ((insn + (unsigned long)0x02000000) | |
3225 | & (unsigned long)0x7e000000); | |
3226 | insn |= (unsigned long)0x00f80000; | |
3227 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3228 | ||
3229 | r_type = R_FRV_TLSMOFFHI; | |
3230 | howto = elf32_frv_howto_table + r_type; | |
3231 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3232 | } | |
3233 | ||
3234 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3235 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) | |
3236 | { | |
3237 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3238 | with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>. | |
3239 | Preserve the packing bit. */ | |
3240 | insn = (insn & (unsigned long)0x8003f000) | |
3241 | | (unsigned long)0x00c80000 | |
3242 | | ((insn + (unsigned long)0x02000000) | |
3243 | & (unsigned long)0x7e000000); | |
3244 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3245 | ||
3246 | r_type = R_FRV_GOTTLSOFF12; | |
3247 | howto = elf32_frv_howto_table + r_type; | |
3248 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3249 | } | |
3250 | ||
3251 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3252 | { | |
3253 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3254 | with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>. | |
3255 | Preserve the packing bit. */ | |
3256 | insn = (insn & (unsigned long)0x81ffffbf) | |
3257 | | ((insn + (unsigned long)0x02000000) | |
3258 | & (unsigned long)0x7e000000); | |
3259 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3260 | ||
3261 | /* #tlsoff(symbol+offset) is just a relaxation | |
3262 | annotation, so there's nothing left to | |
3263 | relocate. */ | |
3264 | continue; | |
3265 | } | |
3266 | ||
3267 | break; | |
3268 | ||
3269 | case R_FRV_GETTLSOFF_RELAX: | |
3270 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3271 | ||
3272 | /* Is this a calll or callil instruction? */ | |
3273 | if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000) | |
3274 | { | |
3275 | r = info->callbacks->warning | |
3276 | (info, | |
3277 | _("R_FRV_GETTLSOFF_RELAX" | |
3278 | " not applied to a calll instruction"), | |
3279 | name, input_bfd, input_section, rel->r_offset); | |
3280 | return FALSE; | |
3281 | } | |
3282 | ||
3283 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3284 | relocation + rel->r_addend) | |
3285 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3286 | info)) | |
3287 | { | |
3288 | /* Replace calll with a nop. Preserve the packing bit. */ | |
3289 | insn &= (unsigned long)0x80000000; | |
3290 | insn |= (unsigned long)0x00880000; | |
3291 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3292 | ||
3293 | /* Nothing to relocate. */ | |
3294 | continue; | |
3295 | } | |
3296 | ||
3297 | else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3298 | relocation + rel->r_addend)) | |
3299 | { | |
3300 | /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9. | |
3301 | Preserve the packing bit. */ | |
3302 | insn &= (unsigned long)0x80000000; | |
3303 | insn |= (unsigned long)0x12f40000; | |
3304 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3305 | ||
3306 | r_type = R_FRV_TLSMOFFLO; | |
3307 | howto = elf32_frv_howto_table + r_type; | |
3308 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3309 | } | |
3310 | ||
3311 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3312 | { | |
3313 | /* Replace calll with a nop. Preserve the packing bit. */ | |
3314 | insn &= (unsigned long)0x80000000; | |
3315 | insn |= (unsigned long)0x00880000; | |
3316 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3317 | ||
3318 | /* Nothing to relocate. */ | |
3319 | continue; | |
3320 | } | |
3321 | ||
3322 | break; | |
3323 | ||
3324 | case R_FRV_GOTTLSOFF12: | |
3325 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3326 | ||
3327 | /* Is this an ldi instruction? */ | |
3328 | if ((insn & (unsigned long)0x01fc0000) != 0x00c80000) | |
3329 | { | |
3330 | r = info->callbacks->warning | |
3331 | (info, | |
3332 | _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"), | |
3333 | name, input_bfd, input_section, rel->r_offset); | |
3334 | return FALSE; | |
3335 | } | |
3336 | ||
3337 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, | |
3338 | relocation + rel->r_addend)) | |
3339 | { | |
3340 | /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC | |
3341 | with setlos #tlsmofflo(symbol+offset), grC. | |
3342 | Preserve the packing bit. */ | |
3343 | insn &= (unsigned long)0xfe000000; | |
3344 | insn |= (unsigned long)0x00fc0000; | |
3345 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3346 | ||
3347 | r_type = R_FRV_TLSMOFFLO; | |
3348 | howto = elf32_frv_howto_table + r_type; | |
3349 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3350 | } | |
3351 | ||
3352 | break; | |
3353 | ||
3354 | case R_FRV_GOTTLSOFFHI: | |
3355 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3356 | ||
3357 | /* Is this a sethi instruction? */ | |
3358 | if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) | |
3359 | { | |
3360 | r = info->callbacks->warning | |
3361 | (info, | |
3362 | _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"), | |
3363 | name, input_bfd, input_section, rel->r_offset); | |
3364 | return FALSE; | |
3365 | } | |
3366 | ||
3367 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, | |
3368 | relocation + rel->r_addend) | |
3369 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3370 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) | |
3371 | { | |
3372 | /* Replace sethi with a nop. Preserve the packing bit. */ | |
3373 | insn &= (unsigned long)0x80000000; | |
3374 | insn |= (unsigned long)0x00880000; | |
3375 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3376 | ||
3377 | /* Nothing to relocate. */ | |
3378 | continue; | |
3379 | } | |
3380 | ||
3381 | break; | |
3382 | ||
3383 | case R_FRV_GOTTLSOFFLO: | |
3384 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3385 | ||
3386 | /* Is this a setlo or setlos instruction? */ | |
3387 | if ((insn & (unsigned long)0x01f70000) != 0x00f40000) | |
3388 | { | |
3389 | r = info->callbacks->warning | |
3390 | (info, | |
3391 | _("R_FRV_GOTTLSOFFLO" | |
3392 | " not applied to a setlo or setlos instruction"), | |
3393 | name, input_bfd, input_section, rel->r_offset); | |
3394 | return FALSE; | |
3395 | } | |
3396 | ||
3397 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, | |
3398 | relocation + rel->r_addend) | |
3399 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3400 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) | |
3401 | { | |
3402 | /* Replace setlo/setlos with a nop. Preserve the | |
3403 | packing bit. */ | |
3404 | insn &= (unsigned long)0x80000000; | |
3405 | insn |= (unsigned long)0x00880000; | |
3406 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3407 | ||
3408 | /* Nothing to relocate. */ | |
3409 | continue; | |
3410 | } | |
3411 | ||
3412 | break; | |
3413 | ||
3414 | case R_FRV_TLSOFF_RELAX: | |
3415 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3416 | ||
3417 | /* Is this an ld instruction? */ | |
3418 | if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100) | |
3419 | { | |
3420 | r = info->callbacks->warning | |
3421 | (info, | |
3422 | _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"), | |
3423 | name, input_bfd, input_section, rel->r_offset); | |
3424 | return FALSE; | |
3425 | } | |
51532845 | 3426 | |
90219bd0 AO |
3427 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, |
3428 | relocation + rel->r_addend)) | |
3429 | { | |
3430 | /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC | |
3431 | with setlos #tlsmofflo(symbol+offset), grC. | |
3432 | Preserve the packing bit. */ | |
3433 | insn &= (unsigned long)0xfe000000; | |
3434 | insn |= (unsigned long)0x00fc0000; | |
3435 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3436 | ||
3437 | r_type = R_FRV_TLSMOFFLO; | |
3438 | howto = elf32_frv_howto_table + r_type; | |
3439 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3440 | } | |
43850d5b | 3441 | |
90219bd0 AO |
3442 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) |
3443 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) | |
3444 | { | |
3445 | /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC | |
3446 | with ldi @(grB, #gottlsoff12(symbol+offset), grC. | |
3447 | Preserve the packing bit. */ | |
3448 | insn = (insn & (unsigned long)0xfe03f000) | |
3449 | | (unsigned long)0x00c80000;; | |
3450 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3451 | ||
3452 | r_type = R_FRV_GOTTLSOFF12; | |
3453 | howto = elf32_frv_howto_table + r_type; | |
3454 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3455 | } | |
51532845 | 3456 | |
90219bd0 | 3457 | break; |
51532845 | 3458 | |
90219bd0 AO |
3459 | case R_FRV_TLSMOFFHI: |
3460 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
51532845 | 3461 | |
90219bd0 AO |
3462 | /* Is this a sethi instruction? */ |
3463 | if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) | |
3464 | { | |
3465 | r = info->callbacks->warning | |
3466 | (info, | |
3467 | _("R_FRV_TLSMOFFHI not applied to a sethi instruction"), | |
3468 | name, input_bfd, input_section, rel->r_offset); | |
3469 | return FALSE; | |
3470 | } | |
51532845 | 3471 | |
90219bd0 AO |
3472 | if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, |
3473 | info)) | |
3474 | { | |
3475 | /* Replace sethi with a nop. Preserve the packing bit. */ | |
3476 | insn &= (unsigned long)0x80000000; | |
3477 | insn |= (unsigned long)0x00880000; | |
3478 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3479 | ||
3480 | /* Nothing to relocate. */ | |
3481 | continue; | |
3482 | } | |
3483 | ||
3484 | break; | |
3485 | ||
3486 | case R_FRV_TLSMOFFLO: | |
3487 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3488 | ||
3489 | /* Is this a setlo or setlos instruction? */ | |
3490 | if ((insn & (unsigned long)0x01f70000) != 0x00f40000) | |
3491 | { | |
3492 | r = info->callbacks->warning | |
3493 | (info, | |
3494 | _("R_FRV_TLSMOFFLO" | |
3495 | " not applied to a setlo or setlos instruction"), | |
3496 | name, input_bfd, input_section, rel->r_offset); | |
3497 | return FALSE; | |
3498 | } | |
3499 | ||
3500 | if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3501 | info)) | |
3502 | /* If the corresponding sethi (if it exists) decayed | |
3503 | to a nop, make sure this becomes (or already is) a | |
3504 | setlos, not setlo. */ | |
3505 | { | |
3506 | insn |= (unsigned long)0x00080000; | |
3507 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3508 | } | |
3509 | ||
3510 | break; | |
3511 | ||
0e71e495 BE |
3512 | /* |
3513 | There's nothing to relax in these: | |
3b36f7e6 AM |
3514 | R_FRV_TLSDESC_VALUE |
3515 | R_FRV_TLSOFF | |
3516 | R_FRV_TLSMOFF12 | |
3517 | R_FRV_TLSMOFFHI | |
3518 | R_FRV_TLSMOFFLO | |
3519 | R_FRV_TLSMOFF | |
0e71e495 BE |
3520 | */ |
3521 | ||
90219bd0 AO |
3522 | default: |
3523 | break; | |
3524 | } | |
51532845 AO |
3525 | |
3526 | switch (r_type) | |
3527 | { | |
3528 | case R_FRV_LABEL24: | |
3529 | check_segment[0] = isec_segment; | |
43850d5b AO |
3530 | if (! IS_FDPIC (output_bfd)) |
3531 | check_segment[1] = isec_segment; | |
3532 | else if (picrel->plt) | |
51532845 | 3533 | { |
43850d5b AO |
3534 | relocation = frvfdpic_plt_section (info)->output_section->vma |
3535 | + frvfdpic_plt_section (info)->output_offset | |
51532845 AO |
3536 | + picrel->plt_entry; |
3537 | check_segment[1] = plt_segment; | |
3538 | } | |
3539 | /* We don't want to warn on calls to undefined weak symbols, | |
3540 | as calls to them must be protected by non-NULL tests | |
3541 | anyway, and unprotected calls would invoke undefined | |
3542 | behavior. */ | |
3543 | else if (picrel->symndx == -1 | |
3544 | && picrel->d.h->root.type == bfd_link_hash_undefweak) | |
3545 | check_segment[1] = check_segment[0]; | |
3546 | else | |
3547 | check_segment[1] = sec | |
43850d5b | 3548 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3549 | : (unsigned)-1; |
3550 | break; | |
3551 | ||
3552 | case R_FRV_GOT12: | |
3553 | case R_FRV_GOTHI: | |
3554 | case R_FRV_GOTLO: | |
3555 | relocation = picrel->got_entry; | |
3556 | check_segment[0] = check_segment[1] = got_segment; | |
3557 | break; | |
f12123c0 | 3558 | |
51532845 AO |
3559 | case R_FRV_FUNCDESC_GOT12: |
3560 | case R_FRV_FUNCDESC_GOTHI: | |
3561 | case R_FRV_FUNCDESC_GOTLO: | |
3562 | relocation = picrel->fdgot_entry; | |
3563 | check_segment[0] = check_segment[1] = got_segment; | |
3564 | break; | |
f12123c0 | 3565 | |
51532845 AO |
3566 | case R_FRV_GOTOFFHI: |
3567 | case R_FRV_GOTOFF12: | |
3568 | case R_FRV_GOTOFFLO: | |
43850d5b AO |
3569 | relocation -= frvfdpic_got_section (info)->output_section->vma |
3570 | + frvfdpic_got_section (info)->output_offset | |
3571 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
3572 | check_segment[0] = got_segment; |
3573 | check_segment[1] = sec | |
43850d5b | 3574 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3575 | : (unsigned)-1; |
3576 | break; | |
3577 | ||
3578 | case R_FRV_FUNCDESC_GOTOFF12: | |
3579 | case R_FRV_FUNCDESC_GOTOFFHI: | |
3580 | case R_FRV_FUNCDESC_GOTOFFLO: | |
3581 | relocation = picrel->fd_entry; | |
3582 | check_segment[0] = check_segment[1] = got_segment; | |
3583 | break; | |
3584 | ||
3585 | case R_FRV_FUNCDESC: | |
3586 | { | |
3587 | int dynindx; | |
3588 | bfd_vma addend = rel->r_addend; | |
3589 | ||
072c8903 | 3590 | if (! (h && h->root.type == bfd_link_hash_undefweak |
43850d5b | 3591 | && FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 | 3592 | { |
072c8903 AO |
3593 | /* If the symbol is dynamic and there may be dynamic |
3594 | symbol resolution because we are or are linked with a | |
3595 | shared library, emit a FUNCDESC relocation such that | |
3596 | the dynamic linker will allocate the function | |
3597 | descriptor. If the symbol needs a non-local function | |
3598 | descriptor but binds locally (e.g., its visibility is | |
3599 | protected, emit a dynamic relocation decayed to | |
3600 | section+offset. */ | |
43850d5b AO |
3601 | if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h) |
3602 | && FRVFDPIC_SYM_LOCAL (info, h) | |
072c8903 | 3603 | && !(info->executable && !info->pie)) |
51532845 | 3604 | { |
072c8903 AO |
3605 | dynindx = elf_section_data (h->root.u.def.section |
3606 | ->output_section)->dynindx; | |
3607 | addend += h->root.u.def.section->output_offset | |
3608 | + h->root.u.def.value; | |
3609 | } | |
43850d5b | 3610 | else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)) |
072c8903 AO |
3611 | { |
3612 | if (addend) | |
3613 | { | |
3614 | info->callbacks->warning | |
3615 | (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"), | |
3616 | name, input_bfd, input_section, rel->r_offset); | |
3617 | return FALSE; | |
3618 | } | |
3619 | dynindx = h->dynindx; | |
3620 | } | |
3621 | else | |
3622 | { | |
3623 | /* Otherwise, we know we have a private function | |
3624 | descriptor, so reference it directly. */ | |
3625 | BFD_ASSERT (picrel->privfd); | |
3626 | r_type = R_FRV_32; | |
43850d5b | 3627 | dynindx = elf_section_data (frvfdpic_got_section (info) |
072c8903 | 3628 | ->output_section)->dynindx; |
43850d5b AO |
3629 | addend = frvfdpic_got_section (info)->output_offset |
3630 | + frvfdpic_got_initial_offset (info) | |
072c8903 | 3631 | + picrel->fd_entry; |
51532845 | 3632 | } |
51532845 | 3633 | |
072c8903 AO |
3634 | /* If there is room for dynamic symbol resolution, emit |
3635 | the dynamic relocation. However, if we're linking an | |
3636 | executable at a fixed location, we won't have emitted a | |
3637 | dynamic symbol entry for the got section, so idx will | |
3638 | be zero, which means we can and should compute the | |
3639 | address of the private descriptor ourselves. */ | |
3640 | if (info->executable && !info->pie | |
43850d5b | 3641 | && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h))) |
072c8903 | 3642 | { |
43850d5b | 3643 | addend += frvfdpic_got_section (info)->output_section->vma; |
072c8903 AO |
3644 | if ((bfd_get_section_flags (output_bfd, |
3645 | input_section->output_section) | |
3646 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
3647 | { | |
43850d5b AO |
3648 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3649 | input_section | |
3650 | ->output_section)) | |
072c8903 AO |
3651 | { |
3652 | info->callbacks->warning | |
3653 | (info, | |
3654 | _("cannot emit fixups in read-only section"), | |
3655 | name, input_bfd, input_section, rel->r_offset); | |
3656 | return FALSE; | |
3657 | } | |
43850d5b AO |
3658 | _frvfdpic_add_rofixup (output_bfd, |
3659 | frvfdpic_gotfixup_section | |
3660 | (info), | |
3661 | _bfd_elf_section_offset | |
3662 | (output_bfd, info, | |
3663 | input_section, rel->r_offset) | |
3664 | + input_section | |
3665 | ->output_section->vma | |
3666 | + input_section->output_offset, | |
3667 | picrel); | |
072c8903 AO |
3668 | } |
3669 | } | |
3670 | else if ((bfd_get_section_flags (output_bfd, | |
3671 | input_section->output_section) | |
3672 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
51532845 | 3673 | { |
43850d5b AO |
3674 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3675 | input_section | |
3676 | ->output_section)) | |
51532845 AO |
3677 | { |
3678 | info->callbacks->warning | |
3679 | (info, | |
072c8903 | 3680 | _("cannot emit dynamic relocations in read-only section"), |
51532845 AO |
3681 | name, input_bfd, input_section, rel->r_offset); |
3682 | return FALSE; | |
3683 | } | |
43850d5b AO |
3684 | _frvfdpic_add_dyn_reloc (output_bfd, |
3685 | frvfdpic_gotrel_section (info), | |
3686 | _bfd_elf_section_offset | |
3687 | (output_bfd, info, | |
3688 | input_section, rel->r_offset) | |
3689 | + input_section | |
3690 | ->output_section->vma | |
3691 | + input_section->output_offset, | |
3692 | r_type, dynindx, addend, picrel); | |
51532845 | 3693 | } |
43850d5b AO |
3694 | else |
3695 | addend += frvfdpic_got_section (info)->output_section->vma; | |
51532845 AO |
3696 | } |
3697 | ||
3698 | /* We want the addend in-place because dynamic | |
3699 | relocations are REL. Setting relocation to it should | |
3700 | arrange for it to be installed. */ | |
3701 | relocation = addend - rel->r_addend; | |
3702 | } | |
3703 | check_segment[0] = check_segment[1] = got_segment; | |
3704 | break; | |
3705 | ||
3706 | case R_FRV_32: | |
43850d5b AO |
3707 | if (! IS_FDPIC (output_bfd)) |
3708 | { | |
3709 | check_segment[0] = check_segment[1] = -1; | |
3710 | break; | |
3711 | } | |
3712 | /* Fall through. */ | |
51532845 AO |
3713 | case R_FRV_FUNCDESC_VALUE: |
3714 | { | |
3715 | int dynindx; | |
3716 | bfd_vma addend = rel->r_addend; | |
3717 | ||
3718 | /* If the symbol is dynamic but binds locally, use | |
3719 | section+offset. */ | |
43850d5b | 3720 | if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) |
51532845 AO |
3721 | { |
3722 | if (addend && r_type == R_FRV_FUNCDESC_VALUE) | |
3723 | { | |
3724 | info->callbacks->warning | |
3725 | (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"), | |
3726 | name, input_bfd, input_section, rel->r_offset); | |
3727 | return FALSE; | |
3728 | } | |
3729 | dynindx = h->dynindx; | |
3730 | } | |
3731 | else | |
3732 | { | |
3733 | if (h) | |
3734 | addend += h->root.u.def.value; | |
3735 | else | |
3736 | addend += sym->st_value; | |
3737 | if (osec) | |
3738 | addend += osec->output_offset; | |
3739 | if (osec && osec->output_section | |
3740 | && ! bfd_is_abs_section (osec->output_section) | |
3741 | && ! bfd_is_und_section (osec->output_section)) | |
3742 | dynindx = elf_section_data (osec->output_section)->dynindx; | |
3743 | else | |
3744 | dynindx = 0; | |
3745 | } | |
3746 | ||
3747 | /* If we're linking an executable at a fixed address, we | |
3748 | can omit the dynamic relocation as long as the symbol | |
3749 | is defined in the current link unit (which is implied | |
3750 | by its output section not being NULL). */ | |
3751 | if (info->executable && !info->pie | |
43850d5b | 3752 | && (!h || FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 AO |
3753 | { |
3754 | if (osec) | |
3755 | addend += osec->output_section->vma; | |
43850d5b | 3756 | if (IS_FDPIC (input_bfd) |
51532845 AO |
3757 | && (bfd_get_section_flags (output_bfd, |
3758 | input_section->output_section) | |
3759 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
3760 | { | |
43850d5b AO |
3761 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3762 | input_section | |
3763 | ->output_section)) | |
51532845 AO |
3764 | { |
3765 | info->callbacks->warning | |
3766 | (info, | |
3767 | _("cannot emit fixups in read-only section"), | |
3768 | name, input_bfd, input_section, rel->r_offset); | |
3769 | return FALSE; | |
3770 | } | |
3771 | if (!h || h->root.type != bfd_link_hash_undefweak) | |
3772 | { | |
43850d5b AO |
3773 | _frvfdpic_add_rofixup (output_bfd, |
3774 | frvfdpic_gotfixup_section | |
3775 | (info), | |
3776 | _bfd_elf_section_offset | |
3777 | (output_bfd, info, | |
3778 | input_section, rel->r_offset) | |
3779 | + input_section | |
3780 | ->output_section->vma | |
3781 | + input_section->output_offset, | |
3782 | picrel); | |
51532845 | 3783 | if (r_type == R_FRV_FUNCDESC_VALUE) |
43850d5b | 3784 | _frvfdpic_add_rofixup |
51532845 | 3785 | (output_bfd, |
43850d5b | 3786 | frvfdpic_gotfixup_section (info), |
51532845 AO |
3787 | _bfd_elf_section_offset |
3788 | (output_bfd, info, | |
3789 | input_section, rel->r_offset) | |
3790 | + input_section->output_section->vma | |
3b712a1a | 3791 | + input_section->output_offset + 4, picrel); |
51532845 AO |
3792 | } |
3793 | } | |
3794 | } | |
3795 | else | |
3796 | { | |
3797 | if ((bfd_get_section_flags (output_bfd, | |
3798 | input_section->output_section) | |
3799 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
3800 | { | |
43850d5b AO |
3801 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3802 | input_section | |
3803 | ->output_section)) | |
51532845 AO |
3804 | { |
3805 | info->callbacks->warning | |
3806 | (info, | |
3807 | _("cannot emit dynamic relocations in read-only section"), | |
3808 | name, input_bfd, input_section, rel->r_offset); | |
3809 | return FALSE; | |
3810 | } | |
43850d5b AO |
3811 | _frvfdpic_add_dyn_reloc (output_bfd, |
3812 | frvfdpic_gotrel_section (info), | |
3813 | _bfd_elf_section_offset | |
3814 | (output_bfd, info, | |
3815 | input_section, rel->r_offset) | |
3816 | + input_section | |
3817 | ->output_section->vma | |
3818 | + input_section->output_offset, | |
3819 | r_type, dynindx, addend, picrel); | |
51532845 | 3820 | } |
43850d5b AO |
3821 | else if (osec) |
3822 | addend += osec->output_section->vma; | |
51532845 AO |
3823 | /* We want the addend in-place because dynamic |
3824 | relocations are REL. Setting relocation to it | |
3825 | should arrange for it to be installed. */ | |
3826 | relocation = addend - rel->r_addend; | |
3827 | } | |
3828 | ||
3829 | if (r_type == R_FRV_FUNCDESC_VALUE) | |
3830 | { | |
3831 | /* If we've omitted the dynamic relocation, just emit | |
3832 | the fixed addresses of the symbol and of the local | |
3833 | GOT base offset. */ | |
3834 | if (info->executable && !info->pie | |
43850d5b | 3835 | && (!h || FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 | 3836 | bfd_put_32 (output_bfd, |
43850d5b AO |
3837 | frvfdpic_got_section (info)->output_section->vma |
3838 | + frvfdpic_got_section (info)->output_offset | |
3839 | + frvfdpic_got_initial_offset (info), | |
51532845 AO |
3840 | contents + rel->r_offset + 4); |
3841 | else | |
3842 | /* A function descriptor used for lazy or local | |
3843 | resolving is initialized such that its high word | |
3844 | contains the output section index in which the | |
3845 | PLT entries are located, and the low word | |
3846 | contains the offset of the lazy PLT entry entry | |
3847 | point into that section. */ | |
3848 | bfd_put_32 (output_bfd, | |
43850d5b | 3849 | h && ! FRVFDPIC_SYM_LOCAL (info, h) |
51532845 | 3850 | ? 0 |
43850d5b AO |
3851 | : _frvfdpic_osec_to_segment (output_bfd, |
3852 | sec | |
3853 | ->output_section), | |
51532845 AO |
3854 | contents + rel->r_offset + 4); |
3855 | } | |
3856 | } | |
3857 | check_segment[0] = check_segment[1] = got_segment; | |
3858 | break; | |
3859 | ||
3860 | case R_FRV_GPREL12: | |
3861 | case R_FRV_GPRELU12: | |
3862 | case R_FRV_GPREL32: | |
3863 | case R_FRV_GPRELHI: | |
3864 | case R_FRV_GPRELLO: | |
3865 | check_segment[0] = gprel_segment; | |
3866 | check_segment[1] = sec | |
43850d5b | 3867 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3868 | : (unsigned)-1; |
3869 | break; | |
3870 | ||
90219bd0 AO |
3871 | case R_FRV_GETTLSOFF: |
3872 | relocation = frvfdpic_plt_section (info)->output_section->vma | |
3873 | + frvfdpic_plt_section (info)->output_offset | |
3874 | + picrel->tlsplt_entry; | |
3875 | BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1 | |
3876 | && picrel->tlsdesc_entry); | |
3877 | check_segment[0] = isec_segment; | |
3878 | check_segment[1] = plt_segment; | |
3879 | break; | |
3880 | ||
3881 | case R_FRV_GOTTLSDESC12: | |
3882 | case R_FRV_GOTTLSDESCHI: | |
3883 | case R_FRV_GOTTLSDESCLO: | |
3884 | BFD_ASSERT (picrel->tlsdesc_entry); | |
3885 | relocation = picrel->tlsdesc_entry; | |
3886 | check_segment[0] = tls_segment; | |
3887 | check_segment[1] = sec | |
3888 | && ! bfd_is_abs_section (sec) | |
3889 | && ! bfd_is_und_section (sec) | |
3890 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) | |
3891 | : tls_segment; | |
3892 | break; | |
3893 | ||
3894 | case R_FRV_TLSMOFF12: | |
3895 | case R_FRV_TLSMOFFHI: | |
3896 | case R_FRV_TLSMOFFLO: | |
3897 | case R_FRV_TLSMOFF: | |
3898 | check_segment[0] = tls_segment; | |
3899 | if (! sec) | |
3900 | check_segment[1] = -1; | |
3901 | else if (bfd_is_abs_section (sec) | |
3902 | || bfd_is_und_section (sec)) | |
3903 | { | |
3904 | relocation = 0; | |
3905 | check_segment[1] = tls_segment; | |
3906 | } | |
3907 | else if (sec->output_section) | |
3908 | { | |
3909 | relocation -= tls_biased_base (info); | |
3910 | check_segment[1] = | |
3911 | _frvfdpic_osec_to_segment (output_bfd, sec->output_section); | |
3912 | } | |
68320ddb AO |
3913 | else |
3914 | check_segment[1] = -1; | |
90219bd0 AO |
3915 | break; |
3916 | ||
3917 | case R_FRV_GOTTLSOFF12: | |
3918 | case R_FRV_GOTTLSOFFHI: | |
3919 | case R_FRV_GOTTLSOFFLO: | |
3920 | BFD_ASSERT (picrel->tlsoff_entry); | |
3921 | relocation = picrel->tlsoff_entry; | |
3922 | check_segment[0] = tls_segment; | |
3923 | check_segment[1] = sec | |
3924 | && ! bfd_is_abs_section (sec) | |
3925 | && ! bfd_is_und_section (sec) | |
3926 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) | |
3927 | : tls_segment; | |
3928 | break; | |
3b36f7e6 | 3929 | |
90219bd0 AO |
3930 | case R_FRV_TLSDESC_VALUE: |
3931 | case R_FRV_TLSOFF: | |
3932 | /* These shouldn't be present in input object files. */ | |
3933 | check_segment[0] = check_segment[1] = isec_segment; | |
3934 | break; | |
3935 | ||
3936 | case R_FRV_TLSDESC_RELAX: | |
3937 | case R_FRV_GETTLSOFF_RELAX: | |
3938 | case R_FRV_TLSOFF_RELAX: | |
3939 | /* These are just annotations for relaxation, nothing to do | |
3940 | here. */ | |
3941 | continue; | |
3942 | ||
51532845 AO |
3943 | default: |
3944 | check_segment[0] = isec_segment; | |
3945 | check_segment[1] = sec | |
43850d5b | 3946 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3947 | : (unsigned)-1; |
3948 | break; | |
3949 | } | |
3950 | ||
43850d5b | 3951 | if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd)) |
51532845 | 3952 | { |
0e71e495 BE |
3953 | /* If you take this out, remove the #error from fdpic-static-6.d |
3954 | in the ld testsuite. */ | |
51532845 AO |
3955 | /* This helps catch problems in GCC while we can't do more |
3956 | than static linking. The idea is to test whether the | |
3957 | input file basename is crt0.o only once. */ | |
3958 | if (silence_segment_error == 1) | |
3959 | silence_segment_error = | |
3960 | (strlen (input_bfd->filename) == 6 | |
3961 | && strcmp (input_bfd->filename, "crt0.o") == 0) | |
3962 | || (strlen (input_bfd->filename) > 6 | |
3963 | && strcmp (input_bfd->filename | |
3964 | + strlen (input_bfd->filename) - 7, | |
3965 | "/crt0.o") == 0) | |
3966 | ? -1 : 0; | |
51532845 AO |
3967 | if (!silence_segment_error |
3968 | /* We don't want duplicate errors for undefined | |
3969 | symbols. */ | |
3970 | && !(picrel && picrel->symndx == -1 | |
3971 | && picrel->d.h->root.type == bfd_link_hash_undefined)) | |
68320ddb AO |
3972 | { |
3973 | if (info->shared || info->pie) | |
3974 | (*_bfd_error_handler) | |
3975 | (_("%B(%A+0x%lx): reloc against `%s': %s"), | |
3976 | input_bfd, input_section, (long)rel->r_offset, name, | |
3977 | _("relocation references a different segment")); | |
3978 | else | |
3979 | info->callbacks->warning | |
3980 | (info, | |
3981 | _("relocation references a different segment"), | |
3982 | name, input_bfd, input_section, rel->r_offset); | |
3983 | } | |
51532845 AO |
3984 | if (!silence_segment_error && (info->shared || info->pie)) |
3985 | return FALSE; | |
3986 | elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC; | |
3987 | } | |
3988 | ||
3989 | switch (r_type) | |
3990 | { | |
3991 | case R_FRV_GOTOFFHI: | |
90219bd0 | 3992 | case R_FRV_TLSMOFFHI: |
51532845 AO |
3993 | /* We need the addend to be applied before we shift the |
3994 | value right. */ | |
3995 | relocation += rel->r_addend; | |
3996 | /* Fall through. */ | |
3997 | case R_FRV_GOTHI: | |
3998 | case R_FRV_FUNCDESC_GOTHI: | |
3999 | case R_FRV_FUNCDESC_GOTOFFHI: | |
90219bd0 AO |
4000 | case R_FRV_GOTTLSOFFHI: |
4001 | case R_FRV_GOTTLSDESCHI: | |
51532845 AO |
4002 | relocation >>= 16; |
4003 | /* Fall through. */ | |
4004 | ||
4005 | case R_FRV_GOTLO: | |
4006 | case R_FRV_FUNCDESC_GOTLO: | |
4007 | case R_FRV_GOTOFFLO: | |
4008 | case R_FRV_FUNCDESC_GOTOFFLO: | |
90219bd0 AO |
4009 | case R_FRV_GOTTLSOFFLO: |
4010 | case R_FRV_GOTTLSDESCLO: | |
4011 | case R_FRV_TLSMOFFLO: | |
51532845 AO |
4012 | relocation &= 0xffff; |
4013 | break; | |
4014 | ||
4015 | default: | |
4016 | break; | |
4017 | } | |
4018 | ||
4019 | switch (r_type) | |
4020 | { | |
4021 | case R_FRV_LABEL24: | |
43850d5b | 4022 | if (! IS_FDPIC (output_bfd) || ! picrel->plt) |
51532845 AO |
4023 | break; |
4024 | /* Fall through. */ | |
f12123c0 | 4025 | |
51532845 AO |
4026 | /* When referencing a GOT entry, a function descriptor or a |
4027 | PLT, we don't want the addend to apply to the reference, | |
4028 | but rather to the referenced symbol. The actual entry | |
4029 | will have already been created taking the addend into | |
4030 | account, so cancel it out here. */ | |
4031 | case R_FRV_GOT12: | |
4032 | case R_FRV_GOTHI: | |
4033 | case R_FRV_GOTLO: | |
4034 | case R_FRV_FUNCDESC_GOT12: | |
4035 | case R_FRV_FUNCDESC_GOTHI: | |
4036 | case R_FRV_FUNCDESC_GOTLO: | |
4037 | case R_FRV_FUNCDESC_GOTOFF12: | |
4038 | case R_FRV_FUNCDESC_GOTOFFHI: | |
4039 | case R_FRV_FUNCDESC_GOTOFFLO: | |
90219bd0 AO |
4040 | case R_FRV_GETTLSOFF: |
4041 | case R_FRV_GOTTLSDESC12: | |
4042 | case R_FRV_GOTTLSDESCHI: | |
4043 | case R_FRV_GOTTLSDESCLO: | |
4044 | case R_FRV_GOTTLSOFF12: | |
4045 | case R_FRV_GOTTLSOFFHI: | |
4046 | case R_FRV_GOTTLSOFFLO: | |
51532845 AO |
4047 | /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12 |
4048 | here, since we do want to apply the addend to the others. | |
4049 | Note that we've applied the addend to GOTOFFHI before we | |
f12123c0 | 4050 | shifted it right. */ |
51532845 | 4051 | case R_FRV_GOTOFFHI: |
90219bd0 | 4052 | case R_FRV_TLSMOFFHI: |
51532845 AO |
4053 | relocation -= rel->r_addend; |
4054 | break; | |
4055 | ||
4056 | default: | |
4057 | break; | |
4058 | } | |
4059 | ||
4060 | if (r_type == R_FRV_HI16) | |
4061 | r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation); | |
4062 | ||
4063 | else if (r_type == R_FRV_LO16) | |
4064 | r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation); | |
4065 | ||
90219bd0 | 4066 | else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF) |
51532845 AO |
4067 | r = elf32_frv_relocate_label24 (input_bfd, input_section, rel, |
4068 | contents, relocation); | |
4069 | ||
4070 | else if (r_type == R_FRV_GPREL12) | |
4071 | r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel, | |
4072 | contents, relocation); | |
4073 | ||
4074 | else if (r_type == R_FRV_GPRELU12) | |
4075 | r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel, | |
4076 | contents, relocation); | |
4077 | ||
4078 | else if (r_type == R_FRV_GPRELLO) | |
4079 | r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel, | |
4080 | contents, relocation); | |
4081 | ||
4082 | else if (r_type == R_FRV_GPRELHI) | |
4083 | r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel, | |
4084 | contents, relocation); | |
4085 | ||
90219bd0 AO |
4086 | else if (r_type == R_FRV_TLSOFF |
4087 | || r_type == R_FRV_TLSDESC_VALUE) | |
4088 | r = bfd_reloc_notsupported; | |
4089 | ||
51532845 AO |
4090 | else |
4091 | r = frv_final_link_relocate (howto, input_bfd, input_section, contents, | |
4092 | rel, relocation); | |
4093 | ||
4094 | if (r != bfd_reloc_ok) | |
4095 | { | |
4096 | const char * msg = (const char *) NULL; | |
4097 | ||
4098 | switch (r) | |
4099 | { | |
4100 | case bfd_reloc_overflow: | |
4101 | r = info->callbacks->reloc_overflow | |
dfeffb9f L |
4102 | (info, (h ? &h->root : NULL), name, howto->name, |
4103 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); | |
51532845 AO |
4104 | break; |
4105 | ||
4106 | case bfd_reloc_undefined: | |
4107 | r = info->callbacks->undefined_symbol | |
4108 | (info, name, input_bfd, input_section, rel->r_offset, TRUE); | |
4109 | break; | |
4110 | ||
4111 | case bfd_reloc_outofrange: | |
4112 | msg = _("internal error: out of range error"); | |
4113 | break; | |
4114 | ||
4115 | case bfd_reloc_notsupported: | |
4116 | msg = _("internal error: unsupported relocation error"); | |
4117 | break; | |
4118 | ||
4119 | case bfd_reloc_dangerous: | |
4120 | msg = _("internal error: dangerous relocation"); | |
4121 | break; | |
4122 | ||
4123 | default: | |
4124 | msg = _("internal error: unknown error"); | |
4125 | break; | |
4126 | } | |
4127 | ||
4128 | if (msg) | |
68320ddb AO |
4129 | { |
4130 | (*_bfd_error_handler) | |
4131 | (_("%B(%A+0x%lx): reloc against `%s': %s"), | |
4132 | input_bfd, input_section, (long)rel->r_offset, name, msg); | |
4133 | return FALSE; | |
4134 | } | |
51532845 AO |
4135 | |
4136 | if (! r) | |
4137 | return FALSE; | |
4138 | } | |
4139 | } | |
4140 | ||
4141 | return TRUE; | |
4142 | } | |
4143 | \f | |
4144 | /* Return the section that should be marked against GC for a given | |
4145 | relocation. */ | |
4146 | ||
4147 | static asection * | |
4148 | elf32_frv_gc_mark_hook (sec, info, rel, h, sym) | |
4149 | asection *sec; | |
4150 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
4151 | Elf_Internal_Rela *rel; | |
4152 | struct elf_link_hash_entry *h; | |
4153 | Elf_Internal_Sym *sym; | |
4154 | { | |
4155 | if (h != NULL) | |
4156 | { | |
4157 | switch (ELF32_R_TYPE (rel->r_info)) | |
4158 | { | |
4159 | case R_FRV_GNU_VTINHERIT: | |
4160 | case R_FRV_GNU_VTENTRY: | |
4161 | break; | |
4162 | ||
4163 | default: | |
4164 | switch (h->root.type) | |
4165 | { | |
4166 | default: | |
4167 | break; | |
4168 | ||
4169 | case bfd_link_hash_defined: | |
4170 | case bfd_link_hash_defweak: | |
4171 | return h->root.u.def.section; | |
4172 | ||
4173 | case bfd_link_hash_common: | |
4174 | return h->root.u.c.p->section; | |
4175 | } | |
4176 | } | |
4177 | } | |
4178 | else | |
4179 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
4180 | ||
4181 | return NULL; | |
4182 | } | |
4183 | ||
4184 | /* Update the got entry reference counts for the section being removed. */ | |
4185 | ||
4186 | static bfd_boolean | |
4187 | elf32_frv_gc_sweep_hook (abfd, info, sec, relocs) | |
4188 | bfd *abfd ATTRIBUTE_UNUSED; | |
4189 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
4190 | asection *sec ATTRIBUTE_UNUSED; | |
4191 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; | |
4192 | { | |
4193 | return TRUE; | |
4194 | } | |
4195 | ||
4196 | \f | |
4197 | /* Hook called by the linker routine which adds symbols from an object | |
4198 | file. We use it to put .comm items in .scomm, and not .comm. */ | |
4199 | ||
4200 | static bfd_boolean | |
4201 | elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) | |
4202 | bfd *abfd; | |
4203 | struct bfd_link_info *info; | |
555cd476 | 4204 | Elf_Internal_Sym *sym; |
51532845 AO |
4205 | const char **namep ATTRIBUTE_UNUSED; |
4206 | flagword *flagsp ATTRIBUTE_UNUSED; | |
4207 | asection **secp; | |
4208 | bfd_vma *valp; | |
4209 | { | |
4210 | if (sym->st_shndx == SHN_COMMON | |
4211 | && !info->relocatable | |
4212 | && (int)sym->st_size <= (int)bfd_get_gp_size (abfd)) | |
4213 | { | |
4214 | /* Common symbols less than or equal to -G nn bytes are | |
4215 | automatically put into .sbss. */ | |
4216 | ||
4217 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); | |
4218 | ||
4219 | if (scomm == NULL) | |
4220 | { | |
3496cb2a L |
4221 | scomm = bfd_make_section_with_flags (abfd, ".scommon", |
4222 | (SEC_ALLOC | |
4223 | | SEC_IS_COMMON | |
4224 | | SEC_LINKER_CREATED)); | |
4225 | if (scomm == NULL) | |
51532845 AO |
4226 | return FALSE; |
4227 | } | |
4228 | ||
4229 | *secp = scomm; | |
4230 | *valp = sym->st_size; | |
4231 | } | |
4232 | ||
4233 | return TRUE; | |
4234 | } | |
43850d5b | 4235 | |
aee6f5b4 AO |
4236 | /* We need dynamic symbols for every section, since segments can |
4237 | relocate independently. */ | |
4238 | static bfd_boolean | |
4239 | _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED, | |
4240 | struct bfd_link_info *info | |
4241 | ATTRIBUTE_UNUSED, | |
4242 | asection *p ATTRIBUTE_UNUSED) | |
4243 | { | |
4244 | switch (elf_section_data (p)->this_hdr.sh_type) | |
4245 | { | |
4246 | case SHT_PROGBITS: | |
4247 | case SHT_NOBITS: | |
4248 | /* If sh_type is yet undecided, assume it could be | |
4249 | SHT_PROGBITS/SHT_NOBITS. */ | |
4250 | case SHT_NULL: | |
4251 | return FALSE; | |
4252 | ||
4253 | /* There shouldn't be section relative relocations | |
4254 | against any other section. */ | |
4255 | default: | |
4256 | return TRUE; | |
4257 | } | |
4258 | } | |
4259 | ||
43850d5b | 4260 | /* Create a .got section, as well as its additional info field. This |
51532845 AO |
4261 | is almost entirely copied from |
4262 | elflink.c:_bfd_elf_create_got_section(). */ | |
4263 | ||
4264 | static bfd_boolean | |
4265 | _frv_create_got_section (bfd *abfd, struct bfd_link_info *info) | |
4266 | { | |
90219bd0 | 4267 | flagword flags, pltflags; |
51532845 AO |
4268 | asection *s; |
4269 | struct elf_link_hash_entry *h; | |
4270 | struct bfd_link_hash_entry *bh; | |
4271 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
4272 | int ptralign; | |
43850d5b | 4273 | int offset; |
51532845 AO |
4274 | |
4275 | /* This function may be called more than once. */ | |
4276 | s = bfd_get_section_by_name (abfd, ".got"); | |
4277 | if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0) | |
4278 | return TRUE; | |
4279 | ||
4280 | /* Machine specific: although pointers are 32-bits wide, we want the | |
4281 | GOT to be aligned to a 64-bit boundary, such that function | |
4282 | descriptors in it can be accessed with 64-bit loads and | |
4283 | stores. */ | |
4284 | ptralign = 3; | |
4285 | ||
4286 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
4287 | | SEC_LINKER_CREATED); | |
90219bd0 | 4288 | pltflags = flags; |
51532845 | 4289 | |
3496cb2a | 4290 | s = bfd_make_section_with_flags (abfd, ".got", flags); |
51532845 | 4291 | if (s == NULL |
51532845 AO |
4292 | || !bfd_set_section_alignment (abfd, s, ptralign)) |
4293 | return FALSE; | |
4294 | ||
4295 | if (bed->want_got_plt) | |
4296 | { | |
3496cb2a | 4297 | s = bfd_make_section_with_flags (abfd, ".got.plt", flags); |
51532845 | 4298 | if (s == NULL |
51532845 AO |
4299 | || !bfd_set_section_alignment (abfd, s, ptralign)) |
4300 | return FALSE; | |
4301 | } | |
4302 | ||
4303 | if (bed->want_got_sym) | |
4304 | { | |
4305 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | |
4306 | (or .got.plt) section. We don't do this in the linker script | |
4307 | because we don't want to define the symbol if we are not creating | |
4308 | a global offset table. */ | |
d98685ac AM |
4309 | h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); |
4310 | elf_hash_table (info)->hgot = h; | |
4311 | if (h == NULL) | |
51532845 | 4312 | return FALSE; |
51532845 AO |
4313 | |
4314 | /* Machine-specific: we want the symbol for executables as | |
4315 | well. */ | |
c152c796 | 4316 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
51532845 | 4317 | return FALSE; |
51532845 AO |
4318 | } |
4319 | ||
4320 | /* The first bit of the global offset table is the header. */ | |
3b36f7e6 | 4321 | s->size += bed->got_header_size; |
51532845 AO |
4322 | |
4323 | /* This is the machine-specific part. Create and initialize section | |
4324 | data for the got. */ | |
43850d5b AO |
4325 | if (IS_FDPIC (abfd)) |
4326 | { | |
4327 | frvfdpic_got_section (info) = s; | |
90219bd0 AO |
4328 | frvfdpic_relocs_info (info) = htab_try_create (1, |
4329 | frvfdpic_relocs_info_hash, | |
43850d5b AO |
4330 | frvfdpic_relocs_info_eq, |
4331 | (htab_del) NULL); | |
4332 | if (! frvfdpic_relocs_info (info)) | |
4333 | return FALSE; | |
51532845 | 4334 | |
3496cb2a L |
4335 | s = bfd_make_section_with_flags (abfd, ".rel.got", |
4336 | (flags | SEC_READONLY)); | |
43850d5b | 4337 | if (s == NULL |
43850d5b AO |
4338 | || ! bfd_set_section_alignment (abfd, s, 2)) |
4339 | return FALSE; | |
51532845 | 4340 | |
43850d5b | 4341 | frvfdpic_gotrel_section (info) = s; |
51532845 | 4342 | |
43850d5b | 4343 | /* Machine-specific. */ |
3496cb2a L |
4344 | s = bfd_make_section_with_flags (abfd, ".rofixup", |
4345 | (flags | SEC_READONLY)); | |
43850d5b | 4346 | if (s == NULL |
43850d5b AO |
4347 | || ! bfd_set_section_alignment (abfd, s, 2)) |
4348 | return FALSE; | |
51532845 | 4349 | |
43850d5b AO |
4350 | frvfdpic_gotfixup_section (info) = s; |
4351 | offset = -2048; | |
4352 | flags = BSF_GLOBAL; | |
4353 | } | |
4354 | else | |
4355 | { | |
4356 | offset = 2048; | |
4357 | flags = BSF_GLOBAL | BSF_WEAK; | |
4358 | } | |
51532845 | 4359 | |
43850d5b AO |
4360 | /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it |
4361 | turns out that we're linking with a different linker script, the | |
4362 | linker script will override it. */ | |
51532845 AO |
4363 | bh = NULL; |
4364 | if (!(_bfd_generic_link_add_one_symbol | |
43850d5b | 4365 | (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE, |
51532845 AO |
4366 | bed->collect, &bh))) |
4367 | return FALSE; | |
4368 | h = (struct elf_link_hash_entry *) bh; | |
f5385ebf | 4369 | h->def_regular = 1; |
51532845 | 4370 | h->type = STT_OBJECT; |
90219bd0 | 4371 | /* h->other = STV_HIDDEN; */ /* Should we? */ |
51532845 AO |
4372 | |
4373 | /* Machine-specific: we want the symbol for executables as well. */ | |
43850d5b | 4374 | if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h)) |
51532845 | 4375 | return FALSE; |
43850d5b | 4376 | |
90219bd0 AO |
4377 | if (!IS_FDPIC (abfd)) |
4378 | return TRUE; | |
51532845 | 4379 | |
90219bd0 AO |
4380 | /* FDPIC supports Thread Local Storage, and this may require a |
4381 | procedure linkage table for TLS PLT entries. */ | |
51532845 | 4382 | |
51532845 AO |
4383 | /* This is mostly copied from |
4384 | elflink.c:_bfd_elf_create_dynamic_sections(). */ | |
51532845 | 4385 | |
90219bd0 | 4386 | flags = pltflags; |
51532845 AO |
4387 | pltflags |= SEC_CODE; |
4388 | if (bed->plt_not_loaded) | |
4389 | pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); | |
4390 | if (bed->plt_readonly) | |
4391 | pltflags |= SEC_READONLY; | |
4392 | ||
3496cb2a | 4393 | s = bfd_make_section_with_flags (abfd, ".plt", pltflags); |
51532845 | 4394 | if (s == NULL |
51532845 AO |
4395 | || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) |
4396 | return FALSE; | |
4397 | /* FRV-specific: remember it. */ | |
43850d5b | 4398 | frvfdpic_plt_section (info) = s; |
51532845 | 4399 | |
d98685ac AM |
4400 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the |
4401 | .plt section. */ | |
7325306f RS |
4402 | if (bed->want_plt_sym) |
4403 | { | |
4404 | h = _bfd_elf_define_linkage_sym (abfd, info, s, | |
4405 | "_PROCEDURE_LINKAGE_TABLE_"); | |
4406 | elf_hash_table (info)->hplt = h; | |
4407 | if (h == NULL) | |
4408 | return FALSE; | |
4409 | } | |
51532845 AO |
4410 | |
4411 | /* FRV-specific: we want rel relocations for the plt. */ | |
3496cb2a L |
4412 | s = bfd_make_section_with_flags (abfd, ".rel.plt", |
4413 | flags | SEC_READONLY); | |
51532845 | 4414 | if (s == NULL |
51532845 AO |
4415 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) |
4416 | return FALSE; | |
4417 | /* FRV-specific: remember it. */ | |
43850d5b | 4418 | frvfdpic_pltrel_section (info) = s; |
51532845 | 4419 | |
90219bd0 AO |
4420 | return TRUE; |
4421 | } | |
4422 | ||
4423 | /* Make sure the got and plt sections exist, and that our pointers in | |
4424 | the link hash table point to them. */ | |
4425 | ||
4426 | static bfd_boolean | |
4427 | elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |
4428 | { | |
4429 | /* This is mostly copied from | |
4430 | elflink.c:_bfd_elf_create_dynamic_sections(). */ | |
4431 | flagword flags; | |
4432 | asection *s; | |
4433 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
4434 | ||
4435 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
4436 | | SEC_LINKER_CREATED); | |
4437 | ||
4438 | /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and | |
4439 | .rel[a].bss sections. */ | |
4440 | ||
4441 | /* FRV-specific: we want to create the GOT and the PLT in the FRV | |
4442 | way. */ | |
51532845 AO |
4443 | if (! _frv_create_got_section (abfd, info)) |
4444 | return FALSE; | |
4445 | ||
4446 | /* FRV-specific: make sure we created everything we wanted. */ | |
43850d5b AO |
4447 | BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info) |
4448 | && frvfdpic_gotfixup_section (info) | |
4449 | && frvfdpic_plt_section (info) | |
4450 | && frvfdpic_pltrel_section (info)); | |
51532845 AO |
4451 | |
4452 | if (bed->want_dynbss) | |
4453 | { | |
4454 | /* The .dynbss section is a place to put symbols which are defined | |
4455 | by dynamic objects, are referenced by regular objects, and are | |
4456 | not functions. We must allocate space for them in the process | |
4457 | image and use a R_*_COPY reloc to tell the dynamic linker to | |
4458 | initialize them at run time. The linker script puts the .dynbss | |
4459 | section into the .bss section of the final image. */ | |
3496cb2a L |
4460 | s = bfd_make_section_with_flags (abfd, ".dynbss", |
4461 | SEC_ALLOC | SEC_LINKER_CREATED); | |
4462 | if (s == NULL) | |
51532845 AO |
4463 | return FALSE; |
4464 | ||
4465 | /* The .rel[a].bss section holds copy relocs. This section is not | |
4466 | normally needed. We need to create it here, though, so that the | |
4467 | linker will map it to an output section. We can't just create it | |
4468 | only if we need it, because we will not know whether we need it | |
4469 | until we have seen all the input files, and the first time the | |
4470 | main linker code calls BFD after examining all the input files | |
4471 | (size_dynamic_sections) the input sections have already been | |
4472 | mapped to the output sections. If the section turns out not to | |
4473 | be needed, we can discard it later. We will never need this | |
4474 | section when generating a shared object, since they do not use | |
4475 | copy relocs. */ | |
4476 | if (! info->shared) | |
4477 | { | |
3496cb2a L |
4478 | s = bfd_make_section_with_flags (abfd, |
4479 | (bed->default_use_rela_p | |
4480 | ? ".rela.bss" : ".rel.bss"), | |
4481 | flags | SEC_READONLY); | |
51532845 | 4482 | if (s == NULL |
51532845 AO |
4483 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) |
4484 | return FALSE; | |
4485 | } | |
4486 | } | |
4487 | ||
4488 | return TRUE; | |
4489 | } | |
4490 | ||
90219bd0 AO |
4491 | /* Compute the total GOT and PLT size required by each symbol in each |
4492 | range. Symbols may require up to 4 words in the GOT: an entry | |
4493 | pointing to the symbol, an entry pointing to its function | |
4494 | descriptor, and a private function descriptors taking two | |
4495 | words. */ | |
51532845 | 4496 | |
90219bd0 AO |
4497 | static void |
4498 | _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry, | |
4499 | struct _frvfdpic_dynamic_got_info *dinfo) | |
51532845 | 4500 | { |
51532845 AO |
4501 | /* Allocate space for a GOT entry pointing to the symbol. */ |
4502 | if (entry->got12) | |
4503 | dinfo->got12 += 4; | |
4504 | else if (entry->gotlos) | |
4505 | dinfo->gotlos += 4; | |
4506 | else if (entry->gothilo) | |
4507 | dinfo->gothilo += 4; | |
4508 | else | |
4509 | entry->relocs32--; | |
4510 | entry->relocs32++; | |
4511 | ||
4512 | /* Allocate space for a GOT entry pointing to the function | |
4513 | descriptor. */ | |
4514 | if (entry->fdgot12) | |
4515 | dinfo->got12 += 4; | |
4516 | else if (entry->fdgotlos) | |
4517 | dinfo->gotlos += 4; | |
4518 | else if (entry->fdgothilo) | |
4519 | dinfo->gothilo += 4; | |
4520 | else | |
4521 | entry->relocsfd--; | |
4522 | entry->relocsfd++; | |
4523 | ||
4524 | /* Decide whether we need a PLT entry, a function descriptor in the | |
4525 | GOT, and a lazy PLT entry for this symbol. */ | |
4526 | entry->plt = entry->call | |
43850d5b | 4527 | && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) |
51532845 AO |
4528 | && elf_hash_table (dinfo->info)->dynamic_sections_created; |
4529 | entry->privfd = entry->plt | |
4530 | || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo | |
4531 | || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo) | |
4532 | && (entry->symndx != -1 | |
43850d5b | 4533 | || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))); |
51532845 | 4534 | entry->lazyplt = entry->privfd |
43850d5b | 4535 | && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) |
51532845 AO |
4536 | && ! (dinfo->info->flags & DF_BIND_NOW) |
4537 | && elf_hash_table (dinfo->info)->dynamic_sections_created; | |
4538 | ||
4539 | /* Allocate space for a function descriptor. */ | |
4540 | if (entry->fdgoff12) | |
4541 | dinfo->fd12 += 8; | |
4542 | else if (entry->fdgofflos) | |
4543 | dinfo->fdlos += 8; | |
4544 | else if (entry->privfd && entry->plt) | |
4545 | dinfo->fdplt += 8; | |
4546 | else if (entry->privfd) | |
4547 | dinfo->fdhilo += 8; | |
4548 | else | |
4549 | entry->relocsfdv--; | |
4550 | entry->relocsfdv++; | |
4551 | ||
4552 | if (entry->lazyplt) | |
4553 | dinfo->lzplt += 8; | |
90219bd0 AO |
4554 | } |
4555 | ||
4556 | /* Compute the total GOT size required by each TLS symbol in each | |
4557 | range. Symbols may require up to 5 words in the GOT: an entry | |
4558 | holding the TLS offset for the symbol, and an entry with a full TLS | |
4559 | descriptor taking 4 words. */ | |
4560 | ||
4561 | static void | |
4562 | _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry, | |
4563 | struct _frvfdpic_dynamic_got_info *dinfo, | |
4564 | bfd_boolean subtract) | |
4565 | { | |
4566 | const int l = subtract ? -1 : 1; | |
3b36f7e6 | 4567 | |
90219bd0 AO |
4568 | /* Allocate space for a GOT entry with the TLS offset of the |
4569 | symbol. */ | |
4570 | if (entry->tlsoff12) | |
4571 | dinfo->got12 += 4 * l; | |
4572 | else if (entry->tlsofflos) | |
4573 | dinfo->gotlos += 4 * l; | |
4574 | else if (entry->tlsoffhilo) | |
4575 | dinfo->gothilo += 4 * l; | |
4576 | else | |
4577 | entry->relocstlsoff -= l; | |
4578 | entry->relocstlsoff += l; | |
4579 | ||
4580 | /* If there's any TLSOFF relocation, mark the output file as not | |
4581 | suitable for dlopening. This mark will remain even if we relax | |
4582 | all such relocations, but this is not a problem, since we'll only | |
4583 | do so for executables, and we definitely don't want anyone | |
4584 | dlopening executables. */ | |
4585 | if (entry->relocstlsoff) | |
4586 | dinfo->info->flags |= DF_STATIC_TLS; | |
4587 | ||
4588 | /* Allocate space for a TLS descriptor. */ | |
4589 | if (entry->tlsdesc12) | |
4590 | dinfo->tlsd12 += 8 * l; | |
4591 | else if (entry->tlsdesclos) | |
4592 | dinfo->tlsdlos += 8 * l; | |
4593 | else if (entry->tlsplt) | |
4594 | dinfo->tlsdplt += 8 * l; | |
4595 | else if (entry->tlsdeschilo) | |
4596 | dinfo->tlsdhilo += 8 * l; | |
4597 | else | |
4598 | entry->relocstlsd -= l; | |
4599 | entry->relocstlsd += l; | |
4600 | } | |
4601 | ||
4602 | /* Compute the number of dynamic relocations and fixups that a symbol | |
4603 | requires, and add (or subtract) from the grand and per-symbol | |
4604 | totals. */ | |
4605 | ||
4606 | static void | |
4607 | _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry, | |
4608 | struct _frvfdpic_dynamic_got_info *dinfo, | |
4609 | bfd_boolean subtract) | |
4610 | { | |
4611 | bfd_vma relocs = 0, fixups = 0, tlsrets = 0; | |
51532845 AO |
4612 | |
4613 | if (!dinfo->info->executable || dinfo->info->pie) | |
90219bd0 AO |
4614 | { |
4615 | relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv | |
4616 | + entry->relocstlsd; | |
4617 | ||
4618 | /* In the executable, TLS relocations to symbols that bind | |
4619 | locally (including those that resolve to global TLS offsets) | |
4620 | are resolved immediately, without any need for fixups or | |
4621 | dynamic relocations. In shared libraries, however, we must | |
4622 | emit dynamic relocations even for local symbols, because we | |
4623 | don't know the module id the library is going to get at | |
4624 | run-time, nor its TLS base offset. */ | |
4625 | if (!dinfo->info->executable | |
4626 | || (entry->symndx == -1 | |
4627 | && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) | |
4628 | relocs += entry->relocstlsoff; | |
4629 | } | |
51532845 AO |
4630 | else |
4631 | { | |
43850d5b | 4632 | if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)) |
51532845 AO |
4633 | { |
4634 | if (entry->symndx != -1 | |
3b712a1a AO |
4635 | || entry->d.h->root.type != bfd_link_hash_undefweak) |
4636 | fixups += entry->relocs32 + 2 * entry->relocsfdv; | |
90219bd0 AO |
4637 | fixups += entry->relocstlsd; |
4638 | tlsrets += entry->relocstlsd; | |
51532845 AO |
4639 | } |
4640 | else | |
90219bd0 AO |
4641 | { |
4642 | relocs += entry->relocs32 + entry->relocsfdv | |
4643 | + entry->relocstlsoff + entry->relocstlsd; | |
4644 | } | |
3b712a1a | 4645 | |
43850d5b AO |
4646 | if (entry->symndx != -1 |
4647 | || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)) | |
51532845 AO |
4648 | { |
4649 | if (entry->symndx != -1 | |
4650 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
3b712a1a | 4651 | fixups += entry->relocsfd; |
51532845 AO |
4652 | } |
4653 | else | |
3b712a1a | 4654 | relocs += entry->relocsfd; |
51532845 AO |
4655 | } |
4656 | ||
90219bd0 AO |
4657 | if (subtract) |
4658 | { | |
4659 | relocs = - relocs; | |
4660 | fixups = - fixups; | |
4661 | tlsrets = - tlsrets; | |
4662 | } | |
4663 | ||
3b712a1a AO |
4664 | entry->dynrelocs += relocs; |
4665 | entry->fixups += fixups; | |
4666 | dinfo->relocs += relocs; | |
4667 | dinfo->fixups += fixups; | |
90219bd0 AO |
4668 | dinfo->tls_ret_refs += tlsrets; |
4669 | } | |
3b712a1a | 4670 | |
90219bd0 AO |
4671 | /* Look for opportunities to relax TLS relocations. We can assume |
4672 | we're linking the main executable or a static-tls library, since | |
4673 | otherwise we wouldn't have got here. When relaxing, we have to | |
4674 | first undo any previous accounting of TLS uses of fixups, dynamic | |
4675 | relocations, GOT and PLT entries. */ | |
4676 | ||
4677 | static void | |
4678 | _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry, | |
4679 | struct _frvfdpic_dynamic_got_info *dinfo, | |
4680 | bfd_boolean relaxing) | |
4681 | { | |
4682 | bfd_boolean changed = ! relaxing; | |
4683 | ||
4684 | BFD_ASSERT (dinfo->info->executable | |
4685 | || (dinfo->info->flags & DF_STATIC_TLS)); | |
4686 | ||
4687 | if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo) | |
4688 | { | |
4689 | if (! changed) | |
4690 | { | |
4691 | _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); | |
4692 | _frvfdpic_count_tls_entries (entry, dinfo, TRUE); | |
4693 | changed = TRUE; | |
4694 | } | |
4695 | ||
4696 | /* When linking an executable, we can always decay GOTTLSDESC to | |
4697 | TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise. | |
4698 | When linking a static-tls shared library, using TLSMOFF is | |
4699 | not an option, but we can still use GOTTLSOFF. When decaying | |
4700 | to GOTTLSOFF, we must keep the GOT entry in range. We know | |
4701 | it has to fit because we'll be trading the 4 words of hte TLS | |
4702 | descriptor for a single word in the same range. */ | |
4703 | if (! dinfo->info->executable | |
4704 | || (entry->symndx == -1 | |
4705 | && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) | |
4706 | { | |
4707 | entry->tlsoff12 |= entry->tlsdesc12; | |
4708 | entry->tlsofflos |= entry->tlsdesclos; | |
4709 | entry->tlsoffhilo |= entry->tlsdeschilo; | |
4710 | } | |
4711 | ||
4712 | entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0; | |
4713 | } | |
4714 | ||
4715 | /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the | |
4716 | main executable. We have to check whether the symbol's TLSOFF is | |
4717 | in range for a setlos. For symbols with a hash entry, we can | |
4718 | determine exactly what to do; for others locals, we don't have | |
4719 | addresses handy, so we use the size of the TLS section as an | |
4720 | approximation. If we get it wrong, we'll retain a GOT entry | |
4721 | holding the TLS offset (without dynamic relocations or fixups), | |
4722 | but we'll still optimize away the loads from it. Since TLS sizes | |
4723 | are generally very small, it's probably not worth attempting to | |
4724 | do better than this. */ | |
4725 | if ((entry->tlsplt | |
4726 | || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo) | |
4727 | && dinfo->info->executable && relaxing | |
4728 | && ((entry->symndx == -1 | |
4729 | && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) | |
4730 | /* The above may hold for an undefweak TLS symbol, so make | |
4731 | sure we don't have this case before accessing def.value | |
4732 | and def.section. */ | |
4733 | && (entry->d.h->root.type == bfd_link_hash_undefweak | |
4734 | || (bfd_vma)(entry->d.h->root.u.def.value | |
4735 | + (entry->d.h->root.u.def.section | |
4736 | ->output_section->vma) | |
4737 | + entry->d.h->root.u.def.section->output_offset | |
4738 | + entry->addend | |
4739 | - tls_biased_base (dinfo->info) | |
4740 | + 32768) < (bfd_vma)65536)) | |
4741 | || (entry->symndx != -1 | |
4742 | && (elf_hash_table (dinfo->info)->tls_sec->size | |
4743 | + abs (entry->addend) < 32768 + FRVFDPIC_TLS_BIAS)))) | |
4744 | { | |
4745 | if (! changed) | |
4746 | { | |
4747 | _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); | |
4748 | _frvfdpic_count_tls_entries (entry, dinfo, TRUE); | |
4749 | changed = TRUE; | |
4750 | } | |
3b36f7e6 | 4751 | |
90219bd0 AO |
4752 | entry->tlsplt = |
4753 | entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0; | |
4754 | } | |
4755 | ||
4756 | /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already | |
4757 | have a #gottlsoff12 relocation for this entry, or if we can fit | |
4758 | one more in the 12-bit (and 16-bit) ranges. */ | |
4759 | if (entry->tlsplt | |
4760 | && (entry->tlsoff12 | |
4761 | || (relaxing | |
4762 | && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4 | |
4763 | && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 | |
4764 | + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos | |
4765 | <= 65536 - 12 - 4)))) | |
4766 | { | |
4767 | if (! changed) | |
4768 | { | |
4769 | _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); | |
4770 | _frvfdpic_count_tls_entries (entry, dinfo, TRUE); | |
4771 | changed = TRUE; | |
4772 | } | |
4773 | ||
4774 | entry->tlsoff12 = 1; | |
4775 | entry->tlsplt = 0; | |
4776 | } | |
4777 | ||
4778 | if (changed) | |
4779 | { | |
4780 | _frvfdpic_count_tls_entries (entry, dinfo, FALSE); | |
4781 | _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE); | |
4782 | } | |
4783 | ||
4784 | return; | |
51532845 AO |
4785 | } |
4786 | ||
90219bd0 AO |
4787 | /* Compute the total GOT and PLT size required by each symbol in each range. * |
4788 | Symbols may require up to 4 words in the GOT: an entry pointing to | |
4789 | the symbol, an entry pointing to its function descriptor, and a | |
4790 | private function descriptors taking two words. */ | |
51532845 | 4791 | |
90219bd0 AO |
4792 | static int |
4793 | _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_) | |
51532845 | 4794 | { |
90219bd0 AO |
4795 | struct frvfdpic_relocs_info *entry = *entryp; |
4796 | struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; | |
4797 | ||
4798 | _frvfdpic_count_nontls_entries (entry, dinfo); | |
4799 | ||
4800 | if (dinfo->info->executable || (dinfo->info->flags & DF_STATIC_TLS)) | |
4801 | _frvfdpic_relax_tls_entries (entry, dinfo, FALSE); | |
4802 | else | |
4803 | { | |
4804 | _frvfdpic_count_tls_entries (entry, dinfo, FALSE); | |
4805 | _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE); | |
4806 | } | |
51532845 | 4807 | |
90219bd0 AO |
4808 | return 1; |
4809 | } | |
51532845 AO |
4810 | |
4811 | /* Determine the positive and negative ranges to be used by each | |
4812 | offset range in the GOT. FDCUR and CUR, that must be aligned to a | |
4813 | double-word boundary, are the minimum (negative) and maximum | |
4814 | (positive) GOT offsets already used by previous ranges, except for | |
4815 | an ODD entry that may have been left behind. GOT and FD indicate | |
4816 | the size of GOT entries and function descriptors that must be | |
4817 | placed within the range from -WRAP to WRAP. If there's room left, | |
4818 | up to FDPLT bytes should be reserved for additional function | |
4819 | descriptors. */ | |
4820 | ||
4821 | inline static bfd_signed_vma | |
43850d5b AO |
4822 | _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad, |
4823 | bfd_signed_vma fdcur, | |
4824 | bfd_signed_vma odd, | |
4825 | bfd_signed_vma cur, | |
4826 | bfd_vma got, | |
4827 | bfd_vma fd, | |
4828 | bfd_vma fdplt, | |
90219bd0 AO |
4829 | bfd_vma tlsd, |
4830 | bfd_vma tlsdplt, | |
43850d5b | 4831 | bfd_vma wrap) |
51532845 AO |
4832 | { |
4833 | bfd_signed_vma wrapmin = -wrap; | |
90219bd0 | 4834 | const bfd_vma tdescsz = 8; |
51532845 AO |
4835 | |
4836 | /* Start at the given initial points. */ | |
4837 | gad->fdcur = fdcur; | |
4838 | gad->cur = cur; | |
4839 | ||
4840 | /* If we had an incoming odd word and we have any got entries that | |
4841 | are going to use it, consume it, otherwise leave gad->odd at | |
4842 | zero. We might force gad->odd to zero and return the incoming | |
4843 | odd such that it is used by the next range, but then GOT entries | |
4844 | might appear to be out of order and we wouldn't be able to | |
4845 | shorten the GOT by one word if it turns out to end with an | |
4846 | unpaired GOT entry. */ | |
4847 | if (odd && got) | |
4848 | { | |
4849 | gad->odd = odd; | |
4850 | got -= 4; | |
4851 | odd = 0; | |
4852 | } | |
4853 | else | |
4854 | gad->odd = 0; | |
4855 | ||
4856 | /* If we're left with an unpaired GOT entry, compute its location | |
4857 | such that we can return it. Otherwise, if got doesn't require an | |
4858 | odd number of words here, either odd was already zero in the | |
4859 | block above, or it was set to zero because got was non-zero, or | |
4860 | got was already zero. In the latter case, we want the value of | |
4861 | odd to carry over to the return statement, so we don't want to | |
4862 | reset odd unless the condition below is true. */ | |
4863 | if (got & 4) | |
4864 | { | |
4865 | odd = cur + got; | |
4866 | got += 4; | |
4867 | } | |
f12123c0 | 4868 | |
51532845 AO |
4869 | /* Compute the tentative boundaries of this range. */ |
4870 | gad->max = cur + got; | |
4871 | gad->min = fdcur - fd; | |
4872 | gad->fdplt = 0; | |
4873 | ||
4874 | /* If function descriptors took too much space, wrap some of them | |
4875 | around. */ | |
4876 | if (gad->min < wrapmin) | |
4877 | { | |
4878 | gad->max += wrapmin - gad->min; | |
90219bd0 AO |
4879 | gad->tmin = gad->min = wrapmin; |
4880 | } | |
4881 | ||
4882 | /* If GOT entries took too much space, wrap some of them around. | |
4883 | This may well cause gad->min to become lower than wrapmin. This | |
4884 | will cause a relocation overflow later on, so we don't have to | |
4885 | report it here . */ | |
4886 | if ((bfd_vma) gad->max > wrap) | |
4887 | { | |
4888 | gad->min -= gad->max - wrap; | |
4889 | gad->max = wrap; | |
4890 | } | |
4891 | ||
4892 | /* Add TLS descriptors. */ | |
4893 | gad->tmax = gad->max + tlsd; | |
4894 | gad->tmin = gad->min; | |
4895 | gad->tlsdplt = 0; | |
4896 | ||
4897 | /* If TLS descriptors took too much space, wrap an integral number | |
4898 | of them around. */ | |
4899 | if ((bfd_vma) gad->tmax > wrap) | |
4900 | { | |
4901 | bfd_vma wrapsize = gad->tmax - wrap; | |
4902 | ||
4903 | wrapsize += tdescsz / 2; | |
4904 | wrapsize &= ~ tdescsz / 2; | |
4905 | ||
4906 | gad->tmin -= wrapsize; | |
4907 | gad->tmax -= wrapsize; | |
51532845 | 4908 | } |
90219bd0 | 4909 | |
51532845 AO |
4910 | /* If there is space left and we have function descriptors |
4911 | referenced in PLT entries that could take advantage of shorter | |
90219bd0 AO |
4912 | offsets, place them now. */ |
4913 | if (fdplt && gad->tmin > wrapmin) | |
51532845 AO |
4914 | { |
4915 | bfd_vma fds; | |
90219bd0 AO |
4916 | |
4917 | if ((bfd_vma) (gad->tmin - wrapmin) < fdplt) | |
4918 | fds = gad->tmin - wrapmin; | |
51532845 AO |
4919 | else |
4920 | fds = fdplt; | |
4921 | ||
4922 | fdplt -= fds; | |
4923 | gad->min -= fds; | |
90219bd0 | 4924 | gad->tmin -= fds; |
51532845 AO |
4925 | gad->fdplt += fds; |
4926 | } | |
4927 | ||
51532845 AO |
4928 | /* If there is more space left, try to place some more function |
4929 | descriptors for PLT entries. */ | |
90219bd0 | 4930 | if (fdplt && (bfd_vma) gad->tmax < wrap) |
51532845 AO |
4931 | { |
4932 | bfd_vma fds; | |
90219bd0 AO |
4933 | |
4934 | if ((bfd_vma) (wrap - gad->tmax) < fdplt) | |
4935 | fds = wrap - gad->tmax; | |
51532845 AO |
4936 | else |
4937 | fds = fdplt; | |
4938 | ||
4939 | fdplt -= fds; | |
4940 | gad->max += fds; | |
90219bd0 | 4941 | gad->tmax += fds; |
51532845 AO |
4942 | gad->fdplt += fds; |
4943 | } | |
4944 | ||
90219bd0 AO |
4945 | /* If there is space left and we have TLS descriptors referenced in |
4946 | PLT entries that could take advantage of shorter offsets, place | |
4947 | them now. */ | |
4948 | if (tlsdplt && gad->tmin > wrapmin) | |
4949 | { | |
4950 | bfd_vma tlsds; | |
4951 | ||
4952 | if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt) | |
4953 | tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2); | |
4954 | else | |
4955 | tlsds = tlsdplt; | |
4956 | ||
4957 | tlsdplt -= tlsds; | |
4958 | gad->tmin -= tlsds; | |
4959 | gad->tlsdplt += tlsds; | |
4960 | } | |
4961 | ||
4962 | /* If there is more space left, try to place some more TLS | |
4963 | descriptors for PLT entries. Although we could try to fit an | |
4964 | additional TLS descriptor with half of it just before before the | |
4965 | wrap point and another right past the wrap point, this might | |
4966 | cause us to run out of space for the next region, so don't do | |
4967 | it. */ | |
4968 | if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2) | |
4969 | { | |
4970 | bfd_vma tlsds; | |
4971 | ||
4972 | if ((bfd_vma) (wrap - gad->tmax) < tlsdplt) | |
4973 | tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2); | |
4974 | else | |
4975 | tlsds = tlsdplt; | |
4976 | ||
4977 | tlsdplt -= tlsds; | |
4978 | gad->tmax += tlsds; | |
4979 | gad->tlsdplt += tlsds; | |
4980 | } | |
4981 | ||
51532845 AO |
4982 | /* If odd was initially computed as an offset past the wrap point, |
4983 | wrap it around. */ | |
4984 | if (odd > gad->max) | |
4985 | odd = gad->min + odd - gad->max; | |
4986 | ||
43850d5b | 4987 | /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed |
51532845 AO |
4988 | before returning, so do it here too. This guarantees that, |
4989 | should cur and fdcur meet at the wrap point, they'll both be | |
4990 | equal to min. */ | |
4991 | if (gad->cur == gad->max) | |
4992 | gad->cur = gad->min; | |
4993 | ||
90219bd0 AO |
4994 | /* Ditto for _frvfdpic_get_tlsdesc_entry(). */ |
4995 | gad->tcur = gad->max; | |
4996 | if (gad->tcur == gad->tmax) | |
4997 | gad->tcur = gad->tmin; | |
4998 | ||
51532845 AO |
4999 | return odd; |
5000 | } | |
5001 | ||
5002 | /* Compute the location of the next GOT entry, given the allocation | |
5003 | data for a range. */ | |
5004 | ||
5005 | inline static bfd_signed_vma | |
43850d5b | 5006 | _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) |
51532845 AO |
5007 | { |
5008 | bfd_signed_vma ret; | |
f12123c0 | 5009 | |
51532845 AO |
5010 | if (gad->odd) |
5011 | { | |
5012 | /* If there was an odd word left behind, use it. */ | |
5013 | ret = gad->odd; | |
5014 | gad->odd = 0; | |
5015 | } | |
5016 | else | |
5017 | { | |
5018 | /* Otherwise, use the word pointed to by cur, reserve the next | |
5019 | as an odd word, and skip to the next pair of words, possibly | |
5020 | wrapping around. */ | |
5021 | ret = gad->cur; | |
5022 | gad->odd = gad->cur + 4; | |
5023 | gad->cur += 8; | |
5024 | if (gad->cur == gad->max) | |
5025 | gad->cur = gad->min; | |
5026 | } | |
5027 | ||
5028 | return ret; | |
5029 | } | |
5030 | ||
5031 | /* Compute the location of the next function descriptor entry in the | |
5032 | GOT, given the allocation data for a range. */ | |
5033 | ||
5034 | inline static bfd_signed_vma | |
43850d5b | 5035 | _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) |
51532845 AO |
5036 | { |
5037 | /* If we're at the bottom, wrap around, and only then allocate the | |
5038 | next pair of words. */ | |
5039 | if (gad->fdcur == gad->min) | |
5040 | gad->fdcur = gad->max; | |
5041 | return gad->fdcur -= 8; | |
5042 | } | |
5043 | ||
90219bd0 AO |
5044 | /* Compute the location of the next TLS descriptor entry in the GOT, |
5045 | given the allocation data for a range. */ | |
5046 | inline static bfd_signed_vma | |
5047 | _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) | |
5048 | { | |
5049 | bfd_signed_vma ret; | |
5050 | ||
5051 | ret = gad->tcur; | |
5052 | ||
5053 | gad->tcur += 8; | |
5054 | ||
5055 | /* If we're at the top of the region, wrap around to the bottom. */ | |
5056 | if (gad->tcur == gad->tmax) | |
5057 | gad->tcur = gad->tmin; | |
5058 | ||
5059 | return ret; | |
5060 | } | |
5061 | ||
51532845 AO |
5062 | /* Assign GOT offsets for every GOT entry and function descriptor. |
5063 | Doing everything in a single pass is tricky. */ | |
5064 | ||
5065 | static int | |
43850d5b | 5066 | _frvfdpic_assign_got_entries (void **entryp, void *info_) |
51532845 | 5067 | { |
43850d5b AO |
5068 | struct frvfdpic_relocs_info *entry = *entryp; |
5069 | struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; | |
51532845 AO |
5070 | |
5071 | if (entry->got12) | |
43850d5b | 5072 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12); |
51532845 | 5073 | else if (entry->gotlos) |
43850d5b | 5074 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); |
51532845 | 5075 | else if (entry->gothilo) |
43850d5b | 5076 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); |
51532845 AO |
5077 | |
5078 | if (entry->fdgot12) | |
43850d5b | 5079 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12); |
51532845 | 5080 | else if (entry->fdgotlos) |
43850d5b | 5081 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); |
51532845 | 5082 | else if (entry->fdgothilo) |
43850d5b | 5083 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); |
51532845 AO |
5084 | |
5085 | if (entry->fdgoff12) | |
43850d5b | 5086 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); |
51532845 AO |
5087 | else if (entry->plt && dinfo->got12.fdplt) |
5088 | { | |
5089 | dinfo->got12.fdplt -= 8; | |
43850d5b | 5090 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); |
51532845 AO |
5091 | } |
5092 | else if (entry->fdgofflos) | |
43850d5b | 5093 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); |
51532845 AO |
5094 | else if (entry->plt && dinfo->gotlos.fdplt) |
5095 | { | |
5096 | dinfo->gotlos.fdplt -= 8; | |
43850d5b | 5097 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); |
51532845 AO |
5098 | } |
5099 | else if (entry->plt) | |
5100 | { | |
5101 | dinfo->gothilo.fdplt -= 8; | |
43850d5b | 5102 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); |
51532845 AO |
5103 | } |
5104 | else if (entry->privfd) | |
43850d5b | 5105 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); |
f12123c0 | 5106 | |
90219bd0 AO |
5107 | if (entry->tlsoff12) |
5108 | entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12); | |
5109 | else if (entry->tlsofflos) | |
5110 | entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); | |
5111 | else if (entry->tlsoffhilo) | |
5112 | entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); | |
5113 | ||
5114 | if (entry->tlsdesc12) | |
5115 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); | |
5116 | else if (entry->tlsplt && dinfo->got12.tlsdplt) | |
5117 | { | |
5118 | dinfo->got12.tlsdplt -= 8; | |
5119 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); | |
5120 | } | |
5121 | else if (entry->tlsdesclos) | |
5122 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); | |
5123 | else if (entry->tlsplt && dinfo->gotlos.tlsdplt) | |
5124 | { | |
5125 | dinfo->gotlos.tlsdplt -= 8; | |
5126 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); | |
5127 | } | |
5128 | else if (entry->tlsplt) | |
5129 | { | |
5130 | dinfo->gothilo.tlsdplt -= 8; | |
5131 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); | |
5132 | } | |
5133 | else if (entry->tlsdeschilo) | |
5134 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); | |
5135 | ||
51532845 AO |
5136 | return 1; |
5137 | } | |
5138 | ||
5139 | /* Assign GOT offsets to private function descriptors used by PLT | |
5140 | entries (or referenced by 32-bit offsets), as well as PLT entries | |
5141 | and lazy PLT entries. */ | |
5142 | ||
5143 | static int | |
43850d5b | 5144 | _frvfdpic_assign_plt_entries (void **entryp, void *info_) |
51532845 | 5145 | { |
43850d5b AO |
5146 | struct frvfdpic_relocs_info *entry = *entryp; |
5147 | struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; | |
51532845 | 5148 | |
90219bd0 AO |
5149 | if (entry->privfd) |
5150 | BFD_ASSERT (entry->fd_entry); | |
51532845 AO |
5151 | |
5152 | if (entry->plt) | |
5153 | { | |
5154 | int size; | |
5155 | ||
5156 | /* We use the section's raw size to mark the location of the | |
5157 | next PLT entry. */ | |
eea6121a | 5158 | entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size; |
51532845 AO |
5159 | |
5160 | /* Figure out the length of this PLT entry based on the | |
5161 | addressing mode we need to reach the function descriptor. */ | |
5162 | BFD_ASSERT (entry->fd_entry); | |
5163 | if (entry->fd_entry >= -(1 << (12 - 1)) | |
5164 | && entry->fd_entry < (1 << (12 - 1))) | |
5165 | size = 8; | |
5166 | else if (entry->fd_entry >= -(1 << (16 - 1)) | |
5167 | && entry->fd_entry < (1 << (16 - 1))) | |
5168 | size = 12; | |
5169 | else | |
5170 | size = 16; | |
5171 | ||
eea6121a | 5172 | frvfdpic_plt_section (dinfo->g.info)->size += size; |
51532845 AO |
5173 | } |
5174 | ||
5175 | if (entry->lazyplt) | |
5176 | { | |
5177 | entry->lzplt_entry = dinfo->g.lzplt; | |
5178 | dinfo->g.lzplt += 8; | |
5179 | /* If this entry is the one that gets the resolver stub, account | |
5180 | for the additional instruction. */ | |
43850d5b AO |
5181 | if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE |
5182 | == FRVFDPIC_LZPLT_RESOLV_LOC) | |
51532845 AO |
5183 | dinfo->g.lzplt += 4; |
5184 | } | |
f12123c0 | 5185 | |
90219bd0 AO |
5186 | if (entry->tlsplt) |
5187 | { | |
5188 | int size; | |
5189 | ||
5190 | entry->tlsplt_entry | |
5191 | = frvfdpic_plt_section (dinfo->g.info)->size; | |
5192 | ||
5193 | if (dinfo->g.info->executable | |
5194 | && (entry->symndx != -1 | |
5195 | || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h))) | |
5196 | { | |
5197 | if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1)) | |
5198 | /* FIXME: here we use the size of the TLS section | |
5199 | as an upper bound for the value of the TLS | |
5200 | symbol, because we may not know the exact value | |
5201 | yet. If we get it wrong, we'll just waste a | |
5202 | word in the PLT, and we should never get even | |
5203 | close to 32 KiB of TLS anyway. */ | |
5204 | && elf_hash_table (dinfo->g.info)->tls_sec | |
5205 | && (elf_hash_table (dinfo->g.info)->tls_sec->size | |
5206 | + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1)))) | |
5207 | size = 8; | |
5208 | else | |
5209 | size = 12; | |
5210 | } | |
5211 | else if (entry->tlsoff_entry) | |
5212 | { | |
5213 | if (entry->tlsoff_entry >= -(1 << (12 - 1)) | |
5214 | && entry->tlsoff_entry < (1 << (12 - 1))) | |
5215 | size = 8; | |
5216 | else if (entry->tlsoff_entry >= -(1 << (16 - 1)) | |
5217 | && entry->tlsoff_entry < (1 << (16 - 1))) | |
5218 | size = 12; | |
5219 | else | |
5220 | size = 16; | |
5221 | } | |
5222 | else | |
5223 | { | |
5224 | BFD_ASSERT (entry->tlsdesc_entry); | |
5225 | ||
5226 | if (entry->tlsdesc_entry >= -(1 << (12 - 1)) | |
5227 | && entry->tlsdesc_entry < (1 << (12 - 1))) | |
5228 | size = 8; | |
5229 | else if (entry->tlsdesc_entry >= -(1 << (16 - 1)) | |
5230 | && entry->tlsdesc_entry < (1 << (16 - 1))) | |
5231 | size = 12; | |
5232 | else | |
5233 | size = 16; | |
5234 | } | |
3b36f7e6 | 5235 | |
90219bd0 AO |
5236 | frvfdpic_plt_section (dinfo->g.info)->size += size; |
5237 | } | |
5238 | ||
5239 | return 1; | |
5240 | } | |
5241 | ||
5242 | /* Cancel out any effects of calling _frvfdpic_assign_got_entries and | |
5243 | _frvfdpic_assign_plt_entries. */ | |
5244 | ||
5245 | static int | |
5246 | _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED) | |
5247 | { | |
5248 | struct frvfdpic_relocs_info *entry = *entryp; | |
5249 | ||
5250 | entry->got_entry = 0; | |
5251 | entry->fdgot_entry = 0; | |
5252 | entry->fd_entry = 0; | |
5253 | entry->plt_entry = (bfd_vma)-1; | |
5254 | entry->lzplt_entry = (bfd_vma)-1; | |
5255 | entry->tlsoff_entry = 0; | |
5256 | entry->tlsdesc_entry = 0; | |
5257 | entry->tlsplt_entry = (bfd_vma)-1; | |
5258 | ||
51532845 | 5259 | return 1; |
f12123c0 | 5260 | } |
51532845 AO |
5261 | |
5262 | /* Follow indirect and warning hash entries so that each got entry | |
5263 | points to the final symbol definition. P must point to a pointer | |
5264 | to the hash table we're traversing. Since this traversal may | |
5265 | modify the hash table, we set this pointer to NULL to indicate | |
5266 | we've made a potentially-destructive change to the hash table, so | |
5267 | the traversal must be restarted. */ | |
5268 | static int | |
43850d5b | 5269 | _frvfdpic_resolve_final_relocs_info (void **entryp, void *p) |
51532845 | 5270 | { |
43850d5b | 5271 | struct frvfdpic_relocs_info *entry = *entryp; |
51532845 AO |
5272 | htab_t *htab = p; |
5273 | ||
5274 | if (entry->symndx == -1) | |
5275 | { | |
5276 | struct elf_link_hash_entry *h = entry->d.h; | |
43850d5b | 5277 | struct frvfdpic_relocs_info *oentry; |
51532845 AO |
5278 | |
5279 | while (h->root.type == bfd_link_hash_indirect | |
5280 | || h->root.type == bfd_link_hash_warning) | |
5281 | h = (struct elf_link_hash_entry *)h->root.u.i.link; | |
5282 | ||
5283 | if (entry->d.h == h) | |
5284 | return 1; | |
5285 | ||
43850d5b AO |
5286 | oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend, |
5287 | NO_INSERT); | |
3b712a1a AO |
5288 | |
5289 | if (oentry) | |
5290 | { | |
5291 | /* Merge the two entries. */ | |
43850d5b | 5292 | frvfdpic_pic_merge_early_relocs_info (oentry, entry); |
3b712a1a AO |
5293 | htab_clear_slot (*htab, entryp); |
5294 | return 1; | |
5295 | } | |
5296 | ||
51532845 AO |
5297 | entry->d.h = h; |
5298 | ||
5299 | /* If we can't find this entry with the new bfd hash, re-insert | |
5300 | it, and get the traversal restarted. */ | |
5301 | if (! htab_find (*htab, entry)) | |
5302 | { | |
5303 | htab_clear_slot (*htab, entryp); | |
5304 | entryp = htab_find_slot (*htab, entry, INSERT); | |
5305 | if (! *entryp) | |
5306 | *entryp = entry; | |
5307 | /* Abort the traversal, since the whole table may have | |
5308 | moved, and leave it up to the parent to restart the | |
5309 | process. */ | |
5310 | *(htab_t *)p = NULL; | |
5311 | return 0; | |
5312 | } | |
5313 | } | |
5314 | ||
5315 | return 1; | |
5316 | } | |
5317 | ||
90219bd0 AO |
5318 | /* Compute the total size of the GOT, the PLT, the dynamic relocations |
5319 | section and the rofixup section. Assign locations for GOT and PLT | |
5320 | entries. */ | |
51532845 AO |
5321 | |
5322 | static bfd_boolean | |
90219bd0 AO |
5323 | _frvfdpic_size_got_plt (bfd *output_bfd, |
5324 | struct _frvfdpic_dynamic_got_plt_info *gpinfop) | |
51532845 | 5325 | { |
51532845 | 5326 | bfd_signed_vma odd; |
90219bd0 AO |
5327 | bfd_vma limit, tlslimit; |
5328 | struct bfd_link_info *info = gpinfop->g.info; | |
5329 | bfd *dynobj = elf_hash_table (info)->dynobj; | |
51532845 | 5330 | |
90219bd0 AO |
5331 | memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g, |
5332 | sizeof (gpinfop->g)); | |
51532845 AO |
5333 | |
5334 | odd = 12; | |
5335 | /* Compute the total size taken by entries in the 12-bit and 16-bit | |
5336 | ranges, to tell how many PLT function descriptors we can bring | |
5337 | into the 12-bit range without causing the 16-bit range to | |
5338 | overflow. */ | |
90219bd0 AO |
5339 | limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos |
5340 | + gpinfop->g.fd12 + gpinfop->g.fdlos | |
5341 | + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos; | |
51532845 AO |
5342 | if (limit < (bfd_vma)1 << 16) |
5343 | limit = ((bfd_vma)1 << 16) - limit; | |
5344 | else | |
5345 | limit = 0; | |
90219bd0 AO |
5346 | if (gpinfop->g.fdplt < limit) |
5347 | { | |
5348 | tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8; | |
5349 | limit = gpinfop->g.fdplt; | |
5350 | } | |
5351 | else | |
5352 | tlslimit = 0; | |
5353 | if (gpinfop->g.tlsdplt < tlslimit) | |
5354 | tlslimit = gpinfop->g.tlsdplt; | |
51532845 AO |
5355 | |
5356 | /* Determine the ranges of GOT offsets that we can use for each | |
5357 | range of addressing modes. */ | |
90219bd0 | 5358 | odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12, |
43850d5b AO |
5359 | 0, |
5360 | odd, | |
5361 | 16, | |
90219bd0 AO |
5362 | gpinfop->g.got12, |
5363 | gpinfop->g.fd12, | |
43850d5b | 5364 | limit, |
90219bd0 AO |
5365 | gpinfop->g.tlsd12, |
5366 | tlslimit, | |
43850d5b | 5367 | (bfd_vma)1 << (12-1)); |
90219bd0 AO |
5368 | odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos, |
5369 | gpinfop->got12.tmin, | |
43850d5b | 5370 | odd, |
90219bd0 AO |
5371 | gpinfop->got12.tmax, |
5372 | gpinfop->g.gotlos, | |
5373 | gpinfop->g.fdlos, | |
5374 | gpinfop->g.fdplt | |
5375 | - gpinfop->got12.fdplt, | |
5376 | gpinfop->g.tlsdlos, | |
5377 | gpinfop->g.tlsdplt | |
5378 | - gpinfop->got12.tlsdplt, | |
43850d5b | 5379 | (bfd_vma)1 << (16-1)); |
90219bd0 AO |
5380 | odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo, |
5381 | gpinfop->gotlos.tmin, | |
43850d5b | 5382 | odd, |
90219bd0 AO |
5383 | gpinfop->gotlos.tmax, |
5384 | gpinfop->g.gothilo, | |
5385 | gpinfop->g.fdhilo, | |
5386 | gpinfop->g.fdplt | |
5387 | - gpinfop->got12.fdplt | |
5388 | - gpinfop->gotlos.fdplt, | |
5389 | gpinfop->g.tlsdhilo, | |
5390 | gpinfop->g.tlsdplt | |
5391 | - gpinfop->got12.tlsdplt | |
5392 | - gpinfop->gotlos.tlsdplt, | |
43850d5b | 5393 | (bfd_vma)1 << (32-1)); |
51532845 AO |
5394 | |
5395 | /* Now assign (most) GOT offsets. */ | |
43850d5b | 5396 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries, |
90219bd0 | 5397 | gpinfop); |
51532845 | 5398 | |
90219bd0 AO |
5399 | frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax |
5400 | - gpinfop->gothilo.tmin | |
51532845 AO |
5401 | /* If an odd word is the last word of the GOT, we don't need this |
5402 | word to be part of the GOT. */ | |
90219bd0 | 5403 | - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0); |
eea6121a | 5404 | if (frvfdpic_got_section (info)->size == 0) |
43850d5b | 5405 | frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; |
eea6121a | 5406 | else if (frvfdpic_got_section (info)->size == 12 |
51532845 AO |
5407 | && ! elf_hash_table (info)->dynamic_sections_created) |
5408 | { | |
43850d5b | 5409 | frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; |
eea6121a | 5410 | frvfdpic_got_section (info)->size = 0; |
51532845 | 5411 | } |
90219bd0 AO |
5412 | /* This will be non-NULL during relaxation. The assumption is that |
5413 | the size of one of these sections will never grow, only shrink, | |
5414 | so we can use the larger buffer we allocated before. */ | |
5415 | else if (frvfdpic_got_section (info)->contents == NULL) | |
51532845 | 5416 | { |
43850d5b AO |
5417 | frvfdpic_got_section (info)->contents = |
5418 | (bfd_byte *) bfd_zalloc (dynobj, | |
eea6121a | 5419 | frvfdpic_got_section (info)->size); |
43850d5b | 5420 | if (frvfdpic_got_section (info)->contents == NULL) |
51532845 AO |
5421 | return FALSE; |
5422 | } | |
f12123c0 | 5423 | |
90219bd0 | 5424 | if (frvfdpic_gotrel_section (info)) |
51532845 AO |
5425 | /* Subtract the number of lzplt entries, since those will generate |
5426 | relocations in the pltrel section. */ | |
eea6121a | 5427 | frvfdpic_gotrel_section (info)->size = |
90219bd0 | 5428 | (gpinfop->g.relocs - gpinfop->g.lzplt / 8) |
51532845 AO |
5429 | * get_elf_backend_data (output_bfd)->s->sizeof_rel; |
5430 | else | |
90219bd0 | 5431 | BFD_ASSERT (gpinfop->g.relocs == 0); |
eea6121a | 5432 | if (frvfdpic_gotrel_section (info)->size == 0) |
43850d5b | 5433 | frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5434 | else if (frvfdpic_gotrel_section (info)->contents == NULL) |
51532845 | 5435 | { |
43850d5b AO |
5436 | frvfdpic_gotrel_section (info)->contents = |
5437 | (bfd_byte *) bfd_zalloc (dynobj, | |
eea6121a | 5438 | frvfdpic_gotrel_section (info)->size); |
43850d5b | 5439 | if (frvfdpic_gotrel_section (info)->contents == NULL) |
51532845 AO |
5440 | return FALSE; |
5441 | } | |
5442 | ||
90219bd0 | 5443 | frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4; |
eea6121a | 5444 | if (frvfdpic_gotfixup_section (info)->size == 0) |
43850d5b | 5445 | frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5446 | else if (frvfdpic_gotfixup_section (info)->contents == NULL) |
51532845 | 5447 | { |
43850d5b | 5448 | frvfdpic_gotfixup_section (info)->contents = |
51532845 | 5449 | (bfd_byte *) bfd_zalloc (dynobj, |
eea6121a | 5450 | frvfdpic_gotfixup_section (info)->size); |
43850d5b | 5451 | if (frvfdpic_gotfixup_section (info)->contents == NULL) |
51532845 AO |
5452 | return FALSE; |
5453 | } | |
f12123c0 | 5454 | |
90219bd0 | 5455 | if (frvfdpic_pltrel_section (info)) |
51532845 | 5456 | { |
eea6121a | 5457 | frvfdpic_pltrel_section (info)->size = |
90219bd0 AO |
5458 | gpinfop->g.lzplt / 8 |
5459 | * get_elf_backend_data (output_bfd)->s->sizeof_rel; | |
eea6121a | 5460 | if (frvfdpic_pltrel_section (info)->size == 0) |
43850d5b | 5461 | frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5462 | else if (frvfdpic_pltrel_section (info)->contents == NULL) |
51532845 | 5463 | { |
43850d5b | 5464 | frvfdpic_pltrel_section (info)->contents = |
51532845 | 5465 | (bfd_byte *) bfd_zalloc (dynobj, |
eea6121a | 5466 | frvfdpic_pltrel_section (info)->size); |
43850d5b | 5467 | if (frvfdpic_pltrel_section (info)->contents == NULL) |
51532845 AO |
5468 | return FALSE; |
5469 | } | |
5470 | } | |
f12123c0 | 5471 | |
51532845 AO |
5472 | /* Add 4 bytes for every block of at most 65535 lazy PLT entries, |
5473 | such that there's room for the additional instruction needed to | |
43850d5b AO |
5474 | call the resolver. Since _frvfdpic_assign_got_entries didn't |
5475 | account for them, our block size is 4 bytes smaller than the real | |
5476 | block size. */ | |
90219bd0 | 5477 | if (frvfdpic_plt_section (info)) |
51532845 | 5478 | { |
90219bd0 AO |
5479 | frvfdpic_plt_section (info)->size = gpinfop->g.lzplt |
5480 | + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8) | |
43850d5b | 5481 | / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4); |
51532845 | 5482 | } |
b34976b6 | 5483 | |
43850d5b | 5484 | /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to |
51532845 | 5485 | actually assign lazy PLT entries addresses. */ |
90219bd0 | 5486 | gpinfop->g.lzplt = 0; |
b34976b6 | 5487 | |
51532845 AO |
5488 | /* Save information that we're going to need to generate GOT and PLT |
5489 | entries. */ | |
90219bd0 | 5490 | frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin; |
b34976b6 | 5491 | |
51532845 AO |
5492 | if (get_elf_backend_data (output_bfd)->want_got_sym) |
5493 | elf_hash_table (info)->hgot->root.u.def.value | |
90219bd0 | 5494 | = frvfdpic_got_initial_offset (info); |
b34976b6 | 5495 | |
90219bd0 | 5496 | if (frvfdpic_plt_section (info)) |
43850d5b | 5497 | frvfdpic_plt_initial_offset (info) = |
eea6121a | 5498 | frvfdpic_plt_section (info)->size; |
b34976b6 | 5499 | |
90219bd0 AO |
5500 | /* Allocate a ret statement at plt_initial_offset, to be used by |
5501 | locally-resolved TLS descriptors. */ | |
5502 | if (gpinfop->g.tls_ret_refs) | |
5503 | frvfdpic_plt_section (info)->size += 4; | |
5504 | ||
43850d5b | 5505 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries, |
90219bd0 | 5506 | gpinfop); |
51532845 AO |
5507 | |
5508 | /* Allocate the PLT section contents only after | |
43850d5b | 5509 | _frvfdpic_assign_plt_entries has a chance to add the size of the |
51532845 | 5510 | non-lazy PLT entries. */ |
90219bd0 | 5511 | if (frvfdpic_plt_section (info)) |
51532845 | 5512 | { |
eea6121a | 5513 | if (frvfdpic_plt_section (info)->size == 0) |
43850d5b | 5514 | frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5515 | else if (frvfdpic_plt_section (info)->contents == NULL) |
4e5ba5b7 | 5516 | { |
43850d5b AO |
5517 | frvfdpic_plt_section (info)->contents = |
5518 | (bfd_byte *) bfd_zalloc (dynobj, | |
eea6121a | 5519 | frvfdpic_plt_section (info)->size); |
43850d5b | 5520 | if (frvfdpic_plt_section (info)->contents == NULL) |
51532845 AO |
5521 | return FALSE; |
5522 | } | |
5523 | } | |
b34976b6 | 5524 | |
90219bd0 AO |
5525 | return TRUE; |
5526 | } | |
5527 | ||
5528 | /* Set the sizes of the dynamic sections. */ | |
5529 | ||
5530 | static bfd_boolean | |
5531 | elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd, | |
5532 | struct bfd_link_info *info) | |
5533 | { | |
5534 | bfd *dynobj; | |
5535 | asection *s; | |
5536 | struct _frvfdpic_dynamic_got_plt_info gpinfo; | |
5537 | ||
5538 | dynobj = elf_hash_table (info)->dynobj; | |
5539 | BFD_ASSERT (dynobj != NULL); | |
5540 | ||
5541 | if (elf_hash_table (info)->dynamic_sections_created) | |
5542 | { | |
5543 | /* Set the contents of the .interp section to the interpreter. */ | |
5544 | if (info->executable) | |
5545 | { | |
5546 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
5547 | BFD_ASSERT (s != NULL); | |
5548 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5549 | s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER; | |
5550 | } | |
5551 | } | |
5552 | ||
5553 | memset (&gpinfo, 0, sizeof (gpinfo)); | |
5554 | gpinfo.g.info = info; | |
5555 | ||
5556 | for (;;) | |
5557 | { | |
5558 | htab_t relocs = frvfdpic_relocs_info (info); | |
5559 | ||
5560 | htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs); | |
5561 | ||
5562 | if (relocs == frvfdpic_relocs_info (info)) | |
5563 | break; | |
5564 | } | |
5565 | ||
5566 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries, | |
5567 | &gpinfo.g); | |
5568 | ||
5569 | /* Allocate space to save the summary information, we're going to | |
5570 | use it if we're doing relaxations. */ | |
5571 | frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g)); | |
5572 | ||
5573 | if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo)) | |
5574 | return FALSE; | |
5575 | ||
51532845 AO |
5576 | if (elf_hash_table (info)->dynamic_sections_created) |
5577 | { | |
eea6121a | 5578 | if (frvfdpic_got_section (info)->size) |
5a580b3a | 5579 | if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)) |
51532845 AO |
5580 | return FALSE; |
5581 | ||
eea6121a | 5582 | if (frvfdpic_pltrel_section (info)->size) |
5a580b3a AM |
5583 | if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0) |
5584 | || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL) | |
5585 | || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0)) | |
51532845 AO |
5586 | return FALSE; |
5587 | ||
eea6121a | 5588 | if (frvfdpic_gotrel_section (info)->size) |
5a580b3a AM |
5589 | if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0) |
5590 | || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0) | |
5591 | || !_bfd_elf_add_dynamic_entry (info, DT_RELENT, | |
5592 | sizeof (Elf32_External_Rel))) | |
51532845 AO |
5593 | return FALSE; |
5594 | } | |
4e5ba5b7 | 5595 | |
51532845 AO |
5596 | return TRUE; |
5597 | } | |
b34976b6 | 5598 | |
51532845 | 5599 | static bfd_boolean |
43850d5b AO |
5600 | elf32_frvfdpic_always_size_sections (bfd *output_bfd, |
5601 | struct bfd_link_info *info) | |
51532845 | 5602 | { |
43850d5b | 5603 | if (!info->relocatable) |
51532845 AO |
5604 | { |
5605 | struct elf_link_hash_entry *h; | |
b34976b6 | 5606 | |
51532845 AO |
5607 | /* Force a PT_GNU_STACK segment to be created. */ |
5608 | if (! elf_tdata (output_bfd)->stack_flags) | |
5609 | elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X; | |
4e5ba5b7 | 5610 | |
51532845 AO |
5611 | /* Define __stacksize if it's not defined yet. */ |
5612 | h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", | |
5613 | FALSE, FALSE, FALSE); | |
5614 | if (! h || h->root.type != bfd_link_hash_defined | |
5615 | || h->type != STT_OBJECT | |
f5385ebf | 5616 | || !h->def_regular) |
51532845 | 5617 | { |
ea01195e | 5618 | struct bfd_link_hash_entry *bh = NULL; |
4e5ba5b7 | 5619 | |
51532845 AO |
5620 | if (!(_bfd_generic_link_add_one_symbol |
5621 | (info, output_bfd, "__stacksize", | |
5622 | BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE, | |
5623 | (const char *) NULL, FALSE, | |
5624 | get_elf_backend_data (output_bfd)->collect, &bh))) | |
5625 | return FALSE; | |
4e5ba5b7 | 5626 | |
51532845 | 5627 | h = (struct elf_link_hash_entry *) bh; |
f5385ebf | 5628 | h->def_regular = 1; |
51532845 | 5629 | h->type = STT_OBJECT; |
90219bd0 | 5630 | /* This one must NOT be hidden. */ |
51532845 | 5631 | } |
51532845 | 5632 | } |
4e5ba5b7 | 5633 | |
51532845 AO |
5634 | return TRUE; |
5635 | } | |
4e5ba5b7 | 5636 | |
90219bd0 AO |
5637 | /* Look for opportunities to relax TLS relocations. We can assume |
5638 | we're linking the main executable or a static-tls library, since | |
5639 | otherwise we wouldn't have got here. */ | |
5640 | ||
5641 | static int | |
5642 | _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_) | |
5643 | { | |
5644 | struct frvfdpic_relocs_info *entry = *entryp; | |
5645 | struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; | |
5646 | ||
5647 | _frvfdpic_relax_tls_entries (entry, dinfo, TRUE); | |
5648 | ||
5649 | return 1; | |
5650 | } | |
5651 | ||
5652 | static bfd_boolean | |
5653 | elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
5654 | struct bfd_link_info *info, bfd_boolean *again) | |
5655 | { | |
5656 | struct _frvfdpic_dynamic_got_plt_info gpinfo; | |
5657 | ||
5658 | /* If we return early, we didn't change anything. */ | |
5659 | *again = FALSE; | |
5660 | ||
5661 | /* We'll do our thing when requested to relax the GOT section. */ | |
5662 | if (sec != frvfdpic_got_section (info)) | |
5663 | return TRUE; | |
5664 | ||
5665 | /* We can only relax when linking the main executable or a library | |
5666 | that can't be dlopened. */ | |
5667 | if (! info->executable && ! (info->flags & DF_STATIC_TLS)) | |
5668 | return TRUE; | |
5669 | ||
5670 | /* If there isn't a TLS section for this binary, we can't do | |
5671 | anything about its TLS relocations (it probably doesn't have | |
5672 | any. */ | |
5673 | if (elf_hash_table (info)->tls_sec == NULL) | |
5674 | return TRUE; | |
5675 | ||
5676 | memset (&gpinfo, 0, sizeof (gpinfo)); | |
5677 | memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g)); | |
5678 | ||
5679 | /* Now look for opportunities to relax, adjusting the GOT usage | |
5680 | as needed. */ | |
5681 | htab_traverse (frvfdpic_relocs_info (info), | |
5682 | _frvfdpic_relax_got_plt_entries, | |
5683 | &gpinfo.g); | |
5684 | ||
5685 | /* If we changed anything, reset and re-assign GOT and PLT entries. */ | |
5686 | if (memcmp (frvfdpic_dynamic_got_plt_info (info), | |
5687 | &gpinfo.g, sizeof (gpinfo.g)) != 0) | |
5688 | { | |
5689 | /* Clear GOT and PLT assignments. */ | |
5690 | htab_traverse (frvfdpic_relocs_info (info), | |
5691 | _frvfdpic_reset_got_plt_entries, | |
5692 | NULL); | |
5693 | ||
5694 | /* The owner of the TLS section is the output bfd. There should | |
5695 | be a better way to get to it. */ | |
5696 | if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner, | |
5697 | &gpinfo)) | |
5698 | return FALSE; | |
5699 | ||
5700 | /* Repeat until we don't make any further changes. We could fail to | |
5701 | introduce changes in a round if, for example, the 12-bit range is | |
5702 | full, but we later release some space by getting rid of TLS | |
5703 | descriptors in it. We have to repeat the whole process because | |
5704 | we might have changed the size of a section processed before this | |
5705 | one. */ | |
5706 | *again = TRUE; | |
5707 | } | |
5708 | ||
5709 | return TRUE; | |
5710 | } | |
5711 | ||
51532845 | 5712 | static bfd_boolean |
e36284ab AM |
5713 | elf32_frvfdpic_modify_program_headers (bfd *output_bfd, |
5714 | struct bfd_link_info *info) | |
51532845 | 5715 | { |
e36284ab | 5716 | struct elf_obj_tdata *tdata = elf_tdata (output_bfd); |
43850d5b | 5717 | struct elf_segment_map *m; |
e36284ab | 5718 | Elf_Internal_Phdr *p; |
4e5ba5b7 | 5719 | |
7e9f3bd6 AO |
5720 | /* objcopy and strip preserve what's already there using |
5721 | elf32_frvfdpic_copy_private_bfd_data (). */ | |
5722 | if (! info) | |
5723 | return TRUE; | |
5724 | ||
e36284ab | 5725 | for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++) |
43850d5b AO |
5726 | if (m->p_type == PT_GNU_STACK) |
5727 | break; | |
5728 | ||
5729 | if (m) | |
5730 | { | |
43850d5b | 5731 | struct elf_link_hash_entry *h; |
51532845 | 5732 | |
e36284ab AM |
5733 | /* Obtain the pointer to the __stacksize symbol. */ |
5734 | h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", | |
5735 | FALSE, FALSE, FALSE); | |
5736 | if (h) | |
4e5ba5b7 | 5737 | { |
43850d5b AO |
5738 | while (h->root.type == bfd_link_hash_indirect |
5739 | || h->root.type == bfd_link_hash_warning) | |
e36284ab | 5740 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
43850d5b | 5741 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); |
e36284ab | 5742 | } |
4e5ba5b7 | 5743 | |
e36284ab AM |
5744 | /* Set the header p_memsz from the symbol value. We |
5745 | intentionally ignore the symbol section. */ | |
5746 | if (h && h->root.type == bfd_link_hash_defined) | |
5747 | p->p_memsz = h->root.u.def.value; | |
5748 | else | |
5749 | p->p_memsz = DEFAULT_STACK_SIZE; | |
51532845 | 5750 | |
e36284ab | 5751 | p->p_align = 8; |
51532845 | 5752 | } |
b34976b6 | 5753 | |
51532845 AO |
5754 | return TRUE; |
5755 | } | |
b34976b6 | 5756 | |
51532845 | 5757 | /* Fill in code and data in dynamic sections. */ |
4e5ba5b7 | 5758 | |
51532845 | 5759 | static bfd_boolean |
43850d5b AO |
5760 | elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
5761 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
5762 | { | |
5763 | /* Nothing to be done for non-FDPIC. */ | |
5764 | return TRUE; | |
5765 | } | |
5766 | ||
5767 | static bfd_boolean | |
5768 | elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd, | |
5769 | struct bfd_link_info *info) | |
51532845 AO |
5770 | { |
5771 | bfd *dynobj; | |
5772 | asection *sdyn; | |
4e5ba5b7 | 5773 | |
51532845 | 5774 | dynobj = elf_hash_table (info)->dynobj; |
4e5ba5b7 | 5775 | |
90219bd0 AO |
5776 | if (frvfdpic_dynamic_got_plt_info (info)) |
5777 | { | |
5778 | BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0); | |
5779 | } | |
43850d5b | 5780 | if (frvfdpic_got_section (info)) |
51532845 | 5781 | { |
eea6121a | 5782 | BFD_ASSERT (frvfdpic_gotrel_section (info)->size |
43850d5b | 5783 | == (frvfdpic_gotrel_section (info)->reloc_count |
51532845 | 5784 | * sizeof (Elf32_External_Rel))); |
4e5ba5b7 | 5785 | |
43850d5b | 5786 | if (frvfdpic_gotfixup_section (info)) |
51532845 | 5787 | { |
43850d5b AO |
5788 | struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot; |
5789 | bfd_vma got_value = hgot->root.u.def.value | |
5790 | + hgot->root.u.def.section->output_section->vma | |
5791 | + hgot->root.u.def.section->output_offset; | |
90219bd0 | 5792 | struct bfd_link_hash_entry *hend; |
4e5ba5b7 | 5793 | |
43850d5b AO |
5794 | _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info), |
5795 | got_value, 0); | |
51532845 | 5796 | |
eea6121a | 5797 | if (frvfdpic_gotfixup_section (info)->size |
43850d5b | 5798 | != (frvfdpic_gotfixup_section (info)->reloc_count * 4)) |
51532845 | 5799 | { |
90219bd0 | 5800 | error: |
43850d5b AO |
5801 | (*_bfd_error_handler) |
5802 | ("LINKER BUG: .rofixup section size mismatch"); | |
5803 | return FALSE; | |
51532845 | 5804 | } |
90219bd0 AO |
5805 | |
5806 | hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__", | |
5807 | FALSE, FALSE, TRUE); | |
5808 | if (hend | |
5809 | && (hend->type == bfd_link_hash_defined | |
5810 | || hend->type == bfd_link_hash_defweak)) | |
5811 | { | |
3b36f7e6 | 5812 | bfd_vma value = |
90219bd0 AO |
5813 | frvfdpic_gotfixup_section (info)->output_section->vma |
5814 | + frvfdpic_gotfixup_section (info)->output_offset | |
5815 | + frvfdpic_gotfixup_section (info)->size | |
5816 | - hend->u.def.section->output_section->vma | |
5817 | - hend->u.def.section->output_offset; | |
5818 | BFD_ASSERT (hend->u.def.value == value); | |
5819 | if (hend->u.def.value != value) | |
5820 | goto error; | |
5821 | } | |
4e5ba5b7 DB |
5822 | } |
5823 | } | |
90219bd0 | 5824 | if (frvfdpic_pltrel_section (info)) |
51532845 | 5825 | { |
eea6121a | 5826 | BFD_ASSERT (frvfdpic_pltrel_section (info)->size |
43850d5b | 5827 | == (frvfdpic_pltrel_section (info)->reloc_count |
51532845 AO |
5828 | * sizeof (Elf32_External_Rel))); |
5829 | } | |
4e5ba5b7 | 5830 | |
4e5ba5b7 | 5831 | |
51532845 | 5832 | if (elf_hash_table (info)->dynamic_sections_created) |
4e5ba5b7 | 5833 | { |
51532845 AO |
5834 | Elf32_External_Dyn * dyncon; |
5835 | Elf32_External_Dyn * dynconend; | |
5836 | ||
90219bd0 AO |
5837 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
5838 | ||
51532845 AO |
5839 | BFD_ASSERT (sdyn != NULL); |
5840 | ||
5841 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 5842 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
51532845 AO |
5843 | |
5844 | for (; dyncon < dynconend; dyncon++) | |
4e5ba5b7 | 5845 | { |
51532845 | 5846 | Elf_Internal_Dyn dyn; |
4e5ba5b7 | 5847 | |
51532845 AO |
5848 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
5849 | ||
5850 | switch (dyn.d_tag) | |
4e5ba5b7 DB |
5851 | { |
5852 | default: | |
5853 | break; | |
5854 | ||
51532845 | 5855 | case DT_PLTGOT: |
43850d5b AO |
5856 | dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma |
5857 | + frvfdpic_got_section (info)->output_offset | |
5858 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
5859 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5860 | break; | |
4e5ba5b7 | 5861 | |
51532845 | 5862 | case DT_JMPREL: |
43850d5b AO |
5863 | dyn.d_un.d_ptr = frvfdpic_pltrel_section (info) |
5864 | ->output_section->vma | |
5865 | + frvfdpic_pltrel_section (info)->output_offset; | |
51532845 AO |
5866 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5867 | break; | |
5868 | ||
5869 | case DT_PLTRELSZ: | |
eea6121a | 5870 | dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size; |
51532845 AO |
5871 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5872 | break; | |
4e5ba5b7 DB |
5873 | } |
5874 | } | |
5875 | } | |
4e5ba5b7 | 5876 | |
51532845 | 5877 | return TRUE; |
4e5ba5b7 DB |
5878 | } |
5879 | ||
51532845 AO |
5880 | /* Adjust a symbol defined by a dynamic object and referenced by a |
5881 | regular object. */ | |
4e5ba5b7 | 5882 | |
b34976b6 | 5883 | static bfd_boolean |
43850d5b AO |
5884 | elf32_frvfdpic_adjust_dynamic_symbol |
5885 | (struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
5886 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) | |
4e5ba5b7 | 5887 | { |
51532845 AO |
5888 | bfd * dynobj; |
5889 | ||
5890 | dynobj = elf_hash_table (info)->dynobj; | |
5891 | ||
5892 | /* Make sure we know what is going on here. */ | |
5893 | BFD_ASSERT (dynobj != NULL | |
f6e332e6 | 5894 | && (h->u.weakdef != NULL |
f5385ebf AM |
5895 | || (h->def_dynamic |
5896 | && h->ref_regular | |
5897 | && !h->def_regular))); | |
51532845 AO |
5898 | |
5899 | /* If this is a weak symbol, and there is a real definition, the | |
5900 | processor independent code will have arranged for us to see the | |
5901 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 5902 | if (h->u.weakdef != NULL) |
51532845 | 5903 | { |
f6e332e6 AM |
5904 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
5905 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
5906 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
5907 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
51532845 AO |
5908 | } |
5909 | ||
b34976b6 | 5910 | return TRUE; |
4e5ba5b7 DB |
5911 | } |
5912 | ||
51532845 | 5913 | /* Perform any actions needed for dynamic symbols. */ |
4e5ba5b7 | 5914 | |
b34976b6 | 5915 | static bfd_boolean |
43850d5b AO |
5916 | elf32_frvfdpic_finish_dynamic_symbol |
5917 | (bfd *output_bfd ATTRIBUTE_UNUSED, | |
5918 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
5919 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED, | |
5920 | Elf_Internal_Sym *sym ATTRIBUTE_UNUSED) | |
4e5ba5b7 | 5921 | { |
b34976b6 | 5922 | return TRUE; |
4e5ba5b7 | 5923 | } |
51532845 | 5924 | |
ec3391e7 AO |
5925 | /* Decide whether to attempt to turn absptr or lsda encodings in |
5926 | shared libraries into pcrel within the given input section. */ | |
5927 | ||
5928 | static bfd_boolean | |
43850d5b AO |
5929 | frvfdpic_elf_use_relative_eh_frame |
5930 | (bfd *input_bfd ATTRIBUTE_UNUSED, | |
5931 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
5932 | asection *eh_frame_section ATTRIBUTE_UNUSED) | |
ec3391e7 AO |
5933 | { |
5934 | /* We can't use PC-relative encodings in FDPIC binaries, in general. */ | |
43850d5b | 5935 | return FALSE; |
ec3391e7 AO |
5936 | } |
5937 | ||
5938 | /* Adjust the contents of an eh_frame_hdr section before they're output. */ | |
5939 | ||
5940 | static bfd_byte | |
43850d5b AO |
5941 | frvfdpic_elf_encode_eh_address (bfd *abfd, |
5942 | struct bfd_link_info *info, | |
5943 | asection *osec, bfd_vma offset, | |
5944 | asection *loc_sec, bfd_vma loc_offset, | |
5945 | bfd_vma *encoded) | |
ec3391e7 AO |
5946 | { |
5947 | struct elf_link_hash_entry *h; | |
5948 | ||
ec3391e7 AO |
5949 | h = elf_hash_table (info)->hgot; |
5950 | BFD_ASSERT (h && h->root.type == bfd_link_hash_defined); | |
5951 | ||
43850d5b AO |
5952 | if (! h || (_frvfdpic_osec_to_segment (abfd, osec) |
5953 | == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section))) | |
ec3391e7 AO |
5954 | return _bfd_elf_encode_eh_address (abfd, info, osec, offset, |
5955 | loc_sec, loc_offset, encoded); | |
5956 | ||
43850d5b AO |
5957 | BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec) |
5958 | == (_frvfdpic_osec_to_segment | |
5959 | (abfd, h->root.u.def.section->output_section))); | |
ec3391e7 AO |
5960 | |
5961 | *encoded = osec->vma + offset | |
5962 | - (h->root.u.def.value | |
5963 | + h->root.u.def.section->output_section->vma | |
5964 | + h->root.u.def.section->output_offset); | |
5965 | ||
5966 | return DW_EH_PE_datarel | DW_EH_PE_sdata4; | |
5967 | } | |
5968 | ||
4e5ba5b7 | 5969 | /* Look through the relocs for a section during the first phase. |
51532845 AO |
5970 | |
5971 | Besides handling virtual table relocs for gc, we have to deal with | |
5972 | all sorts of PIC-related relocations. We describe below the | |
5973 | general plan on how to handle such relocations, even though we only | |
5974 | collect information at this point, storing them in hash tables for | |
5975 | perusal of later passes. | |
5976 | ||
5977 | 32 relocations are propagated to the linker output when creating | |
5978 | position-independent output. LO16 and HI16 relocations are not | |
5979 | supposed to be encountered in this case. | |
5980 | ||
5981 | LABEL16 should always be resolvable by the linker, since it's only | |
5982 | used by branches. | |
5983 | ||
5984 | LABEL24, on the other hand, is used by calls. If it turns out that | |
5985 | the target of a call is a dynamic symbol, a PLT entry must be | |
5986 | created for it, which triggers the creation of a private function | |
5987 | descriptor and, unless lazy binding is disabled, a lazy PLT entry. | |
5988 | ||
5989 | GPREL relocations require the referenced symbol to be in the same | |
5990 | segment as _gp, but this can only be checked later. | |
5991 | ||
5992 | All GOT, GOTOFF and FUNCDESC relocations require a .got section to | |
5993 | exist. LABEL24 might as well, since it may require a PLT entry, | |
5994 | that will require a got. | |
5995 | ||
5996 | Non-FUNCDESC GOT relocations require a GOT entry to be created | |
5997 | regardless of whether the symbol is dynamic. However, since a | |
5998 | global symbol that turns out to not be exported may have the same | |
5999 | address of a non-dynamic symbol, we don't assign GOT entries at | |
6000 | this point, such that we can share them in this case. A relocation | |
6001 | for the GOT entry always has to be created, be it to offset a | |
6002 | private symbol by the section load address, be it to get the symbol | |
6003 | resolved dynamically. | |
6004 | ||
6005 | FUNCDESC GOT relocations require a GOT entry to be created, and | |
6006 | handled as if a FUNCDESC relocation was applied to the GOT entry in | |
6007 | an object file. | |
6008 | ||
6009 | FUNCDESC relocations referencing a symbol that turns out to NOT be | |
6010 | dynamic cause a private function descriptor to be created. The | |
6011 | FUNCDESC relocation then decays to a 32 relocation that points at | |
6012 | the private descriptor. If the symbol is dynamic, the FUNCDESC | |
6013 | relocation is propagated to the linker output, such that the | |
6014 | dynamic linker creates the canonical descriptor, pointing to the | |
6015 | dynamically-resolved definition of the function. | |
6016 | ||
6017 | Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic | |
6018 | symbols that are assigned to the same segment as the GOT, but we | |
6019 | can only check this later, after we know the complete set of | |
6020 | symbols defined and/or exported. | |
6021 | ||
6022 | FUNCDESC GOTOFF relocations require a function descriptor to be | |
6023 | created and, unless lazy binding is disabled or the symbol is not | |
6024 | dynamic, a lazy PLT entry. Since we can't tell at this point | |
6025 | whether a symbol is going to be dynamic, we have to decide later | |
6026 | whether to create a lazy PLT entry or bind the descriptor directly | |
6027 | to the private function. | |
6028 | ||
6029 | FUNCDESC_VALUE relocations are not supposed to be present in object | |
6030 | files, but they may very well be simply propagated to the linker | |
6031 | output, since they have no side effect. | |
6032 | ||
6033 | ||
6034 | A function descriptor always requires a FUNCDESC_VALUE relocation. | |
6035 | Whether it's in .plt.rel or not depends on whether lazy binding is | |
6036 | enabled and on whether the referenced symbol is dynamic. | |
6037 | ||
6038 | The existence of a lazy PLT requires the resolverStub lazy PLT | |
6039 | entry to be present. | |
6040 | ||
6041 | ||
6042 | As for assignment of GOT, PLT and lazy PLT entries, and private | |
6043 | descriptors, we might do them all sequentially, but we can do | |
6044 | better than that. For example, we can place GOT entries and | |
6045 | private function descriptors referenced using 12-bit operands | |
6046 | closer to the PIC register value, such that these relocations don't | |
6047 | overflow. Those that are only referenced with LO16 relocations | |
6048 | could come next, but we may as well place PLT-required function | |
6049 | descriptors in the 12-bit range to make them shorter. Symbols | |
6050 | referenced with LO16/HI16 may come next, but we may place | |
6051 | additional function descriptors in the 16-bit range if we can | |
6052 | reliably tell that we've already placed entries that are ever | |
6053 | referenced with only LO16. PLT entries are therefore generated as | |
6054 | small as possible, while not introducing relocation overflows in | |
6055 | GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be | |
6056 | generated before or after PLT entries, but not intermingled with | |
6057 | them, such that we can have more lazy PLT entries in range for a | |
6058 | branch to the resolverStub. The resolverStub should be emitted at | |
6059 | the most distant location from the first lazy PLT entry such that | |
6060 | it's still in range for a branch, or closer, if there isn't a need | |
6061 | for so many lazy PLT entries. Additional lazy PLT entries may be | |
6062 | emitted after the resolverStub, as long as branches are still in | |
6063 | range. If the branch goes out of range, longer lazy PLT entries | |
6064 | are emitted. | |
6065 | ||
6066 | We could further optimize PLT and lazy PLT entries by giving them | |
6067 | priority in assignment to closer-to-gr17 locations depending on the | |
6068 | number of occurrences of references to them (assuming a function | |
6069 | that's called more often is more important for performance, so its | |
6070 | PLT entry should be faster), or taking hints from the compiler. | |
6071 | Given infinite time and money... :-) */ | |
b34976b6 AM |
6072 | |
6073 | static bfd_boolean | |
4e5ba5b7 DB |
6074 | elf32_frv_check_relocs (abfd, info, sec, relocs) |
6075 | bfd *abfd; | |
6076 | struct bfd_link_info *info; | |
6077 | asection *sec; | |
6078 | const Elf_Internal_Rela *relocs; | |
6079 | { | |
6080 | Elf_Internal_Shdr *symtab_hdr; | |
6081 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
6082 | const Elf_Internal_Rela *rel; | |
6083 | const Elf_Internal_Rela *rel_end; | |
51532845 | 6084 | bfd *dynobj; |
43850d5b | 6085 | struct frvfdpic_relocs_info *picrel; |
b34976b6 | 6086 | |
1049f94e | 6087 | if (info->relocatable) |
b34976b6 AM |
6088 | return TRUE; |
6089 | ||
4e5ba5b7 DB |
6090 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
6091 | sym_hashes = elf_sym_hashes (abfd); | |
6092 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym); | |
6093 | if (!elf_bad_symtab (abfd)) | |
6094 | sym_hashes_end -= symtab_hdr->sh_info; | |
b34976b6 | 6095 | |
51532845 | 6096 | dynobj = elf_hash_table (info)->dynobj; |
4e5ba5b7 DB |
6097 | rel_end = relocs + sec->reloc_count; |
6098 | for (rel = relocs; rel < rel_end; rel++) | |
6099 | { | |
6100 | struct elf_link_hash_entry *h; | |
6101 | unsigned long r_symndx; | |
b34976b6 | 6102 | |
4e5ba5b7 DB |
6103 | r_symndx = ELF32_R_SYM (rel->r_info); |
6104 | if (r_symndx < symtab_hdr->sh_info) | |
6105 | h = NULL; | |
6106 | else | |
973a3492 L |
6107 | { |
6108 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
6109 | while (h->root.type == bfd_link_hash_indirect | |
6110 | || h->root.type == bfd_link_hash_warning) | |
6111 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6112 | } | |
b34976b6 | 6113 | |
51532845 AO |
6114 | switch (ELF32_R_TYPE (rel->r_info)) |
6115 | { | |
90219bd0 AO |
6116 | case R_FRV_GETTLSOFF: |
6117 | case R_FRV_TLSDESC_VALUE: | |
6118 | case R_FRV_GOTTLSDESC12: | |
6119 | case R_FRV_GOTTLSDESCHI: | |
6120 | case R_FRV_GOTTLSDESCLO: | |
6121 | case R_FRV_GOTTLSOFF12: | |
6122 | case R_FRV_GOTTLSOFFHI: | |
6123 | case R_FRV_GOTTLSOFFLO: | |
6124 | case R_FRV_TLSOFF: | |
51532845 AO |
6125 | case R_FRV_GOT12: |
6126 | case R_FRV_GOTHI: | |
6127 | case R_FRV_GOTLO: | |
6128 | case R_FRV_FUNCDESC_GOT12: | |
6129 | case R_FRV_FUNCDESC_GOTHI: | |
6130 | case R_FRV_FUNCDESC_GOTLO: | |
6131 | case R_FRV_GOTOFF12: | |
6132 | case R_FRV_GOTOFFHI: | |
6133 | case R_FRV_GOTOFFLO: | |
6134 | case R_FRV_FUNCDESC_GOTOFF12: | |
6135 | case R_FRV_FUNCDESC_GOTOFFHI: | |
6136 | case R_FRV_FUNCDESC_GOTOFFLO: | |
6137 | case R_FRV_FUNCDESC: | |
6138 | case R_FRV_FUNCDESC_VALUE: | |
90219bd0 AO |
6139 | case R_FRV_TLSMOFF12: |
6140 | case R_FRV_TLSMOFFHI: | |
6141 | case R_FRV_TLSMOFFLO: | |
6142 | case R_FRV_TLSMOFF: | |
43850d5b AO |
6143 | if (! IS_FDPIC (abfd)) |
6144 | goto bad_reloc; | |
6145 | /* Fall through. */ | |
6146 | case R_FRV_GPREL12: | |
6147 | case R_FRV_GPRELU12: | |
6148 | case R_FRV_GPRELHI: | |
6149 | case R_FRV_GPRELLO: | |
6150 | case R_FRV_LABEL24: | |
6151 | case R_FRV_32: | |
51532845 AO |
6152 | if (! dynobj) |
6153 | { | |
6154 | elf_hash_table (info)->dynobj = dynobj = abfd; | |
6155 | if (! _frv_create_got_section (abfd, info)) | |
6156 | return FALSE; | |
6157 | } | |
43850d5b AO |
6158 | if (! IS_FDPIC (abfd)) |
6159 | { | |
6160 | picrel = NULL; | |
6161 | break; | |
6162 | } | |
51532845 AO |
6163 | if (h != NULL) |
6164 | { | |
6165 | if (h->dynindx == -1) | |
6166 | switch (ELF_ST_VISIBILITY (h->other)) | |
6167 | { | |
6168 | case STV_INTERNAL: | |
6169 | case STV_HIDDEN: | |
6170 | break; | |
6171 | default: | |
c152c796 | 6172 | bfd_elf_link_record_dynamic_symbol (info, h); |
51532845 AO |
6173 | break; |
6174 | } | |
6175 | picrel | |
43850d5b AO |
6176 | = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), |
6177 | abfd, h, | |
6178 | rel->r_addend, INSERT); | |
51532845 AO |
6179 | } |
6180 | else | |
43850d5b AO |
6181 | picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info |
6182 | (info), abfd, r_symndx, | |
6183 | rel->r_addend, INSERT); | |
51532845 AO |
6184 | if (! picrel) |
6185 | return FALSE; | |
6186 | break; | |
6187 | ||
6188 | default: | |
6189 | picrel = NULL; | |
6190 | break; | |
6191 | } | |
f12123c0 | 6192 | |
4e5ba5b7 DB |
6193 | switch (ELF32_R_TYPE (rel->r_info)) |
6194 | { | |
51532845 | 6195 | case R_FRV_LABEL24: |
43850d5b AO |
6196 | if (IS_FDPIC (abfd)) |
6197 | picrel->call = 1; | |
51532845 | 6198 | break; |
f12123c0 | 6199 | |
51532845 AO |
6200 | case R_FRV_FUNCDESC_VALUE: |
6201 | picrel->relocsfdv++; | |
6202 | if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
6203 | picrel->relocs32--; | |
6204 | /* Fall through. */ | |
43850d5b | 6205 | |
51532845 | 6206 | case R_FRV_32: |
43850d5b AO |
6207 | if (! IS_FDPIC (abfd)) |
6208 | break; | |
6209 | ||
51532845 AO |
6210 | picrel->sym = 1; |
6211 | if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
6212 | picrel->relocs32++; | |
6213 | break; | |
f12123c0 | 6214 | |
51532845 AO |
6215 | case R_FRV_GOT12: |
6216 | picrel->got12 = 1; | |
6217 | break; | |
f12123c0 | 6218 | |
51532845 AO |
6219 | case R_FRV_GOTHI: |
6220 | case R_FRV_GOTLO: | |
6221 | picrel->gothilo = 1; | |
6222 | break; | |
6223 | ||
6224 | case R_FRV_FUNCDESC_GOT12: | |
6225 | picrel->fdgot12 = 1; | |
6226 | break; | |
f12123c0 | 6227 | |
51532845 AO |
6228 | case R_FRV_FUNCDESC_GOTHI: |
6229 | case R_FRV_FUNCDESC_GOTLO: | |
6230 | picrel->fdgothilo = 1; | |
6231 | break; | |
f12123c0 | 6232 | |
51532845 AO |
6233 | case R_FRV_GOTOFF12: |
6234 | case R_FRV_GOTOFFHI: | |
6235 | case R_FRV_GOTOFFLO: | |
6236 | picrel->gotoff = 1; | |
6237 | break; | |
f12123c0 | 6238 | |
51532845 AO |
6239 | case R_FRV_FUNCDESC_GOTOFF12: |
6240 | picrel->fdgoff12 = 1; | |
6241 | break; | |
f12123c0 | 6242 | |
51532845 AO |
6243 | case R_FRV_FUNCDESC_GOTOFFHI: |
6244 | case R_FRV_FUNCDESC_GOTOFFLO: | |
6245 | picrel->fdgoffhilo = 1; | |
6246 | break; | |
f12123c0 | 6247 | |
51532845 AO |
6248 | case R_FRV_FUNCDESC: |
6249 | picrel->fd = 1; | |
6250 | picrel->relocsfd++; | |
6251 | break; | |
f12123c0 | 6252 | |
90219bd0 AO |
6253 | case R_FRV_GETTLSOFF: |
6254 | picrel->tlsplt = 1; | |
6255 | break; | |
6256 | ||
6257 | case R_FRV_TLSDESC_VALUE: | |
6258 | picrel->relocstlsd++; | |
6259 | goto bad_reloc; | |
3b36f7e6 | 6260 | |
90219bd0 AO |
6261 | case R_FRV_GOTTLSDESC12: |
6262 | picrel->tlsdesc12 = 1; | |
6263 | break; | |
6264 | ||
6265 | case R_FRV_GOTTLSDESCHI: | |
6266 | case R_FRV_GOTTLSDESCLO: | |
6267 | picrel->tlsdeschilo = 1; | |
6268 | break; | |
6269 | ||
6270 | case R_FRV_TLSMOFF12: | |
6271 | case R_FRV_TLSMOFFHI: | |
6272 | case R_FRV_TLSMOFFLO: | |
6273 | case R_FRV_TLSMOFF: | |
6274 | break; | |
6275 | ||
6276 | case R_FRV_GOTTLSOFF12: | |
6277 | picrel->tlsoff12 = 1; | |
6278 | info->flags |= DF_STATIC_TLS; | |
6279 | break; | |
3b36f7e6 | 6280 | |
90219bd0 AO |
6281 | case R_FRV_GOTTLSOFFHI: |
6282 | case R_FRV_GOTTLSOFFLO: | |
6283 | picrel->tlsoffhilo = 1; | |
6284 | info->flags |= DF_STATIC_TLS; | |
6285 | break; | |
3b36f7e6 | 6286 | |
90219bd0 AO |
6287 | case R_FRV_TLSOFF: |
6288 | picrel->relocstlsoff++; | |
6289 | info->flags |= DF_STATIC_TLS; | |
6290 | goto bad_reloc; | |
6291 | ||
4e5ba5b7 DB |
6292 | /* This relocation describes the C++ object vtable hierarchy. |
6293 | Reconstruct it for later use during GC. */ | |
6294 | case R_FRV_GNU_VTINHERIT: | |
c152c796 | 6295 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 6296 | return FALSE; |
4e5ba5b7 | 6297 | break; |
b34976b6 | 6298 | |
4e5ba5b7 DB |
6299 | /* This relocation describes which C++ vtable entries are actually |
6300 | used. Record for later use during GC. */ | |
6301 | case R_FRV_GNU_VTENTRY: | |
c152c796 | 6302 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 6303 | return FALSE; |
4e5ba5b7 | 6304 | break; |
43850d5b AO |
6305 | |
6306 | case R_FRV_LABEL16: | |
6307 | case R_FRV_LO16: | |
6308 | case R_FRV_HI16: | |
6309 | case R_FRV_GPREL12: | |
6310 | case R_FRV_GPRELU12: | |
6311 | case R_FRV_GPREL32: | |
6312 | case R_FRV_GPRELHI: | |
6313 | case R_FRV_GPRELLO: | |
90219bd0 AO |
6314 | case R_FRV_TLSDESC_RELAX: |
6315 | case R_FRV_GETTLSOFF_RELAX: | |
6316 | case R_FRV_TLSOFF_RELAX: | |
43850d5b AO |
6317 | break; |
6318 | ||
6319 | default: | |
6320 | bad_reloc: | |
6321 | (*_bfd_error_handler) | |
d003868e AM |
6322 | (_("%B: unsupported relocation type %i"), |
6323 | abfd, ELF32_R_TYPE (rel->r_info)); | |
43850d5b | 6324 | return FALSE; |
4e5ba5b7 DB |
6325 | } |
6326 | } | |
b34976b6 AM |
6327 | |
6328 | return TRUE; | |
4e5ba5b7 DB |
6329 | } |
6330 | ||
6331 | \f | |
6332 | /* Return the machine subcode from the ELF e_flags header. */ | |
6333 | ||
6334 | static int | |
6335 | elf32_frv_machine (abfd) | |
6336 | bfd *abfd; | |
6337 | { | |
6338 | switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK) | |
6339 | { | |
6340 | default: break; | |
9c8ee639 | 6341 | case EF_FRV_CPU_FR550: return bfd_mach_fr550; |
4e5ba5b7 | 6342 | case EF_FRV_CPU_FR500: return bfd_mach_fr500; |
676a64f4 RS |
6343 | case EF_FRV_CPU_FR450: return bfd_mach_fr450; |
6344 | case EF_FRV_CPU_FR405: return bfd_mach_fr400; | |
4e5ba5b7 DB |
6345 | case EF_FRV_CPU_FR400: return bfd_mach_fr400; |
6346 | case EF_FRV_CPU_FR300: return bfd_mach_fr300; | |
6347 | case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple; | |
6348 | case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat; | |
6349 | } | |
6350 | ||
6351 | return bfd_mach_frv; | |
6352 | } | |
6353 | ||
6354 | /* Set the right machine number for a FRV ELF file. */ | |
6355 | ||
b34976b6 | 6356 | static bfd_boolean |
4e5ba5b7 DB |
6357 | elf32_frv_object_p (abfd) |
6358 | bfd *abfd; | |
6359 | { | |
6360 | bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd)); | |
43850d5b AO |
6361 | return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0) |
6362 | == (IS_FDPIC (abfd))); | |
4e5ba5b7 DB |
6363 | } |
6364 | \f | |
6365 | /* Function to set the ELF flag bits. */ | |
6366 | ||
b34976b6 | 6367 | static bfd_boolean |
4e5ba5b7 DB |
6368 | frv_elf_set_private_flags (abfd, flags) |
6369 | bfd *abfd; | |
6370 | flagword flags; | |
6371 | { | |
6372 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 AM |
6373 | elf_flags_init (abfd) = TRUE; |
6374 | return TRUE; | |
4e5ba5b7 DB |
6375 | } |
6376 | ||
6377 | /* Copy backend specific data from one object module to another. */ | |
6378 | ||
b34976b6 | 6379 | static bfd_boolean |
4e5ba5b7 DB |
6380 | frv_elf_copy_private_bfd_data (ibfd, obfd) |
6381 | bfd *ibfd; | |
6382 | bfd *obfd; | |
6383 | { | |
6384 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
6385 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 6386 | return TRUE; |
4e5ba5b7 DB |
6387 | |
6388 | BFD_ASSERT (!elf_flags_init (obfd) | |
6389 | || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags); | |
6390 | ||
6391 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; | |
b34976b6 AM |
6392 | elf_flags_init (obfd) = TRUE; |
6393 | return TRUE; | |
4e5ba5b7 DB |
6394 | } |
6395 | ||
676a64f4 RS |
6396 | /* Return true if the architecture described by elf header flag |
6397 | EXTENSION is an extension of the architecture described by BASE. */ | |
6398 | ||
6399 | static bfd_boolean | |
6400 | frv_elf_arch_extension_p (flagword base, flagword extension) | |
6401 | { | |
6402 | if (base == extension) | |
6403 | return TRUE; | |
6404 | ||
6405 | /* CPU_GENERIC code can be merged with code for a specific | |
6406 | architecture, in which case the result is marked as being | |
6407 | for the specific architecture. Everything is therefore | |
6408 | an extension of CPU_GENERIC. */ | |
6409 | if (base == EF_FRV_CPU_GENERIC) | |
6410 | return TRUE; | |
6411 | ||
6412 | if (extension == EF_FRV_CPU_FR450) | |
6413 | if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405) | |
6414 | return TRUE; | |
6415 | ||
6416 | if (extension == EF_FRV_CPU_FR405) | |
6417 | if (base == EF_FRV_CPU_FR400) | |
6418 | return TRUE; | |
6419 | ||
6420 | return FALSE; | |
6421 | } | |
6422 | ||
7e9f3bd6 AO |
6423 | static bfd_boolean |
6424 | elf32_frvfdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) | |
6425 | { | |
6426 | unsigned i; | |
6427 | ||
6428 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
6429 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
6430 | return TRUE; | |
6431 | ||
6432 | if (! frv_elf_copy_private_bfd_data (ibfd, obfd)) | |
6433 | return FALSE; | |
6434 | ||
6435 | if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr | |
6436 | || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr) | |
6437 | return TRUE; | |
6438 | ||
6439 | /* Copy the stack size. */ | |
6440 | for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++) | |
6441 | if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK) | |
6442 | { | |
6443 | Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i]; | |
6444 | ||
6445 | for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++) | |
6446 | if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK) | |
6447 | { | |
6448 | memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr)); | |
6449 | ||
6450 | /* Rewrite the phdrs, since we're only called after they | |
6451 | were first written. */ | |
6452 | if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd) | |
6453 | ->s->sizeof_ehdr, SEEK_SET) != 0 | |
6454 | || get_elf_backend_data (obfd)->s | |
6455 | ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr, | |
6456 | elf_elfheader (obfd)->e_phnum) != 0) | |
6457 | return FALSE; | |
6458 | break; | |
6459 | } | |
6460 | ||
6461 | break; | |
6462 | } | |
6463 | ||
6464 | return TRUE; | |
6465 | } | |
6466 | ||
4e5ba5b7 DB |
6467 | /* Merge backend specific data from an object file to the output |
6468 | object file when linking. */ | |
6469 | ||
b34976b6 | 6470 | static bfd_boolean |
4e5ba5b7 DB |
6471 | frv_elf_merge_private_bfd_data (ibfd, obfd) |
6472 | bfd *ibfd; | |
6473 | bfd *obfd; | |
6474 | { | |
6475 | flagword old_flags, old_partial; | |
6476 | flagword new_flags, new_partial; | |
b34976b6 | 6477 | bfd_boolean error = FALSE; |
4e5ba5b7 DB |
6478 | char new_opt[80]; |
6479 | char old_opt[80]; | |
6480 | ||
6481 | new_opt[0] = old_opt[0] = '\0'; | |
6482 | new_flags = elf_elfheader (ibfd)->e_flags; | |
6483 | old_flags = elf_elfheader (obfd)->e_flags; | |
6484 | ||
51532845 AO |
6485 | if (new_flags & EF_FRV_FDPIC) |
6486 | new_flags &= ~EF_FRV_PIC; | |
6487 | ||
4e5ba5b7 DB |
6488 | #ifdef DEBUG |
6489 | (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s", | |
6490 | old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no", | |
6491 | bfd_get_filename (ibfd)); | |
6492 | #endif | |
6493 | ||
6494 | if (!elf_flags_init (obfd)) /* First call, no flags set. */ | |
6495 | { | |
b34976b6 | 6496 | elf_flags_init (obfd) = TRUE; |
4e5ba5b7 DB |
6497 | old_flags = new_flags; |
6498 | } | |
6499 | ||
6500 | else if (new_flags == old_flags) /* Compatible flags are ok. */ | |
6501 | ; | |
6502 | ||
6503 | else /* Possibly incompatible flags. */ | |
6504 | { | |
6505 | /* Warn if different # of gprs are used. Note, 0 means nothing is | |
6506 | said about the size of gprs. */ | |
6507 | new_partial = (new_flags & EF_FRV_GPR_MASK); | |
6508 | old_partial = (old_flags & EF_FRV_GPR_MASK); | |
6509 | if (new_partial == old_partial) | |
6510 | ; | |
6511 | ||
6512 | else if (new_partial == 0) | |
6513 | ; | |
6514 | ||
6515 | else if (old_partial == 0) | |
6516 | old_flags |= new_partial; | |
6517 | ||
6518 | else | |
6519 | { | |
6520 | switch (new_partial) | |
6521 | { | |
6522 | default: strcat (new_opt, " -mgpr-??"); break; | |
6523 | case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break; | |
6524 | case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break; | |
6525 | } | |
6526 | ||
6527 | switch (old_partial) | |
6528 | { | |
6529 | default: strcat (old_opt, " -mgpr-??"); break; | |
6530 | case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break; | |
6531 | case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break; | |
6532 | } | |
6533 | } | |
6534 | ||
6535 | /* Warn if different # of fprs are used. Note, 0 means nothing is | |
6536 | said about the size of fprs. */ | |
6537 | new_partial = (new_flags & EF_FRV_FPR_MASK); | |
6538 | old_partial = (old_flags & EF_FRV_FPR_MASK); | |
6539 | if (new_partial == old_partial) | |
6540 | ; | |
6541 | ||
6542 | else if (new_partial == 0) | |
6543 | ; | |
6544 | ||
6545 | else if (old_partial == 0) | |
6546 | old_flags |= new_partial; | |
6547 | ||
6548 | else | |
6549 | { | |
6550 | switch (new_partial) | |
6551 | { | |
6552 | default: strcat (new_opt, " -mfpr-?"); break; | |
6553 | case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break; | |
6554 | case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break; | |
6555 | case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break; | |
6556 | } | |
6557 | ||
6558 | switch (old_partial) | |
6559 | { | |
6560 | default: strcat (old_opt, " -mfpr-?"); break; | |
6561 | case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break; | |
6562 | case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break; | |
6563 | case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break; | |
6564 | } | |
6565 | } | |
6566 | ||
6567 | /* Warn if different dword support was used. Note, 0 means nothing is | |
6568 | said about the dword support. */ | |
6569 | new_partial = (new_flags & EF_FRV_DWORD_MASK); | |
6570 | old_partial = (old_flags & EF_FRV_DWORD_MASK); | |
6571 | if (new_partial == old_partial) | |
6572 | ; | |
6573 | ||
6574 | else if (new_partial == 0) | |
6575 | ; | |
6576 | ||
6577 | else if (old_partial == 0) | |
6578 | old_flags |= new_partial; | |
6579 | ||
6580 | else | |
6581 | { | |
6582 | switch (new_partial) | |
6583 | { | |
6584 | default: strcat (new_opt, " -mdword-?"); break; | |
6585 | case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break; | |
6586 | case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break; | |
6587 | } | |
6588 | ||
6589 | switch (old_partial) | |
6590 | { | |
6591 | default: strcat (old_opt, " -mdword-?"); break; | |
6592 | case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break; | |
6593 | case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break; | |
6594 | } | |
6595 | } | |
6596 | ||
6597 | /* Or in flags that accumulate (ie, if one module uses it, mark that the | |
6598 | feature is used. */ | |
6599 | old_flags |= new_flags & (EF_FRV_DOUBLE | |
6600 | | EF_FRV_MEDIA | |
6601 | | EF_FRV_MULADD | |
6602 | | EF_FRV_NON_PIC_RELOCS); | |
6603 | ||
6604 | /* If any module was compiled without -G0, clear the G0 bit. */ | |
6605 | old_flags = ((old_flags & ~ EF_FRV_G0) | |
6606 | | (old_flags & new_flags & EF_FRV_G0)); | |
6607 | ||
6608 | /* If any module was compiled without -mnopack, clear the mnopack bit. */ | |
6609 | old_flags = ((old_flags & ~ EF_FRV_NOPACK) | |
6610 | | (old_flags & new_flags & EF_FRV_NOPACK)); | |
6611 | ||
6612 | /* We don't have to do anything if the pic flags are the same, or the new | |
6613 | module(s) were compiled with -mlibrary-pic. */ | |
6614 | new_partial = (new_flags & EF_FRV_PIC_FLAGS); | |
6615 | old_partial = (old_flags & EF_FRV_PIC_FLAGS); | |
6616 | if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0)) | |
6617 | ; | |
6618 | ||
6619 | /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic | |
6620 | flags if any from the new module. */ | |
6621 | else if ((old_partial & EF_FRV_LIBPIC) != 0) | |
6622 | old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial; | |
6623 | ||
6624 | /* If we have mixtures of -fpic and -fPIC, or in both bits. */ | |
6625 | else if (new_partial != 0 && old_partial != 0) | |
6626 | old_flags |= new_partial; | |
6627 | ||
6628 | /* One module was compiled for pic and the other was not, see if we have | |
6629 | had any relocations that are not pic-safe. */ | |
6630 | else | |
6631 | { | |
6632 | if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0) | |
6633 | old_flags |= new_partial; | |
6634 | else | |
6635 | { | |
6636 | old_flags &= ~ EF_FRV_PIC_FLAGS; | |
6637 | #ifndef FRV_NO_PIC_ERROR | |
b34976b6 | 6638 | error = TRUE; |
4e5ba5b7 DB |
6639 | (*_bfd_error_handler) |
6640 | (_("%s: compiled with %s and linked with modules that use non-pic relocations"), | |
6641 | bfd_get_filename (ibfd), | |
6642 | (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic"); | |
6643 | #endif | |
6644 | } | |
6645 | } | |
6646 | ||
6647 | /* Warn if different cpu is used (allow a specific cpu to override | |
6648 | the generic cpu). */ | |
6649 | new_partial = (new_flags & EF_FRV_CPU_MASK); | |
6650 | old_partial = (old_flags & EF_FRV_CPU_MASK); | |
676a64f4 | 6651 | if (frv_elf_arch_extension_p (new_partial, old_partial)) |
4e5ba5b7 DB |
6652 | ; |
6653 | ||
676a64f4 | 6654 | else if (frv_elf_arch_extension_p (old_partial, new_partial)) |
4e5ba5b7 DB |
6655 | old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial; |
6656 | ||
6657 | else | |
6658 | { | |
6659 | switch (new_partial) | |
6660 | { | |
6661 | default: strcat (new_opt, " -mcpu=?"); break; | |
6662 | case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break; | |
6663 | case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break; | |
9c8ee639 | 6664 | case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break; |
4e5ba5b7 | 6665 | case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break; |
676a64f4 RS |
6666 | case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break; |
6667 | case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
6668 | case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break; |
6669 | case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break; | |
6670 | case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break; | |
6671 | } | |
6672 | ||
6673 | switch (old_partial) | |
6674 | { | |
6675 | default: strcat (old_opt, " -mcpu=?"); break; | |
6676 | case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break; | |
6677 | case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break; | |
9c8ee639 | 6678 | case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break; |
4e5ba5b7 | 6679 | case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break; |
676a64f4 RS |
6680 | case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break; |
6681 | case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
6682 | case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break; |
6683 | case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break; | |
6684 | case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break; | |
6685 | } | |
6686 | } | |
b34976b6 | 6687 | |
4e5ba5b7 DB |
6688 | /* Print out any mismatches from above. */ |
6689 | if (new_opt[0]) | |
6690 | { | |
b34976b6 | 6691 | error = TRUE; |
4e5ba5b7 DB |
6692 | (*_bfd_error_handler) |
6693 | (_("%s: compiled with %s and linked with modules compiled with %s"), | |
6694 | bfd_get_filename (ibfd), new_opt, old_opt); | |
6695 | } | |
6696 | ||
6697 | /* Warn about any other mismatches */ | |
6698 | new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS); | |
6699 | old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS); | |
6700 | if (new_partial != old_partial) | |
6701 | { | |
6702 | old_flags |= new_partial; | |
b34976b6 | 6703 | error = TRUE; |
4e5ba5b7 DB |
6704 | (*_bfd_error_handler) |
6705 | (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"), | |
6706 | bfd_get_filename (ibfd), (long)new_partial, (long)old_partial); | |
6707 | } | |
6708 | } | |
6709 | ||
6710 | /* If the cpu is -mcpu=simple, then set the -mnopack bit. */ | |
6711 | if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE) | |
6712 | old_flags |= EF_FRV_NOPACK; | |
6713 | ||
6714 | /* Update the old flags now with changes made above. */ | |
6715 | old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK; | |
6716 | elf_elfheader (obfd)->e_flags = old_flags; | |
6717 | if (old_partial != (old_flags & EF_FRV_CPU_MASK)) | |
6718 | bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd)); | |
6719 | ||
43850d5b AO |
6720 | if (((new_flags & EF_FRV_FDPIC) == 0) |
6721 | != (! IS_FDPIC (ibfd))) | |
6722 | { | |
6723 | error = TRUE; | |
6724 | if (IS_FDPIC (obfd)) | |
6725 | (*_bfd_error_handler) | |
6726 | (_("%s: cannot link non-fdpic object file into fdpic executable"), | |
6727 | bfd_get_filename (ibfd)); | |
6728 | else | |
6729 | (*_bfd_error_handler) | |
6730 | (_("%s: cannot link fdpic object file into non-fdpic executable"), | |
6731 | bfd_get_filename (ibfd)); | |
6732 | } | |
6733 | ||
4e5ba5b7 DB |
6734 | if (error) |
6735 | bfd_set_error (bfd_error_bad_value); | |
6736 | ||
6737 | return !error; | |
6738 | } | |
6739 | ||
6740 | \f | |
b34976b6 | 6741 | bfd_boolean |
4e5ba5b7 DB |
6742 | frv_elf_print_private_bfd_data (abfd, ptr) |
6743 | bfd *abfd; | |
6744 | PTR ptr; | |
6745 | { | |
6746 | FILE *file = (FILE *) ptr; | |
6747 | flagword flags; | |
6748 | ||
6749 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
6750 | ||
6751 | /* Print normal ELF private data. */ | |
6752 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
6753 | ||
6754 | flags = elf_elfheader (abfd)->e_flags; | |
6755 | fprintf (file, _("private flags = 0x%lx:"), (long)flags); | |
6756 | ||
6757 | switch (flags & EF_FRV_CPU_MASK) | |
6758 | { | |
6759 | default: break; | |
6760 | case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break; | |
9c8ee639 | 6761 | case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break; |
4e5ba5b7 | 6762 | case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break; |
676a64f4 RS |
6763 | case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break; |
6764 | case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
6765 | case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break; |
6766 | case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break; | |
6767 | case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break; | |
6768 | } | |
6769 | ||
6770 | switch (flags & EF_FRV_GPR_MASK) | |
6771 | { | |
6772 | default: break; | |
6773 | case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break; | |
6774 | case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break; | |
6775 | } | |
6776 | ||
6777 | switch (flags & EF_FRV_FPR_MASK) | |
6778 | { | |
6779 | default: break; | |
6780 | case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break; | |
6781 | case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break; | |
6782 | case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break; | |
6783 | } | |
6784 | ||
6785 | switch (flags & EF_FRV_DWORD_MASK) | |
6786 | { | |
6787 | default: break; | |
6788 | case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break; | |
6789 | case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break; | |
6790 | } | |
6791 | ||
6792 | if (flags & EF_FRV_DOUBLE) | |
6793 | fprintf (file, " -mdouble"); | |
6794 | ||
6795 | if (flags & EF_FRV_MEDIA) | |
6796 | fprintf (file, " -mmedia"); | |
6797 | ||
6798 | if (flags & EF_FRV_MULADD) | |
6799 | fprintf (file, " -mmuladd"); | |
6800 | ||
6801 | if (flags & EF_FRV_PIC) | |
6802 | fprintf (file, " -fpic"); | |
6803 | ||
6804 | if (flags & EF_FRV_BIGPIC) | |
6805 | fprintf (file, " -fPIC"); | |
6806 | ||
51532845 AO |
6807 | if (flags & EF_FRV_LIBPIC) |
6808 | fprintf (file, " -mlibrary-pic"); | |
6809 | ||
6810 | if (flags & EF_FRV_FDPIC) | |
6811 | fprintf (file, " -mfdpic"); | |
f12123c0 | 6812 | |
4e5ba5b7 DB |
6813 | if (flags & EF_FRV_NON_PIC_RELOCS) |
6814 | fprintf (file, " non-pic relocations"); | |
6815 | ||
6816 | if (flags & EF_FRV_G0) | |
6817 | fprintf (file, " -G0"); | |
6818 | ||
6819 | fputc ('\n', file); | |
b34976b6 | 6820 | return TRUE; |
4e5ba5b7 DB |
6821 | } |
6822 | ||
6823 | \f | |
888b45b8 KB |
6824 | /* Support for core dump NOTE sections. */ |
6825 | ||
6826 | static bfd_boolean | |
6827 | elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
6828 | { | |
6829 | int offset; | |
6830 | unsigned int raw_size; | |
6831 | ||
6832 | switch (note->descsz) | |
6833 | { | |
6834 | default: | |
6835 | return FALSE; | |
6836 | ||
6837 | /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other | |
6838 | hardcoded offsets and sizes listed below (and contained within | |
6839 | this lexical block) refer to fields in the target's elf_prstatus | |
6840 | struct. */ | |
6841 | case 268: | |
6842 | /* `pr_cursig' is at offset 12. */ | |
6843 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
6844 | ||
6845 | /* `pr_pid' is at offset 24. */ | |
6846 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
6847 | ||
6848 | /* `pr_reg' is at offset 72. */ | |
6849 | offset = 72; | |
6850 | ||
6851 | /* Most grok_prstatus implementations set `raw_size' to the size | |
6852 | of the pr_reg field. For Linux/FRV, we set `raw_size' to be | |
6853 | the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap' | |
6854 | and `pr_interp_fdpic_loadmap', both of which (by design) | |
6855 | immediately follow `pr_reg'. This will allow these fields to | |
6856 | be viewed by GDB as registers. | |
6857 | ||
6858 | `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and | |
6859 | `pr_interp_fdpic_loadmap' are 4 bytes each. */ | |
6860 | raw_size = 184 + 4 + 4; | |
6861 | ||
6862 | break; | |
6863 | } | |
6864 | ||
6865 | /* Make a ".reg/999" section. */ | |
6866 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size, | |
6867 | note->descpos + offset); | |
6868 | } | |
6869 | ||
6870 | static bfd_boolean | |
6871 | elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
6872 | { | |
6873 | switch (note->descsz) | |
6874 | { | |
6875 | default: | |
6876 | return FALSE; | |
6877 | ||
6878 | /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */ | |
6879 | case 124: | |
6880 | ||
6881 | /* `pr_fname' is found at offset 28 and is 16 bytes long. */ | |
6882 | elf_tdata (abfd)->core_program | |
6883 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); | |
6884 | ||
6885 | /* `pr_psargs' is found at offset 44 and is 80 bytes long. */ | |
6886 | elf_tdata (abfd)->core_command | |
6887 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); | |
6888 | } | |
6889 | ||
6890 | /* Note that for some reason, a spurious space is tacked | |
6891 | onto the end of the args in some (at least one anyway) | |
6892 | implementations, so strip it off if it exists. */ | |
6893 | ||
6894 | { | |
6895 | char *command = elf_tdata (abfd)->core_command; | |
6896 | int n = strlen (command); | |
6897 | ||
6898 | if (0 < n && command[n - 1] == ' ') | |
6899 | command[n - 1] = '\0'; | |
6900 | } | |
6901 | ||
6902 | return TRUE; | |
6903 | } | |
4e5ba5b7 DB |
6904 | #define ELF_ARCH bfd_arch_frv |
6905 | #define ELF_MACHINE_CODE EM_CYGNUS_FRV | |
6906 | #define ELF_MAXPAGESIZE 0x1000 | |
6907 | ||
6908 | #define TARGET_BIG_SYM bfd_elf32_frv_vec | |
6909 | #define TARGET_BIG_NAME "elf32-frv" | |
6910 | ||
4e5ba5b7 DB |
6911 | #define elf_info_to_howto frv_info_to_howto_rela |
6912 | #define elf_backend_relocate_section elf32_frv_relocate_section | |
6913 | #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook | |
6914 | #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook | |
6915 | #define elf_backend_check_relocs elf32_frv_check_relocs | |
6916 | #define elf_backend_object_p elf32_frv_object_p | |
6917 | #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook | |
6918 | ||
6919 | #define elf_backend_can_gc_sections 1 | |
de2d743e | 6920 | #define elf_backend_rela_normal 1 |
4e5ba5b7 DB |
6921 | |
6922 | #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup | |
6923 | #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags | |
6924 | #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data | |
6925 | #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data | |
6926 | #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data | |
6927 | ||
43850d5b AO |
6928 | #define elf_backend_want_got_sym 1 |
6929 | #define elf_backend_got_header_size 0 | |
6930 | #define elf_backend_want_got_plt 0 | |
6931 | #define elf_backend_plt_readonly 1 | |
6932 | #define elf_backend_want_plt_sym 0 | |
6933 | #define elf_backend_plt_header_size 0 | |
6934 | ||
6935 | #define elf_backend_finish_dynamic_sections \ | |
6936 | elf32_frv_finish_dynamic_sections | |
6937 | ||
888b45b8 KB |
6938 | #define elf_backend_grok_prstatus elf32_frv_grok_prstatus |
6939 | #define elf_backend_grok_psinfo elf32_frv_grok_psinfo | |
6940 | ||
43850d5b AO |
6941 | #include "elf32-target.h" |
6942 | ||
6943 | #undef ELF_MAXPAGESIZE | |
6944 | #define ELF_MAXPAGESIZE 0x4000 | |
6945 | ||
6946 | #undef TARGET_BIG_SYM | |
6947 | #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec | |
6948 | #undef TARGET_BIG_NAME | |
6949 | #define TARGET_BIG_NAME "elf32-frvfdpic" | |
6950 | #undef elf32_bed | |
6951 | #define elf32_bed elf32_frvfdpic_bed | |
6952 | ||
6953 | #undef elf_info_to_howto_rel | |
6954 | #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel | |
6955 | ||
6956 | #undef bfd_elf32_bfd_link_hash_table_create | |
6957 | #define bfd_elf32_bfd_link_hash_table_create \ | |
6958 | frvfdpic_elf_link_hash_table_create | |
6959 | #undef elf_backend_always_size_sections | |
51532845 | 6960 | #define elf_backend_always_size_sections \ |
43850d5b | 6961 | elf32_frvfdpic_always_size_sections |
e36284ab AM |
6962 | #undef elf_backend_modify_program_headers |
6963 | #define elf_backend_modify_program_headers \ | |
6964 | elf32_frvfdpic_modify_program_headers | |
7e9f3bd6 AO |
6965 | #undef bfd_elf32_bfd_copy_private_bfd_data |
6966 | #define bfd_elf32_bfd_copy_private_bfd_data \ | |
6967 | elf32_frvfdpic_copy_private_bfd_data | |
51532845 | 6968 | |
43850d5b | 6969 | #undef elf_backend_create_dynamic_sections |
51532845 | 6970 | #define elf_backend_create_dynamic_sections \ |
43850d5b AO |
6971 | elf32_frvfdpic_create_dynamic_sections |
6972 | #undef elf_backend_adjust_dynamic_symbol | |
51532845 | 6973 | #define elf_backend_adjust_dynamic_symbol \ |
43850d5b AO |
6974 | elf32_frvfdpic_adjust_dynamic_symbol |
6975 | #undef elf_backend_size_dynamic_sections | |
51532845 | 6976 | #define elf_backend_size_dynamic_sections \ |
43850d5b | 6977 | elf32_frvfdpic_size_dynamic_sections |
90219bd0 AO |
6978 | #undef bfd_elf32_bfd_relax_section |
6979 | #define bfd_elf32_bfd_relax_section \ | |
6980 | elf32_frvfdpic_relax_section | |
43850d5b | 6981 | #undef elf_backend_finish_dynamic_symbol |
51532845 | 6982 | #define elf_backend_finish_dynamic_symbol \ |
43850d5b AO |
6983 | elf32_frvfdpic_finish_dynamic_symbol |
6984 | #undef elf_backend_finish_dynamic_sections | |
51532845 | 6985 | #define elf_backend_finish_dynamic_sections \ |
43850d5b | 6986 | elf32_frvfdpic_finish_dynamic_sections |
51532845 | 6987 | |
43850d5b | 6988 | #undef elf_backend_can_make_relative_eh_frame |
ec3391e7 | 6989 | #define elf_backend_can_make_relative_eh_frame \ |
43850d5b AO |
6990 | frvfdpic_elf_use_relative_eh_frame |
6991 | #undef elf_backend_can_make_lsda_relative_eh_frame | |
ec3391e7 | 6992 | #define elf_backend_can_make_lsda_relative_eh_frame \ |
43850d5b AO |
6993 | frvfdpic_elf_use_relative_eh_frame |
6994 | #undef elf_backend_encode_eh_address | |
6995 | #define elf_backend_encode_eh_address \ | |
6996 | frvfdpic_elf_encode_eh_address | |
ec3391e7 | 6997 | |
43850d5b | 6998 | #undef elf_backend_may_use_rel_p |
51532845 | 6999 | #define elf_backend_may_use_rel_p 1 |
43850d5b | 7000 | #undef elf_backend_may_use_rela_p |
51532845 AO |
7001 | #define elf_backend_may_use_rela_p 1 |
7002 | /* We use REL for dynamic relocations only. */ | |
43850d5b | 7003 | #undef elf_backend_default_use_rela_p |
51532845 AO |
7004 | #define elf_backend_default_use_rela_p 1 |
7005 | ||
aee6f5b4 AO |
7006 | #undef elf_backend_omit_section_dynsym |
7007 | #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym | |
7008 | ||
4e5ba5b7 | 7009 | #include "elf32-target.h" |