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 TRUE
, /* 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 TRUE
), /* 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 */
471 HOWTO (R_C6000_EHTYPE
, /* type */
473 2, /* size (0 = byte, 1 = short, 2 = long) */
475 FALSE
, /* pc_relative */
477 complain_overflow_dont
,/* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_C6000_EHTYPE", /* name */
480 FALSE
, /* partial_inplace */
482 0xffffffff, /* dst_mask */
483 FALSE
), /* pcrel_offset */
708 HOWTO (R_C6000_ALIGN
, /* type */
710 0, /* size (0 = byte, 1 = short, 2 = long) */
712 FALSE
, /* pc_relative */
714 complain_overflow_dont
,/* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_C6000_ALIGN", /* name */
717 FALSE
, /* partial_inplace */
720 FALSE
), /* pcrel_offset */
721 HOWTO (R_C6000_FPHEAD
, /* type */
723 0, /* size (0 = byte, 1 = short, 2 = long) */
725 FALSE
, /* pc_relative */
727 complain_overflow_dont
,/* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 "R_C6000_FPHEAD", /* name */
730 FALSE
, /* partial_inplace */
733 FALSE
), /* pcrel_offset */
734 HOWTO (R_C6000_NOCMP
, /* type */
736 0, /* size (0 = byte, 1 = short, 2 = long) */
738 FALSE
, /* pc_relative */
740 complain_overflow_dont
,/* complain_on_overflow */
741 bfd_elf_generic_reloc
, /* special_function */
742 "R_C6000_NOCMP", /* name */
743 FALSE
, /* partial_inplace */
746 FALSE
) /* pcrel_offset */
749 static reloc_howto_type elf32_tic6x_howto_table_rel
[] =
751 HOWTO (R_C6000_NONE
, /* type */
753 0, /* size (0 = byte, 1 = short, 2 = long) */
755 FALSE
, /* pc_relative */
757 complain_overflow_dont
,/* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_C6000_NONE", /* name */
760 TRUE
, /* partial_inplace */
763 FALSE
), /* pcrel_offset */
764 HOWTO (R_C6000_ABS32
, /* type */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 FALSE
, /* pc_relative */
770 complain_overflow_dont
,/* complain_on_overflow */
771 bfd_elf_generic_reloc
, /* special_function */
772 "R_C6000_ABS32", /* name */
773 TRUE
, /* partial_inplace */
774 0xffffffff, /* src_mask */
775 0xffffffff, /* dst_mask */
776 FALSE
), /* pcrel_offset */
777 HOWTO (R_C6000_ABS16
, /* type */
779 1, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE
, /* pc_relative */
783 complain_overflow_bitfield
,/* complain_on_overflow */
784 bfd_elf_generic_reloc
, /* special_function */
785 "R_C6000_ABS16", /* name */
786 TRUE
, /* partial_inplace */
787 0x0000ffff, /* src_mask */
788 0x0000ffff, /* dst_mask */
789 FALSE
), /* pcrel_offset */
790 HOWTO (R_C6000_ABS8
, /* type */
792 0, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE
, /* pc_relative */
796 complain_overflow_bitfield
,/* complain_on_overflow */
797 bfd_elf_generic_reloc
, /* special_function */
798 "R_C6000_ABS8", /* name */
799 TRUE
, /* partial_inplace */
800 0x000000ff, /* src_mask */
801 0x000000ff, /* dst_mask */
802 FALSE
), /* pcrel_offset */
803 HOWTO (R_C6000_PCR_S21
, /* type */
805 2, /* size (0 = byte, 1 = short, 2 = long) */
807 TRUE
, /* pc_relative */
809 complain_overflow_signed
,/* complain_on_overflow */
810 bfd_elf_generic_reloc
, /* special_function */
811 "R_C6000_PCR_S21", /* name */
812 TRUE
, /* partial_inplace */
813 0x0fffff80, /* src_mask */
814 0x0fffff80, /* dst_mask */
815 TRUE
), /* pcrel_offset */
816 HOWTO (R_C6000_PCR_S12
, /* type */
818 2, /* size (0 = byte, 1 = short, 2 = long) */
820 TRUE
, /* pc_relative */
822 complain_overflow_signed
,/* complain_on_overflow */
823 bfd_elf_generic_reloc
, /* special_function */
824 "R_C6000_PCR_S12", /* name */
825 TRUE
, /* partial_inplace */
826 0x0fff0000, /* src_mask */
827 0x0fff0000, /* dst_mask */
828 TRUE
), /* pcrel_offset */
829 HOWTO (R_C6000_PCR_S10
, /* type */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
833 TRUE
, /* pc_relative */
835 complain_overflow_signed
,/* complain_on_overflow */
836 bfd_elf_generic_reloc
, /* special_function */
837 "R_C6000_PCR_S10", /* name */
838 TRUE
, /* partial_inplace */
839 0x007fe000, /* src_mask */
840 0x007fe000, /* dst_mask */
841 TRUE
), /* pcrel_offset */
842 HOWTO (R_C6000_PCR_S7
, /* type */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
846 TRUE
, /* pc_relative */
848 complain_overflow_signed
,/* complain_on_overflow */
849 bfd_elf_generic_reloc
, /* special_function */
850 "R_C6000_PCR_S7", /* name */
851 TRUE
, /* partial_inplace */
852 0x007f0000, /* src_mask */
853 0x007f0000, /* dst_mask */
854 TRUE
), /* pcrel_offset */
855 HOWTO (R_C6000_ABS_S16
, /* type */
857 2, /* size (0 = byte, 1 = short, 2 = long) */
859 FALSE
, /* pc_relative */
861 complain_overflow_signed
,/* complain_on_overflow */
862 bfd_elf_generic_reloc
, /* special_function */
863 "R_C6000_ABS_S16", /* name */
864 TRUE
, /* partial_inplace */
865 0x007fff80, /* src_mask */
866 0x007fff80, /* dst_mask */
867 FALSE
), /* pcrel_offset */
868 HOWTO (R_C6000_ABS_L16
, /* type */
870 2, /* size (0 = byte, 1 = short, 2 = long) */
872 FALSE
, /* pc_relative */
874 complain_overflow_dont
,/* complain_on_overflow */
875 bfd_elf_generic_reloc
, /* special_function */
876 "R_C6000_ABS_L16", /* name */
877 TRUE
, /* partial_inplace */
878 0x007fff80, /* src_mask */
879 0x007fff80, /* dst_mask */
880 FALSE
), /* pcrel_offset */
881 EMPTY_HOWTO (R_C6000_ABS_H16
),
882 HOWTO (R_C6000_SBR_U15_B
, /* type */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE
, /* pc_relative */
888 complain_overflow_unsigned
,/* complain_on_overflow */
889 bfd_elf_generic_reloc
, /* special_function */
890 "R_C6000_SBR_U15_B", /* name */
891 TRUE
, /* partial_inplace */
892 0x007fff00, /* src_mask */
893 0x007fff00, /* dst_mask */
894 FALSE
), /* pcrel_offset */
895 HOWTO (R_C6000_SBR_U15_H
, /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 FALSE
, /* pc_relative */
901 complain_overflow_unsigned
,/* complain_on_overflow */
902 bfd_elf_generic_reloc
, /* special_function */
903 "R_C6000_SBR_U15_H", /* name */
904 TRUE
, /* partial_inplace */
905 0x007fff00, /* src_mask */
906 0x007fff00, /* dst_mask */
907 FALSE
), /* pcrel_offset */
908 HOWTO (R_C6000_SBR_U15_W
, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_unsigned
,/* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* special_function */
916 "R_C6000_SBR_U15_W", /* name */
917 TRUE
, /* partial_inplace */
918 0x007fff00, /* src_mask */
919 0x007fff00, /* dst_mask */
920 FALSE
), /* pcrel_offset */
921 HOWTO (R_C6000_SBR_S16
, /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_signed
,/* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 "R_C6000_SBR_S16", /* name */
930 TRUE
, /* partial_inplace */
931 0x007fff80, /* src_mask */
932 0x007fff80, /* dst_mask */
933 FALSE
), /* pcrel_offset */
934 HOWTO (R_C6000_SBR_L16_B
, /* type */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_dont
,/* complain_on_overflow */
941 bfd_elf_generic_reloc
, /* special_function */
942 "R_C6000_SBR_L16_B", /* name */
943 TRUE
, /* partial_inplace */
944 0x007fff80, /* src_mask */
945 0x007fff80, /* dst_mask */
946 FALSE
), /* pcrel_offset */
947 HOWTO (R_C6000_SBR_L16_H
, /* type */
949 2, /* size (0 = byte, 1 = short, 2 = long) */
951 FALSE
, /* pc_relative */
953 complain_overflow_dont
,/* complain_on_overflow */
954 bfd_elf_generic_reloc
, /* special_function */
955 "R_C6000_SBR_L16_H", /* name */
956 TRUE
, /* partial_inplace */
957 0x007fff80, /* src_mask */
958 0x007fff80, /* dst_mask */
959 FALSE
), /* pcrel_offset */
960 HOWTO (R_C6000_SBR_L16_W
, /* type */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_dont
,/* complain_on_overflow */
967 bfd_elf_generic_reloc
, /* special_function */
968 "R_C6000_SBR_L16_W", /* name */
969 TRUE
, /* partial_inplace */
970 0x007fff80, /* src_mask */
971 0x007fff80, /* dst_mask */
972 FALSE
), /* pcrel_offset */
973 EMPTY_HOWTO (R_C6000_SBR_H16_B
),
974 EMPTY_HOWTO (R_C6000_SBR_H16_H
),
975 EMPTY_HOWTO (R_C6000_SBR_H16_W
),
976 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
978 2, /* size (0 = byte, 1 = short, 2 = long) */
980 FALSE
, /* pc_relative */
982 complain_overflow_unsigned
,/* complain_on_overflow */
983 bfd_elf_generic_reloc
, /* special_function */
984 "R_C6000_SBR_GOT_U15_W",/* name */
985 TRUE
, /* partial_inplace */
986 0x007fff00, /* src_mask */
987 0x007fff00, /* dst_mask */
988 FALSE
), /* pcrel_offset */
989 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
991 2, /* size (0 = byte, 1 = short, 2 = long) */
993 FALSE
, /* pc_relative */
995 complain_overflow_dont
,/* complain_on_overflow */
996 bfd_elf_generic_reloc
, /* special_function */
997 "R_C6000_SBR_GOT_L16_W",/* name */
998 TRUE
, /* partial_inplace */
999 0x007fff80, /* src_mask */
1000 0x007fff80, /* dst_mask */
1001 FALSE
), /* pcrel_offset */
1002 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W
),
1003 HOWTO (R_C6000_DSBT_INDEX
, /* type */
1005 2, /* size (0 = byte, 1 = short, 2 = long) */
1007 FALSE
, /* pc_relative */
1009 complain_overflow_unsigned
,/* complain_on_overflow */
1010 bfd_elf_generic_reloc
, /* special_function */
1011 "R_C6000_DSBT_INDEX", /* name */
1012 TRUE
, /* partial_inplace */
1014 0x007fff00, /* dst_mask */
1015 FALSE
), /* pcrel_offset */
1016 HOWTO (R_C6000_PREL31
, /* type */
1018 2, /* size (0 = byte, 1 = short, 2 = long) */
1020 TRUE
, /* pc_relative */
1022 complain_overflow_dont
,/* complain_on_overflow */
1023 bfd_elf_generic_reloc
, /* special_function */
1024 "R_C6000_PREL31", /* name */
1025 TRUE
, /* partial_inplace */
1027 0x7fffffff, /* dst_mask */
1028 TRUE
), /* pcrel_offset */
1029 HOWTO (R_C6000_COPY
, /* type */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_dont
,/* complain_on_overflow */
1036 bfd_elf_generic_reloc
, /* special_function */
1037 "R_C6000_COPY", /* name */
1038 TRUE
, /* partial_inplace */
1040 0xffffffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1042 HOWTO (R_C6000_JUMP_SLOT
, /* type */
1044 2, /* size (0 = byte, 1 = short, 2 = long) */
1046 FALSE
, /* pc_relative */
1048 complain_overflow_dont
,/* complain_on_overflow */
1049 bfd_elf_generic_reloc
, /* special_function */
1050 "R_C6000_JUMP_SLOT", /* name */
1051 FALSE
, /* partial_inplace */
1053 0xffffffff, /* dst_mask */
1054 FALSE
), /* pcrel_offset */
1055 HOWTO (R_C6000_EHTYPE
, /* type */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE
, /* pc_relative */
1061 complain_overflow_dont
,/* complain_on_overflow */
1062 bfd_elf_generic_reloc
, /* special_function */
1063 "R_C6000_EHTYPE", /* name */
1064 FALSE
, /* partial_inplace */
1066 0xffffffff, /* dst_mask */
1067 FALSE
), /* pcrel_offset */
1292 HOWTO (R_C6000_ALIGN
, /* type */
1294 0, /* size (0 = byte, 1 = short, 2 = long) */
1296 FALSE
, /* pc_relative */
1298 complain_overflow_dont
,/* complain_on_overflow */
1299 bfd_elf_generic_reloc
, /* special_function */
1300 "R_C6000_ALIGN", /* name */
1301 TRUE
, /* partial_inplace */
1304 FALSE
), /* pcrel_offset */
1305 HOWTO (R_C6000_FPHEAD
, /* type */
1307 0, /* size (0 = byte, 1 = short, 2 = long) */
1309 FALSE
, /* pc_relative */
1311 complain_overflow_dont
,/* complain_on_overflow */
1312 bfd_elf_generic_reloc
, /* special_function */
1313 "R_C6000_FPHEAD", /* name */
1314 TRUE
, /* partial_inplace */
1317 FALSE
), /* pcrel_offset */
1318 HOWTO (R_C6000_NOCMP
, /* type */
1320 0, /* size (0 = byte, 1 = short, 2 = long) */
1322 FALSE
, /* pc_relative */
1324 complain_overflow_dont
,/* complain_on_overflow */
1325 bfd_elf_generic_reloc
, /* special_function */
1326 "R_C6000_NOCMP", /* name */
1327 TRUE
, /* partial_inplace */
1330 FALSE
) /* pcrel_offset */
1333 /* Map BFD relocations to ELF relocations. */
1337 bfd_reloc_code_real_type bfd_reloc_val
;
1338 enum elf_tic6x_reloc_type elf_reloc_val
;
1341 static const tic6x_reloc_map elf32_tic6x_reloc_map
[] =
1343 { BFD_RELOC_NONE
, R_C6000_NONE
},
1344 { BFD_RELOC_32
, R_C6000_ABS32
},
1345 { BFD_RELOC_16
, R_C6000_ABS16
},
1346 { BFD_RELOC_8
, R_C6000_ABS8
},
1347 { BFD_RELOC_C6000_PCR_S21
, R_C6000_PCR_S21
},
1348 { BFD_RELOC_C6000_PCR_S12
, R_C6000_PCR_S12
},
1349 { BFD_RELOC_C6000_PCR_S10
, R_C6000_PCR_S10
},
1350 { BFD_RELOC_C6000_PCR_S7
, R_C6000_PCR_S7
},
1351 { BFD_RELOC_C6000_ABS_S16
, R_C6000_ABS_S16
},
1352 { BFD_RELOC_C6000_ABS_L16
, R_C6000_ABS_L16
},
1353 { BFD_RELOC_C6000_ABS_H16
, R_C6000_ABS_H16
},
1354 { BFD_RELOC_C6000_SBR_U15_B
, R_C6000_SBR_U15_B
},
1355 { BFD_RELOC_C6000_SBR_U15_H
, R_C6000_SBR_U15_H
},
1356 { BFD_RELOC_C6000_SBR_U15_W
, R_C6000_SBR_U15_W
},
1357 { BFD_RELOC_C6000_SBR_S16
, R_C6000_SBR_S16
},
1358 { BFD_RELOC_C6000_SBR_L16_B
, R_C6000_SBR_L16_B
},
1359 { BFD_RELOC_C6000_SBR_L16_H
, R_C6000_SBR_L16_H
},
1360 { BFD_RELOC_C6000_SBR_L16_W
, R_C6000_SBR_L16_W
},
1361 { BFD_RELOC_C6000_SBR_H16_B
, R_C6000_SBR_H16_B
},
1362 { BFD_RELOC_C6000_SBR_H16_H
, R_C6000_SBR_H16_H
},
1363 { BFD_RELOC_C6000_SBR_H16_W
, R_C6000_SBR_H16_W
},
1364 { BFD_RELOC_C6000_SBR_GOT_U15_W
, R_C6000_SBR_GOT_U15_W
},
1365 { BFD_RELOC_C6000_SBR_GOT_L16_W
, R_C6000_SBR_GOT_L16_W
},
1366 { BFD_RELOC_C6000_SBR_GOT_H16_W
, R_C6000_SBR_GOT_H16_W
},
1367 { BFD_RELOC_C6000_DSBT_INDEX
, R_C6000_DSBT_INDEX
},
1368 { BFD_RELOC_C6000_PREL31
, R_C6000_PREL31
},
1369 { BFD_RELOC_C6000_COPY
, R_C6000_COPY
},
1370 { BFD_RELOC_C6000_JUMP_SLOT
, R_C6000_JUMP_SLOT
},
1371 { BFD_RELOC_C6000_EHTYPE
, R_C6000_EHTYPE
},
1372 { BFD_RELOC_C6000_PCR_H16
, R_C6000_PCR_H16
},
1373 { BFD_RELOC_C6000_PCR_L16
, R_C6000_PCR_L16
},
1374 { BFD_RELOC_C6000_ALIGN
, R_C6000_ALIGN
},
1375 { BFD_RELOC_C6000_FPHEAD
, R_C6000_FPHEAD
},
1376 { BFD_RELOC_C6000_NOCMP
, R_C6000_NOCMP
}
1379 static reloc_howto_type
*
1380 elf32_tic6x_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1384 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_reloc_map
); i
++)
1385 if (elf32_tic6x_reloc_map
[i
].bfd_reloc_val
== code
)
1387 enum elf_tic6x_reloc_type elf_reloc_val
;
1388 reloc_howto_type
*howto
;
1390 elf_reloc_val
= elf32_tic6x_reloc_map
[i
].elf_reloc_val
;
1391 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1392 howto
= &elf32_tic6x_howto_table
[elf_reloc_val
];
1394 howto
= &elf32_tic6x_howto_table_rel
[elf_reloc_val
];
1396 /* Some relocations are RELA-only; do not return them for
1398 if (howto
->name
== NULL
)
1407 static reloc_howto_type
*
1408 elf32_tic6x_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1410 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1414 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table
); i
++)
1415 if (elf32_tic6x_howto_table
[i
].name
!= NULL
1416 && strcasecmp (elf32_tic6x_howto_table
[i
].name
, r_name
) == 0)
1417 return &elf32_tic6x_howto_table
[i
];
1423 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table_rel
); i
++)
1424 if (elf32_tic6x_howto_table_rel
[i
].name
!= NULL
1425 && strcasecmp (elf32_tic6x_howto_table_rel
[i
].name
, r_name
) == 0)
1426 return &elf32_tic6x_howto_table_rel
[i
];
1433 elf32_tic6x_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1434 Elf_Internal_Rela
*elf_reloc
)
1436 unsigned int r_type
;
1438 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1439 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table
))
1440 bfd_reloc
->howto
= NULL
;
1442 bfd_reloc
->howto
= &elf32_tic6x_howto_table
[r_type
];
1446 elf32_tic6x_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1447 Elf_Internal_Rela
*elf_reloc
)
1449 unsigned int r_type
;
1451 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1452 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table_rel
))
1453 bfd_reloc
->howto
= NULL
;
1455 bfd_reloc
->howto
= &elf32_tic6x_howto_table_rel
[r_type
];
1459 elf32_tic6x_set_use_rela_p (bfd
*abfd
, bfd_boolean use_rela_p
)
1461 elf32_tic6x_tdata (abfd
)->use_rela_p
= use_rela_p
;
1464 /* Create an entry in a C6X ELF linker hash table. */
1466 static struct bfd_hash_entry
*
1467 elf32_tic6x_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1468 struct bfd_hash_table
*table
,
1471 /* Allocate the structure if it has not already been allocated by a
1475 entry
= bfd_hash_allocate (table
,
1476 sizeof (struct elf32_tic6x_link_hash_entry
));
1481 /* Call the allocation method of the superclass. */
1482 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1485 struct elf32_tic6x_link_hash_entry
*eh
;
1487 eh
= (struct elf32_tic6x_link_hash_entry
*) entry
;
1488 eh
->dyn_relocs
= NULL
;
1494 /* Create a C6X ELF linker hash table. */
1496 static struct bfd_link_hash_table
*
1497 elf32_tic6x_link_hash_table_create (bfd
*abfd
)
1499 struct elf32_tic6x_link_hash_table
*ret
;
1500 bfd_size_type amt
= sizeof (struct elf32_tic6x_link_hash_table
);
1502 ret
= bfd_malloc (amt
);
1506 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1507 elf32_tic6x_link_hash_newfunc
,
1508 sizeof (struct elf32_tic6x_link_hash_entry
),
1515 ret
->sym_cache
.abfd
= NULL
;
1517 ret
->elf
.is_relocatable_executable
= 1;
1519 return &ret
->elf
.root
;
1523 elf32_tic6x_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
1527 obj_attribute
*out_attr
;
1528 out_attr
= elf_known_obj_attributes_proc (abfd
);
1529 if (out_attr
[Tag_ABI_PIC
].i
== 0)
1531 _bfd_error_handler (_("warning: generating a shared library "
1532 "containing non-PIC code"));
1534 if (out_attr
[Tag_ABI_PID
].i
== 0)
1536 _bfd_error_handler (_("warning: generating a shared library "
1537 "containing non-PID code"));
1540 /* Invoke the regular ELF backend linker to do all the work. */
1541 if (!bfd_elf_final_link (abfd
, info
))
1547 /* Destroy a C6X ELF linker hash table. */
1550 elf32_tic6x_link_hash_table_free (struct bfd_link_hash_table
*hash
)
1552 _bfd_generic_link_hash_table_free (hash
);
1555 /* Called to pass PARAMS to the backend. We store them in the hash table
1556 associated with INFO. */
1559 elf32_tic6x_setup (struct bfd_link_info
*info
,
1560 struct elf32_tic6x_params
*params
)
1562 struct elf32_tic6x_link_hash_table
*htab
= elf32_tic6x_hash_table (info
);
1563 htab
->params
= *params
;
1566 /* Determine if we're dealing with a DSBT object. */
1569 elf32_tic6x_using_dsbt (bfd
*abfd
)
1571 return bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
,
1575 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1576 sections in DYNOBJ, and set up shortcuts to them in our hash
1580 elf32_tic6x_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1582 struct elf32_tic6x_link_hash_table
*htab
;
1585 htab
= elf32_tic6x_hash_table (info
);
1589 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1593 flags
= (SEC_ALLOC
| SEC_LOAD
1594 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1595 htab
->dsbt
= bfd_make_section_anyway_with_flags (dynobj
, ".dsbt",
1597 if (htab
->dsbt
== NULL
1598 || ! bfd_set_section_alignment (dynobj
, htab
->dsbt
, 2)
1599 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.splt
, 5))
1602 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1604 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1607 || (!info
->shared
&& !htab
->srelbss
))
1614 elf32_tic6x_mkobject (bfd
*abfd
)
1618 ret
= bfd_elf_allocate_object (abfd
, sizeof (struct elf32_tic6x_obj_tdata
),
1621 elf32_tic6x_set_use_rela_p (abfd
, TRUE
);
1625 /* Install relocation RELA into section SRELA, incrementing its
1629 elf32_tic6x_install_rela (bfd
*output_bfd
, asection
*srela
,
1630 Elf_Internal_Rela
*rela
)
1633 bfd_vma off
= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1634 loc
= srela
->contents
+ off
;
1635 BFD_ASSERT (off
< srela
->size
);
1636 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
1639 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1640 of the GOT at this offset have been initialized with the relocation. */
1643 elf32_tic6x_make_got_dynreloc (bfd
*output_bfd
,
1644 struct elf32_tic6x_link_hash_table
*htab
,
1645 asection
*sym_sec
, bfd_vma offset
)
1647 asection
*sgot
= htab
->elf
.sgot
;
1648 Elf_Internal_Rela outrel
;
1651 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
1652 outrel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
1653 if (sym_sec
&& sym_sec
->output_section
1654 && ! bfd_is_abs_section (sym_sec
->output_section
)
1655 && ! bfd_is_und_section (sym_sec
->output_section
))
1657 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
1658 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
1664 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_C6000_ABS32
);
1665 elf32_tic6x_install_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
1668 /* Finish up dynamic symbol handling. We set the contents of various
1669 dynamic sections here. */
1672 elf32_tic6x_finish_dynamic_symbol (bfd
* output_bfd
,
1673 struct bfd_link_info
*info
,
1674 struct elf_link_hash_entry
*h
,
1675 Elf_Internal_Sym
* sym
)
1678 struct elf32_tic6x_link_hash_table
*htab
;
1680 htab
= elf32_tic6x_hash_table (info
);
1681 dynobj
= htab
->elf
.dynobj
;
1683 if (h
->plt
.offset
!= (bfd_vma
) -1)
1686 bfd_vma got_section_offset
, got_dp_offset
, rela_offset
;
1687 Elf_Internal_Rela rela
;
1689 asection
*plt
, *gotplt
, *relplt
;
1690 const struct elf_backend_data
*bed
;
1692 bed
= get_elf_backend_data (output_bfd
);
1694 BFD_ASSERT (htab
->elf
.splt
!= NULL
);
1695 plt
= htab
->elf
.splt
;
1696 gotplt
= htab
->elf
.sgotplt
;
1697 relplt
= htab
->elf
.srelplt
;
1699 /* This symbol has an entry in the procedure linkage table. Set
1702 if ((h
->dynindx
== -1
1703 && !((h
->forced_local
|| info
->executable
)
1705 && h
->type
== STT_GNU_IFUNC
))
1711 /* Get the index in the procedure linkage table which
1712 corresponds to this symbol. This is the index of this symbol
1713 in all the symbols for which we are making plt entries. The
1714 first entry in the procedure linkage table is reserved.
1716 Get the offset into the .got table of the entry that
1717 corresponds to this function. Each .got entry is 4 bytes.
1718 The first three are reserved.
1720 For static executables, we don't reserve anything. */
1722 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1723 got_section_offset
= plt_index
+ bed
->got_header_size
/ 4;
1724 got_dp_offset
= got_section_offset
+ htab
->params
.dsbt_size
;
1725 rela_offset
= plt_index
* sizeof (Elf32_External_Rela
);
1727 got_section_offset
*= 4;
1729 /* Fill in the entry in the procedure linkage table. */
1731 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1732 bfd_put_32 (output_bfd
, got_dp_offset
<< 8 | 0x0100006e,
1733 plt
->contents
+ h
->plt
.offset
);
1734 /* mvk .s2 low(rela_offset), b0 */
1735 bfd_put_32 (output_bfd
, (rela_offset
& 0xffff) << 7 | 0x0000002a,
1736 plt
->contents
+ h
->plt
.offset
+ 4);
1737 /* mvkh .s2 high(rela_offset), b0 */
1738 bfd_put_32 (output_bfd
, ((rela_offset
>> 16) & 0xffff) << 7 | 0x0000006a,
1739 plt
->contents
+ h
->plt
.offset
+ 8);
1741 bfd_put_32 (output_bfd
, 0x00002000,
1742 plt
->contents
+ h
->plt
.offset
+ 12);
1744 bfd_put_32 (output_bfd
, 0x00080362,
1745 plt
->contents
+ h
->plt
.offset
+ 16);
1747 bfd_put_32 (output_bfd
, 0x00008000,
1748 plt
->contents
+ h
->plt
.offset
+ 20);
1750 /* Fill in the entry in the global offset table. */
1751 bfd_put_32 (output_bfd
,
1752 (plt
->output_section
->vma
+ plt
->output_offset
),
1753 gotplt
->contents
+ got_section_offset
);
1755 /* Fill in the entry in the .rel.plt section. */
1756 rela
.r_offset
= (gotplt
->output_section
->vma
1757 + gotplt
->output_offset
1758 + got_section_offset
);
1759 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_JUMP_SLOT
);
1761 loc
= relplt
->contents
+ rela_offset
;
1762 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1764 if (!h
->def_regular
)
1766 /* Mark the symbol as undefined, rather than as defined in
1767 the .plt section. */
1768 sym
->st_shndx
= SHN_UNDEF
;
1773 if (h
->got
.offset
!= (bfd_vma
) -1)
1778 /* This symbol has an entry in the global offset table.
1781 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1782 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1783 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1785 /* If this is a -Bsymbolic link, and the symbol is defined
1786 locally, we just want to emit a RELATIVE reloc. Likewise if
1787 the symbol was forced to be local because of a version file.
1788 The entry in the global offset table will already have been
1789 initialized in the relocate_section function. */
1792 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1794 asection
*s
= h
->root
.u
.def
.section
;
1795 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, s
,
1796 h
->got
.offset
& ~(bfd_vma
) 1);
1800 Elf_Internal_Rela outrel
;
1801 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1802 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1803 outrel
.r_offset
= (sgot
->output_section
->vma
1804 + sgot
->output_offset
1805 + (h
->got
.offset
& ~(bfd_vma
) 1));
1806 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_ABS32
);
1807 outrel
.r_addend
= 0;
1809 elf32_tic6x_install_rela (output_bfd
, srela
, &outrel
);
1815 Elf_Internal_Rela rel
;
1817 /* This symbol needs a copy reloc. Set it up. */
1819 if (h
->dynindx
== -1
1820 || (h
->root
.type
!= bfd_link_hash_defined
1821 && h
->root
.type
!= bfd_link_hash_defweak
)
1822 || htab
->srelbss
== NULL
)
1825 rel
.r_offset
= (h
->root
.u
.def
.value
1826 + h
->root
.u
.def
.section
->output_section
->vma
1827 + h
->root
.u
.def
.section
->output_offset
);
1828 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_COPY
);
1831 elf32_tic6x_install_rela (output_bfd
, htab
->srelbss
, &rel
);
1834 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1835 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1836 || h
== elf_hash_table (info
)->hgot
)
1837 sym
->st_shndx
= SHN_ABS
;
1842 /* Unwinding tables are not referenced directly. This pass marks them as
1843 required if the corresponding code section is marked. */
1846 elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info
*info
,
1847 elf_gc_mark_hook_fn gc_mark_hook
)
1850 Elf_Internal_Shdr
**elf_shdrp
;
1853 /* Marking EH data may cause additional code sections to be marked,
1854 requiring multiple passes. */
1859 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
1863 if (! is_tic6x_elf (sub
))
1866 elf_shdrp
= elf_elfsections (sub
);
1867 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
1869 Elf_Internal_Shdr
*hdr
;
1871 hdr
= &elf_section_data (o
)->this_hdr
;
1872 if (hdr
->sh_type
== SHT_C6000_UNWIND
1874 && hdr
->sh_link
< elf_numsections (sub
)
1876 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
1879 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
1889 /* Return TRUE if this is an unwinding table index. */
1892 is_tic6x_elf_unwind_section_name (const char *name
)
1894 return (CONST_STRNEQ (name
, ELF_STRING_C6000_unwind
)
1895 || CONST_STRNEQ (name
, ELF_STRING_C6000_unwind_once
));
1899 /* Set the type and flags for an unwinding index table. We do this by
1900 the section name, which is a hack, but ought to work. */
1903 elf32_tic6x_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1904 Elf_Internal_Shdr
*hdr
, asection
*sec
)
1908 name
= bfd_get_section_name (abfd
, sec
);
1910 if (is_tic6x_elf_unwind_section_name (name
))
1912 hdr
->sh_type
= SHT_C6000_UNWIND
;
1913 hdr
->sh_flags
|= SHF_LINK_ORDER
;
1919 /* Update the got entry reference counts for the section being removed. */
1922 elf32_tic6x_gc_sweep_hook (bfd
*abfd
,
1923 struct bfd_link_info
*info
,
1925 const Elf_Internal_Rela
*relocs
)
1927 struct elf32_tic6x_link_hash_table
*htab
;
1928 Elf_Internal_Shdr
*symtab_hdr
;
1929 struct elf_link_hash_entry
**sym_hashes
;
1930 bfd_signed_vma
*local_got_refcounts
;
1931 const Elf_Internal_Rela
*rel
, *relend
;
1933 if (info
->relocatable
)
1936 htab
= elf32_tic6x_hash_table (info
);
1940 elf_section_data (sec
)->local_dynrel
= NULL
;
1942 symtab_hdr
= &elf_symtab_hdr (abfd
);
1943 sym_hashes
= elf_sym_hashes (abfd
);
1944 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1946 relend
= relocs
+ sec
->reloc_count
;
1947 for (rel
= relocs
; rel
< relend
; rel
++)
1949 unsigned long r_symndx
;
1950 unsigned int r_type
;
1951 struct elf_link_hash_entry
*h
= NULL
;
1953 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1954 if (r_symndx
>= symtab_hdr
->sh_info
)
1956 struct elf32_tic6x_link_hash_entry
*eh
;
1957 struct elf_dyn_relocs
**pp
;
1958 struct elf_dyn_relocs
*p
;
1960 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1961 while (h
->root
.type
== bfd_link_hash_indirect
1962 || h
->root
.type
== bfd_link_hash_warning
)
1963 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1964 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
1966 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1969 /* Everything must go for SEC. */
1975 r_type
= ELF32_R_TYPE (rel
->r_info
);
1979 case R_C6000_SBR_GOT_U15_W
:
1980 case R_C6000_SBR_GOT_L16_W
:
1981 case R_C6000_SBR_GOT_H16_W
:
1982 case R_C6000_EHTYPE
:
1985 if (h
->got
.refcount
> 0)
1986 h
->got
.refcount
-= 1;
1988 else if (local_got_refcounts
!= NULL
)
1990 if (local_got_refcounts
[r_symndx
] > 0)
1991 local_got_refcounts
[r_symndx
] -= 1;
2003 /* Adjust a symbol defined by a dynamic object and referenced by a
2004 regular object. The current definition is in some section of the
2005 dynamic object, but we're not including those sections. We have to
2006 change the definition to something the rest of the link can
2010 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2011 struct elf_link_hash_entry
*h
)
2013 struct elf32_tic6x_link_hash_table
*htab
;
2017 dynobj
= elf_hash_table (info
)->dynobj
;
2019 /* Make sure we know what is going on here. */
2020 BFD_ASSERT (dynobj
!= NULL
2022 || h
->u
.weakdef
!= NULL
2023 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
2025 /* If this is a function, put it in the procedure linkage table. We
2026 will fill in the contents of the procedure linkage table later,
2027 when we know the address of the .got section. */
2028 if (h
->type
== STT_FUNC
2031 if (h
->plt
.refcount
<= 0
2032 || SYMBOL_CALLS_LOCAL (info
, h
)
2033 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2034 && h
->root
.type
== bfd_link_hash_undefweak
))
2036 /* This case can occur if we saw a PLT32 reloc in an input
2037 file, but the symbol was never referred to by a dynamic
2038 object, or if all references were garbage collected. In
2039 such a case, we don't actually need to build a procedure
2040 linkage table, and we can just do a PC32 reloc instead. */
2041 h
->plt
.offset
= (bfd_vma
) -1;
2048 /* If this is a weak symbol, and there is a real definition, the
2049 processor independent code will have arranged for us to see the
2050 real definition first, and we can just use the same value. */
2051 if (h
->u
.weakdef
!= NULL
)
2053 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2054 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2055 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2056 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2057 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2061 /* This is a reference to a symbol defined by a dynamic object which
2062 is not a function. */
2064 /* If we are creating a shared library, we must presume that the
2065 only references to the symbol are via the global offset table.
2066 For such cases we need not do anything here; the relocations will
2067 be handled correctly by relocate_section. */
2071 /* If there are no references to this symbol that do not use the
2072 GOT, we don't need to generate a copy reloc. */
2073 if (!h
->non_got_ref
)
2076 /* If -z nocopyreloc was given, we won't generate them either. */
2077 if (info
->nocopyreloc
)
2083 htab
= elf32_tic6x_hash_table (info
);
2089 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2090 h
->root
.root
.string
);
2094 /* We must allocate the symbol in our .dynbss section, which will
2095 become part of the .bss section of the executable. There will be
2096 an entry for this symbol in the .dynsym section. The dynamic
2097 object will contain position independent code, so all references
2098 from the dynamic object to this symbol will go through the global
2099 offset table. The dynamic linker will use the .dynsym entry to
2100 determine the address it must put in the global offset table, so
2101 both the dynamic object and the regular object will refer to the
2102 same memory location for the variable. */
2104 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2105 copy the initial value out of the dynamic object and into the
2106 runtime process image. */
2107 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2109 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
2115 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2119 elf32_tic6x_new_section_hook (bfd
*abfd
, asection
*sec
)
2123 ret
= _bfd_elf_new_section_hook (abfd
, sec
);
2124 sec
->use_rela_p
= elf32_tic6x_tdata (abfd
)->use_rela_p
;
2129 /* Return true if relocation REL against section SEC is a REL rather
2130 than RELA relocation. RELOCS is the first relocation in the
2131 section and ABFD is the bfd that contains SEC. */
2134 elf32_tic6x_rel_relocation_p (bfd
*abfd
, asection
*sec
,
2135 const Elf_Internal_Rela
*relocs
,
2136 const Elf_Internal_Rela
*rel
)
2138 Elf_Internal_Shdr
*rel_hdr
;
2139 const struct elf_backend_data
*bed
;
2141 /* To determine which flavor of relocation this is, we depend on the
2142 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2143 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
2144 if (rel_hdr
== NULL
)
2146 bed
= get_elf_backend_data (abfd
);
2147 return ((size_t) (rel
- relocs
)
2148 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
2151 /* We need dynamic symbols for every section, since segments can
2152 relocate independently. */
2154 elf32_tic6x_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2155 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2158 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2162 /* If sh_type is yet undecided, assume it could be
2163 SHT_PROGBITS/SHT_NOBITS. */
2167 /* There shouldn't be section relative relocations
2168 against any other section. */
2175 elf32_tic6x_relocate_section (bfd
*output_bfd
,
2176 struct bfd_link_info
*info
,
2178 asection
*input_section
,
2180 Elf_Internal_Rela
*relocs
,
2181 Elf_Internal_Sym
*local_syms
,
2182 asection
**local_sections
)
2184 struct elf32_tic6x_link_hash_table
*htab
;
2185 Elf_Internal_Shdr
*symtab_hdr
;
2186 struct elf_link_hash_entry
**sym_hashes
;
2187 bfd_vma
*local_got_offsets
;
2188 Elf_Internal_Rela
*rel
;
2189 Elf_Internal_Rela
*relend
;
2190 bfd_boolean ok
= TRUE
;
2192 htab
= elf32_tic6x_hash_table (info
);
2193 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
2194 sym_hashes
= elf_sym_hashes (input_bfd
);
2195 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2197 relend
= relocs
+ input_section
->reloc_count
;
2199 for (rel
= relocs
; rel
< relend
; rel
++)
2202 unsigned long r_symndx
;
2204 reloc_howto_type
*howto
;
2205 Elf_Internal_Sym
*sym
;
2207 struct elf_link_hash_entry
*h
;
2208 bfd_vma off
, relocation
;
2209 bfd_boolean unresolved_reloc
;
2210 bfd_reloc_status_type r
;
2211 struct bfd_link_hash_entry
*sbh
;
2214 r_type
= ELF32_R_TYPE (rel
->r_info
);
2215 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2217 is_rel
= elf32_tic6x_rel_relocation_p (input_bfd
, input_section
,
2221 elf32_tic6x_info_to_howto_rel (input_bfd
, &bfd_reloc
, rel
);
2223 elf32_tic6x_info_to_howto (input_bfd
, &bfd_reloc
, rel
);
2224 howto
= bfd_reloc
.howto
;
2227 bfd_set_error (bfd_error_bad_value
);
2234 unresolved_reloc
= FALSE
;
2236 if (r_symndx
< symtab_hdr
->sh_info
)
2238 sym
= local_syms
+ r_symndx
;
2239 sec
= local_sections
[r_symndx
];
2240 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2246 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2247 r_symndx
, symtab_hdr
, sym_hashes
,
2249 unresolved_reloc
, warned
);
2252 if (sec
!= NULL
&& elf_discarded_section (sec
))
2253 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2254 rel
, relend
, howto
, contents
);
2256 if (info
->relocatable
)
2260 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2263 relocation
= sec
->output_offset
+ sym
->st_value
;
2264 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
2265 contents
+ rel
->r_offset
);
2275 case R_C6000_FPHEAD
:
2277 /* No action needed. */
2280 case R_C6000_PCR_S21
:
2281 /* A branch to an undefined weak symbol is turned into a
2282 "b .s2 B3" instruction if the existing insn is of the
2283 form "b .s2 symbol". */
2284 if (h
? h
->root
.type
== bfd_link_hash_undefweak
2285 && (htab
->elf
.splt
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
2286 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2288 unsigned long oldval
;
2289 oldval
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2291 if ((oldval
& 0x7e) == 0x12)
2293 oldval
&= 0xF0000001;
2294 bfd_put_32 (input_bfd
, oldval
| 0x000c0362,
2295 contents
+ rel
->r_offset
);
2301 case R_C6000_PCR_S12
:
2302 case R_C6000_PCR_S10
:
2303 case R_C6000_PCR_S7
:
2305 && h
->plt
.offset
!= (bfd_vma
) -1
2306 && htab
->elf
.splt
!= NULL
)
2308 relocation
= (htab
->elf
.splt
->output_section
->vma
2309 + htab
->elf
.splt
->output_offset
2313 /* Generic PC-relative handling produces a value relative to
2314 the exact location of the relocation. Adjust it to be
2315 relative to the start of the fetch packet instead. */
2316 relocation
+= (input_section
->output_section
->vma
2317 + input_section
->output_offset
2318 + rel
->r_offset
) & 0x1f;
2319 unresolved_reloc
= FALSE
;
2322 case R_C6000_DSBT_INDEX
:
2323 relocation
= elf32_tic6x_hash_table (info
)->params
.dsbt_index
;
2324 if (!info
->shared
|| relocation
!= 0)
2331 case R_C6000_ABS_S16
:
2332 case R_C6000_ABS_L16
:
2333 case R_C6000_ABS_H16
:
2334 /* When generating a shared object or relocatable executable, these
2335 relocations are copied into the output file to be resolved at
2337 if ((info
->shared
|| elf32_tic6x_using_dsbt (output_bfd
))
2338 && (input_section
->flags
& SEC_ALLOC
)
2340 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2341 || h
->root
.type
!= bfd_link_hash_undefweak
))
2343 Elf_Internal_Rela outrel
;
2344 bfd_boolean skip
, relocate
;
2347 unresolved_reloc
= FALSE
;
2349 sreloc
= elf_section_data (input_section
)->sreloc
;
2350 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
2356 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2358 if (outrel
.r_offset
== (bfd_vma
) -1)
2360 else if (outrel
.r_offset
== (bfd_vma
) -2)
2361 skip
= TRUE
, relocate
= TRUE
;
2362 outrel
.r_offset
+= (input_section
->output_section
->vma
2363 + input_section
->output_offset
);
2366 memset (&outrel
, 0, sizeof outrel
);
2371 || !h
->def_regular
))
2373 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2374 outrel
.r_addend
= rel
->r_addend
;
2380 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2382 if (bfd_is_abs_section (sec
))
2384 else if (sec
== NULL
|| sec
->owner
== NULL
)
2386 bfd_set_error (bfd_error_bad_value
);
2393 osec
= sec
->output_section
;
2394 indx
= elf_section_data (osec
)->dynindx
;
2395 outrel
.r_addend
-= osec
->vma
;
2396 BFD_ASSERT (indx
!= 0);
2399 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2402 elf32_tic6x_install_rela (output_bfd
, sreloc
, &outrel
);
2404 /* If this reloc is against an external symbol, we do not want to
2405 fiddle with the addend. Otherwise, we need to include the symbol
2406 value so that it becomes an addend for the dynamic reloc. */
2411 /* Generic logic OK. */
2414 case R_C6000_SBR_U15_B
:
2415 case R_C6000_SBR_U15_H
:
2416 case R_C6000_SBR_U15_W
:
2417 case R_C6000_SBR_S16
:
2418 case R_C6000_SBR_L16_B
:
2419 case R_C6000_SBR_L16_H
:
2420 case R_C6000_SBR_L16_W
:
2421 case R_C6000_SBR_H16_B
:
2422 case R_C6000_SBR_H16_H
:
2423 case R_C6000_SBR_H16_W
:
2424 sbh
= bfd_link_hash_lookup (info
->hash
, "__c6xabi_DSBT_BASE",
2425 FALSE
, FALSE
, TRUE
);
2427 && (sbh
->type
== bfd_link_hash_defined
2428 || sbh
->type
== bfd_link_hash_defweak
))
2430 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
2431 && (htab
->elf
.splt
== NULL
2432 || h
->plt
.offset
== (bfd_vma
) -1))
2433 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2436 relocation
-= (sbh
->u
.def
.value
2437 + sbh
->u
.def
.section
->output_section
->vma
2438 + sbh
->u
.def
.section
->output_offset
);
2442 (*_bfd_error_handler
) (_("%B: SB-relative relocation but "
2443 "__c6xabi_DSBT_BASE not defined"),
2450 case R_C6000_SBR_GOT_U15_W
:
2451 case R_C6000_SBR_GOT_L16_W
:
2452 case R_C6000_SBR_GOT_H16_W
:
2453 case R_C6000_EHTYPE
:
2454 /* Relocation is to the entry for this symbol in the global
2456 if (htab
->elf
.sgot
== NULL
)
2463 off
= h
->got
.offset
;
2464 dyn
= htab
->elf
.dynamic_sections_created
;
2465 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2467 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2468 || (ELF_ST_VISIBILITY (h
->other
)
2469 && h
->root
.type
== bfd_link_hash_undefweak
))
2471 /* This is actually a static link, or it is a
2472 -Bsymbolic link and the symbol is defined
2473 locally, or the symbol was forced to be local
2474 because of a version file. We must initialize
2475 this entry in the global offset table. Since the
2476 offset must always be a multiple of 4, we use the
2477 least significant bit to record whether we have
2478 initialized it already.
2480 When doing a dynamic link, we create a .rel.got
2481 relocation entry to initialize the value. This
2482 is done in the finish_dynamic_symbol routine. */
2487 bfd_put_32 (output_bfd
, relocation
,
2488 htab
->elf
.sgot
->contents
+ off
);
2491 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
2493 && !(ELF_ST_VISIBILITY (h
->other
)
2494 && h
->root
.type
== bfd_link_hash_undefweak
))
2495 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
,
2500 unresolved_reloc
= FALSE
;
2504 if (local_got_offsets
== NULL
)
2507 off
= local_got_offsets
[r_symndx
];
2509 /* The offset must always be a multiple of 4. We use
2510 the least significant bit to record whether we have
2511 already generated the necessary reloc. */
2516 bfd_put_32 (output_bfd
, relocation
,
2517 htab
->elf
.sgot
->contents
+ off
);
2519 if (info
->shared
|| elf32_tic6x_using_dsbt (output_bfd
))
2520 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
, off
);
2522 local_got_offsets
[r_symndx
] |= 1;
2526 if (off
>= (bfd_vma
) -2)
2530 relocation
= (htab
->elf
.sgot
->output_section
->vma
2531 + htab
->elf
.sgot
->output_offset
+ off
2532 - htab
->dsbt
->output_section
->vma
2533 - htab
->dsbt
->output_offset
);
2535 relocation
= (htab
->elf
.sgot
->output_section
->vma
2536 + htab
->elf
.sgot
->output_offset
+ off
2537 - htab
->elf
.sgotplt
->output_section
->vma
2538 - htab
->elf
.sgotplt
->output_offset
);
2540 if (rel
->r_addend
!= 0)
2542 /* We can't do anything for a relocation which is against
2543 a symbol *plus offset*. GOT holds relocations for
2544 symbols. Make this an error; the compiler isn't
2545 allowed to pass us these kinds of things. */
2547 (*_bfd_error_handler
)
2548 (_("%B, section %A: relocation %s with non-zero addend %d"
2549 " against local symbol"),
2552 elf32_tic6x_howto_table
[r_type
].name
,
2555 (*_bfd_error_handler
)
2556 (_("%B, section %A: relocation %s with non-zero addend %d"
2557 " against symbol `%s'"),
2560 elf32_tic6x_howto_table
[r_type
].name
,
2562 h
->root
.root
.string
[0] != '\0' ? h
->root
.root
.string
2563 : _("[whose name is lost]"));
2565 bfd_set_error (bfd_error_bad_value
);
2570 case R_C6000_PREL31
:
2572 && h
->plt
.offset
!= (bfd_vma
) -1
2573 && htab
->elf
.splt
!= NULL
)
2575 relocation
= (htab
->elf
.splt
->output_section
->vma
2576 + htab
->elf
.splt
->output_offset
2582 /* Invalid in relocatable object. */
2584 /* Unknown relocation. */
2585 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2591 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2592 contents
, rel
->r_offset
,
2593 relocation
, rel
->r_addend
);
2596 if (r
== bfd_reloc_ok
2597 && howto
->complain_on_overflow
== complain_overflow_bitfield
)
2599 /* Generic overflow handling accepts cases the ABI says
2600 should be rejected for R_C6000_ABS16 and
2602 bfd_vma value
= (relocation
+ rel
->r_addend
) & 0xffffffff;
2603 bfd_vma sbit
= 1 << (howto
->bitsize
- 1);
2604 bfd_vma sbits
= (-(bfd_vma
) sbit
) & 0xffffffff;
2605 bfd_vma value_sbits
= value
& sbits
;
2607 if (value_sbits
!= 0
2608 && value_sbits
!= sbit
2609 && value_sbits
!= sbits
)
2610 r
= bfd_reloc_overflow
;
2613 if (r
!= bfd_reloc_ok
)
2616 const char *error_message
;
2619 name
= h
->root
.root
.string
;
2622 name
= bfd_elf_string_from_elf_section (input_bfd
,
2623 symtab_hdr
->sh_link
,
2628 name
= bfd_section_name (input_bfd
, sec
);
2633 case bfd_reloc_overflow
:
2634 /* If the overflowing reloc was to an undefined symbol,
2635 we have already printed one error message and there
2636 is no point complaining again. */
2638 h
->root
.type
!= bfd_link_hash_undefined
)
2639 && (!((*info
->callbacks
->reloc_overflow
)
2640 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2641 (bfd_vma
) 0, input_bfd
, input_section
,
2646 case bfd_reloc_undefined
:
2647 if (!((*info
->callbacks
->undefined_symbol
)
2648 (info
, name
, input_bfd
, input_section
,
2649 rel
->r_offset
, TRUE
)))
2653 case bfd_reloc_outofrange
:
2654 error_message
= _("out of range");
2657 case bfd_reloc_notsupported
:
2658 error_message
= _("unsupported relocation");
2661 case bfd_reloc_dangerous
:
2662 error_message
= _("dangerous relocation");
2666 error_message
= _("unknown error");
2670 BFD_ASSERT (error_message
!= NULL
);
2671 if (!((*info
->callbacks
->reloc_dangerous
)
2672 (info
, error_message
, input_bfd
, input_section
,
2684 /* Look through the relocs for a section during the first phase, and
2685 calculate needed space in the global offset table, procedure linkage
2686 table, and dynamic reloc sections. */
2689 elf32_tic6x_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2690 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2692 struct elf32_tic6x_link_hash_table
*htab
;
2693 Elf_Internal_Shdr
*symtab_hdr
;
2694 struct elf_link_hash_entry
**sym_hashes
;
2695 const Elf_Internal_Rela
*rel
;
2696 const Elf_Internal_Rela
*rel_end
;
2699 if (info
->relocatable
)
2702 htab
= elf32_tic6x_hash_table (info
);
2703 symtab_hdr
= &elf_symtab_hdr (abfd
);
2704 sym_hashes
= elf_sym_hashes (abfd
);
2706 /* Create dynamic sections for relocatable executables so that we can
2707 copy relocations. */
2708 if (elf32_tic6x_using_dsbt (abfd
)
2709 && ! htab
->elf
.dynamic_sections_created
)
2711 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2717 rel_end
= relocs
+ sec
->reloc_count
;
2718 for (rel
= relocs
; rel
< rel_end
; rel
++)
2720 unsigned int r_type
;
2721 unsigned long r_symndx
;
2722 struct elf_link_hash_entry
*h
;
2723 Elf_Internal_Sym
*isym
;
2725 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2726 r_type
= ELF32_R_TYPE (rel
->r_info
);
2728 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2730 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
2736 if (r_symndx
< symtab_hdr
->sh_info
)
2738 /* A local symbol. */
2739 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2748 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2749 while (h
->root
.type
== bfd_link_hash_indirect
2750 || h
->root
.type
== bfd_link_hash_warning
)
2751 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2756 case R_C6000_PCR_S21
:
2757 case R_C6000_PREL31
:
2758 /* This symbol requires a procedure linkage table entry. We
2759 actually build the entry in adjust_dynamic_symbol,
2760 because this might be a case of linking PIC code which is
2761 never referenced by a dynamic object, in which case we
2762 don't need to generate a procedure linkage table entry
2765 /* If this is a local symbol, we resolve it directly without
2766 creating a procedure linkage table entry. */
2771 h
->plt
.refcount
+= 1;
2774 case R_C6000_SBR_GOT_U15_W
:
2775 case R_C6000_SBR_GOT_L16_W
:
2776 case R_C6000_SBR_GOT_H16_W
:
2777 case R_C6000_EHTYPE
:
2778 /* This symbol requires a global offset table entry. */
2781 h
->got
.refcount
+= 1;
2785 bfd_signed_vma
*local_got_refcounts
;
2787 /* This is a global offset table entry for a local symbol. */
2788 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2789 if (local_got_refcounts
== NULL
)
2793 size
= symtab_hdr
->sh_info
;
2794 size
*= (sizeof (bfd_signed_vma
)
2795 + sizeof (bfd_vma
) + sizeof(char));
2796 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2797 if (local_got_refcounts
== NULL
)
2799 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2801 local_got_refcounts
[r_symndx
] += 1;
2804 if (htab
->elf
.sgot
== NULL
)
2806 if (htab
->elf
.dynobj
== NULL
)
2807 htab
->elf
.dynobj
= abfd
;
2808 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2813 case R_C6000_DSBT_INDEX
:
2814 /* We'd like to check for nonzero dsbt_index here, but it's
2815 set up only after check_relocs is called. Instead, we
2816 store the number of R_C6000_DSBT_INDEX relocs in the
2817 pc_count field, and potentially discard the extra space
2818 in elf32_tic6x_allocate_dynrelocs. */
2826 case R_C6000_ABS_S16
:
2827 case R_C6000_ABS_L16
:
2828 case R_C6000_ABS_H16
:
2829 /* If we are creating a shared library, and this is a reloc
2830 against a global symbol, or a non PC relative reloc
2831 against a local symbol, then we need to copy the reloc
2832 into the shared library. However, if we are linking with
2833 -Bsymbolic, we do not need to copy a reloc against a
2834 global symbol which is defined in an object we are
2835 including in the link (i.e., DEF_REGULAR is set). At
2836 this point we have not seen all the input files, so it is
2837 possible that DEF_REGULAR is not set now but will be set
2838 later (it is never cleared). In case of a weak definition,
2839 DEF_REGULAR may be cleared later by a strong definition in
2840 a shared library. We account for that possibility below by
2841 storing information in the relocs_copied field of the hash
2842 table entry. A similar situation occurs when creating
2843 shared libraries and symbol visibility changes render the
2846 If on the other hand, we are creating an executable, we
2847 may need to keep relocations for symbols satisfied by a
2848 dynamic library if we manage to avoid copy relocs for the
2850 if ((info
->shared
|| elf32_tic6x_using_dsbt (abfd
))
2851 && (sec
->flags
& SEC_ALLOC
) != 0)
2853 struct elf_dyn_relocs
*p
;
2854 struct elf_dyn_relocs
**head
;
2856 /* We must copy these reloc types into the output file.
2857 Create a reloc section in dynobj and make room for
2861 if (htab
->elf
.dynobj
== NULL
)
2862 htab
->elf
.dynobj
= abfd
;
2864 sreloc
= _bfd_elf_make_dynamic_reloc_section
2865 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela? */ TRUE
);
2871 /* If this is a global symbol, we count the number of
2872 relocations we need for this symbol. */
2875 head
= &((struct elf32_tic6x_link_hash_entry
*) h
)->dyn_relocs
;
2879 /* Track dynamic relocs needed for local syms too.
2880 We really need local syms available to do this
2885 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2889 vpp
= &elf_section_data (s
)->local_dynrel
;
2890 head
= (struct elf_dyn_relocs
**)vpp
;
2894 if (p
== NULL
|| p
->sec
!= sec
)
2896 bfd_size_type amt
= sizeof *p
;
2897 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
2908 if (r_type
== R_C6000_DSBT_INDEX
)
2913 case R_C6000_SBR_U15_B
:
2914 case R_C6000_SBR_U15_H
:
2915 case R_C6000_SBR_U15_W
:
2916 case R_C6000_SBR_S16
:
2917 case R_C6000_SBR_L16_B
:
2918 case R_C6000_SBR_L16_H
:
2919 case R_C6000_SBR_L16_W
:
2920 case R_C6000_SBR_H16_B
:
2921 case R_C6000_SBR_H16_H
:
2922 case R_C6000_SBR_H16_W
:
2923 if (h
!= NULL
&& info
->executable
)
2925 /* For B14-relative addresses, we might need a copy
2940 elf32_tic6x_add_symbol_hook (bfd
*abfd
,
2941 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2942 Elf_Internal_Sym
*sym
,
2943 const char **namep ATTRIBUTE_UNUSED
,
2944 flagword
*flagsp ATTRIBUTE_UNUSED
,
2948 switch (sym
->st_shndx
)
2950 case SHN_TIC6X_SCOMMON
:
2951 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2952 (*secp
)->flags
|= SEC_IS_COMMON
;
2953 *valp
= sym
->st_size
;
2954 bfd_set_section_alignment (abfd
, *secp
, bfd_log2 (sym
->st_value
));
2962 elf32_tic6x_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
2964 elf_symbol_type
*elfsym
;
2966 elfsym
= (elf_symbol_type
*) asym
;
2967 switch (elfsym
->internal_elf_sym
.st_shndx
)
2969 case SHN_TIC6X_SCOMMON
:
2970 if (tic6x_elf_scom_section
.name
== NULL
)
2972 /* Initialize the small common section. */
2973 tic6x_elf_scom_section
.name
= ".scommon";
2974 tic6x_elf_scom_section
.flags
= SEC_IS_COMMON
;
2975 tic6x_elf_scom_section
.output_section
= &tic6x_elf_scom_section
;
2976 tic6x_elf_scom_section
.symbol
= &tic6x_elf_scom_symbol
;
2977 tic6x_elf_scom_section
.symbol_ptr_ptr
= &tic6x_elf_scom_symbol_ptr
;
2978 tic6x_elf_scom_symbol
.name
= ".scommon";
2979 tic6x_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2980 tic6x_elf_scom_symbol
.section
= &tic6x_elf_scom_section
;
2981 tic6x_elf_scom_symbol_ptr
= &tic6x_elf_scom_symbol
;
2983 asym
->section
= &tic6x_elf_scom_section
;
2984 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2990 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2991 const char *name ATTRIBUTE_UNUSED
,
2992 Elf_Internal_Sym
*sym
,
2993 asection
*input_sec
,
2994 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2996 /* If we see a common symbol, which implies a relocatable link, then
2997 if a symbol was small common in an input file, mark it as small
2998 common in the output file. */
2999 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
3000 sym
->st_shndx
= SHN_TIC6X_SCOMMON
;
3006 elf32_tic6x_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
3010 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3012 *retval
= SHN_TIC6X_SCOMMON
;
3019 /* Allocate space in .plt, .got and associated reloc sections for
3023 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3025 struct bfd_link_info
*info
;
3026 struct elf32_tic6x_link_hash_table
*htab
;
3027 struct elf32_tic6x_link_hash_entry
*eh
;
3028 struct elf_dyn_relocs
*p
;
3030 if (h
->root
.type
== bfd_link_hash_indirect
)
3033 if (h
->root
.type
== bfd_link_hash_warning
)
3034 /* When warning symbols are created, they **replace** the "real"
3035 entry in the hash table, thus we never get to see the real
3036 symbol in a hash traversal. So look at it now. */
3037 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3038 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3040 info
= (struct bfd_link_info
*) inf
;
3041 htab
= elf32_tic6x_hash_table (info
);
3043 if (htab
->elf
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3045 /* Make sure this symbol is output as a dynamic symbol.
3046 Undefined weak syms won't yet be marked as dynamic. */
3047 if (h
->dynindx
== -1 && !h
->forced_local
)
3049 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3054 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3056 asection
*s
= htab
->elf
.splt
;
3058 /* If this is the first .plt entry, make room for the special
3061 s
->size
+= PLT_ENTRY_SIZE
;
3063 h
->plt
.offset
= s
->size
;
3065 /* If this symbol is not defined in a regular file, and we are
3066 not generating a shared library, then set the symbol to this
3067 location in the .plt. This is required to make function
3068 pointers compare as equal between the normal executable and
3069 the shared library. */
3070 if (! info
->shared
&& !h
->def_regular
)
3072 h
->root
.u
.def
.section
= s
;
3073 h
->root
.u
.def
.value
= h
->plt
.offset
;
3076 /* Make room for this entry. */
3077 s
->size
+= PLT_ENTRY_SIZE
;
3078 /* We also need to make an entry in the .got.plt section, which
3079 will be placed in the .got section by the linker script. */
3080 htab
->elf
.sgotplt
->size
+= 4;
3081 /* We also need to make an entry in the .rel.plt section. */
3082 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3086 h
->plt
.offset
= (bfd_vma
) -1;
3092 h
->plt
.offset
= (bfd_vma
) -1;
3096 if (h
->got
.refcount
> 0)
3100 /* Make sure this symbol is output as a dynamic symbol.
3101 Undefined weak syms won't yet be marked as dynamic. */
3102 if (h
->dynindx
== -1
3103 && !h
->forced_local
)
3105 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3110 h
->got
.offset
= s
->size
;
3113 if (!(ELF_ST_VISIBILITY (h
->other
)
3114 && h
->root
.type
== bfd_link_hash_undefweak
))
3115 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3118 h
->got
.offset
= (bfd_vma
) -1;
3120 if (eh
->dyn_relocs
== NULL
)
3123 /* Discard relocs on undefined weak syms with non-default
3125 if (info
->shared
|| elf32_tic6x_using_dsbt (htab
->obfd
))
3127 /* We use the pc_count field to hold the number of
3128 R_C6000_DSBT_INDEX relocs. */
3129 if (htab
->params
.dsbt_index
!= 0)
3131 struct elf_dyn_relocs
**pp
;
3133 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3135 p
->count
-= p
->pc_count
;
3144 if (eh
->dyn_relocs
!= NULL
3145 && h
->root
.type
== bfd_link_hash_undefweak
)
3147 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3148 eh
->dyn_relocs
= NULL
;
3150 /* Make sure undefined weak symbols are output as a dynamic
3152 else if (h
->dynindx
== -1
3153 && !h
->forced_local
)
3155 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3161 /* Finally, allocate space. */
3162 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3166 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3168 BFD_ASSERT (sreloc
!= NULL
);
3169 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3175 /* Find any dynamic relocs that apply to read-only sections. */
3178 elf32_tic6x_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3180 struct elf32_tic6x_link_hash_entry
*eh
;
3181 struct elf_dyn_relocs
*p
;
3183 if (h
->root
.type
== bfd_link_hash_warning
)
3184 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3186 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3187 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3189 asection
*s
= p
->sec
->output_section
;
3191 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3193 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3195 info
->flags
|= DF_TEXTREL
;
3197 /* Not an error, just cut short the traversal. */
3204 /* Set the sizes of the dynamic sections. */
3207 elf32_tic6x_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3209 struct elf32_tic6x_link_hash_table
*htab
;
3215 htab
= elf32_tic6x_hash_table (info
);
3216 dynobj
= htab
->elf
.dynobj
;
3220 if (htab
->elf
.dynamic_sections_created
)
3222 /* Set the contents of the .interp section to the interpreter. */
3223 if (info
->executable
)
3225 s
= bfd_get_section_by_name (dynobj
, ".interp");
3228 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3229 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3233 /* Set up .got offsets for local syms, and space for local dynamic
3235 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3237 bfd_signed_vma
*local_got
;
3238 bfd_signed_vma
*end_local_got
;
3239 char *local_tls_type
;
3240 bfd_vma
*local_tlsdesc_gotent
;
3241 bfd_size_type locsymcount
;
3242 Elf_Internal_Shdr
*symtab_hdr
;
3245 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3247 struct elf_dyn_relocs
*p
;
3249 for (p
= ((struct elf_dyn_relocs
*)
3250 elf_section_data (s
)->local_dynrel
);
3254 if (!bfd_is_abs_section (p
->sec
)
3255 && bfd_is_abs_section (p
->sec
->output_section
))
3257 /* Input section has been discarded, either because
3258 it is a copy of a linkonce section or due to
3259 linker script /DISCARD/, so we'll be discarding
3262 else if (p
->count
!= 0)
3264 srel
= elf_section_data (p
->sec
)->sreloc
;
3265 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3266 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3267 info
->flags
|= DF_TEXTREL
;
3272 local_got
= elf_local_got_refcounts (ibfd
);
3276 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3277 locsymcount
= symtab_hdr
->sh_info
;
3278 end_local_got
= local_got
+ locsymcount
;
3280 srel
= htab
->elf
.srelgot
;
3281 for (; local_got
< end_local_got
;
3282 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3286 *local_got
= s
->size
;
3289 if (info
->shared
|| elf32_tic6x_using_dsbt (output_bfd
))
3291 srel
->size
+= sizeof (Elf32_External_Rela
);
3295 *local_got
= (bfd_vma
) -1;
3299 /* Allocate global sym .plt and .got entries, and space for global
3300 sym dynamic relocs. */
3301 elf_link_hash_traverse (&htab
->elf
, elf32_tic6x_allocate_dynrelocs
, info
);
3303 /* We now have determined the sizes of the various dynamic sections.
3304 Allocate memory for them. */
3306 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3308 bfd_boolean strip_section
= TRUE
;
3310 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3313 if (s
== htab
->dsbt
)
3314 s
->size
= 4 * htab
->params
.dsbt_size
;
3315 else if (s
== htab
->elf
.splt
3316 || s
== htab
->elf
.sgot
3317 || s
== htab
->elf
.sgotplt
3318 || s
== htab
->sdynbss
)
3320 /* Strip this section if we don't need it; see the
3322 /* We'd like to strip these sections if they aren't needed, but if
3323 we've exported dynamic symbols from them we must leave them.
3324 It's too late to tell BFD to get rid of the symbols. */
3326 if (htab
->elf
.hplt
!= NULL
)
3327 strip_section
= FALSE
;
3329 /* Round up the size of the PLT section to a multiple of 32. */
3330 if (s
== htab
->elf
.splt
&& s
->size
> 0)
3331 s
->size
= (s
->size
+ 31) & ~(bfd_vma
)31;
3333 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3336 && s
!= htab
->elf
.srelplt
)
3339 /* We use the reloc_count field as a counter if we need
3340 to copy relocs into the output file. */
3345 /* It's not one of our sections, so don't allocate space. */
3351 /* If we don't need this section, strip it from the
3352 output file. This is mostly to handle .rel.bss and
3353 .rel.plt. We must create both sections in
3354 create_dynamic_sections, because they must be created
3355 before the linker maps input sections to output
3356 sections. The linker does that before
3357 adjust_dynamic_symbol is called, and it is that
3358 function which decides whether anything needs to go
3359 into these sections. */
3361 s
->flags
|= SEC_EXCLUDE
;
3365 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3368 /* Allocate memory for the section contents. We use bfd_zalloc
3369 here in case unused entries are not reclaimed before the
3370 section's contents are written out. This should not happen,
3371 but this way if it does, we get a R_C6000_NONE reloc instead
3373 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3374 if (s
->contents
== NULL
)
3378 if (htab
->elf
.dynamic_sections_created
)
3380 /* Add some entries to the .dynamic section. We fill in the
3381 values later, in elf32_tic6x_finish_dynamic_sections, but we
3382 must add the entries now so that we get the correct size for
3383 the .dynamic section. The DT_DEBUG entry is filled in by the
3384 dynamic linker and used by the debugger. */
3385 #define add_dynamic_entry(TAG, VAL) \
3386 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3388 if (info
->executable
)
3390 if (!add_dynamic_entry (DT_DEBUG
, 0))
3394 if (!add_dynamic_entry (DT_C6000_DSBT_BASE
, 0)
3395 || !add_dynamic_entry (DT_C6000_DSBT_SIZE
, htab
->params
.dsbt_size
)
3396 || !add_dynamic_entry (DT_C6000_DSBT_INDEX
,
3397 htab
->params
.dsbt_index
))
3400 if (htab
->elf
.splt
->size
!= 0)
3402 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3403 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3404 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3405 || !add_dynamic_entry (DT_JMPREL
, 0))
3411 if (!add_dynamic_entry (DT_RELA
, 0)
3412 || !add_dynamic_entry (DT_RELASZ
, 0)
3413 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3416 /* If any dynamic relocs apply to a read-only section,
3417 then we need a DT_TEXTREL entry. */
3418 if ((info
->flags
& DF_TEXTREL
) == 0)
3419 elf_link_hash_traverse (&htab
->elf
,
3420 elf32_tic6x_readonly_dynrelocs
, info
);
3422 if ((info
->flags
& DF_TEXTREL
) != 0)
3424 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3429 #undef add_dynamic_entry
3434 /* This function is called after all the input files have been read,
3435 and the input sections have been assigned to output sections. */
3438 elf32_tic6x_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3440 if (elf32_tic6x_using_dsbt (output_bfd
) && !info
->relocatable
)
3442 struct elf_link_hash_entry
*h
;
3444 /* Force a PT_GNU_STACK segment to be created. */
3445 if (! elf_tdata (output_bfd
)->stack_flags
)
3446 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
3448 /* Define __stacksize if it's not defined yet. */
3449 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3450 FALSE
, FALSE
, FALSE
);
3451 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
3452 || h
->type
!= STT_OBJECT
3455 struct bfd_link_hash_entry
*bh
= NULL
;
3457 if (!(_bfd_generic_link_add_one_symbol
3458 (info
, output_bfd
, "__stacksize",
3459 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
3460 (const char *) NULL
, FALSE
,
3461 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
3464 h
= (struct elf_link_hash_entry
*) bh
;
3466 h
->type
= STT_OBJECT
;
3473 elf32_tic6x_modify_program_headers (bfd
*output_bfd
,
3474 struct bfd_link_info
*info
)
3476 struct elf_obj_tdata
*tdata
= elf_tdata (output_bfd
);
3477 struct elf_segment_map
*m
;
3478 Elf_Internal_Phdr
*p
;
3480 /* objcopy and strip preserve what's already there using
3481 elf32_tic6x_copy_private_bfd_data (). */
3485 for (p
= tdata
->phdr
, m
= tdata
->segment_map
; m
!= NULL
; m
= m
->next
, p
++)
3486 if (m
->p_type
== PT_GNU_STACK
)
3491 struct elf_link_hash_entry
*h
;
3493 /* Obtain the pointer to the __stacksize symbol. */
3494 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3495 FALSE
, FALSE
, FALSE
);
3498 while (h
->root
.type
== bfd_link_hash_indirect
3499 || h
->root
.type
== bfd_link_hash_warning
)
3500 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3501 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
3504 /* Set the header p_memsz from the symbol value. We
3505 intentionally ignore the symbol section. */
3506 if (h
&& h
->root
.type
== bfd_link_hash_defined
)
3507 p
->p_memsz
= h
->root
.u
.def
.value
;
3509 p
->p_memsz
= DEFAULT_STACK_SIZE
;
3518 elf32_tic6x_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3519 struct bfd_link_info
*info
)
3521 struct elf32_tic6x_link_hash_table
*htab
;
3525 htab
= elf32_tic6x_hash_table (info
);
3526 dynobj
= htab
->elf
.dynobj
;
3527 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3529 if (elf_hash_table (info
)->dynamic_sections_created
)
3531 Elf32_External_Dyn
* dyncon
;
3532 Elf32_External_Dyn
* dynconend
;
3534 BFD_ASSERT (sdyn
!= NULL
);
3536 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3537 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3539 for (; dyncon
< dynconend
; dyncon
++)
3541 Elf_Internal_Dyn dyn
;
3544 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3551 case DT_C6000_DSBT_BASE
:
3553 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
);
3557 s
= htab
->elf
.sgotplt
;
3558 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3562 s
= htab
->elf
.srelplt
;
3563 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3567 s
= htab
->elf
.srelplt
;
3568 dyn
.d_un
.d_val
= s
->size
;
3571 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3574 /* Fill in the first entry in the procedure linkage table. */
3575 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
3577 bfd_vma got_offs
= (htab
->elf
.sgotplt
->output_section
->vma
3578 + htab
->elf
.sgotplt
->output_offset
3579 - htab
->dsbt
->output_section
->vma
3580 - htab
->dsbt
->output_offset
) / 4;
3582 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3583 bfd_put_32 (output_bfd
, got_offs
<< 8 | 0x0100006e,
3584 htab
->elf
.splt
->contents
);
3585 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3586 bfd_put_32 (output_bfd
, (got_offs
+ 1) << 8 | 0x0080006e,
3587 htab
->elf
.splt
->contents
+ 4);
3589 bfd_put_32 (output_bfd
, 0x00004000,
3590 htab
->elf
.splt
->contents
+ 8);
3592 bfd_put_32 (output_bfd
, 0x00080362,
3593 htab
->elf
.splt
->contents
+ 12);
3595 bfd_put_32 (output_bfd
, 0x00008000,
3596 htab
->elf
.splt
->contents
+ 16);
3598 elf_section_data (htab
->elf
.splt
->output_section
)
3599 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3606 /* Return address for Ith PLT stub in section PLT, for relocation REL
3607 or (bfd_vma) -1 if it should not be included. */
3610 elf32_tic6x_plt_sym_val (bfd_vma i
, const asection
*plt
,
3611 const arelent
*rel ATTRIBUTE_UNUSED
)
3613 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3617 elf32_tic6x_obj_attrs_arg_type (int tag
)
3619 if (tag
== Tag_ABI_compatibility
)
3620 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
3622 return ATTR_TYPE_FLAG_STR_VAL
;
3624 return ATTR_TYPE_FLAG_INT_VAL
;
3628 elf32_tic6x_obj_attrs_order (int num
)
3630 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
3631 return Tag_ABI_conformance
;
3632 if ((num
- 1) < Tag_ABI_conformance
)
3638 elf32_tic6x_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
3640 if ((tag
& 127) < 64)
3643 (_("%B: error: unknown mandatory EABI object attribute %d"),
3645 bfd_set_error (bfd_error_bad_value
);
3651 (_("%B: warning: unknown EABI object attribute %d"),
3657 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3658 and return the merged value. At present, all merges succeed, so no
3659 return value for errors is defined. */
3662 elf32_tic6x_merge_arch_attributes (int arch1
, int arch2
)
3664 int min_arch
, max_arch
;
3666 min_arch
= (arch1
< arch2
? arch1
: arch2
);
3667 max_arch
= (arch1
> arch2
? arch1
: arch2
);
3669 /* In most cases, the numerically greatest value is the correct
3670 merged value, but merging C64 and C67 results in C674X. */
3671 if ((min_arch
== C6XABI_Tag_ISA_C67X
3672 || min_arch
== C6XABI_Tag_ISA_C67XP
)
3673 && (max_arch
== C6XABI_Tag_ISA_C64X
3674 || max_arch
== C6XABI_Tag_ISA_C64XP
))
3675 return C6XABI_Tag_ISA_C674X
;
3680 /* Convert a Tag_ABI_array_object_alignment or
3681 Tag_ABI_array_object_align_expected tag value TAG to a
3682 corresponding alignment value; return the alignment, or -1 for an
3683 unknown tag value. */
3686 elf32_tic6x_tag_to_array_alignment (int tag
)
3704 /* Convert a Tag_ABI_array_object_alignment or
3705 Tag_ABI_array_object_align_expected alignment ALIGN to a
3706 corresponding tag value; return the tag value. */
3709 elf32_tic6x_array_alignment_to_tag (int align
)
3727 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3728 succeeded, FALSE otherwise. */
3731 elf32_tic6x_merge_attributes (bfd
*ibfd
, bfd
*obfd
)
3733 bfd_boolean result
= TRUE
;
3734 obj_attribute
*in_attr
;
3735 obj_attribute
*out_attr
;
3737 int array_align_in
, array_align_out
, array_expect_in
, array_expect_out
;
3739 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
3741 /* This is the first object. Copy the attributes. */
3742 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
3744 out_attr
= elf_known_obj_attributes_proc (obfd
);
3746 /* Use the Tag_null value to indicate the attributes have been
3753 in_attr
= elf_known_obj_attributes_proc (ibfd
);
3754 out_attr
= elf_known_obj_attributes_proc (obfd
);
3756 /* No specification yet for handling of unknown attributes, so just
3757 ignore them and handle known ones. */
3759 if (out_attr
[Tag_ABI_stack_align_preserved
].i
3760 < in_attr
[Tag_ABI_stack_align_needed
].i
)
3763 (_("error: %B requires more stack alignment than %B preserves"),
3767 if (in_attr
[Tag_ABI_stack_align_preserved
].i
3768 < out_attr
[Tag_ABI_stack_align_needed
].i
)
3771 (_("error: %B requires more stack alignment than %B preserves"),
3776 array_align_in
= elf32_tic6x_tag_to_array_alignment
3777 (in_attr
[Tag_ABI_array_object_alignment
].i
);
3778 if (array_align_in
== -1)
3781 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3785 array_align_out
= elf32_tic6x_tag_to_array_alignment
3786 (out_attr
[Tag_ABI_array_object_alignment
].i
);
3787 if (array_align_out
== -1)
3790 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3794 array_expect_in
= elf32_tic6x_tag_to_array_alignment
3795 (in_attr
[Tag_ABI_array_object_align_expected
].i
);
3796 if (array_expect_in
== -1)
3799 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3803 array_expect_out
= elf32_tic6x_tag_to_array_alignment
3804 (out_attr
[Tag_ABI_array_object_align_expected
].i
);
3805 if (array_expect_out
== -1)
3808 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3813 if (array_align_out
< array_expect_in
)
3816 (_("error: %B requires more array alignment than %B preserves"),
3820 if (array_align_in
< array_expect_out
)
3823 (_("error: %B requires more array alignment than %B preserves"),
3828 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
3833 out_attr
[i
].i
= elf32_tic6x_merge_arch_attributes (in_attr
[i
].i
,
3837 case Tag_ABI_wchar_t
:
3838 if (out_attr
[i
].i
== 0)
3839 out_attr
[i
].i
= in_attr
[i
].i
;
3840 if (out_attr
[i
].i
!= 0
3841 && in_attr
[i
].i
!= 0
3842 && out_attr
[i
].i
!= in_attr
[i
].i
)
3845 (_("warning: %B and %B differ in wchar_t size"), obfd
, ibfd
);
3849 case Tag_ABI_stack_align_needed
:
3850 if (out_attr
[i
].i
< in_attr
[i
].i
)
3851 out_attr
[i
].i
= in_attr
[i
].i
;
3854 case Tag_ABI_stack_align_preserved
:
3855 if (out_attr
[i
].i
> in_attr
[i
].i
)
3856 out_attr
[i
].i
= in_attr
[i
].i
;
3860 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3863 (_("warning: %B and %B differ in whether code is "
3864 "compiled for DSBT"),
3871 if (out_attr
[i
].i
> in_attr
[i
].i
)
3872 out_attr
[i
].i
= in_attr
[i
].i
;
3875 case Tag_ABI_array_object_alignment
:
3876 if (array_align_out
!= -1
3877 && array_align_in
!= -1
3878 && array_align_out
> array_align_in
)
3880 = elf32_tic6x_array_alignment_to_tag (array_align_in
);
3883 case Tag_ABI_array_object_align_expected
:
3884 if (array_expect_out
!= -1
3885 && array_expect_in
!= -1
3886 && array_expect_out
< array_expect_in
)
3888 = elf32_tic6x_array_alignment_to_tag (array_expect_in
);
3891 case Tag_ABI_conformance
:
3892 /* Merging for this attribute is not specified. As on ARM,
3893 treat a missing attribute as no claim to conform and only
3894 merge identical values. */
3895 if (out_attr
[i
].s
== NULL
3896 || in_attr
[i
].s
== NULL
3897 || strcmp (out_attr
[i
].s
,
3899 out_attr
[i
].s
= NULL
;
3902 case Tag_ABI_compatibility
:
3903 /* Merged in _bfd_elf_merge_object_attributes. */
3908 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
3912 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
3913 out_attr
[i
].type
= in_attr
[i
].type
;
3916 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
3917 if (!_bfd_elf_merge_object_attributes (ibfd
, obfd
))
3920 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
3926 elf32_tic6x_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3928 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
3931 if (!elf32_tic6x_merge_attributes (ibfd
, obfd
))
3938 elf32_tic6x_copy_private_data (bfd
* ibfd
, bfd
* obfd
)
3940 _bfd_elf_copy_private_bfd_data (ibfd
, obfd
);
3942 if (! is_tic6x_elf (ibfd
) || ! is_tic6x_elf (obfd
))
3945 /* Copy the stack size. */
3946 if (elf_tdata (ibfd
)->phdr
&& elf_tdata (obfd
)->phdr
3947 && elf32_tic6x_using_dsbt (ibfd
) && elf32_tic6x_using_dsbt (obfd
))
3951 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
3952 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
3954 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
3956 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
3957 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
3959 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
3961 /* Rewrite the phdrs, since we're only called after they
3962 were first written. */
3964 (bfd_signed_vma
) get_elf_backend_data (obfd
)
3965 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
3966 || get_elf_backend_data (obfd
)->s
3967 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
3968 elf_elfheader (obfd
)->e_phnum
) != 0)
3980 #define TARGET_LITTLE_SYM bfd_elf32_tic6x_le_vec
3981 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
3982 #define TARGET_BIG_SYM bfd_elf32_tic6x_be_vec
3983 #define TARGET_BIG_NAME "elf32-tic6x-be"
3984 #define ELF_ARCH bfd_arch_tic6x
3985 #define ELF_TARGET_ID TIC6X_ELF_DATA
3986 #define ELF_MACHINE_CODE EM_TI_C6000
3987 #define ELF_MAXPAGESIZE 0x1000
3988 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
3989 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
3990 #define bfd_elf32_bfd_copy_private_bfd_data elf32_tic6x_copy_private_data
3991 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
3992 #define bfd_elf32_mkobject elf32_tic6x_mkobject
3993 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
3994 #define bfd_elf32_bfd_link_hash_table_free elf32_tic6x_link_hash_table_free
3995 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
3996 #define elf_backend_can_gc_sections 1
3997 #define elf_backend_default_use_rela_p 1
3998 #define elf_backend_may_use_rel_p 1
3999 #define elf_backend_may_use_rela_p 1
4000 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
4001 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
4002 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
4003 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
4004 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4005 #define elf_backend_obj_attrs_vendor "c6xabi"
4006 #define elf_backend_can_refcount 1
4007 #define elf_backend_want_got_plt 1
4008 #define elf_backend_want_dynbss 1
4009 #define elf_backend_plt_readonly 1
4010 #define elf_backend_rela_normal 1
4011 #define elf_backend_got_header_size 8
4012 #define elf_backend_fake_sections elf32_tic6x_fake_sections
4013 #define elf_backend_gc_sweep_hook elf32_tic6x_gc_sweep_hook
4014 #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
4015 #define elf_backend_modify_program_headers \
4016 elf32_tic6x_modify_program_headers
4017 #define elf_backend_create_dynamic_sections \
4018 elf32_tic6x_create_dynamic_sections
4019 #define elf_backend_adjust_dynamic_symbol \
4020 elf32_tic6x_adjust_dynamic_symbol
4021 #define elf_backend_check_relocs elf32_tic6x_check_relocs
4022 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4023 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4024 #define elf_backend_link_output_symbol_hook \
4025 elf32_tic6x_link_output_symbol_hook
4026 #define elf_backend_section_from_bfd_section \
4027 elf32_tic6x_section_from_bfd_section
4028 #define elf_backend_relocate_section elf32_tic6x_relocate_section
4029 #define elf_backend_finish_dynamic_symbol \
4030 elf32_tic6x_finish_dynamic_symbol
4031 #define elf_backend_always_size_sections \
4032 elf32_tic6x_always_size_sections
4033 #define elf_backend_size_dynamic_sections \
4034 elf32_tic6x_size_dynamic_sections
4035 #define elf_backend_finish_dynamic_sections \
4036 elf32_tic6x_finish_dynamic_sections
4037 #define bfd_elf32_bfd_final_link \
4038 elf32_tic6x_final_link
4039 #define elf_info_to_howto elf32_tic6x_info_to_howto
4040 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
4042 #undef elf_backend_omit_section_dynsym
4043 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4044 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4047 #include "elf32-target.h"