1 /* ADI Blackfin BFD support for 32-bit ELF.
2 Copyright 2005, 2006 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 2 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, MA 02110-1301,
27 /* FUNCTION : bfin_pltpc_reloc
28 ABSTRACT : TODO : figure out how to handle pltpc relocs. */
29 static bfd_reloc_status_type
31 bfd
*abfd ATTRIBUTE_UNUSED
,
32 arelent
*reloc_entry ATTRIBUTE_UNUSED
,
33 asymbol
*symbol ATTRIBUTE_UNUSED
,
34 PTR data ATTRIBUTE_UNUSED
,
35 asection
*input_section ATTRIBUTE_UNUSED
,
36 bfd
*output_bfd ATTRIBUTE_UNUSED
,
37 char **error_message ATTRIBUTE_UNUSED
)
39 bfd_reloc_status_type flag
= bfd_reloc_ok
;
44 static bfd_reloc_status_type
45 bfin_pcrel24_reloc (bfd
*abfd
,
49 asection
*input_section
,
51 char **error_message ATTRIBUTE_UNUSED
)
54 bfd_size_type addr
= reloc_entry
->address
;
55 bfd_vma output_base
= 0;
56 reloc_howto_type
*howto
= reloc_entry
->howto
;
57 asection
*output_section
;
58 bfd_boolean relocatable
= (output_bfd
!= NULL
);
60 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
61 return bfd_reloc_outofrange
;
63 if (bfd_is_und_section (symbol
->section
)
64 && (symbol
->flags
& BSF_WEAK
) == 0
66 return bfd_reloc_undefined
;
68 if (bfd_is_com_section (symbol
->section
))
71 relocation
= symbol
->value
;
73 output_section
= symbol
->section
->output_section
;
78 output_base
= output_section
->vma
;
80 if (!relocatable
|| !strcmp (symbol
->name
, symbol
->section
->name
))
81 relocation
+= output_base
+ symbol
->section
->output_offset
;
83 if (!relocatable
&& !strcmp (symbol
->name
, symbol
->section
->name
))
84 relocation
+= reloc_entry
->addend
;
86 relocation
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
87 relocation
-= reloc_entry
->address
;
89 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
91 bfd_reloc_status_type status
;
92 status
= bfd_check_overflow (howto
->complain_on_overflow
,
95 bfd_arch_bits_per_address(abfd
),
97 if (status
!= bfd_reloc_ok
)
101 /* if rightshift is 1 and the number odd, return error. */
102 if (howto
->rightshift
&& (relocation
& 0x01))
104 fprintf(stderr
, "relocation should be even number\n");
105 return bfd_reloc_overflow
;
108 relocation
>>= (bfd_vma
) howto
->rightshift
;
109 /* Shift everything up to where it's going to be used. */
111 relocation
<<= (bfd_vma
) howto
->bitpos
;
115 reloc_entry
->address
+= input_section
->output_offset
;
116 reloc_entry
->addend
+= symbol
->section
->output_offset
;
122 /* We are getting reloc_entry->address 2 byte off from
123 the start of instruction. Assuming absolute postion
124 of the reloc data. But, following code had been written assuming
125 reloc address is starting at begining of instruction.
126 To compensate that I have increased the value of
127 relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
130 x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ addr
- 2);
131 x
= (x
& 0xff00) | ((relocation
>> 16) & 0xff);
132 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
- 2);
134 x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ addr
);
135 x
= relocation
& 0xFFFF;
136 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
);
141 static bfd_reloc_status_type
142 bfin_imm16_reloc (bfd
*abfd
,
143 arelent
*reloc_entry
,
146 asection
*input_section
,
148 char **error_message ATTRIBUTE_UNUSED
)
150 bfd_vma relocation
, x
;
151 bfd_size_type reloc_addr
= reloc_entry
->address
;
152 bfd_vma output_base
= 0;
153 reloc_howto_type
*howto
= reloc_entry
->howto
;
154 asection
*output_section
;
155 bfd_boolean relocatable
= (output_bfd
!= NULL
);
157 /* Is the address of the relocation really within the section? */
158 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
159 return bfd_reloc_outofrange
;
161 if (bfd_is_und_section (symbol
->section
)
162 && (symbol
->flags
& BSF_WEAK
) == 0
164 return bfd_reloc_undefined
;
166 output_section
= symbol
->section
->output_section
;
167 relocation
= symbol
->value
;
169 /* Convert input-section-relative symbol value to absolute. */
173 output_base
= output_section
->vma
;
175 if (!relocatable
|| !strcmp (symbol
->name
, symbol
->section
->name
))
176 relocation
+= output_base
+ symbol
->section
->output_offset
;
178 /* Add in supplied addend. */
179 relocation
+= reloc_entry
->addend
;
183 reloc_entry
->address
+= input_section
->output_offset
;
184 reloc_entry
->addend
+= symbol
->section
->output_offset
;
188 reloc_entry
->addend
= 0;
191 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
193 bfd_reloc_status_type flag
;
194 flag
= bfd_check_overflow (howto
->complain_on_overflow
,
197 bfd_arch_bits_per_address(abfd
),
199 if (flag
!= bfd_reloc_ok
)
203 /* Here the variable relocation holds the final address of the
204 symbol we are relocating against, plus any addend. */
206 relocation
>>= (bfd_vma
) howto
->rightshift
;
208 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ reloc_addr
);
213 static bfd_reloc_status_type
214 bfin_byte4_reloc (bfd
*abfd
,
215 arelent
*reloc_entry
,
218 asection
*input_section
,
220 char **error_message ATTRIBUTE_UNUSED
)
222 bfd_vma relocation
, x
;
223 bfd_size_type addr
= reloc_entry
->address
;
224 bfd_vma output_base
= 0;
225 asection
*output_section
;
226 bfd_boolean relocatable
= (output_bfd
!= NULL
);
228 /* Is the address of the relocation really within the section? */
229 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
230 return bfd_reloc_outofrange
;
232 if (bfd_is_und_section (symbol
->section
)
233 && (symbol
->flags
& BSF_WEAK
) == 0
235 return bfd_reloc_undefined
;
237 output_section
= symbol
->section
->output_section
;
238 relocation
= symbol
->value
;
239 /* Convert input-section-relative symbol value to absolute. */
243 output_base
= output_section
->vma
;
246 && symbol
->section
->name
247 && !strcmp (symbol
->name
, symbol
->section
->name
))
250 relocation
+= output_base
+ symbol
->section
->output_offset
;
253 relocation
+= reloc_entry
->addend
;
257 /* This output will be relocatable ... like ld -r. */
258 reloc_entry
->address
+= input_section
->output_offset
;
259 reloc_entry
->addend
+= symbol
->section
->output_offset
;
263 reloc_entry
->addend
= 0;
266 /* Here the variable relocation holds the final address of the
267 symbol we are relocating against, plus any addend. */
268 x
= relocation
& 0xFFFF0000;
270 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
+ 2);
272 x
= relocation
& 0x0000FFFF;
273 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ addr
);
277 /* bfin_bfd_reloc handles the blackfin arithmetic relocations.
278 Use this instead of bfd_perform_relocation. */
279 static bfd_reloc_status_type
280 bfin_bfd_reloc (bfd
*abfd
,
281 arelent
*reloc_entry
,
284 asection
*input_section
,
286 char **error_message ATTRIBUTE_UNUSED
)
289 bfd_size_type addr
= reloc_entry
->address
;
290 bfd_vma output_base
= 0;
291 reloc_howto_type
*howto
= reloc_entry
->howto
;
292 asection
*output_section
;
293 bfd_boolean relocatable
= (output_bfd
!= NULL
);
295 /* Is the address of the relocation really within the section? */
296 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
297 return bfd_reloc_outofrange
;
299 if (bfd_is_und_section (symbol
->section
)
300 && (symbol
->flags
& BSF_WEAK
) == 0
302 return bfd_reloc_undefined
;
304 /* Get symbol value. (Common symbols are special.) */
305 if (bfd_is_com_section (symbol
->section
))
308 relocation
= symbol
->value
;
310 output_section
= symbol
->section
->output_section
;
312 /* Convert input-section-relative symbol value to absolute. */
316 output_base
= output_section
->vma
;
318 if (!relocatable
|| !strcmp (symbol
->name
, symbol
->section
->name
))
319 relocation
+= output_base
+ symbol
->section
->output_offset
;
321 if (!relocatable
&& !strcmp (symbol
->name
, symbol
->section
->name
))
323 /* Add in supplied addend. */
324 relocation
+= reloc_entry
->addend
;
327 /* Here the variable relocation holds the final address of the
328 symbol we are relocating against, plus any addend. */
330 if (howto
->pc_relative
== TRUE
)
332 relocation
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
334 if (howto
->pcrel_offset
== TRUE
)
335 relocation
-= reloc_entry
->address
;
340 reloc_entry
->address
+= input_section
->output_offset
;
341 reloc_entry
->addend
+= symbol
->section
->output_offset
;
344 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
346 bfd_reloc_status_type status
;
348 status
= bfd_check_overflow (howto
->complain_on_overflow
,
351 bfd_arch_bits_per_address(abfd
),
353 if (status
!= bfd_reloc_ok
)
357 /* If rightshift is 1 and the number odd, return error. */
358 if (howto
->rightshift
&& (relocation
& 0x01))
360 fprintf(stderr
, "relocation should be even number\n");
361 return bfd_reloc_overflow
;
364 relocation
>>= (bfd_vma
) howto
->rightshift
;
366 /* Shift everything up to where it's going to be used. */
368 relocation
<<= (bfd_vma
) howto
->bitpos
;
371 x = ( (x & ~howto->dst_mask) | (relocation & howto->dst_mask))
373 /* handle 8 and 16 bit relocations here. */
378 char x
= bfd_get_8 (abfd
, (char *) data
+ addr
);
380 bfd_put_8 (abfd
, x
, (unsigned char *) data
+ addr
);
386 unsigned short x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ addr
);
388 bfd_put_16 (abfd
, (bfd_vma
) x
, (unsigned char *) data
+ addr
);
393 return bfd_reloc_other
;
399 /* HOWTO Table for blackfin.
400 Blackfin relocations are fairly complicated.
401 Some of the salient features are
402 a. Even numbered offsets. A number of (not all) relocations are
403 even numbered. This means that the rightmost bit is not stored.
404 Needs to right shift by 1 and check to see if value is not odd
405 b. A relocation can be an expression. An expression takes on
406 a variety of relocations arranged in a stack.
407 As a result, we cannot use the standard generic function as special
408 function. We will have our own, which is very similar to the standard
409 generic function except that it understands how to get the value from
410 the relocation stack. . */
412 #define BFIN_RELOC_MIN 0
413 #define BFIN_RELOC_MAX 0x13
414 #define BFIN_GNUEXT_RELOC_MIN 0x40
415 #define BFIN_GNUEXT_RELOC_MAX 0x43
416 #define BFIN_ARELOC_MIN 0xE0
417 #define BFIN_ARELOC_MAX 0xF3
419 static reloc_howto_type bfin_howto_table
[] =
421 /* This reloc does nothing. . */
422 HOWTO (R_unused0
, /* type. */
424 2, /* size (0 = byte, 1 = short, 2 = long). */
426 FALSE
, /* pc_relative. */
428 complain_overflow_bitfield
, /* complain_on_overflow. */
429 bfd_elf_generic_reloc
, /* special_function. */
430 "R_unused0", /* name. */
431 FALSE
, /* partial_inplace. */
434 FALSE
), /* pcrel_offset. */
436 HOWTO (R_pcrel5m2
, /* type. */
438 1, /* size (0 = byte, 1 = short, 2 = long).. */
440 TRUE
, /* pc_relative. */
442 complain_overflow_unsigned
, /* complain_on_overflow. */
443 bfin_bfd_reloc
, /* special_function. */
444 "R_pcrel5m2", /* name. */
445 FALSE
, /* partial_inplace. */
447 0x0000000F, /* dst_mask. */
448 FALSE
), /* pcrel_offset. */
450 HOWTO (R_unused1
, /* type. */
452 2, /* size (0 = byte, 1 = short, 2 = long). */
454 FALSE
, /* pc_relative. */
456 complain_overflow_bitfield
, /* complain_on_overflow. */
457 bfd_elf_generic_reloc
, /* special_function. */
458 "R_unused1", /* name. */
459 FALSE
, /* partial_inplace. */
462 FALSE
), /* pcrel_offset. */
464 HOWTO (R_pcrel10
, /* type. */
466 1, /* size (0 = byte, 1 = short, 2 = long). */
468 TRUE
, /* pc_relative. */
470 complain_overflow_signed
, /* complain_on_overflow. */
471 bfin_bfd_reloc
, /* special_function. */
472 "R_pcrel10", /* name. */
473 FALSE
, /* partial_inplace. */
475 0x000003FF, /* dst_mask. */
476 TRUE
), /* pcrel_offset. */
478 HOWTO (R_pcrel12_jump
, /* type. */
480 /* the offset is actually 13 bit
481 aligned on a word boundary so
482 only 12 bits have to be used.
483 Right shift the rightmost bit.. */
484 1, /* size (0 = byte, 1 = short, 2 = long). */
486 TRUE
, /* pc_relative. */
488 complain_overflow_signed
, /* complain_on_overflow. */
489 bfin_bfd_reloc
, /* special_function. */
490 "R_pcrel12_jump", /* name. */
491 FALSE
, /* partial_inplace. */
493 0x0FFF, /* dst_mask. */
494 TRUE
), /* pcrel_offset. */
496 HOWTO (R_rimm16
, /* type. */
498 1, /* size (0 = byte, 1 = short, 2 = long). */
500 FALSE
, /* pc_relative. */
502 complain_overflow_signed
, /* complain_on_overflow. */
503 bfin_imm16_reloc
, /* special_function. */
504 "R_rimm16", /* name. */
505 FALSE
, /* partial_inplace. */
507 0x0000FFFF, /* dst_mask. */
508 TRUE
), /* pcrel_offset. */
510 HOWTO (R_luimm16
, /* type. */
512 1, /* size (0 = byte, 1 = short, 2 = long). */
514 FALSE
, /* pc_relative. */
516 complain_overflow_dont
, /* complain_on_overflow. */
517 bfin_imm16_reloc
, /* special_function. */
518 "R_luimm16", /* name. */
519 FALSE
, /* partial_inplace. */
521 0x0000FFFF, /* dst_mask. */
522 TRUE
), /* pcrel_offset. */
524 HOWTO (R_huimm16
, /* type. */
525 16, /* rightshift. */
526 1, /* size (0 = byte, 1 = short, 2 = long). */
528 FALSE
, /* pc_relative. */
530 complain_overflow_unsigned
, /* complain_on_overflow. */
531 bfin_imm16_reloc
, /* special_function. */
532 "R_huimm16", /* name. */
533 FALSE
, /* partial_inplace. */
535 0x0000FFFF, /* dst_mask. */
536 TRUE
), /* pcrel_offset. */
538 HOWTO (R_pcrel12_jump_s
, /* type. */
540 1, /* size (0 = byte, 1 = short, 2 = long). */
542 TRUE
, /* pc_relative. */
544 complain_overflow_signed
, /* complain_on_overflow. */
545 bfin_bfd_reloc
, /* special_function. */
546 "R_pcrel12_jump_s", /* name. */
547 FALSE
, /* partial_inplace. */
549 0x00000FFF, /* dst_mask. */
550 TRUE
), /* pcrel_offset. */
552 HOWTO (R_pcrel24_jump_x
, /* type. */
554 2, /* size (0 = byte, 1 = short, 2 = long). */
556 TRUE
, /* pc_relative. */
558 complain_overflow_signed
, /* complain_on_overflow. */
559 bfin_pcrel24_reloc
, /* special_function. */
560 "R_pcrel24_jump_x", /* name. */
561 FALSE
, /* partial_inplace. */
563 0x00FFFFFF, /* dst_mask. */
564 TRUE
), /* pcrel_offset. */
566 HOWTO (R_pcrel24
, /* type. */
568 2, /* size (0 = byte, 1 = short, 2 = long). */
570 TRUE
, /* pc_relative. */
572 complain_overflow_signed
, /* complain_on_overflow. */
573 bfin_pcrel24_reloc
, /* special_function. */
574 "R_pcrel24", /* name. */
575 FALSE
, /* partial_inplace. */
577 0x00FFFFFF, /* dst_mask. */
578 TRUE
), /* pcrel_offset. */
580 HOWTO (R_unusedb
, /* type. */
582 2, /* size (0 = byte, 1 = short, 2 = long). */
584 FALSE
, /* pc_relative. */
586 complain_overflow_dont
, /* complain_on_overflow. */
587 bfd_elf_generic_reloc
, /* special_function. */
588 "R_unusedb", /* name. */
589 FALSE
, /* partial_inplace. */
592 FALSE
), /* pcrel_offset. */
594 HOWTO (R_unusedc
, /* type. */
596 2, /* size (0 = byte, 1 = short, 2 = long). */
598 FALSE
, /* pc_relative. */
600 complain_overflow_dont
, /* complain_on_overflow. */
601 bfd_elf_generic_reloc
, /* special_function. */
602 "R_unusedc", /* name. */
603 FALSE
, /* partial_inplace. */
606 FALSE
), /* pcrel_offset. */
608 HOWTO (R_pcrel24_jump_l
, /* type. */
610 2, /* size (0 = byte, 1 = short, 2 = long). */
612 TRUE
, /* pc_relative. */
614 complain_overflow_signed
, /* complain_on_overflow. */
615 bfin_pcrel24_reloc
, /* special_function. */
616 "R_pcrel24_jump_l", /* name. */
617 FALSE
, /* partial_inplace. */
619 0x00FFFFFF, /* dst_mask. */
620 TRUE
), /* pcrel_offset. */
622 HOWTO (R_pcrel24_call_x
, /* type. */
624 2, /* size (0 = byte, 1 = short, 2 = long). */
626 TRUE
, /* pc_relative. */
628 complain_overflow_signed
, /* complain_on_overflow. */
629 bfin_pcrel24_reloc
, /* special_function. */
630 "R_pcrel24_call_x", /* name. */
631 FALSE
, /* partial_inplace. */
633 0x00FFFFFF, /* dst_mask. */
634 TRUE
), /* pcrel_offset. */
636 HOWTO (R_var_eq_symb
, /* type. */
638 2, /* size (0 = byte, 1 = short, 2 = long). */
640 FALSE
, /* pc_relative. */
642 complain_overflow_bitfield
, /* complain_on_overflow. */
643 bfin_bfd_reloc
, /* special_function. */
644 "R_var_eq_symb", /* name. */
645 FALSE
, /* partial_inplace. */
648 FALSE
), /* pcrel_offset. */
650 HOWTO (R_byte_data
, /* type. */
652 0, /* size (0 = byte, 1 = short, 2 = long). */
654 FALSE
, /* pc_relative. */
656 complain_overflow_unsigned
, /* complain_on_overflow. */
657 bfin_bfd_reloc
, /* special_function. */
658 "R_byte_data", /* name. */
659 FALSE
, /* partial_inplace. */
661 0xFF, /* dst_mask. */
662 TRUE
), /* pcrel_offset. */
664 HOWTO (R_byte2_data
, /* type. */
666 1, /* size (0 = byte, 1 = short, 2 = long). */
668 FALSE
, /* pc_relative. */
670 complain_overflow_signed
, /* complain_on_overflow. */
671 bfin_bfd_reloc
, /* special_function. */
672 "R_byte2_data", /* name. */
673 FALSE
, /* partial_inplace. */
675 0xFFFF, /* dst_mask. */
676 TRUE
), /* pcrel_offset. */
678 HOWTO (R_byte4_data
, /* type. */
680 2, /* size (0 = byte, 1 = short, 2 = long). */
682 FALSE
, /* pc_relative. */
684 complain_overflow_unsigned
, /* complain_on_overflow. */
685 bfin_byte4_reloc
, /* special_function. */
686 "R_byte4_data", /* name. */
687 FALSE
, /* partial_inplace. */
689 0xFFFFFFFF, /* dst_mask. */
690 TRUE
), /* pcrel_offset. */
692 HOWTO (R_pcrel11
, /* type. */
694 1, /* size (0 = byte, 1 = short, 2 = long). */
696 TRUE
, /* pc_relative. */
698 complain_overflow_unsigned
, /* complain_on_overflow. */
699 bfin_bfd_reloc
, /* special_function. */
700 "R_pcrel11", /* name. */
701 FALSE
, /* partial_inplace. */
703 0x000003FF, /* dst_mask. */
704 FALSE
), /* pcrel_offset. */
707 static reloc_howto_type bfin_gnuext_howto_table
[] =
709 HOWTO (R_pltpc
, /* type. */
711 1, /* size (0 = byte, 1 = short, 2 = long). */
713 FALSE
, /* pc_relative. */
715 complain_overflow_bitfield
, /* complain_on_overflow. */
716 bfin_pltpc_reloc
, /* special_function. */
717 "R_pltpc", /* name. */
718 FALSE
, /* partial_inplace. */
719 0xffff, /* src_mask. */
720 0xffff, /* dst_mask. */
721 FALSE
), /* pcrel_offset. */
723 HOWTO (R_got
, /* type. */
725 1, /* size (0 = byte, 1 = short, 2 = long). */
727 FALSE
, /* pc_relative. */
729 complain_overflow_bitfield
, /* complain_on_overflow. */
730 bfd_elf_generic_reloc
, /* special_function. */
732 FALSE
, /* partial_inplace. */
733 0x7fff, /* src_mask. */
734 0x7fff, /* dst_mask. */
735 FALSE
), /* pcrel_offset. */
737 /* GNU extension to record C++ vtable hierarchy. */
738 HOWTO (R_BFIN_GNU_VTINHERIT
, /* type. */
740 2, /* size (0 = byte, 1 = short, 2 = long). */
742 FALSE
, /* pc_relative. */
744 complain_overflow_dont
, /* complain_on_overflow. */
745 NULL
, /* special_function. */
746 "R_BFIN_GNU_VTINHERIT", /* name. */
747 FALSE
, /* partial_inplace. */
750 FALSE
), /* pcrel_offset. */
752 /* GNU extension to record C++ vtable member usage. */
753 HOWTO (R_BFIN_GNU_VTENTRY
, /* type. */
755 2, /* size (0 = byte, 1 = short, 2 = long). */
757 FALSE
, /* pc_relative. */
759 complain_overflow_dont
, /* complain_on_overflow. */
760 _bfd_elf_rel_vtable_reloc_fn
, /* special_function. */
761 "R_BFIN_GNU_VTENTRY", /* name. */
762 FALSE
, /* partial_inplace. */
765 FALSE
) /* pcrel_offset. */
768 struct bfin_reloc_map
770 bfd_reloc_code_real_type bfd_reloc_val
;
771 unsigned int bfin_reloc_val
;
774 static const struct bfin_reloc_map bfin_reloc_map
[] =
776 { BFD_RELOC_NONE
, R_unused0
},
777 { BFD_RELOC_BFIN_5_PCREL
, R_pcrel5m2
},
778 { BFD_RELOC_NONE
, R_unused1
},
779 { BFD_RELOC_BFIN_10_PCREL
, R_pcrel10
},
780 { BFD_RELOC_BFIN_12_PCREL_JUMP
, R_pcrel12_jump
},
781 { BFD_RELOC_BFIN_16_IMM
, R_rimm16
},
782 { BFD_RELOC_BFIN_16_LOW
, R_luimm16
},
783 { BFD_RELOC_BFIN_16_HIGH
, R_huimm16
},
784 { BFD_RELOC_BFIN_12_PCREL_JUMP_S
, R_pcrel12_jump_s
},
785 { BFD_RELOC_24_PCREL
, R_pcrel24
},
786 { BFD_RELOC_24_PCREL
, R_pcrel24
},
787 { BFD_RELOC_BFIN_24_PCREL_JUMP_L
, R_pcrel24_jump_l
},
788 { BFD_RELOC_NONE
, R_unusedb
},
789 { BFD_RELOC_NONE
, R_unusedc
},
790 { BFD_RELOC_BFIN_24_PCREL_CALL_X
, R_pcrel24_call_x
},
791 { BFD_RELOC_8
, R_byte_data
},
792 { BFD_RELOC_16
, R_byte2_data
},
793 { BFD_RELOC_32
, R_byte4_data
},
794 { BFD_RELOC_BFIN_11_PCREL
, R_pcrel11
},
795 { BFD_RELOC_BFIN_GOT
, R_got
},
796 { BFD_RELOC_BFIN_PLTPC
, R_pltpc
},
797 { BFD_RELOC_VTABLE_INHERIT
, R_BFIN_GNU_VTINHERIT
},
798 { BFD_RELOC_VTABLE_ENTRY
, R_BFIN_GNU_VTENTRY
},
803 bfin_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
805 Elf_Internal_Rela
*dst
)
809 r_type
= ELF32_R_TYPE (dst
->r_info
);
811 if (r_type
<= BFIN_RELOC_MAX
)
812 cache_ptr
->howto
= &bfin_howto_table
[r_type
];
814 else if (r_type
>= BFIN_GNUEXT_RELOC_MIN
&& r_type
<= BFIN_GNUEXT_RELOC_MAX
)
815 cache_ptr
->howto
= &bfin_gnuext_howto_table
[r_type
- BFIN_GNUEXT_RELOC_MIN
];
818 cache_ptr
->howto
= (reloc_howto_type
*) NULL
;
821 /* Given a BFD reloc type, return the howto. */
822 static reloc_howto_type
*
823 bfin_bfd_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
824 bfd_reloc_code_real_type code
)
827 unsigned int r_type
= BFIN_RELOC_MIN
;
829 for (i
= sizeof (bfin_reloc_map
) / sizeof (bfin_reloc_map
[0]); --i
;)
830 if (bfin_reloc_map
[i
].bfd_reloc_val
== code
)
831 r_type
= bfin_reloc_map
[i
].bfin_reloc_val
;
833 if (r_type
<= BFIN_RELOC_MAX
&& r_type
> BFIN_RELOC_MIN
)
834 return &bfin_howto_table
[r_type
];
836 else if (r_type
>= BFIN_GNUEXT_RELOC_MIN
&& r_type
<= BFIN_GNUEXT_RELOC_MAX
)
837 return &bfin_gnuext_howto_table
[r_type
- BFIN_GNUEXT_RELOC_MIN
];
839 return (reloc_howto_type
*) NULL
;
842 /* Given a bfin relocation type, return the howto. */
843 static reloc_howto_type
*
844 bfin_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
847 if (r_type
<= BFIN_RELOC_MAX
)
848 return &bfin_howto_table
[r_type
];
850 else if (r_type
>= BFIN_GNUEXT_RELOC_MIN
&& r_type
<= BFIN_GNUEXT_RELOC_MAX
)
851 return &bfin_gnuext_howto_table
[r_type
- BFIN_GNUEXT_RELOC_MIN
];
853 return (reloc_howto_type
*) NULL
;
857 /* Return TRUE if the name is a local label.
858 bfin local labels begin with L$. */
860 bfin_is_local_label_name (
861 bfd
*abfd ATTRIBUTE_UNUSED
,
864 if (label
[0] == 'L' && label
[1] == '$' )
867 return _bfd_elf_is_local_label_name (abfd
, label
);
871 /* Look through the relocs for a section during the first phase, and
872 allocate space in the global offset table or procedure linkage
876 bfin_check_relocs (bfd
* abfd
,
877 struct bfd_link_info
*info
,
879 const Elf_Internal_Rela
*relocs
)
882 Elf_Internal_Shdr
*symtab_hdr
;
883 struct elf_link_hash_entry
**sym_hashes
;
884 bfd_signed_vma
*local_got_refcounts
;
885 const Elf_Internal_Rela
*rel
;
886 const Elf_Internal_Rela
*rel_end
;
890 if (info
->relocatable
)
893 dynobj
= elf_hash_table (info
)->dynobj
;
894 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
895 sym_hashes
= elf_sym_hashes (abfd
);
896 local_got_refcounts
= elf_local_got_refcounts (abfd
);
902 rel_end
= relocs
+ sec
->reloc_count
;
903 for (rel
= relocs
; rel
< rel_end
; rel
++)
905 unsigned long r_symndx
;
906 struct elf_link_hash_entry
*h
;
908 r_symndx
= ELF32_R_SYM (rel
->r_info
);
909 if (r_symndx
< symtab_hdr
->sh_info
)
912 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
914 switch (ELF32_R_TYPE (rel
->r_info
))
916 /* This relocation describes the C++ object vtable hierarchy.
917 Reconstruct it for later use during GC. */
918 case R_BFIN_GNU_VTINHERIT
:
919 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
923 /* This relocation describes which C++ vtable entries
924 are actually used. Record for later use during GC. */
925 case R_BFIN_GNU_VTENTRY
:
926 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
932 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
938 /* Create the .got section. */
939 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
940 if (!_bfd_elf_create_got_section (dynobj
, info
))
946 sgot
= bfd_get_section_by_name (dynobj
, ".got");
947 BFD_ASSERT (sgot
!= NULL
);
950 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
952 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
955 srelgot
= bfd_make_section (dynobj
, ".rela.got");
957 || !bfd_set_section_flags (dynobj
, srelgot
,
964 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
971 if (h
->got
.refcount
== 0)
973 /* Make sure this symbol is output as a dynamic symbol. */
974 if (h
->dynindx
== -1 && !h
->forced_local
)
976 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
980 /* Allocate space in the .got section. */
982 /* Allocate relocation space. */
983 srelgot
->size
+= sizeof (Elf32_External_Rela
);
989 /* This is a global offset table entry for a local symbol. */
990 if (local_got_refcounts
== NULL
)
994 size
= symtab_hdr
->sh_info
;
995 size
*= sizeof (bfd_signed_vma
);
996 local_got_refcounts
= ((bfd_signed_vma
*)
997 bfd_zalloc (abfd
, size
));
998 if (local_got_refcounts
== NULL
)
1000 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1002 if (local_got_refcounts
[r_symndx
] == 0)
1007 /* If we are generating a shared object, we need to
1008 output a R_68K_RELATIVE reloc so that the dynamic
1009 linker can adjust this GOT entry. */
1010 srelgot
->size
+= sizeof (Elf32_External_Rela
);
1013 local_got_refcounts
[r_symndx
]++;
1025 static enum elf_reloc_type_class
1026 elf32_bfin_reloc_type_class (const Elf_Internal_Rela
* rela
)
1028 switch ((int) ELF32_R_TYPE (rela
->r_info
))
1031 return reloc_class_normal
;
1036 bfin_relocate_section (bfd
* output_bfd
,
1037 struct bfd_link_info
*info
,
1039 asection
* input_section
,
1040 bfd_byte
* contents
,
1041 Elf_Internal_Rela
* relocs
,
1042 Elf_Internal_Sym
* local_syms
,
1043 asection
** local_sections
)
1046 Elf_Internal_Shdr
*symtab_hdr
;
1047 struct elf_link_hash_entry
**sym_hashes
;
1048 bfd_vma
*local_got_offsets
;
1051 Elf_Internal_Rela
*rel
;
1052 Elf_Internal_Rela
*relend
;
1055 if (info
->relocatable
)
1058 dynobj
= elf_hash_table (info
)->dynobj
;
1059 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1060 sym_hashes
= elf_sym_hashes (input_bfd
);
1061 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1067 relend
= relocs
+ input_section
->reloc_count
;
1068 for (; rel
< relend
; rel
++, i
++)
1071 reloc_howto_type
*howto
;
1072 unsigned long r_symndx
;
1073 struct elf_link_hash_entry
*h
;
1074 Elf_Internal_Sym
*sym
;
1076 bfd_vma relocation
= 0;
1077 bfd_boolean unresolved_reloc
;
1078 bfd_reloc_status_type r
;
1081 r_type
= ELF32_R_TYPE (rel
->r_info
);
1082 if (r_type
< 0 || r_type
>= 243)
1084 bfd_set_error (bfd_error_bad_value
);
1088 if (r_type
== R_BFIN_GNU_VTENTRY
1089 || r_type
== R_BFIN_GNU_VTINHERIT
)
1092 howto
= bfin_reloc_type_lookup (input_bfd
, r_type
);
1095 bfd_set_error (bfd_error_bad_value
);
1098 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1103 unresolved_reloc
= FALSE
;
1105 if (r_symndx
< symtab_hdr
->sh_info
)
1107 sym
= local_syms
+ r_symndx
;
1108 sec
= local_sections
[r_symndx
];
1109 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1115 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1116 r_symndx
, symtab_hdr
, sym_hashes
,
1118 unresolved_reloc
, warned
);
1121 address
= rel
->r_offset
;
1123 /* Then, process normally. */
1126 case R_BFIN_GNU_VTINHERIT
:
1127 case R_BFIN_GNU_VTENTRY
:
1128 return bfd_reloc_ok
;
1131 /* Relocation is to the address of the entry for this symbol
1132 in the global offset table. */
1134 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1137 /* Relocation is the offset of the entry for this symbol in
1138 the global offset table. */
1145 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1146 BFD_ASSERT (sgot
!= NULL
);
1153 off
= h
->got
.offset
;
1154 BFD_ASSERT (off
!= (bfd_vma
) - 1);
1155 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
1157 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1164 /* This is actually a static link, or it is a
1165 -Bsymbolic link and the symbol is defined
1166 locally, or the symbol was forced to be local
1167 because of a version file.. We must initialize
1168 this entry in the global offset table. Since
1169 the offset must always be a multiple of 4, we
1170 use the least significant bit to record whether
1171 we have initialized it already.
1173 When doing a dynamic link, we create a .rela.got
1174 relocation entry to initialize the value. This
1175 is done in the finish_dynamic_symbol routine. */
1180 bfd_put_32 (output_bfd
, relocation
,
1181 sgot
->contents
+ off
);
1186 unresolved_reloc
= FALSE
;
1190 BFD_ASSERT (local_got_offsets
!= NULL
);
1191 off
= local_got_offsets
[r_symndx
];
1192 BFD_ASSERT (off
!= (bfd_vma
) - 1);
1194 /* The offset must always be a multiple of 4. We use
1195 the least significant bit to record whether we have
1196 already generated the necessary reloc. */
1201 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1206 Elf_Internal_Rela outrel
;
1209 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1210 BFD_ASSERT (s
!= NULL
);
1212 outrel
.r_offset
= (sgot
->output_section
->vma
1213 + sgot
->output_offset
+ off
);
1215 ELF32_R_INFO (0, R_pcrel24
);
1216 outrel
.r_addend
= relocation
;
1219 s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1220 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1223 local_got_offsets
[r_symndx
] |= 1;
1227 relocation
= sgot
->output_offset
+ off
;
1229 /* bfin : preg = [preg + 17bitdiv4offset] relocation is div by 4. */
1235 case R_pcrel24_jump_l
:
1239 relocation
+= rel
->r_addend
;
1241 /* Perform usual pc-relative correction. */
1242 relocation
-= input_section
->output_section
->vma
+ input_section
->output_offset
;
1243 relocation
-= address
;
1245 /* We are getting reloc_entry->address 2 byte off from
1246 the start of instruction. Assuming absolute postion
1247 of the reloc data. But, following code had been written assuming
1248 reloc address is starting at begining of instruction.
1249 To compensate that I have increased the value of
1250 relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
1257 x
= bfd_get_16 (input_bfd
, contents
+ address
);
1258 x
= (x
& 0xff00) | ((relocation
>> 16) & 0xff);
1259 bfd_put_16 (input_bfd
, x
, contents
+ address
);
1261 x
= bfd_get_16 (input_bfd
, contents
+ address
+ 2);
1262 x
= relocation
& 0xFFFF;
1263 bfd_put_16 (input_bfd
, x
, contents
+ address
+ 2);
1270 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1272 relocation
, rel
->r_addend
);
1277 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
1278 because such sections are not SEC_ALLOC and thus ld.so will
1279 not process them. */
1280 if (unresolved_reloc
1281 && !((input_section
->flags
& SEC_DEBUGGING
) != 0 && h
->def_dynamic
))
1283 (*_bfd_error_handler
)
1284 (_("%B(%A+0x%lx): unresolvable relocation against symbol `%s'"),
1286 input_section
, (long) rel
->r_offset
, h
->root
.root
.string
);
1290 if (r
!= bfd_reloc_ok
)
1295 name
= h
->root
.root
.string
;
1298 name
= bfd_elf_string_from_elf_section (input_bfd
,
1299 symtab_hdr
->sh_link
,
1304 name
= bfd_section_name (input_bfd
, sec
);
1307 if (r
== bfd_reloc_overflow
)
1309 if (!(info
->callbacks
->reloc_overflow
1310 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
1311 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
)))
1316 (*_bfd_error_handler
)
1317 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
1318 input_bfd
, input_section
,
1319 (long) rel
->r_offset
, name
, (int) r
);
1329 bfin_gc_mark_hook (asection
* sec
,
1330 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1331 Elf_Internal_Rela
* rel
,
1332 struct elf_link_hash_entry
*h
,
1333 Elf_Internal_Sym
* sym
)
1337 switch (ELF32_R_TYPE (rel
->r_info
))
1340 case R_BFIN_GNU_VTINHERIT
:
1341 case R_BFIN_GNU_VTENTRY
:
1345 switch (h
->root
.type
)
1350 case bfd_link_hash_defined
:
1351 case bfd_link_hash_defweak
:
1352 return h
->root
.u
.def
.section
;
1354 case bfd_link_hash_common
:
1355 return h
->root
.u
.c
.p
->section
;
1360 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1366 /* Update the got entry reference counts for the section being removed. */
1369 bfin_gc_sweep_hook (bfd
* abfd
,
1370 struct bfd_link_info
*info
,
1372 const Elf_Internal_Rela
* relocs
)
1374 Elf_Internal_Shdr
*symtab_hdr
;
1375 struct elf_link_hash_entry
**sym_hashes
;
1376 bfd_signed_vma
*local_got_refcounts
;
1377 const Elf_Internal_Rela
*rel
, *relend
;
1382 dynobj
= elf_hash_table (info
)->dynobj
;
1386 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1387 sym_hashes
= elf_sym_hashes (abfd
);
1388 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1390 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1391 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1393 relend
= relocs
+ sec
->reloc_count
;
1394 for (rel
= relocs
; rel
< relend
; rel
++)
1396 unsigned long r_symndx
;
1397 struct elf_link_hash_entry
*h
;
1399 switch (ELF32_R_TYPE (rel
->r_info
))
1402 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1403 if (r_symndx
>= symtab_hdr
->sh_info
)
1405 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1406 if (h
->got
.refcount
> 0)
1409 if (h
->got
.refcount
== 0)
1411 /* We don't need the .got entry any more. */
1413 srelgot
->size
-= sizeof (Elf32_External_Rela
);
1417 else if (local_got_refcounts
!= NULL
)
1419 if (local_got_refcounts
[r_symndx
] > 0)
1421 --local_got_refcounts
[r_symndx
];
1422 if (local_got_refcounts
[r_symndx
] == 0)
1424 /* We don't need the .got entry any more. */
1427 srelgot
->size
-= sizeof (Elf32_External_Rela
);
1441 /* Merge backend specific data from an object file to the output
1442 object file when linking. */
1444 elf32_bfin_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
1449 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1450 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1453 in_flags
= elf_elfheader (ibfd
)->e_flags
;
1454 out_flags
= elf_elfheader (obfd
)->e_flags
;
1456 if (!elf_flags_init (obfd
))
1458 elf_flags_init (obfd
) = TRUE
;
1459 elf_elfheader (obfd
)->e_flags
= in_flags
;
1467 elf32_bfin_set_private_flags (bfd
* abfd
, flagword flags
)
1469 elf_elfheader (abfd
)->e_flags
= flags
;
1470 elf_flags_init (abfd
) = TRUE
;
1475 /* Display the flags field. */
1477 elf32_bfin_print_private_bfd_data (bfd
* abfd
, PTR ptr
)
1479 FILE *file
= (FILE *) ptr
;
1481 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
1483 /* Print normal ELF private data. */
1484 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
1486 /* Ignore init flag - it may not be set, despite the flags field
1487 containing valid data. */
1489 /* xgettext:c-format */
1490 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
1497 /* bfin ELF linker hash entry. */
1499 struct bfin_link_hash_entry
1501 struct elf_link_hash_entry root
;
1503 /* Number of PC relative relocs copied for this symbol. */
1504 struct bfin_pcrel_relocs_copied
*pcrel_relocs_copied
;
1507 /* bfin ELF linker hash table. */
1509 struct bfin_link_hash_table
1511 struct elf_link_hash_table root
;
1513 /* Small local sym to section mapping cache. */
1514 struct sym_sec_cache sym_sec
;
1517 #define bfin_hash_entry(ent) ((struct bfin_link_hash_entry *) (ent))
1519 static struct bfd_hash_entry
*
1520 bfin_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1521 struct bfd_hash_table
*table
, const char *string
)
1523 struct bfd_hash_entry
*ret
= entry
;
1525 /* Allocate the structure if it has not already been allocated by a
1528 ret
= bfd_hash_allocate (table
, sizeof (struct bfin_link_hash_entry
));
1532 /* Call the allocation method of the superclass. */
1533 ret
= _bfd_elf_link_hash_newfunc (ret
, table
, string
);
1535 bfin_hash_entry (ret
)->pcrel_relocs_copied
= NULL
;
1540 /* Create an bfin ELF linker hash table. */
1542 static struct bfd_link_hash_table
*
1543 bfin_link_hash_table_create (bfd
* abfd
)
1545 struct bfin_link_hash_table
*ret
;
1546 bfd_size_type amt
= sizeof (struct bfin_link_hash_table
);
1548 ret
= (struct bfin_link_hash_table
*) bfd_malloc (amt
);
1549 if (ret
== (struct bfin_link_hash_table
*) NULL
)
1552 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
1553 bfin_link_hash_newfunc
,
1554 sizeof (struct bfin_link_hash_entry
)))
1560 ret
->sym_sec
.abfd
= NULL
;
1562 return &ret
->root
.root
;
1565 /* The size in bytes of an entry in the procedure linkage table. */
1567 /* Finish up the dynamic sections. */
1570 bfin_finish_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
1571 struct bfd_link_info
*info
)
1576 dynobj
= elf_hash_table (info
)->dynobj
;
1578 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1580 if (elf_hash_table (info
)->dynamic_sections_created
)
1582 Elf32_External_Dyn
*dyncon
, *dynconend
;
1584 BFD_ASSERT (sdyn
!= NULL
);
1586 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1587 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
1588 for (; dyncon
< dynconend
; dyncon
++)
1590 Elf_Internal_Dyn dyn
;
1592 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1600 /* Finish up dynamic symbol handling. We set the contents of various
1601 dynamic sections here. */
1604 bfin_finish_dynamic_symbol (bfd
* output_bfd
,
1605 struct bfd_link_info
*info
,
1606 struct elf_link_hash_entry
*h
,
1607 Elf_Internal_Sym
* sym
)
1611 dynobj
= elf_hash_table (info
)->dynobj
;
1613 if (h
->got
.offset
!= (bfd_vma
) - 1)
1617 Elf_Internal_Rela rela
;
1620 /* This symbol has an entry in the global offset table.
1623 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1624 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1625 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1627 rela
.r_offset
= (sgot
->output_section
->vma
1628 + sgot
->output_offset
1629 + (h
->got
.offset
& ~(bfd_vma
) 1));
1631 /* If this is a -Bsymbolic link, and the symbol is defined
1632 locally, we just want to emit a RELATIVE reloc. Likewise if
1633 the symbol was forced to be local because of a version file.
1634 The entry in the global offset table will already have been
1635 initialized in the relocate_section function. */
1638 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1640 fprintf(stderr
, "*** check this relocation %s\n", __FUNCTION__
);
1641 rela
.r_info
= ELF32_R_INFO (0, R_pcrel24
);
1642 rela
.r_addend
= bfd_get_signed_32 (output_bfd
,
1646 offset
& ~(bfd_vma
) 1)));
1650 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1651 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1652 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_got
);
1656 loc
= srela
->contents
;
1657 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1658 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1665 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1666 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1667 || h
== elf_hash_table (info
)->hgot
)
1668 sym
->st_shndx
= SHN_ABS
;
1673 /* Adjust a symbol defined by a dynamic object and referenced by a
1674 regular object. The current definition is in some section of the
1675 dynamic object, but we're not including those sections. We have to
1676 change the definition to something the rest of the link can
1680 bfin_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1681 struct elf_link_hash_entry
*h
)
1685 unsigned int power_of_two
;
1687 dynobj
= elf_hash_table (info
)->dynobj
;
1689 /* Make sure we know what is going on here. */
1690 BFD_ASSERT (dynobj
!= NULL
1692 || h
->u
.weakdef
!= NULL
1693 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
1695 /* If this is a function, put it in the procedure linkage table. We
1696 will fill in the contents of the procedure linkage table later,
1697 when we know the address of the .got section. */
1698 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
1703 /* If this is a weak symbol, and there is a real definition, the
1704 processor independent code will have arranged for us to see the
1705 real definition first, and we can just use the same value. */
1706 if (h
->u
.weakdef
!= NULL
)
1708 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1709 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1710 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1711 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1715 /* This is a reference to a symbol defined by a dynamic object which
1716 is not a function. */
1718 /* If we are creating a shared library, we must presume that the
1719 only references to the symbol are via the global offset table.
1720 For such cases we need not do anything here; the relocations will
1721 be handled correctly by relocate_section. */
1725 /* We must allocate the symbol in our .dynbss section, which will
1726 become part of the .bss section of the executable. There will be
1727 an entry for this symbol in the .dynsym section. The dynamic
1728 object will contain position independent code, so all references
1729 from the dynamic object to this symbol will go through the global
1730 offset table. The dynamic linker will use the .dynsym entry to
1731 determine the address it must put in the global offset table, so
1732 both the dynamic object and the regular object will refer to the
1733 same memory location for the variable. */
1735 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1736 BFD_ASSERT (s
!= NULL
);
1738 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
1739 copy the initial value out of the dynamic object and into the
1740 runtime process image. We need to remember the offset into the
1741 .rela.bss section we are going to use. */
1742 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1746 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1747 BFD_ASSERT (srel
!= NULL
);
1748 srel
->size
+= sizeof (Elf32_External_Rela
);
1752 /* We need to figure out the alignment required for this symbol. I
1753 have no idea how ELF linkers handle this. */
1754 power_of_two
= bfd_log2 (h
->size
);
1755 if (power_of_two
> 3)
1758 /* Apply the required alignment. */
1759 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
1760 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1762 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1766 /* Define the symbol as being at this point in the section. */
1767 h
->root
.u
.def
.section
= s
;
1768 h
->root
.u
.def
.value
= s
->size
;
1770 /* Increment the section size to make room for the symbol. */
1776 /* The bfin linker needs to keep track of the number of relocs that it
1777 decides to copy in check_relocs for each symbol. This is so that it
1778 can discard PC relative relocs if it doesn't need them when linking
1779 with -Bsymbolic. We store the information in a field extending the
1780 regular ELF linker hash table. */
1782 /* This structure keeps track of the number of PC relative relocs we have
1783 copied for a given symbol. */
1785 struct bfin_pcrel_relocs_copied
1788 struct bfin_pcrel_relocs_copied
*next
;
1789 /* A section in dynobj. */
1791 /* Number of relocs copied in this section. */
1792 bfd_size_type count
;
1795 /* This function is called via elf_link_hash_traverse if we are
1796 creating a shared object. In the -Bsymbolic case it discards the
1797 space allocated to copy PC relative relocs against symbols which
1798 are defined in regular objects. For the normal shared case, it
1799 discards space for pc-relative relocs that have become local due to
1800 symbol visibility changes. We allocated space for them in the
1801 check_relocs routine, but we won't fill them in in the
1802 relocate_section routine.
1804 We also check whether any of the remaining relocations apply
1805 against a readonly section, and set the DF_TEXTREL flag in this
1809 bfin_discard_copies (struct elf_link_hash_entry
*h
, PTR inf
)
1811 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1812 struct bfin_pcrel_relocs_copied
*s
;
1814 if (h
->root
.type
== bfd_link_hash_warning
)
1815 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1817 if (!h
->def_regular
|| (!info
->symbolic
&& !h
->forced_local
))
1819 if ((info
->flags
& DF_TEXTREL
) == 0)
1821 /* Look for relocations against read-only sections. */
1822 for (s
= bfin_hash_entry (h
)->pcrel_relocs_copied
;
1823 s
!= NULL
; s
= s
->next
)
1824 if ((s
->section
->flags
& SEC_READONLY
) != 0)
1826 info
->flags
|= DF_TEXTREL
;
1834 for (s
= bfin_hash_entry (h
)->pcrel_relocs_copied
;
1835 s
!= NULL
; s
= s
->next
)
1836 s
->section
->size
-= s
->count
* sizeof (Elf32_External_Rela
);
1841 /* Set the sizes of the dynamic sections. */
1842 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
1845 bfin_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
1846 struct bfd_link_info
*info
)
1852 dynobj
= elf_hash_table (info
)->dynobj
;
1853 BFD_ASSERT (dynobj
!= NULL
);
1855 if (elf_hash_table (info
)->dynamic_sections_created
)
1857 /* Set the contents of the .interp section to the interpreter. */
1858 if (info
->executable
)
1860 s
= bfd_get_section_by_name (dynobj
, ".interp");
1861 BFD_ASSERT (s
!= NULL
);
1862 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1863 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1868 /* We may have created entries in the .rela.got section.
1869 However, if we are not creating the dynamic sections, we will
1870 not actually use these entries. Reset the size of .rela.got,
1871 which will cause it to get stripped from the output file
1873 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1878 /* If this is a -Bsymbolic shared link, then we need to discard all
1879 PC relative relocs against symbols defined in a regular object.
1880 For the normal shared case we discard the PC relative relocs
1881 against symbols that have become local due to visibility changes.
1882 We allocated space for them in the check_relocs routine, but we
1883 will not fill them in in the relocate_section routine. */
1885 elf_link_hash_traverse (elf_hash_table (info
),
1886 bfin_discard_copies
, (PTR
) info
);
1888 /* The check_relocs and adjust_dynamic_symbol entry points have
1889 determined the sizes of the various dynamic sections. Allocate
1892 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1897 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1900 /* It's OK to base decisions on the section name, because none
1901 of the dynobj section names depend upon the input files. */
1902 name
= bfd_get_section_name (dynobj
, s
);
1906 if (strncmp (name
, ".rela", 5) == 0)
1910 /* If we don't need this section, strip it from the
1911 output file. This is mostly to handle .rela.bss and
1912 .rela.plt. We must create both sections in
1913 create_dynamic_sections, because they must be created
1914 before the linker maps input sections to output
1915 sections. The linker does that before
1916 adjust_dynamic_symbol is called, and it is that
1917 function which decides whether anything needs to go
1918 into these sections. */
1925 /* We use the reloc_count field as a counter if we need
1926 to copy relocs into the output file. */
1930 else if (strncmp (name
, ".got", 4) != 0)
1932 /* It's not one of our sections, so don't allocate space. */
1938 s
->flags
|= SEC_EXCLUDE
;
1942 /* Allocate memory for the section contents. */
1943 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
1944 Unused entries should be reclaimed before the section's contents
1945 are written out, but at the moment this does not happen. Thus in
1946 order to prevent writing out garbage, we initialise the section's
1947 contents to zero. */
1948 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
1949 if (s
->contents
== NULL
&& s
->size
!= 0)
1953 if (elf_hash_table (info
)->dynamic_sections_created
)
1955 /* Add some entries to the .dynamic section. We fill in the
1956 values later, in bfin_finish_dynamic_sections, but we
1957 must add the entries now so that we get the correct size for
1958 the .dynamic section. The DT_DEBUG entry is filled in by the
1959 dynamic linker and used by the debugger. */
1960 #define add_dynamic_entry(TAG, VAL) \
1961 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1965 if (!add_dynamic_entry (DT_DEBUG
, 0))
1972 if (!add_dynamic_entry (DT_RELA
, 0)
1973 || !add_dynamic_entry (DT_RELASZ
, 0)
1974 || !add_dynamic_entry (DT_RELAENT
,
1975 sizeof (Elf32_External_Rela
)))
1979 if ((info
->flags
& DF_TEXTREL
) != 0)
1981 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1985 #undef add_dynamic_entry
1990 /* Given a .data section and a .emreloc in-memory section, store
1991 relocation information into the .emreloc section which can be
1992 used at runtime to relocate the section. This is called by the
1993 linker when the --embedded-relocs switch is used. This is called
1994 after the add_symbols entry point has been called for all the
1995 objects, and before the final_link entry point is called. */
1997 bfd_boolean bfd_bfin_elf32_create_embedded_relocs
1998 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, asection
*, char **));
2001 bfd_bfin_elf32_create_embedded_relocs (
2003 struct bfd_link_info
*info
,
2008 Elf_Internal_Shdr
*symtab_hdr
;
2009 Elf_Internal_Sym
*isymbuf
= NULL
;
2010 Elf_Internal_Rela
*internal_relocs
= NULL
;
2011 Elf_Internal_Rela
*irel
, *irelend
;
2015 BFD_ASSERT (! info
->relocatable
);
2019 if (datasec
->reloc_count
== 0)
2022 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2024 /* Get a copy of the native relocations. */
2025 internal_relocs
= (_bfd_elf_link_read_relocs
2026 (abfd
, datasec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2027 info
->keep_memory
));
2028 if (internal_relocs
== NULL
)
2031 amt
= (bfd_size_type
) datasec
->reloc_count
* 12;
2032 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, amt
);
2033 if (relsec
->contents
== NULL
)
2036 p
= relsec
->contents
;
2038 irelend
= internal_relocs
+ datasec
->reloc_count
;
2039 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
2041 asection
*targetsec
;
2043 /* We are going to write a four byte longword into the runtime
2044 reloc section. The longword will be the address in the data
2045 section which must be relocated. It is followed by the name
2046 of the target section NUL-padded or truncated to 8
2049 /* We can only relocate absolute longword relocs at run time. */
2050 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_byte4_data
)
2052 *errmsg
= _("unsupported reloc type");
2053 bfd_set_error (bfd_error_bad_value
);
2057 /* Get the target section referred to by the reloc. */
2058 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2060 /* A local symbol. */
2061 Elf_Internal_Sym
*isym
;
2063 /* Read this BFD's local symbols if we haven't done so already. */
2064 if (isymbuf
== NULL
)
2066 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2067 if (isymbuf
== NULL
)
2068 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2069 symtab_hdr
->sh_info
, 0,
2071 if (isymbuf
== NULL
)
2075 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2076 targetsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2081 struct elf_link_hash_entry
*h
;
2083 /* An external symbol. */
2084 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
2085 h
= elf_sym_hashes (abfd
)[indx
];
2086 BFD_ASSERT (h
!= NULL
);
2087 if (h
->root
.type
== bfd_link_hash_defined
2088 || h
->root
.type
== bfd_link_hash_defweak
)
2089 targetsec
= h
->root
.u
.def
.section
;
2094 bfd_put_32 (abfd
, irel
->r_offset
+ datasec
->output_offset
, p
);
2095 memset (p
+ 4, 0, 8);
2096 if (targetsec
!= NULL
)
2097 strncpy ((char *) p
+ 4, targetsec
->output_section
->name
, 8);
2100 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2102 if (internal_relocs
!= NULL
2103 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
2104 free (internal_relocs
);
2108 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2110 if (internal_relocs
!= NULL
2111 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
2112 free (internal_relocs
);
2116 #define TARGET_LITTLE_SYM bfd_elf32_bfin_vec
2117 #define TARGET_LITTLE_NAME "elf32-bfin"
2118 #define ELF_ARCH bfd_arch_bfin
2119 #define ELF_MACHINE_CODE EM_BLACKFIN
2120 #define ELF_MAXPAGESIZE 0x1000
2121 #define elf_symbol_leading_char '_'
2123 #define bfd_elf32_bfd_reloc_type_lookup bfin_bfd_reloc_type_lookup
2124 #define elf_info_to_howto bfin_info_to_howto
2125 #define elf_info_to_howto_rel 0
2127 #define bfd_elf32_bfd_is_local_label_name \
2128 bfin_is_local_label_name
2129 #define bfin_hash_table(p) \
2130 ((struct bfin_link_hash_table *) (p)->hash)
2134 #define elf_backend_create_dynamic_sections \
2135 _bfd_elf_create_dynamic_sections
2136 #define bfd_elf32_bfd_link_hash_table_create \
2137 bfin_link_hash_table_create
2138 #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link
2140 #define elf_backend_check_relocs bfin_check_relocs
2141 #define elf_backend_adjust_dynamic_symbol \
2142 bfin_adjust_dynamic_symbol
2143 #define elf_backend_size_dynamic_sections \
2144 bfin_size_dynamic_sections
2145 #define elf_backend_relocate_section bfin_relocate_section
2146 #define elf_backend_finish_dynamic_symbol \
2147 bfin_finish_dynamic_symbol
2148 #define elf_backend_finish_dynamic_sections \
2149 bfin_finish_dynamic_sections
2150 #define elf_backend_gc_mark_hook bfin_gc_mark_hook
2151 #define elf_backend_gc_sweep_hook bfin_gc_sweep_hook
2152 #define bfd_elf32_bfd_merge_private_bfd_data \
2153 elf32_bfin_merge_private_bfd_data
2154 #define bfd_elf32_bfd_set_private_flags \
2155 elf32_bfin_set_private_flags
2156 #define bfd_elf32_bfd_print_private_bfd_data \
2157 elf32_bfin_print_private_bfd_data
2158 #define elf_backend_reloc_type_class elf32_bfin_reloc_type_class
2159 #define elf_backend_can_gc_sections 1
2160 #define elf_backend_can_refcount 1
2161 #define elf_backend_want_got_plt 0
2162 #define elf_backend_plt_readonly 1
2163 #define elf_backend_want_plt_sym 0
2164 #define elf_backend_got_header_size 12
2165 #define elf_backend_rela_normal 1
2168 #include "elf32-target.h"