1 /* 32-bit ELF support for TI C6X
2 Copyright (C) 2010-2015 Free Software Foundation, Inc.
3 Contributed by Joseph Myers <joseph@codesourcery.com>
4 Bernd Schmidt <bernds@codesourcery.com>
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
27 #include "libiberty.h"
29 #include "elf/tic6x.h"
30 #include "elf32-tic6x.h"
32 #define ELF_DYNAMIC_INTERPRETER "/lib/ld-uClibc.so.0"
34 /* DSBT binaries have a default 128K stack. */
35 #define DEFAULT_STACK_SIZE 0x20000
37 /* The size in bytes of an entry in the procedure linkage table. */
38 #define PLT_ENTRY_SIZE 24
40 /* TI C6X ELF linker hash table. */
42 struct elf32_tic6x_link_hash_table
44 struct elf_link_hash_table elf
;
46 /* Short-cuts to get to dynamic linker sections. */
50 /* C6X specific command line arguments. */
51 struct elf32_tic6x_params params
;
53 /* Small local sym cache. */
54 struct sym_cache sym_cache
;
56 /* The output BFD, for convenience. */
59 /* The .dsbt section. */
63 /* Get the TI C6X ELF linker hash table from a link_info structure. */
65 #define elf32_tic6x_hash_table(p) \
66 ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
68 /* TI C6X ELF linker hash entry. */
70 struct elf32_tic6x_link_hash_entry
72 struct elf_link_hash_entry elf
;
74 /* Track dynamic relocs copied for this symbol. */
75 struct elf_dyn_relocs
*dyn_relocs
;
81 INSERT_EXIDX_CANTUNWIND_AT_END
83 tic6x_unwind_edit_type
;
85 /* A (sorted) list of edits to apply to an unwind table. */
86 typedef struct tic6x_unwind_table_edit
88 tic6x_unwind_edit_type type
;
89 /* Note: we sometimes want to insert an unwind entry corresponding to a
90 section different from the one we're currently writing out, so record the
91 (text) section this edit relates to here. */
92 asection
*linked_section
;
94 struct tic6x_unwind_table_edit
*next
;
96 tic6x_unwind_table_edit
;
98 typedef struct _tic6x_elf_section_data
100 /* Information about mapping symbols. */
101 struct bfd_elf_section_data elf
;
102 /* Information about unwind tables. */
105 /* Unwind info attached to a text section. */
108 asection
*tic6x_exidx_sec
;
111 /* Unwind info attached to an .c6xabi.exidx section. */
114 tic6x_unwind_table_edit
*unwind_edit_list
;
115 tic6x_unwind_table_edit
*unwind_edit_tail
;
119 _tic6x_elf_section_data
;
121 #define elf32_tic6x_section_data(sec) \
122 ((_tic6x_elf_section_data *) elf_section_data (sec))
124 struct elf32_tic6x_obj_tdata
126 struct elf_obj_tdata root
;
128 /* Whether to use RELA relocations when generating relocations.
129 This is a per-object flag to allow the assembler to generate REL
130 relocations for use in linker testcases. */
131 bfd_boolean use_rela_p
;
134 #define elf32_tic6x_tdata(abfd) \
135 ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
137 #define is_tic6x_elf(bfd) \
138 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
139 && elf_tdata (bfd) != NULL \
140 && elf_object_id (bfd) == TIC6X_ELF_DATA)
142 /* C6X ELF uses two common sections. One is the usual one, and the
143 other is for small objects. All the small objects are kept
144 together, and then referenced via the gp pointer, which yields
145 faster assembler code. This is what we use for the small common
146 section. This approach is copied from ecoff.c. */
147 static asection tic6x_elf_scom_section
;
148 static asymbol tic6x_elf_scom_symbol
;
149 static asymbol
*tic6x_elf_scom_symbol_ptr
;
151 static reloc_howto_type elf32_tic6x_howto_table
[] =
153 HOWTO (R_C6000_NONE
, /* type */
155 3, /* size (0 = byte, 1 = short, 2 = long) */
157 FALSE
, /* pc_relative */
159 complain_overflow_dont
,/* complain_on_overflow */
160 bfd_elf_generic_reloc
, /* special_function */
161 "R_C6000_NONE", /* name */
162 FALSE
, /* partial_inplace */
165 FALSE
), /* pcrel_offset */
166 HOWTO (R_C6000_ABS32
, /* type */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
170 FALSE
, /* pc_relative */
172 complain_overflow_dont
,/* complain_on_overflow */
173 bfd_elf_generic_reloc
, /* special_function */
174 "R_C6000_ABS32", /* name */
175 FALSE
, /* partial_inplace */
177 0xffffffff, /* dst_mask */
178 FALSE
), /* pcrel_offset */
179 HOWTO (R_C6000_ABS16
, /* type */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE
, /* pc_relative */
185 complain_overflow_bitfield
,/* complain_on_overflow */
186 bfd_elf_generic_reloc
, /* special_function */
187 "R_C6000_ABS16", /* name */
188 FALSE
, /* partial_inplace */
190 0x0000ffff, /* dst_mask */
191 FALSE
), /* pcrel_offset */
192 HOWTO (R_C6000_ABS8
, /* type */
194 0, /* size (0 = byte, 1 = short, 2 = long) */
196 FALSE
, /* pc_relative */
198 complain_overflow_bitfield
,/* complain_on_overflow */
199 bfd_elf_generic_reloc
, /* special_function */
200 "R_C6000_ABS8", /* name */
201 FALSE
, /* partial_inplace */
203 0x000000ff, /* dst_mask */
204 FALSE
), /* pcrel_offset */
205 HOWTO (R_C6000_PCR_S21
, /* type */
207 2, /* size (0 = byte, 1 = short, 2 = long) */
209 TRUE
, /* pc_relative */
211 complain_overflow_signed
,/* complain_on_overflow */
212 bfd_elf_generic_reloc
, /* special_function */
213 "R_C6000_PCR_S21", /* name */
214 FALSE
, /* partial_inplace */
216 0x0fffff80, /* dst_mask */
217 TRUE
), /* pcrel_offset */
218 HOWTO (R_C6000_PCR_S12
, /* type */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
222 TRUE
, /* pc_relative */
224 complain_overflow_signed
,/* complain_on_overflow */
225 bfd_elf_generic_reloc
, /* special_function */
226 "R_C6000_PCR_S12", /* name */
227 FALSE
, /* partial_inplace */
229 0x0fff0000, /* dst_mask */
230 TRUE
), /* pcrel_offset */
231 HOWTO (R_C6000_PCR_S10
, /* type */
233 2, /* size (0 = byte, 1 = short, 2 = long) */
235 TRUE
, /* pc_relative */
237 complain_overflow_signed
,/* complain_on_overflow */
238 bfd_elf_generic_reloc
, /* special_function */
239 "R_C6000_PCR_S10", /* name */
240 FALSE
, /* partial_inplace */
242 0x007fe000, /* dst_mask */
243 TRUE
), /* pcrel_offset */
244 HOWTO (R_C6000_PCR_S7
, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 TRUE
, /* pc_relative */
250 complain_overflow_signed
,/* complain_on_overflow */
251 bfd_elf_generic_reloc
, /* special_function */
252 "R_C6000_PCR_S7", /* name */
253 FALSE
, /* partial_inplace */
255 0x007f0000, /* dst_mask */
256 TRUE
), /* pcrel_offset */
257 HOWTO (R_C6000_ABS_S16
, /* type */
259 2, /* size (0 = byte, 1 = short, 2 = long) */
261 FALSE
, /* pc_relative */
263 complain_overflow_signed
,/* complain_on_overflow */
264 bfd_elf_generic_reloc
, /* special_function */
265 "R_C6000_ABS_S16", /* name */
266 FALSE
, /* partial_inplace */
268 0x007fff80, /* dst_mask */
269 FALSE
), /* pcrel_offset */
270 HOWTO (R_C6000_ABS_L16
, /* type */
272 2, /* size (0 = byte, 1 = short, 2 = long) */
274 FALSE
, /* pc_relative */
276 complain_overflow_dont
,/* complain_on_overflow */
277 bfd_elf_generic_reloc
, /* special_function */
278 "R_C6000_ABS_L16", /* name */
279 FALSE
, /* partial_inplace */
281 0x007fff80, /* dst_mask */
282 FALSE
), /* pcrel_offset */
283 HOWTO (R_C6000_ABS_H16
, /* type */
285 2, /* size (0 = byte, 1 = short, 2 = long) */
287 FALSE
, /* pc_relative */
289 complain_overflow_dont
,/* complain_on_overflow */
290 bfd_elf_generic_reloc
, /* special_function */
291 "R_C6000_ABS_H16", /* name */
292 FALSE
, /* partial_inplace */
294 0x007fff80, /* dst_mask */
295 FALSE
), /* pcrel_offset */
296 HOWTO (R_C6000_SBR_U15_B
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 FALSE
, /* pc_relative */
302 complain_overflow_unsigned
,/* complain_on_overflow */
303 bfd_elf_generic_reloc
, /* special_function */
304 "R_C6000_SBR_U15_B", /* name */
305 FALSE
, /* partial_inplace */
307 0x007fff00, /* dst_mask */
308 FALSE
), /* pcrel_offset */
309 HOWTO (R_C6000_SBR_U15_H
, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 FALSE
, /* pc_relative */
315 complain_overflow_unsigned
,/* complain_on_overflow */
316 bfd_elf_generic_reloc
, /* special_function */
317 "R_C6000_SBR_U15_H", /* name */
318 FALSE
, /* partial_inplace */
320 0x007fff00, /* dst_mask */
321 FALSE
), /* pcrel_offset */
322 HOWTO (R_C6000_SBR_U15_W
, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 FALSE
, /* pc_relative */
328 complain_overflow_unsigned
,/* complain_on_overflow */
329 bfd_elf_generic_reloc
, /* special_function */
330 "R_C6000_SBR_U15_W", /* name */
331 FALSE
, /* partial_inplace */
333 0x007fff00, /* dst_mask */
334 FALSE
), /* pcrel_offset */
335 HOWTO (R_C6000_SBR_S16
, /* type */
337 2, /* size (0 = byte, 1 = short, 2 = long) */
339 FALSE
, /* pc_relative */
341 complain_overflow_signed
,/* complain_on_overflow */
342 bfd_elf_generic_reloc
, /* special_function */
343 "R_C6000_SBR_S16", /* name */
344 FALSE
, /* partial_inplace */
346 0x007fff80, /* dst_mask */
347 FALSE
), /* pcrel_offset */
348 HOWTO (R_C6000_SBR_L16_B
, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 FALSE
, /* pc_relative */
354 complain_overflow_dont
,/* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_C6000_SBR_L16_B", /* name */
357 FALSE
, /* partial_inplace */
359 0x007fff80, /* dst_mask */
360 FALSE
), /* pcrel_offset */
361 HOWTO (R_C6000_SBR_L16_H
, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 FALSE
, /* pc_relative */
367 complain_overflow_dont
,/* complain_on_overflow */
368 bfd_elf_generic_reloc
, /* special_function */
369 "R_C6000_SBR_L16_H", /* name */
370 FALSE
, /* partial_inplace */
372 0x007fff80, /* dst_mask */
373 FALSE
), /* pcrel_offset */
374 HOWTO (R_C6000_SBR_L16_W
, /* type */
376 2, /* size (0 = byte, 1 = short, 2 = long) */
378 FALSE
, /* pc_relative */
380 complain_overflow_dont
,/* complain_on_overflow */
381 bfd_elf_generic_reloc
, /* special_function */
382 "R_C6000_SBR_L16_W", /* name */
383 FALSE
, /* partial_inplace */
385 0x007fff80, /* dst_mask */
386 FALSE
), /* pcrel_offset */
387 HOWTO (R_C6000_SBR_H16_B
, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 FALSE
, /* pc_relative */
393 complain_overflow_dont
,/* complain_on_overflow */
394 bfd_elf_generic_reloc
, /* special_function */
395 "R_C6000_SBR_H16_B", /* name */
396 FALSE
, /* partial_inplace */
398 0x007fff80, /* dst_mask */
399 FALSE
), /* pcrel_offset */
400 HOWTO (R_C6000_SBR_H16_H
, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 FALSE
, /* pc_relative */
406 complain_overflow_dont
,/* complain_on_overflow */
407 bfd_elf_generic_reloc
, /* special_function */
408 "R_C6000_SBR_H16_H", /* name */
409 FALSE
, /* partial_inplace */
411 0x007fff80, /* dst_mask */
412 FALSE
), /* pcrel_offset */
413 HOWTO (R_C6000_SBR_H16_W
, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 FALSE
, /* pc_relative */
419 complain_overflow_dont
,/* complain_on_overflow */
420 bfd_elf_generic_reloc
, /* special_function */
421 "R_C6000_SBR_H16_W", /* name */
422 FALSE
, /* partial_inplace */
424 0x007fff80, /* dst_mask */
425 FALSE
), /* pcrel_offset */
426 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 FALSE
, /* pc_relative */
432 complain_overflow_unsigned
,/* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 "R_C6000_SBR_GOT_U15_W",/* name */
435 FALSE
, /* partial_inplace */
437 0x007fff00, /* dst_mask */
438 FALSE
), /* pcrel_offset */
439 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 FALSE
, /* pc_relative */
445 complain_overflow_dont
,/* complain_on_overflow */
446 bfd_elf_generic_reloc
, /* special_function */
447 "R_C6000_SBR_GOT_L16_W",/* name */
448 FALSE
, /* partial_inplace */
450 0x007fff80, /* dst_mask */
451 FALSE
), /* pcrel_offset */
452 HOWTO (R_C6000_SBR_GOT_H16_W
, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 FALSE
, /* pc_relative */
458 complain_overflow_dont
,/* complain_on_overflow */
459 bfd_elf_generic_reloc
, /* special_function */
460 "R_C6000_SBR_GOT_H16_W",/* name */
461 FALSE
, /* partial_inplace */
463 0x007fff80, /* dst_mask */
464 FALSE
), /* pcrel_offset */
465 HOWTO (R_C6000_DSBT_INDEX
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 FALSE
, /* pc_relative */
471 complain_overflow_unsigned
,/* complain_on_overflow */
472 bfd_elf_generic_reloc
, /* special_function */
473 "R_C6000_DSBT_INDEX", /* name */
474 FALSE
, /* partial_inplace */
476 0x007fff00, /* dst_mask */
477 FALSE
), /* pcrel_offset */
478 HOWTO (R_C6000_PREL31
, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 TRUE
, /* pc_relative */
484 complain_overflow_dont
,/* complain_on_overflow */
485 bfd_elf_generic_reloc
, /* special_function */
486 "R_C6000_PREL31", /* name */
487 FALSE
, /* partial_inplace */
489 0x7fffffff, /* dst_mask */
490 TRUE
), /* pcrel_offset */
491 HOWTO (R_C6000_COPY
, /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 FALSE
, /* pc_relative */
497 complain_overflow_dont
,/* complain_on_overflow */
498 bfd_elf_generic_reloc
, /* special_function */
499 "R_C6000_COPY", /* name */
500 FALSE
, /* partial_inplace */
502 0xffffffff, /* dst_mask */
503 FALSE
), /* pcrel_offset */
504 HOWTO (R_C6000_JUMP_SLOT
, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 FALSE
, /* pc_relative */
510 complain_overflow_dont
,/* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_C6000_JUMP_SLOT", /* name */
513 FALSE
, /* partial_inplace */
515 0xffffffff, /* dst_mask */
516 FALSE
), /* pcrel_offset */
517 HOWTO (R_C6000_EHTYPE
, /* type */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 FALSE
, /* pc_relative */
523 complain_overflow_dont
,/* complain_on_overflow */
524 bfd_elf_generic_reloc
, /* special_function */
525 "R_C6000_EHTYPE", /* name */
526 FALSE
, /* partial_inplace */
528 0xffffffff, /* dst_mask */
529 FALSE
), /* pcrel_offset */
530 HOWTO (R_C6000_PCR_H16
, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 TRUE
, /* pc_relative */
536 complain_overflow_dont
,/* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 "R_C6000_PCR_H16", /* name */
539 FALSE
, /* partial_inplace */
541 0x007fff80, /* dst_mask */
542 TRUE
), /* pcrel_offset */
543 HOWTO (R_C6000_PCR_L16
, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 TRUE
, /* pc_relative */
549 complain_overflow_dont
,/* complain_on_overflow */
550 bfd_elf_generic_reloc
, /* special_function */
551 "R_C6000_PCR_L16", /* name */
552 FALSE
, /* partial_inplace */
554 0x007fff80, /* dst_mask */
555 TRUE
), /* pcrel_offset */
778 HOWTO (R_C6000_ALIGN
, /* type */
780 0, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE
, /* pc_relative */
784 complain_overflow_dont
,/* complain_on_overflow */
785 bfd_elf_generic_reloc
, /* special_function */
786 "R_C6000_ALIGN", /* name */
787 FALSE
, /* partial_inplace */
790 FALSE
), /* pcrel_offset */
791 HOWTO (R_C6000_FPHEAD
, /* type */
793 0, /* size (0 = byte, 1 = short, 2 = long) */
795 FALSE
, /* pc_relative */
797 complain_overflow_dont
,/* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 "R_C6000_FPHEAD", /* name */
800 FALSE
, /* partial_inplace */
803 FALSE
), /* pcrel_offset */
804 HOWTO (R_C6000_NOCMP
, /* type */
806 0, /* size (0 = byte, 1 = short, 2 = long) */
808 FALSE
, /* pc_relative */
810 complain_overflow_dont
,/* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_C6000_NOCMP", /* name */
813 FALSE
, /* partial_inplace */
816 FALSE
) /* pcrel_offset */
819 static reloc_howto_type elf32_tic6x_howto_table_rel
[] =
821 HOWTO (R_C6000_NONE
, /* type */
823 3, /* size (0 = byte, 1 = short, 2 = long) */
825 FALSE
, /* pc_relative */
827 complain_overflow_dont
,/* complain_on_overflow */
828 bfd_elf_generic_reloc
, /* special_function */
829 "R_C6000_NONE", /* name */
830 TRUE
, /* partial_inplace */
833 FALSE
), /* pcrel_offset */
834 HOWTO (R_C6000_ABS32
, /* type */
836 2, /* size (0 = byte, 1 = short, 2 = long) */
838 FALSE
, /* pc_relative */
840 complain_overflow_dont
,/* complain_on_overflow */
841 bfd_elf_generic_reloc
, /* special_function */
842 "R_C6000_ABS32", /* name */
843 TRUE
, /* partial_inplace */
844 0xffffffff, /* src_mask */
845 0xffffffff, /* dst_mask */
846 FALSE
), /* pcrel_offset */
847 HOWTO (R_C6000_ABS16
, /* type */
849 1, /* size (0 = byte, 1 = short, 2 = long) */
851 FALSE
, /* pc_relative */
853 complain_overflow_bitfield
,/* complain_on_overflow */
854 bfd_elf_generic_reloc
, /* special_function */
855 "R_C6000_ABS16", /* name */
856 TRUE
, /* partial_inplace */
857 0x0000ffff, /* src_mask */
858 0x0000ffff, /* dst_mask */
859 FALSE
), /* pcrel_offset */
860 HOWTO (R_C6000_ABS8
, /* type */
862 0, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_bitfield
,/* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_C6000_ABS8", /* name */
869 TRUE
, /* partial_inplace */
870 0x000000ff, /* src_mask */
871 0x000000ff, /* dst_mask */
872 FALSE
), /* pcrel_offset */
873 HOWTO (R_C6000_PCR_S21
, /* type */
875 2, /* size (0 = byte, 1 = short, 2 = long) */
877 TRUE
, /* pc_relative */
879 complain_overflow_signed
,/* complain_on_overflow */
880 bfd_elf_generic_reloc
, /* special_function */
881 "R_C6000_PCR_S21", /* name */
882 TRUE
, /* partial_inplace */
883 0x0fffff80, /* src_mask */
884 0x0fffff80, /* dst_mask */
885 TRUE
), /* pcrel_offset */
886 HOWTO (R_C6000_PCR_S12
, /* type */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
890 TRUE
, /* pc_relative */
892 complain_overflow_signed
,/* complain_on_overflow */
893 bfd_elf_generic_reloc
, /* special_function */
894 "R_C6000_PCR_S12", /* name */
895 TRUE
, /* partial_inplace */
896 0x0fff0000, /* src_mask */
897 0x0fff0000, /* dst_mask */
898 TRUE
), /* pcrel_offset */
899 HOWTO (R_C6000_PCR_S10
, /* type */
901 2, /* size (0 = byte, 1 = short, 2 = long) */
903 TRUE
, /* pc_relative */
905 complain_overflow_signed
,/* complain_on_overflow */
906 bfd_elf_generic_reloc
, /* special_function */
907 "R_C6000_PCR_S10", /* name */
908 TRUE
, /* partial_inplace */
909 0x007fe000, /* src_mask */
910 0x007fe000, /* dst_mask */
911 TRUE
), /* pcrel_offset */
912 HOWTO (R_C6000_PCR_S7
, /* type */
914 2, /* size (0 = byte, 1 = short, 2 = long) */
916 TRUE
, /* pc_relative */
918 complain_overflow_signed
,/* complain_on_overflow */
919 bfd_elf_generic_reloc
, /* special_function */
920 "R_C6000_PCR_S7", /* name */
921 TRUE
, /* partial_inplace */
922 0x007f0000, /* src_mask */
923 0x007f0000, /* dst_mask */
924 TRUE
), /* pcrel_offset */
925 HOWTO (R_C6000_ABS_S16
, /* type */
927 2, /* size (0 = byte, 1 = short, 2 = long) */
929 FALSE
, /* pc_relative */
931 complain_overflow_signed
,/* complain_on_overflow */
932 bfd_elf_generic_reloc
, /* special_function */
933 "R_C6000_ABS_S16", /* name */
934 TRUE
, /* partial_inplace */
935 0x007fff80, /* src_mask */
936 0x007fff80, /* dst_mask */
937 FALSE
), /* pcrel_offset */
938 HOWTO (R_C6000_ABS_L16
, /* type */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_dont
,/* complain_on_overflow */
945 bfd_elf_generic_reloc
, /* special_function */
946 "R_C6000_ABS_L16", /* name */
947 TRUE
, /* partial_inplace */
948 0x007fff80, /* src_mask */
949 0x007fff80, /* dst_mask */
950 FALSE
), /* pcrel_offset */
951 EMPTY_HOWTO (R_C6000_ABS_H16
),
952 HOWTO (R_C6000_SBR_U15_B
, /* type */
954 2, /* size (0 = byte, 1 = short, 2 = long) */
956 FALSE
, /* pc_relative */
958 complain_overflow_unsigned
,/* complain_on_overflow */
959 bfd_elf_generic_reloc
, /* special_function */
960 "R_C6000_SBR_U15_B", /* name */
961 TRUE
, /* partial_inplace */
962 0x007fff00, /* src_mask */
963 0x007fff00, /* dst_mask */
964 FALSE
), /* pcrel_offset */
965 HOWTO (R_C6000_SBR_U15_H
, /* type */
967 2, /* size (0 = byte, 1 = short, 2 = long) */
969 FALSE
, /* pc_relative */
971 complain_overflow_unsigned
,/* complain_on_overflow */
972 bfd_elf_generic_reloc
, /* special_function */
973 "R_C6000_SBR_U15_H", /* name */
974 TRUE
, /* partial_inplace */
975 0x007fff00, /* src_mask */
976 0x007fff00, /* dst_mask */
977 FALSE
), /* pcrel_offset */
978 HOWTO (R_C6000_SBR_U15_W
, /* type */
980 2, /* size (0 = byte, 1 = short, 2 = long) */
982 FALSE
, /* pc_relative */
984 complain_overflow_unsigned
,/* complain_on_overflow */
985 bfd_elf_generic_reloc
, /* special_function */
986 "R_C6000_SBR_U15_W", /* name */
987 TRUE
, /* partial_inplace */
988 0x007fff00, /* src_mask */
989 0x007fff00, /* dst_mask */
990 FALSE
), /* pcrel_offset */
991 HOWTO (R_C6000_SBR_S16
, /* type */
993 2, /* size (0 = byte, 1 = short, 2 = long) */
995 FALSE
, /* pc_relative */
997 complain_overflow_signed
,/* complain_on_overflow */
998 bfd_elf_generic_reloc
, /* special_function */
999 "R_C6000_SBR_S16", /* name */
1000 TRUE
, /* partial_inplace */
1001 0x007fff80, /* src_mask */
1002 0x007fff80, /* dst_mask */
1003 FALSE
), /* pcrel_offset */
1004 HOWTO (R_C6000_SBR_L16_B
, /* type */
1006 2, /* size (0 = byte, 1 = short, 2 = long) */
1008 FALSE
, /* pc_relative */
1010 complain_overflow_dont
,/* complain_on_overflow */
1011 bfd_elf_generic_reloc
, /* special_function */
1012 "R_C6000_SBR_L16_B", /* name */
1013 TRUE
, /* partial_inplace */
1014 0x007fff80, /* src_mask */
1015 0x007fff80, /* dst_mask */
1016 FALSE
), /* pcrel_offset */
1017 HOWTO (R_C6000_SBR_L16_H
, /* type */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE
, /* pc_relative */
1023 complain_overflow_dont
,/* complain_on_overflow */
1024 bfd_elf_generic_reloc
, /* special_function */
1025 "R_C6000_SBR_L16_H", /* name */
1026 TRUE
, /* partial_inplace */
1027 0x007fff80, /* src_mask */
1028 0x007fff80, /* dst_mask */
1029 FALSE
), /* pcrel_offset */
1030 HOWTO (R_C6000_SBR_L16_W
, /* type */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1034 FALSE
, /* pc_relative */
1036 complain_overflow_dont
,/* complain_on_overflow */
1037 bfd_elf_generic_reloc
, /* special_function */
1038 "R_C6000_SBR_L16_W", /* name */
1039 TRUE
, /* partial_inplace */
1040 0x007fff80, /* src_mask */
1041 0x007fff80, /* dst_mask */
1042 FALSE
), /* pcrel_offset */
1043 EMPTY_HOWTO (R_C6000_SBR_H16_B
),
1044 EMPTY_HOWTO (R_C6000_SBR_H16_H
),
1045 EMPTY_HOWTO (R_C6000_SBR_H16_W
),
1046 HOWTO (R_C6000_SBR_GOT_U15_W
, /* type */
1048 2, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE
, /* pc_relative */
1052 complain_overflow_unsigned
,/* complain_on_overflow */
1053 bfd_elf_generic_reloc
, /* special_function */
1054 "R_C6000_SBR_GOT_U15_W",/* name */
1055 TRUE
, /* partial_inplace */
1056 0x007fff00, /* src_mask */
1057 0x007fff00, /* dst_mask */
1058 FALSE
), /* pcrel_offset */
1059 HOWTO (R_C6000_SBR_GOT_L16_W
, /* type */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE
, /* pc_relative */
1065 complain_overflow_dont
,/* complain_on_overflow */
1066 bfd_elf_generic_reloc
, /* special_function */
1067 "R_C6000_SBR_GOT_L16_W",/* name */
1068 TRUE
, /* partial_inplace */
1069 0x007fff80, /* src_mask */
1070 0x007fff80, /* dst_mask */
1071 FALSE
), /* pcrel_offset */
1072 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W
),
1073 HOWTO (R_C6000_DSBT_INDEX
, /* type */
1075 2, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE
, /* pc_relative */
1079 complain_overflow_unsigned
,/* complain_on_overflow */
1080 bfd_elf_generic_reloc
, /* special_function */
1081 "R_C6000_DSBT_INDEX", /* name */
1082 TRUE
, /* partial_inplace */
1084 0x007fff00, /* dst_mask */
1085 FALSE
), /* pcrel_offset */
1086 HOWTO (R_C6000_PREL31
, /* type */
1088 2, /* size (0 = byte, 1 = short, 2 = long) */
1090 TRUE
, /* pc_relative */
1092 complain_overflow_dont
,/* complain_on_overflow */
1093 bfd_elf_generic_reloc
, /* special_function */
1094 "R_C6000_PREL31", /* name */
1095 TRUE
, /* partial_inplace */
1097 0x7fffffff, /* dst_mask */
1098 TRUE
), /* pcrel_offset */
1099 HOWTO (R_C6000_COPY
, /* type */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 FALSE
, /* pc_relative */
1105 complain_overflow_dont
,/* complain_on_overflow */
1106 bfd_elf_generic_reloc
, /* special_function */
1107 "R_C6000_COPY", /* name */
1108 TRUE
, /* partial_inplace */
1110 0xffffffff, /* dst_mask */
1111 FALSE
), /* pcrel_offset */
1112 HOWTO (R_C6000_JUMP_SLOT
, /* type */
1114 2, /* size (0 = byte, 1 = short, 2 = long) */
1116 FALSE
, /* pc_relative */
1118 complain_overflow_dont
,/* complain_on_overflow */
1119 bfd_elf_generic_reloc
, /* special_function */
1120 "R_C6000_JUMP_SLOT", /* name */
1121 FALSE
, /* partial_inplace */
1123 0xffffffff, /* dst_mask */
1124 FALSE
), /* pcrel_offset */
1125 HOWTO (R_C6000_EHTYPE
, /* type */
1127 2, /* size (0 = byte, 1 = short, 2 = long) */
1129 FALSE
, /* pc_relative */
1131 complain_overflow_dont
,/* complain_on_overflow */
1132 bfd_elf_generic_reloc
, /* special_function */
1133 "R_C6000_EHTYPE", /* name */
1134 FALSE
, /* partial_inplace */
1136 0xffffffff, /* dst_mask */
1137 FALSE
), /* pcrel_offset */
1138 EMPTY_HOWTO (R_C6000_PCR_H16
),
1139 EMPTY_HOWTO (R_C6000_PCR_L16
),
1362 HOWTO (R_C6000_ALIGN
, /* type */
1364 0, /* size (0 = byte, 1 = short, 2 = long) */
1366 FALSE
, /* pc_relative */
1368 complain_overflow_dont
,/* complain_on_overflow */
1369 bfd_elf_generic_reloc
, /* special_function */
1370 "R_C6000_ALIGN", /* name */
1371 TRUE
, /* partial_inplace */
1374 FALSE
), /* pcrel_offset */
1375 HOWTO (R_C6000_FPHEAD
, /* type */
1377 0, /* size (0 = byte, 1 = short, 2 = long) */
1379 FALSE
, /* pc_relative */
1381 complain_overflow_dont
,/* complain_on_overflow */
1382 bfd_elf_generic_reloc
, /* special_function */
1383 "R_C6000_FPHEAD", /* name */
1384 TRUE
, /* partial_inplace */
1387 FALSE
), /* pcrel_offset */
1388 HOWTO (R_C6000_NOCMP
, /* type */
1390 0, /* size (0 = byte, 1 = short, 2 = long) */
1392 FALSE
, /* pc_relative */
1394 complain_overflow_dont
,/* complain_on_overflow */
1395 bfd_elf_generic_reloc
, /* special_function */
1396 "R_C6000_NOCMP", /* name */
1397 TRUE
, /* partial_inplace */
1400 FALSE
) /* pcrel_offset */
1403 /* Map BFD relocations to ELF relocations. */
1407 bfd_reloc_code_real_type bfd_reloc_val
;
1408 enum elf_tic6x_reloc_type elf_reloc_val
;
1411 static const tic6x_reloc_map elf32_tic6x_reloc_map
[] =
1413 { BFD_RELOC_NONE
, R_C6000_NONE
},
1414 { BFD_RELOC_32
, R_C6000_ABS32
},
1415 { BFD_RELOC_16
, R_C6000_ABS16
},
1416 { BFD_RELOC_8
, R_C6000_ABS8
},
1417 { BFD_RELOC_C6000_PCR_S21
, R_C6000_PCR_S21
},
1418 { BFD_RELOC_C6000_PCR_S12
, R_C6000_PCR_S12
},
1419 { BFD_RELOC_C6000_PCR_S10
, R_C6000_PCR_S10
},
1420 { BFD_RELOC_C6000_PCR_S7
, R_C6000_PCR_S7
},
1421 { BFD_RELOC_C6000_ABS_S16
, R_C6000_ABS_S16
},
1422 { BFD_RELOC_C6000_ABS_L16
, R_C6000_ABS_L16
},
1423 { BFD_RELOC_C6000_ABS_H16
, R_C6000_ABS_H16
},
1424 { BFD_RELOC_C6000_SBR_U15_B
, R_C6000_SBR_U15_B
},
1425 { BFD_RELOC_C6000_SBR_U15_H
, R_C6000_SBR_U15_H
},
1426 { BFD_RELOC_C6000_SBR_U15_W
, R_C6000_SBR_U15_W
},
1427 { BFD_RELOC_C6000_SBR_S16
, R_C6000_SBR_S16
},
1428 { BFD_RELOC_C6000_SBR_L16_B
, R_C6000_SBR_L16_B
},
1429 { BFD_RELOC_C6000_SBR_L16_H
, R_C6000_SBR_L16_H
},
1430 { BFD_RELOC_C6000_SBR_L16_W
, R_C6000_SBR_L16_W
},
1431 { BFD_RELOC_C6000_SBR_H16_B
, R_C6000_SBR_H16_B
},
1432 { BFD_RELOC_C6000_SBR_H16_H
, R_C6000_SBR_H16_H
},
1433 { BFD_RELOC_C6000_SBR_H16_W
, R_C6000_SBR_H16_W
},
1434 { BFD_RELOC_C6000_SBR_GOT_U15_W
, R_C6000_SBR_GOT_U15_W
},
1435 { BFD_RELOC_C6000_SBR_GOT_L16_W
, R_C6000_SBR_GOT_L16_W
},
1436 { BFD_RELOC_C6000_SBR_GOT_H16_W
, R_C6000_SBR_GOT_H16_W
},
1437 { BFD_RELOC_C6000_DSBT_INDEX
, R_C6000_DSBT_INDEX
},
1438 { BFD_RELOC_C6000_PREL31
, R_C6000_PREL31
},
1439 { BFD_RELOC_C6000_COPY
, R_C6000_COPY
},
1440 { BFD_RELOC_C6000_JUMP_SLOT
, R_C6000_JUMP_SLOT
},
1441 { BFD_RELOC_C6000_EHTYPE
, R_C6000_EHTYPE
},
1442 { BFD_RELOC_C6000_PCR_H16
, R_C6000_PCR_H16
},
1443 { BFD_RELOC_C6000_PCR_L16
, R_C6000_PCR_L16
},
1444 { BFD_RELOC_C6000_ALIGN
, R_C6000_ALIGN
},
1445 { BFD_RELOC_C6000_FPHEAD
, R_C6000_FPHEAD
},
1446 { BFD_RELOC_C6000_NOCMP
, R_C6000_NOCMP
}
1449 static reloc_howto_type
*
1450 elf32_tic6x_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1454 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_reloc_map
); i
++)
1455 if (elf32_tic6x_reloc_map
[i
].bfd_reloc_val
== code
)
1457 enum elf_tic6x_reloc_type elf_reloc_val
;
1458 reloc_howto_type
*howto
;
1460 elf_reloc_val
= elf32_tic6x_reloc_map
[i
].elf_reloc_val
;
1461 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1462 howto
= &elf32_tic6x_howto_table
[elf_reloc_val
];
1464 howto
= &elf32_tic6x_howto_table_rel
[elf_reloc_val
];
1466 /* Some relocations are RELA-only; do not return them for
1468 if (howto
->name
== NULL
)
1477 static reloc_howto_type
*
1478 elf32_tic6x_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1480 if (elf32_tic6x_tdata (abfd
)->use_rela_p
)
1484 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table
); i
++)
1485 if (elf32_tic6x_howto_table
[i
].name
!= NULL
1486 && strcasecmp (elf32_tic6x_howto_table
[i
].name
, r_name
) == 0)
1487 return &elf32_tic6x_howto_table
[i
];
1493 for (i
= 0; i
< ARRAY_SIZE (elf32_tic6x_howto_table_rel
); i
++)
1494 if (elf32_tic6x_howto_table_rel
[i
].name
!= NULL
1495 && strcasecmp (elf32_tic6x_howto_table_rel
[i
].name
, r_name
) == 0)
1496 return &elf32_tic6x_howto_table_rel
[i
];
1503 elf32_tic6x_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1504 Elf_Internal_Rela
*elf_reloc
)
1506 unsigned int r_type
;
1508 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1509 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table
))
1510 bfd_reloc
->howto
= NULL
;
1512 bfd_reloc
->howto
= &elf32_tic6x_howto_table
[r_type
];
1516 elf32_tic6x_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1517 Elf_Internal_Rela
*elf_reloc
)
1519 unsigned int r_type
;
1521 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1522 if (r_type
>= ARRAY_SIZE (elf32_tic6x_howto_table_rel
))
1523 bfd_reloc
->howto
= NULL
;
1525 bfd_reloc
->howto
= &elf32_tic6x_howto_table_rel
[r_type
];
1529 elf32_tic6x_set_use_rela_p (bfd
*abfd
, bfd_boolean use_rela_p
)
1531 elf32_tic6x_tdata (abfd
)->use_rela_p
= use_rela_p
;
1534 /* Create an entry in a C6X ELF linker hash table. */
1536 static struct bfd_hash_entry
*
1537 elf32_tic6x_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1538 struct bfd_hash_table
*table
,
1541 /* Allocate the structure if it has not already been allocated by a
1545 entry
= bfd_hash_allocate (table
,
1546 sizeof (struct elf32_tic6x_link_hash_entry
));
1551 /* Call the allocation method of the superclass. */
1552 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1555 struct elf32_tic6x_link_hash_entry
*eh
;
1557 eh
= (struct elf32_tic6x_link_hash_entry
*) entry
;
1558 eh
->dyn_relocs
= NULL
;
1564 /* Create a C6X ELF linker hash table. */
1566 static struct bfd_link_hash_table
*
1567 elf32_tic6x_link_hash_table_create (bfd
*abfd
)
1569 struct elf32_tic6x_link_hash_table
*ret
;
1570 bfd_size_type amt
= sizeof (struct elf32_tic6x_link_hash_table
);
1572 ret
= bfd_zmalloc (amt
);
1576 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1577 elf32_tic6x_link_hash_newfunc
,
1578 sizeof (struct elf32_tic6x_link_hash_entry
),
1586 ret
->elf
.is_relocatable_executable
= 1;
1588 return &ret
->elf
.root
;
1592 elf32_tic6x_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
1594 if (bfd_link_pic (info
))
1596 obj_attribute
*out_attr
;
1597 out_attr
= elf_known_obj_attributes_proc (abfd
);
1598 if (out_attr
[Tag_ABI_PIC
].i
== 0)
1600 _bfd_error_handler (_("warning: generating a shared library "
1601 "containing non-PIC code"));
1603 if (out_attr
[Tag_ABI_PID
].i
== 0)
1605 _bfd_error_handler (_("warning: generating a shared library "
1606 "containing non-PID code"));
1609 /* Invoke the regular ELF backend linker to do all the work. */
1610 if (!bfd_elf_final_link (abfd
, info
))
1616 /* Called to pass PARAMS to the backend. We store them in the hash table
1617 associated with INFO. */
1620 elf32_tic6x_setup (struct bfd_link_info
*info
,
1621 struct elf32_tic6x_params
*params
)
1623 struct elf32_tic6x_link_hash_table
*htab
= elf32_tic6x_hash_table (info
);
1624 htab
->params
= *params
;
1627 /* Determine if we're dealing with a DSBT object. */
1630 elf32_tic6x_using_dsbt (bfd
*abfd
)
1632 return bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
,
1636 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1637 sections in DYNOBJ, and set up shortcuts to them in our hash
1641 elf32_tic6x_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1643 struct elf32_tic6x_link_hash_table
*htab
;
1646 htab
= elf32_tic6x_hash_table (info
);
1650 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1654 flags
= (SEC_ALLOC
| SEC_LOAD
1655 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1656 htab
->dsbt
= bfd_make_section_anyway_with_flags (dynobj
, ".dsbt",
1658 if (htab
->dsbt
== NULL
1659 || ! bfd_set_section_alignment (dynobj
, htab
->dsbt
, 2)
1660 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.splt
, 5))
1663 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
1664 if (!bfd_link_pic (info
))
1665 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
1668 || (!bfd_link_pic (info
) && !htab
->srelbss
))
1675 elf32_tic6x_mkobject (bfd
*abfd
)
1679 ret
= bfd_elf_allocate_object (abfd
, sizeof (struct elf32_tic6x_obj_tdata
),
1682 elf32_tic6x_set_use_rela_p (abfd
, TRUE
);
1686 /* Install relocation RELA into section SRELA, incrementing its
1690 elf32_tic6x_install_rela (bfd
*output_bfd
, asection
*srela
,
1691 Elf_Internal_Rela
*rela
)
1694 bfd_vma off
= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1695 loc
= srela
->contents
+ off
;
1696 BFD_ASSERT (off
< srela
->size
);
1697 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
1700 /* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1701 of the GOT at this offset have been initialized with the relocation. */
1704 elf32_tic6x_make_got_dynreloc (bfd
*output_bfd
,
1705 struct elf32_tic6x_link_hash_table
*htab
,
1706 asection
*sym_sec
, bfd_vma offset
)
1708 asection
*sgot
= htab
->elf
.sgot
;
1709 Elf_Internal_Rela outrel
;
1712 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
1713 outrel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
1714 if (sym_sec
&& sym_sec
->output_section
1715 && ! bfd_is_abs_section (sym_sec
->output_section
)
1716 && ! bfd_is_und_section (sym_sec
->output_section
))
1718 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
1719 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
1725 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_C6000_ABS32
);
1726 elf32_tic6x_install_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
1729 /* Finish up dynamic symbol handling. We set the contents of various
1730 dynamic sections here. */
1733 elf32_tic6x_finish_dynamic_symbol (bfd
* output_bfd
,
1734 struct bfd_link_info
*info
,
1735 struct elf_link_hash_entry
*h
,
1736 Elf_Internal_Sym
* sym
)
1739 struct elf32_tic6x_link_hash_table
*htab
;
1741 htab
= elf32_tic6x_hash_table (info
);
1742 dynobj
= htab
->elf
.dynobj
;
1744 if (h
->plt
.offset
!= (bfd_vma
) -1)
1747 bfd_vma got_section_offset
, got_dp_offset
, rela_offset
;
1748 Elf_Internal_Rela rela
;
1750 asection
*plt
, *gotplt
, *relplt
;
1751 const struct elf_backend_data
*bed
;
1753 bed
= get_elf_backend_data (output_bfd
);
1755 BFD_ASSERT (htab
->elf
.splt
!= NULL
);
1756 plt
= htab
->elf
.splt
;
1757 gotplt
= htab
->elf
.sgotplt
;
1758 relplt
= htab
->elf
.srelplt
;
1760 /* This symbol has an entry in the procedure linkage table. Set
1763 if ((h
->dynindx
== -1
1764 && !((h
->forced_local
|| bfd_link_executable (info
))
1766 && h
->type
== STT_GNU_IFUNC
))
1772 /* Get the index in the procedure linkage table which
1773 corresponds to this symbol. This is the index of this symbol
1774 in all the symbols for which we are making plt entries. The
1775 first entry in the procedure linkage table is reserved.
1777 Get the offset into the .got table of the entry that
1778 corresponds to this function. Each .got entry is 4 bytes.
1779 The first three are reserved.
1781 For static executables, we don't reserve anything. */
1783 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1784 got_section_offset
= plt_index
+ bed
->got_header_size
/ 4;
1785 got_dp_offset
= got_section_offset
+ htab
->params
.dsbt_size
;
1786 rela_offset
= plt_index
* sizeof (Elf32_External_Rela
);
1788 got_section_offset
*= 4;
1790 /* Fill in the entry in the procedure linkage table. */
1792 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1793 bfd_put_32 (output_bfd
, got_dp_offset
<< 8 | 0x0100006e,
1794 plt
->contents
+ h
->plt
.offset
);
1795 /* mvk .s2 low(rela_offset), b0 */
1796 bfd_put_32 (output_bfd
, (rela_offset
& 0xffff) << 7 | 0x0000002a,
1797 plt
->contents
+ h
->plt
.offset
+ 4);
1798 /* mvkh .s2 high(rela_offset), b0 */
1799 bfd_put_32 (output_bfd
, ((rela_offset
>> 16) & 0xffff) << 7 | 0x0000006a,
1800 plt
->contents
+ h
->plt
.offset
+ 8);
1802 bfd_put_32 (output_bfd
, 0x00002000,
1803 plt
->contents
+ h
->plt
.offset
+ 12);
1805 bfd_put_32 (output_bfd
, 0x00080362,
1806 plt
->contents
+ h
->plt
.offset
+ 16);
1808 bfd_put_32 (output_bfd
, 0x00008000,
1809 plt
->contents
+ h
->plt
.offset
+ 20);
1811 /* Fill in the entry in the global offset table. */
1812 bfd_put_32 (output_bfd
,
1813 (plt
->output_section
->vma
+ plt
->output_offset
),
1814 gotplt
->contents
+ got_section_offset
);
1816 /* Fill in the entry in the .rel.plt section. */
1817 rela
.r_offset
= (gotplt
->output_section
->vma
1818 + gotplt
->output_offset
1819 + got_section_offset
);
1820 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_JUMP_SLOT
);
1822 loc
= relplt
->contents
+ rela_offset
;
1823 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1825 if (!h
->def_regular
)
1827 /* Mark the symbol as undefined, rather than as defined in
1828 the .plt section. */
1829 sym
->st_shndx
= SHN_UNDEF
;
1834 if (h
->got
.offset
!= (bfd_vma
) -1)
1839 /* This symbol has an entry in the global offset table.
1842 sgot
= bfd_get_linker_section (dynobj
, ".got");
1843 srela
= bfd_get_linker_section (dynobj
, ".rela.got");
1844 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1846 /* If this is a -Bsymbolic link, and the symbol is defined
1847 locally, we just want to emit a RELATIVE reloc. Likewise if
1848 the symbol was forced to be local because of a version file.
1849 The entry in the global offset table will already have been
1850 initialized in the relocate_section function. */
1851 if (bfd_link_pic (info
)
1852 && (SYMBOLIC_BIND (info
, h
)
1853 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
1855 asection
*s
= h
->root
.u
.def
.section
;
1856 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, s
,
1857 h
->got
.offset
& ~(bfd_vma
) 1);
1861 Elf_Internal_Rela outrel
;
1862 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1863 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
1864 outrel
.r_offset
= (sgot
->output_section
->vma
1865 + sgot
->output_offset
1866 + (h
->got
.offset
& ~(bfd_vma
) 1));
1867 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_ABS32
);
1868 outrel
.r_addend
= 0;
1870 elf32_tic6x_install_rela (output_bfd
, srela
, &outrel
);
1876 Elf_Internal_Rela rel
;
1878 /* This symbol needs a copy reloc. Set it up. */
1880 if (h
->dynindx
== -1
1881 || (h
->root
.type
!= bfd_link_hash_defined
1882 && h
->root
.type
!= bfd_link_hash_defweak
)
1883 || htab
->srelbss
== NULL
)
1886 rel
.r_offset
= (h
->root
.u
.def
.value
1887 + h
->root
.u
.def
.section
->output_section
->vma
1888 + h
->root
.u
.def
.section
->output_offset
);
1889 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_C6000_COPY
);
1892 elf32_tic6x_install_rela (output_bfd
, htab
->srelbss
, &rel
);
1895 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1896 if (h
== elf_hash_table (info
)->hdynamic
1897 || h
== elf_hash_table (info
)->hgot
)
1898 sym
->st_shndx
= SHN_ABS
;
1903 /* Unwinding tables are not referenced directly. This pass marks them as
1904 required if the corresponding code section is marked. */
1907 elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info
*info
,
1908 elf_gc_mark_hook_fn gc_mark_hook
)
1911 Elf_Internal_Shdr
**elf_shdrp
;
1914 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
1916 /* Marking EH data may cause additional code sections to be marked,
1917 requiring multiple passes. */
1922 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
1926 if (! is_tic6x_elf (sub
))
1929 elf_shdrp
= elf_elfsections (sub
);
1930 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
1932 Elf_Internal_Shdr
*hdr
;
1934 hdr
= &elf_section_data (o
)->this_hdr
;
1935 if (hdr
->sh_type
== SHT_C6000_UNWIND
1937 && hdr
->sh_link
< elf_numsections (sub
)
1939 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
1942 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
1952 /* Return TRUE if this is an unwinding table index. */
1955 is_tic6x_elf_unwind_section_name (const char *name
)
1957 return (CONST_STRNEQ (name
, ELF_STRING_C6000_unwind
)
1958 || CONST_STRNEQ (name
, ELF_STRING_C6000_unwind_once
));
1962 /* Set the type and flags for an unwinding index table. We do this by
1963 the section name, which is a hack, but ought to work. */
1966 elf32_tic6x_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1967 Elf_Internal_Shdr
*hdr
, asection
*sec
)
1971 name
= bfd_get_section_name (abfd
, sec
);
1973 if (is_tic6x_elf_unwind_section_name (name
))
1975 hdr
->sh_type
= SHT_C6000_UNWIND
;
1976 hdr
->sh_flags
|= SHF_LINK_ORDER
;
1982 /* Update the got entry reference counts for the section being removed. */
1985 elf32_tic6x_gc_sweep_hook (bfd
*abfd
,
1986 struct bfd_link_info
*info
,
1988 const Elf_Internal_Rela
*relocs
)
1990 struct elf32_tic6x_link_hash_table
*htab
;
1991 Elf_Internal_Shdr
*symtab_hdr
;
1992 struct elf_link_hash_entry
**sym_hashes
;
1993 bfd_signed_vma
*local_got_refcounts
;
1994 const Elf_Internal_Rela
*rel
, *relend
;
1996 if (bfd_link_relocatable (info
))
1999 htab
= elf32_tic6x_hash_table (info
);
2003 elf_section_data (sec
)->local_dynrel
= NULL
;
2005 symtab_hdr
= &elf_symtab_hdr (abfd
);
2006 sym_hashes
= elf_sym_hashes (abfd
);
2007 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2009 relend
= relocs
+ sec
->reloc_count
;
2010 for (rel
= relocs
; rel
< relend
; rel
++)
2012 unsigned long r_symndx
;
2013 unsigned int r_type
;
2014 struct elf_link_hash_entry
*h
= NULL
;
2016 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2017 if (r_symndx
>= symtab_hdr
->sh_info
)
2019 struct elf32_tic6x_link_hash_entry
*eh
;
2020 struct elf_dyn_relocs
**pp
;
2021 struct elf_dyn_relocs
*p
;
2023 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2024 while (h
->root
.type
== bfd_link_hash_indirect
2025 || h
->root
.type
== bfd_link_hash_warning
)
2026 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2027 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
2029 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2032 /* Everything must go for SEC. */
2038 r_type
= ELF32_R_TYPE (rel
->r_info
);
2042 case R_C6000_SBR_GOT_U15_W
:
2043 case R_C6000_SBR_GOT_L16_W
:
2044 case R_C6000_SBR_GOT_H16_W
:
2045 case R_C6000_EHTYPE
:
2048 if (h
->got
.refcount
> 0)
2049 h
->got
.refcount
-= 1;
2051 else if (local_got_refcounts
!= NULL
)
2053 if (local_got_refcounts
[r_symndx
] > 0)
2054 local_got_refcounts
[r_symndx
] -= 1;
2066 /* Adjust a symbol defined by a dynamic object and referenced by a
2067 regular object. The current definition is in some section of the
2068 dynamic object, but we're not including those sections. We have to
2069 change the definition to something the rest of the link can
2073 elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2074 struct elf_link_hash_entry
*h
)
2076 struct elf32_tic6x_link_hash_table
*htab
;
2080 dynobj
= elf_hash_table (info
)->dynobj
;
2082 /* Make sure we know what is going on here. */
2083 BFD_ASSERT (dynobj
!= NULL
2085 || h
->u
.weakdef
!= NULL
2086 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
2088 /* If this is a function, put it in the procedure linkage table. We
2089 will fill in the contents of the procedure linkage table later,
2090 when we know the address of the .got section. */
2091 if (h
->type
== STT_FUNC
2094 if (h
->plt
.refcount
<= 0
2095 || SYMBOL_CALLS_LOCAL (info
, h
)
2096 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2097 && h
->root
.type
== bfd_link_hash_undefweak
))
2099 /* This case can occur if we saw a PLT32 reloc in an input
2100 file, but the symbol was never referred to by a dynamic
2101 object, or if all references were garbage collected. In
2102 such a case, we don't actually need to build a procedure
2103 linkage table, and we can just do a PC32 reloc instead. */
2104 h
->plt
.offset
= (bfd_vma
) -1;
2111 /* If this is a weak symbol, and there is a real definition, the
2112 processor independent code will have arranged for us to see the
2113 real definition first, and we can just use the same value. */
2114 if (h
->u
.weakdef
!= NULL
)
2116 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2117 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2118 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2119 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2120 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2124 /* This is a reference to a symbol defined by a dynamic object which
2125 is not a function. */
2127 /* If we are creating a shared library, we must presume that the
2128 only references to the symbol are via the global offset table.
2129 For such cases we need not do anything here; the relocations will
2130 be handled correctly by relocate_section. */
2131 if (bfd_link_pic (info
))
2134 /* If there are no references to this symbol that do not use the
2135 GOT, we don't need to generate a copy reloc. */
2136 if (!h
->non_got_ref
)
2139 /* If -z nocopyreloc was given, we won't generate them either. */
2140 if (info
->nocopyreloc
)
2146 htab
= elf32_tic6x_hash_table (info
);
2150 /* We must allocate the symbol in our .dynbss section, which will
2151 become part of the .bss section of the executable. There will be
2152 an entry for this symbol in the .dynsym section. The dynamic
2153 object will contain position independent code, so all references
2154 from the dynamic object to this symbol will go through the global
2155 offset table. The dynamic linker will use the .dynsym entry to
2156 determine the address it must put in the global offset table, so
2157 both the dynamic object and the regular object will refer to the
2158 same memory location for the variable. */
2160 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2161 copy the initial value out of the dynamic object and into the
2162 runtime process image. */
2163 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2165 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
2171 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2175 elf32_tic6x_new_section_hook (bfd
*abfd
, asection
*sec
)
2179 /* Allocate target specific section data. */
2180 if (!sec
->used_by_bfd
)
2182 _tic6x_elf_section_data
*sdata
;
2183 bfd_size_type amt
= sizeof (*sdata
);
2185 sdata
= (_tic6x_elf_section_data
*) bfd_zalloc (abfd
, amt
);
2188 sec
->used_by_bfd
= sdata
;
2191 ret
= _bfd_elf_new_section_hook (abfd
, sec
);
2192 sec
->use_rela_p
= elf32_tic6x_tdata (abfd
)->use_rela_p
;
2197 /* Return true if relocation REL against section SEC is a REL rather
2198 than RELA relocation. RELOCS is the first relocation in the
2199 section and ABFD is the bfd that contains SEC. */
2202 elf32_tic6x_rel_relocation_p (bfd
*abfd
, asection
*sec
,
2203 const Elf_Internal_Rela
*relocs
,
2204 const Elf_Internal_Rela
*rel
)
2206 Elf_Internal_Shdr
*rel_hdr
;
2207 const struct elf_backend_data
*bed
;
2209 /* To determine which flavor of relocation this is, we depend on the
2210 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2211 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
2212 if (rel_hdr
== NULL
)
2214 bed
= get_elf_backend_data (abfd
);
2215 return ((size_t) (rel
- relocs
)
2216 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
2219 /* We need dynamic symbols for every section, since segments can
2220 relocate independently. */
2222 elf32_tic6x_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2223 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2226 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2230 /* If sh_type is yet undecided, assume it could be
2231 SHT_PROGBITS/SHT_NOBITS. */
2235 /* There shouldn't be section relative relocations
2236 against any other section. */
2243 elf32_tic6x_relocate_section (bfd
*output_bfd
,
2244 struct bfd_link_info
*info
,
2246 asection
*input_section
,
2248 Elf_Internal_Rela
*relocs
,
2249 Elf_Internal_Sym
*local_syms
,
2250 asection
**local_sections
)
2252 struct elf32_tic6x_link_hash_table
*htab
;
2253 Elf_Internal_Shdr
*symtab_hdr
;
2254 struct elf_link_hash_entry
**sym_hashes
;
2255 bfd_vma
*local_got_offsets
;
2256 Elf_Internal_Rela
*rel
;
2257 Elf_Internal_Rela
*relend
;
2258 bfd_boolean ok
= TRUE
;
2260 htab
= elf32_tic6x_hash_table (info
);
2261 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
2262 sym_hashes
= elf_sym_hashes (input_bfd
);
2263 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2265 relend
= relocs
+ input_section
->reloc_count
;
2267 for (rel
= relocs
; rel
< relend
; rel
++)
2270 unsigned long r_symndx
;
2272 reloc_howto_type
*howto
;
2273 Elf_Internal_Sym
*sym
;
2275 struct elf_link_hash_entry
*h
;
2276 bfd_vma off
, off2
, relocation
;
2277 bfd_boolean unresolved_reloc
;
2278 bfd_reloc_status_type r
;
2279 struct bfd_link_hash_entry
*sbh
;
2282 r_type
= ELF32_R_TYPE (rel
->r_info
);
2283 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2285 is_rel
= elf32_tic6x_rel_relocation_p (input_bfd
, input_section
,
2289 elf32_tic6x_info_to_howto_rel (input_bfd
, &bfd_reloc
, rel
);
2291 elf32_tic6x_info_to_howto (input_bfd
, &bfd_reloc
, rel
);
2292 howto
= bfd_reloc
.howto
;
2295 bfd_set_error (bfd_error_bad_value
);
2302 unresolved_reloc
= FALSE
;
2304 if (r_symndx
< symtab_hdr
->sh_info
)
2306 sym
= local_syms
+ r_symndx
;
2307 sec
= local_sections
[r_symndx
];
2308 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2312 bfd_boolean warned
, ignored
;
2314 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2315 r_symndx
, symtab_hdr
, sym_hashes
,
2317 unresolved_reloc
, warned
, ignored
);
2320 if (sec
!= NULL
&& discarded_section (sec
))
2321 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2322 rel
, 1, relend
, howto
, 0, contents
);
2324 if (bfd_link_relocatable (info
))
2328 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2331 relocation
= sec
->output_offset
+ sym
->st_value
;
2332 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
2333 contents
+ rel
->r_offset
);
2343 case R_C6000_FPHEAD
:
2345 /* No action needed. */
2348 case R_C6000_PCR_S21
:
2349 /* A branch to an undefined weak symbol is turned into a
2350 "b .s2 B3" instruction if the existing insn is of the
2351 form "b .s2 symbol". */
2352 if (h
? h
->root
.type
== bfd_link_hash_undefweak
2353 && (htab
->elf
.splt
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
2354 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2356 unsigned long oldval
;
2357 oldval
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2359 if ((oldval
& 0x7e) == 0x12)
2361 oldval
&= 0xF0000001;
2362 bfd_put_32 (input_bfd
, oldval
| 0x000c0362,
2363 contents
+ rel
->r_offset
);
2369 case R_C6000_PCR_S12
:
2370 case R_C6000_PCR_S10
:
2371 case R_C6000_PCR_S7
:
2373 && h
->plt
.offset
!= (bfd_vma
) -1
2374 && htab
->elf
.splt
!= NULL
)
2376 relocation
= (htab
->elf
.splt
->output_section
->vma
2377 + htab
->elf
.splt
->output_offset
2381 /* Generic PC-relative handling produces a value relative to
2382 the exact location of the relocation. Adjust it to be
2383 relative to the start of the fetch packet instead. */
2384 relocation
+= (input_section
->output_section
->vma
2385 + input_section
->output_offset
2386 + rel
->r_offset
) & 0x1f;
2387 unresolved_reloc
= FALSE
;
2390 case R_C6000_PCR_H16
:
2391 case R_C6000_PCR_L16
:
2392 off
= (input_section
->output_section
->vma
2393 + input_section
->output_offset
2395 /* These must be calculated as R = S - FP(FP(PC) - A).
2396 PC, here, is the value we just computed in OFF. RELOCATION
2397 has the address of S + A. */
2398 relocation
-= rel
->r_addend
;
2399 off2
= ((off
& ~(bfd_vma
)0x1f) - rel
->r_addend
) & (bfd_vma
)~0x1f;
2400 off2
= relocation
- off2
;
2401 relocation
= off
+ off2
;
2404 case R_C6000_DSBT_INDEX
:
2405 relocation
= elf32_tic6x_hash_table (info
)->params
.dsbt_index
;
2406 if (!bfd_link_pic (info
) || relocation
!= 0)
2413 case R_C6000_ABS_S16
:
2414 case R_C6000_ABS_L16
:
2415 case R_C6000_ABS_H16
:
2416 /* When generating a shared object or relocatable executable, these
2417 relocations are copied into the output file to be resolved at
2419 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2420 && (input_section
->flags
& SEC_ALLOC
)
2422 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2423 || h
->root
.type
!= bfd_link_hash_undefweak
))
2425 Elf_Internal_Rela outrel
;
2426 bfd_boolean skip
, relocate
;
2429 unresolved_reloc
= FALSE
;
2431 sreloc
= elf_section_data (input_section
)->sreloc
;
2432 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
2438 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2440 if (outrel
.r_offset
== (bfd_vma
) -1)
2442 else if (outrel
.r_offset
== (bfd_vma
) -2)
2443 skip
= TRUE
, relocate
= TRUE
;
2444 outrel
.r_offset
+= (input_section
->output_section
->vma
2445 + input_section
->output_offset
);
2448 memset (&outrel
, 0, sizeof outrel
);
2451 && (!bfd_link_pic (info
)
2452 || !SYMBOLIC_BIND (info
, h
)
2453 || !h
->def_regular
))
2455 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2456 outrel
.r_addend
= rel
->r_addend
;
2462 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2464 if (bfd_is_abs_section (sec
))
2466 else if (sec
== NULL
|| sec
->owner
== NULL
)
2468 bfd_set_error (bfd_error_bad_value
);
2475 osec
= sec
->output_section
;
2476 indx
= elf_section_data (osec
)->dynindx
;
2477 outrel
.r_addend
-= osec
->vma
;
2478 BFD_ASSERT (indx
!= 0);
2481 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2484 elf32_tic6x_install_rela (output_bfd
, sreloc
, &outrel
);
2486 /* If this reloc is against an external symbol, we do not want to
2487 fiddle with the addend. Otherwise, we need to include the symbol
2488 value so that it becomes an addend for the dynamic reloc. */
2493 /* Generic logic OK. */
2496 case R_C6000_SBR_U15_B
:
2497 case R_C6000_SBR_U15_H
:
2498 case R_C6000_SBR_U15_W
:
2499 case R_C6000_SBR_S16
:
2500 case R_C6000_SBR_L16_B
:
2501 case R_C6000_SBR_L16_H
:
2502 case R_C6000_SBR_L16_W
:
2503 case R_C6000_SBR_H16_B
:
2504 case R_C6000_SBR_H16_H
:
2505 case R_C6000_SBR_H16_W
:
2506 sbh
= bfd_link_hash_lookup (info
->hash
, "__c6xabi_DSBT_BASE",
2507 FALSE
, FALSE
, TRUE
);
2509 && (sbh
->type
== bfd_link_hash_defined
2510 || sbh
->type
== bfd_link_hash_defweak
))
2512 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
2513 && (htab
->elf
.splt
== NULL
2514 || h
->plt
.offset
== (bfd_vma
) -1))
2515 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sec
))
2518 relocation
-= (sbh
->u
.def
.value
2519 + sbh
->u
.def
.section
->output_section
->vma
2520 + sbh
->u
.def
.section
->output_offset
);
2524 (*_bfd_error_handler
) (_("%B: SB-relative relocation but "
2525 "__c6xabi_DSBT_BASE not defined"),
2532 case R_C6000_SBR_GOT_U15_W
:
2533 case R_C6000_SBR_GOT_L16_W
:
2534 case R_C6000_SBR_GOT_H16_W
:
2535 case R_C6000_EHTYPE
:
2536 /* Relocation is to the entry for this symbol in the global
2538 if (htab
->elf
.sgot
== NULL
)
2545 off
= h
->got
.offset
;
2546 dyn
= htab
->elf
.dynamic_sections_created
;
2547 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2548 bfd_link_pic (info
),
2550 || (bfd_link_pic (info
)
2551 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2552 || (ELF_ST_VISIBILITY (h
->other
)
2553 && h
->root
.type
== bfd_link_hash_undefweak
))
2555 /* This is actually a static link, or it is a
2556 -Bsymbolic link and the symbol is defined
2557 locally, or the symbol was forced to be local
2558 because of a version file. We must initialize
2559 this entry in the global offset table. Since the
2560 offset must always be a multiple of 4, we use the
2561 least significant bit to record whether we have
2562 initialized it already.
2564 When doing a dynamic link, we create a .rel.got
2565 relocation entry to initialize the value. This
2566 is done in the finish_dynamic_symbol routine. */
2571 bfd_put_32 (output_bfd
, relocation
,
2572 htab
->elf
.sgot
->contents
+ off
);
2575 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2576 bfd_link_pic (info
),
2578 && !(ELF_ST_VISIBILITY (h
->other
)
2579 && h
->root
.type
== bfd_link_hash_undefweak
))
2580 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
,
2585 unresolved_reloc
= FALSE
;
2589 if (local_got_offsets
== NULL
)
2592 off
= local_got_offsets
[r_symndx
];
2594 /* The offset must always be a multiple of 4. We use
2595 the least significant bit to record whether we have
2596 already generated the necessary reloc. */
2601 bfd_put_32 (output_bfd
, relocation
,
2602 htab
->elf
.sgot
->contents
+ off
);
2604 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
2605 elf32_tic6x_make_got_dynreloc (output_bfd
, htab
, sec
, off
);
2607 local_got_offsets
[r_symndx
] |= 1;
2611 if (off
>= (bfd_vma
) -2)
2615 relocation
= (htab
->elf
.sgot
->output_section
->vma
2616 + htab
->elf
.sgot
->output_offset
+ off
2617 - htab
->dsbt
->output_section
->vma
2618 - htab
->dsbt
->output_offset
);
2620 relocation
= (htab
->elf
.sgot
->output_section
->vma
2621 + htab
->elf
.sgot
->output_offset
+ off
2622 - htab
->elf
.sgotplt
->output_section
->vma
2623 - htab
->elf
.sgotplt
->output_offset
);
2625 if (rel
->r_addend
!= 0)
2627 /* We can't do anything for a relocation which is against
2628 a symbol *plus offset*. GOT holds relocations for
2629 symbols. Make this an error; the compiler isn't
2630 allowed to pass us these kinds of things. */
2632 (*_bfd_error_handler
)
2633 (_("%B, section %A: relocation %s with non-zero addend %d"
2634 " against local symbol"),
2637 elf32_tic6x_howto_table
[r_type
].name
,
2640 (*_bfd_error_handler
)
2641 (_("%B, section %A: relocation %s with non-zero addend %d"
2642 " against symbol `%s'"),
2645 elf32_tic6x_howto_table
[r_type
].name
,
2647 h
->root
.root
.string
[0] != '\0' ? h
->root
.root
.string
2648 : _("[whose name is lost]"));
2650 bfd_set_error (bfd_error_bad_value
);
2655 case R_C6000_PREL31
:
2657 && h
->plt
.offset
!= (bfd_vma
) -1
2658 && htab
->elf
.splt
!= NULL
)
2660 relocation
= (htab
->elf
.splt
->output_section
->vma
2661 + htab
->elf
.splt
->output_offset
2667 /* Invalid in relocatable object. */
2669 /* Unknown relocation. */
2670 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2676 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2677 contents
, rel
->r_offset
,
2678 relocation
, rel
->r_addend
);
2681 if (r
== bfd_reloc_ok
2682 && howto
->complain_on_overflow
== complain_overflow_bitfield
)
2684 /* Generic overflow handling accepts cases the ABI says
2685 should be rejected for R_C6000_ABS16 and
2687 bfd_vma value
= (relocation
+ rel
->r_addend
) & 0xffffffff;
2688 bfd_vma sbit
= 1 << (howto
->bitsize
- 1);
2689 bfd_vma sbits
= (-(bfd_vma
) sbit
) & 0xffffffff;
2690 bfd_vma value_sbits
= value
& sbits
;
2692 if (value_sbits
!= 0
2693 && value_sbits
!= sbit
2694 && value_sbits
!= sbits
)
2695 r
= bfd_reloc_overflow
;
2698 if (r
!= bfd_reloc_ok
)
2701 const char *error_message
;
2704 name
= h
->root
.root
.string
;
2707 name
= bfd_elf_string_from_elf_section (input_bfd
,
2708 symtab_hdr
->sh_link
,
2713 name
= bfd_section_name (input_bfd
, sec
);
2718 case bfd_reloc_overflow
:
2719 /* If the overflowing reloc was to an undefined symbol,
2720 we have already printed one error message and there
2721 is no point complaining again. */
2723 h
->root
.type
!= bfd_link_hash_undefined
)
2724 && (!((*info
->callbacks
->reloc_overflow
)
2725 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2726 (bfd_vma
) 0, input_bfd
, input_section
,
2731 case bfd_reloc_undefined
:
2732 if (!((*info
->callbacks
->undefined_symbol
)
2733 (info
, name
, input_bfd
, input_section
,
2734 rel
->r_offset
, TRUE
)))
2738 case bfd_reloc_outofrange
:
2739 error_message
= _("out of range");
2742 case bfd_reloc_notsupported
:
2743 error_message
= _("unsupported relocation");
2746 case bfd_reloc_dangerous
:
2747 error_message
= _("dangerous relocation");
2751 error_message
= _("unknown error");
2755 BFD_ASSERT (error_message
!= NULL
);
2756 if (!((*info
->callbacks
->reloc_dangerous
)
2757 (info
, error_message
, input_bfd
, input_section
,
2769 /* Look through the relocs for a section during the first phase, and
2770 calculate needed space in the global offset table, procedure linkage
2771 table, and dynamic reloc sections. */
2774 elf32_tic6x_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2775 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2777 struct elf32_tic6x_link_hash_table
*htab
;
2778 Elf_Internal_Shdr
*symtab_hdr
;
2779 struct elf_link_hash_entry
**sym_hashes
;
2780 const Elf_Internal_Rela
*rel
;
2781 const Elf_Internal_Rela
*rel_end
;
2784 if (bfd_link_relocatable (info
))
2787 htab
= elf32_tic6x_hash_table (info
);
2788 symtab_hdr
= &elf_symtab_hdr (abfd
);
2789 sym_hashes
= elf_sym_hashes (abfd
);
2791 /* Create dynamic sections for relocatable executables so that we can
2792 copy relocations. */
2793 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2794 && ! htab
->elf
.dynamic_sections_created
)
2796 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2802 rel_end
= relocs
+ sec
->reloc_count
;
2803 for (rel
= relocs
; rel
< rel_end
; rel
++)
2805 unsigned int r_type
;
2806 unsigned long r_symndx
;
2807 struct elf_link_hash_entry
*h
;
2808 Elf_Internal_Sym
*isym
;
2810 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2811 r_type
= ELF32_R_TYPE (rel
->r_info
);
2813 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2815 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
2821 if (r_symndx
< symtab_hdr
->sh_info
)
2823 /* A local symbol. */
2824 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2833 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2834 while (h
->root
.type
== bfd_link_hash_indirect
2835 || h
->root
.type
== bfd_link_hash_warning
)
2836 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2838 /* PR15323, ref flags aren't set for references in the same
2840 h
->root
.non_ir_ref
= 1;
2845 case R_C6000_PCR_S21
:
2846 case R_C6000_PREL31
:
2847 /* This symbol requires a procedure linkage table entry. We
2848 actually build the entry in adjust_dynamic_symbol,
2849 because this might be a case of linking PIC code which is
2850 never referenced by a dynamic object, in which case we
2851 don't need to generate a procedure linkage table entry
2854 /* If this is a local symbol, we resolve it directly without
2855 creating a procedure linkage table entry. */
2860 h
->plt
.refcount
+= 1;
2863 case R_C6000_SBR_GOT_U15_W
:
2864 case R_C6000_SBR_GOT_L16_W
:
2865 case R_C6000_SBR_GOT_H16_W
:
2866 case R_C6000_EHTYPE
:
2867 /* This symbol requires a global offset table entry. */
2870 h
->got
.refcount
+= 1;
2874 bfd_signed_vma
*local_got_refcounts
;
2876 /* This is a global offset table entry for a local symbol. */
2877 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2878 if (local_got_refcounts
== NULL
)
2882 size
= symtab_hdr
->sh_info
;
2883 size
*= (sizeof (bfd_signed_vma
)
2884 + sizeof (bfd_vma
) + sizeof(char));
2885 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2886 if (local_got_refcounts
== NULL
)
2888 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2890 local_got_refcounts
[r_symndx
] += 1;
2893 if (htab
->elf
.sgot
== NULL
)
2895 if (htab
->elf
.dynobj
== NULL
)
2896 htab
->elf
.dynobj
= abfd
;
2897 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2902 case R_C6000_DSBT_INDEX
:
2903 /* We'd like to check for nonzero dsbt_index here, but it's
2904 set up only after check_relocs is called. Instead, we
2905 store the number of R_C6000_DSBT_INDEX relocs in the
2906 pc_count field, and potentially discard the extra space
2907 in elf32_tic6x_allocate_dynrelocs. */
2908 if (!bfd_link_pic (info
))
2915 case R_C6000_ABS_S16
:
2916 case R_C6000_ABS_L16
:
2917 case R_C6000_ABS_H16
:
2918 /* If we are creating a shared library, and this is a reloc
2919 against a global symbol, or a non PC relative reloc
2920 against a local symbol, then we need to copy the reloc
2921 into the shared library. However, if we are linking with
2922 -Bsymbolic, we do not need to copy a reloc against a
2923 global symbol which is defined in an object we are
2924 including in the link (i.e., DEF_REGULAR is set). At
2925 this point we have not seen all the input files, so it is
2926 possible that DEF_REGULAR is not set now but will be set
2927 later (it is never cleared). In case of a weak definition,
2928 DEF_REGULAR may be cleared later by a strong definition in
2929 a shared library. We account for that possibility below by
2930 storing information in the relocs_copied field of the hash
2931 table entry. A similar situation occurs when creating
2932 shared libraries and symbol visibility changes render the
2935 If on the other hand, we are creating an executable, we
2936 may need to keep relocations for symbols satisfied by a
2937 dynamic library if we manage to avoid copy relocs for the
2939 if ((bfd_link_pic (info
) || elf32_tic6x_using_dsbt (abfd
))
2940 && (sec
->flags
& SEC_ALLOC
) != 0)
2942 struct elf_dyn_relocs
*p
;
2943 struct elf_dyn_relocs
**head
;
2945 /* We must copy these reloc types into the output file.
2946 Create a reloc section in dynobj and make room for
2950 if (htab
->elf
.dynobj
== NULL
)
2951 htab
->elf
.dynobj
= abfd
;
2953 sreloc
= _bfd_elf_make_dynamic_reloc_section
2954 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela? */ TRUE
);
2960 /* If this is a global symbol, we count the number of
2961 relocations we need for this symbol. */
2964 head
= &((struct elf32_tic6x_link_hash_entry
*) h
)->dyn_relocs
;
2968 /* Track dynamic relocs needed for local syms too.
2969 We really need local syms available to do this
2974 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2978 vpp
= &elf_section_data (s
)->local_dynrel
;
2979 head
= (struct elf_dyn_relocs
**)vpp
;
2983 if (p
== NULL
|| p
->sec
!= sec
)
2985 bfd_size_type amt
= sizeof *p
;
2986 p
= bfd_alloc (htab
->elf
.dynobj
, amt
);
2997 if (r_type
== R_C6000_DSBT_INDEX
)
3002 case R_C6000_SBR_U15_B
:
3003 case R_C6000_SBR_U15_H
:
3004 case R_C6000_SBR_U15_W
:
3005 case R_C6000_SBR_S16
:
3006 case R_C6000_SBR_L16_B
:
3007 case R_C6000_SBR_L16_H
:
3008 case R_C6000_SBR_L16_W
:
3009 case R_C6000_SBR_H16_B
:
3010 case R_C6000_SBR_H16_H
:
3011 case R_C6000_SBR_H16_W
:
3012 if (h
!= NULL
&& bfd_link_executable (info
))
3014 /* For B14-relative addresses, we might need a copy
3029 elf32_tic6x_add_symbol_hook (bfd
*abfd
,
3030 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3031 Elf_Internal_Sym
*sym
,
3032 const char **namep ATTRIBUTE_UNUSED
,
3033 flagword
*flagsp ATTRIBUTE_UNUSED
,
3037 switch (sym
->st_shndx
)
3039 case SHN_TIC6X_SCOMMON
:
3040 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3041 (*secp
)->flags
|= SEC_IS_COMMON
;
3042 *valp
= sym
->st_size
;
3043 (void) bfd_set_section_alignment (abfd
, *secp
, bfd_log2 (sym
->st_value
));
3051 elf32_tic6x_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
3053 elf_symbol_type
*elfsym
;
3055 elfsym
= (elf_symbol_type
*) asym
;
3056 switch (elfsym
->internal_elf_sym
.st_shndx
)
3058 case SHN_TIC6X_SCOMMON
:
3059 if (tic6x_elf_scom_section
.name
== NULL
)
3061 /* Initialize the small common section. */
3062 tic6x_elf_scom_section
.name
= ".scommon";
3063 tic6x_elf_scom_section
.flags
= SEC_IS_COMMON
;
3064 tic6x_elf_scom_section
.output_section
= &tic6x_elf_scom_section
;
3065 tic6x_elf_scom_section
.symbol
= &tic6x_elf_scom_symbol
;
3066 tic6x_elf_scom_section
.symbol_ptr_ptr
= &tic6x_elf_scom_symbol_ptr
;
3067 tic6x_elf_scom_symbol
.name
= ".scommon";
3068 tic6x_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3069 tic6x_elf_scom_symbol
.section
= &tic6x_elf_scom_section
;
3070 tic6x_elf_scom_symbol_ptr
= &tic6x_elf_scom_symbol
;
3072 asym
->section
= &tic6x_elf_scom_section
;
3073 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3079 elf32_tic6x_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3080 const char *name ATTRIBUTE_UNUSED
,
3081 Elf_Internal_Sym
*sym
,
3082 asection
*input_sec
,
3083 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
3085 /* If we see a common symbol, which implies a relocatable link, then
3086 if a symbol was small common in an input file, mark it as small
3087 common in the output file. */
3088 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
3089 sym
->st_shndx
= SHN_TIC6X_SCOMMON
;
3095 elf32_tic6x_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
3099 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3101 *retval
= SHN_TIC6X_SCOMMON
;
3108 /* Allocate space in .plt, .got and associated reloc sections for
3112 elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3114 struct bfd_link_info
*info
;
3115 struct elf32_tic6x_link_hash_table
*htab
;
3116 struct elf32_tic6x_link_hash_entry
*eh
;
3117 struct elf_dyn_relocs
*p
;
3119 if (h
->root
.type
== bfd_link_hash_indirect
)
3122 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3123 info
= (struct bfd_link_info
*) inf
;
3124 htab
= elf32_tic6x_hash_table (info
);
3126 if (htab
->elf
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3128 /* Make sure this symbol is output as a dynamic symbol.
3129 Undefined weak syms won't yet be marked as dynamic. */
3130 if (h
->dynindx
== -1 && !h
->forced_local
)
3132 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3136 if (bfd_link_pic (info
)
3137 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3139 asection
*s
= htab
->elf
.splt
;
3141 /* If this is the first .plt entry, make room for the special
3144 s
->size
+= PLT_ENTRY_SIZE
;
3146 h
->plt
.offset
= s
->size
;
3148 /* If this symbol is not defined in a regular file, and we are
3149 not generating a shared library, then set the symbol to this
3150 location in the .plt. This is required to make function
3151 pointers compare as equal between the normal executable and
3152 the shared library. */
3153 if (! bfd_link_pic (info
) && !h
->def_regular
)
3155 h
->root
.u
.def
.section
= s
;
3156 h
->root
.u
.def
.value
= h
->plt
.offset
;
3159 /* Make room for this entry. */
3160 s
->size
+= PLT_ENTRY_SIZE
;
3161 /* We also need to make an entry in the .got.plt section, which
3162 will be placed in the .got section by the linker script. */
3163 htab
->elf
.sgotplt
->size
+= 4;
3164 /* We also need to make an entry in the .rel.plt section. */
3165 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3169 h
->plt
.offset
= (bfd_vma
) -1;
3175 h
->plt
.offset
= (bfd_vma
) -1;
3179 if (h
->got
.refcount
> 0)
3183 /* Make sure this symbol is output as a dynamic symbol.
3184 Undefined weak syms won't yet be marked as dynamic. */
3185 if (h
->dynindx
== -1
3186 && !h
->forced_local
)
3188 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3193 h
->got
.offset
= s
->size
;
3196 if (!(ELF_ST_VISIBILITY (h
->other
)
3197 && h
->root
.type
== bfd_link_hash_undefweak
))
3198 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3201 h
->got
.offset
= (bfd_vma
) -1;
3203 if (eh
->dyn_relocs
== NULL
)
3206 /* Discard relocs on undefined weak syms with non-default
3208 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (htab
->obfd
))
3210 /* We use the pc_count field to hold the number of
3211 R_C6000_DSBT_INDEX relocs. */
3212 if (htab
->params
.dsbt_index
!= 0)
3214 struct elf_dyn_relocs
**pp
;
3216 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3218 p
->count
-= p
->pc_count
;
3227 if (eh
->dyn_relocs
!= NULL
3228 && h
->root
.type
== bfd_link_hash_undefweak
)
3230 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3231 eh
->dyn_relocs
= NULL
;
3233 /* Make sure undefined weak symbols are output as a dynamic
3235 else if (h
->dynindx
== -1
3236 && !h
->forced_local
)
3238 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3244 /* Finally, allocate space. */
3245 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3249 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3251 BFD_ASSERT (sreloc
!= NULL
);
3252 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3258 /* Find any dynamic relocs that apply to read-only sections. */
3261 elf32_tic6x_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3263 struct elf32_tic6x_link_hash_entry
*eh
;
3264 struct elf_dyn_relocs
*p
;
3266 eh
= (struct elf32_tic6x_link_hash_entry
*) h
;
3267 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3269 asection
*s
= p
->sec
->output_section
;
3271 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3273 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3275 info
->flags
|= DF_TEXTREL
;
3277 /* Not an error, just cut short the traversal. */
3284 /* Set the sizes of the dynamic sections. */
3287 elf32_tic6x_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3289 struct elf32_tic6x_link_hash_table
*htab
;
3295 htab
= elf32_tic6x_hash_table (info
);
3296 dynobj
= htab
->elf
.dynobj
;
3300 if (htab
->elf
.dynamic_sections_created
)
3302 /* Set the contents of the .interp section to the interpreter. */
3303 if (bfd_link_executable (info
) && !info
->nointerp
)
3305 s
= bfd_get_linker_section (dynobj
, ".interp");
3308 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3309 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3313 /* Set up .got offsets for local syms, and space for local dynamic
3315 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3317 bfd_signed_vma
*local_got
;
3318 bfd_signed_vma
*end_local_got
;
3319 bfd_size_type locsymcount
;
3320 Elf_Internal_Shdr
*symtab_hdr
;
3323 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3325 struct elf_dyn_relocs
*p
;
3327 for (p
= ((struct elf_dyn_relocs
*)
3328 elf_section_data (s
)->local_dynrel
);
3332 if (!bfd_is_abs_section (p
->sec
)
3333 && bfd_is_abs_section (p
->sec
->output_section
))
3335 /* Input section has been discarded, either because
3336 it is a copy of a linkonce section or due to
3337 linker script /DISCARD/, so we'll be discarding
3340 else if (p
->count
!= 0)
3342 srel
= elf_section_data (p
->sec
)->sreloc
;
3343 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3344 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3345 info
->flags
|= DF_TEXTREL
;
3350 local_got
= elf_local_got_refcounts (ibfd
);
3354 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3355 locsymcount
= symtab_hdr
->sh_info
;
3356 end_local_got
= local_got
+ locsymcount
;
3358 srel
= htab
->elf
.srelgot
;
3359 for (; local_got
< end_local_got
; ++local_got
)
3363 *local_got
= s
->size
;
3366 if (bfd_link_pic (info
) || elf32_tic6x_using_dsbt (output_bfd
))
3368 srel
->size
+= sizeof (Elf32_External_Rela
);
3372 *local_got
= (bfd_vma
) -1;
3376 /* Allocate global sym .plt and .got entries, and space for global
3377 sym dynamic relocs. */
3378 elf_link_hash_traverse (&htab
->elf
, elf32_tic6x_allocate_dynrelocs
, info
);
3380 /* We now have determined the sizes of the various dynamic sections.
3381 Allocate memory for them. */
3383 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3385 bfd_boolean strip_section
= TRUE
;
3387 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3390 if (s
== htab
->dsbt
)
3391 s
->size
= 4 * htab
->params
.dsbt_size
;
3392 else if (s
== htab
->elf
.splt
3393 || s
== htab
->elf
.sgot
3394 || s
== htab
->elf
.sgotplt
3395 || s
== htab
->sdynbss
)
3397 /* Strip this section if we don't need it; see the
3399 /* We'd like to strip these sections if they aren't needed, but if
3400 we've exported dynamic symbols from them we must leave them.
3401 It's too late to tell BFD to get rid of the symbols. */
3403 if (htab
->elf
.hplt
!= NULL
)
3404 strip_section
= FALSE
;
3406 /* Round up the size of the PLT section to a multiple of 32. */
3407 if (s
== htab
->elf
.splt
&& s
->size
> 0)
3408 s
->size
= (s
->size
+ 31) & ~(bfd_vma
)31;
3410 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3413 && s
!= htab
->elf
.srelplt
)
3416 /* We use the reloc_count field as a counter if we need
3417 to copy relocs into the output file. */
3422 /* It's not one of our sections, so don't allocate space. */
3428 /* If we don't need this section, strip it from the
3429 output file. This is mostly to handle .rel.bss and
3430 .rel.plt. We must create both sections in
3431 create_dynamic_sections, because they must be created
3432 before the linker maps input sections to output
3433 sections. The linker does that before
3434 adjust_dynamic_symbol is called, and it is that
3435 function which decides whether anything needs to go
3436 into these sections. */
3438 s
->flags
|= SEC_EXCLUDE
;
3442 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3445 /* Allocate memory for the section contents. We use bfd_zalloc
3446 here in case unused entries are not reclaimed before the
3447 section's contents are written out. This should not happen,
3448 but this way if it does, we get a R_C6000_NONE reloc instead
3450 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3451 if (s
->contents
== NULL
)
3455 if (htab
->elf
.dynamic_sections_created
)
3457 /* Add some entries to the .dynamic section. We fill in the
3458 values later, in elf32_tic6x_finish_dynamic_sections, but we
3459 must add the entries now so that we get the correct size for
3460 the .dynamic section. The DT_DEBUG entry is filled in by the
3461 dynamic linker and used by the debugger. */
3462 #define add_dynamic_entry(TAG, VAL) \
3463 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3465 if (bfd_link_executable (info
))
3467 if (!add_dynamic_entry (DT_DEBUG
, 0))
3471 if (!add_dynamic_entry (DT_C6000_DSBT_BASE
, 0)
3472 || !add_dynamic_entry (DT_C6000_DSBT_SIZE
, htab
->params
.dsbt_size
)
3473 || !add_dynamic_entry (DT_C6000_DSBT_INDEX
,
3474 htab
->params
.dsbt_index
))
3477 if (htab
->elf
.splt
->size
!= 0)
3479 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3480 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3481 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3482 || !add_dynamic_entry (DT_JMPREL
, 0))
3488 if (!add_dynamic_entry (DT_RELA
, 0)
3489 || !add_dynamic_entry (DT_RELASZ
, 0)
3490 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3493 /* If any dynamic relocs apply to a read-only section,
3494 then we need a DT_TEXTREL entry. */
3495 if ((info
->flags
& DF_TEXTREL
) == 0)
3496 elf_link_hash_traverse (&htab
->elf
,
3497 elf32_tic6x_readonly_dynrelocs
, info
);
3499 if ((info
->flags
& DF_TEXTREL
) != 0)
3501 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3506 #undef add_dynamic_entry
3511 /* This function is called after all the input files have been read,
3512 and the input sections have been assigned to output sections. */
3515 elf32_tic6x_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3517 if (elf32_tic6x_using_dsbt (output_bfd
) && !bfd_link_relocatable (info
)
3518 && !bfd_elf_stack_segment_size (output_bfd
, info
,
3519 "__stacksize", DEFAULT_STACK_SIZE
))
3526 elf32_tic6x_finish_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3527 struct bfd_link_info
*info
)
3529 struct elf32_tic6x_link_hash_table
*htab
;
3533 htab
= elf32_tic6x_hash_table (info
);
3534 dynobj
= htab
->elf
.dynobj
;
3535 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
3537 if (elf_hash_table (info
)->dynamic_sections_created
)
3539 Elf32_External_Dyn
* dyncon
;
3540 Elf32_External_Dyn
* dynconend
;
3542 BFD_ASSERT (sdyn
!= NULL
);
3544 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3545 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3547 for (; dyncon
< dynconend
; dyncon
++)
3549 Elf_Internal_Dyn dyn
;
3552 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3559 case DT_C6000_DSBT_BASE
:
3561 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
);
3565 s
= htab
->elf
.sgotplt
;
3566 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3570 s
= htab
->elf
.srelplt
;
3571 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3575 s
= htab
->elf
.srelplt
;
3576 dyn
.d_un
.d_val
= s
->size
;
3579 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3582 /* Fill in the first entry in the procedure linkage table. */
3583 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
3585 bfd_vma got_offs
= (htab
->elf
.sgotplt
->output_section
->vma
3586 + htab
->elf
.sgotplt
->output_offset
3587 - htab
->dsbt
->output_section
->vma
3588 - htab
->dsbt
->output_offset
) / 4;
3590 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3591 bfd_put_32 (output_bfd
, got_offs
<< 8 | 0x0100006e,
3592 htab
->elf
.splt
->contents
);
3593 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3594 bfd_put_32 (output_bfd
, (got_offs
+ 1) << 8 | 0x0080006e,
3595 htab
->elf
.splt
->contents
+ 4);
3597 bfd_put_32 (output_bfd
, 0x00004000,
3598 htab
->elf
.splt
->contents
+ 8);
3600 bfd_put_32 (output_bfd
, 0x00080362,
3601 htab
->elf
.splt
->contents
+ 12);
3603 bfd_put_32 (output_bfd
, 0x00008000,
3604 htab
->elf
.splt
->contents
+ 16);
3606 elf_section_data (htab
->elf
.splt
->output_section
)
3607 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3614 /* Return address for Ith PLT stub in section PLT, for relocation REL
3615 or (bfd_vma) -1 if it should not be included. */
3618 elf32_tic6x_plt_sym_val (bfd_vma i
, const asection
*plt
,
3619 const arelent
*rel ATTRIBUTE_UNUSED
)
3621 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3625 elf32_tic6x_obj_attrs_arg_type (int tag
)
3627 if (tag
== Tag_ABI_compatibility
)
3628 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
3630 return ATTR_TYPE_FLAG_STR_VAL
;
3632 return ATTR_TYPE_FLAG_INT_VAL
;
3636 elf32_tic6x_obj_attrs_order (int num
)
3638 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
3639 return Tag_ABI_conformance
;
3640 if ((num
- 1) < Tag_ABI_conformance
)
3646 elf32_tic6x_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
3648 if ((tag
& 127) < 64)
3651 (_("%B: error: unknown mandatory EABI object attribute %d"),
3653 bfd_set_error (bfd_error_bad_value
);
3659 (_("%B: warning: unknown EABI object attribute %d"),
3665 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
3666 and return the merged value. At present, all merges succeed, so no
3667 return value for errors is defined. */
3670 elf32_tic6x_merge_arch_attributes (int arch1
, int arch2
)
3672 int min_arch
, max_arch
;
3674 min_arch
= (arch1
< arch2
? arch1
: arch2
);
3675 max_arch
= (arch1
> arch2
? arch1
: arch2
);
3677 /* In most cases, the numerically greatest value is the correct
3678 merged value, but merging C64 and C67 results in C674X. */
3679 if ((min_arch
== C6XABI_Tag_ISA_C67X
3680 || min_arch
== C6XABI_Tag_ISA_C67XP
)
3681 && (max_arch
== C6XABI_Tag_ISA_C64X
3682 || max_arch
== C6XABI_Tag_ISA_C64XP
))
3683 return C6XABI_Tag_ISA_C674X
;
3688 /* Convert a Tag_ABI_array_object_alignment or
3689 Tag_ABI_array_object_align_expected tag value TAG to a
3690 corresponding alignment value; return the alignment, or -1 for an
3691 unknown tag value. */
3694 elf32_tic6x_tag_to_array_alignment (int tag
)
3712 /* Convert a Tag_ABI_array_object_alignment or
3713 Tag_ABI_array_object_align_expected alignment ALIGN to a
3714 corresponding tag value; return the tag value. */
3717 elf32_tic6x_array_alignment_to_tag (int align
)
3735 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3736 succeeded, FALSE otherwise. */
3739 elf32_tic6x_merge_attributes (bfd
*ibfd
, bfd
*obfd
)
3741 bfd_boolean result
= TRUE
;
3742 obj_attribute
*in_attr
;
3743 obj_attribute
*out_attr
;
3745 int array_align_in
, array_align_out
, array_expect_in
, array_expect_out
;
3747 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
3749 /* This is the first object. Copy the attributes. */
3750 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
3752 out_attr
= elf_known_obj_attributes_proc (obfd
);
3754 /* Use the Tag_null value to indicate the attributes have been
3761 in_attr
= elf_known_obj_attributes_proc (ibfd
);
3762 out_attr
= elf_known_obj_attributes_proc (obfd
);
3764 /* No specification yet for handling of unknown attributes, so just
3765 ignore them and handle known ones. */
3767 if (out_attr
[Tag_ABI_stack_align_preserved
].i
3768 < in_attr
[Tag_ABI_stack_align_needed
].i
)
3771 (_("error: %B requires more stack alignment than %B preserves"),
3775 if (in_attr
[Tag_ABI_stack_align_preserved
].i
3776 < out_attr
[Tag_ABI_stack_align_needed
].i
)
3779 (_("error: %B requires more stack alignment than %B preserves"),
3784 array_align_in
= elf32_tic6x_tag_to_array_alignment
3785 (in_attr
[Tag_ABI_array_object_alignment
].i
);
3786 if (array_align_in
== -1)
3789 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3793 array_align_out
= elf32_tic6x_tag_to_array_alignment
3794 (out_attr
[Tag_ABI_array_object_alignment
].i
);
3795 if (array_align_out
== -1)
3798 (_("error: unknown Tag_ABI_array_object_alignment value in %B"),
3802 array_expect_in
= elf32_tic6x_tag_to_array_alignment
3803 (in_attr
[Tag_ABI_array_object_align_expected
].i
);
3804 if (array_expect_in
== -1)
3807 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3811 array_expect_out
= elf32_tic6x_tag_to_array_alignment
3812 (out_attr
[Tag_ABI_array_object_align_expected
].i
);
3813 if (array_expect_out
== -1)
3816 (_("error: unknown Tag_ABI_array_object_align_expected value in %B"),
3821 if (array_align_out
< array_expect_in
)
3824 (_("error: %B requires more array alignment than %B preserves"),
3828 if (array_align_in
< array_expect_out
)
3831 (_("error: %B requires more array alignment than %B preserves"),
3836 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
3841 out_attr
[i
].i
= elf32_tic6x_merge_arch_attributes (in_attr
[i
].i
,
3845 case Tag_ABI_wchar_t
:
3846 if (out_attr
[i
].i
== 0)
3847 out_attr
[i
].i
= in_attr
[i
].i
;
3848 if (out_attr
[i
].i
!= 0
3849 && in_attr
[i
].i
!= 0
3850 && out_attr
[i
].i
!= in_attr
[i
].i
)
3853 (_("warning: %B and %B differ in wchar_t size"), obfd
, ibfd
);
3857 case Tag_ABI_stack_align_needed
:
3858 if (out_attr
[i
].i
< in_attr
[i
].i
)
3859 out_attr
[i
].i
= in_attr
[i
].i
;
3862 case Tag_ABI_stack_align_preserved
:
3863 if (out_attr
[i
].i
> in_attr
[i
].i
)
3864 out_attr
[i
].i
= in_attr
[i
].i
;
3868 if (out_attr
[i
].i
!= in_attr
[i
].i
)
3871 (_("warning: %B and %B differ in whether code is "
3872 "compiled for DSBT"),
3879 if (out_attr
[i
].i
> in_attr
[i
].i
)
3880 out_attr
[i
].i
= in_attr
[i
].i
;
3883 case Tag_ABI_array_object_alignment
:
3884 if (array_align_out
!= -1
3885 && array_align_in
!= -1
3886 && array_align_out
> array_align_in
)
3888 = elf32_tic6x_array_alignment_to_tag (array_align_in
);
3891 case Tag_ABI_array_object_align_expected
:
3892 if (array_expect_out
!= -1
3893 && array_expect_in
!= -1
3894 && array_expect_out
< array_expect_in
)
3896 = elf32_tic6x_array_alignment_to_tag (array_expect_in
);
3899 case Tag_ABI_conformance
:
3900 /* Merging for this attribute is not specified. As on ARM,
3901 treat a missing attribute as no claim to conform and only
3902 merge identical values. */
3903 if (out_attr
[i
].s
== NULL
3904 || in_attr
[i
].s
== NULL
3905 || strcmp (out_attr
[i
].s
,
3907 out_attr
[i
].s
= NULL
;
3910 case Tag_ABI_compatibility
:
3911 /* Merged in _bfd_elf_merge_object_attributes. */
3916 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
3920 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
3921 out_attr
[i
].type
= in_attr
[i
].type
;
3924 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
3925 if (!_bfd_elf_merge_object_attributes (ibfd
, obfd
))
3928 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
3934 elf32_tic6x_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3936 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
3939 if (! is_tic6x_elf (ibfd
) || ! is_tic6x_elf (obfd
))
3942 if (!elf32_tic6x_merge_attributes (ibfd
, obfd
))
3948 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
3949 adds the edit to the start of the list. (The list must be built in order of
3950 ascending TINDEX: the function's callers are primarily responsible for
3951 maintaining that condition). */
3954 elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit
**head
,
3955 tic6x_unwind_table_edit
**tail
,
3956 tic6x_unwind_edit_type type
,
3957 asection
*linked_section
,
3958 unsigned int tindex
)
3960 tic6x_unwind_table_edit
*new_edit
= (tic6x_unwind_table_edit
*)
3961 xmalloc (sizeof (tic6x_unwind_table_edit
));
3963 new_edit
->type
= type
;
3964 new_edit
->linked_section
= linked_section
;
3965 new_edit
->index
= tindex
;
3969 new_edit
->next
= NULL
;
3972 (*tail
)->next
= new_edit
;
3981 new_edit
->next
= *head
;
3990 static _tic6x_elf_section_data
*
3991 get_tic6x_elf_section_data (asection
* sec
)
3993 if (sec
&& sec
->owner
&& is_tic6x_elf (sec
->owner
))
3994 return elf32_tic6x_section_data (sec
);
4000 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST must be negative. */
4002 elf32_tic6x_adjust_exidx_size (asection
*exidx_sec
, int adjust
)
4006 if (!exidx_sec
->rawsize
)
4007 exidx_sec
->rawsize
= exidx_sec
->size
;
4009 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
4010 out_sec
= exidx_sec
->output_section
;
4011 /* Adjust size of output section. */
4012 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
4015 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
4017 elf32_tic6x_insert_cantunwind_after (asection
*text_sec
, asection
*exidx_sec
)
4019 struct _tic6x_elf_section_data
*exidx_data
;
4021 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
4022 elf32_tic6x_add_unwind_table_edit (
4023 &exidx_data
->u
.exidx
.unwind_edit_list
,
4024 &exidx_data
->u
.exidx
.unwind_edit_tail
,
4025 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
4027 elf32_tic6x_adjust_exidx_size (exidx_sec
, 8);
4030 /* Scan .cx6abi.exidx tables, and create a list describing edits which
4031 should be made to those tables, such that:
4033 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
4034 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
4035 codes which have been inlined into the index).
4037 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
4039 The edits are applied when the tables are written
4040 (in elf32_tic6x_write_section).
4044 elf32_tic6x_fix_exidx_coverage (asection
**text_section_order
,
4045 unsigned int num_text_sections
,
4046 struct bfd_link_info
*info
,
4047 bfd_boolean merge_exidx_entries
)
4050 unsigned int last_second_word
= 0, i
;
4051 asection
*last_exidx_sec
= NULL
;
4052 asection
*last_text_sec
= NULL
;
4053 int last_unwind_type
= -1;
4055 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
4057 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link
.next
)
4061 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
4063 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
4064 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
4066 if (!hdr
|| hdr
->sh_type
!= SHT_C6000_UNWIND
)
4069 if (elf_sec
->linked_to
)
4071 Elf_Internal_Shdr
*linked_hdr
4072 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
4073 struct _tic6x_elf_section_data
*linked_sec_tic6x_data
4074 = get_tic6x_elf_section_data (linked_hdr
->bfd_section
);
4076 if (linked_sec_tic6x_data
== NULL
)
4079 /* Link this .c6xabi.exidx section back from the
4080 text section it describes. */
4081 linked_sec_tic6x_data
->u
.text
.tic6x_exidx_sec
= sec
;
4086 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
4087 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
4088 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
4090 for (i
= 0; i
< num_text_sections
; i
++)
4092 asection
*sec
= text_section_order
[i
];
4093 asection
*exidx_sec
;
4094 struct _tic6x_elf_section_data
*tic6x_data
4095 = get_tic6x_elf_section_data (sec
);
4096 struct _tic6x_elf_section_data
*exidx_data
;
4097 bfd_byte
*contents
= NULL
;
4098 int deleted_exidx_bytes
= 0;
4100 tic6x_unwind_table_edit
*unwind_edit_head
= NULL
;
4101 tic6x_unwind_table_edit
*unwind_edit_tail
= NULL
;
4102 Elf_Internal_Shdr
*hdr
;
4105 if (tic6x_data
== NULL
)
4108 exidx_sec
= tic6x_data
->u
.text
.tic6x_exidx_sec
;
4109 if (exidx_sec
== NULL
)
4111 /* Section has no unwind data. */
4112 if (last_unwind_type
== 0 || !last_exidx_sec
)
4115 /* Ignore zero sized sections. */
4119 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4120 last_unwind_type
= 0;
4124 /* Skip /DISCARD/ sections. */
4125 if (bfd_is_abs_section (exidx_sec
->output_section
))
4128 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
4129 if (hdr
->sh_type
!= SHT_C6000_UNWIND
)
4132 exidx_data
= get_tic6x_elf_section_data (exidx_sec
);
4133 if (exidx_data
== NULL
)
4136 ibfd
= exidx_sec
->owner
;
4138 if (hdr
->contents
!= NULL
)
4139 contents
= hdr
->contents
;
4140 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
4144 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
4146 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
4150 /* An EXIDX_CANTUNWIND entry. */
4151 if (second_word
== 1)
4153 if (last_unwind_type
== 0)
4157 /* Inlined unwinding data. Merge if equal to previous. */
4158 else if ((second_word
& 0x80000000) != 0)
4160 if (merge_exidx_entries
4161 && last_second_word
== second_word
4162 && last_unwind_type
== 1)
4165 last_second_word
= second_word
;
4167 /* Normal table entry. In theory we could merge these too,
4168 but duplicate entries are likely to be much less common. */
4174 elf32_tic6x_add_unwind_table_edit (&unwind_edit_head
,
4175 &unwind_edit_tail
, DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
4177 deleted_exidx_bytes
+= 8;
4180 last_unwind_type
= unwind_type
;
4183 /* Free contents if we allocated it ourselves. */
4184 if (contents
!= hdr
->contents
)
4187 /* Record edits to be applied later (in elf32_tic6x_write_section). */
4188 exidx_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
4189 exidx_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
4191 if (deleted_exidx_bytes
> 0)
4192 elf32_tic6x_adjust_exidx_size (exidx_sec
, -deleted_exidx_bytes
);
4194 last_exidx_sec
= exidx_sec
;
4195 last_text_sec
= sec
;
4198 /* Add terminating CANTUNWIND entry. */
4199 if (last_exidx_sec
&& last_unwind_type
!= 0)
4200 elf32_tic6x_insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
4205 /* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified. */
4207 static unsigned long
4208 elf32_tic6x_add_low31 (unsigned long val
, bfd_vma addend
)
4210 return (val
& ~0x7ffffffful
) | ((val
+ addend
) & 0x7ffffffful
);
4213 /* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
4214 relocations. OFFSET is in bytes, and will be scaled before encoding. */
4218 elf32_tic6x_copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
,
4221 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
4222 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
4225 /* High bit of first word is supposed to be zero. */
4226 if ((first_word
& 0x80000000ul
) == 0)
4227 first_word
= elf32_tic6x_add_low31 (first_word
, offset
);
4229 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
4230 (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry. */
4231 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
4232 second_word
= elf32_tic6x_add_low31 (second_word
, offset
);
4234 bfd_put_32 (output_bfd
, first_word
, to
);
4235 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
4238 /* Do the actual mangling of exception index tables. */
4241 elf32_tic6x_write_section (bfd
*output_bfd
,
4242 struct bfd_link_info
*link_info
,
4246 _tic6x_elf_section_data
*tic6x_data
;
4247 struct elf32_tic6x_link_hash_table
*globals
4248 = elf32_tic6x_hash_table (link_info
);
4249 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4251 if (globals
== NULL
)
4254 /* If this section has not been allocated an _tic6x_elf_section_data
4255 structure then we cannot record anything. */
4256 tic6x_data
= get_tic6x_elf_section_data (sec
);
4257 if (tic6x_data
== NULL
)
4260 if (tic6x_data
->elf
.this_hdr
.sh_type
!= SHT_C6000_UNWIND
)
4263 tic6x_unwind_table_edit
*edit_node
4264 = tic6x_data
->u
.exidx
.unwind_edit_list
;
4265 /* Now, sec->size is the size of the section we will write. The original
4266 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
4267 markers) was sec->rawsize. (This isn't the case if we perform no
4268 edits, then rawsize will be zero and we should use size). */
4269 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
4270 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
4271 unsigned int in_index
, out_index
;
4272 bfd_vma add_to_offsets
= 0;
4274 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
4278 unsigned int edit_index
= edit_node
->index
;
4280 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
4282 elf32_tic6x_copy_exidx_entry (output_bfd
,
4283 edited_contents
+ out_index
* 8,
4284 contents
+ in_index
* 8, add_to_offsets
);
4288 else if (in_index
== edit_index
4289 || (in_index
* 8 >= input_size
4290 && edit_index
== UINT_MAX
))
4292 switch (edit_node
->type
)
4294 case DELETE_EXIDX_ENTRY
:
4296 add_to_offsets
+= 8;
4299 case INSERT_EXIDX_CANTUNWIND_AT_END
:
4301 asection
*text_sec
= edit_node
->linked_section
;
4302 bfd_vma text_offset
= text_sec
->output_section
->vma
4303 + text_sec
->output_offset
4305 bfd_vma exidx_offset
= offset
+ out_index
* 8;
4306 unsigned long prel31_offset
;
4308 /* Note: this is meant to be equivalent to an
4309 R_C6000_PREL31 relocation. These synthetic
4310 EXIDX_CANTUNWIND markers are not relocated by the
4311 usual BFD method. */
4312 prel31_offset
= ((text_offset
- exidx_offset
) >> 1)
4315 /* First address we can't unwind. */
4316 bfd_put_32 (output_bfd
, prel31_offset
,
4317 &edited_contents
[out_index
* 8]);
4319 /* Code for EXIDX_CANTUNWIND. */
4320 bfd_put_32 (output_bfd
, 0x1,
4321 &edited_contents
[out_index
* 8 + 4]);
4324 add_to_offsets
-= 8;
4329 edit_node
= edit_node
->next
;
4334 /* No more edits, copy remaining entries verbatim. */
4335 elf32_tic6x_copy_exidx_entry (output_bfd
,
4336 edited_contents
+ out_index
* 8,
4337 contents
+ in_index
* 8, add_to_offsets
);
4343 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
4344 bfd_set_section_contents (output_bfd
, sec
->output_section
,
4346 (file_ptr
) sec
->output_offset
, sec
->size
);
4351 #define TARGET_LITTLE_SYM tic6x_elf32_le_vec
4352 #define TARGET_LITTLE_NAME "elf32-tic6x-le"
4353 #define TARGET_BIG_SYM tic6x_elf32_be_vec
4354 #define TARGET_BIG_NAME "elf32-tic6x-be"
4355 #define ELF_ARCH bfd_arch_tic6x
4356 #define ELF_TARGET_ID TIC6X_ELF_DATA
4357 #define ELF_MACHINE_CODE EM_TI_C6000
4358 #define ELF_MAXPAGESIZE 0x1000
4359 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
4360 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
4361 #define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
4362 #define bfd_elf32_mkobject elf32_tic6x_mkobject
4363 #define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
4364 #define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
4365 #define elf_backend_stack_align 8
4366 #define elf_backend_can_gc_sections 1
4367 #define elf_backend_default_use_rela_p 1
4368 #define elf_backend_may_use_rel_p 1
4369 #define elf_backend_may_use_rela_p 1
4370 #define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
4371 #define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
4372 #define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
4373 #define elf_backend_obj_attrs_section ".c6xabi.attributes"
4374 #define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4375 #define elf_backend_obj_attrs_vendor "c6xabi"
4376 #define elf_backend_can_refcount 1
4377 #define elf_backend_want_got_plt 1
4378 #define elf_backend_want_dynbss 1
4379 #define elf_backend_plt_readonly 1
4380 #define elf_backend_rela_normal 1
4381 #define elf_backend_got_header_size 8
4382 #define elf_backend_fake_sections elf32_tic6x_fake_sections
4383 #define elf_backend_gc_sweep_hook elf32_tic6x_gc_sweep_hook
4384 #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
4385 #define elf_backend_create_dynamic_sections \
4386 elf32_tic6x_create_dynamic_sections
4387 #define elf_backend_adjust_dynamic_symbol \
4388 elf32_tic6x_adjust_dynamic_symbol
4389 #define elf_backend_check_relocs elf32_tic6x_check_relocs
4390 #define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4391 #define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4392 #define elf_backend_link_output_symbol_hook \
4393 elf32_tic6x_link_output_symbol_hook
4394 #define elf_backend_section_from_bfd_section \
4395 elf32_tic6x_section_from_bfd_section
4396 #define elf_backend_relocate_section elf32_tic6x_relocate_section
4397 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4398 #define elf_backend_finish_dynamic_symbol \
4399 elf32_tic6x_finish_dynamic_symbol
4400 #define elf_backend_always_size_sections \
4401 elf32_tic6x_always_size_sections
4402 #define elf_backend_size_dynamic_sections \
4403 elf32_tic6x_size_dynamic_sections
4404 #define elf_backend_finish_dynamic_sections \
4405 elf32_tic6x_finish_dynamic_sections
4406 #define bfd_elf32_bfd_final_link \
4407 elf32_tic6x_final_link
4408 #define elf_backend_write_section elf32_tic6x_write_section
4409 #define elf_info_to_howto elf32_tic6x_info_to_howto
4410 #define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
4412 #undef elf_backend_omit_section_dynsym
4413 #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4414 #define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4416 #include "elf32-target.h"
4419 #define elf32_bed elf32_tic6x_linux_bed
4421 #undef TARGET_LITTLE_SYM
4422 #define TARGET_LITTLE_SYM tic6x_elf32_linux_le_vec
4423 #undef TARGET_LITTLE_NAME
4424 #define TARGET_LITTLE_NAME "elf32-tic6x-linux-le"
4425 #undef TARGET_BIG_SYM
4426 #define TARGET_BIG_SYM tic6x_elf32_linux_be_vec
4427 #undef TARGET_BIG_NAME
4428 #define TARGET_BIG_NAME "elf32-tic6x-linux-be"
4430 #define ELF_OSABI ELFOSABI_C6000_LINUX
4432 #include "elf32-target.h"
4435 #define elf32_bed elf32_tic6x_elf_bed
4437 #undef TARGET_LITTLE_SYM
4438 #define TARGET_LITTLE_SYM tic6x_elf32_c6000_le_vec
4439 #undef TARGET_LITTLE_NAME
4440 #define TARGET_LITTLE_NAME "elf32-tic6x-elf-le"
4441 #undef TARGET_BIG_SYM
4442 #define TARGET_BIG_SYM tic6x_elf32_c6000_be_vec
4443 #undef TARGET_BIG_NAME
4444 #define TARGET_BIG_NAME "elf32-tic6x-elf-be"
4446 #define ELF_OSABI ELFOSABI_C6000_ELFABI
4448 #include "elf32-target.h"