1 /* 32-bit ELF support for TI C6X
2 Copyright 2010, 2011, 2012
3 Free Software Foundation, Inc.
4 Contributed by Joseph Myers <joseph@codesourcery.com>
5 Bernd Schmidt <bernds@codesourcery.com>
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
28 #include "libiberty.h"
30 #include "elf/tic6x.h"
31 #include "elf32-tic6x.h"
33 #define ELF_DYNAMIC_INTERPRETER "/lib/ld-uClibc.so.0"
35 /* DSBT binaries have a default 128K stack. */
36 #define DEFAULT_STACK_SIZE 0x20000
38 /* The size in bytes of an entry in the procedure linkage table. */
39 #define PLT_ENTRY_SIZE 24
41 /* TI C6X ELF linker hash table. */
43 struct elf32_tic6x_link_hash_table
45 struct elf_link_hash_table elf;
47 /* Short-cuts to get to dynamic linker sections. */
51 /* C6X specific command line arguments. */
52 struct elf32_tic6x_params params;
54 /* Small local sym cache. */
55 struct sym_cache sym_cache;
57 /* The output BFD, for convenience. */
60 /* The .dsbt section. */
64 /* Get the TI C6X ELF linker hash table from a link_info structure. */
66 #define elf32_tic6x_hash_table(p) \
67 ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
69 /* TI C6X ELF linker hash entry. */
71 struct elf32_tic6x_link_hash_entry
73 struct elf_link_hash_entry elf;
75 /* Track dynamic relocs copied for this symbol. */
76 struct elf_dyn_relocs *dyn_relocs;
82 INSERT_EXIDX_CANTUNWIND_AT_END
84 tic6x_unwind_edit_type;
86 /* A (sorted) list of edits to apply to an unwind table. */
87 typedef struct tic6x_unwind_table_edit
89 tic6x_unwind_edit_type type;
90 /* Note: we sometimes want to insert an unwind entry corresponding to a
91 section different from the one we're currently writing out, so record the
92 (text) section this edit relates to here. */
93 asection *linked_section;
95 struct tic6x_unwind_table_edit *next;
97 tic6x_unwind_table_edit;
99 typedef struct _tic6x_elf_section_data
101 /* Information about mapping symbols. */
102 struct bfd_elf_section_data elf;
103 /* Information about unwind tables. */
106 /* Unwind info attached to a text section. */
109 asection *tic6x_exidx_sec;
112 /* Unwind info attached to an .c6xabi.exidx section. */
115 tic6x_unwind_table_edit *unwind_edit_list;
116 tic6x_unwind_table_edit *unwind_edit_tail;
120 _tic6x_elf_section_data;
122 #define elf32_tic6x_section_data(sec) \
123 ((_tic6x_elf_section_data *) elf_section_data (sec))
125 struct elf32_tic6x_obj_tdata
127 struct elf_obj_tdata root;
129 /* Whether to use RELA relocations when generating relocations.
130 This is a per-object flag to allow the assembler to generate REL
131 relocations for use in linker testcases. */
132 bfd_boolean use_rela_p;
135 #define elf32_tic6x_tdata(abfd) \
136 ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
138 #define is_tic6x_elf(bfd) \
139 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
140 && elf_tdata (bfd) != NULL \
141 && elf_object_id (bfd) == TIC6X_ELF_DATA)
143 /* C6X ELF uses two common sections. One is the usual one, and the
144 other is for small objects. All the small objects are kept
145 together, and then referenced via the gp pointer, which yields
146 faster assembler code. This is what we use for the small common
147 section. This approach is copied from ecoff.c. */
148 static asection tic6x_elf_scom_section;
149 static asymbol tic6x_elf_scom_symbol;
150 static asymbol *tic6x_elf_scom_symbol_ptr;
152 static reloc_howto_type elf32_tic6x_howto_table[] =
154 HOWTO (R_C6000_NONE, /* type */
156 0, /* size (0 = byte, 1 = short, 2 = long) */
158 FALSE, /* pc_relative */
160 complain_overflow_dont,/* complain_on_overflow */
161 bfd_elf_generic_reloc, /* special_function */
162 "R_C6000_NONE", /* name */
163 FALSE, /* partial_inplace */
166 FALSE), /* pcrel_offset */
167 HOWTO (R_C6000_ABS32, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE, /* pc_relative */
173 complain_overflow_dont,/* complain_on_overflow */
174 bfd_elf_generic_reloc, /* special_function */
175 "R_C6000_ABS32", /* name */
176 FALSE, /* partial_inplace */
178 0xffffffff, /* dst_mask */
179 FALSE), /* pcrel_offset */
180 HOWTO (R_C6000_ABS16, /* type */
182 1, /* size (0 = byte, 1 = short, 2 = long) */
184 FALSE, /* pc_relative */
186 complain_overflow_bitfield,/* complain_on_overflow */
187 bfd_elf_generic_reloc, /* special_function */
188 "R_C6000_ABS16", /* name */
189 FALSE, /* partial_inplace */
191 0x0000ffff, /* dst_mask */
192 FALSE), /* pcrel_offset */
193 HOWTO (R_C6000_ABS8, /* type */
195 0, /* size (0 = byte, 1 = short, 2 = long) */
197 FALSE, /* pc_relative */
199 complain_overflow_bitfield,/* complain_on_overflow */
200 bfd_elf_generic_reloc, /* special_function */
201 "R_C6000_ABS8", /* name */
202 FALSE, /* partial_inplace */
204 0x000000ff, /* dst_mask */
205 FALSE), /* pcrel_offset */
206 HOWTO (R_C6000_PCR_S21, /* type */
208 2, /* size (0 = byte, 1 = short, 2 = long) */
210 TRUE, /* pc_relative */
212 complain_overflow_signed,/* complain_on_overflow */
213 bfd_elf_generic_reloc, /* special_function */
214 "R_C6000_PCR_S21", /* name */
215 FALSE, /* partial_inplace */
217 0x0fffff80, /* dst_mask */
218 TRUE), /* pcrel_offset */
219 HOWTO (R_C6000_PCR_S12, /* type */
221 2, /* size (0 = byte, 1 = short, 2 = long) */
223 TRUE, /* pc_relative */
225 complain_overflow_signed,/* complain_on_overflow */
226 bfd_elf_generic_reloc, /* special_function */
227 "R_C6000_PCR_S12", /* name */
228 FALSE, /* partial_inplace */
230 0x0fff0000, /* dst_mask */
231 TRUE), /* pcrel_offset */
232 HOWTO (R_C6000_PCR_S10, /* type */
234 2, /* size (0 = byte, 1 = short, 2 = long) */
236 TRUE, /* pc_relative */
238 complain_overflow_signed,/* complain_on_overflow */
239 bfd_elf_generic_reloc, /* special_function */
240 "R_C6000_PCR_S10", /* name */
241 FALSE, /* partial_inplace */
243 0x007fe000, /* dst_mask */
244 TRUE), /* pcrel_offset */
245 HOWTO (R_C6000_PCR_S7, /* type */
247 2, /* size (0 = byte, 1 = short, 2 = long) */
249 TRUE, /* pc_relative */
251 complain_overflow_signed,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_C6000_PCR_S7", /* name */
254 FALSE, /* partial_inplace */
256 0x007f0000, /* dst_mask */
257 TRUE), /* pcrel_offset */
258 HOWTO (R_C6000_ABS_S16, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 FALSE, /* pc_relative */
264 complain_overflow_signed,/* complain_on_overflow */
265 bfd_elf_generic_reloc, /* special_function */
266 "R_C6000_ABS_S16", /* name */
267 FALSE, /* partial_inplace */
269 0x007fff80, /* dst_mask */
270 FALSE), /* pcrel_offset */
271 HOWTO (R_C6000_ABS_L16, /* type */
273 2, /* size (0 = byte, 1 = short, 2 = long) */
275 FALSE, /* pc_relative */
277 complain_overflow_dont,/* complain_on_overflow */
278 bfd_elf_generic_reloc, /* special_function */
279 "R_C6000_ABS_L16", /* name */
280 FALSE, /* partial_inplace */
282 0x007fff80, /* dst_mask */
283 FALSE), /* pcrel_offset */
284 HOWTO (R_C6000_ABS_H16, /* type */
286 2, /* size (0 = byte, 1 = short, 2 = long) */
288 FALSE, /* pc_relative */
290 complain_overflow_dont,/* complain_on_overflow */
291 bfd_elf_generic_reloc, /* special_function */
292 "R_C6000_ABS_H16", /* name */
293 FALSE, /* partial_inplace */
295 0x007fff80, /* dst_mask */
296 FALSE), /* pcrel_offset */
297 HOWTO (R_C6000_SBR_U15_B, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 FALSE, /* pc_relative */
303 complain_overflow_unsigned,/* complain_on_overflow */
304 bfd_elf_generic_reloc, /* special_function */
305 "R_C6000_SBR_U15_B", /* name */
306 FALSE, /* partial_inplace */
308 0x007fff00, /* dst_mask */
309 FALSE), /* pcrel_offset */
310 HOWTO (R_C6000_SBR_U15_H, /* type */
312 2, /* size (0 = byte, 1 = short, 2 = long) */
314 FALSE, /* pc_relative */
316 complain_overflow_unsigned,/* complain_on_overflow */
317 bfd_elf_generic_reloc, /* special_function */
318 "R_C6000_SBR_U15_H", /* name */
319 FALSE, /* partial_inplace */
321 0x007fff00, /* dst_mask */
322 FALSE), /* pcrel_offset */
323 HOWTO (R_C6000_SBR_U15_W, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE, /* pc_relative */
329 complain_overflow_unsigned,/* complain_on_overflow */
330 bfd_elf_generic_reloc, /* special_function */
331 "R_C6000_SBR_U15_W", /* name */
332 FALSE, /* partial_inplace */
334 0x007fff00, /* dst_mask */
335 FALSE), /* pcrel_offset */
336 HOWTO (R_C6000_SBR_S16, /* type */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
340 FALSE, /* pc_relative */
342 complain_overflow_signed,/* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_C6000_SBR_S16", /* name */
345 FALSE, /* partial_inplace */
347 0x007fff80, /* dst_mask */
348 FALSE), /* pcrel_offset */
349 HOWTO (R_C6000_SBR_L16_B, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 FALSE, /* pc_relative */
355 complain_overflow_dont,/* complain_on_overflow */
356 bfd_elf_generic_reloc, /* special_function */
357 "R_C6000_SBR_L16_B", /* name */
358 FALSE, /* partial_inplace */
360 0x007fff80, /* dst_mask */
361 FALSE), /* pcrel_offset */
362 HOWTO (R_C6000_SBR_L16_H, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 FALSE, /* pc_relative */
368 complain_overflow_dont,/* complain_on_overflow */
369 bfd_elf_generic_reloc, /* special_function */
370 "R_C6000_SBR_L16_H", /* name */
371 FALSE, /* partial_inplace */
373 0x007fff80, /* dst_mask */
374 FALSE), /* pcrel_offset */
375 HOWTO (R_C6000_SBR_L16_W, /* type */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
379 FALSE, /* pc_relative */
381 complain_overflow_dont,/* complain_on_overflow */
382 bfd_elf_generic_reloc, /* special_function */
383 "R_C6000_SBR_L16_W", /* name */
384 FALSE, /* partial_inplace */
386 0x007fff80, /* dst_mask */
387 FALSE), /* pcrel_offset */
388 HOWTO (R_C6000_SBR_H16_B, /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 FALSE, /* pc_relative */
394 complain_overflow_dont,/* complain_on_overflow */
395 bfd_elf_generic_reloc, /* special_function */
396 "R_C6000_SBR_H16_B", /* name */
397 FALSE, /* partial_inplace */
399 0x007fff80, /* dst_mask */
400 FALSE), /* pcrel_offset */
401 HOWTO (R_C6000_SBR_H16_H, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE, /* pc_relative */
407 complain_overflow_dont,/* complain_on_overflow */
408 bfd_elf_generic_reloc, /* special_function */
409 "R_C6000_SBR_H16_H", /* name */
410 FALSE, /* partial_inplace */
412 0x007fff80, /* dst_mask */
413 FALSE), /* pcrel_offset */
414 HOWTO (R_C6000_SBR_H16_W, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 FALSE, /* pc_relative */
420 complain_overflow_dont,/* complain_on_overflow */
421 bfd_elf_generic_reloc, /* special_function */
422 "R_C6000_SBR_H16_W", /* name */
423 FALSE, /* partial_inplace */
425 0x007fff80, /* dst_mask */
426 FALSE), /* pcrel_offset */
427 HOWTO (R_C6000_SBR_GOT_U15_W, /* type */
429 2, /* size (0 = byte, 1 = short, 2 = long) */
431 FALSE, /* pc_relative */
433 complain_overflow_unsigned,/* complain_on_overflow */
434 bfd_elf_generic_reloc, /* special_function */
435 "R_C6000_SBR_GOT_U15_W",/* name */
436 FALSE, /* partial_inplace */
438 0x007fff00, /* dst_mask */
439 FALSE), /* pcrel_offset */
440 HOWTO (R_C6000_SBR_GOT_L16_W, /* type */
442 2, /* size (0 = byte, 1 = short, 2 = long) */
444 FALSE, /* pc_relative */
446 complain_overflow_dont,/* complain_on_overflow */
447 bfd_elf_generic_reloc, /* special_function */
448 "R_C6000_SBR_GOT_L16_W",/* name */
449 FALSE, /* partial_inplace */
451 0x007fff80, /* dst_mask */
452 FALSE), /* pcrel_offset */
453 HOWTO (R_C6000_SBR_GOT_H16_W, /* type */
455 2, /* size (0 = byte, 1 = short, 2 = long) */
457 FALSE, /* pc_relative */
459 complain_overflow_dont,/* complain_on_overflow */
460 bfd_elf_generic_reloc, /* special_function */
461 "R_C6000_SBR_GOT_H16_W",/* name */
462 FALSE, /* partial_inplace */
464 0x007fff80, /* dst_mask */
465 FALSE), /* pcrel_offset */
466 HOWTO (R_C6000_DSBT_INDEX, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE, /* pc_relative */
472 complain_overflow_unsigned,/* complain_on_overflow */
473 bfd_elf_generic_reloc, /* special_function */
474 "R_C6000_DSBT_INDEX", /* name */
475 FALSE, /* partial_inplace */
477 0x007fff00, /* dst_mask */
478 FALSE), /* pcrel_offset */
479 HOWTO (R_C6000_PREL31, /* type */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
483 TRUE, /* pc_relative */
485 complain_overflow_dont,/* complain_on_overflow */
486 bfd_elf_generic_reloc, /* special_function */
487 "R_C6000_PREL31", /* name */
488 FALSE, /* partial_inplace */
490 0x7fffffff, /* dst_mask */
491 TRUE), /* pcrel_offset */
492 HOWTO (R_C6000_COPY, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 FALSE, /* pc_relative */
498 complain_overflow_dont,/* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_C6000_COPY", /* name */
501 FALSE, /* partial_inplace */
503 0xffffffff, /* dst_mask */
504 FALSE), /* pcrel_offset */
505 HOWTO (R_C6000_JUMP_SLOT, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 FALSE, /* pc_relative */
511 complain_overflow_dont,/* complain_on_overflow */
512 bfd_elf_generic_reloc, /* special_function */
513 "R_C6000_JUMP_SLOT", /* name */
514 FALSE, /* partial_inplace */
516 0xffffffff, /* dst_mask */
517 FALSE), /* pcrel_offset */
518 HOWTO (R_C6000_EHTYPE, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 FALSE, /* pc_relative */
524 complain_overflow_dont,/* complain_on_overflow */
525 bfd_elf_generic_reloc, /* special_function */
526 "R_C6000_EHTYPE", /* name */
527 FALSE, /* partial_inplace */
529 0xffffffff, /* dst_mask */
530 FALSE), /* pcrel_offset */
531 HOWTO (R_C6000_PCR_H16, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 TRUE, /* pc_relative */
537 complain_overflow_dont,/* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_C6000_PCR_H16", /* name */
540 FALSE, /* partial_inplace */
542 0x007fff80, /* dst_mask */
543 TRUE), /* pcrel_offset */
544 HOWTO (R_C6000_PCR_L16, /* type */
546 2, /* size (0 = byte, 1 = short, 2 = long) */
548 TRUE, /* pc_relative */
550 complain_overflow_dont,/* complain_on_overflow */
551 bfd_elf_generic_reloc, /* special_function */
552 "R_C6000_PCR_L16", /* name */
553 FALSE, /* partial_inplace */
555 0x007fff80, /* dst_mask */
556 TRUE), /* pcrel_offset */
779 HOWTO (R_C6000_ALIGN, /* type */
781 0, /* size (0 = byte, 1 = short, 2 = long) */
783 FALSE, /* pc_relative */
785 complain_overflow_dont,/* complain_on_overflow */
786 bfd_elf_generic_reloc, /* special_function */
787 "R_C6000_ALIGN", /* name */
788 FALSE, /* partial_inplace */
791 FALSE), /* pcrel_offset */
792 HOWTO (R_C6000_FPHEAD, /* type */
794 0, /* size (0 = byte, 1 = short, 2 = long) */
796 FALSE, /* pc_relative */
798 complain_overflow_dont,/* complain_on_overflow */
799 bfd_elf_generic_reloc, /* special_function */
800 "R_C6000_FPHEAD", /* name */
801 FALSE, /* partial_inplace */
804 FALSE), /* pcrel_offset */
805 HOWTO (R_C6000_NOCMP, /* type */
807 0, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE, /* pc_relative */
811 complain_overflow_dont,/* complain_on_overflow */
812 bfd_elf_generic_reloc, /* special_function */
813 "R_C6000_NOCMP", /* name */
814 FALSE, /* partial_inplace */
817 FALSE) /* pcrel_offset */
820 static reloc_howto_type elf32_tic6x_howto_table_rel[] =
822 HOWTO (R_C6000_NONE, /* type */
824 0, /* size (0 = byte, 1 = short, 2 = long) */
826 FALSE, /* pc_relative */
828 complain_overflow_dont,/* complain_on_overflow */
829 bfd_elf_generic_reloc, /* special_function */
830 "R_C6000_NONE", /* name */
831 TRUE, /* partial_inplace */
834 FALSE), /* pcrel_offset */
835 HOWTO (R_C6000_ABS32, /* type */
837 2, /* size (0 = byte, 1 = short, 2 = long) */
839 FALSE, /* pc_relative */
841 complain_overflow_dont,/* complain_on_overflow */
842 bfd_elf_generic_reloc, /* special_function */
843 "R_C6000_ABS32", /* name */
844 TRUE, /* partial_inplace */
845 0xffffffff, /* src_mask */
846 0xffffffff, /* dst_mask */
847 FALSE), /* pcrel_offset */
848 HOWTO (R_C6000_ABS16, /* type */
850 1, /* size (0 = byte, 1 = short, 2 = long) */
852 FALSE, /* pc_relative */
854 complain_overflow_bitfield,/* complain_on_overflow */
855 bfd_elf_generic_reloc, /* special_function */
856 "R_C6000_ABS16", /* name */
857 TRUE, /* partial_inplace */
858 0x0000ffff, /* src_mask */
859 0x0000ffff, /* dst_mask */
860 FALSE), /* pcrel_offset */
861 HOWTO (R_C6000_ABS8, /* type */
863 0, /* size (0 = byte, 1 = short, 2 = long) */
865 FALSE, /* pc_relative */
867 complain_overflow_bitfield,/* complain_on_overflow */
868 bfd_elf_generic_reloc, /* special_function */
869 "R_C6000_ABS8", /* name */
870 TRUE, /* partial_inplace */
871 0x000000ff, /* src_mask */
872 0x000000ff, /* dst_mask */
873 FALSE), /* pcrel_offset */
874 HOWTO (R_C6000_PCR_S21, /* type */
876 2, /* size (0 = byte, 1 = short, 2 = long) */
878 TRUE, /* pc_relative */
880 complain_overflow_signed,/* complain_on_overflow */
881 bfd_elf_generic_reloc, /* special_function */
882 "R_C6000_PCR_S21", /* name */
883 TRUE, /* partial_inplace */
884 0x0fffff80, /* src_mask */
885 0x0fffff80, /* dst_mask */
886 TRUE), /* pcrel_offset */
887 HOWTO (R_C6000_PCR_S12, /* type */
889 2, /* size (0 = byte, 1 = short, 2 = long) */
891 TRUE, /* pc_relative */
893 complain_overflow_signed,/* complain_on_overflow */
894 bfd_elf_generic_reloc, /* special_function */
895 "R_C6000_PCR_S12", /* name */
896 TRUE, /* partial_inplace */
897 0x0fff0000, /* src_mask */
898 0x0fff0000, /* dst_mask */
899 TRUE), /* pcrel_offset */
900 HOWTO (R_C6000_PCR_S10, /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 TRUE, /* pc_relative */
906 complain_overflow_signed,/* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_C6000_PCR_S10", /* name */
909 TRUE, /* partial_inplace */
910 0x007fe000, /* src_mask */
911 0x007fe000, /* dst_mask */
912 TRUE), /* pcrel_offset */
913 HOWTO (R_C6000_PCR_S7, /* type */
915 2, /* size (0 = byte, 1 = short, 2 = long) */
917 TRUE, /* pc_relative */
919 complain_overflow_signed,/* complain_on_overflow */
920 bfd_elf_generic_reloc, /* special_function */
921 "R_C6000_PCR_S7", /* name */
922 TRUE, /* partial_inplace */
923 0x007f0000, /* src_mask */
924 0x007f0000, /* dst_mask */
925 TRUE), /* pcrel_offset */
926 HOWTO (R_C6000_ABS_S16, /* type */
928 2, /* size (0 = byte, 1 = short, 2 = long) */
930 FALSE, /* pc_relative */
932 complain_overflow_signed,/* complain_on_overflow */
933 bfd_elf_generic_reloc, /* special_function */
934 "R_C6000_ABS_S16", /* name */
935 TRUE, /* partial_inplace */
936 0x007fff80, /* src_mask */
937 0x007fff80, /* dst_mask */
938 FALSE), /* pcrel_offset */
939 HOWTO (R_C6000_ABS_L16, /* type */
941 2, /* size (0 = byte, 1 = short, 2 = long) */
943 FALSE, /* pc_relative */
945 complain_overflow_dont,/* complain_on_overflow */
946 bfd_elf_generic_reloc, /* special_function */
947 "R_C6000_ABS_L16", /* name */
948 TRUE, /* partial_inplace */
949 0x007fff80, /* src_mask */
950 0x007fff80, /* dst_mask */
951 FALSE), /* pcrel_offset */
952 EMPTY_HOWTO (R_C6000_ABS_H16),
953 HOWTO (R_C6000_SBR_U15_B, /* type */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 FALSE, /* pc_relative */
959 complain_overflow_unsigned,/* complain_on_overflow */
960 bfd_elf_generic_reloc, /* special_function */
961 "R_C6000_SBR_U15_B", /* name */
962 TRUE, /* partial_inplace */
963 0x007fff00, /* src_mask */
964 0x007fff00, /* dst_mask */
965 FALSE), /* pcrel_offset */
966 HOWTO (R_C6000_SBR_U15_H, /* type */
968 2, /* size (0 = byte, 1 = short, 2 = long) */
970 FALSE, /* pc_relative */
972 complain_overflow_unsigned,/* complain_on_overflow */
973 bfd_elf_generic_reloc, /* special_function */
974 "R_C6000_SBR_U15_H", /* name */
975 TRUE, /* partial_inplace */
976 0x007fff00, /* src_mask */
977 0x007fff00, /* dst_mask */
978 FALSE), /* pcrel_offset */
979 HOWTO (R_C6000_SBR_U15_W, /* type */
981 2, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE, /* pc_relative */
985 complain_overflow_unsigned,/* complain_on_overflow */
986 bfd_elf_generic_reloc, /* special_function */
987 "R_C6000_SBR_U15_W", /* name */
988 TRUE, /* partial_inplace */
989 0x007fff00, /* src_mask */
990 0x007fff00, /* dst_mask */
991 FALSE), /* pcrel_offset */
992 HOWTO (R_C6000_SBR_S16, /* type */
994 2, /* size (0 = byte, 1 = short, 2 = long) */
996 FALSE, /* pc_relative */
998 complain_overflow_signed,/* complain_on_overflow */
999 bfd_elf_generic_reloc, /* special_function */
1000 "R_C6000_SBR_S16", /* name */
1001 TRUE, /* partial_inplace */
1002 0x007fff80, /* src_mask */
1003 0x007fff80, /* dst_mask */
1004 FALSE), /* pcrel_offset */
1005 HOWTO (R_C6000_SBR_L16_B, /* type */
1007 2, /* size (0 = byte, 1 = short, 2 = long) */
1009 FALSE, /* pc_relative */
1011 complain_overflow_dont,/* complain_on_overflow */
1012 bfd_elf_generic_reloc, /* special_function */
1013 "R_C6000_SBR_L16_B", /* name */
1014 TRUE, /* partial_inplace */
1015 0x007fff80, /* src_mask */
1016 0x007fff80, /* dst_mask */
1017 FALSE), /* pcrel_offset */
1018 HOWTO (R_C6000_SBR_L16_H, /* type */
1020 2, /* size (0 = byte, 1 = short, 2 = long) */
1022 FALSE, /* pc_relative */
1024 complain_overflow_dont,/* complain_on_overflow */
1025 bfd_elf_generic_reloc, /* special_function */
1026 "R_C6000_SBR_L16_H", /* name */
1027 TRUE, /* partial_inplace */
1028 0x007fff80, /* src_mask */
1029 0x007fff80, /* dst_mask */
1030 FALSE), /* pcrel_offset */
1031 HOWTO (R_C6000_SBR_L16_W, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 FALSE, /* pc_relative */
1037 complain_overflow_dont,/* complain_on_overflow */
1038 bfd_elf_generic_reloc, /* special_function */
1039 "R_C6000_SBR_L16_W", /* name */
1040 TRUE, /* partial_inplace */
1041 0x007fff80, /* src_mask */
1042 0x007fff80, /* dst_mask */
1043 FALSE), /* pcrel_offset */
1044 EMPTY_HOWTO (R_C6000_SBR_H16_B),
1045 EMPTY_HOWTO (R_C6000_SBR_H16_H),
1046 EMPTY_HOWTO (R_C6000_SBR_H16_W),
1047 HOWTO (R_C6000_SBR_GOT_U15_W, /* type */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 FALSE, /* pc_relative */
1053 complain_overflow_unsigned,/* complain_on_overflow */
1054 bfd_elf_generic_reloc, /* special_function */
1055 "R_C6000_SBR_GOT_U15_W",/* name */
1056 TRUE, /* partial_inplace */
1057 0x007fff00, /* src_mask */
1058 0x007fff00, /* dst_mask */
1059 FALSE), /* pcrel_offset */
1060 HOWTO (R_C6000_SBR_GOT_L16_W, /* type */
1062 2, /* size (0 = byte, 1 = short, 2 = long) */
1064 FALSE, /* pc_relative */
1066 complain_overflow_dont,/* complain_on_overflow */
1067 bfd_elf_generic_reloc, /* special_function */
1068 "R_C6000_SBR_GOT_L16_W",/* name */
1069 TRUE, /* partial_inplace */
1070 0x007fff80, /* src_mask */
1071 0x007fff80, /* dst_mask */
1072 FALSE), /* pcrel_offset */
1073 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W),
1074 HOWTO (R_C6000_DSBT_INDEX, /* type */
1076 2, /* size (0 = byte, 1 = short, 2 = long) */
1078 FALSE, /* pc_relative */
1080 complain_overflow_unsigned,/* complain_on_overflow */
1081 bfd_elf_generic_reloc, /* special_function */
1082 "R_C6000_DSBT_INDEX", /* name */
1083 TRUE, /* partial_inplace */
1085 0x007fff00, /* dst_mask */
1086 FALSE), /* pcrel_offset */
1087 HOWTO (R_C6000_PREL31, /* type */
1089 2, /* size (0 = byte, 1 = short, 2 = long) */
1091 TRUE, /* pc_relative */
1093 complain_overflow_dont,/* complain_on_overflow */
1094 bfd_elf_generic_reloc, /* special_function */
1095 "R_C6000_PREL31", /* name */
1096 TRUE, /* partial_inplace */
1098 0x7fffffff, /* dst_mask */
1099 TRUE), /* pcrel_offset */
1100 HOWTO (R_C6000_COPY, /* type */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1104 FALSE, /* pc_relative */
1106 complain_overflow_dont,/* complain_on_overflow */
1107 bfd_elf_generic_reloc, /* special_function */
1108 "R_C6000_COPY", /* name */
1109 TRUE, /* partial_inplace */
1111 0xffffffff, /* dst_mask */
1112 FALSE), /* pcrel_offset */
1113 HOWTO (R_C6000_JUMP_SLOT, /* type */
1115 2, /* size (0 = byte, 1 = short, 2 = long) */
1117 FALSE, /* pc_relative */
1119 complain_overflow_dont,/* complain_on_overflow */
1120 bfd_elf_generic_reloc, /* special_function */
1121 "R_C6000_JUMP_SLOT", /* name */
1122 FALSE, /* partial_inplace */
1124 0xffffffff, /* dst_mask */
1125 FALSE), /* pcrel_offset */
1126 HOWTO (R_C6000_EHTYPE, /* type */
1128 2, /* size (0 = byte, 1 = short, 2 = long) */
1130 FALSE, /* pc_relative */
1132 complain_overflow_dont,/* complain_on_overflow */
1133 bfd_elf_generic_reloc, /* special_function */
1134 "R_C6000_EHTYPE", /* name */
1135 FALSE, /* partial_inplace */
1137 0xffffffff, /* dst_mask */
1138 FALSE), /* pcrel_offset */
1139 EMPTY_HOWTO (R_C6000_PCR_H16),
1140 EMPTY_HOWTO (R_C6000_PCR_L16),
1363 HOWTO (R_C6000_ALIGN, /* type */
1365 0, /* size (0 = byte, 1 = short, 2 = long) */
1367 FALSE, /* pc_relative */
1369 complain_overflow_dont,/* complain_on_overflow */
1370 bfd_elf_generic_reloc, /* special_function */
1371 "R_C6000_ALIGN", /* name */
1372 TRUE, /* partial_inplace */
1375 FALSE), /* pcrel_offset */
1376 HOWTO (R_C6000_FPHEAD, /* type */
1378 0, /* size (0 = byte, 1 = short, 2 = long) */
1380 FALSE, /* pc_relative */
1382 complain_overflow_dont,/* complain_on_overflow */
1383 bfd_elf_generic_reloc, /* special_function */
1384 "R_C6000_FPHEAD", /* name */
1385 TRUE, /* partial_inplace */
1388 FALSE), /* pcrel_offset */
1389 HOWTO (R_C6000_NOCMP, /* type */
1391 0, /* size (0 = byte, 1 = short, 2 = long) */
1393 FALSE, /* pc_relative */
1395 complain_overflow_dont,/* complain_on_overflow */
1396 bfd_elf_generic_reloc, /* special_function */
1397 "R_C6000_NOCMP", /* name */
1398 TRUE, /* partial_inplace */
1401 FALSE) /* pcrel_offset */
1404 /* Map BFD relocations to ELF relocations. */
1408 bfd_reloc_code_real_type bfd_reloc_val;
1409 enum elf_tic6x_reloc_type elf_reloc_val;
1412 static const tic6x_reloc_map elf32_tic6x_reloc_map[] =
1414 { BFD_RELOC_NONE, R_C6000_NONE },
1415 { BFD_RELOC_32, R_C6000_ABS32 },
1416 { BFD_RELOC_16, R_C6000_ABS16 },
1417 { BFD_RELOC_8, R_C6000_ABS8 },
1418 { BFD_RELOC_C6000_PCR_S21, R_C6000_PCR_S21 },
1419 { BFD_RELOC_C6000_PCR_S12, R_C6000_PCR_S12 },
1420 { BFD_RELOC_C6000_PCR_S10, R_C6000_PCR_S10 },
1421 { BFD_RELOC_C6000_PCR_S7, R_C6000_PCR_S7 },
1422 { BFD_RELOC_C6000_ABS_S16, R_C6000_ABS_S16 },
1423 { BFD_RELOC_C6000_ABS_L16, R_C6000_ABS_L16 },
1424 { BFD_RELOC_C6000_ABS_H16, R_C6000_ABS_H16 },
1425 { BFD_RELOC_C6000_SBR_U15_B, R_C6000_SBR_U15_B },
1426 { BFD_RELOC_C6000_SBR_U15_H, R_C6000_SBR_U15_H },
1427 { BFD_RELOC_C6000_SBR_U15_W, R_C6000_SBR_U15_W },
1428 { BFD_RELOC_C6000_SBR_S16, R_C6000_SBR_S16 },
1429 { BFD_RELOC_C6000_SBR_L16_B, R_C6000_SBR_L16_B },
1430 { BFD_RELOC_C6000_SBR_L16_H, R_C6000_SBR_L16_H },
1431 { BFD_RELOC_C6000_SBR_L16_W, R_C6000_SBR_L16_W },
1432 { BFD_RELOC_C6000_SBR_H16_B, R_C6000_SBR_H16_B },
1433 { BFD_RELOC_C6000_SBR_H16_H, R_C6000_SBR_H16_H },
1434 { BFD_RELOC_C6000_SBR_H16_W, R_C6000_SBR_H16_W },
1435 { BFD_RELOC_C6000_SBR_GOT_U15_W, R_C6000_SBR_GOT_U15_W },
1436 { BFD_RELOC_C6000_SBR_GOT_L16_W, R_C6000_SBR_GOT_L16_W },
1437 { BFD_RELOC_C6000_SBR_GOT_H16_W, R_C6000_SBR_GOT_H16_W },
1438 { BFD_RELOC_C6000_DSBT_INDEX, R_C6000_DSBT_INDEX },
1439 { BFD_RELOC_C6000_PREL31, R_C6000_PREL31 },
1440 { BFD_RELOC_C6000_COPY, R_C6000_COPY },
1441 { BFD_RELOC_C6000_JUMP_SLOT, R_C6000_JUMP_SLOT },
1442 { BFD_RELOC_C6000_EHTYPE, R_C6000_EHTYPE },
1443 { BFD_RELOC_C6000_PCR_H16, R_C6000_PCR_H16 },
1444 { BFD_RELOC_C6000_PCR_L16, R_C6000_PCR_L16 },
1445 { BFD_RELOC_C6000_ALIGN, R_C6000_ALIGN },
1446 { BFD_RELOC_C6000_FPHEAD, R_C6000_FPHEAD },
1447 { BFD_RELOC_C6000_NOCMP, R_C6000_NOCMP }
1450 static reloc_howto_type *
1451 elf32_tic6x_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
1455 for (i = 0; i < ARRAY_SIZE (elf32_tic6x_reloc_map); i++)
1456 if (elf32_tic6x_reloc_map[i].bfd_reloc_val == code)
1458 enum elf_tic6x_reloc_type elf_reloc_val;
1459 reloc_howto_type *howto;
1461 elf_reloc_val = elf32_tic6x_reloc_map[i].elf_reloc_val;
1462 if (elf32_tic6x_tdata (abfd)->use_rela_p)
1463 howto = &elf32_tic6x_howto_table[elf_reloc_val];
1465 howto = &elf32_tic6x_howto_table_rel[elf_reloc_val];
1467 /* Some relocations are RELA-only; do not return them for
1469 if (howto->name == NULL)
1478 static reloc_howto_type *
1479 elf32_tic6x_reloc_name_lookup (bfd *abfd, const char *r_name)
1481 if (elf32_tic6x_tdata (abfd)->use_rela_p)
1485 for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table); i++)
1486 if (elf32_tic6x_howto_table[i].name != NULL
1487 && strcasecmp (elf32_tic6x_howto_table[i].name, r_name) == 0)
1488 return &elf32_tic6x_howto_table[i];
1494 for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table_rel); i++)
1495 if (elf32_tic6x_howto_table_rel[i].name != NULL
1496 && strcasecmp (elf32_tic6x_howto_table_rel[i].name, r_name) == 0)
1497 return &elf32_tic6x_howto_table_rel[i];
1504 elf32_tic6x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1505 Elf_Internal_Rela *elf_reloc)
1507 unsigned int r_type;
1509 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1510 if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table))
1511 bfd_reloc->howto = NULL;
1513 bfd_reloc->howto = &elf32_tic6x_howto_table[r_type];
1517 elf32_tic6x_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1518 Elf_Internal_Rela *elf_reloc)
1520 unsigned int r_type;
1522 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1523 if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table_rel))
1524 bfd_reloc->howto = NULL;
1526 bfd_reloc->howto = &elf32_tic6x_howto_table_rel[r_type];
1530 elf32_tic6x_set_use_rela_p (bfd *abfd, bfd_boolean use_rela_p)
1532 elf32_tic6x_tdata (abfd)->use_rela_p = use_rela_p;
1535 /* Create an entry in a C6X ELF linker hash table. */
1537 static struct bfd_hash_entry *
1538 elf32_tic6x_link_hash_newfunc (struct bfd_hash_entry *entry,
1539 struct bfd_hash_table *table,
1542 /* Allocate the structure if it has not already been allocated by a
1546 entry = bfd_hash_allocate (table,
1547 sizeof (struct elf32_tic6x_link_hash_entry));
1552 /* Call the allocation method of the superclass. */
1553 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
1556 struct elf32_tic6x_link_hash_entry *eh;
1558 eh = (struct elf32_tic6x_link_hash_entry *) entry;
1559 eh->dyn_relocs = NULL;
1565 /* Create a C6X ELF linker hash table. */
1567 static struct bfd_link_hash_table *
1568 elf32_tic6x_link_hash_table_create (bfd *abfd)
1570 struct elf32_tic6x_link_hash_table *ret;
1571 bfd_size_type amt = sizeof (struct elf32_tic6x_link_hash_table);
1573 ret = bfd_malloc (amt);
1577 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1578 elf32_tic6x_link_hash_newfunc,
1579 sizeof (struct elf32_tic6x_link_hash_entry),
1586 ret->sym_cache.abfd = NULL;
1588 ret->elf.is_relocatable_executable = 1;
1590 return &ret->elf.root;
1594 elf32_tic6x_final_link (bfd *abfd, struct bfd_link_info *info)
1598 obj_attribute *out_attr;
1599 out_attr = elf_known_obj_attributes_proc (abfd);
1600 if (out_attr[Tag_ABI_PIC].i == 0)
1602 _bfd_error_handler (_("warning: generating a shared library "
1603 "containing non-PIC code"));
1605 if (out_attr[Tag_ABI_PID].i == 0)
1607 _bfd_error_handler (_("warning: generating a shared library "
1608 "containing non-PID code"));
1611 /* Invoke the regular ELF backend linker to do all the work. */
1612 if (!bfd_elf_final_link (abfd, info))
1618 /* Destroy a C6X ELF linker hash table. */
1621 elf32_tic6x_link_hash_table_free (struct bfd_link_hash_table *hash)
1623 _bfd_generic_link_hash_table_free (hash);
1626 /* Called to pass PARAMS to the backend. We store them in the hash table
1627 associated with INFO. */
1630 elf32_tic6x_setup (struct bfd_link_info *info,
1631 struct elf32_tic6x_params *params)
1633 struct elf32_tic6x_link_hash_table *htab = elf32_tic6x_hash_table (info);
1634 htab->params = *params;
1637 /* Determine if we're dealing with a DSBT object. */
1640 elf32_tic6x_using_dsbt (bfd *abfd)
1642 return bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC,
1646 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1647 sections in DYNOBJ, and set up shortcuts to them in our hash
1651 elf32_tic6x_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1653 struct elf32_tic6x_link_hash_table *htab;
1656 htab = elf32_tic6x_hash_table (info);
1660 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1664 flags = (SEC_ALLOC | SEC_LOAD
1665 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1666 htab->dsbt = bfd_make_section_anyway_with_flags (dynobj, ".dsbt",
1668 if (htab->dsbt == NULL
1669 || ! bfd_set_section_alignment (dynobj, htab->dsbt, 2)
1670 || ! bfd_set_section_alignment (dynobj, htab->elf.splt, 5))
1673 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1675 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
1678 || (!info->shared && !htab->srelbss))
1685 elf32_tic6x_mkobject (bfd *abfd)
1689 ret = bfd_elf_allocate_object (abfd, sizeof (struct elf32_tic6x_obj_tdata),
1692 elf32_tic6x_set_use_rela_p (abfd, TRUE);
1696 /* Install relocation RELA into section SRELA, incrementing its
1700 elf32_tic6x_install_rela (bfd *output_bfd, asection *srela,
1701 Elf_Internal_Rela *rela)
1704 bfd_vma off = srela->reloc_count++ * sizeof (Elf32_External_Rela);
1705 loc = srela->contents + off;
1706 BFD_ASSERT (off < srela->size);
1707 bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
1710 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1711 of the GOT at this offset have been initialized with the relocation. */
1714 elf32_tic6x_make_got_dynreloc (bfd *output_bfd,
1715 struct elf32_tic6x_link_hash_table *htab,
1716 asection *sym_sec, bfd_vma offset)
1718 asection *sgot = htab->elf.sgot;
1719 Elf_Internal_Rela outrel;
1722 outrel.r_offset = sgot->output_section->vma + sgot->output_offset + offset;
1723 outrel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
1724 if (sym_sec && sym_sec->output_section
1725 && ! bfd_is_abs_section (sym_sec->output_section)
1726 && ! bfd_is_und_section (sym_sec->output_section))
1728 dynindx = elf_section_data (sym_sec->output_section)->dynindx;
1729 outrel.r_addend -= sym_sec->output_section->vma;
1735 outrel.r_info = ELF32_R_INFO (dynindx, R_C6000_ABS32);
1736 elf32_tic6x_install_rela (output_bfd, htab->elf.srelgot, &outrel);
1739 /* Finish up dynamic symbol handling. We set the contents of various
1740 dynamic sections here. */
1743 elf32_tic6x_finish_dynamic_symbol (bfd * output_bfd,
1744 struct bfd_link_info *info,
1745 struct elf_link_hash_entry *h,
1746 Elf_Internal_Sym * sym)
1749 struct elf32_tic6x_link_hash_table *htab;
1751 htab = elf32_tic6x_hash_table (info);
1752 dynobj = htab->elf.dynobj;
1754 if (h->plt.offset != (bfd_vma) -1)
1757 bfd_vma got_section_offset, got_dp_offset, rela_offset;
1758 Elf_Internal_Rela rela;
1760 asection *plt, *gotplt, *relplt;
1761 const struct elf_backend_data *bed;
1763 bed = get_elf_backend_data (output_bfd);
1765 BFD_ASSERT (htab->elf.splt != NULL);
1766 plt = htab->elf.splt;
1767 gotplt = htab->elf.sgotplt;
1768 relplt = htab->elf.srelplt;
1770 /* This symbol has an entry in the procedure linkage table. Set
1773 if ((h->dynindx == -1
1774 && !((h->forced_local || info->executable)
1776 && h->type == STT_GNU_IFUNC))
1782 /* Get the index in the procedure linkage table which
1783 corresponds to this symbol. This is the index of this symbol
1784 in all the symbols for which we are making plt entries. The
1785 first entry in the procedure linkage table is reserved.
1787 Get the offset into the .got table of the entry that
1788 corresponds to this function. Each .got entry is 4 bytes.
1789 The first three are reserved.
1791 For static executables, we don't reserve anything. */
1793 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1794 got_section_offset = plt_index + bed->got_header_size / 4;
1795 got_dp_offset = got_section_offset + htab->params.dsbt_size;
1796 rela_offset = plt_index * sizeof (Elf32_External_Rela);
1798 got_section_offset *= 4;
1800 /* Fill in the entry in the procedure linkage table. */
1802 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1803 bfd_put_32 (output_bfd, got_dp_offset << 8 | 0x0100006e,
1804 plt->contents + h->plt.offset);
1805 /* mvk .s2 low(rela_offset), b0 */
1806 bfd_put_32 (output_bfd, (rela_offset & 0xffff) << 7 | 0x0000002a,
1807 plt->contents + h->plt.offset + 4);
1808 /* mvkh .s2 high(rela_offset), b0 */
1809 bfd_put_32 (output_bfd, ((rela_offset >> 16) & 0xffff) << 7 | 0x0000006a,
1810 plt->contents + h->plt.offset + 8);
1812 bfd_put_32 (output_bfd, 0x00002000,
1813 plt->contents + h->plt.offset + 12);
1815 bfd_put_32 (output_bfd, 0x00080362,
1816 plt->contents + h->plt.offset + 16);
1818 bfd_put_32 (output_bfd, 0x00008000,
1819 plt->contents + h->plt.offset + 20);
1821 /* Fill in the entry in the global offset table. */
1822 bfd_put_32 (output_bfd,
1823 (plt->output_section->vma + plt->output_offset),
1824 gotplt->contents + got_section_offset);
1826 /* Fill in the entry in the .rel.plt section. */
1827 rela.r_offset = (gotplt->output_section->vma
1828 + gotplt->output_offset
1829 + got_section_offset);
1830 rela.r_info = ELF32_R_INFO (h->dynindx, R_C6000_JUMP_SLOT);
1832 loc = relplt->contents + rela_offset;
1833 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1835 if (!h->def_regular)
1837 /* Mark the symbol as undefined, rather than as defined in
1838 the .plt section. */
1839 sym->st_shndx = SHN_UNDEF;
1844 if (h->got.offset != (bfd_vma) -1)
1849 /* This symbol has an entry in the global offset table.
1852 sgot = bfd_get_section_by_name (dynobj, ".got");
1853 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1854 BFD_ASSERT (sgot != NULL && srela != NULL);
1856 /* If this is a -Bsymbolic link, and the symbol is defined
1857 locally, we just want to emit a RELATIVE reloc. Likewise if
1858 the symbol was forced to be local because of a version file.
1859 The entry in the global offset table will already have been
1860 initialized in the relocate_section function. */
1863 || h->dynindx == -1 || h->forced_local) && h->def_regular)
1865 asection *s = h->root.u.def.section;
1866 elf32_tic6x_make_got_dynreloc (output_bfd, htab, s,
1867 h->got.offset & ~(bfd_vma) 1);
1871 Elf_Internal_Rela outrel;
1872 bfd_put_32 (output_bfd, (bfd_vma) 0,
1873 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
1874 outrel.r_offset = (sgot->output_section->vma
1875 + sgot->output_offset
1876 + (h->got.offset & ~(bfd_vma) 1));
1877 outrel.r_info = ELF32_R_INFO (h->dynindx, R_C6000_ABS32);
1878 outrel.r_addend = 0;
1880 elf32_tic6x_install_rela (output_bfd, srela, &outrel);
1886 Elf_Internal_Rela rel;
1888 /* This symbol needs a copy reloc. Set it up. */
1890 if (h->dynindx == -1
1891 || (h->root.type != bfd_link_hash_defined
1892 && h->root.type != bfd_link_hash_defweak)
1893 || htab->srelbss == NULL)
1896 rel.r_offset = (h->root.u.def.value
1897 + h->root.u.def.section->output_section->vma
1898 + h->root.u.def.section->output_offset);
1899 rel.r_info = ELF32_R_INFO (h->dynindx, R_C6000_COPY);
1902 elf32_tic6x_install_rela (output_bfd, htab->srelbss, &rel);
1905 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1906 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1907 || h == elf_hash_table (info)->hgot)
1908 sym->st_shndx = SHN_ABS;
1913 /* Unwinding tables are not referenced directly. This pass marks them as
1914 required if the corresponding code section is marked. */
1917 elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info *info,
1918 elf_gc_mark_hook_fn gc_mark_hook)
1921 Elf_Internal_Shdr **elf_shdrp;
1924 _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
1926 /* Marking EH data may cause additional code sections to be marked,
1927 requiring multiple passes. */
1932 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
1936 if (! is_tic6x_elf (sub))
1939 elf_shdrp = elf_elfsections (sub);
1940 for (o = sub->sections; o != NULL; o = o->next)
1942 Elf_Internal_Shdr *hdr;
1944 hdr = &elf_section_data (o)->this_hdr;
1945 if (hdr->sh_type == SHT_C6000_UNWIND
1947 && hdr->sh_link < elf_numsections (sub)
1949 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
1952 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
1962 /* Return TRUE if this is an unwinding table index. */
1965 is_tic6x_elf_unwind_section_name (const char *name)
1967 return (CONST_STRNEQ (name, ELF_STRING_C6000_unwind)
1968 || CONST_STRNEQ (name, ELF_STRING_C6000_unwind_once));
1972 /* Set the type and flags for an unwinding index table. We do this by
1973 the section name, which is a hack, but ought to work. */
1976 elf32_tic6x_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
1977 Elf_Internal_Shdr *hdr, asection *sec)
1981 name = bfd_get_section_name (abfd, sec);
1983 if (is_tic6x_elf_unwind_section_name (name))
1985 hdr->sh_type = SHT_C6000_UNWIND;
1986 hdr->sh_flags |= SHF_LINK_ORDER;
1992 /* Update the got entry reference counts for the section being removed. */
1995 elf32_tic6x_gc_sweep_hook (bfd *abfd,
1996 struct bfd_link_info *info,
1998 const Elf_Internal_Rela *relocs)
2000 struct elf32_tic6x_link_hash_table *htab;
2001 Elf_Internal_Shdr *symtab_hdr;
2002 struct elf_link_hash_entry **sym_hashes;
2003 bfd_signed_vma *local_got_refcounts;
2004 const Elf_Internal_Rela *rel, *relend;
2006 if (info->relocatable)
2009 htab = elf32_tic6x_hash_table (info);
2013 elf_section_data (sec)->local_dynrel = NULL;
2015 symtab_hdr = &elf_symtab_hdr (abfd);
2016 sym_hashes = elf_sym_hashes (abfd);
2017 local_got_refcounts = elf_local_got_refcounts (abfd);
2019 relend = relocs + sec->reloc_count;
2020 for (rel = relocs; rel < relend; rel++)
2022 unsigned long r_symndx;
2023 unsigned int r_type;
2024 struct elf_link_hash_entry *h = NULL;
2026 r_symndx = ELF32_R_SYM (rel->r_info);
2027 if (r_symndx >= symtab_hdr->sh_info)
2029 struct elf32_tic6x_link_hash_entry *eh;
2030 struct elf_dyn_relocs **pp;
2031 struct elf_dyn_relocs *p;
2033 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2034 while (h->root.type == bfd_link_hash_indirect
2035 || h->root.type == bfd_link_hash_warning)
2036 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2037 eh = (struct elf32_tic6x_link_hash_entry *) h;
2039 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
2042 /* Everything must go for SEC. */
2048 r_type = ELF32_R_TYPE (rel->r_info);
2052 case R_C6000_SBR_GOT_U15_W:
2053 case R_C6000_SBR_GOT_L16_W:
2054 case R_C6000_SBR_GOT_H16_W:
2055 case R_C6000_EHTYPE:
2058 if (h->got.refcount > 0)
2059 h->got.refcount -= 1;
2061 else if (local_got_refcounts != NULL)
2063 if (local_got_refcounts[r_symndx] > 0)
2064 local_got_refcounts[r_symndx] -= 1;
2076 /* Adjust a symbol defined by a dynamic object and referenced by a
2077 regular object. The current definition is in some section of the
2078 dynamic object, but we're not including those sections. We have to
2079 change the definition to something the rest of the link can
2083 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info *info,
2084 struct elf_link_hash_entry *h)
2086 struct elf32_tic6x_link_hash_table *htab;
2090 dynobj = elf_hash_table (info)->dynobj;
2092 /* Make sure we know what is going on here. */
2093 BFD_ASSERT (dynobj != NULL
2095 || h->u.weakdef != NULL
2096 || (h->def_dynamic && h->ref_regular && !h->def_regular)));
2098 /* If this is a function, put it in the procedure linkage table. We
2099 will fill in the contents of the procedure linkage table later,
2100 when we know the address of the .got section. */
2101 if (h->type == STT_FUNC
2104 if (h->plt.refcount <= 0
2105 || SYMBOL_CALLS_LOCAL (info, h)
2106 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2107 && h->root.type == bfd_link_hash_undefweak))
2109 /* This case can occur if we saw a PLT32 reloc in an input
2110 file, but the symbol was never referred to by a dynamic
2111 object, or if all references were garbage collected. In
2112 such a case, we don't actually need to build a procedure
2113 linkage table, and we can just do a PC32 reloc instead. */
2114 h->plt.offset = (bfd_vma) -1;
2121 /* If this is a weak symbol, and there is a real definition, the
2122 processor independent code will have arranged for us to see the
2123 real definition first, and we can just use the same value. */
2124 if (h->u.weakdef != NULL)
2126 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2127 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2128 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2129 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2130 h->non_got_ref = h->u.weakdef->non_got_ref;
2134 /* This is a reference to a symbol defined by a dynamic object which
2135 is not a function. */
2137 /* If we are creating a shared library, we must presume that the
2138 only references to the symbol are via the global offset table.
2139 For such cases we need not do anything here; the relocations will
2140 be handled correctly by relocate_section. */
2144 /* If there are no references to this symbol that do not use the
2145 GOT, we don't need to generate a copy reloc. */
2146 if (!h->non_got_ref)
2149 /* If -z nocopyreloc was given, we won't generate them either. */
2150 if (info->nocopyreloc)
2156 htab = elf32_tic6x_hash_table (info);
2160 /* We must allocate the symbol in our .dynbss section, which will
2161 become part of the .bss section of the executable. There will be
2162 an entry for this symbol in the .dynsym section. The dynamic
2163 object will contain position independent code, so all references
2164 from the dynamic object to this symbol will go through the global
2165 offset table. The dynamic linker will use the .dynsym entry to
2166 determine the address it must put in the global offset table, so
2167 both the dynamic object and the regular object will refer to the
2168 same memory location for the variable. */
2170 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2171 copy the initial value out of the dynamic object and into the
2172 runtime process image. */
2173 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2175 htab->srelbss->size += sizeof (Elf32_External_Rela);
2181 return _bfd_elf_adjust_dynamic_copy (h, s);
2185 elf32_tic6x_new_section_hook (bfd *abfd, asection *sec)
2189 /* Allocate target specific section data. */
2190 if (!sec->used_by_bfd)
2192 _tic6x_elf_section_data *sdata;
2193 bfd_size_type amt = sizeof (*sdata);
2195 sdata = (_tic6x_elf_section_data *) bfd_zalloc (abfd, amt);
2198 sec->used_by_bfd = sdata;
2201 ret = _bfd_elf_new_section_hook (abfd, sec);
2202 sec->use_rela_p = elf32_tic6x_tdata (abfd)->use_rela_p;
2207 /* Return true if relocation REL against section SEC is a REL rather
2208 than RELA relocation. RELOCS is the first relocation in the
2209 section and ABFD is the bfd that contains SEC. */
2212 elf32_tic6x_rel_relocation_p (bfd *abfd, asection *sec,
2213 const Elf_Internal_Rela *relocs,
2214 const Elf_Internal_Rela *rel)
2216 Elf_Internal_Shdr *rel_hdr;
2217 const struct elf_backend_data *bed;
2219 /* To determine which flavor of relocation this is, we depend on the
2220 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2221 rel_hdr = elf_section_data (sec)->rel.hdr;
2222 if (rel_hdr == NULL)
2224 bed = get_elf_backend_data (abfd);
2225 return ((size_t) (rel - relocs)
2226 < NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel);
2229 /* We need dynamic symbols for every section, since segments can
2230 relocate independently. */
2232 elf32_tic6x_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
2233 struct bfd_link_info *info ATTRIBUTE_UNUSED,
2236 switch (elf_section_data (p)->this_hdr.sh_type)
2240 /* If sh_type is yet undecided, assume it could be
2241 SHT_PROGBITS/SHT_NOBITS. */
2245 /* There shouldn't be section relative relocations
2246 against any other section. */
2253 elf32_tic6x_relocate_section (bfd *output_bfd,
2254 struct bfd_link_info *info,
2256 asection *input_section,
2258 Elf_Internal_Rela *relocs,
2259 Elf_Internal_Sym *local_syms,
2260 asection **local_sections)
2262 struct elf32_tic6x_link_hash_table *htab;
2263 Elf_Internal_Shdr *symtab_hdr;
2264 struct elf_link_hash_entry **sym_hashes;
2265 bfd_vma *local_got_offsets;
2266 Elf_Internal_Rela *rel;
2267 Elf_Internal_Rela *relend;
2268 bfd_boolean ok = TRUE;
2270 htab = elf32_tic6x_hash_table (info);
2271 symtab_hdr = & elf_symtab_hdr (input_bfd);
2272 sym_hashes = elf_sym_hashes (input_bfd);
2273 local_got_offsets = elf_local_got_offsets (input_bfd);
2275 relend = relocs + input_section->reloc_count;
2277 for (rel = relocs; rel < relend; rel ++)
2280 unsigned long r_symndx;
2282 reloc_howto_type *howto;
2283 Elf_Internal_Sym *sym;
2285 struct elf_link_hash_entry *h;
2286 bfd_vma off, off2, relocation;
2287 bfd_boolean unresolved_reloc;
2288 bfd_reloc_status_type r;
2289 struct bfd_link_hash_entry *sbh;
2292 r_type = ELF32_R_TYPE (rel->r_info);
2293 r_symndx = ELF32_R_SYM (rel->r_info);
2295 is_rel = elf32_tic6x_rel_relocation_p (input_bfd, input_section,
2299 elf32_tic6x_info_to_howto_rel (input_bfd, &bfd_reloc, rel);
2301 elf32_tic6x_info_to_howto (input_bfd, &bfd_reloc, rel);
2302 howto = bfd_reloc.howto;
2305 bfd_set_error (bfd_error_bad_value);
2312 unresolved_reloc = FALSE;
2314 if (r_symndx < symtab_hdr->sh_info)
2316 sym = local_syms + r_symndx;
2317 sec = local_sections[r_symndx];
2318 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2324 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2325 r_symndx, symtab_hdr, sym_hashes,
2327 unresolved_reloc, warned);
2330 if (sec != NULL && elf_discarded_section (sec))
2331 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2332 rel, relend, howto, contents);
2334 if (info->relocatable)
2338 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2341 relocation = sec->output_offset + sym->st_value;
2342 r = _bfd_relocate_contents (howto, input_bfd, relocation,
2343 contents + rel->r_offset);
2353 case R_C6000_FPHEAD:
2355 /* No action needed. */
2358 case R_C6000_PCR_S21:
2359 /* A branch to an undefined weak symbol is turned into a
2360 "b .s2 B3" instruction if the existing insn is of the
2361 form "b .s2 symbol". */
2362 if (h ? h->root.type == bfd_link_hash_undefweak
2363 && (htab->elf.splt == NULL || h->plt.offset == (bfd_vma) -1)
2364 : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
2366 unsigned long oldval;
2367 oldval = bfd_get_32 (input_bfd, contents + rel->r_offset);
2369 if ((oldval & 0x7e) == 0x12)
2371 oldval &= 0xF0000001;
2372 bfd_put_32 (input_bfd, oldval | 0x000c0362,
2373 contents + rel->r_offset);
2379 case R_C6000_PCR_S12:
2380 case R_C6000_PCR_S10:
2381 case R_C6000_PCR_S7:
2383 && h->plt.offset != (bfd_vma) -1
2384 && htab->elf.splt != NULL)
2386 relocation = (htab->elf.splt->output_section->vma
2387 + htab->elf.splt->output_offset
2391 /* Generic PC-relative handling produces a value relative to
2392 the exact location of the relocation. Adjust it to be
2393 relative to the start of the fetch packet instead. */
2394 relocation += (input_section->output_section->vma
2395 + input_section->output_offset
2396 + rel->r_offset) & 0x1f;
2397 unresolved_reloc = FALSE;
2400 case R_C6000_PCR_H16:
2401 case R_C6000_PCR_L16:
2402 off = (input_section->output_section->vma
2403 + input_section->output_offset
2405 /* These must be calculated as R = S - FP(FP(PC) - A).
2406 PC, here, is the value we just computed in OFF. RELOCATION
2407 has the address of S + A. */
2408 relocation -= rel->r_addend;
2409 off2 = ((off & ~(bfd_vma)0x1f) - rel->r_addend) & (bfd_vma)~0x1f;
2410 off2 = relocation - off2;
2411 relocation = off + off2;
2414 case R_C6000_DSBT_INDEX:
2415 relocation = elf32_tic6x_hash_table (info)->params.dsbt_index;
2416 if (!info->shared || relocation != 0)
2423 case R_C6000_ABS_S16:
2424 case R_C6000_ABS_L16:
2425 case R_C6000_ABS_H16:
2426 /* When generating a shared object or relocatable executable, these
2427 relocations are copied into the output file to be resolved at
2429 if ((info->shared || elf32_tic6x_using_dsbt (output_bfd))
2430 && (input_section->flags & SEC_ALLOC)
2432 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2433 || h->root.type != bfd_link_hash_undefweak))
2435 Elf_Internal_Rela outrel;
2436 bfd_boolean skip, relocate;
2439 unresolved_reloc = FALSE;
2441 sreloc = elf_section_data (input_section)->sreloc;
2442 BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
2448 _bfd_elf_section_offset (output_bfd, info, input_section,
2450 if (outrel.r_offset == (bfd_vma) -1)
2452 else if (outrel.r_offset == (bfd_vma) -2)
2453 skip = TRUE, relocate = TRUE;
2454 outrel.r_offset += (input_section->output_section->vma
2455 + input_section->output_offset);
2458 memset (&outrel, 0, sizeof outrel);
2463 || !h->def_regular))
2465 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2466 outrel.r_addend = rel->r_addend;
2472 outrel.r_addend = relocation + rel->r_addend;
2474 if (bfd_is_abs_section (sec))
2476 else if (sec == NULL || sec->owner == NULL)
2478 bfd_set_error (bfd_error_bad_value);
2485 osec = sec->output_section;
2486 indx = elf_section_data (osec)->dynindx;
2487 outrel.r_addend -= osec->vma;
2488 BFD_ASSERT (indx != 0);
2491 outrel.r_info = ELF32_R_INFO (indx, r_type);
2494 elf32_tic6x_install_rela (output_bfd, sreloc, &outrel);
2496 /* If this reloc is against an external symbol, we do not want to
2497 fiddle with the addend. Otherwise, we need to include the symbol
2498 value so that it becomes an addend for the dynamic reloc. */
2503 /* Generic logic OK. */
2506 case R_C6000_SBR_U15_B:
2507 case R_C6000_SBR_U15_H:
2508 case R_C6000_SBR_U15_W:
2509 case R_C6000_SBR_S16:
2510 case R_C6000_SBR_L16_B:
2511 case R_C6000_SBR_L16_H:
2512 case R_C6000_SBR_L16_W:
2513 case R_C6000_SBR_H16_B:
2514 case R_C6000_SBR_H16_H:
2515 case R_C6000_SBR_H16_W:
2516 sbh = bfd_link_hash_lookup (info->hash, "__c6xabi_DSBT_BASE",
2517 FALSE, FALSE, TRUE);
2519 && (sbh->type == bfd_link_hash_defined
2520 || sbh->type == bfd_link_hash_defweak))
2522 if (h ? (h->root.type == bfd_link_hash_undefweak
2523 && (htab->elf.splt == NULL
2524 || h->plt.offset == (bfd_vma) -1))
2525 : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
2528 relocation -= (sbh->u.def.value
2529 + sbh->u.def.section->output_section->vma
2530 + sbh->u.def.section->output_offset);
2534 (*_bfd_error_handler) (_("%B: SB-relative relocation but "
2535 "__c6xabi_DSBT_BASE not defined"),
2542 case R_C6000_SBR_GOT_U15_W:
2543 case R_C6000_SBR_GOT_L16_W:
2544 case R_C6000_SBR_GOT_H16_W:
2545 case R_C6000_EHTYPE:
2546 /* Relocation is to the entry for this symbol in the global
2548 if (htab->elf.sgot == NULL)
2555 off = h->got.offset;
2556 dyn = htab->elf.dynamic_sections_created;
2557 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2559 && SYMBOL_REFERENCES_LOCAL (info, h))
2560 || (ELF_ST_VISIBILITY (h->other)
2561 && h->root.type == bfd_link_hash_undefweak))
2563 /* This is actually a static link, or it is a
2564 -Bsymbolic link and the symbol is defined
2565 locally, or the symbol was forced to be local
2566 because of a version file. We must initialize
2567 this entry in the global offset table. Since the
2568 offset must always be a multiple of 4, we use the
2569 least significant bit to record whether we have
2570 initialized it already.
2572 When doing a dynamic link, we create a .rel.got
2573 relocation entry to initialize the value. This
2574 is done in the finish_dynamic_symbol routine. */
2579 bfd_put_32 (output_bfd, relocation,
2580 htab->elf.sgot->contents + off);
2583 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
2585 && !(ELF_ST_VISIBILITY (h->other)
2586 && h->root.type == bfd_link_hash_undefweak))
2587 elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec,
2592 unresolved_reloc = FALSE;
2596 if (local_got_offsets == NULL)
2599 off = local_got_offsets[r_symndx];
2601 /* The offset must always be a multiple of 4. We use
2602 the least significant bit to record whether we have
2603 already generated the necessary reloc. */
2608 bfd_put_32 (output_bfd, relocation,
2609 htab->elf.sgot->contents + off);
2611 if (info->shared || elf32_tic6x_using_dsbt (output_bfd))
2612 elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec, off);
2614 local_got_offsets[r_symndx] |= 1;
2618 if (off >= (bfd_vma) -2)
2622 relocation = (htab->elf.sgot->output_section->vma
2623 + htab->elf.sgot->output_offset + off
2624 - htab->dsbt->output_section->vma
2625 - htab->dsbt->output_offset);
2627 relocation = (htab->elf.sgot->output_section->vma
2628 + htab->elf.sgot->output_offset + off
2629 - htab->elf.sgotplt->output_section->vma
2630 - htab->elf.sgotplt->output_offset);
2632 if (rel->r_addend != 0)
2634 /* We can't do anything for a relocation which is against
2635 a symbol *plus offset*. GOT holds relocations for
2636 symbols. Make this an error; the compiler isn't
2637 allowed to pass us these kinds of things. */
2639 (*_bfd_error_handler)
2640 (_("%B, section %A: relocation %s with non-zero addend %d"
2641 " against local symbol"),
2644 elf32_tic6x_howto_table[r_type].name,
2647 (*_bfd_error_handler)
2648 (_("%B, section %A: relocation %s with non-zero addend %d"
2649 " against symbol `%s'"),
2652 elf32_tic6x_howto_table[r_type].name,
2654 h->root.root.string[0] != '\0' ? h->root.root.string
2655 : _("[whose name is lost]"));
2657 bfd_set_error (bfd_error_bad_value);
2662 case R_C6000_PREL31:
2664 && h->plt.offset != (bfd_vma) -1
2665 && htab->elf.splt != NULL)
2667 relocation = (htab->elf.splt->output_section->vma
2668 + htab->elf.splt->output_offset
2674 /* Invalid in relocatable object. */
2676 /* Unknown relocation. */
2677 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
2683 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2684 contents, rel->r_offset,
2685 relocation, rel->r_addend);
2688 if (r == bfd_reloc_ok
2689 && howto->complain_on_overflow == complain_overflow_bitfield)
2691 /* Generic overflow handling accepts cases the ABI says
2692 should be rejected for R_C6000_ABS16 and
2694 bfd_vma value = (relocation + rel->r_addend) & 0xffffffff;
2695 bfd_vma sbit = 1 << (howto->bitsize - 1);
2696 bfd_vma sbits = (-(bfd_vma) sbit) & 0xffffffff;
2697 bfd_vma value_sbits = value & sbits;
2699 if (value_sbits != 0
2700 && value_sbits != sbit
2701 && value_sbits != sbits)
2702 r = bfd_reloc_overflow;
2705 if (r != bfd_reloc_ok)
2708 const char *error_message;
2711 name = h->root.root.string;
2714 name = bfd_elf_string_from_elf_section (input_bfd,
2715 symtab_hdr->sh_link,
2720 name = bfd_section_name (input_bfd, sec);
2725 case bfd_reloc_overflow:
2726 /* If the overflowing reloc was to an undefined symbol,
2727 we have already printed one error message and there
2728 is no point complaining again. */
2730 h->root.type != bfd_link_hash_undefined)
2731 && (!((*info->callbacks->reloc_overflow)
2732 (info, (h ? &h->root : NULL), name, howto->name,
2733 (bfd_vma) 0, input_bfd, input_section,
2738 case bfd_reloc_undefined:
2739 if (!((*info->callbacks->undefined_symbol)
2740 (info, name, input_bfd, input_section,
2741 rel->r_offset, TRUE)))
2745 case bfd_reloc_outofrange:
2746 error_message = _("out of range");
2749 case bfd_reloc_notsupported:
2750 error_message = _("unsupported relocation");
2753 case bfd_reloc_dangerous:
2754 error_message = _("dangerous relocation");
2758 error_message = _("unknown error");
2762 BFD_ASSERT (error_message != NULL);
2763 if (!((*info->callbacks->reloc_dangerous)
2764 (info, error_message, input_bfd, input_section,
2776 /* Look through the relocs for a section during the first phase, and
2777 calculate needed space in the global offset table, procedure linkage
2778 table, and dynamic reloc sections. */
2781 elf32_tic6x_check_relocs (bfd *abfd, struct bfd_link_info *info,
2782 asection *sec, const Elf_Internal_Rela *relocs)
2784 struct elf32_tic6x_link_hash_table *htab;
2785 Elf_Internal_Shdr *symtab_hdr;
2786 struct elf_link_hash_entry **sym_hashes;
2787 const Elf_Internal_Rela *rel;
2788 const Elf_Internal_Rela *rel_end;
2791 if (info->relocatable)
2794 htab = elf32_tic6x_hash_table (info);
2795 symtab_hdr = &elf_symtab_hdr (abfd);
2796 sym_hashes = elf_sym_hashes (abfd);
2798 /* Create dynamic sections for relocatable executables so that we can
2799 copy relocations. */
2800 if ((info->shared || elf32_tic6x_using_dsbt (abfd))
2801 && ! htab->elf.dynamic_sections_created)
2803 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
2809 rel_end = relocs + sec->reloc_count;
2810 for (rel = relocs; rel < rel_end; rel++)
2812 unsigned int r_type;
2813 unsigned long r_symndx;
2814 struct elf_link_hash_entry *h;
2815 Elf_Internal_Sym *isym;
2817 r_symndx = ELF32_R_SYM (rel->r_info);
2818 r_type = ELF32_R_TYPE (rel->r_info);
2820 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
2822 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
2828 if (r_symndx < symtab_hdr->sh_info)
2830 /* A local symbol. */
2831 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2840 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2841 while (h->root.type == bfd_link_hash_indirect
2842 || h->root.type == bfd_link_hash_warning)
2843 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2848 case R_C6000_PCR_S21:
2849 case R_C6000_PREL31:
2850 /* This symbol requires a procedure linkage table entry. We
2851 actually build the entry in adjust_dynamic_symbol,
2852 because this might be a case of linking PIC code which is
2853 never referenced by a dynamic object, in which case we
2854 don't need to generate a procedure linkage table entry
2857 /* If this is a local symbol, we resolve it directly without
2858 creating a procedure linkage table entry. */
2863 h->plt.refcount += 1;
2866 case R_C6000_SBR_GOT_U15_W:
2867 case R_C6000_SBR_GOT_L16_W:
2868 case R_C6000_SBR_GOT_H16_W:
2869 case R_C6000_EHTYPE:
2870 /* This symbol requires a global offset table entry. */
2873 h->got.refcount += 1;
2877 bfd_signed_vma *local_got_refcounts;
2879 /* This is a global offset table entry for a local symbol. */
2880 local_got_refcounts = elf_local_got_refcounts (abfd);
2881 if (local_got_refcounts == NULL)
2885 size = symtab_hdr->sh_info;
2886 size *= (sizeof (bfd_signed_vma)
2887 + sizeof (bfd_vma) + sizeof(char));
2888 local_got_refcounts = bfd_zalloc (abfd, size);
2889 if (local_got_refcounts == NULL)
2891 elf_local_got_refcounts (abfd) = local_got_refcounts;
2893 local_got_refcounts[r_symndx] += 1;
2896 if (htab->elf.sgot == NULL)
2898 if (htab->elf.dynobj == NULL)
2899 htab->elf.dynobj = abfd;
2900 if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
2905 case R_C6000_DSBT_INDEX:
2906 /* We'd like to check for nonzero dsbt_index here, but it's
2907 set up only after check_relocs is called. Instead, we
2908 store the number of R_C6000_DSBT_INDEX relocs in the
2909 pc_count field, and potentially discard the extra space
2910 in elf32_tic6x_allocate_dynrelocs. */
2918 case R_C6000_ABS_S16:
2919 case R_C6000_ABS_L16:
2920 case R_C6000_ABS_H16:
2921 /* If we are creating a shared library, and this is a reloc
2922 against a global symbol, or a non PC relative reloc
2923 against a local symbol, then we need to copy the reloc
2924 into the shared library. However, if we are linking with
2925 -Bsymbolic, we do not need to copy a reloc against a
2926 global symbol which is defined in an object we are
2927 including in the link (i.e., DEF_REGULAR is set). At
2928 this point we have not seen all the input files, so it is
2929 possible that DEF_REGULAR is not set now but will be set
2930 later (it is never cleared). In case of a weak definition,
2931 DEF_REGULAR may be cleared later by a strong definition in
2932 a shared library. We account for that possibility below by
2933 storing information in the relocs_copied field of the hash
2934 table entry. A similar situation occurs when creating
2935 shared libraries and symbol visibility changes render the
2938 If on the other hand, we are creating an executable, we
2939 may need to keep relocations for symbols satisfied by a
2940 dynamic library if we manage to avoid copy relocs for the
2942 if ((info->shared || elf32_tic6x_using_dsbt (abfd))
2943 && (sec->flags & SEC_ALLOC) != 0)
2945 struct elf_dyn_relocs *p;
2946 struct elf_dyn_relocs **head;
2948 /* We must copy these reloc types into the output file.
2949 Create a reloc section in dynobj and make room for
2953 if (htab->elf.dynobj == NULL)
2954 htab->elf.dynobj = abfd;
2956 sreloc = _bfd_elf_make_dynamic_reloc_section
2957 (sec, htab->elf.dynobj, 2, abfd, /*rela? */ TRUE);
2963 /* If this is a global symbol, we count the number of
2964 relocations we need for this symbol. */
2967 head = &((struct elf32_tic6x_link_hash_entry *) h)->dyn_relocs;
2971 /* Track dynamic relocs needed for local syms too.
2972 We really need local syms available to do this
2977 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2981 vpp = &elf_section_data (s)->local_dynrel;
2982 head = (struct elf_dyn_relocs **)vpp;
2986 if (p == NULL || p->sec != sec)
2988 bfd_size_type amt = sizeof *p;
2989 p = bfd_alloc (htab->elf.dynobj, amt);
3000 if (r_type == R_C6000_DSBT_INDEX)
3005 case R_C6000_SBR_U15_B:
3006 case R_C6000_SBR_U15_H:
3007 case R_C6000_SBR_U15_W:
3008 case R_C6000_SBR_S16:
3009 case R_C6000_SBR_L16_B:
3010 case R_C6000_SBR_L16_H:
3011 case R_C6000_SBR_L16_W:
3012 case R_C6000_SBR_H16_B:
3013 case R_C6000_SBR_H16_H:
3014 case R_C6000_SBR_H16_W:
3015 if (h != NULL && info->executable)
3017 /* For B14-relative addresses, we might need a copy
3032 elf32_tic6x_add_symbol_hook (bfd *abfd,
3033 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3034 Elf_Internal_Sym *sym,
3035 const char **namep ATTRIBUTE_UNUSED,
3036 flagword *flagsp ATTRIBUTE_UNUSED,
3040 switch (sym->st_shndx)
3042 case SHN_TIC6X_SCOMMON:
3043 *secp = bfd_make_section_old_way (abfd, ".scommon");
3044 (*secp)->flags |= SEC_IS_COMMON;
3045 *valp = sym->st_size;
3046 bfd_set_section_alignment (abfd, *secp, bfd_log2 (sym->st_value));
3054 elf32_tic6x_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
3056 elf_symbol_type *elfsym;
3058 elfsym = (elf_symbol_type *) asym;
3059 switch (elfsym->internal_elf_sym.st_shndx)
3061 case SHN_TIC6X_SCOMMON:
3062 if (tic6x_elf_scom_section.name == NULL)
3064 /* Initialize the small common section. */
3065 tic6x_elf_scom_section.name = ".scommon";
3066 tic6x_elf_scom_section.flags = SEC_IS_COMMON;
3067 tic6x_elf_scom_section.output_section = &tic6x_elf_scom_section;
3068 tic6x_elf_scom_section.symbol = &tic6x_elf_scom_symbol;
3069 tic6x_elf_scom_section.symbol_ptr_ptr = &tic6x_elf_scom_symbol_ptr;
3070 tic6x_elf_scom_symbol.name = ".scommon";
3071 tic6x_elf_scom_symbol.flags = BSF_SECTION_SYM;
3072 tic6x_elf_scom_symbol.section = &tic6x_elf_scom_section;
3073 tic6x_elf_scom_symbol_ptr = &tic6x_elf_scom_symbol;
3075 asym->section = &tic6x_elf_scom_section;
3076 asym->value = elfsym->internal_elf_sym.st_size;
3082 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3083 const char *name ATTRIBUTE_UNUSED,
3084 Elf_Internal_Sym *sym,
3085 asection *input_sec,
3086 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3088 /* If we see a common symbol, which implies a relocatable link, then
3089 if a symbol was small common in an input file, mark it as small
3090 common in the output file. */
3091 if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
3092 sym->st_shndx = SHN_TIC6X_SCOMMON;
3098 elf32_tic6x_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
3102 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
3104 *retval = SHN_TIC6X_SCOMMON;
3111 /* Allocate space in .plt, .got and associated reloc sections for
3115 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3117 struct bfd_link_info *info;
3118 struct elf32_tic6x_link_hash_table *htab;
3119 struct elf32_tic6x_link_hash_entry *eh;
3120 struct elf_dyn_relocs *p;
3122 if (h->root.type == bfd_link_hash_indirect)
3125 eh = (struct elf32_tic6x_link_hash_entry *) h;
3126 info = (struct bfd_link_info *) inf;
3127 htab = elf32_tic6x_hash_table (info);
3129 if (htab->elf.dynamic_sections_created && h->plt.refcount > 0)
3131 /* Make sure this symbol is output as a dynamic symbol.
3132 Undefined weak syms won't yet be marked as dynamic. */
3133 if (h->dynindx == -1 && !h->forced_local)
3135 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3140 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3142 asection *s = htab->elf.splt;
3144 /* If this is the first .plt entry, make room for the special
3147 s->size += PLT_ENTRY_SIZE;
3149 h->plt.offset = s->size;
3151 /* If this symbol is not defined in a regular file, and we are
3152 not generating a shared library, then set the symbol to this
3153 location in the .plt. This is required to make function
3154 pointers compare as equal between the normal executable and
3155 the shared library. */
3156 if (! info->shared && !h->def_regular)
3158 h->root.u.def.section = s;
3159 h->root.u.def.value = h->plt.offset;
3162 /* Make room for this entry. */
3163 s->size += PLT_ENTRY_SIZE;
3164 /* We also need to make an entry in the .got.plt section, which
3165 will be placed in the .got section by the linker script. */
3166 htab->elf.sgotplt->size += 4;
3167 /* We also need to make an entry in the .rel.plt section. */
3168 htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
3172 h->plt.offset = (bfd_vma) -1;
3178 h->plt.offset = (bfd_vma) -1;
3182 if (h->got.refcount > 0)
3186 /* Make sure this symbol is output as a dynamic symbol.
3187 Undefined weak syms won't yet be marked as dynamic. */
3188 if (h->dynindx == -1
3189 && !h->forced_local)
3191 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3196 h->got.offset = s->size;
3199 if (!(ELF_ST_VISIBILITY (h->other)
3200 && h->root.type == bfd_link_hash_undefweak))
3201 htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
3204 h->got.offset = (bfd_vma) -1;
3206 if (eh->dyn_relocs == NULL)
3209 /* Discard relocs on undefined weak syms with non-default
3211 if (info->shared || elf32_tic6x_using_dsbt (htab->obfd))
3213 /* We use the pc_count field to hold the number of
3214 R_C6000_DSBT_INDEX relocs. */
3215 if (htab->params.dsbt_index != 0)
3217 struct elf_dyn_relocs **pp;
3219 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3221 p->count -= p->pc_count;
3230 if (eh->dyn_relocs != NULL
3231 && h->root.type == bfd_link_hash_undefweak)
3233 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
3234 eh->dyn_relocs = NULL;
3236 /* Make sure undefined weak symbols are output as a dynamic
3238 else if (h->dynindx == -1
3239 && !h->forced_local)
3241 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3247 /* Finally, allocate space. */
3248 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3252 sreloc = elf_section_data (p->sec)->sreloc;
3254 BFD_ASSERT (sreloc != NULL);
3255 sreloc->size += p->count * sizeof (Elf32_External_Rela);
3261 /* Find any dynamic relocs that apply to read-only sections. */
3264 elf32_tic6x_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3266 struct elf32_tic6x_link_hash_entry *eh;
3267 struct elf_dyn_relocs *p;
3269 eh = (struct elf32_tic6x_link_hash_entry *) h;
3270 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3272 asection *s = p->sec->output_section;
3274 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3276 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3278 info->flags |= DF_TEXTREL;
3280 /* Not an error, just cut short the traversal. */
3287 /* Set the sizes of the dynamic sections. */
3290 elf32_tic6x_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
3292 struct elf32_tic6x_link_hash_table *htab;
3298 htab = elf32_tic6x_hash_table (info);
3299 dynobj = htab->elf.dynobj;
3303 if (htab->elf.dynamic_sections_created)
3305 /* Set the contents of the .interp section to the interpreter. */
3306 if (info->executable)
3308 s = bfd_get_section_by_name (dynobj, ".interp");
3311 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3312 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3316 /* Set up .got offsets for local syms, and space for local dynamic
3318 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3320 bfd_signed_vma *local_got;
3321 bfd_signed_vma *end_local_got;
3322 char *local_tls_type;
3323 bfd_vma *local_tlsdesc_gotent;
3324 bfd_size_type locsymcount;
3325 Elf_Internal_Shdr *symtab_hdr;
3328 for (s = ibfd->sections; s != NULL; s = s->next)
3330 struct elf_dyn_relocs *p;
3332 for (p = ((struct elf_dyn_relocs *)
3333 elf_section_data (s)->local_dynrel);
3337 if (!bfd_is_abs_section (p->sec)
3338 && bfd_is_abs_section (p->sec->output_section))
3340 /* Input section has been discarded, either because
3341 it is a copy of a linkonce section or due to
3342 linker script /DISCARD/, so we'll be discarding
3345 else if (p->count != 0)
3347 srel = elf_section_data (p->sec)->sreloc;
3348 srel->size += p->count * sizeof (Elf32_External_Rela);
3349 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3350 info->flags |= DF_TEXTREL;
3355 local_got = elf_local_got_refcounts (ibfd);
3359 symtab_hdr = &elf_symtab_hdr (ibfd);
3360 locsymcount = symtab_hdr->sh_info;
3361 end_local_got = local_got + locsymcount;
3363 srel = htab->elf.srelgot;
3364 for (; local_got < end_local_got;
3365 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
3369 *local_got = s->size;
3372 if (info->shared || elf32_tic6x_using_dsbt (output_bfd))
3374 srel->size += sizeof (Elf32_External_Rela);
3378 *local_got = (bfd_vma) -1;
3382 /* Allocate global sym .plt and .got entries, and space for global
3383 sym dynamic relocs. */
3384 elf_link_hash_traverse (&htab->elf, elf32_tic6x_allocate_dynrelocs, info);
3386 /* We now have determined the sizes of the various dynamic sections.
3387 Allocate memory for them. */
3389 for (s = dynobj->sections; s != NULL; s = s->next)
3391 bfd_boolean strip_section = TRUE;
3393 if ((s->flags & SEC_LINKER_CREATED) == 0)
3396 if (s == htab->dsbt)
3397 s->size = 4 * htab->params.dsbt_size;
3398 else if (s == htab->elf.splt
3399 || s == htab->elf.sgot
3400 || s == htab->elf.sgotplt
3401 || s == htab->sdynbss)
3403 /* Strip this section if we don't need it; see the
3405 /* We'd like to strip these sections if they aren't needed, but if
3406 we've exported dynamic symbols from them we must leave them.
3407 It's too late to tell BFD to get rid of the symbols. */
3409 if (htab->elf.hplt != NULL)
3410 strip_section = FALSE;
3412 /* Round up the size of the PLT section to a multiple of 32. */
3413 if (s == htab->elf.splt && s->size > 0)
3414 s->size = (s->size + 31) & ~(bfd_vma)31;
3416 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
3419 && s != htab->elf.srelplt)
3422 /* We use the reloc_count field as a counter if we need
3423 to copy relocs into the output file. */
3428 /* It's not one of our sections, so don't allocate space. */
3434 /* If we don't need this section, strip it from the
3435 output file. This is mostly to handle .rel.bss and
3436 .rel.plt. We must create both sections in
3437 create_dynamic_sections, because they must be created
3438 before the linker maps input sections to output
3439 sections. The linker does that before
3440 adjust_dynamic_symbol is called, and it is that
3441 function which decides whether anything needs to go
3442 into these sections. */
3444 s->flags |= SEC_EXCLUDE;
3448 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3451 /* Allocate memory for the section contents. We use bfd_zalloc
3452 here in case unused entries are not reclaimed before the
3453 section's contents are written out. This should not happen,
3454 but this way if it does, we get a R_C6000_NONE reloc instead
3456 s->contents = bfd_zalloc (dynobj, s->size);
3457 if (s->contents == NULL)
3461 if (htab->elf.dynamic_sections_created)
3463 /* Add some entries to the .dynamic section. We fill in the
3464 values later, in elf32_tic6x_finish_dynamic_sections, but we
3465 must add the entries now so that we get the correct size for
3466 the .dynamic section. The DT_DEBUG entry is filled in by the
3467 dynamic linker and used by the debugger. */
3468 #define add_dynamic_entry(TAG, VAL) \
3469 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3471 if (info->executable)
3473 if (!add_dynamic_entry (DT_DEBUG, 0))
3477 if (!add_dynamic_entry (DT_C6000_DSBT_BASE, 0)
3478 || !add_dynamic_entry (DT_C6000_DSBT_SIZE, htab->params.dsbt_size)
3479 || !add_dynamic_entry (DT_C6000_DSBT_INDEX,
3480 htab->params.dsbt_index))
3483 if (htab->elf.splt->size != 0)
3485 if (!add_dynamic_entry (DT_PLTGOT, 0)
3486 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3487 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3488 || !add_dynamic_entry (DT_JMPREL, 0))
3494 if (!add_dynamic_entry (DT_RELA, 0)
3495 || !add_dynamic_entry (DT_RELASZ, 0)
3496 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3499 /* If any dynamic relocs apply to a read-only section,
3500 then we need a DT_TEXTREL entry. */
3501 if ((info->flags & DF_TEXTREL) == 0)
3502 elf_link_hash_traverse (&htab->elf,
3503 elf32_tic6x_readonly_dynrelocs, info);
3505 if ((info->flags & DF_TEXTREL) != 0)
3507 if (!add_dynamic_entry (DT_TEXTREL, 0))
3512 #undef add_dynamic_entry
3517 /* This function is called after all the input files have been read,
3518 and the input sections have been assigned to output sections. */
3521 elf32_tic6x_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3523 if (elf32_tic6x_using_dsbt (output_bfd) && !info->relocatable)
3525 struct elf_link_hash_entry *h;
3527 /* Force a PT_GNU_STACK segment to be created. */
3528 if (! elf_tdata (output_bfd)->stack_flags)
3529 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
3531 /* Define __stacksize if it's not defined yet. */
3532 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3533 FALSE, FALSE, FALSE);
3534 if (! h || h->root.type != bfd_link_hash_defined
3535 || h->type != STT_OBJECT
3538 struct bfd_link_hash_entry *bh = NULL;
3540 if (!(_bfd_generic_link_add_one_symbol
3541 (info, output_bfd, "__stacksize",
3542 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
3543 (const char *) NULL, FALSE,
3544 get_elf_backend_data (output_bfd)->collect, &bh)))
3547 h = (struct elf_link_hash_entry *) bh;
3549 h->type = STT_OBJECT;
3556 elf32_tic6x_modify_program_headers (bfd *output_bfd,
3557 struct bfd_link_info *info)
3559 struct elf_obj_tdata *tdata = elf_tdata (output_bfd);
3560 struct elf_segment_map *m;
3561 Elf_Internal_Phdr *p;
3563 /* objcopy and strip preserve what's already there using
3564 elf32_tic6x_copy_private_bfd_data (). */
3568 for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++)
3569 if (m->p_type == PT_GNU_STACK)
3574 struct elf_link_hash_entry *h;
3576 /* Obtain the pointer to the __stacksize symbol. */
3577 h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
3578 FALSE, FALSE, FALSE);
3581 while (h->root.type == bfd_link_hash_indirect
3582 || h->root.type == bfd_link_hash_warning)
3583 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3584 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
3587 /* Set the header p_memsz from the symbol value. We
3588 intentionally ignore the symbol section. */
3589 if (h && h->root.type == bfd_link_hash_defined)
3590 p->p_memsz = h->root.u.def.value;
3592 p->p_memsz = DEFAULT_STACK_SIZE;
3601 elf32_tic6x_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3602 struct bfd_link_info *info)
3604 struct elf32_tic6x_link_hash_table *htab;
3608 htab = elf32_tic6x_hash_table (info);
3609 dynobj = htab->elf.dynobj;
3610 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3612 if (elf_hash_table (info)->dynamic_sections_created)
3614 Elf32_External_Dyn * dyncon;
3615 Elf32_External_Dyn * dynconend;
3617 BFD_ASSERT (sdyn != NULL);
3619 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3620 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3622 for (; dyncon < dynconend; dyncon++)
3624 Elf_Internal_Dyn dyn;
3627 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3634 case DT_C6000_DSBT_BASE:
3636 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset);
3640 s = htab->elf.sgotplt;
3641 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3645 s = htab->elf.srelplt;
3646 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3650 s = htab->elf.srelplt;
3651 dyn.d_un.d_val = s->size;
3654 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3657 /* Fill in the first entry in the procedure linkage table. */
3658 if (htab->elf.splt && htab->elf.splt->size > 0)
3660 bfd_vma got_offs = (htab->elf.sgotplt->output_section->vma
3661 + htab->elf.sgotplt->output_offset
3662 - htab->dsbt->output_section->vma
3663 - htab->dsbt->output_offset) / 4;
3665 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3666 bfd_put_32 (output_bfd, got_offs << 8 | 0x0100006e,
3667 htab->elf.splt->contents);
3668 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3669 bfd_put_32 (output_bfd, (got_offs + 1) << 8 | 0x0080006e,
3670 htab->elf.splt->contents + 4);
3672 bfd_put_32 (output_bfd, 0x00004000,
3673 htab->elf.splt->contents + 8);
3675 bfd_put_32 (output_bfd, 0x00080362,
3676 htab->elf.splt->contents + 12);
3678 bfd_put_32 (output_bfd, 0x00008000,
3679 htab->elf.splt->contents + 16);
3681 elf_section_data (htab->elf.splt->output_section)
3682 ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
3689 /* Return address for Ith PLT stub in section PLT, for relocation REL
3690 or (bfd_vma) -1 if it should not be included. */
3693 elf32_tic6x_plt_sym_val (bfd_vma i, const asection *plt,
3694 const arelent *rel ATTRIBUTE_UNUSED)
3696 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
3700 elf32_tic6x_obj_attrs_arg_type (int tag)
3702 if (tag == Tag_ABI_compatibility)
3703 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
3705 return ATTR_TYPE_FLAG_STR_VAL;
3707 return ATTR_TYPE_FLAG_INT_VAL;
3711 elf32_tic6x_obj_attrs_order (int num)
3713 if (num == LEAST_KNOWN_OBJ_ATTRIBUTE)
3714 return Tag_ABI_conformance;
3715 if ((num - 1) < Tag_ABI_conformance)
3721 elf32_tic6x_obj_attrs_handle_unknown (bfd *abfd, int tag)
3723 if ((tag & 127) < 64)
3726 (_("%B: error: unknown mandatory EABI object attribute %d"),
3728 bfd_set_error (bfd_error_bad_value);
3734 (_("%B: warning: unknown EABI object attribute %d"),
3740 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3741 and return the merged value. At present, all merges succeed, so no
3742 return value for errors is defined. */
3745 elf32_tic6x_merge_arch_attributes (int arch1, int arch2)
3747 int min_arch, max_arch;
3749 min_arch = (arch1 < arch2 ? arch1 : arch2);
3750 max_arch = (arch1 > arch2 ? arch1 : arch2);
3752 /* In most cases, the numerically greatest value is the correct
3753 merged value, but merging C64 and C67 results in C674X. */
3754 if ((min_arch == C6XABI_Tag_ISA_C67X
3755 || min_arch == C6XABI_Tag_ISA_C67XP)
3756 && (max_arch == C6XABI_Tag_ISA_C64X
3757 || max_arch == C6XABI_Tag_ISA_C64XP))
3758 return C6XABI_Tag_ISA_C674X;
3763 /* Convert a Tag_ABI_array_object_alignment or
3764 Tag_ABI_array_object_align_expected tag value TAG to a
3765 corresponding alignment value; return the alignment, or -1 for an
3766 unknown tag value. */
3769 elf32_tic6x_tag_to_array_alignment (int tag)
3787 /* Convert a Tag_ABI_array_object_alignment or
3788 Tag_ABI_array_object_align_expected alignment ALIGN to a
3789 corresponding tag value; return the tag value. */
3792 elf32_tic6x_array_alignment_to_tag (int align)
3810 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3811 succeeded, FALSE otherwise. */
3814 elf32_tic6x_merge_attributes (bfd *ibfd, bfd *obfd)
3816 bfd_boolean result = TRUE;
3817 obj_attribute *in_attr;
3818 obj_attribute *out_attr;
3820 int array_align_in, array_align_out, array_expect_in, array_expect_out;
3822 if (!elf_known_obj_attributes_proc (obfd)[0].i)
3824 /* This is the first object. Copy the attributes. */
3825 _bfd_elf_copy_obj_attributes (ibfd, obfd);
3827 out_attr = elf_known_obj_attributes_proc (obfd);
3829 /* Use the Tag_null value to indicate the attributes have been
3836 in_attr = elf_known_obj_attributes_proc (ibfd);
3837 out_attr = elf_known_obj_attributes_proc (obfd);
3839 /* No specification yet for handling of unknown attributes, so just
3840 ignore them and handle known ones. */
3842 if (out_attr[Tag_ABI_stack_align_preserved].i
3843 < in_attr[Tag_ABI_stack_align_needed].i)
3846 (_("error: %B requires more stack alignment than %B preserves"),
3850 if (in_attr[Tag_ABI_stack_align_preserved].i
3851 < out_attr[Tag_ABI_stack_align_needed].i)
3854 (_("error: %B requires more stack alignment than %B preserves"),
3859 array_align_in = elf32_tic6x_tag_to_array_alignment
3860 (in_attr[Tag_ABI_array_object_alignment].i);
3861 if (array_align_in == -1)
3864 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3868 array_align_out = elf32_tic6x_tag_to_array_alignment
3869 (out_attr[Tag_ABI_array_object_alignment].i);
3870 if (array_align_out == -1)
3873 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3877 array_expect_in = elf32_tic6x_tag_to_array_alignment
3878 (in_attr[Tag_ABI_array_object_align_expected].i);
3879 if (array_expect_in == -1)
3882 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3886 array_expect_out = elf32_tic6x_tag_to_array_alignment
3887 (out_attr[Tag_ABI_array_object_align_expected].i);
3888 if (array_expect_out == -1)
3891 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3896 if (array_align_out < array_expect_in)
3899 (_("error: %B requires more array alignment than %B preserves"),
3903 if (array_align_in < array_expect_out)
3906 (_("error: %B requires more array alignment than %B preserves"),
3911 for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
3916 out_attr[i].i = elf32_tic6x_merge_arch_attributes (in_attr[i].i,
3920 case Tag_ABI_wchar_t:
3921 if (out_attr[i].i == 0)
3922 out_attr[i].i = in_attr[i].i;
3923 if (out_attr[i].i != 0
3924 && in_attr[i].i != 0
3925 && out_attr[i].i != in_attr[i].i)
3928 (_("warning: %B and %B differ in wchar_t size"), obfd, ibfd);
3932 case Tag_ABI_stack_align_needed:
3933 if (out_attr[i].i < in_attr[i].i)
3934 out_attr[i].i = in_attr[i].i;
3937 case Tag_ABI_stack_align_preserved:
3938 if (out_attr[i].i > in_attr[i].i)
3939 out_attr[i].i = in_attr[i].i;
3943 if (out_attr[i].i != in_attr[i].i)
3946 (_("warning: %B and %B differ in whether code is "
3947 "compiled for DSBT"),
3954 if (out_attr[i].i > in_attr[i].i)
3955 out_attr[i].i = in_attr[i].i;
3958 case Tag_ABI_array_object_alignment:
3959 if (array_align_out != -1
3960 && array_align_in != -1
3961 && array_align_out > array_align_in)
3963 = elf32_tic6x_array_alignment_to_tag (array_align_in);
3966 case Tag_ABI_array_object_align_expected:
3967 if (array_expect_out != -1
3968 && array_expect_in != -1
3969 && array_expect_out < array_expect_in)
3971 = elf32_tic6x_array_alignment_to_tag (array_expect_in);
3974 case Tag_ABI_conformance:
3975 /* Merging for this attribute is not specified. As on ARM,
3976 treat a missing attribute as no claim to conform and only
3977 merge identical values. */
3978 if (out_attr[i].s == NULL
3979 || in_attr[i].s == NULL
3980 || strcmp (out_attr[i].s,
3982 out_attr[i].s = NULL;
3985 case Tag_ABI_compatibility:
3986 /* Merged in _bfd_elf_merge_object_attributes. */
3991 = result && _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
3995 if (in_attr[i].type && !out_attr[i].type)
3996 out_attr[i].type = in_attr[i].type;
3999 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
4000 if (!_bfd_elf_merge_object_attributes (ibfd, obfd))
4003 result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd);
4009 elf32_tic6x_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4011 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
4014 if (!elf32_tic6x_merge_attributes (ibfd, obfd))
4021 elf32_tic6x_copy_private_data (bfd * ibfd, bfd * obfd)
4023 _bfd_elf_copy_private_bfd_data (ibfd, obfd);
4025 if (! is_tic6x_elf (ibfd) || ! is_tic6x_elf (obfd))
4028 /* Copy the stack size. */
4029 if (elf_tdata (ibfd)->phdr && elf_tdata (obfd)->phdr
4030 && elf32_tic6x_using_dsbt (ibfd) && elf32_tic6x_using_dsbt (obfd))
4034 for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
4035 if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK)
4037 Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i];
4039 for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++)
4040 if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK)
4042 memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr));
4044 /* Rewrite the phdrs, since we're only called after they
4045 were first written. */
4047 (bfd_signed_vma) get_elf_backend_data (obfd)
4048 ->s->sizeof_ehdr, SEEK_SET) != 0
4049 || get_elf_backend_data (obfd)->s
4050 ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
4051 elf_elfheader (obfd)->e_phnum) != 0)
4063 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
4064 adds the edit to the start of the list. (The list must be built in order of
4065 ascending TINDEX: the function's callers are primarily responsible for
4066 maintaining that condition). */
4069 elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit **head,
4070 tic6x_unwind_table_edit **tail,
4071 tic6x_unwind_edit_type type,
4072 asection *linked_section,
4073 unsigned int tindex)
4075 tic6x_unwind_table_edit *new_edit = (tic6x_unwind_table_edit *)
4076 xmalloc (sizeof (tic6x_unwind_table_edit));
4078 new_edit->type = type;
4079 new_edit->linked_section = linked_section;
4080 new_edit->index = tindex;
4084 new_edit->next = NULL;
4087 (*tail)->next = new_edit;
4096 new_edit->next = *head;
4105 static _tic6x_elf_section_data *
4106 get_tic6x_elf_section_data (asection * sec)
4108 if (sec && sec->owner && is_tic6x_elf (sec->owner))
4109 return elf32_tic6x_section_data (sec);
4115 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST must be negative. */
4117 elf32_tic6x_adjust_exidx_size (asection *exidx_sec, int adjust)
4121 if (!exidx_sec->rawsize)
4122 exidx_sec->rawsize = exidx_sec->size;
4124 bfd_set_section_size (exidx_sec->owner, exidx_sec, exidx_sec->size + adjust);
4125 out_sec = exidx_sec->output_section;
4126 /* Adjust size of output section. */
4127 bfd_set_section_size (out_sec->owner, out_sec, out_sec->size +adjust);
4130 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
4132 elf32_tic6x_insert_cantunwind_after (asection *text_sec, asection *exidx_sec)
4134 struct _tic6x_elf_section_data *exidx_data;
4136 exidx_data = get_tic6x_elf_section_data (exidx_sec);
4137 elf32_tic6x_add_unwind_table_edit (
4138 &exidx_data->u.exidx.unwind_edit_list,
4139 &exidx_data->u.exidx.unwind_edit_tail,
4140 INSERT_EXIDX_CANTUNWIND_AT_END, text_sec, UINT_MAX);
4142 elf32_tic6x_adjust_exidx_size (exidx_sec, 8);
4145 /* Scan .cx6abi.exidx tables, and create a list describing edits which
4146 should be made to those tables, such that:
4148 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
4149 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
4150 codes which have been inlined into the index).
4152 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
4154 The edits are applied when the tables are written
4155 (in elf32_tic6x_write_section).
4159 elf32_tic6x_fix_exidx_coverage (asection **text_section_order,
4160 unsigned int num_text_sections,
4161 struct bfd_link_info *info,
4162 bfd_boolean merge_exidx_entries)
4165 unsigned int last_second_word = 0, i;
4166 asection *last_exidx_sec = NULL;
4167 asection *last_text_sec = NULL;
4168 int last_unwind_type = -1;
4170 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
4172 for (inp = info->input_bfds; inp != NULL; inp = inp->link_next)
4176 for (sec = inp->sections; sec != NULL; sec = sec->next)
4178 struct bfd_elf_section_data *elf_sec = elf_section_data (sec);
4179 Elf_Internal_Shdr *hdr = &elf_sec->this_hdr;
4181 if (!hdr || hdr->sh_type != SHT_C6000_UNWIND)
4184 if (elf_sec->linked_to)
4186 Elf_Internal_Shdr *linked_hdr
4187 = &elf_section_data (elf_sec->linked_to)->this_hdr;
4188 struct _tic6x_elf_section_data *linked_sec_tic6x_data
4189 = get_tic6x_elf_section_data (linked_hdr->bfd_section);
4191 if (linked_sec_tic6x_data == NULL)
4194 /* Link this .c6xabi.exidx section back from the
4195 text section it describes. */
4196 linked_sec_tic6x_data->u.text.tic6x_exidx_sec = sec;
4201 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
4202 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
4203 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
4205 for (i = 0; i < num_text_sections; i++)
4207 asection *sec = text_section_order[i];
4208 asection *exidx_sec;
4209 struct _tic6x_elf_section_data *tic6x_data
4210 = get_tic6x_elf_section_data (sec);
4211 struct _tic6x_elf_section_data *exidx_data;
4212 bfd_byte *contents = NULL;
4213 int deleted_exidx_bytes = 0;
4215 tic6x_unwind_table_edit *unwind_edit_head = NULL;
4216 tic6x_unwind_table_edit *unwind_edit_tail = NULL;
4217 Elf_Internal_Shdr *hdr;
4220 if (tic6x_data == NULL)
4223 exidx_sec = tic6x_data->u.text.tic6x_exidx_sec;
4224 if (exidx_sec == NULL)
4226 /* Section has no unwind data. */
4227 if (last_unwind_type == 0 || !last_exidx_sec)
4230 /* Ignore zero sized sections. */
4234 elf32_tic6x_insert_cantunwind_after (last_text_sec, last_exidx_sec);
4235 last_unwind_type = 0;
4239 /* Skip /DISCARD/ sections. */
4240 if (bfd_is_abs_section (exidx_sec->output_section))
4243 hdr = &elf_section_data (exidx_sec)->this_hdr;
4244 if (hdr->sh_type != SHT_C6000_UNWIND)
4247 exidx_data = get_tic6x_elf_section_data (exidx_sec);
4248 if (exidx_data == NULL)
4251 ibfd = exidx_sec->owner;
4253 if (hdr->contents != NULL)
4254 contents = hdr->contents;
4255 else if (! bfd_malloc_and_get_section (ibfd, exidx_sec, &contents))
4259 for (j = 0; j < hdr->sh_size; j += 8)
4261 unsigned int second_word = bfd_get_32 (ibfd, contents + j + 4);
4265 /* An EXIDX_CANTUNWIND entry. */
4266 if (second_word == 1)
4268 if (last_unwind_type == 0)
4272 /* Inlined unwinding data. Merge if equal to previous. */
4273 else if ((second_word & 0x80000000) != 0)
4275 if (merge_exidx_entries
4276 && last_second_word == second_word
4277 && last_unwind_type == 1)
4280 last_second_word = second_word;
4282 /* Normal table entry. In theory we could merge these too,
4283 but duplicate entries are likely to be much less common. */
4289 elf32_tic6x_add_unwind_table_edit (&unwind_edit_head,
4290 &unwind_edit_tail, DELETE_EXIDX_ENTRY, NULL, j / 8);
4292 deleted_exidx_bytes += 8;
4295 last_unwind_type = unwind_type;
4298 /* Free contents if we allocated it ourselves. */
4299 if (contents != hdr->contents)
4302 /* Record edits to be applied later (in elf32_tic6x_write_section). */
4303 exidx_data->u.exidx.unwind_edit_list = unwind_edit_head;
4304 exidx_data->u.exidx.unwind_edit_tail = unwind_edit_tail;
4306 if (deleted_exidx_bytes > 0)
4307 elf32_tic6x_adjust_exidx_size (exidx_sec, -deleted_exidx_bytes);
4309 last_exidx_sec = exidx_sec;
4310 last_text_sec = sec;
4313 /* Add terminating CANTUNWIND entry. */
4314 if (last_exidx_sec && last_unwind_type != 0)
4315 elf32_tic6x_insert_cantunwind_after (last_text_sec, last_exidx_sec);
4320 /* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified. */
4322 static unsigned long
4323 elf32_tic6x_add_low31 (unsigned long val, bfd_vma addend)
4325 return (val & ~0x7ffffffful) | ((val + addend) & 0x7ffffffful);
4328 /* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
4329 relocations. OFFSET is in bytes, and will be scaled before encoding. */
4333 elf32_tic6x_copy_exidx_entry (bfd *output_bfd, bfd_byte *to, bfd_byte *from,
4336 unsigned long first_word = bfd_get_32 (output_bfd, from);
4337 unsigned long second_word = bfd_get_32 (output_bfd, from + 4);
4340 /* High bit of first word is supposed to be zero. */
4341 if ((first_word & 0x80000000ul) == 0)
4342 first_word = elf32_tic6x_add_low31 (first_word, offset);
4344 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
4345 (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry. */
4346 if ((second_word != 0x1) && ((second_word & 0x80000000ul) == 0))
4347 second_word = elf32_tic6x_add_low31 (second_word, offset);
4349 bfd_put_32 (output_bfd, first_word, to);
4350 bfd_put_32 (output_bfd, second_word, to + 4);
4353 /* Do the actual mangling of exception index tables. */
4356 elf32_tic6x_write_section (bfd *output_bfd,
4357 struct bfd_link_info *link_info,
4361 _tic6x_elf_section_data *tic6x_data;
4362 struct elf32_tic6x_link_hash_table *globals
4363 = elf32_tic6x_hash_table (link_info);
4364 bfd_vma offset = sec->output_section->vma + sec->output_offset;
4366 if (globals == NULL)
4369 /* If this section has not been allocated an _tic6x_elf_section_data
4370 structure then we cannot record anything. */
4371 tic6x_data = get_tic6x_elf_section_data (sec);
4372 if (tic6x_data == NULL)
4375 if (tic6x_data->elf.this_hdr.sh_type != SHT_C6000_UNWIND)
4378 tic6x_unwind_table_edit *edit_node
4379 = tic6x_data->u.exidx.unwind_edit_list;
4380 /* Now, sec->size is the size of the section we will write. The original
4381 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
4382 markers) was sec->rawsize. (This isn't the case if we perform no
4383 edits, then rawsize will be zero and we should use size). */
4384 bfd_byte *edited_contents = (bfd_byte *) bfd_malloc (sec->size);
4385 unsigned int input_size = sec->rawsize ? sec->rawsize : sec->size;
4386 unsigned int in_index, out_index;
4387 bfd_vma add_to_offsets = 0;
4389 for (in_index = 0, out_index = 0; in_index * 8 < input_size || edit_node;)
4393 unsigned int edit_index = edit_node->index;
4395 if (in_index < edit_index && in_index * 8 < input_size)
4397 elf32_tic6x_copy_exidx_entry (output_bfd,
4398 edited_contents + out_index * 8,
4399 contents + in_index * 8, add_to_offsets);
4403 else if (in_index == edit_index
4404 || (in_index * 8 >= input_size
4405 && edit_index == UINT_MAX))
4407 switch (edit_node->type)
4409 case DELETE_EXIDX_ENTRY:
4411 add_to_offsets += 8;
4414 case INSERT_EXIDX_CANTUNWIND_AT_END:
4416 asection *text_sec = edit_node->linked_section;
4417 bfd_vma text_offset = text_sec->output_section->vma
4418 + text_sec->output_offset
4420 bfd_vma exidx_offset = offset + out_index * 8;
4421 unsigned long prel31_offset;
4423 /* Note: this is meant to be equivalent to an
4424 R_C6000_PREL31 relocation. These synthetic
4425 EXIDX_CANTUNWIND markers are not relocated by the
4426 usual BFD method. */
4427 prel31_offset = ((text_offset - exidx_offset) >> 1)
4430 /* First address we can't unwind. */
4431 bfd_put_32 (output_bfd, prel31_offset,
4432 &edited_contents[out_index * 8]);
4434 /* Code for EXIDX_CANTUNWIND. */
4435 bfd_put_32 (output_bfd, 0x1,
4436 &edited_contents[out_index * 8 + 4]);
4439 add_to_offsets -= 8;
4444 edit_node = edit_node->next;
4449 /* No more edits, copy remaining entries verbatim. */
4450 elf32_tic6x_copy_exidx_entry (output_bfd,
4451 edited_contents + out_index * 8,
4452 contents + in_index * 8, add_to_offsets);
4458 if (!(sec->flags & SEC_EXCLUDE) && !(sec->flags & SEC_NEVER_LOAD))
4459 bfd_set_section_contents (output_bfd, sec->output_section,
4461 (file_ptr) sec->output_offset, sec->size);
4467 elf32_tic6x_set_osabi (bfd *abfd, struct bfd_link_info *link_info)
4469 if (link_info != NULL && link_info->relocatable)
4471 _bfd_elf_set_osabi (abfd, link_info);
4474 #define TARGET_LITTLE_SYM bfd_elf32_tic6x_le_vec
4475 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
4476 #define TARGET_BIG_SYM bfd_elf32_tic6x_be_vec
4477 #define TARGET_BIG_NAME "elf32-tic6x-be"
4478 #define ELF_ARCH bfd_arch_tic6x
4479 #define ELF_TARGET_ID TIC6X_ELF_DATA
4480 #define ELF_MACHINE_CODE EM_TI_C6000
4481 #define ELF_MAXPAGESIZE 0x1000
4482 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
4483 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
4484 #define bfd_elf32_bfd_copy_private_bfd_data elf32_tic6x_copy_private_data
4485 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
4486 #define bfd_elf32_mkobject elf32_tic6x_mkobject
4487 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
4488 #define bfd_elf32_bfd_link_hash_table_free elf32_tic6x_link_hash_table_free
4489 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
4490 #define elf_backend_can_gc_sections 1
4491 #define elf_backend_default_use_rela_p 1
4492 #define elf_backend_may_use_rel_p 1
4493 #define elf_backend_may_use_rela_p 1
4494 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
4495 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
4496 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
4497 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
4498 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4499 #define elf_backend_obj_attrs_vendor "c6xabi"
4500 #define elf_backend_can_refcount 1
4501 #define elf_backend_want_got_plt 1
4502 #define elf_backend_want_dynbss 1
4503 #define elf_backend_plt_readonly 1
4504 #define elf_backend_rela_normal 1
4505 #define elf_backend_got_header_size 8
4506 #define elf_backend_fake_sections elf32_tic6x_fake_sections
4507 #define elf_backend_gc_sweep_hook elf32_tic6x_gc_sweep_hook
4508 #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
4509 #define elf_backend_modify_program_headers \
4510 elf32_tic6x_modify_program_headers
4511 #define elf_backend_create_dynamic_sections \
4512 elf32_tic6x_create_dynamic_sections
4513 #define elf_backend_adjust_dynamic_symbol \
4514 elf32_tic6x_adjust_dynamic_symbol
4515 #define elf_backend_check_relocs elf32_tic6x_check_relocs
4516 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4517 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4518 #define elf_backend_link_output_symbol_hook \
4519 elf32_tic6x_link_output_symbol_hook
4520 #define elf_backend_section_from_bfd_section \
4521 elf32_tic6x_section_from_bfd_section
4522 #define elf_backend_relocate_section elf32_tic6x_relocate_section
4523 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4524 #define elf_backend_finish_dynamic_symbol \
4525 elf32_tic6x_finish_dynamic_symbol
4526 #define elf_backend_always_size_sections \
4527 elf32_tic6x_always_size_sections
4528 #define elf_backend_size_dynamic_sections \
4529 elf32_tic6x_size_dynamic_sections
4530 #define elf_backend_finish_dynamic_sections \
4531 elf32_tic6x_finish_dynamic_sections
4532 #define bfd_elf32_bfd_final_link \
4533 elf32_tic6x_final_link
4534 #define elf_backend_write_section elf32_tic6x_write_section
4535 #define elf_info_to_howto elf32_tic6x_info_to_howto
4536 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
4538 #undef elf_backend_omit_section_dynsym
4539 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4540 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4542 #include "elf32-target.h"
4545 #define elf32_bed elf32_tic6x_linux_bed
4547 #undef TARGET_LITTLE_SYM
4548 #define TARGET_LITTLE_SYM bfd_elf32_tic6x_linux_le_vec
4549 #undef TARGET_LITTLE_NAME
4550 #define TARGET_LITTLE_NAME "elf32-tic6x-linux-le"
4551 #undef TARGET_BIG_SYM
4552 #define TARGET_BIG_SYM bfd_elf32_tic6x_linux_be_vec
4553 #undef TARGET_BIG_NAME
4554 #define TARGET_BIG_NAME "elf32-tic6x-linux-be"
4556 #define ELF_OSABI ELFOSABI_C6000_LINUX
4558 #undef elf_backend_post_process_headers
4559 #define elf_backend_post_process_headers elf32_tic6x_set_osabi
4561 #include "elf32-target.h"
4564 #define elf32_bed elf32_tic6x_elf_bed
4566 #undef TARGET_LITTLE_SYM
4567 #define TARGET_LITTLE_SYM bfd_elf32_tic6x_elf_le_vec
4568 #undef TARGET_LITTLE_NAME
4569 #define TARGET_LITTLE_NAME "elf32-tic6x-elf-le"
4570 #undef TARGET_BIG_SYM
4571 #define TARGET_BIG_SYM bfd_elf32_tic6x_elf_be_vec
4572 #undef TARGET_BIG_NAME
4573 #define TARGET_BIG_NAME "elf32-tic6x-elf-be"
4575 #define ELF_OSABI ELFOSABI_C6000_ELFABI
4577 #undef elf_backend_post_process_headers
4578 #define elf_backend_post_process_headers elf32_tic6x_set_osabi
4580 #include "elf32-target.h"