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