Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/bfd/elf32-frv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (show annotations) (download) (as text)
Mon Jul 27 20:34:36 2009 UTC (14 years, 8 months ago) by monamour
File MIME type: text/x-csrc
File size: 219951 byte(s)
Update to HEAD.
1 /* FRV-specific support for 32-bit ELF.
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf/frv.h"
27 #include "dwarf2.h"
28 #include "hashtab.h"
29
30 /* Forward declarations. */
31 static bfd_reloc_status_type elf32_frv_relocate_lo16
32 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
33 static bfd_reloc_status_type elf32_frv_relocate_hi16
34 PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
35 static bfd_reloc_status_type elf32_frv_relocate_label24
36 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
37 static bfd_reloc_status_type elf32_frv_relocate_gprel12
38 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
39 bfd_byte *, bfd_vma));
40 static bfd_reloc_status_type elf32_frv_relocate_gprelu12
41 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
42 bfd_byte *, bfd_vma));
43 static bfd_reloc_status_type elf32_frv_relocate_gprello
44 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
45 bfd_byte *, bfd_vma));
46 static bfd_reloc_status_type elf32_frv_relocate_gprelhi
47 PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
48 bfd_byte *, bfd_vma));
49 static reloc_howto_type *frv_reloc_type_lookup
50 PARAMS ((bfd *, bfd_reloc_code_real_type));
51 static void frv_info_to_howto_rela
52 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
53 static bfd_boolean elf32_frv_relocate_section
54 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
55 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
56 static bfd_boolean elf32_frv_add_symbol_hook
57 PARAMS (( bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
58 const char **, flagword *, asection **, bfd_vma *));
59 static bfd_reloc_status_type frv_final_link_relocate
60 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
61 Elf_Internal_Rela *, bfd_vma));
62 static bfd_boolean elf32_frv_check_relocs
63 PARAMS ((bfd *, struct bfd_link_info *, asection *,
64 const Elf_Internal_Rela *));
65 static int elf32_frv_machine
66 PARAMS ((bfd *));
67 static bfd_boolean elf32_frv_object_p
68 PARAMS ((bfd *));
69 static bfd_boolean frv_elf_set_private_flags
70 PARAMS ((bfd *, flagword));
71 static bfd_boolean frv_elf_copy_private_bfd_data
72 PARAMS ((bfd *, bfd *));
73 static bfd_boolean frv_elf_merge_private_bfd_data
74 PARAMS ((bfd *, bfd *));
75 static bfd_boolean frv_elf_print_private_bfd_data
76 PARAMS ((bfd *, PTR));
77 static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd,
78 Elf_Internal_Note * note);
79 static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd,
80 Elf_Internal_Note * note);
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 */
89 FALSE, /* pc_relative */
90 0, /* bitpos */
91 complain_overflow_bitfield, /* complain_on_overflow */
92 bfd_elf_generic_reloc, /* special_function */
93 "R_FRV_NONE", /* name */
94 FALSE, /* partial_inplace */
95 0, /* src_mask */
96 0, /* dst_mask */
97 FALSE), /* pcrel_offset */
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 */
104 FALSE, /* pc_relative */
105 0, /* bitpos */
106 complain_overflow_bitfield, /* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_FRV_32", /* name */
109 FALSE, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE), /* pcrel_offset */
113
114 /* A 16 bit pc-relative relocation. */
115 HOWTO (R_FRV_LABEL16, /* type */
116 2, /* rightshift */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
118 16, /* bitsize */
119 TRUE, /* pc_relative */
120 0, /* bitpos */
121 complain_overflow_signed, /* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_FRV_LABEL16", /* name */
124 FALSE, /* partial_inplace */
125 0xffff, /* src_mask */
126 0xffff, /* dst_mask */
127 TRUE), /* pcrel_offset */
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 */
134 TRUE, /* pc_relative */
135 0, /* bitpos */
136 complain_overflow_bitfield, /* complain_on_overflow */
137 bfd_elf_generic_reloc, /* special_function */
138 "R_FRV_LABEL24", /* name */
139 FALSE, /* partial_inplace */
140 0x7e03ffff, /* src_mask */
141 0x7e03ffff, /* dst_mask */
142 TRUE), /* pcrel_offset */
143
144 HOWTO (R_FRV_LO16, /* type */
145 0, /* rightshift */
146 2, /* size (0 = byte, 1 = short, 2 = long) */
147 16, /* bitsize */
148 FALSE, /* pc_relative */
149 0, /* bitpos */
150 complain_overflow_dont, /* complain_on_overflow */
151 bfd_elf_generic_reloc, /* special_function */
152 "R_FRV_LO16", /* name */
153 FALSE, /* partial_inplace */
154 0xffff, /* src_mask */
155 0xffff, /* dst_mask */
156 FALSE), /* pcrel_offset */
157
158 HOWTO (R_FRV_HI16, /* type */
159 0, /* rightshift */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
161 16, /* bitsize */
162 FALSE, /* pc_relative */
163 0, /* bitpos */
164 complain_overflow_dont, /* complain_on_overflow */
165 bfd_elf_generic_reloc, /* special_function */
166 "R_FRV_HI16", /* name */
167 FALSE, /* partial_inplace */
168 0xffff, /* src_mask */
169 0xffff, /* dst_mask */
170 FALSE), /* pcrel_offset */
171
172 HOWTO (R_FRV_GPREL12, /* type */
173 0, /* rightshift */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
175 12, /* bitsize */
176 FALSE, /* pc_relative */
177 0, /* bitpos */
178 complain_overflow_dont, /* complain_on_overflow */
179 bfd_elf_generic_reloc, /* special_function */
180 "R_FRV_GPREL12", /* name */
181 FALSE, /* partial_inplace */
182 0xfff, /* src_mask */
183 0xfff, /* dst_mask */
184 FALSE), /* pcrel_offset */
185
186 HOWTO (R_FRV_GPRELU12, /* type */
187 0, /* rightshift */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
189 12, /* bitsize */
190 FALSE, /* pc_relative */
191 0, /* bitpos */
192 complain_overflow_dont, /* complain_on_overflow */
193 bfd_elf_generic_reloc, /* special_function */
194 "R_FRV_GPRELU12", /* name */
195 FALSE, /* partial_inplace */
196 0xfff, /* src_mask */
197 0x3f03f, /* dst_mask */
198 FALSE), /* pcrel_offset */
199
200 HOWTO (R_FRV_GPREL32, /* type */
201 0, /* rightshift */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
203 32, /* bitsize */
204 FALSE, /* pc_relative */
205 0, /* bitpos */
206 complain_overflow_dont, /* complain_on_overflow */
207 bfd_elf_generic_reloc, /* special_function */
208 "R_FRV_GPREL32", /* name */
209 FALSE, /* partial_inplace */
210 0xffffffff, /* src_mask */
211 0xffffffff, /* dst_mask */
212 FALSE), /* pcrel_offset */
213
214 HOWTO (R_FRV_GPRELHI, /* type */
215 0, /* rightshift */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
217 16, /* bitsize */
218 FALSE, /* pc_relative */
219 0, /* bitpos */
220 complain_overflow_dont, /* complain_on_overflow */
221 bfd_elf_generic_reloc, /* special_function */
222 "R_FRV_GPRELHI", /* name */
223 FALSE, /* partial_inplace */
224 0xffff, /* src_mask */
225 0xffff, /* dst_mask */
226 FALSE), /* pcrel_offset */
227
228 HOWTO (R_FRV_GPRELLO, /* type */
229 0, /* rightshift */
230 2, /* size (0 = byte, 1 = short, 2 = long) */
231 16, /* bitsize */
232 FALSE, /* pc_relative */
233 0, /* bitpos */
234 complain_overflow_dont, /* complain_on_overflow */
235 bfd_elf_generic_reloc, /* special_function */
236 "R_FRV_GPRELLO", /* name */
237 FALSE, /* partial_inplace */
238 0xffff, /* src_mask */
239 0xffff, /* dst_mask */
240 FALSE), /* pcrel_offset */
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
353 /* The 64-bit descriptor of a function. */
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
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 */
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 */
731 FALSE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_dont, /* complain_on_overflow */
734 NULL, /* special_function */
735 "R_FRV_GNU_VTINHERIT", /* name */
736 FALSE, /* partial_inplace */
737 0, /* src_mask */
738 0, /* dst_mask */
739 FALSE); /* pcrel_offset */
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 */
747 FALSE, /* pc_relative */
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 */
752 FALSE, /* partial_inplace */
753 0, /* src_mask */
754 0, /* dst_mask */
755 FALSE); /* pcrel_offset */
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
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
848
849 extern const bfd_target bfd_elf32_frvfdpic_vec;
850 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
851
852 /* An extension of the elf hash table data structure, containing some
853 additional FRV-specific data. */
854 struct frvfdpic_elf_link_hash_table
855 {
856 struct elf_link_hash_table elf;
857
858 /* A pointer to the .got section. */
859 asection *sgot;
860 /* A pointer to the .rel.got section. */
861 asection *sgotrel;
862 /* A pointer to the .rofixup section. */
863 asection *sgotfixup;
864 /* A pointer to the .plt section. */
865 asection *splt;
866 /* A pointer to the .rel.plt section. */
867 asection *spltrel;
868 /* GOT base offset. */
869 bfd_vma got0;
870 /* Location of the first non-lazy PLT entry, i.e., the number of
871 bytes taken by lazy PLT entries. If locally-bound TLS
872 descriptors require a ret instruction, it will be placed at this
873 offset. */
874 bfd_vma plt0;
875 /* A hash table holding information about which symbols were
876 referenced with which PIC-related relocations. */
877 struct htab *relocs_info;
878 /* Summary reloc information collected by
879 _frvfdpic_count_got_plt_entries. */
880 struct _frvfdpic_dynamic_got_info *g;
881 };
882
883 /* Get the FRV ELF linker hash table from a link_info structure. */
884
885 #define frvfdpic_hash_table(info) \
886 ((struct frvfdpic_elf_link_hash_table *) ((info)->hash))
887
888 #define frvfdpic_got_section(info) \
889 (frvfdpic_hash_table (info)->sgot)
890 #define frvfdpic_gotrel_section(info) \
891 (frvfdpic_hash_table (info)->sgotrel)
892 #define frvfdpic_gotfixup_section(info) \
893 (frvfdpic_hash_table (info)->sgotfixup)
894 #define frvfdpic_plt_section(info) \
895 (frvfdpic_hash_table (info)->splt)
896 #define frvfdpic_pltrel_section(info) \
897 (frvfdpic_hash_table (info)->spltrel)
898 #define frvfdpic_relocs_info(info) \
899 (frvfdpic_hash_table (info)->relocs_info)
900 #define frvfdpic_got_initial_offset(info) \
901 (frvfdpic_hash_table (info)->got0)
902 #define frvfdpic_plt_initial_offset(info) \
903 (frvfdpic_hash_table (info)->plt0)
904 #define frvfdpic_dynamic_got_plt_info(info) \
905 (frvfdpic_hash_table (info)->g)
906
907 /* Currently it's the same, but if some day we have a reason to change
908 it, we'd better be using a different macro.
909
910 FIXME: if there's any TLS PLT entry that uses local-exec or
911 initial-exec models, we could use the ret at the end of any of them
912 instead of adding one more. */
913 #define frvfdpic_plt_tls_ret_offset(info) \
914 (frvfdpic_plt_initial_offset (info))
915
916 /* The name of the dynamic interpreter. This is put in the .interp
917 section. */
918
919 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
920
921 #define DEFAULT_STACK_SIZE 0x20000
922
923 /* This structure is used to collect the number of entries present in
924 each addressable range of the got. */
925 struct _frvfdpic_dynamic_got_info
926 {
927 /* Several bits of information about the current link. */
928 struct bfd_link_info *info;
929 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
930 ranges. */
931 bfd_vma got12, gotlos, gothilo;
932 /* Total GOT size needed for function descriptor entries within the 12-,
933 16- or 32-bit ranges. */
934 bfd_vma fd12, fdlos, fdhilo;
935 /* Total GOT size needed by function descriptor entries referenced
936 in PLT entries, that would be profitable to place in offsets
937 close to the PIC register. */
938 bfd_vma fdplt;
939 /* Total PLT size needed by lazy PLT entries. */
940 bfd_vma lzplt;
941 /* Total GOT size needed for TLS descriptor entries within the 12-,
942 16- or 32-bit ranges. */
943 bfd_vma tlsd12, tlsdlos, tlsdhilo;
944 /* Total GOT size needed by TLS descriptors referenced in PLT
945 entries, that would be profitable to place in offers close to the
946 PIC register. */
947 bfd_vma tlsdplt;
948 /* Total PLT size needed by TLS lazy PLT entries. */
949 bfd_vma tlslzplt;
950 /* Number of relocations carried over from input object files. */
951 unsigned long relocs;
952 /* Number of fixups introduced by relocations in input object files. */
953 unsigned long fixups;
954 /* The number of fixups that reference the ret instruction added to
955 the PLT for locally-resolved TLS descriptors. */
956 unsigned long tls_ret_refs;
957 };
958
959 /* This structure is used to assign offsets to got entries, function
960 descriptors, plt entries and lazy plt entries. */
961
962 struct _frvfdpic_dynamic_got_plt_info
963 {
964 /* Summary information collected with _frvfdpic_count_got_plt_entries. */
965 struct _frvfdpic_dynamic_got_info g;
966
967 /* For each addressable range, we record a MAX (positive) and MIN
968 (negative) value. CUR is used to assign got entries, and it's
969 incremented from an initial positive value to MAX, then from MIN
970 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
971 assign function descriptors, and it's decreased from an initial
972 non-positive value to MIN, then from MAX down to CUR (unless CUR
973 wraps around first). All of MIN, MAX, CUR and FDCUR always point
974 to even words. ODD, if non-zero, indicates an odd word to be
975 used for the next got entry, otherwise CUR is used and
976 incremented by a pair of words, wrapping around when it reaches
977 MAX. FDCUR is decremented (and wrapped) before the next function
978 descriptor is chosen. FDPLT indicates the number of remaining
979 slots that can be used for function descriptors used only by PLT
980 entries.
981
982 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
983 starts as MAX, and grows up to TMAX, then wraps around to TMIN
984 and grows up to MIN. TLSDPLT indicates the number of remaining
985 slots that can be used for TLS descriptors used only by TLS PLT
986 entries. */
987 struct _frvfdpic_dynamic_got_alloc_data
988 {
989 bfd_signed_vma max, cur, odd, fdcur, min;
990 bfd_signed_vma tmax, tcur, tmin;
991 bfd_vma fdplt, tlsdplt;
992 } got12, gotlos, gothilo;
993 };
994
995 /* Create an FRV ELF linker hash table. */
996
997 static struct bfd_link_hash_table *
998 frvfdpic_elf_link_hash_table_create (bfd *abfd)
999 {
1000 struct frvfdpic_elf_link_hash_table *ret;
1001 bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table);
1002
1003 ret = bfd_zalloc (abfd, amt);
1004 if (ret == NULL)
1005 return NULL;
1006
1007 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1008 _bfd_elf_link_hash_newfunc,
1009 sizeof (struct elf_link_hash_entry)))
1010 {
1011 free (ret);
1012 return NULL;
1013 }
1014
1015 return &ret->elf.root;
1016 }
1017
1018 /* Decide whether a reference to a symbol can be resolved locally or
1019 not. If the symbol is protected, we want the local address, but
1020 its function descriptor must be assigned by the dynamic linker. */
1021 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
1022 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1023 || ! elf_hash_table (INFO)->dynamic_sections_created)
1024 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
1025 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1026
1027 /* This structure collects information on what kind of GOT, PLT or
1028 function descriptors are required by relocations that reference a
1029 certain symbol. */
1030 struct frvfdpic_relocs_info
1031 {
1032 /* The index of the symbol, as stored in the relocation r_info, if
1033 we have a local symbol; -1 otherwise. */
1034 long symndx;
1035 union
1036 {
1037 /* The input bfd in which the symbol is defined, if it's a local
1038 symbol. */
1039 bfd *abfd;
1040 /* If symndx == -1, the hash table entry corresponding to a global
1041 symbol (even if it turns out to bind locally, in which case it
1042 should ideally be replaced with section's symndx + addend). */
1043 struct elf_link_hash_entry *h;
1044 } d;
1045 /* The addend of the relocation that references the symbol. */
1046 bfd_vma addend;
1047
1048 /* The fields above are used to identify an entry. The fields below
1049 contain information on how an entry is used and, later on, which
1050 locations it was assigned. */
1051 /* The following 3 fields record whether the symbol+addend above was
1052 ever referenced with a GOT relocation. The 12 suffix indicates a
1053 GOT12 relocation; los is used for GOTLO relocations that are not
1054 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
1055 pairs. */
1056 unsigned got12:1;
1057 unsigned gotlos:1;
1058 unsigned gothilo:1;
1059 /* Whether a FUNCDESC relocation references symbol+addend. */
1060 unsigned fd:1;
1061 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1062 unsigned fdgot12:1;
1063 unsigned fdgotlos:1;
1064 unsigned fdgothilo:1;
1065 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1066 unsigned fdgoff12:1;
1067 unsigned fdgofflos:1;
1068 unsigned fdgoffhilo:1;
1069 /* Whether a GETTLSOFF relocation references symbol+addend. */
1070 unsigned tlsplt:1;
1071 /* FIXME: we should probably add tlspltdesc, tlspltoff and
1072 tlspltimm, to tell what kind of TLS PLT entry we're generating.
1073 We might instead just pre-compute flags telling whether the
1074 object is suitable for local exec, initial exec or general
1075 dynamic addressing, and use that all over the place. We could
1076 also try to do a better job of merging TLSOFF and TLSDESC entries
1077 in main executables, but perhaps we can get rid of TLSDESC
1078 entirely in them instead. */
1079 /* Whether a GOTTLSDESC relocation references symbol+addend. */
1080 unsigned tlsdesc12:1;
1081 unsigned tlsdesclos:1;
1082 unsigned tlsdeschilo:1;
1083 /* Whether a GOTTLSOFF relocation references symbol+addend. */
1084 unsigned tlsoff12:1;
1085 unsigned tlsofflos:1;
1086 unsigned tlsoffhilo:1;
1087 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
1088 GOTOFFHI relocations. The addend doesn't really matter, since we
1089 envision that this will only be used to check whether the symbol
1090 is mapped to the same segment as the got. */
1091 unsigned gotoff:1;
1092 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1093 unsigned call:1;
1094 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1095 relocation. */
1096 unsigned sym:1;
1097 /* Whether we need a PLT entry for a symbol. Should be implied by
1098 something like:
1099 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
1100 unsigned plt:1;
1101 /* Whether a function descriptor should be created in this link unit
1102 for symbol+addend. Should be implied by something like:
1103 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
1104 || ((fd || fdgot12 || fdgotlos || fdgothilo)
1105 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1106 unsigned privfd:1;
1107 /* Whether a lazy PLT entry is needed for this symbol+addend.
1108 Should be implied by something like:
1109 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
1110 && ! (info->flags & DF_BIND_NOW)) */
1111 unsigned lazyplt:1;
1112 /* Whether we've already emitted GOT relocations and PLT entries as
1113 needed for this symbol. */
1114 unsigned done:1;
1115
1116 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
1117 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
1118 symbol+addend. */
1119 unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff;
1120
1121 /* The number of .rofixups entries and dynamic relocations allocated
1122 for this symbol, minus any that might have already been used. */
1123 unsigned fixups, dynrelocs;
1124
1125 /* The offsets of the GOT entries assigned to symbol+addend, to the
1126 function descriptor's address, and to a function descriptor,
1127 respectively. Should be zero if unassigned. The offsets are
1128 counted from the value that will be assigned to the PIC register,
1129 not from the beginning of the .got section. */
1130 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
1131 /* The offsets of the PLT entries assigned to symbol+addend,
1132 non-lazy and lazy, respectively. If unassigned, should be
1133 (bfd_vma)-1. */
1134 bfd_vma plt_entry, lzplt_entry;
1135 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
1136 bfd_signed_vma tlsoff_entry, tlsdesc_entry;
1137 /* The offset of the TLS offset PLT entry. */
1138 bfd_vma tlsplt_entry;
1139 };
1140
1141 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
1142 static hashval_t
1143 frvfdpic_relocs_info_hash (const void *entry_)
1144 {
1145 const struct frvfdpic_relocs_info *entry = entry_;
1146
1147 return (entry->symndx == -1
1148 ? (long) entry->d.h->root.root.hash
1149 : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend;
1150 }
1151
1152 /* Test whether the key fields of two frvfdpic_relocs_info entries are
1153 identical. */
1154 static int
1155 frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
1156 {
1157 const struct frvfdpic_relocs_info *e1 = entry1;
1158 const struct frvfdpic_relocs_info *e2 = entry2;
1159
1160 return e1->symndx == e2->symndx && e1->addend == e2->addend
1161 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
1162 }
1163
1164 /* Find or create an entry in a hash table HT that matches the key
1165 fields of the given ENTRY. If it's not found, memory for a new
1166 entry is allocated in ABFD's obstack. */
1167 static struct frvfdpic_relocs_info *
1168 frvfdpic_relocs_info_find (struct htab *ht,
1169 bfd *abfd,
1170 const struct frvfdpic_relocs_info *entry,
1171 enum insert_option insert)
1172 {
1173 struct frvfdpic_relocs_info **loc =
1174 (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
1175
1176 if (! loc)
1177 return NULL;
1178
1179 if (*loc)
1180 return *loc;
1181
1182 *loc = bfd_zalloc (abfd, sizeof (**loc));
1183
1184 if (! *loc)
1185 return *loc;
1186
1187 (*loc)->symndx = entry->symndx;
1188 (*loc)->d = entry->d;
1189 (*loc)->addend = entry->addend;
1190 (*loc)->plt_entry = (bfd_vma)-1;
1191 (*loc)->lzplt_entry = (bfd_vma)-1;
1192 (*loc)->tlsplt_entry = (bfd_vma)-1;
1193
1194 return *loc;
1195 }
1196
1197 /* Obtain the address of the entry in HT associated with H's symbol +
1198 addend, creating a new entry if none existed. ABFD is only used
1199 for memory allocation purposes. */
1200 inline static struct frvfdpic_relocs_info *
1201 frvfdpic_relocs_info_for_global (struct htab *ht,
1202 bfd *abfd,
1203 struct elf_link_hash_entry *h,
1204 bfd_vma addend,
1205 enum insert_option insert)
1206 {
1207 struct frvfdpic_relocs_info entry;
1208
1209 entry.symndx = -1;
1210 entry.d.h = h;
1211 entry.addend = addend;
1212
1213 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1214 }
1215
1216 /* Obtain the address of the entry in HT associated with the SYMNDXth
1217 local symbol of the input bfd ABFD, plus the addend, creating a new
1218 entry if none existed. */
1219 inline static struct frvfdpic_relocs_info *
1220 frvfdpic_relocs_info_for_local (struct htab *ht,
1221 bfd *abfd,
1222 long symndx,
1223 bfd_vma addend,
1224 enum insert_option insert)
1225 {
1226 struct frvfdpic_relocs_info entry;
1227
1228 entry.symndx = symndx;
1229 entry.d.abfd = abfd;
1230 entry.addend = addend;
1231
1232 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
1233 }
1234
1235 /* Merge fields set by check_relocs() of two entries that end up being
1236 mapped to the same (presumably global) symbol. */
1237
1238 inline static void
1239 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
1240 struct frvfdpic_relocs_info const *e1)
1241 {
1242 e2->got12 |= e1->got12;
1243 e2->gotlos |= e1->gotlos;
1244 e2->gothilo |= e1->gothilo;
1245 e2->fd |= e1->fd;
1246 e2->fdgot12 |= e1->fdgot12;
1247 e2->fdgotlos |= e1->fdgotlos;
1248 e2->fdgothilo |= e1->fdgothilo;
1249 e2->fdgoff12 |= e1->fdgoff12;
1250 e2->fdgofflos |= e1->fdgofflos;
1251 e2->fdgoffhilo |= e1->fdgoffhilo;
1252 e2->tlsplt |= e1->tlsplt;
1253 e2->tlsdesc12 |= e1->tlsdesc12;
1254 e2->tlsdesclos |= e1->tlsdesclos;
1255 e2->tlsdeschilo |= e1->tlsdeschilo;
1256 e2->tlsoff12 |= e1->tlsoff12;
1257 e2->tlsofflos |= e1->tlsofflos;
1258 e2->tlsoffhilo |= e1->tlsoffhilo;
1259 e2->gotoff |= e1->gotoff;
1260 e2->call |= e1->call;
1261 e2->sym |= e1->sym;
1262 }
1263
1264 /* Every block of 65535 lazy PLT entries shares a single call to the
1265 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1266 32767, counting from 0). All other lazy PLT entries branch to it
1267 in a single instruction. */
1268
1269 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
1270 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
1271
1272 /* Add a dynamic relocation to the SRELOC section. */
1273
1274 inline static bfd_vma
1275 _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
1276 int reloc_type, long dynindx, bfd_vma addend,
1277 struct frvfdpic_relocs_info *entry)
1278 {
1279 Elf_Internal_Rela outrel;
1280 bfd_vma reloc_offset;
1281
1282 outrel.r_offset = offset;
1283 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
1284 outrel.r_addend = addend;
1285
1286 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
1287 BFD_ASSERT (reloc_offset < sreloc->size);
1288 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1289 sreloc->contents + reloc_offset);
1290 sreloc->reloc_count++;
1291
1292 /* If the entry's index is zero, this relocation was probably to a
1293 linkonce section that got discarded. We reserved a dynamic
1294 relocation, but it was for another entry than the one we got at
1295 the time of emitting the relocation. Unfortunately there's no
1296 simple way for us to catch this situation, since the relocation
1297 is cleared right before calling relocate_section, at which point
1298 we no longer know what the relocation used to point to. */
1299 if (entry->symndx)
1300 {
1301 BFD_ASSERT (entry->dynrelocs > 0);
1302 entry->dynrelocs--;
1303 }
1304
1305 return reloc_offset;
1306 }
1307
1308 /* Add a fixup to the ROFIXUP section. */
1309
1310 static bfd_vma
1311 _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
1312 struct frvfdpic_relocs_info *entry)
1313 {
1314 bfd_vma fixup_offset;
1315
1316 if (rofixup->flags & SEC_EXCLUDE)
1317 return -1;
1318
1319 fixup_offset = rofixup->reloc_count * 4;
1320 if (rofixup->contents)
1321 {
1322 BFD_ASSERT (fixup_offset < rofixup->size);
1323 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
1324 }
1325 rofixup->reloc_count++;
1326
1327 if (entry && entry->symndx)
1328 {
1329 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
1330 above. */
1331 BFD_ASSERT (entry->fixups > 0);
1332 entry->fixups--;
1333 }
1334
1335 return fixup_offset;
1336 }
1337
1338 /* Find the segment number in which OSEC, and output section, is
1339 located. */
1340
1341 static unsigned
1342 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
1343 {
1344 Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
1345
1346 return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
1347 }
1348
1349 inline static bfd_boolean
1350 _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
1351 {
1352 unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
1353
1354 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
1355 }
1356
1357 #define FRVFDPIC_TLS_BIAS (2048 - 16)
1358
1359 /* Return the base VMA address which should be subtracted from real addresses
1360 when resolving TLSMOFF relocation.
1361 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
1362
1363 static bfd_vma
1364 tls_biased_base (struct bfd_link_info *info)
1365 {
1366 /* If tls_sec is NULL, we should have signalled an error already. */
1367 if (elf_hash_table (info)->tls_sec == NULL)
1368 return FRVFDPIC_TLS_BIAS;
1369 return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS;
1370 }
1371
1372 /* Generate relocations for GOT entries, function descriptors, and
1373 code for PLT and lazy PLT entries. */
1374
1375 inline static bfd_boolean
1376 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
1377 bfd *output_bfd,
1378 struct bfd_link_info *info,
1379 asection *sec,
1380 Elf_Internal_Sym *sym,
1381 bfd_vma addend)
1382
1383 {
1384 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
1385 int dynindx = -1;
1386
1387 if (entry->done)
1388 return TRUE;
1389 entry->done = 1;
1390
1391 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry
1392 || entry->tlsoff_entry || entry->tlsdesc_entry)
1393 {
1394 /* If the symbol is dynamic, consider it for dynamic
1395 relocations, otherwise decay to section + offset. */
1396 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
1397 dynindx = entry->d.h->dynindx;
1398 else
1399 {
1400 if (sec
1401 && sec->output_section
1402 && ! bfd_is_abs_section (sec->output_section)
1403 && ! bfd_is_und_section (sec->output_section))
1404 dynindx = elf_section_data (sec->output_section)->dynindx;
1405 else
1406 dynindx = 0;
1407 }
1408 }
1409
1410 /* Generate relocation for GOT entry pointing to the symbol. */
1411 if (entry->got_entry)
1412 {
1413 int idx = dynindx;
1414 bfd_vma ad = addend;
1415
1416 /* If the symbol is dynamic but binds locally, use
1417 section+offset. */
1418 if (sec && (entry->symndx != -1
1419 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1420 {
1421 if (entry->symndx == -1)
1422 ad += entry->d.h->root.u.def.value;
1423 else
1424 ad += sym->st_value;
1425 ad += sec->output_offset;
1426 if (sec->output_section && elf_section_data (sec->output_section))
1427 idx = elf_section_data (sec->output_section)->dynindx;
1428 else
1429 idx = 0;
1430 }
1431
1432 /* If we're linking an executable at a fixed address, we can
1433 omit the dynamic relocation as long as the symbol is local to
1434 this module. */
1435 if (info->executable && !info->pie
1436 && (entry->symndx != -1
1437 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1438 {
1439 if (sec)
1440 ad += sec->output_section->vma;
1441 if (entry->symndx != -1
1442 || entry->d.h->root.type != bfd_link_hash_undefweak)
1443 _frvfdpic_add_rofixup (output_bfd,
1444 frvfdpic_gotfixup_section (info),
1445 frvfdpic_got_section (info)->output_section
1446 ->vma
1447 + frvfdpic_got_section (info)->output_offset
1448 + frvfdpic_got_initial_offset (info)
1449 + entry->got_entry, entry);
1450 }
1451 else
1452 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1453 _bfd_elf_section_offset
1454 (output_bfd, info,
1455 frvfdpic_got_section (info),
1456 frvfdpic_got_initial_offset (info)
1457 + entry->got_entry)
1458 + frvfdpic_got_section (info)
1459 ->output_section->vma
1460 + frvfdpic_got_section (info)->output_offset,
1461 R_FRV_32, idx, ad, entry);
1462
1463 bfd_put_32 (output_bfd, ad,
1464 frvfdpic_got_section (info)->contents
1465 + frvfdpic_got_initial_offset (info)
1466 + entry->got_entry);
1467 }
1468
1469 /* Generate relocation for GOT entry pointing to a canonical
1470 function descriptor. */
1471 if (entry->fdgot_entry)
1472 {
1473 int reloc, idx;
1474 bfd_vma ad = 0;
1475
1476 if (! (entry->symndx == -1
1477 && entry->d.h->root.type == bfd_link_hash_undefweak
1478 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1479 {
1480 /* If the symbol is dynamic and there may be dynamic symbol
1481 resolution because we are, or are linked with, a shared
1482 library, emit a FUNCDESC relocation such that the dynamic
1483 linker will allocate the function descriptor. If the
1484 symbol needs a non-local function descriptor but binds
1485 locally (e.g., its visibility is protected, emit a
1486 dynamic relocation decayed to section+offset. */
1487 if (entry->symndx == -1
1488 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
1489 && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
1490 && !(info->executable && !info->pie))
1491 {
1492 reloc = R_FRV_FUNCDESC;
1493 idx = elf_section_data (entry->d.h->root.u.def.section
1494 ->output_section)->dynindx;
1495 ad = entry->d.h->root.u.def.section->output_offset
1496 + entry->d.h->root.u.def.value;
1497 }
1498 else if (entry->symndx == -1
1499 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
1500 {
1501 reloc = R_FRV_FUNCDESC;
1502 idx = dynindx;
1503 ad = addend;
1504 if (ad)
1505 {
1506 (*info->callbacks->reloc_dangerous)
1507 (info, _("relocation requires zero addend"),
1508 elf_hash_table (info)->dynobj,
1509 frvfdpic_got_section (info),
1510 entry->fdgot_entry);
1511 return FALSE;
1512 }
1513 }
1514 else
1515 {
1516 /* Otherwise, we know we have a private function descriptor,
1517 so reference it directly. */
1518 if (elf_hash_table (info)->dynamic_sections_created)
1519 BFD_ASSERT (entry->privfd);
1520 reloc = R_FRV_32;
1521 idx = elf_section_data (frvfdpic_got_section (info)
1522 ->output_section)->dynindx;
1523 ad = frvfdpic_got_section (info)->output_offset
1524 + frvfdpic_got_initial_offset (info) + entry->fd_entry;
1525 }
1526
1527 /* If there is room for dynamic symbol resolution, emit the
1528 dynamic relocation. However, if we're linking an
1529 executable at a fixed location, we won't have emitted a
1530 dynamic symbol entry for the got section, so idx will be
1531 zero, which means we can and should compute the address
1532 of the private descriptor ourselves. */
1533 if (info->executable && !info->pie
1534 && (entry->symndx != -1
1535 || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
1536 {
1537 ad += frvfdpic_got_section (info)->output_section->vma;
1538 _frvfdpic_add_rofixup (output_bfd,
1539 frvfdpic_gotfixup_section (info),
1540 frvfdpic_got_section (info)
1541 ->output_section->vma
1542 + frvfdpic_got_section (info)
1543 ->output_offset
1544 + frvfdpic_got_initial_offset (info)
1545 + entry->fdgot_entry, entry);
1546 }
1547 else
1548 _frvfdpic_add_dyn_reloc (output_bfd,
1549 frvfdpic_gotrel_section (info),
1550 _bfd_elf_section_offset
1551 (output_bfd, info,
1552 frvfdpic_got_section (info),
1553 frvfdpic_got_initial_offset (info)
1554 + entry->fdgot_entry)
1555 + frvfdpic_got_section (info)
1556 ->output_section->vma
1557 + frvfdpic_got_section (info)
1558 ->output_offset,
1559 reloc, idx, ad, entry);
1560 }
1561
1562 bfd_put_32 (output_bfd, ad,
1563 frvfdpic_got_section (info)->contents
1564 + frvfdpic_got_initial_offset (info)
1565 + entry->fdgot_entry);
1566 }
1567
1568 /* Generate relocation to fill in a private function descriptor in
1569 the GOT. */
1570 if (entry->fd_entry)
1571 {
1572 int idx = dynindx;
1573 bfd_vma ad = addend;
1574 bfd_vma ofst;
1575 long lowword, highword;
1576
1577 /* If the symbol is dynamic but binds locally, use
1578 section+offset. */
1579 if (sec && (entry->symndx != -1
1580 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1581 {
1582 if (entry->symndx == -1)
1583 ad += entry->d.h->root.u.def.value;
1584 else
1585 ad += sym->st_value;
1586 ad += sec->output_offset;
1587 if (sec->output_section && elf_section_data (sec->output_section))
1588 idx = elf_section_data (sec->output_section)->dynindx;
1589 else
1590 idx = 0;
1591 }
1592
1593 /* If we're linking an executable at a fixed address, we can
1594 omit the dynamic relocation as long as the symbol is local to
1595 this module. */
1596 if (info->executable && !info->pie
1597 && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1598 {
1599 if (sec)
1600 ad += sec->output_section->vma;
1601 ofst = 0;
1602 if (entry->symndx != -1
1603 || entry->d.h->root.type != bfd_link_hash_undefweak)
1604 {
1605 _frvfdpic_add_rofixup (output_bfd,
1606 frvfdpic_gotfixup_section (info),
1607 frvfdpic_got_section (info)
1608 ->output_section->vma
1609 + frvfdpic_got_section (info)
1610 ->output_offset
1611 + frvfdpic_got_initial_offset (info)
1612 + entry->fd_entry, entry);
1613 _frvfdpic_add_rofixup (output_bfd,
1614 frvfdpic_gotfixup_section (info),
1615 frvfdpic_got_section (info)
1616 ->output_section->vma
1617 + frvfdpic_got_section (info)
1618 ->output_offset
1619 + frvfdpic_got_initial_offset (info)
1620 + entry->fd_entry + 4, entry);
1621 }
1622 }
1623 else
1624 {
1625 ofst =
1626 _frvfdpic_add_dyn_reloc (output_bfd,
1627 entry->lazyplt
1628 ? frvfdpic_pltrel_section (info)
1629 : frvfdpic_gotrel_section (info),
1630 _bfd_elf_section_offset
1631 (output_bfd, info,
1632 frvfdpic_got_section (info),
1633 frvfdpic_got_initial_offset (info)
1634 + entry->fd_entry)
1635 + frvfdpic_got_section (info)
1636 ->output_section->vma
1637 + frvfdpic_got_section (info)
1638 ->output_offset,
1639 R_FRV_FUNCDESC_VALUE, idx, ad, entry);
1640 }
1641
1642 /* If we've omitted the dynamic relocation, just emit the fixed
1643 addresses of the symbol and of the local GOT base offset. */
1644 if (info->executable && !info->pie && sec && sec->output_section)
1645 {
1646 lowword = ad;
1647 highword = frvfdpic_got_section (info)->output_section->vma
1648 + frvfdpic_got_section (info)->output_offset
1649 + frvfdpic_got_initial_offset (info);
1650 }
1651 else if (entry->lazyplt)
1652 {
1653 if (ad)
1654 {
1655 (*info->callbacks->reloc_dangerous)
1656 (info, _("relocation requires zero addend"),
1657 elf_hash_table (info)->dynobj,
1658 frvfdpic_got_section (info),
1659 entry->fd_entry);
1660 return FALSE;
1661 }
1662
1663 fd_lazy_rel_offset = ofst;
1664
1665 /* A function descriptor used for lazy or local resolving is
1666 initialized such that its high word contains the output
1667 section index in which the PLT entries are located, and
1668 the low word contains the address of the lazy PLT entry
1669 entry point, that must be within the memory region
1670 assigned to that section. */
1671 lowword = entry->lzplt_entry + 4
1672 + frvfdpic_plt_section (info)->output_offset
1673 + frvfdpic_plt_section (info)->output_section->vma;
1674 highword = _frvfdpic_osec_to_segment
1675 (output_bfd, frvfdpic_plt_section (info)->output_section);
1676 }
1677 else
1678 {
1679 /* A function descriptor for a local function gets the index
1680 of the section. For a non-local function, it's
1681 disregarded. */
1682 lowword = ad;
1683 if (sec == NULL
1684 || (entry->symndx == -1 && entry->d.h->dynindx != -1
1685 && entry->d.h->dynindx == idx))
1686 highword = 0;
1687 else
1688 highword = _frvfdpic_osec_to_segment
1689 (output_bfd, sec->output_section);
1690 }
1691
1692 bfd_put_32 (output_bfd, lowword,
1693 frvfdpic_got_section (info)->contents
1694 + frvfdpic_got_initial_offset (info)
1695 + entry->fd_entry);
1696 bfd_put_32 (output_bfd, highword,
1697 frvfdpic_got_section (info)->contents
1698 + frvfdpic_got_initial_offset (info)
1699 + entry->fd_entry + 4);
1700 }
1701
1702 /* Generate code for the PLT entry. */
1703 if (entry->plt_entry != (bfd_vma) -1)
1704 {
1705 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1706 + entry->plt_entry;
1707
1708 BFD_ASSERT (entry->fd_entry);
1709
1710 /* Figure out what kind of PLT entry we need, depending on the
1711 location of the function descriptor within the GOT. */
1712 if (entry->fd_entry >= -(1 << (12 - 1))
1713 && entry->fd_entry < (1 << (12 - 1)))
1714 {
1715 /* lddi @(gr15, fd_entry), gr14 */
1716 bfd_put_32 (output_bfd,
1717 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
1718 plt_code);
1719 plt_code += 4;
1720 }
1721 else
1722 {
1723 if (entry->fd_entry >= -(1 << (16 - 1))
1724 && entry->fd_entry < (1 << (16 - 1)))
1725 {
1726 /* setlos lo(fd_entry), gr14 */
1727 bfd_put_32 (output_bfd,
1728 0x9cfc0000
1729 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1730 plt_code);
1731 plt_code += 4;
1732 }
1733 else
1734 {
1735 /* sethi.p hi(fd_entry), gr14
1736 setlo lo(fd_entry), gr14 */
1737 bfd_put_32 (output_bfd,
1738 0x1cf80000
1739 | ((entry->fd_entry >> 16)
1740 & (((bfd_vma)1 << 16) - 1)),
1741 plt_code);
1742 plt_code += 4;
1743 bfd_put_32 (output_bfd,
1744 0x9cf40000
1745 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
1746 plt_code);
1747 plt_code += 4;
1748 }
1749 /* ldd @(gr14,gr15),gr14 */
1750 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
1751 plt_code += 4;
1752 }
1753 /* jmpl @(gr14,gr0) */
1754 bfd_put_32 (output_bfd, 0x8030e000, plt_code);
1755 }
1756
1757 /* Generate code for the lazy PLT entry. */
1758 if (entry->lzplt_entry != (bfd_vma) -1)
1759 {
1760 bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
1761 + entry->lzplt_entry;
1762 bfd_vma resolverStub_addr;
1763
1764 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
1765 lzplt_code += 4;
1766
1767 resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
1768 * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
1769 if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
1770 resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
1771
1772 if (entry->lzplt_entry == resolverStub_addr)
1773 {
1774 /* This is a lazy PLT entry that includes a resolver call. */
1775 /* ldd @(gr15,gr0), gr4
1776 jmpl @(gr4,gr0) */
1777 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
1778 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
1779 }
1780 else
1781 {
1782 /* bra resolverStub */
1783 bfd_put_32 (output_bfd,
1784 0xc01a0000
1785 | (((resolverStub_addr - entry->lzplt_entry)
1786 / 4) & (((bfd_vma)1 << 16) - 1)),
1787 lzplt_code);
1788 }
1789 }
1790
1791 /* Generate relocation for GOT entry holding the TLS offset. */
1792 if (entry->tlsoff_entry)
1793 {
1794 int idx = dynindx;
1795 bfd_vma ad = addend;
1796
1797 if (entry->symndx != -1
1798 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))
1799 {
1800 /* If the symbol is dynamic but binds locally, use
1801 section+offset. */
1802 if (sec)
1803 {
1804 if (entry->symndx == -1)
1805 ad += entry->d.h->root.u.def.value;
1806 else
1807 ad += sym->st_value;
1808 ad += sec->output_offset;
1809 if (sec->output_section
1810 && elf_section_data (sec->output_section))
1811 idx = elf_section_data (sec->output_section)->dynindx;
1812 else
1813 idx = 0;
1814 }
1815 }
1816
1817 /* *ABS*+addend is special for TLS relocations, use only the
1818 addend. */
1819 if (info->executable
1820 && idx == 0
1821 && (bfd_is_abs_section (sec)
1822 || bfd_is_und_section (sec)))
1823 ;
1824 /* If we're linking an executable, we can entirely omit the
1825 dynamic relocation if the symbol is local to this module. */
1826 else if (info->executable
1827 && (entry->symndx != -1
1828 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1829 {
1830 if (sec)
1831 ad += sec->output_section->vma - tls_biased_base (info);
1832 }
1833 else
1834 {
1835 if (idx == 0
1836 && (bfd_is_abs_section (sec)
1837 || bfd_is_und_section (sec)))
1838 {
1839 if (! elf_hash_table (info)->tls_sec)
1840 {
1841 (*info->callbacks->undefined_symbol)
1842 (info, "TLS section", elf_hash_table (info)->dynobj,
1843 frvfdpic_got_section (info), entry->tlsoff_entry, TRUE);
1844 return FALSE;
1845 }
1846 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1847 ad += FRVFDPIC_TLS_BIAS;
1848 }
1849 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1850 _bfd_elf_section_offset
1851 (output_bfd, info,
1852 frvfdpic_got_section (info),
1853 frvfdpic_got_initial_offset (info)
1854 + entry->tlsoff_entry)
1855 + frvfdpic_got_section (info)
1856 ->output_section->vma
1857 + frvfdpic_got_section (info)
1858 ->output_offset,
1859 R_FRV_TLSOFF, idx, ad, entry);
1860 }
1861
1862 bfd_put_32 (output_bfd, ad,
1863 frvfdpic_got_section (info)->contents
1864 + frvfdpic_got_initial_offset (info)
1865 + entry->tlsoff_entry);
1866 }
1867
1868 if (entry->tlsdesc_entry)
1869 {
1870 int idx = dynindx;
1871 bfd_vma ad = addend;
1872
1873 /* If the symbol is dynamic but binds locally, use
1874 section+offset. */
1875 if (sec && (entry->symndx != -1
1876 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1877 {
1878 if (entry->symndx == -1)
1879 ad += entry->d.h->root.u.def.value;
1880 else
1881 ad += sym->st_value;
1882 ad += sec->output_offset;
1883 if (sec->output_section && elf_section_data (sec->output_section))
1884 idx = elf_section_data (sec->output_section)->dynindx;
1885 else
1886 idx = 0;
1887 }
1888
1889 /* If we didn't set up a TLS offset entry, but we're linking an
1890 executable and the symbol binds locally, we can use the
1891 module offset in the TLS descriptor in relaxations. */
1892 if (info->executable && ! entry->tlsoff_entry)
1893 entry->tlsoff_entry = entry->tlsdesc_entry + 4;
1894
1895 if (info->executable && !info->pie
1896 && ((idx == 0
1897 && (bfd_is_abs_section (sec)
1898 || bfd_is_und_section (sec)))
1899 || entry->symndx != -1
1900 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1901 {
1902 /* *ABS*+addend is special for TLS relocations, use only the
1903 addend for the TLS offset, and take the module id as
1904 0. */
1905 if (idx == 0
1906 && (bfd_is_abs_section (sec)
1907 || bfd_is_und_section (sec)))
1908 ;
1909 /* For other TLS symbols that bind locally, add the section
1910 TLS offset to the addend. */
1911 else if (sec)
1912 ad += sec->output_section->vma - tls_biased_base (info);
1913
1914 bfd_put_32 (output_bfd,
1915 frvfdpic_plt_section (info)->output_section->vma
1916 + frvfdpic_plt_section (info)->output_offset
1917 + frvfdpic_plt_tls_ret_offset (info),
1918 frvfdpic_got_section (info)->contents
1919 + frvfdpic_got_initial_offset (info)
1920 + entry->tlsdesc_entry);
1921
1922 _frvfdpic_add_rofixup (output_bfd,
1923 frvfdpic_gotfixup_section (info),
1924 frvfdpic_got_section (info)
1925 ->output_section->vma
1926 + frvfdpic_got_section (info)
1927 ->output_offset
1928 + frvfdpic_got_initial_offset (info)
1929 + entry->tlsdesc_entry, entry);
1930
1931 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs);
1932
1933 /* We've used one of the reserved fixups, so discount it so
1934 that we can check at the end that we've used them
1935 all. */
1936 frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--;
1937
1938 /* While at that, make sure the ret instruction makes to the
1939 right location in the PLT. We could do it only when we
1940 got to 0, but since the check at the end will only print
1941 a warning, make sure we have the ret in place in case the
1942 warning is missed. */
1943 bfd_put_32 (output_bfd, 0xc03a4000,
1944 frvfdpic_plt_section (info)->contents
1945 + frvfdpic_plt_tls_ret_offset (info));
1946 }
1947 else
1948 {
1949 if (idx == 0
1950 && (bfd_is_abs_section (sec)
1951 || bfd_is_und_section (sec)))
1952 {
1953 if (! elf_hash_table (info)->tls_sec)
1954 {
1955 (*info->callbacks->undefined_symbol)
1956 (info, "TLS section", elf_hash_table (info)->dynobj,
1957 frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE);
1958 return FALSE;
1959 }
1960 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
1961 ad += FRVFDPIC_TLS_BIAS;
1962 }
1963
1964 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
1965 _bfd_elf_section_offset
1966 (output_bfd, info,
1967 frvfdpic_got_section (info),
1968 frvfdpic_got_initial_offset (info)
1969 + entry->tlsdesc_entry)
1970 + frvfdpic_got_section (info)
1971 ->output_section->vma
1972 + frvfdpic_got_section (info)
1973 ->output_offset,
1974 R_FRV_TLSDESC_VALUE, idx, ad, entry);
1975
1976 bfd_put_32 (output_bfd, 0,
1977 frvfdpic_got_section (info)->contents
1978 + frvfdpic_got_initial_offset (info)
1979 + entry->tlsdesc_entry);
1980 }
1981
1982 bfd_put_32 (output_bfd, ad,
1983 frvfdpic_got_section (info)->contents
1984 + frvfdpic_got_initial_offset (info)
1985 + entry->tlsdesc_entry + 4);
1986 }
1987
1988 /* Generate code for the get-TLS-offset PLT entry. */
1989 if (entry->tlsplt_entry != (bfd_vma) -1)
1990 {
1991 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
1992 + entry->tlsplt_entry;
1993
1994 if (info->executable
1995 && (entry->symndx != -1
1996 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
1997 {
1998 int idx = dynindx;
1999 bfd_vma ad = addend;
2000
2001 /* sec may be NULL when referencing an undefweak symbol
2002 while linking a static executable. */
2003 if (!sec)
2004 {
2005 BFD_ASSERT (entry->symndx == -1
2006 && entry->d.h->root.type == bfd_link_hash_undefweak);
2007 }
2008 else
2009 {
2010 if (entry->symndx == -1)
2011 ad += entry->d.h->root.u.def.value;
2012 else
2013 ad += sym->st_value;
2014 ad += sec->output_offset;
2015 if (sec->output_section
2016 && elf_section_data (sec->output_section))
2017 idx = elf_section_data (sec->output_section)->dynindx;
2018 else
2019 idx = 0;
2020 }
2021
2022 /* *ABS*+addend is special for TLS relocations, use only the
2023 addend for the TLS offset, and take the module id as
2024 0. */
2025 if (idx == 0
2026 && (bfd_is_abs_section (sec)
2027 || bfd_is_und_section (sec)))
2028 ;
2029 /* For other TLS symbols that bind locally, add the section
2030 TLS offset to the addend. */
2031 else if (sec)
2032 ad += sec->output_section->vma - tls_biased_base (info);
2033
2034 if ((bfd_signed_vma)ad >= -(1 << (16 - 1))
2035 && (bfd_signed_vma)ad < (1 << (16 - 1)))
2036 {
2037 /* setlos lo(ad), gr9 */
2038 bfd_put_32 (output_bfd,
2039 0x92fc0000
2040 | (ad
2041 & (((bfd_vma)1 << 16) - 1)),
2042 plt_code);
2043 plt_code += 4;
2044 }
2045 else
2046 {
2047 /* sethi.p hi(ad), gr9
2048 setlo lo(ad), gr9 */
2049 bfd_put_32 (output_bfd,
2050 0x12f80000
2051 | ((ad >> 16)
2052 & (((bfd_vma)1 << 16) - 1)),
2053 plt_code);
2054 plt_code += 4;
2055 bfd_put_32 (output_bfd,
2056 0x92f40000
2057 | (ad
2058 & (((bfd_vma)1 << 16) - 1)),
2059 plt_code);
2060 plt_code += 4;
2061 }
2062 /* ret */
2063 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2064 }
2065 else if (entry->tlsoff_entry)
2066 {
2067 /* Figure out what kind of PLT entry we need, depending on the
2068 location of the TLS descriptor within the GOT. */
2069 if (entry->tlsoff_entry >= -(1 << (12 - 1))
2070 && entry->tlsoff_entry < (1 << (12 - 1)))
2071 {
2072 /* ldi @(gr15, tlsoff_entry), gr9 */
2073 bfd_put_32 (output_bfd,
2074 0x92c8f000 | (entry->tlsoff_entry
2075 & ((1 << 12) - 1)),
2076 plt_code);
2077 plt_code += 4;
2078 }
2079 else
2080 {
2081 if (entry->tlsoff_entry >= -(1 << (16 - 1))
2082 && entry->tlsoff_entry < (1 << (16 - 1)))
2083 {
2084 /* setlos lo(tlsoff_entry), gr8 */
2085 bfd_put_32 (output_bfd,
2086 0x90fc0000
2087 | (entry->tlsoff_entry
2088 & (((bfd_vma)1 << 16) - 1)),
2089 plt_code);
2090 plt_code += 4;
2091 }
2092 else
2093 {
2094 /* sethi.p hi(tlsoff_entry), gr8
2095 setlo lo(tlsoff_entry), gr8 */
2096 bfd_put_32 (output_bfd,
2097 0x10f80000
2098 | ((entry->tlsoff_entry >> 16)
2099 & (((bfd_vma)1 << 16) - 1)),
2100 plt_code);
2101 plt_code += 4;
2102 bfd_put_32 (output_bfd,
2103 0x90f40000
2104 | (entry->tlsoff_entry
2105 & (((bfd_vma)1 << 16) - 1)),
2106 plt_code);
2107 plt_code += 4;
2108 }
2109 /* ld @(gr15,gr8),gr9 */
2110 bfd_put_32 (output_bfd, 0x9008f108, plt_code);
2111 plt_code += 4;
2112 }
2113 /* ret */
2114 bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
2115 }
2116 else
2117 {
2118 BFD_ASSERT (entry->tlsdesc_entry);
2119
2120 /* Figure out what kind of PLT entry we need, depending on the
2121 location of the TLS descriptor within the GOT. */
2122 if (entry->tlsdesc_entry >= -(1 << (12 - 1))
2123 && entry->tlsdesc_entry < (1 << (12 - 1)))
2124 {
2125 /* lddi @(gr15, tlsdesc_entry), gr8 */
2126 bfd_put_32 (output_bfd,
2127 0x90ccf000 | (entry->tlsdesc_entry
2128 & ((1 << 12) - 1)),
2129 plt_code);
2130 plt_code += 4;
2131 }
2132 else
2133 {
2134 if (entry->tlsdesc_entry >= -(1 << (16 - 1))
2135 && entry->tlsdesc_entry < (1 << (16 - 1)))
2136 {
2137 /* setlos lo(tlsdesc_entry), gr8 */
2138 bfd_put_32 (output_bfd,
2139 0x90fc0000
2140 | (entry->tlsdesc_entry
2141 & (((bfd_vma)1 << 16) - 1)),
2142 plt_code);
2143 plt_code += 4;
2144 }
2145 else
2146 {
2147 /* sethi.p hi(tlsdesc_entry), gr8
2148 setlo lo(tlsdesc_entry), gr8 */
2149 bfd_put_32 (output_bfd,
2150 0x10f80000
2151 | ((entry->tlsdesc_entry >> 16)
2152 & (((bfd_vma)1 << 16) - 1)),
2153 plt_code);
2154 plt_code += 4;
2155 bfd_put_32 (output_bfd,
2156 0x90f40000
2157 | (entry->tlsdesc_entry
2158 & (((bfd_vma)1 << 16) - 1)),
2159 plt_code);
2160 plt_code += 4;
2161 }
2162 /* ldd @(gr15,gr8),gr8 */
2163 bfd_put_32 (output_bfd, 0x9008f148, plt_code);
2164 plt_code += 4;
2165 }
2166 /* jmpl @(gr8,gr0) */
2167 bfd_put_32 (output_bfd, 0x80308000, plt_code);
2168 }
2169 }
2170
2171 return TRUE;
2172 }
2173
2174 /* Handle an FRV small data reloc. */
2175
2176 static bfd_reloc_status_type
2177 elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
2178 contents, value)
2179 struct bfd_link_info *info;
2180 bfd *input_bfd;
2181 asection *input_section;
2182 Elf_Internal_Rela *relocation;
2183 bfd_byte *contents;
2184 bfd_vma value;
2185 {
2186 bfd_vma insn;
2187 bfd_vma gp;
2188 struct bfd_link_hash_entry *h;
2189
2190 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2191
2192 gp = (h->u.def.value
2193 + h->u.def.section->output_section->vma
2194 + h->u.def.section->output_offset);
2195
2196 value -= input_section->output_section->vma;
2197 value -= (gp - input_section->output_section->vma);
2198
2199 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2200
2201 value += relocation->r_addend;
2202
2203 if ((long) value > 0x7ff || (long) value < -0x800)
2204 return bfd_reloc_overflow;
2205
2206 bfd_put_32 (input_bfd,
2207 (insn & 0xfffff000) | (value & 0xfff),
2208 contents + relocation->r_offset);
2209
2210 return bfd_reloc_ok;
2211 }
2212
2213 /* Handle an FRV small data reloc. for the u12 field. */
2214
2215 static bfd_reloc_status_type
2216 elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
2217 contents, value)
2218 struct bfd_link_info *info;
2219 bfd *input_bfd;
2220 asection *input_section;
2221 Elf_Internal_Rela *relocation;
2222 bfd_byte *contents;
2223 bfd_vma value;
2224 {
2225 bfd_vma insn;
2226 bfd_vma gp;
2227 struct bfd_link_hash_entry *h;
2228 bfd_vma mask;
2229
2230 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2231
2232 gp = (h->u.def.value
2233 + h->u.def.section->output_section->vma
2234 + h->u.def.section->output_offset);
2235
2236 value -= input_section->output_section->vma;
2237 value -= (gp - input_section->output_section->vma);
2238
2239 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2240
2241 value += relocation->r_addend;
2242
2243 if ((long) value > 0x7ff || (long) value < -0x800)
2244 return bfd_reloc_overflow;
2245
2246 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
2247 mask = 0x3f03f;
2248 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
2249
2250 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2251
2252 return bfd_reloc_ok;
2253 }
2254
2255 /* Handle an FRV ELF HI16 reloc. */
2256
2257 static bfd_reloc_status_type
2258 elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
2259 bfd *input_bfd;
2260 Elf_Internal_Rela *relhi;
2261 bfd_byte *contents;
2262 bfd_vma value;
2263 {
2264 bfd_vma insn;
2265
2266 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
2267
2268 value += relhi->r_addend;
2269 value = ((value >> 16) & 0xffff);
2270
2271 insn = (insn & 0xffff0000) | value;
2272
2273 if ((long) value > 0xffff || (long) value < -0x10000)
2274 return bfd_reloc_overflow;
2275
2276 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
2277 return bfd_reloc_ok;
2278
2279 }
2280 static bfd_reloc_status_type
2281 elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
2282 bfd *input_bfd;
2283 Elf_Internal_Rela *rello;
2284 bfd_byte *contents;
2285 bfd_vma value;
2286 {
2287 bfd_vma insn;
2288
2289 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2290
2291 value += rello->r_addend;
2292 value = value & 0xffff;
2293
2294 insn = (insn & 0xffff0000) | value;
2295
2296 if ((long) value > 0xffff || (long) value < -0x10000)
2297 return bfd_reloc_overflow;
2298
2299 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2300 return bfd_reloc_ok;
2301 }
2302
2303 /* Perform the relocation for the CALL label24 instruction. */
2304
2305 static bfd_reloc_status_type
2306 elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
2307 bfd *input_bfd;
2308 asection *input_section;
2309 Elf_Internal_Rela *rello;
2310 bfd_byte *contents;
2311 bfd_vma value;
2312 {
2313 bfd_vma insn;
2314 bfd_vma label6;
2315 bfd_vma label18;
2316
2317 /* The format for the call instruction is:
2318
2319 0 000000 0001111 000000000000000000
2320 label6 opcode label18
2321
2322 The branch calculation is: pc + (4*label24)
2323 where label24 is the concatenation of label6 and label18. */
2324
2325 /* Grab the instruction. */
2326 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
2327
2328 value -= input_section->output_section->vma + input_section->output_offset;
2329 value -= rello->r_offset;
2330 value += rello->r_addend;
2331
2332 value = value >> 2;
2333
2334 label6 = value & 0xfc0000;
2335 label6 = label6 << 7;
2336
2337 label18 = value & 0x3ffff;
2338
2339 insn = insn & 0x803c0000;
2340 insn = insn | label6;
2341 insn = insn | label18;
2342
2343 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
2344
2345 return bfd_reloc_ok;
2346 }
2347
2348 static bfd_reloc_status_type
2349 elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
2350 contents, value)
2351 struct bfd_link_info *info;
2352 bfd *input_bfd;
2353 asection *input_section;
2354 Elf_Internal_Rela *relocation;
2355 bfd_byte *contents;
2356 bfd_vma value;
2357 {
2358 bfd_vma insn;
2359 bfd_vma gp;
2360 struct bfd_link_hash_entry *h;
2361
2362 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2363
2364 gp = (h->u.def.value
2365 + h->u.def.section->output_section->vma
2366 + h->u.def.section->output_offset);
2367
2368 value -= input_section->output_section->vma;
2369 value -= (gp - input_section->output_section->vma);
2370 value += relocation->r_addend;
2371 value = ((value >> 16) & 0xffff);
2372
2373 if ((long) value > 0xffff || (long) value < -0x10000)
2374 return bfd_reloc_overflow;
2375
2376 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2377 insn = (insn & 0xffff0000) | value;
2378
2379 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2380 return bfd_reloc_ok;
2381 }
2382
2383 static bfd_reloc_status_type
2384 elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
2385 contents, value)
2386 struct bfd_link_info *info;
2387 bfd *input_bfd;
2388 asection *input_section;
2389 Elf_Internal_Rela *relocation;
2390 bfd_byte *contents;
2391 bfd_vma value;
2392 {
2393 bfd_vma insn;
2394 bfd_vma gp;
2395 struct bfd_link_hash_entry *h;
2396
2397 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
2398
2399 gp = (h->u.def.value
2400 + h->u.def.section->output_section->vma
2401 + h->u.def.section->output_offset);
2402
2403 value -= input_section->output_section->vma;
2404 value -= (gp - input_section->output_section->vma);
2405 value += relocation->r_addend;
2406 value = value & 0xffff;
2407
2408 if ((long) value > 0xffff || (long) value < -0x10000)
2409 return bfd_reloc_overflow;
2410
2411 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
2412 insn = (insn & 0xffff0000) | value;
2413
2414 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
2415
2416 return bfd_reloc_ok;
2417 }
2418
2419 static reloc_howto_type *
2420 frv_reloc_type_lookup (abfd, code)
2421 bfd *abfd ATTRIBUTE_UNUSED;
2422 bfd_reloc_code_real_type code;
2423 {
2424 switch (code)
2425 {
2426 default:
2427 break;
2428
2429 case BFD_RELOC_NONE:
2430 return &elf32_frv_howto_table[ (int) R_FRV_NONE];
2431
2432 case BFD_RELOC_32:
2433 if (elf_elfheader (abfd)->e_type == ET_EXEC
2434 || elf_elfheader (abfd)->e_type == ET_DYN)
2435 return &elf32_frv_rel_32_howto;
2436 /* Fall through. */
2437 case BFD_RELOC_CTOR:
2438 return &elf32_frv_howto_table[ (int) R_FRV_32];
2439
2440 case BFD_RELOC_FRV_LABEL16:
2441 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
2442
2443 case BFD_RELOC_FRV_LABEL24:
2444 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
2445
2446 case BFD_RELOC_FRV_LO16:
2447 return &elf32_frv_howto_table[ (int) R_FRV_LO16];
2448
2449 case BFD_RELOC_FRV_HI16:
2450 return &elf32_frv_howto_table[ (int) R_FRV_HI16];
2451
2452 case BFD_RELOC_FRV_GPREL12:
2453 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
2454
2455 case BFD_RELOC_FRV_GPRELU12:
2456 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
2457
2458 case BFD_RELOC_FRV_GPREL32:
2459 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
2460
2461 case BFD_RELOC_FRV_GPRELHI:
2462 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
2463
2464 case BFD_RELOC_FRV_GPRELLO:
2465 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
2466
2467 case BFD_RELOC_FRV_GOT12:
2468 return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
2469
2470 case BFD_RELOC_FRV_GOTHI:
2471 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
2472
2473 case BFD_RELOC_FRV_GOTLO:
2474 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
2475
2476 case BFD_RELOC_FRV_FUNCDESC:
2477 if (elf_elfheader (abfd)->e_type == ET_EXEC
2478 || elf_elfheader (abfd)->e_type == ET_DYN)
2479 return &elf32_frv_rel_funcdesc_howto;
2480 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
2481
2482 case BFD_RELOC_FRV_FUNCDESC_GOT12:
2483 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
2484
2485 case BFD_RELOC_FRV_FUNCDESC_GOTHI:
2486 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
2487
2488 case BFD_RELOC_FRV_FUNCDESC_GOTLO:
2489 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
2490
2491 case BFD_RELOC_FRV_FUNCDESC_VALUE:
2492 if (elf_elfheader (abfd)->e_type == ET_EXEC
2493 || elf_elfheader (abfd)->e_type == ET_DYN)
2494 return &elf32_frv_rel_funcdesc_value_howto;
2495 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
2496
2497 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
2498 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
2499
2500 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
2501 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
2502
2503 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
2504 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
2505
2506 case BFD_RELOC_FRV_GOTOFF12:
2507 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
2508
2509 case BFD_RELOC_FRV_GOTOFFHI:
2510 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
2511
2512 case BFD_RELOC_FRV_GOTOFFLO:
2513 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
2514
2515 case BFD_RELOC_FRV_GETTLSOFF:
2516 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF];
2517
2518 case BFD_RELOC_FRV_TLSDESC_VALUE:
2519 if (elf_elfheader (abfd)->e_type == ET_EXEC
2520 || elf_elfheader (abfd)->e_type == ET_DYN)
2521 return &elf32_frv_rel_tlsdesc_value_howto;
2522 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE];
2523
2524 case BFD_RELOC_FRV_GOTTLSDESC12:
2525 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12];
2526
2527 case BFD_RELOC_FRV_GOTTLSDESCHI:
2528 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI];
2529
2530 case BFD_RELOC_FRV_GOTTLSDESCLO:
2531 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO];
2532
2533 case BFD_RELOC_FRV_TLSMOFF12:
2534 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12];
2535
2536 case BFD_RELOC_FRV_TLSMOFFHI:
2537 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI];
2538
2539 case BFD_RELOC_FRV_TLSMOFFLO:
2540 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO];
2541
2542 case BFD_RELOC_FRV_GOTTLSOFF12:
2543 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12];
2544
2545 case BFD_RELOC_FRV_GOTTLSOFFHI:
2546 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI];
2547
2548 case BFD_RELOC_FRV_GOTTLSOFFLO:
2549 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO];
2550
2551 case BFD_RELOC_FRV_TLSOFF:
2552 if (elf_elfheader (abfd)->e_type == ET_EXEC
2553 || elf_elfheader (abfd)->e_type == ET_DYN)
2554 return &elf32_frv_rel_tlsoff_howto;
2555 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF];
2556
2557 case BFD_RELOC_FRV_TLSDESC_RELAX:
2558 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX];
2559
2560 case BFD_RELOC_FRV_GETTLSOFF_RELAX:
2561 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX];
2562
2563 case BFD_RELOC_FRV_TLSOFF_RELAX:
2564 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX];
2565
2566 case BFD_RELOC_FRV_TLSMOFF:
2567 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF];
2568
2569 case BFD_RELOC_VTABLE_INHERIT:
2570 return &elf32_frv_vtinherit_howto;
2571
2572 case BFD_RELOC_VTABLE_ENTRY:
2573 return &elf32_frv_vtentry_howto;
2574 }
2575
2576 return NULL;
2577 }
2578
2579 static reloc_howto_type *
2580 frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
2581 {
2582 unsigned int i;
2583
2584 for (i = 0;
2585 i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]);
2586 i++)
2587 if (elf32_frv_howto_table[i].name != NULL
2588 && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0)
2589 return &elf32_frv_howto_table[i];
2590
2591 if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0)
2592 return &elf32_frv_vtinherit_howto;
2593 if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0)
2594 return &elf32_frv_vtentry_howto;
2595
2596 return NULL;
2597 }
2598
2599 /* Set the howto pointer for an FRV ELF reloc. */
2600
2601 static void
2602 frv_info_to_howto_rela (abfd, cache_ptr, dst)
2603 bfd *abfd ATTRIBUTE_UNUSED;
2604 arelent *cache_ptr;
2605 Elf_Internal_Rela *dst;
2606 {
2607 unsigned int r_type;
2608
2609 r_type = ELF32_R_TYPE (dst->r_info);
2610 switch (r_type)
2611 {
2612 case R_FRV_GNU_VTINHERIT:
2613 cache_ptr->howto = &elf32_frv_vtinherit_howto;
2614 break;
2615
2616 case R_FRV_GNU_VTENTRY:
2617 cache_ptr->howto = &elf32_frv_vtentry_howto;
2618 break;
2619
2620 default:
2621 cache_ptr->howto = & elf32_frv_howto_table [r_type];
2622 break;
2623 }
2624 }
2625
2626 /* Set the howto pointer for an FRV ELF REL reloc. */
2627 static void
2628 frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
2629 arelent *cache_ptr, Elf_Internal_Rela *dst)
2630 {
2631 unsigned int r_type;
2632
2633 r_type = ELF32_R_TYPE (dst->r_info);
2634 switch (r_type)
2635 {
2636 case R_FRV_32:
2637 cache_ptr->howto = &elf32_frv_rel_32_howto;
2638 break;
2639
2640 case R_FRV_FUNCDESC:
2641 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
2642 break;
2643
2644 case R_FRV_FUNCDESC_VALUE:
2645 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
2646 break;
2647
2648 case R_FRV_TLSDESC_VALUE:
2649 cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto;
2650 break;
2651
2652 case R_FRV_TLSOFF:
2653 cache_ptr->howto = &elf32_frv_rel_tlsoff_howto;
2654 break;
2655
2656 default:
2657 cache_ptr->howto = NULL;
2658 break;
2659 }
2660 }
2661
2662 /* Perform a single relocation. By default we use the standard BFD
2663 routines, but a few relocs, we have to do them ourselves. */
2664
2665 static bfd_reloc_status_type
2666 frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
2667 relocation)
2668 reloc_howto_type *howto;
2669 bfd *input_bfd;
2670 asection *input_section;
2671 bfd_byte *contents;
2672 Elf_Internal_Rela *rel;
2673 bfd_vma relocation;
2674 {
2675 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2676 contents, rel->r_offset, relocation,
2677 rel->r_addend);
2678 }
2679
2680
2681 /* Relocate an FRV ELF section.
2682
2683 The RELOCATE_SECTION function is called by the new ELF backend linker
2684 to handle the relocations for a section.
2685
2686 The relocs are always passed as Rela structures; if the section
2687 actually uses Rel structures, the r_addend field will always be
2688 zero.
2689
2690 This function is responsible for adjusting the section contents as
2691 necessary, and (if using Rela relocs and generating a relocatable
2692 output file) adjusting the reloc addend as necessary.
2693
2694 This function does not have to worry about setting the reloc
2695 address or the reloc symbol index.
2696
2697 LOCAL_SYMS is a pointer to the swapped in local symbols.
2698
2699 LOCAL_SECTIONS is an array giving the section in the input file
2700 corresponding to the st_shndx field of each local symbol.
2701
2702 The global hash table entry for the global symbols can be found
2703 via elf_sym_hashes (input_bfd).
2704
2705 When generating relocatable output, this function must handle
2706 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2707 going to be the section symbol corresponding to the output
2708 section, which means that the addend must be adjusted
2709 accordingly. */
2710
2711 static bfd_boolean
2712 elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
2713 contents, relocs, local_syms, local_sections)
2714 bfd *output_bfd ATTRIBUTE_UNUSED;
2715 struct bfd_link_info *info;
2716 bfd *input_bfd;
2717 asection *input_section;
2718 bfd_byte *contents;
2719 Elf_Internal_Rela *relocs;
2720 Elf_Internal_Sym *local_syms;
2721 asection **local_sections;
2722 {
2723 Elf_Internal_Shdr *symtab_hdr;
2724 struct elf_link_hash_entry **sym_hashes;
2725 Elf_Internal_Rela *rel;
2726 Elf_Internal_Rela *relend;
2727 unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment,
2728 check_segment[2];
2729 int silence_segment_error = !(info->shared || info->pie);
2730 unsigned long insn;
2731
2732 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2733 sym_hashes = elf_sym_hashes (input_bfd);
2734 relend = relocs + input_section->reloc_count;
2735
2736 isec_segment = _frvfdpic_osec_to_segment (output_bfd,
2737 input_section->output_section);
2738 if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
2739 got_segment = _frvfdpic_osec_to_segment (output_bfd,
2740 frvfdpic_got_section (info)
2741 ->output_section);
2742 else
2743 got_segment = -1;
2744 if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
2745 gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
2746 frvfdpic_gotfixup_section (info)
2747 ->output_section);
2748 else
2749 gprel_segment = -1;
2750 if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info))
2751 plt_segment = _frvfdpic_osec_to_segment (output_bfd,
2752 frvfdpic_plt_section (info)
2753 ->output_section);
2754 else
2755 plt_segment = -1;
2756 if (elf_hash_table (info)->tls_sec)
2757 tls_segment = _frvfdpic_osec_to_segment (output_bfd,
2758 elf_hash_table (info)->tls_sec);
2759 else
2760 tls_segment = -1;
2761
2762 for (rel = relocs; rel < relend; rel ++)
2763 {
2764 reloc_howto_type *howto;
2765 unsigned long r_symndx;
2766 Elf_Internal_Sym *sym;
2767 asection *sec;
2768 struct elf_link_hash_entry *h;
2769 bfd_vma relocation;
2770 bfd_reloc_status_type r;
2771 const char * name = NULL;
2772 int r_type;
2773 asection *osec;
2774 struct frvfdpic_relocs_info *picrel;
2775 bfd_vma orig_addend = rel->r_addend;
2776
2777 r_type = ELF32_R_TYPE (rel->r_info);
2778
2779 if ( r_type == R_FRV_GNU_VTINHERIT
2780 || r_type == R_FRV_GNU_VTENTRY)
2781 continue;
2782
2783 r_symndx = ELF32_R_SYM (rel->r_info);
2784 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
2785 h = NULL;
2786 sym = NULL;
2787 sec = NULL;
2788
2789 if (r_symndx < symtab_hdr->sh_info)
2790 {
2791 sym = local_syms + r_symndx;
2792 osec = sec = local_sections [r_symndx];
2793 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2794
2795 name = bfd_elf_string_from_elf_section
2796 (input_bfd, symtab_hdr->sh_link, sym->st_name);
2797 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
2798 }
2799 else
2800 {
2801 bfd_boolean warned;
2802 bfd_boolean unresolved_reloc;
2803
2804 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2805 r_symndx, symtab_hdr, sym_hashes,
2806 h, sec, relocation,
2807 unresolved_reloc, warned);
2808 osec = sec;
2809 }
2810
2811 if (sec != NULL && elf_discarded_section (sec))
2812 {
2813 /* For relocs against symbols from removed linkonce sections,
2814 or sections discarded by a linker script, we just want the
2815 section contents zeroed. Avoid any special processing. */
2816 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2817 rel->r_info = 0;
2818 rel->r_addend = 0;
2819 continue;
2820 }
2821
2822 if (info->relocatable)
2823 continue;
2824
2825 if (r_type != R_FRV_TLSMOFF
2826 && h != NULL
2827 && (h->root.type == bfd_link_hash_defined
2828 || h->root.type == bfd_link_hash_defweak)
2829 && !FRVFDPIC_SYM_LOCAL (info, h))
2830 {
2831 osec = sec = NULL;
2832 relocation = 0;
2833 }
2834
2835 switch (r_type)
2836 {
2837 case R_FRV_LABEL24:
2838 case R_FRV_32:
2839 if (! IS_FDPIC (output_bfd))
2840 goto non_fdpic;
2841
2842 case R_FRV_GOT12:
2843 case R_FRV_GOTHI:
2844 case R_FRV_GOTLO:
2845 case R_FRV_FUNCDESC_GOT12:
2846 case R_FRV_FUNCDESC_GOTHI:
2847 case R_FRV_FUNCDESC_GOTLO:
2848 case R_FRV_GOTOFF12:
2849 case R_FRV_GOTOFFHI:
2850 case R_FRV_GOTOFFLO:
2851 case R_FRV_FUNCDESC_GOTOFF12:
2852 case R_FRV_FUNCDESC_GOTOFFHI:
2853 case R_FRV_FUNCDESC_GOTOFFLO:
2854 case R_FRV_FUNCDESC:
2855 case R_FRV_FUNCDESC_VALUE:
2856 case R_FRV_GETTLSOFF:
2857 case R_FRV_TLSDESC_VALUE:
2858 case R_FRV_GOTTLSDESC12:
2859 case R_FRV_GOTTLSDESCHI:
2860 case R_FRV_GOTTLSDESCLO:
2861 case R_FRV_TLSMOFF12:
2862 case R_FRV_TLSMOFFHI:
2863 case R_FRV_TLSMOFFLO:
2864 case R_FRV_GOTTLSOFF12:
2865 case R_FRV_GOTTLSOFFHI:
2866 case R_FRV_GOTTLSOFFLO:
2867 case R_FRV_TLSOFF:
2868 case R_FRV_TLSDESC_RELAX:
2869 case R_FRV_GETTLSOFF_RELAX:
2870 case R_FRV_TLSOFF_RELAX:
2871 case R_FRV_TLSMOFF:
2872 if (h != NULL)
2873 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
2874 (info), input_bfd, h,
2875 orig_addend, INSERT);
2876 else
2877 /* In order to find the entry we created before, we must
2878 use the original addend, not the one that may have been
2879 modified by _bfd_elf_rela_local_sym(). */
2880 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
2881 (info), input_bfd, r_symndx,
2882 orig_addend, INSERT);
2883 if (! picrel)
2884 return FALSE;
2885
2886 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
2887 osec, sym,
2888 rel->r_addend))
2889 {
2890 (*_bfd_error_handler)
2891 (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
2892 input_bfd, input_section, rel->r_offset, name, rel->r_addend);
2893 return FALSE;
2894 }
2895
2896 break;
2897
2898 default:
2899 non_fdpic:
2900 picrel = NULL;
2901 if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
2902 {
2903 info->callbacks->warning
2904 (info, _("relocation references symbol not defined in the module"),
2905 name, input_bfd, input_section, rel->r_offset);
2906 return FALSE;
2907 }
2908 break;
2909 }
2910
2911 switch (r_type)
2912 {
2913 case R_FRV_GETTLSOFF:
2914 case R_FRV_TLSDESC_VALUE:
2915 case R_FRV_GOTTLSDESC12:
2916 case R_FRV_GOTTLSDESCHI:
2917 case R_FRV_GOTTLSDESCLO:
2918 case R_FRV_TLSMOFF12:
2919 case R_FRV_TLSMOFFHI:
2920 case R_FRV_TLSMOFFLO:
2921 case R_FRV_GOTTLSOFF12:
2922 case R_FRV_GOTTLSOFFHI:
2923 case R_FRV_GOTTLSOFFLO:
2924 case R_FRV_TLSOFF:
2925 case R_FRV_TLSDESC_RELAX:
2926 case R_FRV_GETTLSOFF_RELAX:
2927 case R_FRV_TLSOFF_RELAX:
2928 case R_FRV_TLSMOFF:
2929 if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec)))
2930 relocation += tls_biased_base (info);
2931 break;
2932
2933 default:
2934 break;
2935 }
2936
2937 /* Try to apply TLS relaxations. */
2938 if (1)
2939 switch (r_type)
2940 {
2941
2942 #define LOCAL_EXEC_P(info, picrel) \
2943 ((info)->executable \
2944 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
2945 #define INITIAL_EXEC_P(info, picrel) \
2946 (((info)->executable || (info)->flags & DF_STATIC_TLS) \
2947 && (picrel)->tlsoff_entry)
2948
2949 #define IN_RANGE_FOR_OFST12_P(value) \
2950 ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
2951 #define IN_RANGE_FOR_SETLOS_P(value) \
2952 ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
2953 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
2954 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
2955
2956 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2957 (LOCAL_EXEC_P ((info), (picrel)) \
2958 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2959 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
2960 (INITIAL_EXEC_P ((info), (picrel)) \
2961 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
2962
2963 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
2964 (LOCAL_EXEC_P ((info), (picrel)))
2965 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
2966 (INITIAL_EXEC_P ((info), (picrel)))
2967
2968 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
2969 (LOCAL_EXEC_P ((info), (picrel)) \
2970 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
2971
2972 case R_FRV_GETTLSOFF:
2973 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2974
2975 /* Is this a call instruction? */
2976 if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
2977 {
2978 r = info->callbacks->warning
2979 (info,
2980 _("R_FRV_GETTLSOFF not applied to a call instruction"),
2981 name, input_bfd, input_section, rel->r_offset);
2982 return FALSE;
2983 }
2984
2985 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel,
2986 relocation + rel->r_addend))
2987 {
2988 /* Replace the call instruction (except the packing bit)
2989 with setlos #tlsmofflo(symbol+offset), gr9. */
2990 insn &= (unsigned long)0x80000000;
2991 insn |= (unsigned long)0x12fc0000;
2992 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
2993
2994 r_type = R_FRV_TLSMOFFLO;
2995 howto = elf32_frv_howto_table + r_type;
2996 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
2997 }
2998
2999 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel))
3000 {
3001 /* Replace the call instruction (except the packing bit)
3002 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
3003 insn &= (unsigned long)0x80000000;
3004 insn |= (unsigned long)0x12c8f000;
3005 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3006
3007 r_type = R_FRV_GOTTLSOFF12;
3008 howto = elf32_frv_howto_table + r_type;
3009 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3010 }
3011
3012 break;
3013
3014 case R_FRV_GOTTLSDESC12:
3015 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3016
3017 /* Is this an lddi instruction? */
3018 if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
3019 {
3020 r = info->callbacks->warning
3021 (info,
3022 _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
3023 name, input_bfd, input_section, rel->r_offset);
3024 return FALSE;
3025 }
3026
3027 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3028 relocation + rel->r_addend)
3029 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3030 info))
3031 {
3032 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3033 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3034 Preserve the packing bit. */
3035 insn = (insn & (unsigned long)0x80000000)
3036 | ((insn + (unsigned long)0x02000000)
3037 & (unsigned long)0x7e000000);
3038 insn |= (unsigned long)0x00fc0000;
3039 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3040
3041 r_type = R_FRV_TLSMOFFLO;
3042 howto = elf32_frv_howto_table + r_type;
3043 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3044 }
3045
3046 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3047 relocation + rel->r_addend))
3048 {
3049 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3050 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3051 Preserve the packing bit. */
3052 insn = (insn & (unsigned long)0x80000000)
3053 | ((insn + (unsigned long)0x02000000)
3054 & (unsigned long)0x7e000000);
3055 insn |= (unsigned long)0x00f80000;
3056 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3057
3058 r_type = R_FRV_TLSMOFFHI;
3059 howto = elf32_frv_howto_table + r_type;
3060 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3061 }
3062
3063 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3064 {
3065 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
3066 with ldi @(grB, #gottlsoff12(symbol+offset),
3067 gr<C+1>. Preserve the packing bit. If gottlsoff12
3068 overflows, we'll error out, but that's sort-of ok,
3069 since we'd started with gottlsdesc12, that's actually
3070 more demanding. Compiling with -fPIE instead of
3071 -fpie would fix it; linking with --relax should fix
3072 it as well. */
3073 insn = (insn & (unsigned long)0x80cbf000)
3074 | ((insn + (unsigned long)0x02000000)
3075 & (unsigned long)0x7e000000);
3076 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3077
3078 r_type = R_FRV_GOTTLSOFF12;
3079 howto = elf32_frv_howto_table + r_type;
3080 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3081 }
3082
3083 break;
3084
3085 case R_FRV_GOTTLSDESCHI:
3086 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3087
3088 /* Is this a sethi instruction? */
3089 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3090 {
3091 r = info->callbacks->warning
3092 (info,
3093 _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
3094 name, input_bfd, input_section, rel->r_offset);
3095 return FALSE;
3096 }
3097
3098 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3099 relocation + rel->r_addend)
3100 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3101 && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)))
3102 {
3103 /* Replace sethi with a nop. Preserve the packing bit. */
3104 insn &= (unsigned long)0x80000000;
3105 insn |= (unsigned long)0x00880000;
3106 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3107
3108 /* Nothing to relocate. */
3109 continue;
3110 }
3111
3112 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3113 {
3114 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3115 r_type = R_FRV_GOTTLSOFFHI;
3116 howto = elf32_frv_howto_table + r_type;
3117 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3118 }
3119
3120 break;
3121
3122 case R_FRV_GOTTLSDESCLO:
3123 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3124
3125 /* Is this a setlo or setlos instruction? */
3126 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3127 {
3128 r = info->callbacks->warning
3129 (info,
3130 _("R_FRV_GOTTLSDESCLO"
3131 " not applied to a setlo or setlos instruction"),
3132 name, input_bfd, input_section, rel->r_offset);
3133 return FALSE;
3134 }
3135
3136 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3137 relocation + rel->r_addend)
3138 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3139 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3140 {
3141 /* Replace setlo/setlos with a nop. Preserve the
3142 packing bit. */
3143 insn &= (unsigned long)0x80000000;
3144 insn |= (unsigned long)0x00880000;
3145 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3146
3147 /* Nothing to relocate. */
3148 continue;
3149 }
3150
3151 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3152 {
3153 /* If the corresponding sethi (if it exists) decayed
3154 to a nop, make sure this becomes (or already is) a
3155 setlos, not setlo. */
3156 if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))
3157 {
3158 insn |= (unsigned long)0x00080000;
3159 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3160 }
3161
3162 /* Simply decay GOTTLSDESC to GOTTLSOFF. */
3163 r_type = R_FRV_GOTTLSOFFLO;
3164 howto = elf32_frv_howto_table + r_type;
3165 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3166 }
3167
3168 break;
3169
3170 case R_FRV_TLSDESC_RELAX:
3171 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3172
3173 /* Is this an ldd instruction? */
3174 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
3175 {
3176 r = info->callbacks->warning
3177 (info,
3178 _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
3179 name, input_bfd, input_section, rel->r_offset);
3180 return FALSE;
3181 }
3182
3183 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3184 relocation + rel->r_addend)
3185 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3186 info))
3187 {
3188 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3189 with setlos #tlsmofflo(symbol+offset), gr<C+1>.
3190 Preserve the packing bit. */
3191 insn = (insn & (unsigned long)0x80000000)
3192 | ((insn + (unsigned long)0x02000000)
3193 & (unsigned long)0x7e000000);
3194 insn |= (unsigned long)0x00fc0000;
3195 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3196
3197 r_type = R_FRV_TLSMOFFLO;
3198 howto = elf32_frv_howto_table + r_type;
3199 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3200 }
3201
3202 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3203 relocation + rel->r_addend))
3204 {
3205 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3206 with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
3207 Preserve the packing bit. */
3208 insn = (insn & (unsigned long)0x80000000)
3209 | ((insn + (unsigned long)0x02000000)
3210 & (unsigned long)0x7e000000);
3211 insn |= (unsigned long)0x00f80000;
3212 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3213
3214 r_type = R_FRV_TLSMOFFHI;
3215 howto = elf32_frv_howto_table + r_type;
3216 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3217 }
3218
3219 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3220 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3221 {
3222 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3223 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
3224 Preserve the packing bit. */
3225 insn = (insn & (unsigned long)0x8003f000)
3226 | (unsigned long)0x00c80000
3227 | ((insn + (unsigned long)0x02000000)
3228 & (unsigned long)0x7e000000);
3229 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3230
3231 r_type = R_FRV_GOTTLSOFF12;
3232 howto = elf32_frv_howto_table + r_type;
3233 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3234 }
3235
3236 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3237 {
3238 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
3239 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
3240 Preserve the packing bit. */
3241 insn = (insn & (unsigned long)0x81ffffbf)
3242 | ((insn + (unsigned long)0x02000000)
3243 & (unsigned long)0x7e000000);
3244 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3245
3246 /* #tlsoff(symbol+offset) is just a relaxation
3247 annotation, so there's nothing left to
3248 relocate. */
3249 continue;
3250 }
3251
3252 break;
3253
3254 case R_FRV_GETTLSOFF_RELAX:
3255 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3256
3257 /* Is this a calll or callil instruction? */
3258 if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
3259 {
3260 r = info->callbacks->warning
3261 (info,
3262 _("R_FRV_GETTLSOFF_RELAX"
3263 " not applied to a calll instruction"),
3264 name, input_bfd, input_section, rel->r_offset);
3265 return FALSE;
3266 }
3267
3268 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3269 relocation + rel->r_addend)
3270 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
3271 info))
3272 {
3273 /* Replace calll with a nop. Preserve the packing bit. */
3274 insn &= (unsigned long)0x80000000;
3275 insn |= (unsigned long)0x00880000;
3276 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3277
3278 /* Nothing to relocate. */
3279 continue;
3280 }
3281
3282 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
3283 relocation + rel->r_addend))
3284 {
3285 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
3286 Preserve the packing bit. */
3287 insn &= (unsigned long)0x80000000;
3288 insn |= (unsigned long)0x12f40000;
3289 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3290
3291 r_type = R_FRV_TLSMOFFLO;
3292 howto = elf32_frv_howto_table + r_type;
3293 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3294 }
3295
3296 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
3297 {
3298 /* Replace calll with a nop. Preserve the packing bit. */
3299 insn &= (unsigned long)0x80000000;
3300 insn |= (unsigned long)0x00880000;
3301 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3302
3303 /* Nothing to relocate. */
3304 continue;
3305 }
3306
3307 break;
3308
3309 case R_FRV_GOTTLSOFF12:
3310 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3311
3312 /* Is this an ldi instruction? */
3313 if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
3314 {
3315 r = info->callbacks->warning
3316 (info,
3317 _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
3318 name, input_bfd, input_section, rel->r_offset);
3319 return FALSE;
3320 }
3321
3322 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3323 relocation + rel->r_addend))
3324 {
3325 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
3326 with setlos #tlsmofflo(symbol+offset), grC.
3327 Preserve the packing bit. */
3328 insn &= (unsigned long)0xfe000000;
3329 insn |= (unsigned long)0x00fc0000;
3330 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3331
3332 r_type = R_FRV_TLSMOFFLO;
3333 howto = elf32_frv_howto_table + r_type;
3334 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3335 }
3336
3337 break;
3338
3339 case R_FRV_GOTTLSOFFHI:
3340 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3341
3342 /* Is this a sethi instruction? */
3343 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3344 {
3345 r = info->callbacks->warning
3346 (info,
3347 _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
3348 name, input_bfd, input_section, rel->r_offset);
3349 return FALSE;
3350 }
3351
3352 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3353 relocation + rel->r_addend)
3354 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3355 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3356 {
3357 /* Replace sethi with a nop. Preserve the packing bit. */
3358 insn &= (unsigned long)0x80000000;
3359 insn |= (unsigned long)0x00880000;
3360 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3361
3362 /* Nothing to relocate. */
3363 continue;
3364 }
3365
3366 break;
3367
3368 case R_FRV_GOTTLSOFFLO:
3369 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3370
3371 /* Is this a setlo or setlos instruction? */
3372 if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
3373 {
3374 r = info->callbacks->warning
3375 (info,
3376 _("R_FRV_GOTTLSOFFLO"
3377 " not applied to a setlo or setlos instruction"),
3378 name, input_bfd, input_section, rel->r_offset);
3379 return FALSE;
3380 }
3381
3382 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3383 relocation + rel->r_addend)
3384 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3385 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
3386 {
3387 /* Replace setlo/setlos with a nop. Preserve the
3388 packing bit. */
3389 insn &= (unsigned long)0x80000000;
3390 insn |= (unsigned long)0x00880000;
3391 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3392
3393 /* Nothing to relocate. */
3394 continue;
3395 }
3396
3397 break;
3398
3399 case R_FRV_TLSOFF_RELAX:
3400 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3401
3402 /* Is this an ld instruction? */
3403 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
3404 {
3405 r = info->callbacks->warning
3406 (info,
3407 _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
3408 name, input_bfd, input_section, rel->r_offset);
3409 return FALSE;
3410 }
3411
3412 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
3413 relocation + rel->r_addend))
3414 {
3415 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
3416 with setlos #tlsmofflo(symbol+offset), grC.
3417 Preserve the packing bit. */
3418 insn &= (unsigned long)0xfe000000;
3419 insn |= (unsigned long)0x00fc0000;
3420 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3421
3422 r_type = R_FRV_TLSMOFFLO;
3423 howto = elf32_frv_howto_table + r_type;
3424 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3425 }
3426
3427 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
3428 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
3429 {
3430 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
3431 with ldi @(grB, #gottlsoff12(symbol+offset), grC.
3432 Preserve the packing bit. */
3433 insn = (insn & (unsigned long)0xfe03f000)
3434 | (unsigned long)0x00c80000;;
3435 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
3436
3437 r_type = R_FRV_GOTTLSOFF12;
3438 howto = elf32_frv_howto_table + r_type;
3439 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
3440 }
3441
3442 break;
3443
3444 case R_FRV_TLSMOFFHI:
3445 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3446
3447 /* Is this a sethi instruction? */
3448 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
3449 {
3450 r = info->callbacks->warning
3451 (info,
3452 _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
3453 name, input_bfd, input_section, rel->r_offset);
3454 return FALSE;
3455 }
3456
3457 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation