1 /* 32-bit ELF support for TI C6X
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
3 Contributed by Joseph Myers <joseph@codesourcery.com>
4 Bernd Schmidt <bernds@codesourcery.com>
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 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 /* C6X specific command line arguments. */
47 struct elf32_tic6x_params params
;
49 /* Small local sym cache. */
50 struct sym_cache sym_cache
;
52 /* The output BFD, for convenience. */
55 /* The .dsbt section. */
59 /* Get the TI C6X ELF linker hash table from a link_info structure. */
61 #define elf32_tic6x_hash_table(p) \
62 ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
67 INSERT_EXIDX_CANTUNWIND_AT_END
69 tic6x_unwind_edit_type
;
71 /* A (sorted) list of edits to apply to an unwind table. */
72 typedef struct tic6x_unwind_table_edit
74 tic6x_unwind_edit_type type
;
75 /* Note: we sometimes want to insert an unwind entry corresponding to a
76 section different from the one we're currently writing out, so record the
77 (text) section this edit relates to here. */
78 asection
*linked_section
;
80 struct tic6x_unwind_table_edit
*next
;
82 tic6x_unwind_table_edit
;
84 typedef struct _tic6x_elf_section_data
86 /* Information about mapping symbols. */
87 struct bfd_elf_section_data elf
;
88 /* Information about unwind tables. */
91 /* Unwind info attached to a text section. */
94 asection
*tic6x_exidx_sec
;
97 /* Unwind info attached to an .c6xabi.exidx section. */
100 tic6x_unwind_table_edit
*unwind_edit_list
;
101 tic6x_unwind_table_edit
*unwind_edit_tail
;
105 _tic6x_elf_section_data
;
107 #define elf32_tic6x_section_data(sec) \
108 ((_tic6x_elf_section_data *) elf_section_data (sec))
110 struct elf32_tic6x_obj_tdata
112 struct elf_obj_tdata root
;
114 /* Whether to use RELA relocations when generating relocations.
115 This is a per-object flag to allow the assembler to generate REL
116 relocations for use in linker testcases. */
117 bfd_boolean use_rela_p
;
120 #define elf32_tic6x_tdata(abfd) \
121 ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
123 #define is_tic6x_elf(bfd) \
124 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
125 && elf_tdata (bfd) != NULL \
126 && elf_object_id (bfd) == TIC6X_ELF_DATA)
128 /* C6X ELF uses two common sections. One is the usual one, and the
129 other is for small objects. All the small objects are kept
130 together, and then referenced via the gp pointer, which yields
131 faster assembler code. This is what we use for the small common
132 section. This approach is copied from ecoff.c. */
133 static asection tic6x_elf_scom_section
;
134 static asymbol tic6x_elf_scom_symbol
;
135 static asymbol
*tic6x_elf_scom_symbol_ptr
;
137 static reloc_howto_type elf32_tic6x_howto_table
[] =
139 HOWTO (R_C6000_NONE
, /* type */
141 3, /* size (0 = byte, 1 = short, 2 = long) */
143 FALSE
, /* pc_relative */
145 complain_overflow_dont
,/* complain_on_overflow */
146 bfd_elf_generic_reloc
, /* special_function */
147 "R_C6000_NONE", /* name */
148 FALSE
, /* partial_inplace */
151 FALSE
), /* pcrel_offset */
152 HOWTO (R_C6000_ABS32
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_dont
,/* complain_on_overflow */
159 bfd_elf_generic_reloc
, /* special_function */
160 "R_C6000_ABS32", /* name */
161 FALSE
, /* partial_inplace */
163 0xffffffff, /* dst_mask */
164 FALSE
), /* pcrel_offset */
165 HOWTO (R_C6000_ABS16
, /* type */
167 1, /* size (0 = byte, 1 = short, 2 = long) */
169 FALSE
, /* pc_relative */
171 complain_overflow_bitfield
,/* complain_on_overflow */
172 bfd_elf_generic_reloc
, /* special_function */
173 "R_C6000_ABS16", /* name */
174 FALSE
, /* partial_inplace */
176 0x0000ffff, /* dst_mask */
177 FALSE
), /* pcrel_offset */
178 HOWTO (R_C6000_ABS8
, /* type */
180 0, /* size (0 = byte, 1 = short, 2 = long) */
182 FALSE
, /* pc_relative */
184 complain_overflow_bitfield
,/* complain_on_overflow */
185 bfd_elf_generic_reloc
, /* special_function */
186 "R_C6000_ABS8", /* name */
187 FALSE
, /* partial_inplace */
189 0x000000ff, /* dst_mask */
190 FALSE
), /* pcrel_offset */
191 HOWTO (R_C6000_PCR_S21
, /* type */
193 2, /* size (0 = byte, 1 = short, 2 = long) */
195 TRUE
, /* pc_relative */
197 complain_overflow_signed
,/* complain_on_overflow */
198 bfd_elf_generic_reloc
, /* special_function */
199 "R_C6000_PCR_S21", /* name */
200 FALSE
, /* partial_inplace */
202 0x0fffff80, /* dst_mask */
203 TRUE
), /* pcrel_offset */
204 HOWTO (R_C6000_PCR_S12
, /* type */
206 2, /* size (0 = byte, 1 = short, 2 = long) */
208 TRUE
, /* pc_relative */
210 complain_overflow_signed
,/* complain_on_overflow */
211 bfd_elf_generic_reloc
, /* special_function */
212 "R_C6000_PCR_S12", /* name */
213 FALSE
, /* partial_inplace */
215 0x0fff0000, /* dst_mask */
216 TRUE
), /* pcrel_offset */
217 HOWTO (R_C6000_PCR_S10
, /* type */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
221 TRUE
, /* pc_relative */
223 complain_overflow_signed
,/* complain_on_overflow */
224 bfd_elf_generic_reloc
, /* special_function */
225 "R_C6000_PCR_S10", /* name */
226 FALSE
, /* partial_inplace */
228 0x007fe000, /* dst_mask */
229 TRUE
), /* pcrel_offset */
230 HOWTO (R_C6000_PCR_S7
, /* type */
232 2, /* size (0 = byte, 1 = short, 2 = long) */
234 TRUE
, /* pc_relative */
236 complain_overflow_signed
,/* complain_on_overflow */
237 bfd_elf_generic_reloc
, /* special_function */
238 "R_C6000_PCR_S7", /* name */
239 FALSE
, /* partial_inplace */
241 0x007f0000, /* dst_mask */
242 TRUE
), /* pcrel_offset */
243 HOWTO (R_C6000_ABS_S16
, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE
, /* pc_relative */
249 complain_overflow_signed
,/* complain_on_overflow */
250 bfd_elf_generic_reloc
, /* special_function */
251 "R_C6000_ABS_S16", /* name */
252 FALSE
, /* partial_inplace */
254 0x007fff80, /* dst_mask */
255 FALSE
), /* pcrel_offset */
256 HOWTO (R_C6000_ABS_L16
, /* type */
258 2, /* size (0 = byte, 1 = short, 2 = long) */
260 FALSE
, /* pc_relative */
262 complain_overflow_dont
,/* complain_on_overflow */
263 bfd_elf_generic_reloc
, /* special_function */
264 "R_C6000_ABS_L16", /* name */
265 FALSE
, /* partial_inplace */
267 0x007fff80, /* dst_mask */
268 FALSE
), /* pcrel_offset */
269 HOWTO (R_C6000_ABS_H16
, /* type */
271 2, /* size (0 = byte, 1 = short, 2 = long) */
273 FALSE
, /* pc_relative */
275 complain_overflow_dont
,/* complain_on_overflow */
276 bfd_elf_generic_reloc
, /* special_function */
277 "R_C6000_ABS_H16", /* name */
278 FALSE
, /* partial_inplace */
280 0x007fff80, /* dst_mask */
281 FALSE
), /* pcrel_offset */
282 HOWTO (R_C6000_SBR_U15_B
, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE
, /* pc_relative */
288 complain_overflow_unsigned
,/* complain_on_overflow */
289 bfd_elf_generic_reloc
, /* special_function */
290 "R_C6000_SBR_U15_B", /* name */
291 FALSE
, /* partial_inplace */
293 0x007fff00, /* dst_mask */
294 FALSE
), /* pcrel_offset */
295 HOWTO (R_C6000_SBR_U15_H
, /* type */
297 2, /* size (0 = byte, 1 = short, 2 = long) */
299 FALSE
, /* pc_relative */
301 complain_overflow_unsigned
,/* complain_on_overflow */
302 bfd_elf_generic_reloc
, /* special_function */
303 "R_C6000_SBR_U15_H", /* name */
304 FALSE
, /* partial_inplace */
306 0x007fff00, /* dst_mask */
307 FALSE
), /* pcrel_offset */
308 HOWTO (R_C6000_SBR_U15_W
, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 FALSE
, /* pc_relative */
314 complain_overflow_unsigned
,/* complain_on_overflow */
315 bfd_elf_generic_reloc
, /* special_function */
316 "R_C6000_SBR_U15_W", /* name */
317 FALSE
, /* partial_inplace */
319 0x007fff00, /* dst_mask */
320 FALSE
), /* pcrel_offset */
321 HOWTO (R_C6000_SBR_S16
, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 FALSE
, /* pc_relative */
327 complain_overflow_signed
,/* complain_on_overflow */
328 bfd_elf_generic_reloc
, /* special_function */
329 "R_C6000_SBR_S16", /* name */
330 FALSE
, /* partial_inplace */
332 0x007fff80, /* dst_mask */
333 FALSE
), /* pcrel_offset */
334 HOWTO (R_C6000_SBR_L16_B
, /* type */
336 2, /* size (0 = byte, 1 = short, 2 = long) */
338 FALSE
, /* pc_relative */
340 complain_overflow_dont
,/* complain_on_overflow */
341 bfd_elf_generic_reloc
, /* special_function */
342 "R_C6000_SBR_L16_B", /* name */
343 FALSE
, /* partial_inplace */
345 0x007fff80, /* dst_mask */
346 FALSE
), /* pcrel_offset */
347 HOWTO (R_C6000_SBR_L16_H
, /* type */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
351 FALSE
, /* pc_relative */
353 complain_overflow_dont
,/* complain_on_overflow */
354 bfd_elf_generic_reloc
, /* special_function */
355 "R_C6000_SBR_L16_H", /* name */
356 FALSE
, /* partial_inplace */
358 0x007fff80, /* dst_mask */
359 FALSE
), /* pcrel_offset */
360 HOWTO (R_C6000_SBR_L16_W
, /* type */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
364 FALSE
, /* pc_relative */
366 complain_overflow_dont
,/* complain_on_overflow */
367 bfd_elf_generic_reloc
, /* special_function */
368 "R_C6000_SBR_L16_W", /* name */
369 FALSE
, /* partial_inplace */
371 0x007fff80, /* dst_mask */
372 FALSE
), /* pcrel_offset */
373 HOWTO (R_C6000_SBR_H16_B
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE
, /* pc_relative */
379 complain_overflow_dont
,/* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 "R_C6000_SBR_H16_B", /* name */
382 FALSE
, /* partial_inplace */
384 0x007fff80, /* dst_mask */
385 FALSE
), /* pcrel_offset */
386 HOWTO (R_C6000_SBR_H16_H
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_dont
,/* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_C6000_SBR_H16_H", /* name */
395 FALSE
, /* partial_inplace */
397 0x007fff80, /* dst_mask */
398 FALSE
), /* pcrel_offset */
399 HOWTO (R_C6000_SBR_H16_W
, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 FALSE
, /* pc_relative */
405 complain_overflow_dont
,/* complain_on_overflow */
406 bfd_elf_generic_reloc
, /* special_function */
407 "R_C6000_SBR_H16_W", /* name */
408 FALSE
, /* partial_inplace */
410 0x007fff80, /* dst_mask */
411 FALSE
), /* pcrel_offset */
412 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE
, /* pc_relative */
418 complain_overflow_unsigned
,/* complain_on_overflow */
419 bfd_elf_generic_reloc
, /* special_function */
420 "R_C6000_SBR_GOT_U15_W",/* name */
421 FALSE
, /* partial_inplace */
423 0x007fff00, /* dst_mask */
424 FALSE
), /* pcrel_offset */
425 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
427 2, /* size (0 = byte, 1 = short, 2 = long) */
429 FALSE
, /* pc_relative */
431 complain_overflow_dont
,/* complain_on_overflow */
432 bfd_elf_generic_reloc
, /* special_function */
433 "R_C6000_SBR_GOT_L16_W",/* name */
434 FALSE
, /* partial_inplace */
436 0x007fff80, /* dst_mask */
437 FALSE
), /* pcrel_offset */
438 HOWTO (R_C6000_SBR_GOT_H16_W
, /* type */
440 2, /* size (0 = byte, 1 = short, 2 = long) */
442 FALSE
, /* pc_relative */
444 complain_overflow_dont
,/* complain_on_overflow */
445 bfd_elf_generic_reloc
, /* special_function */
446 "R_C6000_SBR_GOT_H16_W",/* name */
447 FALSE
, /* partial_inplace */
449 0x007fff80, /* dst_mask */
450 FALSE
), /* pcrel_offset */
451 HOWTO (R_C6000_DSBT_INDEX
, /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 FALSE
, /* pc_relative */
457 complain_overflow_unsigned
,/* complain_on_overflow */
458 bfd_elf_generic_reloc
, /* special_function */
459 "R_C6000_DSBT_INDEX", /* name */
460 FALSE
, /* partial_inplace */
462 0x007fff00, /* dst_mask */
463 FALSE
), /* pcrel_offset */
464 HOWTO (R_C6000_PREL31
, /* type */
466 2, /* size (0 = byte, 1 = short, 2 = long) */
468 TRUE
, /* pc_relative */
470 complain_overflow_dont
,/* complain_on_overflow */
471 bfd_elf_generic_reloc
, /* special_function */
472 "R_C6000_PREL31", /* name */
473 FALSE
, /* partial_inplace */
475 0x7fffffff, /* dst_mask */
476 TRUE
), /* pcrel_offset */
477 HOWTO (R_C6000_COPY
, /* type */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
481 FALSE
, /* pc_relative */
483 complain_overflow_dont
,/* complain_on_overflow */
484 bfd_elf_generic_reloc
, /* special_function */
485 "R_C6000_COPY", /* name */
486 FALSE
, /* partial_inplace */
488 0xffffffff, /* dst_mask */
489 FALSE
), /* pcrel_offset */
490 HOWTO (R_C6000_JUMP_SLOT
, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 FALSE
, /* pc_relative */
496 complain_overflow_dont
,/* complain_on_overflow */
497 bfd_elf_generic_reloc
, /* special_function */
498 "R_C6000_JUMP_SLOT", /* name */
499 FALSE
, /* partial_inplace */
501 0xffffffff, /* dst_mask */
502 FALSE
), /* pcrel_offset */
503 HOWTO (R_C6000_EHTYPE
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 FALSE
, /* pc_relative */
509 complain_overflow_dont
,/* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 "R_C6000_EHTYPE", /* name */
512 FALSE
, /* partial_inplace */
514 0xffffffff, /* dst_mask */
515 FALSE
), /* pcrel_offset */
516 HOWTO (R_C6000_PCR_H16
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 TRUE
, /* pc_relative */
522 complain_overflow_dont
,/* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_C6000_PCR_H16", /* name */
525 FALSE
, /* partial_inplace */
527 0x007fff80, /* dst_mask */
528 TRUE
), /* pcrel_offset */
529 HOWTO (R_C6000_PCR_L16
, /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 TRUE
, /* pc_relative */
535 complain_overflow_dont
,/* complain_on_overflow */
536 bfd_elf_generic_reloc
, /* special_function */
537 "R_C6000_PCR_L16", /* name */
538 FALSE
, /* partial_inplace */
540 0x007fff80, /* dst_mask */
541 TRUE
), /* pcrel_offset */
764 HOWTO (R_C6000_ALIGN
, /* type */
766 0, /* 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_ALIGN", /* name */
773 FALSE
, /* partial_inplace */
776 FALSE
), /* pcrel_offset */
777 HOWTO (R_C6000_FPHEAD
, /* type */
779 0, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE
, /* pc_relative */
783 complain_overflow_dont
,/* complain_on_overflow */
784 bfd_elf_generic_reloc
, /* special_function */
785 "R_C6000_FPHEAD", /* name */
786 FALSE
, /* partial_inplace */
789 FALSE
), /* pcrel_offset */
790 HOWTO (R_C6000_NOCMP
, /* type */
792 0, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE
, /* pc_relative */
796 complain_overflow_dont
,/* complain_on_overflow */
797 bfd_elf_generic_reloc
, /* special_function */
798 "R_C6000_NOCMP", /* name */
799 FALSE
, /* partial_inplace */
802 FALSE
) /* pcrel_offset */
805 static reloc_howto_type elf32_tic6x_howto_table_rel
[] =
807 HOWTO (R_C6000_NONE
, /* type */
809 3, /* size (0 = byte, 1 = short, 2 = long) */
811 FALSE
, /* pc_relative */
813 complain_overflow_dont
,/* complain_on_overflow */
814 bfd_elf_generic_reloc
, /* special_function */
815 "R_C6000_NONE", /* name */
816 TRUE
, /* partial_inplace */
819 FALSE
), /* pcrel_offset */
820 HOWTO (R_C6000_ABS32
, /* type */
822 2, /* size (0 = byte, 1 = short, 2 = long) */
824 FALSE
, /* pc_relative */
826 complain_overflow_dont
,/* complain_on_overflow */
827 bfd_elf_generic_reloc
, /* special_function */
828 "R_C6000_ABS32", /* name */
829 TRUE
, /* partial_inplace */
830 0xffffffff, /* src_mask */
831 0xffffffff, /* dst_mask */
832 FALSE
), /* pcrel_offset */
833 HOWTO (R_C6000_ABS16
, /* type */
835 1, /* size (0 = byte, 1 = short, 2 = long) */
837 FALSE
, /* pc_relative */
839 complain_overflow_bitfield
,/* complain_on_overflow */
840 bfd_elf_generic_reloc
, /* special_function */
841 "R_C6000_ABS16", /* name */
842 TRUE
, /* partial_inplace */
843 0x0000ffff, /* src_mask */
844 0x0000ffff, /* dst_mask */
845 FALSE
), /* pcrel_offset */
846 HOWTO (R_C6000_ABS8
, /* type */
848 0, /* size (0 = byte, 1 = short, 2 = long) */
850 FALSE
, /* pc_relative */
852 complain_overflow_bitfield
,/* complain_on_overflow */
853 bfd_elf_generic_reloc
, /* special_function */
854 "R_C6000_ABS8", /* name */
855 TRUE
, /* partial_inplace */
856 0x000000ff, /* src_mask */
857 0x000000ff, /* dst_mask */
858 FALSE
), /* pcrel_offset */
859 HOWTO (R_C6000_PCR_S21
, /* type */
861 2, /* size (0 = byte, 1 = short, 2 = long) */
863 TRUE
, /* pc_relative */
865 complain_overflow_signed
,/* complain_on_overflow */
866 bfd_elf_generic_reloc
, /* special_function */
867 "R_C6000_PCR_S21", /* name */
868 TRUE
, /* partial_inplace */
869 0x0fffff80, /* src_mask */
870 0x0fffff80, /* dst_mask */
871 TRUE
), /* pcrel_offset */
872 HOWTO (R_C6000_PCR_S12
, /* type */
874 2, /* size (0 = byte, 1 = short, 2 = long) */
876 TRUE
, /* pc_relative */
878 complain_overflow_signed
,/* complain_on_overflow */
879 bfd_elf_generic_reloc
, /* special_function */
880 "R_C6000_PCR_S12", /* name */
881 TRUE
, /* partial_inplace */
882 0x0fff0000, /* src_mask */
883 0x0fff0000, /* dst_mask */
884 TRUE
), /* pcrel_offset */
885 HOWTO (R_C6000_PCR_S10
, /* type */
887 2, /* size (0 = byte, 1 = short, 2 = long) */
889 TRUE
, /* pc_relative */
891 complain_overflow_signed
,/* complain_on_overflow */
892 bfd_elf_generic_reloc
, /* special_function */
893 "R_C6000_PCR_S10", /* name */
894 TRUE
, /* partial_inplace */
895 0x007fe000, /* src_mask */
896 0x007fe000, /* dst_mask */
897 TRUE
), /* pcrel_offset */
898 HOWTO (R_C6000_PCR_S7
, /* type */
900 2, /* size (0 = byte, 1 = short, 2 = long) */
902 TRUE
, /* pc_relative */
904 complain_overflow_signed
,/* complain_on_overflow */
905 bfd_elf_generic_reloc
, /* special_function */
906 "R_C6000_PCR_S7", /* name */
907 TRUE
, /* partial_inplace */
908 0x007f0000, /* src_mask */
909 0x007f0000, /* dst_mask */
910 TRUE
), /* pcrel_offset */
911 HOWTO (R_C6000_ABS_S16
, /* type */
913 2, /* size (0 = byte, 1 = short, 2 = long) */
915 FALSE
, /* pc_relative */
917 complain_overflow_signed
,/* complain_on_overflow */
918 bfd_elf_generic_reloc
, /* special_function */
919 "R_C6000_ABS_S16", /* name */
920 TRUE
, /* partial_inplace */
921 0x007fff80, /* src_mask */
922 0x007fff80, /* dst_mask */
923 FALSE
), /* pcrel_offset */
924 HOWTO (R_C6000_ABS_L16
, /* type */
926 2, /* size (0 = byte, 1 = short, 2 = long) */
928 FALSE
, /* pc_relative */
930 complain_overflow_dont
,/* complain_on_overflow */
931 bfd_elf_generic_reloc
, /* special_function */
932 "R_C6000_ABS_L16", /* name */
933 TRUE
, /* partial_inplace */
934 0x007fff80, /* src_mask */
935 0x007fff80, /* dst_mask */
936 FALSE
), /* pcrel_offset */
937 EMPTY_HOWTO (R_C6000_ABS_H16
),
938 HOWTO (R_C6000_SBR_U15_B
, /* type */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_unsigned
,/* complain_on_overflow */
945 bfd_elf_generic_reloc
, /* special_function */
946 "R_C6000_SBR_U15_B", /* name */
947 TRUE
, /* partial_inplace */
948 0x007fff00, /* src_mask */
949 0x007fff00, /* dst_mask */
950 FALSE
), /* pcrel_offset */
951 HOWTO (R_C6000_SBR_U15_H
, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE
, /* pc_relative */
957 complain_overflow_unsigned
,/* complain_on_overflow */
958 bfd_elf_generic_reloc
, /* special_function */
959 "R_C6000_SBR_U15_H", /* name */
960 TRUE
, /* partial_inplace */
961 0x007fff00, /* src_mask */
962 0x007fff00, /* dst_mask */
963 FALSE
), /* pcrel_offset */
964 HOWTO (R_C6000_SBR_U15_W
, /* type */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE
, /* pc_relative */
970 complain_overflow_unsigned
,/* complain_on_overflow */
971 bfd_elf_generic_reloc
, /* special_function */
972 "R_C6000_SBR_U15_W", /* name */
973 TRUE
, /* partial_inplace */
974 0x007fff00, /* src_mask */
975 0x007fff00, /* dst_mask */
976 FALSE
), /* pcrel_offset */
977 HOWTO (R_C6000_SBR_S16
, /* type */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
981 FALSE
, /* pc_relative */
983 complain_overflow_signed
,/* complain_on_overflow */
984 bfd_elf_generic_reloc
, /* special_function */
985 "R_C6000_SBR_S16", /* name */
986 TRUE
, /* partial_inplace */
987 0x007fff80, /* src_mask */
988 0x007fff80, /* dst_mask */
989 FALSE
), /* pcrel_offset */
990 HOWTO (R_C6000_SBR_L16_B
, /* type */
992 2, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE
, /* pc_relative */
996 complain_overflow_dont
,/* complain_on_overflow */
997 bfd_elf_generic_reloc
, /* special_function */
998 "R_C6000_SBR_L16_B", /* name */
999 TRUE
, /* partial_inplace */
1000 0x007fff80, /* src_mask */
1001 0x007fff80, /* dst_mask */
1002 FALSE
), /* pcrel_offset */
1003 HOWTO (R_C6000_SBR_L16_H
, /* type */
1005 2, /* size (0 = byte, 1 = short, 2 = long) */
1007 FALSE
, /* pc_relative */
1009 complain_overflow_dont
,/* complain_on_overflow */
1010 bfd_elf_generic_reloc
, /* special_function */
1011 "R_C6000_SBR_L16_H", /* name */
1012 TRUE
, /* partial_inplace */
1013 0x007fff80, /* src_mask */
1014 0x007fff80, /* dst_mask */
1015 FALSE
), /* pcrel_offset */
1016 HOWTO (R_C6000_SBR_L16_W
, /* type */
1018 2, /* size (0 = byte, 1 = short, 2 = long) */
1020 FALSE
, /* pc_relative */
1022 complain_overflow_dont
,/* complain_on_overflow */
1023 bfd_elf_generic_reloc
, /* special_function */
1024 "R_C6000_SBR_L16_W", /* name */
1025 TRUE
, /* partial_inplace */
1026 0x007fff80, /* src_mask */
1027 0x007fff80, /* dst_mask */
1028 FALSE
), /* pcrel_offset */
1029 EMPTY_HOWTO (R_C6000_SBR_H16_B
),
1030 EMPTY_HOWTO (R_C6000_SBR_H16_H
),
1031 EMPTY_HOWTO (R_C6000_SBR_H16_W
),
1032 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 FALSE
, /* pc_relative */
1038 complain_overflow_unsigned
,/* complain_on_overflow */
1039 bfd_elf_generic_reloc
, /* special_function */
1040 "R_C6000_SBR_GOT_U15_W",/* name */
1041 TRUE
, /* partial_inplace */
1042 0x007fff00, /* src_mask */
1043 0x007fff00, /* dst_mask */
1044 FALSE
), /* pcrel_offset */
1045 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 FALSE
, /* pc_relative */
1051 complain_overflow_dont
,/* complain_on_overflow */
1052 bfd_elf_generic_reloc
, /* special_function */
1053 "R_C6000_SBR_GOT_L16_W",/* name */
1054 TRUE
, /* partial_inplace */
1055 0x007fff80, /* src_mask */
1056 0x007fff80, /* dst_mask */
1057 FALSE
), /* pcrel_offset */
1058 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W
),
1059 HOWTO (R_C6000_DSBT_INDEX
, /* type */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE
, /* pc_relative */
1065 complain_overflow_unsigned
,/* complain_on_overflow */
1066 bfd_elf_generic_reloc
, /* special_function */
1067 "R_C6000_DSBT_INDEX", /* name */
1068 TRUE
, /* partial_inplace */
1070 0x007fff00, /* dst_mask */
1071 FALSE
), /* pcrel_offset */
1072 HOWTO (R_C6000_PREL31
, /* type */
1074 2, /* size (0 = byte, 1 = short, 2 = long) */
1076 TRUE
, /* pc_relative */
1078 complain_overflow_dont
,/* complain_on_overflow */
1079 bfd_elf_generic_reloc
, /* special_function */
1080 "R_C6000_PREL31", /* name */
1081 TRUE
, /* partial_inplace */
1083 0x7fffffff, /* dst_mask */
1084 TRUE
), /* pcrel_offset */
1085 HOWTO (R_C6000_COPY
, /* type */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1089 FALSE
, /* pc_relative */
1091 complain_overflow_dont
,/* complain_on_overflow */
1092 bfd_elf_generic_reloc
, /* special_function */
1093 "R_C6000_COPY", /* name */
1094 TRUE
, /* partial_inplace */
1096 0xffffffff, /* dst_mask */
1097 FALSE
), /* pcrel_offset */
1098 HOWTO (R_C6000_JUMP_SLOT
, /* type */
1100 2, /* size (0 = byte, 1 = short, 2 = long) */
1102 FALSE
, /* pc_relative */
1104 complain_overflow_dont
,/* complain_on_overflow */
1105 bfd_elf_generic_reloc
, /* special_function */
1106 "R_C6000_JUMP_SLOT", /* name */
1107 FALSE
, /* partial_inplace */
1109 0xffffffff, /* dst_mask */
1110 FALSE
), /* pcrel_offset */
1111 HOWTO (R_C6000_EHTYPE
, /* type */
1113 2, /* size (0 = byte, 1 = short, 2 = long) */
1115 FALSE
, /* pc_relative */
1117 complain_overflow_dont
,/* complain_on_overflow */
1118 bfd_elf_generic_reloc
, /* special_function */
1119 "R_C6000_EHTYPE", /* name */
1120 FALSE
, /* partial_inplace */
1122 0xffffffff, /* dst_mask */
1123 FALSE
), /* pcrel_offset */
1124 EMPTY_HOWTO (R_C6000_PCR_H16
),
1125 EMPTY_HOWTO (R_C6000_PCR_L16
),
1348 HOWTO (R_C6000_ALIGN
, /* type */
1350 0, /* size (0 = byte, 1 = short, 2 = long) */
1352 FALSE
, /* pc_relative */
1354 complain_overflow_dont
,/* complain_on_overflow */
1355 bfd_elf_generic_reloc
, /* special_function */
1356 "R_C6000_ALIGN", /* name */
1357 TRUE
, /* partial_inplace */
1360 FALSE
), /* pcrel_offset */
1361 HOWTO (R_C6000_FPHEAD
, /* type */
1363 0, /* size (0 = byte, 1 = short, 2 = long) */
1365 FALSE
, /* pc_relative */
1367 complain_overflow_dont
,/* complain_on_overflow */
1368 bfd_elf_generic_reloc
, /* special_function */
1369 "R_C6000_FPHEAD", /* name */
1370 TRUE
, /* partial_inplace */
1373 FALSE
), /* pcrel_offset */
1374 HOWTO (R_C6000_NOCMP
, /* type */
1376 0, /* size (0 = byte, 1 = short, 2 = long) */
1378 FALSE
, /* pc_relative */
1380 complain_overflow_dont
,/* complain_on_overflow */
1381 bfd_elf_generic_reloc
, /* special_function */
1382 "R_C6000_NOCMP", /* name */
1383 TRUE
, /* partial_inplace */
1386 FALSE
) /* pcrel_offset */
1389 /* Map BFD relocations to ELF relocations. */
1393 bfd_reloc_code_real_type bfd_reloc_val
;
1394 enum elf_tic6x_reloc_type elf_reloc_val
;
1397 static const tic6x_reloc_map elf32_tic6x_reloc_map
[] =
1399 { BFD_RELOC_NONE
, R_C6000_NONE
},
1400 { BFD_RELOC_32
, R_C6000_ABS32
},
1401 { BFD_RELOC_16
, R_C6000_ABS16
},
1402 { BFD_RELOC_8
, R_C6000_ABS8
},
1403 { BFD_RELOC_C6000_PCR_S21
, R_C6000_PCR_S21
},
1404 { BFD_RELOC_C6000_PCR_S12
, R_C6000_PCR_S12
},
1405 { BFD_RELOC_C6000_PCR_S10
, R_C6000_PCR_S10
},
1406 { BFD_RELOC_C6000_PCR_S7
, R_C6000_PCR_S7
},
1407 { BFD_RELOC_C6000_ABS_S16
, R_C6000_ABS_S16
},
1408 { BFD_RELOC_C6000_ABS_L16
, R_C6000_ABS_L16
},
1409 { BFD_RELOC_C6000_ABS_H16
, R_C6000_ABS_H16
},
1410 { BFD_RELOC_C6000_SBR_U15_B
, R_C6000_SBR_U15_B
},
1411 { BFD_RELOC_C6000_SBR_U15_H
, R_C6000_SBR_U15_H
},
1412 { BFD_RELOC_C6000_SBR_U15_W
, R_C6000_SBR_U15_W
},
1413 { BFD_RELOC_C6000_SBR_S16
, R_C6000_SBR_S16
},
1414 { BFD_RELOC_C6000_SBR_L16_B
, R_C6000_SBR_L16_B
},
1415 { BFD_RELOC_C6000_SBR_L16_H
, R_C6000_SBR_L16_H
},
1416 { BFD_RELOC_C6000_SBR_L16_W
, R_C6000_SBR_L16_W
},
1417 { BFD_RELOC_C6000_SBR_H16_B
, R_C6000_SBR_H16_B
},
1418 { BFD_RELOC_C6000_SBR_H16_H
, R_C6000_SBR_H16_H
},
1419 { BFD_RELOC_C6000_SBR_H16_W
, R_C6000_SBR_H16_W
},
1420 { BFD_RELOC_C6000_SBR_GOT_U15_W
, R_C6000_SBR_GOT_U15_W
},
1421 { BFD_RELOC_C6000_SBR_GOT_L16_W
, R_C6000_SBR_GOT_L16_W
},
1422 { BFD_RELOC_C6000_SBR_GOT_H16_W
, R_C6000_SBR_GOT_H16_W
},
1423 { BFD_RELOC_C6000_DSBT_INDEX
, R_C6000_DSBT_INDEX
},
1424 { BFD_RELOC_C6000_PREL31
, R_C6000_PREL31
},
1425 { BFD_RELOC_C6000_COPY
, R_C6000_COPY
},
1426 { BFD_RELOC_C6000_JUMP_SLOT
, R_C6000_JUMP_SLOT
},
1427 { BFD_RELOC_C6000_EHTYPE
, R_C6000_EHTYPE
},
1428 { BFD_RELOC_C6000_PCR_H16
, R_C6000_PCR_H16
},
1429 { BFD_RELOC_C6000_PCR_L16
, R_C6000_PCR_L16
},
1430 { BFD_RELOC_C6000_ALIGN
, R_C6000_ALIGN
},
1431 { BFD_RELOC_C6000_FPHEAD
, R_C6000_FPHEAD
},
1432 { BFD_RELOC_C6000_NOCMP
, R_C6000_NOCMP
}
1435 static reloc_howto_type
*
1436 elf32_tic6x_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1440 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_reloc_map
); i
++)
1441 if (elf32_tic6x_reloc_map
[i
].bfd_reloc_val
== code
)
1443 enum elf_tic6x_reloc_type elf_reloc_val
;
1444 reloc_howto_type
*howto
;
1446 elf_reloc_val
= elf32_tic6x_reloc_map
[i
].elf_reloc_val
;
1447 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1448 howto
= &elf32_tic6x_howto_table
[elf_reloc_val
];
1450 howto
= &elf32_tic6x_howto_table_rel
[elf_reloc_val
];
1452 /* Some relocations are RELA-only; do not return them for
1454 if (howto
->name
== NULL
)
1463 static reloc_howto_type
*
1464 elf32_tic6x_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1466 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1470 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table
); i
++)
1471 if (elf32_tic6x_howto_table
[i
].name
!= NULL
1472 && strcasecmp (elf32_tic6x_howto_table
[i
].name
, r_name
) == 0)
1473 return &elf32_tic6x_howto_table
[i
];
1479 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table_rel
); i
++)
1480 if (elf32_tic6x_howto_table_rel
[i
].name
!= NULL
1481 && strcasecmp (elf32_tic6x_howto_table_rel
[i
].name
, r_name
) == 0)
1482 return &elf32_tic6x_howto_table_rel
[i
];
1489 elf32_tic6x_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1490 Elf_Internal_Rela
*elf_reloc
)
1492 unsigned int r_type
;
1494 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1495 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table
))
1497 /* xgettext:c-format */
1498 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1500 bfd_set_error (bfd_error_bad_value
);
1504 bfd_reloc
->howto
= &elf32_tic6x_howto_table
[r_type
];
1505 if (bfd_reloc
->howto
== NULL
|| bfd_reloc
->howto
->name
== NULL
)
1507 /* xgettext:c-format */
1508 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1510 bfd_set_error (bfd_error_bad_value
);
1518 elf32_tic6x_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1519 Elf_Internal_Rela
*elf_reloc
)
1521 unsigned int r_type
;
1523 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1524 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table_rel
))
1526 /* xgettext:c-format */
1527 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1529 bfd_set_error (bfd_error_bad_value
);
1533 bfd_reloc
->howto
= &elf32_tic6x_howto_table_rel
[r_type
];
1534 if (bfd_reloc
->howto
== NULL
|| bfd_reloc
->howto
->name
== NULL
)
1536 /* xgettext:c-format */
1537 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1539 bfd_set_error (bfd_error_bad_value
);
1547 elf32_tic6x_set_use_rela_p (bfd
*abfd
, bfd_boolean use_rela_p
)
1549 elf32_tic6x_tdata (abfd
)->use_rela_p
= use_rela_p
;
1552 /* Create a C6X ELF linker hash table. */
1554 static struct bfd_link_hash_table
*
1555 elf32_tic6x_link_hash_table_create (bfd
*abfd
)
1557 struct elf32_tic6x_link_hash_table
*ret
;
1558 size_t amt
= sizeof (struct elf32_tic6x_link_hash_table
);
1560 ret
= bfd_zmalloc (amt
);
1564 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1565 _bfd_elf_link_hash_newfunc
,
1566 sizeof (struct elf_link_hash_entry
),
1574 ret
->elf
.is_relocatable_executable
= 1;
1576 return &ret
->elf
.root
;
1580 elf32_tic6x_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
1582 if (bfd_link_pic (info
))
1584 obj_attribute
*out_attr
;
1585 out_attr
= elf_known_obj_attributes_proc (abfd
);
1586 if (out_attr
[Tag_ABI_PIC
].i
== 0)
1588 _bfd_error_handler (_("warning: generating a shared library "
1589 "containing non-PIC code"));
1591 if (out_attr
[Tag_ABI_PID
].i
== 0)
1593 _bfd_error_handler (_("warning: generating a shared library "
1594 "containing non-PID code"));
1597 /* Invoke the regular ELF backend linker to do all the work. */
1598 if (!bfd_elf_final_link (abfd
, info
))
1604 /* Called to pass PARAMS to the backend. We store them in the hash table
1605 associated with INFO. */
1608 elf32_tic6x_setup (struct bfd_link_info
*info
,
1609 struct elf32_tic6x_params
*params
)
1611 struct elf32_tic6x_link_hash_table
*htab
= elf32_tic6x_hash_table (info
);
1612 htab
->params
= *params
;
1615 /* Determine if we're dealing with a DSBT object. */
1618 elf32_tic6x_using_dsbt (bfd
*abfd
)
1620 return bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
,
1624 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1625 sections in DYNOBJ, and set up shortcuts to them in our hash
1629 elf32_tic6x_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1631 struct elf32_tic6x_link_hash_table
*htab
;
1634 htab
= elf32_tic6x_hash_table (info
);
1638 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1642 flags
= (SEC_ALLOC
| SEC_LOAD
1643 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1644 htab
->dsbt
= bfd_make_section_anyway_with_flags (dynobj
, ".dsbt",
1646 if (htab
->dsbt
== NULL
1647 || !bfd_set_section_alignment (htab
->dsbt
, 2)
1648 || !bfd_set_section_alignment (htab
->elf
.splt
, 5))
1655 elf32_tic6x_mkobject (bfd
*abfd
)
1659 ret
= bfd_elf_allocate_object (abfd
, sizeof (struct elf32_tic6x_obj_tdata
),
1662 elf32_tic6x_set_use_rela_p (abfd
, TRUE
);
1666 /* Install relocation RELA into section SRELA, incrementing its
1670 elf32_tic6x_install_rela (bfd
*output_bfd
, asection
*srela
,
1671 Elf_Internal_Rela
*rela
)
1674 bfd_vma off
= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1675 loc
= srela
->contents
+ off
;
1676 BFD_ASSERT (off
< srela
->size
);
1677 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
1680 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1681 of the GOT at this offset have been initialized with the relocation. */
1684 elf32_tic6x_make_got_dynreloc (bfd
*output_bfd
,
1685 struct elf32_tic6x_link_hash_table
*htab
,
1686 asection
*sym_sec
, bfd_vma offset
)
1688 asection
*sgot
= htab
->elf
.sgot
;
1689 Elf_Internal_Rela outrel
;
1692 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
1693 outrel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
1694 if (sym_sec
&& sym_sec
->output_section
1695 && ! bfd_is_abs_section (sym_sec
->output_section
)
1696 && ! bfd_is_und_section (sym_sec
->output_section
))
1698 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
1699 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
1705 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_C6000_ABS32
);
1706 elf32_tic6x_install_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
1709 /* Finish up dynamic symbol handling. We set the contents of various
1710 dynamic sections here. */
1713 elf32_tic6x_finish_dynamic_symbol (bfd
* output_bfd
,
1714 struct bfd_link_info
*info
,
1715 struct elf_link_hash_entry
*h
,
1716 Elf_Internal_Sym
* sym
)
1718 struct elf32_tic6x_link_hash_table
*htab
;
1720 htab
= elf32_tic6x_hash_table (info
);
1722 if (h
->plt
.offset
!= (bfd_vma
) -1)
1725 bfd_vma got_section_offset
, got_dp_offset
, rela_offset
;
1726 Elf_Internal_Rela rela
;
1728 asection
*plt
, *gotplt
, *relplt
;
1729 const struct elf_backend_data
*bed
;
1731 bed
= get_elf_backend_data (output_bfd
);
1733 BFD_ASSERT (htab
->elf
.splt
!= NULL
);
1734 plt
= htab
->elf
.splt
;
1735 gotplt
= htab
->elf
.sgotplt
;
1736 relplt
= htab
->elf
.srelplt
;
1738 /* This symbol has an entry in the procedure linkage table. Set
1741 if ((h
->dynindx
== -1
1742 && !((h
->forced_local
|| bfd_link_executable (info
))
1744 && h
->type
== STT_GNU_IFUNC
))
1750 /* Get the index in the procedure linkage table which
1751 corresponds to this symbol. This is the index of this symbol
1752 in all the symbols for which we are making plt entries. The
1753 first entry in the procedure linkage table is reserved.
1755 Get the offset into the .got table of the entry that
1756 corresponds to this function. Each .got entry is 4 bytes.
1757 The first three are reserved.
1759 For static executables, we don't reserve anything. */
1761 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1762 got_section_offset
= plt_index
+ bed
->got_header_size
/ 4;
1763 got_dp_offset
= got_section_offset
+ htab
->params
.dsbt_size
;
1764 rela_offset
= plt_index
* sizeof (Elf32_External_Rela
);
1766 got_section_offset
*= 4;
1768 /* Fill in the entry in the procedure linkage table. */
1770 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1771 bfd_put_32 (output_bfd
, got_dp_offset
<< 8 | 0x0100006e,
1772 plt
->contents
+ h
->plt
.offset
);
1773 /* mvk .s2 low(rela_offset), b0 */
1774 bfd_put_32 (output_bfd
, (rela_offset
& 0xffff) << 7 | 0x0000002a,
1775 plt
->contents
+ h
->plt
.offset
+ 4);
1776 /* mvkh .s2 high(rela_offset), b0 */
1777 bfd_put_32 (output_bfd
, ((rela_offset
>> 16) & 0xffff) << 7 | 0x0000006a,
1778 plt
->contents
+ h
->plt
.offset
+ 8);
1780 bfd_put_32 (output_bfd
, 0x00002000,
1781 plt
->contents
+ h
->plt
.offset
+ 12);
1783 bfd_put_32 (output_bfd
, 0x00080362,
1784 plt
->contents
+ h
->plt
.offset
+ 16);
1786 bfd_put_32 (output_bfd
, 0x00008000,
1787 plt
->contents
+ h
->plt
.offset
+ 20);
1789 /* Fill in the entry in the global offset table. */
1790 bfd_put_32 (output_bfd
,
1791 (plt
->output_section
->vma
+ plt
->output_offset
),
1792 gotplt
->contents
+ got_section_offset
);
1794 /* Fill in the entry in the .rel.plt section. */
1795 rela
.r_offset
= (gotplt
->output_section
->vma
1796 + gotplt
->output_offset
1797 + got_section_offset
);
1798 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_JUMP_SLOT
);
1800 loc
= relplt
->contents
+ rela_offset
;
1801 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1803 if (!h
->def_regular
)
1805 /* Mark the symbol as undefined, rather than as defined in
1806 the .plt section. */
1807 sym
->st_shndx
= SHN_UNDEF
;
1812 if (h
->got
.offset
!= (bfd_vma
) -1)
1817 /* This symbol has an entry in the global offset table.
1820 sgot
= htab
->elf
.sgot
;
1821 srela
= htab
->elf
.srelgot
;
1822 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1824 /* If this is a -Bsymbolic link, and the symbol is defined
1825 locally, we just want to emit a RELATIVE reloc. Likewise if
1826 the symbol was forced to be local because of a version file.
1827 The entry in the global offset table will already have been
1828 initialized in the relocate_section function. */
1829 if (bfd_link_pic (info
)
1830 && (SYMBOLIC_BIND (info
, h
)
1831 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1833 asection
*s
= h
->root
.u
.def
.section
;
1834 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, s
,
1835 h
->got
.offset
& ~(bfd_vma
) 1);
1839 Elf_Internal_Rela outrel
;
1840 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1841 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1842 outrel
.r_offset
= (sgot
->output_section
->vma
1843 + sgot
->output_offset
1844 + (h
->got
.offset
& ~(bfd_vma
) 1));
1845 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_ABS32
);
1846 outrel
.r_addend
= 0;
1848 elf32_tic6x_install_rela (output_bfd
, srela
, &outrel
);
1854 Elf_Internal_Rela rel
;
1857 /* This symbol needs a copy reloc. Set it up. */
1859 if (h
->dynindx
== -1
1860 || (h
->root
.type
!= bfd_link_hash_defined
1861 && h
->root
.type
!= bfd_link_hash_defweak
)
1862 || htab
->elf
.srelbss
== NULL
1863 || htab
->elf
.sreldynrelro
== NULL
)
1866 rel
.r_offset
= (h
->root
.u
.def
.value
1867 + h
->root
.u
.def
.section
->output_section
->vma
1868 + h
->root
.u
.def
.section
->output_offset
);
1869 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_COPY
);
1871 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
1872 s
= htab
->elf
.sreldynrelro
;
1874 s
= htab
->elf
.srelbss
;
1876 elf32_tic6x_install_rela (output_bfd
, s
, &rel
);
1879 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1880 if (h
== elf_hash_table (info
)->hdynamic
1881 || h
== elf_hash_table (info
)->hgot
)
1882 sym
->st_shndx
= SHN_ABS
;
1887 /* Unwinding tables are not referenced directly. This pass marks them as
1888 required if the corresponding code section is marked. */
1891 elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info
*info
,
1892 elf_gc_mark_hook_fn gc_mark_hook
)
1895 Elf_Internal_Shdr
**elf_shdrp
;
1898 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
1900 /* Marking EH data may cause additional code sections to be marked,
1901 requiring multiple passes. */
1906 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
1910 if (! is_tic6x_elf (sub
))
1913 elf_shdrp
= elf_elfsections (sub
);
1914 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
1916 Elf_Internal_Shdr
*hdr
;
1918 hdr
= &elf_section_data (o
)->this_hdr
;
1919 if (hdr
->sh_type
== SHT_C6000_UNWIND
1921 && hdr
->sh_link
< elf_numsections (sub
)
1923 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
1926 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
1936 /* Return TRUE if this is an unwinding table index. */
1939 is_tic6x_elf_unwind_section_name (const char *name
)
1941 return (CONST_STRNEQ (name
, ELF_STRING_C6000_unwind
)
1942 || CONST_STRNEQ (name
, ELF_STRING_C6000_unwind_once
));
1946 /* Set the type and flags for an unwinding index table. We do this by
1947 the section name, which is a hack, but ought to work. */
1950 elf32_tic6x_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1951 Elf_Internal_Shdr
*hdr
, asection
*sec
)
1955 name
= bfd_section_name (sec
);
1957 if (is_tic6x_elf_unwind_section_name (name
))
1959 hdr
->sh_type
= SHT_C6000_UNWIND
;
1960 hdr
->sh_flags
|= SHF_LINK_ORDER
;
1966 /* Find dynamic relocs for H that apply to read-only sections. */
1969 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
1971 struct elf_dyn_relocs
*p
;
1973 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1975 asection
*s
= p
->sec
->output_section
;
1977 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1983 /* Adjust a symbol defined by a dynamic object and referenced by a
1984 regular object. The current definition is in some section of the
1985 dynamic object, but we're not including those sections. We have to
1986 change the definition to something the rest of the link can
1990 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1991 struct elf_link_hash_entry
*h
)
1993 struct elf32_tic6x_link_hash_table
*htab
;
1997 dynobj
= elf_hash_table (info
)->dynobj
;
1999 /* Make sure we know what is going on here. */
2000 BFD_ASSERT (dynobj
!= NULL
2003 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
2005 /* If this is a function, put it in the procedure linkage table. We
2006 will fill in the contents of the procedure linkage table later,
2007 when we know the address of the .got section. */
2008 if (h
->type
== STT_FUNC
2011 if (h
->plt
.refcount
<= 0
2012 || SYMBOL_CALLS_LOCAL (info
, h
)
2013 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2014 && h
->root
.type
== bfd_link_hash_undefweak
))
2016 /* This case can occur if we saw a PLT32 reloc in an input
2017 file, but the symbol was never referred to by a dynamic
2018 object, or if all references were garbage collected. In
2019 such a case, we don't actually need to build a procedure
2020 linkage table, and we can just do a PC32 reloc instead. */
2021 h
->plt
.offset
= (bfd_vma
) -1;
2028 /* If this is a weak symbol, and there is a real definition, the
2029 processor independent code will have arranged for us to see the
2030 real definition first, and we can just use the same value. */
2031 if (h
->is_weakalias
)
2033 struct elf_link_hash_entry
*def
= weakdef (h
);
2034 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
2035 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
2036 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
2037 h
->non_got_ref
= def
->non_got_ref
;
2041 /* This is a reference to a symbol defined by a dynamic object which
2042 is not a function. */
2044 /* If we are creating a shared library, we must presume that the
2045 only references to the symbol are via the global offset table.
2046 For such cases we need not do anything here; the relocations will
2047 be handled correctly by relocate_section. */
2048 if (bfd_link_pic (info
))
2051 /* If there are no references to this symbol that do not use the
2052 GOT, we don't need to generate a copy reloc. */
2053 if (!h
->non_got_ref
)
2056 /* If -z nocopyreloc was given, we won't generate them either. */
2057 if (info
->nocopyreloc
)
2063 htab
= elf32_tic6x_hash_table (info
);
2067 /* We must allocate the symbol in our .dynbss section, which will
2068 become part of the .bss section of the executable. There will be
2069 an entry for this symbol in the .dynsym section. The dynamic
2070 object will contain position independent code, so all references
2071 from the dynamic object to this symbol will go through the global
2072 offset table. The dynamic linker will use the .dynsym entry to
2073 determine the address it must put in the global offset table, so
2074 both the dynamic object and the regular object will refer to the
2075 same memory location for the variable. */
2077 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2078 copy the initial value out of the dynamic object and into the
2079 runtime process image. */
2080 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2082 s
= htab
->elf
.sdynrelro
;
2083 srel
= htab
->elf
.sreldynrelro
;
2087 s
= htab
->elf
.sdynbss
;
2088 srel
= htab
->elf
.srelbss
;
2090 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2092 srel
->size
+= sizeof (Elf32_External_Rela
);
2096 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2100 elf32_tic6x_new_section_hook (bfd
*abfd
, asection
*sec
)
2104 /* Allocate target specific section data. */
2105 if (!sec
->used_by_bfd
)
2107 _tic6x_elf_section_data
*sdata
;
2108 size_t amt
= sizeof (*sdata
);
2110 sdata
= (_tic6x_elf_section_data
*) bfd_zalloc (abfd
, amt
);
2113 sec
->used_by_bfd
= sdata
;
2116 ret
= _bfd_elf_new_section_hook (abfd
, sec
);
2117 sec
->use_rela_p
= elf32_tic6x_tdata (abfd
)->use_rela_p
;
2122 /* Return true if relocation REL against section SEC is a REL rather
2123 than RELA relocation. RELOCS is the first relocation in the
2124 section and ABFD is the bfd that contains SEC. */
2127 elf32_tic6x_rel_relocation_p (bfd
*abfd
, asection
*sec
,
2128 const Elf_Internal_Rela
*relocs
,
2129 const Elf_Internal_Rela
*rel
)
2131 Elf_Internal_Shdr
*rel_hdr
;
2132 const struct elf_backend_data
*bed
;
2134 /* To determine which flavor of relocation this is, we depend on the
2135 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2136 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
2137 if (rel_hdr
== NULL
)
2139 bed
= get_elf_backend_data (abfd
);
2140 return ((size_t) (rel
- relocs
)
2141 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
2144 /* We need dynamic symbols for every section, since segments can
2145 relocate independently. */
2147 elf32_tic6x_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2148 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2151 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2155 /* If sh_type is yet undecided, assume it could be
2156 SHT_PROGBITS/SHT_NOBITS. */
2160 /* There shouldn't be section relative relocations
2161 against any other section. */
2168 elf32_tic6x_relocate_section (bfd
*output_bfd
,
2169 struct bfd_link_info
*info
,
2171 asection
*input_section
,
2173 Elf_Internal_Rela
*relocs
,
2174 Elf_Internal_Sym
*local_syms
,
2175 asection
**local_sections
)
2177 struct elf32_tic6x_link_hash_table
*htab
;
2178 Elf_Internal_Shdr
*symtab_hdr
;
2179 struct elf_link_hash_entry
**sym_hashes
;
2180 bfd_vma
*local_got_offsets
;
2181 Elf_Internal_Rela
*rel
;
2182 Elf_Internal_Rela
*relend
;
2183 bfd_boolean ok
= TRUE
;
2185 htab
= elf32_tic6x_hash_table (info
);
2186 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
2187 sym_hashes
= elf_sym_hashes (input_bfd
);
2188 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2190 relend
= relocs
+ input_section
->reloc_count
;
2192 for (rel
= relocs
; rel
< relend
; rel
++)
2195 unsigned long r_symndx
;
2197 reloc_howto_type
*howto
;
2198 Elf_Internal_Sym
*sym
;
2200 struct elf_link_hash_entry
*h
;
2201 bfd_vma off
, off2
, relocation
;
2202 bfd_boolean unresolved_reloc
;
2203 bfd_reloc_status_type r
;
2204 struct bfd_link_hash_entry
*sbh
;
2208 r_type
= ELF32_R_TYPE (rel
->r_info
);
2209 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2211 is_rel
= elf32_tic6x_rel_relocation_p (input_bfd
, input_section
,
2215 res
= elf32_tic6x_info_to_howto_rel (input_bfd
, &bfd_reloc
, rel
);
2217 res
= elf32_tic6x_info_to_howto (input_bfd
, &bfd_reloc
, rel
);
2219 if (!res
|| (howto
= bfd_reloc
.howto
) == NULL
)
2221 bfd_set_error (bfd_error_bad_value
);
2228 unresolved_reloc
= FALSE
;
2230 if (r_symndx
< symtab_hdr
->sh_info
)
2232 sym
= local_syms
+ r_symndx
;
2233 sec
= local_sections
[r_symndx
];
2234 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2238 bfd_boolean warned
, ignored
;
2240 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2241 r_symndx
, symtab_hdr
, sym_hashes
,
2243 unresolved_reloc
, warned
, ignored
);
2246 if (sec
!= NULL
&& discarded_section (sec
))
2247 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2248 rel
, 1, relend
, howto
, 0, contents
);
2250 if (bfd_link_relocatable (info
))
2254 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2257 relocation
= sec
->output_offset
+ sym
->st_value
;
2258 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
2259 contents
+ rel
->r_offset
);
2269 case R_C6000_FPHEAD
:
2271 /* No action needed. */
2274 case R_C6000_PCR_S21
:
2275 /* A branch to an undefined weak symbol is turned into a
2276 "b .s2 B3" instruction if the existing insn is of the
2277 form "b .s2 symbol". */
2278 if (h
? h
->root
.type
== bfd_link_hash_undefweak
2279 && (htab
->elf
.splt
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
2280 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2282 unsigned long oldval
;
2283 oldval
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2285 if ((oldval
& 0x7e) == 0x12)
2287 oldval
&= 0xF0000001;
2288 bfd_put_32 (input_bfd
, oldval
| 0x000c0362,
2289 contents
+ rel
->r_offset
);
2296 case R_C6000_PCR_S12
:
2297 case R_C6000_PCR_S10
:
2298 case R_C6000_PCR_S7
:
2300 && h
->plt
.offset
!= (bfd_vma
) -1
2301 && htab
->elf
.splt
!= NULL
)
2303 relocation
= (htab
->elf
.splt
->output_section
->vma
2304 + htab
->elf
.splt
->output_offset
2308 /* Generic PC-relative handling produces a value relative to
2309 the exact location of the relocation. Adjust it to be
2310 relative to the start of the fetch packet instead. */
2311 relocation
+= (input_section
->output_section
->vma
2312 + input_section
->output_offset
2313 + rel
->r_offset
) & 0x1f;
2314 unresolved_reloc
= FALSE
;
2317 case R_C6000_PCR_H16
:
2318 case R_C6000_PCR_L16
:
2319 off
= (input_section
->output_section
->vma
2320 + input_section
->output_offset
2322 /* These must be calculated as R = S - FP(FP(PC) - A).
2323 PC, here, is the value we just computed in OFF. RELOCATION
2324 has the address of S + A. */
2325 relocation
-= rel
->r_addend
;
2326 off2
= ((off
& ~(bfd_vma
)0x1f) - rel
->r_addend
) & (bfd_vma
)~0x1f;
2327 off2
= relocation
- off2
;
2328 relocation
= off
+ off2
;
2331 case R_C6000_DSBT_INDEX
:
2332 relocation
= elf32_tic6x_hash_table (info
)->params
.dsbt_index
;
2333 if (!bfd_link_pic (info
) || relocation
!= 0)
2340 case R_C6000_ABS_S16
:
2341 case R_C6000_ABS_L16
:
2342 case R_C6000_ABS_H16
:
2343 /* When generating a shared object or relocatable executable, these
2344 relocations are copied into the output file to be resolved at
2346 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2347 && (input_section
->flags
& SEC_ALLOC
)
2349 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2350 || h
->root
.type
!= bfd_link_hash_undefweak
))
2352 Elf_Internal_Rela outrel
;
2353 bfd_boolean skip
, relocate
;
2356 unresolved_reloc
= FALSE
;
2358 sreloc
= elf_section_data (input_section
)->sreloc
;
2359 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
2365 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2367 if (outrel
.r_offset
== (bfd_vma
) -1)
2369 else if (outrel
.r_offset
== (bfd_vma
) -2)
2370 skip
= TRUE
, relocate
= TRUE
;
2371 outrel
.r_offset
+= (input_section
->output_section
->vma
2372 + input_section
->output_offset
);
2375 memset (&outrel
, 0, sizeof outrel
);
2378 && (!bfd_link_pic (info
)
2379 || !SYMBOLIC_BIND (info
, h
)
2380 || !h
->def_regular
))
2382 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2383 outrel
.r_addend
= rel
->r_addend
;
2389 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2391 if (bfd_is_abs_section (sec
))
2393 else if (sec
== NULL
|| sec
->owner
== NULL
)
2395 bfd_set_error (bfd_error_bad_value
);
2402 osec
= sec
->output_section
;
2403 indx
= elf_section_data (osec
)->dynindx
;
2404 outrel
.r_addend
-= osec
->vma
;
2405 BFD_ASSERT (indx
!= 0);
2408 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2411 elf32_tic6x_install_rela (output_bfd
, sreloc
, &outrel
);
2413 /* If this reloc is against an external symbol, we do not want to
2414 fiddle with the addend. Otherwise, we need to include the symbol
2415 value so that it becomes an addend for the dynamic reloc. */
2420 /* Generic logic OK. */
2423 case R_C6000_SBR_U15_B
:
2424 case R_C6000_SBR_U15_H
:
2425 case R_C6000_SBR_U15_W
:
2426 case R_C6000_SBR_S16
:
2427 case R_C6000_SBR_L16_B
:
2428 case R_C6000_SBR_L16_H
:
2429 case R_C6000_SBR_L16_W
:
2430 case R_C6000_SBR_H16_B
:
2431 case R_C6000_SBR_H16_H
:
2432 case R_C6000_SBR_H16_W
:
2433 sbh
= bfd_link_hash_lookup (info
->hash
, "__c6xabi_DSBT_BASE",
2434 FALSE
, FALSE
, TRUE
);
2436 && (sbh
->type
== bfd_link_hash_defined
2437 || sbh
->type
== bfd_link_hash_defweak
))
2439 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
2440 && (htab
->elf
.splt
== NULL
2441 || h
->plt
.offset
== (bfd_vma
) -1))
2442 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2445 relocation
-= (sbh
->u
.def
.value
2446 + sbh
->u
.def
.section
->output_section
->vma
2447 + sbh
->u
.def
.section
->output_offset
);
2451 _bfd_error_handler (_("%pB: SB-relative relocation but "
2452 "__c6xabi_DSBT_BASE not defined"),
2459 case R_C6000_SBR_GOT_U15_W
:
2460 case R_C6000_SBR_GOT_L16_W
:
2461 case R_C6000_SBR_GOT_H16_W
:
2462 case R_C6000_EHTYPE
:
2463 /* Relocation is to the entry for this symbol in the global
2465 if (htab
->elf
.sgot
== NULL
)
2472 off
= h
->got
.offset
;
2473 dyn
= htab
->elf
.dynamic_sections_created
;
2474 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2475 bfd_link_pic (info
),
2477 || (bfd_link_pic (info
)
2478 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2479 || (ELF_ST_VISIBILITY (h
->other
)
2480 && h
->root
.type
== bfd_link_hash_undefweak
))
2482 /* This is actually a static link, or it is a
2483 -Bsymbolic link and the symbol is defined
2484 locally, or the symbol was forced to be local
2485 because of a version file. We must initialize
2486 this entry in the global offset table. Since the
2487 offset must always be a multiple of 4, we use the
2488 least significant bit to record whether we have
2489 initialized it already.
2491 When doing a dynamic link, we create a .rel.got
2492 relocation entry to initialize the value. This
2493 is done in the finish_dynamic_symbol routine. */
2498 bfd_put_32 (output_bfd
, relocation
,
2499 htab
->elf
.sgot
->contents
+ off
);
2502 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2503 bfd_link_pic (info
),
2505 && !(ELF_ST_VISIBILITY (h
->other
)
2506 && h
->root
.type
== bfd_link_hash_undefweak
))
2507 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
,
2512 unresolved_reloc
= FALSE
;
2516 if (local_got_offsets
== NULL
)
2519 off
= local_got_offsets
[r_symndx
];
2521 /* The offset must always be a multiple of 4. We use
2522 the least significant bit to record whether we have
2523 already generated the necessary reloc. */
2528 bfd_put_32 (output_bfd
, relocation
,
2529 htab
->elf
.sgot
->contents
+ off
);
2531 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2532 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
, off
);
2534 local_got_offsets
[r_symndx
] |= 1;
2538 if (off
>= (bfd_vma
) -2)
2542 relocation
= (htab
->elf
.sgot
->output_section
->vma
2543 + htab
->elf
.sgot
->output_offset
+ off
2544 - htab
->dsbt
->output_section
->vma
2545 - htab
->dsbt
->output_offset
);
2547 relocation
= (htab
->elf
.sgot
->output_section
->vma
2548 + htab
->elf
.sgot
->output_offset
+ off
2549 - htab
->elf
.sgotplt
->output_section
->vma
2550 - htab
->elf
.sgotplt
->output_offset
);
2552 if (rel
->r_addend
!= 0)
2554 /* We can't do anything for a relocation which is against
2555 a symbol *plus offset*. GOT holds relocations for
2556 symbols. Make this an error; the compiler isn't
2557 allowed to pass us these kinds of things. */
2560 /* xgettext:c-format */
2561 (_("%pB, section %pA: relocation %s with non-zero addend %"
2562 PRId64
" against local symbol"),
2565 elf32_tic6x_howto_table
[r_type
].name
,
2566 (int64_t) rel
->r_addend
);
2569 /* xgettext:c-format */
2570 (_("%pB, section %pA: relocation %s with non-zero addend %"
2571 PRId64
" against symbol `%s'"),
2574 elf32_tic6x_howto_table
[r_type
].name
,
2575 (int64_t) rel
->r_addend
,
2576 h
->root
.root
.string
[0] != '\0' ? h
->root
.root
.string
2577 : _("[whose name is lost]"));
2579 bfd_set_error (bfd_error_bad_value
);
2584 case R_C6000_PREL31
:
2586 && h
->plt
.offset
!= (bfd_vma
) -1
2587 && htab
->elf
.splt
!= NULL
)
2589 relocation
= (htab
->elf
.splt
->output_section
->vma
2590 + htab
->elf
.splt
->output_offset
2596 /* Invalid in relocatable object. */
2598 /* Unknown relocation. */
2599 /* xgettext:c-format */
2600 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2602 bfd_set_error (bfd_error_bad_value
);
2607 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2608 contents
, rel
->r_offset
,
2609 relocation
, rel
->r_addend
);
2612 if (r
== bfd_reloc_ok
2613 && howto
->complain_on_overflow
== complain_overflow_bitfield
)
2615 /* Generic overflow handling accepts cases the ABI says
2616 should be rejected for R_C6000_ABS16 and
2618 bfd_vma value
= (relocation
+ rel
->r_addend
) & 0xffffffff;
2619 bfd_vma sbit
= 1 << (howto
->bitsize
- 1);
2620 bfd_vma sbits
= (-(bfd_vma
) sbit
) & 0xffffffff;
2621 bfd_vma value_sbits
= value
& sbits
;
2623 if (value_sbits
!= 0
2624 && value_sbits
!= sbit
2625 && value_sbits
!= sbits
)
2626 r
= bfd_reloc_overflow
;
2629 if (r
!= bfd_reloc_ok
)
2632 const char *error_message
;
2635 name
= h
->root
.root
.string
;
2638 name
= bfd_elf_string_from_elf_section (input_bfd
,
2639 symtab_hdr
->sh_link
,
2644 name
= bfd_section_name (sec
);
2649 case bfd_reloc_overflow
:
2650 /* If the overflowing reloc was to an undefined symbol,
2651 we have already printed one error message and there
2652 is no point complaining again. */
2653 if (!h
|| h
->root
.type
!= bfd_link_hash_undefined
)
2654 (*info
->callbacks
->reloc_overflow
)
2655 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2656 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
2659 case bfd_reloc_undefined
:
2660 (*info
->callbacks
->undefined_symbol
) (info
, name
, input_bfd
,
2662 rel
->r_offset
, TRUE
);
2665 case bfd_reloc_outofrange
:
2666 error_message
= _("out of range");
2669 case bfd_reloc_notsupported
:
2670 error_message
= _("unsupported relocation");
2673 case bfd_reloc_dangerous
:
2674 error_message
= _("dangerous relocation");
2678 error_message
= _("unknown error");
2682 BFD_ASSERT (error_message
!= NULL
);
2683 (*info
->callbacks
->reloc_dangerous
)
2684 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
2694 /* Look through the relocs for a section during the first phase, and
2695 calculate needed space in the global offset table, procedure linkage
2696 table, and dynamic reloc sections. */
2699 elf32_tic6x_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2700 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2702 struct elf32_tic6x_link_hash_table
*htab
;
2703 Elf_Internal_Shdr
*symtab_hdr
;
2704 struct elf_link_hash_entry
**sym_hashes
;
2705 const Elf_Internal_Rela
*rel
;
2706 const Elf_Internal_Rela
*rel_end
;
2709 if (bfd_link_relocatable (info
))
2712 htab
= elf32_tic6x_hash_table (info
);
2713 symtab_hdr
= &elf_symtab_hdr (abfd
);
2714 sym_hashes
= elf_sym_hashes (abfd
);
2716 /* Create dynamic sections for relocatable executables so that we can
2717 copy relocations. */
2718 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2719 && ! htab
->elf
.dynamic_sections_created
)
2721 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2727 rel_end
= relocs
+ sec
->reloc_count
;
2728 for (rel
= relocs
; rel
< rel_end
; rel
++)
2730 unsigned int r_type
;
2731 unsigned int r_symndx
;
2732 struct elf_link_hash_entry
*h
;
2733 Elf_Internal_Sym
*isym
;
2735 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2736 r_type
= ELF32_R_TYPE (rel
->r_info
);
2738 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2740 /* xgettext:c-format */
2741 _bfd_error_handler (_("%pB: bad symbol index: %d"),
2746 if (r_symndx
< symtab_hdr
->sh_info
)
2748 /* A local symbol. */
2749 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2758 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2759 while (h
->root
.type
== bfd_link_hash_indirect
2760 || h
->root
.type
== bfd_link_hash_warning
)
2761 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2766 case R_C6000_PCR_S21
:
2767 case R_C6000_PREL31
:
2768 /* This symbol requires a procedure linkage table entry. We
2769 actually build the entry in adjust_dynamic_symbol,
2770 because this might be a case of linking PIC code which is
2771 never referenced by a dynamic object, in which case we
2772 don't need to generate a procedure linkage table entry
2775 /* If this is a local symbol, we resolve it directly without
2776 creating a procedure linkage table entry. */
2781 h
->plt
.refcount
+= 1;
2784 case R_C6000_SBR_GOT_U15_W
:
2785 case R_C6000_SBR_GOT_L16_W
:
2786 case R_C6000_SBR_GOT_H16_W
:
2787 case R_C6000_EHTYPE
:
2788 /* This symbol requires a global offset table entry. */
2791 h
->got
.refcount
+= 1;
2795 bfd_signed_vma
*local_got_refcounts
;
2797 /* This is a global offset table entry for a local symbol. */
2798 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2799 if (local_got_refcounts
== NULL
)
2803 size
= symtab_hdr
->sh_info
;
2804 size
*= (sizeof (bfd_signed_vma
)
2805 + sizeof (bfd_vma
) + sizeof(char));
2806 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2807 if (local_got_refcounts
== NULL
)
2809 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2811 local_got_refcounts
[r_symndx
] += 1;
2814 if (htab
->elf
.sgot
== NULL
)
2816 if (htab
->elf
.dynobj
== NULL
)
2817 htab
->elf
.dynobj
= abfd
;
2818 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2823 case R_C6000_DSBT_INDEX
:
2824 /* We'd like to check for nonzero dsbt_index here, but it's
2825 set up only after check_relocs is called. Instead, we
2826 store the number of R_C6000_DSBT_INDEX relocs in the
2827 pc_count field, and potentially discard the extra space
2828 in elf32_tic6x_allocate_dynrelocs. */
2829 if (!bfd_link_pic (info
))
2836 case R_C6000_ABS_S16
:
2837 case R_C6000_ABS_L16
:
2838 case R_C6000_ABS_H16
:
2839 /* If we are creating a shared library, and this is a reloc
2840 against a global symbol, or a non PC relative reloc
2841 against a local symbol, then we need to copy the reloc
2842 into the shared library. However, if we are linking with
2843 -Bsymbolic, we do not need to copy a reloc against a
2844 global symbol which is defined in an object we are
2845 including in the link (i.e., DEF_REGULAR is set). At
2846 this point we have not seen all the input files, so it is
2847 possible that DEF_REGULAR is not set now but will be set
2848 later (it is never cleared). In case of a weak definition,
2849 DEF_REGULAR may be cleared later by a strong definition in
2850 a shared library. We account for that possibility below by
2851 storing information in the relocs_copied field of the hash
2852 table entry. A similar situation occurs when creating
2853 shared libraries and symbol visibility changes render the
2856 If on the other hand, we are creating an executable, we
2857 may need to keep relocations for symbols satisfied by a
2858 dynamic library if we manage to avoid copy relocs for the
2860 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2861 && (sec
->flags
& SEC_ALLOC
) != 0)
2863 struct elf_dyn_relocs
*p
;
2864 struct elf_dyn_relocs
**head
;
2866 /* We must copy these reloc types into the output file.
2867 Create a reloc section in dynobj and make room for
2871 if (htab
->elf
.dynobj
== NULL
)
2872 htab
->elf
.dynobj
= abfd
;
2874 sreloc
= _bfd_elf_make_dynamic_reloc_section
2875 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela? */ TRUE
);
2881 /* If this is a global symbol, we count the number of
2882 relocations we need for this symbol. */
2885 head
= &h
->dyn_relocs
;
2889 /* Track dynamic relocs needed for local syms too.
2890 We really need local syms available to do this
2895 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2899 vpp
= &elf_section_data (s
)->local_dynrel
;
2900 head
= (struct elf_dyn_relocs
**)vpp
;
2904 if (p
== NULL
|| p
->sec
!= sec
)
2906 size_t amt
= sizeof *p
;
2907 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
2918 if (r_type
== R_C6000_DSBT_INDEX
)
2923 case R_C6000_SBR_U15_B
:
2924 case R_C6000_SBR_U15_H
:
2925 case R_C6000_SBR_U15_W
:
2926 case R_C6000_SBR_S16
:
2927 case R_C6000_SBR_L16_B
:
2928 case R_C6000_SBR_L16_H
:
2929 case R_C6000_SBR_L16_W
:
2930 case R_C6000_SBR_H16_B
:
2931 case R_C6000_SBR_H16_H
:
2932 case R_C6000_SBR_H16_W
:
2934 /* These relocations implicitly reference __c6xabi_DSBT_BASE.
2935 Add an explicit reference so that the symbol will be
2936 provided by a linker script. */
2937 struct bfd_link_hash_entry
*bh
= NULL
;
2938 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
2939 "__c6xabi_DSBT_BASE",
2941 bfd_und_section_ptr
, 0,
2942 NULL
, FALSE
, FALSE
, &bh
))
2944 ((struct elf_link_hash_entry
*) bh
)->non_elf
= 0;
2946 if (h
!= NULL
&& bfd_link_executable (info
))
2948 /* For B14-relative addresses, we might need a copy
2963 elf32_tic6x_add_symbol_hook (bfd
*abfd
,
2964 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2965 Elf_Internal_Sym
*sym
,
2966 const char **namep ATTRIBUTE_UNUSED
,
2967 flagword
*flagsp ATTRIBUTE_UNUSED
,
2971 switch (sym
->st_shndx
)
2973 case SHN_TIC6X_SCOMMON
:
2974 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2975 (*secp
)->flags
|= SEC_IS_COMMON
;
2976 *valp
= sym
->st_size
;
2977 bfd_set_section_alignment (*secp
, bfd_log2 (sym
->st_value
));
2985 elf32_tic6x_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
2987 elf_symbol_type
*elfsym
;
2989 elfsym
= (elf_symbol_type
*) asym
;
2990 switch (elfsym
->internal_elf_sym
.st_shndx
)
2992 case SHN_TIC6X_SCOMMON
:
2993 if (tic6x_elf_scom_section
.name
== NULL
)
2995 /* Initialize the small common section. */
2996 tic6x_elf_scom_section
.name
= ".scommon";
2997 tic6x_elf_scom_section
.flags
= SEC_IS_COMMON
;
2998 tic6x_elf_scom_section
.output_section
= &tic6x_elf_scom_section
;
2999 tic6x_elf_scom_section
.symbol
= &tic6x_elf_scom_symbol
;
3000 tic6x_elf_scom_section
.symbol_ptr_ptr
= &tic6x_elf_scom_symbol_ptr
;
3001 tic6x_elf_scom_symbol
.name
= ".scommon";
3002 tic6x_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3003 tic6x_elf_scom_symbol
.section
= &tic6x_elf_scom_section
;
3004 tic6x_elf_scom_symbol_ptr
= &tic6x_elf_scom_symbol
;
3006 asym
->section
= &tic6x_elf_scom_section
;
3007 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3013 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3014 const char *name ATTRIBUTE_UNUSED
,
3015 Elf_Internal_Sym
*sym
,
3016 asection
*input_sec
,
3017 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
3019 /* If we see a common symbol, which implies a relocatable link, then
3020 if a symbol was small common in an input file, mark it as small
3021 common in the output file. */
3022 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
3023 sym
->st_shndx
= SHN_TIC6X_SCOMMON
;
3029 elf32_tic6x_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
3033 if (strcmp (bfd_section_name (sec
), ".scommon") == 0)
3035 *retval
= SHN_TIC6X_SCOMMON
;
3042 /* Allocate space in .plt, .got and associated reloc sections for
3046 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3048 struct bfd_link_info
*info
;
3049 struct elf32_tic6x_link_hash_table
*htab
;
3050 struct elf_dyn_relocs
*p
;
3052 if (h
->root
.type
== bfd_link_hash_indirect
)
3055 info
= (struct bfd_link_info
*) inf
;
3056 htab
= elf32_tic6x_hash_table (info
);
3058 if (htab
->elf
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3060 /* Make sure this symbol is output as a dynamic symbol.
3061 Undefined weak syms won't yet be marked as dynamic. */
3062 if (h
->dynindx
== -1 && !h
->forced_local
)
3064 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3068 if (bfd_link_pic (info
)
3069 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3071 asection
*s
= htab
->elf
.splt
;
3073 /* If this is the first .plt entry, make room for the special
3076 s
->size
+= PLT_ENTRY_SIZE
;
3078 h
->plt
.offset
= s
->size
;
3080 /* If this symbol is not defined in a regular file, and we are
3081 not generating a shared library, then set the symbol to this
3082 location in the .plt. This is required to make function
3083 pointers compare as equal between the normal executable and
3084 the shared library. */
3085 if (! bfd_link_pic (info
) && !h
->def_regular
)
3087 h
->root
.u
.def
.section
= s
;
3088 h
->root
.u
.def
.value
= h
->plt
.offset
;
3091 /* Make room for this entry. */
3092 s
->size
+= PLT_ENTRY_SIZE
;
3093 /* We also need to make an entry in the .got.plt section, which
3094 will be placed in the .got section by the linker script. */
3095 htab
->elf
.sgotplt
->size
+= 4;
3096 /* We also need to make an entry in the .rel.plt section. */
3097 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3101 h
->plt
.offset
= (bfd_vma
) -1;
3107 h
->plt
.offset
= (bfd_vma
) -1;
3111 if (h
->got
.refcount
> 0)
3115 /* Make sure this symbol is output as a dynamic symbol.
3116 Undefined weak syms won't yet be marked as dynamic. */
3117 if (h
->dynindx
== -1
3118 && !h
->forced_local
)
3120 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3125 h
->got
.offset
= s
->size
;
3128 if (!(ELF_ST_VISIBILITY (h
->other
)
3129 && h
->root
.type
== bfd_link_hash_undefweak
))
3130 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3133 h
->got
.offset
= (bfd_vma
) -1;
3135 if (h
->dyn_relocs
== NULL
)
3138 /* Discard relocs on undefined weak syms with non-default
3140 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (htab
->obfd
))
3142 /* We use the pc_count field to hold the number of
3143 R_C6000_DSBT_INDEX relocs. */
3144 if (htab
->params
.dsbt_index
!= 0)
3146 struct elf_dyn_relocs
**pp
;
3148 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
3150 p
->count
-= p
->pc_count
;
3159 if (h
->dyn_relocs
!= NULL
3160 && h
->root
.type
== bfd_link_hash_undefweak
)
3162 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3163 h
->dyn_relocs
= NULL
;
3165 /* Make sure undefined weak symbols are output as a dynamic
3167 else if (h
->dynindx
== -1
3168 && !h
->forced_local
)
3170 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3176 /* Finally, allocate space. */
3177 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3181 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3183 BFD_ASSERT (sreloc
!= NULL
);
3184 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3190 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
3191 read-only sections. */
3194 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
3198 if (h
->root
.type
== bfd_link_hash_indirect
)
3201 sec
= readonly_dynrelocs (h
);
3204 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
3206 info
->flags
|= DF_TEXTREL
;
3207 info
->callbacks
->minfo
3208 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
3209 sec
->owner
, h
->root
.root
.string
, sec
);
3211 /* Not an error, just cut short the traversal. */
3217 /* Set the sizes of the dynamic sections. */
3220 elf32_tic6x_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3222 struct elf32_tic6x_link_hash_table
*htab
;
3228 htab
= elf32_tic6x_hash_table (info
);
3229 dynobj
= htab
->elf
.dynobj
;
3233 if (htab
->elf
.dynamic_sections_created
)
3235 /* Set the contents of the .interp section to the interpreter. */
3236 if (bfd_link_executable (info
) && !info
->nointerp
)
3238 s
= bfd_get_linker_section (dynobj
, ".interp");
3241 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3242 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3246 /* Set up .got offsets for local syms, and space for local dynamic
3248 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3250 bfd_signed_vma
*local_got
;
3251 bfd_signed_vma
*end_local_got
;
3252 bfd_size_type locsymcount
;
3253 Elf_Internal_Shdr
*symtab_hdr
;
3256 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3258 struct elf_dyn_relocs
*p
;
3260 for (p
= ((struct elf_dyn_relocs
*)
3261 elf_section_data (s
)->local_dynrel
);
3265 if (!bfd_is_abs_section (p
->sec
)
3266 && bfd_is_abs_section (p
->sec
->output_section
))
3268 /* Input section has been discarded, either because
3269 it is a copy of a linkonce section or due to
3270 linker script /DISCARD/, so we'll be discarding
3273 else if (p
->count
!= 0)
3275 srel
= elf_section_data (p
->sec
)->sreloc
;
3276 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3277 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3278 info
->flags
|= DF_TEXTREL
;
3283 local_got
= elf_local_got_refcounts (ibfd
);
3287 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3288 locsymcount
= symtab_hdr
->sh_info
;
3289 end_local_got
= local_got
+ locsymcount
;
3291 srel
= htab
->elf
.srelgot
;
3292 for (; local_got
< end_local_got
; ++local_got
)
3296 *local_got
= s
->size
;
3299 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
3301 srel
->size
+= sizeof (Elf32_External_Rela
);
3305 *local_got
= (bfd_vma
) -1;
3309 /* Allocate global sym .plt and .got entries, and space for global
3310 sym dynamic relocs. */
3311 elf_link_hash_traverse (&htab
->elf
, elf32_tic6x_allocate_dynrelocs
, info
);
3313 /* We now have determined the sizes of the various dynamic sections.
3314 Allocate memory for them. */
3316 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3318 bfd_boolean strip_section
= TRUE
;
3320 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3323 if (s
== htab
->dsbt
)
3324 s
->size
= 4 * htab
->params
.dsbt_size
;
3325 else if (s
== htab
->elf
.splt
3326 || s
== htab
->elf
.sgot
3327 || s
== htab
->elf
.sgotplt
3328 || s
== htab
->elf
.sdynbss
3329 || s
== htab
->elf
.sdynrelro
)
3331 /* Strip this section if we don't need it; see the
3333 /* We'd like to strip these sections if they aren't needed, but if
3334 we've exported dynamic symbols from them we must leave them.
3335 It's too late to tell BFD to get rid of the symbols. */
3337 if (htab
->elf
.hplt
!= NULL
)
3338 strip_section
= FALSE
;
3340 /* Round up the size of the PLT section to a multiple of 32. */
3341 if (s
== htab
->elf
.splt
&& s
->size
> 0)
3342 s
->size
= (s
->size
+ 31) & ~(bfd_vma
)31;
3344 else if (CONST_STRNEQ (bfd_section_name (s
), ".rela"))
3347 && s
!= htab
->elf
.srelplt
)
3350 /* We use the reloc_count field as a counter if we need
3351 to copy relocs into the output file. */
3356 /* It's not one of our sections, so don't allocate space. */
3362 /* If we don't need this section, strip it from the
3363 output file. This is mostly to handle .rel.bss and
3364 .rel.plt. We must create both sections in
3365 create_dynamic_sections, because they must be created
3366 before the linker maps input sections to output
3367 sections. The linker does that before
3368 adjust_dynamic_symbol is called, and it is that
3369 function which decides whether anything needs to go
3370 into these sections. */
3372 s
->flags
|= SEC_EXCLUDE
;
3376 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3379 /* Allocate memory for the section contents. We use bfd_zalloc
3380 here in case unused entries are not reclaimed before the
3381 section's contents are written out. This should not happen,
3382 but this way if it does, we get a R_C6000_NONE reloc instead
3384 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3385 if (s
->contents
== NULL
)
3389 if (htab
->elf
.dynamic_sections_created
)
3391 /* Add some entries to the .dynamic section. We fill in the
3392 values later, in elf32_tic6x_finish_dynamic_sections, but we
3393 must add the entries now so that we get the correct size for
3394 the .dynamic section. The DT_DEBUG entry is filled in by the
3395 dynamic linker and used by the debugger. */
3396 #define add_dynamic_entry(TAG, VAL) \
3397 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3399 if (bfd_link_executable (info
))
3401 if (!add_dynamic_entry (DT_DEBUG
, 0))
3405 if (!add_dynamic_entry (DT_C6000_DSBT_BASE
, 0)
3406 || !add_dynamic_entry (DT_C6000_DSBT_SIZE
, htab
->params
.dsbt_size
)
3407 || !add_dynamic_entry (DT_C6000_DSBT_INDEX
,
3408 htab
->params
.dsbt_index
))
3411 if (htab
->elf
.splt
->size
!= 0)
3413 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3414 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3415 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3416 || !add_dynamic_entry (DT_JMPREL
, 0))
3422 if (!add_dynamic_entry (DT_RELA
, 0)
3423 || !add_dynamic_entry (DT_RELASZ
, 0)
3424 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3427 /* If any dynamic relocs apply to a read-only section,
3428 then we need a DT_TEXTREL entry. */
3429 if ((info
->flags
& DF_TEXTREL
) == 0)
3430 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
3432 if ((info
->flags
& DF_TEXTREL
) != 0)
3434 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3439 #undef add_dynamic_entry
3444 /* This function is called after all the input files have been read,
3445 and the input sections have been assigned to output sections. */
3448 elf32_tic6x_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3450 if (elf32_tic6x_using_dsbt (output_bfd
) && !bfd_link_relocatable (info
)
3451 && !bfd_elf_stack_segment_size (output_bfd
, info
,
3452 "__stacksize", DEFAULT_STACK_SIZE
))
3459 elf32_tic6x_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3460 struct bfd_link_info
*info
)
3462 struct elf32_tic6x_link_hash_table
*htab
;
3466 htab
= elf32_tic6x_hash_table (info
);
3467 dynobj
= htab
->elf
.dynobj
;
3468 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
3470 if (elf_hash_table (info
)->dynamic_sections_created
)
3472 Elf32_External_Dyn
* dyncon
;
3473 Elf32_External_Dyn
* dynconend
;
3475 BFD_ASSERT (sdyn
!= NULL
);
3477 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3478 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3480 for (; dyncon
< dynconend
; dyncon
++)
3482 Elf_Internal_Dyn dyn
;
3485 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3492 case DT_C6000_DSBT_BASE
:
3494 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
);
3498 s
= htab
->elf
.sgotplt
;
3499 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3503 s
= htab
->elf
.srelplt
;
3504 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3508 s
= htab
->elf
.srelplt
;
3509 dyn
.d_un
.d_val
= s
->size
;
3512 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3515 /* Fill in the first entry in the procedure linkage table. */
3516 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
3518 bfd_vma got_offs
= (htab
->elf
.sgotplt
->output_section
->vma
3519 + htab
->elf
.sgotplt
->output_offset
3520 - htab
->dsbt
->output_section
->vma
3521 - htab
->dsbt
->output_offset
) / 4;
3523 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3524 bfd_put_32 (output_bfd
, got_offs
<< 8 | 0x0100006e,
3525 htab
->elf
.splt
->contents
);
3526 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3527 bfd_put_32 (output_bfd
, (got_offs
+ 1) << 8 | 0x0080006e,
3528 htab
->elf
.splt
->contents
+ 4);
3530 bfd_put_32 (output_bfd
, 0x00004000,
3531 htab
->elf
.splt
->contents
+ 8);
3533 bfd_put_32 (output_bfd
, 0x00080362,
3534 htab
->elf
.splt
->contents
+ 12);
3536 bfd_put_32 (output_bfd
, 0x00008000,
3537 htab
->elf
.splt
->contents
+ 16);
3539 elf_section_data (htab
->elf
.splt
->output_section
)
3540 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3547 /* Return address for Ith PLT stub in section PLT, for relocation REL
3548 or (bfd_vma) -1 if it should not be included. */
3551 elf32_tic6x_plt_sym_val (bfd_vma i
, const asection
*plt
,
3552 const arelent
*rel ATTRIBUTE_UNUSED
)
3554 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3558 elf32_tic6x_obj_attrs_arg_type (int tag
)
3560 if (tag
== Tag_ABI_compatibility
)
3561 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
3563 return ATTR_TYPE_FLAG_STR_VAL
;
3565 return ATTR_TYPE_FLAG_INT_VAL
;
3569 elf32_tic6x_obj_attrs_order (int num
)
3571 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
3572 return Tag_ABI_conformance
;
3573 if ((num
- 1) < Tag_ABI_conformance
)
3579 elf32_tic6x_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
3581 if ((tag
& 127) < 64)
3584 /* xgettext:c-format */
3585 (_("%pB: error: unknown mandatory EABI object attribute %d"),
3587 bfd_set_error (bfd_error_bad_value
);
3593 /* xgettext:c-format */
3594 (_("%pB: warning: unknown EABI object attribute %d"),
3600 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3601 and return the merged value. At present, all merges succeed, so no
3602 return value for errors is defined. */
3605 elf32_tic6x_merge_arch_attributes (int arch1
, int arch2
)
3607 int min_arch
, max_arch
;
3609 min_arch
= (arch1
< arch2
? arch1
: arch2
);
3610 max_arch
= (arch1
> arch2
? arch1
: arch2
);
3612 /* In most cases, the numerically greatest value is the correct
3613 merged value, but merging C64 and C67 results in C674X. */
3614 if ((min_arch
== C6XABI_Tag_ISA_C67X
3615 || min_arch
== C6XABI_Tag_ISA_C67XP
)
3616 && (max_arch
== C6XABI_Tag_ISA_C64X
3617 || max_arch
== C6XABI_Tag_ISA_C64XP
))
3618 return C6XABI_Tag_ISA_C674X
;
3623 /* Convert a Tag_ABI_array_object_alignment or
3624 Tag_ABI_array_object_align_expected tag value TAG to a
3625 corresponding alignment value; return the alignment, or -1 for an
3626 unknown tag value. */
3629 elf32_tic6x_tag_to_array_alignment (int tag
)
3647 /* Convert a Tag_ABI_array_object_alignment or
3648 Tag_ABI_array_object_align_expected alignment ALIGN to a
3649 corresponding tag value; return the tag value. */
3652 elf32_tic6x_array_alignment_to_tag (int align
)
3670 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3671 succeeded, FALSE otherwise. */
3674 elf32_tic6x_merge_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
3676 bfd
*obfd
= info
->output_bfd
;
3677 bfd_boolean result
= TRUE
;
3678 obj_attribute
*in_attr
;
3679 obj_attribute
*out_attr
;
3681 int array_align_in
, array_align_out
, array_expect_in
, array_expect_out
;
3683 /* FIXME: What should be checked when linking shared libraries? */
3684 if ((ibfd
->flags
& DYNAMIC
) != 0)
3687 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
3689 /* This is the first object. Copy the attributes. */
3690 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
3692 out_attr
= elf_known_obj_attributes_proc (obfd
);
3694 /* Use the Tag_null value to indicate the attributes have been
3701 in_attr
= elf_known_obj_attributes_proc (ibfd
);
3702 out_attr
= elf_known_obj_attributes_proc (obfd
);
3704 /* No specification yet for handling of unknown attributes, so just
3705 ignore them and handle known ones. */
3707 if (out_attr
[Tag_ABI_stack_align_preserved
].i
3708 < in_attr
[Tag_ABI_stack_align_needed
].i
)
3711 /* xgettext:c-format */
3712 (_("error: %pB requires more stack alignment than %pB preserves"),
3716 if (in_attr
[Tag_ABI_stack_align_preserved
].i
3717 < out_attr
[Tag_ABI_stack_align_needed
].i
)
3720 /* xgettext:c-format */
3721 (_("error: %pB requires more stack alignment than %pB preserves"),
3726 array_align_in
= elf32_tic6x_tag_to_array_alignment
3727 (in_attr
[Tag_ABI_array_object_alignment
].i
);
3728 if (array_align_in
== -1)
3731 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
3735 array_align_out
= elf32_tic6x_tag_to_array_alignment
3736 (out_attr
[Tag_ABI_array_object_alignment
].i
);
3737 if (array_align_out
== -1)
3740 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
3744 array_expect_in
= elf32_tic6x_tag_to_array_alignment
3745 (in_attr
[Tag_ABI_array_object_align_expected
].i
);
3746 if (array_expect_in
== -1)
3749 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
3753 array_expect_out
= elf32_tic6x_tag_to_array_alignment
3754 (out_attr
[Tag_ABI_array_object_align_expected
].i
);
3755 if (array_expect_out
== -1)
3758 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
3763 if (array_align_out
< array_expect_in
)
3766 /* xgettext:c-format */
3767 (_("error: %pB requires more array alignment than %pB preserves"),
3771 if (array_align_in
< array_expect_out
)
3774 /* xgettext:c-format */
3775 (_("error: %pB requires more array alignment than %pB preserves"),
3780 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
3785 out_attr
[i
].i
= elf32_tic6x_merge_arch_attributes (in_attr
[i
].i
,
3789 case Tag_ABI_wchar_t
:
3790 if (out_attr
[i
].i
== 0)
3791 out_attr
[i
].i
= in_attr
[i
].i
;
3792 if (out_attr
[i
].i
!= 0
3793 && in_attr
[i
].i
!= 0
3794 && out_attr
[i
].i
!= in_attr
[i
].i
)
3797 /* xgettext:c-format */
3798 (_("warning: %pB and %pB differ in wchar_t size"), obfd
, ibfd
);
3802 case Tag_ABI_stack_align_needed
:
3803 if (out_attr
[i
].i
< in_attr
[i
].i
)
3804 out_attr
[i
].i
= in_attr
[i
].i
;
3807 case Tag_ABI_stack_align_preserved
:
3808 if (out_attr
[i
].i
> in_attr
[i
].i
)
3809 out_attr
[i
].i
= in_attr
[i
].i
;
3813 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3816 /* xgettext:c-format */
3817 (_("warning: %pB and %pB differ in whether code is "
3818 "compiled for DSBT"),
3825 /* Don't transfer these tags from dynamic objects. */
3826 if ((ibfd
->flags
& DYNAMIC
) != 0)
3828 if (out_attr
[i
].i
> in_attr
[i
].i
)
3829 out_attr
[i
].i
= in_attr
[i
].i
;
3832 case Tag_ABI_array_object_alignment
:
3833 if (array_align_out
!= -1
3834 && array_align_in
!= -1
3835 && array_align_out
> array_align_in
)
3837 = elf32_tic6x_array_alignment_to_tag (array_align_in
);
3840 case Tag_ABI_array_object_align_expected
:
3841 if (array_expect_out
!= -1
3842 && array_expect_in
!= -1
3843 && array_expect_out
< array_expect_in
)
3845 = elf32_tic6x_array_alignment_to_tag (array_expect_in
);
3848 case Tag_ABI_conformance
:
3849 /* Merging for this attribute is not specified. As on ARM,
3850 treat a missing attribute as no claim to conform and only
3851 merge identical values. */
3852 if (out_attr
[i
].s
== NULL
3853 || in_attr
[i
].s
== NULL
3854 || strcmp (out_attr
[i
].s
,
3856 out_attr
[i
].s
= NULL
;
3859 case Tag_ABI_compatibility
:
3860 /* Merged in _bfd_elf_merge_object_attributes. */
3865 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
3869 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
3870 out_attr
[i
].type
= in_attr
[i
].type
;
3873 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
3874 if (!_bfd_elf_merge_object_attributes (ibfd
, info
))
3877 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
3883 elf32_tic6x_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
3885 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
3888 if (! is_tic6x_elf (ibfd
) || ! is_tic6x_elf (info
->output_bfd
))
3891 if (!elf32_tic6x_merge_attributes (ibfd
, info
))
3897 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
3898 adds the edit to the start of the list. (The list must be built in order of
3899 ascending TINDEX: the function's callers are primarily responsible for
3900 maintaining that condition). */
3903 elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit
**head
,
3904 tic6x_unwind_table_edit
**tail
,
3905 tic6x_unwind_edit_type type
,
3906 asection
*linked_section
,
3907 unsigned int tindex
)
3909 tic6x_unwind_table_edit
*new_edit
= (tic6x_unwind_table_edit
*)
3910 xmalloc (sizeof (tic6x_unwind_table_edit
));
3912 new_edit
->type
= type
;
3913 new_edit
->linked_section
= linked_section
;
3914 new_edit
->index
= tindex
;
3918 new_edit
->next
= NULL
;
3921 (*tail
)->next
= new_edit
;
3930 new_edit
->next
= *head
;
3939 static _tic6x_elf_section_data
*
3940 get_tic6x_elf_section_data (asection
* sec
)
3942 if (sec
&& sec
->owner
&& is_tic6x_elf (sec
->owner
))
3943 return elf32_tic6x_section_data (sec
);
3949 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST must be negative. */
3951 elf32_tic6x_adjust_exidx_size (asection
*exidx_sec
, int adjust
)
3955 if (!exidx_sec
->rawsize
)
3956 exidx_sec
->rawsize
= exidx_sec
->size
;
3958 bfd_set_section_size (exidx_sec
, exidx_sec
->size
+ adjust
);
3959 out_sec
= exidx_sec
->output_section
;
3960 /* Adjust size of output section. */
3961 bfd_set_section_size (out_sec
, out_sec
->size
+adjust
);
3964 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
3966 elf32_tic6x_insert_cantunwind_after (asection
*text_sec
, asection
*exidx_sec
)
3968 struct _tic6x_elf_section_data
*exidx_data
;
3970 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
3971 elf32_tic6x_add_unwind_table_edit (
3972 &exidx_data
->u
.exidx
.unwind_edit_list
,
3973 &exidx_data
->u
.exidx
.unwind_edit_tail
,
3974 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
3976 elf32_tic6x_adjust_exidx_size (exidx_sec
, 8);
3979 /* Scan .cx6abi.exidx tables, and create a list describing edits which
3980 should be made to those tables, such that:
3982 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
3983 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
3984 codes which have been inlined into the index).
3986 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
3988 The edits are applied when the tables are written
3989 (in elf32_tic6x_write_section).
3993 elf32_tic6x_fix_exidx_coverage (asection
**text_section_order
,
3994 unsigned int num_text_sections
,
3995 struct bfd_link_info
*info
,
3996 bfd_boolean merge_exidx_entries
)
3999 unsigned int last_second_word
= 0, i
;
4000 asection
*last_exidx_sec
= NULL
;
4001 asection
*last_text_sec
= NULL
;
4002 int last_unwind_type
= -1;
4004 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
4006 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link
.next
)
4010 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
4012 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
4013 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
4015 if (!hdr
|| hdr
->sh_type
!= SHT_C6000_UNWIND
)
4018 if (elf_sec
->linked_to
)
4020 Elf_Internal_Shdr
*linked_hdr
4021 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
4022 struct _tic6x_elf_section_data
*linked_sec_tic6x_data
4023 = get_tic6x_elf_section_data (linked_hdr
->bfd_section
);
4025 if (linked_sec_tic6x_data
== NULL
)
4028 /* Link this .c6xabi.exidx section back from the
4029 text section it describes. */
4030 linked_sec_tic6x_data
->u
.text
.tic6x_exidx_sec
= sec
;
4035 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
4036 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
4037 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
4039 for (i
= 0; i
< num_text_sections
; i
++)
4041 asection
*sec
= text_section_order
[i
];
4042 asection
*exidx_sec
;
4043 struct _tic6x_elf_section_data
*tic6x_data
4044 = get_tic6x_elf_section_data (sec
);
4045 struct _tic6x_elf_section_data
*exidx_data
;
4046 bfd_byte
*contents
= NULL
;
4047 int deleted_exidx_bytes
= 0;
4049 tic6x_unwind_table_edit
*unwind_edit_head
= NULL
;
4050 tic6x_unwind_table_edit
*unwind_edit_tail
= NULL
;
4051 Elf_Internal_Shdr
*hdr
;
4054 if (tic6x_data
== NULL
)
4057 exidx_sec
= tic6x_data
->u
.text
.tic6x_exidx_sec
;
4058 if (exidx_sec
== NULL
)
4060 /* Section has no unwind data. */
4061 if (last_unwind_type
== 0 || !last_exidx_sec
)
4064 /* Ignore zero sized sections. */
4068 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4069 last_unwind_type
= 0;
4073 /* Skip /DISCARD/ sections. */
4074 if (bfd_is_abs_section (exidx_sec
->output_section
))
4077 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
4078 if (hdr
->sh_type
!= SHT_C6000_UNWIND
)
4081 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
4082 if (exidx_data
== NULL
)
4085 ibfd
= exidx_sec
->owner
;
4087 if (hdr
->contents
!= NULL
)
4088 contents
= hdr
->contents
;
4089 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
4093 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
4095 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
4099 /* An EXIDX_CANTUNWIND entry. */
4100 if (second_word
== 1)
4102 if (last_unwind_type
== 0)
4106 /* Inlined unwinding data. Merge if equal to previous. */
4107 else if ((second_word
& 0x80000000) != 0)
4109 if (merge_exidx_entries
4110 && last_second_word
== second_word
4111 && last_unwind_type
== 1)
4114 last_second_word
= second_word
;
4116 /* Normal table entry. In theory we could merge these too,
4117 but duplicate entries are likely to be much less common. */
4123 elf32_tic6x_add_unwind_table_edit (&unwind_edit_head
,
4124 &unwind_edit_tail
, DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
4126 deleted_exidx_bytes
+= 8;
4129 last_unwind_type
= unwind_type
;
4132 /* Free contents if we allocated it ourselves. */
4133 if (contents
!= hdr
->contents
)
4136 /* Record edits to be applied later (in elf32_tic6x_write_section). */
4137 exidx_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
4138 exidx_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
4140 if (deleted_exidx_bytes
> 0)
4141 elf32_tic6x_adjust_exidx_size (exidx_sec
, -deleted_exidx_bytes
);
4143 last_exidx_sec
= exidx_sec
;
4144 last_text_sec
= sec
;
4147 /* Add terminating CANTUNWIND entry. */
4148 if (last_exidx_sec
&& last_unwind_type
!= 0)
4149 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4154 /* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified. */
4156 static unsigned long
4157 elf32_tic6x_add_low31 (unsigned long val
, bfd_vma addend
)
4159 return (val
& ~0x7ffffffful
) | ((val
+ addend
) & 0x7ffffffful
);
4162 /* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
4163 relocations. OFFSET is in bytes, and will be scaled before encoding. */
4167 elf32_tic6x_copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
,
4170 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
4171 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
4174 /* High bit of first word is supposed to be zero. */
4175 if ((first_word
& 0x80000000ul
) == 0)
4176 first_word
= elf32_tic6x_add_low31 (first_word
, offset
);
4178 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
4179 (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry. */
4180 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
4181 second_word
= elf32_tic6x_add_low31 (second_word
, offset
);
4183 bfd_put_32 (output_bfd
, first_word
, to
);
4184 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
4187 /* Do the actual mangling of exception index tables. */
4190 elf32_tic6x_write_section (bfd
*output_bfd
,
4191 struct bfd_link_info
*link_info
,
4195 _tic6x_elf_section_data
*tic6x_data
;
4196 struct elf32_tic6x_link_hash_table
*globals
4197 = elf32_tic6x_hash_table (link_info
);
4198 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4200 if (globals
== NULL
)
4203 /* If this section has not been allocated an _tic6x_elf_section_data
4204 structure then we cannot record anything. */
4205 tic6x_data
= get_tic6x_elf_section_data (sec
);
4206 if (tic6x_data
== NULL
)
4209 if (tic6x_data
->elf
.this_hdr
.sh_type
!= SHT_C6000_UNWIND
)
4212 tic6x_unwind_table_edit
*edit_node
4213 = tic6x_data
->u
.exidx
.unwind_edit_list
;
4214 /* Now, sec->size is the size of the section we will write. The original
4215 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
4216 markers) was sec->rawsize. (This isn't the case if we perform no
4217 edits, then rawsize will be zero and we should use size). */
4218 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
4219 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
4220 unsigned int in_index
, out_index
;
4221 bfd_vma add_to_offsets
= 0;
4223 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
4227 unsigned int edit_index
= edit_node
->index
;
4229 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
4231 elf32_tic6x_copy_exidx_entry (output_bfd
,
4232 edited_contents
+ out_index
* 8,
4233 contents
+ in_index
* 8, add_to_offsets
);
4237 else if (in_index
== edit_index
4238 || (in_index
* 8 >= input_size
4239 && edit_index
== UINT_MAX
))
4241 switch (edit_node
->type
)
4243 case DELETE_EXIDX_ENTRY
:
4245 add_to_offsets
+= 8;
4248 case INSERT_EXIDX_CANTUNWIND_AT_END
:
4250 asection
*text_sec
= edit_node
->linked_section
;
4251 bfd_vma text_offset
= text_sec
->output_section
->vma
4252 + text_sec
->output_offset
4254 bfd_vma exidx_offset
= offset
+ out_index
* 8;
4255 unsigned long prel31_offset
;
4257 /* Note: this is meant to be equivalent to an
4258 R_C6000_PREL31 relocation. These synthetic
4259 EXIDX_CANTUNWIND markers are not relocated by the
4260 usual BFD method. */
4261 prel31_offset
= ((text_offset
- exidx_offset
) >> 1)
4264 /* First address we can't unwind. */
4265 bfd_put_32 (output_bfd
, prel31_offset
,
4266 &edited_contents
[out_index
* 8]);
4268 /* Code for EXIDX_CANTUNWIND. */
4269 bfd_put_32 (output_bfd
, 0x1,
4270 &edited_contents
[out_index
* 8 + 4]);
4273 add_to_offsets
-= 8;
4278 edit_node
= edit_node
->next
;
4283 /* No more edits, copy remaining entries verbatim. */
4284 elf32_tic6x_copy_exidx_entry (output_bfd
,
4285 edited_contents
+ out_index
* 8,
4286 contents
+ in_index
* 8, add_to_offsets
);
4292 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
4293 bfd_set_section_contents (output_bfd
, sec
->output_section
,
4295 (file_ptr
) sec
->output_offset
, sec
->size
);
4300 #define TARGET_LITTLE_SYM tic6x_elf32_le_vec
4301 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
4302 #define TARGET_BIG_SYM tic6x_elf32_be_vec
4303 #define TARGET_BIG_NAME "elf32-tic6x-be"
4304 #define ELF_ARCH bfd_arch_tic6x
4305 #define ELF_TARGET_ID TIC6X_ELF_DATA
4306 #define ELF_MACHINE_CODE EM_TI_C6000
4307 #define ELF_MAXPAGESIZE 0x1000
4308 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
4309 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
4310 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
4311 #define bfd_elf32_mkobject elf32_tic6x_mkobject
4312 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
4313 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
4314 #define elf_backend_stack_align 8
4315 #define elf_backend_can_gc_sections 1
4316 #define elf_backend_default_use_rela_p 1
4317 #define elf_backend_may_use_rel_p 1
4318 #define elf_backend_may_use_rela_p 1
4319 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
4320 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
4321 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
4322 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
4323 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4324 #define elf_backend_obj_attrs_vendor "c6xabi"
4325 #define elf_backend_can_refcount 1
4326 #define elf_backend_want_got_plt 1
4327 #define elf_backend_want_dynbss 1
4328 #define elf_backend_want_dynrelro 1
4329 #define elf_backend_plt_readonly 1
4330 #define elf_backend_rela_normal 1
4331 #define elf_backend_got_header_size 8
4332 #define elf_backend_fake_sections elf32_tic6x_fake_sections
4333 #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
4334 #define elf_backend_create_dynamic_sections \
4335 elf32_tic6x_create_dynamic_sections
4336 #define elf_backend_adjust_dynamic_symbol \
4337 elf32_tic6x_adjust_dynamic_symbol
4338 #define elf_backend_check_relocs elf32_tic6x_check_relocs
4339 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4340 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4341 #define elf_backend_link_output_symbol_hook \
4342 elf32_tic6x_link_output_symbol_hook
4343 #define elf_backend_section_from_bfd_section \
4344 elf32_tic6x_section_from_bfd_section
4345 #define elf_backend_relocate_section elf32_tic6x_relocate_section
4346 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4347 #define elf_backend_finish_dynamic_symbol \
4348 elf32_tic6x_finish_dynamic_symbol
4349 #define elf_backend_always_size_sections \
4350 elf32_tic6x_always_size_sections
4351 #define elf_backend_size_dynamic_sections \
4352 elf32_tic6x_size_dynamic_sections
4353 #define elf_backend_finish_dynamic_sections \
4354 elf32_tic6x_finish_dynamic_sections
4355 #define bfd_elf32_bfd_final_link \
4356 elf32_tic6x_final_link
4357 #define elf_backend_write_section elf32_tic6x_write_section
4358 #define elf_info_to_howto elf32_tic6x_info_to_howto
4359 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
4361 #undef elf_backend_omit_section_dynsym
4362 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4363 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4365 #include "elf32-target.h"
4368 #define elf32_bed elf32_tic6x_linux_bed
4370 #undef TARGET_LITTLE_SYM
4371 #define TARGET_LITTLE_SYM tic6x_elf32_linux_le_vec
4372 #undef TARGET_LITTLE_NAME
4373 #define TARGET_LITTLE_NAME "elf32-tic6x-linux-le"
4374 #undef TARGET_BIG_SYM
4375 #define TARGET_BIG_SYM tic6x_elf32_linux_be_vec
4376 #undef TARGET_BIG_NAME
4377 #define TARGET_BIG_NAME "elf32-tic6x-linux-be"
4379 #define ELF_OSABI ELFOSABI_C6000_LINUX
4381 #include "elf32-target.h"
4384 #define elf32_bed elf32_tic6x_elf_bed
4386 #undef TARGET_LITTLE_SYM
4387 #define TARGET_LITTLE_SYM tic6x_elf32_c6000_le_vec
4388 #undef TARGET_LITTLE_NAME
4389 #define TARGET_LITTLE_NAME "elf32-tic6x-elf-le"
4390 #undef TARGET_BIG_SYM
4391 #define TARGET_BIG_SYM tic6x_elf32_c6000_be_vec
4392 #undef TARGET_BIG_NAME
4393 #define TARGET_BIG_NAME "elf32-tic6x-elf-be"
4395 #define ELF_OSABI ELFOSABI_C6000_ELFABI
4397 #include "elf32-target.h"