1 /* 32-bit ELF support for TI C6X
3 Free Software Foundation, Inc.
4 Contributed by Joseph Myers <joseph@codesourcery.com>
5 Bernd Schmidt <bernds@codesourcery.com>
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
27 #include "libiberty.h"
29 #include "elf/tic6x.h"
30 #include "elf32-tic6x.h"
32 #define ELF_DYNAMIC_INTERPRETER "/lib/ld-uClibc.so.0"
34 /* DSBT binaries have a default 128K stack. */
35 #define DEFAULT_STACK_SIZE 0x20000
37 /* The size in bytes of an entry in the procedure linkage table. */
38 #define PLT_ENTRY_SIZE 24
40 /* TI C6X ELF linker hash table. */
42 struct elf32_tic6x_link_hash_table
44 struct elf_link_hash_table elf
;
46 /* Short-cuts to get to dynamic linker sections. */
50 /* C6X specific command line arguments. */
51 struct elf32_tic6x_params params
;
53 /* Small local sym cache. */
54 struct sym_cache sym_cache
;
56 /* The output BFD, for convenience. */
59 /* The .dsbt section. */
63 /* Get the TI C6X ELF linker hash table from a link_info structure. */
65 #define elf32_tic6x_hash_table(p) \
66 ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
68 /* TI C6X ELF linker hash entry. */
70 struct elf32_tic6x_link_hash_entry
72 struct elf_link_hash_entry elf
;
74 /* Track dynamic relocs copied for this symbol. */
75 struct elf_dyn_relocs
*dyn_relocs
;
78 struct elf32_tic6x_obj_tdata
80 struct elf_obj_tdata root
;
82 /* Whether to use RELA relocations when generating relocations.
83 This is a per-object flag to allow the assembler to generate REL
84 relocations for use in linker testcases. */
85 bfd_boolean use_rela_p
;
88 #define elf32_tic6x_tdata(abfd) \
89 ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
91 #define is_tic6x_elf(bfd) \
92 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
93 && elf_tdata (bfd) != NULL \
94 && elf_object_id (bfd) == TIC6X_ELF_DATA)
96 /* C6X ELF uses two common sections. One is the usual one, and the
97 other is for small objects. All the small objects are kept
98 together, and then referenced via the gp pointer, which yields
99 faster assembler code. This is what we use for the small common
100 section. This approach is copied from ecoff.c. */
101 static asection tic6x_elf_scom_section
;
102 static asymbol tic6x_elf_scom_symbol
;
103 static asymbol
*tic6x_elf_scom_symbol_ptr
;
105 static reloc_howto_type elf32_tic6x_howto_table
[] =
107 HOWTO (R_C6000_NONE
, /* type */
109 0, /* size (0 = byte, 1 = short, 2 = long) */
111 FALSE
, /* pc_relative */
113 complain_overflow_dont
,/* complain_on_overflow */
114 bfd_elf_generic_reloc
, /* special_function */
115 "R_C6000_NONE", /* name */
116 FALSE
, /* partial_inplace */
119 FALSE
), /* pcrel_offset */
120 HOWTO (R_C6000_ABS32
, /* type */
122 2, /* size (0 = byte, 1 = short, 2 = long) */
124 FALSE
, /* pc_relative */
126 complain_overflow_dont
,/* complain_on_overflow */
127 bfd_elf_generic_reloc
, /* special_function */
128 "R_C6000_ABS32", /* name */
129 FALSE
, /* partial_inplace */
131 0xffffffff, /* dst_mask */
132 FALSE
), /* pcrel_offset */
133 HOWTO (R_C6000_ABS16
, /* type */
135 1, /* size (0 = byte, 1 = short, 2 = long) */
137 FALSE
, /* pc_relative */
139 complain_overflow_bitfield
,/* complain_on_overflow */
140 bfd_elf_generic_reloc
, /* special_function */
141 "R_C6000_ABS16", /* name */
142 FALSE
, /* partial_inplace */
144 0x0000ffff, /* dst_mask */
145 FALSE
), /* pcrel_offset */
146 HOWTO (R_C6000_ABS8
, /* type */
148 0, /* size (0 = byte, 1 = short, 2 = long) */
150 FALSE
, /* pc_relative */
152 complain_overflow_bitfield
,/* complain_on_overflow */
153 bfd_elf_generic_reloc
, /* special_function */
154 "R_C6000_ABS8", /* name */
155 FALSE
, /* partial_inplace */
157 0x000000ff, /* dst_mask */
158 FALSE
), /* pcrel_offset */
159 HOWTO (R_C6000_PCR_S21
, /* type */
161 2, /* size (0 = byte, 1 = short, 2 = long) */
163 TRUE
, /* pc_relative */
165 complain_overflow_signed
,/* complain_on_overflow */
166 bfd_elf_generic_reloc
, /* special_function */
167 "R_C6000_PCR_S21", /* name */
168 FALSE
, /* partial_inplace */
170 0x0fffff80, /* dst_mask */
171 TRUE
), /* pcrel_offset */
172 HOWTO (R_C6000_PCR_S12
, /* type */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
176 TRUE
, /* pc_relative */
178 complain_overflow_signed
,/* complain_on_overflow */
179 bfd_elf_generic_reloc
, /* special_function */
180 "R_C6000_PCR_S12", /* name */
181 FALSE
, /* partial_inplace */
183 0x0fff0000, /* dst_mask */
184 TRUE
), /* pcrel_offset */
185 HOWTO (R_C6000_PCR_S10
, /* type */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
189 TRUE
, /* pc_relative */
191 complain_overflow_signed
,/* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_C6000_PCR_S10", /* name */
194 FALSE
, /* partial_inplace */
196 0x007fe000, /* dst_mask */
197 TRUE
), /* pcrel_offset */
198 HOWTO (R_C6000_PCR_S7
, /* type */
200 2, /* size (0 = byte, 1 = short, 2 = long) */
202 TRUE
, /* pc_relative */
204 complain_overflow_signed
,/* complain_on_overflow */
205 bfd_elf_generic_reloc
, /* special_function */
206 "R_C6000_PCR_S7", /* name */
207 FALSE
, /* partial_inplace */
209 0x007f0000, /* dst_mask */
210 TRUE
), /* pcrel_offset */
211 HOWTO (R_C6000_ABS_S16
, /* type */
213 2, /* size (0 = byte, 1 = short, 2 = long) */
215 FALSE
, /* pc_relative */
217 complain_overflow_signed
,/* complain_on_overflow */
218 bfd_elf_generic_reloc
, /* special_function */
219 "R_C6000_ABS_S16", /* name */
220 FALSE
, /* partial_inplace */
222 0x007fff80, /* dst_mask */
223 FALSE
), /* pcrel_offset */
224 HOWTO (R_C6000_ABS_L16
, /* type */
226 2, /* size (0 = byte, 1 = short, 2 = long) */
228 FALSE
, /* pc_relative */
230 complain_overflow_dont
,/* complain_on_overflow */
231 bfd_elf_generic_reloc
, /* special_function */
232 "R_C6000_ABS_L16", /* name */
233 FALSE
, /* partial_inplace */
235 0x007fff80, /* dst_mask */
236 FALSE
), /* pcrel_offset */
237 HOWTO (R_C6000_ABS_H16
, /* type */
239 2, /* size (0 = byte, 1 = short, 2 = long) */
241 FALSE
, /* pc_relative */
243 complain_overflow_dont
,/* complain_on_overflow */
244 bfd_elf_generic_reloc
, /* special_function */
245 "R_C6000_ABS_H16", /* name */
246 FALSE
, /* partial_inplace */
248 0x007fff80, /* dst_mask */
249 FALSE
), /* pcrel_offset */
250 HOWTO (R_C6000_SBR_U15_B
, /* type */
252 2, /* size (0 = byte, 1 = short, 2 = long) */
254 FALSE
, /* pc_relative */
256 complain_overflow_unsigned
,/* complain_on_overflow */
257 bfd_elf_generic_reloc
, /* special_function */
258 "R_C6000_SBR_U15_B", /* name */
259 FALSE
, /* partial_inplace */
261 0x007fff00, /* dst_mask */
262 FALSE
), /* pcrel_offset */
263 HOWTO (R_C6000_SBR_U15_H
, /* type */
265 2, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE
, /* pc_relative */
269 complain_overflow_unsigned
,/* complain_on_overflow */
270 bfd_elf_generic_reloc
, /* special_function */
271 "R_C6000_SBR_U15_H", /* name */
272 FALSE
, /* partial_inplace */
274 0x007fff00, /* dst_mask */
275 FALSE
), /* pcrel_offset */
276 HOWTO (R_C6000_SBR_U15_W
, /* type */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE
, /* pc_relative */
282 complain_overflow_unsigned
,/* complain_on_overflow */
283 bfd_elf_generic_reloc
, /* special_function */
284 "R_C6000_SBR_U15_W", /* name */
285 FALSE
, /* partial_inplace */
287 0x007fff00, /* dst_mask */
288 FALSE
), /* pcrel_offset */
289 HOWTO (R_C6000_SBR_S16
, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE
, /* pc_relative */
295 complain_overflow_signed
,/* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_C6000_SBR_S16", /* name */
298 FALSE
, /* partial_inplace */
300 0x007fff80, /* dst_mask */
301 FALSE
), /* pcrel_offset */
302 HOWTO (R_C6000_SBR_L16_B
, /* type */
304 2, /* size (0 = byte, 1 = short, 2 = long) */
306 FALSE
, /* pc_relative */
308 complain_overflow_dont
,/* complain_on_overflow */
309 bfd_elf_generic_reloc
, /* special_function */
310 "R_C6000_SBR_L16_B", /* name */
311 FALSE
, /* partial_inplace */
313 0x007fff80, /* dst_mask */
314 FALSE
), /* pcrel_offset */
315 HOWTO (R_C6000_SBR_L16_H
, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 FALSE
, /* pc_relative */
321 complain_overflow_dont
,/* complain_on_overflow */
322 bfd_elf_generic_reloc
, /* special_function */
323 "R_C6000_SBR_L16_H", /* name */
324 FALSE
, /* partial_inplace */
326 0x007fff80, /* dst_mask */
327 FALSE
), /* pcrel_offset */
328 HOWTO (R_C6000_SBR_L16_W
, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 FALSE
, /* pc_relative */
334 complain_overflow_dont
,/* complain_on_overflow */
335 bfd_elf_generic_reloc
, /* special_function */
336 "R_C6000_SBR_L16_W", /* name */
337 FALSE
, /* partial_inplace */
339 0x007fff80, /* dst_mask */
340 FALSE
), /* pcrel_offset */
341 HOWTO (R_C6000_SBR_H16_B
, /* type */
343 2, /* size (0 = byte, 1 = short, 2 = long) */
345 FALSE
, /* pc_relative */
347 complain_overflow_dont
,/* complain_on_overflow */
348 bfd_elf_generic_reloc
, /* special_function */
349 "R_C6000_SBR_H16_B", /* name */
350 FALSE
, /* partial_inplace */
352 0x007fff80, /* dst_mask */
353 FALSE
), /* pcrel_offset */
354 HOWTO (R_C6000_SBR_H16_H
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_dont
,/* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_C6000_SBR_H16_H", /* name */
363 FALSE
, /* partial_inplace */
365 0x007fff80, /* dst_mask */
366 FALSE
), /* pcrel_offset */
367 HOWTO (R_C6000_SBR_H16_W
, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 FALSE
, /* pc_relative */
373 complain_overflow_dont
,/* complain_on_overflow */
374 bfd_elf_generic_reloc
, /* special_function */
375 "R_C6000_SBR_H16_W", /* name */
376 FALSE
, /* partial_inplace */
378 0x007fff80, /* dst_mask */
379 FALSE
), /* pcrel_offset */
380 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
384 FALSE
, /* pc_relative */
386 complain_overflow_unsigned
,/* complain_on_overflow */
387 bfd_elf_generic_reloc
, /* special_function */
388 "R_C6000_SBR_GOT_U15_W",/* name */
389 FALSE
, /* partial_inplace */
391 0x007fff00, /* dst_mask */
392 FALSE
), /* pcrel_offset */
393 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
395 2, /* size (0 = byte, 1 = short, 2 = long) */
397 FALSE
, /* pc_relative */
399 complain_overflow_dont
,/* complain_on_overflow */
400 bfd_elf_generic_reloc
, /* special_function */
401 "R_C6000_SBR_GOT_L16_W",/* name */
402 FALSE
, /* partial_inplace */
404 0x007fff80, /* dst_mask */
405 FALSE
), /* pcrel_offset */
406 HOWTO (R_C6000_SBR_GOT_H16_W
, /* type */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE
, /* pc_relative */
412 complain_overflow_dont
,/* complain_on_overflow */
413 bfd_elf_generic_reloc
, /* special_function */
414 "R_C6000_SBR_GOT_H16_W",/* name */
415 FALSE
, /* partial_inplace */
417 0x007fff80, /* dst_mask */
418 FALSE
), /* pcrel_offset */
419 HOWTO (R_C6000_DSBT_INDEX
, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 FALSE
, /* pc_relative */
425 complain_overflow_unsigned
,/* complain_on_overflow */
426 bfd_elf_generic_reloc
, /* special_function */
427 "R_C6000_DSBT_INDEX", /* name */
428 FALSE
, /* partial_inplace */
430 0x007fff00, /* dst_mask */
431 FALSE
), /* pcrel_offset */
432 HOWTO (R_C6000_PREL31
, /* type */
434 2, /* size (0 = byte, 1 = short, 2 = long) */
436 FALSE
, /* pc_relative */
438 complain_overflow_dont
,/* complain_on_overflow */
439 bfd_elf_generic_reloc
, /* special_function */
440 "R_C6000_PREL31", /* name */
441 FALSE
, /* partial_inplace */
443 0x7fffffff, /* dst_mask */
444 FALSE
), /* pcrel_offset */
445 HOWTO (R_C6000_COPY
, /* type */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
449 FALSE
, /* pc_relative */
451 complain_overflow_dont
,/* complain_on_overflow */
452 bfd_elf_generic_reloc
, /* special_function */
453 "R_C6000_COPY", /* name */
454 FALSE
, /* partial_inplace */
456 0xffffffff, /* dst_mask */
457 FALSE
), /* pcrel_offset */
458 HOWTO (R_C6000_JUMP_SLOT
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 FALSE
, /* pc_relative */
464 complain_overflow_dont
,/* complain_on_overflow */
465 bfd_elf_generic_reloc
, /* special_function */
466 "R_C6000_JUMP_SLOT", /* name */
467 FALSE
, /* partial_inplace */
469 0xffffffff, /* dst_mask */
470 FALSE
), /* pcrel_offset */
696 HOWTO (R_C6000_ALIGN
, /* type */
698 0, /* size (0 = byte, 1 = short, 2 = long) */
700 FALSE
, /* pc_relative */
702 complain_overflow_dont
,/* complain_on_overflow */
703 bfd_elf_generic_reloc
, /* special_function */
704 "R_C6000_ALIGN", /* name */
705 FALSE
, /* partial_inplace */
708 FALSE
), /* pcrel_offset */
709 HOWTO (R_C6000_FPHEAD
, /* type */
711 0, /* size (0 = byte, 1 = short, 2 = long) */
713 FALSE
, /* pc_relative */
715 complain_overflow_dont
,/* complain_on_overflow */
716 bfd_elf_generic_reloc
, /* special_function */
717 "R_C6000_FPHEAD", /* name */
718 FALSE
, /* partial_inplace */
721 FALSE
), /* pcrel_offset */
722 HOWTO (R_C6000_NOCMP
, /* type */
724 0, /* size (0 = byte, 1 = short, 2 = long) */
726 FALSE
, /* pc_relative */
728 complain_overflow_dont
,/* complain_on_overflow */
729 bfd_elf_generic_reloc
, /* special_function */
730 "R_C6000_NOCMP", /* name */
731 FALSE
, /* partial_inplace */
734 FALSE
) /* pcrel_offset */
737 static reloc_howto_type elf32_tic6x_howto_table_rel
[] =
739 HOWTO (R_C6000_NONE
, /* type */
741 0, /* size (0 = byte, 1 = short, 2 = long) */
743 FALSE
, /* pc_relative */
745 complain_overflow_dont
,/* complain_on_overflow */
746 bfd_elf_generic_reloc
, /* special_function */
747 "R_C6000_NONE", /* name */
748 TRUE
, /* partial_inplace */
751 FALSE
), /* pcrel_offset */
752 HOWTO (R_C6000_ABS32
, /* type */
754 2, /* size (0 = byte, 1 = short, 2 = long) */
756 FALSE
, /* pc_relative */
758 complain_overflow_dont
,/* complain_on_overflow */
759 bfd_elf_generic_reloc
, /* special_function */
760 "R_C6000_ABS32", /* name */
761 TRUE
, /* partial_inplace */
762 0xffffffff, /* src_mask */
763 0xffffffff, /* dst_mask */
764 FALSE
), /* pcrel_offset */
765 HOWTO (R_C6000_ABS16
, /* type */
767 1, /* size (0 = byte, 1 = short, 2 = long) */
769 FALSE
, /* pc_relative */
771 complain_overflow_bitfield
,/* complain_on_overflow */
772 bfd_elf_generic_reloc
, /* special_function */
773 "R_C6000_ABS16", /* name */
774 TRUE
, /* partial_inplace */
775 0x0000ffff, /* src_mask */
776 0x0000ffff, /* dst_mask */
777 FALSE
), /* pcrel_offset */
778 HOWTO (R_C6000_ABS8
, /* type */
780 0, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE
, /* pc_relative */
784 complain_overflow_bitfield
,/* complain_on_overflow */
785 bfd_elf_generic_reloc
, /* special_function */
786 "R_C6000_ABS8", /* name */
787 TRUE
, /* partial_inplace */
788 0x000000ff, /* src_mask */
789 0x000000ff, /* dst_mask */
790 FALSE
), /* pcrel_offset */
791 HOWTO (R_C6000_PCR_S21
, /* type */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
795 TRUE
, /* pc_relative */
797 complain_overflow_signed
,/* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 "R_C6000_PCR_S21", /* name */
800 TRUE
, /* partial_inplace */
801 0x0fffff80, /* src_mask */
802 0x0fffff80, /* dst_mask */
803 TRUE
), /* pcrel_offset */
804 HOWTO (R_C6000_PCR_S12
, /* type */
806 2, /* size (0 = byte, 1 = short, 2 = long) */
808 TRUE
, /* pc_relative */
810 complain_overflow_signed
,/* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_C6000_PCR_S12", /* name */
813 TRUE
, /* partial_inplace */
814 0x0fff0000, /* src_mask */
815 0x0fff0000, /* dst_mask */
816 TRUE
), /* pcrel_offset */
817 HOWTO (R_C6000_PCR_S10
, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 TRUE
, /* pc_relative */
823 complain_overflow_signed
,/* complain_on_overflow */
824 bfd_elf_generic_reloc
, /* special_function */
825 "R_C6000_PCR_S10", /* name */
826 TRUE
, /* partial_inplace */
827 0x007fe000, /* src_mask */
828 0x007fe000, /* dst_mask */
829 TRUE
), /* pcrel_offset */
830 HOWTO (R_C6000_PCR_S7
, /* type */
832 2, /* size (0 = byte, 1 = short, 2 = long) */
834 TRUE
, /* pc_relative */
836 complain_overflow_signed
,/* complain_on_overflow */
837 bfd_elf_generic_reloc
, /* special_function */
838 "R_C6000_PCR_S7", /* name */
839 TRUE
, /* partial_inplace */
840 0x007f0000, /* src_mask */
841 0x007f0000, /* dst_mask */
842 TRUE
), /* pcrel_offset */
843 HOWTO (R_C6000_ABS_S16
, /* type */
845 2, /* size (0 = byte, 1 = short, 2 = long) */
847 FALSE
, /* pc_relative */
849 complain_overflow_signed
,/* complain_on_overflow */
850 bfd_elf_generic_reloc
, /* special_function */
851 "R_C6000_ABS_S16", /* name */
852 TRUE
, /* partial_inplace */
853 0x007fff80, /* src_mask */
854 0x007fff80, /* dst_mask */
855 FALSE
), /* pcrel_offset */
856 HOWTO (R_C6000_ABS_L16
, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_dont
,/* complain_on_overflow */
863 bfd_elf_generic_reloc
, /* special_function */
864 "R_C6000_ABS_L16", /* name */
865 TRUE
, /* partial_inplace */
866 0x007fff80, /* src_mask */
867 0x007fff80, /* dst_mask */
868 FALSE
), /* pcrel_offset */
869 EMPTY_HOWTO (R_C6000_ABS_H16
),
870 HOWTO (R_C6000_SBR_U15_B
, /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 FALSE
, /* pc_relative */
876 complain_overflow_unsigned
,/* complain_on_overflow */
877 bfd_elf_generic_reloc
, /* special_function */
878 "R_C6000_SBR_U15_B", /* name */
879 TRUE
, /* partial_inplace */
880 0x007fff00, /* src_mask */
881 0x007fff00, /* dst_mask */
882 FALSE
), /* pcrel_offset */
883 HOWTO (R_C6000_SBR_U15_H
, /* type */
885 2, /* size (0 = byte, 1 = short, 2 = long) */
887 FALSE
, /* pc_relative */
889 complain_overflow_unsigned
,/* complain_on_overflow */
890 bfd_elf_generic_reloc
, /* special_function */
891 "R_C6000_SBR_U15_H", /* name */
892 TRUE
, /* partial_inplace */
893 0x007fff00, /* src_mask */
894 0x007fff00, /* dst_mask */
895 FALSE
), /* pcrel_offset */
896 HOWTO (R_C6000_SBR_U15_W
, /* type */
898 2, /* size (0 = byte, 1 = short, 2 = long) */
900 FALSE
, /* pc_relative */
902 complain_overflow_unsigned
,/* complain_on_overflow */
903 bfd_elf_generic_reloc
, /* special_function */
904 "R_C6000_SBR_U15_W", /* name */
905 TRUE
, /* partial_inplace */
906 0x007fff00, /* src_mask */
907 0x007fff00, /* dst_mask */
908 FALSE
), /* pcrel_offset */
909 HOWTO (R_C6000_SBR_S16
, /* type */
911 2, /* size (0 = byte, 1 = short, 2 = long) */
913 FALSE
, /* pc_relative */
915 complain_overflow_signed
,/* complain_on_overflow */
916 bfd_elf_generic_reloc
, /* special_function */
917 "R_C6000_SBR_S16", /* name */
918 TRUE
, /* partial_inplace */
919 0x007fff80, /* src_mask */
920 0x007fff80, /* dst_mask */
921 FALSE
), /* pcrel_offset */
922 HOWTO (R_C6000_SBR_L16_B
, /* type */
924 2, /* 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_C6000_SBR_L16_B", /* name */
931 TRUE
, /* partial_inplace */
932 0x007fff80, /* src_mask */
933 0x007fff80, /* dst_mask */
934 FALSE
), /* pcrel_offset */
935 HOWTO (R_C6000_SBR_L16_H
, /* type */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
939 FALSE
, /* pc_relative */
941 complain_overflow_dont
,/* complain_on_overflow */
942 bfd_elf_generic_reloc
, /* special_function */
943 "R_C6000_SBR_L16_H", /* name */
944 TRUE
, /* partial_inplace */
945 0x007fff80, /* src_mask */
946 0x007fff80, /* dst_mask */
947 FALSE
), /* pcrel_offset */
948 HOWTO (R_C6000_SBR_L16_W
, /* type */
950 2, /* size (0 = byte, 1 = short, 2 = long) */
952 FALSE
, /* pc_relative */
954 complain_overflow_dont
,/* complain_on_overflow */
955 bfd_elf_generic_reloc
, /* special_function */
956 "R_C6000_SBR_L16_W", /* name */
957 TRUE
, /* partial_inplace */
958 0x007fff80, /* src_mask */
959 0x007fff80, /* dst_mask */
960 FALSE
), /* pcrel_offset */
961 EMPTY_HOWTO (R_C6000_SBR_H16_B
),
962 EMPTY_HOWTO (R_C6000_SBR_H16_H
),
963 EMPTY_HOWTO (R_C6000_SBR_H16_W
),
964 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE
, /* pc_relative */
970 complain_overflow_unsigned
,/* complain_on_overflow */
971 bfd_elf_generic_reloc
, /* special_function */
972 "R_C6000_SBR_GOT_U15_W",/* name */
973 TRUE
, /* partial_inplace */
974 0x007fff00, /* src_mask */
975 0x007fff00, /* dst_mask */
976 FALSE
), /* pcrel_offset */
977 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
981 FALSE
, /* pc_relative */
983 complain_overflow_dont
,/* complain_on_overflow */
984 bfd_elf_generic_reloc
, /* special_function */
985 "R_C6000_SBR_GOT_L16_W",/* name */
986 TRUE
, /* partial_inplace */
987 0x007fff80, /* src_mask */
988 0x007fff80, /* dst_mask */
989 FALSE
), /* pcrel_offset */
990 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W
),
991 HOWTO (R_C6000_DSBT_INDEX
, /* type */
993 2, /* size (0 = byte, 1 = short, 2 = long) */
995 FALSE
, /* pc_relative */
997 complain_overflow_unsigned
,/* complain_on_overflow */
998 bfd_elf_generic_reloc
, /* special_function */
999 "R_C6000_DSBT_INDEX", /* name */
1000 TRUE
, /* partial_inplace */
1002 0x007fff00, /* dst_mask */
1003 FALSE
), /* pcrel_offset */
1004 HOWTO (R_C6000_PREL31
, /* type */
1006 2, /* size (0 = byte, 1 = short, 2 = long) */
1008 FALSE
, /* pc_relative */
1010 complain_overflow_dont
,/* complain_on_overflow */
1011 bfd_elf_generic_reloc
, /* special_function */
1012 "R_C6000_PREL31", /* name */
1013 TRUE
, /* partial_inplace */
1015 0x7fffffff, /* dst_mask */
1016 FALSE
), /* pcrel_offset */
1017 HOWTO (R_C6000_COPY
, /* type */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE
, /* pc_relative */
1023 complain_overflow_dont
,/* complain_on_overflow */
1024 bfd_elf_generic_reloc
, /* special_function */
1025 "R_C6000_COPY", /* name */
1026 TRUE
, /* partial_inplace */
1028 0xffffffff, /* dst_mask */
1029 FALSE
), /* pcrel_offset */
1030 HOWTO (R_C6000_JUMP_SLOT
, /* type */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1034 FALSE
, /* pc_relative */
1036 complain_overflow_dont
,/* complain_on_overflow */
1037 bfd_elf_generic_reloc
, /* special_function */
1038 "R_C6000_JUMP_SLOT", /* name */
1039 FALSE
, /* partial_inplace */
1041 0xffffffff, /* dst_mask */
1042 FALSE
), /* pcrel_offset */
1268 HOWTO (R_C6000_ALIGN
, /* type */
1270 0, /* size (0 = byte, 1 = short, 2 = long) */
1272 FALSE
, /* pc_relative */
1274 complain_overflow_dont
,/* complain_on_overflow */
1275 bfd_elf_generic_reloc
, /* special_function */
1276 "R_C6000_ALIGN", /* name */
1277 TRUE
, /* partial_inplace */
1280 FALSE
), /* pcrel_offset */
1281 HOWTO (R_C6000_FPHEAD
, /* type */
1283 0, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_dont
,/* complain_on_overflow */
1288 bfd_elf_generic_reloc
, /* special_function */
1289 "R_C6000_FPHEAD", /* name */
1290 TRUE
, /* partial_inplace */
1293 FALSE
), /* pcrel_offset */
1294 HOWTO (R_C6000_NOCMP
, /* type */
1296 0, /* size (0 = byte, 1 = short, 2 = long) */
1298 FALSE
, /* pc_relative */
1300 complain_overflow_dont
,/* complain_on_overflow */
1301 bfd_elf_generic_reloc
, /* special_function */
1302 "R_C6000_NOCMP", /* name */
1303 TRUE
, /* partial_inplace */
1306 FALSE
) /* pcrel_offset */
1309 /* Map BFD relocations to ELF relocations. */
1313 bfd_reloc_code_real_type bfd_reloc_val
;
1314 enum elf_tic6x_reloc_type elf_reloc_val
;
1317 static const tic6x_reloc_map elf32_tic6x_reloc_map
[] =
1319 { BFD_RELOC_NONE
, R_C6000_NONE
},
1320 { BFD_RELOC_32
, R_C6000_ABS32
},
1321 { BFD_RELOC_16
, R_C6000_ABS16
},
1322 { BFD_RELOC_8
, R_C6000_ABS8
},
1323 { BFD_RELOC_C6000_PCR_S21
, R_C6000_PCR_S21
},
1324 { BFD_RELOC_C6000_PCR_S12
, R_C6000_PCR_S12
},
1325 { BFD_RELOC_C6000_PCR_S10
, R_C6000_PCR_S10
},
1326 { BFD_RELOC_C6000_PCR_S7
, R_C6000_PCR_S7
},
1327 { BFD_RELOC_C6000_ABS_S16
, R_C6000_ABS_S16
},
1328 { BFD_RELOC_C6000_ABS_L16
, R_C6000_ABS_L16
},
1329 { BFD_RELOC_C6000_ABS_H16
, R_C6000_ABS_H16
},
1330 { BFD_RELOC_C6000_SBR_U15_B
, R_C6000_SBR_U15_B
},
1331 { BFD_RELOC_C6000_SBR_U15_H
, R_C6000_SBR_U15_H
},
1332 { BFD_RELOC_C6000_SBR_U15_W
, R_C6000_SBR_U15_W
},
1333 { BFD_RELOC_C6000_SBR_S16
, R_C6000_SBR_S16
},
1334 { BFD_RELOC_C6000_SBR_L16_B
, R_C6000_SBR_L16_B
},
1335 { BFD_RELOC_C6000_SBR_L16_H
, R_C6000_SBR_L16_H
},
1336 { BFD_RELOC_C6000_SBR_L16_W
, R_C6000_SBR_L16_W
},
1337 { BFD_RELOC_C6000_SBR_H16_B
, R_C6000_SBR_H16_B
},
1338 { BFD_RELOC_C6000_SBR_H16_H
, R_C6000_SBR_H16_H
},
1339 { BFD_RELOC_C6000_SBR_H16_W
, R_C6000_SBR_H16_W
},
1340 { BFD_RELOC_C6000_SBR_GOT_U15_W
, R_C6000_SBR_GOT_U15_W
},
1341 { BFD_RELOC_C6000_SBR_GOT_L16_W
, R_C6000_SBR_GOT_L16_W
},
1342 { BFD_RELOC_C6000_SBR_GOT_H16_W
, R_C6000_SBR_GOT_H16_W
},
1343 { BFD_RELOC_C6000_DSBT_INDEX
, R_C6000_DSBT_INDEX
},
1344 { BFD_RELOC_C6000_PREL31
, R_C6000_PREL31
},
1345 { BFD_RELOC_C6000_COPY
, R_C6000_COPY
},
1346 { BFD_RELOC_C6000_JUMP_SLOT
, R_C6000_JUMP_SLOT
},
1347 { BFD_RELOC_C6000_EHTYPE
, R_C6000_EHTYPE
},
1348 { BFD_RELOC_C6000_PCR_H16
, R_C6000_PCR_H16
},
1349 { BFD_RELOC_C6000_PCR_L16
, R_C6000_PCR_L16
},
1350 { BFD_RELOC_C6000_ALIGN
, R_C6000_ALIGN
},
1351 { BFD_RELOC_C6000_FPHEAD
, R_C6000_FPHEAD
},
1352 { BFD_RELOC_C6000_NOCMP
, R_C6000_NOCMP
}
1355 static reloc_howto_type
*
1356 elf32_tic6x_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1360 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_reloc_map
); i
++)
1361 if (elf32_tic6x_reloc_map
[i
].bfd_reloc_val
== code
)
1363 enum elf_tic6x_reloc_type elf_reloc_val
;
1364 reloc_howto_type
*howto
;
1366 elf_reloc_val
= elf32_tic6x_reloc_map
[i
].elf_reloc_val
;
1367 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1368 howto
= &elf32_tic6x_howto_table
[elf_reloc_val
];
1370 howto
= &elf32_tic6x_howto_table_rel
[elf_reloc_val
];
1372 /* Some relocations are RELA-only; do not return them for
1374 if (howto
->name
== NULL
)
1383 static reloc_howto_type
*
1384 elf32_tic6x_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1386 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1390 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table
); i
++)
1391 if (elf32_tic6x_howto_table
[i
].name
!= NULL
1392 && strcasecmp (elf32_tic6x_howto_table
[i
].name
, r_name
) == 0)
1393 return &elf32_tic6x_howto_table
[i
];
1399 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table_rel
); i
++)
1400 if (elf32_tic6x_howto_table_rel
[i
].name
!= NULL
1401 && strcasecmp (elf32_tic6x_howto_table_rel
[i
].name
, r_name
) == 0)
1402 return &elf32_tic6x_howto_table_rel
[i
];
1409 elf32_tic6x_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1410 Elf_Internal_Rela
*elf_reloc
)
1412 unsigned int r_type
;
1414 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1415 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table
))
1416 bfd_reloc
->howto
= NULL
;
1418 bfd_reloc
->howto
= &elf32_tic6x_howto_table
[r_type
];
1422 elf32_tic6x_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1423 Elf_Internal_Rela
*elf_reloc
)
1425 unsigned int r_type
;
1427 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1428 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table_rel
))
1429 bfd_reloc
->howto
= NULL
;
1431 bfd_reloc
->howto
= &elf32_tic6x_howto_table_rel
[r_type
];
1435 elf32_tic6x_set_use_rela_p (bfd
*abfd
, bfd_boolean use_rela_p
)
1437 elf32_tic6x_tdata (abfd
)->use_rela_p
= use_rela_p
;
1440 /* Create an entry in a C6X ELF linker hash table. */
1442 static struct bfd_hash_entry
*
1443 elf32_tic6x_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1444 struct bfd_hash_table
*table
,
1447 /* Allocate the structure if it has not already been allocated by a
1451 entry
= bfd_hash_allocate (table
,
1452 sizeof (struct elf32_tic6x_link_hash_entry
));
1457 /* Call the allocation method of the superclass. */
1458 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1461 struct elf32_tic6x_link_hash_entry
*eh
;
1463 eh
= (struct elf32_tic6x_link_hash_entry
*) entry
;
1464 eh
->dyn_relocs
= NULL
;
1470 /* Create a C6X ELF linker hash table. */
1472 static struct bfd_link_hash_table
*
1473 elf32_tic6x_link_hash_table_create (bfd
*abfd
)
1475 struct elf32_tic6x_link_hash_table
*ret
;
1476 bfd_size_type amt
= sizeof (struct elf32_tic6x_link_hash_table
);
1478 ret
= bfd_malloc (amt
);
1482 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1483 elf32_tic6x_link_hash_newfunc
,
1484 sizeof (struct elf32_tic6x_link_hash_entry
),
1491 ret
->sym_cache
.abfd
= NULL
;
1493 ret
->elf
.is_relocatable_executable
= 1;
1495 return &ret
->elf
.root
;
1498 /* Destroy a C6X ELF linker hash table. */
1501 elf32_tic6x_link_hash_table_free (struct bfd_link_hash_table
*hash
)
1503 _bfd_generic_link_hash_table_free (hash
);
1506 /* Called to pass PARAMS to the backend. We store them in the hash table
1507 associated with INFO. */
1510 elf32_tic6x_setup (struct bfd_link_info
*info
,
1511 struct elf32_tic6x_params
*params
)
1513 struct elf32_tic6x_link_hash_table
*htab
= elf32_tic6x_hash_table (info
);
1514 htab
->params
= *params
;
1517 /* Determine if we're dealing with a DSBT object. */
1520 elf32_tic6x_using_dsbt (bfd
*abfd
)
1522 return bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
,
1526 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1527 sections in DYNOBJ, and set up shortcuts to them in our hash
1531 elf32_tic6x_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1533 struct elf32_tic6x_link_hash_table
*htab
;
1536 htab
= elf32_tic6x_hash_table (info
);
1540 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1544 flags
= (SEC_ALLOC
| SEC_LOAD
1545 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1546 htab
->dsbt
= bfd_make_section_anyway_with_flags (dynobj
, ".dsbt",
1548 if (htab
->dsbt
== NULL
1549 || ! bfd_set_section_alignment (dynobj
, htab
->dsbt
, 2)
1550 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.splt
, 5))
1553 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1555 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1558 || (!info
->shared
&& !htab
->srelbss
))
1565 elf32_tic6x_mkobject (bfd
*abfd
)
1569 ret
= bfd_elf_allocate_object (abfd
, sizeof (struct elf32_tic6x_obj_tdata
),
1572 elf32_tic6x_set_use_rela_p (abfd
, TRUE
);
1576 /* Install relocation RELA into section SRELA, incrementing its
1580 elf32_tic6x_install_rela (bfd
*output_bfd
, asection
*srela
,
1581 Elf_Internal_Rela
*rela
)
1584 bfd_vma off
= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1585 loc
= srela
->contents
+ off
;
1586 BFD_ASSERT (off
< srela
->size
);
1587 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
1590 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1591 of the GOT at this offset have been initialized with the relocation. */
1594 elf32_tic6x_make_got_dynreloc (bfd
*output_bfd
,
1595 struct elf32_tic6x_link_hash_table
*htab
,
1596 asection
*sym_sec
, bfd_vma offset
)
1598 asection
*sgot
= htab
->elf
.sgot
;
1599 Elf_Internal_Rela outrel
;
1602 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
1603 outrel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
1604 if (sym_sec
&& sym_sec
->output_section
1605 && ! bfd_is_abs_section (sym_sec
->output_section
)
1606 && ! bfd_is_und_section (sym_sec
->output_section
))
1608 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
1609 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
1615 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_C6000_ABS32
);
1616 elf32_tic6x_install_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
1619 /* Finish up dynamic symbol handling. We set the contents of various
1620 dynamic sections here. */
1623 elf32_tic6x_finish_dynamic_symbol (bfd
* output_bfd
,
1624 struct bfd_link_info
*info
,
1625 struct elf_link_hash_entry
*h
,
1626 Elf_Internal_Sym
* sym
)
1629 struct elf32_tic6x_link_hash_table
*htab
;
1631 htab
= elf32_tic6x_hash_table (info
);
1632 dynobj
= htab
->elf
.dynobj
;
1634 if (h
->plt
.offset
!= (bfd_vma
) -1)
1637 bfd_vma got_section_offset
, got_dp_offset
, rela_offset
;
1638 Elf_Internal_Rela rela
;
1640 asection
*plt
, *gotplt
, *relplt
;
1641 const struct elf_backend_data
*bed
;
1643 bed
= get_elf_backend_data (output_bfd
);
1645 BFD_ASSERT (htab
->elf
.splt
!= NULL
);
1646 plt
= htab
->elf
.splt
;
1647 gotplt
= htab
->elf
.sgotplt
;
1648 relplt
= htab
->elf
.srelplt
;
1650 /* This symbol has an entry in the procedure linkage table. Set
1653 if ((h
->dynindx
== -1
1654 && !((h
->forced_local
|| info
->executable
)
1656 && h
->type
== STT_GNU_IFUNC
))
1662 /* Get the index in the procedure linkage table which
1663 corresponds to this symbol. This is the index of this symbol
1664 in all the symbols for which we are making plt entries. The
1665 first entry in the procedure linkage table is reserved.
1667 Get the offset into the .got table of the entry that
1668 corresponds to this function. Each .got entry is 4 bytes.
1669 The first three are reserved.
1671 For static executables, we don't reserve anything. */
1673 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1674 got_section_offset
= plt_index
+ bed
->got_header_size
/ 4;
1675 got_dp_offset
= got_section_offset
+ htab
->params
.dsbt_size
;
1676 rela_offset
= plt_index
* sizeof (Elf32_External_Rela
);
1678 got_section_offset
*= 4;
1680 /* Fill in the entry in the procedure linkage table. */
1682 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1683 bfd_put_32 (output_bfd
, got_dp_offset
<< 8 | 0x0100006e,
1684 plt
->contents
+ h
->plt
.offset
);
1685 /* mvk .s2 low(rela_offset), b0 */
1686 bfd_put_32 (output_bfd
, (rela_offset
& 0xffff) << 7 | 0x0000002a,
1687 plt
->contents
+ h
->plt
.offset
+ 4);
1688 /* mvkh .s2 high(rela_offset), b0 */
1689 bfd_put_32 (output_bfd
, ((rela_offset
>> 16) & 0xffff) << 7 | 0x0000006a,
1690 plt
->contents
+ h
->plt
.offset
+ 8);
1692 bfd_put_32 (output_bfd
, 0x00002000,
1693 plt
->contents
+ h
->plt
.offset
+ 12);
1695 bfd_put_32 (output_bfd
, 0x00080362,
1696 plt
->contents
+ h
->plt
.offset
+ 16);
1698 bfd_put_32 (output_bfd
, 0x00008000,
1699 plt
->contents
+ h
->plt
.offset
+ 20);
1701 /* Fill in the entry in the global offset table. */
1702 bfd_put_32 (output_bfd
,
1703 (plt
->output_section
->vma
+ plt
->output_offset
),
1704 gotplt
->contents
+ got_section_offset
);
1706 /* Fill in the entry in the .rel.plt section. */
1707 rela
.r_offset
= (gotplt
->output_section
->vma
1708 + gotplt
->output_offset
1709 + got_section_offset
);
1710 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_JUMP_SLOT
);
1712 loc
= relplt
->contents
+ rela_offset
;
1713 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1715 if (!h
->def_regular
)
1717 /* Mark the symbol as undefined, rather than as defined in
1718 the .plt section. */
1719 sym
->st_shndx
= SHN_UNDEF
;
1724 if (h
->got
.offset
!= (bfd_vma
) -1)
1729 /* This symbol has an entry in the global offset table.
1732 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1733 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1734 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1736 /* If this is a -Bsymbolic link, and the symbol is defined
1737 locally, we just want to emit a RELATIVE reloc. Likewise if
1738 the symbol was forced to be local because of a version file.
1739 The entry in the global offset table will already have been
1740 initialized in the relocate_section function. */
1743 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1745 asection
*s
= h
->root
.u
.def
.section
;
1746 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, s
,
1747 h
->got
.offset
& ~(bfd_vma
) 1);
1751 Elf_Internal_Rela outrel
;
1752 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1753 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1754 outrel
.r_offset
= (sgot
->output_section
->vma
1755 + sgot
->output_offset
1756 + (h
->got
.offset
& ~(bfd_vma
) 1));
1757 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_ABS32
);
1758 outrel
.r_addend
= 0;
1760 elf32_tic6x_install_rela (output_bfd
, srela
, &outrel
);
1766 Elf_Internal_Rela rel
;
1768 /* This symbol needs a copy reloc. Set it up. */
1770 if (h
->dynindx
== -1
1771 || (h
->root
.type
!= bfd_link_hash_defined
1772 && h
->root
.type
!= bfd_link_hash_defweak
)
1773 || htab
->srelbss
== NULL
)
1776 rel
.r_offset
= (h
->root
.u
.def
.value
1777 + h
->root
.u
.def
.section
->output_section
->vma
1778 + h
->root
.u
.def
.section
->output_offset
);
1779 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_COPY
);
1782 elf32_tic6x_install_rela (output_bfd
, htab
->srelbss
, &rel
);
1785 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1786 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1787 || h
== elf_hash_table (info
)->hgot
)
1788 sym
->st_shndx
= SHN_ABS
;
1793 /* Update the got entry reference counts for the section being removed. */
1796 elf32_tic6x_gc_sweep_hook (bfd
*abfd
,
1797 struct bfd_link_info
*info
,
1799 const Elf_Internal_Rela
*relocs
)
1801 struct elf32_tic6x_link_hash_table
*htab
;
1802 Elf_Internal_Shdr
*symtab_hdr
;
1803 struct elf_link_hash_entry
**sym_hashes
;
1804 bfd_signed_vma
*local_got_refcounts
;
1805 const Elf_Internal_Rela
*rel
, *relend
;
1807 if (info
->relocatable
)
1810 htab
= elf32_tic6x_hash_table (info
);
1814 elf_section_data (sec
)->local_dynrel
= NULL
;
1816 symtab_hdr
= &elf_symtab_hdr (abfd
);
1817 sym_hashes
= elf_sym_hashes (abfd
);
1818 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1820 relend
= relocs
+ sec
->reloc_count
;
1821 for (rel
= relocs
; rel
< relend
; rel
++)
1823 unsigned long r_symndx
;
1824 unsigned int r_type
;
1825 struct elf_link_hash_entry
*h
= NULL
;
1827 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1828 if (r_symndx
>= symtab_hdr
->sh_info
)
1830 struct elf32_tic6x_link_hash_entry
*eh
;
1831 struct elf_dyn_relocs
**pp
;
1832 struct elf_dyn_relocs
*p
;
1834 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1835 while (h
->root
.type
== bfd_link_hash_indirect
1836 || h
->root
.type
== bfd_link_hash_warning
)
1837 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1838 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
1840 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1843 /* Everything must go for SEC. */
1849 r_type
= ELF32_R_TYPE (rel
->r_info
);
1853 case R_C6000_SBR_GOT_U15_W
:
1854 case R_C6000_SBR_GOT_L16_W
:
1855 case R_C6000_SBR_GOT_H16_W
:
1858 if (h
->got
.refcount
> 0)
1859 h
->got
.refcount
-= 1;
1861 else if (local_got_refcounts
!= NULL
)
1863 if (local_got_refcounts
[r_symndx
] > 0)
1864 local_got_refcounts
[r_symndx
] -= 1;
1876 /* Adjust a symbol defined by a dynamic object and referenced by a
1877 regular object. The current definition is in some section of the
1878 dynamic object, but we're not including those sections. We have to
1879 change the definition to something the rest of the link can
1883 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1884 struct elf_link_hash_entry
*h
)
1886 struct elf32_tic6x_link_hash_table
*htab
;
1890 dynobj
= elf_hash_table (info
)->dynobj
;
1892 /* Make sure we know what is going on here. */
1893 BFD_ASSERT (dynobj
!= NULL
1895 || h
->u
.weakdef
!= NULL
1896 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
1898 /* If this is a function, put it in the procedure linkage table. We
1899 will fill in the contents of the procedure linkage table later,
1900 when we know the address of the .got section. */
1901 if (h
->type
== STT_FUNC
1904 if (h
->plt
.refcount
<= 0
1905 || SYMBOL_CALLS_LOCAL (info
, h
)
1906 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1907 && h
->root
.type
== bfd_link_hash_undefweak
))
1909 /* This case can occur if we saw a PLT32 reloc in an input
1910 file, but the symbol was never referred to by a dynamic
1911 object, or if all references were garbage collected. In
1912 such a case, we don't actually need to build a procedure
1913 linkage table, and we can just do a PC32 reloc instead. */
1914 h
->plt
.offset
= (bfd_vma
) -1;
1921 /* If this is a weak symbol, and there is a real definition, the
1922 processor independent code will have arranged for us to see the
1923 real definition first, and we can just use the same value. */
1924 if (h
->u
.weakdef
!= NULL
)
1926 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1927 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1928 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1929 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1930 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1934 /* This is a reference to a symbol defined by a dynamic object which
1935 is not a function. */
1937 /* If we are creating a shared library, we must presume that the
1938 only references to the symbol are via the global offset table.
1939 For such cases we need not do anything here; the relocations will
1940 be handled correctly by relocate_section. */
1944 /* If there are no references to this symbol that do not use the
1945 GOT, we don't need to generate a copy reloc. */
1946 if (!h
->non_got_ref
)
1949 /* If -z nocopyreloc was given, we won't generate them either. */
1950 if (info
->nocopyreloc
)
1956 htab
= elf32_tic6x_hash_table (info
);
1962 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1963 h
->root
.root
.string
);
1967 /* We must allocate the symbol in our .dynbss section, which will
1968 become part of the .bss section of the executable. There will be
1969 an entry for this symbol in the .dynsym section. The dynamic
1970 object will contain position independent code, so all references
1971 from the dynamic object to this symbol will go through the global
1972 offset table. The dynamic linker will use the .dynsym entry to
1973 determine the address it must put in the global offset table, so
1974 both the dynamic object and the regular object will refer to the
1975 same memory location for the variable. */
1977 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
1978 copy the initial value out of the dynamic object and into the
1979 runtime process image. */
1980 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1982 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
1988 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1992 elf32_tic6x_new_section_hook (bfd
*abfd
, asection
*sec
)
1996 ret
= _bfd_elf_new_section_hook (abfd
, sec
);
1997 sec
->use_rela_p
= elf32_tic6x_tdata (abfd
)->use_rela_p
;
2002 /* Return true if relocation REL against section SEC is a REL rather
2003 than RELA relocation. RELOCS is the first relocation in the
2004 section and ABFD is the bfd that contains SEC. */
2007 elf32_tic6x_rel_relocation_p (bfd
*abfd
, asection
*sec
,
2008 const Elf_Internal_Rela
*relocs
,
2009 const Elf_Internal_Rela
*rel
)
2011 Elf_Internal_Shdr
*rel_hdr
;
2012 const struct elf_backend_data
*bed
;
2014 /* To determine which flavor of relocation this is, we depend on the
2015 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2016 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
2017 if (rel_hdr
== NULL
)
2019 bed
= get_elf_backend_data (abfd
);
2020 return ((size_t) (rel
- relocs
)
2021 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
2024 /* We need dynamic symbols for every section, since segments can
2025 relocate independently. */
2027 elf32_tic6x_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2028 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2031 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2035 /* If sh_type is yet undecided, assume it could be
2036 SHT_PROGBITS/SHT_NOBITS. */
2040 /* There shouldn't be section relative relocations
2041 against any other section. */
2048 elf32_tic6x_relocate_section (bfd
*output_bfd
,
2049 struct bfd_link_info
*info
,
2051 asection
*input_section
,
2053 Elf_Internal_Rela
*relocs
,
2054 Elf_Internal_Sym
*local_syms
,
2055 asection
**local_sections
)
2058 struct elf32_tic6x_link_hash_table
*htab
;
2059 Elf_Internal_Shdr
*symtab_hdr
;
2060 struct elf_link_hash_entry
**sym_hashes
;
2061 bfd_vma
*local_got_offsets
;
2062 Elf_Internal_Rela
*rel
;
2063 Elf_Internal_Rela
*relend
;
2064 bfd_boolean ok
= TRUE
;
2066 htab
= elf32_tic6x_hash_table (info
);
2067 dynobj
= elf_hash_table (info
)->dynobj
;
2068 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
2069 sym_hashes
= elf_sym_hashes (input_bfd
);
2070 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2072 relend
= relocs
+ input_section
->reloc_count
;
2074 for (rel
= relocs
; rel
< relend
; rel
++)
2077 unsigned long r_symndx
;
2079 reloc_howto_type
*howto
;
2080 Elf_Internal_Sym
*sym
;
2082 struct elf_link_hash_entry
*h
;
2083 bfd_vma off
, relocation
;
2084 bfd_boolean unresolved_reloc
;
2085 bfd_reloc_status_type r
;
2086 struct bfd_link_hash_entry
*sbh
;
2089 r_type
= ELF32_R_TYPE (rel
->r_info
);
2090 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2092 is_rel
= elf32_tic6x_rel_relocation_p (input_bfd
, input_section
,
2096 elf32_tic6x_info_to_howto_rel (input_bfd
, &bfd_reloc
, rel
);
2098 elf32_tic6x_info_to_howto (input_bfd
, &bfd_reloc
, rel
);
2099 howto
= bfd_reloc
.howto
;
2102 bfd_set_error (bfd_error_bad_value
);
2109 unresolved_reloc
= FALSE
;
2111 if (r_symndx
< symtab_hdr
->sh_info
)
2113 sym
= local_syms
+ r_symndx
;
2114 sec
= local_sections
[r_symndx
];
2115 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2121 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2122 r_symndx
, symtab_hdr
, sym_hashes
,
2124 unresolved_reloc
, warned
);
2127 if (sec
!= NULL
&& elf_discarded_section (sec
))
2128 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2129 rel
, relend
, howto
, contents
);
2131 if (info
->relocatable
)
2135 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2138 relocation
= sec
->output_offset
+ sym
->st_value
;
2139 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
2140 contents
+ rel
->r_offset
);
2150 case R_C6000_FPHEAD
:
2152 /* No action needed. */
2155 case R_C6000_PCR_S21
:
2156 /* A branch to an undefined weak symbol is turned into a
2157 "b .s2 B3" instruction if the existing insn is of the
2158 form "b .s2 symbol". */
2159 if (h
? h
->root
.type
== bfd_link_hash_undefweak
2160 && (htab
->elf
.splt
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
2161 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2163 unsigned long oldval
;
2164 oldval
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2166 if ((oldval
& 0x7e) == 0x12)
2168 oldval
&= 0xF0000001;
2169 bfd_put_32 (input_bfd
, oldval
| 0x000c0362,
2170 contents
+ rel
->r_offset
);
2176 case R_C6000_PCR_S12
:
2177 case R_C6000_PCR_S10
:
2178 case R_C6000_PCR_S7
:
2180 && h
->plt
.offset
!= (bfd_vma
) -1
2181 && htab
->elf
.splt
!= NULL
)
2183 relocation
= (htab
->elf
.splt
->output_section
->vma
2184 + htab
->elf
.splt
->output_offset
2188 /* Generic PC-relative handling produces a value relative to
2189 the exact location of the relocation. Adjust it to be
2190 relative to the start of the fetch packet instead. */
2191 relocation
+= (input_section
->output_section
->vma
2192 + input_section
->output_offset
2193 + rel
->r_offset
) & 0x1f;
2194 unresolved_reloc
= FALSE
;
2197 case R_C6000_DSBT_INDEX
:
2198 relocation
= elf32_tic6x_hash_table (info
)->params
.dsbt_index
;
2199 if (!info
->shared
|| relocation
!= 0)
2206 case R_C6000_ABS_S16
:
2207 case R_C6000_ABS_L16
:
2208 case R_C6000_ABS_H16
:
2209 /* When generating a shared object or relocatable executable, these
2210 relocations are copied into the output file to be resolved at
2212 if ((info
->shared
|| elf32_tic6x_using_dsbt (output_bfd
))
2213 && (input_section
->flags
& SEC_ALLOC
)
2215 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2216 || h
->root
.type
!= bfd_link_hash_undefweak
))
2218 Elf_Internal_Rela outrel
;
2219 bfd_boolean skip
, relocate
;
2222 unresolved_reloc
= FALSE
;
2224 sreloc
= elf_section_data (input_section
)->sreloc
;
2225 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
2231 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2233 if (outrel
.r_offset
== (bfd_vma
) -1)
2235 else if (outrel
.r_offset
== (bfd_vma
) -2)
2236 skip
= TRUE
, relocate
= TRUE
;
2237 outrel
.r_offset
+= (input_section
->output_section
->vma
2238 + input_section
->output_offset
);
2241 memset (&outrel
, 0, sizeof outrel
);
2246 || !h
->def_regular
))
2248 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2249 outrel
.r_addend
= rel
->r_addend
;
2255 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2257 if (bfd_is_abs_section (sec
))
2259 else if (sec
== NULL
|| sec
->owner
== NULL
)
2261 bfd_set_error (bfd_error_bad_value
);
2268 osec
= sec
->output_section
;
2269 indx
= elf_section_data (osec
)->dynindx
;
2270 outrel
.r_addend
-= osec
->vma
;
2271 BFD_ASSERT (indx
!= 0);
2274 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2277 elf32_tic6x_install_rela (output_bfd
, sreloc
, &outrel
);
2279 /* If this reloc is against an external symbol, we do not want to
2280 fiddle with the addend. Otherwise, we need to include the symbol
2281 value so that it becomes an addend for the dynamic reloc. */
2286 /* Generic logic OK. */
2289 case R_C6000_SBR_U15_B
:
2290 case R_C6000_SBR_U15_H
:
2291 case R_C6000_SBR_U15_W
:
2292 case R_C6000_SBR_S16
:
2293 case R_C6000_SBR_L16_B
:
2294 case R_C6000_SBR_L16_H
:
2295 case R_C6000_SBR_L16_W
:
2296 case R_C6000_SBR_H16_B
:
2297 case R_C6000_SBR_H16_H
:
2298 case R_C6000_SBR_H16_W
:
2299 sbh
= bfd_link_hash_lookup (info
->hash
, "__c6xabi_DSBT_BASE",
2300 FALSE
, FALSE
, TRUE
);
2302 && (sbh
->type
== bfd_link_hash_defined
2303 || sbh
->type
== bfd_link_hash_defweak
))
2305 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
2306 && (htab
->elf
.splt
== NULL
2307 || h
->plt
.offset
== (bfd_vma
) -1))
2308 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2311 relocation
-= (sbh
->u
.def
.value
2312 + sbh
->u
.def
.section
->output_section
->vma
2313 + sbh
->u
.def
.section
->output_offset
);
2317 (*_bfd_error_handler
) (_("%B: SB-relative relocation but "
2318 "__c6xabi_DSBT_BASE not defined"),
2325 case R_C6000_SBR_GOT_U15_W
:
2326 case R_C6000_SBR_GOT_L16_W
:
2327 case R_C6000_SBR_GOT_H16_W
:
2328 /* Relocation is to the entry for this symbol in the global
2330 if (htab
->elf
.sgot
== NULL
)
2337 off
= h
->got
.offset
;
2338 dyn
= htab
->elf
.dynamic_sections_created
;
2339 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2341 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2342 || (ELF_ST_VISIBILITY (h
->other
)
2343 && h
->root
.type
== bfd_link_hash_undefweak
))
2345 /* This is actually a static link, or it is a
2346 -Bsymbolic link and the symbol is defined
2347 locally, or the symbol was forced to be local
2348 because of a version file. We must initialize
2349 this entry in the global offset table. Since the
2350 offset must always be a multiple of 4, we use the
2351 least significant bit to record whether we have
2352 initialized it already.
2354 When doing a dynamic link, we create a .rel.got
2355 relocation entry to initialize the value. This
2356 is done in the finish_dynamic_symbol routine. */
2361 bfd_put_32 (output_bfd
, relocation
,
2362 htab
->elf
.sgot
->contents
+ off
);
2365 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
2367 && !(ELF_ST_VISIBILITY (h
->other
)
2368 && h
->root
.type
== bfd_link_hash_undefweak
))
2369 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
,
2374 unresolved_reloc
= FALSE
;
2378 if (local_got_offsets
== NULL
)
2381 off
= local_got_offsets
[r_symndx
];
2383 /* The offset must always be a multiple of 4. We use
2384 the least significant bit to record whether we have
2385 already generated the necessary reloc. */
2390 bfd_put_32 (output_bfd
, relocation
,
2391 htab
->elf
.sgot
->contents
+ off
);
2393 if (info
->shared
|| elf32_tic6x_using_dsbt (output_bfd
))
2394 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
, off
);
2396 local_got_offsets
[r_symndx
] |= 1;
2400 if (off
>= (bfd_vma
) -2)
2404 relocation
= (htab
->elf
.sgot
->output_section
->vma
2405 + htab
->elf
.sgot
->output_offset
+ off
2406 - htab
->dsbt
->output_section
->vma
2407 - htab
->dsbt
->output_offset
);
2409 relocation
= (htab
->elf
.sgot
->output_section
->vma
2410 + htab
->elf
.sgot
->output_offset
+ off
2411 - htab
->elf
.sgotplt
->output_section
->vma
2412 - htab
->elf
.sgotplt
->output_offset
);
2414 if (rel
->r_addend
!= 0)
2416 /* We can't do anything for a relocation which is against
2417 a symbol *plus offset*. GOT holds relocations for
2418 symbols. Make this an error; the compiler isn't
2419 allowed to pass us these kinds of things. */
2421 (*_bfd_error_handler
)
2422 (_("%B, section %A: relocation %s with non-zero addend %d"
2423 " against local symbol"),
2426 elf32_tic6x_howto_table
[r_type
].name
,
2429 (*_bfd_error_handler
)
2430 (_("%B, section %A: relocation %s with non-zero addend %d"
2431 " against symbol `%s'"),
2434 elf32_tic6x_howto_table
[r_type
].name
,
2436 h
->root
.root
.string
[0] != '\0' ? h
->root
.root
.string
2437 : _("[whose name is lost]"));
2439 bfd_set_error (bfd_error_bad_value
);
2444 case R_C6000_PREL31
:
2445 /* Shared libraries and exception handling support not
2447 (*_bfd_error_handler
) (_("%B: relocation type %d not implemented"),
2453 /* Invalid in relocatable object. */
2455 /* Unknown relocation. */
2456 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2462 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2463 contents
, rel
->r_offset
,
2464 relocation
, rel
->r_addend
);
2467 if (r
== bfd_reloc_ok
2468 && howto
->complain_on_overflow
== complain_overflow_bitfield
)
2470 /* Generic overflow handling accepts cases the ABI says
2471 should be rejected for R_C6000_ABS16 and
2473 bfd_vma value
= (relocation
+ rel
->r_addend
) & 0xffffffff;
2474 bfd_vma sbit
= 1 << (howto
->bitsize
- 1);
2475 bfd_vma sbits
= (-(bfd_vma
) sbit
) & 0xffffffff;
2476 bfd_vma value_sbits
= value
& sbits
;
2478 if (value_sbits
!= 0
2479 && value_sbits
!= sbit
2480 && value_sbits
!= sbits
)
2481 r
= bfd_reloc_overflow
;
2484 if (r
!= bfd_reloc_ok
)
2487 const char *error_message
;
2490 name
= h
->root
.root
.string
;
2493 name
= bfd_elf_string_from_elf_section (input_bfd
,
2494 symtab_hdr
->sh_link
,
2499 name
= bfd_section_name (input_bfd
, sec
);
2504 case bfd_reloc_overflow
:
2505 /* If the overflowing reloc was to an undefined symbol,
2506 we have already printed one error message and there
2507 is no point complaining again. */
2509 h
->root
.type
!= bfd_link_hash_undefined
)
2510 && (!((*info
->callbacks
->reloc_overflow
)
2511 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2512 (bfd_vma
) 0, input_bfd
, input_section
,
2517 case bfd_reloc_undefined
:
2518 if (!((*info
->callbacks
->undefined_symbol
)
2519 (info
, name
, input_bfd
, input_section
,
2520 rel
->r_offset
, TRUE
)))
2524 case bfd_reloc_outofrange
:
2525 error_message
= _("out of range");
2528 case bfd_reloc_notsupported
:
2529 error_message
= _("unsupported relocation");
2532 case bfd_reloc_dangerous
:
2533 error_message
= _("dangerous relocation");
2537 error_message
= _("unknown error");
2541 BFD_ASSERT (error_message
!= NULL
);
2542 if (!((*info
->callbacks
->reloc_dangerous
)
2543 (info
, error_message
, input_bfd
, input_section
,
2555 /* Look through the relocs for a section during the first phase, and
2556 calculate needed space in the global offset table, procedure linkage
2557 table, and dynamic reloc sections. */
2560 elf32_tic6x_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2561 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2563 struct elf32_tic6x_link_hash_table
*htab
;
2564 Elf_Internal_Shdr
*symtab_hdr
;
2565 struct elf_link_hash_entry
**sym_hashes
;
2566 const Elf_Internal_Rela
*rel
;
2567 const Elf_Internal_Rela
*rel_end
;
2570 if (info
->relocatable
)
2573 htab
= elf32_tic6x_hash_table (info
);
2574 symtab_hdr
= &elf_symtab_hdr (abfd
);
2575 sym_hashes
= elf_sym_hashes (abfd
);
2577 /* Create dynamic sections for relocatable executables so that we can
2578 copy relocations. */
2579 if (elf32_tic6x_using_dsbt (abfd
)
2580 && ! htab
->elf
.dynamic_sections_created
)
2582 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2588 rel_end
= relocs
+ sec
->reloc_count
;
2589 for (rel
= relocs
; rel
< rel_end
; rel
++)
2591 unsigned int r_type
;
2592 unsigned long r_symndx
;
2593 struct elf_link_hash_entry
*h
;
2594 Elf_Internal_Sym
*isym
;
2596 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2597 r_type
= ELF32_R_TYPE (rel
->r_info
);
2599 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2601 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
2607 if (r_symndx
< symtab_hdr
->sh_info
)
2609 /* A local symbol. */
2610 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2619 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2620 while (h
->root
.type
== bfd_link_hash_indirect
2621 || h
->root
.type
== bfd_link_hash_warning
)
2622 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2627 case R_C6000_PCR_S21
:
2628 /* This symbol requires a procedure linkage table entry. We
2629 actually build the entry in adjust_dynamic_symbol,
2630 because this might be a case of linking PIC code which is
2631 never referenced by a dynamic object, in which case we
2632 don't need to generate a procedure linkage table entry
2635 /* If this is a local symbol, we resolve it directly without
2636 creating a procedure linkage table entry. */
2641 h
->plt
.refcount
+= 1;
2644 case R_C6000_SBR_GOT_U15_W
:
2645 case R_C6000_SBR_GOT_L16_W
:
2646 case R_C6000_SBR_GOT_H16_W
:
2647 /* This symbol requires a global offset table entry. */
2650 h
->got
.refcount
+= 1;
2654 bfd_signed_vma
*local_got_refcounts
;
2656 /* This is a global offset table entry for a local symbol. */
2657 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2658 if (local_got_refcounts
== NULL
)
2662 size
= symtab_hdr
->sh_info
;
2663 size
*= (sizeof (bfd_signed_vma
)
2664 + sizeof (bfd_vma
) + sizeof(char));
2665 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2666 if (local_got_refcounts
== NULL
)
2668 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2670 local_got_refcounts
[r_symndx
] += 1;
2673 if (htab
->elf
.sgot
== NULL
)
2675 if (htab
->elf
.dynobj
== NULL
)
2676 htab
->elf
.dynobj
= abfd
;
2677 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2682 case R_C6000_DSBT_INDEX
:
2683 /* We'd like to check for nonzero dsbt_index here, but it's
2684 set up only after check_relocs is called. Instead, we
2685 store the number of R_C6000_DSBT_INDEX relocs in the
2686 pc_count field, and potentially discard the extra space
2687 in elf32_tic6x_allocate_dynrelocs. */
2695 case R_C6000_ABS_S16
:
2696 case R_C6000_ABS_L16
:
2697 case R_C6000_ABS_H16
:
2698 /* If we are creating a shared library, and this is a reloc
2699 against a global symbol, or a non PC relative reloc
2700 against a local symbol, then we need to copy the reloc
2701 into the shared library. However, if we are linking with
2702 -Bsymbolic, we do not need to copy a reloc against a
2703 global symbol which is defined in an object we are
2704 including in the link (i.e., DEF_REGULAR is set). At
2705 this point we have not seen all the input files, so it is
2706 possible that DEF_REGULAR is not set now but will be set
2707 later (it is never cleared). In case of a weak definition,
2708 DEF_REGULAR may be cleared later by a strong definition in
2709 a shared library. We account for that possibility below by
2710 storing information in the relocs_copied field of the hash
2711 table entry. A similar situation occurs when creating
2712 shared libraries and symbol visibility changes render the
2715 If on the other hand, we are creating an executable, we
2716 may need to keep relocations for symbols satisfied by a
2717 dynamic library if we manage to avoid copy relocs for the
2719 if ((info
->shared
|| elf32_tic6x_using_dsbt (abfd
))
2720 && (sec
->flags
& SEC_ALLOC
) != 0)
2722 struct elf_dyn_relocs
*p
;
2723 struct elf_dyn_relocs
**head
;
2725 /* We must copy these reloc types into the output file.
2726 Create a reloc section in dynobj and make room for
2730 if (htab
->elf
.dynobj
== NULL
)
2731 htab
->elf
.dynobj
= abfd
;
2733 sreloc
= _bfd_elf_make_dynamic_reloc_section
2734 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela? */ TRUE
);
2740 /* If this is a global symbol, we count the number of
2741 relocations we need for this symbol. */
2744 head
= &((struct elf32_tic6x_link_hash_entry
*) h
)->dyn_relocs
;
2748 /* Track dynamic relocs needed for local syms too.
2749 We really need local syms available to do this
2754 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2758 vpp
= &elf_section_data (s
)->local_dynrel
;
2759 head
= (struct elf_dyn_relocs
**)vpp
;
2763 if (p
== NULL
|| p
->sec
!= sec
)
2765 bfd_size_type amt
= sizeof *p
;
2766 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
2776 if (r_type
== R_C6000_DSBT_INDEX
)
2781 case R_C6000_SBR_U15_B
:
2782 case R_C6000_SBR_U15_H
:
2783 case R_C6000_SBR_U15_W
:
2784 case R_C6000_SBR_S16
:
2785 case R_C6000_SBR_L16_B
:
2786 case R_C6000_SBR_L16_H
:
2787 case R_C6000_SBR_L16_W
:
2788 case R_C6000_SBR_H16_B
:
2789 case R_C6000_SBR_H16_H
:
2790 case R_C6000_SBR_H16_W
:
2791 if (h
!= NULL
&& info
->executable
)
2793 /* For B14-relative addresses, we might need a copy
2808 elf32_tic6x_add_symbol_hook (bfd
*abfd
,
2809 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2810 Elf_Internal_Sym
*sym
,
2811 const char **namep ATTRIBUTE_UNUSED
,
2812 flagword
*flagsp ATTRIBUTE_UNUSED
,
2816 switch (sym
->st_shndx
)
2818 case SHN_TIC6X_SCOMMON
:
2819 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2820 (*secp
)->flags
|= SEC_IS_COMMON
;
2821 *valp
= sym
->st_size
;
2822 bfd_set_section_alignment (abfd
, *secp
, bfd_log2 (sym
->st_value
));
2830 elf32_tic6x_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
2832 elf_symbol_type
*elfsym
;
2834 elfsym
= (elf_symbol_type
*) asym
;
2835 switch (elfsym
->internal_elf_sym
.st_shndx
)
2837 case SHN_TIC6X_SCOMMON
:
2838 if (tic6x_elf_scom_section
.name
== NULL
)
2840 /* Initialize the small common section. */
2841 tic6x_elf_scom_section
.name
= ".scommon";
2842 tic6x_elf_scom_section
.flags
= SEC_IS_COMMON
;
2843 tic6x_elf_scom_section
.output_section
= &tic6x_elf_scom_section
;
2844 tic6x_elf_scom_section
.symbol
= &tic6x_elf_scom_symbol
;
2845 tic6x_elf_scom_section
.symbol_ptr_ptr
= &tic6x_elf_scom_symbol_ptr
;
2846 tic6x_elf_scom_symbol
.name
= ".scommon";
2847 tic6x_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2848 tic6x_elf_scom_symbol
.section
= &tic6x_elf_scom_section
;
2849 tic6x_elf_scom_symbol_ptr
= &tic6x_elf_scom_symbol
;
2851 asym
->section
= &tic6x_elf_scom_section
;
2852 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2858 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2859 const char *name ATTRIBUTE_UNUSED
,
2860 Elf_Internal_Sym
*sym
,
2861 asection
*input_sec
,
2862 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2864 /* If we see a common symbol, which implies a relocatable link, then
2865 if a symbol was small common in an input file, mark it as small
2866 common in the output file. */
2867 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
2868 sym
->st_shndx
= SHN_TIC6X_SCOMMON
;
2874 elf32_tic6x_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
2878 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2880 *retval
= SHN_TIC6X_SCOMMON
;
2887 /* Allocate space in .plt, .got and associated reloc sections for
2891 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2893 struct bfd_link_info
*info
;
2894 struct elf32_tic6x_link_hash_table
*htab
;
2895 struct elf32_tic6x_link_hash_entry
*eh
;
2896 struct elf_dyn_relocs
*p
;
2898 if (h
->root
.type
== bfd_link_hash_indirect
)
2901 if (h
->root
.type
== bfd_link_hash_warning
)
2902 /* When warning symbols are created, they **replace** the "real"
2903 entry in the hash table, thus we never get to see the real
2904 symbol in a hash traversal. So look at it now. */
2905 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2906 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
2908 info
= (struct bfd_link_info
*) inf
;
2909 htab
= elf32_tic6x_hash_table (info
);
2911 if (htab
->elf
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
2913 /* Make sure this symbol is output as a dynamic symbol.
2914 Undefined weak syms won't yet be marked as dynamic. */
2915 if (h
->dynindx
== -1 && !h
->forced_local
)
2917 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2922 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2924 asection
*s
= htab
->elf
.splt
;
2926 /* If this is the first .plt entry, make room for the special
2929 s
->size
+= PLT_ENTRY_SIZE
;
2931 h
->plt
.offset
= s
->size
;
2933 /* If this symbol is not defined in a regular file, and we are
2934 not generating a shared library, then set the symbol to this
2935 location in the .plt. This is required to make function
2936 pointers compare as equal between the normal executable and
2937 the shared library. */
2938 if (! info
->shared
&& !h
->def_regular
)
2940 h
->root
.u
.def
.section
= s
;
2941 h
->root
.u
.def
.value
= h
->plt
.offset
;
2944 /* Make room for this entry. */
2945 s
->size
+= PLT_ENTRY_SIZE
;
2946 /* We also need to make an entry in the .got.plt section, which
2947 will be placed in the .got section by the linker script. */
2948 htab
->elf
.sgotplt
->size
+= 4;
2949 /* We also need to make an entry in the .rel.plt section. */
2950 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
2954 h
->plt
.offset
= (bfd_vma
) -1;
2960 h
->plt
.offset
= (bfd_vma
) -1;
2964 if (h
->got
.refcount
> 0)
2968 /* Make sure this symbol is output as a dynamic symbol.
2969 Undefined weak syms won't yet be marked as dynamic. */
2970 if (h
->dynindx
== -1
2971 && !h
->forced_local
)
2973 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2978 h
->got
.offset
= s
->size
;
2981 if (!(ELF_ST_VISIBILITY (h
->other
)
2982 && h
->root
.type
== bfd_link_hash_undefweak
))
2983 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
2986 h
->got
.offset
= (bfd_vma
) -1;
2988 if (eh
->dyn_relocs
== NULL
)
2991 /* Discard relocs on undefined weak syms with non-default
2993 if (info
->shared
|| elf32_tic6x_using_dsbt (htab
->obfd
))
2995 /* We use the pc_count field to hold the number of
2996 R_C6000_DSBT_INDEX relocs. */
2997 if (htab
->params
.dsbt_index
!= 0)
2999 struct elf_dyn_relocs
**pp
;
3001 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3003 p
->count
-= p
->pc_count
;
3012 if (eh
->dyn_relocs
!= NULL
3013 && h
->root
.type
== bfd_link_hash_undefweak
)
3015 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3016 eh
->dyn_relocs
= NULL
;
3018 /* Make sure undefined weak symbols are output as a dynamic
3020 else if (h
->dynindx
== -1
3021 && !h
->forced_local
)
3023 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3029 /* Finally, allocate space. */
3030 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3034 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3036 BFD_ASSERT (sreloc
!= NULL
);
3037 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3043 /* Find any dynamic relocs that apply to read-only sections. */
3046 elf32_tic6x_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3048 struct elf32_tic6x_link_hash_entry
*eh
;
3049 struct elf_dyn_relocs
*p
;
3051 if (h
->root
.type
== bfd_link_hash_warning
)
3052 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3054 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3055 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3057 asection
*s
= p
->sec
->output_section
;
3059 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3061 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3063 info
->flags
|= DF_TEXTREL
;
3065 /* Not an error, just cut short the traversal. */
3072 /* Set the sizes of the dynamic sections. */
3075 elf32_tic6x_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3077 struct elf32_tic6x_link_hash_table
*htab
;
3083 htab
= elf32_tic6x_hash_table (info
);
3084 dynobj
= htab
->elf
.dynobj
;
3088 if (htab
->elf
.dynamic_sections_created
)
3090 /* Set the contents of the .interp section to the interpreter. */
3091 if (info
->executable
)
3093 s
= bfd_get_section_by_name (dynobj
, ".interp");
3096 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3097 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3101 /* Set up .got offsets for local syms, and space for local dynamic
3103 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3105 bfd_signed_vma
*local_got
;
3106 bfd_signed_vma
*end_local_got
;
3107 char *local_tls_type
;
3108 bfd_vma
*local_tlsdesc_gotent
;
3109 bfd_size_type locsymcount
;
3110 Elf_Internal_Shdr
*symtab_hdr
;
3113 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3115 struct elf_dyn_relocs
*p
;
3117 for (p
= ((struct elf_dyn_relocs
*)
3118 elf_section_data (s
)->local_dynrel
);
3122 if (!bfd_is_abs_section (p
->sec
)
3123 && bfd_is_abs_section (p
->sec
->output_section
))
3125 /* Input section has been discarded, either because
3126 it is a copy of a linkonce section or due to
3127 linker script /DISCARD/, so we'll be discarding
3130 else if (p
->count
!= 0)
3132 srel
= elf_section_data (p
->sec
)->sreloc
;
3133 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3134 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3135 info
->flags
|= DF_TEXTREL
;
3140 local_got
= elf_local_got_refcounts (ibfd
);
3144 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3145 locsymcount
= symtab_hdr
->sh_info
;
3146 end_local_got
= local_got
+ locsymcount
;
3148 srel
= htab
->elf
.srelgot
;
3149 for (; local_got
< end_local_got
;
3150 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3154 *local_got
= s
->size
;
3157 if (info
->shared
|| elf32_tic6x_using_dsbt (output_bfd
))
3159 srel
->size
+= sizeof (Elf32_External_Rela
);
3163 *local_got
= (bfd_vma
) -1;
3167 /* Allocate global sym .plt and .got entries, and space for global
3168 sym dynamic relocs. */
3169 elf_link_hash_traverse (&htab
->elf
, elf32_tic6x_allocate_dynrelocs
, info
);
3171 /* We now have determined the sizes of the various dynamic sections.
3172 Allocate memory for them. */
3174 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3176 bfd_boolean strip_section
= TRUE
;
3178 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3181 if (s
== htab
->dsbt
)
3182 s
->size
= 4 * htab
->params
.dsbt_size
;
3183 else if (s
== htab
->elf
.splt
3184 || s
== htab
->elf
.sgot
3185 || s
== htab
->elf
.sgotplt
3186 || s
== htab
->sdynbss
)
3188 /* Strip this section if we don't need it; see the
3190 /* We'd like to strip these sections if they aren't needed, but if
3191 we've exported dynamic symbols from them we must leave them.
3192 It's too late to tell BFD to get rid of the symbols. */
3194 if (htab
->elf
.hplt
!= NULL
)
3195 strip_section
= FALSE
;
3197 /* Round up the size of the PLT section to a multiple of 32. */
3198 if (s
== htab
->elf
.splt
&& s
->size
> 0)
3199 s
->size
= (s
->size
+ 31) & ~(bfd_vma
)31;
3201 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3204 && s
!= htab
->elf
.srelplt
)
3207 /* We use the reloc_count field as a counter if we need
3208 to copy relocs into the output file. */
3213 /* It's not one of our sections, so don't allocate space. */
3219 /* If we don't need this section, strip it from the
3220 output file. This is mostly to handle .rel.bss and
3221 .rel.plt. We must create both sections in
3222 create_dynamic_sections, because they must be created
3223 before the linker maps input sections to output
3224 sections. The linker does that before
3225 adjust_dynamic_symbol is called, and it is that
3226 function which decides whether anything needs to go
3227 into these sections. */
3229 s
->flags
|= SEC_EXCLUDE
;
3233 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3236 /* Allocate memory for the section contents. We use bfd_zalloc
3237 here in case unused entries are not reclaimed before the
3238 section's contents are written out. This should not happen,
3239 but this way if it does, we get a R_C6000_NONE reloc instead
3241 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3242 if (s
->contents
== NULL
)
3246 if (htab
->elf
.dynamic_sections_created
)
3248 /* Add some entries to the .dynamic section. We fill in the
3249 values later, in elf32_tic6x_finish_dynamic_sections, but we
3250 must add the entries now so that we get the correct size for
3251 the .dynamic section. The DT_DEBUG entry is filled in by the
3252 dynamic linker and used by the debugger. */
3253 #define add_dynamic_entry(TAG, VAL) \
3254 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3256 if (info
->executable
)
3258 if (!add_dynamic_entry (DT_DEBUG
, 0))
3262 if (!add_dynamic_entry (DT_C6000_DSBT_BASE
, 0)
3263 || !add_dynamic_entry (DT_C6000_DSBT_SIZE
, htab
->params
.dsbt_size
)
3264 || !add_dynamic_entry (DT_C6000_DSBT_INDEX
,
3265 htab
->params
.dsbt_index
))
3268 if (htab
->elf
.splt
->size
!= 0)
3270 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3271 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3272 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3273 || !add_dynamic_entry (DT_JMPREL
, 0))
3279 if (!add_dynamic_entry (DT_RELA
, 0)
3280 || !add_dynamic_entry (DT_RELASZ
, 0)
3281 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3284 /* If any dynamic relocs apply to a read-only section,
3285 then we need a DT_TEXTREL entry. */
3286 if ((info
->flags
& DF_TEXTREL
) == 0)
3287 elf_link_hash_traverse (&htab
->elf
,
3288 elf32_tic6x_readonly_dynrelocs
, info
);
3290 if ((info
->flags
& DF_TEXTREL
) != 0)
3292 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3297 #undef add_dynamic_entry
3302 /* This function is called after all the input files have been read,
3303 and the input sections have been assigned to output sections. */
3306 elf32_tic6x_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3308 if (elf32_tic6x_using_dsbt (output_bfd
) && !info
->relocatable
)
3310 struct elf_link_hash_entry
*h
;
3312 /* Force a PT_GNU_STACK segment to be created. */
3313 if (! elf_tdata (output_bfd
)->stack_flags
)
3314 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
3316 /* Define __stacksize if it's not defined yet. */
3317 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3318 FALSE
, FALSE
, FALSE
);
3319 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
3320 || h
->type
!= STT_OBJECT
3323 struct bfd_link_hash_entry
*bh
= NULL
;
3325 if (!(_bfd_generic_link_add_one_symbol
3326 (info
, output_bfd
, "__stacksize",
3327 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
3328 (const char *) NULL
, FALSE
,
3329 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
3332 h
= (struct elf_link_hash_entry
*) bh
;
3334 h
->type
= STT_OBJECT
;
3341 elf32_tic6x_modify_program_headers (bfd
*output_bfd
,
3342 struct bfd_link_info
*info
)
3344 struct elf_obj_tdata
*tdata
= elf_tdata (output_bfd
);
3345 struct elf_segment_map
*m
;
3346 Elf_Internal_Phdr
*p
;
3348 /* objcopy and strip preserve what's already there using
3349 elf32_tic6x_copy_private_bfd_data (). */
3353 for (p
= tdata
->phdr
, m
= tdata
->segment_map
; m
!= NULL
; m
= m
->next
, p
++)
3354 if (m
->p_type
== PT_GNU_STACK
)
3359 struct elf_link_hash_entry
*h
;
3361 /* Obtain the pointer to the __stacksize symbol. */
3362 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3363 FALSE
, FALSE
, FALSE
);
3366 while (h
->root
.type
== bfd_link_hash_indirect
3367 || h
->root
.type
== bfd_link_hash_warning
)
3368 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3369 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
3372 /* Set the header p_memsz from the symbol value. We
3373 intentionally ignore the symbol section. */
3374 if (h
&& h
->root
.type
== bfd_link_hash_defined
)
3375 p
->p_memsz
= h
->root
.u
.def
.value
;
3377 p
->p_memsz
= DEFAULT_STACK_SIZE
;
3386 elf32_tic6x_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3387 struct bfd_link_info
*info
)
3389 struct elf32_tic6x_link_hash_table
*htab
;
3393 htab
= elf32_tic6x_hash_table (info
);
3394 dynobj
= htab
->elf
.dynobj
;
3395 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3397 if (elf_hash_table (info
)->dynamic_sections_created
)
3399 Elf32_External_Dyn
* dyncon
;
3400 Elf32_External_Dyn
* dynconend
;
3402 BFD_ASSERT (sdyn
!= NULL
);
3404 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3405 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3407 for (; dyncon
< dynconend
; dyncon
++)
3409 Elf_Internal_Dyn dyn
;
3412 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3419 case DT_C6000_DSBT_BASE
:
3421 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
);
3425 s
= htab
->elf
.sgotplt
;
3426 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3430 s
= htab
->elf
.srelplt
;
3431 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3435 s
= htab
->elf
.srelplt
;
3436 dyn
.d_un
.d_val
= s
->size
;
3439 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3442 /* Fill in the first entry in the procedure linkage table. */
3443 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
3445 bfd_vma got_offs
= (htab
->elf
.sgotplt
->output_section
->vma
3446 + htab
->elf
.sgotplt
->output_offset
3447 - htab
->dsbt
->output_section
->vma
3448 - htab
->dsbt
->output_offset
) / 4;
3450 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3451 bfd_put_32 (output_bfd
, got_offs
<< 8 | 0x0100006e,
3452 htab
->elf
.splt
->contents
);
3453 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3454 bfd_put_32 (output_bfd
, (got_offs
+ 1) << 8 | 0x0080006e,
3455 htab
->elf
.splt
->contents
+ 4);
3457 bfd_put_32 (output_bfd
, 0x00004000,
3458 htab
->elf
.splt
->contents
+ 8);
3460 bfd_put_32 (output_bfd
, 0x00080362,
3461 htab
->elf
.splt
->contents
+ 12);
3463 bfd_put_32 (output_bfd
, 0x00008000,
3464 htab
->elf
.splt
->contents
+ 16);
3466 elf_section_data (htab
->elf
.splt
->output_section
)
3467 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3474 /* Return address for Ith PLT stub in section PLT, for relocation REL
3475 or (bfd_vma) -1 if it should not be included. */
3478 elf32_tic6x_plt_sym_val (bfd_vma i
, const asection
*plt
,
3479 const arelent
*rel ATTRIBUTE_UNUSED
)
3481 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3485 elf32_tic6x_obj_attrs_arg_type (int tag
)
3487 if (tag
== Tag_ABI_compatibility
)
3488 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
3490 return ATTR_TYPE_FLAG_STR_VAL
;
3492 return ATTR_TYPE_FLAG_INT_VAL
;
3496 elf32_tic6x_obj_attrs_order (int num
)
3498 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
3499 return Tag_ABI_conformance
;
3500 if ((num
- 1) < Tag_ABI_conformance
)
3506 elf32_tic6x_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
3508 if ((tag
& 127) < 64)
3511 (_("%B: error: unknown mandatory EABI object attribute %d"),
3513 bfd_set_error (bfd_error_bad_value
);
3519 (_("%B: warning: unknown EABI object attribute %d"),
3525 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3526 and return the merged value. At present, all merges succeed, so no
3527 return value for errors is defined. */
3530 elf32_tic6x_merge_arch_attributes (int arch1
, int arch2
)
3532 int min_arch
, max_arch
;
3534 min_arch
= (arch1
< arch2
? arch1
: arch2
);
3535 max_arch
= (arch1
> arch2
? arch1
: arch2
);
3537 /* In most cases, the numerically greatest value is the correct
3538 merged value, but merging C64 and C67 results in C674X. */
3539 if ((min_arch
== C6XABI_Tag_ISA_C67X
3540 || min_arch
== C6XABI_Tag_ISA_C67XP
)
3541 && (max_arch
== C6XABI_Tag_ISA_C64X
3542 || max_arch
== C6XABI_Tag_ISA_C64XP
))
3543 return C6XABI_Tag_ISA_C674X
;
3548 /* Convert a Tag_ABI_array_object_alignment or
3549 Tag_ABI_array_object_align_expected tag value TAG to a
3550 corresponding alignment value; return the alignment, or -1 for an
3551 unknown tag value. */
3554 elf32_tic6x_tag_to_array_alignment (int tag
)
3572 /* Convert a Tag_ABI_array_object_alignment or
3573 Tag_ABI_array_object_align_expected alignment ALIGN to a
3574 corresponding tag value; return the tag value. */
3577 elf32_tic6x_array_alignment_to_tag (int align
)
3595 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3596 succeeded, FALSE otherwise. */
3599 elf32_tic6x_merge_attributes (bfd
*ibfd
, bfd
*obfd
)
3601 bfd_boolean result
= TRUE
;
3602 obj_attribute
*in_attr
;
3603 obj_attribute
*out_attr
;
3605 int array_align_in
, array_align_out
, array_expect_in
, array_expect_out
;
3607 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
3609 /* This is the first object. Copy the attributes. */
3610 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
3612 out_attr
= elf_known_obj_attributes_proc (obfd
);
3614 /* Use the Tag_null value to indicate the attributes have been
3621 in_attr
= elf_known_obj_attributes_proc (ibfd
);
3622 out_attr
= elf_known_obj_attributes_proc (obfd
);
3624 /* No specification yet for handling of unknown attributes, so just
3625 ignore them and handle known ones. */
3627 if (out_attr
[Tag_ABI_stack_align_preserved
].i
3628 < in_attr
[Tag_ABI_stack_align_needed
].i
)
3631 (_("error: %B requires more stack alignment than %B preserves"),
3635 if (in_attr
[Tag_ABI_stack_align_preserved
].i
3636 < out_attr
[Tag_ABI_stack_align_needed
].i
)
3639 (_("error: %B requires more stack alignment than %B preserves"),
3644 array_align_in
= elf32_tic6x_tag_to_array_alignment
3645 (in_attr
[Tag_ABI_array_object_alignment
].i
);
3646 if (array_align_in
== -1)
3649 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3653 array_align_out
= elf32_tic6x_tag_to_array_alignment
3654 (out_attr
[Tag_ABI_array_object_alignment
].i
);
3655 if (array_align_out
== -1)
3658 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3662 array_expect_in
= elf32_tic6x_tag_to_array_alignment
3663 (in_attr
[Tag_ABI_array_object_align_expected
].i
);
3664 if (array_expect_in
== -1)
3667 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3671 array_expect_out
= elf32_tic6x_tag_to_array_alignment
3672 (out_attr
[Tag_ABI_array_object_align_expected
].i
);
3673 if (array_expect_out
== -1)
3676 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3681 if (array_align_out
< array_expect_in
)
3684 (_("error: %B requires more array alignment than %B preserves"),
3688 if (array_align_in
< array_expect_out
)
3691 (_("error: %B requires more array alignment than %B preserves"),
3696 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
3701 out_attr
[i
].i
= elf32_tic6x_merge_arch_attributes (in_attr
[i
].i
,
3705 case Tag_ABI_wchar_t
:
3706 if (out_attr
[i
].i
== 0)
3707 out_attr
[i
].i
= in_attr
[i
].i
;
3708 if (out_attr
[i
].i
!= 0
3709 && in_attr
[i
].i
!= 0
3710 && out_attr
[i
].i
!= in_attr
[i
].i
)
3713 (_("warning: %B and %B differ in wchar_t size"), obfd
, ibfd
);
3717 case Tag_ABI_stack_align_needed
:
3718 if (out_attr
[i
].i
< in_attr
[i
].i
)
3719 out_attr
[i
].i
= in_attr
[i
].i
;
3722 case Tag_ABI_stack_align_preserved
:
3723 if (out_attr
[i
].i
> in_attr
[i
].i
)
3724 out_attr
[i
].i
= in_attr
[i
].i
;
3728 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3731 (_("warning: %B and %B differ in whether code is "
3732 "compiled for DSBT"),
3738 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3741 (_("warning: %B and %B differ in position-dependence of "
3748 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3751 (_("warning: %B and %B differ in position-dependence of "
3757 case Tag_ABI_array_object_alignment
:
3758 if (array_align_out
!= -1
3759 && array_align_in
!= -1
3760 && array_align_out
> array_align_in
)
3762 = elf32_tic6x_array_alignment_to_tag (array_align_in
);
3765 case Tag_ABI_array_object_align_expected
:
3766 if (array_expect_out
!= -1
3767 && array_expect_in
!= -1
3768 && array_expect_out
< array_expect_in
)
3770 = elf32_tic6x_array_alignment_to_tag (array_expect_in
);
3773 case Tag_ABI_conformance
:
3774 /* Merging for this attribute is not specified. As on ARM,
3775 treat a missing attribute as no claim to conform and only
3776 merge identical values. */
3777 if (out_attr
[i
].s
== NULL
3778 || in_attr
[i
].s
== NULL
3779 || strcmp (out_attr
[i
].s
,
3781 out_attr
[i
].s
= NULL
;
3784 case Tag_ABI_compatibility
:
3785 /* Merged in _bfd_elf_merge_object_attributes. */
3790 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
3794 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
3795 out_attr
[i
].type
= in_attr
[i
].type
;
3798 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
3799 if (!_bfd_elf_merge_object_attributes (ibfd
, obfd
))
3802 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
3808 elf32_tic6x_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3810 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
3813 if (!elf32_tic6x_merge_attributes (ibfd
, obfd
))
3820 elf32_tic6x_copy_private_data (bfd
* ibfd
, bfd
* obfd
)
3822 _bfd_elf_copy_private_bfd_data (ibfd
, obfd
);
3824 if (! is_tic6x_elf (ibfd
) || ! is_tic6x_elf (obfd
))
3827 /* Copy the stack size. */
3828 if (elf_tdata (ibfd
)->phdr
&& elf_tdata (obfd
)->phdr
3829 && elf32_tic6x_using_dsbt (ibfd
) && elf32_tic6x_using_dsbt (obfd
))
3833 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
3834 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
3836 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
3838 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
3839 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
3841 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
3843 /* Rewrite the phdrs, since we're only called after they
3844 were first written. */
3846 (bfd_signed_vma
) get_elf_backend_data (obfd
)
3847 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
3848 || get_elf_backend_data (obfd
)->s
3849 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
3850 elf_elfheader (obfd
)->e_phnum
) != 0)
3862 #define TARGET_LITTLE_SYM bfd_elf32_tic6x_le_vec
3863 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
3864 #define TARGET_BIG_SYM bfd_elf32_tic6x_be_vec
3865 #define TARGET_BIG_NAME "elf32-tic6x-be"
3866 #define ELF_ARCH bfd_arch_tic6x
3867 #define ELF_TARGET_ID TIC6X_ELF_DATA
3868 #define ELF_MACHINE_CODE EM_TI_C6000
3869 #define ELF_MAXPAGESIZE 0x1000
3870 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
3871 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
3872 #define bfd_elf32_bfd_copy_private_bfd_data elf32_tic6x_copy_private_data
3873 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
3874 #define bfd_elf32_mkobject elf32_tic6x_mkobject
3875 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
3876 #define bfd_elf32_bfd_link_hash_table_free elf32_tic6x_link_hash_table_free
3877 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
3878 #define elf_backend_can_gc_sections 1
3879 #define elf_backend_default_use_rela_p 1
3880 #define elf_backend_may_use_rel_p 1
3881 #define elf_backend_may_use_rela_p 1
3882 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
3883 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
3884 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
3885 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
3886 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
3887 #define elf_backend_obj_attrs_vendor "c6xabi"
3888 #define elf_backend_can_refcount 1
3889 #define elf_backend_want_got_plt 1
3890 #define elf_backend_want_dynbss 1
3891 #define elf_backend_plt_readonly 1
3892 #define elf_backend_rela_normal 1
3893 #define elf_backend_got_header_size 8
3894 #define elf_backend_gc_sweep_hook elf32_tic6x_gc_sweep_hook
3895 #define elf_backend_modify_program_headers \
3896 elf32_tic6x_modify_program_headers
3897 #define elf_backend_create_dynamic_sections \
3898 elf32_tic6x_create_dynamic_sections
3899 #define elf_backend_adjust_dynamic_symbol \
3900 elf32_tic6x_adjust_dynamic_symbol
3901 #define elf_backend_check_relocs elf32_tic6x_check_relocs
3902 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
3903 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
3904 #define elf_backend_link_output_symbol_hook \
3905 elf32_tic6x_link_output_symbol_hook
3906 #define elf_backend_section_from_bfd_section \
3907 elf32_tic6x_section_from_bfd_section
3908 #define elf_backend_relocate_section elf32_tic6x_relocate_section
3909 #define elf_backend_finish_dynamic_symbol \
3910 elf32_tic6x_finish_dynamic_symbol
3911 #define elf_backend_always_size_sections \
3912 elf32_tic6x_always_size_sections
3913 #define elf_backend_size_dynamic_sections \
3914 elf32_tic6x_size_dynamic_sections
3915 #define elf_backend_finish_dynamic_sections \
3916 elf32_tic6x_finish_dynamic_sections
3917 #define elf_info_to_howto elf32_tic6x_info_to_howto
3918 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
3920 #undef elf_backend_omit_section_dynsym
3921 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
3922 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
3925 #include "elf32-target.h"