1 /* ADI Blackfin BFD support for 32-bit ELF.
2 Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
28 #include "elf32-bfin.h"
30 /* FUNCTION : bfin_pltpc_reloc
31 ABSTRACT : TODO : figure out how to handle pltpc relocs. */
32 static bfd_reloc_status_type
34 bfd
*abfd ATTRIBUTE_UNUSED
,
35 arelent
*reloc_entry ATTRIBUTE_UNUSED
,
36 asymbol
*symbol ATTRIBUTE_UNUSED
,
37 void * data ATTRIBUTE_UNUSED
,
38 asection
*input_section ATTRIBUTE_UNUSED
,
39 bfd
*output_bfd ATTRIBUTE_UNUSED
,
40 char **error_message ATTRIBUTE_UNUSED
)
42 bfd_reloc_status_type flag
= bfd_reloc_ok
;
47 static bfd_reloc_status_type
48 bfin_pcrel24_reloc (bfd
*abfd
,
52 asection
*input_section
,
54 char **error_message ATTRIBUTE_UNUSED
)
57 bfd_size_type addr
= reloc_entry
->address
;
58 bfd_vma output_base
= 0;
59 reloc_howto_type
*howto
= reloc_entry
->howto
;
60 asection
*output_section
;
61 bool relocatable
= (output_bfd
!= NULL
);
62 bfd_size_type limit
= bfd_get_section_limit_octets (abfd
, input_section
);
64 if (addr
- 2 > limit
|| limit
- (addr
- 2) < 2)
65 return bfd_reloc_outofrange
;
67 if (bfd_is_und_section (symbol
->section
)
68 && (symbol
->flags
& BSF_WEAK
) == 0
70 return bfd_reloc_undefined
;
72 if (bfd_is_com_section (symbol
->section
))
75 relocation
= symbol
->value
;
77 output_section
= symbol
->section
->output_section
;
82 output_base
= output_section
->vma
;
84 if (!relocatable
|| !strcmp (symbol
->name
, symbol
->section
->name
))
85 relocation
+= output_base
+ symbol
->section
->output_offset
;
87 if (!relocatable
&& !strcmp (symbol
->name
, symbol
->section
->name
))
88 relocation
+= reloc_entry
->addend
;
90 relocation
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
91 relocation
-= reloc_entry
->address
;
93 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
95 bfd_reloc_status_type status
;
96 status
= bfd_check_overflow (howto
->complain_on_overflow
,
99 bfd_arch_bits_per_address(abfd
),
101 if (status
!= bfd_reloc_ok
)
105 /* if rightshift is 1 and the number odd, return error. */
106 if (howto
->rightshift
&& (relocation
& 0x01))
108 _bfd_error_handler (_("relocation should be even number"));
109 return bfd_reloc_overflow
;
112 relocation
>>= (bfd_vma
) howto
->rightshift
;
113 /* Shift everything up to where it's going to be used. */
115 relocation
<<= (bfd_vma
) howto
->bitpos
;
119 reloc_entry
->address
+= input_section
->output_offset
;
120 reloc_entry
->addend
+= symbol
->section
->output_offset
;
126 /* We are getting reloc_entry->address 2 byte off from
127 the start of instruction. Assuming absolute postion
128 of the reloc data. But, following code had been written assuming
129 reloc address is starting at begining of instruction.
130 To compensate that I have increased the value of
131 relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
134 x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ addr
- 2);
135 x
= (x
& 0xff00) | ((relocation
>> 16) & 0xff);
136 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
- 2);
138 x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ addr
);
139 x
= relocation
& 0xFFFF;
140 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
);
145 static bfd_reloc_status_type
146 bfin_imm16_reloc (bfd
*abfd
,
147 arelent
*reloc_entry
,
150 asection
*input_section
,
152 char **error_message ATTRIBUTE_UNUSED
)
154 bfd_vma relocation
, x
;
155 bfd_size_type reloc_addr
= reloc_entry
->address
;
156 bfd_vma output_base
= 0;
157 reloc_howto_type
*howto
= reloc_entry
->howto
;
158 asection
*output_section
;
159 bool relocatable
= (output_bfd
!= NULL
);
160 bfd_size_type limit
= bfd_get_section_limit_octets (abfd
, input_section
);
162 /* Is the address of the relocation really within the section? */
163 if (reloc_addr
> limit
|| limit
- reloc_addr
< 2)
164 return bfd_reloc_outofrange
;
166 if (bfd_is_und_section (symbol
->section
)
167 && (symbol
->flags
& BSF_WEAK
) == 0
169 return bfd_reloc_undefined
;
171 output_section
= symbol
->section
->output_section
;
172 relocation
= symbol
->value
;
174 /* Convert input-section-relative symbol value to absolute. */
178 output_base
= output_section
->vma
;
180 if (!relocatable
|| !strcmp (symbol
->name
, symbol
->section
->name
))
181 relocation
+= output_base
+ symbol
->section
->output_offset
;
183 /* Add in supplied addend. */
184 relocation
+= reloc_entry
->addend
;
188 reloc_entry
->address
+= input_section
->output_offset
;
189 reloc_entry
->addend
+= symbol
->section
->output_offset
;
193 reloc_entry
->addend
= 0;
196 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
198 bfd_reloc_status_type flag
;
199 flag
= bfd_check_overflow (howto
->complain_on_overflow
,
202 bfd_arch_bits_per_address(abfd
),
204 if (flag
!= bfd_reloc_ok
)
208 /* Here the variable relocation holds the final address of the
209 symbol we are relocating against, plus any addend. */
211 relocation
>>= (bfd_vma
) howto
->rightshift
;
213 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ reloc_addr
);
218 static bfd_reloc_status_type
219 bfin_byte4_reloc (bfd
*abfd
,
220 arelent
*reloc_entry
,
223 asection
*input_section
,
225 char **error_message ATTRIBUTE_UNUSED
)
227 bfd_vma relocation
, x
;
228 bfd_size_type addr
= reloc_entry
->address
;
229 bfd_vma output_base
= 0;
230 asection
*output_section
;
231 bool relocatable
= (output_bfd
!= NULL
);
232 bfd_size_type limit
= bfd_get_section_limit_octets (abfd
, input_section
);
234 /* Is the address of the relocation really within the section? */
235 if (addr
> limit
|| limit
- addr
< 4)
236 return bfd_reloc_outofrange
;
238 if (bfd_is_und_section (symbol
->section
)
239 && (symbol
->flags
& BSF_WEAK
) == 0
241 return bfd_reloc_undefined
;
243 output_section
= symbol
->section
->output_section
;
244 relocation
= symbol
->value
;
245 /* Convert input-section-relative symbol value to absolute. */
249 output_base
= output_section
->vma
;
252 && symbol
->section
->name
253 && !strcmp (symbol
->name
, symbol
->section
->name
))
256 relocation
+= output_base
+ symbol
->section
->output_offset
;
259 relocation
+= reloc_entry
->addend
;
263 /* This output will be relocatable ... like ld -r. */
264 reloc_entry
->address
+= input_section
->output_offset
;
265 reloc_entry
->addend
+= symbol
->section
->output_offset
;
269 reloc_entry
->addend
= 0;
272 /* Here the variable relocation holds the final address of the
273 symbol we are relocating against, plus any addend. */
274 x
= relocation
& 0xFFFF0000;
276 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
+ 2);
278 x
= relocation
& 0x0000FFFF;
279 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
);
283 /* bfin_bfd_reloc handles the blackfin arithmetic relocations.
284 Use this instead of bfd_perform_relocation. */
285 static bfd_reloc_status_type
286 bfin_bfd_reloc (bfd
*abfd
,
287 arelent
*reloc_entry
,
290 asection
*input_section
,
292 char **error_message ATTRIBUTE_UNUSED
)
295 bfd_size_type addr
= reloc_entry
->address
;
296 bfd_vma output_base
= 0;
297 reloc_howto_type
*howto
= reloc_entry
->howto
;
298 asection
*output_section
;
299 bool relocatable
= (output_bfd
!= NULL
);
300 bfd_size_type limit
= bfd_get_section_limit_octets (abfd
, input_section
);
302 /* Is the address of the relocation really within the section? */
303 if (addr
> limit
|| limit
- addr
< howto
->size
+ 1u)
304 return bfd_reloc_outofrange
;
306 if (bfd_is_und_section (symbol
->section
)
307 && (symbol
->flags
& BSF_WEAK
) == 0
309 return bfd_reloc_undefined
;
311 /* Get symbol value. (Common symbols are special.) */
312 if (bfd_is_com_section (symbol
->section
))
315 relocation
= symbol
->value
;
317 output_section
= symbol
->section
->output_section
;
319 /* Convert input-section-relative symbol value to absolute. */
323 output_base
= output_section
->vma
;
325 if (!relocatable
|| !strcmp (symbol
->name
, symbol
->section
->name
))
326 relocation
+= output_base
+ symbol
->section
->output_offset
;
328 if (!relocatable
&& !strcmp (symbol
->name
, symbol
->section
->name
))
330 /* Add in supplied addend. */
331 relocation
+= reloc_entry
->addend
;
334 /* Here the variable relocation holds the final address of the
335 symbol we are relocating against, plus any addend. */
337 if (howto
->pc_relative
)
339 relocation
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
341 if (howto
->pcrel_offset
)
342 relocation
-= reloc_entry
->address
;
347 reloc_entry
->address
+= input_section
->output_offset
;
348 reloc_entry
->addend
+= symbol
->section
->output_offset
;
351 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
353 bfd_reloc_status_type status
;
355 status
= bfd_check_overflow (howto
->complain_on_overflow
,
358 bfd_arch_bits_per_address(abfd
),
360 if (status
!= bfd_reloc_ok
)
364 /* If rightshift is 1 and the number odd, return error. */
365 if (howto
->rightshift
&& (relocation
& 0x01))
367 _bfd_error_handler (_("relocation should be even number"));
368 return bfd_reloc_overflow
;
371 relocation
>>= (bfd_vma
) howto
->rightshift
;
373 /* Shift everything up to where it's going to be used. */
375 relocation
<<= (bfd_vma
) howto
->bitpos
;
378 x = ( (x & ~howto->dst_mask) | (relocation & howto->dst_mask))
380 /* handle 8 and 16 bit relocations here. */
385 char x
= bfd_get_8 (abfd
, (char *) data
+ addr
);
387 bfd_put_8 (abfd
, x
, (unsigned char *) data
+ addr
);
393 unsigned short x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ addr
);
395 bfd_put_16 (abfd
, (bfd_vma
) x
, (unsigned char *) data
+ addr
);
400 return bfd_reloc_other
;
406 /* HOWTO Table for blackfin.
407 Blackfin relocations are fairly complicated.
408 Some of the salient features are
409 a. Even numbered offsets. A number of (not all) relocations are
410 even numbered. This means that the rightmost bit is not stored.
411 Needs to right shift by 1 and check to see if value is not odd
412 b. A relocation can be an expression. An expression takes on
413 a variety of relocations arranged in a stack.
414 As a result, we cannot use the standard generic function as special
415 function. We will have our own, which is very similar to the standard
416 generic function except that it understands how to get the value from
417 the relocation stack. . */
419 #define BFIN_RELOC_MIN 0
420 #define BFIN_RELOC_MAX 0x21
421 #define BFIN_GNUEXT_RELOC_MIN 0x40
422 #define BFIN_GNUEXT_RELOC_MAX 0x43
423 #define BFIN_ARELOC_MIN 0xE0
424 #define BFIN_ARELOC_MAX 0xF3
426 static reloc_howto_type bfin_howto_table
[] =
428 /* This reloc does nothing. . */
429 HOWTO (R_BFIN_UNUSED0
, /* type. */
431 3, /* size (0 = byte, 1 = short, 2 = long). */
433 false, /* pc_relative. */
435 complain_overflow_dont
, /* complain_on_overflow. */
436 bfd_elf_generic_reloc
, /* special_function. */
437 "R_BFIN_UNUSED0", /* name. */
438 false, /* partial_inplace. */
441 false), /* pcrel_offset. */
443 HOWTO (R_BFIN_PCREL5M2
, /* type. */
445 1, /* size (0 = byte, 1 = short, 2 = long).. */
447 true, /* pc_relative. */
449 complain_overflow_unsigned
, /* complain_on_overflow. */
450 bfin_bfd_reloc
, /* special_function. */
451 "R_BFIN_PCREL5M2", /* name. */
452 false, /* partial_inplace. */
454 0x0000000F, /* dst_mask. */
455 false), /* pcrel_offset. */
457 HOWTO (R_BFIN_UNUSED1
, /* type. */
459 3, /* size (0 = byte, 1 = short, 2 = long). */
461 false, /* pc_relative. */
463 complain_overflow_dont
, /* complain_on_overflow. */
464 bfd_elf_generic_reloc
, /* special_function. */
465 "R_BFIN_UNUSED1", /* name. */
466 false, /* partial_inplace. */
469 false), /* pcrel_offset. */
471 HOWTO (R_BFIN_PCREL10
, /* type. */
473 1, /* size (0 = byte, 1 = short, 2 = long). */
475 true, /* pc_relative. */
477 complain_overflow_signed
, /* complain_on_overflow. */
478 bfin_bfd_reloc
, /* special_function. */
479 "R_BFIN_PCREL10", /* name. */
480 false, /* partial_inplace. */
482 0x000003FF, /* dst_mask. */
483 true), /* pcrel_offset. */
485 HOWTO (R_BFIN_PCREL12_JUMP
, /* type. */
487 /* the offset is actually 13 bit
488 aligned on a word boundary so
489 only 12 bits have to be used.
490 Right shift the rightmost bit.. */
491 1, /* size (0 = byte, 1 = short, 2 = long). */
493 true, /* pc_relative. */
495 complain_overflow_signed
, /* complain_on_overflow. */
496 bfin_bfd_reloc
, /* special_function. */
497 "R_BFIN_PCREL12_JUMP", /* name. */
498 false, /* partial_inplace. */
500 0x0FFF, /* dst_mask. */
501 true), /* pcrel_offset. */
503 HOWTO (R_BFIN_RIMM16
, /* type. */
505 1, /* size (0 = byte, 1 = short, 2 = long). */
507 false, /* pc_relative. */
509 complain_overflow_signed
, /* complain_on_overflow. */
510 bfin_imm16_reloc
, /* special_function. */
511 "R_BFIN_RIMM16", /* name. */
512 false, /* partial_inplace. */
514 0x0000FFFF, /* dst_mask. */
515 true), /* pcrel_offset. */
517 HOWTO (R_BFIN_LUIMM16
, /* type. */
519 1, /* size (0 = byte, 1 = short, 2 = long). */
521 false, /* pc_relative. */
523 complain_overflow_dont
, /* complain_on_overflow. */
524 bfin_imm16_reloc
, /* special_function. */
525 "R_BFIN_LUIMM16", /* name. */
526 false, /* partial_inplace. */
528 0x0000FFFF, /* dst_mask. */
529 true), /* pcrel_offset. */
531 HOWTO (R_BFIN_HUIMM16
, /* type. */
532 16, /* rightshift. */
533 1, /* size (0 = byte, 1 = short, 2 = long). */
535 false, /* pc_relative. */
537 complain_overflow_unsigned
, /* complain_on_overflow. */
538 bfin_imm16_reloc
, /* special_function. */
539 "R_BFIN_HUIMM16", /* name. */
540 false, /* partial_inplace. */
542 0x0000FFFF, /* dst_mask. */
543 true), /* pcrel_offset. */
545 HOWTO (R_BFIN_PCREL12_JUMP_S
, /* type. */
547 1, /* size (0 = byte, 1 = short, 2 = long). */
549 true, /* pc_relative. */
551 complain_overflow_signed
, /* complain_on_overflow. */
552 bfin_bfd_reloc
, /* special_function. */
553 "R_BFIN_PCREL12_JUMP_S", /* name. */
554 false, /* partial_inplace. */
556 0x00000FFF, /* dst_mask. */
557 true), /* pcrel_offset. */
559 HOWTO (R_BFIN_PCREL24_JUMP_X
, /* type. */
561 2, /* size (0 = byte, 1 = short, 2 = long). */
563 true, /* pc_relative. */
565 complain_overflow_signed
, /* complain_on_overflow. */
566 bfin_pcrel24_reloc
, /* special_function. */
567 "R_BFIN_PCREL24_JUMP_X", /* name. */
568 false, /* partial_inplace. */
570 0x00FFFFFF, /* dst_mask. */
571 true), /* pcrel_offset. */
573 HOWTO (R_BFIN_PCREL24
, /* type. */
575 2, /* size (0 = byte, 1 = short, 2 = long). */
577 true, /* pc_relative. */
579 complain_overflow_signed
, /* complain_on_overflow. */
580 bfin_pcrel24_reloc
, /* special_function. */
581 "R_BFIN_PCREL24", /* name. */
582 false, /* partial_inplace. */
584 0x00FFFFFF, /* dst_mask. */
585 true), /* pcrel_offset. */
587 HOWTO (R_BFIN_UNUSEDB
, /* type. */
589 3, /* size (0 = byte, 1 = short, 2 = long). */
591 false, /* pc_relative. */
593 complain_overflow_dont
, /* complain_on_overflow. */
594 bfd_elf_generic_reloc
, /* special_function. */
595 "R_BFIN_UNUSEDB", /* name. */
596 false, /* partial_inplace. */
599 false), /* pcrel_offset. */
601 HOWTO (R_BFIN_UNUSEDC
, /* type. */
603 3, /* size (0 = byte, 1 = short, 2 = long). */
605 false, /* pc_relative. */
607 complain_overflow_dont
, /* complain_on_overflow. */
608 bfd_elf_generic_reloc
, /* special_function. */
609 "R_BFIN_UNUSEDC", /* name. */
610 false, /* partial_inplace. */
613 false), /* pcrel_offset. */
615 HOWTO (R_BFIN_PCREL24_JUMP_L
, /* type. */
617 2, /* size (0 = byte, 1 = short, 2 = long). */
619 true, /* pc_relative. */
621 complain_overflow_signed
, /* complain_on_overflow. */
622 bfin_pcrel24_reloc
, /* special_function. */
623 "R_BFIN_PCREL24_JUMP_L", /* name. */
624 false, /* partial_inplace. */
626 0x00FFFFFF, /* dst_mask. */
627 true), /* pcrel_offset. */
629 HOWTO (R_BFIN_PCREL24_CALL_X
, /* type. */
631 2, /* size (0 = byte, 1 = short, 2 = long). */
633 true, /* pc_relative. */
635 complain_overflow_signed
, /* complain_on_overflow. */
636 bfin_pcrel24_reloc
, /* special_function. */
637 "R_BFIN_PCREL24_CALL_X", /* name. */
638 false, /* partial_inplace. */
640 0x00FFFFFF, /* dst_mask. */
641 true), /* pcrel_offset. */
643 HOWTO (R_BFIN_VAR_EQ_SYMB
, /* type. */
645 2, /* size (0 = byte, 1 = short, 2 = long). */
647 false, /* pc_relative. */
649 complain_overflow_bitfield
, /* complain_on_overflow. */
650 bfin_bfd_reloc
, /* special_function. */
651 "R_BFIN_VAR_EQ_SYMB", /* name. */
652 false, /* partial_inplace. */
655 false), /* pcrel_offset. */
657 HOWTO (R_BFIN_BYTE_DATA
, /* type. */
659 0, /* size (0 = byte, 1 = short, 2 = long). */
661 false, /* pc_relative. */
663 complain_overflow_unsigned
, /* complain_on_overflow. */
664 bfin_bfd_reloc
, /* special_function. */
665 "R_BFIN_BYTE_DATA", /* name. */
666 false, /* partial_inplace. */
668 0xFF, /* dst_mask. */
669 true), /* pcrel_offset. */
671 HOWTO (R_BFIN_BYTE2_DATA
, /* type. */
673 1, /* size (0 = byte, 1 = short, 2 = long). */
675 false, /* pc_relative. */
677 complain_overflow_signed
, /* complain_on_overflow. */
678 bfin_bfd_reloc
, /* special_function. */
679 "R_BFIN_BYTE2_DATA", /* name. */
680 false, /* partial_inplace. */
682 0xFFFF, /* dst_mask. */
683 true), /* pcrel_offset. */
685 HOWTO (R_BFIN_BYTE4_DATA
, /* type. */
687 2, /* size (0 = byte, 1 = short, 2 = long). */
689 false, /* pc_relative. */
691 complain_overflow_unsigned
, /* complain_on_overflow. */
692 bfin_byte4_reloc
, /* special_function. */
693 "R_BFIN_BYTE4_DATA", /* name. */
694 false, /* partial_inplace. */
696 0xFFFFFFFF, /* dst_mask. */
697 true), /* pcrel_offset. */
699 HOWTO (R_BFIN_PCREL11
, /* type. */
701 1, /* size (0 = byte, 1 = short, 2 = long). */
703 true, /* pc_relative. */
705 complain_overflow_unsigned
, /* complain_on_overflow. */
706 bfin_bfd_reloc
, /* special_function. */
707 "R_BFIN_PCREL11", /* name. */
708 false, /* partial_inplace. */
710 0x000003FF, /* dst_mask. */
711 false), /* pcrel_offset. */
714 /* A 18-bit signed operand with the GOT offset for the address of
716 HOWTO (R_BFIN_GOT17M4
, /* type */
718 1, /* size (0 = byte, 1 = short, 2 = long) */
720 false, /* pc_relative */
722 complain_overflow_signed
, /* complain_on_overflow */
723 bfd_elf_generic_reloc
, /* special_function */
724 "R_BFIN_GOT17M4", /* name */
725 false, /* partial_inplace */
726 0xffff, /* src_mask */
727 0xffff, /* dst_mask */
728 false), /* pcrel_offset */
730 /* The upper 16 bits of the GOT offset for the address of the
732 HOWTO (R_BFIN_GOTHI
, /* type */
734 1, /* size (0 = byte, 1 = short, 2 = long) */
736 false, /* pc_relative */
738 complain_overflow_dont
, /* complain_on_overflow */
739 bfd_elf_generic_reloc
, /* special_function */
740 "R_BFIN_GOTHI", /* name */
741 false, /* partial_inplace */
742 0xffff, /* src_mask */
743 0xffff, /* dst_mask */
744 false), /* pcrel_offset */
746 /* The lower 16 bits of the GOT offset for the address of the
748 HOWTO (R_BFIN_GOTLO
, /* type */
750 1, /* size (0 = byte, 1 = short, 2 = long) */
752 false, /* pc_relative */
754 complain_overflow_dont
, /* complain_on_overflow */
755 bfd_elf_generic_reloc
, /* special_function */
756 "R_BFIN_GOTLO", /* name */
757 false, /* partial_inplace */
758 0xffff, /* src_mask */
759 0xffff, /* dst_mask */
760 false), /* pcrel_offset */
762 /* The 32-bit address of the canonical descriptor of a function. */
763 HOWTO (R_BFIN_FUNCDESC
, /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 false, /* pc_relative */
769 complain_overflow_bitfield
, /* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 "R_BFIN_FUNCDESC", /* name */
772 false, /* partial_inplace */
773 0xffffffff, /* src_mask */
774 0xffffffff, /* dst_mask */
775 false), /* pcrel_offset */
777 /* A 12-bit signed operand with the GOT offset for the address of
778 canonical descriptor of a function. */
779 HOWTO (R_BFIN_FUNCDESC_GOT17M4
, /* type */
781 1, /* size (0 = byte, 1 = short, 2 = long) */
783 false, /* pc_relative */
785 complain_overflow_signed
, /* complain_on_overflow */
786 bfd_elf_generic_reloc
, /* special_function */
787 "R_BFIN_FUNCDESC_GOT17M4", /* name */
788 false, /* partial_inplace */
789 0xffff, /* src_mask */
790 0xffff, /* dst_mask */
791 false), /* pcrel_offset */
793 /* The upper 16 bits of the GOT offset for the address of the
794 canonical descriptor of a function. */
795 HOWTO (R_BFIN_FUNCDESC_GOTHI
, /* type */
797 1, /* size (0 = byte, 1 = short, 2 = long) */
799 false, /* pc_relative */
801 complain_overflow_dont
, /* complain_on_overflow */
802 bfd_elf_generic_reloc
, /* special_function */
803 "R_BFIN_FUNCDESC_GOTHI", /* name */
804 false, /* partial_inplace */
805 0xffff, /* src_mask */
806 0xffff, /* dst_mask */
807 false), /* pcrel_offset */
809 /* The lower 16 bits of the GOT offset for the address of the
810 canonical descriptor of a function. */
811 HOWTO (R_BFIN_FUNCDESC_GOTLO
, /* type */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
815 false, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 bfd_elf_generic_reloc
, /* special_function */
819 "R_BFIN_FUNCDESC_GOTLO", /* name */
820 false, /* partial_inplace */
821 0xffff, /* src_mask */
822 0xffff, /* dst_mask */
823 false), /* pcrel_offset */
825 /* The 32-bit address of the canonical descriptor of a function. */
826 HOWTO (R_BFIN_FUNCDESC_VALUE
, /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 false, /* pc_relative */
832 complain_overflow_bitfield
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_BFIN_FUNCDESC_VALUE", /* name */
835 false, /* partial_inplace */
836 0xffffffff, /* src_mask */
837 0xffffffff, /* dst_mask */
838 false), /* pcrel_offset */
840 /* A 12-bit signed operand with the GOT offset for the address of
841 canonical descriptor of a function. */
842 HOWTO (R_BFIN_FUNCDESC_GOTOFF17M4
, /* type */
844 1, /* size (0 = byte, 1 = short, 2 = long) */
846 false, /* pc_relative */
848 complain_overflow_signed
, /* complain_on_overflow */
849 bfd_elf_generic_reloc
, /* special_function */
850 "R_BFIN_FUNCDESC_GOTOFF17M4", /* name */
851 false, /* partial_inplace */
852 0xffff, /* src_mask */
853 0xffff, /* dst_mask */
854 false), /* pcrel_offset */
856 /* The upper 16 bits of the GOT offset for the address of the
857 canonical descriptor of a function. */
858 HOWTO (R_BFIN_FUNCDESC_GOTOFFHI
, /* type */
860 1, /* size (0 = byte, 1 = short, 2 = long) */
862 false, /* pc_relative */
864 complain_overflow_dont
, /* complain_on_overflow */
865 bfd_elf_generic_reloc
, /* special_function */
866 "R_BFIN_FUNCDESC_GOTOFFHI", /* name */
867 false, /* partial_inplace */
868 0xffff, /* src_mask */
869 0xffff, /* dst_mask */
870 false), /* pcrel_offset */
872 /* The lower 16 bits of the GOT offset for the address of the
873 canonical descriptor of a function. */
874 HOWTO (R_BFIN_FUNCDESC_GOTOFFLO
, /* type */
876 1, /* size (0 = byte, 1 = short, 2 = long) */
878 false, /* pc_relative */
880 complain_overflow_dont
, /* complain_on_overflow */
881 bfd_elf_generic_reloc
, /* special_function */
882 "R_BFIN_FUNCDESC_GOTOFFLO", /* name */
883 false, /* partial_inplace */
884 0xffff, /* src_mask */
885 0xffff, /* dst_mask */
886 false), /* pcrel_offset */
888 /* A 12-bit signed operand with the GOT offset for the address of
890 HOWTO (R_BFIN_GOTOFF17M4
, /* type */
892 1, /* size (0 = byte, 1 = short, 2 = long) */
894 false, /* pc_relative */
896 complain_overflow_signed
, /* complain_on_overflow */
897 bfd_elf_generic_reloc
, /* special_function */
898 "R_BFIN_GOTOFF17M4", /* name */
899 false, /* partial_inplace */
900 0xffff, /* src_mask */
901 0xffff, /* dst_mask */
902 false), /* pcrel_offset */
904 /* The upper 16 bits of the GOT offset for the address of the
906 HOWTO (R_BFIN_GOTOFFHI
, /* type */
908 1, /* size (0 = byte, 1 = short, 2 = long) */
910 false, /* pc_relative */
912 complain_overflow_dont
, /* complain_on_overflow */
913 bfd_elf_generic_reloc
, /* special_function */
914 "R_BFIN_GOTOFFHI", /* name */
915 false, /* partial_inplace */
916 0xffff, /* src_mask */
917 0xffff, /* dst_mask */
918 false), /* pcrel_offset */
920 /* The lower 16 bits of the GOT offset for the address of the
922 HOWTO (R_BFIN_GOTOFFLO
, /* type */
924 1, /* size (0 = byte, 1 = short, 2 = long) */
926 false, /* pc_relative */
928 complain_overflow_dont
, /* complain_on_overflow */
929 bfd_elf_generic_reloc
, /* special_function */
930 "R_BFIN_GOTOFFLO", /* name */
931 false, /* partial_inplace */
932 0xffff, /* src_mask */
933 0xffff, /* dst_mask */
934 false), /* pcrel_offset */
937 static reloc_howto_type bfin_gnuext_howto_table
[] =
939 HOWTO (R_BFIN_PLTPC
, /* type. */
941 1, /* size (0 = byte, 1 = short, 2 = long). */
943 false, /* pc_relative. */
945 complain_overflow_bitfield
, /* complain_on_overflow. */
946 bfin_pltpc_reloc
, /* special_function. */
947 "R_BFIN_PLTPC", /* name. */
948 false, /* partial_inplace. */
949 0xffff, /* src_mask. */
950 0xffff, /* dst_mask. */
951 false), /* pcrel_offset. */
953 HOWTO (R_BFIN_GOT
, /* type. */
955 1, /* size (0 = byte, 1 = short, 2 = long). */
957 false, /* pc_relative. */
959 complain_overflow_bitfield
, /* complain_on_overflow. */
960 bfd_elf_generic_reloc
, /* special_function. */
961 "R_BFIN_GOT", /* name. */
962 false, /* partial_inplace. */
963 0x7fff, /* src_mask. */
964 0x7fff, /* dst_mask. */
965 false), /* pcrel_offset. */
967 /* GNU extension to record C++ vtable hierarchy. */
968 HOWTO (R_BFIN_GNU_VTINHERIT
, /* type. */
970 2, /* size (0 = byte, 1 = short, 2 = long). */
972 false, /* pc_relative. */
974 complain_overflow_dont
, /* complain_on_overflow. */
975 NULL
, /* special_function. */
976 "R_BFIN_GNU_VTINHERIT", /* name. */
977 false, /* partial_inplace. */
980 false), /* pcrel_offset. */
982 /* GNU extension to record C++ vtable member usage. */
983 HOWTO (R_BFIN_GNU_VTENTRY
, /* type. */
985 2, /* size (0 = byte, 1 = short, 2 = long). */
987 false, /* pc_relative. */
989 complain_overflow_dont
, /* complain_on_overflow. */
990 _bfd_elf_rel_vtable_reloc_fn
, /* special_function. */
991 "R_BFIN_GNU_VTENTRY", /* name. */
992 false, /* partial_inplace. */
995 false) /* pcrel_offset. */
998 struct bfin_reloc_map
1000 bfd_reloc_code_real_type bfd_reloc_val
;
1001 unsigned int bfin_reloc_val
;
1004 static const struct bfin_reloc_map bfin_reloc_map
[] =
1006 { BFD_RELOC_NONE
, R_BFIN_UNUSED0
},
1007 { BFD_RELOC_BFIN_5_PCREL
, R_BFIN_PCREL5M2
},
1008 { BFD_RELOC_NONE
, R_BFIN_UNUSED1
},
1009 { BFD_RELOC_BFIN_10_PCREL
, R_BFIN_PCREL10
},
1010 { BFD_RELOC_BFIN_12_PCREL_JUMP
, R_BFIN_PCREL12_JUMP
},
1011 { BFD_RELOC_BFIN_16_IMM
, R_BFIN_RIMM16
},
1012 { BFD_RELOC_BFIN_16_LOW
, R_BFIN_LUIMM16
},
1013 { BFD_RELOC_BFIN_16_HIGH
, R_BFIN_HUIMM16
},
1014 { BFD_RELOC_BFIN_12_PCREL_JUMP_S
, R_BFIN_PCREL12_JUMP_S
},
1015 { BFD_RELOC_24_PCREL
, R_BFIN_PCREL24
},
1016 { BFD_RELOC_24_PCREL
, R_BFIN_PCREL24
},
1017 { BFD_RELOC_BFIN_24_PCREL_JUMP_L
, R_BFIN_PCREL24_JUMP_L
},
1018 { BFD_RELOC_NONE
, R_BFIN_UNUSEDB
},
1019 { BFD_RELOC_NONE
, R_BFIN_UNUSEDC
},
1020 { BFD_RELOC_BFIN_24_PCREL_CALL_X
, R_BFIN_PCREL24_CALL_X
},
1021 { BFD_RELOC_8
, R_BFIN_BYTE_DATA
},
1022 { BFD_RELOC_16
, R_BFIN_BYTE2_DATA
},
1023 { BFD_RELOC_32
, R_BFIN_BYTE4_DATA
},
1024 { BFD_RELOC_BFIN_11_PCREL
, R_BFIN_PCREL11
},
1025 { BFD_RELOC_BFIN_GOT
, R_BFIN_GOT
},
1026 { BFD_RELOC_BFIN_PLTPC
, R_BFIN_PLTPC
},
1028 { BFD_RELOC_BFIN_GOT17M4
, R_BFIN_GOT17M4
},
1029 { BFD_RELOC_BFIN_GOTHI
, R_BFIN_GOTHI
},
1030 { BFD_RELOC_BFIN_GOTLO
, R_BFIN_GOTLO
},
1031 { BFD_RELOC_BFIN_FUNCDESC
, R_BFIN_FUNCDESC
},
1032 { BFD_RELOC_BFIN_FUNCDESC_GOT17M4
, R_BFIN_FUNCDESC_GOT17M4
},
1033 { BFD_RELOC_BFIN_FUNCDESC_GOTHI
, R_BFIN_FUNCDESC_GOTHI
},
1034 { BFD_RELOC_BFIN_FUNCDESC_GOTLO
, R_BFIN_FUNCDESC_GOTLO
},
1035 { BFD_RELOC_BFIN_FUNCDESC_VALUE
, R_BFIN_FUNCDESC_VALUE
},
1036 { BFD_RELOC_BFIN_FUNCDESC_GOTOFF17M4
, R_BFIN_FUNCDESC_GOTOFF17M4
},
1037 { BFD_RELOC_BFIN_FUNCDESC_GOTOFFHI
, R_BFIN_FUNCDESC_GOTOFFHI
},
1038 { BFD_RELOC_BFIN_FUNCDESC_GOTOFFLO
, R_BFIN_FUNCDESC_GOTOFFLO
},
1039 { BFD_RELOC_BFIN_GOTOFF17M4
, R_BFIN_GOTOFF17M4
},
1040 { BFD_RELOC_BFIN_GOTOFFHI
, R_BFIN_GOTOFFHI
},
1041 { BFD_RELOC_BFIN_GOTOFFLO
, R_BFIN_GOTOFFLO
},
1043 { BFD_RELOC_VTABLE_INHERIT
, R_BFIN_GNU_VTINHERIT
},
1044 { BFD_RELOC_VTABLE_ENTRY
, R_BFIN_GNU_VTENTRY
},
1049 bfin_info_to_howto (bfd
*abfd
,
1051 Elf_Internal_Rela
*dst
)
1053 unsigned int r_type
;
1055 r_type
= ELF32_R_TYPE (dst
->r_info
);
1057 if (r_type
<= BFIN_RELOC_MAX
)
1058 cache_ptr
->howto
= &bfin_howto_table
[r_type
];
1060 else if (r_type
>= BFIN_GNUEXT_RELOC_MIN
&& r_type
<= BFIN_GNUEXT_RELOC_MAX
)
1061 cache_ptr
->howto
= &bfin_gnuext_howto_table
[r_type
- BFIN_GNUEXT_RELOC_MIN
];
1065 /* xgettext:c-format */
1066 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1068 bfd_set_error (bfd_error_bad_value
);
1075 /* Given a BFD reloc type, return the howto. */
1076 static reloc_howto_type
*
1077 bfin_bfd_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
1078 bfd_reloc_code_real_type code
)
1081 unsigned int r_type
= (unsigned int) -1;
1083 for (i
= sizeof (bfin_reloc_map
) / sizeof (bfin_reloc_map
[0]); i
--;)
1084 if (bfin_reloc_map
[i
].bfd_reloc_val
== code
)
1085 r_type
= bfin_reloc_map
[i
].bfin_reloc_val
;
1087 if (r_type
<= BFIN_RELOC_MAX
)
1088 return &bfin_howto_table
[r_type
];
1090 else if (r_type
>= BFIN_GNUEXT_RELOC_MIN
&& r_type
<= BFIN_GNUEXT_RELOC_MAX
)
1091 return &bfin_gnuext_howto_table
[r_type
- BFIN_GNUEXT_RELOC_MIN
];
1093 return (reloc_howto_type
*) NULL
;
1096 static reloc_howto_type
*
1097 bfin_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1103 i
< (sizeof (bfin_howto_table
)
1104 / sizeof (bfin_howto_table
[0]));
1106 if (bfin_howto_table
[i
].name
!= NULL
1107 && strcasecmp (bfin_howto_table
[i
].name
, r_name
) == 0)
1108 return &bfin_howto_table
[i
];
1111 i
< (sizeof (bfin_gnuext_howto_table
)
1112 / sizeof (bfin_gnuext_howto_table
[0]));
1114 if (bfin_gnuext_howto_table
[i
].name
!= NULL
1115 && strcasecmp (bfin_gnuext_howto_table
[i
].name
, r_name
) == 0)
1116 return &bfin_gnuext_howto_table
[i
];
1121 /* Given a bfin relocation type, return the howto. */
1122 static reloc_howto_type
*
1123 bfin_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
1124 unsigned int r_type
)
1126 if (r_type
<= BFIN_RELOC_MAX
)
1127 return &bfin_howto_table
[r_type
];
1129 else if (r_type
>= BFIN_GNUEXT_RELOC_MIN
&& r_type
<= BFIN_GNUEXT_RELOC_MAX
)
1130 return &bfin_gnuext_howto_table
[r_type
- BFIN_GNUEXT_RELOC_MIN
];
1132 return (reloc_howto_type
*) NULL
;
1135 /* Set by ld emulation if --code-in-l1. */
1136 bool elf32_bfin_code_in_l1
= 0;
1138 /* Set by ld emulation if --data-in-l1. */
1139 bool elf32_bfin_data_in_l1
= 0;
1142 elf32_bfin_final_write_processing (bfd
*abfd
)
1144 if (elf32_bfin_code_in_l1
)
1145 elf_elfheader (abfd
)->e_flags
|= EF_BFIN_CODE_IN_L1
;
1146 if (elf32_bfin_data_in_l1
)
1147 elf_elfheader (abfd
)->e_flags
|= EF_BFIN_DATA_IN_L1
;
1148 return _bfd_elf_final_write_processing (abfd
);
1151 /* Return TRUE if the name is a local label.
1152 bfin local labels begin with L$. */
1154 bfin_is_local_label_name (bfd
*abfd
, const char *label
)
1156 if (label
[0] == 'L' && label
[1] == '$' )
1159 return _bfd_elf_is_local_label_name (abfd
, label
);
1162 /* Look through the relocs for a section during the first phase, and
1163 allocate space in the global offset table or procedure linkage
1167 bfin_check_relocs (bfd
* abfd
,
1168 struct bfd_link_info
*info
,
1170 const Elf_Internal_Rela
*relocs
)
1173 Elf_Internal_Shdr
*symtab_hdr
;
1174 struct elf_link_hash_entry
**sym_hashes
;
1175 bfd_signed_vma
*local_got_refcounts
;
1176 const Elf_Internal_Rela
*rel
;
1177 const Elf_Internal_Rela
*rel_end
;
1181 if (bfd_link_relocatable (info
))
1184 dynobj
= elf_hash_table (info
)->dynobj
;
1185 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1186 sym_hashes
= elf_sym_hashes (abfd
);
1187 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1192 rel_end
= relocs
+ sec
->reloc_count
;
1193 for (rel
= relocs
; rel
< rel_end
; rel
++)
1195 unsigned long r_symndx
;
1196 struct elf_link_hash_entry
*h
;
1198 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1199 if (r_symndx
< symtab_hdr
->sh_info
)
1203 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1204 while (h
->root
.type
== bfd_link_hash_indirect
1205 || h
->root
.type
== bfd_link_hash_warning
)
1206 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
1209 switch (ELF32_R_TYPE (rel
->r_info
))
1211 /* This relocation describes the C++ object vtable hierarchy.
1212 Reconstruct it for later use during GC. */
1213 case R_BFIN_GNU_VTINHERIT
:
1214 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1218 /* This relocation describes which C++ vtable entries
1219 are actually used. Record for later use during GC. */
1220 case R_BFIN_GNU_VTENTRY
:
1221 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1227 && strcmp (h
->root
.root
.string
, "__GLOBAL_OFFSET_TABLE_") == 0)
1233 /* Create the .got section. */
1234 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
1235 if (!_bfd_elf_create_got_section (dynobj
, info
))
1239 sgot
= elf_hash_table (info
)->sgot
;
1240 srelgot
= elf_hash_table (info
)->srelgot
;
1241 BFD_ASSERT (sgot
!= NULL
);
1245 if (h
->got
.refcount
== 0)
1247 /* Make sure this symbol is output as a dynamic symbol. */
1248 if (h
->dynindx
== -1 && !h
->forced_local
)
1250 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
1254 /* Allocate space in the .got section. */
1256 /* Allocate relocation space. */
1257 srelgot
->size
+= sizeof (Elf32_External_Rela
);
1263 /* This is a global offset table entry for a local symbol. */
1264 if (local_got_refcounts
== NULL
)
1268 size
= symtab_hdr
->sh_info
;
1269 size
*= sizeof (bfd_signed_vma
);
1270 local_got_refcounts
= ((bfd_signed_vma
*)
1271 bfd_zalloc (abfd
, size
));
1272 if (local_got_refcounts
== NULL
)
1274 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1276 if (local_got_refcounts
[r_symndx
] == 0)
1279 if (bfd_link_pic (info
))
1281 /* If we are generating a shared object, we need to
1282 output a R_68K_RELATIVE reloc so that the dynamic
1283 linker can adjust this GOT entry. */
1284 srelgot
->size
+= sizeof (Elf32_External_Rela
);
1287 local_got_refcounts
[r_symndx
]++;
1299 static enum elf_reloc_type_class
1300 elf32_bfin_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1301 const asection
*rel_sec ATTRIBUTE_UNUSED
,
1302 const Elf_Internal_Rela
* rela
)
1304 switch ((int) ELF32_R_TYPE (rela
->r_info
))
1307 return reloc_class_normal
;
1311 static bfd_reloc_status_type
1312 bfin_final_link_relocate (Elf_Internal_Rela
*rel
, reloc_howto_type
*howto
,
1313 bfd
*input_bfd
, asection
*input_section
,
1314 bfd_byte
*contents
, bfd_vma address
,
1315 bfd_vma value
, bfd_vma addend
)
1317 int r_type
= ELF32_R_TYPE (rel
->r_info
);
1319 if (r_type
== R_BFIN_PCREL24
|| r_type
== R_BFIN_PCREL24_JUMP_L
)
1321 bfd_reloc_status_type r
= bfd_reloc_ok
;
1323 bfd_size_type limit
= bfd_get_section_limit_octets (input_bfd
,
1326 if (address
- 2 > limit
|| limit
- (address
- 2) < 4)
1327 return bfd_reloc_outofrange
;
1331 /* Perform usual pc-relative correction. */
1332 value
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
1335 /* We are getting reloc_entry->address 2 byte off from
1336 the start of instruction. Assuming absolute postion
1337 of the reloc data. But, following code had been written assuming
1338 reloc address is starting at begining of instruction.
1339 To compensate that I have increased the value of
1340 relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
1345 if ((value
& 0xFF000000) != 0
1346 && (value
& 0xFF000000) != 0xFF000000)
1347 r
= bfd_reloc_overflow
;
1351 x
= bfd_get_16 (input_bfd
, contents
+ address
);
1352 x
= (x
& 0xff00) | ((value
>> 16) & 0xff);
1353 bfd_put_16 (input_bfd
, x
, contents
+ address
);
1355 x
= bfd_get_16 (input_bfd
, contents
+ address
+ 2);
1357 bfd_put_16 (input_bfd
, x
, contents
+ address
+ 2);
1361 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
1362 rel
->r_offset
, value
, addend
);
1367 bfin_relocate_section (bfd
* output_bfd
,
1368 struct bfd_link_info
*info
,
1370 asection
* input_section
,
1371 bfd_byte
* contents
,
1372 Elf_Internal_Rela
* relocs
,
1373 Elf_Internal_Sym
* local_syms
,
1374 asection
** local_sections
)
1377 Elf_Internal_Shdr
*symtab_hdr
;
1378 struct elf_link_hash_entry
**sym_hashes
;
1379 bfd_vma
*local_got_offsets
;
1381 Elf_Internal_Rela
*rel
;
1382 Elf_Internal_Rela
*relend
;
1385 dynobj
= elf_hash_table (info
)->dynobj
;
1386 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1387 sym_hashes
= elf_sym_hashes (input_bfd
);
1388 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1393 relend
= relocs
+ input_section
->reloc_count
;
1394 for (; rel
< relend
; rel
++, i
++)
1397 reloc_howto_type
*howto
;
1398 unsigned long r_symndx
;
1399 struct elf_link_hash_entry
*h
;
1400 Elf_Internal_Sym
*sym
;
1402 bfd_vma relocation
= 0;
1403 bool unresolved_reloc
;
1404 bfd_reloc_status_type r
;
1407 r_type
= ELF32_R_TYPE (rel
->r_info
);
1408 if (r_type
< 0 || r_type
>= 243)
1410 bfd_set_error (bfd_error_bad_value
);
1414 if (r_type
== R_BFIN_GNU_VTENTRY
1415 || r_type
== R_BFIN_GNU_VTINHERIT
)
1418 howto
= bfin_reloc_type_lookup (input_bfd
, r_type
);
1421 bfd_set_error (bfd_error_bad_value
);
1424 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1429 unresolved_reloc
= false;
1431 if (r_symndx
< symtab_hdr
->sh_info
)
1433 sym
= local_syms
+ r_symndx
;
1434 sec
= local_sections
[r_symndx
];
1435 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1439 bool warned
, ignored
;
1441 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1442 r_symndx
, symtab_hdr
, sym_hashes
,
1444 unresolved_reloc
, warned
, ignored
);
1447 if (sec
!= NULL
&& discarded_section (sec
))
1448 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
1449 rel
, 1, relend
, howto
, 0, contents
);
1451 if (bfd_link_relocatable (info
))
1454 address
= rel
->r_offset
;
1456 /* Then, process normally. */
1459 case R_BFIN_GNU_VTINHERIT
:
1460 case R_BFIN_GNU_VTENTRY
:
1461 return bfd_reloc_ok
;
1464 /* Relocation is to the address of the entry for this symbol
1465 in the global offset table. */
1467 && strcmp (h
->root
.root
.string
, "__GLOBAL_OFFSET_TABLE_") == 0)
1470 /* Relocation is the offset of the entry for this symbol in
1471 the global offset table. */
1478 /* Create the .got section. */
1479 elf_hash_table (info
)->dynobj
= dynobj
= output_bfd
;
1480 if (!_bfd_elf_create_got_section (dynobj
, info
))
1484 sgot
= elf_hash_table (info
)->sgot
;
1485 BFD_ASSERT (sgot
!= NULL
);
1491 off
= h
->got
.offset
;
1492 BFD_ASSERT (off
!= (bfd_vma
) - 1);
1493 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
1495 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
1496 bfd_link_pic (info
),
1498 || (bfd_link_pic (info
)
1504 /* This is actually a static link, or it is a
1505 -Bsymbolic link and the symbol is defined
1506 locally, or the symbol was forced to be local
1507 because of a version file.. We must initialize
1508 this entry in the global offset table. Since
1509 the offset must always be a multiple of 4, we
1510 use the least significant bit to record whether
1511 we have initialized it already.
1513 When doing a dynamic link, we create a .rela.got
1514 relocation entry to initialize the value. This
1515 is done in the finish_dynamic_symbol routine. */
1520 bfd_put_32 (output_bfd
, relocation
,
1521 sgot
->contents
+ off
);
1526 unresolved_reloc
= false;
1530 BFD_ASSERT (local_got_offsets
!= NULL
);
1531 off
= local_got_offsets
[r_symndx
];
1532 BFD_ASSERT (off
!= (bfd_vma
) - 1);
1534 /* The offset must always be a multiple of 4. We use
1535 the least significant bit to record whether we have
1536 already generated the necessary reloc. */
1541 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1543 if (bfd_link_pic (info
))
1546 Elf_Internal_Rela outrel
;
1549 s
= elf_hash_table (info
)->srelgot
;
1550 BFD_ASSERT (s
!= NULL
);
1552 outrel
.r_offset
= (sgot
->output_section
->vma
1553 + sgot
->output_offset
+ off
);
1555 ELF32_R_INFO (0, R_BFIN_PCREL24
);
1556 outrel
.r_addend
= relocation
;
1559 s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1560 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1563 local_got_offsets
[r_symndx
] |= 1;
1567 relocation
= sgot
->output_offset
+ off
;
1569 /* bfin : preg = [preg + 17bitdiv4offset] relocation is div by 4. */
1576 r
= bfin_final_link_relocate (rel
, howto
, input_bfd
, input_section
,
1578 relocation
, rel
->r_addend
);
1583 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
1584 because such sections are not SEC_ALLOC and thus ld.so will
1585 not process them. */
1586 if (unresolved_reloc
1587 && !((input_section
->flags
& SEC_DEBUGGING
) != 0 && h
->def_dynamic
)
1588 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1589 rel
->r_offset
) != (bfd_vma
) -1)
1592 /* xgettext:c-format */
1593 (_("%pB(%pA+%#" PRIx64
"): "
1594 "unresolvable relocation against symbol `%s'"),
1595 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
1596 h
->root
.root
.string
);
1600 if (r
!= bfd_reloc_ok
)
1605 name
= h
->root
.root
.string
;
1608 name
= bfd_elf_string_from_elf_section (input_bfd
,
1609 symtab_hdr
->sh_link
,
1614 name
= bfd_section_name (sec
);
1617 if (r
== bfd_reloc_overflow
)
1618 (*info
->callbacks
->reloc_overflow
)
1619 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
1620 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
1624 /* xgettext:c-format */
1625 (_("%pB(%pA+%#" PRIx64
"): reloc against `%s': error %d"),
1626 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
1637 bfin_gc_mark_hook (asection
* sec
,
1638 struct bfd_link_info
*info
,
1639 Elf_Internal_Rela
* rel
,
1640 struct elf_link_hash_entry
*h
,
1641 Elf_Internal_Sym
* sym
)
1644 switch (ELF32_R_TYPE (rel
->r_info
))
1646 case R_BFIN_GNU_VTINHERIT
:
1647 case R_BFIN_GNU_VTENTRY
:
1651 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1654 extern const bfd_target bfin_elf32_fdpic_vec
;
1655 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfin_elf32_fdpic_vec)
1657 /* An extension of the elf hash table data structure,
1658 containing some additional Blackfin-specific data. */
1659 struct bfinfdpic_elf_link_hash_table
1661 struct elf_link_hash_table elf
;
1663 /* A pointer to the .rofixup section. */
1664 asection
*sgotfixup
;
1665 /* GOT base offset. */
1667 /* Location of the first non-lazy PLT entry, i.e., the number of
1668 bytes taken by lazy PLT entries. */
1670 /* A hash table holding information about which symbols were
1671 referenced with which PIC-related relocations. */
1672 struct htab
*relocs_info
;
1673 /* Summary reloc information collected by
1674 _bfinfdpic_count_got_plt_entries. */
1675 struct _bfinfdpic_dynamic_got_info
*g
;
1678 /* Get the Blackfin ELF linker hash table from a link_info structure. */
1680 #define bfinfdpic_hash_table(p) \
1681 ((is_elf_hash_table ((p)->hash) \
1682 && elf_hash_table_id (elf_hash_table (p)) == BFIN_ELF_DATA) \
1683 ? (struct bfinfdpic_elf_link_hash_table *) (p)->hash : NULL)
1685 #define bfinfdpic_got_section(info) \
1686 (bfinfdpic_hash_table (info)->elf.sgot)
1687 #define bfinfdpic_gotrel_section(info) \
1688 (bfinfdpic_hash_table (info)->elf.srelgot)
1689 #define bfinfdpic_gotfixup_section(info) \
1690 (bfinfdpic_hash_table (info)->sgotfixup)
1691 #define bfinfdpic_plt_section(info) \
1692 (bfinfdpic_hash_table (info)->elf.splt)
1693 #define bfinfdpic_pltrel_section(info) \
1694 (bfinfdpic_hash_table (info)->elf.srelplt)
1695 #define bfinfdpic_relocs_info(info) \
1696 (bfinfdpic_hash_table (info)->relocs_info)
1697 #define bfinfdpic_got_initial_offset(info) \
1698 (bfinfdpic_hash_table (info)->got0)
1699 #define bfinfdpic_plt_initial_offset(info) \
1700 (bfinfdpic_hash_table (info)->plt0)
1701 #define bfinfdpic_dynamic_got_plt_info(info) \
1702 (bfinfdpic_hash_table (info)->g)
1704 /* The name of the dynamic interpreter. This is put in the .interp
1707 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1709 #define DEFAULT_STACK_SIZE 0x20000
1711 /* This structure is used to collect the number of entries present in
1712 each addressable range of the got. */
1713 struct _bfinfdpic_dynamic_got_info
1715 /* Several bits of information about the current link. */
1716 struct bfd_link_info
*info
;
1717 /* Total size needed for GOT entries within the 18- or 32-bit
1719 bfd_vma got17m4
, gothilo
;
1720 /* Total size needed for function descriptor entries within the 18-
1721 or 32-bit ranges. */
1722 bfd_vma fd17m4
, fdhilo
;
1723 /* Total size needed function descriptor entries referenced in PLT
1724 entries, that would be profitable to place in offsets close to
1725 the PIC register. */
1727 /* Total size needed by lazy PLT entries. */
1729 /* Number of relocations carried over from input object files. */
1730 unsigned long relocs
;
1731 /* Number of fixups introduced by relocations in input object files. */
1732 unsigned long fixups
;
1735 /* Create a Blackfin ELF linker hash table. */
1737 static struct bfd_link_hash_table
*
1738 bfinfdpic_elf_link_hash_table_create (bfd
*abfd
)
1740 struct bfinfdpic_elf_link_hash_table
*ret
;
1741 size_t amt
= sizeof (struct bfinfdpic_elf_link_hash_table
);
1743 ret
= bfd_zmalloc (amt
);
1747 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1748 _bfd_elf_link_hash_newfunc
,
1749 sizeof (struct elf_link_hash_entry
),
1756 return &ret
->elf
.root
;
1759 /* Decide whether a reference to a symbol can be resolved locally or
1760 not. If the symbol is protected, we want the local address, but
1761 its function descriptor must be assigned by the dynamic linker. */
1762 #define BFINFDPIC_SYM_LOCAL(INFO, H) \
1763 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1764 || ! elf_hash_table (INFO)->dynamic_sections_created)
1765 #define BFINFDPIC_FUNCDESC_LOCAL(INFO, H) \
1766 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1768 /* This structure collects information on what kind of GOT, PLT or
1769 function descriptors are required by relocations that reference a
1771 struct bfinfdpic_relocs_info
1773 /* The index of the symbol, as stored in the relocation r_info, if
1774 we have a local symbol; -1 otherwise. */
1778 /* The input bfd in which the symbol is defined, if it's a local
1781 /* If symndx == -1, the hash table entry corresponding to a global
1782 symbol (even if it turns out to bind locally, in which case it
1783 should ideally be replaced with section's symndx + addend). */
1784 struct elf_link_hash_entry
*h
;
1786 /* The addend of the relocation that references the symbol. */
1789 /* The fields above are used to identify an entry. The fields below
1790 contain information on how an entry is used and, later on, which
1791 locations it was assigned. */
1792 /* The following 2 fields record whether the symbol+addend above was
1793 ever referenced with a GOT relocation. The 17M4 suffix indicates a
1794 GOT17M4 relocation; hilo is used for GOTLO/GOTHI pairs. */
1797 /* Whether a FUNCDESC relocation references symbol+addend. */
1799 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1802 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1803 unsigned fdgoff17m4
;
1804 unsigned fdgoffhilo
;
1805 /* Whether symbol+addend is referenced with GOTOFF17M4, GOTOFFLO or
1806 GOTOFFHI relocations. The addend doesn't really matter, since we
1807 envision that this will only be used to check whether the symbol
1808 is mapped to the same segment as the got. */
1810 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1812 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1815 /* Whether we need a PLT entry for a symbol. Should be implied by
1817 (call && symndx == -1 && ! BFINFDPIC_SYM_LOCAL (info, d.h)) */
1819 /* Whether a function descriptor should be created in this link unit
1820 for symbol+addend. Should be implied by something like:
1821 (plt || fdgotoff17m4 || fdgotofflohi
1822 || ((fd || fdgot17m4 || fdgothilo)
1823 && (symndx != -1 || BFINFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1825 /* Whether a lazy PLT entry is needed for this symbol+addend.
1826 Should be implied by something like:
1827 (privfd && symndx == -1 && ! BFINFDPIC_SYM_LOCAL (info, d.h)
1828 && ! (info->flags & DF_BIND_NOW)) */
1830 /* Whether we've already emitted GOT relocations and PLT entries as
1831 needed for this symbol. */
1834 /* The number of R_BFIN_BYTE4_DATA, R_BFIN_FUNCDESC and R_BFIN_FUNCDESC_VALUE
1835 relocations referencing the symbol. */
1836 unsigned relocs32
, relocsfd
, relocsfdv
;
1838 /* The number of .rofixups entries and dynamic relocations allocated
1839 for this symbol, minus any that might have already been used. */
1840 unsigned fixups
, dynrelocs
;
1842 /* The offsets of the GOT entries assigned to symbol+addend, to the
1843 function descriptor's address, and to a function descriptor,
1844 respectively. Should be zero if unassigned. The offsets are
1845 counted from the value that will be assigned to the PIC register,
1846 not from the beginning of the .got section. */
1847 bfd_signed_vma got_entry
, fdgot_entry
, fd_entry
;
1848 /* The offsets of the PLT entries assigned to symbol+addend,
1849 non-lazy and lazy, respectively. If unassigned, should be
1851 bfd_vma plt_entry
, lzplt_entry
;
1854 /* Compute a hash with the key fields of an bfinfdpic_relocs_info entry. */
1856 bfinfdpic_relocs_info_hash (const void *entry_
)
1858 const struct bfinfdpic_relocs_info
*entry
= entry_
;
1860 return (entry
->symndx
== -1
1861 ? (long) entry
->d
.h
->root
.root
.hash
1862 : entry
->symndx
+ (long) entry
->d
.abfd
->id
* 257) + entry
->addend
;
1865 /* Test whether the key fields of two bfinfdpic_relocs_info entries are
1868 bfinfdpic_relocs_info_eq (const void *entry1
, const void *entry2
)
1870 const struct bfinfdpic_relocs_info
*e1
= entry1
;
1871 const struct bfinfdpic_relocs_info
*e2
= entry2
;
1873 return e1
->symndx
== e2
->symndx
&& e1
->addend
== e2
->addend
1874 && (e1
->symndx
== -1 ? e1
->d
.h
== e2
->d
.h
: e1
->d
.abfd
== e2
->d
.abfd
);
1877 /* Find or create an entry in a hash table HT that matches the key
1878 fields of the given ENTRY. If it's not found, memory for a new
1879 entry is allocated in ABFD's obstack. */
1880 static struct bfinfdpic_relocs_info
*
1881 bfinfdpic_relocs_info_find (struct htab
*ht
,
1883 const struct bfinfdpic_relocs_info
*entry
,
1884 enum insert_option insert
)
1886 struct bfinfdpic_relocs_info
**loc
;
1891 loc
= (struct bfinfdpic_relocs_info
**) htab_find_slot (ht
, entry
, insert
);
1899 *loc
= bfd_zalloc (abfd
, sizeof (**loc
));
1904 (*loc
)->symndx
= entry
->symndx
;
1905 (*loc
)->d
= entry
->d
;
1906 (*loc
)->addend
= entry
->addend
;
1907 (*loc
)->plt_entry
= (bfd_vma
)-1;
1908 (*loc
)->lzplt_entry
= (bfd_vma
)-1;
1913 /* Obtain the address of the entry in HT associated with H's symbol +
1914 addend, creating a new entry if none existed. ABFD is only used
1915 for memory allocation purposes. */
1916 inline static struct bfinfdpic_relocs_info
*
1917 bfinfdpic_relocs_info_for_global (struct htab
*ht
,
1919 struct elf_link_hash_entry
*h
,
1921 enum insert_option insert
)
1923 struct bfinfdpic_relocs_info entry
;
1927 entry
.addend
= addend
;
1929 return bfinfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1932 /* Obtain the address of the entry in HT associated with the SYMNDXth
1933 local symbol of the input bfd ABFD, plus the addend, creating a new
1934 entry if none existed. */
1935 inline static struct bfinfdpic_relocs_info
*
1936 bfinfdpic_relocs_info_for_local (struct htab
*ht
,
1940 enum insert_option insert
)
1942 struct bfinfdpic_relocs_info entry
;
1944 entry
.symndx
= symndx
;
1945 entry
.d
.abfd
= abfd
;
1946 entry
.addend
= addend
;
1948 return bfinfdpic_relocs_info_find (ht
, abfd
, &entry
, insert
);
1951 /* Merge fields set by check_relocs() of two entries that end up being
1952 mapped to the same (presumably global) symbol. */
1955 bfinfdpic_pic_merge_early_relocs_info (struct bfinfdpic_relocs_info
*e2
,
1956 struct bfinfdpic_relocs_info
const *e1
)
1958 e2
->got17m4
|= e1
->got17m4
;
1959 e2
->gothilo
|= e1
->gothilo
;
1961 e2
->fdgot17m4
|= e1
->fdgot17m4
;
1962 e2
->fdgothilo
|= e1
->fdgothilo
;
1963 e2
->fdgoff17m4
|= e1
->fdgoff17m4
;
1964 e2
->fdgoffhilo
|= e1
->fdgoffhilo
;
1965 e2
->gotoff
|= e1
->gotoff
;
1966 e2
->call
|= e1
->call
;
1970 /* Every block of 65535 lazy PLT entries shares a single call to the
1971 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1972 32767, counting from 0). All other lazy PLT entries branch to it
1973 in a single instruction. */
1975 #define LZPLT_RESOLVER_EXTRA 10
1976 #define LZPLT_NORMAL_SIZE 6
1977 #define LZPLT_ENTRIES 1362
1979 #define BFINFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) LZPLT_NORMAL_SIZE * LZPLT_ENTRIES + LZPLT_RESOLVER_EXTRA)
1980 #define BFINFDPIC_LZPLT_RESOLV_LOC (LZPLT_NORMAL_SIZE * LZPLT_ENTRIES / 2)
1982 /* Add a dynamic relocation to the SRELOC section. */
1984 inline static bfd_vma
1985 _bfinfdpic_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
1986 int reloc_type
, long dynindx
, bfd_vma addend
,
1987 struct bfinfdpic_relocs_info
*entry
)
1989 Elf_Internal_Rela outrel
;
1990 bfd_vma reloc_offset
;
1992 outrel
.r_offset
= offset
;
1993 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
1994 outrel
.r_addend
= addend
;
1996 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rel
);
1997 BFD_ASSERT (reloc_offset
< sreloc
->size
);
1998 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1999 sreloc
->contents
+ reloc_offset
);
2000 sreloc
->reloc_count
++;
2002 /* If the entry's index is zero, this relocation was probably to a
2003 linkonce section that got discarded. We reserved a dynamic
2004 relocation, but it was for another entry than the one we got at
2005 the time of emitting the relocation. Unfortunately there's no
2006 simple way for us to catch this situation, since the relocation
2007 is cleared right before calling relocate_section, at which point
2008 we no longer know what the relocation used to point to. */
2011 BFD_ASSERT (entry
->dynrelocs
> 0);
2015 return reloc_offset
;
2018 /* Add a fixup to the ROFIXUP section. */
2021 _bfinfdpic_add_rofixup (bfd
*output_bfd
, asection
*rofixup
, bfd_vma offset
,
2022 struct bfinfdpic_relocs_info
*entry
)
2024 bfd_vma fixup_offset
;
2026 if (rofixup
->flags
& SEC_EXCLUDE
)
2029 fixup_offset
= rofixup
->reloc_count
* 4;
2030 if (rofixup
->contents
)
2032 BFD_ASSERT (fixup_offset
< rofixup
->size
);
2033 bfd_put_32 (output_bfd
, offset
, rofixup
->contents
+ fixup_offset
);
2035 rofixup
->reloc_count
++;
2037 if (entry
&& entry
->symndx
)
2039 /* See discussion about symndx == 0 in _bfinfdpic_add_dyn_reloc
2041 BFD_ASSERT (entry
->fixups
> 0);
2045 return fixup_offset
;
2048 /* Find the segment number in which OSEC, and output section, is
2052 _bfinfdpic_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
2054 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section (output_bfd
, osec
);
2056 return (p
!= NULL
) ? p
- elf_tdata (output_bfd
)->phdr
: -1;
2060 _bfinfdpic_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
2062 unsigned seg
= _bfinfdpic_osec_to_segment (output_bfd
, osec
);
2064 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
2067 /* Generate relocations for GOT entries, function descriptors, and
2068 code for PLT and lazy PLT entries. */
2071 _bfinfdpic_emit_got_relocs_plt_entries (struct bfinfdpic_relocs_info
*entry
,
2073 struct bfd_link_info
*info
,
2075 Elf_Internal_Sym
*sym
,
2078 bfd_vma fd_lazy_rel_offset
= (bfd_vma
) -1;
2085 if (entry
->got_entry
|| entry
->fdgot_entry
|| entry
->fd_entry
)
2087 /* If the symbol is dynamic, consider it for dynamic
2088 relocations, otherwise decay to section + offset. */
2089 if (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1)
2090 dynindx
= entry
->d
.h
->dynindx
;
2094 && sec
->output_section
2095 && ! bfd_is_abs_section (sec
->output_section
)
2096 && ! bfd_is_und_section (sec
->output_section
))
2097 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
2103 /* Generate relocation for GOT entry pointing to the symbol. */
2104 if (entry
->got_entry
)
2107 bfd_vma ad
= addend
;
2109 /* If the symbol is dynamic but binds locally, use
2111 if (sec
&& (entry
->symndx
!= -1
2112 || BFINFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2114 if (entry
->symndx
== -1)
2115 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2117 ad
+= sym
->st_value
;
2118 ad
+= sec
->output_offset
;
2119 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
2120 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2125 /* If we're linking an executable at a fixed address, we can
2126 omit the dynamic relocation as long as the symbol is local to
2128 if (bfd_link_pde (info
)
2129 && (entry
->symndx
!= -1
2130 || BFINFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2133 ad
+= sec
->output_section
->vma
;
2134 if (entry
->symndx
!= -1
2135 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
2136 _bfinfdpic_add_rofixup (output_bfd
,
2137 bfinfdpic_gotfixup_section (info
),
2138 bfinfdpic_got_section (info
)->output_section
2140 + bfinfdpic_got_section (info
)->output_offset
2141 + bfinfdpic_got_initial_offset (info
)
2142 + entry
->got_entry
, entry
);
2145 _bfinfdpic_add_dyn_reloc (output_bfd
, bfinfdpic_gotrel_section (info
),
2146 _bfd_elf_section_offset
2148 bfinfdpic_got_section (info
),
2149 bfinfdpic_got_initial_offset (info
)
2151 + bfinfdpic_got_section (info
)
2152 ->output_section
->vma
2153 + bfinfdpic_got_section (info
)->output_offset
,
2154 R_BFIN_BYTE4_DATA
, idx
, ad
, entry
);
2156 bfd_put_32 (output_bfd
, ad
,
2157 bfinfdpic_got_section (info
)->contents
2158 + bfinfdpic_got_initial_offset (info
)
2159 + entry
->got_entry
);
2162 /* Generate relocation for GOT entry pointing to a canonical
2163 function descriptor. */
2164 if (entry
->fdgot_entry
)
2169 if (! (entry
->symndx
== -1
2170 && entry
->d
.h
->root
.type
== bfd_link_hash_undefweak
2171 && BFINFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2173 /* If the symbol is dynamic and there may be dynamic symbol
2174 resolution because we are, or are linked with, a shared
2175 library, emit a FUNCDESC relocation such that the dynamic
2176 linker will allocate the function descriptor. If the
2177 symbol needs a non-local function descriptor but binds
2178 locally (e.g., its visibility is protected, emit a
2179 dynamic relocation decayed to section+offset. */
2180 if (entry
->symndx
== -1
2181 && ! BFINFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)
2182 && BFINFDPIC_SYM_LOCAL (info
, entry
->d
.h
)
2183 && !bfd_link_pde (info
))
2185 reloc
= R_BFIN_FUNCDESC
;
2186 idx
= elf_section_data (entry
->d
.h
->root
.u
.def
.section
2187 ->output_section
)->dynindx
;
2188 ad
= entry
->d
.h
->root
.u
.def
.section
->output_offset
2189 + entry
->d
.h
->root
.u
.def
.value
;
2191 else if (entry
->symndx
== -1
2192 && ! BFINFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
))
2194 reloc
= R_BFIN_FUNCDESC
;
2202 /* Otherwise, we know we have a private function descriptor,
2203 so reference it directly. */
2204 if (elf_hash_table (info
)->dynamic_sections_created
)
2205 BFD_ASSERT (entry
->privfd
);
2206 reloc
= R_BFIN_BYTE4_DATA
;
2207 idx
= elf_section_data (bfinfdpic_got_section (info
)
2208 ->output_section
)->dynindx
;
2209 ad
= bfinfdpic_got_section (info
)->output_offset
2210 + bfinfdpic_got_initial_offset (info
) + entry
->fd_entry
;
2213 /* If there is room for dynamic symbol resolution, emit the
2214 dynamic relocation. However, if we're linking an
2215 executable at a fixed location, we won't have emitted a
2216 dynamic symbol entry for the got section, so idx will be
2217 zero, which means we can and should compute the address
2218 of the private descriptor ourselves. */
2219 if (bfd_link_pde (info
)
2220 && (entry
->symndx
!= -1
2221 || BFINFDPIC_FUNCDESC_LOCAL (info
, entry
->d
.h
)))
2223 ad
+= bfinfdpic_got_section (info
)->output_section
->vma
;
2224 _bfinfdpic_add_rofixup (output_bfd
,
2225 bfinfdpic_gotfixup_section (info
),
2226 bfinfdpic_got_section (info
)
2227 ->output_section
->vma
2228 + bfinfdpic_got_section (info
)
2230 + bfinfdpic_got_initial_offset (info
)
2231 + entry
->fdgot_entry
, entry
);
2234 _bfinfdpic_add_dyn_reloc (output_bfd
,
2235 bfinfdpic_gotrel_section (info
),
2236 _bfd_elf_section_offset
2238 bfinfdpic_got_section (info
),
2239 bfinfdpic_got_initial_offset (info
)
2240 + entry
->fdgot_entry
)
2241 + bfinfdpic_got_section (info
)
2242 ->output_section
->vma
2243 + bfinfdpic_got_section (info
)
2245 reloc
, idx
, ad
, entry
);
2248 bfd_put_32 (output_bfd
, ad
,
2249 bfinfdpic_got_section (info
)->contents
2250 + bfinfdpic_got_initial_offset (info
)
2251 + entry
->fdgot_entry
);
2254 /* Generate relocation to fill in a private function descriptor in
2256 if (entry
->fd_entry
)
2259 bfd_vma ad
= addend
;
2261 long lowword
, highword
;
2263 /* If the symbol is dynamic but binds locally, use
2265 if (sec
&& (entry
->symndx
!= -1
2266 || BFINFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2268 if (entry
->symndx
== -1)
2269 ad
+= entry
->d
.h
->root
.u
.def
.value
;
2271 ad
+= sym
->st_value
;
2272 ad
+= sec
->output_offset
;
2273 if (sec
->output_section
&& elf_section_data (sec
->output_section
))
2274 idx
= elf_section_data (sec
->output_section
)->dynindx
;
2279 /* If we're linking an executable at a fixed address, we can
2280 omit the dynamic relocation as long as the symbol is local to
2282 if (bfd_link_pde (info
)
2283 && (entry
->symndx
!= -1 || BFINFDPIC_SYM_LOCAL (info
, entry
->d
.h
)))
2286 ad
+= sec
->output_section
->vma
;
2288 if (entry
->symndx
!= -1
2289 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
2291 _bfinfdpic_add_rofixup (output_bfd
,
2292 bfinfdpic_gotfixup_section (info
),
2293 bfinfdpic_got_section (info
)
2294 ->output_section
->vma
2295 + bfinfdpic_got_section (info
)
2297 + bfinfdpic_got_initial_offset (info
)
2298 + entry
->fd_entry
, entry
);
2299 _bfinfdpic_add_rofixup (output_bfd
,
2300 bfinfdpic_gotfixup_section (info
),
2301 bfinfdpic_got_section (info
)
2302 ->output_section
->vma
2303 + bfinfdpic_got_section (info
)
2305 + bfinfdpic_got_initial_offset (info
)
2306 + entry
->fd_entry
+ 4, entry
);
2312 = _bfinfdpic_add_dyn_reloc (output_bfd
,
2314 ? bfinfdpic_pltrel_section (info
)
2315 : bfinfdpic_gotrel_section (info
),
2316 _bfd_elf_section_offset
2318 bfinfdpic_got_section (info
),
2319 bfinfdpic_got_initial_offset (info
)
2321 + bfinfdpic_got_section (info
)
2322 ->output_section
->vma
2323 + bfinfdpic_got_section (info
)
2325 R_BFIN_FUNCDESC_VALUE
, idx
, ad
, entry
);
2328 /* If we've omitted the dynamic relocation, just emit the fixed
2329 addresses of the symbol and of the local GOT base offset. */
2330 if (bfd_link_pde (info
)
2332 && sec
->output_section
)
2335 highword
= bfinfdpic_got_section (info
)->output_section
->vma
2336 + bfinfdpic_got_section (info
)->output_offset
2337 + bfinfdpic_got_initial_offset (info
);
2339 else if (entry
->lazyplt
)
2344 fd_lazy_rel_offset
= ofst
;
2346 /* A function descriptor used for lazy or local resolving is
2347 initialized such that its high word contains the output
2348 section index in which the PLT entries are located, and
2349 the low word contains the address of the lazy PLT entry
2350 entry point, that must be within the memory region
2351 assigned to that section. */
2352 lowword
= entry
->lzplt_entry
+ 4
2353 + bfinfdpic_plt_section (info
)->output_offset
2354 + bfinfdpic_plt_section (info
)->output_section
->vma
;
2355 highword
= _bfinfdpic_osec_to_segment
2356 (output_bfd
, bfinfdpic_plt_section (info
)->output_section
);
2360 /* A function descriptor for a local function gets the index
2361 of the section. For a non-local function, it's
2365 || (entry
->symndx
== -1 && entry
->d
.h
->dynindx
!= -1
2366 && entry
->d
.h
->dynindx
== idx
))
2369 highword
= _bfinfdpic_osec_to_segment
2370 (output_bfd
, sec
->output_section
);
2373 bfd_put_32 (output_bfd
, lowword
,
2374 bfinfdpic_got_section (info
)->contents
2375 + bfinfdpic_got_initial_offset (info
)
2377 bfd_put_32 (output_bfd
, highword
,
2378 bfinfdpic_got_section (info
)->contents
2379 + bfinfdpic_got_initial_offset (info
)
2380 + entry
->fd_entry
+ 4);
2383 /* Generate code for the PLT entry. */
2384 if (entry
->plt_entry
!= (bfd_vma
) -1)
2386 bfd_byte
*plt_code
= bfinfdpic_plt_section (info
)->contents
2389 BFD_ASSERT (entry
->fd_entry
);
2391 /* Figure out what kind of PLT entry we need, depending on the
2392 location of the function descriptor within the GOT. */
2393 if (entry
->fd_entry
>= -(1 << (18 - 1))
2394 && entry
->fd_entry
+ 4 < (1 << (18 - 1)))
2396 /* P1 = [P3 + fd_entry]; P3 = [P3 + fd_entry + 4] */
2397 bfd_put_32 (output_bfd
,
2398 0xe519 | ((entry
->fd_entry
<< 14) & 0xFFFF0000),
2400 bfd_put_32 (output_bfd
,
2401 0xe51b | (((entry
->fd_entry
+ 4) << 14) & 0xFFFF0000),
2407 /* P1.L = fd_entry; P1.H = fd_entry;
2411 bfd_put_32 (output_bfd
,
2412 0xe109 | (entry
->fd_entry
<< 16),
2414 bfd_put_32 (output_bfd
,
2415 0xe149 | (entry
->fd_entry
& 0xFFFF0000),
2417 bfd_put_16 (output_bfd
, 0x5ad9, plt_code
+ 8);
2418 bfd_put_16 (output_bfd
, 0x9159, plt_code
+ 10);
2419 bfd_put_16 (output_bfd
, 0xac5b, plt_code
+ 12);
2423 bfd_put_16 (output_bfd
, 0x0051, plt_code
);
2426 /* Generate code for the lazy PLT entry. */
2427 if (entry
->lzplt_entry
!= (bfd_vma
) -1)
2429 bfd_byte
*lzplt_code
= bfinfdpic_plt_section (info
)->contents
2430 + entry
->lzplt_entry
;
2431 bfd_vma resolverStub_addr
;
2433 bfd_put_32 (output_bfd
, fd_lazy_rel_offset
, lzplt_code
);
2436 resolverStub_addr
= entry
->lzplt_entry
/ BFINFDPIC_LZPLT_BLOCK_SIZE
2437 * BFINFDPIC_LZPLT_BLOCK_SIZE
+ BFINFDPIC_LZPLT_RESOLV_LOC
;
2438 if (resolverStub_addr
>= bfinfdpic_plt_initial_offset (info
))
2439 resolverStub_addr
= bfinfdpic_plt_initial_offset (info
) - LZPLT_NORMAL_SIZE
- LZPLT_RESOLVER_EXTRA
;
2441 if (entry
->lzplt_entry
== resolverStub_addr
)
2443 /* This is a lazy PLT entry that includes a resolver call.
2447 bfd_put_32 (output_bfd
,
2450 bfd_put_16 (output_bfd
, 0x0052, lzplt_code
+ 4);
2454 /* JUMP.S resolverStub */
2455 bfd_put_16 (output_bfd
,
2457 | (((resolverStub_addr
- entry
->lzplt_entry
)
2458 / 2) & (((bfd_vma
)1 << 12) - 1)),
2466 /* Relocate an Blackfin ELF section.
2468 The RELOCATE_SECTION function is called by the new ELF backend linker
2469 to handle the relocations for a section.
2471 The relocs are always passed as Rela structures; if the section
2472 actually uses Rel structures, the r_addend field will always be
2475 This function is responsible for adjusting the section contents as
2476 necessary, and (if using Rela relocs and generating a relocatable
2477 output file) adjusting the reloc addend as necessary.
2479 This function does not have to worry about setting the reloc
2480 address or the reloc symbol index.
2482 LOCAL_SYMS is a pointer to the swapped in local symbols.
2484 LOCAL_SECTIONS is an array giving the section in the input file
2485 corresponding to the st_shndx field of each local symbol.
2487 The global hash table entry for the global symbols can be found
2488 via elf_sym_hashes (input_bfd).
2490 When generating relocatable output, this function must handle
2491 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2492 going to be the section symbol corresponding to the output
2493 section, which means that the addend must be adjusted
2497 bfinfdpic_relocate_section (bfd
* output_bfd
,
2498 struct bfd_link_info
*info
,
2500 asection
* input_section
,
2501 bfd_byte
* contents
,
2502 Elf_Internal_Rela
* relocs
,
2503 Elf_Internal_Sym
* local_syms
,
2504 asection
** local_sections
)
2506 Elf_Internal_Shdr
*symtab_hdr
;
2507 struct elf_link_hash_entry
**sym_hashes
;
2508 Elf_Internal_Rela
*rel
;
2509 Elf_Internal_Rela
*relend
;
2510 unsigned isec_segment
, got_segment
, plt_segment
,
2512 int silence_segment_error
= !bfd_link_pic (info
);
2514 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2515 sym_hashes
= elf_sym_hashes (input_bfd
);
2516 relend
= relocs
+ input_section
->reloc_count
;
2518 isec_segment
= _bfinfdpic_osec_to_segment (output_bfd
,
2519 input_section
->output_section
);
2520 if (IS_FDPIC (output_bfd
) && bfinfdpic_got_section (info
))
2521 got_segment
= _bfinfdpic_osec_to_segment (output_bfd
,
2522 bfinfdpic_got_section (info
)
2526 if (IS_FDPIC (output_bfd
) && elf_hash_table (info
)->dynamic_sections_created
)
2527 plt_segment
= _bfinfdpic_osec_to_segment (output_bfd
,
2528 bfinfdpic_plt_section (info
)
2533 for (rel
= relocs
; rel
< relend
; rel
++)
2535 reloc_howto_type
*howto
;
2536 unsigned long r_symndx
;
2537 Elf_Internal_Sym
*sym
;
2539 struct elf_link_hash_entry
*h
;
2541 bfd_reloc_status_type r
;
2542 const char * name
= NULL
;
2545 struct bfinfdpic_relocs_info
*picrel
;
2546 bfd_vma orig_addend
= rel
->r_addend
;
2548 r_type
= ELF32_R_TYPE (rel
->r_info
);
2550 if (r_type
== R_BFIN_GNU_VTINHERIT
2551 || r_type
== R_BFIN_GNU_VTENTRY
)
2554 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2555 howto
= bfin_reloc_type_lookup (input_bfd
, r_type
);
2558 bfd_set_error (bfd_error_bad_value
);
2567 if (r_symndx
< symtab_hdr
->sh_info
)
2569 sym
= local_syms
+ r_symndx
;
2570 osec
= sec
= local_sections
[r_symndx
];
2571 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2573 name
= bfd_elf_string_from_elf_section
2574 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
2575 name
= name
== NULL
? bfd_section_name (sec
) : name
;
2579 bool warned
, ignored
;
2580 bool unresolved_reloc
;
2582 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2583 r_symndx
, symtab_hdr
, sym_hashes
,
2585 unresolved_reloc
, warned
, ignored
);
2589 if (sec
!= NULL
&& discarded_section (sec
))
2590 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2591 rel
, 1, relend
, howto
, 0, contents
);
2593 if (bfd_link_relocatable (info
))
2597 && (h
->root
.type
== bfd_link_hash_defined
2598 || h
->root
.type
== bfd_link_hash_defweak
)
2599 && !BFINFDPIC_SYM_LOCAL (info
, h
))
2607 case R_BFIN_PCREL24
:
2608 case R_BFIN_PCREL24_JUMP_L
:
2609 case R_BFIN_BYTE4_DATA
:
2610 if (! IS_FDPIC (output_bfd
))
2614 case R_BFIN_GOT17M4
:
2617 case R_BFIN_FUNCDESC_GOT17M4
:
2618 case R_BFIN_FUNCDESC_GOTHI
:
2619 case R_BFIN_FUNCDESC_GOTLO
:
2620 case R_BFIN_GOTOFF17M4
:
2621 case R_BFIN_GOTOFFHI
:
2622 case R_BFIN_GOTOFFLO
:
2623 case R_BFIN_FUNCDESC_GOTOFF17M4
:
2624 case R_BFIN_FUNCDESC_GOTOFFHI
:
2625 case R_BFIN_FUNCDESC_GOTOFFLO
:
2626 case R_BFIN_FUNCDESC
:
2627 case R_BFIN_FUNCDESC_VALUE
:
2628 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2632 picrel
= bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info
2633 (info
), input_bfd
, h
,
2634 orig_addend
, INSERT
);
2636 /* In order to find the entry we created before, we must
2637 use the original addend, not the one that may have been
2638 modified by _bfd_elf_rela_local_sym(). */
2639 picrel
= bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info
2640 (info
), input_bfd
, r_symndx
,
2641 orig_addend
, INSERT
);
2645 if (!_bfinfdpic_emit_got_relocs_plt_entries (picrel
, output_bfd
, info
,
2650 /* xgettext:c-format */
2651 (_("%pB: relocation at `%pA+%#" PRIx64
"' "
2652 "references symbol `%s' with nonzero addend"),
2653 input_bfd
, input_section
, (uint64_t) rel
->r_offset
, name
);
2663 if (h
&& ! BFINFDPIC_SYM_LOCAL (info
, h
)
2664 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2665 rel
->r_offset
) != (bfd_vma
) -1)
2667 info
->callbacks
->warning
2668 (info
, _("relocation references symbol not defined in the module"),
2669 name
, input_bfd
, input_section
, rel
->r_offset
);
2677 case R_BFIN_PCREL24
:
2678 case R_BFIN_PCREL24_JUMP_L
:
2679 check_segment
[0] = isec_segment
;
2680 if (! IS_FDPIC (output_bfd
))
2681 check_segment
[1] = isec_segment
;
2682 else if (picrel
->plt
)
2684 relocation
= bfinfdpic_plt_section (info
)->output_section
->vma
2685 + bfinfdpic_plt_section (info
)->output_offset
2686 + picrel
->plt_entry
;
2687 check_segment
[1] = plt_segment
;
2689 /* We don't want to warn on calls to undefined weak symbols,
2690 as calls to them must be protected by non-NULL tests
2691 anyway, and unprotected calls would invoke undefined
2693 else if (picrel
->symndx
== -1
2694 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefweak
)
2695 check_segment
[1] = check_segment
[0];
2697 check_segment
[1] = sec
2698 ? _bfinfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
2702 case R_BFIN_GOT17M4
:
2705 relocation
= picrel
->got_entry
;
2706 check_segment
[0] = check_segment
[1] = got_segment
;
2709 case R_BFIN_FUNCDESC_GOT17M4
:
2710 case R_BFIN_FUNCDESC_GOTHI
:
2711 case R_BFIN_FUNCDESC_GOTLO
:
2712 relocation
= picrel
->fdgot_entry
;
2713 check_segment
[0] = check_segment
[1] = got_segment
;
2716 case R_BFIN_GOTOFFHI
:
2717 case R_BFIN_GOTOFF17M4
:
2718 case R_BFIN_GOTOFFLO
:
2719 relocation
-= bfinfdpic_got_section (info
)->output_section
->vma
2720 + bfinfdpic_got_section (info
)->output_offset
2721 + bfinfdpic_got_initial_offset (info
);
2722 check_segment
[0] = got_segment
;
2723 check_segment
[1] = sec
2724 ? _bfinfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
2728 case R_BFIN_FUNCDESC_GOTOFF17M4
:
2729 case R_BFIN_FUNCDESC_GOTOFFHI
:
2730 case R_BFIN_FUNCDESC_GOTOFFLO
:
2731 relocation
= picrel
->fd_entry
;
2732 check_segment
[0] = check_segment
[1] = got_segment
;
2735 case R_BFIN_FUNCDESC
:
2736 if ((input_section
->flags
& SEC_ALLOC
) != 0)
2739 bfd_vma addend
= rel
->r_addend
;
2741 if (! (h
&& h
->root
.type
== bfd_link_hash_undefweak
2742 && BFINFDPIC_SYM_LOCAL (info
, h
)))
2744 /* If the symbol is dynamic and there may be dynamic
2745 symbol resolution because we are or are linked with a
2746 shared library, emit a FUNCDESC relocation such that
2747 the dynamic linker will allocate the function
2748 descriptor. If the symbol needs a non-local function
2749 descriptor but binds locally (e.g., its visibility is
2750 protected, emit a dynamic relocation decayed to
2752 if (h
&& ! BFINFDPIC_FUNCDESC_LOCAL (info
, h
)
2753 && BFINFDPIC_SYM_LOCAL (info
, h
)
2754 && !bfd_link_pde (info
))
2756 dynindx
= elf_section_data (h
->root
.u
.def
.section
2757 ->output_section
)->dynindx
;
2758 addend
+= h
->root
.u
.def
.section
->output_offset
2759 + h
->root
.u
.def
.value
;
2761 else if (h
&& ! BFINFDPIC_FUNCDESC_LOCAL (info
, h
))
2765 info
->callbacks
->warning
2766 (info
, _("R_BFIN_FUNCDESC references dynamic symbol with nonzero addend"),
2767 name
, input_bfd
, input_section
, rel
->r_offset
);
2770 dynindx
= h
->dynindx
;
2774 /* Otherwise, we know we have a private function
2775 descriptor, so reference it directly. */
2776 BFD_ASSERT (picrel
->privfd
);
2777 r_type
= R_BFIN_BYTE4_DATA
;
2778 dynindx
= elf_section_data (bfinfdpic_got_section (info
)
2779 ->output_section
)->dynindx
;
2780 addend
= bfinfdpic_got_section (info
)->output_offset
2781 + bfinfdpic_got_initial_offset (info
)
2785 /* If there is room for dynamic symbol resolution, emit
2786 the dynamic relocation. However, if we're linking an
2787 executable at a fixed location, we won't have emitted a
2788 dynamic symbol entry for the got section, so idx will
2789 be zero, which means we can and should compute the
2790 address of the private descriptor ourselves. */
2791 if (bfd_link_pde (info
)
2792 && (!h
|| BFINFDPIC_FUNCDESC_LOCAL (info
, h
)))
2796 addend
+= bfinfdpic_got_section (info
)->output_section
->vma
;
2797 if ((bfd_section_flags (input_section
->output_section
)
2798 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2800 if (_bfinfdpic_osec_readonly_p (output_bfd
,
2804 info
->callbacks
->warning
2806 _("cannot emit fixups in read-only section"),
2807 name
, input_bfd
, input_section
, rel
->r_offset
);
2811 offset
= _bfd_elf_section_offset
2813 input_section
, rel
->r_offset
);
2815 if (offset
!= (bfd_vma
)-1)
2816 _bfinfdpic_add_rofixup (output_bfd
,
2817 bfinfdpic_gotfixup_section
2819 offset
+ input_section
2820 ->output_section
->vma
2821 + input_section
->output_offset
,
2825 else if ((bfd_section_flags (input_section
->output_section
)
2826 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2830 if (_bfinfdpic_osec_readonly_p (output_bfd
,
2834 info
->callbacks
->warning
2836 _("cannot emit dynamic relocations in read-only section"),
2837 name
, input_bfd
, input_section
, rel
->r_offset
);
2840 offset
= _bfd_elf_section_offset (output_bfd
, info
,
2841 input_section
, rel
->r_offset
);
2843 if (offset
!= (bfd_vma
)-1)
2844 _bfinfdpic_add_dyn_reloc (output_bfd
,
2845 bfinfdpic_gotrel_section (info
),
2846 offset
+ input_section
2847 ->output_section
->vma
2848 + input_section
->output_offset
,
2850 dynindx
, addend
, picrel
);
2853 addend
+= bfinfdpic_got_section (info
)->output_section
->vma
;
2856 /* We want the addend in-place because dynamic
2857 relocations are REL. Setting relocation to it should
2858 arrange for it to be installed. */
2859 relocation
= addend
- rel
->r_addend
;
2861 check_segment
[0] = check_segment
[1] = got_segment
;
2864 case R_BFIN_BYTE4_DATA
:
2865 if (! IS_FDPIC (output_bfd
))
2867 check_segment
[0] = check_segment
[1] = -1;
2871 case R_BFIN_FUNCDESC_VALUE
:
2874 bfd_vma addend
= rel
->r_addend
;
2876 offset
= _bfd_elf_section_offset (output_bfd
, info
,
2877 input_section
, rel
->r_offset
);
2879 /* If the symbol is dynamic but binds locally, use
2881 if (h
&& ! BFINFDPIC_SYM_LOCAL (info
, h
))
2883 if (addend
&& r_type
== R_BFIN_FUNCDESC_VALUE
)
2885 info
->callbacks
->warning
2886 (info
, _("R_BFIN_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
2887 name
, input_bfd
, input_section
, rel
->r_offset
);
2890 dynindx
= h
->dynindx
;
2895 addend
+= h
->root
.u
.def
.value
;
2897 addend
+= sym
->st_value
;
2899 addend
+= osec
->output_offset
;
2900 if (osec
&& osec
->output_section
2901 && ! bfd_is_abs_section (osec
->output_section
)
2902 && ! bfd_is_und_section (osec
->output_section
))
2903 dynindx
= elf_section_data (osec
->output_section
)->dynindx
;
2908 /* If we're linking an executable at a fixed address, we
2909 can omit the dynamic relocation as long as the symbol
2910 is defined in the current link unit (which is implied
2911 by its output section not being NULL). */
2912 if (bfd_link_pde (info
)
2913 && (!h
|| BFINFDPIC_SYM_LOCAL (info
, h
)))
2916 addend
+= osec
->output_section
->vma
;
2917 if (IS_FDPIC (input_bfd
)
2918 && (bfd_section_flags (input_section
->output_section
)
2919 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2921 if (_bfinfdpic_osec_readonly_p (output_bfd
,
2925 info
->callbacks
->warning
2927 _("cannot emit fixups in read-only section"),
2928 name
, input_bfd
, input_section
, rel
->r_offset
);
2931 if (!h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
2933 if (offset
!= (bfd_vma
)-1)
2935 _bfinfdpic_add_rofixup (output_bfd
,
2936 bfinfdpic_gotfixup_section
2938 offset
+ input_section
2939 ->output_section
->vma
2940 + input_section
->output_offset
,
2943 if (r_type
== R_BFIN_FUNCDESC_VALUE
)
2944 _bfinfdpic_add_rofixup
2946 bfinfdpic_gotfixup_section (info
),
2947 offset
+ input_section
->output_section
->vma
2948 + input_section
->output_offset
+ 4, picrel
);
2955 if ((bfd_section_flags (input_section
->output_section
)
2956 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2958 if (_bfinfdpic_osec_readonly_p (output_bfd
,
2962 info
->callbacks
->warning
2964 _("cannot emit dynamic relocations in read-only section"),
2965 name
, input_bfd
, input_section
, rel
->r_offset
);
2969 if (offset
!= (bfd_vma
)-1)
2970 _bfinfdpic_add_dyn_reloc (output_bfd
,
2971 bfinfdpic_gotrel_section (info
),
2973 + input_section
->output_section
->vma
2974 + input_section
->output_offset
,
2975 r_type
, dynindx
, addend
, picrel
);
2978 addend
+= osec
->output_section
->vma
;
2979 /* We want the addend in-place because dynamic
2980 relocations are REL. Setting relocation to it
2981 should arrange for it to be installed. */
2982 relocation
= addend
- rel
->r_addend
;
2985 if (r_type
== R_BFIN_FUNCDESC_VALUE
)
2987 /* If we've omitted the dynamic relocation, just emit
2988 the fixed addresses of the symbol and of the local
2990 if (bfd_link_pde (info
)
2991 && (!h
|| BFINFDPIC_SYM_LOCAL (info
, h
)))
2992 bfd_put_32 (output_bfd
,
2993 bfinfdpic_got_section (info
)->output_section
->vma
2994 + bfinfdpic_got_section (info
)->output_offset
2995 + bfinfdpic_got_initial_offset (info
),
2996 contents
+ rel
->r_offset
+ 4);
2998 /* A function descriptor used for lazy or local
2999 resolving is initialized such that its high word
3000 contains the output section index in which the
3001 PLT entries are located, and the low word
3002 contains the offset of the lazy PLT entry entry
3003 point into that section. */
3004 bfd_put_32 (output_bfd
,
3005 h
&& ! BFINFDPIC_SYM_LOCAL (info
, h
)
3007 : _bfinfdpic_osec_to_segment (output_bfd
,
3010 contents
+ rel
->r_offset
+ 4);
3013 check_segment
[0] = check_segment
[1] = got_segment
;
3017 check_segment
[0] = isec_segment
;
3018 check_segment
[1] = sec
3019 ? _bfinfdpic_osec_to_segment (output_bfd
, sec
->output_section
)
3024 if (check_segment
[0] != check_segment
[1] && IS_FDPIC (output_bfd
))
3026 #if 1 /* If you take this out, remove the #error from fdpic-static-6.d
3027 in the ld testsuite. */
3028 /* This helps catch problems in GCC while we can't do more
3029 than static linking. The idea is to test whether the
3030 input file basename is crt0.o only once. */
3031 if (silence_segment_error
== 1)
3032 silence_segment_error
=
3033 (strlen (bfd_get_filename (input_bfd
)) == 6
3034 && filename_cmp (bfd_get_filename (input_bfd
), "crt0.o") == 0)
3035 || (strlen (bfd_get_filename (input_bfd
)) > 6
3036 && filename_cmp (bfd_get_filename (input_bfd
)
3037 + strlen (bfd_get_filename (input_bfd
)) - 7,
3041 if (!silence_segment_error
3042 /* We don't want duplicate errors for undefined
3044 && !(picrel
&& picrel
->symndx
== -1
3045 && picrel
->d
.h
->root
.type
== bfd_link_hash_undefined
))
3046 info
->callbacks
->warning
3049 ? _("relocations between different segments are not supported")
3050 : _("warning: relocation references a different segment"),
3051 name
, input_bfd
, input_section
, rel
->r_offset
);
3052 if (!silence_segment_error
&& bfd_link_pic (info
))
3054 elf_elfheader (output_bfd
)->e_flags
|= EF_BFIN_PIC
;
3059 case R_BFIN_GOTOFFHI
:
3060 /* We need the addend to be applied before we shift the
3062 relocation
+= rel
->r_addend
;
3065 case R_BFIN_FUNCDESC_GOTHI
:
3066 case R_BFIN_FUNCDESC_GOTOFFHI
:
3071 case R_BFIN_FUNCDESC_GOTLO
:
3072 case R_BFIN_GOTOFFLO
:
3073 case R_BFIN_FUNCDESC_GOTOFFLO
:
3074 relocation
&= 0xffff;
3083 case R_BFIN_PCREL24
:
3084 case R_BFIN_PCREL24_JUMP_L
:
3085 if (! IS_FDPIC (output_bfd
) || ! picrel
->plt
)
3089 /* When referencing a GOT entry, a function descriptor or a
3090 PLT, we don't want the addend to apply to the reference,
3091 but rather to the referenced symbol. The actual entry
3092 will have already been created taking the addend into
3093 account, so cancel it out here. */
3094 case R_BFIN_GOT17M4
:
3097 case R_BFIN_FUNCDESC_GOT17M4
:
3098 case R_BFIN_FUNCDESC_GOTHI
:
3099 case R_BFIN_FUNCDESC_GOTLO
:
3100 case R_BFIN_FUNCDESC_GOTOFF17M4
:
3101 case R_BFIN_FUNCDESC_GOTOFFHI
:
3102 case R_BFIN_FUNCDESC_GOTOFFLO
:
3103 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF17M4
3104 here, since we do want to apply the addend to the others.
3105 Note that we've applied the addend to GOTOFFHI before we
3106 shifted it right. */
3107 case R_BFIN_GOTOFFHI
:
3108 relocation
-= rel
->r_addend
;
3115 r
= bfin_final_link_relocate (rel
, howto
, input_bfd
, input_section
,
3116 contents
, rel
->r_offset
,
3117 relocation
, rel
->r_addend
);
3119 if (r
!= bfd_reloc_ok
)
3121 const char * msg
= (const char *) NULL
;
3125 case bfd_reloc_overflow
:
3126 (*info
->callbacks
->reloc_overflow
)
3127 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3128 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3131 case bfd_reloc_undefined
:
3132 (*info
->callbacks
->undefined_symbol
)
3133 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, true);
3136 case bfd_reloc_outofrange
:
3137 msg
= _("internal error: out of range error");
3140 case bfd_reloc_notsupported
:
3141 msg
= _("internal error: unsupported relocation error");
3144 case bfd_reloc_dangerous
:
3145 msg
= _("internal error: dangerous relocation");
3149 msg
= _("internal error: unknown error");
3154 (*info
->callbacks
->warning
) (info
, msg
, name
, input_bfd
,
3155 input_section
, rel
->r_offset
);
3162 /* We need dynamic symbols for every section, since segments can
3163 relocate independently. */
3165 _bfinfdpic_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3166 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3169 switch (elf_section_data (p
)->this_hdr
.sh_type
)
3173 /* If sh_type is yet undecided, assume it could be
3174 SHT_PROGBITS/SHT_NOBITS. */
3178 /* There shouldn't be section relative relocations
3179 against any other section. */
3185 /* Create a .got section, as well as its additional info field. This
3186 is almost entirely copied from
3187 elflink.c:_bfd_elf_create_got_section(). */
3190 _bfin_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3192 flagword flags
, pltflags
;
3194 struct elf_link_hash_entry
*h
;
3195 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3198 /* This function may be called more than once. */
3199 s
= elf_hash_table (info
)->sgot
;
3203 /* Machine specific: although pointers are 32-bits wide, we want the
3204 GOT to be aligned to a 64-bit boundary, such that function
3205 descriptors in it can be accessed with 64-bit loads and
3209 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3210 | SEC_LINKER_CREATED
);
3213 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3214 elf_hash_table (info
)->sgot
= s
;
3216 || !bfd_set_section_alignment (s
, ptralign
))
3219 if (bed
->want_got_sym
)
3221 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
3222 (or .got.plt) section. We don't do this in the linker script
3223 because we don't want to define the symbol if we are not creating
3224 a global offset table. */
3225 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "__GLOBAL_OFFSET_TABLE_");
3226 elf_hash_table (info
)->hgot
= h
;
3230 /* Machine-specific: we want the symbol for executables as
3232 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3236 /* The first bit of the global offset table is the header. */
3237 s
->size
+= bed
->got_header_size
;
3239 /* This is the machine-specific part. Create and initialize section
3240 data for the got. */
3241 if (IS_FDPIC (abfd
))
3243 bfinfdpic_relocs_info (info
) = htab_try_create (1,
3244 bfinfdpic_relocs_info_hash
,
3245 bfinfdpic_relocs_info_eq
,
3247 if (! bfinfdpic_relocs_info (info
))
3250 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.got",
3251 (flags
| SEC_READONLY
));
3253 || !bfd_set_section_alignment (s
, 2))
3256 bfinfdpic_gotrel_section (info
) = s
;
3258 /* Machine-specific. */
3259 s
= bfd_make_section_anyway_with_flags (abfd
, ".rofixup",
3260 (flags
| SEC_READONLY
));
3262 || !bfd_set_section_alignment (s
, 2))
3265 bfinfdpic_gotfixup_section (info
) = s
;
3268 pltflags
|= SEC_CODE
;
3269 if (bed
->plt_not_loaded
)
3270 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
3271 if (bed
->plt_readonly
)
3272 pltflags
|= SEC_READONLY
;
3274 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", pltflags
);
3276 || !bfd_set_section_alignment (s
, bed
->plt_alignment
))
3278 /* Blackfin-specific: remember it. */
3279 bfinfdpic_plt_section (info
) = s
;
3281 if (bed
->want_plt_sym
)
3283 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3285 struct bfd_link_hash_entry
*bh
= NULL
;
3287 if (! (_bfd_generic_link_add_one_symbol
3288 (info
, abfd
, "__PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
, 0, NULL
,
3289 false, get_elf_backend_data (abfd
)->collect
, &bh
)))
3291 h
= (struct elf_link_hash_entry
*) bh
;
3293 h
->type
= STT_OBJECT
;
3295 if (! bfd_link_executable (info
)
3296 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3300 /* Blackfin-specific: we want rel relocations for the plt. */
3301 s
= bfd_make_section_anyway_with_flags (abfd
, ".rel.plt",
3302 flags
| SEC_READONLY
);
3304 || !bfd_set_section_alignment (s
, bed
->s
->log_file_align
))
3306 /* Blackfin-specific: remember it. */
3307 bfinfdpic_pltrel_section (info
) = s
;
3312 /* Make sure the got and plt sections exist, and that our pointers in
3313 the link hash table point to them. */
3316 elf32_bfinfdpic_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3318 /* This is mostly copied from
3319 elflink.c:_bfd_elf_create_dynamic_sections(). */
3322 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3324 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3325 | SEC_LINKER_CREATED
);
3327 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3328 .rel[a].bss sections. */
3330 /* Blackfin-specific: we want to create the GOT in the Blackfin way. */
3331 if (! _bfin_create_got_section (abfd
, info
))
3334 /* Blackfin-specific: make sure we created everything we wanted. */
3335 BFD_ASSERT (bfinfdpic_got_section (info
) && bfinfdpic_gotrel_section (info
)
3336 /* && bfinfdpic_gotfixup_section (info) */
3337 && bfinfdpic_plt_section (info
)
3338 && bfinfdpic_pltrel_section (info
));
3340 if (bed
->want_dynbss
)
3342 /* The .dynbss section is a place to put symbols which are defined
3343 by dynamic objects, are referenced by regular objects, and are
3344 not functions. We must allocate space for them in the process
3345 image and use a R_*_COPY reloc to tell the dynamic linker to
3346 initialize them at run time. The linker script puts the .dynbss
3347 section into the .bss section of the final image. */
3348 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynbss",
3349 SEC_ALLOC
| SEC_LINKER_CREATED
);
3353 /* The .rel[a].bss section holds copy relocs. This section is not
3354 normally needed. We need to create it here, though, so that the
3355 linker will map it to an output section. We can't just create it
3356 only if we need it, because we will not know whether we need it
3357 until we have seen all the input files, and the first time the
3358 main linker code calls BFD after examining all the input files
3359 (size_dynamic_sections) the input sections have already been
3360 mapped to the output sections. If the section turns out not to
3361 be needed, we can discard it later. We will never need this
3362 section when generating a shared object, since they do not use
3364 if (! bfd_link_pic (info
))
3366 s
= bfd_make_section_anyway_with_flags (abfd
,
3368 flags
| SEC_READONLY
);
3370 || !bfd_set_section_alignment (s
, bed
->s
->log_file_align
))
3378 /* Compute the total GOT size required by each symbol in each range.
3379 Symbols may require up to 4 words in the GOT: an entry pointing to
3380 the symbol, an entry pointing to its function descriptor, and a
3381 private function descriptors taking two words. */
3384 _bfinfdpic_count_nontls_entries (struct bfinfdpic_relocs_info
*entry
,
3385 struct _bfinfdpic_dynamic_got_info
*dinfo
)
3387 /* Allocate space for a GOT entry pointing to the symbol. */
3389 dinfo
->got17m4
+= 4;
3390 else if (entry
->gothilo
)
3391 dinfo
->gothilo
+= 4;
3396 /* Allocate space for a GOT entry pointing to the function
3398 if (entry
->fdgot17m4
)
3399 dinfo
->got17m4
+= 4;
3400 else if (entry
->fdgothilo
)
3401 dinfo
->gothilo
+= 4;
3406 /* Decide whether we need a PLT entry, a function descriptor in the
3407 GOT, and a lazy PLT entry for this symbol. */
3408 entry
->plt
= entry
->call
3409 && entry
->symndx
== -1 && ! BFINFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
3410 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
3411 entry
->privfd
= entry
->plt
3412 || entry
->fdgoff17m4
|| entry
->fdgoffhilo
3413 || ((entry
->fd
|| entry
->fdgot17m4
|| entry
->fdgothilo
)
3414 && (entry
->symndx
!= -1
3415 || BFINFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
)));
3416 entry
->lazyplt
= entry
->privfd
3417 && entry
->symndx
== -1 && ! BFINFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
)
3418 && ! (dinfo
->info
->flags
& DF_BIND_NOW
)
3419 && elf_hash_table (dinfo
->info
)->dynamic_sections_created
;
3421 /* Allocate space for a function descriptor. */
3422 if (entry
->fdgoff17m4
)
3424 else if (entry
->privfd
&& entry
->plt
)
3426 else if (entry
->privfd
)
3433 dinfo
->lzplt
+= LZPLT_NORMAL_SIZE
;
3436 /* Compute the number of dynamic relocations and fixups that a symbol
3437 requires, and add (or subtract) from the grand and per-symbol
3441 _bfinfdpic_count_relocs_fixups (struct bfinfdpic_relocs_info
*entry
,
3442 struct _bfinfdpic_dynamic_got_info
*dinfo
,
3445 bfd_vma relocs
= 0, fixups
= 0;
3447 if (!bfd_link_pde (dinfo
->info
))
3448 relocs
= entry
->relocs32
+ entry
->relocsfd
+ entry
->relocsfdv
;
3451 if (entry
->symndx
!= -1 || BFINFDPIC_SYM_LOCAL (dinfo
->info
, entry
->d
.h
))
3453 if (entry
->symndx
!= -1
3454 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
3455 fixups
+= entry
->relocs32
+ 2 * entry
->relocsfdv
;
3458 relocs
+= entry
->relocs32
+ entry
->relocsfdv
;
3460 if (entry
->symndx
!= -1
3461 || BFINFDPIC_FUNCDESC_LOCAL (dinfo
->info
, entry
->d
.h
))
3463 if (entry
->symndx
!= -1
3464 || entry
->d
.h
->root
.type
!= bfd_link_hash_undefweak
)
3465 fixups
+= entry
->relocsfd
;
3468 relocs
+= entry
->relocsfd
;
3477 entry
->dynrelocs
+= relocs
;
3478 entry
->fixups
+= fixups
;
3479 dinfo
->relocs
+= relocs
;
3480 dinfo
->fixups
+= fixups
;
3483 /* Compute the total GOT and PLT size required by each symbol in each range. *
3484 Symbols may require up to 4 words in the GOT: an entry pointing to
3485 the symbol, an entry pointing to its function descriptor, and a
3486 private function descriptors taking two words. */
3489 _bfinfdpic_count_got_plt_entries (void **entryp
, void *dinfo_
)
3491 struct bfinfdpic_relocs_info
*entry
= *entryp
;
3492 struct _bfinfdpic_dynamic_got_info
*dinfo
= dinfo_
;
3494 _bfinfdpic_count_nontls_entries (entry
, dinfo
);
3496 _bfinfdpic_count_relocs_fixups (entry
, dinfo
, false);
3501 /* This structure is used to assign offsets to got entries, function
3502 descriptors, plt entries and lazy plt entries. */
3504 struct _bfinfdpic_dynamic_got_plt_info
3506 /* Summary information collected with _bfinfdpic_count_got_plt_entries. */
3507 struct _bfinfdpic_dynamic_got_info g
;
3509 /* For each addressable range, we record a MAX (positive) and MIN
3510 (negative) value. CUR is used to assign got entries, and it's
3511 incremented from an initial positive value to MAX, then from MIN
3512 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
3513 assign function descriptors, and it's decreased from an initial
3514 non-positive value to MIN, then from MAX down to CUR (unless CUR
3515 wraps around first). All of MIN, MAX, CUR and FDCUR always point
3516 to even words. ODD, if non-zero, indicates an odd word to be
3517 used for the next got entry, otherwise CUR is used and
3518 incremented by a pair of words, wrapping around when it reaches
3519 MAX. FDCUR is decremented (and wrapped) before the next function
3520 descriptor is chosen. FDPLT indicates the number of remaining
3521 slots that can be used for function descriptors used only by PLT
3523 struct _bfinfdpic_dynamic_got_alloc_data
3525 bfd_signed_vma max
, cur
, odd
, fdcur
, min
;
3530 /* Determine the positive and negative ranges to be used by each
3531 offset range in the GOT. FDCUR and CUR, that must be aligned to a
3532 double-word boundary, are the minimum (negative) and maximum
3533 (positive) GOT offsets already used by previous ranges, except for
3534 an ODD entry that may have been left behind. GOT and FD indicate
3535 the size of GOT entries and function descriptors that must be
3536 placed within the range from -WRAP to WRAP. If there's room left,
3537 up to FDPLT bytes should be reserved for additional function
3540 inline static bfd_signed_vma
3541 _bfinfdpic_compute_got_alloc_data (struct _bfinfdpic_dynamic_got_alloc_data
*gad
,
3542 bfd_signed_vma fdcur
,
3550 bfd_signed_vma wrapmin
= -wrap
;
3552 /* Start at the given initial points. */
3556 /* If we had an incoming odd word and we have any got entries that
3557 are going to use it, consume it, otherwise leave gad->odd at
3558 zero. We might force gad->odd to zero and return the incoming
3559 odd such that it is used by the next range, but then GOT entries
3560 might appear to be out of order and we wouldn't be able to
3561 shorten the GOT by one word if it turns out to end with an
3562 unpaired GOT entry. */
3572 /* If we're left with an unpaired GOT entry, compute its location
3573 such that we can return it. Otherwise, if got doesn't require an
3574 odd number of words here, either odd was already zero in the
3575 block above, or it was set to zero because got was non-zero, or
3576 got was already zero. In the latter case, we want the value of
3577 odd to carry over to the return statement, so we don't want to
3578 reset odd unless the condition below is true. */
3585 /* Compute the tentative boundaries of this range. */
3586 gad
->max
= cur
+ got
;
3587 gad
->min
= fdcur
- fd
;
3590 /* If function descriptors took too much space, wrap some of them
3592 if (gad
->min
< wrapmin
)
3594 gad
->max
+= wrapmin
- gad
->min
;
3597 /* If there is space left and we have function descriptors
3598 referenced in PLT entries that could take advantage of shorter
3599 offsets, place them here. */
3600 else if (fdplt
&& gad
->min
> wrapmin
)
3603 if ((bfd_vma
) (gad
->min
- wrapmin
) < fdplt
)
3604 fds
= gad
->min
- wrapmin
;
3613 /* If GOT entries took too much space, wrap some of them around.
3614 This may well cause gad->min to become lower than wrapmin. This
3615 will cause a relocation overflow later on, so we don't have to
3617 if ((bfd_vma
) gad
->max
> wrap
)
3619 gad
->min
-= gad
->max
- wrap
;
3622 /* If there is more space left, try to place some more function
3623 descriptors for PLT entries. */
3624 else if (fdplt
&& (bfd_vma
) gad
->max
< wrap
)
3627 if ((bfd_vma
) (wrap
- gad
->max
) < fdplt
)
3628 fds
= wrap
- gad
->max
;
3637 /* If odd was initially computed as an offset past the wrap point,
3640 odd
= gad
->min
+ odd
- gad
->max
;
3642 /* _bfinfdpic_get_got_entry() below will always wrap gad->cur if needed
3643 before returning, so do it here too. This guarantees that,
3644 should cur and fdcur meet at the wrap point, they'll both be
3646 if (gad
->cur
== gad
->max
)
3647 gad
->cur
= gad
->min
;
3652 /* Compute the location of the next GOT entry, given the allocation
3653 data for a range. */
3655 inline static bfd_signed_vma
3656 _bfinfdpic_get_got_entry (struct _bfinfdpic_dynamic_got_alloc_data
*gad
)
3662 /* If there was an odd word left behind, use it. */
3668 /* Otherwise, use the word pointed to by cur, reserve the next
3669 as an odd word, and skip to the next pair of words, possibly
3672 gad
->odd
= gad
->cur
+ 4;
3674 if (gad
->cur
== gad
->max
)
3675 gad
->cur
= gad
->min
;
3681 /* Compute the location of the next function descriptor entry in the
3682 GOT, given the allocation data for a range. */
3684 inline static bfd_signed_vma
3685 _bfinfdpic_get_fd_entry (struct _bfinfdpic_dynamic_got_alloc_data
*gad
)
3687 /* If we're at the bottom, wrap around, and only then allocate the
3688 next pair of words. */
3689 if (gad
->fdcur
== gad
->min
)
3690 gad
->fdcur
= gad
->max
;
3691 return gad
->fdcur
-= 8;
3694 /* Assign GOT offsets for every GOT entry and function descriptor.
3695 Doing everything in a single pass is tricky. */
3698 _bfinfdpic_assign_got_entries (void **entryp
, void *info_
)
3700 struct bfinfdpic_relocs_info
*entry
= *entryp
;
3701 struct _bfinfdpic_dynamic_got_plt_info
*dinfo
= info_
;
3704 entry
->got_entry
= _bfinfdpic_get_got_entry (&dinfo
->got17m4
);
3705 else if (entry
->gothilo
)
3706 entry
->got_entry
= _bfinfdpic_get_got_entry (&dinfo
->gothilo
);
3708 if (entry
->fdgot17m4
)
3709 entry
->fdgot_entry
= _bfinfdpic_get_got_entry (&dinfo
->got17m4
);
3710 else if (entry
->fdgothilo
)
3711 entry
->fdgot_entry
= _bfinfdpic_get_got_entry (&dinfo
->gothilo
);
3713 if (entry
->fdgoff17m4
)
3714 entry
->fd_entry
= _bfinfdpic_get_fd_entry (&dinfo
->got17m4
);
3715 else if (entry
->plt
&& dinfo
->got17m4
.fdplt
)
3717 dinfo
->got17m4
.fdplt
-= 8;
3718 entry
->fd_entry
= _bfinfdpic_get_fd_entry (&dinfo
->got17m4
);
3720 else if (entry
->plt
)
3722 dinfo
->gothilo
.fdplt
-= 8;
3723 entry
->fd_entry
= _bfinfdpic_get_fd_entry (&dinfo
->gothilo
);
3725 else if (entry
->privfd
)
3726 entry
->fd_entry
= _bfinfdpic_get_fd_entry (&dinfo
->gothilo
);
3731 /* Assign GOT offsets to private function descriptors used by PLT
3732 entries (or referenced by 32-bit offsets), as well as PLT entries
3733 and lazy PLT entries. */
3736 _bfinfdpic_assign_plt_entries (void **entryp
, void *info_
)
3738 struct bfinfdpic_relocs_info
*entry
= *entryp
;
3739 struct _bfinfdpic_dynamic_got_plt_info
*dinfo
= info_
;
3741 /* If this symbol requires a local function descriptor, allocate
3743 if (entry
->privfd
&& entry
->fd_entry
== 0)
3745 if (dinfo
->got17m4
.fdplt
)
3747 entry
->fd_entry
= _bfinfdpic_get_fd_entry (&dinfo
->got17m4
);
3748 dinfo
->got17m4
.fdplt
-= 8;
3752 BFD_ASSERT (dinfo
->gothilo
.fdplt
);
3753 entry
->fd_entry
= _bfinfdpic_get_fd_entry (&dinfo
->gothilo
);
3754 dinfo
->gothilo
.fdplt
-= 8;
3762 /* We use the section's raw size to mark the location of the
3764 entry
->plt_entry
= bfinfdpic_plt_section (dinfo
->g
.info
)->size
;
3766 /* Figure out the length of this PLT entry based on the
3767 addressing mode we need to reach the function descriptor. */
3768 BFD_ASSERT (entry
->fd_entry
);
3769 if (entry
->fd_entry
>= -(1 << (18 - 1))
3770 && entry
->fd_entry
+ 4 < (1 << (18 - 1)))
3775 bfinfdpic_plt_section (dinfo
->g
.info
)->size
+= size
;
3780 entry
->lzplt_entry
= dinfo
->g
.lzplt
;
3781 dinfo
->g
.lzplt
+= LZPLT_NORMAL_SIZE
;
3782 /* If this entry is the one that gets the resolver stub, account
3783 for the additional instruction. */
3784 if (entry
->lzplt_entry
% BFINFDPIC_LZPLT_BLOCK_SIZE
3785 == BFINFDPIC_LZPLT_RESOLV_LOC
)
3786 dinfo
->g
.lzplt
+= LZPLT_RESOLVER_EXTRA
;
3792 /* Cancel out any effects of calling _bfinfdpic_assign_got_entries and
3793 _bfinfdpic_assign_plt_entries. */
3796 _bfinfdpic_reset_got_plt_entries (void **entryp
, void *ignore ATTRIBUTE_UNUSED
)
3798 struct bfinfdpic_relocs_info
*entry
= *entryp
;
3800 entry
->got_entry
= 0;
3801 entry
->fdgot_entry
= 0;
3802 entry
->fd_entry
= 0;
3803 entry
->plt_entry
= (bfd_vma
)-1;
3804 entry
->lzplt_entry
= (bfd_vma
)-1;
3809 /* Follow indirect and warning hash entries so that each got entry
3810 points to the final symbol definition. P must point to a pointer
3811 to the hash table we're traversing. Since this traversal may
3812 modify the hash table, we set this pointer to NULL to indicate
3813 we've made a potentially-destructive change to the hash table, so
3814 the traversal must be restarted. */
3816 _bfinfdpic_resolve_final_relocs_info (void **entryp
, void *p
)
3818 struct bfinfdpic_relocs_info
*entry
= *entryp
;
3821 if (entry
->symndx
== -1)
3823 struct elf_link_hash_entry
*h
= entry
->d
.h
;
3824 struct bfinfdpic_relocs_info
*oentry
;
3826 while (h
->root
.type
== bfd_link_hash_indirect
3827 || h
->root
.type
== bfd_link_hash_warning
)
3828 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
3830 if (entry
->d
.h
== h
)
3833 oentry
= bfinfdpic_relocs_info_for_global (*htab
, 0, h
, entry
->addend
,
3838 /* Merge the two entries. */
3839 bfinfdpic_pic_merge_early_relocs_info (oentry
, entry
);
3840 htab_clear_slot (*htab
, entryp
);
3846 /* If we can't find this entry with the new bfd hash, re-insert
3847 it, and get the traversal restarted. */
3848 if (! htab_find (*htab
, entry
))
3850 htab_clear_slot (*htab
, entryp
);
3851 entryp
= htab_find_slot (*htab
, entry
, INSERT
);
3854 /* Abort the traversal, since the whole table may have
3855 moved, and leave it up to the parent to restart the
3857 *(htab_t
*)p
= NULL
;
3865 /* Compute the total size of the GOT, the PLT, the dynamic relocations
3866 section and the rofixup section. Assign locations for GOT and PLT
3870 _bfinfdpic_size_got_plt (bfd
*output_bfd
,
3871 struct _bfinfdpic_dynamic_got_plt_info
*gpinfop
)
3875 struct bfd_link_info
*info
= gpinfop
->g
.info
;
3876 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
3878 memcpy (bfinfdpic_dynamic_got_plt_info (info
), &gpinfop
->g
,
3879 sizeof (gpinfop
->g
));
3882 /* Compute the total size taken by entries in the 18-bit range,
3883 to tell how many PLT function descriptors we can bring into it
3884 without causing it to overflow. */
3885 limit
= odd
+ gpinfop
->g
.got17m4
+ gpinfop
->g
.fd17m4
;
3886 if (limit
< (bfd_vma
)1 << 18)
3887 limit
= ((bfd_vma
)1 << 18) - limit
;
3890 if (gpinfop
->g
.fdplt
< limit
)
3891 limit
= gpinfop
->g
.fdplt
;
3893 /* Determine the ranges of GOT offsets that we can use for each
3894 range of addressing modes. */
3895 odd
= _bfinfdpic_compute_got_alloc_data (&gpinfop
->got17m4
,
3902 (bfd_vma
)1 << (18-1));
3903 odd
= _bfinfdpic_compute_got_alloc_data (&gpinfop
->gothilo
,
3904 gpinfop
->got17m4
.min
,
3906 gpinfop
->got17m4
.max
,
3909 gpinfop
->g
.fdplt
- gpinfop
->got17m4
.fdplt
,
3910 (bfd_vma
)1 << (32-1));
3912 /* Now assign (most) GOT offsets. */
3913 htab_traverse (bfinfdpic_relocs_info (info
), _bfinfdpic_assign_got_entries
,
3916 bfinfdpic_got_section (info
)->size
= gpinfop
->gothilo
.max
3917 - gpinfop
->gothilo
.min
3918 /* If an odd word is the last word of the GOT, we don't need this
3919 word to be part of the GOT. */
3920 - (odd
+ 4 == gpinfop
->gothilo
.max
? 4 : 0);
3921 if (bfinfdpic_got_section (info
)->size
== 0)
3922 bfinfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
3923 else if (bfinfdpic_got_section (info
)->size
== 12
3924 && ! elf_hash_table (info
)->dynamic_sections_created
)
3926 bfinfdpic_got_section (info
)->flags
|= SEC_EXCLUDE
;
3927 bfinfdpic_got_section (info
)->size
= 0;
3931 bfinfdpic_got_section (info
)->contents
=
3932 (bfd_byte
*) bfd_zalloc (dynobj
,
3933 bfinfdpic_got_section (info
)->size
);
3934 if (bfinfdpic_got_section (info
)->contents
== NULL
)
3938 if (elf_hash_table (info
)->dynamic_sections_created
)
3939 /* Subtract the number of lzplt entries, since those will generate
3940 relocations in the pltrel section. */
3941 bfinfdpic_gotrel_section (info
)->size
=
3942 (gpinfop
->g
.relocs
- gpinfop
->g
.lzplt
/ LZPLT_NORMAL_SIZE
)
3943 * get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
3945 BFD_ASSERT (gpinfop
->g
.relocs
== 0);
3946 if (bfinfdpic_gotrel_section (info
)->size
== 0)
3947 bfinfdpic_gotrel_section (info
)->flags
|= SEC_EXCLUDE
;
3950 bfinfdpic_gotrel_section (info
)->contents
=
3951 (bfd_byte
*) bfd_zalloc (dynobj
,
3952 bfinfdpic_gotrel_section (info
)->size
);
3953 if (bfinfdpic_gotrel_section (info
)->contents
== NULL
)
3957 bfinfdpic_gotfixup_section (info
)->size
= (gpinfop
->g
.fixups
+ 1) * 4;
3958 if (bfinfdpic_gotfixup_section (info
)->size
== 0)
3959 bfinfdpic_gotfixup_section (info
)->flags
|= SEC_EXCLUDE
;
3962 bfinfdpic_gotfixup_section (info
)->contents
=
3963 (bfd_byte
*) bfd_zalloc (dynobj
,
3964 bfinfdpic_gotfixup_section (info
)->size
);
3965 if (bfinfdpic_gotfixup_section (info
)->contents
== NULL
)
3969 if (elf_hash_table (info
)->dynamic_sections_created
)
3970 bfinfdpic_pltrel_section (info
)->size
=
3971 gpinfop
->g
.lzplt
/ LZPLT_NORMAL_SIZE
* get_elf_backend_data (output_bfd
)->s
->sizeof_rel
;
3972 if (bfinfdpic_pltrel_section (info
)->size
== 0)
3973 bfinfdpic_pltrel_section (info
)->flags
|= SEC_EXCLUDE
;
3976 bfinfdpic_pltrel_section (info
)->contents
=
3977 (bfd_byte
*) bfd_zalloc (dynobj
,
3978 bfinfdpic_pltrel_section (info
)->size
);
3979 if (bfinfdpic_pltrel_section (info
)->contents
== NULL
)
3983 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
3984 such that there's room for the additional instruction needed to
3985 call the resolver. Since _bfinfdpic_assign_got_entries didn't
3986 account for them, our block size is 4 bytes smaller than the real
3988 if (elf_hash_table (info
)->dynamic_sections_created
)
3990 bfinfdpic_plt_section (info
)->size
= gpinfop
->g
.lzplt
3991 + ((gpinfop
->g
.lzplt
+ (BFINFDPIC_LZPLT_BLOCK_SIZE
- 4) - LZPLT_NORMAL_SIZE
)
3992 / (BFINFDPIC_LZPLT_BLOCK_SIZE
- 4) * LZPLT_RESOLVER_EXTRA
);
3995 /* Reset it, such that _bfinfdpic_assign_plt_entries() can use it to
3996 actually assign lazy PLT entries addresses. */
3997 gpinfop
->g
.lzplt
= 0;
3999 /* Save information that we're going to need to generate GOT and PLT
4001 bfinfdpic_got_initial_offset (info
) = -gpinfop
->gothilo
.min
;
4003 if (get_elf_backend_data (output_bfd
)->want_got_sym
)
4004 elf_hash_table (info
)->hgot
->root
.u
.def
.value
4005 = bfinfdpic_got_initial_offset (info
);
4007 if (elf_hash_table (info
)->dynamic_sections_created
)
4008 bfinfdpic_plt_initial_offset (info
) =
4009 bfinfdpic_plt_section (info
)->size
;
4011 htab_traverse (bfinfdpic_relocs_info (info
), _bfinfdpic_assign_plt_entries
,
4014 /* Allocate the PLT section contents only after
4015 _bfinfdpic_assign_plt_entries has a chance to add the size of the
4016 non-lazy PLT entries. */
4017 if (bfinfdpic_plt_section (info
)->size
== 0)
4018 bfinfdpic_plt_section (info
)->flags
|= SEC_EXCLUDE
;
4021 bfinfdpic_plt_section (info
)->contents
=
4022 (bfd_byte
*) bfd_zalloc (dynobj
,
4023 bfinfdpic_plt_section (info
)->size
);
4024 if (bfinfdpic_plt_section (info
)->contents
== NULL
)
4031 /* Set the sizes of the dynamic sections. */
4034 elf32_bfinfdpic_size_dynamic_sections (bfd
*output_bfd
,
4035 struct bfd_link_info
*info
)
4037 struct elf_link_hash_table
*htab
;
4040 struct _bfinfdpic_dynamic_got_plt_info gpinfo
;
4042 htab
= elf_hash_table (info
);
4043 dynobj
= htab
->dynobj
;
4044 BFD_ASSERT (dynobj
!= NULL
);
4046 if (htab
->dynamic_sections_created
)
4048 /* Set the contents of the .interp section to the interpreter. */
4049 if (bfd_link_executable (info
) && !info
->nointerp
)
4051 s
= bfd_get_linker_section (dynobj
, ".interp");
4052 BFD_ASSERT (s
!= NULL
);
4053 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4054 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
4058 memset (&gpinfo
, 0, sizeof (gpinfo
));
4059 gpinfo
.g
.info
= info
;
4063 htab_t relocs
= bfinfdpic_relocs_info (info
);
4065 htab_traverse (relocs
, _bfinfdpic_resolve_final_relocs_info
, &relocs
);
4067 if (relocs
== bfinfdpic_relocs_info (info
))
4071 htab_traverse (bfinfdpic_relocs_info (info
), _bfinfdpic_count_got_plt_entries
,
4074 /* Allocate space to save the summary information, we're going to
4075 use it if we're doing relaxations. */
4076 bfinfdpic_dynamic_got_plt_info (info
) = bfd_alloc (dynobj
, sizeof (gpinfo
.g
));
4078 if (!_bfinfdpic_size_got_plt (output_bfd
, &gpinfo
))
4081 s
= bfd_get_linker_section (dynobj
, ".dynbss");
4082 if (s
&& s
->size
== 0)
4083 s
->flags
|= SEC_EXCLUDE
;
4085 s
= bfd_get_linker_section (dynobj
, ".rela.bss");
4086 if (s
&& s
->size
== 0)
4087 s
->flags
|= SEC_EXCLUDE
;
4089 return _bfd_elf_add_dynamic_tags (output_bfd
, info
, true);
4093 elf32_bfinfdpic_always_size_sections (bfd
*output_bfd
,
4094 struct bfd_link_info
*info
)
4096 if (!bfd_link_relocatable (info
)
4097 && !bfd_elf_stack_segment_size (output_bfd
, info
,
4098 "__stacksize", DEFAULT_STACK_SIZE
))
4104 /* Check whether any of the relocations was optimized away, and
4105 subtract it from the relocation or fixup count. */
4107 _bfinfdpic_check_discarded_relocs (bfd
*abfd
, asection
*sec
,
4108 struct bfd_link_info
*info
,
4111 Elf_Internal_Shdr
*symtab_hdr
;
4112 struct elf_link_hash_entry
**sym_hashes
;
4113 Elf_Internal_Rela
*rel
, *erel
;
4115 if ((sec
->flags
& SEC_RELOC
) == 0
4116 || sec
->reloc_count
== 0)
4119 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4120 sym_hashes
= elf_sym_hashes (abfd
);
4122 rel
= elf_section_data (sec
)->relocs
;
4124 /* Now examine each relocation. */
4125 for (erel
= rel
+ sec
->reloc_count
; rel
< erel
; rel
++)
4127 struct elf_link_hash_entry
*h
;
4128 unsigned long r_symndx
;
4129 struct bfinfdpic_relocs_info
*picrel
;
4130 struct _bfinfdpic_dynamic_got_info
*dinfo
;
4132 if (ELF32_R_TYPE (rel
->r_info
) != R_BFIN_BYTE4_DATA
4133 && ELF32_R_TYPE (rel
->r_info
) != R_BFIN_FUNCDESC
)
4136 if (_bfd_elf_section_offset (sec
->output_section
->owner
,
4137 info
, sec
, rel
->r_offset
)
4141 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4142 if (r_symndx
< symtab_hdr
->sh_info
)
4146 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4147 while (h
->root
.type
== bfd_link_hash_indirect
4148 || h
->root
.type
== bfd_link_hash_warning
)
4149 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
4153 picrel
= bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info (info
),
4155 rel
->r_addend
, NO_INSERT
);
4157 picrel
= bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info (info
),
4159 rel
->r_addend
, NO_INSERT
);
4165 dinfo
= bfinfdpic_dynamic_got_plt_info (info
);
4167 _bfinfdpic_count_relocs_fixups (picrel
, dinfo
, true);
4168 if (ELF32_R_TYPE (rel
->r_info
) == R_BFIN_BYTE4_DATA
)
4170 else /* we know (ELF32_R_TYPE (rel->r_info) == R_BFIN_FUNCDESC) */
4172 _bfinfdpic_count_relocs_fixups (picrel
, dinfo
, false);
4179 bfinfdpic_elf_discard_info (bfd
*ibfd
,
4180 struct elf_reloc_cookie
*cookie ATTRIBUTE_UNUSED
,
4181 struct bfd_link_info
*info
)
4183 bool changed
= false;
4187 /* Account for relaxation of .eh_frame section. */
4188 for (s
= ibfd
->sections
; s
; s
= s
->next
)
4189 if (s
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4191 if (!_bfinfdpic_check_discarded_relocs (ibfd
, s
, info
, &changed
))
4193 obfd
= s
->output_section
->owner
;
4198 struct _bfinfdpic_dynamic_got_plt_info gpinfo
;
4200 memset (&gpinfo
, 0, sizeof (gpinfo
));
4201 memcpy (&gpinfo
.g
, bfinfdpic_dynamic_got_plt_info (info
),
4204 /* Clear GOT and PLT assignments. */
4205 htab_traverse (bfinfdpic_relocs_info (info
),
4206 _bfinfdpic_reset_got_plt_entries
,
4209 if (!_bfinfdpic_size_got_plt (obfd
, &gpinfo
))
4217 elf32_bfinfdpic_finish_dynamic_sections (bfd
*output_bfd
,
4218 struct bfd_link_info
*info
)
4223 dynobj
= elf_hash_table (info
)->dynobj
;
4225 if (bfinfdpic_got_section (info
))
4227 BFD_ASSERT (bfinfdpic_gotrel_section (info
)->size
4228 /* PR 17334: It appears that the GOT section can end up
4229 being bigger than the number of relocs. Presumably
4230 because some relocs have been deleted. A test case has
4231 yet to be generated for verify this, but in the meantime
4232 the test below has been changed from == to >= so that
4233 applications can continue to be built. */
4234 >= (bfinfdpic_gotrel_section (info
)->reloc_count
4235 * sizeof (Elf32_External_Rel
)));
4237 if (bfinfdpic_gotfixup_section (info
))
4239 struct elf_link_hash_entry
*hgot
= elf_hash_table (info
)->hgot
;
4240 bfd_vma got_value
= hgot
->root
.u
.def
.value
4241 + hgot
->root
.u
.def
.section
->output_section
->vma
4242 + hgot
->root
.u
.def
.section
->output_offset
;
4244 _bfinfdpic_add_rofixup (output_bfd
, bfinfdpic_gotfixup_section (info
),
4247 if (bfinfdpic_gotfixup_section (info
)->size
4248 != (bfinfdpic_gotfixup_section (info
)->reloc_count
* 4))
4251 ("LINKER BUG: .rofixup section size mismatch");
4256 if (elf_hash_table (info
)->dynamic_sections_created
)
4258 BFD_ASSERT (bfinfdpic_pltrel_section (info
)->size
4259 == (bfinfdpic_pltrel_section (info
)->reloc_count
4260 * sizeof (Elf32_External_Rel
)));
4263 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4265 if (elf_hash_table (info
)->dynamic_sections_created
)
4267 Elf32_External_Dyn
* dyncon
;
4268 Elf32_External_Dyn
* dynconend
;
4270 BFD_ASSERT (sdyn
!= NULL
);
4272 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4273 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4275 for (; dyncon
< dynconend
; dyncon
++)
4277 Elf_Internal_Dyn dyn
;
4279 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4287 dyn
.d_un
.d_ptr
= bfinfdpic_got_section (info
)->output_section
->vma
4288 + bfinfdpic_got_section (info
)->output_offset
4289 + bfinfdpic_got_initial_offset (info
);
4290 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4294 dyn
.d_un
.d_ptr
= bfinfdpic_pltrel_section (info
)
4295 ->output_section
->vma
4296 + bfinfdpic_pltrel_section (info
)->output_offset
;
4297 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4301 dyn
.d_un
.d_val
= bfinfdpic_pltrel_section (info
)->size
;
4302 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4311 /* Adjust a symbol defined by a dynamic object and referenced by a
4315 elf32_bfinfdpic_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4316 struct elf_link_hash_entry
*h
)
4320 dynobj
= elf_hash_table (info
)->dynobj
;
4322 /* Make sure we know what is going on here. */
4323 BFD_ASSERT (dynobj
!= NULL
4327 && !h
->def_regular
)));
4329 /* If this is a weak symbol, and there is a real definition, the
4330 processor independent code will have arranged for us to see the
4331 real definition first, and we can just use the same value. */
4332 if (h
->is_weakalias
)
4334 struct elf_link_hash_entry
*def
= weakdef (h
);
4335 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
4336 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
4337 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
4343 /* Perform any actions needed for dynamic symbols. */
4346 elf32_bfinfdpic_finish_dynamic_symbol
4347 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4348 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4349 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
4350 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
4355 /* Decide whether to attempt to turn absptr or lsda encodings in
4356 shared libraries into pcrel within the given input section. */
4359 bfinfdpic_elf_use_relative_eh_frame
4360 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
4361 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4362 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
4364 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
4368 /* Adjust the contents of an eh_frame_hdr section before they're output. */
4371 bfinfdpic_elf_encode_eh_address (bfd
*abfd
,
4372 struct bfd_link_info
*info
,
4373 asection
*osec
, bfd_vma offset
,
4374 asection
*loc_sec
, bfd_vma loc_offset
,
4377 struct elf_link_hash_entry
*h
;
4379 h
= elf_hash_table (info
)->hgot
;
4380 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
4382 if (! h
|| (_bfinfdpic_osec_to_segment (abfd
, osec
)
4383 == _bfinfdpic_osec_to_segment (abfd
, loc_sec
->output_section
)))
4384 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
4385 loc_sec
, loc_offset
, encoded
);
4387 BFD_ASSERT (_bfinfdpic_osec_to_segment (abfd
, osec
)
4388 == (_bfinfdpic_osec_to_segment
4389 (abfd
, h
->root
.u
.def
.section
->output_section
)));
4391 *encoded
= osec
->vma
+ offset
4392 - (h
->root
.u
.def
.value
4393 + h
->root
.u
.def
.section
->output_section
->vma
4394 + h
->root
.u
.def
.section
->output_offset
);
4396 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
4401 /* Look through the relocs for a section during the first phase.
4403 Besides handling virtual table relocs for gc, we have to deal with
4404 all sorts of PIC-related relocations. We describe below the
4405 general plan on how to handle such relocations, even though we only
4406 collect information at this point, storing them in hash tables for
4407 perusal of later passes.
4409 32 relocations are propagated to the linker output when creating
4410 position-independent output. LO16 and HI16 relocations are not
4411 supposed to be encountered in this case.
4413 LABEL16 should always be resolvable by the linker, since it's only
4416 LABEL24, on the other hand, is used by calls. If it turns out that
4417 the target of a call is a dynamic symbol, a PLT entry must be
4418 created for it, which triggers the creation of a private function
4419 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
4421 GPREL relocations require the referenced symbol to be in the same
4422 segment as _gp, but this can only be checked later.
4424 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
4425 exist. LABEL24 might as well, since it may require a PLT entry,
4426 that will require a got.
4428 Non-FUNCDESC GOT relocations require a GOT entry to be created
4429 regardless of whether the symbol is dynamic. However, since a
4430 global symbol that turns out to not be exported may have the same
4431 address of a non-dynamic symbol, we don't assign GOT entries at
4432 this point, such that we can share them in this case. A relocation
4433 for the GOT entry always has to be created, be it to offset a
4434 private symbol by the section load address, be it to get the symbol
4435 resolved dynamically.
4437 FUNCDESC GOT relocations require a GOT entry to be created, and
4438 handled as if a FUNCDESC relocation was applied to the GOT entry in
4441 FUNCDESC relocations referencing a symbol that turns out to NOT be
4442 dynamic cause a private function descriptor to be created. The
4443 FUNCDESC relocation then decays to a 32 relocation that points at
4444 the private descriptor. If the symbol is dynamic, the FUNCDESC
4445 relocation is propagated to the linker output, such that the
4446 dynamic linker creates the canonical descriptor, pointing to the
4447 dynamically-resolved definition of the function.
4449 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
4450 symbols that are assigned to the same segment as the GOT, but we
4451 can only check this later, after we know the complete set of
4452 symbols defined and/or exported.
4454 FUNCDESC GOTOFF relocations require a function descriptor to be
4455 created and, unless lazy binding is disabled or the symbol is not
4456 dynamic, a lazy PLT entry. Since we can't tell at this point
4457 whether a symbol is going to be dynamic, we have to decide later
4458 whether to create a lazy PLT entry or bind the descriptor directly
4459 to the private function.
4461 FUNCDESC_VALUE relocations are not supposed to be present in object
4462 files, but they may very well be simply propagated to the linker
4463 output, since they have no side effect.
4466 A function descriptor always requires a FUNCDESC_VALUE relocation.
4467 Whether it's in .plt.rel or not depends on whether lazy binding is
4468 enabled and on whether the referenced symbol is dynamic.
4470 The existence of a lazy PLT requires the resolverStub lazy PLT
4471 entry to be present.
4474 As for assignment of GOT, PLT and lazy PLT entries, and private
4475 descriptors, we might do them all sequentially, but we can do
4476 better than that. For example, we can place GOT entries and
4477 private function descriptors referenced using 12-bit operands
4478 closer to the PIC register value, such that these relocations don't
4479 overflow. Those that are only referenced with LO16 relocations
4480 could come next, but we may as well place PLT-required function
4481 descriptors in the 12-bit range to make them shorter. Symbols
4482 referenced with LO16/HI16 may come next, but we may place
4483 additional function descriptors in the 16-bit range if we can
4484 reliably tell that we've already placed entries that are ever
4485 referenced with only LO16. PLT entries are therefore generated as
4486 small as possible, while not introducing relocation overflows in
4487 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
4488 generated before or after PLT entries, but not intermingled with
4489 them, such that we can have more lazy PLT entries in range for a
4490 branch to the resolverStub. The resolverStub should be emitted at
4491 the most distant location from the first lazy PLT entry such that
4492 it's still in range for a branch, or closer, if there isn't a need
4493 for so many lazy PLT entries. Additional lazy PLT entries may be
4494 emitted after the resolverStub, as long as branches are still in
4495 range. If the branch goes out of range, longer lazy PLT entries
4498 We could further optimize PLT and lazy PLT entries by giving them
4499 priority in assignment to closer-to-gr17 locations depending on the
4500 number of occurrences of references to them (assuming a function
4501 that's called more often is more important for performance, so its
4502 PLT entry should be faster), or taking hints from the compiler.
4503 Given infinite time and money... :-) */
4506 bfinfdpic_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4507 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4509 Elf_Internal_Shdr
*symtab_hdr
;
4510 struct elf_link_hash_entry
**sym_hashes
;
4511 const Elf_Internal_Rela
*rel
;
4512 const Elf_Internal_Rela
*rel_end
;
4514 struct bfinfdpic_relocs_info
*picrel
;
4516 if (bfd_link_relocatable (info
))
4519 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4520 sym_hashes
= elf_sym_hashes (abfd
);
4522 dynobj
= elf_hash_table (info
)->dynobj
;
4523 rel_end
= relocs
+ sec
->reloc_count
;
4524 for (rel
= relocs
; rel
< rel_end
; rel
++)
4526 struct elf_link_hash_entry
*h
;
4527 unsigned long r_symndx
;
4529 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4530 if (r_symndx
< symtab_hdr
->sh_info
)
4534 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4535 while (h
->root
.type
== bfd_link_hash_indirect
4536 || h
->root
.type
== bfd_link_hash_warning
)
4537 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4540 switch (ELF32_R_TYPE (rel
->r_info
))
4542 case R_BFIN_GOT17M4
:
4545 case R_BFIN_FUNCDESC_GOT17M4
:
4546 case R_BFIN_FUNCDESC_GOTHI
:
4547 case R_BFIN_FUNCDESC_GOTLO
:
4548 case R_BFIN_GOTOFF17M4
:
4549 case R_BFIN_GOTOFFHI
:
4550 case R_BFIN_GOTOFFLO
:
4551 case R_BFIN_FUNCDESC_GOTOFF17M4
:
4552 case R_BFIN_FUNCDESC_GOTOFFHI
:
4553 case R_BFIN_FUNCDESC_GOTOFFLO
:
4554 case R_BFIN_FUNCDESC
:
4555 case R_BFIN_FUNCDESC_VALUE
:
4556 if (! IS_FDPIC (abfd
))
4559 case R_BFIN_PCREL24
:
4560 case R_BFIN_PCREL24_JUMP_L
:
4561 case R_BFIN_BYTE4_DATA
:
4562 if (IS_FDPIC (abfd
) && ! dynobj
)
4564 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4565 if (! _bfin_create_got_section (abfd
, info
))
4568 if (! IS_FDPIC (abfd
))
4575 if (h
->dynindx
== -1)
4576 switch (ELF_ST_VISIBILITY (h
->other
))
4582 bfd_elf_link_record_dynamic_symbol (info
, h
);
4586 = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info (info
),
4588 rel
->r_addend
, INSERT
);
4591 picrel
= bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info
4592 (info
), abfd
, r_symndx
,
4593 rel
->r_addend
, INSERT
);
4603 switch (ELF32_R_TYPE (rel
->r_info
))
4605 case R_BFIN_PCREL24
:
4606 case R_BFIN_PCREL24_JUMP_L
:
4607 if (IS_FDPIC (abfd
))
4611 case R_BFIN_FUNCDESC_VALUE
:
4612 picrel
->relocsfdv
++;
4613 if (bfd_section_flags (sec
) & SEC_ALLOC
)
4617 case R_BFIN_BYTE4_DATA
:
4618 if (! IS_FDPIC (abfd
))
4622 if (bfd_section_flags (sec
) & SEC_ALLOC
)
4626 case R_BFIN_GOT17M4
:
4635 case R_BFIN_FUNCDESC_GOT17M4
:
4636 picrel
->fdgot17m4
++;
4639 case R_BFIN_FUNCDESC_GOTHI
:
4640 case R_BFIN_FUNCDESC_GOTLO
:
4641 picrel
->fdgothilo
++;
4644 case R_BFIN_GOTOFF17M4
:
4645 case R_BFIN_GOTOFFHI
:
4646 case R_BFIN_GOTOFFLO
:
4650 case R_BFIN_FUNCDESC_GOTOFF17M4
:
4651 picrel
->fdgoff17m4
++;
4654 case R_BFIN_FUNCDESC_GOTOFFHI
:
4655 case R_BFIN_FUNCDESC_GOTOFFLO
:
4656 picrel
->fdgoffhilo
++;
4659 case R_BFIN_FUNCDESC
:
4664 /* This relocation describes the C++ object vtable hierarchy.
4665 Reconstruct it for later use during GC. */
4666 case R_BFIN_GNU_VTINHERIT
:
4667 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4671 /* This relocation describes which C++ vtable entries are actually
4672 used. Record for later use during GC. */
4673 case R_BFIN_GNU_VTENTRY
:
4674 BFD_ASSERT (h
!= NULL
);
4676 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4680 case R_BFIN_HUIMM16
:
4681 case R_BFIN_LUIMM16
:
4682 case R_BFIN_PCREL12_JUMP_S
:
4683 case R_BFIN_PCREL10
:
4689 /* xgettext:c-format */
4690 (_("%pB: unsupported relocation type %#x"),
4691 abfd
, (int) ELF32_R_TYPE (rel
->r_info
));
4699 /* Set the right machine number for a Blackfin ELF file. */
4702 elf32_bfin_object_p (bfd
*abfd
)
4704 bfd_default_set_arch_mach (abfd
, bfd_arch_bfin
, 0);
4705 return (((elf_elfheader (abfd
)->e_flags
& EF_BFIN_FDPIC
) != 0)
4706 == (IS_FDPIC (abfd
)));
4710 elf32_bfin_set_private_flags (bfd
* abfd
, flagword flags
)
4712 elf_elfheader (abfd
)->e_flags
= flags
;
4713 elf_flags_init (abfd
) = true;
4717 /* Display the flags field. */
4719 elf32_bfin_print_private_bfd_data (bfd
* abfd
, void * ptr
)
4721 FILE *file
= (FILE *) ptr
;
4724 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4726 /* Print normal ELF private data. */
4727 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4729 flags
= elf_elfheader (abfd
)->e_flags
;
4731 /* xgettext:c-format */
4732 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
4734 if (flags
& EF_BFIN_PIC
)
4735 fprintf (file
, " -fpic");
4737 if (flags
& EF_BFIN_FDPIC
)
4738 fprintf (file
, " -mfdpic");
4745 /* Merge backend specific data from an object file to the output
4746 object file when linking. */
4749 elf32_bfin_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
4751 bfd
*obfd
= info
->output_bfd
;
4752 flagword old_flags
, new_flags
;
4755 /* FIXME: What should be checked when linking shared libraries? */
4756 if ((ibfd
->flags
& DYNAMIC
) != 0)
4759 new_flags
= elf_elfheader (ibfd
)->e_flags
;
4760 old_flags
= elf_elfheader (obfd
)->e_flags
;
4762 if (new_flags
& EF_BFIN_FDPIC
)
4763 new_flags
&= ~EF_BFIN_PIC
;
4769 ("old_flags = 0x%.8x, new_flags = 0x%.8x, init = %s, filename = %pB",
4770 old_flags
, new_flags
, elf_flags_init (obfd
) ? "yes" : "no", ibfd
);
4772 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
4774 elf_flags_init (obfd
) = true;
4775 elf_elfheader (obfd
)->e_flags
= new_flags
;
4778 if (((new_flags
& EF_BFIN_FDPIC
) == 0) != (! IS_FDPIC (obfd
)))
4781 if (IS_FDPIC (obfd
))
4783 (_("%pB: cannot link non-fdpic object file into fdpic executable"),
4787 (_("%pB: cannot link fdpic object file into non-fdpic executable"),
4792 bfd_set_error (bfd_error_bad_value
);
4797 /* bfin ELF linker hash entry. */
4799 struct bfin_link_hash_entry
4801 struct elf_link_hash_entry root
;
4803 /* Number of PC relative relocs copied for this symbol. */
4804 struct bfin_pcrel_relocs_copied
*pcrel_relocs_copied
;
4807 #define bfin_hash_entry(ent) ((struct bfin_link_hash_entry *) (ent))
4809 static struct bfd_hash_entry
*
4810 bfin_link_hash_newfunc (struct bfd_hash_entry
*entry
,
4811 struct bfd_hash_table
*table
, const char *string
)
4813 struct bfd_hash_entry
*ret
= entry
;
4815 /* Allocate the structure if it has not already been allocated by a
4818 ret
= bfd_hash_allocate (table
, sizeof (struct bfin_link_hash_entry
));
4822 /* Call the allocation method of the superclass. */
4823 ret
= _bfd_elf_link_hash_newfunc (ret
, table
, string
);
4825 bfin_hash_entry (ret
)->pcrel_relocs_copied
= NULL
;
4830 /* Create an bfin ELF linker hash table. */
4832 static struct bfd_link_hash_table
*
4833 bfin_link_hash_table_create (bfd
* abfd
)
4835 struct elf_link_hash_table
*ret
;
4836 size_t amt
= sizeof (struct elf_link_hash_table
);
4838 ret
= bfd_zmalloc (amt
);
4842 if (!_bfd_elf_link_hash_table_init (ret
, abfd
, bfin_link_hash_newfunc
,
4843 sizeof (struct elf_link_hash_entry
),
4853 /* The size in bytes of an entry in the procedure linkage table. */
4855 /* Finish up the dynamic sections. */
4858 bfin_finish_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
4859 struct bfd_link_info
*info
)
4864 dynobj
= elf_hash_table (info
)->dynobj
;
4866 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4868 if (elf_hash_table (info
)->dynamic_sections_created
)
4870 Elf32_External_Dyn
*dyncon
, *dynconend
;
4872 BFD_ASSERT (sdyn
!= NULL
);
4874 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4875 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4876 for (; dyncon
< dynconend
; dyncon
++)
4878 Elf_Internal_Dyn dyn
;
4880 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4888 /* Finish up dynamic symbol handling. We set the contents of various
4889 dynamic sections here. */
4892 bfin_finish_dynamic_symbol (bfd
* output_bfd
,
4893 struct bfd_link_info
*info
,
4894 struct elf_link_hash_entry
*h
,
4895 Elf_Internal_Sym
* sym
)
4897 if (h
->got
.offset
!= (bfd_vma
) - 1)
4901 Elf_Internal_Rela rela
;
4904 /* This symbol has an entry in the global offset table.
4907 sgot
= elf_hash_table (info
)->sgot
;
4908 srela
= elf_hash_table (info
)->srelgot
;
4909 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
4911 rela
.r_offset
= (sgot
->output_section
->vma
4912 + sgot
->output_offset
4913 + (h
->got
.offset
& ~(bfd_vma
) 1));
4915 /* If this is a -Bsymbolic link, and the symbol is defined
4916 locally, we just want to emit a RELATIVE reloc. Likewise if
4917 the symbol was forced to be local because of a version file.
4918 The entry in the global offset table will already have been
4919 initialized in the relocate_section function. */
4920 if (bfd_link_pic (info
)
4922 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
4924 _bfd_error_handler (_("*** check this relocation %s"),
4926 rela
.r_info
= ELF32_R_INFO (0, R_BFIN_PCREL24
);
4927 rela
.r_addend
= bfd_get_signed_32 (output_bfd
,
4931 offset
& ~(bfd_vma
) 1)));
4935 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4936 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
4937 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_BFIN_GOT
);
4941 loc
= srela
->contents
;
4942 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4943 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4950 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4951 if (strcmp (h
->root
.root
.string
, "__DYNAMIC") == 0
4952 || h
== elf_hash_table (info
)->hgot
)
4953 sym
->st_shndx
= SHN_ABS
;
4958 /* Adjust a symbol defined by a dynamic object and referenced by a
4959 regular object. The current definition is in some section of the
4960 dynamic object, but we're not including those sections. We have to
4961 change the definition to something the rest of the link can
4965 bfin_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4966 struct elf_link_hash_entry
*h
)
4970 unsigned int power_of_two
;
4972 dynobj
= elf_hash_table (info
)->dynobj
;
4974 /* Make sure we know what is going on here. */
4975 BFD_ASSERT (dynobj
!= NULL
4978 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
4980 /* If this is a function, put it in the procedure linkage table. We
4981 will fill in the contents of the procedure linkage table later,
4982 when we know the address of the .got section. */
4983 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
4988 /* If this is a weak symbol, and there is a real definition, the
4989 processor independent code will have arranged for us to see the
4990 real definition first, and we can just use the same value. */
4991 if (h
->is_weakalias
)
4993 struct elf_link_hash_entry
*def
= weakdef (h
);
4994 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
4995 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
4996 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
5000 /* This is a reference to a symbol defined by a dynamic object which
5001 is not a function. */
5003 /* If we are creating a shared library, we must presume that the
5004 only references to the symbol are via the global offset table.
5005 For such cases we need not do anything here; the relocations will
5006 be handled correctly by relocate_section. */
5007 if (bfd_link_pic (info
))
5010 /* We must allocate the symbol in our .dynbss section, which will
5011 become part of the .bss section of the executable. There will be
5012 an entry for this symbol in the .dynsym section. The dynamic
5013 object will contain position independent code, so all references
5014 from the dynamic object to this symbol will go through the global
5015 offset table. The dynamic linker will use the .dynsym entry to
5016 determine the address it must put in the global offset table, so
5017 both the dynamic object and the regular object will refer to the
5018 same memory location for the variable. */
5020 s
= bfd_get_linker_section (dynobj
, ".dynbss");
5021 BFD_ASSERT (s
!= NULL
);
5023 #if 0 /* Bfin does not currently have a COPY reloc. */
5024 /* We must generate a R_BFIN_COPY reloc to tell the dynamic linker to
5025 copy the initial value out of the dynamic object and into the
5026 runtime process image. We need to remember the offset into the
5027 .rela.bss section we are going to use. */
5028 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5032 srel
= bfd_get_linker_section (dynobj
, ".rela.bss");
5033 BFD_ASSERT (srel
!= NULL
);
5034 srel
->size
+= sizeof (Elf32_External_Rela
);
5038 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5040 _bfd_error_handler (_("the bfin target does not currently support the generation of copy relocations"));
5044 /* We need to figure out the alignment required for this symbol. I
5045 have no idea how ELF linkers handle this. */
5046 power_of_two
= bfd_log2 (h
->size
);
5047 if (power_of_two
> 3)
5050 /* Apply the required alignment. */
5051 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
5052 if (power_of_two
> bfd_section_alignment (s
))
5054 if (!bfd_set_section_alignment (s
, power_of_two
))
5058 /* Define the symbol as being at this point in the section. */
5059 h
->root
.u
.def
.section
= s
;
5060 h
->root
.u
.def
.value
= s
->size
;
5062 /* Increment the section size to make room for the symbol. */
5068 /* The bfin linker needs to keep track of the number of relocs that it
5069 decides to copy in check_relocs for each symbol. This is so that it
5070 can discard PC relative relocs if it doesn't need them when linking
5071 with -Bsymbolic. We store the information in a field extending the
5072 regular ELF linker hash table. */
5074 /* This structure keeps track of the number of PC relative relocs we have
5075 copied for a given symbol. */
5077 struct bfin_pcrel_relocs_copied
5080 struct bfin_pcrel_relocs_copied
*next
;
5081 /* A section in dynobj. */
5083 /* Number of relocs copied in this section. */
5084 bfd_size_type count
;
5087 /* This function is called via elf_link_hash_traverse if we are
5088 creating a shared object. In the -Bsymbolic case it discards the
5089 space allocated to copy PC relative relocs against symbols which
5090 are defined in regular objects. For the normal shared case, it
5091 discards space for pc-relative relocs that have become local due to
5092 symbol visibility changes. We allocated space for them in the
5093 check_relocs routine, but we won't fill them in in the
5094 relocate_section routine.
5096 We also check whether any of the remaining relocations apply
5097 against a readonly section, and set the DF_TEXTREL flag in this
5101 bfin_discard_copies (struct elf_link_hash_entry
*h
, void * inf
)
5103 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5104 struct bfin_pcrel_relocs_copied
*s
;
5106 if (!h
->def_regular
|| (!info
->symbolic
&& !h
->forced_local
))
5108 if ((info
->flags
& DF_TEXTREL
) == 0)
5110 /* Look for relocations against read-only sections. */
5111 for (s
= bfin_hash_entry (h
)->pcrel_relocs_copied
;
5112 s
!= NULL
; s
= s
->next
)
5113 if ((s
->section
->flags
& SEC_READONLY
) != 0)
5115 info
->flags
|= DF_TEXTREL
;
5123 for (s
= bfin_hash_entry (h
)->pcrel_relocs_copied
;
5124 s
!= NULL
; s
= s
->next
)
5125 s
->section
->size
-= s
->count
* sizeof (Elf32_External_Rela
);
5131 bfin_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
5132 struct bfd_link_info
*info
)
5138 dynobj
= elf_hash_table (info
)->dynobj
;
5139 BFD_ASSERT (dynobj
!= NULL
);
5141 if (elf_hash_table (info
)->dynamic_sections_created
)
5143 /* Set the contents of the .interp section to the interpreter. */
5144 if (bfd_link_executable (info
) && !info
->nointerp
)
5146 s
= bfd_get_linker_section (dynobj
, ".interp");
5147 BFD_ASSERT (s
!= NULL
);
5148 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5149 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5154 /* We may have created entries in the .rela.got section.
5155 However, if we are not creating the dynamic sections, we will
5156 not actually use these entries. Reset the size of .rela.got,
5157 which will cause it to get stripped from the output file
5159 s
= elf_hash_table (info
)->srelgot
;
5164 /* If this is a -Bsymbolic shared link, then we need to discard all
5165 PC relative relocs against symbols defined in a regular object.
5166 For the normal shared case we discard the PC relative relocs
5167 against symbols that have become local due to visibility changes.
5168 We allocated space for them in the check_relocs routine, but we
5169 will not fill them in in the relocate_section routine. */
5170 if (bfd_link_pic (info
))
5171 elf_link_hash_traverse (elf_hash_table (info
),
5172 bfin_discard_copies
, info
);
5174 /* The check_relocs and adjust_dynamic_symbol entry points have
5175 determined the sizes of the various dynamic sections. Allocate
5178 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5183 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5186 /* It's OK to base decisions on the section name, because none
5187 of the dynobj section names depend upon the input files. */
5188 name
= bfd_section_name (s
);
5192 if (startswith (name
, ".rela"))
5196 /* If we don't need this section, strip it from the
5197 output file. This is mostly to handle .rela.bss and
5198 .rela.plt. We must create both sections in
5199 create_dynamic_sections, because they must be created
5200 before the linker maps input sections to output
5201 sections. The linker does that before
5202 adjust_dynamic_symbol is called, and it is that
5203 function which decides whether anything needs to go
5204 into these sections. */
5211 /* We use the reloc_count field as a counter if we need
5212 to copy relocs into the output file. */
5216 else if (! startswith (name
, ".got"))
5218 /* It's not one of our sections, so don't allocate space. */
5224 s
->flags
|= SEC_EXCLUDE
;
5228 /* Allocate memory for the section contents. */
5229 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
5230 Unused entries should be reclaimed before the section's contents
5231 are written out, but at the moment this does not happen. Thus in
5232 order to prevent writing out garbage, we initialise the section's
5233 contents to zero. */
5234 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
5235 if (s
->contents
== NULL
&& s
->size
!= 0)
5239 if (elf_hash_table (info
)->dynamic_sections_created
)
5241 /* Add some entries to the .dynamic section. We fill in the
5242 values later, in bfin_finish_dynamic_sections, but we
5243 must add the entries now so that we get the correct size for
5244 the .dynamic section. The DT_DEBUG entry is filled in by the
5245 dynamic linker and used by the debugger. */
5246 #define add_dynamic_entry(TAG, VAL) \
5247 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5249 if (!bfd_link_pic (info
))
5251 if (!add_dynamic_entry (DT_DEBUG
, 0))
5258 if (!add_dynamic_entry (DT_RELA
, 0)
5259 || !add_dynamic_entry (DT_RELASZ
, 0)
5260 || !add_dynamic_entry (DT_RELAENT
,
5261 sizeof (Elf32_External_Rela
)))
5265 if ((info
->flags
& DF_TEXTREL
) != 0)
5267 if (!add_dynamic_entry (DT_TEXTREL
, 0))
5271 #undef add_dynamic_entry
5276 /* Given a .data section and a .emreloc in-memory section, store
5277 relocation information into the .emreloc section which can be
5278 used at runtime to relocate the section. This is called by the
5279 linker when the --embedded-relocs switch is used. This is called
5280 after the add_symbols entry point has been called for all the
5281 objects, and before the final_link entry point is called. */
5284 bfd_bfin_elf32_create_embedded_relocs (bfd
*abfd
,
5285 struct bfd_link_info
*info
,
5290 Elf_Internal_Shdr
*symtab_hdr
;
5291 Elf_Internal_Sym
*isymbuf
= NULL
;
5292 Elf_Internal_Rela
*internal_relocs
= NULL
;
5293 Elf_Internal_Rela
*irel
, *irelend
;
5297 BFD_ASSERT (! bfd_link_relocatable (info
));
5301 if (datasec
->reloc_count
== 0)
5304 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5306 /* Get a copy of the native relocations. */
5307 internal_relocs
= (_bfd_elf_link_read_relocs
5308 (abfd
, datasec
, NULL
, (Elf_Internal_Rela
*) NULL
,
5309 info
->keep_memory
));
5310 if (internal_relocs
== NULL
)
5313 amt
= (bfd_size_type
) datasec
->reloc_count
* 12;
5314 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, amt
);
5315 if (relsec
->contents
== NULL
)
5318 p
= relsec
->contents
;
5320 irelend
= internal_relocs
+ datasec
->reloc_count
;
5321 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
5323 asection
*targetsec
;
5325 /* We are going to write a four byte longword into the runtime
5326 reloc section. The longword will be the address in the data
5327 section which must be relocated. It is followed by the name
5328 of the target section NUL-padded or truncated to 8
5331 /* We can only relocate absolute longword relocs at run time. */
5332 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_BFIN_BYTE4_DATA
)
5334 *errmsg
= _("unsupported relocation type");
5335 bfd_set_error (bfd_error_bad_value
);
5339 /* Get the target section referred to by the reloc. */
5340 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
5342 /* A local symbol. */
5343 Elf_Internal_Sym
*isym
;
5345 /* Read this BFD's local symbols if we haven't done so already. */
5346 if (isymbuf
== NULL
)
5348 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5349 if (isymbuf
== NULL
)
5350 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
5351 symtab_hdr
->sh_info
, 0,
5353 if (isymbuf
== NULL
)
5357 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
5358 targetsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5363 struct elf_link_hash_entry
*h
;
5365 /* An external symbol. */
5366 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
5367 h
= elf_sym_hashes (abfd
)[indx
];
5368 BFD_ASSERT (h
!= NULL
);
5369 if (h
->root
.type
== bfd_link_hash_defined
5370 || h
->root
.type
== bfd_link_hash_defweak
)
5371 targetsec
= h
->root
.u
.def
.section
;
5376 bfd_put_32 (abfd
, irel
->r_offset
+ datasec
->output_offset
, p
);
5377 memset (p
+ 4, 0, 8);
5378 if (targetsec
!= NULL
)
5379 strncpy ((char *) p
+ 4, targetsec
->output_section
->name
, 8);
5382 if (symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5384 if (elf_section_data (datasec
)->relocs
!= internal_relocs
)
5385 free (internal_relocs
);
5389 if (symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5391 if (elf_section_data (datasec
)->relocs
!= internal_relocs
)
5392 free (internal_relocs
);
5396 struct bfd_elf_special_section
const elf32_bfin_special_sections
[] =
5398 { ".l1.text", 8, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
5399 { ".l1.data", 8, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
5400 { NULL
, 0, 0, 0, 0 }
5404 #define TARGET_LITTLE_SYM bfin_elf32_vec
5405 #define TARGET_LITTLE_NAME "elf32-bfin"
5406 #define ELF_ARCH bfd_arch_bfin
5407 #define ELF_TARGET_ID BFIN_ELF_DATA
5408 #define ELF_MACHINE_CODE EM_BLACKFIN
5409 #define ELF_MAXPAGESIZE 0x1000
5410 #define elf_symbol_leading_char '_'
5412 #define bfd_elf32_bfd_reloc_type_lookup bfin_bfd_reloc_type_lookup
5413 #define bfd_elf32_bfd_reloc_name_lookup \
5414 bfin_bfd_reloc_name_lookup
5415 #define elf_info_to_howto bfin_info_to_howto
5416 #define elf_info_to_howto_rel NULL
5417 #define elf_backend_object_p elf32_bfin_object_p
5419 #define bfd_elf32_bfd_is_local_label_name \
5420 bfin_is_local_label_name
5422 #define elf_backend_create_dynamic_sections \
5423 _bfd_elf_create_dynamic_sections
5424 #define bfd_elf32_bfd_link_hash_table_create \
5425 bfin_link_hash_table_create
5426 #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link
5428 #define elf_backend_check_relocs bfin_check_relocs
5429 #define elf_backend_adjust_dynamic_symbol \
5430 bfin_adjust_dynamic_symbol
5431 #define elf_backend_size_dynamic_sections \
5432 bfin_size_dynamic_sections
5433 #define elf_backend_relocate_section bfin_relocate_section
5434 #define elf_backend_finish_dynamic_symbol \
5435 bfin_finish_dynamic_symbol
5436 #define elf_backend_finish_dynamic_sections \
5437 bfin_finish_dynamic_sections
5438 #define elf_backend_gc_mark_hook bfin_gc_mark_hook
5439 #define bfd_elf32_bfd_merge_private_bfd_data \
5440 elf32_bfin_merge_private_bfd_data
5441 #define bfd_elf32_bfd_set_private_flags \
5442 elf32_bfin_set_private_flags
5443 #define bfd_elf32_bfd_print_private_bfd_data \
5444 elf32_bfin_print_private_bfd_data
5445 #define elf_backend_final_write_processing \
5446 elf32_bfin_final_write_processing
5447 #define elf_backend_reloc_type_class elf32_bfin_reloc_type_class
5448 #define elf_backend_stack_align 8
5449 #define elf_backend_can_gc_sections 1
5450 #define elf_backend_special_sections elf32_bfin_special_sections
5451 #define elf_backend_can_refcount 1
5452 #define elf_backend_want_got_plt 0
5453 #define elf_backend_plt_readonly 1
5454 #define elf_backend_want_plt_sym 0
5455 #define elf_backend_got_header_size 12
5456 #define elf_backend_rela_normal 1
5458 #include "elf32-target.h"
5460 #undef TARGET_LITTLE_SYM
5461 #define TARGET_LITTLE_SYM bfin_elf32_fdpic_vec
5462 #undef TARGET_LITTLE_NAME
5463 #define TARGET_LITTLE_NAME "elf32-bfinfdpic"
5465 #define elf32_bed elf32_bfinfdpic_bed
5467 #undef elf_backend_got_header_size
5468 #define elf_backend_got_header_size 0
5470 #undef elf_backend_relocate_section
5471 #define elf_backend_relocate_section bfinfdpic_relocate_section
5472 #undef elf_backend_check_relocs
5473 #define elf_backend_check_relocs bfinfdpic_check_relocs
5475 #undef bfd_elf32_bfd_link_hash_table_create
5476 #define bfd_elf32_bfd_link_hash_table_create \
5477 bfinfdpic_elf_link_hash_table_create
5478 #undef elf_backend_always_size_sections
5479 #define elf_backend_always_size_sections \
5480 elf32_bfinfdpic_always_size_sections
5482 #undef elf_backend_create_dynamic_sections
5483 #define elf_backend_create_dynamic_sections \
5484 elf32_bfinfdpic_create_dynamic_sections
5485 #undef elf_backend_adjust_dynamic_symbol
5486 #define elf_backend_adjust_dynamic_symbol \
5487 elf32_bfinfdpic_adjust_dynamic_symbol
5488 #undef elf_backend_size_dynamic_sections
5489 #define elf_backend_size_dynamic_sections \
5490 elf32_bfinfdpic_size_dynamic_sections
5491 #undef elf_backend_finish_dynamic_symbol
5492 #define elf_backend_finish_dynamic_symbol \
5493 elf32_bfinfdpic_finish_dynamic_symbol
5494 #undef elf_backend_finish_dynamic_sections
5495 #define elf_backend_finish_dynamic_sections \
5496 elf32_bfinfdpic_finish_dynamic_sections
5498 #undef elf_backend_discard_info
5499 #define elf_backend_discard_info \
5500 bfinfdpic_elf_discard_info
5501 #undef elf_backend_can_make_relative_eh_frame
5502 #define elf_backend_can_make_relative_eh_frame \
5503 bfinfdpic_elf_use_relative_eh_frame
5504 #undef elf_backend_can_make_lsda_relative_eh_frame
5505 #define elf_backend_can_make_lsda_relative_eh_frame \
5506 bfinfdpic_elf_use_relative_eh_frame
5507 #undef elf_backend_encode_eh_address
5508 #define elf_backend_encode_eh_address \
5509 bfinfdpic_elf_encode_eh_address
5511 #undef elf_backend_may_use_rel_p
5512 #define elf_backend_may_use_rel_p 1
5513 #undef elf_backend_may_use_rela_p
5514 #define elf_backend_may_use_rela_p 1
5515 /* We use REL for dynamic relocations only. */
5516 #undef elf_backend_default_use_rela_p
5517 #define elf_backend_default_use_rela_p 1
5519 #undef elf_backend_omit_section_dynsym
5520 #define elf_backend_omit_section_dynsym _bfinfdpic_link_omit_section_dynsym
5522 #include "elf32-target.h"