1 /* 32-bit ELF support for TI C6X
2 Copyright (C) 2010-2018 Free Software Foundation, Inc.
3 Contributed by Joseph Myers <joseph@codesourcery.com>
4 Bernd Schmidt <bernds@codesourcery.com>
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
27 #include "libiberty.h"
29 #include "elf/tic6x.h"
30 #include "elf32-tic6x.h"
32 #define ELF_DYNAMIC_INTERPRETER "/lib/ld-uClibc.so.0"
34 /* DSBT binaries have a default 128K stack. */
35 #define DEFAULT_STACK_SIZE 0x20000
37 /* The size in bytes of an entry in the procedure linkage table. */
38 #define PLT_ENTRY_SIZE 24
40 /* TI C6X ELF linker hash table. */
42 struct elf32_tic6x_link_hash_table
44 struct elf_link_hash_table elf
;
46 /* C6X specific command line arguments. */
47 struct elf32_tic6x_params params
;
49 /* Small local sym cache. */
50 struct sym_cache sym_cache
;
52 /* The output BFD, for convenience. */
55 /* The .dsbt section. */
59 /* Get the TI C6X ELF linker hash table from a link_info structure. */
61 #define elf32_tic6x_hash_table(p) \
62 ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
64 /* TI C6X ELF linker hash entry. */
66 struct elf32_tic6x_link_hash_entry
68 struct elf_link_hash_entry elf
;
70 /* Track dynamic relocs copied for this symbol. */
71 struct elf_dyn_relocs
*dyn_relocs
;
77 INSERT_EXIDX_CANTUNWIND_AT_END
79 tic6x_unwind_edit_type
;
81 /* A (sorted) list of edits to apply to an unwind table. */
82 typedef struct tic6x_unwind_table_edit
84 tic6x_unwind_edit_type type
;
85 /* Note: we sometimes want to insert an unwind entry corresponding to a
86 section different from the one we're currently writing out, so record the
87 (text) section this edit relates to here. */
88 asection
*linked_section
;
90 struct tic6x_unwind_table_edit
*next
;
92 tic6x_unwind_table_edit
;
94 typedef struct _tic6x_elf_section_data
96 /* Information about mapping symbols. */
97 struct bfd_elf_section_data elf
;
98 /* Information about unwind tables. */
101 /* Unwind info attached to a text section. */
104 asection
*tic6x_exidx_sec
;
107 /* Unwind info attached to an .c6xabi.exidx section. */
110 tic6x_unwind_table_edit
*unwind_edit_list
;
111 tic6x_unwind_table_edit
*unwind_edit_tail
;
115 _tic6x_elf_section_data
;
117 #define elf32_tic6x_section_data(sec) \
118 ((_tic6x_elf_section_data *) elf_section_data (sec))
120 struct elf32_tic6x_obj_tdata
122 struct elf_obj_tdata root
;
124 /* Whether to use RELA relocations when generating relocations.
125 This is a per-object flag to allow the assembler to generate REL
126 relocations for use in linker testcases. */
127 bfd_boolean use_rela_p
;
130 #define elf32_tic6x_tdata(abfd) \
131 ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
133 #define is_tic6x_elf(bfd) \
134 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
135 && elf_tdata (bfd) != NULL \
136 && elf_object_id (bfd) == TIC6X_ELF_DATA)
138 /* C6X ELF uses two common sections. One is the usual one, and the
139 other is for small objects. All the small objects are kept
140 together, and then referenced via the gp pointer, which yields
141 faster assembler code. This is what we use for the small common
142 section. This approach is copied from ecoff.c. */
143 static asection tic6x_elf_scom_section
;
144 static asymbol tic6x_elf_scom_symbol
;
145 static asymbol
*tic6x_elf_scom_symbol_ptr
;
147 static reloc_howto_type elf32_tic6x_howto_table
[] =
149 HOWTO (R_C6000_NONE
, /* type */
151 3, /* 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_NONE", /* name */
158 FALSE
, /* partial_inplace */
161 FALSE
), /* pcrel_offset */
162 HOWTO (R_C6000_ABS32
, /* type */
164 2, /* size (0 = byte, 1 = short, 2 = long) */
166 FALSE
, /* pc_relative */
168 complain_overflow_dont
,/* complain_on_overflow */
169 bfd_elf_generic_reloc
, /* special_function */
170 "R_C6000_ABS32", /* name */
171 FALSE
, /* partial_inplace */
173 0xffffffff, /* dst_mask */
174 FALSE
), /* pcrel_offset */
175 HOWTO (R_C6000_ABS16
, /* type */
177 1, /* 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_ABS16", /* name */
184 FALSE
, /* partial_inplace */
186 0x0000ffff, /* dst_mask */
187 FALSE
), /* pcrel_offset */
188 HOWTO (R_C6000_ABS8
, /* type */
190 0, /* size (0 = byte, 1 = short, 2 = long) */
192 FALSE
, /* pc_relative */
194 complain_overflow_bitfield
,/* complain_on_overflow */
195 bfd_elf_generic_reloc
, /* special_function */
196 "R_C6000_ABS8", /* name */
197 FALSE
, /* partial_inplace */
199 0x000000ff, /* dst_mask */
200 FALSE
), /* pcrel_offset */
201 HOWTO (R_C6000_PCR_S21
, /* 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_S21", /* name */
210 FALSE
, /* partial_inplace */
212 0x0fffff80, /* dst_mask */
213 TRUE
), /* pcrel_offset */
214 HOWTO (R_C6000_PCR_S12
, /* 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_S12", /* name */
223 FALSE
, /* partial_inplace */
225 0x0fff0000, /* dst_mask */
226 TRUE
), /* pcrel_offset */
227 HOWTO (R_C6000_PCR_S10
, /* 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_S10", /* name */
236 FALSE
, /* partial_inplace */
238 0x007fe000, /* dst_mask */
239 TRUE
), /* pcrel_offset */
240 HOWTO (R_C6000_PCR_S7
, /* type */
242 2, /* size (0 = byte, 1 = short, 2 = long) */
244 TRUE
, /* pc_relative */
246 complain_overflow_signed
,/* complain_on_overflow */
247 bfd_elf_generic_reloc
, /* special_function */
248 "R_C6000_PCR_S7", /* name */
249 FALSE
, /* partial_inplace */
251 0x007f0000, /* dst_mask */
252 TRUE
), /* pcrel_offset */
253 HOWTO (R_C6000_ABS_S16
, /* type */
255 2, /* size (0 = byte, 1 = short, 2 = long) */
257 FALSE
, /* pc_relative */
259 complain_overflow_signed
,/* complain_on_overflow */
260 bfd_elf_generic_reloc
, /* special_function */
261 "R_C6000_ABS_S16", /* name */
262 FALSE
, /* partial_inplace */
264 0x007fff80, /* dst_mask */
265 FALSE
), /* pcrel_offset */
266 HOWTO (R_C6000_ABS_L16
, /* 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_L16", /* name */
275 FALSE
, /* partial_inplace */
277 0x007fff80, /* dst_mask */
278 FALSE
), /* pcrel_offset */
279 HOWTO (R_C6000_ABS_H16
, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 FALSE
, /* pc_relative */
285 complain_overflow_dont
,/* complain_on_overflow */
286 bfd_elf_generic_reloc
, /* special_function */
287 "R_C6000_ABS_H16", /* name */
288 FALSE
, /* partial_inplace */
290 0x007fff80, /* dst_mask */
291 FALSE
), /* pcrel_offset */
292 HOWTO (R_C6000_SBR_U15_B
, /* 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_B", /* name */
301 FALSE
, /* partial_inplace */
303 0x007fff00, /* dst_mask */
304 FALSE
), /* pcrel_offset */
305 HOWTO (R_C6000_SBR_U15_H
, /* 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_H", /* name */
314 FALSE
, /* partial_inplace */
316 0x007fff00, /* dst_mask */
317 FALSE
), /* pcrel_offset */
318 HOWTO (R_C6000_SBR_U15_W
, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 FALSE
, /* pc_relative */
324 complain_overflow_unsigned
,/* complain_on_overflow */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_C6000_SBR_U15_W", /* name */
327 FALSE
, /* partial_inplace */
329 0x007fff00, /* dst_mask */
330 FALSE
), /* pcrel_offset */
331 HOWTO (R_C6000_SBR_S16
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE
, /* pc_relative */
337 complain_overflow_signed
,/* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_C6000_SBR_S16", /* name */
340 FALSE
, /* partial_inplace */
342 0x007fff80, /* dst_mask */
343 FALSE
), /* pcrel_offset */
344 HOWTO (R_C6000_SBR_L16_B
, /* 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_B", /* name */
353 FALSE
, /* partial_inplace */
355 0x007fff80, /* dst_mask */
356 FALSE
), /* pcrel_offset */
357 HOWTO (R_C6000_SBR_L16_H
, /* 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_H", /* name */
366 FALSE
, /* partial_inplace */
368 0x007fff80, /* dst_mask */
369 FALSE
), /* pcrel_offset */
370 HOWTO (R_C6000_SBR_L16_W
, /* 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_L16_W", /* name */
379 FALSE
, /* partial_inplace */
381 0x007fff80, /* dst_mask */
382 FALSE
), /* pcrel_offset */
383 HOWTO (R_C6000_SBR_H16_B
, /* 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_B", /* name */
392 FALSE
, /* partial_inplace */
394 0x007fff80, /* dst_mask */
395 FALSE
), /* pcrel_offset */
396 HOWTO (R_C6000_SBR_H16_H
, /* 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_H", /* name */
405 FALSE
, /* partial_inplace */
407 0x007fff80, /* dst_mask */
408 FALSE
), /* pcrel_offset */
409 HOWTO (R_C6000_SBR_H16_W
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE
, /* pc_relative */
415 complain_overflow_dont
,/* complain_on_overflow */
416 bfd_elf_generic_reloc
, /* special_function */
417 "R_C6000_SBR_H16_W", /* name */
418 FALSE
, /* partial_inplace */
420 0x007fff80, /* dst_mask */
421 FALSE
), /* pcrel_offset */
422 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE
, /* pc_relative */
428 complain_overflow_unsigned
,/* complain_on_overflow */
429 bfd_elf_generic_reloc
, /* special_function */
430 "R_C6000_SBR_GOT_U15_W",/* name */
431 FALSE
, /* partial_inplace */
433 0x007fff00, /* dst_mask */
434 FALSE
), /* pcrel_offset */
435 HOWTO (R_C6000_SBR_GOT_L16_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_L16_W",/* name */
444 FALSE
, /* partial_inplace */
446 0x007fff80, /* dst_mask */
447 FALSE
), /* pcrel_offset */
448 HOWTO (R_C6000_SBR_GOT_H16_W
, /* type */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 FALSE
, /* pc_relative */
454 complain_overflow_dont
,/* complain_on_overflow */
455 bfd_elf_generic_reloc
, /* special_function */
456 "R_C6000_SBR_GOT_H16_W",/* name */
457 FALSE
, /* partial_inplace */
459 0x007fff80, /* dst_mask */
460 FALSE
), /* pcrel_offset */
461 HOWTO (R_C6000_DSBT_INDEX
, /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 FALSE
, /* pc_relative */
467 complain_overflow_unsigned
,/* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 "R_C6000_DSBT_INDEX", /* name */
470 FALSE
, /* partial_inplace */
472 0x007fff00, /* dst_mask */
473 FALSE
), /* pcrel_offset */
474 HOWTO (R_C6000_PREL31
, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 TRUE
, /* pc_relative */
480 complain_overflow_dont
,/* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_C6000_PREL31", /* name */
483 FALSE
, /* partial_inplace */
485 0x7fffffff, /* dst_mask */
486 TRUE
), /* pcrel_offset */
487 HOWTO (R_C6000_COPY
, /* 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_COPY", /* name */
496 FALSE
, /* partial_inplace */
498 0xffffffff, /* dst_mask */
499 FALSE
), /* pcrel_offset */
500 HOWTO (R_C6000_JUMP_SLOT
, /* 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_JUMP_SLOT", /* name */
509 FALSE
, /* partial_inplace */
511 0xffffffff, /* dst_mask */
512 FALSE
), /* pcrel_offset */
513 HOWTO (R_C6000_EHTYPE
, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 FALSE
, /* pc_relative */
519 complain_overflow_dont
,/* complain_on_overflow */
520 bfd_elf_generic_reloc
, /* special_function */
521 "R_C6000_EHTYPE", /* name */
522 FALSE
, /* partial_inplace */
524 0xffffffff, /* dst_mask */
525 FALSE
), /* pcrel_offset */
526 HOWTO (R_C6000_PCR_H16
, /* 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_H16", /* name */
535 FALSE
, /* partial_inplace */
537 0x007fff80, /* dst_mask */
538 TRUE
), /* pcrel_offset */
539 HOWTO (R_C6000_PCR_L16
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 TRUE
, /* pc_relative */
545 complain_overflow_dont
,/* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 "R_C6000_PCR_L16", /* name */
548 FALSE
, /* partial_inplace */
550 0x007fff80, /* dst_mask */
551 TRUE
), /* pcrel_offset */
774 HOWTO (R_C6000_ALIGN
, /* 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_ALIGN", /* name */
783 FALSE
, /* partial_inplace */
786 FALSE
), /* pcrel_offset */
787 HOWTO (R_C6000_FPHEAD
, /* 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_FPHEAD", /* name */
796 FALSE
, /* partial_inplace */
799 FALSE
), /* pcrel_offset */
800 HOWTO (R_C6000_NOCMP
, /* type */
802 0, /* size (0 = byte, 1 = short, 2 = long) */
804 FALSE
, /* pc_relative */
806 complain_overflow_dont
,/* complain_on_overflow */
807 bfd_elf_generic_reloc
, /* special_function */
808 "R_C6000_NOCMP", /* name */
809 FALSE
, /* partial_inplace */
812 FALSE
) /* pcrel_offset */
815 static reloc_howto_type elf32_tic6x_howto_table_rel
[] =
817 HOWTO (R_C6000_NONE
, /* type */
819 3, /* 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_NONE", /* name */
826 TRUE
, /* partial_inplace */
829 FALSE
), /* pcrel_offset */
830 HOWTO (R_C6000_ABS32
, /* type */
832 2, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE
, /* pc_relative */
836 complain_overflow_dont
,/* complain_on_overflow */
837 bfd_elf_generic_reloc
, /* special_function */
838 "R_C6000_ABS32", /* name */
839 TRUE
, /* partial_inplace */
840 0xffffffff, /* src_mask */
841 0xffffffff, /* dst_mask */
842 FALSE
), /* pcrel_offset */
843 HOWTO (R_C6000_ABS16
, /* type */
845 1, /* 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_ABS16", /* name */
852 TRUE
, /* partial_inplace */
853 0x0000ffff, /* src_mask */
854 0x0000ffff, /* dst_mask */
855 FALSE
), /* pcrel_offset */
856 HOWTO (R_C6000_ABS8
, /* type */
858 0, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_bitfield
,/* complain_on_overflow */
863 bfd_elf_generic_reloc
, /* special_function */
864 "R_C6000_ABS8", /* name */
865 TRUE
, /* partial_inplace */
866 0x000000ff, /* src_mask */
867 0x000000ff, /* dst_mask */
868 FALSE
), /* pcrel_offset */
869 HOWTO (R_C6000_PCR_S21
, /* 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_S21", /* name */
878 TRUE
, /* partial_inplace */
879 0x0fffff80, /* src_mask */
880 0x0fffff80, /* dst_mask */
881 TRUE
), /* pcrel_offset */
882 HOWTO (R_C6000_PCR_S12
, /* 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_S12", /* name */
891 TRUE
, /* partial_inplace */
892 0x0fff0000, /* src_mask */
893 0x0fff0000, /* dst_mask */
894 TRUE
), /* pcrel_offset */
895 HOWTO (R_C6000_PCR_S10
, /* 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_S10", /* name */
904 TRUE
, /* partial_inplace */
905 0x007fe000, /* src_mask */
906 0x007fe000, /* dst_mask */
907 TRUE
), /* pcrel_offset */
908 HOWTO (R_C6000_PCR_S7
, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 TRUE
, /* pc_relative */
914 complain_overflow_signed
,/* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* special_function */
916 "R_C6000_PCR_S7", /* name */
917 TRUE
, /* partial_inplace */
918 0x007f0000, /* src_mask */
919 0x007f0000, /* dst_mask */
920 TRUE
), /* pcrel_offset */
921 HOWTO (R_C6000_ABS_S16
, /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_signed
,/* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 "R_C6000_ABS_S16", /* name */
930 TRUE
, /* partial_inplace */
931 0x007fff80, /* src_mask */
932 0x007fff80, /* dst_mask */
933 FALSE
), /* pcrel_offset */
934 HOWTO (R_C6000_ABS_L16
, /* type */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_dont
,/* complain_on_overflow */
941 bfd_elf_generic_reloc
, /* special_function */
942 "R_C6000_ABS_L16", /* name */
943 TRUE
, /* partial_inplace */
944 0x007fff80, /* src_mask */
945 0x007fff80, /* dst_mask */
946 FALSE
), /* pcrel_offset */
947 EMPTY_HOWTO (R_C6000_ABS_H16
),
948 HOWTO (R_C6000_SBR_U15_B
, /* 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_B", /* name */
957 TRUE
, /* partial_inplace */
958 0x007fff00, /* src_mask */
959 0x007fff00, /* dst_mask */
960 FALSE
), /* pcrel_offset */
961 HOWTO (R_C6000_SBR_U15_H
, /* 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_H", /* name */
970 TRUE
, /* partial_inplace */
971 0x007fff00, /* src_mask */
972 0x007fff00, /* dst_mask */
973 FALSE
), /* pcrel_offset */
974 HOWTO (R_C6000_SBR_U15_W
, /* type */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
978 FALSE
, /* pc_relative */
980 complain_overflow_unsigned
,/* complain_on_overflow */
981 bfd_elf_generic_reloc
, /* special_function */
982 "R_C6000_SBR_U15_W", /* name */
983 TRUE
, /* partial_inplace */
984 0x007fff00, /* src_mask */
985 0x007fff00, /* dst_mask */
986 FALSE
), /* pcrel_offset */
987 HOWTO (R_C6000_SBR_S16
, /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 FALSE
, /* pc_relative */
993 complain_overflow_signed
,/* complain_on_overflow */
994 bfd_elf_generic_reloc
, /* special_function */
995 "R_C6000_SBR_S16", /* name */
996 TRUE
, /* partial_inplace */
997 0x007fff80, /* src_mask */
998 0x007fff80, /* dst_mask */
999 FALSE
), /* pcrel_offset */
1000 HOWTO (R_C6000_SBR_L16_B
, /* 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_B", /* name */
1009 TRUE
, /* partial_inplace */
1010 0x007fff80, /* src_mask */
1011 0x007fff80, /* dst_mask */
1012 FALSE
), /* pcrel_offset */
1013 HOWTO (R_C6000_SBR_L16_H
, /* 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_H", /* name */
1022 TRUE
, /* partial_inplace */
1023 0x007fff80, /* src_mask */
1024 0x007fff80, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1026 HOWTO (R_C6000_SBR_L16_W
, /* type */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE
, /* pc_relative */
1032 complain_overflow_dont
,/* complain_on_overflow */
1033 bfd_elf_generic_reloc
, /* special_function */
1034 "R_C6000_SBR_L16_W", /* name */
1035 TRUE
, /* partial_inplace */
1036 0x007fff80, /* src_mask */
1037 0x007fff80, /* dst_mask */
1038 FALSE
), /* pcrel_offset */
1039 EMPTY_HOWTO (R_C6000_SBR_H16_B
),
1040 EMPTY_HOWTO (R_C6000_SBR_H16_H
),
1041 EMPTY_HOWTO (R_C6000_SBR_H16_W
),
1042 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
1044 2, /* size (0 = byte, 1 = short, 2 = long) */
1046 FALSE
, /* pc_relative */
1048 complain_overflow_unsigned
,/* complain_on_overflow */
1049 bfd_elf_generic_reloc
, /* special_function */
1050 "R_C6000_SBR_GOT_U15_W",/* name */
1051 TRUE
, /* partial_inplace */
1052 0x007fff00, /* src_mask */
1053 0x007fff00, /* dst_mask */
1054 FALSE
), /* pcrel_offset */
1055 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE
, /* pc_relative */
1061 complain_overflow_dont
,/* complain_on_overflow */
1062 bfd_elf_generic_reloc
, /* special_function */
1063 "R_C6000_SBR_GOT_L16_W",/* name */
1064 TRUE
, /* partial_inplace */
1065 0x007fff80, /* src_mask */
1066 0x007fff80, /* dst_mask */
1067 FALSE
), /* pcrel_offset */
1068 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W
),
1069 HOWTO (R_C6000_DSBT_INDEX
, /* type */
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 FALSE
, /* pc_relative */
1075 complain_overflow_unsigned
,/* complain_on_overflow */
1076 bfd_elf_generic_reloc
, /* special_function */
1077 "R_C6000_DSBT_INDEX", /* name */
1078 TRUE
, /* partial_inplace */
1080 0x007fff00, /* dst_mask */
1081 FALSE
), /* pcrel_offset */
1082 HOWTO (R_C6000_PREL31
, /* type */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1086 TRUE
, /* pc_relative */
1088 complain_overflow_dont
,/* complain_on_overflow */
1089 bfd_elf_generic_reloc
, /* special_function */
1090 "R_C6000_PREL31", /* name */
1091 TRUE
, /* partial_inplace */
1093 0x7fffffff, /* dst_mask */
1094 TRUE
), /* pcrel_offset */
1095 HOWTO (R_C6000_COPY
, /* 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_COPY", /* name */
1104 TRUE
, /* partial_inplace */
1106 0xffffffff, /* dst_mask */
1107 FALSE
), /* pcrel_offset */
1108 HOWTO (R_C6000_JUMP_SLOT
, /* 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_JUMP_SLOT", /* name */
1117 FALSE
, /* partial_inplace */
1119 0xffffffff, /* dst_mask */
1120 FALSE
), /* pcrel_offset */
1121 HOWTO (R_C6000_EHTYPE
, /* type */
1123 2, /* size (0 = byte, 1 = short, 2 = long) */
1125 FALSE
, /* pc_relative */
1127 complain_overflow_dont
,/* complain_on_overflow */
1128 bfd_elf_generic_reloc
, /* special_function */
1129 "R_C6000_EHTYPE", /* name */
1130 FALSE
, /* partial_inplace */
1132 0xffffffff, /* dst_mask */
1133 FALSE
), /* pcrel_offset */
1134 EMPTY_HOWTO (R_C6000_PCR_H16
),
1135 EMPTY_HOWTO (R_C6000_PCR_L16
),
1358 HOWTO (R_C6000_ALIGN
, /* 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_ALIGN", /* name */
1367 TRUE
, /* partial_inplace */
1370 FALSE
), /* pcrel_offset */
1371 HOWTO (R_C6000_FPHEAD
, /* 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_FPHEAD", /* name */
1380 TRUE
, /* partial_inplace */
1383 FALSE
), /* pcrel_offset */
1384 HOWTO (R_C6000_NOCMP
, /* type */
1386 0, /* size (0 = byte, 1 = short, 2 = long) */
1388 FALSE
, /* pc_relative */
1390 complain_overflow_dont
,/* complain_on_overflow */
1391 bfd_elf_generic_reloc
, /* special_function */
1392 "R_C6000_NOCMP", /* name */
1393 TRUE
, /* partial_inplace */
1396 FALSE
) /* pcrel_offset */
1399 /* Map BFD relocations to ELF relocations. */
1403 bfd_reloc_code_real_type bfd_reloc_val
;
1404 enum elf_tic6x_reloc_type elf_reloc_val
;
1407 static const tic6x_reloc_map elf32_tic6x_reloc_map
[] =
1409 { BFD_RELOC_NONE
, R_C6000_NONE
},
1410 { BFD_RELOC_32
, R_C6000_ABS32
},
1411 { BFD_RELOC_16
, R_C6000_ABS16
},
1412 { BFD_RELOC_8
, R_C6000_ABS8
},
1413 { BFD_RELOC_C6000_PCR_S21
, R_C6000_PCR_S21
},
1414 { BFD_RELOC_C6000_PCR_S12
, R_C6000_PCR_S12
},
1415 { BFD_RELOC_C6000_PCR_S10
, R_C6000_PCR_S10
},
1416 { BFD_RELOC_C6000_PCR_S7
, R_C6000_PCR_S7
},
1417 { BFD_RELOC_C6000_ABS_S16
, R_C6000_ABS_S16
},
1418 { BFD_RELOC_C6000_ABS_L16
, R_C6000_ABS_L16
},
1419 { BFD_RELOC_C6000_ABS_H16
, R_C6000_ABS_H16
},
1420 { BFD_RELOC_C6000_SBR_U15_B
, R_C6000_SBR_U15_B
},
1421 { BFD_RELOC_C6000_SBR_U15_H
, R_C6000_SBR_U15_H
},
1422 { BFD_RELOC_C6000_SBR_U15_W
, R_C6000_SBR_U15_W
},
1423 { BFD_RELOC_C6000_SBR_S16
, R_C6000_SBR_S16
},
1424 { BFD_RELOC_C6000_SBR_L16_B
, R_C6000_SBR_L16_B
},
1425 { BFD_RELOC_C6000_SBR_L16_H
, R_C6000_SBR_L16_H
},
1426 { BFD_RELOC_C6000_SBR_L16_W
, R_C6000_SBR_L16_W
},
1427 { BFD_RELOC_C6000_SBR_H16_B
, R_C6000_SBR_H16_B
},
1428 { BFD_RELOC_C6000_SBR_H16_H
, R_C6000_SBR_H16_H
},
1429 { BFD_RELOC_C6000_SBR_H16_W
, R_C6000_SBR_H16_W
},
1430 { BFD_RELOC_C6000_SBR_GOT_U15_W
, R_C6000_SBR_GOT_U15_W
},
1431 { BFD_RELOC_C6000_SBR_GOT_L16_W
, R_C6000_SBR_GOT_L16_W
},
1432 { BFD_RELOC_C6000_SBR_GOT_H16_W
, R_C6000_SBR_GOT_H16_W
},
1433 { BFD_RELOC_C6000_DSBT_INDEX
, R_C6000_DSBT_INDEX
},
1434 { BFD_RELOC_C6000_PREL31
, R_C6000_PREL31
},
1435 { BFD_RELOC_C6000_COPY
, R_C6000_COPY
},
1436 { BFD_RELOC_C6000_JUMP_SLOT
, R_C6000_JUMP_SLOT
},
1437 { BFD_RELOC_C6000_EHTYPE
, R_C6000_EHTYPE
},
1438 { BFD_RELOC_C6000_PCR_H16
, R_C6000_PCR_H16
},
1439 { BFD_RELOC_C6000_PCR_L16
, R_C6000_PCR_L16
},
1440 { BFD_RELOC_C6000_ALIGN
, R_C6000_ALIGN
},
1441 { BFD_RELOC_C6000_FPHEAD
, R_C6000_FPHEAD
},
1442 { BFD_RELOC_C6000_NOCMP
, R_C6000_NOCMP
}
1445 static reloc_howto_type
*
1446 elf32_tic6x_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1450 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_reloc_map
); i
++)
1451 if (elf32_tic6x_reloc_map
[i
].bfd_reloc_val
== code
)
1453 enum elf_tic6x_reloc_type elf_reloc_val
;
1454 reloc_howto_type
*howto
;
1456 elf_reloc_val
= elf32_tic6x_reloc_map
[i
].elf_reloc_val
;
1457 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1458 howto
= &elf32_tic6x_howto_table
[elf_reloc_val
];
1460 howto
= &elf32_tic6x_howto_table_rel
[elf_reloc_val
];
1462 /* Some relocations are RELA-only; do not return them for
1464 if (howto
->name
== NULL
)
1473 static reloc_howto_type
*
1474 elf32_tic6x_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1476 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1480 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table
); i
++)
1481 if (elf32_tic6x_howto_table
[i
].name
!= NULL
1482 && strcasecmp (elf32_tic6x_howto_table
[i
].name
, r_name
) == 0)
1483 return &elf32_tic6x_howto_table
[i
];
1489 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table_rel
); i
++)
1490 if (elf32_tic6x_howto_table_rel
[i
].name
!= NULL
1491 && strcasecmp (elf32_tic6x_howto_table_rel
[i
].name
, r_name
) == 0)
1492 return &elf32_tic6x_howto_table_rel
[i
];
1499 elf32_tic6x_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1500 Elf_Internal_Rela
*elf_reloc
)
1502 unsigned int r_type
;
1504 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1505 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table
))
1507 /* xgettext:c-format */
1508 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1510 bfd_set_error (bfd_error_bad_value
);
1514 bfd_reloc
->howto
= &elf32_tic6x_howto_table
[r_type
];
1515 if (bfd_reloc
->howto
== NULL
|| bfd_reloc
->howto
->name
== NULL
)
1517 /* xgettext:c-format */
1518 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1520 bfd_set_error (bfd_error_bad_value
);
1528 elf32_tic6x_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1529 Elf_Internal_Rela
*elf_reloc
)
1531 unsigned int r_type
;
1533 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1534 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table_rel
))
1536 /* xgettext:c-format */
1537 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1539 bfd_set_error (bfd_error_bad_value
);
1543 bfd_reloc
->howto
= &elf32_tic6x_howto_table_rel
[r_type
];
1544 if (bfd_reloc
->howto
== NULL
|| bfd_reloc
->howto
->name
== NULL
)
1546 /* xgettext:c-format */
1547 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1549 bfd_set_error (bfd_error_bad_value
);
1557 elf32_tic6x_set_use_rela_p (bfd
*abfd
, bfd_boolean use_rela_p
)
1559 elf32_tic6x_tdata (abfd
)->use_rela_p
= use_rela_p
;
1562 /* Create an entry in a C6X ELF linker hash table. */
1564 static struct bfd_hash_entry
*
1565 elf32_tic6x_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1566 struct bfd_hash_table
*table
,
1569 /* Allocate the structure if it has not already been allocated by a
1573 entry
= bfd_hash_allocate (table
,
1574 sizeof (struct elf32_tic6x_link_hash_entry
));
1579 /* Call the allocation method of the superclass. */
1580 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1583 struct elf32_tic6x_link_hash_entry
*eh
;
1585 eh
= (struct elf32_tic6x_link_hash_entry
*) entry
;
1586 eh
->dyn_relocs
= NULL
;
1592 /* Create a C6X ELF linker hash table. */
1594 static struct bfd_link_hash_table
*
1595 elf32_tic6x_link_hash_table_create (bfd
*abfd
)
1597 struct elf32_tic6x_link_hash_table
*ret
;
1598 bfd_size_type amt
= sizeof (struct elf32_tic6x_link_hash_table
);
1600 ret
= bfd_zmalloc (amt
);
1604 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1605 elf32_tic6x_link_hash_newfunc
,
1606 sizeof (struct elf32_tic6x_link_hash_entry
),
1614 ret
->elf
.is_relocatable_executable
= 1;
1616 return &ret
->elf
.root
;
1620 elf32_tic6x_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
1622 if (bfd_link_pic (info
))
1624 obj_attribute
*out_attr
;
1625 out_attr
= elf_known_obj_attributes_proc (abfd
);
1626 if (out_attr
[Tag_ABI_PIC
].i
== 0)
1628 _bfd_error_handler (_("warning: generating a shared library "
1629 "containing non-PIC code"));
1631 if (out_attr
[Tag_ABI_PID
].i
== 0)
1633 _bfd_error_handler (_("warning: generating a shared library "
1634 "containing non-PID code"));
1637 /* Invoke the regular ELF backend linker to do all the work. */
1638 if (!bfd_elf_final_link (abfd
, info
))
1644 /* Called to pass PARAMS to the backend. We store them in the hash table
1645 associated with INFO. */
1648 elf32_tic6x_setup (struct bfd_link_info
*info
,
1649 struct elf32_tic6x_params
*params
)
1651 struct elf32_tic6x_link_hash_table
*htab
= elf32_tic6x_hash_table (info
);
1652 htab
->params
= *params
;
1655 /* Determine if we're dealing with a DSBT object. */
1658 elf32_tic6x_using_dsbt (bfd
*abfd
)
1660 return bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
,
1664 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1665 sections in DYNOBJ, and set up shortcuts to them in our hash
1669 elf32_tic6x_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1671 struct elf32_tic6x_link_hash_table
*htab
;
1674 htab
= elf32_tic6x_hash_table (info
);
1678 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1682 flags
= (SEC_ALLOC
| SEC_LOAD
1683 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1684 htab
->dsbt
= bfd_make_section_anyway_with_flags (dynobj
, ".dsbt",
1686 if (htab
->dsbt
== NULL
1687 || ! bfd_set_section_alignment (dynobj
, htab
->dsbt
, 2)
1688 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.splt
, 5))
1695 elf32_tic6x_mkobject (bfd
*abfd
)
1699 ret
= bfd_elf_allocate_object (abfd
, sizeof (struct elf32_tic6x_obj_tdata
),
1702 elf32_tic6x_set_use_rela_p (abfd
, TRUE
);
1706 /* Install relocation RELA into section SRELA, incrementing its
1710 elf32_tic6x_install_rela (bfd
*output_bfd
, asection
*srela
,
1711 Elf_Internal_Rela
*rela
)
1714 bfd_vma off
= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1715 loc
= srela
->contents
+ off
;
1716 BFD_ASSERT (off
< srela
->size
);
1717 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
1720 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1721 of the GOT at this offset have been initialized with the relocation. */
1724 elf32_tic6x_make_got_dynreloc (bfd
*output_bfd
,
1725 struct elf32_tic6x_link_hash_table
*htab
,
1726 asection
*sym_sec
, bfd_vma offset
)
1728 asection
*sgot
= htab
->elf
.sgot
;
1729 Elf_Internal_Rela outrel
;
1732 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
1733 outrel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
1734 if (sym_sec
&& sym_sec
->output_section
1735 && ! bfd_is_abs_section (sym_sec
->output_section
)
1736 && ! bfd_is_und_section (sym_sec
->output_section
))
1738 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
1739 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
1745 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_C6000_ABS32
);
1746 elf32_tic6x_install_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
1749 /* Finish up dynamic symbol handling. We set the contents of various
1750 dynamic sections here. */
1753 elf32_tic6x_finish_dynamic_symbol (bfd
* output_bfd
,
1754 struct bfd_link_info
*info
,
1755 struct elf_link_hash_entry
*h
,
1756 Elf_Internal_Sym
* sym
)
1758 struct elf32_tic6x_link_hash_table
*htab
;
1760 htab
= elf32_tic6x_hash_table (info
);
1762 if (h
->plt
.offset
!= (bfd_vma
) -1)
1765 bfd_vma got_section_offset
, got_dp_offset
, rela_offset
;
1766 Elf_Internal_Rela rela
;
1768 asection
*plt
, *gotplt
, *relplt
;
1769 const struct elf_backend_data
*bed
;
1771 bed
= get_elf_backend_data (output_bfd
);
1773 BFD_ASSERT (htab
->elf
.splt
!= NULL
);
1774 plt
= htab
->elf
.splt
;
1775 gotplt
= htab
->elf
.sgotplt
;
1776 relplt
= htab
->elf
.srelplt
;
1778 /* This symbol has an entry in the procedure linkage table. Set
1781 if ((h
->dynindx
== -1
1782 && !((h
->forced_local
|| bfd_link_executable (info
))
1784 && h
->type
== STT_GNU_IFUNC
))
1790 /* Get the index in the procedure linkage table which
1791 corresponds to this symbol. This is the index of this symbol
1792 in all the symbols for which we are making plt entries. The
1793 first entry in the procedure linkage table is reserved.
1795 Get the offset into the .got table of the entry that
1796 corresponds to this function. Each .got entry is 4 bytes.
1797 The first three are reserved.
1799 For static executables, we don't reserve anything. */
1801 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1802 got_section_offset
= plt_index
+ bed
->got_header_size
/ 4;
1803 got_dp_offset
= got_section_offset
+ htab
->params
.dsbt_size
;
1804 rela_offset
= plt_index
* sizeof (Elf32_External_Rela
);
1806 got_section_offset
*= 4;
1808 /* Fill in the entry in the procedure linkage table. */
1810 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1811 bfd_put_32 (output_bfd
, got_dp_offset
<< 8 | 0x0100006e,
1812 plt
->contents
+ h
->plt
.offset
);
1813 /* mvk .s2 low(rela_offset), b0 */
1814 bfd_put_32 (output_bfd
, (rela_offset
& 0xffff) << 7 | 0x0000002a,
1815 plt
->contents
+ h
->plt
.offset
+ 4);
1816 /* mvkh .s2 high(rela_offset), b0 */
1817 bfd_put_32 (output_bfd
, ((rela_offset
>> 16) & 0xffff) << 7 | 0x0000006a,
1818 plt
->contents
+ h
->plt
.offset
+ 8);
1820 bfd_put_32 (output_bfd
, 0x00002000,
1821 plt
->contents
+ h
->plt
.offset
+ 12);
1823 bfd_put_32 (output_bfd
, 0x00080362,
1824 plt
->contents
+ h
->plt
.offset
+ 16);
1826 bfd_put_32 (output_bfd
, 0x00008000,
1827 plt
->contents
+ h
->plt
.offset
+ 20);
1829 /* Fill in the entry in the global offset table. */
1830 bfd_put_32 (output_bfd
,
1831 (plt
->output_section
->vma
+ plt
->output_offset
),
1832 gotplt
->contents
+ got_section_offset
);
1834 /* Fill in the entry in the .rel.plt section. */
1835 rela
.r_offset
= (gotplt
->output_section
->vma
1836 + gotplt
->output_offset
1837 + got_section_offset
);
1838 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_JUMP_SLOT
);
1840 loc
= relplt
->contents
+ rela_offset
;
1841 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1843 if (!h
->def_regular
)
1845 /* Mark the symbol as undefined, rather than as defined in
1846 the .plt section. */
1847 sym
->st_shndx
= SHN_UNDEF
;
1852 if (h
->got
.offset
!= (bfd_vma
) -1)
1857 /* This symbol has an entry in the global offset table.
1860 sgot
= htab
->elf
.sgot
;
1861 srela
= htab
->elf
.srelgot
;
1862 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1864 /* If this is a -Bsymbolic link, and the symbol is defined
1865 locally, we just want to emit a RELATIVE reloc. Likewise if
1866 the symbol was forced to be local because of a version file.
1867 The entry in the global offset table will already have been
1868 initialized in the relocate_section function. */
1869 if (bfd_link_pic (info
)
1870 && (SYMBOLIC_BIND (info
, h
)
1871 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1873 asection
*s
= h
->root
.u
.def
.section
;
1874 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, s
,
1875 h
->got
.offset
& ~(bfd_vma
) 1);
1879 Elf_Internal_Rela outrel
;
1880 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1881 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1882 outrel
.r_offset
= (sgot
->output_section
->vma
1883 + sgot
->output_offset
1884 + (h
->got
.offset
& ~(bfd_vma
) 1));
1885 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_ABS32
);
1886 outrel
.r_addend
= 0;
1888 elf32_tic6x_install_rela (output_bfd
, srela
, &outrel
);
1894 Elf_Internal_Rela rel
;
1897 /* This symbol needs a copy reloc. Set it up. */
1899 if (h
->dynindx
== -1
1900 || (h
->root
.type
!= bfd_link_hash_defined
1901 && h
->root
.type
!= bfd_link_hash_defweak
)
1902 || htab
->elf
.srelbss
== NULL
1903 || htab
->elf
.sreldynrelro
== NULL
)
1906 rel
.r_offset
= (h
->root
.u
.def
.value
1907 + h
->root
.u
.def
.section
->output_section
->vma
1908 + h
->root
.u
.def
.section
->output_offset
);
1909 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_COPY
);
1911 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
1912 s
= htab
->elf
.sreldynrelro
;
1914 s
= htab
->elf
.srelbss
;
1916 elf32_tic6x_install_rela (output_bfd
, s
, &rel
);
1919 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1920 if (h
== elf_hash_table (info
)->hdynamic
1921 || h
== elf_hash_table (info
)->hgot
)
1922 sym
->st_shndx
= SHN_ABS
;
1927 /* Unwinding tables are not referenced directly. This pass marks them as
1928 required if the corresponding code section is marked. */
1931 elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info
*info
,
1932 elf_gc_mark_hook_fn gc_mark_hook
)
1935 Elf_Internal_Shdr
**elf_shdrp
;
1938 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
1940 /* Marking EH data may cause additional code sections to be marked,
1941 requiring multiple passes. */
1946 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
1950 if (! is_tic6x_elf (sub
))
1953 elf_shdrp
= elf_elfsections (sub
);
1954 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
1956 Elf_Internal_Shdr
*hdr
;
1958 hdr
= &elf_section_data (o
)->this_hdr
;
1959 if (hdr
->sh_type
== SHT_C6000_UNWIND
1961 && hdr
->sh_link
< elf_numsections (sub
)
1963 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
1966 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
1976 /* Return TRUE if this is an unwinding table index. */
1979 is_tic6x_elf_unwind_section_name (const char *name
)
1981 return (CONST_STRNEQ (name
, ELF_STRING_C6000_unwind
)
1982 || CONST_STRNEQ (name
, ELF_STRING_C6000_unwind_once
));
1986 /* Set the type and flags for an unwinding index table. We do this by
1987 the section name, which is a hack, but ought to work. */
1990 elf32_tic6x_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1991 Elf_Internal_Shdr
*hdr
, asection
*sec
)
1995 name
= bfd_get_section_name (abfd
, sec
);
1997 if (is_tic6x_elf_unwind_section_name (name
))
1999 hdr
->sh_type
= SHT_C6000_UNWIND
;
2000 hdr
->sh_flags
|= SHF_LINK_ORDER
;
2006 /* Find dynamic relocs for H that apply to read-only sections. */
2009 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
2011 struct elf_dyn_relocs
*p
;
2012 struct elf32_tic6x_link_hash_entry
*eh
2013 = (struct elf32_tic6x_link_hash_entry
*) h
;
2015 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2017 asection
*s
= p
->sec
->output_section
;
2019 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2025 /* Adjust a symbol defined by a dynamic object and referenced by a
2026 regular object. The current definition is in some section of the
2027 dynamic object, but we're not including those sections. We have to
2028 change the definition to something the rest of the link can
2032 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2033 struct elf_link_hash_entry
*h
)
2035 struct elf32_tic6x_link_hash_table
*htab
;
2039 dynobj
= elf_hash_table (info
)->dynobj
;
2041 /* Make sure we know what is going on here. */
2042 BFD_ASSERT (dynobj
!= NULL
2045 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
2047 /* If this is a function, put it in the procedure linkage table. We
2048 will fill in the contents of the procedure linkage table later,
2049 when we know the address of the .got section. */
2050 if (h
->type
== STT_FUNC
2053 if (h
->plt
.refcount
<= 0
2054 || SYMBOL_CALLS_LOCAL (info
, h
)
2055 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2056 && h
->root
.type
== bfd_link_hash_undefweak
))
2058 /* This case can occur if we saw a PLT32 reloc in an input
2059 file, but the symbol was never referred to by a dynamic
2060 object, or if all references were garbage collected. In
2061 such a case, we don't actually need to build a procedure
2062 linkage table, and we can just do a PC32 reloc instead. */
2063 h
->plt
.offset
= (bfd_vma
) -1;
2070 /* If this is a weak symbol, and there is a real definition, the
2071 processor independent code will have arranged for us to see the
2072 real definition first, and we can just use the same value. */
2073 if (h
->is_weakalias
)
2075 struct elf_link_hash_entry
*def
= weakdef (h
);
2076 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
2077 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
2078 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
2079 h
->non_got_ref
= def
->non_got_ref
;
2083 /* This is a reference to a symbol defined by a dynamic object which
2084 is not a function. */
2086 /* If we are creating a shared library, we must presume that the
2087 only references to the symbol are via the global offset table.
2088 For such cases we need not do anything here; the relocations will
2089 be handled correctly by relocate_section. */
2090 if (bfd_link_pic (info
))
2093 /* If there are no references to this symbol that do not use the
2094 GOT, we don't need to generate a copy reloc. */
2095 if (!h
->non_got_ref
)
2098 /* If -z nocopyreloc was given, we won't generate them either. */
2099 if (info
->nocopyreloc
)
2105 htab
= elf32_tic6x_hash_table (info
);
2109 /* We must allocate the symbol in our .dynbss section, which will
2110 become part of the .bss section of the executable. There will be
2111 an entry for this symbol in the .dynsym section. The dynamic
2112 object will contain position independent code, so all references
2113 from the dynamic object to this symbol will go through the global
2114 offset table. The dynamic linker will use the .dynsym entry to
2115 determine the address it must put in the global offset table, so
2116 both the dynamic object and the regular object will refer to the
2117 same memory location for the variable. */
2119 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2120 copy the initial value out of the dynamic object and into the
2121 runtime process image. */
2122 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2124 s
= htab
->elf
.sdynrelro
;
2125 srel
= htab
->elf
.sreldynrelro
;
2129 s
= htab
->elf
.sdynbss
;
2130 srel
= htab
->elf
.srelbss
;
2132 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2134 srel
->size
+= sizeof (Elf32_External_Rela
);
2138 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2142 elf32_tic6x_new_section_hook (bfd
*abfd
, asection
*sec
)
2146 /* Allocate target specific section data. */
2147 if (!sec
->used_by_bfd
)
2149 _tic6x_elf_section_data
*sdata
;
2150 bfd_size_type amt
= sizeof (*sdata
);
2152 sdata
= (_tic6x_elf_section_data
*) bfd_zalloc (abfd
, amt
);
2155 sec
->used_by_bfd
= sdata
;
2158 ret
= _bfd_elf_new_section_hook (abfd
, sec
);
2159 sec
->use_rela_p
= elf32_tic6x_tdata (abfd
)->use_rela_p
;
2164 /* Return true if relocation REL against section SEC is a REL rather
2165 than RELA relocation. RELOCS is the first relocation in the
2166 section and ABFD is the bfd that contains SEC. */
2169 elf32_tic6x_rel_relocation_p (bfd
*abfd
, asection
*sec
,
2170 const Elf_Internal_Rela
*relocs
,
2171 const Elf_Internal_Rela
*rel
)
2173 Elf_Internal_Shdr
*rel_hdr
;
2174 const struct elf_backend_data
*bed
;
2176 /* To determine which flavor of relocation this is, we depend on the
2177 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2178 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
2179 if (rel_hdr
== NULL
)
2181 bed
= get_elf_backend_data (abfd
);
2182 return ((size_t) (rel
- relocs
)
2183 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
2186 /* We need dynamic symbols for every section, since segments can
2187 relocate independently. */
2189 elf32_tic6x_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2190 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2193 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2197 /* If sh_type is yet undecided, assume it could be
2198 SHT_PROGBITS/SHT_NOBITS. */
2202 /* There shouldn't be section relative relocations
2203 against any other section. */
2210 elf32_tic6x_relocate_section (bfd
*output_bfd
,
2211 struct bfd_link_info
*info
,
2213 asection
*input_section
,
2215 Elf_Internal_Rela
*relocs
,
2216 Elf_Internal_Sym
*local_syms
,
2217 asection
**local_sections
)
2219 struct elf32_tic6x_link_hash_table
*htab
;
2220 Elf_Internal_Shdr
*symtab_hdr
;
2221 struct elf_link_hash_entry
**sym_hashes
;
2222 bfd_vma
*local_got_offsets
;
2223 Elf_Internal_Rela
*rel
;
2224 Elf_Internal_Rela
*relend
;
2225 bfd_boolean ok
= TRUE
;
2227 htab
= elf32_tic6x_hash_table (info
);
2228 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
2229 sym_hashes
= elf_sym_hashes (input_bfd
);
2230 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2232 relend
= relocs
+ input_section
->reloc_count
;
2234 for (rel
= relocs
; rel
< relend
; rel
++)
2237 unsigned long r_symndx
;
2239 reloc_howto_type
*howto
;
2240 Elf_Internal_Sym
*sym
;
2242 struct elf_link_hash_entry
*h
;
2243 bfd_vma off
, off2
, relocation
;
2244 bfd_boolean unresolved_reloc
;
2245 bfd_reloc_status_type r
;
2246 struct bfd_link_hash_entry
*sbh
;
2250 r_type
= ELF32_R_TYPE (rel
->r_info
);
2251 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2253 is_rel
= elf32_tic6x_rel_relocation_p (input_bfd
, input_section
,
2257 res
= elf32_tic6x_info_to_howto_rel (input_bfd
, &bfd_reloc
, rel
);
2259 res
= elf32_tic6x_info_to_howto (input_bfd
, &bfd_reloc
, rel
);
2261 if (!res
|| (howto
= bfd_reloc
.howto
) == NULL
)
2263 bfd_set_error (bfd_error_bad_value
);
2270 unresolved_reloc
= FALSE
;
2272 if (r_symndx
< symtab_hdr
->sh_info
)
2274 sym
= local_syms
+ r_symndx
;
2275 sec
= local_sections
[r_symndx
];
2276 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2280 bfd_boolean warned
, ignored
;
2282 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2283 r_symndx
, symtab_hdr
, sym_hashes
,
2285 unresolved_reloc
, warned
, ignored
);
2288 if (sec
!= NULL
&& discarded_section (sec
))
2289 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2290 rel
, 1, relend
, howto
, 0, contents
);
2292 if (bfd_link_relocatable (info
))
2296 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2299 relocation
= sec
->output_offset
+ sym
->st_value
;
2300 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
2301 contents
+ rel
->r_offset
);
2311 case R_C6000_FPHEAD
:
2313 /* No action needed. */
2316 case R_C6000_PCR_S21
:
2317 /* A branch to an undefined weak symbol is turned into a
2318 "b .s2 B3" instruction if the existing insn is of the
2319 form "b .s2 symbol". */
2320 if (h
? h
->root
.type
== bfd_link_hash_undefweak
2321 && (htab
->elf
.splt
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
2322 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2324 unsigned long oldval
;
2325 oldval
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2327 if ((oldval
& 0x7e) == 0x12)
2329 oldval
&= 0xF0000001;
2330 bfd_put_32 (input_bfd
, oldval
| 0x000c0362,
2331 contents
+ rel
->r_offset
);
2338 case R_C6000_PCR_S12
:
2339 case R_C6000_PCR_S10
:
2340 case R_C6000_PCR_S7
:
2342 && h
->plt
.offset
!= (bfd_vma
) -1
2343 && htab
->elf
.splt
!= NULL
)
2345 relocation
= (htab
->elf
.splt
->output_section
->vma
2346 + htab
->elf
.splt
->output_offset
2350 /* Generic PC-relative handling produces a value relative to
2351 the exact location of the relocation. Adjust it to be
2352 relative to the start of the fetch packet instead. */
2353 relocation
+= (input_section
->output_section
->vma
2354 + input_section
->output_offset
2355 + rel
->r_offset
) & 0x1f;
2356 unresolved_reloc
= FALSE
;
2359 case R_C6000_PCR_H16
:
2360 case R_C6000_PCR_L16
:
2361 off
= (input_section
->output_section
->vma
2362 + input_section
->output_offset
2364 /* These must be calculated as R = S - FP(FP(PC) - A).
2365 PC, here, is the value we just computed in OFF. RELOCATION
2366 has the address of S + A. */
2367 relocation
-= rel
->r_addend
;
2368 off2
= ((off
& ~(bfd_vma
)0x1f) - rel
->r_addend
) & (bfd_vma
)~0x1f;
2369 off2
= relocation
- off2
;
2370 relocation
= off
+ off2
;
2373 case R_C6000_DSBT_INDEX
:
2374 relocation
= elf32_tic6x_hash_table (info
)->params
.dsbt_index
;
2375 if (!bfd_link_pic (info
) || relocation
!= 0)
2382 case R_C6000_ABS_S16
:
2383 case R_C6000_ABS_L16
:
2384 case R_C6000_ABS_H16
:
2385 /* When generating a shared object or relocatable executable, these
2386 relocations are copied into the output file to be resolved at
2388 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2389 && (input_section
->flags
& SEC_ALLOC
)
2391 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2392 || h
->root
.type
!= bfd_link_hash_undefweak
))
2394 Elf_Internal_Rela outrel
;
2395 bfd_boolean skip
, relocate
;
2398 unresolved_reloc
= FALSE
;
2400 sreloc
= elf_section_data (input_section
)->sreloc
;
2401 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
2407 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2409 if (outrel
.r_offset
== (bfd_vma
) -1)
2411 else if (outrel
.r_offset
== (bfd_vma
) -2)
2412 skip
= TRUE
, relocate
= TRUE
;
2413 outrel
.r_offset
+= (input_section
->output_section
->vma
2414 + input_section
->output_offset
);
2417 memset (&outrel
, 0, sizeof outrel
);
2420 && (!bfd_link_pic (info
)
2421 || !SYMBOLIC_BIND (info
, h
)
2422 || !h
->def_regular
))
2424 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2425 outrel
.r_addend
= rel
->r_addend
;
2431 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2433 if (bfd_is_abs_section (sec
))
2435 else if (sec
== NULL
|| sec
->owner
== NULL
)
2437 bfd_set_error (bfd_error_bad_value
);
2444 osec
= sec
->output_section
;
2445 indx
= elf_section_data (osec
)->dynindx
;
2446 outrel
.r_addend
-= osec
->vma
;
2447 BFD_ASSERT (indx
!= 0);
2450 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2453 elf32_tic6x_install_rela (output_bfd
, sreloc
, &outrel
);
2455 /* If this reloc is against an external symbol, we do not want to
2456 fiddle with the addend. Otherwise, we need to include the symbol
2457 value so that it becomes an addend for the dynamic reloc. */
2462 /* Generic logic OK. */
2465 case R_C6000_SBR_U15_B
:
2466 case R_C6000_SBR_U15_H
:
2467 case R_C6000_SBR_U15_W
:
2468 case R_C6000_SBR_S16
:
2469 case R_C6000_SBR_L16_B
:
2470 case R_C6000_SBR_L16_H
:
2471 case R_C6000_SBR_L16_W
:
2472 case R_C6000_SBR_H16_B
:
2473 case R_C6000_SBR_H16_H
:
2474 case R_C6000_SBR_H16_W
:
2475 sbh
= bfd_link_hash_lookup (info
->hash
, "__c6xabi_DSBT_BASE",
2476 FALSE
, FALSE
, TRUE
);
2478 && (sbh
->type
== bfd_link_hash_defined
2479 || sbh
->type
== bfd_link_hash_defweak
))
2481 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
2482 && (htab
->elf
.splt
== NULL
2483 || h
->plt
.offset
== (bfd_vma
) -1))
2484 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2487 relocation
-= (sbh
->u
.def
.value
2488 + sbh
->u
.def
.section
->output_section
->vma
2489 + sbh
->u
.def
.section
->output_offset
);
2493 _bfd_error_handler (_("%pB: SB-relative relocation but "
2494 "__c6xabi_DSBT_BASE not defined"),
2501 case R_C6000_SBR_GOT_U15_W
:
2502 case R_C6000_SBR_GOT_L16_W
:
2503 case R_C6000_SBR_GOT_H16_W
:
2504 case R_C6000_EHTYPE
:
2505 /* Relocation is to the entry for this symbol in the global
2507 if (htab
->elf
.sgot
== NULL
)
2514 off
= h
->got
.offset
;
2515 dyn
= htab
->elf
.dynamic_sections_created
;
2516 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2517 bfd_link_pic (info
),
2519 || (bfd_link_pic (info
)
2520 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2521 || (ELF_ST_VISIBILITY (h
->other
)
2522 && h
->root
.type
== bfd_link_hash_undefweak
))
2524 /* This is actually a static link, or it is a
2525 -Bsymbolic link and the symbol is defined
2526 locally, or the symbol was forced to be local
2527 because of a version file. We must initialize
2528 this entry in the global offset table. Since the
2529 offset must always be a multiple of 4, we use the
2530 least significant bit to record whether we have
2531 initialized it already.
2533 When doing a dynamic link, we create a .rel.got
2534 relocation entry to initialize the value. This
2535 is done in the finish_dynamic_symbol routine. */
2540 bfd_put_32 (output_bfd
, relocation
,
2541 htab
->elf
.sgot
->contents
+ off
);
2544 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2545 bfd_link_pic (info
),
2547 && !(ELF_ST_VISIBILITY (h
->other
)
2548 && h
->root
.type
== bfd_link_hash_undefweak
))
2549 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
,
2554 unresolved_reloc
= FALSE
;
2558 if (local_got_offsets
== NULL
)
2561 off
= local_got_offsets
[r_symndx
];
2563 /* The offset must always be a multiple of 4. We use
2564 the least significant bit to record whether we have
2565 already generated the necessary reloc. */
2570 bfd_put_32 (output_bfd
, relocation
,
2571 htab
->elf
.sgot
->contents
+ off
);
2573 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2574 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
, off
);
2576 local_got_offsets
[r_symndx
] |= 1;
2580 if (off
>= (bfd_vma
) -2)
2584 relocation
= (htab
->elf
.sgot
->output_section
->vma
2585 + htab
->elf
.sgot
->output_offset
+ off
2586 - htab
->dsbt
->output_section
->vma
2587 - htab
->dsbt
->output_offset
);
2589 relocation
= (htab
->elf
.sgot
->output_section
->vma
2590 + htab
->elf
.sgot
->output_offset
+ off
2591 - htab
->elf
.sgotplt
->output_section
->vma
2592 - htab
->elf
.sgotplt
->output_offset
);
2594 if (rel
->r_addend
!= 0)
2596 /* We can't do anything for a relocation which is against
2597 a symbol *plus offset*. GOT holds relocations for
2598 symbols. Make this an error; the compiler isn't
2599 allowed to pass us these kinds of things. */
2602 /* xgettext:c-format */
2603 (_("%pB, section %pA: relocation %s with non-zero addend %"
2604 PRId64
" against local symbol"),
2607 elf32_tic6x_howto_table
[r_type
].name
,
2608 (int64_t) rel
->r_addend
);
2611 /* xgettext:c-format */
2612 (_("%pB, section %pA: relocation %s with non-zero addend %"
2613 PRId64
" against symbol `%s'"),
2616 elf32_tic6x_howto_table
[r_type
].name
,
2617 (int64_t) rel
->r_addend
,
2618 h
->root
.root
.string
[0] != '\0' ? h
->root
.root
.string
2619 : _("[whose name is lost]"));
2621 bfd_set_error (bfd_error_bad_value
);
2626 case R_C6000_PREL31
:
2628 && h
->plt
.offset
!= (bfd_vma
) -1
2629 && htab
->elf
.splt
!= NULL
)
2631 relocation
= (htab
->elf
.splt
->output_section
->vma
2632 + htab
->elf
.splt
->output_offset
2638 /* Invalid in relocatable object. */
2640 /* Unknown relocation. */
2641 /* xgettext:c-format */
2642 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2644 bfd_set_error (bfd_error_bad_value
);
2649 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2650 contents
, rel
->r_offset
,
2651 relocation
, rel
->r_addend
);
2654 if (r
== bfd_reloc_ok
2655 && howto
->complain_on_overflow
== complain_overflow_bitfield
)
2657 /* Generic overflow handling accepts cases the ABI says
2658 should be rejected for R_C6000_ABS16 and
2660 bfd_vma value
= (relocation
+ rel
->r_addend
) & 0xffffffff;
2661 bfd_vma sbit
= 1 << (howto
->bitsize
- 1);
2662 bfd_vma sbits
= (-(bfd_vma
) sbit
) & 0xffffffff;
2663 bfd_vma value_sbits
= value
& sbits
;
2665 if (value_sbits
!= 0
2666 && value_sbits
!= sbit
2667 && value_sbits
!= sbits
)
2668 r
= bfd_reloc_overflow
;
2671 if (r
!= bfd_reloc_ok
)
2674 const char *error_message
;
2677 name
= h
->root
.root
.string
;
2680 name
= bfd_elf_string_from_elf_section (input_bfd
,
2681 symtab_hdr
->sh_link
,
2686 name
= bfd_section_name (input_bfd
, sec
);
2691 case bfd_reloc_overflow
:
2692 /* If the overflowing reloc was to an undefined symbol,
2693 we have already printed one error message and there
2694 is no point complaining again. */
2695 if (!h
|| h
->root
.type
!= bfd_link_hash_undefined
)
2696 (*info
->callbacks
->reloc_overflow
)
2697 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2698 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
2701 case bfd_reloc_undefined
:
2702 (*info
->callbacks
->undefined_symbol
) (info
, name
, input_bfd
,
2704 rel
->r_offset
, TRUE
);
2707 case bfd_reloc_outofrange
:
2708 error_message
= _("out of range");
2711 case bfd_reloc_notsupported
:
2712 error_message
= _("unsupported relocation");
2715 case bfd_reloc_dangerous
:
2716 error_message
= _("dangerous relocation");
2720 error_message
= _("unknown error");
2724 BFD_ASSERT (error_message
!= NULL
);
2725 (*info
->callbacks
->reloc_dangerous
)
2726 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
2736 /* Look through the relocs for a section during the first phase, and
2737 calculate needed space in the global offset table, procedure linkage
2738 table, and dynamic reloc sections. */
2741 elf32_tic6x_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2742 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2744 struct elf32_tic6x_link_hash_table
*htab
;
2745 Elf_Internal_Shdr
*symtab_hdr
;
2746 struct elf_link_hash_entry
**sym_hashes
;
2747 const Elf_Internal_Rela
*rel
;
2748 const Elf_Internal_Rela
*rel_end
;
2751 if (bfd_link_relocatable (info
))
2754 htab
= elf32_tic6x_hash_table (info
);
2755 symtab_hdr
= &elf_symtab_hdr (abfd
);
2756 sym_hashes
= elf_sym_hashes (abfd
);
2758 /* Create dynamic sections for relocatable executables so that we can
2759 copy relocations. */
2760 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2761 && ! htab
->elf
.dynamic_sections_created
)
2763 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2769 rel_end
= relocs
+ sec
->reloc_count
;
2770 for (rel
= relocs
; rel
< rel_end
; rel
++)
2772 unsigned int r_type
;
2773 unsigned int r_symndx
;
2774 struct elf_link_hash_entry
*h
;
2775 Elf_Internal_Sym
*isym
;
2777 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2778 r_type
= ELF32_R_TYPE (rel
->r_info
);
2780 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2782 /* xgettext:c-format */
2783 _bfd_error_handler (_("%pB: bad symbol index: %d"),
2788 if (r_symndx
< symtab_hdr
->sh_info
)
2790 /* A local symbol. */
2791 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2800 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2801 while (h
->root
.type
== bfd_link_hash_indirect
2802 || h
->root
.type
== bfd_link_hash_warning
)
2803 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2808 case R_C6000_PCR_S21
:
2809 case R_C6000_PREL31
:
2810 /* This symbol requires a procedure linkage table entry. We
2811 actually build the entry in adjust_dynamic_symbol,
2812 because this might be a case of linking PIC code which is
2813 never referenced by a dynamic object, in which case we
2814 don't need to generate a procedure linkage table entry
2817 /* If this is a local symbol, we resolve it directly without
2818 creating a procedure linkage table entry. */
2823 h
->plt
.refcount
+= 1;
2826 case R_C6000_SBR_GOT_U15_W
:
2827 case R_C6000_SBR_GOT_L16_W
:
2828 case R_C6000_SBR_GOT_H16_W
:
2829 case R_C6000_EHTYPE
:
2830 /* This symbol requires a global offset table entry. */
2833 h
->got
.refcount
+= 1;
2837 bfd_signed_vma
*local_got_refcounts
;
2839 /* This is a global offset table entry for a local symbol. */
2840 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2841 if (local_got_refcounts
== NULL
)
2845 size
= symtab_hdr
->sh_info
;
2846 size
*= (sizeof (bfd_signed_vma
)
2847 + sizeof (bfd_vma
) + sizeof(char));
2848 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2849 if (local_got_refcounts
== NULL
)
2851 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2853 local_got_refcounts
[r_symndx
] += 1;
2856 if (htab
->elf
.sgot
== NULL
)
2858 if (htab
->elf
.dynobj
== NULL
)
2859 htab
->elf
.dynobj
= abfd
;
2860 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2865 case R_C6000_DSBT_INDEX
:
2866 /* We'd like to check for nonzero dsbt_index here, but it's
2867 set up only after check_relocs is called. Instead, we
2868 store the number of R_C6000_DSBT_INDEX relocs in the
2869 pc_count field, and potentially discard the extra space
2870 in elf32_tic6x_allocate_dynrelocs. */
2871 if (!bfd_link_pic (info
))
2878 case R_C6000_ABS_S16
:
2879 case R_C6000_ABS_L16
:
2880 case R_C6000_ABS_H16
:
2881 /* If we are creating a shared library, and this is a reloc
2882 against a global symbol, or a non PC relative reloc
2883 against a local symbol, then we need to copy the reloc
2884 into the shared library. However, if we are linking with
2885 -Bsymbolic, we do not need to copy a reloc against a
2886 global symbol which is defined in an object we are
2887 including in the link (i.e., DEF_REGULAR is set). At
2888 this point we have not seen all the input files, so it is
2889 possible that DEF_REGULAR is not set now but will be set
2890 later (it is never cleared). In case of a weak definition,
2891 DEF_REGULAR may be cleared later by a strong definition in
2892 a shared library. We account for that possibility below by
2893 storing information in the relocs_copied field of the hash
2894 table entry. A similar situation occurs when creating
2895 shared libraries and symbol visibility changes render the
2898 If on the other hand, we are creating an executable, we
2899 may need to keep relocations for symbols satisfied by a
2900 dynamic library if we manage to avoid copy relocs for the
2902 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2903 && (sec
->flags
& SEC_ALLOC
) != 0)
2905 struct elf_dyn_relocs
*p
;
2906 struct elf_dyn_relocs
**head
;
2908 /* We must copy these reloc types into the output file.
2909 Create a reloc section in dynobj and make room for
2913 if (htab
->elf
.dynobj
== NULL
)
2914 htab
->elf
.dynobj
= abfd
;
2916 sreloc
= _bfd_elf_make_dynamic_reloc_section
2917 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela? */ TRUE
);
2923 /* If this is a global symbol, we count the number of
2924 relocations we need for this symbol. */
2927 head
= &((struct elf32_tic6x_link_hash_entry
*) h
)->dyn_relocs
;
2931 /* Track dynamic relocs needed for local syms too.
2932 We really need local syms available to do this
2937 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2941 vpp
= &elf_section_data (s
)->local_dynrel
;
2942 head
= (struct elf_dyn_relocs
**)vpp
;
2946 if (p
== NULL
|| p
->sec
!= sec
)
2948 bfd_size_type amt
= sizeof *p
;
2949 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
2960 if (r_type
== R_C6000_DSBT_INDEX
)
2965 case R_C6000_SBR_U15_B
:
2966 case R_C6000_SBR_U15_H
:
2967 case R_C6000_SBR_U15_W
:
2968 case R_C6000_SBR_S16
:
2969 case R_C6000_SBR_L16_B
:
2970 case R_C6000_SBR_L16_H
:
2971 case R_C6000_SBR_L16_W
:
2972 case R_C6000_SBR_H16_B
:
2973 case R_C6000_SBR_H16_H
:
2974 case R_C6000_SBR_H16_W
:
2975 if (h
!= NULL
&& bfd_link_executable (info
))
2977 /* For B14-relative addresses, we might need a copy
2992 elf32_tic6x_add_symbol_hook (bfd
*abfd
,
2993 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2994 Elf_Internal_Sym
*sym
,
2995 const char **namep ATTRIBUTE_UNUSED
,
2996 flagword
*flagsp ATTRIBUTE_UNUSED
,
3000 switch (sym
->st_shndx
)
3002 case SHN_TIC6X_SCOMMON
:
3003 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3004 (*secp
)->flags
|= SEC_IS_COMMON
;
3005 *valp
= sym
->st_size
;
3006 (void) bfd_set_section_alignment (abfd
, *secp
, bfd_log2 (sym
->st_value
));
3014 elf32_tic6x_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
3016 elf_symbol_type
*elfsym
;
3018 elfsym
= (elf_symbol_type
*) asym
;
3019 switch (elfsym
->internal_elf_sym
.st_shndx
)
3021 case SHN_TIC6X_SCOMMON
:
3022 if (tic6x_elf_scom_section
.name
== NULL
)
3024 /* Initialize the small common section. */
3025 tic6x_elf_scom_section
.name
= ".scommon";
3026 tic6x_elf_scom_section
.flags
= SEC_IS_COMMON
;
3027 tic6x_elf_scom_section
.output_section
= &tic6x_elf_scom_section
;
3028 tic6x_elf_scom_section
.symbol
= &tic6x_elf_scom_symbol
;
3029 tic6x_elf_scom_section
.symbol_ptr_ptr
= &tic6x_elf_scom_symbol_ptr
;
3030 tic6x_elf_scom_symbol
.name
= ".scommon";
3031 tic6x_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3032 tic6x_elf_scom_symbol
.section
= &tic6x_elf_scom_section
;
3033 tic6x_elf_scom_symbol_ptr
= &tic6x_elf_scom_symbol
;
3035 asym
->section
= &tic6x_elf_scom_section
;
3036 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3042 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3043 const char *name ATTRIBUTE_UNUSED
,
3044 Elf_Internal_Sym
*sym
,
3045 asection
*input_sec
,
3046 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
3048 /* If we see a common symbol, which implies a relocatable link, then
3049 if a symbol was small common in an input file, mark it as small
3050 common in the output file. */
3051 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
3052 sym
->st_shndx
= SHN_TIC6X_SCOMMON
;
3058 elf32_tic6x_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
3062 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3064 *retval
= SHN_TIC6X_SCOMMON
;
3071 /* Allocate space in .plt, .got and associated reloc sections for
3075 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3077 struct bfd_link_info
*info
;
3078 struct elf32_tic6x_link_hash_table
*htab
;
3079 struct elf32_tic6x_link_hash_entry
*eh
;
3080 struct elf_dyn_relocs
*p
;
3082 if (h
->root
.type
== bfd_link_hash_indirect
)
3085 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3086 info
= (struct bfd_link_info
*) inf
;
3087 htab
= elf32_tic6x_hash_table (info
);
3089 if (htab
->elf
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3091 /* Make sure this symbol is output as a dynamic symbol.
3092 Undefined weak syms won't yet be marked as dynamic. */
3093 if (h
->dynindx
== -1 && !h
->forced_local
)
3095 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3099 if (bfd_link_pic (info
)
3100 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3102 asection
*s
= htab
->elf
.splt
;
3104 /* If this is the first .plt entry, make room for the special
3107 s
->size
+= PLT_ENTRY_SIZE
;
3109 h
->plt
.offset
= s
->size
;
3111 /* If this symbol is not defined in a regular file, and we are
3112 not generating a shared library, then set the symbol to this
3113 location in the .plt. This is required to make function
3114 pointers compare as equal between the normal executable and
3115 the shared library. */
3116 if (! bfd_link_pic (info
) && !h
->def_regular
)
3118 h
->root
.u
.def
.section
= s
;
3119 h
->root
.u
.def
.value
= h
->plt
.offset
;
3122 /* Make room for this entry. */
3123 s
->size
+= PLT_ENTRY_SIZE
;
3124 /* We also need to make an entry in the .got.plt section, which
3125 will be placed in the .got section by the linker script. */
3126 htab
->elf
.sgotplt
->size
+= 4;
3127 /* We also need to make an entry in the .rel.plt section. */
3128 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3132 h
->plt
.offset
= (bfd_vma
) -1;
3138 h
->plt
.offset
= (bfd_vma
) -1;
3142 if (h
->got
.refcount
> 0)
3146 /* Make sure this symbol is output as a dynamic symbol.
3147 Undefined weak syms won't yet be marked as dynamic. */
3148 if (h
->dynindx
== -1
3149 && !h
->forced_local
)
3151 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3156 h
->got
.offset
= s
->size
;
3159 if (!(ELF_ST_VISIBILITY (h
->other
)
3160 && h
->root
.type
== bfd_link_hash_undefweak
))
3161 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3164 h
->got
.offset
= (bfd_vma
) -1;
3166 if (eh
->dyn_relocs
== NULL
)
3169 /* Discard relocs on undefined weak syms with non-default
3171 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (htab
->obfd
))
3173 /* We use the pc_count field to hold the number of
3174 R_C6000_DSBT_INDEX relocs. */
3175 if (htab
->params
.dsbt_index
!= 0)
3177 struct elf_dyn_relocs
**pp
;
3179 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3181 p
->count
-= p
->pc_count
;
3190 if (eh
->dyn_relocs
!= NULL
3191 && h
->root
.type
== bfd_link_hash_undefweak
)
3193 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3194 eh
->dyn_relocs
= NULL
;
3196 /* Make sure undefined weak symbols are output as a dynamic
3198 else if (h
->dynindx
== -1
3199 && !h
->forced_local
)
3201 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3207 /* Finally, allocate space. */
3208 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3212 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3214 BFD_ASSERT (sreloc
!= NULL
);
3215 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3221 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
3222 read-only sections. */
3225 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
3229 if (h
->root
.type
== bfd_link_hash_indirect
)
3232 sec
= readonly_dynrelocs (h
);
3235 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
3237 info
->flags
|= DF_TEXTREL
;
3238 info
->callbacks
->minfo
3239 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
3240 sec
->owner
, h
->root
.root
.string
, sec
);
3242 /* Not an error, just cut short the traversal. */
3248 /* Set the sizes of the dynamic sections. */
3251 elf32_tic6x_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3253 struct elf32_tic6x_link_hash_table
*htab
;
3259 htab
= elf32_tic6x_hash_table (info
);
3260 dynobj
= htab
->elf
.dynobj
;
3264 if (htab
->elf
.dynamic_sections_created
)
3266 /* Set the contents of the .interp section to the interpreter. */
3267 if (bfd_link_executable (info
) && !info
->nointerp
)
3269 s
= bfd_get_linker_section (dynobj
, ".interp");
3272 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3273 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3277 /* Set up .got offsets for local syms, and space for local dynamic
3279 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3281 bfd_signed_vma
*local_got
;
3282 bfd_signed_vma
*end_local_got
;
3283 bfd_size_type locsymcount
;
3284 Elf_Internal_Shdr
*symtab_hdr
;
3287 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3289 struct elf_dyn_relocs
*p
;
3291 for (p
= ((struct elf_dyn_relocs
*)
3292 elf_section_data (s
)->local_dynrel
);
3296 if (!bfd_is_abs_section (p
->sec
)
3297 && bfd_is_abs_section (p
->sec
->output_section
))
3299 /* Input section has been discarded, either because
3300 it is a copy of a linkonce section or due to
3301 linker script /DISCARD/, so we'll be discarding
3304 else if (p
->count
!= 0)
3306 srel
= elf_section_data (p
->sec
)->sreloc
;
3307 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3308 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3309 info
->flags
|= DF_TEXTREL
;
3314 local_got
= elf_local_got_refcounts (ibfd
);
3318 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3319 locsymcount
= symtab_hdr
->sh_info
;
3320 end_local_got
= local_got
+ locsymcount
;
3322 srel
= htab
->elf
.srelgot
;
3323 for (; local_got
< end_local_got
; ++local_got
)
3327 *local_got
= s
->size
;
3330 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
3332 srel
->size
+= sizeof (Elf32_External_Rela
);
3336 *local_got
= (bfd_vma
) -1;
3340 /* Allocate global sym .plt and .got entries, and space for global
3341 sym dynamic relocs. */
3342 elf_link_hash_traverse (&htab
->elf
, elf32_tic6x_allocate_dynrelocs
, info
);
3344 /* We now have determined the sizes of the various dynamic sections.
3345 Allocate memory for them. */
3347 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3349 bfd_boolean strip_section
= TRUE
;
3351 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3354 if (s
== htab
->dsbt
)
3355 s
->size
= 4 * htab
->params
.dsbt_size
;
3356 else if (s
== htab
->elf
.splt
3357 || s
== htab
->elf
.sgot
3358 || s
== htab
->elf
.sgotplt
3359 || s
== htab
->elf
.sdynbss
3360 || s
== htab
->elf
.sdynrelro
)
3362 /* Strip this section if we don't need it; see the
3364 /* We'd like to strip these sections if they aren't needed, but if
3365 we've exported dynamic symbols from them we must leave them.
3366 It's too late to tell BFD to get rid of the symbols. */
3368 if (htab
->elf
.hplt
!= NULL
)
3369 strip_section
= FALSE
;
3371 /* Round up the size of the PLT section to a multiple of 32. */
3372 if (s
== htab
->elf
.splt
&& s
->size
> 0)
3373 s
->size
= (s
->size
+ 31) & ~(bfd_vma
)31;
3375 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3378 && s
!= htab
->elf
.srelplt
)
3381 /* We use the reloc_count field as a counter if we need
3382 to copy relocs into the output file. */
3387 /* It's not one of our sections, so don't allocate space. */
3393 /* If we don't need this section, strip it from the
3394 output file. This is mostly to handle .rel.bss and
3395 .rel.plt. We must create both sections in
3396 create_dynamic_sections, because they must be created
3397 before the linker maps input sections to output
3398 sections. The linker does that before
3399 adjust_dynamic_symbol is called, and it is that
3400 function which decides whether anything needs to go
3401 into these sections. */
3403 s
->flags
|= SEC_EXCLUDE
;
3407 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3410 /* Allocate memory for the section contents. We use bfd_zalloc
3411 here in case unused entries are not reclaimed before the
3412 section's contents are written out. This should not happen,
3413 but this way if it does, we get a R_C6000_NONE reloc instead
3415 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3416 if (s
->contents
== NULL
)
3420 if (htab
->elf
.dynamic_sections_created
)
3422 /* Add some entries to the .dynamic section. We fill in the
3423 values later, in elf32_tic6x_finish_dynamic_sections, but we
3424 must add the entries now so that we get the correct size for
3425 the .dynamic section. The DT_DEBUG entry is filled in by the
3426 dynamic linker and used by the debugger. */
3427 #define add_dynamic_entry(TAG, VAL) \
3428 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3430 if (bfd_link_executable (info
))
3432 if (!add_dynamic_entry (DT_DEBUG
, 0))
3436 if (!add_dynamic_entry (DT_C6000_DSBT_BASE
, 0)
3437 || !add_dynamic_entry (DT_C6000_DSBT_SIZE
, htab
->params
.dsbt_size
)
3438 || !add_dynamic_entry (DT_C6000_DSBT_INDEX
,
3439 htab
->params
.dsbt_index
))
3442 if (htab
->elf
.splt
->size
!= 0)
3444 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3445 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3446 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3447 || !add_dynamic_entry (DT_JMPREL
, 0))
3453 if (!add_dynamic_entry (DT_RELA
, 0)
3454 || !add_dynamic_entry (DT_RELASZ
, 0)
3455 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3458 /* If any dynamic relocs apply to a read-only section,
3459 then we need a DT_TEXTREL entry. */
3460 if ((info
->flags
& DF_TEXTREL
) == 0)
3461 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
3463 if ((info
->flags
& DF_TEXTREL
) != 0)
3465 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3470 #undef add_dynamic_entry
3475 /* This function is called after all the input files have been read,
3476 and the input sections have been assigned to output sections. */
3479 elf32_tic6x_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3481 if (elf32_tic6x_using_dsbt (output_bfd
) && !bfd_link_relocatable (info
)
3482 && !bfd_elf_stack_segment_size (output_bfd
, info
,
3483 "__stacksize", DEFAULT_STACK_SIZE
))
3490 elf32_tic6x_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3491 struct bfd_link_info
*info
)
3493 struct elf32_tic6x_link_hash_table
*htab
;
3497 htab
= elf32_tic6x_hash_table (info
);
3498 dynobj
= htab
->elf
.dynobj
;
3499 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
3501 if (elf_hash_table (info
)->dynamic_sections_created
)
3503 Elf32_External_Dyn
* dyncon
;
3504 Elf32_External_Dyn
* dynconend
;
3506 BFD_ASSERT (sdyn
!= NULL
);
3508 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3509 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3511 for (; dyncon
< dynconend
; dyncon
++)
3513 Elf_Internal_Dyn dyn
;
3516 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3523 case DT_C6000_DSBT_BASE
:
3525 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
);
3529 s
= htab
->elf
.sgotplt
;
3530 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3534 s
= htab
->elf
.srelplt
;
3535 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3539 s
= htab
->elf
.srelplt
;
3540 dyn
.d_un
.d_val
= s
->size
;
3543 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3546 /* Fill in the first entry in the procedure linkage table. */
3547 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
3549 bfd_vma got_offs
= (htab
->elf
.sgotplt
->output_section
->vma
3550 + htab
->elf
.sgotplt
->output_offset
3551 - htab
->dsbt
->output_section
->vma
3552 - htab
->dsbt
->output_offset
) / 4;
3554 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3555 bfd_put_32 (output_bfd
, got_offs
<< 8 | 0x0100006e,
3556 htab
->elf
.splt
->contents
);
3557 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3558 bfd_put_32 (output_bfd
, (got_offs
+ 1) << 8 | 0x0080006e,
3559 htab
->elf
.splt
->contents
+ 4);
3561 bfd_put_32 (output_bfd
, 0x00004000,
3562 htab
->elf
.splt
->contents
+ 8);
3564 bfd_put_32 (output_bfd
, 0x00080362,
3565 htab
->elf
.splt
->contents
+ 12);
3567 bfd_put_32 (output_bfd
, 0x00008000,
3568 htab
->elf
.splt
->contents
+ 16);
3570 elf_section_data (htab
->elf
.splt
->output_section
)
3571 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3578 /* Return address for Ith PLT stub in section PLT, for relocation REL
3579 or (bfd_vma) -1 if it should not be included. */
3582 elf32_tic6x_plt_sym_val (bfd_vma i
, const asection
*plt
,
3583 const arelent
*rel ATTRIBUTE_UNUSED
)
3585 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3589 elf32_tic6x_obj_attrs_arg_type (int tag
)
3591 if (tag
== Tag_ABI_compatibility
)
3592 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
3594 return ATTR_TYPE_FLAG_STR_VAL
;
3596 return ATTR_TYPE_FLAG_INT_VAL
;
3600 elf32_tic6x_obj_attrs_order (int num
)
3602 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
3603 return Tag_ABI_conformance
;
3604 if ((num
- 1) < Tag_ABI_conformance
)
3610 elf32_tic6x_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
3612 if ((tag
& 127) < 64)
3615 /* xgettext:c-format */
3616 (_("%pB: error: unknown mandatory EABI object attribute %d"),
3618 bfd_set_error (bfd_error_bad_value
);
3624 /* xgettext:c-format */
3625 (_("%pB: warning: unknown EABI object attribute %d"),
3631 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3632 and return the merged value. At present, all merges succeed, so no
3633 return value for errors is defined. */
3636 elf32_tic6x_merge_arch_attributes (int arch1
, int arch2
)
3638 int min_arch
, max_arch
;
3640 min_arch
= (arch1
< arch2
? arch1
: arch2
);
3641 max_arch
= (arch1
> arch2
? arch1
: arch2
);
3643 /* In most cases, the numerically greatest value is the correct
3644 merged value, but merging C64 and C67 results in C674X. */
3645 if ((min_arch
== C6XABI_Tag_ISA_C67X
3646 || min_arch
== C6XABI_Tag_ISA_C67XP
)
3647 && (max_arch
== C6XABI_Tag_ISA_C64X
3648 || max_arch
== C6XABI_Tag_ISA_C64XP
))
3649 return C6XABI_Tag_ISA_C674X
;
3654 /* Convert a Tag_ABI_array_object_alignment or
3655 Tag_ABI_array_object_align_expected tag value TAG to a
3656 corresponding alignment value; return the alignment, or -1 for an
3657 unknown tag value. */
3660 elf32_tic6x_tag_to_array_alignment (int tag
)
3678 /* Convert a Tag_ABI_array_object_alignment or
3679 Tag_ABI_array_object_align_expected alignment ALIGN to a
3680 corresponding tag value; return the tag value. */
3683 elf32_tic6x_array_alignment_to_tag (int align
)
3701 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3702 succeeded, FALSE otherwise. */
3705 elf32_tic6x_merge_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
3707 bfd
*obfd
= info
->output_bfd
;
3708 bfd_boolean result
= TRUE
;
3709 obj_attribute
*in_attr
;
3710 obj_attribute
*out_attr
;
3712 int array_align_in
, array_align_out
, array_expect_in
, array_expect_out
;
3714 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
3716 /* This is the first object. Copy the attributes. */
3717 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
3719 out_attr
= elf_known_obj_attributes_proc (obfd
);
3721 /* Use the Tag_null value to indicate the attributes have been
3728 in_attr
= elf_known_obj_attributes_proc (ibfd
);
3729 out_attr
= elf_known_obj_attributes_proc (obfd
);
3731 /* No specification yet for handling of unknown attributes, so just
3732 ignore them and handle known ones. */
3734 if (out_attr
[Tag_ABI_stack_align_preserved
].i
3735 < in_attr
[Tag_ABI_stack_align_needed
].i
)
3738 /* xgettext:c-format */
3739 (_("error: %pB requires more stack alignment than %pB preserves"),
3743 if (in_attr
[Tag_ABI_stack_align_preserved
].i
3744 < out_attr
[Tag_ABI_stack_align_needed
].i
)
3747 /* xgettext:c-format */
3748 (_("error: %pB requires more stack alignment than %pB preserves"),
3753 array_align_in
= elf32_tic6x_tag_to_array_alignment
3754 (in_attr
[Tag_ABI_array_object_alignment
].i
);
3755 if (array_align_in
== -1)
3758 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
3762 array_align_out
= elf32_tic6x_tag_to_array_alignment
3763 (out_attr
[Tag_ABI_array_object_alignment
].i
);
3764 if (array_align_out
== -1)
3767 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
3771 array_expect_in
= elf32_tic6x_tag_to_array_alignment
3772 (in_attr
[Tag_ABI_array_object_align_expected
].i
);
3773 if (array_expect_in
== -1)
3776 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
3780 array_expect_out
= elf32_tic6x_tag_to_array_alignment
3781 (out_attr
[Tag_ABI_array_object_align_expected
].i
);
3782 if (array_expect_out
== -1)
3785 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
3790 if (array_align_out
< array_expect_in
)
3793 /* xgettext:c-format */
3794 (_("error: %pB requires more array alignment than %pB preserves"),
3798 if (array_align_in
< array_expect_out
)
3801 /* xgettext:c-format */
3802 (_("error: %pB requires more array alignment than %pB preserves"),
3807 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
3812 out_attr
[i
].i
= elf32_tic6x_merge_arch_attributes (in_attr
[i
].i
,
3816 case Tag_ABI_wchar_t
:
3817 if (out_attr
[i
].i
== 0)
3818 out_attr
[i
].i
= in_attr
[i
].i
;
3819 if (out_attr
[i
].i
!= 0
3820 && in_attr
[i
].i
!= 0
3821 && out_attr
[i
].i
!= in_attr
[i
].i
)
3824 /* xgettext:c-format */
3825 (_("warning: %pB and %pB differ in wchar_t size"), obfd
, ibfd
);
3829 case Tag_ABI_stack_align_needed
:
3830 if (out_attr
[i
].i
< in_attr
[i
].i
)
3831 out_attr
[i
].i
= in_attr
[i
].i
;
3834 case Tag_ABI_stack_align_preserved
:
3835 if (out_attr
[i
].i
> in_attr
[i
].i
)
3836 out_attr
[i
].i
= in_attr
[i
].i
;
3840 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3843 /* xgettext:c-format */
3844 (_("warning: %pB and %pB differ in whether code is "
3845 "compiled for DSBT"),
3852 if (out_attr
[i
].i
> in_attr
[i
].i
)
3853 out_attr
[i
].i
= in_attr
[i
].i
;
3856 case Tag_ABI_array_object_alignment
:
3857 if (array_align_out
!= -1
3858 && array_align_in
!= -1
3859 && array_align_out
> array_align_in
)
3861 = elf32_tic6x_array_alignment_to_tag (array_align_in
);
3864 case Tag_ABI_array_object_align_expected
:
3865 if (array_expect_out
!= -1
3866 && array_expect_in
!= -1
3867 && array_expect_out
< array_expect_in
)
3869 = elf32_tic6x_array_alignment_to_tag (array_expect_in
);
3872 case Tag_ABI_conformance
:
3873 /* Merging for this attribute is not specified. As on ARM,
3874 treat a missing attribute as no claim to conform and only
3875 merge identical values. */
3876 if (out_attr
[i
].s
== NULL
3877 || in_attr
[i
].s
== NULL
3878 || strcmp (out_attr
[i
].s
,
3880 out_attr
[i
].s
= NULL
;
3883 case Tag_ABI_compatibility
:
3884 /* Merged in _bfd_elf_merge_object_attributes. */
3889 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
3893 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
3894 out_attr
[i
].type
= in_attr
[i
].type
;
3897 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
3898 if (!_bfd_elf_merge_object_attributes (ibfd
, info
))
3901 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
3907 elf32_tic6x_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
3909 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
3912 if (! is_tic6x_elf (ibfd
) || ! is_tic6x_elf (info
->output_bfd
))
3915 if (!elf32_tic6x_merge_attributes (ibfd
, info
))
3921 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
3922 adds the edit to the start of the list. (The list must be built in order of
3923 ascending TINDEX: the function's callers are primarily responsible for
3924 maintaining that condition). */
3927 elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit
**head
,
3928 tic6x_unwind_table_edit
**tail
,
3929 tic6x_unwind_edit_type type
,
3930 asection
*linked_section
,
3931 unsigned int tindex
)
3933 tic6x_unwind_table_edit
*new_edit
= (tic6x_unwind_table_edit
*)
3934 xmalloc (sizeof (tic6x_unwind_table_edit
));
3936 new_edit
->type
= type
;
3937 new_edit
->linked_section
= linked_section
;
3938 new_edit
->index
= tindex
;
3942 new_edit
->next
= NULL
;
3945 (*tail
)->next
= new_edit
;
3954 new_edit
->next
= *head
;
3963 static _tic6x_elf_section_data
*
3964 get_tic6x_elf_section_data (asection
* sec
)
3966 if (sec
&& sec
->owner
&& is_tic6x_elf (sec
->owner
))
3967 return elf32_tic6x_section_data (sec
);
3973 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST must be negative. */
3975 elf32_tic6x_adjust_exidx_size (asection
*exidx_sec
, int adjust
)
3979 if (!exidx_sec
->rawsize
)
3980 exidx_sec
->rawsize
= exidx_sec
->size
;
3982 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
3983 out_sec
= exidx_sec
->output_section
;
3984 /* Adjust size of output section. */
3985 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
3988 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
3990 elf32_tic6x_insert_cantunwind_after (asection
*text_sec
, asection
*exidx_sec
)
3992 struct _tic6x_elf_section_data
*exidx_data
;
3994 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
3995 elf32_tic6x_add_unwind_table_edit (
3996 &exidx_data
->u
.exidx
.unwind_edit_list
,
3997 &exidx_data
->u
.exidx
.unwind_edit_tail
,
3998 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
4000 elf32_tic6x_adjust_exidx_size (exidx_sec
, 8);
4003 /* Scan .cx6abi.exidx tables, and create a list describing edits which
4004 should be made to those tables, such that:
4006 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
4007 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
4008 codes which have been inlined into the index).
4010 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
4012 The edits are applied when the tables are written
4013 (in elf32_tic6x_write_section).
4017 elf32_tic6x_fix_exidx_coverage (asection
**text_section_order
,
4018 unsigned int num_text_sections
,
4019 struct bfd_link_info
*info
,
4020 bfd_boolean merge_exidx_entries
)
4023 unsigned int last_second_word
= 0, i
;
4024 asection
*last_exidx_sec
= NULL
;
4025 asection
*last_text_sec
= NULL
;
4026 int last_unwind_type
= -1;
4028 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
4030 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link
.next
)
4034 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
4036 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
4037 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
4039 if (!hdr
|| hdr
->sh_type
!= SHT_C6000_UNWIND
)
4042 if (elf_sec
->linked_to
)
4044 Elf_Internal_Shdr
*linked_hdr
4045 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
4046 struct _tic6x_elf_section_data
*linked_sec_tic6x_data
4047 = get_tic6x_elf_section_data (linked_hdr
->bfd_section
);
4049 if (linked_sec_tic6x_data
== NULL
)
4052 /* Link this .c6xabi.exidx section back from the
4053 text section it describes. */
4054 linked_sec_tic6x_data
->u
.text
.tic6x_exidx_sec
= sec
;
4059 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
4060 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
4061 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
4063 for (i
= 0; i
< num_text_sections
; i
++)
4065 asection
*sec
= text_section_order
[i
];
4066 asection
*exidx_sec
;
4067 struct _tic6x_elf_section_data
*tic6x_data
4068 = get_tic6x_elf_section_data (sec
);
4069 struct _tic6x_elf_section_data
*exidx_data
;
4070 bfd_byte
*contents
= NULL
;
4071 int deleted_exidx_bytes
= 0;
4073 tic6x_unwind_table_edit
*unwind_edit_head
= NULL
;
4074 tic6x_unwind_table_edit
*unwind_edit_tail
= NULL
;
4075 Elf_Internal_Shdr
*hdr
;
4078 if (tic6x_data
== NULL
)
4081 exidx_sec
= tic6x_data
->u
.text
.tic6x_exidx_sec
;
4082 if (exidx_sec
== NULL
)
4084 /* Section has no unwind data. */
4085 if (last_unwind_type
== 0 || !last_exidx_sec
)
4088 /* Ignore zero sized sections. */
4092 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4093 last_unwind_type
= 0;
4097 /* Skip /DISCARD/ sections. */
4098 if (bfd_is_abs_section (exidx_sec
->output_section
))
4101 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
4102 if (hdr
->sh_type
!= SHT_C6000_UNWIND
)
4105 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
4106 if (exidx_data
== NULL
)
4109 ibfd
= exidx_sec
->owner
;
4111 if (hdr
->contents
!= NULL
)
4112 contents
= hdr
->contents
;
4113 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
4117 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
4119 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
4123 /* An EXIDX_CANTUNWIND entry. */
4124 if (second_word
== 1)
4126 if (last_unwind_type
== 0)
4130 /* Inlined unwinding data. Merge if equal to previous. */
4131 else if ((second_word
& 0x80000000) != 0)
4133 if (merge_exidx_entries
4134 && last_second_word
== second_word
4135 && last_unwind_type
== 1)
4138 last_second_word
= second_word
;
4140 /* Normal table entry. In theory we could merge these too,
4141 but duplicate entries are likely to be much less common. */
4147 elf32_tic6x_add_unwind_table_edit (&unwind_edit_head
,
4148 &unwind_edit_tail
, DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
4150 deleted_exidx_bytes
+= 8;
4153 last_unwind_type
= unwind_type
;
4156 /* Free contents if we allocated it ourselves. */
4157 if (contents
!= hdr
->contents
)
4160 /* Record edits to be applied later (in elf32_tic6x_write_section). */
4161 exidx_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
4162 exidx_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
4164 if (deleted_exidx_bytes
> 0)
4165 elf32_tic6x_adjust_exidx_size (exidx_sec
, -deleted_exidx_bytes
);
4167 last_exidx_sec
= exidx_sec
;
4168 last_text_sec
= sec
;
4171 /* Add terminating CANTUNWIND entry. */
4172 if (last_exidx_sec
&& last_unwind_type
!= 0)
4173 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4178 /* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified. */
4180 static unsigned long
4181 elf32_tic6x_add_low31 (unsigned long val
, bfd_vma addend
)
4183 return (val
& ~0x7ffffffful
) | ((val
+ addend
) & 0x7ffffffful
);
4186 /* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
4187 relocations. OFFSET is in bytes, and will be scaled before encoding. */
4191 elf32_tic6x_copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
,
4194 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
4195 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
4198 /* High bit of first word is supposed to be zero. */
4199 if ((first_word
& 0x80000000ul
) == 0)
4200 first_word
= elf32_tic6x_add_low31 (first_word
, offset
);
4202 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
4203 (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry. */
4204 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
4205 second_word
= elf32_tic6x_add_low31 (second_word
, offset
);
4207 bfd_put_32 (output_bfd
, first_word
, to
);
4208 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
4211 /* Do the actual mangling of exception index tables. */
4214 elf32_tic6x_write_section (bfd
*output_bfd
,
4215 struct bfd_link_info
*link_info
,
4219 _tic6x_elf_section_data
*tic6x_data
;
4220 struct elf32_tic6x_link_hash_table
*globals
4221 = elf32_tic6x_hash_table (link_info
);
4222 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4224 if (globals
== NULL
)
4227 /* If this section has not been allocated an _tic6x_elf_section_data
4228 structure then we cannot record anything. */
4229 tic6x_data
= get_tic6x_elf_section_data (sec
);
4230 if (tic6x_data
== NULL
)
4233 if (tic6x_data
->elf
.this_hdr
.sh_type
!= SHT_C6000_UNWIND
)
4236 tic6x_unwind_table_edit
*edit_node
4237 = tic6x_data
->u
.exidx
.unwind_edit_list
;
4238 /* Now, sec->size is the size of the section we will write. The original
4239 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
4240 markers) was sec->rawsize. (This isn't the case if we perform no
4241 edits, then rawsize will be zero and we should use size). */
4242 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
4243 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
4244 unsigned int in_index
, out_index
;
4245 bfd_vma add_to_offsets
= 0;
4247 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
4251 unsigned int edit_index
= edit_node
->index
;
4253 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
4255 elf32_tic6x_copy_exidx_entry (output_bfd
,
4256 edited_contents
+ out_index
* 8,
4257 contents
+ in_index
* 8, add_to_offsets
);
4261 else if (in_index
== edit_index
4262 || (in_index
* 8 >= input_size
4263 && edit_index
== UINT_MAX
))
4265 switch (edit_node
->type
)
4267 case DELETE_EXIDX_ENTRY
:
4269 add_to_offsets
+= 8;
4272 case INSERT_EXIDX_CANTUNWIND_AT_END
:
4274 asection
*text_sec
= edit_node
->linked_section
;
4275 bfd_vma text_offset
= text_sec
->output_section
->vma
4276 + text_sec
->output_offset
4278 bfd_vma exidx_offset
= offset
+ out_index
* 8;
4279 unsigned long prel31_offset
;
4281 /* Note: this is meant to be equivalent to an
4282 R_C6000_PREL31 relocation. These synthetic
4283 EXIDX_CANTUNWIND markers are not relocated by the
4284 usual BFD method. */
4285 prel31_offset
= ((text_offset
- exidx_offset
) >> 1)
4288 /* First address we can't unwind. */
4289 bfd_put_32 (output_bfd
, prel31_offset
,
4290 &edited_contents
[out_index
* 8]);
4292 /* Code for EXIDX_CANTUNWIND. */
4293 bfd_put_32 (output_bfd
, 0x1,
4294 &edited_contents
[out_index
* 8 + 4]);
4297 add_to_offsets
-= 8;
4302 edit_node
= edit_node
->next
;
4307 /* No more edits, copy remaining entries verbatim. */
4308 elf32_tic6x_copy_exidx_entry (output_bfd
,
4309 edited_contents
+ out_index
* 8,
4310 contents
+ in_index
* 8, add_to_offsets
);
4316 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
4317 bfd_set_section_contents (output_bfd
, sec
->output_section
,
4319 (file_ptr
) sec
->output_offset
, sec
->size
);
4324 #define TARGET_LITTLE_SYM tic6x_elf32_le_vec
4325 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
4326 #define TARGET_BIG_SYM tic6x_elf32_be_vec
4327 #define TARGET_BIG_NAME "elf32-tic6x-be"
4328 #define ELF_ARCH bfd_arch_tic6x
4329 #define ELF_TARGET_ID TIC6X_ELF_DATA
4330 #define ELF_MACHINE_CODE EM_TI_C6000
4331 #define ELF_MAXPAGESIZE 0x1000
4332 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
4333 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
4334 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
4335 #define bfd_elf32_mkobject elf32_tic6x_mkobject
4336 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
4337 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
4338 #define elf_backend_stack_align 8
4339 #define elf_backend_can_gc_sections 1
4340 #define elf_backend_default_use_rela_p 1
4341 #define elf_backend_may_use_rel_p 1
4342 #define elf_backend_may_use_rela_p 1
4343 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
4344 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
4345 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
4346 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
4347 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4348 #define elf_backend_obj_attrs_vendor "c6xabi"
4349 #define elf_backend_can_refcount 1
4350 #define elf_backend_want_got_plt 1
4351 #define elf_backend_want_dynbss 1
4352 #define elf_backend_want_dynrelro 1
4353 #define elf_backend_plt_readonly 1
4354 #define elf_backend_rela_normal 1
4355 #define elf_backend_got_header_size 8
4356 #define elf_backend_fake_sections elf32_tic6x_fake_sections
4357 #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
4358 #define elf_backend_create_dynamic_sections \
4359 elf32_tic6x_create_dynamic_sections
4360 #define elf_backend_adjust_dynamic_symbol \
4361 elf32_tic6x_adjust_dynamic_symbol
4362 #define elf_backend_check_relocs elf32_tic6x_check_relocs
4363 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4364 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4365 #define elf_backend_link_output_symbol_hook \
4366 elf32_tic6x_link_output_symbol_hook
4367 #define elf_backend_section_from_bfd_section \
4368 elf32_tic6x_section_from_bfd_section
4369 #define elf_backend_relocate_section elf32_tic6x_relocate_section
4370 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4371 #define elf_backend_finish_dynamic_symbol \
4372 elf32_tic6x_finish_dynamic_symbol
4373 #define elf_backend_always_size_sections \
4374 elf32_tic6x_always_size_sections
4375 #define elf_backend_size_dynamic_sections \
4376 elf32_tic6x_size_dynamic_sections
4377 #define elf_backend_finish_dynamic_sections \
4378 elf32_tic6x_finish_dynamic_sections
4379 #define bfd_elf32_bfd_final_link \
4380 elf32_tic6x_final_link
4381 #define elf_backend_write_section elf32_tic6x_write_section
4382 #define elf_info_to_howto elf32_tic6x_info_to_howto
4383 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
4385 #undef elf_backend_omit_section_dynsym
4386 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4387 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4389 #include "elf32-target.h"
4392 #define elf32_bed elf32_tic6x_linux_bed
4394 #undef TARGET_LITTLE_SYM
4395 #define TARGET_LITTLE_SYM tic6x_elf32_linux_le_vec
4396 #undef TARGET_LITTLE_NAME
4397 #define TARGET_LITTLE_NAME "elf32-tic6x-linux-le"
4398 #undef TARGET_BIG_SYM
4399 #define TARGET_BIG_SYM tic6x_elf32_linux_be_vec
4400 #undef TARGET_BIG_NAME
4401 #define TARGET_BIG_NAME "elf32-tic6x-linux-be"
4403 #define ELF_OSABI ELFOSABI_C6000_LINUX
4405 #include "elf32-target.h"
4408 #define elf32_bed elf32_tic6x_elf_bed
4410 #undef TARGET_LITTLE_SYM
4411 #define TARGET_LITTLE_SYM tic6x_elf32_c6000_le_vec
4412 #undef TARGET_LITTLE_NAME
4413 #define TARGET_LITTLE_NAME "elf32-tic6x-elf-le"
4414 #undef TARGET_BIG_SYM
4415 #define TARGET_BIG_SYM tic6x_elf32_c6000_be_vec
4416 #undef TARGET_BIG_NAME
4417 #define TARGET_BIG_NAME "elf32-tic6x-elf-be"
4419 #define ELF_OSABI ELFOSABI_C6000_ELFABI
4421 #include "elf32-target.h"