1 /* 32-bit ELF support for TI C6X
2 Copyright (C) 2010-2017 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
))
1506 bfd_reloc
->howto
= NULL
;
1508 bfd_reloc
->howto
= &elf32_tic6x_howto_table
[r_type
];
1512 elf32_tic6x_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1513 Elf_Internal_Rela
*elf_reloc
)
1515 unsigned int r_type
;
1517 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1518 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table_rel
))
1519 bfd_reloc
->howto
= NULL
;
1521 bfd_reloc
->howto
= &elf32_tic6x_howto_table_rel
[r_type
];
1525 elf32_tic6x_set_use_rela_p (bfd
*abfd
, bfd_boolean use_rela_p
)
1527 elf32_tic6x_tdata (abfd
)->use_rela_p
= use_rela_p
;
1530 /* Create an entry in a C6X ELF linker hash table. */
1532 static struct bfd_hash_entry
*
1533 elf32_tic6x_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1534 struct bfd_hash_table
*table
,
1537 /* Allocate the structure if it has not already been allocated by a
1541 entry
= bfd_hash_allocate (table
,
1542 sizeof (struct elf32_tic6x_link_hash_entry
));
1547 /* Call the allocation method of the superclass. */
1548 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1551 struct elf32_tic6x_link_hash_entry
*eh
;
1553 eh
= (struct elf32_tic6x_link_hash_entry
*) entry
;
1554 eh
->dyn_relocs
= NULL
;
1560 /* Create a C6X ELF linker hash table. */
1562 static struct bfd_link_hash_table
*
1563 elf32_tic6x_link_hash_table_create (bfd
*abfd
)
1565 struct elf32_tic6x_link_hash_table
*ret
;
1566 bfd_size_type amt
= sizeof (struct elf32_tic6x_link_hash_table
);
1568 ret
= bfd_zmalloc (amt
);
1572 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1573 elf32_tic6x_link_hash_newfunc
,
1574 sizeof (struct elf32_tic6x_link_hash_entry
),
1582 ret
->elf
.is_relocatable_executable
= 1;
1584 return &ret
->elf
.root
;
1588 elf32_tic6x_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
1590 if (bfd_link_pic (info
))
1592 obj_attribute
*out_attr
;
1593 out_attr
= elf_known_obj_attributes_proc (abfd
);
1594 if (out_attr
[Tag_ABI_PIC
].i
== 0)
1596 _bfd_error_handler (_("warning: generating a shared library "
1597 "containing non-PIC code"));
1599 if (out_attr
[Tag_ABI_PID
].i
== 0)
1601 _bfd_error_handler (_("warning: generating a shared library "
1602 "containing non-PID code"));
1605 /* Invoke the regular ELF backend linker to do all the work. */
1606 if (!bfd_elf_final_link (abfd
, info
))
1612 /* Called to pass PARAMS to the backend. We store them in the hash table
1613 associated with INFO. */
1616 elf32_tic6x_setup (struct bfd_link_info
*info
,
1617 struct elf32_tic6x_params
*params
)
1619 struct elf32_tic6x_link_hash_table
*htab
= elf32_tic6x_hash_table (info
);
1620 htab
->params
= *params
;
1623 /* Determine if we're dealing with a DSBT object. */
1626 elf32_tic6x_using_dsbt (bfd
*abfd
)
1628 return bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
,
1632 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1633 sections in DYNOBJ, and set up shortcuts to them in our hash
1637 elf32_tic6x_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1639 struct elf32_tic6x_link_hash_table
*htab
;
1642 htab
= elf32_tic6x_hash_table (info
);
1646 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1650 flags
= (SEC_ALLOC
| SEC_LOAD
1651 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1652 htab
->dsbt
= bfd_make_section_anyway_with_flags (dynobj
, ".dsbt",
1654 if (htab
->dsbt
== NULL
1655 || ! bfd_set_section_alignment (dynobj
, htab
->dsbt
, 2)
1656 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.splt
, 5))
1663 elf32_tic6x_mkobject (bfd
*abfd
)
1667 ret
= bfd_elf_allocate_object (abfd
, sizeof (struct elf32_tic6x_obj_tdata
),
1670 elf32_tic6x_set_use_rela_p (abfd
, TRUE
);
1674 /* Install relocation RELA into section SRELA, incrementing its
1678 elf32_tic6x_install_rela (bfd
*output_bfd
, asection
*srela
,
1679 Elf_Internal_Rela
*rela
)
1682 bfd_vma off
= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1683 loc
= srela
->contents
+ off
;
1684 BFD_ASSERT (off
< srela
->size
);
1685 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
1688 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1689 of the GOT at this offset have been initialized with the relocation. */
1692 elf32_tic6x_make_got_dynreloc (bfd
*output_bfd
,
1693 struct elf32_tic6x_link_hash_table
*htab
,
1694 asection
*sym_sec
, bfd_vma offset
)
1696 asection
*sgot
= htab
->elf
.sgot
;
1697 Elf_Internal_Rela outrel
;
1700 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
1701 outrel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
1702 if (sym_sec
&& sym_sec
->output_section
1703 && ! bfd_is_abs_section (sym_sec
->output_section
)
1704 && ! bfd_is_und_section (sym_sec
->output_section
))
1706 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
1707 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
1713 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_C6000_ABS32
);
1714 elf32_tic6x_install_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
1717 /* Finish up dynamic symbol handling. We set the contents of various
1718 dynamic sections here. */
1721 elf32_tic6x_finish_dynamic_symbol (bfd
* output_bfd
,
1722 struct bfd_link_info
*info
,
1723 struct elf_link_hash_entry
*h
,
1724 Elf_Internal_Sym
* sym
)
1726 struct elf32_tic6x_link_hash_table
*htab
;
1728 htab
= elf32_tic6x_hash_table (info
);
1730 if (h
->plt
.offset
!= (bfd_vma
) -1)
1733 bfd_vma got_section_offset
, got_dp_offset
, rela_offset
;
1734 Elf_Internal_Rela rela
;
1736 asection
*plt
, *gotplt
, *relplt
;
1737 const struct elf_backend_data
*bed
;
1739 bed
= get_elf_backend_data (output_bfd
);
1741 BFD_ASSERT (htab
->elf
.splt
!= NULL
);
1742 plt
= htab
->elf
.splt
;
1743 gotplt
= htab
->elf
.sgotplt
;
1744 relplt
= htab
->elf
.srelplt
;
1746 /* This symbol has an entry in the procedure linkage table. Set
1749 if ((h
->dynindx
== -1
1750 && !((h
->forced_local
|| bfd_link_executable (info
))
1752 && h
->type
== STT_GNU_IFUNC
))
1758 /* Get the index in the procedure linkage table which
1759 corresponds to this symbol. This is the index of this symbol
1760 in all the symbols for which we are making plt entries. The
1761 first entry in the procedure linkage table is reserved.
1763 Get the offset into the .got table of the entry that
1764 corresponds to this function. Each .got entry is 4 bytes.
1765 The first three are reserved.
1767 For static executables, we don't reserve anything. */
1769 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1770 got_section_offset
= plt_index
+ bed
->got_header_size
/ 4;
1771 got_dp_offset
= got_section_offset
+ htab
->params
.dsbt_size
;
1772 rela_offset
= plt_index
* sizeof (Elf32_External_Rela
);
1774 got_section_offset
*= 4;
1776 /* Fill in the entry in the procedure linkage table. */
1778 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1779 bfd_put_32 (output_bfd
, got_dp_offset
<< 8 | 0x0100006e,
1780 plt
->contents
+ h
->plt
.offset
);
1781 /* mvk .s2 low(rela_offset), b0 */
1782 bfd_put_32 (output_bfd
, (rela_offset
& 0xffff) << 7 | 0x0000002a,
1783 plt
->contents
+ h
->plt
.offset
+ 4);
1784 /* mvkh .s2 high(rela_offset), b0 */
1785 bfd_put_32 (output_bfd
, ((rela_offset
>> 16) & 0xffff) << 7 | 0x0000006a,
1786 plt
->contents
+ h
->plt
.offset
+ 8);
1788 bfd_put_32 (output_bfd
, 0x00002000,
1789 plt
->contents
+ h
->plt
.offset
+ 12);
1791 bfd_put_32 (output_bfd
, 0x00080362,
1792 plt
->contents
+ h
->plt
.offset
+ 16);
1794 bfd_put_32 (output_bfd
, 0x00008000,
1795 plt
->contents
+ h
->plt
.offset
+ 20);
1797 /* Fill in the entry in the global offset table. */
1798 bfd_put_32 (output_bfd
,
1799 (plt
->output_section
->vma
+ plt
->output_offset
),
1800 gotplt
->contents
+ got_section_offset
);
1802 /* Fill in the entry in the .rel.plt section. */
1803 rela
.r_offset
= (gotplt
->output_section
->vma
1804 + gotplt
->output_offset
1805 + got_section_offset
);
1806 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_JUMP_SLOT
);
1808 loc
= relplt
->contents
+ rela_offset
;
1809 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1811 if (!h
->def_regular
)
1813 /* Mark the symbol as undefined, rather than as defined in
1814 the .plt section. */
1815 sym
->st_shndx
= SHN_UNDEF
;
1820 if (h
->got
.offset
!= (bfd_vma
) -1)
1825 /* This symbol has an entry in the global offset table.
1828 sgot
= htab
->elf
.sgot
;
1829 srela
= htab
->elf
.srelgot
;
1830 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1832 /* If this is a -Bsymbolic link, and the symbol is defined
1833 locally, we just want to emit a RELATIVE reloc. Likewise if
1834 the symbol was forced to be local because of a version file.
1835 The entry in the global offset table will already have been
1836 initialized in the relocate_section function. */
1837 if (bfd_link_pic (info
)
1838 && (SYMBOLIC_BIND (info
, h
)
1839 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1841 asection
*s
= h
->root
.u
.def
.section
;
1842 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, s
,
1843 h
->got
.offset
& ~(bfd_vma
) 1);
1847 Elf_Internal_Rela outrel
;
1848 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1849 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1850 outrel
.r_offset
= (sgot
->output_section
->vma
1851 + sgot
->output_offset
1852 + (h
->got
.offset
& ~(bfd_vma
) 1));
1853 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_ABS32
);
1854 outrel
.r_addend
= 0;
1856 elf32_tic6x_install_rela (output_bfd
, srela
, &outrel
);
1862 Elf_Internal_Rela rel
;
1865 /* This symbol needs a copy reloc. Set it up. */
1867 if (h
->dynindx
== -1
1868 || (h
->root
.type
!= bfd_link_hash_defined
1869 && h
->root
.type
!= bfd_link_hash_defweak
)
1870 || htab
->elf
.srelbss
== NULL
1871 || htab
->elf
.sreldynrelro
== NULL
)
1874 rel
.r_offset
= (h
->root
.u
.def
.value
1875 + h
->root
.u
.def
.section
->output_section
->vma
1876 + h
->root
.u
.def
.section
->output_offset
);
1877 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_COPY
);
1879 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
1880 s
= htab
->elf
.sreldynrelro
;
1882 s
= htab
->elf
.srelbss
;
1884 elf32_tic6x_install_rela (output_bfd
, s
, &rel
);
1887 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1888 if (h
== elf_hash_table (info
)->hdynamic
1889 || h
== elf_hash_table (info
)->hgot
)
1890 sym
->st_shndx
= SHN_ABS
;
1895 /* Unwinding tables are not referenced directly. This pass marks them as
1896 required if the corresponding code section is marked. */
1899 elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info
*info
,
1900 elf_gc_mark_hook_fn gc_mark_hook
)
1903 Elf_Internal_Shdr
**elf_shdrp
;
1906 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
1908 /* Marking EH data may cause additional code sections to be marked,
1909 requiring multiple passes. */
1914 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
1918 if (! is_tic6x_elf (sub
))
1921 elf_shdrp
= elf_elfsections (sub
);
1922 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
1924 Elf_Internal_Shdr
*hdr
;
1926 hdr
= &elf_section_data (o
)->this_hdr
;
1927 if (hdr
->sh_type
== SHT_C6000_UNWIND
1929 && hdr
->sh_link
< elf_numsections (sub
)
1931 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
1934 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
1944 /* Return TRUE if this is an unwinding table index. */
1947 is_tic6x_elf_unwind_section_name (const char *name
)
1949 return (CONST_STRNEQ (name
, ELF_STRING_C6000_unwind
)
1950 || CONST_STRNEQ (name
, ELF_STRING_C6000_unwind_once
));
1954 /* Set the type and flags for an unwinding index table. We do this by
1955 the section name, which is a hack, but ought to work. */
1958 elf32_tic6x_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1959 Elf_Internal_Shdr
*hdr
, asection
*sec
)
1963 name
= bfd_get_section_name (abfd
, sec
);
1965 if (is_tic6x_elf_unwind_section_name (name
))
1967 hdr
->sh_type
= SHT_C6000_UNWIND
;
1968 hdr
->sh_flags
|= SHF_LINK_ORDER
;
1974 /* Adjust a symbol defined by a dynamic object and referenced by a
1975 regular object. The current definition is in some section of the
1976 dynamic object, but we're not including those sections. We have to
1977 change the definition to something the rest of the link can
1981 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1982 struct elf_link_hash_entry
*h
)
1984 struct elf32_tic6x_link_hash_table
*htab
;
1988 dynobj
= elf_hash_table (info
)->dynobj
;
1990 /* Make sure we know what is going on here. */
1991 BFD_ASSERT (dynobj
!= NULL
1993 || h
->u
.weakdef
!= NULL
1994 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
1996 /* If this is a function, put it in the procedure linkage table. We
1997 will fill in the contents of the procedure linkage table later,
1998 when we know the address of the .got section. */
1999 if (h
->type
== STT_FUNC
2002 if (h
->plt
.refcount
<= 0
2003 || SYMBOL_CALLS_LOCAL (info
, h
)
2004 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2005 && h
->root
.type
== bfd_link_hash_undefweak
))
2007 /* This case can occur if we saw a PLT32 reloc in an input
2008 file, but the symbol was never referred to by a dynamic
2009 object, or if all references were garbage collected. In
2010 such a case, we don't actually need to build a procedure
2011 linkage table, and we can just do a PC32 reloc instead. */
2012 h
->plt
.offset
= (bfd_vma
) -1;
2019 /* If this is a weak symbol, and there is a real definition, the
2020 processor independent code will have arranged for us to see the
2021 real definition first, and we can just use the same value. */
2022 if (h
->u
.weakdef
!= NULL
)
2024 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2025 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2026 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2027 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2028 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2032 /* This is a reference to a symbol defined by a dynamic object which
2033 is not a function. */
2035 /* If we are creating a shared library, we must presume that the
2036 only references to the symbol are via the global offset table.
2037 For such cases we need not do anything here; the relocations will
2038 be handled correctly by relocate_section. */
2039 if (bfd_link_pic (info
))
2042 /* If there are no references to this symbol that do not use the
2043 GOT, we don't need to generate a copy reloc. */
2044 if (!h
->non_got_ref
)
2047 /* If -z nocopyreloc was given, we won't generate them either. */
2048 if (info
->nocopyreloc
)
2054 htab
= elf32_tic6x_hash_table (info
);
2058 /* We must allocate the symbol in our .dynbss section, which will
2059 become part of the .bss section of the executable. There will be
2060 an entry for this symbol in the .dynsym section. The dynamic
2061 object will contain position independent code, so all references
2062 from the dynamic object to this symbol will go through the global
2063 offset table. The dynamic linker will use the .dynsym entry to
2064 determine the address it must put in the global offset table, so
2065 both the dynamic object and the regular object will refer to the
2066 same memory location for the variable. */
2068 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2069 copy the initial value out of the dynamic object and into the
2070 runtime process image. */
2071 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2073 s
= htab
->elf
.sdynrelro
;
2074 srel
= htab
->elf
.sreldynrelro
;
2078 s
= htab
->elf
.sdynbss
;
2079 srel
= htab
->elf
.srelbss
;
2081 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2083 srel
->size
+= sizeof (Elf32_External_Rela
);
2087 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2091 elf32_tic6x_new_section_hook (bfd
*abfd
, asection
*sec
)
2095 /* Allocate target specific section data. */
2096 if (!sec
->used_by_bfd
)
2098 _tic6x_elf_section_data
*sdata
;
2099 bfd_size_type amt
= sizeof (*sdata
);
2101 sdata
= (_tic6x_elf_section_data
*) bfd_zalloc (abfd
, amt
);
2104 sec
->used_by_bfd
= sdata
;
2107 ret
= _bfd_elf_new_section_hook (abfd
, sec
);
2108 sec
->use_rela_p
= elf32_tic6x_tdata (abfd
)->use_rela_p
;
2113 /* Return true if relocation REL against section SEC is a REL rather
2114 than RELA relocation. RELOCS is the first relocation in the
2115 section and ABFD is the bfd that contains SEC. */
2118 elf32_tic6x_rel_relocation_p (bfd
*abfd
, asection
*sec
,
2119 const Elf_Internal_Rela
*relocs
,
2120 const Elf_Internal_Rela
*rel
)
2122 Elf_Internal_Shdr
*rel_hdr
;
2123 const struct elf_backend_data
*bed
;
2125 /* To determine which flavor of relocation this is, we depend on the
2126 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2127 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
2128 if (rel_hdr
== NULL
)
2130 bed
= get_elf_backend_data (abfd
);
2131 return ((size_t) (rel
- relocs
)
2132 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
2135 /* We need dynamic symbols for every section, since segments can
2136 relocate independently. */
2138 elf32_tic6x_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2139 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2142 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2146 /* If sh_type is yet undecided, assume it could be
2147 SHT_PROGBITS/SHT_NOBITS. */
2151 /* There shouldn't be section relative relocations
2152 against any other section. */
2159 elf32_tic6x_relocate_section (bfd
*output_bfd
,
2160 struct bfd_link_info
*info
,
2162 asection
*input_section
,
2164 Elf_Internal_Rela
*relocs
,
2165 Elf_Internal_Sym
*local_syms
,
2166 asection
**local_sections
)
2168 struct elf32_tic6x_link_hash_table
*htab
;
2169 Elf_Internal_Shdr
*symtab_hdr
;
2170 struct elf_link_hash_entry
**sym_hashes
;
2171 bfd_vma
*local_got_offsets
;
2172 Elf_Internal_Rela
*rel
;
2173 Elf_Internal_Rela
*relend
;
2174 bfd_boolean ok
= TRUE
;
2176 htab
= elf32_tic6x_hash_table (info
);
2177 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
2178 sym_hashes
= elf_sym_hashes (input_bfd
);
2179 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2181 relend
= relocs
+ input_section
->reloc_count
;
2183 for (rel
= relocs
; rel
< relend
; rel
++)
2186 unsigned long r_symndx
;
2188 reloc_howto_type
*howto
;
2189 Elf_Internal_Sym
*sym
;
2191 struct elf_link_hash_entry
*h
;
2192 bfd_vma off
, off2
, relocation
;
2193 bfd_boolean unresolved_reloc
;
2194 bfd_reloc_status_type r
;
2195 struct bfd_link_hash_entry
*sbh
;
2198 r_type
= ELF32_R_TYPE (rel
->r_info
);
2199 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2201 is_rel
= elf32_tic6x_rel_relocation_p (input_bfd
, input_section
,
2205 elf32_tic6x_info_to_howto_rel (input_bfd
, &bfd_reloc
, rel
);
2207 elf32_tic6x_info_to_howto (input_bfd
, &bfd_reloc
, rel
);
2208 howto
= bfd_reloc
.howto
;
2211 bfd_set_error (bfd_error_bad_value
);
2218 unresolved_reloc
= FALSE
;
2220 if (r_symndx
< symtab_hdr
->sh_info
)
2222 sym
= local_syms
+ r_symndx
;
2223 sec
= local_sections
[r_symndx
];
2224 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2228 bfd_boolean warned
, ignored
;
2230 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2231 r_symndx
, symtab_hdr
, sym_hashes
,
2233 unresolved_reloc
, warned
, ignored
);
2236 if (sec
!= NULL
&& discarded_section (sec
))
2237 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2238 rel
, 1, relend
, howto
, 0, contents
);
2240 if (bfd_link_relocatable (info
))
2244 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2247 relocation
= sec
->output_offset
+ sym
->st_value
;
2248 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
2249 contents
+ rel
->r_offset
);
2259 case R_C6000_FPHEAD
:
2261 /* No action needed. */
2264 case R_C6000_PCR_S21
:
2265 /* A branch to an undefined weak symbol is turned into a
2266 "b .s2 B3" instruction if the existing insn is of the
2267 form "b .s2 symbol". */
2268 if (h
? h
->root
.type
== bfd_link_hash_undefweak
2269 && (htab
->elf
.splt
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
2270 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2272 unsigned long oldval
;
2273 oldval
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2275 if ((oldval
& 0x7e) == 0x12)
2277 oldval
&= 0xF0000001;
2278 bfd_put_32 (input_bfd
, oldval
| 0x000c0362,
2279 contents
+ rel
->r_offset
);
2286 case R_C6000_PCR_S12
:
2287 case R_C6000_PCR_S10
:
2288 case R_C6000_PCR_S7
:
2290 && h
->plt
.offset
!= (bfd_vma
) -1
2291 && htab
->elf
.splt
!= NULL
)
2293 relocation
= (htab
->elf
.splt
->output_section
->vma
2294 + htab
->elf
.splt
->output_offset
2298 /* Generic PC-relative handling produces a value relative to
2299 the exact location of the relocation. Adjust it to be
2300 relative to the start of the fetch packet instead. */
2301 relocation
+= (input_section
->output_section
->vma
2302 + input_section
->output_offset
2303 + rel
->r_offset
) & 0x1f;
2304 unresolved_reloc
= FALSE
;
2307 case R_C6000_PCR_H16
:
2308 case R_C6000_PCR_L16
:
2309 off
= (input_section
->output_section
->vma
2310 + input_section
->output_offset
2312 /* These must be calculated as R = S - FP(FP(PC) - A).
2313 PC, here, is the value we just computed in OFF. RELOCATION
2314 has the address of S + A. */
2315 relocation
-= rel
->r_addend
;
2316 off2
= ((off
& ~(bfd_vma
)0x1f) - rel
->r_addend
) & (bfd_vma
)~0x1f;
2317 off2
= relocation
- off2
;
2318 relocation
= off
+ off2
;
2321 case R_C6000_DSBT_INDEX
:
2322 relocation
= elf32_tic6x_hash_table (info
)->params
.dsbt_index
;
2323 if (!bfd_link_pic (info
) || relocation
!= 0)
2330 case R_C6000_ABS_S16
:
2331 case R_C6000_ABS_L16
:
2332 case R_C6000_ABS_H16
:
2333 /* When generating a shared object or relocatable executable, these
2334 relocations are copied into the output file to be resolved at
2336 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2337 && (input_section
->flags
& SEC_ALLOC
)
2339 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2340 || h
->root
.type
!= bfd_link_hash_undefweak
))
2342 Elf_Internal_Rela outrel
;
2343 bfd_boolean skip
, relocate
;
2346 unresolved_reloc
= FALSE
;
2348 sreloc
= elf_section_data (input_section
)->sreloc
;
2349 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
2355 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2357 if (outrel
.r_offset
== (bfd_vma
) -1)
2359 else if (outrel
.r_offset
== (bfd_vma
) -2)
2360 skip
= TRUE
, relocate
= TRUE
;
2361 outrel
.r_offset
+= (input_section
->output_section
->vma
2362 + input_section
->output_offset
);
2365 memset (&outrel
, 0, sizeof outrel
);
2368 && (!bfd_link_pic (info
)
2369 || !SYMBOLIC_BIND (info
, h
)
2370 || !h
->def_regular
))
2372 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2373 outrel
.r_addend
= rel
->r_addend
;
2379 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2381 if (bfd_is_abs_section (sec
))
2383 else if (sec
== NULL
|| sec
->owner
== NULL
)
2385 bfd_set_error (bfd_error_bad_value
);
2392 osec
= sec
->output_section
;
2393 indx
= elf_section_data (osec
)->dynindx
;
2394 outrel
.r_addend
-= osec
->vma
;
2395 BFD_ASSERT (indx
!= 0);
2398 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2401 elf32_tic6x_install_rela (output_bfd
, sreloc
, &outrel
);
2403 /* If this reloc is against an external symbol, we do not want to
2404 fiddle with the addend. Otherwise, we need to include the symbol
2405 value so that it becomes an addend for the dynamic reloc. */
2410 /* Generic logic OK. */
2413 case R_C6000_SBR_U15_B
:
2414 case R_C6000_SBR_U15_H
:
2415 case R_C6000_SBR_U15_W
:
2416 case R_C6000_SBR_S16
:
2417 case R_C6000_SBR_L16_B
:
2418 case R_C6000_SBR_L16_H
:
2419 case R_C6000_SBR_L16_W
:
2420 case R_C6000_SBR_H16_B
:
2421 case R_C6000_SBR_H16_H
:
2422 case R_C6000_SBR_H16_W
:
2423 sbh
= bfd_link_hash_lookup (info
->hash
, "__c6xabi_DSBT_BASE",
2424 FALSE
, FALSE
, TRUE
);
2426 && (sbh
->type
== bfd_link_hash_defined
2427 || sbh
->type
== bfd_link_hash_defweak
))
2429 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
2430 && (htab
->elf
.splt
== NULL
2431 || h
->plt
.offset
== (bfd_vma
) -1))
2432 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2435 relocation
-= (sbh
->u
.def
.value
2436 + sbh
->u
.def
.section
->output_section
->vma
2437 + sbh
->u
.def
.section
->output_offset
);
2441 _bfd_error_handler (_("%B: SB-relative relocation but "
2442 "__c6xabi_DSBT_BASE not defined"),
2449 case R_C6000_SBR_GOT_U15_W
:
2450 case R_C6000_SBR_GOT_L16_W
:
2451 case R_C6000_SBR_GOT_H16_W
:
2452 case R_C6000_EHTYPE
:
2453 /* Relocation is to the entry for this symbol in the global
2455 if (htab
->elf
.sgot
== NULL
)
2462 off
= h
->got
.offset
;
2463 dyn
= htab
->elf
.dynamic_sections_created
;
2464 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2465 bfd_link_pic (info
),
2467 || (bfd_link_pic (info
)
2468 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2469 || (ELF_ST_VISIBILITY (h
->other
)
2470 && h
->root
.type
== bfd_link_hash_undefweak
))
2472 /* This is actually a static link, or it is a
2473 -Bsymbolic link and the symbol is defined
2474 locally, or the symbol was forced to be local
2475 because of a version file. We must initialize
2476 this entry in the global offset table. Since the
2477 offset must always be a multiple of 4, we use the
2478 least significant bit to record whether we have
2479 initialized it already.
2481 When doing a dynamic link, we create a .rel.got
2482 relocation entry to initialize the value. This
2483 is done in the finish_dynamic_symbol routine. */
2488 bfd_put_32 (output_bfd
, relocation
,
2489 htab
->elf
.sgot
->contents
+ off
);
2492 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2493 bfd_link_pic (info
),
2495 && !(ELF_ST_VISIBILITY (h
->other
)
2496 && h
->root
.type
== bfd_link_hash_undefweak
))
2497 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
,
2502 unresolved_reloc
= FALSE
;
2506 if (local_got_offsets
== NULL
)
2509 off
= local_got_offsets
[r_symndx
];
2511 /* The offset must always be a multiple of 4. We use
2512 the least significant bit to record whether we have
2513 already generated the necessary reloc. */
2518 bfd_put_32 (output_bfd
, relocation
,
2519 htab
->elf
.sgot
->contents
+ off
);
2521 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2522 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
, off
);
2524 local_got_offsets
[r_symndx
] |= 1;
2528 if (off
>= (bfd_vma
) -2)
2532 relocation
= (htab
->elf
.sgot
->output_section
->vma
2533 + htab
->elf
.sgot
->output_offset
+ off
2534 - htab
->dsbt
->output_section
->vma
2535 - htab
->dsbt
->output_offset
);
2537 relocation
= (htab
->elf
.sgot
->output_section
->vma
2538 + htab
->elf
.sgot
->output_offset
+ off
2539 - htab
->elf
.sgotplt
->output_section
->vma
2540 - htab
->elf
.sgotplt
->output_offset
);
2542 if (rel
->r_addend
!= 0)
2544 /* We can't do anything for a relocation which is against
2545 a symbol *plus offset*. GOT holds relocations for
2546 symbols. Make this an error; the compiler isn't
2547 allowed to pass us these kinds of things. */
2550 /* xgettext:c-format */
2551 (_("%B, section %A: relocation %s with non-zero addend %Ld"
2552 " against local symbol"),
2555 elf32_tic6x_howto_table
[r_type
].name
,
2559 /* xgettext:c-format */
2560 (_("%B, section %A: relocation %s with non-zero addend %Ld"
2561 " against symbol `%s'"),
2564 elf32_tic6x_howto_table
[r_type
].name
,
2566 h
->root
.root
.string
[0] != '\0' ? h
->root
.root
.string
2567 : _("[whose name is lost]"));
2569 bfd_set_error (bfd_error_bad_value
);
2574 case R_C6000_PREL31
:
2576 && h
->plt
.offset
!= (bfd_vma
) -1
2577 && htab
->elf
.splt
!= NULL
)
2579 relocation
= (htab
->elf
.splt
->output_section
->vma
2580 + htab
->elf
.splt
->output_offset
2586 /* Invalid in relocatable object. */
2588 /* Unknown relocation. */
2589 /* xgettext:c-format */
2590 _bfd_error_handler (_("%B: invalid relocation type %d"),
2596 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2597 contents
, rel
->r_offset
,
2598 relocation
, rel
->r_addend
);
2601 if (r
== bfd_reloc_ok
2602 && howto
->complain_on_overflow
== complain_overflow_bitfield
)
2604 /* Generic overflow handling accepts cases the ABI says
2605 should be rejected for R_C6000_ABS16 and
2607 bfd_vma value
= (relocation
+ rel
->r_addend
) & 0xffffffff;
2608 bfd_vma sbit
= 1 << (howto
->bitsize
- 1);
2609 bfd_vma sbits
= (-(bfd_vma
) sbit
) & 0xffffffff;
2610 bfd_vma value_sbits
= value
& sbits
;
2612 if (value_sbits
!= 0
2613 && value_sbits
!= sbit
2614 && value_sbits
!= sbits
)
2615 r
= bfd_reloc_overflow
;
2618 if (r
!= bfd_reloc_ok
)
2621 const char *error_message
;
2624 name
= h
->root
.root
.string
;
2627 name
= bfd_elf_string_from_elf_section (input_bfd
,
2628 symtab_hdr
->sh_link
,
2633 name
= bfd_section_name (input_bfd
, sec
);
2638 case bfd_reloc_overflow
:
2639 /* If the overflowing reloc was to an undefined symbol,
2640 we have already printed one error message and there
2641 is no point complaining again. */
2642 if (!h
|| h
->root
.type
!= bfd_link_hash_undefined
)
2643 (*info
->callbacks
->reloc_overflow
)
2644 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2645 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
2648 case bfd_reloc_undefined
:
2649 (*info
->callbacks
->undefined_symbol
) (info
, name
, input_bfd
,
2651 rel
->r_offset
, TRUE
);
2654 case bfd_reloc_outofrange
:
2655 error_message
= _("out of range");
2658 case bfd_reloc_notsupported
:
2659 error_message
= _("unsupported relocation");
2662 case bfd_reloc_dangerous
:
2663 error_message
= _("dangerous relocation");
2667 error_message
= _("unknown error");
2671 BFD_ASSERT (error_message
!= NULL
);
2672 (*info
->callbacks
->reloc_dangerous
)
2673 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
2683 /* Look through the relocs for a section during the first phase, and
2684 calculate needed space in the global offset table, procedure linkage
2685 table, and dynamic reloc sections. */
2688 elf32_tic6x_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2689 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2691 struct elf32_tic6x_link_hash_table
*htab
;
2692 Elf_Internal_Shdr
*symtab_hdr
;
2693 struct elf_link_hash_entry
**sym_hashes
;
2694 const Elf_Internal_Rela
*rel
;
2695 const Elf_Internal_Rela
*rel_end
;
2698 if (bfd_link_relocatable (info
))
2701 htab
= elf32_tic6x_hash_table (info
);
2702 symtab_hdr
= &elf_symtab_hdr (abfd
);
2703 sym_hashes
= elf_sym_hashes (abfd
);
2705 /* Create dynamic sections for relocatable executables so that we can
2706 copy relocations. */
2707 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2708 && ! htab
->elf
.dynamic_sections_created
)
2710 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2716 rel_end
= relocs
+ sec
->reloc_count
;
2717 for (rel
= relocs
; rel
< rel_end
; rel
++)
2719 unsigned int r_type
;
2720 unsigned int r_symndx
;
2721 struct elf_link_hash_entry
*h
;
2722 Elf_Internal_Sym
*isym
;
2724 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2725 r_type
= ELF32_R_TYPE (rel
->r_info
);
2727 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2729 /* xgettext:c-format */
2730 _bfd_error_handler (_("%B: bad symbol index: %d"),
2735 if (r_symndx
< symtab_hdr
->sh_info
)
2737 /* A local symbol. */
2738 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2747 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2748 while (h
->root
.type
== bfd_link_hash_indirect
2749 || h
->root
.type
== bfd_link_hash_warning
)
2750 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2752 /* PR15323, ref flags aren't set for references in the same
2754 h
->root
.non_ir_ref_regular
= 1;
2759 case R_C6000_PCR_S21
:
2760 case R_C6000_PREL31
:
2761 /* This symbol requires a procedure linkage table entry. We
2762 actually build the entry in adjust_dynamic_symbol,
2763 because this might be a case of linking PIC code which is
2764 never referenced by a dynamic object, in which case we
2765 don't need to generate a procedure linkage table entry
2768 /* If this is a local symbol, we resolve it directly without
2769 creating a procedure linkage table entry. */
2774 h
->plt
.refcount
+= 1;
2777 case R_C6000_SBR_GOT_U15_W
:
2778 case R_C6000_SBR_GOT_L16_W
:
2779 case R_C6000_SBR_GOT_H16_W
:
2780 case R_C6000_EHTYPE
:
2781 /* This symbol requires a global offset table entry. */
2784 h
->got
.refcount
+= 1;
2788 bfd_signed_vma
*local_got_refcounts
;
2790 /* This is a global offset table entry for a local symbol. */
2791 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2792 if (local_got_refcounts
== NULL
)
2796 size
= symtab_hdr
->sh_info
;
2797 size
*= (sizeof (bfd_signed_vma
)
2798 + sizeof (bfd_vma
) + sizeof(char));
2799 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2800 if (local_got_refcounts
== NULL
)
2802 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2804 local_got_refcounts
[r_symndx
] += 1;
2807 if (htab
->elf
.sgot
== NULL
)
2809 if (htab
->elf
.dynobj
== NULL
)
2810 htab
->elf
.dynobj
= abfd
;
2811 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2816 case R_C6000_DSBT_INDEX
:
2817 /* We'd like to check for nonzero dsbt_index here, but it's
2818 set up only after check_relocs is called. Instead, we
2819 store the number of R_C6000_DSBT_INDEX relocs in the
2820 pc_count field, and potentially discard the extra space
2821 in elf32_tic6x_allocate_dynrelocs. */
2822 if (!bfd_link_pic (info
))
2829 case R_C6000_ABS_S16
:
2830 case R_C6000_ABS_L16
:
2831 case R_C6000_ABS_H16
:
2832 /* If we are creating a shared library, and this is a reloc
2833 against a global symbol, or a non PC relative reloc
2834 against a local symbol, then we need to copy the reloc
2835 into the shared library. However, if we are linking with
2836 -Bsymbolic, we do not need to copy a reloc against a
2837 global symbol which is defined in an object we are
2838 including in the link (i.e., DEF_REGULAR is set). At
2839 this point we have not seen all the input files, so it is
2840 possible that DEF_REGULAR is not set now but will be set
2841 later (it is never cleared). In case of a weak definition,
2842 DEF_REGULAR may be cleared later by a strong definition in
2843 a shared library. We account for that possibility below by
2844 storing information in the relocs_copied field of the hash
2845 table entry. A similar situation occurs when creating
2846 shared libraries and symbol visibility changes render the
2849 If on the other hand, we are creating an executable, we
2850 may need to keep relocations for symbols satisfied by a
2851 dynamic library if we manage to avoid copy relocs for the
2853 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2854 && (sec
->flags
& SEC_ALLOC
) != 0)
2856 struct elf_dyn_relocs
*p
;
2857 struct elf_dyn_relocs
**head
;
2859 /* We must copy these reloc types into the output file.
2860 Create a reloc section in dynobj and make room for
2864 if (htab
->elf
.dynobj
== NULL
)
2865 htab
->elf
.dynobj
= abfd
;
2867 sreloc
= _bfd_elf_make_dynamic_reloc_section
2868 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela? */ TRUE
);
2874 /* If this is a global symbol, we count the number of
2875 relocations we need for this symbol. */
2878 head
= &((struct elf32_tic6x_link_hash_entry
*) h
)->dyn_relocs
;
2882 /* Track dynamic relocs needed for local syms too.
2883 We really need local syms available to do this
2888 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2892 vpp
= &elf_section_data (s
)->local_dynrel
;
2893 head
= (struct elf_dyn_relocs
**)vpp
;
2897 if (p
== NULL
|| p
->sec
!= sec
)
2899 bfd_size_type amt
= sizeof *p
;
2900 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
2911 if (r_type
== R_C6000_DSBT_INDEX
)
2916 case R_C6000_SBR_U15_B
:
2917 case R_C6000_SBR_U15_H
:
2918 case R_C6000_SBR_U15_W
:
2919 case R_C6000_SBR_S16
:
2920 case R_C6000_SBR_L16_B
:
2921 case R_C6000_SBR_L16_H
:
2922 case R_C6000_SBR_L16_W
:
2923 case R_C6000_SBR_H16_B
:
2924 case R_C6000_SBR_H16_H
:
2925 case R_C6000_SBR_H16_W
:
2926 if (h
!= NULL
&& bfd_link_executable (info
))
2928 /* For B14-relative addresses, we might need a copy
2943 elf32_tic6x_add_symbol_hook (bfd
*abfd
,
2944 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2945 Elf_Internal_Sym
*sym
,
2946 const char **namep ATTRIBUTE_UNUSED
,
2947 flagword
*flagsp ATTRIBUTE_UNUSED
,
2951 switch (sym
->st_shndx
)
2953 case SHN_TIC6X_SCOMMON
:
2954 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2955 (*secp
)->flags
|= SEC_IS_COMMON
;
2956 *valp
= sym
->st_size
;
2957 (void) bfd_set_section_alignment (abfd
, *secp
, bfd_log2 (sym
->st_value
));
2965 elf32_tic6x_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
2967 elf_symbol_type
*elfsym
;
2969 elfsym
= (elf_symbol_type
*) asym
;
2970 switch (elfsym
->internal_elf_sym
.st_shndx
)
2972 case SHN_TIC6X_SCOMMON
:
2973 if (tic6x_elf_scom_section
.name
== NULL
)
2975 /* Initialize the small common section. */
2976 tic6x_elf_scom_section
.name
= ".scommon";
2977 tic6x_elf_scom_section
.flags
= SEC_IS_COMMON
;
2978 tic6x_elf_scom_section
.output_section
= &tic6x_elf_scom_section
;
2979 tic6x_elf_scom_section
.symbol
= &tic6x_elf_scom_symbol
;
2980 tic6x_elf_scom_section
.symbol_ptr_ptr
= &tic6x_elf_scom_symbol_ptr
;
2981 tic6x_elf_scom_symbol
.name
= ".scommon";
2982 tic6x_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2983 tic6x_elf_scom_symbol
.section
= &tic6x_elf_scom_section
;
2984 tic6x_elf_scom_symbol_ptr
= &tic6x_elf_scom_symbol
;
2986 asym
->section
= &tic6x_elf_scom_section
;
2987 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2993 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2994 const char *name ATTRIBUTE_UNUSED
,
2995 Elf_Internal_Sym
*sym
,
2996 asection
*input_sec
,
2997 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2999 /* If we see a common symbol, which implies a relocatable link, then
3000 if a symbol was small common in an input file, mark it as small
3001 common in the output file. */
3002 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
3003 sym
->st_shndx
= SHN_TIC6X_SCOMMON
;
3009 elf32_tic6x_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
3013 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3015 *retval
= SHN_TIC6X_SCOMMON
;
3022 /* Allocate space in .plt, .got and associated reloc sections for
3026 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3028 struct bfd_link_info
*info
;
3029 struct elf32_tic6x_link_hash_table
*htab
;
3030 struct elf32_tic6x_link_hash_entry
*eh
;
3031 struct elf_dyn_relocs
*p
;
3033 if (h
->root
.type
== bfd_link_hash_indirect
)
3036 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3037 info
= (struct bfd_link_info
*) inf
;
3038 htab
= elf32_tic6x_hash_table (info
);
3040 if (htab
->elf
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3042 /* Make sure this symbol is output as a dynamic symbol.
3043 Undefined weak syms won't yet be marked as dynamic. */
3044 if (h
->dynindx
== -1 && !h
->forced_local
)
3046 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3050 if (bfd_link_pic (info
)
3051 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3053 asection
*s
= htab
->elf
.splt
;
3055 /* If this is the first .plt entry, make room for the special
3058 s
->size
+= PLT_ENTRY_SIZE
;
3060 h
->plt
.offset
= s
->size
;
3062 /* If this symbol is not defined in a regular file, and we are
3063 not generating a shared library, then set the symbol to this
3064 location in the .plt. This is required to make function
3065 pointers compare as equal between the normal executable and
3066 the shared library. */
3067 if (! bfd_link_pic (info
) && !h
->def_regular
)
3069 h
->root
.u
.def
.section
= s
;
3070 h
->root
.u
.def
.value
= h
->plt
.offset
;
3073 /* Make room for this entry. */
3074 s
->size
+= PLT_ENTRY_SIZE
;
3075 /* We also need to make an entry in the .got.plt section, which
3076 will be placed in the .got section by the linker script. */
3077 htab
->elf
.sgotplt
->size
+= 4;
3078 /* We also need to make an entry in the .rel.plt section. */
3079 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3083 h
->plt
.offset
= (bfd_vma
) -1;
3089 h
->plt
.offset
= (bfd_vma
) -1;
3093 if (h
->got
.refcount
> 0)
3097 /* Make sure this symbol is output as a dynamic symbol.
3098 Undefined weak syms won't yet be marked as dynamic. */
3099 if (h
->dynindx
== -1
3100 && !h
->forced_local
)
3102 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3107 h
->got
.offset
= s
->size
;
3110 if (!(ELF_ST_VISIBILITY (h
->other
)
3111 && h
->root
.type
== bfd_link_hash_undefweak
))
3112 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3115 h
->got
.offset
= (bfd_vma
) -1;
3117 if (eh
->dyn_relocs
== NULL
)
3120 /* Discard relocs on undefined weak syms with non-default
3122 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (htab
->obfd
))
3124 /* We use the pc_count field to hold the number of
3125 R_C6000_DSBT_INDEX relocs. */
3126 if (htab
->params
.dsbt_index
!= 0)
3128 struct elf_dyn_relocs
**pp
;
3130 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3132 p
->count
-= p
->pc_count
;
3141 if (eh
->dyn_relocs
!= NULL
3142 && h
->root
.type
== bfd_link_hash_undefweak
)
3144 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3145 eh
->dyn_relocs
= NULL
;
3147 /* Make sure undefined weak symbols are output as a dynamic
3149 else if (h
->dynindx
== -1
3150 && !h
->forced_local
)
3152 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3158 /* Finally, allocate space. */
3159 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3163 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3165 BFD_ASSERT (sreloc
!= NULL
);
3166 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3172 /* Find any dynamic relocs that apply to read-only sections. */
3175 elf32_tic6x_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3177 struct elf32_tic6x_link_hash_entry
*eh
;
3178 struct elf_dyn_relocs
*p
;
3180 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3181 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3183 asection
*s
= p
->sec
->output_section
;
3185 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3187 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3189 info
->flags
|= DF_TEXTREL
;
3191 /* Not an error, just cut short the traversal. */
3198 /* Set the sizes of the dynamic sections. */
3201 elf32_tic6x_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3203 struct elf32_tic6x_link_hash_table
*htab
;
3209 htab
= elf32_tic6x_hash_table (info
);
3210 dynobj
= htab
->elf
.dynobj
;
3214 if (htab
->elf
.dynamic_sections_created
)
3216 /* Set the contents of the .interp section to the interpreter. */
3217 if (bfd_link_executable (info
) && !info
->nointerp
)
3219 s
= bfd_get_linker_section (dynobj
, ".interp");
3222 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3223 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3227 /* Set up .got offsets for local syms, and space for local dynamic
3229 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3231 bfd_signed_vma
*local_got
;
3232 bfd_signed_vma
*end_local_got
;
3233 bfd_size_type locsymcount
;
3234 Elf_Internal_Shdr
*symtab_hdr
;
3237 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3239 struct elf_dyn_relocs
*p
;
3241 for (p
= ((struct elf_dyn_relocs
*)
3242 elf_section_data (s
)->local_dynrel
);
3246 if (!bfd_is_abs_section (p
->sec
)
3247 && bfd_is_abs_section (p
->sec
->output_section
))
3249 /* Input section has been discarded, either because
3250 it is a copy of a linkonce section or due to
3251 linker script /DISCARD/, so we'll be discarding
3254 else if (p
->count
!= 0)
3256 srel
= elf_section_data (p
->sec
)->sreloc
;
3257 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3258 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3259 info
->flags
|= DF_TEXTREL
;
3264 local_got
= elf_local_got_refcounts (ibfd
);
3268 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3269 locsymcount
= symtab_hdr
->sh_info
;
3270 end_local_got
= local_got
+ locsymcount
;
3272 srel
= htab
->elf
.srelgot
;
3273 for (; local_got
< end_local_got
; ++local_got
)
3277 *local_got
= s
->size
;
3280 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
3282 srel
->size
+= sizeof (Elf32_External_Rela
);
3286 *local_got
= (bfd_vma
) -1;
3290 /* Allocate global sym .plt and .got entries, and space for global
3291 sym dynamic relocs. */
3292 elf_link_hash_traverse (&htab
->elf
, elf32_tic6x_allocate_dynrelocs
, info
);
3294 /* We now have determined the sizes of the various dynamic sections.
3295 Allocate memory for them. */
3297 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3299 bfd_boolean strip_section
= TRUE
;
3301 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3304 if (s
== htab
->dsbt
)
3305 s
->size
= 4 * htab
->params
.dsbt_size
;
3306 else if (s
== htab
->elf
.splt
3307 || s
== htab
->elf
.sgot
3308 || s
== htab
->elf
.sgotplt
3309 || s
== htab
->elf
.sdynbss
3310 || s
== htab
->elf
.sdynrelro
)
3312 /* Strip this section if we don't need it; see the
3314 /* We'd like to strip these sections if they aren't needed, but if
3315 we've exported dynamic symbols from them we must leave them.
3316 It's too late to tell BFD to get rid of the symbols. */
3318 if (htab
->elf
.hplt
!= NULL
)
3319 strip_section
= FALSE
;
3321 /* Round up the size of the PLT section to a multiple of 32. */
3322 if (s
== htab
->elf
.splt
&& s
->size
> 0)
3323 s
->size
= (s
->size
+ 31) & ~(bfd_vma
)31;
3325 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3328 && s
!= htab
->elf
.srelplt
)
3331 /* We use the reloc_count field as a counter if we need
3332 to copy relocs into the output file. */
3337 /* It's not one of our sections, so don't allocate space. */
3343 /* If we don't need this section, strip it from the
3344 output file. This is mostly to handle .rel.bss and
3345 .rel.plt. We must create both sections in
3346 create_dynamic_sections, because they must be created
3347 before the linker maps input sections to output
3348 sections. The linker does that before
3349 adjust_dynamic_symbol is called, and it is that
3350 function which decides whether anything needs to go
3351 into these sections. */
3353 s
->flags
|= SEC_EXCLUDE
;
3357 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3360 /* Allocate memory for the section contents. We use bfd_zalloc
3361 here in case unused entries are not reclaimed before the
3362 section's contents are written out. This should not happen,
3363 but this way if it does, we get a R_C6000_NONE reloc instead
3365 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3366 if (s
->contents
== NULL
)
3370 if (htab
->elf
.dynamic_sections_created
)
3372 /* Add some entries to the .dynamic section. We fill in the
3373 values later, in elf32_tic6x_finish_dynamic_sections, but we
3374 must add the entries now so that we get the correct size for
3375 the .dynamic section. The DT_DEBUG entry is filled in by the
3376 dynamic linker and used by the debugger. */
3377 #define add_dynamic_entry(TAG, VAL) \
3378 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3380 if (bfd_link_executable (info
))
3382 if (!add_dynamic_entry (DT_DEBUG
, 0))
3386 if (!add_dynamic_entry (DT_C6000_DSBT_BASE
, 0)
3387 || !add_dynamic_entry (DT_C6000_DSBT_SIZE
, htab
->params
.dsbt_size
)
3388 || !add_dynamic_entry (DT_C6000_DSBT_INDEX
,
3389 htab
->params
.dsbt_index
))
3392 if (htab
->elf
.splt
->size
!= 0)
3394 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3395 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3396 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3397 || !add_dynamic_entry (DT_JMPREL
, 0))
3403 if (!add_dynamic_entry (DT_RELA
, 0)
3404 || !add_dynamic_entry (DT_RELASZ
, 0)
3405 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3408 /* If any dynamic relocs apply to a read-only section,
3409 then we need a DT_TEXTREL entry. */
3410 if ((info
->flags
& DF_TEXTREL
) == 0)
3411 elf_link_hash_traverse (&htab
->elf
,
3412 elf32_tic6x_readonly_dynrelocs
, info
);
3414 if ((info
->flags
& DF_TEXTREL
) != 0)
3416 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3421 #undef add_dynamic_entry
3426 /* This function is called after all the input files have been read,
3427 and the input sections have been assigned to output sections. */
3430 elf32_tic6x_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3432 if (elf32_tic6x_using_dsbt (output_bfd
) && !bfd_link_relocatable (info
)
3433 && !bfd_elf_stack_segment_size (output_bfd
, info
,
3434 "__stacksize", DEFAULT_STACK_SIZE
))
3441 elf32_tic6x_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3442 struct bfd_link_info
*info
)
3444 struct elf32_tic6x_link_hash_table
*htab
;
3448 htab
= elf32_tic6x_hash_table (info
);
3449 dynobj
= htab
->elf
.dynobj
;
3450 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
3452 if (elf_hash_table (info
)->dynamic_sections_created
)
3454 Elf32_External_Dyn
* dyncon
;
3455 Elf32_External_Dyn
* dynconend
;
3457 BFD_ASSERT (sdyn
!= NULL
);
3459 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3460 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3462 for (; dyncon
< dynconend
; dyncon
++)
3464 Elf_Internal_Dyn dyn
;
3467 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3474 case DT_C6000_DSBT_BASE
:
3476 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
);
3480 s
= htab
->elf
.sgotplt
;
3481 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3485 s
= htab
->elf
.srelplt
;
3486 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3490 s
= htab
->elf
.srelplt
;
3491 dyn
.d_un
.d_val
= s
->size
;
3494 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3497 /* Fill in the first entry in the procedure linkage table. */
3498 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
3500 bfd_vma got_offs
= (htab
->elf
.sgotplt
->output_section
->vma
3501 + htab
->elf
.sgotplt
->output_offset
3502 - htab
->dsbt
->output_section
->vma
3503 - htab
->dsbt
->output_offset
) / 4;
3505 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3506 bfd_put_32 (output_bfd
, got_offs
<< 8 | 0x0100006e,
3507 htab
->elf
.splt
->contents
);
3508 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3509 bfd_put_32 (output_bfd
, (got_offs
+ 1) << 8 | 0x0080006e,
3510 htab
->elf
.splt
->contents
+ 4);
3512 bfd_put_32 (output_bfd
, 0x00004000,
3513 htab
->elf
.splt
->contents
+ 8);
3515 bfd_put_32 (output_bfd
, 0x00080362,
3516 htab
->elf
.splt
->contents
+ 12);
3518 bfd_put_32 (output_bfd
, 0x00008000,
3519 htab
->elf
.splt
->contents
+ 16);
3521 elf_section_data (htab
->elf
.splt
->output_section
)
3522 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3529 /* Return address for Ith PLT stub in section PLT, for relocation REL
3530 or (bfd_vma) -1 if it should not be included. */
3533 elf32_tic6x_plt_sym_val (bfd_vma i
, const asection
*plt
,
3534 const arelent
*rel ATTRIBUTE_UNUSED
)
3536 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3540 elf32_tic6x_obj_attrs_arg_type (int tag
)
3542 if (tag
== Tag_ABI_compatibility
)
3543 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
3545 return ATTR_TYPE_FLAG_STR_VAL
;
3547 return ATTR_TYPE_FLAG_INT_VAL
;
3551 elf32_tic6x_obj_attrs_order (int num
)
3553 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
3554 return Tag_ABI_conformance
;
3555 if ((num
- 1) < Tag_ABI_conformance
)
3561 elf32_tic6x_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
3563 if ((tag
& 127) < 64)
3566 /* xgettext:c-format */
3567 (_("%B: error: unknown mandatory EABI object attribute %d"),
3569 bfd_set_error (bfd_error_bad_value
);
3575 /* xgettext:c-format */
3576 (_("%B: warning: unknown EABI object attribute %d"),
3582 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3583 and return the merged value. At present, all merges succeed, so no
3584 return value for errors is defined. */
3587 elf32_tic6x_merge_arch_attributes (int arch1
, int arch2
)
3589 int min_arch
, max_arch
;
3591 min_arch
= (arch1
< arch2
? arch1
: arch2
);
3592 max_arch
= (arch1
> arch2
? arch1
: arch2
);
3594 /* In most cases, the numerically greatest value is the correct
3595 merged value, but merging C64 and C67 results in C674X. */
3596 if ((min_arch
== C6XABI_Tag_ISA_C67X
3597 || min_arch
== C6XABI_Tag_ISA_C67XP
)
3598 && (max_arch
== C6XABI_Tag_ISA_C64X
3599 || max_arch
== C6XABI_Tag_ISA_C64XP
))
3600 return C6XABI_Tag_ISA_C674X
;
3605 /* Convert a Tag_ABI_array_object_alignment or
3606 Tag_ABI_array_object_align_expected tag value TAG to a
3607 corresponding alignment value; return the alignment, or -1 for an
3608 unknown tag value. */
3611 elf32_tic6x_tag_to_array_alignment (int tag
)
3629 /* Convert a Tag_ABI_array_object_alignment or
3630 Tag_ABI_array_object_align_expected alignment ALIGN to a
3631 corresponding tag value; return the tag value. */
3634 elf32_tic6x_array_alignment_to_tag (int align
)
3652 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3653 succeeded, FALSE otherwise. */
3656 elf32_tic6x_merge_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
3658 bfd
*obfd
= info
->output_bfd
;
3659 bfd_boolean result
= TRUE
;
3660 obj_attribute
*in_attr
;
3661 obj_attribute
*out_attr
;
3663 int array_align_in
, array_align_out
, array_expect_in
, array_expect_out
;
3665 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
3667 /* This is the first object. Copy the attributes. */
3668 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
3670 out_attr
= elf_known_obj_attributes_proc (obfd
);
3672 /* Use the Tag_null value to indicate the attributes have been
3679 in_attr
= elf_known_obj_attributes_proc (ibfd
);
3680 out_attr
= elf_known_obj_attributes_proc (obfd
);
3682 /* No specification yet for handling of unknown attributes, so just
3683 ignore them and handle known ones. */
3685 if (out_attr
[Tag_ABI_stack_align_preserved
].i
3686 < in_attr
[Tag_ABI_stack_align_needed
].i
)
3689 /* xgettext:c-format */
3690 (_("error: %B requires more stack alignment than %B preserves"),
3694 if (in_attr
[Tag_ABI_stack_align_preserved
].i
3695 < out_attr
[Tag_ABI_stack_align_needed
].i
)
3698 /* xgettext:c-format */
3699 (_("error: %B requires more stack alignment than %B preserves"),
3704 array_align_in
= elf32_tic6x_tag_to_array_alignment
3705 (in_attr
[Tag_ABI_array_object_alignment
].i
);
3706 if (array_align_in
== -1)
3709 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3713 array_align_out
= elf32_tic6x_tag_to_array_alignment
3714 (out_attr
[Tag_ABI_array_object_alignment
].i
);
3715 if (array_align_out
== -1)
3718 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3722 array_expect_in
= elf32_tic6x_tag_to_array_alignment
3723 (in_attr
[Tag_ABI_array_object_align_expected
].i
);
3724 if (array_expect_in
== -1)
3727 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3731 array_expect_out
= elf32_tic6x_tag_to_array_alignment
3732 (out_attr
[Tag_ABI_array_object_align_expected
].i
);
3733 if (array_expect_out
== -1)
3736 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3741 if (array_align_out
< array_expect_in
)
3744 /* xgettext:c-format */
3745 (_("error: %B requires more array alignment than %B preserves"),
3749 if (array_align_in
< array_expect_out
)
3752 /* xgettext:c-format */
3753 (_("error: %B requires more array alignment than %B preserves"),
3758 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
3763 out_attr
[i
].i
= elf32_tic6x_merge_arch_attributes (in_attr
[i
].i
,
3767 case Tag_ABI_wchar_t
:
3768 if (out_attr
[i
].i
== 0)
3769 out_attr
[i
].i
= in_attr
[i
].i
;
3770 if (out_attr
[i
].i
!= 0
3771 && in_attr
[i
].i
!= 0
3772 && out_attr
[i
].i
!= in_attr
[i
].i
)
3775 /* xgettext:c-format */
3776 (_("warning: %B and %B differ in wchar_t size"), obfd
, ibfd
);
3780 case Tag_ABI_stack_align_needed
:
3781 if (out_attr
[i
].i
< in_attr
[i
].i
)
3782 out_attr
[i
].i
= in_attr
[i
].i
;
3785 case Tag_ABI_stack_align_preserved
:
3786 if (out_attr
[i
].i
> in_attr
[i
].i
)
3787 out_attr
[i
].i
= in_attr
[i
].i
;
3791 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3794 /* xgettext:c-format */
3795 (_("warning: %B and %B differ in whether code is "
3796 "compiled for DSBT"),
3803 if (out_attr
[i
].i
> in_attr
[i
].i
)
3804 out_attr
[i
].i
= in_attr
[i
].i
;
3807 case Tag_ABI_array_object_alignment
:
3808 if (array_align_out
!= -1
3809 && array_align_in
!= -1
3810 && array_align_out
> array_align_in
)
3812 = elf32_tic6x_array_alignment_to_tag (array_align_in
);
3815 case Tag_ABI_array_object_align_expected
:
3816 if (array_expect_out
!= -1
3817 && array_expect_in
!= -1
3818 && array_expect_out
< array_expect_in
)
3820 = elf32_tic6x_array_alignment_to_tag (array_expect_in
);
3823 case Tag_ABI_conformance
:
3824 /* Merging for this attribute is not specified. As on ARM,
3825 treat a missing attribute as no claim to conform and only
3826 merge identical values. */
3827 if (out_attr
[i
].s
== NULL
3828 || in_attr
[i
].s
== NULL
3829 || strcmp (out_attr
[i
].s
,
3831 out_attr
[i
].s
= NULL
;
3834 case Tag_ABI_compatibility
:
3835 /* Merged in _bfd_elf_merge_object_attributes. */
3840 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
3844 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
3845 out_attr
[i
].type
= in_attr
[i
].type
;
3848 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
3849 if (!_bfd_elf_merge_object_attributes (ibfd
, info
))
3852 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
3858 elf32_tic6x_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
3860 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
3863 if (! is_tic6x_elf (ibfd
) || ! is_tic6x_elf (info
->output_bfd
))
3866 if (!elf32_tic6x_merge_attributes (ibfd
, info
))
3872 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
3873 adds the edit to the start of the list. (The list must be built in order of
3874 ascending TINDEX: the function's callers are primarily responsible for
3875 maintaining that condition). */
3878 elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit
**head
,
3879 tic6x_unwind_table_edit
**tail
,
3880 tic6x_unwind_edit_type type
,
3881 asection
*linked_section
,
3882 unsigned int tindex
)
3884 tic6x_unwind_table_edit
*new_edit
= (tic6x_unwind_table_edit
*)
3885 xmalloc (sizeof (tic6x_unwind_table_edit
));
3887 new_edit
->type
= type
;
3888 new_edit
->linked_section
= linked_section
;
3889 new_edit
->index
= tindex
;
3893 new_edit
->next
= NULL
;
3896 (*tail
)->next
= new_edit
;
3905 new_edit
->next
= *head
;
3914 static _tic6x_elf_section_data
*
3915 get_tic6x_elf_section_data (asection
* sec
)
3917 if (sec
&& sec
->owner
&& is_tic6x_elf (sec
->owner
))
3918 return elf32_tic6x_section_data (sec
);
3924 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST must be negative. */
3926 elf32_tic6x_adjust_exidx_size (asection
*exidx_sec
, int adjust
)
3930 if (!exidx_sec
->rawsize
)
3931 exidx_sec
->rawsize
= exidx_sec
->size
;
3933 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
3934 out_sec
= exidx_sec
->output_section
;
3935 /* Adjust size of output section. */
3936 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
3939 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
3941 elf32_tic6x_insert_cantunwind_after (asection
*text_sec
, asection
*exidx_sec
)
3943 struct _tic6x_elf_section_data
*exidx_data
;
3945 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
3946 elf32_tic6x_add_unwind_table_edit (
3947 &exidx_data
->u
.exidx
.unwind_edit_list
,
3948 &exidx_data
->u
.exidx
.unwind_edit_tail
,
3949 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
3951 elf32_tic6x_adjust_exidx_size (exidx_sec
, 8);
3954 /* Scan .cx6abi.exidx tables, and create a list describing edits which
3955 should be made to those tables, such that:
3957 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
3958 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
3959 codes which have been inlined into the index).
3961 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
3963 The edits are applied when the tables are written
3964 (in elf32_tic6x_write_section).
3968 elf32_tic6x_fix_exidx_coverage (asection
**text_section_order
,
3969 unsigned int num_text_sections
,
3970 struct bfd_link_info
*info
,
3971 bfd_boolean merge_exidx_entries
)
3974 unsigned int last_second_word
= 0, i
;
3975 asection
*last_exidx_sec
= NULL
;
3976 asection
*last_text_sec
= NULL
;
3977 int last_unwind_type
= -1;
3979 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
3981 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link
.next
)
3985 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
3987 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
3988 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
3990 if (!hdr
|| hdr
->sh_type
!= SHT_C6000_UNWIND
)
3993 if (elf_sec
->linked_to
)
3995 Elf_Internal_Shdr
*linked_hdr
3996 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
3997 struct _tic6x_elf_section_data
*linked_sec_tic6x_data
3998 = get_tic6x_elf_section_data (linked_hdr
->bfd_section
);
4000 if (linked_sec_tic6x_data
== NULL
)
4003 /* Link this .c6xabi.exidx section back from the
4004 text section it describes. */
4005 linked_sec_tic6x_data
->u
.text
.tic6x_exidx_sec
= sec
;
4010 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
4011 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
4012 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
4014 for (i
= 0; i
< num_text_sections
; i
++)
4016 asection
*sec
= text_section_order
[i
];
4017 asection
*exidx_sec
;
4018 struct _tic6x_elf_section_data
*tic6x_data
4019 = get_tic6x_elf_section_data (sec
);
4020 struct _tic6x_elf_section_data
*exidx_data
;
4021 bfd_byte
*contents
= NULL
;
4022 int deleted_exidx_bytes
= 0;
4024 tic6x_unwind_table_edit
*unwind_edit_head
= NULL
;
4025 tic6x_unwind_table_edit
*unwind_edit_tail
= NULL
;
4026 Elf_Internal_Shdr
*hdr
;
4029 if (tic6x_data
== NULL
)
4032 exidx_sec
= tic6x_data
->u
.text
.tic6x_exidx_sec
;
4033 if (exidx_sec
== NULL
)
4035 /* Section has no unwind data. */
4036 if (last_unwind_type
== 0 || !last_exidx_sec
)
4039 /* Ignore zero sized sections. */
4043 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4044 last_unwind_type
= 0;
4048 /* Skip /DISCARD/ sections. */
4049 if (bfd_is_abs_section (exidx_sec
->output_section
))
4052 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
4053 if (hdr
->sh_type
!= SHT_C6000_UNWIND
)
4056 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
4057 if (exidx_data
== NULL
)
4060 ibfd
= exidx_sec
->owner
;
4062 if (hdr
->contents
!= NULL
)
4063 contents
= hdr
->contents
;
4064 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
4068 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
4070 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
4074 /* An EXIDX_CANTUNWIND entry. */
4075 if (second_word
== 1)
4077 if (last_unwind_type
== 0)
4081 /* Inlined unwinding data. Merge if equal to previous. */
4082 else if ((second_word
& 0x80000000) != 0)
4084 if (merge_exidx_entries
4085 && last_second_word
== second_word
4086 && last_unwind_type
== 1)
4089 last_second_word
= second_word
;
4091 /* Normal table entry. In theory we could merge these too,
4092 but duplicate entries are likely to be much less common. */
4098 elf32_tic6x_add_unwind_table_edit (&unwind_edit_head
,
4099 &unwind_edit_tail
, DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
4101 deleted_exidx_bytes
+= 8;
4104 last_unwind_type
= unwind_type
;
4107 /* Free contents if we allocated it ourselves. */
4108 if (contents
!= hdr
->contents
)
4111 /* Record edits to be applied later (in elf32_tic6x_write_section). */
4112 exidx_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
4113 exidx_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
4115 if (deleted_exidx_bytes
> 0)
4116 elf32_tic6x_adjust_exidx_size (exidx_sec
, -deleted_exidx_bytes
);
4118 last_exidx_sec
= exidx_sec
;
4119 last_text_sec
= sec
;
4122 /* Add terminating CANTUNWIND entry. */
4123 if (last_exidx_sec
&& last_unwind_type
!= 0)
4124 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4129 /* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified. */
4131 static unsigned long
4132 elf32_tic6x_add_low31 (unsigned long val
, bfd_vma addend
)
4134 return (val
& ~0x7ffffffful
) | ((val
+ addend
) & 0x7ffffffful
);
4137 /* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
4138 relocations. OFFSET is in bytes, and will be scaled before encoding. */
4142 elf32_tic6x_copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
,
4145 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
4146 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
4149 /* High bit of first word is supposed to be zero. */
4150 if ((first_word
& 0x80000000ul
) == 0)
4151 first_word
= elf32_tic6x_add_low31 (first_word
, offset
);
4153 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
4154 (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry. */
4155 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
4156 second_word
= elf32_tic6x_add_low31 (second_word
, offset
);
4158 bfd_put_32 (output_bfd
, first_word
, to
);
4159 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
4162 /* Do the actual mangling of exception index tables. */
4165 elf32_tic6x_write_section (bfd
*output_bfd
,
4166 struct bfd_link_info
*link_info
,
4170 _tic6x_elf_section_data
*tic6x_data
;
4171 struct elf32_tic6x_link_hash_table
*globals
4172 = elf32_tic6x_hash_table (link_info
);
4173 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4175 if (globals
== NULL
)
4178 /* If this section has not been allocated an _tic6x_elf_section_data
4179 structure then we cannot record anything. */
4180 tic6x_data
= get_tic6x_elf_section_data (sec
);
4181 if (tic6x_data
== NULL
)
4184 if (tic6x_data
->elf
.this_hdr
.sh_type
!= SHT_C6000_UNWIND
)
4187 tic6x_unwind_table_edit
*edit_node
4188 = tic6x_data
->u
.exidx
.unwind_edit_list
;
4189 /* Now, sec->size is the size of the section we will write. The original
4190 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
4191 markers) was sec->rawsize. (This isn't the case if we perform no
4192 edits, then rawsize will be zero and we should use size). */
4193 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
4194 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
4195 unsigned int in_index
, out_index
;
4196 bfd_vma add_to_offsets
= 0;
4198 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
4202 unsigned int edit_index
= edit_node
->index
;
4204 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
4206 elf32_tic6x_copy_exidx_entry (output_bfd
,
4207 edited_contents
+ out_index
* 8,
4208 contents
+ in_index
* 8, add_to_offsets
);
4212 else if (in_index
== edit_index
4213 || (in_index
* 8 >= input_size
4214 && edit_index
== UINT_MAX
))
4216 switch (edit_node
->type
)
4218 case DELETE_EXIDX_ENTRY
:
4220 add_to_offsets
+= 8;
4223 case INSERT_EXIDX_CANTUNWIND_AT_END
:
4225 asection
*text_sec
= edit_node
->linked_section
;
4226 bfd_vma text_offset
= text_sec
->output_section
->vma
4227 + text_sec
->output_offset
4229 bfd_vma exidx_offset
= offset
+ out_index
* 8;
4230 unsigned long prel31_offset
;
4232 /* Note: this is meant to be equivalent to an
4233 R_C6000_PREL31 relocation. These synthetic
4234 EXIDX_CANTUNWIND markers are not relocated by the
4235 usual BFD method. */
4236 prel31_offset
= ((text_offset
- exidx_offset
) >> 1)
4239 /* First address we can't unwind. */
4240 bfd_put_32 (output_bfd
, prel31_offset
,
4241 &edited_contents
[out_index
* 8]);
4243 /* Code for EXIDX_CANTUNWIND. */
4244 bfd_put_32 (output_bfd
, 0x1,
4245 &edited_contents
[out_index
* 8 + 4]);
4248 add_to_offsets
-= 8;
4253 edit_node
= edit_node
->next
;
4258 /* No more edits, copy remaining entries verbatim. */
4259 elf32_tic6x_copy_exidx_entry (output_bfd
,
4260 edited_contents
+ out_index
* 8,
4261 contents
+ in_index
* 8, add_to_offsets
);
4267 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
4268 bfd_set_section_contents (output_bfd
, sec
->output_section
,
4270 (file_ptr
) sec
->output_offset
, sec
->size
);
4275 #define TARGET_LITTLE_SYM tic6x_elf32_le_vec
4276 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
4277 #define TARGET_BIG_SYM tic6x_elf32_be_vec
4278 #define TARGET_BIG_NAME "elf32-tic6x-be"
4279 #define ELF_ARCH bfd_arch_tic6x
4280 #define ELF_TARGET_ID TIC6X_ELF_DATA
4281 #define ELF_MACHINE_CODE EM_TI_C6000
4282 #define ELF_MAXPAGESIZE 0x1000
4283 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
4284 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
4285 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
4286 #define bfd_elf32_mkobject elf32_tic6x_mkobject
4287 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
4288 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
4289 #define elf_backend_stack_align 8
4290 #define elf_backend_can_gc_sections 1
4291 #define elf_backend_default_use_rela_p 1
4292 #define elf_backend_may_use_rel_p 1
4293 #define elf_backend_may_use_rela_p 1
4294 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
4295 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
4296 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
4297 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
4298 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4299 #define elf_backend_obj_attrs_vendor "c6xabi"
4300 #define elf_backend_can_refcount 1
4301 #define elf_backend_want_got_plt 1
4302 #define elf_backend_want_dynbss 1
4303 #define elf_backend_want_dynrelro 1
4304 #define elf_backend_plt_readonly 1
4305 #define elf_backend_rela_normal 1
4306 #define elf_backend_got_header_size 8
4307 #define elf_backend_fake_sections elf32_tic6x_fake_sections
4308 #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
4309 #define elf_backend_create_dynamic_sections \
4310 elf32_tic6x_create_dynamic_sections
4311 #define elf_backend_adjust_dynamic_symbol \
4312 elf32_tic6x_adjust_dynamic_symbol
4313 #define elf_backend_check_relocs elf32_tic6x_check_relocs
4314 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4315 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4316 #define elf_backend_link_output_symbol_hook \
4317 elf32_tic6x_link_output_symbol_hook
4318 #define elf_backend_section_from_bfd_section \
4319 elf32_tic6x_section_from_bfd_section
4320 #define elf_backend_relocate_section elf32_tic6x_relocate_section
4321 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4322 #define elf_backend_finish_dynamic_symbol \
4323 elf32_tic6x_finish_dynamic_symbol
4324 #define elf_backend_always_size_sections \
4325 elf32_tic6x_always_size_sections
4326 #define elf_backend_size_dynamic_sections \
4327 elf32_tic6x_size_dynamic_sections
4328 #define elf_backend_finish_dynamic_sections \
4329 elf32_tic6x_finish_dynamic_sections
4330 #define bfd_elf32_bfd_final_link \
4331 elf32_tic6x_final_link
4332 #define elf_backend_write_section elf32_tic6x_write_section
4333 #define elf_info_to_howto elf32_tic6x_info_to_howto
4334 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
4336 #undef elf_backend_omit_section_dynsym
4337 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4338 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4340 #include "elf32-target.h"
4343 #define elf32_bed elf32_tic6x_linux_bed
4345 #undef TARGET_LITTLE_SYM
4346 #define TARGET_LITTLE_SYM tic6x_elf32_linux_le_vec
4347 #undef TARGET_LITTLE_NAME
4348 #define TARGET_LITTLE_NAME "elf32-tic6x-linux-le"
4349 #undef TARGET_BIG_SYM
4350 #define TARGET_BIG_SYM tic6x_elf32_linux_be_vec
4351 #undef TARGET_BIG_NAME
4352 #define TARGET_BIG_NAME "elf32-tic6x-linux-be"
4354 #define ELF_OSABI ELFOSABI_C6000_LINUX
4356 #include "elf32-target.h"
4359 #define elf32_bed elf32_tic6x_elf_bed
4361 #undef TARGET_LITTLE_SYM
4362 #define TARGET_LITTLE_SYM tic6x_elf32_c6000_le_vec
4363 #undef TARGET_LITTLE_NAME
4364 #define TARGET_LITTLE_NAME "elf32-tic6x-elf-le"
4365 #undef TARGET_BIG_SYM
4366 #define TARGET_BIG_SYM tic6x_elf32_c6000_be_vec
4367 #undef TARGET_BIG_NAME
4368 #define TARGET_BIG_NAME "elf32-tic6x-elf-be"
4370 #define ELF_OSABI ELFOSABI_C6000_ELFABI
4372 #include "elf32-target.h"