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 /* The output BFD, for convenience. */
52 /* The .dsbt section. */
56 /* Get the TI C6X ELF linker hash table from a link_info structure. */
58 #define elf32_tic6x_hash_table(p) \
59 ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
64 INSERT_EXIDX_CANTUNWIND_AT_END
66 tic6x_unwind_edit_type
;
68 /* A (sorted) list of edits to apply to an unwind table. */
69 typedef struct tic6x_unwind_table_edit
71 tic6x_unwind_edit_type type
;
72 /* Note: we sometimes want to insert an unwind entry corresponding to a
73 section different from the one we're currently writing out, so record the
74 (text) section this edit relates to here. */
75 asection
*linked_section
;
77 struct tic6x_unwind_table_edit
*next
;
79 tic6x_unwind_table_edit
;
81 typedef struct _tic6x_elf_section_data
83 /* Information about mapping symbols. */
84 struct bfd_elf_section_data elf
;
85 /* Information about unwind tables. */
88 /* Unwind info attached to a text section. */
91 asection
*tic6x_exidx_sec
;
94 /* Unwind info attached to an .c6xabi.exidx section. */
97 tic6x_unwind_table_edit
*unwind_edit_list
;
98 tic6x_unwind_table_edit
*unwind_edit_tail
;
102 _tic6x_elf_section_data
;
104 #define elf32_tic6x_section_data(sec) \
105 ((_tic6x_elf_section_data *) elf_section_data (sec))
107 struct elf32_tic6x_obj_tdata
109 struct elf_obj_tdata root
;
111 /* Whether to use RELA relocations when generating relocations.
112 This is a per-object flag to allow the assembler to generate REL
113 relocations for use in linker testcases. */
114 bfd_boolean use_rela_p
;
117 #define elf32_tic6x_tdata(abfd) \
118 ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
120 #define is_tic6x_elf(bfd) \
121 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
122 && elf_tdata (bfd) != NULL \
123 && elf_object_id (bfd) == TIC6X_ELF_DATA)
125 /* C6X ELF uses two common sections. One is the usual one, and the
126 other is for small objects. All the small objects are kept
127 together, and then referenced via the gp pointer, which yields
128 faster assembler code. This is what we use for the small common
129 section. This approach is copied from ecoff.c. */
130 static asection tic6x_elf_scom_section
;
131 static asymbol tic6x_elf_scom_symbol
;
132 static asymbol
*tic6x_elf_scom_symbol_ptr
;
134 static reloc_howto_type elf32_tic6x_howto_table
[] =
136 HOWTO (R_C6000_NONE
, /* type */
138 3, /* size (0 = byte, 1 = short, 2 = long) */
140 FALSE
, /* pc_relative */
142 complain_overflow_dont
,/* complain_on_overflow */
143 bfd_elf_generic_reloc
, /* special_function */
144 "R_C6000_NONE", /* name */
145 FALSE
, /* partial_inplace */
148 FALSE
), /* pcrel_offset */
149 HOWTO (R_C6000_ABS32
, /* type */
151 2, /* size (0 = byte, 1 = short, 2 = long) */
153 FALSE
, /* pc_relative */
155 complain_overflow_dont
,/* complain_on_overflow */
156 bfd_elf_generic_reloc
, /* special_function */
157 "R_C6000_ABS32", /* name */
158 FALSE
, /* partial_inplace */
160 0xffffffff, /* dst_mask */
161 FALSE
), /* pcrel_offset */
162 HOWTO (R_C6000_ABS16
, /* type */
164 1, /* size (0 = byte, 1 = short, 2 = long) */
166 FALSE
, /* pc_relative */
168 complain_overflow_bitfield
,/* complain_on_overflow */
169 bfd_elf_generic_reloc
, /* special_function */
170 "R_C6000_ABS16", /* name */
171 FALSE
, /* partial_inplace */
173 0x0000ffff, /* dst_mask */
174 FALSE
), /* pcrel_offset */
175 HOWTO (R_C6000_ABS8
, /* type */
177 0, /* size (0 = byte, 1 = short, 2 = long) */
179 FALSE
, /* pc_relative */
181 complain_overflow_bitfield
,/* complain_on_overflow */
182 bfd_elf_generic_reloc
, /* special_function */
183 "R_C6000_ABS8", /* name */
184 FALSE
, /* partial_inplace */
186 0x000000ff, /* dst_mask */
187 FALSE
), /* pcrel_offset */
188 HOWTO (R_C6000_PCR_S21
, /* type */
190 2, /* size (0 = byte, 1 = short, 2 = long) */
192 TRUE
, /* pc_relative */
194 complain_overflow_signed
,/* complain_on_overflow */
195 bfd_elf_generic_reloc
, /* special_function */
196 "R_C6000_PCR_S21", /* name */
197 FALSE
, /* partial_inplace */
199 0x0fffff80, /* dst_mask */
200 TRUE
), /* pcrel_offset */
201 HOWTO (R_C6000_PCR_S12
, /* type */
203 2, /* size (0 = byte, 1 = short, 2 = long) */
205 TRUE
, /* pc_relative */
207 complain_overflow_signed
,/* complain_on_overflow */
208 bfd_elf_generic_reloc
, /* special_function */
209 "R_C6000_PCR_S12", /* name */
210 FALSE
, /* partial_inplace */
212 0x0fff0000, /* dst_mask */
213 TRUE
), /* pcrel_offset */
214 HOWTO (R_C6000_PCR_S10
, /* type */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
218 TRUE
, /* pc_relative */
220 complain_overflow_signed
,/* complain_on_overflow */
221 bfd_elf_generic_reloc
, /* special_function */
222 "R_C6000_PCR_S10", /* name */
223 FALSE
, /* partial_inplace */
225 0x007fe000, /* dst_mask */
226 TRUE
), /* pcrel_offset */
227 HOWTO (R_C6000_PCR_S7
, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 TRUE
, /* pc_relative */
233 complain_overflow_signed
,/* complain_on_overflow */
234 bfd_elf_generic_reloc
, /* special_function */
235 "R_C6000_PCR_S7", /* name */
236 FALSE
, /* partial_inplace */
238 0x007f0000, /* dst_mask */
239 TRUE
), /* pcrel_offset */
240 HOWTO (R_C6000_ABS_S16
, /* type */
242 2, /* size (0 = byte, 1 = short, 2 = long) */
244 FALSE
, /* pc_relative */
246 complain_overflow_signed
,/* complain_on_overflow */
247 bfd_elf_generic_reloc
, /* special_function */
248 "R_C6000_ABS_S16", /* name */
249 FALSE
, /* partial_inplace */
251 0x007fff80, /* dst_mask */
252 FALSE
), /* pcrel_offset */
253 HOWTO (R_C6000_ABS_L16
, /* type */
255 2, /* size (0 = byte, 1 = short, 2 = long) */
257 FALSE
, /* pc_relative */
259 complain_overflow_dont
,/* complain_on_overflow */
260 bfd_elf_generic_reloc
, /* special_function */
261 "R_C6000_ABS_L16", /* name */
262 FALSE
, /* partial_inplace */
264 0x007fff80, /* dst_mask */
265 FALSE
), /* pcrel_offset */
266 HOWTO (R_C6000_ABS_H16
, /* type */
268 2, /* size (0 = byte, 1 = short, 2 = long) */
270 FALSE
, /* pc_relative */
272 complain_overflow_dont
,/* complain_on_overflow */
273 bfd_elf_generic_reloc
, /* special_function */
274 "R_C6000_ABS_H16", /* name */
275 FALSE
, /* partial_inplace */
277 0x007fff80, /* dst_mask */
278 FALSE
), /* pcrel_offset */
279 HOWTO (R_C6000_SBR_U15_B
, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 FALSE
, /* pc_relative */
285 complain_overflow_unsigned
,/* complain_on_overflow */
286 bfd_elf_generic_reloc
, /* special_function */
287 "R_C6000_SBR_U15_B", /* name */
288 FALSE
, /* partial_inplace */
290 0x007fff00, /* dst_mask */
291 FALSE
), /* pcrel_offset */
292 HOWTO (R_C6000_SBR_U15_H
, /* type */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
296 FALSE
, /* pc_relative */
298 complain_overflow_unsigned
,/* complain_on_overflow */
299 bfd_elf_generic_reloc
, /* special_function */
300 "R_C6000_SBR_U15_H", /* name */
301 FALSE
, /* partial_inplace */
303 0x007fff00, /* dst_mask */
304 FALSE
), /* pcrel_offset */
305 HOWTO (R_C6000_SBR_U15_W
, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 FALSE
, /* pc_relative */
311 complain_overflow_unsigned
,/* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_C6000_SBR_U15_W", /* name */
314 FALSE
, /* partial_inplace */
316 0x007fff00, /* dst_mask */
317 FALSE
), /* pcrel_offset */
318 HOWTO (R_C6000_SBR_S16
, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 FALSE
, /* pc_relative */
324 complain_overflow_signed
,/* complain_on_overflow */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_C6000_SBR_S16", /* name */
327 FALSE
, /* partial_inplace */
329 0x007fff80, /* dst_mask */
330 FALSE
), /* pcrel_offset */
331 HOWTO (R_C6000_SBR_L16_B
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE
, /* pc_relative */
337 complain_overflow_dont
,/* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_C6000_SBR_L16_B", /* name */
340 FALSE
, /* partial_inplace */
342 0x007fff80, /* dst_mask */
343 FALSE
), /* pcrel_offset */
344 HOWTO (R_C6000_SBR_L16_H
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 FALSE
, /* pc_relative */
350 complain_overflow_dont
,/* complain_on_overflow */
351 bfd_elf_generic_reloc
, /* special_function */
352 "R_C6000_SBR_L16_H", /* name */
353 FALSE
, /* partial_inplace */
355 0x007fff80, /* dst_mask */
356 FALSE
), /* pcrel_offset */
357 HOWTO (R_C6000_SBR_L16_W
, /* type */
359 2, /* size (0 = byte, 1 = short, 2 = long) */
361 FALSE
, /* pc_relative */
363 complain_overflow_dont
,/* complain_on_overflow */
364 bfd_elf_generic_reloc
, /* special_function */
365 "R_C6000_SBR_L16_W", /* name */
366 FALSE
, /* partial_inplace */
368 0x007fff80, /* dst_mask */
369 FALSE
), /* pcrel_offset */
370 HOWTO (R_C6000_SBR_H16_B
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE
, /* pc_relative */
376 complain_overflow_dont
,/* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_C6000_SBR_H16_B", /* name */
379 FALSE
, /* partial_inplace */
381 0x007fff80, /* dst_mask */
382 FALSE
), /* pcrel_offset */
383 HOWTO (R_C6000_SBR_H16_H
, /* type */
385 2, /* size (0 = byte, 1 = short, 2 = long) */
387 FALSE
, /* pc_relative */
389 complain_overflow_dont
,/* complain_on_overflow */
390 bfd_elf_generic_reloc
, /* special_function */
391 "R_C6000_SBR_H16_H", /* name */
392 FALSE
, /* partial_inplace */
394 0x007fff80, /* dst_mask */
395 FALSE
), /* pcrel_offset */
396 HOWTO (R_C6000_SBR_H16_W
, /* type */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 FALSE
, /* pc_relative */
402 complain_overflow_dont
,/* complain_on_overflow */
403 bfd_elf_generic_reloc
, /* special_function */
404 "R_C6000_SBR_H16_W", /* name */
405 FALSE
, /* partial_inplace */
407 0x007fff80, /* dst_mask */
408 FALSE
), /* pcrel_offset */
409 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE
, /* pc_relative */
415 complain_overflow_unsigned
,/* complain_on_overflow */
416 bfd_elf_generic_reloc
, /* special_function */
417 "R_C6000_SBR_GOT_U15_W",/* name */
418 FALSE
, /* partial_inplace */
420 0x007fff00, /* dst_mask */
421 FALSE
), /* pcrel_offset */
422 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE
, /* pc_relative */
428 complain_overflow_dont
,/* complain_on_overflow */
429 bfd_elf_generic_reloc
, /* special_function */
430 "R_C6000_SBR_GOT_L16_W",/* name */
431 FALSE
, /* partial_inplace */
433 0x007fff80, /* dst_mask */
434 FALSE
), /* pcrel_offset */
435 HOWTO (R_C6000_SBR_GOT_H16_W
, /* type */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
439 FALSE
, /* pc_relative */
441 complain_overflow_dont
,/* complain_on_overflow */
442 bfd_elf_generic_reloc
, /* special_function */
443 "R_C6000_SBR_GOT_H16_W",/* name */
444 FALSE
, /* partial_inplace */
446 0x007fff80, /* dst_mask */
447 FALSE
), /* pcrel_offset */
448 HOWTO (R_C6000_DSBT_INDEX
, /* type */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 FALSE
, /* pc_relative */
454 complain_overflow_unsigned
,/* complain_on_overflow */
455 bfd_elf_generic_reloc
, /* special_function */
456 "R_C6000_DSBT_INDEX", /* name */
457 FALSE
, /* partial_inplace */
459 0x007fff00, /* dst_mask */
460 FALSE
), /* pcrel_offset */
461 HOWTO (R_C6000_PREL31
, /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 TRUE
, /* pc_relative */
467 complain_overflow_dont
,/* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 "R_C6000_PREL31", /* name */
470 FALSE
, /* partial_inplace */
472 0x7fffffff, /* dst_mask */
473 TRUE
), /* pcrel_offset */
474 HOWTO (R_C6000_COPY
, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 FALSE
, /* pc_relative */
480 complain_overflow_dont
,/* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_C6000_COPY", /* name */
483 FALSE
, /* partial_inplace */
485 0xffffffff, /* dst_mask */
486 FALSE
), /* pcrel_offset */
487 HOWTO (R_C6000_JUMP_SLOT
, /* type */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
491 FALSE
, /* pc_relative */
493 complain_overflow_dont
,/* complain_on_overflow */
494 bfd_elf_generic_reloc
, /* special_function */
495 "R_C6000_JUMP_SLOT", /* name */
496 FALSE
, /* partial_inplace */
498 0xffffffff, /* dst_mask */
499 FALSE
), /* pcrel_offset */
500 HOWTO (R_C6000_EHTYPE
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE
, /* pc_relative */
506 complain_overflow_dont
,/* complain_on_overflow */
507 bfd_elf_generic_reloc
, /* special_function */
508 "R_C6000_EHTYPE", /* name */
509 FALSE
, /* partial_inplace */
511 0xffffffff, /* dst_mask */
512 FALSE
), /* pcrel_offset */
513 HOWTO (R_C6000_PCR_H16
, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 TRUE
, /* pc_relative */
519 complain_overflow_dont
,/* complain_on_overflow */
520 bfd_elf_generic_reloc
, /* special_function */
521 "R_C6000_PCR_H16", /* name */
522 FALSE
, /* partial_inplace */
524 0x007fff80, /* dst_mask */
525 TRUE
), /* pcrel_offset */
526 HOWTO (R_C6000_PCR_L16
, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 TRUE
, /* pc_relative */
532 complain_overflow_dont
,/* complain_on_overflow */
533 bfd_elf_generic_reloc
, /* special_function */
534 "R_C6000_PCR_L16", /* name */
535 FALSE
, /* partial_inplace */
537 0x007fff80, /* dst_mask */
538 TRUE
), /* pcrel_offset */
761 HOWTO (R_C6000_ALIGN
, /* type */
763 0, /* size (0 = byte, 1 = short, 2 = long) */
765 FALSE
, /* pc_relative */
767 complain_overflow_dont
,/* complain_on_overflow */
768 bfd_elf_generic_reloc
, /* special_function */
769 "R_C6000_ALIGN", /* name */
770 FALSE
, /* partial_inplace */
773 FALSE
), /* pcrel_offset */
774 HOWTO (R_C6000_FPHEAD
, /* type */
776 0, /* size (0 = byte, 1 = short, 2 = long) */
778 FALSE
, /* pc_relative */
780 complain_overflow_dont
,/* complain_on_overflow */
781 bfd_elf_generic_reloc
, /* special_function */
782 "R_C6000_FPHEAD", /* name */
783 FALSE
, /* partial_inplace */
786 FALSE
), /* pcrel_offset */
787 HOWTO (R_C6000_NOCMP
, /* type */
789 0, /* size (0 = byte, 1 = short, 2 = long) */
791 FALSE
, /* pc_relative */
793 complain_overflow_dont
,/* complain_on_overflow */
794 bfd_elf_generic_reloc
, /* special_function */
795 "R_C6000_NOCMP", /* name */
796 FALSE
, /* partial_inplace */
799 FALSE
) /* pcrel_offset */
802 static reloc_howto_type elf32_tic6x_howto_table_rel
[] =
804 HOWTO (R_C6000_NONE
, /* type */
806 3, /* size (0 = byte, 1 = short, 2 = long) */
808 FALSE
, /* pc_relative */
810 complain_overflow_dont
,/* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_C6000_NONE", /* name */
813 TRUE
, /* partial_inplace */
816 FALSE
), /* pcrel_offset */
817 HOWTO (R_C6000_ABS32
, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 FALSE
, /* pc_relative */
823 complain_overflow_dont
,/* complain_on_overflow */
824 bfd_elf_generic_reloc
, /* special_function */
825 "R_C6000_ABS32", /* name */
826 TRUE
, /* partial_inplace */
827 0xffffffff, /* src_mask */
828 0xffffffff, /* dst_mask */
829 FALSE
), /* pcrel_offset */
830 HOWTO (R_C6000_ABS16
, /* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE
, /* pc_relative */
836 complain_overflow_bitfield
,/* complain_on_overflow */
837 bfd_elf_generic_reloc
, /* special_function */
838 "R_C6000_ABS16", /* name */
839 TRUE
, /* partial_inplace */
840 0x0000ffff, /* src_mask */
841 0x0000ffff, /* dst_mask */
842 FALSE
), /* pcrel_offset */
843 HOWTO (R_C6000_ABS8
, /* type */
845 0, /* size (0 = byte, 1 = short, 2 = long) */
847 FALSE
, /* pc_relative */
849 complain_overflow_bitfield
,/* complain_on_overflow */
850 bfd_elf_generic_reloc
, /* special_function */
851 "R_C6000_ABS8", /* name */
852 TRUE
, /* partial_inplace */
853 0x000000ff, /* src_mask */
854 0x000000ff, /* dst_mask */
855 FALSE
), /* pcrel_offset */
856 HOWTO (R_C6000_PCR_S21
, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 TRUE
, /* pc_relative */
862 complain_overflow_signed
,/* complain_on_overflow */
863 bfd_elf_generic_reloc
, /* special_function */
864 "R_C6000_PCR_S21", /* name */
865 TRUE
, /* partial_inplace */
866 0x0fffff80, /* src_mask */
867 0x0fffff80, /* dst_mask */
868 TRUE
), /* pcrel_offset */
869 HOWTO (R_C6000_PCR_S12
, /* type */
871 2, /* size (0 = byte, 1 = short, 2 = long) */
873 TRUE
, /* pc_relative */
875 complain_overflow_signed
,/* complain_on_overflow */
876 bfd_elf_generic_reloc
, /* special_function */
877 "R_C6000_PCR_S12", /* name */
878 TRUE
, /* partial_inplace */
879 0x0fff0000, /* src_mask */
880 0x0fff0000, /* dst_mask */
881 TRUE
), /* pcrel_offset */
882 HOWTO (R_C6000_PCR_S10
, /* type */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
886 TRUE
, /* pc_relative */
888 complain_overflow_signed
,/* complain_on_overflow */
889 bfd_elf_generic_reloc
, /* special_function */
890 "R_C6000_PCR_S10", /* name */
891 TRUE
, /* partial_inplace */
892 0x007fe000, /* src_mask */
893 0x007fe000, /* dst_mask */
894 TRUE
), /* pcrel_offset */
895 HOWTO (R_C6000_PCR_S7
, /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 TRUE
, /* pc_relative */
901 complain_overflow_signed
,/* complain_on_overflow */
902 bfd_elf_generic_reloc
, /* special_function */
903 "R_C6000_PCR_S7", /* name */
904 TRUE
, /* partial_inplace */
905 0x007f0000, /* src_mask */
906 0x007f0000, /* dst_mask */
907 TRUE
), /* pcrel_offset */
908 HOWTO (R_C6000_ABS_S16
, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_signed
,/* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* special_function */
916 "R_C6000_ABS_S16", /* name */
917 TRUE
, /* partial_inplace */
918 0x007fff80, /* src_mask */
919 0x007fff80, /* dst_mask */
920 FALSE
), /* pcrel_offset */
921 HOWTO (R_C6000_ABS_L16
, /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_dont
,/* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 "R_C6000_ABS_L16", /* name */
930 TRUE
, /* partial_inplace */
931 0x007fff80, /* src_mask */
932 0x007fff80, /* dst_mask */
933 FALSE
), /* pcrel_offset */
934 EMPTY_HOWTO (R_C6000_ABS_H16
),
935 HOWTO (R_C6000_SBR_U15_B
, /* type */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
939 FALSE
, /* pc_relative */
941 complain_overflow_unsigned
,/* complain_on_overflow */
942 bfd_elf_generic_reloc
, /* special_function */
943 "R_C6000_SBR_U15_B", /* name */
944 TRUE
, /* partial_inplace */
945 0x007fff00, /* src_mask */
946 0x007fff00, /* dst_mask */
947 FALSE
), /* pcrel_offset */
948 HOWTO (R_C6000_SBR_U15_H
, /* type */
950 2, /* size (0 = byte, 1 = short, 2 = long) */
952 FALSE
, /* pc_relative */
954 complain_overflow_unsigned
,/* complain_on_overflow */
955 bfd_elf_generic_reloc
, /* special_function */
956 "R_C6000_SBR_U15_H", /* name */
957 TRUE
, /* partial_inplace */
958 0x007fff00, /* src_mask */
959 0x007fff00, /* dst_mask */
960 FALSE
), /* pcrel_offset */
961 HOWTO (R_C6000_SBR_U15_W
, /* type */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
965 FALSE
, /* pc_relative */
967 complain_overflow_unsigned
,/* complain_on_overflow */
968 bfd_elf_generic_reloc
, /* special_function */
969 "R_C6000_SBR_U15_W", /* name */
970 TRUE
, /* partial_inplace */
971 0x007fff00, /* src_mask */
972 0x007fff00, /* dst_mask */
973 FALSE
), /* pcrel_offset */
974 HOWTO (R_C6000_SBR_S16
, /* type */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
978 FALSE
, /* pc_relative */
980 complain_overflow_signed
,/* complain_on_overflow */
981 bfd_elf_generic_reloc
, /* special_function */
982 "R_C6000_SBR_S16", /* name */
983 TRUE
, /* partial_inplace */
984 0x007fff80, /* src_mask */
985 0x007fff80, /* dst_mask */
986 FALSE
), /* pcrel_offset */
987 HOWTO (R_C6000_SBR_L16_B
, /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 FALSE
, /* pc_relative */
993 complain_overflow_dont
,/* complain_on_overflow */
994 bfd_elf_generic_reloc
, /* special_function */
995 "R_C6000_SBR_L16_B", /* name */
996 TRUE
, /* partial_inplace */
997 0x007fff80, /* src_mask */
998 0x007fff80, /* dst_mask */
999 FALSE
), /* pcrel_offset */
1000 HOWTO (R_C6000_SBR_L16_H
, /* type */
1002 2, /* size (0 = byte, 1 = short, 2 = long) */
1004 FALSE
, /* pc_relative */
1006 complain_overflow_dont
,/* complain_on_overflow */
1007 bfd_elf_generic_reloc
, /* special_function */
1008 "R_C6000_SBR_L16_H", /* name */
1009 TRUE
, /* partial_inplace */
1010 0x007fff80, /* src_mask */
1011 0x007fff80, /* dst_mask */
1012 FALSE
), /* pcrel_offset */
1013 HOWTO (R_C6000_SBR_L16_W
, /* type */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_dont
,/* complain_on_overflow */
1020 bfd_elf_generic_reloc
, /* special_function */
1021 "R_C6000_SBR_L16_W", /* name */
1022 TRUE
, /* partial_inplace */
1023 0x007fff80, /* src_mask */
1024 0x007fff80, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1026 EMPTY_HOWTO (R_C6000_SBR_H16_B
),
1027 EMPTY_HOWTO (R_C6000_SBR_H16_H
),
1028 EMPTY_HOWTO (R_C6000_SBR_H16_W
),
1029 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_unsigned
,/* complain_on_overflow */
1036 bfd_elf_generic_reloc
, /* special_function */
1037 "R_C6000_SBR_GOT_U15_W",/* name */
1038 TRUE
, /* partial_inplace */
1039 0x007fff00, /* src_mask */
1040 0x007fff00, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1042 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
1044 2, /* size (0 = byte, 1 = short, 2 = long) */
1046 FALSE
, /* pc_relative */
1048 complain_overflow_dont
,/* complain_on_overflow */
1049 bfd_elf_generic_reloc
, /* special_function */
1050 "R_C6000_SBR_GOT_L16_W",/* name */
1051 TRUE
, /* partial_inplace */
1052 0x007fff80, /* src_mask */
1053 0x007fff80, /* dst_mask */
1054 FALSE
), /* pcrel_offset */
1055 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W
),
1056 HOWTO (R_C6000_DSBT_INDEX
, /* type */
1058 2, /* size (0 = byte, 1 = short, 2 = long) */
1060 FALSE
, /* pc_relative */
1062 complain_overflow_unsigned
,/* complain_on_overflow */
1063 bfd_elf_generic_reloc
, /* special_function */
1064 "R_C6000_DSBT_INDEX", /* name */
1065 TRUE
, /* partial_inplace */
1067 0x007fff00, /* dst_mask */
1068 FALSE
), /* pcrel_offset */
1069 HOWTO (R_C6000_PREL31
, /* type */
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 TRUE
, /* pc_relative */
1075 complain_overflow_dont
,/* complain_on_overflow */
1076 bfd_elf_generic_reloc
, /* special_function */
1077 "R_C6000_PREL31", /* name */
1078 TRUE
, /* partial_inplace */
1080 0x7fffffff, /* dst_mask */
1081 TRUE
), /* pcrel_offset */
1082 HOWTO (R_C6000_COPY
, /* type */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1086 FALSE
, /* pc_relative */
1088 complain_overflow_dont
,/* complain_on_overflow */
1089 bfd_elf_generic_reloc
, /* special_function */
1090 "R_C6000_COPY", /* name */
1091 TRUE
, /* partial_inplace */
1093 0xffffffff, /* dst_mask */
1094 FALSE
), /* pcrel_offset */
1095 HOWTO (R_C6000_JUMP_SLOT
, /* type */
1097 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 FALSE
, /* pc_relative */
1101 complain_overflow_dont
,/* complain_on_overflow */
1102 bfd_elf_generic_reloc
, /* special_function */
1103 "R_C6000_JUMP_SLOT", /* name */
1104 FALSE
, /* partial_inplace */
1106 0xffffffff, /* dst_mask */
1107 FALSE
), /* pcrel_offset */
1108 HOWTO (R_C6000_EHTYPE
, /* type */
1110 2, /* size (0 = byte, 1 = short, 2 = long) */
1112 FALSE
, /* pc_relative */
1114 complain_overflow_dont
,/* complain_on_overflow */
1115 bfd_elf_generic_reloc
, /* special_function */
1116 "R_C6000_EHTYPE", /* name */
1117 FALSE
, /* partial_inplace */
1119 0xffffffff, /* dst_mask */
1120 FALSE
), /* pcrel_offset */
1121 EMPTY_HOWTO (R_C6000_PCR_H16
),
1122 EMPTY_HOWTO (R_C6000_PCR_L16
),
1345 HOWTO (R_C6000_ALIGN
, /* type */
1347 0, /* size (0 = byte, 1 = short, 2 = long) */
1349 FALSE
, /* pc_relative */
1351 complain_overflow_dont
,/* complain_on_overflow */
1352 bfd_elf_generic_reloc
, /* special_function */
1353 "R_C6000_ALIGN", /* name */
1354 TRUE
, /* partial_inplace */
1357 FALSE
), /* pcrel_offset */
1358 HOWTO (R_C6000_FPHEAD
, /* type */
1360 0, /* size (0 = byte, 1 = short, 2 = long) */
1362 FALSE
, /* pc_relative */
1364 complain_overflow_dont
,/* complain_on_overflow */
1365 bfd_elf_generic_reloc
, /* special_function */
1366 "R_C6000_FPHEAD", /* name */
1367 TRUE
, /* partial_inplace */
1370 FALSE
), /* pcrel_offset */
1371 HOWTO (R_C6000_NOCMP
, /* type */
1373 0, /* size (0 = byte, 1 = short, 2 = long) */
1375 FALSE
, /* pc_relative */
1377 complain_overflow_dont
,/* complain_on_overflow */
1378 bfd_elf_generic_reloc
, /* special_function */
1379 "R_C6000_NOCMP", /* name */
1380 TRUE
, /* partial_inplace */
1383 FALSE
) /* pcrel_offset */
1386 /* Map BFD relocations to ELF relocations. */
1390 bfd_reloc_code_real_type bfd_reloc_val
;
1391 enum elf_tic6x_reloc_type elf_reloc_val
;
1394 static const tic6x_reloc_map elf32_tic6x_reloc_map
[] =
1396 { BFD_RELOC_NONE
, R_C6000_NONE
},
1397 { BFD_RELOC_32
, R_C6000_ABS32
},
1398 { BFD_RELOC_16
, R_C6000_ABS16
},
1399 { BFD_RELOC_8
, R_C6000_ABS8
},
1400 { BFD_RELOC_C6000_PCR_S21
, R_C6000_PCR_S21
},
1401 { BFD_RELOC_C6000_PCR_S12
, R_C6000_PCR_S12
},
1402 { BFD_RELOC_C6000_PCR_S10
, R_C6000_PCR_S10
},
1403 { BFD_RELOC_C6000_PCR_S7
, R_C6000_PCR_S7
},
1404 { BFD_RELOC_C6000_ABS_S16
, R_C6000_ABS_S16
},
1405 { BFD_RELOC_C6000_ABS_L16
, R_C6000_ABS_L16
},
1406 { BFD_RELOC_C6000_ABS_H16
, R_C6000_ABS_H16
},
1407 { BFD_RELOC_C6000_SBR_U15_B
, R_C6000_SBR_U15_B
},
1408 { BFD_RELOC_C6000_SBR_U15_H
, R_C6000_SBR_U15_H
},
1409 { BFD_RELOC_C6000_SBR_U15_W
, R_C6000_SBR_U15_W
},
1410 { BFD_RELOC_C6000_SBR_S16
, R_C6000_SBR_S16
},
1411 { BFD_RELOC_C6000_SBR_L16_B
, R_C6000_SBR_L16_B
},
1412 { BFD_RELOC_C6000_SBR_L16_H
, R_C6000_SBR_L16_H
},
1413 { BFD_RELOC_C6000_SBR_L16_W
, R_C6000_SBR_L16_W
},
1414 { BFD_RELOC_C6000_SBR_H16_B
, R_C6000_SBR_H16_B
},
1415 { BFD_RELOC_C6000_SBR_H16_H
, R_C6000_SBR_H16_H
},
1416 { BFD_RELOC_C6000_SBR_H16_W
, R_C6000_SBR_H16_W
},
1417 { BFD_RELOC_C6000_SBR_GOT_U15_W
, R_C6000_SBR_GOT_U15_W
},
1418 { BFD_RELOC_C6000_SBR_GOT_L16_W
, R_C6000_SBR_GOT_L16_W
},
1419 { BFD_RELOC_C6000_SBR_GOT_H16_W
, R_C6000_SBR_GOT_H16_W
},
1420 { BFD_RELOC_C6000_DSBT_INDEX
, R_C6000_DSBT_INDEX
},
1421 { BFD_RELOC_C6000_PREL31
, R_C6000_PREL31
},
1422 { BFD_RELOC_C6000_COPY
, R_C6000_COPY
},
1423 { BFD_RELOC_C6000_JUMP_SLOT
, R_C6000_JUMP_SLOT
},
1424 { BFD_RELOC_C6000_EHTYPE
, R_C6000_EHTYPE
},
1425 { BFD_RELOC_C6000_PCR_H16
, R_C6000_PCR_H16
},
1426 { BFD_RELOC_C6000_PCR_L16
, R_C6000_PCR_L16
},
1427 { BFD_RELOC_C6000_ALIGN
, R_C6000_ALIGN
},
1428 { BFD_RELOC_C6000_FPHEAD
, R_C6000_FPHEAD
},
1429 { BFD_RELOC_C6000_NOCMP
, R_C6000_NOCMP
}
1432 static reloc_howto_type
*
1433 elf32_tic6x_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1437 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_reloc_map
); i
++)
1438 if (elf32_tic6x_reloc_map
[i
].bfd_reloc_val
== code
)
1440 enum elf_tic6x_reloc_type elf_reloc_val
;
1441 reloc_howto_type
*howto
;
1443 elf_reloc_val
= elf32_tic6x_reloc_map
[i
].elf_reloc_val
;
1444 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1445 howto
= &elf32_tic6x_howto_table
[elf_reloc_val
];
1447 howto
= &elf32_tic6x_howto_table_rel
[elf_reloc_val
];
1449 /* Some relocations are RELA-only; do not return them for
1451 if (howto
->name
== NULL
)
1460 static reloc_howto_type
*
1461 elf32_tic6x_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1463 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1467 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table
); i
++)
1468 if (elf32_tic6x_howto_table
[i
].name
!= NULL
1469 && strcasecmp (elf32_tic6x_howto_table
[i
].name
, r_name
) == 0)
1470 return &elf32_tic6x_howto_table
[i
];
1476 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table_rel
); i
++)
1477 if (elf32_tic6x_howto_table_rel
[i
].name
!= NULL
1478 && strcasecmp (elf32_tic6x_howto_table_rel
[i
].name
, r_name
) == 0)
1479 return &elf32_tic6x_howto_table_rel
[i
];
1486 elf32_tic6x_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1487 Elf_Internal_Rela
*elf_reloc
)
1489 unsigned int r_type
;
1491 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1492 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table
))
1494 /* xgettext:c-format */
1495 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1497 bfd_set_error (bfd_error_bad_value
);
1501 bfd_reloc
->howto
= &elf32_tic6x_howto_table
[r_type
];
1502 if (bfd_reloc
->howto
== NULL
|| bfd_reloc
->howto
->name
== NULL
)
1504 /* xgettext:c-format */
1505 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1507 bfd_set_error (bfd_error_bad_value
);
1515 elf32_tic6x_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1516 Elf_Internal_Rela
*elf_reloc
)
1518 unsigned int r_type
;
1520 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1521 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table_rel
))
1523 /* xgettext:c-format */
1524 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1526 bfd_set_error (bfd_error_bad_value
);
1530 bfd_reloc
->howto
= &elf32_tic6x_howto_table_rel
[r_type
];
1531 if (bfd_reloc
->howto
== NULL
|| bfd_reloc
->howto
->name
== NULL
)
1533 /* xgettext:c-format */
1534 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1536 bfd_set_error (bfd_error_bad_value
);
1544 elf32_tic6x_set_use_rela_p (bfd
*abfd
, bfd_boolean use_rela_p
)
1546 elf32_tic6x_tdata (abfd
)->use_rela_p
= use_rela_p
;
1549 /* Create a C6X ELF linker hash table. */
1551 static struct bfd_link_hash_table
*
1552 elf32_tic6x_link_hash_table_create (bfd
*abfd
)
1554 struct elf32_tic6x_link_hash_table
*ret
;
1555 size_t amt
= sizeof (struct elf32_tic6x_link_hash_table
);
1557 ret
= bfd_zmalloc (amt
);
1561 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1562 _bfd_elf_link_hash_newfunc
,
1563 sizeof (struct elf_link_hash_entry
),
1571 ret
->elf
.is_relocatable_executable
= 1;
1573 return &ret
->elf
.root
;
1577 elf32_tic6x_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
1579 if (bfd_link_pic (info
))
1581 obj_attribute
*out_attr
;
1582 out_attr
= elf_known_obj_attributes_proc (abfd
);
1583 if (out_attr
[Tag_ABI_PIC
].i
== 0)
1585 _bfd_error_handler (_("warning: generating a shared library "
1586 "containing non-PIC code"));
1588 if (out_attr
[Tag_ABI_PID
].i
== 0)
1590 _bfd_error_handler (_("warning: generating a shared library "
1591 "containing non-PID code"));
1594 /* Invoke the regular ELF backend linker to do all the work. */
1595 if (!bfd_elf_final_link (abfd
, info
))
1601 /* Called to pass PARAMS to the backend. We store them in the hash table
1602 associated with INFO. */
1605 elf32_tic6x_setup (struct bfd_link_info
*info
,
1606 struct elf32_tic6x_params
*params
)
1608 struct elf32_tic6x_link_hash_table
*htab
= elf32_tic6x_hash_table (info
);
1609 htab
->params
= *params
;
1612 /* Determine if we're dealing with a DSBT object. */
1615 elf32_tic6x_using_dsbt (bfd
*abfd
)
1617 return bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
,
1621 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1622 sections in DYNOBJ, and set up shortcuts to them in our hash
1626 elf32_tic6x_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1628 struct elf32_tic6x_link_hash_table
*htab
;
1631 htab
= elf32_tic6x_hash_table (info
);
1635 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1639 flags
= (SEC_ALLOC
| SEC_LOAD
1640 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1641 htab
->dsbt
= bfd_make_section_anyway_with_flags (dynobj
, ".dsbt",
1643 if (htab
->dsbt
== NULL
1644 || !bfd_set_section_alignment (htab
->dsbt
, 2)
1645 || !bfd_set_section_alignment (htab
->elf
.splt
, 5))
1652 elf32_tic6x_mkobject (bfd
*abfd
)
1656 ret
= bfd_elf_allocate_object (abfd
, sizeof (struct elf32_tic6x_obj_tdata
),
1659 elf32_tic6x_set_use_rela_p (abfd
, TRUE
);
1663 /* Install relocation RELA into section SRELA, incrementing its
1667 elf32_tic6x_install_rela (bfd
*output_bfd
, asection
*srela
,
1668 Elf_Internal_Rela
*rela
)
1671 bfd_vma off
= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1672 loc
= srela
->contents
+ off
;
1673 BFD_ASSERT (off
< srela
->size
);
1674 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
1677 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1678 of the GOT at this offset have been initialized with the relocation. */
1681 elf32_tic6x_make_got_dynreloc (bfd
*output_bfd
,
1682 struct elf32_tic6x_link_hash_table
*htab
,
1683 asection
*sym_sec
, bfd_vma offset
)
1685 asection
*sgot
= htab
->elf
.sgot
;
1686 Elf_Internal_Rela outrel
;
1689 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
1690 outrel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
1691 if (sym_sec
&& sym_sec
->output_section
1692 && ! bfd_is_abs_section (sym_sec
->output_section
)
1693 && ! bfd_is_und_section (sym_sec
->output_section
))
1695 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
1696 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
1702 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_C6000_ABS32
);
1703 elf32_tic6x_install_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
1706 /* Finish up dynamic symbol handling. We set the contents of various
1707 dynamic sections here. */
1710 elf32_tic6x_finish_dynamic_symbol (bfd
* output_bfd
,
1711 struct bfd_link_info
*info
,
1712 struct elf_link_hash_entry
*h
,
1713 Elf_Internal_Sym
* sym
)
1715 struct elf32_tic6x_link_hash_table
*htab
;
1717 htab
= elf32_tic6x_hash_table (info
);
1719 if (h
->plt
.offset
!= (bfd_vma
) -1)
1722 bfd_vma got_section_offset
, got_dp_offset
, rela_offset
;
1723 Elf_Internal_Rela rela
;
1725 asection
*plt
, *gotplt
, *relplt
;
1726 const struct elf_backend_data
*bed
;
1728 bed
= get_elf_backend_data (output_bfd
);
1730 BFD_ASSERT (htab
->elf
.splt
!= NULL
);
1731 plt
= htab
->elf
.splt
;
1732 gotplt
= htab
->elf
.sgotplt
;
1733 relplt
= htab
->elf
.srelplt
;
1735 /* This symbol has an entry in the procedure linkage table. Set
1738 if ((h
->dynindx
== -1
1739 && !((h
->forced_local
|| bfd_link_executable (info
))
1741 && h
->type
== STT_GNU_IFUNC
))
1747 /* Get the index in the procedure linkage table which
1748 corresponds to this symbol. This is the index of this symbol
1749 in all the symbols for which we are making plt entries. The
1750 first entry in the procedure linkage table is reserved.
1752 Get the offset into the .got table of the entry that
1753 corresponds to this function. Each .got entry is 4 bytes.
1754 The first three are reserved.
1756 For static executables, we don't reserve anything. */
1758 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1759 got_section_offset
= plt_index
+ bed
->got_header_size
/ 4;
1760 got_dp_offset
= got_section_offset
+ htab
->params
.dsbt_size
;
1761 rela_offset
= plt_index
* sizeof (Elf32_External_Rela
);
1763 got_section_offset
*= 4;
1765 /* Fill in the entry in the procedure linkage table. */
1767 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1768 bfd_put_32 (output_bfd
, got_dp_offset
<< 8 | 0x0100006e,
1769 plt
->contents
+ h
->plt
.offset
);
1770 /* mvk .s2 low(rela_offset), b0 */
1771 bfd_put_32 (output_bfd
, (rela_offset
& 0xffff) << 7 | 0x0000002a,
1772 plt
->contents
+ h
->plt
.offset
+ 4);
1773 /* mvkh .s2 high(rela_offset), b0 */
1774 bfd_put_32 (output_bfd
, ((rela_offset
>> 16) & 0xffff) << 7 | 0x0000006a,
1775 plt
->contents
+ h
->plt
.offset
+ 8);
1777 bfd_put_32 (output_bfd
, 0x00002000,
1778 plt
->contents
+ h
->plt
.offset
+ 12);
1780 bfd_put_32 (output_bfd
, 0x00080362,
1781 plt
->contents
+ h
->plt
.offset
+ 16);
1783 bfd_put_32 (output_bfd
, 0x00008000,
1784 plt
->contents
+ h
->plt
.offset
+ 20);
1786 /* Fill in the entry in the global offset table. */
1787 bfd_put_32 (output_bfd
,
1788 (plt
->output_section
->vma
+ plt
->output_offset
),
1789 gotplt
->contents
+ got_section_offset
);
1791 /* Fill in the entry in the .rel.plt section. */
1792 rela
.r_offset
= (gotplt
->output_section
->vma
1793 + gotplt
->output_offset
1794 + got_section_offset
);
1795 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_JUMP_SLOT
);
1797 loc
= relplt
->contents
+ rela_offset
;
1798 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1800 if (!h
->def_regular
)
1802 /* Mark the symbol as undefined, rather than as defined in
1803 the .plt section. */
1804 sym
->st_shndx
= SHN_UNDEF
;
1809 if (h
->got
.offset
!= (bfd_vma
) -1)
1814 /* This symbol has an entry in the global offset table.
1817 sgot
= htab
->elf
.sgot
;
1818 srela
= htab
->elf
.srelgot
;
1819 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1821 /* If this is a -Bsymbolic link, and the symbol is defined
1822 locally, we just want to emit a RELATIVE reloc. Likewise if
1823 the symbol was forced to be local because of a version file.
1824 The entry in the global offset table will already have been
1825 initialized in the relocate_section function. */
1826 if (bfd_link_pic (info
)
1827 && (SYMBOLIC_BIND (info
, h
)
1828 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1830 asection
*s
= h
->root
.u
.def
.section
;
1831 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, s
,
1832 h
->got
.offset
& ~(bfd_vma
) 1);
1836 Elf_Internal_Rela outrel
;
1837 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1838 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1839 outrel
.r_offset
= (sgot
->output_section
->vma
1840 + sgot
->output_offset
1841 + (h
->got
.offset
& ~(bfd_vma
) 1));
1842 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_ABS32
);
1843 outrel
.r_addend
= 0;
1845 elf32_tic6x_install_rela (output_bfd
, srela
, &outrel
);
1851 Elf_Internal_Rela rel
;
1854 /* This symbol needs a copy reloc. Set it up. */
1856 if (h
->dynindx
== -1
1857 || (h
->root
.type
!= bfd_link_hash_defined
1858 && h
->root
.type
!= bfd_link_hash_defweak
)
1859 || htab
->elf
.srelbss
== NULL
1860 || htab
->elf
.sreldynrelro
== NULL
)
1863 rel
.r_offset
= (h
->root
.u
.def
.value
1864 + h
->root
.u
.def
.section
->output_section
->vma
1865 + h
->root
.u
.def
.section
->output_offset
);
1866 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_COPY
);
1868 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
1869 s
= htab
->elf
.sreldynrelro
;
1871 s
= htab
->elf
.srelbss
;
1873 elf32_tic6x_install_rela (output_bfd
, s
, &rel
);
1876 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1877 if (h
== elf_hash_table (info
)->hdynamic
1878 || h
== elf_hash_table (info
)->hgot
)
1879 sym
->st_shndx
= SHN_ABS
;
1884 /* Unwinding tables are not referenced directly. This pass marks them as
1885 required if the corresponding code section is marked. */
1888 elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info
*info
,
1889 elf_gc_mark_hook_fn gc_mark_hook
)
1892 Elf_Internal_Shdr
**elf_shdrp
;
1895 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
1897 /* Marking EH data may cause additional code sections to be marked,
1898 requiring multiple passes. */
1903 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
1907 if (! is_tic6x_elf (sub
))
1910 elf_shdrp
= elf_elfsections (sub
);
1911 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
1913 Elf_Internal_Shdr
*hdr
;
1915 hdr
= &elf_section_data (o
)->this_hdr
;
1916 if (hdr
->sh_type
== SHT_C6000_UNWIND
1918 && hdr
->sh_link
< elf_numsections (sub
)
1920 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
1923 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
1933 /* Return TRUE if this is an unwinding table index. */
1936 is_tic6x_elf_unwind_section_name (const char *name
)
1938 return (CONST_STRNEQ (name
, ELF_STRING_C6000_unwind
)
1939 || CONST_STRNEQ (name
, ELF_STRING_C6000_unwind_once
));
1943 /* Set the type and flags for an unwinding index table. We do this by
1944 the section name, which is a hack, but ought to work. */
1947 elf32_tic6x_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1948 Elf_Internal_Shdr
*hdr
, asection
*sec
)
1952 name
= bfd_section_name (sec
);
1954 if (is_tic6x_elf_unwind_section_name (name
))
1956 hdr
->sh_type
= SHT_C6000_UNWIND
;
1957 hdr
->sh_flags
|= SHF_LINK_ORDER
;
1963 /* Adjust a symbol defined by a dynamic object and referenced by a
1964 regular object. The current definition is in some section of the
1965 dynamic object, but we're not including those sections. We have to
1966 change the definition to something the rest of the link can
1970 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1971 struct elf_link_hash_entry
*h
)
1973 struct elf32_tic6x_link_hash_table
*htab
;
1977 dynobj
= elf_hash_table (info
)->dynobj
;
1979 /* Make sure we know what is going on here. */
1980 BFD_ASSERT (dynobj
!= NULL
1983 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
1985 /* If this is a function, put it in the procedure linkage table. We
1986 will fill in the contents of the procedure linkage table later,
1987 when we know the address of the .got section. */
1988 if (h
->type
== STT_FUNC
1991 if (h
->plt
.refcount
<= 0
1992 || SYMBOL_CALLS_LOCAL (info
, h
)
1993 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1994 && h
->root
.type
== bfd_link_hash_undefweak
))
1996 /* This case can occur if we saw a PLT32 reloc in an input
1997 file, but the symbol was never referred to by a dynamic
1998 object, or if all references were garbage collected. In
1999 such a case, we don't actually need to build a procedure
2000 linkage table, and we can just do a PC32 reloc instead. */
2001 h
->plt
.offset
= (bfd_vma
) -1;
2008 /* If this is a weak symbol, and there is a real definition, the
2009 processor independent code will have arranged for us to see the
2010 real definition first, and we can just use the same value. */
2011 if (h
->is_weakalias
)
2013 struct elf_link_hash_entry
*def
= weakdef (h
);
2014 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
2015 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
2016 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
2017 h
->non_got_ref
= def
->non_got_ref
;
2021 /* This is a reference to a symbol defined by a dynamic object which
2022 is not a function. */
2024 /* If we are creating a shared library, we must presume that the
2025 only references to the symbol are via the global offset table.
2026 For such cases we need not do anything here; the relocations will
2027 be handled correctly by relocate_section. */
2028 if (bfd_link_pic (info
))
2031 /* If there are no references to this symbol that do not use the
2032 GOT, we don't need to generate a copy reloc. */
2033 if (!h
->non_got_ref
)
2036 /* If -z nocopyreloc was given, we won't generate them either. */
2037 if (info
->nocopyreloc
)
2043 htab
= elf32_tic6x_hash_table (info
);
2047 /* We must allocate the symbol in our .dynbss section, which will
2048 become part of the .bss section of the executable. There will be
2049 an entry for this symbol in the .dynsym section. The dynamic
2050 object will contain position independent code, so all references
2051 from the dynamic object to this symbol will go through the global
2052 offset table. The dynamic linker will use the .dynsym entry to
2053 determine the address it must put in the global offset table, so
2054 both the dynamic object and the regular object will refer to the
2055 same memory location for the variable. */
2057 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2058 copy the initial value out of the dynamic object and into the
2059 runtime process image. */
2060 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2062 s
= htab
->elf
.sdynrelro
;
2063 srel
= htab
->elf
.sreldynrelro
;
2067 s
= htab
->elf
.sdynbss
;
2068 srel
= htab
->elf
.srelbss
;
2070 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2072 srel
->size
+= sizeof (Elf32_External_Rela
);
2076 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2080 elf32_tic6x_new_section_hook (bfd
*abfd
, asection
*sec
)
2084 /* Allocate target specific section data. */
2085 if (!sec
->used_by_bfd
)
2087 _tic6x_elf_section_data
*sdata
;
2088 size_t amt
= sizeof (*sdata
);
2090 sdata
= (_tic6x_elf_section_data
*) bfd_zalloc (abfd
, amt
);
2093 sec
->used_by_bfd
= sdata
;
2096 ret
= _bfd_elf_new_section_hook (abfd
, sec
);
2097 sec
->use_rela_p
= elf32_tic6x_tdata (abfd
)->use_rela_p
;
2102 /* Return true if relocation REL against section SEC is a REL rather
2103 than RELA relocation. RELOCS is the first relocation in the
2104 section and ABFD is the bfd that contains SEC. */
2107 elf32_tic6x_rel_relocation_p (bfd
*abfd
, asection
*sec
,
2108 const Elf_Internal_Rela
*relocs
,
2109 const Elf_Internal_Rela
*rel
)
2111 Elf_Internal_Shdr
*rel_hdr
;
2112 const struct elf_backend_data
*bed
;
2114 /* To determine which flavor of relocation this is, we depend on the
2115 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2116 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
2117 if (rel_hdr
== NULL
)
2119 bed
= get_elf_backend_data (abfd
);
2120 return ((size_t) (rel
- relocs
)
2121 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
2124 /* We need dynamic symbols for every section, since segments can
2125 relocate independently. */
2127 elf32_tic6x_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2128 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2131 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2135 /* If sh_type is yet undecided, assume it could be
2136 SHT_PROGBITS/SHT_NOBITS. */
2140 /* There shouldn't be section relative relocations
2141 against any other section. */
2148 elf32_tic6x_relocate_section (bfd
*output_bfd
,
2149 struct bfd_link_info
*info
,
2151 asection
*input_section
,
2153 Elf_Internal_Rela
*relocs
,
2154 Elf_Internal_Sym
*local_syms
,
2155 asection
**local_sections
)
2157 struct elf32_tic6x_link_hash_table
*htab
;
2158 Elf_Internal_Shdr
*symtab_hdr
;
2159 struct elf_link_hash_entry
**sym_hashes
;
2160 bfd_vma
*local_got_offsets
;
2161 Elf_Internal_Rela
*rel
;
2162 Elf_Internal_Rela
*relend
;
2163 bfd_boolean ok
= TRUE
;
2165 htab
= elf32_tic6x_hash_table (info
);
2166 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
2167 sym_hashes
= elf_sym_hashes (input_bfd
);
2168 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2170 relend
= relocs
+ input_section
->reloc_count
;
2172 for (rel
= relocs
; rel
< relend
; rel
++)
2175 unsigned long r_symndx
;
2177 reloc_howto_type
*howto
;
2178 Elf_Internal_Sym
*sym
;
2180 struct elf_link_hash_entry
*h
;
2181 bfd_vma off
, off2
, relocation
;
2182 bfd_boolean unresolved_reloc
;
2183 bfd_reloc_status_type r
;
2184 struct bfd_link_hash_entry
*sbh
;
2188 r_type
= ELF32_R_TYPE (rel
->r_info
);
2189 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2191 is_rel
= elf32_tic6x_rel_relocation_p (input_bfd
, input_section
,
2195 res
= elf32_tic6x_info_to_howto_rel (input_bfd
, &bfd_reloc
, rel
);
2197 res
= elf32_tic6x_info_to_howto (input_bfd
, &bfd_reloc
, rel
);
2199 if (!res
|| (howto
= bfd_reloc
.howto
) == NULL
)
2201 bfd_set_error (bfd_error_bad_value
);
2208 unresolved_reloc
= FALSE
;
2210 if (r_symndx
< symtab_hdr
->sh_info
)
2212 sym
= local_syms
+ r_symndx
;
2213 sec
= local_sections
[r_symndx
];
2214 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2218 bfd_boolean warned
, ignored
;
2220 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2221 r_symndx
, symtab_hdr
, sym_hashes
,
2223 unresolved_reloc
, warned
, ignored
);
2226 if (sec
!= NULL
&& discarded_section (sec
))
2227 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2228 rel
, 1, relend
, howto
, 0, contents
);
2230 if (bfd_link_relocatable (info
))
2234 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2237 relocation
= sec
->output_offset
+ sym
->st_value
;
2238 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
2239 contents
+ rel
->r_offset
);
2249 case R_C6000_FPHEAD
:
2251 /* No action needed. */
2254 case R_C6000_PCR_S21
:
2255 /* A branch to an undefined weak symbol is turned into a
2256 "b .s2 B3" instruction if the existing insn is of the
2257 form "b .s2 symbol". */
2258 if (h
? h
->root
.type
== bfd_link_hash_undefweak
2259 && (htab
->elf
.splt
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
2260 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2262 unsigned long oldval
;
2263 oldval
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2265 if ((oldval
& 0x7e) == 0x12)
2267 oldval
&= 0xF0000001;
2268 bfd_put_32 (input_bfd
, oldval
| 0x000c0362,
2269 contents
+ rel
->r_offset
);
2276 case R_C6000_PCR_S12
:
2277 case R_C6000_PCR_S10
:
2278 case R_C6000_PCR_S7
:
2280 && h
->plt
.offset
!= (bfd_vma
) -1
2281 && htab
->elf
.splt
!= NULL
)
2283 relocation
= (htab
->elf
.splt
->output_section
->vma
2284 + htab
->elf
.splt
->output_offset
2288 /* Generic PC-relative handling produces a value relative to
2289 the exact location of the relocation. Adjust it to be
2290 relative to the start of the fetch packet instead. */
2291 relocation
+= (input_section
->output_section
->vma
2292 + input_section
->output_offset
2293 + rel
->r_offset
) & 0x1f;
2294 unresolved_reloc
= FALSE
;
2297 case R_C6000_PCR_H16
:
2298 case R_C6000_PCR_L16
:
2299 off
= (input_section
->output_section
->vma
2300 + input_section
->output_offset
2302 /* These must be calculated as R = S - FP(FP(PC) - A).
2303 PC, here, is the value we just computed in OFF. RELOCATION
2304 has the address of S + A. */
2305 relocation
-= rel
->r_addend
;
2306 off2
= ((off
& ~(bfd_vma
)0x1f) - rel
->r_addend
) & (bfd_vma
)~0x1f;
2307 off2
= relocation
- off2
;
2308 relocation
= off
+ off2
;
2311 case R_C6000_DSBT_INDEX
:
2312 relocation
= elf32_tic6x_hash_table (info
)->params
.dsbt_index
;
2313 if (!bfd_link_pic (info
) || relocation
!= 0)
2320 case R_C6000_ABS_S16
:
2321 case R_C6000_ABS_L16
:
2322 case R_C6000_ABS_H16
:
2323 /* When generating a shared object or relocatable executable, these
2324 relocations are copied into the output file to be resolved at
2326 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2327 && (input_section
->flags
& SEC_ALLOC
)
2329 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2330 || h
->root
.type
!= bfd_link_hash_undefweak
))
2332 Elf_Internal_Rela outrel
;
2333 bfd_boolean skip
, relocate
;
2336 unresolved_reloc
= FALSE
;
2338 sreloc
= elf_section_data (input_section
)->sreloc
;
2339 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
2345 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2347 if (outrel
.r_offset
== (bfd_vma
) -1)
2349 else if (outrel
.r_offset
== (bfd_vma
) -2)
2350 skip
= TRUE
, relocate
= TRUE
;
2351 outrel
.r_offset
+= (input_section
->output_section
->vma
2352 + input_section
->output_offset
);
2355 memset (&outrel
, 0, sizeof outrel
);
2358 && (!bfd_link_pic (info
)
2359 || !SYMBOLIC_BIND (info
, h
)
2360 || !h
->def_regular
))
2362 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2363 outrel
.r_addend
= rel
->r_addend
;
2369 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2371 if (bfd_is_abs_section (sec
))
2373 else if (sec
== NULL
|| sec
->owner
== NULL
)
2375 bfd_set_error (bfd_error_bad_value
);
2382 osec
= sec
->output_section
;
2383 indx
= elf_section_data (osec
)->dynindx
;
2384 outrel
.r_addend
-= osec
->vma
;
2385 BFD_ASSERT (indx
!= 0);
2388 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2391 elf32_tic6x_install_rela (output_bfd
, sreloc
, &outrel
);
2393 /* If this reloc is against an external symbol, we do not want to
2394 fiddle with the addend. Otherwise, we need to include the symbol
2395 value so that it becomes an addend for the dynamic reloc. */
2400 /* Generic logic OK. */
2403 case R_C6000_SBR_U15_B
:
2404 case R_C6000_SBR_U15_H
:
2405 case R_C6000_SBR_U15_W
:
2406 case R_C6000_SBR_S16
:
2407 case R_C6000_SBR_L16_B
:
2408 case R_C6000_SBR_L16_H
:
2409 case R_C6000_SBR_L16_W
:
2410 case R_C6000_SBR_H16_B
:
2411 case R_C6000_SBR_H16_H
:
2412 case R_C6000_SBR_H16_W
:
2413 sbh
= bfd_link_hash_lookup (info
->hash
, "__c6xabi_DSBT_BASE",
2414 FALSE
, FALSE
, TRUE
);
2416 && (sbh
->type
== bfd_link_hash_defined
2417 || sbh
->type
== bfd_link_hash_defweak
))
2419 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
2420 && (htab
->elf
.splt
== NULL
2421 || h
->plt
.offset
== (bfd_vma
) -1))
2422 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2425 relocation
-= (sbh
->u
.def
.value
2426 + sbh
->u
.def
.section
->output_section
->vma
2427 + sbh
->u
.def
.section
->output_offset
);
2431 _bfd_error_handler (_("%pB: SB-relative relocation but "
2432 "__c6xabi_DSBT_BASE not defined"),
2439 case R_C6000_SBR_GOT_U15_W
:
2440 case R_C6000_SBR_GOT_L16_W
:
2441 case R_C6000_SBR_GOT_H16_W
:
2442 case R_C6000_EHTYPE
:
2443 /* Relocation is to the entry for this symbol in the global
2445 if (htab
->elf
.sgot
== NULL
)
2452 off
= h
->got
.offset
;
2453 dyn
= htab
->elf
.dynamic_sections_created
;
2454 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2455 bfd_link_pic (info
),
2457 || (bfd_link_pic (info
)
2458 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2459 || (ELF_ST_VISIBILITY (h
->other
)
2460 && h
->root
.type
== bfd_link_hash_undefweak
))
2462 /* This is actually a static link, or it is a
2463 -Bsymbolic link and the symbol is defined
2464 locally, or the symbol was forced to be local
2465 because of a version file. We must initialize
2466 this entry in the global offset table. Since the
2467 offset must always be a multiple of 4, we use the
2468 least significant bit to record whether we have
2469 initialized it already.
2471 When doing a dynamic link, we create a .rel.got
2472 relocation entry to initialize the value. This
2473 is done in the finish_dynamic_symbol routine. */
2478 bfd_put_32 (output_bfd
, relocation
,
2479 htab
->elf
.sgot
->contents
+ off
);
2482 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2483 bfd_link_pic (info
),
2485 && !(ELF_ST_VISIBILITY (h
->other
)
2486 && h
->root
.type
== bfd_link_hash_undefweak
))
2487 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
,
2492 unresolved_reloc
= FALSE
;
2496 if (local_got_offsets
== NULL
)
2499 off
= local_got_offsets
[r_symndx
];
2501 /* The offset must always be a multiple of 4. We use
2502 the least significant bit to record whether we have
2503 already generated the necessary reloc. */
2508 bfd_put_32 (output_bfd
, relocation
,
2509 htab
->elf
.sgot
->contents
+ off
);
2511 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2512 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
, off
);
2514 local_got_offsets
[r_symndx
] |= 1;
2518 if (off
>= (bfd_vma
) -2)
2522 relocation
= (htab
->elf
.sgot
->output_section
->vma
2523 + htab
->elf
.sgot
->output_offset
+ off
2524 - htab
->dsbt
->output_section
->vma
2525 - htab
->dsbt
->output_offset
);
2527 relocation
= (htab
->elf
.sgot
->output_section
->vma
2528 + htab
->elf
.sgot
->output_offset
+ off
2529 - htab
->elf
.sgotplt
->output_section
->vma
2530 - htab
->elf
.sgotplt
->output_offset
);
2532 if (rel
->r_addend
!= 0)
2534 /* We can't do anything for a relocation which is against
2535 a symbol *plus offset*. GOT holds relocations for
2536 symbols. Make this an error; the compiler isn't
2537 allowed to pass us these kinds of things. */
2540 /* xgettext:c-format */
2541 (_("%pB, section %pA: relocation %s with non-zero addend %"
2542 PRId64
" against local symbol"),
2545 elf32_tic6x_howto_table
[r_type
].name
,
2546 (int64_t) rel
->r_addend
);
2549 /* xgettext:c-format */
2550 (_("%pB, section %pA: relocation %s with non-zero addend %"
2551 PRId64
" against symbol `%s'"),
2554 elf32_tic6x_howto_table
[r_type
].name
,
2555 (int64_t) rel
->r_addend
,
2556 h
->root
.root
.string
[0] != '\0' ? h
->root
.root
.string
2557 : _("[whose name is lost]"));
2559 bfd_set_error (bfd_error_bad_value
);
2564 case R_C6000_PREL31
:
2566 && h
->plt
.offset
!= (bfd_vma
) -1
2567 && htab
->elf
.splt
!= NULL
)
2569 relocation
= (htab
->elf
.splt
->output_section
->vma
2570 + htab
->elf
.splt
->output_offset
2576 /* Invalid in relocatable object. */
2578 /* Unknown relocation. */
2579 /* xgettext:c-format */
2580 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2582 bfd_set_error (bfd_error_bad_value
);
2587 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2588 contents
, rel
->r_offset
,
2589 relocation
, rel
->r_addend
);
2592 if (r
== bfd_reloc_ok
2593 && howto
->complain_on_overflow
== complain_overflow_bitfield
)
2595 /* Generic overflow handling accepts cases the ABI says
2596 should be rejected for R_C6000_ABS16 and
2598 bfd_vma value
= (relocation
+ rel
->r_addend
) & 0xffffffff;
2599 bfd_vma sbit
= 1 << (howto
->bitsize
- 1);
2600 bfd_vma sbits
= (-(bfd_vma
) sbit
) & 0xffffffff;
2601 bfd_vma value_sbits
= value
& sbits
;
2603 if (value_sbits
!= 0
2604 && value_sbits
!= sbit
2605 && value_sbits
!= sbits
)
2606 r
= bfd_reloc_overflow
;
2609 if (r
!= bfd_reloc_ok
)
2612 const char *error_message
;
2615 name
= h
->root
.root
.string
;
2618 name
= bfd_elf_string_from_elf_section (input_bfd
,
2619 symtab_hdr
->sh_link
,
2624 name
= bfd_section_name (sec
);
2629 case bfd_reloc_overflow
:
2630 /* If the overflowing reloc was to an undefined symbol,
2631 we have already printed one error message and there
2632 is no point complaining again. */
2633 if (!h
|| h
->root
.type
!= bfd_link_hash_undefined
)
2634 (*info
->callbacks
->reloc_overflow
)
2635 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2636 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
2639 case bfd_reloc_undefined
:
2640 (*info
->callbacks
->undefined_symbol
) (info
, name
, input_bfd
,
2642 rel
->r_offset
, TRUE
);
2645 case bfd_reloc_outofrange
:
2646 error_message
= _("out of range");
2649 case bfd_reloc_notsupported
:
2650 error_message
= _("unsupported relocation");
2653 case bfd_reloc_dangerous
:
2654 error_message
= _("dangerous relocation");
2658 error_message
= _("unknown error");
2662 BFD_ASSERT (error_message
!= NULL
);
2663 (*info
->callbacks
->reloc_dangerous
)
2664 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
2674 /* Look through the relocs for a section during the first phase, and
2675 calculate needed space in the global offset table, procedure linkage
2676 table, and dynamic reloc sections. */
2679 elf32_tic6x_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2680 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2682 struct elf32_tic6x_link_hash_table
*htab
;
2683 Elf_Internal_Shdr
*symtab_hdr
;
2684 struct elf_link_hash_entry
**sym_hashes
;
2685 const Elf_Internal_Rela
*rel
;
2686 const Elf_Internal_Rela
*rel_end
;
2689 if (bfd_link_relocatable (info
))
2692 htab
= elf32_tic6x_hash_table (info
);
2693 symtab_hdr
= &elf_symtab_hdr (abfd
);
2694 sym_hashes
= elf_sym_hashes (abfd
);
2696 /* Create dynamic sections for relocatable executables so that we can
2697 copy relocations. */
2698 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2699 && ! htab
->elf
.dynamic_sections_created
)
2701 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2707 rel_end
= relocs
+ sec
->reloc_count
;
2708 for (rel
= relocs
; rel
< rel_end
; rel
++)
2710 unsigned int r_type
;
2711 unsigned int r_symndx
;
2712 struct elf_link_hash_entry
*h
;
2713 Elf_Internal_Sym
*isym
;
2715 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2716 r_type
= ELF32_R_TYPE (rel
->r_info
);
2718 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2720 /* xgettext:c-format */
2721 _bfd_error_handler (_("%pB: bad symbol index: %d"),
2726 if (r_symndx
< symtab_hdr
->sh_info
)
2728 /* A local symbol. */
2729 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
2738 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2739 while (h
->root
.type
== bfd_link_hash_indirect
2740 || h
->root
.type
== bfd_link_hash_warning
)
2741 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2746 case R_C6000_PCR_S21
:
2747 case R_C6000_PREL31
:
2748 /* This symbol requires a procedure linkage table entry. We
2749 actually build the entry in adjust_dynamic_symbol,
2750 because this might be a case of linking PIC code which is
2751 never referenced by a dynamic object, in which case we
2752 don't need to generate a procedure linkage table entry
2755 /* If this is a local symbol, we resolve it directly without
2756 creating a procedure linkage table entry. */
2761 h
->plt
.refcount
+= 1;
2764 case R_C6000_SBR_GOT_U15_W
:
2765 case R_C6000_SBR_GOT_L16_W
:
2766 case R_C6000_SBR_GOT_H16_W
:
2767 case R_C6000_EHTYPE
:
2768 /* This symbol requires a global offset table entry. */
2771 h
->got
.refcount
+= 1;
2775 bfd_signed_vma
*local_got_refcounts
;
2777 /* This is a global offset table entry for a local symbol. */
2778 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2779 if (local_got_refcounts
== NULL
)
2783 size
= symtab_hdr
->sh_info
;
2784 size
*= (sizeof (bfd_signed_vma
)
2785 + sizeof (bfd_vma
) + sizeof(char));
2786 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2787 if (local_got_refcounts
== NULL
)
2789 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2791 local_got_refcounts
[r_symndx
] += 1;
2794 if (htab
->elf
.sgot
== NULL
)
2796 if (htab
->elf
.dynobj
== NULL
)
2797 htab
->elf
.dynobj
= abfd
;
2798 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2803 case R_C6000_DSBT_INDEX
:
2804 /* We'd like to check for nonzero dsbt_index here, but it's
2805 set up only after check_relocs is called. Instead, we
2806 store the number of R_C6000_DSBT_INDEX relocs in the
2807 pc_count field, and potentially discard the extra space
2808 in elf32_tic6x_allocate_dynrelocs. */
2809 if (!bfd_link_pic (info
))
2816 case R_C6000_ABS_S16
:
2817 case R_C6000_ABS_L16
:
2818 case R_C6000_ABS_H16
:
2819 /* If we are creating a shared library, and this is a reloc
2820 against a global symbol, or a non PC relative reloc
2821 against a local symbol, then we need to copy the reloc
2822 into the shared library. However, if we are linking with
2823 -Bsymbolic, we do not need to copy a reloc against a
2824 global symbol which is defined in an object we are
2825 including in the link (i.e., DEF_REGULAR is set). At
2826 this point we have not seen all the input files, so it is
2827 possible that DEF_REGULAR is not set now but will be set
2828 later (it is never cleared). In case of a weak definition,
2829 DEF_REGULAR may be cleared later by a strong definition in
2830 a shared library. We account for that possibility below by
2831 storing information in the relocs_copied field of the hash
2832 table entry. A similar situation occurs when creating
2833 shared libraries and symbol visibility changes render the
2836 If on the other hand, we are creating an executable, we
2837 may need to keep relocations for symbols satisfied by a
2838 dynamic library if we manage to avoid copy relocs for the
2840 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2841 && (sec
->flags
& SEC_ALLOC
) != 0)
2843 struct elf_dyn_relocs
*p
;
2844 struct elf_dyn_relocs
**head
;
2846 /* We must copy these reloc types into the output file.
2847 Create a reloc section in dynobj and make room for
2851 if (htab
->elf
.dynobj
== NULL
)
2852 htab
->elf
.dynobj
= abfd
;
2854 sreloc
= _bfd_elf_make_dynamic_reloc_section
2855 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela? */ TRUE
);
2861 /* If this is a global symbol, we count the number of
2862 relocations we need for this symbol. */
2865 head
= &h
->dyn_relocs
;
2869 /* Track dynamic relocs needed for local syms too.
2870 We really need local syms available to do this
2875 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2879 vpp
= &elf_section_data (s
)->local_dynrel
;
2880 head
= (struct elf_dyn_relocs
**)vpp
;
2884 if (p
== NULL
|| p
->sec
!= sec
)
2886 size_t amt
= sizeof *p
;
2887 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
2898 if (r_type
== R_C6000_DSBT_INDEX
)
2903 case R_C6000_SBR_U15_B
:
2904 case R_C6000_SBR_U15_H
:
2905 case R_C6000_SBR_U15_W
:
2906 case R_C6000_SBR_S16
:
2907 case R_C6000_SBR_L16_B
:
2908 case R_C6000_SBR_L16_H
:
2909 case R_C6000_SBR_L16_W
:
2910 case R_C6000_SBR_H16_B
:
2911 case R_C6000_SBR_H16_H
:
2912 case R_C6000_SBR_H16_W
:
2914 /* These relocations implicitly reference __c6xabi_DSBT_BASE.
2915 Add an explicit reference so that the symbol will be
2916 provided by a linker script. */
2917 struct bfd_link_hash_entry
*bh
= NULL
;
2918 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
2919 "__c6xabi_DSBT_BASE",
2921 bfd_und_section_ptr
, 0,
2922 NULL
, FALSE
, FALSE
, &bh
))
2924 ((struct elf_link_hash_entry
*) bh
)->non_elf
= 0;
2926 if (h
!= NULL
&& bfd_link_executable (info
))
2928 /* For B14-relative addresses, we might need a copy
2943 elf32_tic6x_add_symbol_hook (bfd
*abfd
,
2944 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2945 Elf_Internal_Sym
*sym
,
2946 const char **namep ATTRIBUTE_UNUSED
,
2947 flagword
*flagsp ATTRIBUTE_UNUSED
,
2951 switch (sym
->st_shndx
)
2953 case SHN_TIC6X_SCOMMON
:
2954 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2955 (*secp
)->flags
|= SEC_IS_COMMON
| SEC_SMALL_DATA
;
2956 *valp
= sym
->st_size
;
2957 bfd_set_section_alignment (*secp
, bfd_log2 (sym
->st_value
));
2965 elf32_tic6x_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
2967 elf_symbol_type
*elfsym
;
2969 elfsym
= (elf_symbol_type
*) asym
;
2970 switch (elfsym
->internal_elf_sym
.st_shndx
)
2972 case SHN_TIC6X_SCOMMON
:
2973 if (tic6x_elf_scom_section
.name
== NULL
)
2975 /* Initialize the small common section. */
2976 tic6x_elf_scom_section
.name
= ".scommon";
2977 tic6x_elf_scom_section
.flags
= SEC_IS_COMMON
| SEC_SMALL_DATA
;
2978 tic6x_elf_scom_section
.output_section
= &tic6x_elf_scom_section
;
2979 tic6x_elf_scom_section
.symbol
= &tic6x_elf_scom_symbol
;
2980 tic6x_elf_scom_section
.symbol_ptr_ptr
= &tic6x_elf_scom_symbol_ptr
;
2981 tic6x_elf_scom_symbol
.name
= ".scommon";
2982 tic6x_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2983 tic6x_elf_scom_symbol
.section
= &tic6x_elf_scom_section
;
2984 tic6x_elf_scom_symbol_ptr
= &tic6x_elf_scom_symbol
;
2986 asym
->section
= &tic6x_elf_scom_section
;
2987 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2993 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2994 const char *name ATTRIBUTE_UNUSED
,
2995 Elf_Internal_Sym
*sym
,
2996 asection
*input_sec
,
2997 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2999 /* If we see a common symbol, which implies a relocatable link, then
3000 if a symbol was small common in an input file, mark it as small
3001 common in the output file. */
3002 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
3003 sym
->st_shndx
= SHN_TIC6X_SCOMMON
;
3009 elf32_tic6x_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
3013 if (strcmp (bfd_section_name (sec
), ".scommon") == 0)
3015 *retval
= SHN_TIC6X_SCOMMON
;
3022 /* Allocate space in .plt, .got and associated reloc sections for
3026 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3028 struct bfd_link_info
*info
;
3029 struct elf32_tic6x_link_hash_table
*htab
;
3030 struct elf_dyn_relocs
*p
;
3032 if (h
->root
.type
== bfd_link_hash_indirect
)
3035 info
= (struct bfd_link_info
*) inf
;
3036 htab
= elf32_tic6x_hash_table (info
);
3038 if (htab
->elf
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3040 /* Make sure this symbol is output as a dynamic symbol.
3041 Undefined weak syms won't yet be marked as dynamic. */
3042 if (h
->dynindx
== -1 && !h
->forced_local
)
3044 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3048 if (bfd_link_pic (info
)
3049 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3051 asection
*s
= htab
->elf
.splt
;
3053 /* If this is the first .plt entry, make room for the special
3056 s
->size
+= PLT_ENTRY_SIZE
;
3058 h
->plt
.offset
= s
->size
;
3060 /* If this symbol is not defined in a regular file, and we are
3061 not generating a shared library, then set the symbol to this
3062 location in the .plt. This is required to make function
3063 pointers compare as equal between the normal executable and
3064 the shared library. */
3065 if (! bfd_link_pic (info
) && !h
->def_regular
)
3067 h
->root
.u
.def
.section
= s
;
3068 h
->root
.u
.def
.value
= h
->plt
.offset
;
3071 /* Make room for this entry. */
3072 s
->size
+= PLT_ENTRY_SIZE
;
3073 /* We also need to make an entry in the .got.plt section, which
3074 will be placed in the .got section by the linker script. */
3075 htab
->elf
.sgotplt
->size
+= 4;
3076 /* We also need to make an entry in the .rel.plt section. */
3077 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3081 h
->plt
.offset
= (bfd_vma
) -1;
3087 h
->plt
.offset
= (bfd_vma
) -1;
3091 if (h
->got
.refcount
> 0)
3095 /* Make sure this symbol is output as a dynamic symbol.
3096 Undefined weak syms won't yet be marked as dynamic. */
3097 if (h
->dynindx
== -1
3098 && !h
->forced_local
)
3100 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3105 h
->got
.offset
= s
->size
;
3108 if (!(ELF_ST_VISIBILITY (h
->other
)
3109 && h
->root
.type
== bfd_link_hash_undefweak
))
3110 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3113 h
->got
.offset
= (bfd_vma
) -1;
3115 if (h
->dyn_relocs
== NULL
)
3118 /* Discard relocs on undefined weak syms with non-default
3120 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (htab
->obfd
))
3122 /* We use the pc_count field to hold the number of
3123 R_C6000_DSBT_INDEX relocs. */
3124 if (htab
->params
.dsbt_index
!= 0)
3126 struct elf_dyn_relocs
**pp
;
3128 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
3130 p
->count
-= p
->pc_count
;
3139 if (h
->dyn_relocs
!= NULL
3140 && h
->root
.type
== bfd_link_hash_undefweak
)
3142 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3143 h
->dyn_relocs
= NULL
;
3145 /* Make sure undefined weak symbols are output as a dynamic
3147 else if (h
->dynindx
== -1
3148 && !h
->forced_local
)
3150 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3156 /* Finally, allocate space. */
3157 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3161 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3163 BFD_ASSERT (sreloc
!= NULL
);
3164 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3170 /* Set the sizes of the dynamic sections. */
3173 elf32_tic6x_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3175 struct elf32_tic6x_link_hash_table
*htab
;
3181 htab
= elf32_tic6x_hash_table (info
);
3182 dynobj
= htab
->elf
.dynobj
;
3186 if (htab
->elf
.dynamic_sections_created
)
3188 /* Set the contents of the .interp section to the interpreter. */
3189 if (bfd_link_executable (info
) && !info
->nointerp
)
3191 s
= bfd_get_linker_section (dynobj
, ".interp");
3194 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3195 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3199 /* Set up .got offsets for local syms, and space for local dynamic
3201 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3203 bfd_signed_vma
*local_got
;
3204 bfd_signed_vma
*end_local_got
;
3205 bfd_size_type locsymcount
;
3206 Elf_Internal_Shdr
*symtab_hdr
;
3209 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3211 struct elf_dyn_relocs
*p
;
3213 for (p
= ((struct elf_dyn_relocs
*)
3214 elf_section_data (s
)->local_dynrel
);
3218 if (!bfd_is_abs_section (p
->sec
)
3219 && bfd_is_abs_section (p
->sec
->output_section
))
3221 /* Input section has been discarded, either because
3222 it is a copy of a linkonce section or due to
3223 linker script /DISCARD/, so we'll be discarding
3226 else if (p
->count
!= 0)
3228 srel
= elf_section_data (p
->sec
)->sreloc
;
3229 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3230 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3231 info
->flags
|= DF_TEXTREL
;
3236 local_got
= elf_local_got_refcounts (ibfd
);
3240 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3241 locsymcount
= symtab_hdr
->sh_info
;
3242 end_local_got
= local_got
+ locsymcount
;
3244 srel
= htab
->elf
.srelgot
;
3245 for (; local_got
< end_local_got
; ++local_got
)
3249 *local_got
= s
->size
;
3252 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
3254 srel
->size
+= sizeof (Elf32_External_Rela
);
3258 *local_got
= (bfd_vma
) -1;
3262 /* Allocate global sym .plt and .got entries, and space for global
3263 sym dynamic relocs. */
3264 elf_link_hash_traverse (&htab
->elf
, elf32_tic6x_allocate_dynrelocs
, info
);
3266 /* We now have determined the sizes of the various dynamic sections.
3267 Allocate memory for them. */
3269 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3271 bfd_boolean strip_section
= TRUE
;
3273 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3276 if (s
== htab
->dsbt
)
3277 s
->size
= 4 * htab
->params
.dsbt_size
;
3278 else if (s
== htab
->elf
.splt
3279 || s
== htab
->elf
.sgot
3280 || s
== htab
->elf
.sgotplt
3281 || s
== htab
->elf
.sdynbss
3282 || s
== htab
->elf
.sdynrelro
)
3284 /* Strip this section if we don't need it; see the
3286 /* We'd like to strip these sections if they aren't needed, but if
3287 we've exported dynamic symbols from them we must leave them.
3288 It's too late to tell BFD to get rid of the symbols. */
3290 if (htab
->elf
.hplt
!= NULL
)
3291 strip_section
= FALSE
;
3293 /* Round up the size of the PLT section to a multiple of 32. */
3294 if (s
== htab
->elf
.splt
&& s
->size
> 0)
3295 s
->size
= (s
->size
+ 31) & ~(bfd_vma
)31;
3297 else if (CONST_STRNEQ (bfd_section_name (s
), ".rela"))
3300 && s
!= htab
->elf
.srelplt
)
3303 /* We use the reloc_count field as a counter if we need
3304 to copy relocs into the output file. */
3309 /* It's not one of our sections, so don't allocate space. */
3315 /* If we don't need this section, strip it from the
3316 output file. This is mostly to handle .rel.bss and
3317 .rel.plt. We must create both sections in
3318 create_dynamic_sections, because they must be created
3319 before the linker maps input sections to output
3320 sections. The linker does that before
3321 adjust_dynamic_symbol is called, and it is that
3322 function which decides whether anything needs to go
3323 into these sections. */
3325 s
->flags
|= SEC_EXCLUDE
;
3329 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3332 /* Allocate memory for the section contents. We use bfd_zalloc
3333 here in case unused entries are not reclaimed before the
3334 section's contents are written out. This should not happen,
3335 but this way if it does, we get a R_C6000_NONE reloc instead
3337 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3338 if (s
->contents
== NULL
)
3342 if (htab
->elf
.dynamic_sections_created
)
3344 /* Add some entries to the .dynamic section. We fill in the
3345 values later, in elf32_tic6x_finish_dynamic_sections, but we
3346 must add the entries now so that we get the correct size for
3347 the .dynamic section. The DT_DEBUG entry is filled in by the
3348 dynamic linker and used by the debugger. */
3349 #define add_dynamic_entry(TAG, VAL) \
3350 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3352 if (!_bfd_elf_add_dynamic_tags (output_bfd
, info
, relocs
))
3355 if (!add_dynamic_entry (DT_C6000_DSBT_BASE
, 0)
3356 || !add_dynamic_entry (DT_C6000_DSBT_SIZE
, htab
->params
.dsbt_size
)
3357 || !add_dynamic_entry (DT_C6000_DSBT_INDEX
,
3358 htab
->params
.dsbt_index
))
3362 #undef add_dynamic_entry
3367 /* This function is called after all the input files have been read,
3368 and the input sections have been assigned to output sections. */
3371 elf32_tic6x_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3373 if (elf32_tic6x_using_dsbt (output_bfd
) && !bfd_link_relocatable (info
)
3374 && !bfd_elf_stack_segment_size (output_bfd
, info
,
3375 "__stacksize", DEFAULT_STACK_SIZE
))
3382 elf32_tic6x_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3383 struct bfd_link_info
*info
)
3385 struct elf32_tic6x_link_hash_table
*htab
;
3389 htab
= elf32_tic6x_hash_table (info
);
3390 dynobj
= htab
->elf
.dynobj
;
3391 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
3393 if (elf_hash_table (info
)->dynamic_sections_created
)
3395 Elf32_External_Dyn
* dyncon
;
3396 Elf32_External_Dyn
* dynconend
;
3398 BFD_ASSERT (sdyn
!= NULL
);
3400 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3401 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3403 for (; dyncon
< dynconend
; dyncon
++)
3405 Elf_Internal_Dyn dyn
;
3408 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3415 case DT_C6000_DSBT_BASE
:
3417 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
);
3421 s
= htab
->elf
.sgotplt
;
3422 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3426 s
= htab
->elf
.srelplt
;
3427 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3431 s
= htab
->elf
.srelplt
;
3432 dyn
.d_un
.d_val
= s
->size
;
3435 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3438 /* Fill in the first entry in the procedure linkage table. */
3439 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
3441 bfd_vma got_offs
= (htab
->elf
.sgotplt
->output_section
->vma
3442 + htab
->elf
.sgotplt
->output_offset
3443 - htab
->dsbt
->output_section
->vma
3444 - htab
->dsbt
->output_offset
) / 4;
3446 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3447 bfd_put_32 (output_bfd
, got_offs
<< 8 | 0x0100006e,
3448 htab
->elf
.splt
->contents
);
3449 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3450 bfd_put_32 (output_bfd
, (got_offs
+ 1) << 8 | 0x0080006e,
3451 htab
->elf
.splt
->contents
+ 4);
3453 bfd_put_32 (output_bfd
, 0x00004000,
3454 htab
->elf
.splt
->contents
+ 8);
3456 bfd_put_32 (output_bfd
, 0x00080362,
3457 htab
->elf
.splt
->contents
+ 12);
3459 bfd_put_32 (output_bfd
, 0x00008000,
3460 htab
->elf
.splt
->contents
+ 16);
3462 elf_section_data (htab
->elf
.splt
->output_section
)
3463 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3470 /* Return address for Ith PLT stub in section PLT, for relocation REL
3471 or (bfd_vma) -1 if it should not be included. */
3474 elf32_tic6x_plt_sym_val (bfd_vma i
, const asection
*plt
,
3475 const arelent
*rel ATTRIBUTE_UNUSED
)
3477 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3481 elf32_tic6x_obj_attrs_arg_type (int tag
)
3483 if (tag
== Tag_ABI_compatibility
)
3484 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
3486 return ATTR_TYPE_FLAG_STR_VAL
;
3488 return ATTR_TYPE_FLAG_INT_VAL
;
3492 elf32_tic6x_obj_attrs_order (int num
)
3494 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
3495 return Tag_ABI_conformance
;
3496 if ((num
- 1) < Tag_ABI_conformance
)
3502 elf32_tic6x_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
3504 if ((tag
& 127) < 64)
3507 /* xgettext:c-format */
3508 (_("%pB: error: unknown mandatory EABI object attribute %d"),
3510 bfd_set_error (bfd_error_bad_value
);
3516 /* xgettext:c-format */
3517 (_("%pB: warning: unknown EABI object attribute %d"),
3523 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3524 and return the merged value. At present, all merges succeed, so no
3525 return value for errors is defined. */
3528 elf32_tic6x_merge_arch_attributes (int arch1
, int arch2
)
3530 int min_arch
, max_arch
;
3532 min_arch
= (arch1
< arch2
? arch1
: arch2
);
3533 max_arch
= (arch1
> arch2
? arch1
: arch2
);
3535 /* In most cases, the numerically greatest value is the correct
3536 merged value, but merging C64 and C67 results in C674X. */
3537 if ((min_arch
== C6XABI_Tag_ISA_C67X
3538 || min_arch
== C6XABI_Tag_ISA_C67XP
)
3539 && (max_arch
== C6XABI_Tag_ISA_C64X
3540 || max_arch
== C6XABI_Tag_ISA_C64XP
))
3541 return C6XABI_Tag_ISA_C674X
;
3546 /* Convert a Tag_ABI_array_object_alignment or
3547 Tag_ABI_array_object_align_expected tag value TAG to a
3548 corresponding alignment value; return the alignment, or -1 for an
3549 unknown tag value. */
3552 elf32_tic6x_tag_to_array_alignment (int tag
)
3570 /* Convert a Tag_ABI_array_object_alignment or
3571 Tag_ABI_array_object_align_expected alignment ALIGN to a
3572 corresponding tag value; return the tag value. */
3575 elf32_tic6x_array_alignment_to_tag (int align
)
3593 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3594 succeeded, FALSE otherwise. */
3597 elf32_tic6x_merge_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
3599 bfd
*obfd
= info
->output_bfd
;
3600 bfd_boolean result
= TRUE
;
3601 obj_attribute
*in_attr
;
3602 obj_attribute
*out_attr
;
3604 int array_align_in
, array_align_out
, array_expect_in
, array_expect_out
;
3606 /* FIXME: What should be checked when linking shared libraries? */
3607 if ((ibfd
->flags
& DYNAMIC
) != 0)
3610 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
3612 /* This is the first object. Copy the attributes. */
3613 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
3615 out_attr
= elf_known_obj_attributes_proc (obfd
);
3617 /* Use the Tag_null value to indicate the attributes have been
3624 in_attr
= elf_known_obj_attributes_proc (ibfd
);
3625 out_attr
= elf_known_obj_attributes_proc (obfd
);
3627 /* No specification yet for handling of unknown attributes, so just
3628 ignore them and handle known ones. */
3630 if (out_attr
[Tag_ABI_stack_align_preserved
].i
3631 < in_attr
[Tag_ABI_stack_align_needed
].i
)
3634 /* xgettext:c-format */
3635 (_("error: %pB requires more stack alignment than %pB preserves"),
3639 if (in_attr
[Tag_ABI_stack_align_preserved
].i
3640 < out_attr
[Tag_ABI_stack_align_needed
].i
)
3643 /* xgettext:c-format */
3644 (_("error: %pB requires more stack alignment than %pB preserves"),
3649 array_align_in
= elf32_tic6x_tag_to_array_alignment
3650 (in_attr
[Tag_ABI_array_object_alignment
].i
);
3651 if (array_align_in
== -1)
3654 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
3658 array_align_out
= elf32_tic6x_tag_to_array_alignment
3659 (out_attr
[Tag_ABI_array_object_alignment
].i
);
3660 if (array_align_out
== -1)
3663 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
3667 array_expect_in
= elf32_tic6x_tag_to_array_alignment
3668 (in_attr
[Tag_ABI_array_object_align_expected
].i
);
3669 if (array_expect_in
== -1)
3672 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
3676 array_expect_out
= elf32_tic6x_tag_to_array_alignment
3677 (out_attr
[Tag_ABI_array_object_align_expected
].i
);
3678 if (array_expect_out
== -1)
3681 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
3686 if (array_align_out
< array_expect_in
)
3689 /* xgettext:c-format */
3690 (_("error: %pB requires more array alignment than %pB preserves"),
3694 if (array_align_in
< array_expect_out
)
3697 /* xgettext:c-format */
3698 (_("error: %pB requires more array alignment than %pB preserves"),
3703 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
3708 out_attr
[i
].i
= elf32_tic6x_merge_arch_attributes (in_attr
[i
].i
,
3712 case Tag_ABI_wchar_t
:
3713 if (out_attr
[i
].i
== 0)
3714 out_attr
[i
].i
= in_attr
[i
].i
;
3715 if (out_attr
[i
].i
!= 0
3716 && in_attr
[i
].i
!= 0
3717 && out_attr
[i
].i
!= in_attr
[i
].i
)
3720 /* xgettext:c-format */
3721 (_("warning: %pB and %pB differ in wchar_t size"), obfd
, ibfd
);
3725 case Tag_ABI_stack_align_needed
:
3726 if (out_attr
[i
].i
< in_attr
[i
].i
)
3727 out_attr
[i
].i
= in_attr
[i
].i
;
3730 case Tag_ABI_stack_align_preserved
:
3731 if (out_attr
[i
].i
> in_attr
[i
].i
)
3732 out_attr
[i
].i
= in_attr
[i
].i
;
3736 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3739 /* xgettext:c-format */
3740 (_("warning: %pB and %pB differ in whether code is "
3741 "compiled for DSBT"),
3748 /* Don't transfer these tags from dynamic objects. */
3749 if ((ibfd
->flags
& DYNAMIC
) != 0)
3751 if (out_attr
[i
].i
> in_attr
[i
].i
)
3752 out_attr
[i
].i
= in_attr
[i
].i
;
3755 case Tag_ABI_array_object_alignment
:
3756 if (array_align_out
!= -1
3757 && array_align_in
!= -1
3758 && array_align_out
> array_align_in
)
3760 = elf32_tic6x_array_alignment_to_tag (array_align_in
);
3763 case Tag_ABI_array_object_align_expected
:
3764 if (array_expect_out
!= -1
3765 && array_expect_in
!= -1
3766 && array_expect_out
< array_expect_in
)
3768 = elf32_tic6x_array_alignment_to_tag (array_expect_in
);
3771 case Tag_ABI_conformance
:
3772 /* Merging for this attribute is not specified. As on ARM,
3773 treat a missing attribute as no claim to conform and only
3774 merge identical values. */
3775 if (out_attr
[i
].s
== NULL
3776 || in_attr
[i
].s
== NULL
3777 || strcmp (out_attr
[i
].s
,
3779 out_attr
[i
].s
= NULL
;
3782 case Tag_ABI_compatibility
:
3783 /* Merged in _bfd_elf_merge_object_attributes. */
3788 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
3792 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
3793 out_attr
[i
].type
= in_attr
[i
].type
;
3796 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
3797 if (!_bfd_elf_merge_object_attributes (ibfd
, info
))
3800 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
3806 elf32_tic6x_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
3808 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
3811 if (! is_tic6x_elf (ibfd
) || ! is_tic6x_elf (info
->output_bfd
))
3814 if (!elf32_tic6x_merge_attributes (ibfd
, info
))
3820 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
3821 adds the edit to the start of the list. (The list must be built in order of
3822 ascending TINDEX: the function's callers are primarily responsible for
3823 maintaining that condition). */
3826 elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit
**head
,
3827 tic6x_unwind_table_edit
**tail
,
3828 tic6x_unwind_edit_type type
,
3829 asection
*linked_section
,
3830 unsigned int tindex
)
3832 tic6x_unwind_table_edit
*new_edit
= (tic6x_unwind_table_edit
*)
3833 xmalloc (sizeof (tic6x_unwind_table_edit
));
3835 new_edit
->type
= type
;
3836 new_edit
->linked_section
= linked_section
;
3837 new_edit
->index
= tindex
;
3841 new_edit
->next
= NULL
;
3844 (*tail
)->next
= new_edit
;
3853 new_edit
->next
= *head
;
3862 static _tic6x_elf_section_data
*
3863 get_tic6x_elf_section_data (asection
* sec
)
3865 if (sec
&& sec
->owner
&& is_tic6x_elf (sec
->owner
))
3866 return elf32_tic6x_section_data (sec
);
3872 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST must be negative. */
3874 elf32_tic6x_adjust_exidx_size (asection
*exidx_sec
, int adjust
)
3878 if (!exidx_sec
->rawsize
)
3879 exidx_sec
->rawsize
= exidx_sec
->size
;
3881 bfd_set_section_size (exidx_sec
, exidx_sec
->size
+ adjust
);
3882 out_sec
= exidx_sec
->output_section
;
3883 /* Adjust size of output section. */
3884 bfd_set_section_size (out_sec
, out_sec
->size
+adjust
);
3887 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
3889 elf32_tic6x_insert_cantunwind_after (asection
*text_sec
, asection
*exidx_sec
)
3891 struct _tic6x_elf_section_data
*exidx_data
;
3893 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
3894 elf32_tic6x_add_unwind_table_edit (
3895 &exidx_data
->u
.exidx
.unwind_edit_list
,
3896 &exidx_data
->u
.exidx
.unwind_edit_tail
,
3897 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
3899 elf32_tic6x_adjust_exidx_size (exidx_sec
, 8);
3902 /* Scan .cx6abi.exidx tables, and create a list describing edits which
3903 should be made to those tables, such that:
3905 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
3906 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
3907 codes which have been inlined into the index).
3909 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
3911 The edits are applied when the tables are written
3912 (in elf32_tic6x_write_section).
3916 elf32_tic6x_fix_exidx_coverage (asection
**text_section_order
,
3917 unsigned int num_text_sections
,
3918 struct bfd_link_info
*info
,
3919 bfd_boolean merge_exidx_entries
)
3922 unsigned int last_second_word
= 0, i
;
3923 asection
*last_exidx_sec
= NULL
;
3924 asection
*last_text_sec
= NULL
;
3925 int last_unwind_type
= -1;
3927 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
3929 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link
.next
)
3933 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
3935 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
3936 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
3938 if (!hdr
|| hdr
->sh_type
!= SHT_C6000_UNWIND
)
3941 if (elf_sec
->linked_to
)
3943 Elf_Internal_Shdr
*linked_hdr
3944 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
3945 struct _tic6x_elf_section_data
*linked_sec_tic6x_data
3946 = get_tic6x_elf_section_data (linked_hdr
->bfd_section
);
3948 if (linked_sec_tic6x_data
== NULL
)
3951 /* Link this .c6xabi.exidx section back from the
3952 text section it describes. */
3953 linked_sec_tic6x_data
->u
.text
.tic6x_exidx_sec
= sec
;
3958 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
3959 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
3960 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
3962 for (i
= 0; i
< num_text_sections
; i
++)
3964 asection
*sec
= text_section_order
[i
];
3965 asection
*exidx_sec
;
3966 struct _tic6x_elf_section_data
*tic6x_data
3967 = get_tic6x_elf_section_data (sec
);
3968 struct _tic6x_elf_section_data
*exidx_data
;
3969 bfd_byte
*contents
= NULL
;
3970 int deleted_exidx_bytes
= 0;
3972 tic6x_unwind_table_edit
*unwind_edit_head
= NULL
;
3973 tic6x_unwind_table_edit
*unwind_edit_tail
= NULL
;
3974 Elf_Internal_Shdr
*hdr
;
3977 if (tic6x_data
== NULL
)
3980 exidx_sec
= tic6x_data
->u
.text
.tic6x_exidx_sec
;
3981 if (exidx_sec
== NULL
)
3983 /* Section has no unwind data. */
3984 if (last_unwind_type
== 0 || !last_exidx_sec
)
3987 /* Ignore zero sized sections. */
3991 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
3992 last_unwind_type
= 0;
3996 /* Skip /DISCARD/ sections. */
3997 if (bfd_is_abs_section (exidx_sec
->output_section
))
4000 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
4001 if (hdr
->sh_type
!= SHT_C6000_UNWIND
)
4004 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
4005 if (exidx_data
== NULL
)
4008 ibfd
= exidx_sec
->owner
;
4010 if (hdr
->contents
!= NULL
)
4011 contents
= hdr
->contents
;
4012 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
4016 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
4018 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
4022 /* An EXIDX_CANTUNWIND entry. */
4023 if (second_word
== 1)
4025 if (last_unwind_type
== 0)
4029 /* Inlined unwinding data. Merge if equal to previous. */
4030 else if ((second_word
& 0x80000000) != 0)
4032 if (merge_exidx_entries
4033 && last_second_word
== second_word
4034 && last_unwind_type
== 1)
4037 last_second_word
= second_word
;
4039 /* Normal table entry. In theory we could merge these too,
4040 but duplicate entries are likely to be much less common. */
4046 elf32_tic6x_add_unwind_table_edit (&unwind_edit_head
,
4047 &unwind_edit_tail
, DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
4049 deleted_exidx_bytes
+= 8;
4052 last_unwind_type
= unwind_type
;
4055 /* Free contents if we allocated it ourselves. */
4056 if (contents
!= hdr
->contents
)
4059 /* Record edits to be applied later (in elf32_tic6x_write_section). */
4060 exidx_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
4061 exidx_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
4063 if (deleted_exidx_bytes
> 0)
4064 elf32_tic6x_adjust_exidx_size (exidx_sec
, -deleted_exidx_bytes
);
4066 last_exidx_sec
= exidx_sec
;
4067 last_text_sec
= sec
;
4070 /* Add terminating CANTUNWIND entry. */
4071 if (last_exidx_sec
&& last_unwind_type
!= 0)
4072 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4077 /* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified. */
4079 static unsigned long
4080 elf32_tic6x_add_low31 (unsigned long val
, bfd_vma addend
)
4082 return (val
& ~0x7ffffffful
) | ((val
+ addend
) & 0x7ffffffful
);
4085 /* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
4086 relocations. OFFSET is in bytes, and will be scaled before encoding. */
4090 elf32_tic6x_copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
,
4093 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
4094 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
4097 /* High bit of first word is supposed to be zero. */
4098 if ((first_word
& 0x80000000ul
) == 0)
4099 first_word
= elf32_tic6x_add_low31 (first_word
, offset
);
4101 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
4102 (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry. */
4103 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
4104 second_word
= elf32_tic6x_add_low31 (second_word
, offset
);
4106 bfd_put_32 (output_bfd
, first_word
, to
);
4107 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
4110 /* Do the actual mangling of exception index tables. */
4113 elf32_tic6x_write_section (bfd
*output_bfd
,
4114 struct bfd_link_info
*link_info
,
4118 _tic6x_elf_section_data
*tic6x_data
;
4119 struct elf32_tic6x_link_hash_table
*globals
4120 = elf32_tic6x_hash_table (link_info
);
4121 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4123 if (globals
== NULL
)
4126 /* If this section has not been allocated an _tic6x_elf_section_data
4127 structure then we cannot record anything. */
4128 tic6x_data
= get_tic6x_elf_section_data (sec
);
4129 if (tic6x_data
== NULL
)
4132 if (tic6x_data
->elf
.this_hdr
.sh_type
!= SHT_C6000_UNWIND
)
4135 tic6x_unwind_table_edit
*edit_node
4136 = tic6x_data
->u
.exidx
.unwind_edit_list
;
4137 /* Now, sec->size is the size of the section we will write. The original
4138 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
4139 markers) was sec->rawsize. (This isn't the case if we perform no
4140 edits, then rawsize will be zero and we should use size). */
4141 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
4142 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
4143 unsigned int in_index
, out_index
;
4144 bfd_vma add_to_offsets
= 0;
4146 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
4150 unsigned int edit_index
= edit_node
->index
;
4152 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
4154 elf32_tic6x_copy_exidx_entry (output_bfd
,
4155 edited_contents
+ out_index
* 8,
4156 contents
+ in_index
* 8, add_to_offsets
);
4160 else if (in_index
== edit_index
4161 || (in_index
* 8 >= input_size
4162 && edit_index
== UINT_MAX
))
4164 switch (edit_node
->type
)
4166 case DELETE_EXIDX_ENTRY
:
4168 add_to_offsets
+= 8;
4171 case INSERT_EXIDX_CANTUNWIND_AT_END
:
4173 asection
*text_sec
= edit_node
->linked_section
;
4174 bfd_vma text_offset
= text_sec
->output_section
->vma
4175 + text_sec
->output_offset
4177 bfd_vma exidx_offset
= offset
+ out_index
* 8;
4178 unsigned long prel31_offset
;
4180 /* Note: this is meant to be equivalent to an
4181 R_C6000_PREL31 relocation. These synthetic
4182 EXIDX_CANTUNWIND markers are not relocated by the
4183 usual BFD method. */
4184 prel31_offset
= ((text_offset
- exidx_offset
) >> 1)
4187 /* First address we can't unwind. */
4188 bfd_put_32 (output_bfd
, prel31_offset
,
4189 &edited_contents
[out_index
* 8]);
4191 /* Code for EXIDX_CANTUNWIND. */
4192 bfd_put_32 (output_bfd
, 0x1,
4193 &edited_contents
[out_index
* 8 + 4]);
4196 add_to_offsets
-= 8;
4201 edit_node
= edit_node
->next
;
4206 /* No more edits, copy remaining entries verbatim. */
4207 elf32_tic6x_copy_exidx_entry (output_bfd
,
4208 edited_contents
+ out_index
* 8,
4209 contents
+ in_index
* 8, add_to_offsets
);
4215 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
4216 bfd_set_section_contents (output_bfd
, sec
->output_section
,
4218 (file_ptr
) sec
->output_offset
, sec
->size
);
4223 #define elf32_bed elf32_tic6x_bed
4225 #define TARGET_LITTLE_SYM tic6x_elf32_le_vec
4226 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
4227 #define TARGET_BIG_SYM tic6x_elf32_be_vec
4228 #define TARGET_BIG_NAME "elf32-tic6x-be"
4229 #define ELF_ARCH bfd_arch_tic6x
4230 #define ELF_TARGET_ID TIC6X_ELF_DATA
4231 #define ELF_MACHINE_CODE EM_TI_C6000
4232 #define ELF_MAXPAGESIZE 0x1000
4233 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
4234 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
4235 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
4236 #define bfd_elf32_mkobject elf32_tic6x_mkobject
4237 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
4238 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
4239 #define elf_backend_stack_align 8
4240 #define elf_backend_can_gc_sections 1
4241 #define elf_backend_default_use_rela_p 1
4242 #define elf_backend_may_use_rel_p 1
4243 #define elf_backend_may_use_rela_p 1
4244 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
4245 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
4246 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
4247 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
4248 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4249 #define elf_backend_obj_attrs_vendor "c6xabi"
4250 #define elf_backend_can_refcount 1
4251 #define elf_backend_want_got_plt 1
4252 #define elf_backend_want_dynbss 1
4253 #define elf_backend_want_dynrelro 1
4254 #define elf_backend_plt_readonly 1
4255 #define elf_backend_rela_normal 1
4256 #define elf_backend_got_header_size 8
4257 #define elf_backend_fake_sections elf32_tic6x_fake_sections
4258 #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
4259 #define elf_backend_create_dynamic_sections \
4260 elf32_tic6x_create_dynamic_sections
4261 #define elf_backend_adjust_dynamic_symbol \
4262 elf32_tic6x_adjust_dynamic_symbol
4263 #define elf_backend_check_relocs elf32_tic6x_check_relocs
4264 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4265 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4266 #define elf_backend_link_output_symbol_hook \
4267 elf32_tic6x_link_output_symbol_hook
4268 #define elf_backend_section_from_bfd_section \
4269 elf32_tic6x_section_from_bfd_section
4270 #define elf_backend_relocate_section elf32_tic6x_relocate_section
4271 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4272 #define elf_backend_finish_dynamic_symbol \
4273 elf32_tic6x_finish_dynamic_symbol
4274 #define elf_backend_always_size_sections \
4275 elf32_tic6x_always_size_sections
4276 #define elf_backend_size_dynamic_sections \
4277 elf32_tic6x_size_dynamic_sections
4278 #define elf_backend_finish_dynamic_sections \
4279 elf32_tic6x_finish_dynamic_sections
4280 #define bfd_elf32_bfd_final_link \
4281 elf32_tic6x_final_link
4282 #define elf_backend_write_section elf32_tic6x_write_section
4283 #define elf_info_to_howto elf32_tic6x_info_to_howto
4284 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
4286 #undef elf_backend_omit_section_dynsym
4287 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4288 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4290 #include "elf32-target.h"
4293 #define elf32_bed elf32_tic6x_linux_bed
4295 #undef TARGET_LITTLE_SYM
4296 #define TARGET_LITTLE_SYM tic6x_elf32_linux_le_vec
4297 #undef TARGET_LITTLE_NAME
4298 #define TARGET_LITTLE_NAME "elf32-tic6x-linux-le"
4299 #undef TARGET_BIG_SYM
4300 #define TARGET_BIG_SYM tic6x_elf32_linux_be_vec
4301 #undef TARGET_BIG_NAME
4302 #define TARGET_BIG_NAME "elf32-tic6x-linux-be"
4304 #define ELF_OSABI ELFOSABI_C6000_LINUX
4306 #include "elf32-target.h"
4309 #define elf32_bed elf32_tic6x_elf_bed
4311 #undef TARGET_LITTLE_SYM
4312 #define TARGET_LITTLE_SYM tic6x_elf32_c6000_le_vec
4313 #undef TARGET_LITTLE_NAME
4314 #define TARGET_LITTLE_NAME "elf32-tic6x-elf-le"
4315 #undef TARGET_BIG_SYM
4316 #define TARGET_BIG_SYM tic6x_elf32_c6000_be_vec
4317 #undef TARGET_BIG_NAME
4318 #define TARGET_BIG_NAME "elf32-tic6x-elf-be"
4320 #define ELF_OSABI ELFOSABI_C6000_ELFABI
4322 #include "elf32-target.h"