]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/elf32-tic6x.c
Two fixes in dwarf-mode.el
[thirdparty/binutils-gdb.git] / bfd / elf32-tic6x.c
CommitLineData
40b36596 1/* 32-bit ELF support for TI C6X
b3adc24a 2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
c0621d88 3 Contributed by Joseph Myers <joseph@codesourcery.com>
07d6d2b8 4 Bernd Schmidt <bernds@codesourcery.com>
40b36596
JM
5
6 This file is part of BFD, the Binary File Descriptor library.
7
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.
12
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.
17
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. */
22
23#include "sysdep.h"
fbd9ad90 24#include <limits.h>
40b36596
JM
25#include "bfd.h"
26#include "libbfd.h"
27#include "libiberty.h"
28#include "elf-bfd.h"
29#include "elf/tic6x.h"
41820509
JM
30#include "elf32-tic6x.h"
31
ac145307
BS
32#define ELF_DYNAMIC_INTERPRETER "/lib/ld-uClibc.so.0"
33
34/* DSBT binaries have a default 128K stack. */
35#define DEFAULT_STACK_SIZE 0x20000
36
37/* The size in bytes of an entry in the procedure linkage table. */
38#define PLT_ENTRY_SIZE 24
39
40/* TI C6X ELF linker hash table. */
41
42struct elf32_tic6x_link_hash_table
43{
44 struct elf_link_hash_table elf;
45
ac145307
BS
46 /* C6X specific command line arguments. */
47 struct elf32_tic6x_params params;
48
ac145307
BS
49 /* The output BFD, for convenience. */
50 bfd *obfd;
51
52 /* The .dsbt section. */
53 asection *dsbt;
54};
55
56/* Get the TI C6X ELF linker hash table from a link_info structure. */
57
58#define elf32_tic6x_hash_table(p) \
59 ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
60
fbd9ad90
PB
61typedef enum
62{
63 DELETE_EXIDX_ENTRY,
64 INSERT_EXIDX_CANTUNWIND_AT_END
65}
66tic6x_unwind_edit_type;
67
68/* A (sorted) list of edits to apply to an unwind table. */
69typedef struct tic6x_unwind_table_edit
70{
71 tic6x_unwind_edit_type type;
72 /* Note: we sometimes want to insert an unwind entry corresponding to a
73 section different from the one we're currently writing out, so record the
74 (text) section this edit relates to here. */
75 asection *linked_section;
76 unsigned int index;
77 struct tic6x_unwind_table_edit *next;
78}
79tic6x_unwind_table_edit;
80
81typedef struct _tic6x_elf_section_data
82{
83 /* Information about mapping symbols. */
84 struct bfd_elf_section_data elf;
85 /* Information about unwind tables. */
86 union
87 {
88 /* Unwind info attached to a text section. */
89 struct
90 {
91 asection *tic6x_exidx_sec;
92 } text;
93
94 /* Unwind info attached to an .c6xabi.exidx section. */
95 struct
96 {
97 tic6x_unwind_table_edit *unwind_edit_list;
98 tic6x_unwind_table_edit *unwind_edit_tail;
99 } exidx;
100 } u;
101}
102_tic6x_elf_section_data;
103
104#define elf32_tic6x_section_data(sec) \
105 ((_tic6x_elf_section_data *) elf_section_data (sec))
106
41820509
JM
107struct elf32_tic6x_obj_tdata
108{
109 struct elf_obj_tdata root;
110
111 /* Whether to use RELA relocations when generating relocations.
112 This is a per-object flag to allow the assembler to generate REL
113 relocations for use in linker testcases. */
114 bfd_boolean use_rela_p;
115};
116
117#define elf32_tic6x_tdata(abfd) \
118 ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
40b36596 119
ac145307
BS
120#define is_tic6x_elf(bfd) \
121 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
122 && elf_tdata (bfd) != NULL \
123 && elf_object_id (bfd) == TIC6X_ELF_DATA)
124
125/* C6X ELF uses two common sections. One is the usual one, and the
126 other is for small objects. All the small objects are kept
127 together, and then referenced via the gp pointer, which yields
128 faster assembler code. This is what we use for the small common
129 section. This approach is copied from ecoff.c. */
130static asection tic6x_elf_scom_section;
131static asymbol tic6x_elf_scom_symbol;
132static asymbol *tic6x_elf_scom_symbol_ptr;
133
40b36596
JM
134static reloc_howto_type elf32_tic6x_howto_table[] =
135{
136 HOWTO (R_C6000_NONE, /* type */
137 0, /* rightshift */
6346d5ca 138 3, /* size (0 = byte, 1 = short, 2 = long) */
40b36596
JM
139 0, /* bitsize */
140 FALSE, /* pc_relative */
141 0, /* bitpos */
142 complain_overflow_dont,/* complain_on_overflow */
143 bfd_elf_generic_reloc, /* special_function */
144 "R_C6000_NONE", /* name */
41820509
JM
145 FALSE, /* partial_inplace */
146 0, /* src_mask */
147 0, /* dst_mask */
148 FALSE), /* pcrel_offset */
149 HOWTO (R_C6000_ABS32, /* type */
150 0, /* rightshift */
151 2, /* size (0 = byte, 1 = short, 2 = long) */
152 32, /* bitsize */
153 FALSE, /* pc_relative */
154 0, /* bitpos */
155 complain_overflow_dont,/* complain_on_overflow */
156 bfd_elf_generic_reloc, /* special_function */
157 "R_C6000_ABS32", /* name */
158 FALSE, /* partial_inplace */
159 0, /* src_mask */
160 0xffffffff, /* dst_mask */
161 FALSE), /* pcrel_offset */
162 HOWTO (R_C6000_ABS16, /* type */
163 0, /* rightshift */
164 1, /* size (0 = byte, 1 = short, 2 = long) */
165 16, /* bitsize */
166 FALSE, /* pc_relative */
167 0, /* bitpos */
168 complain_overflow_bitfield,/* complain_on_overflow */
169 bfd_elf_generic_reloc, /* special_function */
170 "R_C6000_ABS16", /* name */
171 FALSE, /* partial_inplace */
172 0, /* src_mask */
173 0x0000ffff, /* dst_mask */
174 FALSE), /* pcrel_offset */
175 HOWTO (R_C6000_ABS8, /* type */
176 0, /* rightshift */
177 0, /* size (0 = byte, 1 = short, 2 = long) */
178 8, /* bitsize */
179 FALSE, /* pc_relative */
180 0, /* bitpos */
181 complain_overflow_bitfield,/* complain_on_overflow */
182 bfd_elf_generic_reloc, /* special_function */
183 "R_C6000_ABS8", /* name */
184 FALSE, /* partial_inplace */
185 0, /* src_mask */
186 0x000000ff, /* dst_mask */
187 FALSE), /* pcrel_offset */
188 HOWTO (R_C6000_PCR_S21, /* type */
189 2, /* rightshift */
190 2, /* size (0 = byte, 1 = short, 2 = long) */
191 21, /* bitsize */
192 TRUE, /* pc_relative */
193 7, /* bitpos */
194 complain_overflow_signed,/* complain_on_overflow */
195 bfd_elf_generic_reloc, /* special_function */
196 "R_C6000_PCR_S21", /* name */
197 FALSE, /* partial_inplace */
198 0, /* src_mask */
199 0x0fffff80, /* dst_mask */
200 TRUE), /* pcrel_offset */
201 HOWTO (R_C6000_PCR_S12, /* type */
202 2, /* rightshift */
203 2, /* size (0 = byte, 1 = short, 2 = long) */
204 12, /* bitsize */
205 TRUE, /* pc_relative */
206 16, /* bitpos */
207 complain_overflow_signed,/* complain_on_overflow */
208 bfd_elf_generic_reloc, /* special_function */
209 "R_C6000_PCR_S12", /* name */
210 FALSE, /* partial_inplace */
211 0, /* src_mask */
212 0x0fff0000, /* dst_mask */
213 TRUE), /* pcrel_offset */
214 HOWTO (R_C6000_PCR_S10, /* type */
215 2, /* rightshift */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
217 10, /* bitsize */
218 TRUE, /* pc_relative */
219 13, /* bitpos */
220 complain_overflow_signed,/* complain_on_overflow */
221 bfd_elf_generic_reloc, /* special_function */
222 "R_C6000_PCR_S10", /* name */
223 FALSE, /* partial_inplace */
224 0, /* src_mask */
225 0x007fe000, /* dst_mask */
226 TRUE), /* pcrel_offset */
227 HOWTO (R_C6000_PCR_S7, /* type */
228 2, /* rightshift */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
230 7, /* bitsize */
231 TRUE, /* pc_relative */
232 16, /* bitpos */
233 complain_overflow_signed,/* complain_on_overflow */
234 bfd_elf_generic_reloc, /* special_function */
235 "R_C6000_PCR_S7", /* name */
236 FALSE, /* partial_inplace */
237 0, /* src_mask */
238 0x007f0000, /* dst_mask */
239 TRUE), /* pcrel_offset */
240 HOWTO (R_C6000_ABS_S16, /* type */
241 0, /* rightshift */
242 2, /* size (0 = byte, 1 = short, 2 = long) */
243 16, /* bitsize */
244 FALSE, /* pc_relative */
245 7, /* bitpos */
246 complain_overflow_signed,/* complain_on_overflow */
247 bfd_elf_generic_reloc, /* special_function */
248 "R_C6000_ABS_S16", /* name */
249 FALSE, /* partial_inplace */
250 0, /* src_mask */
251 0x007fff80, /* dst_mask */
252 FALSE), /* pcrel_offset */
253 HOWTO (R_C6000_ABS_L16, /* type */
254 0, /* rightshift */
255 2, /* size (0 = byte, 1 = short, 2 = long) */
256 16, /* bitsize */
257 FALSE, /* pc_relative */
258 7, /* bitpos */
259 complain_overflow_dont,/* complain_on_overflow */
260 bfd_elf_generic_reloc, /* special_function */
261 "R_C6000_ABS_L16", /* name */
262 FALSE, /* partial_inplace */
263 0, /* src_mask */
264 0x007fff80, /* dst_mask */
265 FALSE), /* pcrel_offset */
266 HOWTO (R_C6000_ABS_H16, /* type */
267 16, /* rightshift */
268 2, /* size (0 = byte, 1 = short, 2 = long) */
269 16, /* bitsize */
270 FALSE, /* pc_relative */
271 7, /* bitpos */
272 complain_overflow_dont,/* complain_on_overflow */
273 bfd_elf_generic_reloc, /* special_function */
274 "R_C6000_ABS_H16", /* name */
275 FALSE, /* partial_inplace */
276 0, /* src_mask */
277 0x007fff80, /* dst_mask */
278 FALSE), /* pcrel_offset */
279 HOWTO (R_C6000_SBR_U15_B, /* type */
280 0, /* rightshift */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
282 15, /* bitsize */
283 FALSE, /* pc_relative */
284 8, /* bitpos */
285 complain_overflow_unsigned,/* complain_on_overflow */
286 bfd_elf_generic_reloc, /* special_function */
287 "R_C6000_SBR_U15_B", /* name */
288 FALSE, /* partial_inplace */
289 0, /* src_mask */
290 0x007fff00, /* dst_mask */
291 FALSE), /* pcrel_offset */
292 HOWTO (R_C6000_SBR_U15_H, /* type */
293 1, /* rightshift */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
295 15, /* bitsize */
296 FALSE, /* pc_relative */
297 8, /* bitpos */
298 complain_overflow_unsigned,/* complain_on_overflow */
299 bfd_elf_generic_reloc, /* special_function */
300 "R_C6000_SBR_U15_H", /* name */
301 FALSE, /* partial_inplace */
302 0, /* src_mask */
303 0x007fff00, /* dst_mask */
304 FALSE), /* pcrel_offset */
305 HOWTO (R_C6000_SBR_U15_W, /* type */
306 2, /* rightshift */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
308 15, /* bitsize */
309 FALSE, /* pc_relative */
310 8, /* bitpos */
311 complain_overflow_unsigned,/* complain_on_overflow */
312 bfd_elf_generic_reloc, /* special_function */
313 "R_C6000_SBR_U15_W", /* name */
314 FALSE, /* partial_inplace */
315 0, /* src_mask */
316 0x007fff00, /* dst_mask */
317 FALSE), /* pcrel_offset */
318 HOWTO (R_C6000_SBR_S16, /* type */
319 0, /* rightshift */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
321 16, /* bitsize */
322 FALSE, /* pc_relative */
323 7, /* bitpos */
324 complain_overflow_signed,/* complain_on_overflow */
325 bfd_elf_generic_reloc, /* special_function */
326 "R_C6000_SBR_S16", /* name */
327 FALSE, /* partial_inplace */
328 0, /* src_mask */
329 0x007fff80, /* dst_mask */
330 FALSE), /* pcrel_offset */
331 HOWTO (R_C6000_SBR_L16_B, /* type */
332 0, /* rightshift */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
334 16, /* bitsize */
335 FALSE, /* pc_relative */
336 7, /* bitpos */
337 complain_overflow_dont,/* complain_on_overflow */
338 bfd_elf_generic_reloc, /* special_function */
339 "R_C6000_SBR_L16_B", /* name */
340 FALSE, /* partial_inplace */
341 0, /* src_mask */
342 0x007fff80, /* dst_mask */
343 FALSE), /* pcrel_offset */
344 HOWTO (R_C6000_SBR_L16_H, /* type */
345 1, /* rightshift */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
347 16, /* bitsize */
348 FALSE, /* pc_relative */
349 7, /* bitpos */
350 complain_overflow_dont,/* complain_on_overflow */
351 bfd_elf_generic_reloc, /* special_function */
352 "R_C6000_SBR_L16_H", /* name */
353 FALSE, /* partial_inplace */
354 0, /* src_mask */
355 0x007fff80, /* dst_mask */
356 FALSE), /* pcrel_offset */
357 HOWTO (R_C6000_SBR_L16_W, /* type */
358 2, /* rightshift */
359 2, /* size (0 = byte, 1 = short, 2 = long) */
360 16, /* bitsize */
361 FALSE, /* pc_relative */
362 7, /* bitpos */
363 complain_overflow_dont,/* complain_on_overflow */
364 bfd_elf_generic_reloc, /* special_function */
365 "R_C6000_SBR_L16_W", /* name */
366 FALSE, /* partial_inplace */
367 0, /* src_mask */
368 0x007fff80, /* dst_mask */
369 FALSE), /* pcrel_offset */
370 HOWTO (R_C6000_SBR_H16_B, /* type */
371 16, /* rightshift */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
373 16, /* bitsize */
374 FALSE, /* pc_relative */
375 7, /* bitpos */
376 complain_overflow_dont,/* complain_on_overflow */
377 bfd_elf_generic_reloc, /* special_function */
378 "R_C6000_SBR_H16_B", /* name */
379 FALSE, /* partial_inplace */
380 0, /* src_mask */
381 0x007fff80, /* dst_mask */
382 FALSE), /* pcrel_offset */
383 HOWTO (R_C6000_SBR_H16_H, /* type */
384 17, /* rightshift */
385 2, /* size (0 = byte, 1 = short, 2 = long) */
386 16, /* bitsize */
387 FALSE, /* pc_relative */
388 7, /* bitpos */
389 complain_overflow_dont,/* complain_on_overflow */
390 bfd_elf_generic_reloc, /* special_function */
391 "R_C6000_SBR_H16_H", /* name */
392 FALSE, /* partial_inplace */
393 0, /* src_mask */
394 0x007fff80, /* dst_mask */
395 FALSE), /* pcrel_offset */
396 HOWTO (R_C6000_SBR_H16_W, /* type */
397 18, /* rightshift */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
399 16, /* bitsize */
400 FALSE, /* pc_relative */
401 7, /* bitpos */
402 complain_overflow_dont,/* complain_on_overflow */
403 bfd_elf_generic_reloc, /* special_function */
404 "R_C6000_SBR_H16_W", /* name */
405 FALSE, /* partial_inplace */
406 0, /* src_mask */
407 0x007fff80, /* dst_mask */
408 FALSE), /* pcrel_offset */
409 HOWTO (R_C6000_SBR_GOT_U15_W, /* type */
410 2, /* rightshift */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
412 15, /* bitsize */
413 FALSE, /* pc_relative */
414 8, /* bitpos */
415 complain_overflow_unsigned,/* complain_on_overflow */
416 bfd_elf_generic_reloc, /* special_function */
417 "R_C6000_SBR_GOT_U15_W",/* name */
418 FALSE, /* partial_inplace */
419 0, /* src_mask */
420 0x007fff00, /* dst_mask */
421 FALSE), /* pcrel_offset */
422 HOWTO (R_C6000_SBR_GOT_L16_W, /* type */
423 2, /* rightshift */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
425 16, /* bitsize */
426 FALSE, /* pc_relative */
427 7, /* bitpos */
428 complain_overflow_dont,/* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 "R_C6000_SBR_GOT_L16_W",/* name */
431 FALSE, /* partial_inplace */
432 0, /* src_mask */
433 0x007fff80, /* dst_mask */
434 FALSE), /* pcrel_offset */
435 HOWTO (R_C6000_SBR_GOT_H16_W, /* type */
436 18, /* rightshift */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
438 16, /* bitsize */
439 FALSE, /* pc_relative */
440 7, /* bitpos */
441 complain_overflow_dont,/* complain_on_overflow */
442 bfd_elf_generic_reloc, /* special_function */
443 "R_C6000_SBR_GOT_H16_W",/* name */
444 FALSE, /* partial_inplace */
445 0, /* src_mask */
446 0x007fff80, /* dst_mask */
447 FALSE), /* pcrel_offset */
448 HOWTO (R_C6000_DSBT_INDEX, /* type */
449 0, /* rightshift */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
451 15, /* bitsize */
452 FALSE, /* pc_relative */
453 8, /* bitpos */
454 complain_overflow_unsigned,/* complain_on_overflow */
455 bfd_elf_generic_reloc, /* special_function */
456 "R_C6000_DSBT_INDEX", /* name */
457 FALSE, /* partial_inplace */
458 0, /* src_mask */
459 0x007fff00, /* dst_mask */
460 FALSE), /* pcrel_offset */
461 HOWTO (R_C6000_PREL31, /* type */
462 1, /* rightshift */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
464 31, /* bitsize */
44e87ece 465 TRUE, /* pc_relative */
41820509
JM
466 0, /* bitpos */
467 complain_overflow_dont,/* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
469 "R_C6000_PREL31", /* name */
470 FALSE, /* partial_inplace */
471 0, /* src_mask */
472 0x7fffffff, /* dst_mask */
44e87ece 473 TRUE), /* pcrel_offset */
41820509
JM
474 HOWTO (R_C6000_COPY, /* type */
475 0, /* rightshift */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
477 32, /* bitsize */
478 FALSE, /* pc_relative */
479 0, /* bitpos */
480 complain_overflow_dont,/* complain_on_overflow */
481 bfd_elf_generic_reloc, /* special_function */
482 "R_C6000_COPY", /* name */
483 FALSE, /* partial_inplace */
484 0, /* src_mask */
485 0xffffffff, /* dst_mask */
486 FALSE), /* pcrel_offset */
ac145307
BS
487 HOWTO (R_C6000_JUMP_SLOT, /* type */
488 0, /* rightshift */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
490 32, /* bitsize */
491 FALSE, /* pc_relative */
492 0, /* bitpos */
493 complain_overflow_dont,/* complain_on_overflow */
494 bfd_elf_generic_reloc, /* special_function */
495 "R_C6000_JUMP_SLOT", /* name */
496 FALSE, /* partial_inplace */
497 0, /* src_mask */
498 0xffffffff, /* dst_mask */
499 FALSE), /* pcrel_offset */
2fbb87f6
PB
500 HOWTO (R_C6000_EHTYPE, /* type */
501 0, /* rightshift */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
503 32, /* bitsize */
504 FALSE, /* pc_relative */
505 0, /* bitpos */
506 complain_overflow_dont,/* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 "R_C6000_EHTYPE", /* name */
509 FALSE, /* partial_inplace */
510 0, /* src_mask */
511 0xffffffff, /* dst_mask */
512 FALSE), /* pcrel_offset */
4a732032
BS
513 HOWTO (R_C6000_PCR_H16, /* type */
514 16, /* rightshift */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
516 16, /* bitsize */
517 TRUE, /* pc_relative */
518 7, /* bitpos */
519 complain_overflow_dont,/* complain_on_overflow */
520 bfd_elf_generic_reloc, /* special_function */
521 "R_C6000_PCR_H16", /* name */
522 FALSE, /* partial_inplace */
523 0, /* src_mask */
524 0x007fff80, /* dst_mask */
525 TRUE), /* pcrel_offset */
526 HOWTO (R_C6000_PCR_L16, /* type */
527 0, /* rightshift */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
529 16, /* bitsize */
530 TRUE, /* pc_relative */
531 7, /* bitpos */
532 complain_overflow_dont,/* complain_on_overflow */
533 bfd_elf_generic_reloc, /* special_function */
534 "R_C6000_PCR_L16", /* name */
535 FALSE, /* partial_inplace */
536 0, /* src_mask */
537 0x007fff80, /* dst_mask */
538 TRUE), /* pcrel_offset */
41820509
JM
539 EMPTY_HOWTO (31),
540 EMPTY_HOWTO (32),
541 EMPTY_HOWTO (33),
542 EMPTY_HOWTO (34),
543 EMPTY_HOWTO (35),
544 EMPTY_HOWTO (36),
545 EMPTY_HOWTO (37),
546 EMPTY_HOWTO (38),
547 EMPTY_HOWTO (39),
548 EMPTY_HOWTO (40),
549 EMPTY_HOWTO (41),
550 EMPTY_HOWTO (42),
551 EMPTY_HOWTO (43),
552 EMPTY_HOWTO (44),
553 EMPTY_HOWTO (45),
554 EMPTY_HOWTO (46),
555 EMPTY_HOWTO (47),
556 EMPTY_HOWTO (48),
557 EMPTY_HOWTO (49),
558 EMPTY_HOWTO (50),
559 EMPTY_HOWTO (51),
560 EMPTY_HOWTO (52),
561 EMPTY_HOWTO (53),
562 EMPTY_HOWTO (54),
563 EMPTY_HOWTO (55),
564 EMPTY_HOWTO (56),
565 EMPTY_HOWTO (57),
566 EMPTY_HOWTO (58),
567 EMPTY_HOWTO (59),
568 EMPTY_HOWTO (60),
569 EMPTY_HOWTO (61),
570 EMPTY_HOWTO (62),
571 EMPTY_HOWTO (63),
572 EMPTY_HOWTO (64),
573 EMPTY_HOWTO (65),
574 EMPTY_HOWTO (66),
575 EMPTY_HOWTO (67),
576 EMPTY_HOWTO (68),
577 EMPTY_HOWTO (69),
578 EMPTY_HOWTO (70),
579 EMPTY_HOWTO (71),
580 EMPTY_HOWTO (72),
581 EMPTY_HOWTO (73),
582 EMPTY_HOWTO (74),
583 EMPTY_HOWTO (75),
584 EMPTY_HOWTO (76),
585 EMPTY_HOWTO (77),
586 EMPTY_HOWTO (78),
587 EMPTY_HOWTO (79),
588 EMPTY_HOWTO (80),
589 EMPTY_HOWTO (81),
590 EMPTY_HOWTO (82),
591 EMPTY_HOWTO (83),
592 EMPTY_HOWTO (84),
593 EMPTY_HOWTO (85),
594 EMPTY_HOWTO (86),
595 EMPTY_HOWTO (87),
596 EMPTY_HOWTO (88),
597 EMPTY_HOWTO (89),
598 EMPTY_HOWTO (90),
599 EMPTY_HOWTO (91),
600 EMPTY_HOWTO (92),
601 EMPTY_HOWTO (93),
602 EMPTY_HOWTO (94),
603 EMPTY_HOWTO (95),
604 EMPTY_HOWTO (96),
605 EMPTY_HOWTO (97),
606 EMPTY_HOWTO (98),
607 EMPTY_HOWTO (99),
608 EMPTY_HOWTO (100),
609 EMPTY_HOWTO (101),
610 EMPTY_HOWTO (102),
611 EMPTY_HOWTO (103),
612 EMPTY_HOWTO (104),
613 EMPTY_HOWTO (105),
614 EMPTY_HOWTO (106),
615 EMPTY_HOWTO (107),
616 EMPTY_HOWTO (108),
617 EMPTY_HOWTO (109),
618 EMPTY_HOWTO (110),
619 EMPTY_HOWTO (111),
620 EMPTY_HOWTO (112),
621 EMPTY_HOWTO (113),
622 EMPTY_HOWTO (114),
623 EMPTY_HOWTO (115),
624 EMPTY_HOWTO (116),
625 EMPTY_HOWTO (117),
626 EMPTY_HOWTO (118),
627 EMPTY_HOWTO (119),
628 EMPTY_HOWTO (120),
629 EMPTY_HOWTO (121),
630 EMPTY_HOWTO (122),
631 EMPTY_HOWTO (123),
632 EMPTY_HOWTO (124),
633 EMPTY_HOWTO (125),
634 EMPTY_HOWTO (126),
635 EMPTY_HOWTO (127),
636 EMPTY_HOWTO (128),
637 EMPTY_HOWTO (129),
638 EMPTY_HOWTO (130),
639 EMPTY_HOWTO (131),
640 EMPTY_HOWTO (132),
641 EMPTY_HOWTO (133),
642 EMPTY_HOWTO (134),
643 EMPTY_HOWTO (135),
644 EMPTY_HOWTO (136),
645 EMPTY_HOWTO (137),
646 EMPTY_HOWTO (138),
647 EMPTY_HOWTO (139),
648 EMPTY_HOWTO (140),
649 EMPTY_HOWTO (141),
650 EMPTY_HOWTO (142),
651 EMPTY_HOWTO (143),
652 EMPTY_HOWTO (144),
653 EMPTY_HOWTO (145),
654 EMPTY_HOWTO (146),
655 EMPTY_HOWTO (147),
656 EMPTY_HOWTO (148),
657 EMPTY_HOWTO (149),
658 EMPTY_HOWTO (150),
659 EMPTY_HOWTO (151),
660 EMPTY_HOWTO (152),
661 EMPTY_HOWTO (153),
662 EMPTY_HOWTO (154),
663 EMPTY_HOWTO (155),
664 EMPTY_HOWTO (156),
665 EMPTY_HOWTO (157),
666 EMPTY_HOWTO (158),
667 EMPTY_HOWTO (159),
668 EMPTY_HOWTO (160),
669 EMPTY_HOWTO (161),
670 EMPTY_HOWTO (162),
671 EMPTY_HOWTO (163),
672 EMPTY_HOWTO (164),
673 EMPTY_HOWTO (165),
674 EMPTY_HOWTO (166),
675 EMPTY_HOWTO (167),
676 EMPTY_HOWTO (168),
677 EMPTY_HOWTO (169),
678 EMPTY_HOWTO (170),
679 EMPTY_HOWTO (171),
680 EMPTY_HOWTO (172),
681 EMPTY_HOWTO (173),
682 EMPTY_HOWTO (174),
683 EMPTY_HOWTO (175),
684 EMPTY_HOWTO (176),
685 EMPTY_HOWTO (177),
686 EMPTY_HOWTO (178),
687 EMPTY_HOWTO (179),
688 EMPTY_HOWTO (180),
689 EMPTY_HOWTO (181),
690 EMPTY_HOWTO (182),
691 EMPTY_HOWTO (183),
692 EMPTY_HOWTO (184),
693 EMPTY_HOWTO (185),
694 EMPTY_HOWTO (186),
695 EMPTY_HOWTO (187),
696 EMPTY_HOWTO (188),
697 EMPTY_HOWTO (189),
698 EMPTY_HOWTO (190),
699 EMPTY_HOWTO (191),
700 EMPTY_HOWTO (192),
701 EMPTY_HOWTO (193),
702 EMPTY_HOWTO (194),
703 EMPTY_HOWTO (195),
704 EMPTY_HOWTO (196),
705 EMPTY_HOWTO (197),
706 EMPTY_HOWTO (198),
707 EMPTY_HOWTO (199),
708 EMPTY_HOWTO (200),
709 EMPTY_HOWTO (201),
710 EMPTY_HOWTO (202),
711 EMPTY_HOWTO (203),
712 EMPTY_HOWTO (204),
713 EMPTY_HOWTO (205),
714 EMPTY_HOWTO (206),
715 EMPTY_HOWTO (207),
716 EMPTY_HOWTO (208),
717 EMPTY_HOWTO (209),
718 EMPTY_HOWTO (210),
719 EMPTY_HOWTO (211),
720 EMPTY_HOWTO (212),
721 EMPTY_HOWTO (213),
722 EMPTY_HOWTO (214),
723 EMPTY_HOWTO (215),
724 EMPTY_HOWTO (216),
725 EMPTY_HOWTO (217),
726 EMPTY_HOWTO (218),
727 EMPTY_HOWTO (219),
728 EMPTY_HOWTO (220),
729 EMPTY_HOWTO (221),
730 EMPTY_HOWTO (222),
731 EMPTY_HOWTO (223),
732 EMPTY_HOWTO (224),
733 EMPTY_HOWTO (225),
734 EMPTY_HOWTO (226),
735 EMPTY_HOWTO (227),
736 EMPTY_HOWTO (228),
737 EMPTY_HOWTO (229),
738 EMPTY_HOWTO (230),
739 EMPTY_HOWTO (231),
740 EMPTY_HOWTO (232),
741 EMPTY_HOWTO (233),
742 EMPTY_HOWTO (234),
743 EMPTY_HOWTO (235),
744 EMPTY_HOWTO (236),
745 EMPTY_HOWTO (237),
746 EMPTY_HOWTO (238),
747 EMPTY_HOWTO (239),
748 EMPTY_HOWTO (240),
749 EMPTY_HOWTO (241),
750 EMPTY_HOWTO (242),
751 EMPTY_HOWTO (243),
752 EMPTY_HOWTO (244),
753 EMPTY_HOWTO (245),
754 EMPTY_HOWTO (246),
755 EMPTY_HOWTO (247),
756 EMPTY_HOWTO (248),
757 EMPTY_HOWTO (249),
758 EMPTY_HOWTO (250),
759 EMPTY_HOWTO (251),
760 EMPTY_HOWTO (252),
761 HOWTO (R_C6000_ALIGN, /* type */
762 0, /* rightshift */
763 0, /* size (0 = byte, 1 = short, 2 = long) */
764 0, /* bitsize */
765 FALSE, /* pc_relative */
766 0, /* bitpos */
767 complain_overflow_dont,/* complain_on_overflow */
768 bfd_elf_generic_reloc, /* special_function */
769 "R_C6000_ALIGN", /* name */
770 FALSE, /* partial_inplace */
771 0, /* src_mask */
772 0, /* dst_mask */
773 FALSE), /* pcrel_offset */
774 HOWTO (R_C6000_FPHEAD, /* type */
775 0, /* rightshift */
776 0, /* size (0 = byte, 1 = short, 2 = long) */
777 0, /* bitsize */
778 FALSE, /* pc_relative */
779 0, /* bitpos */
780 complain_overflow_dont,/* complain_on_overflow */
781 bfd_elf_generic_reloc, /* special_function */
782 "R_C6000_FPHEAD", /* name */
783 FALSE, /* partial_inplace */
784 0, /* src_mask */
785 0, /* dst_mask */
786 FALSE), /* pcrel_offset */
787 HOWTO (R_C6000_NOCMP, /* type */
788 0, /* rightshift */
789 0, /* size (0 = byte, 1 = short, 2 = long) */
790 0, /* bitsize */
791 FALSE, /* pc_relative */
792 0, /* bitpos */
793 complain_overflow_dont,/* complain_on_overflow */
794 bfd_elf_generic_reloc, /* special_function */
795 "R_C6000_NOCMP", /* name */
796 FALSE, /* partial_inplace */
797 0, /* src_mask */
798 0, /* dst_mask */
799 FALSE) /* pcrel_offset */
800};
801
802static reloc_howto_type elf32_tic6x_howto_table_rel[] =
803{
804 HOWTO (R_C6000_NONE, /* type */
805 0, /* rightshift */
6346d5ca 806 3, /* size (0 = byte, 1 = short, 2 = long) */
41820509
JM
807 0, /* bitsize */
808 FALSE, /* pc_relative */
809 0, /* bitpos */
810 complain_overflow_dont,/* complain_on_overflow */
811 bfd_elf_generic_reloc, /* special_function */
812 "R_C6000_NONE", /* name */
813 TRUE, /* partial_inplace */
40b36596
JM
814 0, /* src_mask */
815 0, /* dst_mask */
816 FALSE), /* pcrel_offset */
817 HOWTO (R_C6000_ABS32, /* type */
818 0, /* rightshift */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
820 32, /* bitsize */
821 FALSE, /* pc_relative */
822 0, /* bitpos */
823 complain_overflow_dont,/* complain_on_overflow */
824 bfd_elf_generic_reloc, /* special_function */
825 "R_C6000_ABS32", /* name */
41820509
JM
826 TRUE, /* partial_inplace */
827 0xffffffff, /* src_mask */
40b36596
JM
828 0xffffffff, /* dst_mask */
829 FALSE), /* pcrel_offset */
830 HOWTO (R_C6000_ABS16, /* type */
831 0, /* rightshift */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
833 16, /* bitsize */
834 FALSE, /* pc_relative */
835 0, /* bitpos */
836 complain_overflow_bitfield,/* complain_on_overflow */
837 bfd_elf_generic_reloc, /* special_function */
838 "R_C6000_ABS16", /* name */
41820509
JM
839 TRUE, /* partial_inplace */
840 0x0000ffff, /* src_mask */
40b36596
JM
841 0x0000ffff, /* dst_mask */
842 FALSE), /* pcrel_offset */
843 HOWTO (R_C6000_ABS8, /* type */
844 0, /* rightshift */
845 0, /* size (0 = byte, 1 = short, 2 = long) */
846 8, /* bitsize */
847 FALSE, /* pc_relative */
848 0, /* bitpos */
849 complain_overflow_bitfield,/* complain_on_overflow */
850 bfd_elf_generic_reloc, /* special_function */
851 "R_C6000_ABS8", /* name */
41820509
JM
852 TRUE, /* partial_inplace */
853 0x000000ff, /* src_mask */
40b36596
JM
854 0x000000ff, /* dst_mask */
855 FALSE), /* pcrel_offset */
856 HOWTO (R_C6000_PCR_S21, /* type */
857 2, /* rightshift */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
859 21, /* bitsize */
860 TRUE, /* pc_relative */
861 7, /* bitpos */
862 complain_overflow_signed,/* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_C6000_PCR_S21", /* name */
41820509
JM
865 TRUE, /* partial_inplace */
866 0x0fffff80, /* src_mask */
40b36596
JM
867 0x0fffff80, /* dst_mask */
868 TRUE), /* pcrel_offset */
869 HOWTO (R_C6000_PCR_S12, /* type */
870 2, /* rightshift */
871 2, /* size (0 = byte, 1 = short, 2 = long) */
872 12, /* bitsize */
873 TRUE, /* pc_relative */
874 16, /* bitpos */
875 complain_overflow_signed,/* complain_on_overflow */
876 bfd_elf_generic_reloc, /* special_function */
877 "R_C6000_PCR_S12", /* name */
41820509
JM
878 TRUE, /* partial_inplace */
879 0x0fff0000, /* src_mask */
40b36596
JM
880 0x0fff0000, /* dst_mask */
881 TRUE), /* pcrel_offset */
882 HOWTO (R_C6000_PCR_S10, /* type */
883 2, /* rightshift */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
885 10, /* bitsize */
886 TRUE, /* pc_relative */
887 13, /* bitpos */
888 complain_overflow_signed,/* complain_on_overflow */
889 bfd_elf_generic_reloc, /* special_function */
890 "R_C6000_PCR_S10", /* name */
41820509
JM
891 TRUE, /* partial_inplace */
892 0x007fe000, /* src_mask */
40b36596
JM
893 0x007fe000, /* dst_mask */
894 TRUE), /* pcrel_offset */
895 HOWTO (R_C6000_PCR_S7, /* type */
896 2, /* rightshift */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
898 7, /* bitsize */
899 TRUE, /* pc_relative */
900 16, /* bitpos */
901 complain_overflow_signed,/* complain_on_overflow */
902 bfd_elf_generic_reloc, /* special_function */
903 "R_C6000_PCR_S7", /* name */
41820509
JM
904 TRUE, /* partial_inplace */
905 0x007f0000, /* src_mask */
40b36596
JM
906 0x007f0000, /* dst_mask */
907 TRUE), /* pcrel_offset */
908 HOWTO (R_C6000_ABS_S16, /* type */
909 0, /* rightshift */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
911 16, /* bitsize */
912 FALSE, /* pc_relative */
913 7, /* bitpos */
914 complain_overflow_signed,/* complain_on_overflow */
915 bfd_elf_generic_reloc, /* special_function */
916 "R_C6000_ABS_S16", /* name */
41820509
JM
917 TRUE, /* partial_inplace */
918 0x007fff80, /* src_mask */
40b36596
JM
919 0x007fff80, /* dst_mask */
920 FALSE), /* pcrel_offset */
921 HOWTO (R_C6000_ABS_L16, /* type */
922 0, /* rightshift */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
924 16, /* bitsize */
925 FALSE, /* pc_relative */
926 7, /* bitpos */
927 complain_overflow_dont,/* complain_on_overflow */
928 bfd_elf_generic_reloc, /* special_function */
929 "R_C6000_ABS_L16", /* name */
41820509
JM
930 TRUE, /* partial_inplace */
931 0x007fff80, /* src_mask */
40b36596
JM
932 0x007fff80, /* dst_mask */
933 FALSE), /* pcrel_offset */
41820509 934 EMPTY_HOWTO (R_C6000_ABS_H16),
40b36596
JM
935 HOWTO (R_C6000_SBR_U15_B, /* type */
936 0, /* rightshift */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
938 15, /* bitsize */
939 FALSE, /* pc_relative */
940 8, /* bitpos */
941 complain_overflow_unsigned,/* complain_on_overflow */
942 bfd_elf_generic_reloc, /* special_function */
943 "R_C6000_SBR_U15_B", /* name */
41820509
JM
944 TRUE, /* partial_inplace */
945 0x007fff00, /* src_mask */
40b36596
JM
946 0x007fff00, /* dst_mask */
947 FALSE), /* pcrel_offset */
948 HOWTO (R_C6000_SBR_U15_H, /* type */
949 1, /* rightshift */
950 2, /* size (0 = byte, 1 = short, 2 = long) */
951 15, /* bitsize */
952 FALSE, /* pc_relative */
953 8, /* bitpos */
954 complain_overflow_unsigned,/* complain_on_overflow */
955 bfd_elf_generic_reloc, /* special_function */
956 "R_C6000_SBR_U15_H", /* name */
41820509
JM
957 TRUE, /* partial_inplace */
958 0x007fff00, /* src_mask */
40b36596
JM
959 0x007fff00, /* dst_mask */
960 FALSE), /* pcrel_offset */
961 HOWTO (R_C6000_SBR_U15_W, /* type */
962 2, /* rightshift */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
964 15, /* bitsize */
965 FALSE, /* pc_relative */
966 8, /* bitpos */
967 complain_overflow_unsigned,/* complain_on_overflow */
968 bfd_elf_generic_reloc, /* special_function */
969 "R_C6000_SBR_U15_W", /* name */
41820509
JM
970 TRUE, /* partial_inplace */
971 0x007fff00, /* src_mask */
40b36596
JM
972 0x007fff00, /* dst_mask */
973 FALSE), /* pcrel_offset */
974 HOWTO (R_C6000_SBR_S16, /* type */
975 0, /* rightshift */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
977 16, /* bitsize */
978 FALSE, /* pc_relative */
979 7, /* bitpos */
980 complain_overflow_signed,/* complain_on_overflow */
981 bfd_elf_generic_reloc, /* special_function */
982 "R_C6000_SBR_S16", /* name */
41820509
JM
983 TRUE, /* partial_inplace */
984 0x007fff80, /* src_mask */
40b36596
JM
985 0x007fff80, /* dst_mask */
986 FALSE), /* pcrel_offset */
987 HOWTO (R_C6000_SBR_L16_B, /* type */
988 0, /* rightshift */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
990 16, /* bitsize */
991 FALSE, /* pc_relative */
992 7, /* bitpos */
993 complain_overflow_dont,/* complain_on_overflow */
994 bfd_elf_generic_reloc, /* special_function */
995 "R_C6000_SBR_L16_B", /* name */
41820509
JM
996 TRUE, /* partial_inplace */
997 0x007fff80, /* src_mask */
40b36596
JM
998 0x007fff80, /* dst_mask */
999 FALSE), /* pcrel_offset */
1000 HOWTO (R_C6000_SBR_L16_H, /* type */
1001 1, /* rightshift */
1002 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 16, /* bitsize */
1004 FALSE, /* pc_relative */
1005 7, /* bitpos */
1006 complain_overflow_dont,/* complain_on_overflow */
1007 bfd_elf_generic_reloc, /* special_function */
1008 "R_C6000_SBR_L16_H", /* name */
41820509
JM
1009 TRUE, /* partial_inplace */
1010 0x007fff80, /* src_mask */
40b36596
JM
1011 0x007fff80, /* dst_mask */
1012 FALSE), /* pcrel_offset */
1013 HOWTO (R_C6000_SBR_L16_W, /* type */
1014 2, /* rightshift */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1016 16, /* bitsize */
1017 FALSE, /* pc_relative */
1018 7, /* bitpos */
1019 complain_overflow_dont,/* complain_on_overflow */
1020 bfd_elf_generic_reloc, /* special_function */
1021 "R_C6000_SBR_L16_W", /* name */
41820509
JM
1022 TRUE, /* partial_inplace */
1023 0x007fff80, /* src_mask */
40b36596
JM
1024 0x007fff80, /* dst_mask */
1025 FALSE), /* pcrel_offset */
41820509
JM
1026 EMPTY_HOWTO (R_C6000_SBR_H16_B),
1027 EMPTY_HOWTO (R_C6000_SBR_H16_H),
1028 EMPTY_HOWTO (R_C6000_SBR_H16_W),
40b36596
JM
1029 HOWTO (R_C6000_SBR_GOT_U15_W, /* type */
1030 2, /* rightshift */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 15, /* bitsize */
1033 FALSE, /* pc_relative */
1034 8, /* bitpos */
1035 complain_overflow_unsigned,/* complain_on_overflow */
1036 bfd_elf_generic_reloc, /* special_function */
1037 "R_C6000_SBR_GOT_U15_W",/* name */
41820509
JM
1038 TRUE, /* partial_inplace */
1039 0x007fff00, /* src_mask */
40b36596
JM
1040 0x007fff00, /* dst_mask */
1041 FALSE), /* pcrel_offset */
1042 HOWTO (R_C6000_SBR_GOT_L16_W, /* type */
1043 2, /* rightshift */
1044 2, /* size (0 = byte, 1 = short, 2 = long) */
1045 16, /* bitsize */
1046 FALSE, /* pc_relative */
1047 7, /* bitpos */
1048 complain_overflow_dont,/* complain_on_overflow */
1049 bfd_elf_generic_reloc, /* special_function */
1050 "R_C6000_SBR_GOT_L16_W",/* name */
41820509
JM
1051 TRUE, /* partial_inplace */
1052 0x007fff80, /* src_mask */
40b36596
JM
1053 0x007fff80, /* dst_mask */
1054 FALSE), /* pcrel_offset */
41820509 1055 EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W),
40b36596
JM
1056 HOWTO (R_C6000_DSBT_INDEX, /* type */
1057 0, /* rightshift */
1058 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 15, /* bitsize */
1060 FALSE, /* pc_relative */
1061 8, /* bitpos */
1062 complain_overflow_unsigned,/* complain_on_overflow */
1063 bfd_elf_generic_reloc, /* special_function */
1064 "R_C6000_DSBT_INDEX", /* name */
41820509 1065 TRUE, /* partial_inplace */
40b36596
JM
1066 0, /* src_mask */
1067 0x007fff00, /* dst_mask */
1068 FALSE), /* pcrel_offset */
1069 HOWTO (R_C6000_PREL31, /* type */
1070 1, /* rightshift */
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1072 31, /* bitsize */
44e87ece 1073 TRUE, /* pc_relative */
40b36596
JM
1074 0, /* bitpos */
1075 complain_overflow_dont,/* complain_on_overflow */
1076 bfd_elf_generic_reloc, /* special_function */
1077 "R_C6000_PREL31", /* name */
41820509 1078 TRUE, /* partial_inplace */
40b36596
JM
1079 0, /* src_mask */
1080 0x7fffffff, /* dst_mask */
44e87ece 1081 TRUE), /* pcrel_offset */
40b36596
JM
1082 HOWTO (R_C6000_COPY, /* type */
1083 0, /* rightshift */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1085 32, /* bitsize */
1086 FALSE, /* pc_relative */
1087 0, /* bitpos */
1088 complain_overflow_dont,/* complain_on_overflow */
1089 bfd_elf_generic_reloc, /* special_function */
1090 "R_C6000_COPY", /* name */
41820509 1091 TRUE, /* partial_inplace */
40b36596
JM
1092 0, /* src_mask */
1093 0xffffffff, /* dst_mask */
1094 FALSE), /* pcrel_offset */
ac145307
BS
1095 HOWTO (R_C6000_JUMP_SLOT, /* type */
1096 0, /* rightshift */
1097 2, /* size (0 = byte, 1 = short, 2 = long) */
1098 32, /* bitsize */
1099 FALSE, /* pc_relative */
1100 0, /* bitpos */
1101 complain_overflow_dont,/* complain_on_overflow */
1102 bfd_elf_generic_reloc, /* special_function */
1103 "R_C6000_JUMP_SLOT", /* name */
1104 FALSE, /* partial_inplace */
1105 0, /* src_mask */
1106 0xffffffff, /* dst_mask */
1107 FALSE), /* pcrel_offset */
2fbb87f6
PB
1108 HOWTO (R_C6000_EHTYPE, /* type */
1109 0, /* rightshift */
1110 2, /* size (0 = byte, 1 = short, 2 = long) */
1111 32, /* bitsize */
1112 FALSE, /* pc_relative */
1113 0, /* bitpos */
1114 complain_overflow_dont,/* complain_on_overflow */
1115 bfd_elf_generic_reloc, /* special_function */
1116 "R_C6000_EHTYPE", /* name */
1117 FALSE, /* partial_inplace */
1118 0, /* src_mask */
1119 0xffffffff, /* dst_mask */
1120 FALSE), /* pcrel_offset */
4a732032
BS
1121 EMPTY_HOWTO (R_C6000_PCR_H16),
1122 EMPTY_HOWTO (R_C6000_PCR_L16),
40b36596
JM
1123 EMPTY_HOWTO (31),
1124 EMPTY_HOWTO (32),
1125 EMPTY_HOWTO (33),
1126 EMPTY_HOWTO (34),
1127 EMPTY_HOWTO (35),
1128 EMPTY_HOWTO (36),
1129 EMPTY_HOWTO (37),
1130 EMPTY_HOWTO (38),
1131 EMPTY_HOWTO (39),
1132 EMPTY_HOWTO (40),
1133 EMPTY_HOWTO (41),
1134 EMPTY_HOWTO (42),
1135 EMPTY_HOWTO (43),
1136 EMPTY_HOWTO (44),
1137 EMPTY_HOWTO (45),
1138 EMPTY_HOWTO (46),
1139 EMPTY_HOWTO (47),
1140 EMPTY_HOWTO (48),
1141 EMPTY_HOWTO (49),
1142 EMPTY_HOWTO (50),
1143 EMPTY_HOWTO (51),
1144 EMPTY_HOWTO (52),
1145 EMPTY_HOWTO (53),
1146 EMPTY_HOWTO (54),
1147 EMPTY_HOWTO (55),
1148 EMPTY_HOWTO (56),
1149 EMPTY_HOWTO (57),
1150 EMPTY_HOWTO (58),
1151 EMPTY_HOWTO (59),
1152 EMPTY_HOWTO (60),
1153 EMPTY_HOWTO (61),
1154 EMPTY_HOWTO (62),
1155 EMPTY_HOWTO (63),
1156 EMPTY_HOWTO (64),
1157 EMPTY_HOWTO (65),
1158 EMPTY_HOWTO (66),
1159 EMPTY_HOWTO (67),
1160 EMPTY_HOWTO (68),
1161 EMPTY_HOWTO (69),
1162 EMPTY_HOWTO (70),
1163 EMPTY_HOWTO (71),
1164 EMPTY_HOWTO (72),
1165 EMPTY_HOWTO (73),
1166 EMPTY_HOWTO (74),
1167 EMPTY_HOWTO (75),
1168 EMPTY_HOWTO (76),
1169 EMPTY_HOWTO (77),
1170 EMPTY_HOWTO (78),
1171 EMPTY_HOWTO (79),
1172 EMPTY_HOWTO (80),
1173 EMPTY_HOWTO (81),
1174 EMPTY_HOWTO (82),
1175 EMPTY_HOWTO (83),
1176 EMPTY_HOWTO (84),
1177 EMPTY_HOWTO (85),
1178 EMPTY_HOWTO (86),
1179 EMPTY_HOWTO (87),
1180 EMPTY_HOWTO (88),
1181 EMPTY_HOWTO (89),
1182 EMPTY_HOWTO (90),
1183 EMPTY_HOWTO (91),
1184 EMPTY_HOWTO (92),
1185 EMPTY_HOWTO (93),
1186 EMPTY_HOWTO (94),
1187 EMPTY_HOWTO (95),
1188 EMPTY_HOWTO (96),
1189 EMPTY_HOWTO (97),
1190 EMPTY_HOWTO (98),
1191 EMPTY_HOWTO (99),
1192 EMPTY_HOWTO (100),
1193 EMPTY_HOWTO (101),
1194 EMPTY_HOWTO (102),
1195 EMPTY_HOWTO (103),
1196 EMPTY_HOWTO (104),
1197 EMPTY_HOWTO (105),
1198 EMPTY_HOWTO (106),
1199 EMPTY_HOWTO (107),
1200 EMPTY_HOWTO (108),
1201 EMPTY_HOWTO (109),
1202 EMPTY_HOWTO (110),
1203 EMPTY_HOWTO (111),
1204 EMPTY_HOWTO (112),
1205 EMPTY_HOWTO (113),
1206 EMPTY_HOWTO (114),
1207 EMPTY_HOWTO (115),
1208 EMPTY_HOWTO (116),
1209 EMPTY_HOWTO (117),
1210 EMPTY_HOWTO (118),
1211 EMPTY_HOWTO (119),
1212 EMPTY_HOWTO (120),
1213 EMPTY_HOWTO (121),
1214 EMPTY_HOWTO (122),
1215 EMPTY_HOWTO (123),
1216 EMPTY_HOWTO (124),
1217 EMPTY_HOWTO (125),
1218 EMPTY_HOWTO (126),
1219 EMPTY_HOWTO (127),
1220 EMPTY_HOWTO (128),
1221 EMPTY_HOWTO (129),
1222 EMPTY_HOWTO (130),
1223 EMPTY_HOWTO (131),
1224 EMPTY_HOWTO (132),
1225 EMPTY_HOWTO (133),
1226 EMPTY_HOWTO (134),
1227 EMPTY_HOWTO (135),
1228 EMPTY_HOWTO (136),
1229 EMPTY_HOWTO (137),
1230 EMPTY_HOWTO (138),
1231 EMPTY_HOWTO (139),
1232 EMPTY_HOWTO (140),
1233 EMPTY_HOWTO (141),
1234 EMPTY_HOWTO (142),
1235 EMPTY_HOWTO (143),
1236 EMPTY_HOWTO (144),
1237 EMPTY_HOWTO (145),
1238 EMPTY_HOWTO (146),
1239 EMPTY_HOWTO (147),
1240 EMPTY_HOWTO (148),
1241 EMPTY_HOWTO (149),
1242 EMPTY_HOWTO (150),
1243 EMPTY_HOWTO (151),
1244 EMPTY_HOWTO (152),
1245 EMPTY_HOWTO (153),
1246 EMPTY_HOWTO (154),
1247 EMPTY_HOWTO (155),
1248 EMPTY_HOWTO (156),
1249 EMPTY_HOWTO (157),
1250 EMPTY_HOWTO (158),
1251 EMPTY_HOWTO (159),
1252 EMPTY_HOWTO (160),
1253 EMPTY_HOWTO (161),
1254 EMPTY_HOWTO (162),
1255 EMPTY_HOWTO (163),
1256 EMPTY_HOWTO (164),
1257 EMPTY_HOWTO (165),
1258 EMPTY_HOWTO (166),
1259 EMPTY_HOWTO (167),
1260 EMPTY_HOWTO (168),
1261 EMPTY_HOWTO (169),
1262 EMPTY_HOWTO (170),
1263 EMPTY_HOWTO (171),
1264 EMPTY_HOWTO (172),
1265 EMPTY_HOWTO (173),
1266 EMPTY_HOWTO (174),
1267 EMPTY_HOWTO (175),
1268 EMPTY_HOWTO (176),
1269 EMPTY_HOWTO (177),
1270 EMPTY_HOWTO (178),
1271 EMPTY_HOWTO (179),
1272 EMPTY_HOWTO (180),
1273 EMPTY_HOWTO (181),
1274 EMPTY_HOWTO (182),
1275 EMPTY_HOWTO (183),
1276 EMPTY_HOWTO (184),
1277 EMPTY_HOWTO (185),
1278 EMPTY_HOWTO (186),
1279 EMPTY_HOWTO (187),
1280 EMPTY_HOWTO (188),
1281 EMPTY_HOWTO (189),
1282 EMPTY_HOWTO (190),
1283 EMPTY_HOWTO (191),
1284 EMPTY_HOWTO (192),
1285 EMPTY_HOWTO (193),
1286 EMPTY_HOWTO (194),
1287 EMPTY_HOWTO (195),
1288 EMPTY_HOWTO (196),
1289 EMPTY_HOWTO (197),
1290 EMPTY_HOWTO (198),
1291 EMPTY_HOWTO (199),
1292 EMPTY_HOWTO (200),
1293 EMPTY_HOWTO (201),
1294 EMPTY_HOWTO (202),
1295 EMPTY_HOWTO (203),
1296 EMPTY_HOWTO (204),
1297 EMPTY_HOWTO (205),
1298 EMPTY_HOWTO (206),
1299 EMPTY_HOWTO (207),
1300 EMPTY_HOWTO (208),
1301 EMPTY_HOWTO (209),
1302 EMPTY_HOWTO (210),
1303 EMPTY_HOWTO (211),
1304 EMPTY_HOWTO (212),
1305 EMPTY_HOWTO (213),
1306 EMPTY_HOWTO (214),
1307 EMPTY_HOWTO (215),
1308 EMPTY_HOWTO (216),
1309 EMPTY_HOWTO (217),
1310 EMPTY_HOWTO (218),
1311 EMPTY_HOWTO (219),
1312 EMPTY_HOWTO (220),
1313 EMPTY_HOWTO (221),
1314 EMPTY_HOWTO (222),
1315 EMPTY_HOWTO (223),
1316 EMPTY_HOWTO (224),
1317 EMPTY_HOWTO (225),
1318 EMPTY_HOWTO (226),
1319 EMPTY_HOWTO (227),
1320 EMPTY_HOWTO (228),
1321 EMPTY_HOWTO (229),
1322 EMPTY_HOWTO (230),
1323 EMPTY_HOWTO (231),
1324 EMPTY_HOWTO (232),
1325 EMPTY_HOWTO (233),
1326 EMPTY_HOWTO (234),
1327 EMPTY_HOWTO (235),
1328 EMPTY_HOWTO (236),
1329 EMPTY_HOWTO (237),
1330 EMPTY_HOWTO (238),
1331 EMPTY_HOWTO (239),
1332 EMPTY_HOWTO (240),
1333 EMPTY_HOWTO (241),
1334 EMPTY_HOWTO (242),
1335 EMPTY_HOWTO (243),
1336 EMPTY_HOWTO (244),
1337 EMPTY_HOWTO (245),
1338 EMPTY_HOWTO (246),
1339 EMPTY_HOWTO (247),
1340 EMPTY_HOWTO (248),
1341 EMPTY_HOWTO (249),
1342 EMPTY_HOWTO (250),
1343 EMPTY_HOWTO (251),
1344 EMPTY_HOWTO (252),
1345 HOWTO (R_C6000_ALIGN, /* type */
1346 0, /* rightshift */
1347 0, /* size (0 = byte, 1 = short, 2 = long) */
1348 0, /* bitsize */
1349 FALSE, /* pc_relative */
1350 0, /* bitpos */
1351 complain_overflow_dont,/* complain_on_overflow */
1352 bfd_elf_generic_reloc, /* special_function */
1353 "R_C6000_ALIGN", /* name */
41820509 1354 TRUE, /* partial_inplace */
40b36596
JM
1355 0, /* src_mask */
1356 0, /* dst_mask */
1357 FALSE), /* pcrel_offset */
1358 HOWTO (R_C6000_FPHEAD, /* type */
1359 0, /* rightshift */
1360 0, /* size (0 = byte, 1 = short, 2 = long) */
1361 0, /* bitsize */
1362 FALSE, /* pc_relative */
1363 0, /* bitpos */
1364 complain_overflow_dont,/* complain_on_overflow */
1365 bfd_elf_generic_reloc, /* special_function */
1366 "R_C6000_FPHEAD", /* name */
41820509 1367 TRUE, /* partial_inplace */
40b36596
JM
1368 0, /* src_mask */
1369 0, /* dst_mask */
1370 FALSE), /* pcrel_offset */
1371 HOWTO (R_C6000_NOCMP, /* type */
1372 0, /* rightshift */
1373 0, /* size (0 = byte, 1 = short, 2 = long) */
1374 0, /* bitsize */
1375 FALSE, /* pc_relative */
1376 0, /* bitpos */
1377 complain_overflow_dont,/* complain_on_overflow */
1378 bfd_elf_generic_reloc, /* special_function */
1379 "R_C6000_NOCMP", /* name */
41820509 1380 TRUE, /* partial_inplace */
40b36596
JM
1381 0, /* src_mask */
1382 0, /* dst_mask */
1383 FALSE) /* pcrel_offset */
1384};
1385
1386/* Map BFD relocations to ELF relocations. */
1387
1388typedef struct
1389{
1390 bfd_reloc_code_real_type bfd_reloc_val;
1391 enum elf_tic6x_reloc_type elf_reloc_val;
1392} tic6x_reloc_map;
1393
1394static const tic6x_reloc_map elf32_tic6x_reloc_map[] =
1395 {
1396 { BFD_RELOC_NONE, R_C6000_NONE },
1397 { BFD_RELOC_32, R_C6000_ABS32 },
1398 { BFD_RELOC_16, R_C6000_ABS16 },
1399 { BFD_RELOC_8, R_C6000_ABS8 },
1400 { BFD_RELOC_C6000_PCR_S21, R_C6000_PCR_S21 },
1401 { BFD_RELOC_C6000_PCR_S12, R_C6000_PCR_S12 },
1402 { BFD_RELOC_C6000_PCR_S10, R_C6000_PCR_S10 },
1403 { BFD_RELOC_C6000_PCR_S7, R_C6000_PCR_S7 },
1404 { BFD_RELOC_C6000_ABS_S16, R_C6000_ABS_S16 },
1405 { BFD_RELOC_C6000_ABS_L16, R_C6000_ABS_L16 },
1406 { BFD_RELOC_C6000_ABS_H16, R_C6000_ABS_H16 },
1407 { BFD_RELOC_C6000_SBR_U15_B, R_C6000_SBR_U15_B },
1408 { BFD_RELOC_C6000_SBR_U15_H, R_C6000_SBR_U15_H },
1409 { BFD_RELOC_C6000_SBR_U15_W, R_C6000_SBR_U15_W },
1410 { BFD_RELOC_C6000_SBR_S16, R_C6000_SBR_S16 },
1411 { BFD_RELOC_C6000_SBR_L16_B, R_C6000_SBR_L16_B },
1412 { BFD_RELOC_C6000_SBR_L16_H, R_C6000_SBR_L16_H },
1413 { BFD_RELOC_C6000_SBR_L16_W, R_C6000_SBR_L16_W },
1414 { BFD_RELOC_C6000_SBR_H16_B, R_C6000_SBR_H16_B },
1415 { BFD_RELOC_C6000_SBR_H16_H, R_C6000_SBR_H16_H },
1416 { BFD_RELOC_C6000_SBR_H16_W, R_C6000_SBR_H16_W },
1417 { BFD_RELOC_C6000_SBR_GOT_U15_W, R_C6000_SBR_GOT_U15_W },
1418 { BFD_RELOC_C6000_SBR_GOT_L16_W, R_C6000_SBR_GOT_L16_W },
1419 { BFD_RELOC_C6000_SBR_GOT_H16_W, R_C6000_SBR_GOT_H16_W },
1420 { BFD_RELOC_C6000_DSBT_INDEX, R_C6000_DSBT_INDEX },
1421 { BFD_RELOC_C6000_PREL31, R_C6000_PREL31 },
1422 { BFD_RELOC_C6000_COPY, R_C6000_COPY },
ac145307
BS
1423 { BFD_RELOC_C6000_JUMP_SLOT, R_C6000_JUMP_SLOT },
1424 { BFD_RELOC_C6000_EHTYPE, R_C6000_EHTYPE },
1425 { BFD_RELOC_C6000_PCR_H16, R_C6000_PCR_H16 },
1426 { BFD_RELOC_C6000_PCR_L16, R_C6000_PCR_L16 },
40b36596
JM
1427 { BFD_RELOC_C6000_ALIGN, R_C6000_ALIGN },
1428 { BFD_RELOC_C6000_FPHEAD, R_C6000_FPHEAD },
1429 { BFD_RELOC_C6000_NOCMP, R_C6000_NOCMP }
1430 };
1431
1432static reloc_howto_type *
41820509 1433elf32_tic6x_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
40b36596
JM
1434{
1435 unsigned int i;
1436
1437 for (i = 0; i < ARRAY_SIZE (elf32_tic6x_reloc_map); i++)
1438 if (elf32_tic6x_reloc_map[i].bfd_reloc_val == code)
41820509
JM
1439 {
1440 enum elf_tic6x_reloc_type elf_reloc_val;
1441 reloc_howto_type *howto;
1442
1443 elf_reloc_val = elf32_tic6x_reloc_map[i].elf_reloc_val;
1444 if (elf32_tic6x_tdata (abfd)->use_rela_p)
1445 howto = &elf32_tic6x_howto_table[elf_reloc_val];
1446 else
1447 howto = &elf32_tic6x_howto_table_rel[elf_reloc_val];
1448
1449 /* Some relocations are RELA-only; do not return them for
1450 REL. */
1451 if (howto->name == NULL)
1452 howto = NULL;
1453
1454 return howto;
1455 }
40b36596
JM
1456
1457 return NULL;
1458}
1459
1460static reloc_howto_type *
41820509 1461elf32_tic6x_reloc_name_lookup (bfd *abfd, const char *r_name)
40b36596 1462{
41820509
JM
1463 if (elf32_tic6x_tdata (abfd)->use_rela_p)
1464 {
1465 unsigned int i;
1466
1467 for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table); i++)
1468 if (elf32_tic6x_howto_table[i].name != NULL
1469 && strcasecmp (elf32_tic6x_howto_table[i].name, r_name) == 0)
1470 return &elf32_tic6x_howto_table[i];
1471 }
1472 else
1473 {
1474 unsigned int i;
40b36596 1475
41820509
JM
1476 for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table_rel); i++)
1477 if (elf32_tic6x_howto_table_rel[i].name != NULL
1478 && strcasecmp (elf32_tic6x_howto_table_rel[i].name, r_name) == 0)
1479 return &elf32_tic6x_howto_table_rel[i];
1480 }
40b36596
JM
1481
1482 return NULL;
1483}
1484
f3185997 1485static bfd_boolean
40b36596
JM
1486elf32_tic6x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1487 Elf_Internal_Rela *elf_reloc)
1488{
1489 unsigned int r_type;
1490
1491 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1492 if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table))
f3185997
NC
1493 {
1494 /* xgettext:c-format */
1495 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1496 abfd, r_type);
1497 bfd_set_error (bfd_error_bad_value);
1498 return FALSE;
1499 }
1500
1501 bfd_reloc->howto = &elf32_tic6x_howto_table[r_type];
1502 if (bfd_reloc->howto == NULL || bfd_reloc->howto->name == NULL)
1503 {
1504 /* xgettext:c-format */
1505 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1506 abfd, r_type);
1507 bfd_set_error (bfd_error_bad_value);
1508 return FALSE;
1509 }
1510
1511 return TRUE;
40b36596
JM
1512}
1513
f3185997 1514static bfd_boolean
41820509
JM
1515elf32_tic6x_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1516 Elf_Internal_Rela *elf_reloc)
1517{
1518 unsigned int r_type;
1519
1520 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1521 if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table_rel))
f3185997
NC
1522 {
1523 /* xgettext:c-format */
1524 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1525 abfd, r_type);
1526 bfd_set_error (bfd_error_bad_value);
1527 return FALSE;
1528 }
1529
1530 bfd_reloc->howto = &elf32_tic6x_howto_table_rel[r_type];
1531 if (bfd_reloc->howto == NULL || bfd_reloc->howto->name == NULL)
1532 {
1533 /* xgettext:c-format */
1534 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1535 abfd, r_type);
1536 bfd_set_error (bfd_error_bad_value);
1537 return FALSE;
1538 }
1539
1540 return TRUE;
41820509
JM
1541}
1542
1543void
1544elf32_tic6x_set_use_rela_p (bfd *abfd, bfd_boolean use_rela_p)
1545{
1546 elf32_tic6x_tdata (abfd)->use_rela_p = use_rela_p;
1547}
1548
ac145307
BS
1549/* Create a C6X ELF linker hash table. */
1550
1551static struct bfd_link_hash_table *
1552elf32_tic6x_link_hash_table_create (bfd *abfd)
1553{
1554 struct elf32_tic6x_link_hash_table *ret;
986f0783 1555 size_t amt = sizeof (struct elf32_tic6x_link_hash_table);
ac145307 1556
7bf52ea2 1557 ret = bfd_zmalloc (amt);
ac145307
BS
1558 if (ret == NULL)
1559 return NULL;
1560
1561 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
190eb1dd
L
1562 _bfd_elf_link_hash_newfunc,
1563 sizeof (struct elf_link_hash_entry),
ac145307
BS
1564 TIC6X_ELF_DATA))
1565 {
1566 free (ret);
1567 return NULL;
1568 }
1569
ac145307
BS
1570 ret->obfd = abfd;
1571 ret->elf.is_relocatable_executable = 1;
1572
1573 return &ret->elf.root;
1574}
1575
c6a8f6e0
BS
1576static bfd_boolean
1577elf32_tic6x_final_link (bfd *abfd, struct bfd_link_info *info)
1578{
0e1862bb 1579 if (bfd_link_pic (info))
c6a8f6e0
BS
1580 {
1581 obj_attribute *out_attr;
1582 out_attr = elf_known_obj_attributes_proc (abfd);
1583 if (out_attr[Tag_ABI_PIC].i == 0)
1584 {
1585 _bfd_error_handler (_("warning: generating a shared library "
1586 "containing non-PIC code"));
1587 }
1588 if (out_attr[Tag_ABI_PID].i == 0)
1589 {
1590 _bfd_error_handler (_("warning: generating a shared library "
1591 "containing non-PID code"));
1592 }
1593 }
1594 /* Invoke the regular ELF backend linker to do all the work. */
1595 if (!bfd_elf_final_link (abfd, info))
1596 return FALSE;
1597
1598 return TRUE;
1599}
1600
ac145307
BS
1601/* Called to pass PARAMS to the backend. We store them in the hash table
1602 associated with INFO. */
1603
1604void
1605elf32_tic6x_setup (struct bfd_link_info *info,
1606 struct elf32_tic6x_params *params)
1607{
1608 struct elf32_tic6x_link_hash_table *htab = elf32_tic6x_hash_table (info);
1609 htab->params = *params;
1610}
1611
1612/* Determine if we're dealing with a DSBT object. */
1613
1614static bfd_boolean
1615elf32_tic6x_using_dsbt (bfd *abfd)
1616{
1617 return bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC,
1618 Tag_ABI_DSBT);
1619}
1620
1621/* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
1622 sections in DYNOBJ, and set up shortcuts to them in our hash
1623 table. */
1624
1625static bfd_boolean
1626elf32_tic6x_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1627{
1628 struct elf32_tic6x_link_hash_table *htab;
1629 flagword flags;
1630
1631 htab = elf32_tic6x_hash_table (info);
1632 if (htab == NULL)
1633 return FALSE;
1634
1635 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1636 return FALSE;
1637
1638 /* Create .dsbt */
1639 flags = (SEC_ALLOC | SEC_LOAD
1640 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1641 htab->dsbt = bfd_make_section_anyway_with_flags (dynobj, ".dsbt",
1642 flags);
1643 if (htab->dsbt == NULL
fd361982
AM
1644 || !bfd_set_section_alignment (htab->dsbt, 2)
1645 || !bfd_set_section_alignment (htab->elf.splt, 5))
ac145307
BS
1646 return FALSE;
1647
ac145307
BS
1648 return TRUE;
1649}
1650
41820509
JM
1651static bfd_boolean
1652elf32_tic6x_mkobject (bfd *abfd)
1653{
1654 bfd_boolean ret;
1655
1656 ret = bfd_elf_allocate_object (abfd, sizeof (struct elf32_tic6x_obj_tdata),
1657 TIC6X_ELF_DATA);
1658 if (ret)
1659 elf32_tic6x_set_use_rela_p (abfd, TRUE);
1660 return ret;
1661}
1662
ac145307
BS
1663/* Install relocation RELA into section SRELA, incrementing its
1664 reloc_count. */
1665
1666static void
1667elf32_tic6x_install_rela (bfd *output_bfd, asection *srela,
1668 Elf_Internal_Rela *rela)
1669{
1670 bfd_byte *loc;
1671 bfd_vma off = srela->reloc_count++ * sizeof (Elf32_External_Rela);
1672 loc = srela->contents + off;
1673 BFD_ASSERT (off < srela->size);
1674 bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
1675}
1676
1677/* Create a dynamic reloc against the GOT at offset OFFSET. The contents
1678 of the GOT at this offset have been initialized with the relocation. */
1679
1680static void
1681elf32_tic6x_make_got_dynreloc (bfd *output_bfd,
1682 struct elf32_tic6x_link_hash_table *htab,
1683 asection *sym_sec, bfd_vma offset)
1684{
1685 asection *sgot = htab->elf.sgot;
1686 Elf_Internal_Rela outrel;
1687 int dynindx;
1688
1689 outrel.r_offset = sgot->output_section->vma + sgot->output_offset + offset;
1690 outrel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
1691 if (sym_sec && sym_sec->output_section
1692 && ! bfd_is_abs_section (sym_sec->output_section)
1693 && ! bfd_is_und_section (sym_sec->output_section))
1694 {
1695 dynindx = elf_section_data (sym_sec->output_section)->dynindx;
1696 outrel.r_addend -= sym_sec->output_section->vma;
1697 }
1698 else
1699 {
1700 dynindx = 0;
1701 }
1702 outrel.r_info = ELF32_R_INFO (dynindx, R_C6000_ABS32);
1703 elf32_tic6x_install_rela (output_bfd, htab->elf.srelgot, &outrel);
1704}
1705
1706/* Finish up dynamic symbol handling. We set the contents of various
1707 dynamic sections here. */
1708
1709static bfd_boolean
1710elf32_tic6x_finish_dynamic_symbol (bfd * output_bfd,
1711 struct bfd_link_info *info,
1712 struct elf_link_hash_entry *h,
1713 Elf_Internal_Sym * sym)
1714{
ac145307
BS
1715 struct elf32_tic6x_link_hash_table *htab;
1716
1717 htab = elf32_tic6x_hash_table (info);
ac145307
BS
1718
1719 if (h->plt.offset != (bfd_vma) -1)
1720 {
1721 bfd_vma plt_index;
1722 bfd_vma got_section_offset, got_dp_offset, rela_offset;
1723 Elf_Internal_Rela rela;
1724 bfd_byte *loc;
1725 asection *plt, *gotplt, *relplt;
1726 const struct elf_backend_data *bed;
1727
1728 bed = get_elf_backend_data (output_bfd);
1729
1730 BFD_ASSERT (htab->elf.splt != NULL);
1731 plt = htab->elf.splt;
1732 gotplt = htab->elf.sgotplt;
1733 relplt = htab->elf.srelplt;
1734
1735 /* This symbol has an entry in the procedure linkage table. Set
1736 it up. */
1737
1738 if ((h->dynindx == -1
0e1862bb 1739 && !((h->forced_local || bfd_link_executable (info))
ac145307
BS
1740 && h->def_regular
1741 && h->type == STT_GNU_IFUNC))
1742 || plt == NULL
1743 || gotplt == NULL
1744 || relplt == NULL)
1745 abort ();
1746
1747 /* Get the index in the procedure linkage table which
1748 corresponds to this symbol. This is the index of this symbol
1749 in all the symbols for which we are making plt entries. The
1750 first entry in the procedure linkage table is reserved.
1751
1752 Get the offset into the .got table of the entry that
1753 corresponds to this function. Each .got entry is 4 bytes.
1754 The first three are reserved.
68ffbac6 1755
ac145307
BS
1756 For static executables, we don't reserve anything. */
1757
1758 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1759 got_section_offset = plt_index + bed->got_header_size / 4;
1760 got_dp_offset = got_section_offset + htab->params.dsbt_size;
1761 rela_offset = plt_index * sizeof (Elf32_External_Rela);
1762
1763 got_section_offset *= 4;
1764
1765 /* Fill in the entry in the procedure linkage table. */
1766
1767 /* ldw .d2t2 *+B14($GOT(f)), b2 */
1768 bfd_put_32 (output_bfd, got_dp_offset << 8 | 0x0100006e,
1769 plt->contents + h->plt.offset);
1770 /* mvk .s2 low(rela_offset), b0 */
1771 bfd_put_32 (output_bfd, (rela_offset & 0xffff) << 7 | 0x0000002a,
1772 plt->contents + h->plt.offset + 4);
1773 /* mvkh .s2 high(rela_offset), b0 */
1774 bfd_put_32 (output_bfd, ((rela_offset >> 16) & 0xffff) << 7 | 0x0000006a,
1775 plt->contents + h->plt.offset + 8);
1776 /* nop 2 */
1777 bfd_put_32 (output_bfd, 0x00002000,
1778 plt->contents + h->plt.offset + 12);
1779 /* b .s2 b2 */
1780 bfd_put_32 (output_bfd, 0x00080362,
1781 plt->contents + h->plt.offset + 16);
1782 /* nop 5 */
1783 bfd_put_32 (output_bfd, 0x00008000,
1784 plt->contents + h->plt.offset + 20);
1785
1786 /* Fill in the entry in the global offset table. */
1787 bfd_put_32 (output_bfd,
1788 (plt->output_section->vma + plt->output_offset),
1789 gotplt->contents + got_section_offset);
1790
1791 /* Fill in the entry in the .rel.plt section. */
1792 rela.r_offset = (gotplt->output_section->vma
1793 + gotplt->output_offset
1794 + got_section_offset);
1795 rela.r_info = ELF32_R_INFO (h->dynindx, R_C6000_JUMP_SLOT);
1796 rela.r_addend = 0;
1797 loc = relplt->contents + rela_offset;
1798 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1799
1800 if (!h->def_regular)
1801 {
1802 /* Mark the symbol as undefined, rather than as defined in
1803 the .plt section. */
1804 sym->st_shndx = SHN_UNDEF;
1805 sym->st_value = 0;
1806 }
1807 }
1808
1809 if (h->got.offset != (bfd_vma) -1)
1810 {
1811 asection *sgot;
1812 asection *srela;
1813
1814 /* This symbol has an entry in the global offset table.
07d6d2b8 1815 Set it up. */
ac145307 1816
ce558b89
AM
1817 sgot = htab->elf.sgot;
1818 srela = htab->elf.srelgot;
ac145307
BS
1819 BFD_ASSERT (sgot != NULL && srela != NULL);
1820
1821 /* If this is a -Bsymbolic link, and the symbol is defined
07d6d2b8
AM
1822 locally, we just want to emit a RELATIVE reloc. Likewise if
1823 the symbol was forced to be local because of a version file.
1824 The entry in the global offset table will already have been
1825 initialized in the relocate_section function. */
0e1862bb 1826 if (bfd_link_pic (info)
a496fbc8 1827 && (SYMBOLIC_BIND (info, h)
ac145307
BS
1828 || h->dynindx == -1 || h->forced_local) && h->def_regular)
1829 {
1830 asection *s = h->root.u.def.section;
1831 elf32_tic6x_make_got_dynreloc (output_bfd, htab, s,
1832 h->got.offset & ~(bfd_vma) 1);
1833 }
1834 else
1835 {
1836 Elf_Internal_Rela outrel;
1837 bfd_put_32 (output_bfd, (bfd_vma) 0,
1838 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
1839 outrel.r_offset = (sgot->output_section->vma
1840 + sgot->output_offset
1841 + (h->got.offset & ~(bfd_vma) 1));
1842 outrel.r_info = ELF32_R_INFO (h->dynindx, R_C6000_ABS32);
1843 outrel.r_addend = 0;
1844
1845 elf32_tic6x_install_rela (output_bfd, srela, &outrel);
1846 }
1847 }
1848
1849 if (h->needs_copy)
1850 {
1851 Elf_Internal_Rela rel;
5474d94f 1852 asection *s;
ac145307
BS
1853
1854 /* This symbol needs a copy reloc. Set it up. */
1855
1856 if (h->dynindx == -1
1857 || (h->root.type != bfd_link_hash_defined
1858 && h->root.type != bfd_link_hash_defweak)
5474d94f
AM
1859 || htab->elf.srelbss == NULL
1860 || htab->elf.sreldynrelro == NULL)
ac145307
BS
1861 abort ();
1862
1863 rel.r_offset = (h->root.u.def.value
1864 + h->root.u.def.section->output_section->vma
1865 + h->root.u.def.section->output_offset);
1866 rel.r_info = ELF32_R_INFO (h->dynindx, R_C6000_COPY);
1867 rel.r_addend = 0;
afbf7e8e 1868 if (h->root.u.def.section == htab->elf.sdynrelro)
5474d94f
AM
1869 s = htab->elf.sreldynrelro;
1870 else
1871 s = htab->elf.srelbss;
ac145307 1872
5474d94f 1873 elf32_tic6x_install_rela (output_bfd, s, &rel);
ac145307
BS
1874 }
1875
1876 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9637f6ef 1877 if (h == elf_hash_table (info)->hdynamic
ac145307
BS
1878 || h == elf_hash_table (info)->hgot)
1879 sym->st_shndx = SHN_ABS;
1880
1881 return TRUE;
1882}
1883
9cf0e282
PB
1884/* Unwinding tables are not referenced directly. This pass marks them as
1885 required if the corresponding code section is marked. */
1886
1887static bfd_boolean
1888elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info *info,
1889 elf_gc_mark_hook_fn gc_mark_hook)
1890{
1891 bfd *sub;
1892 Elf_Internal_Shdr **elf_shdrp;
1893 bfd_boolean again;
1894
7f6ab9f8
AM
1895 _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
1896
9cf0e282
PB
1897 /* Marking EH data may cause additional code sections to be marked,
1898 requiring multiple passes. */
1899 again = TRUE;
1900 while (again)
1901 {
1902 again = FALSE;
c72f2fb2 1903 for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
9cf0e282
PB
1904 {
1905 asection *o;
1906
1907 if (! is_tic6x_elf (sub))
1908 continue;
1909
1910 elf_shdrp = elf_elfsections (sub);
1911 for (o = sub->sections; o != NULL; o = o->next)
1912 {
1913 Elf_Internal_Shdr *hdr;
1914
1915 hdr = &elf_section_data (o)->this_hdr;
1916 if (hdr->sh_type == SHT_C6000_UNWIND
1917 && hdr->sh_link
1918 && hdr->sh_link < elf_numsections (sub)
1919 && !o->gc_mark
1920 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
1921 {
1922 again = TRUE;
1923 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
1924 return FALSE;
1925 }
1926 }
1927 }
1928 }
1929
1930 return TRUE;
1931}
1932
1bce6bd8
PB
1933/* Return TRUE if this is an unwinding table index. */
1934
1935static bfd_boolean
1936is_tic6x_elf_unwind_section_name (const char *name)
1937{
1938 return (CONST_STRNEQ (name, ELF_STRING_C6000_unwind)
1939 || CONST_STRNEQ (name, ELF_STRING_C6000_unwind_once));
1940}
1941
1942
1943/* Set the type and flags for an unwinding index table. We do this by
1944 the section name, which is a hack, but ought to work. */
1945
1946static bfd_boolean
1947elf32_tic6x_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
1948 Elf_Internal_Shdr *hdr, asection *sec)
1949{
1950 const char * name;
1951
fd361982 1952 name = bfd_section_name (sec);
1bce6bd8
PB
1953
1954 if (is_tic6x_elf_unwind_section_name (name))
1955 {
1956 hdr->sh_type = SHT_C6000_UNWIND;
1957 hdr->sh_flags |= SHF_LINK_ORDER;
1958 }
1959
1960 return TRUE;
1961}
1962
ac145307
BS
1963/* Adjust a symbol defined by a dynamic object and referenced by a
1964 regular object. The current definition is in some section of the
1965 dynamic object, but we're not including those sections. We have to
1966 change the definition to something the rest of the link can
1967 understand. */
1968
1969static bfd_boolean
1970elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info *info,
1971 struct elf_link_hash_entry *h)
1972{
1973 struct elf32_tic6x_link_hash_table *htab;
1974 bfd *dynobj;
5474d94f 1975 asection *s, *srel;
ac145307
BS
1976
1977 dynobj = elf_hash_table (info)->dynobj;
1978
1979 /* Make sure we know what is going on here. */
1980 BFD_ASSERT (dynobj != NULL
1981 && (h->needs_plt
60d67dc8 1982 || h->is_weakalias
ac145307
BS
1983 || (h->def_dynamic && h->ref_regular && !h->def_regular)));
1984
1985 /* If this is a function, put it in the procedure linkage table. We
1986 will fill in the contents of the procedure linkage table later,
1987 when we know the address of the .got section. */
1988 if (h->type == STT_FUNC
1989 || h->needs_plt)
1990 {
1991 if (h->plt.refcount <= 0
1992 || SYMBOL_CALLS_LOCAL (info, h)
1993 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1994 && h->root.type == bfd_link_hash_undefweak))
1995 {
1996 /* This case can occur if we saw a PLT32 reloc in an input
1997 file, but the symbol was never referred to by a dynamic
1998 object, or if all references were garbage collected. In
1999 such a case, we don't actually need to build a procedure
2000 linkage table, and we can just do a PC32 reloc instead. */
2001 h->plt.offset = (bfd_vma) -1;
2002 h->needs_plt = 0;
2003 }
2004
2005 return TRUE;
2006 }
2007
2008 /* If this is a weak symbol, and there is a real definition, the
2009 processor independent code will have arranged for us to see the
2010 real definition first, and we can just use the same value. */
60d67dc8 2011 if (h->is_weakalias)
ac145307 2012 {
60d67dc8
AM
2013 struct elf_link_hash_entry *def = weakdef (h);
2014 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
2015 h->root.u.def.section = def->root.u.def.section;
2016 h->root.u.def.value = def->root.u.def.value;
2017 h->non_got_ref = def->non_got_ref;
ac145307
BS
2018 return TRUE;
2019 }
2020
2021 /* This is a reference to a symbol defined by a dynamic object which
2022 is not a function. */
2023
2024 /* If we are creating a shared library, we must presume that the
2025 only references to the symbol are via the global offset table.
2026 For such cases we need not do anything here; the relocations will
2027 be handled correctly by relocate_section. */
0e1862bb 2028 if (bfd_link_pic (info))
ac145307
BS
2029 return TRUE;
2030
2031 /* If there are no references to this symbol that do not use the
2032 GOT, we don't need to generate a copy reloc. */
2033 if (!h->non_got_ref)
2034 return TRUE;
2035
2036 /* If -z nocopyreloc was given, we won't generate them either. */
2037 if (info->nocopyreloc)
2038 {
2039 h->non_got_ref = 0;
2040 return TRUE;
2041 }
2042
2043 htab = elf32_tic6x_hash_table (info);
2044 if (htab == NULL)
2045 return FALSE;
2046
ac145307
BS
2047 /* We must allocate the symbol in our .dynbss section, which will
2048 become part of the .bss section of the executable. There will be
2049 an entry for this symbol in the .dynsym section. The dynamic
2050 object will contain position independent code, so all references
2051 from the dynamic object to this symbol will go through the global
2052 offset table. The dynamic linker will use the .dynsym entry to
2053 determine the address it must put in the global offset table, so
2054 both the dynamic object and the regular object will refer to the
2055 same memory location for the variable. */
2056
2057 /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
2058 copy the initial value out of the dynamic object and into the
2059 runtime process image. */
5474d94f
AM
2060 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2061 {
2062 s = htab->elf.sdynrelro;
2063 srel = htab->elf.sreldynrelro;
2064 }
2065 else
2066 {
2067 s = htab->elf.sdynbss;
2068 srel = htab->elf.srelbss;
2069 }
1d7e9d18 2070 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
ac145307 2071 {
5474d94f 2072 srel->size += sizeof (Elf32_External_Rela);
ac145307
BS
2073 h->needs_copy = 1;
2074 }
2075
6cabe1ea 2076 return _bfd_elf_adjust_dynamic_copy (info, h, s);
ac145307
BS
2077}
2078
41820509
JM
2079static bfd_boolean
2080elf32_tic6x_new_section_hook (bfd *abfd, asection *sec)
2081{
2082 bfd_boolean ret;
2083
fbd9ad90
PB
2084 /* Allocate target specific section data. */
2085 if (!sec->used_by_bfd)
2086 {
2087 _tic6x_elf_section_data *sdata;
986f0783 2088 size_t amt = sizeof (*sdata);
fbd9ad90
PB
2089
2090 sdata = (_tic6x_elf_section_data *) bfd_zalloc (abfd, amt);
2091 if (sdata == NULL)
2092 return FALSE;
2093 sec->used_by_bfd = sdata;
2094 }
2095
41820509
JM
2096 ret = _bfd_elf_new_section_hook (abfd, sec);
2097 sec->use_rela_p = elf32_tic6x_tdata (abfd)->use_rela_p;
2098
2099 return ret;
2100}
2101
2102/* Return true if relocation REL against section SEC is a REL rather
2103 than RELA relocation. RELOCS is the first relocation in the
2104 section and ABFD is the bfd that contains SEC. */
2105
2106static bfd_boolean
2107elf32_tic6x_rel_relocation_p (bfd *abfd, asection *sec,
2108 const Elf_Internal_Rela *relocs,
2109 const Elf_Internal_Rela *rel)
2110{
2111 Elf_Internal_Shdr *rel_hdr;
2112 const struct elf_backend_data *bed;
2113
2114 /* To determine which flavor of relocation this is, we depend on the
d4730f92
BS
2115 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
2116 rel_hdr = elf_section_data (sec)->rel.hdr;
2117 if (rel_hdr == NULL)
2118 return FALSE;
41820509 2119 bed = get_elf_backend_data (abfd);
d4730f92
BS
2120 return ((size_t) (rel - relocs)
2121 < NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel);
41820509
JM
2122}
2123
ac145307
BS
2124/* We need dynamic symbols for every section, since segments can
2125 relocate independently. */
2126static bfd_boolean
2127elf32_tic6x_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
2128 struct bfd_link_info *info ATTRIBUTE_UNUSED,
2129 asection *p)
2130{
2131 switch (elf_section_data (p)->this_hdr.sh_type)
2132 {
2133 case SHT_PROGBITS:
2134 case SHT_NOBITS:
2135 /* If sh_type is yet undecided, assume it could be
2136 SHT_PROGBITS/SHT_NOBITS. */
2137 case SHT_NULL:
2138 return FALSE;
2139
2140 /* There shouldn't be section relative relocations
2141 against any other section. */
2142 default:
2143 return TRUE;
2144 }
2145}
2146
40b36596
JM
2147static bfd_boolean
2148elf32_tic6x_relocate_section (bfd *output_bfd,
2149 struct bfd_link_info *info,
2150 bfd *input_bfd,
2151 asection *input_section,
2152 bfd_byte *contents,
2153 Elf_Internal_Rela *relocs,
2154 Elf_Internal_Sym *local_syms,
2155 asection **local_sections)
2156{
ac145307 2157 struct elf32_tic6x_link_hash_table *htab;
40b36596
JM
2158 Elf_Internal_Shdr *symtab_hdr;
2159 struct elf_link_hash_entry **sym_hashes;
ac145307 2160 bfd_vma *local_got_offsets;
40b36596
JM
2161 Elf_Internal_Rela *rel;
2162 Elf_Internal_Rela *relend;
2163 bfd_boolean ok = TRUE;
2164
ac145307 2165 htab = elf32_tic6x_hash_table (info);
40b36596
JM
2166 symtab_hdr = & elf_symtab_hdr (input_bfd);
2167 sym_hashes = elf_sym_hashes (input_bfd);
ac145307 2168 local_got_offsets = elf_local_got_offsets (input_bfd);
40b36596
JM
2169
2170 relend = relocs + input_section->reloc_count;
2171
2172 for (rel = relocs; rel < relend; rel ++)
2173 {
2174 int r_type;
2175 unsigned long r_symndx;
2176 arelent bfd_reloc;
2177 reloc_howto_type *howto;
2178 Elf_Internal_Sym *sym;
2179 asection *sec;
2180 struct elf_link_hash_entry *h;
4a732032 2181 bfd_vma off, off2, relocation;
40b36596
JM
2182 bfd_boolean unresolved_reloc;
2183 bfd_reloc_status_type r;
2184 struct bfd_link_hash_entry *sbh;
41820509 2185 bfd_boolean is_rel;
f3185997 2186 bfd_boolean res;
40b36596
JM
2187
2188 r_type = ELF32_R_TYPE (rel->r_info);
2189 r_symndx = ELF32_R_SYM (rel->r_info);
2190
41820509
JM
2191 is_rel = elf32_tic6x_rel_relocation_p (input_bfd, input_section,
2192 relocs, rel);
2193
2194 if (is_rel)
f3185997 2195 res = elf32_tic6x_info_to_howto_rel (input_bfd, &bfd_reloc, rel);
41820509 2196 else
f3185997
NC
2197 res = elf32_tic6x_info_to_howto (input_bfd, &bfd_reloc, rel);
2198
2199 if (!res || (howto = bfd_reloc.howto) == NULL)
40b36596
JM
2200 {
2201 bfd_set_error (bfd_error_bad_value);
2202 return FALSE;
2203 }
2204
2205 h = NULL;
2206 sym = NULL;
2207 sec = NULL;
2208 unresolved_reloc = FALSE;
2209
2210 if (r_symndx < symtab_hdr->sh_info)
2211 {
2212 sym = local_syms + r_symndx;
2213 sec = local_sections[r_symndx];
2214 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2215 }
2216 else
2217 {
62d887d4 2218 bfd_boolean warned, ignored;
40b36596
JM
2219
2220 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2221 r_symndx, symtab_hdr, sym_hashes,
2222 h, sec, relocation,
62d887d4 2223 unresolved_reloc, warned, ignored);
40b36596
JM
2224 }
2225
dbaa2011 2226 if (sec != NULL && discarded_section (sec))
e4067dbb 2227 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
545fd46b 2228 rel, 1, relend, howto, 0, contents);
40b36596 2229
0e1862bb 2230 if (bfd_link_relocatable (info))
41820509
JM
2231 {
2232 if (is_rel
2233 && sym != NULL
2234 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2235 {
2236 rel->r_addend = 0;
2237 relocation = sec->output_offset + sym->st_value;
2238 r = _bfd_relocate_contents (howto, input_bfd, relocation,
2239 contents + rel->r_offset);
2240 goto done_reloc;
2241 }
2242 continue;
2243 }
40b36596
JM
2244
2245 switch (r_type)
2246 {
2247 case R_C6000_NONE:
2248 case R_C6000_ALIGN:
2249 case R_C6000_FPHEAD:
2250 case R_C6000_NOCMP:
2251 /* No action needed. */
2252 continue;
2253
2254 case R_C6000_PCR_S21:
ac145307
BS
2255 /* A branch to an undefined weak symbol is turned into a
2256 "b .s2 B3" instruction if the existing insn is of the
2257 form "b .s2 symbol". */
2258 if (h ? h->root.type == bfd_link_hash_undefweak
2259 && (htab->elf.splt == NULL || h->plt.offset == (bfd_vma) -1)
2260 : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
2261 {
2262 unsigned long oldval;
2263 oldval = bfd_get_32 (input_bfd, contents + rel->r_offset);
2264
2265 if ((oldval & 0x7e) == 0x12)
2266 {
2267 oldval &= 0xF0000001;
2268 bfd_put_32 (input_bfd, oldval | 0x000c0362,
2269 contents + rel->r_offset);
2270 r = bfd_reloc_ok;
2271 goto done_reloc;
2272 }
2273 }
1a0670f3 2274 /* Fall through. */
ac145307 2275
40b36596
JM
2276 case R_C6000_PCR_S12:
2277 case R_C6000_PCR_S10:
2278 case R_C6000_PCR_S7:
ac145307
BS
2279 if (h != NULL
2280 && h->plt.offset != (bfd_vma) -1
2281 && htab->elf.splt != NULL)
2282 {
2283 relocation = (htab->elf.splt->output_section->vma
2284 + htab->elf.splt->output_offset
2285 + h->plt.offset);
2286 }
2287
40b36596
JM
2288 /* Generic PC-relative handling produces a value relative to
2289 the exact location of the relocation. Adjust it to be
2290 relative to the start of the fetch packet instead. */
2291 relocation += (input_section->output_section->vma
2292 + input_section->output_offset
2293 + rel->r_offset) & 0x1f;
ac145307
BS
2294 unresolved_reloc = FALSE;
2295 break;
2296
4a732032
BS
2297 case R_C6000_PCR_H16:
2298 case R_C6000_PCR_L16:
2299 off = (input_section->output_section->vma
2300 + input_section->output_offset
2301 + rel->r_offset);
2302 /* These must be calculated as R = S - FP(FP(PC) - A).
2303 PC, here, is the value we just computed in OFF. RELOCATION
2304 has the address of S + A. */
2305 relocation -= rel->r_addend;
2306 off2 = ((off & ~(bfd_vma)0x1f) - rel->r_addend) & (bfd_vma)~0x1f;
2307 off2 = relocation - off2;
2308 relocation = off + off2;
2309 break;
2310
ac145307
BS
2311 case R_C6000_DSBT_INDEX:
2312 relocation = elf32_tic6x_hash_table (info)->params.dsbt_index;
0e1862bb 2313 if (!bfd_link_pic (info) || relocation != 0)
ac145307
BS
2314 break;
2315
2316 /* fall through */
40b36596
JM
2317 case R_C6000_ABS32:
2318 case R_C6000_ABS16:
2319 case R_C6000_ABS8:
2320 case R_C6000_ABS_S16:
2321 case R_C6000_ABS_L16:
2322 case R_C6000_ABS_H16:
ac145307
BS
2323 /* When generating a shared object or relocatable executable, these
2324 relocations are copied into the output file to be resolved at
2325 run time. */
0e1862bb 2326 if ((bfd_link_pic (info) || elf32_tic6x_using_dsbt (output_bfd))
ac145307
BS
2327 && (input_section->flags & SEC_ALLOC)
2328 && (h == NULL
2329 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2330 || h->root.type != bfd_link_hash_undefweak))
2331 {
2332 Elf_Internal_Rela outrel;
2333 bfd_boolean skip, relocate;
2334 asection *sreloc;
2335
2336 unresolved_reloc = FALSE;
2337
2338 sreloc = elf_section_data (input_section)->sreloc;
2339 BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
2340
2341 skip = FALSE;
2342 relocate = FALSE;
2343
2344 outrel.r_offset =
2345 _bfd_elf_section_offset (output_bfd, info, input_section,
2346 rel->r_offset);
2347 if (outrel.r_offset == (bfd_vma) -1)
2348 skip = TRUE;
2349 else if (outrel.r_offset == (bfd_vma) -2)
2350 skip = TRUE, relocate = TRUE;
2351 outrel.r_offset += (input_section->output_section->vma
2352 + input_section->output_offset);
2353
2354 if (skip)
2355 memset (&outrel, 0, sizeof outrel);
2356 else if (h != NULL
2357 && h->dynindx != -1
0e1862bb 2358 && (!bfd_link_pic (info)
a496fbc8 2359 || !SYMBOLIC_BIND (info, h)
ac145307
BS
2360 || !h->def_regular))
2361 {
2362 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2363 outrel.r_addend = rel->r_addend;
2364 }
2365 else
2366 {
2367 long indx;
2368
2369 outrel.r_addend = relocation + rel->r_addend;
2370
2371 if (bfd_is_abs_section (sec))
2372 indx = 0;
2373 else if (sec == NULL || sec->owner == NULL)
2374 {
2375 bfd_set_error (bfd_error_bad_value);
2376 return FALSE;
2377 }
2378 else
2379 {
2380 asection *osec;
2381
2382 osec = sec->output_section;
2383 indx = elf_section_data (osec)->dynindx;
2384 outrel.r_addend -= osec->vma;
2385 BFD_ASSERT (indx != 0);
2386 }
2387
2388 outrel.r_info = ELF32_R_INFO (indx, r_type);
2389 }
2390
2391 elf32_tic6x_install_rela (output_bfd, sreloc, &outrel);
2392
2393 /* If this reloc is against an external symbol, we do not want to
2394 fiddle with the addend. Otherwise, we need to include the symbol
2395 value so that it becomes an addend for the dynamic reloc. */
2396 if (! relocate)
2397 continue;
2398 }
2399
40b36596
JM
2400 /* Generic logic OK. */
2401 break;
2402
2403 case R_C6000_SBR_U15_B:
2404 case R_C6000_SBR_U15_H:
2405 case R_C6000_SBR_U15_W:
2406 case R_C6000_SBR_S16:
2407 case R_C6000_SBR_L16_B:
2408 case R_C6000_SBR_L16_H:
2409 case R_C6000_SBR_L16_W:
2410 case R_C6000_SBR_H16_B:
2411 case R_C6000_SBR_H16_H:
2412 case R_C6000_SBR_H16_W:
2413 sbh = bfd_link_hash_lookup (info->hash, "__c6xabi_DSBT_BASE",
2414 FALSE, FALSE, TRUE);
2415 if (sbh != NULL
2416 && (sbh->type == bfd_link_hash_defined
2417 || sbh->type == bfd_link_hash_defweak))
ac145307
BS
2418 {
2419 if (h ? (h->root.type == bfd_link_hash_undefweak
2420 && (htab->elf.splt == NULL
2421 || h->plt.offset == (bfd_vma) -1))
2422 : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
2423 relocation = 0;
2424 else
2425 relocation -= (sbh->u.def.value
2426 + sbh->u.def.section->output_section->vma
2427 + sbh->u.def.section->output_offset);
2428 }
40b36596
JM
2429 else
2430 {
871b3ab2 2431 _bfd_error_handler (_("%pB: SB-relative relocation but "
4eca0228
AM
2432 "__c6xabi_DSBT_BASE not defined"),
2433 input_bfd);
40b36596
JM
2434 ok = FALSE;
2435 continue;
2436 }
2437 break;
2438
2439 case R_C6000_SBR_GOT_U15_W:
2440 case R_C6000_SBR_GOT_L16_W:
2441 case R_C6000_SBR_GOT_H16_W:
2fbb87f6 2442 case R_C6000_EHTYPE:
ac145307
BS
2443 /* Relocation is to the entry for this symbol in the global
2444 offset table. */
2445 if (htab->elf.sgot == NULL)
2446 abort ();
2447
2448 if (h != NULL)
2449 {
2450 bfd_boolean dyn;
2451
2452 off = h->got.offset;
2453 dyn = htab->elf.dynamic_sections_created;
0e1862bb
L
2454 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2455 bfd_link_pic (info),
2456 h)
2457 || (bfd_link_pic (info)
ac145307
BS
2458 && SYMBOL_REFERENCES_LOCAL (info, h))
2459 || (ELF_ST_VISIBILITY (h->other)
2460 && h->root.type == bfd_link_hash_undefweak))
2461 {
2462 /* This is actually a static link, or it is a
2463 -Bsymbolic link and the symbol is defined
2464 locally, or the symbol was forced to be local
2465 because of a version file. We must initialize
2466 this entry in the global offset table. Since the
2467 offset must always be a multiple of 4, we use the
2468 least significant bit to record whether we have
2469 initialized it already.
2470
2471 When doing a dynamic link, we create a .rel.got
2472 relocation entry to initialize the value. This
2473 is done in the finish_dynamic_symbol routine. */
2474 if ((off & 1) != 0)
2475 off &= ~1;
2476 else
2477 {
2478 bfd_put_32 (output_bfd, relocation,
2479 htab->elf.sgot->contents + off);
2480 h->got.offset |= 1;
2481
0e1862bb
L
2482 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2483 bfd_link_pic (info),
ac145307
BS
2484 h)
2485 && !(ELF_ST_VISIBILITY (h->other)
2486 && h->root.type == bfd_link_hash_undefweak))
2487 elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec,
2488 off);
2489 }
2490 }
2491 else
2492 unresolved_reloc = FALSE;
2493 }
2494 else
2495 {
2496 if (local_got_offsets == NULL)
2497 abort ();
2498
2499 off = local_got_offsets[r_symndx];
2500
2501 /* The offset must always be a multiple of 4. We use
2502 the least significant bit to record whether we have
2503 already generated the necessary reloc. */
2504 if ((off & 1) != 0)
2505 off &= ~1;
2506 else
2507 {
2508 bfd_put_32 (output_bfd, relocation,
2509 htab->elf.sgot->contents + off);
2510
0e1862bb 2511 if (bfd_link_pic (info) || elf32_tic6x_using_dsbt (output_bfd))
ac145307
BS
2512 elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec, off);
2513
2514 local_got_offsets[r_symndx] |= 1;
2515 }
2516 }
2517
2518 if (off >= (bfd_vma) -2)
2519 abort ();
2520
2521 if (htab->dsbt)
2522 relocation = (htab->elf.sgot->output_section->vma
2523 + htab->elf.sgot->output_offset + off
2524 - htab->dsbt->output_section->vma
2525 - htab->dsbt->output_offset);
2526 else
2527 relocation = (htab->elf.sgot->output_section->vma
2528 + htab->elf.sgot->output_offset + off
2529 - htab->elf.sgotplt->output_section->vma
2530 - htab->elf.sgotplt->output_offset);
2531
2532 if (rel->r_addend != 0)
2533 {
2534 /* We can't do anything for a relocation which is against
2535 a symbol *plus offset*. GOT holds relocations for
2536 symbols. Make this an error; the compiler isn't
2537 allowed to pass us these kinds of things. */
2538 if (h == NULL)
4eca0228 2539 _bfd_error_handler
695344c0 2540 /* xgettext:c-format */
2dcf00ce
AM
2541 (_("%pB, section %pA: relocation %s with non-zero addend %"
2542 PRId64 " against local symbol"),
ac145307
BS
2543 input_bfd,
2544 input_section,
2545 elf32_tic6x_howto_table[r_type].name,
2dcf00ce 2546 (int64_t) rel->r_addend);
ac145307 2547 else
4eca0228 2548 _bfd_error_handler
695344c0 2549 /* xgettext:c-format */
2dcf00ce
AM
2550 (_("%pB, section %pA: relocation %s with non-zero addend %"
2551 PRId64 " against symbol `%s'"),
ac145307
BS
2552 input_bfd,
2553 input_section,
2554 elf32_tic6x_howto_table[r_type].name,
2dcf00ce 2555 (int64_t) rel->r_addend,
ac145307
BS
2556 h->root.root.string[0] != '\0' ? h->root.root.string
2557 : _("[whose name is lost]"));
2558
2559 bfd_set_error (bfd_error_bad_value);
2560 return FALSE;
2561 }
2562 break;
2563
40b36596 2564 case R_C6000_PREL31:
44e87ece
PB
2565 if (h != NULL
2566 && h->plt.offset != (bfd_vma) -1
2567 && htab->elf.splt != NULL)
2568 {
2569 relocation = (htab->elf.splt->output_section->vma
2570 + htab->elf.splt->output_offset
2571 + h->plt.offset);
2572 }
2573 break;
40b36596
JM
2574
2575 case R_C6000_COPY:
2576 /* Invalid in relocatable object. */
2577 default:
2578 /* Unknown relocation. */
695344c0 2579 /* xgettext:c-format */
0aa13fee 2580 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
4eca0228 2581 input_bfd, r_type);
f3185997 2582 bfd_set_error (bfd_error_bad_value);
40b36596
JM
2583 ok = FALSE;
2584 continue;
2585 }
2586
2587 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2588 contents, rel->r_offset,
2589 relocation, rel->r_addend);
2590
41820509 2591 done_reloc:
40b36596
JM
2592 if (r == bfd_reloc_ok
2593 && howto->complain_on_overflow == complain_overflow_bitfield)
2594 {
2595 /* Generic overflow handling accepts cases the ABI says
2596 should be rejected for R_C6000_ABS16 and
2597 R_C6000_ABS8. */
2598 bfd_vma value = (relocation + rel->r_addend) & 0xffffffff;
2599 bfd_vma sbit = 1 << (howto->bitsize - 1);
2600 bfd_vma sbits = (-(bfd_vma) sbit) & 0xffffffff;
2601 bfd_vma value_sbits = value & sbits;
2602
2603 if (value_sbits != 0
2604 && value_sbits != sbit
2605 && value_sbits != sbits)
2606 r = bfd_reloc_overflow;
2607 }
2608
2609 if (r != bfd_reloc_ok)
2610 {
2611 const char *name;
2612 const char *error_message;
2613
2614 if (h != NULL)
2615 name = h->root.root.string;
2616 else
2617 {
2618 name = bfd_elf_string_from_elf_section (input_bfd,
2619 symtab_hdr->sh_link,
2620 sym->st_name);
2621 if (name == NULL)
2622 return FALSE;
2623 if (*name == '\0')
fd361982 2624 name = bfd_section_name (sec);
40b36596
JM
2625 }
2626
2627 switch (r)
2628 {
2629 case bfd_reloc_overflow:
2630 /* If the overflowing reloc was to an undefined symbol,
2631 we have already printed one error message and there
2632 is no point complaining again. */
1a72702b
AM
2633 if (!h || h->root.type != bfd_link_hash_undefined)
2634 (*info->callbacks->reloc_overflow)
2635 (info, (h ? &h->root : NULL), name, howto->name,
2636 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
40b36596
JM
2637 break;
2638
2639 case bfd_reloc_undefined:
1a72702b
AM
2640 (*info->callbacks->undefined_symbol) (info, name, input_bfd,
2641 input_section,
2642 rel->r_offset, TRUE);
40b36596
JM
2643 break;
2644
2645 case bfd_reloc_outofrange:
2646 error_message = _("out of range");
2647 goto common_error;
2648
2649 case bfd_reloc_notsupported:
2650 error_message = _("unsupported relocation");
2651 goto common_error;
2652
2653 case bfd_reloc_dangerous:
2654 error_message = _("dangerous relocation");
2655 goto common_error;
2656
2657 default:
2658 error_message = _("unknown error");
2659 /* Fall through. */
2660
2661 common_error:
2662 BFD_ASSERT (error_message != NULL);
1a72702b
AM
2663 (*info->callbacks->reloc_dangerous)
2664 (info, error_message, input_bfd, input_section, rel->r_offset);
40b36596
JM
2665 break;
2666 }
2667 }
2668 }
2669
2670 return ok;
2671}
2672
ac145307
BS
2673\f
2674/* Look through the relocs for a section during the first phase, and
2675 calculate needed space in the global offset table, procedure linkage
2676 table, and dynamic reloc sections. */
2677
2678static bfd_boolean
2679elf32_tic6x_check_relocs (bfd *abfd, struct bfd_link_info *info,
2680 asection *sec, const Elf_Internal_Rela *relocs)
2681{
2682 struct elf32_tic6x_link_hash_table *htab;
2683 Elf_Internal_Shdr *symtab_hdr;
2684 struct elf_link_hash_entry **sym_hashes;
2685 const Elf_Internal_Rela *rel;
2686 const Elf_Internal_Rela *rel_end;
2687 asection *sreloc;
2688
0e1862bb 2689 if (bfd_link_relocatable (info))
ac145307
BS
2690 return TRUE;
2691
2692 htab = elf32_tic6x_hash_table (info);
2693 symtab_hdr = &elf_symtab_hdr (abfd);
2694 sym_hashes = elf_sym_hashes (abfd);
2695
2696 /* Create dynamic sections for relocatable executables so that we can
2697 copy relocations. */
0e1862bb 2698 if ((bfd_link_pic (info) || elf32_tic6x_using_dsbt (abfd))
ac145307
BS
2699 && ! htab->elf.dynamic_sections_created)
2700 {
2701 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
2702 return FALSE;
2703 }
2704
2705 sreloc = NULL;
2706
2707 rel_end = relocs + sec->reloc_count;
2708 for (rel = relocs; rel < rel_end; rel++)
2709 {
2710 unsigned int r_type;
d42c267e 2711 unsigned int r_symndx;
ac145307
BS
2712 struct elf_link_hash_entry *h;
2713 Elf_Internal_Sym *isym;
2714
2715 r_symndx = ELF32_R_SYM (rel->r_info);
2716 r_type = ELF32_R_TYPE (rel->r_info);
2717
2718 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
2719 {
695344c0 2720 /* xgettext:c-format */
871b3ab2 2721 _bfd_error_handler (_("%pB: bad symbol index: %d"),
4eca0228 2722 abfd, r_symndx);
ac145307
BS
2723 return FALSE;
2724 }
2725
2726 if (r_symndx < symtab_hdr->sh_info)
2727 {
2728 /* A local symbol. */
f1dfbfdb 2729 isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
ac145307
BS
2730 abfd, r_symndx);
2731 if (isym == NULL)
2732 return FALSE;
2733 h = NULL;
2734 }
2735 else
2736 {
2737 isym = NULL;
2738 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2739 while (h->root.type == bfd_link_hash_indirect
2740 || h->root.type == bfd_link_hash_warning)
2741 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2742 }
2743
2744 switch (r_type)
2745 {
2746 case R_C6000_PCR_S21:
44e87ece 2747 case R_C6000_PREL31:
ac145307
BS
2748 /* This symbol requires a procedure linkage table entry. We
2749 actually build the entry in adjust_dynamic_symbol,
2750 because this might be a case of linking PIC code which is
2751 never referenced by a dynamic object, in which case we
2752 don't need to generate a procedure linkage table entry
2753 after all. */
2754
2755 /* If this is a local symbol, we resolve it directly without
2756 creating a procedure linkage table entry. */
2757 if (h == NULL)
2758 continue;
2759
2760 h->needs_plt = 1;
2761 h->plt.refcount += 1;
2762 break;
2763
2764 case R_C6000_SBR_GOT_U15_W:
2765 case R_C6000_SBR_GOT_L16_W:
2766 case R_C6000_SBR_GOT_H16_W:
2fbb87f6 2767 case R_C6000_EHTYPE:
ac145307
BS
2768 /* This symbol requires a global offset table entry. */
2769 if (h != NULL)
2770 {
2771 h->got.refcount += 1;
2772 }
2773 else
2774 {
2775 bfd_signed_vma *local_got_refcounts;
2776
2777 /* This is a global offset table entry for a local symbol. */
2778 local_got_refcounts = elf_local_got_refcounts (abfd);
2779 if (local_got_refcounts == NULL)
2780 {
2781 bfd_size_type size;
2782
2783 size = symtab_hdr->sh_info;
2784 size *= (sizeof (bfd_signed_vma)
2785 + sizeof (bfd_vma) + sizeof(char));
2786 local_got_refcounts = bfd_zalloc (abfd, size);
2787 if (local_got_refcounts == NULL)
2788 return FALSE;
2789 elf_local_got_refcounts (abfd) = local_got_refcounts;
2790 }
2791 local_got_refcounts[r_symndx] += 1;
2792 }
2793
2794 if (htab->elf.sgot == NULL)
2795 {
2796 if (htab->elf.dynobj == NULL)
2797 htab->elf.dynobj = abfd;
2798 if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
2799 return FALSE;
2800 }
2801 break;
2802
2803 case R_C6000_DSBT_INDEX:
2804 /* We'd like to check for nonzero dsbt_index here, but it's
2805 set up only after check_relocs is called. Instead, we
2806 store the number of R_C6000_DSBT_INDEX relocs in the
2807 pc_count field, and potentially discard the extra space
2808 in elf32_tic6x_allocate_dynrelocs. */
0e1862bb 2809 if (!bfd_link_pic (info))
ac145307
BS
2810 break;
2811
2812 /* fall through */
2813 case R_C6000_ABS32:
2814 case R_C6000_ABS16:
2815 case R_C6000_ABS8:
2816 case R_C6000_ABS_S16:
2817 case R_C6000_ABS_L16:
2818 case R_C6000_ABS_H16:
2819 /* If we are creating a shared library, and this is a reloc
2820 against a global symbol, or a non PC relative reloc
2821 against a local symbol, then we need to copy the reloc
2822 into the shared library. However, if we are linking with
2823 -Bsymbolic, we do not need to copy a reloc against a
2824 global symbol which is defined in an object we are
2825 including in the link (i.e., DEF_REGULAR is set). At
2826 this point we have not seen all the input files, so it is
2827 possible that DEF_REGULAR is not set now but will be set
2828 later (it is never cleared). In case of a weak definition,
2829 DEF_REGULAR may be cleared later by a strong definition in
2830 a shared library. We account for that possibility below by
2831 storing information in the relocs_copied field of the hash
2832 table entry. A similar situation occurs when creating
2833 shared libraries and symbol visibility changes render the
2834 symbol local.
2835
2836 If on the other hand, we are creating an executable, we
2837 may need to keep relocations for symbols satisfied by a
2838 dynamic library if we manage to avoid copy relocs for the
2839 symbol. */
0e1862bb 2840 if ((bfd_link_pic (info) || elf32_tic6x_using_dsbt (abfd))
ac145307
BS
2841 && (sec->flags & SEC_ALLOC) != 0)
2842 {
2843 struct elf_dyn_relocs *p;
2844 struct elf_dyn_relocs **head;
2845
2846 /* We must copy these reloc types into the output file.
2847 Create a reloc section in dynobj and make room for
2848 this reloc. */
2849 if (sreloc == NULL)
2850 {
2851 if (htab->elf.dynobj == NULL)
2852 htab->elf.dynobj = abfd;
2853
2854 sreloc = _bfd_elf_make_dynamic_reloc_section
2855 (sec, htab->elf.dynobj, 2, abfd, /*rela? */ TRUE);
2856
2857 if (sreloc == NULL)
2858 return FALSE;
2859 }
2860
2861 /* If this is a global symbol, we count the number of
2862 relocations we need for this symbol. */
2863 if (h != NULL)
2864 {
190eb1dd 2865 head = &h->dyn_relocs;
ac145307
BS
2866 }
2867 else
2868 {
2869 /* Track dynamic relocs needed for local syms too.
2870 We really need local syms available to do this
2871 easily. Oh well. */
2872 void **vpp;
2873 asection *s;
2874
2875 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2876 if (s == NULL)
2877 s = sec;
2878
2879 vpp = &elf_section_data (s)->local_dynrel;
2880 head = (struct elf_dyn_relocs **)vpp;
2881 }
2882
2883 p = *head;
2884 if (p == NULL || p->sec != sec)
2885 {
986f0783 2886 size_t amt = sizeof *p;
ac145307
BS
2887 p = bfd_alloc (htab->elf.dynobj, amt);
2888 if (p == NULL)
2889 return FALSE;
2890 p->next = *head;
2891 *head = p;
2892 p->sec = sec;
2893 p->count = 0;
2123f9ad 2894 p->pc_count = 0;
ac145307
BS
2895 }
2896
2897 p->count += 1;
2898 if (r_type == R_C6000_DSBT_INDEX)
2899 p->pc_count += 1;
2900 }
2901 break;
2902
2903 case R_C6000_SBR_U15_B:
2904 case R_C6000_SBR_U15_H:
2905 case R_C6000_SBR_U15_W:
2906 case R_C6000_SBR_S16:
2907 case R_C6000_SBR_L16_B:
2908 case R_C6000_SBR_L16_H:
2909 case R_C6000_SBR_L16_W:
2910 case R_C6000_SBR_H16_B:
2911 case R_C6000_SBR_H16_H:
2912 case R_C6000_SBR_H16_W:
527278f3
AM
2913 {
2914 /* These relocations implicitly reference __c6xabi_DSBT_BASE.
2915 Add an explicit reference so that the symbol will be
2916 provided by a linker script. */
2917 struct bfd_link_hash_entry *bh = NULL;
2918 if (!_bfd_generic_link_add_one_symbol (info, abfd,
2919 "__c6xabi_DSBT_BASE",
2920 BSF_GLOBAL,
2921 bfd_und_section_ptr, 0,
2922 NULL, FALSE, FALSE, &bh))
2923 return FALSE;
2924 ((struct elf_link_hash_entry *) bh)->non_elf = 0;
2925 }
0e1862bb 2926 if (h != NULL && bfd_link_executable (info))
ac145307
BS
2927 {
2928 /* For B14-relative addresses, we might need a copy
2929 reloc. */
2930 h->non_got_ref = 1;
2931 }
2932 break;
2933
2934 default:
2935 break;
2936 }
2937 }
2938
2939 return TRUE;
2940}
2941
2942static bfd_boolean
2943elf32_tic6x_add_symbol_hook (bfd *abfd,
2944 struct bfd_link_info *info ATTRIBUTE_UNUSED,
2945 Elf_Internal_Sym *sym,
2946 const char **namep ATTRIBUTE_UNUSED,
2947 flagword *flagsp ATTRIBUTE_UNUSED,
2948 asection **secp,
2949 bfd_vma *valp)
2950{
2951 switch (sym->st_shndx)
2952 {
2953 case SHN_TIC6X_SCOMMON:
2954 *secp = bfd_make_section_old_way (abfd, ".scommon");
2955 (*secp)->flags |= SEC_IS_COMMON;
2956 *valp = sym->st_size;
fd361982 2957 bfd_set_section_alignment (*secp, bfd_log2 (sym->st_value));
ac145307
BS
2958 break;
2959 }
2960
2961 return TRUE;
2962}
2963
2964static void
2965elf32_tic6x_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
2966{
2967 elf_symbol_type *elfsym;
2968
2969 elfsym = (elf_symbol_type *) asym;
2970 switch (elfsym->internal_elf_sym.st_shndx)
2971 {
2972 case SHN_TIC6X_SCOMMON:
2973 if (tic6x_elf_scom_section.name == NULL)
07d6d2b8
AM
2974 {
2975 /* Initialize the small common section. */
2976 tic6x_elf_scom_section.name = ".scommon";
2977 tic6x_elf_scom_section.flags = SEC_IS_COMMON;
2978 tic6x_elf_scom_section.output_section = &tic6x_elf_scom_section;
2979 tic6x_elf_scom_section.symbol = &tic6x_elf_scom_symbol;
2980 tic6x_elf_scom_section.symbol_ptr_ptr = &tic6x_elf_scom_symbol_ptr;
2981 tic6x_elf_scom_symbol.name = ".scommon";
2982 tic6x_elf_scom_symbol.flags = BSF_SECTION_SYM;
2983 tic6x_elf_scom_symbol.section = &tic6x_elf_scom_section;
2984 tic6x_elf_scom_symbol_ptr = &tic6x_elf_scom_symbol;
2985 }
ac145307
BS
2986 asym->section = &tic6x_elf_scom_section;
2987 asym->value = elfsym->internal_elf_sym.st_size;
2988 break;
2989 }
2990}
2991
2992static int
2993elf32_tic6x_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
2994 const char *name ATTRIBUTE_UNUSED,
2995 Elf_Internal_Sym *sym,
2996 asection *input_sec,
2997 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
2998{
2999 /* If we see a common symbol, which implies a relocatable link, then
3000 if a symbol was small common in an input file, mark it as small
3001 common in the output file. */
3002 if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
3003 sym->st_shndx = SHN_TIC6X_SCOMMON;
3004
3005 return 1;
3006}
3007
3008static bfd_boolean
3009elf32_tic6x_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
3010 asection *sec,
3011 int *retval)
3012{
fd361982 3013 if (strcmp (bfd_section_name (sec), ".scommon") == 0)
ac145307
BS
3014 {
3015 *retval = SHN_TIC6X_SCOMMON;
3016 return TRUE;
3017 }
3018
3019 return FALSE;
3020}
3021
3022/* Allocate space in .plt, .got and associated reloc sections for
3023 dynamic relocs. */
3024
3025static bfd_boolean
3026elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3027{
3028 struct bfd_link_info *info;
3029 struct elf32_tic6x_link_hash_table *htab;
ac145307
BS
3030 struct elf_dyn_relocs *p;
3031
3032 if (h->root.type == bfd_link_hash_indirect)
3033 return TRUE;
3034
ac145307
BS
3035 info = (struct bfd_link_info *) inf;
3036 htab = elf32_tic6x_hash_table (info);
3037
3038 if (htab->elf.dynamic_sections_created && h->plt.refcount > 0)
3039 {
3040 /* Make sure this symbol is output as a dynamic symbol.
3041 Undefined weak syms won't yet be marked as dynamic. */
3042 if (h->dynindx == -1 && !h->forced_local)
3043 {
3044 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3045 return FALSE;
3046 }
3047
0e1862bb 3048 if (bfd_link_pic (info)
ac145307
BS
3049 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3050 {
3051 asection *s = htab->elf.splt;
3052
3053 /* If this is the first .plt entry, make room for the special
3054 first entry. */
3055 if (s->size == 0)
3056 s->size += PLT_ENTRY_SIZE;
3057
3058 h->plt.offset = s->size;
3059
3060 /* If this symbol is not defined in a regular file, and we are
3061 not generating a shared library, then set the symbol to this
3062 location in the .plt. This is required to make function
3063 pointers compare as equal between the normal executable and
3064 the shared library. */
0e1862bb 3065 if (! bfd_link_pic (info) && !h->def_regular)
ac145307
BS
3066 {
3067 h->root.u.def.section = s;
3068 h->root.u.def.value = h->plt.offset;
3069 }
3070
3071 /* Make room for this entry. */
3072 s->size += PLT_ENTRY_SIZE;
3073 /* We also need to make an entry in the .got.plt section, which
3074 will be placed in the .got section by the linker script. */
3075 htab->elf.sgotplt->size += 4;
3076 /* We also need to make an entry in the .rel.plt section. */
3077 htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
3078 }
3079 else
3080 {
3081 h->plt.offset = (bfd_vma) -1;
3082 h->needs_plt = 0;
3083 }
3084 }
3085 else
3086 {
3087 h->plt.offset = (bfd_vma) -1;
3088 h->needs_plt = 0;
3089 }
3090
3091 if (h->got.refcount > 0)
3092 {
3093 asection *s;
3094
3095 /* Make sure this symbol is output as a dynamic symbol.
3096 Undefined weak syms won't yet be marked as dynamic. */
3097 if (h->dynindx == -1
3098 && !h->forced_local)
3099 {
3100 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3101 return FALSE;
3102 }
3103
3104 s = htab->elf.sgot;
3105 h->got.offset = s->size;
3106 s->size += 4;
3107
3108 if (!(ELF_ST_VISIBILITY (h->other)
3109 && h->root.type == bfd_link_hash_undefweak))
3110 htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
3111 }
3112 else
3113 h->got.offset = (bfd_vma) -1;
3114
190eb1dd 3115 if (h->dyn_relocs == NULL)
ac145307
BS
3116 return TRUE;
3117
3118 /* Discard relocs on undefined weak syms with non-default
3119 visibility. */
0e1862bb 3120 if (bfd_link_pic (info) || elf32_tic6x_using_dsbt (htab->obfd))
ac145307
BS
3121 {
3122 /* We use the pc_count field to hold the number of
3123 R_C6000_DSBT_INDEX relocs. */
3124 if (htab->params.dsbt_index != 0)
3125 {
3126 struct elf_dyn_relocs **pp;
3127
190eb1dd 3128 for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
ac145307
BS
3129 {
3130 p->count -= p->pc_count;
3131 p->pc_count = 0;
3132 if (p->count == 0)
3133 *pp = p->next;
3134 else
3135 pp = &p->next;
3136 }
3137 }
3138
190eb1dd 3139 if (h->dyn_relocs != NULL
ac145307
BS
3140 && h->root.type == bfd_link_hash_undefweak)
3141 {
3142 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
190eb1dd 3143 h->dyn_relocs = NULL;
ac145307
BS
3144
3145 /* Make sure undefined weak symbols are output as a dynamic
3146 symbol in PIEs. */
3147 else if (h->dynindx == -1
3148 && !h->forced_local)
3149 {
3150 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3151 return FALSE;
3152 }
3153 }
3154 }
3155
3156 /* Finally, allocate space. */
190eb1dd 3157 for (p = h->dyn_relocs; p != NULL; p = p->next)
ac145307
BS
3158 {
3159 asection *sreloc;
3160
3161 sreloc = elf_section_data (p->sec)->sreloc;
3162
3163 BFD_ASSERT (sreloc != NULL);
3164 sreloc->size += p->count * sizeof (Elf32_External_Rela);
3165 }
3166
3167 return TRUE;
3168}
3169
ac145307
BS
3170/* Set the sizes of the dynamic sections. */
3171
3172static bfd_boolean
3173elf32_tic6x_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
3174{
3175 struct elf32_tic6x_link_hash_table *htab;
3176 bfd *dynobj;
3177 asection *s;
3178 bfd_boolean relocs;
3179 bfd *ibfd;
3180
3181 htab = elf32_tic6x_hash_table (info);
3182 dynobj = htab->elf.dynobj;
3183 if (dynobj == NULL)
3184 abort ();
3185
3186 if (htab->elf.dynamic_sections_created)
3187 {
3188 /* Set the contents of the .interp section to the interpreter. */
9b8b325a 3189 if (bfd_link_executable (info) && !info->nointerp)
ac145307 3190 {
3d4d4302 3191 s = bfd_get_linker_section (dynobj, ".interp");
ac145307
BS
3192 if (s == NULL)
3193 abort ();
3194 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3195 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3196 }
3197 }
3198
3199 /* Set up .got offsets for local syms, and space for local dynamic
3200 relocs. */
c72f2fb2 3201 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
ac145307
BS
3202 {
3203 bfd_signed_vma *local_got;
3204 bfd_signed_vma *end_local_got;
ac145307
BS
3205 bfd_size_type locsymcount;
3206 Elf_Internal_Shdr *symtab_hdr;
3207 asection *srel;
3208
3209 for (s = ibfd->sections; s != NULL; s = s->next)
3210 {
3211 struct elf_dyn_relocs *p;
3212
3213 for (p = ((struct elf_dyn_relocs *)
3214 elf_section_data (s)->local_dynrel);
3215 p != NULL;
3216 p = p->next)
3217 {
3218 if (!bfd_is_abs_section (p->sec)
3219 && bfd_is_abs_section (p->sec->output_section))
3220 {
3221 /* Input section has been discarded, either because
3222 it is a copy of a linkonce section or due to
3223 linker script /DISCARD/, so we'll be discarding
3224 the relocs too. */
3225 }
3226 else if (p->count != 0)
3227 {
3228 srel = elf_section_data (p->sec)->sreloc;
3229 srel->size += p->count * sizeof (Elf32_External_Rela);
3230 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3231 info->flags |= DF_TEXTREL;
3232 }
3233 }
3234 }
3235
3236 local_got = elf_local_got_refcounts (ibfd);
3237 if (!local_got)
3238 continue;
3239
3240 symtab_hdr = &elf_symtab_hdr (ibfd);
3241 locsymcount = symtab_hdr->sh_info;
3242 end_local_got = local_got + locsymcount;
3243 s = htab->elf.sgot;
3244 srel = htab->elf.srelgot;
544008aa 3245 for (; local_got < end_local_got; ++local_got)
ac145307
BS
3246 {
3247 if (*local_got > 0)
3248 {
3249 *local_got = s->size;
3250 s->size += 4;
3251
0e1862bb 3252 if (bfd_link_pic (info) || elf32_tic6x_using_dsbt (output_bfd))
ac145307
BS
3253 {
3254 srel->size += sizeof (Elf32_External_Rela);
3255 }
3256 }
3257 else
3258 *local_got = (bfd_vma) -1;
3259 }
3260 }
3261
3262 /* Allocate global sym .plt and .got entries, and space for global
3263 sym dynamic relocs. */
3264 elf_link_hash_traverse (&htab->elf, elf32_tic6x_allocate_dynrelocs, info);
3265
3266 /* We now have determined the sizes of the various dynamic sections.
3267 Allocate memory for them. */
3268 relocs = FALSE;
3269 for (s = dynobj->sections; s != NULL; s = s->next)
3270 {
3271 bfd_boolean strip_section = TRUE;
3272
3273 if ((s->flags & SEC_LINKER_CREATED) == 0)
3274 continue;
3275
3276 if (s == htab->dsbt)
3277 s->size = 4 * htab->params.dsbt_size;
3278 else if (s == htab->elf.splt
3279 || s == htab->elf.sgot
3280 || s == htab->elf.sgotplt
5474d94f
AM
3281 || s == htab->elf.sdynbss
3282 || s == htab->elf.sdynrelro)
ac145307
BS
3283 {
3284 /* Strip this section if we don't need it; see the
3285 comment below. */
3286 /* We'd like to strip these sections if they aren't needed, but if
3287 we've exported dynamic symbols from them we must leave them.
3288 It's too late to tell BFD to get rid of the symbols. */
3289
3290 if (htab->elf.hplt != NULL)
3291 strip_section = FALSE;
3292
3293 /* Round up the size of the PLT section to a multiple of 32. */
3294 if (s == htab->elf.splt && s->size > 0)
3295 s->size = (s->size + 31) & ~(bfd_vma)31;
3296 }
fd361982 3297 else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
ac145307
BS
3298 {
3299 if (s->size != 0
3300 && s != htab->elf.srelplt)
3301 relocs = TRUE;
3302
3303 /* We use the reloc_count field as a counter if we need
3304 to copy relocs into the output file. */
3305 s->reloc_count = 0;
3306 }
3307 else
3308 {
3309 /* It's not one of our sections, so don't allocate space. */
3310 continue;
3311 }
3312
3313 if (s->size == 0)
3314 {
3315 /* If we don't need this section, strip it from the
3316 output file. This is mostly to handle .rel.bss and
3317 .rel.plt. We must create both sections in
3318 create_dynamic_sections, because they must be created
3319 before the linker maps input sections to output
3320 sections. The linker does that before
3321 adjust_dynamic_symbol is called, and it is that
3322 function which decides whether anything needs to go
3323 into these sections. */
3324 if (strip_section)
3325 s->flags |= SEC_EXCLUDE;
3326 continue;
3327 }
3328
3329 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3330 continue;
3331
3332 /* Allocate memory for the section contents. We use bfd_zalloc
3333 here in case unused entries are not reclaimed before the
3334 section's contents are written out. This should not happen,
3335 but this way if it does, we get a R_C6000_NONE reloc instead
3336 of garbage. */
3337 s->contents = bfd_zalloc (dynobj, s->size);
3338 if (s->contents == NULL)
3339 return FALSE;
3340 }
3341
3342 if (htab->elf.dynamic_sections_created)
3343 {
3344 /* Add some entries to the .dynamic section. We fill in the
3345 values later, in elf32_tic6x_finish_dynamic_sections, but we
3346 must add the entries now so that we get the correct size for
3347 the .dynamic section. The DT_DEBUG entry is filled in by the
3348 dynamic linker and used by the debugger. */
3349#define add_dynamic_entry(TAG, VAL) \
3350 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3351
a57f74bb
L
3352 if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs))
3353 return FALSE;
ac145307
BS
3354
3355 if (!add_dynamic_entry (DT_C6000_DSBT_BASE, 0)
3356 || !add_dynamic_entry (DT_C6000_DSBT_SIZE, htab->params.dsbt_size)
3357 || !add_dynamic_entry (DT_C6000_DSBT_INDEX,
3358 htab->params.dsbt_index))
3359 return FALSE;
3360
ac145307
BS
3361 }
3362#undef add_dynamic_entry
3363
3364 return TRUE;
3365}
3366
3367/* This function is called after all the input files have been read,
3368 and the input sections have been assigned to output sections. */
3369
3370static bfd_boolean
3371elf32_tic6x_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3372{
0e1862bb 3373 if (elf32_tic6x_using_dsbt (output_bfd) && !bfd_link_relocatable (info)
04c3a755
NS
3374 && !bfd_elf_stack_segment_size (output_bfd, info,
3375 "__stacksize", DEFAULT_STACK_SIZE))
3376 return FALSE;
ac145307
BS
3377
3378 return TRUE;
3379}
3380
3381static bfd_boolean
3382elf32_tic6x_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3383 struct bfd_link_info *info)
3384{
3385 struct elf32_tic6x_link_hash_table *htab;
3386 bfd *dynobj;
3387 asection *sdyn;
3388
3389 htab = elf32_tic6x_hash_table (info);
3390 dynobj = htab->elf.dynobj;
3d4d4302 3391 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
ac145307
BS
3392
3393 if (elf_hash_table (info)->dynamic_sections_created)
3394 {
3395 Elf32_External_Dyn * dyncon;
3396 Elf32_External_Dyn * dynconend;
3397
3398 BFD_ASSERT (sdyn != NULL);
3399
3400 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3401 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3402
3403 for (; dyncon < dynconend; dyncon++)
3404 {
3405 Elf_Internal_Dyn dyn;
3406 asection *s;
3407
3408 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3409
3410 switch (dyn.d_tag)
3411 {
3412 default:
3413 break;
3414
3415 case DT_C6000_DSBT_BASE:
3416 s = htab->dsbt;
3417 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset);
3418 break;
3419
3420 case DT_PLTGOT:
3421 s = htab->elf.sgotplt;
3422 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3423 break;
3424
3425 case DT_JMPREL:
3426 s = htab->elf.srelplt;
3427 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3428 break;
3429
3430 case DT_PLTRELSZ:
3431 s = htab->elf.srelplt;
3432 dyn.d_un.d_val = s->size;
3433 break;
3434 }
3435 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3436 }
3437
3438 /* Fill in the first entry in the procedure linkage table. */
3439 if (htab->elf.splt && htab->elf.splt->size > 0)
3440 {
3441 bfd_vma got_offs = (htab->elf.sgotplt->output_section->vma
3442 + htab->elf.sgotplt->output_offset
3443 - htab->dsbt->output_section->vma
3444 - htab->dsbt->output_offset) / 4;
3445
3446 /* ldw .D2T2 *+b14[$GOT(0)],b2 */
3447 bfd_put_32 (output_bfd, got_offs << 8 | 0x0100006e,
3448 htab->elf.splt->contents);
3449 /* ldw .D2T2 *+b14[$GOT(4)],b1 */
3450 bfd_put_32 (output_bfd, (got_offs + 1) << 8 | 0x0080006e,
3451 htab->elf.splt->contents + 4);
3452 /* nop 3 */
3453 bfd_put_32 (output_bfd, 0x00004000,
3454 htab->elf.splt->contents + 8);
3455 /* b .s2 b2 */
3456 bfd_put_32 (output_bfd, 0x00080362,
3457 htab->elf.splt->contents + 12);
3458 /* nop 5 */
3459 bfd_put_32 (output_bfd, 0x00008000,
3460 htab->elf.splt->contents + 16);
3461
3462 elf_section_data (htab->elf.splt->output_section)
3463 ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
3464 }
3465 }
3466
3467 return TRUE;
3468}
3469
3470/* Return address for Ith PLT stub in section PLT, for relocation REL
3471 or (bfd_vma) -1 if it should not be included. */
3472
3473static bfd_vma
3474elf32_tic6x_plt_sym_val (bfd_vma i, const asection *plt,
3475 const arelent *rel ATTRIBUTE_UNUSED)
3476{
3477 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
3478}
3479
3480static int
3481elf32_tic6x_obj_attrs_arg_type (int tag)
59e6276b 3482{
3cbd1c06 3483 if (tag == Tag_ABI_compatibility)
59e6276b 3484 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
87779176
JM
3485 else if (tag & 1)
3486 return ATTR_TYPE_FLAG_STR_VAL;
59e6276b 3487 else
59e6276b
JM
3488 return ATTR_TYPE_FLAG_INT_VAL;
3489}
3490
87779176
JM
3491static int
3492elf32_tic6x_obj_attrs_order (int num)
3493{
3494 if (num == LEAST_KNOWN_OBJ_ATTRIBUTE)
3495 return Tag_ABI_conformance;
3496 if ((num - 1) < Tag_ABI_conformance)
3497 return num - 1;
3498 return num;
3499}
3500
0547accf
JM
3501static bfd_boolean
3502elf32_tic6x_obj_attrs_handle_unknown (bfd *abfd, int tag)
3503{
3504 if ((tag & 127) < 64)
3505 {
3506 _bfd_error_handler
695344c0 3507 /* xgettext:c-format */
871b3ab2 3508 (_("%pB: error: unknown mandatory EABI object attribute %d"),
0547accf
JM
3509 abfd, tag);
3510 bfd_set_error (bfd_error_bad_value);
3511 return FALSE;
3512 }
3513 else
3514 {
3515 _bfd_error_handler
695344c0 3516 /* xgettext:c-format */
871b3ab2 3517 (_("%pB: warning: unknown EABI object attribute %d"),
0547accf
JM
3518 abfd, tag);
3519 return TRUE;
3520 }
3521}
3522
75fa6dc1 3523/* Merge the Tag_ISA attribute values ARCH1 and ARCH2
59e6276b
JM
3524 and return the merged value. At present, all merges succeed, so no
3525 return value for errors is defined. */
3526
3527int
3528elf32_tic6x_merge_arch_attributes (int arch1, int arch2)
3529{
3530 int min_arch, max_arch;
3531
3532 min_arch = (arch1 < arch2 ? arch1 : arch2);
3533 max_arch = (arch1 > arch2 ? arch1 : arch2);
3534
3535 /* In most cases, the numerically greatest value is the correct
3536 merged value, but merging C64 and C67 results in C674X. */
75fa6dc1
JM
3537 if ((min_arch == C6XABI_Tag_ISA_C67X
3538 || min_arch == C6XABI_Tag_ISA_C67XP)
3539 && (max_arch == C6XABI_Tag_ISA_C64X
3540 || max_arch == C6XABI_Tag_ISA_C64XP))
3541 return C6XABI_Tag_ISA_C674X;
59e6276b
JM
3542
3543 return max_arch;
3544}
3545
87779176
JM
3546/* Convert a Tag_ABI_array_object_alignment or
3547 Tag_ABI_array_object_align_expected tag value TAG to a
3548 corresponding alignment value; return the alignment, or -1 for an
3549 unknown tag value. */
3550
3551static int
3552elf32_tic6x_tag_to_array_alignment (int tag)
3553{
3554 switch (tag)
3555 {
3556 case 0:
3557 return 8;
3558
3559 case 1:
3560 return 4;
3561
3562 case 2:
3563 return 16;
3564
3565 default:
3566 return -1;
3567 }
3568}
3569
3570/* Convert a Tag_ABI_array_object_alignment or
3571 Tag_ABI_array_object_align_expected alignment ALIGN to a
3572 corresponding tag value; return the tag value. */
3573
3574static int
3575elf32_tic6x_array_alignment_to_tag (int align)
3576{
3577 switch (align)
3578 {
3579 case 8:
3580 return 0;
3581
3582 case 4:
3583 return 1;
3584
3585 case 16:
3586 return 2;
3587
3588 default:
3589 abort ();
3590 }
3591}
3592
59e6276b
JM
3593/* Merge attributes from IBFD and OBFD, returning TRUE if the merge
3594 succeeded, FALSE otherwise. */
3595
3596static bfd_boolean
50e03d47 3597elf32_tic6x_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
59e6276b 3598{
50e03d47 3599 bfd *obfd = info->output_bfd;
87779176 3600 bfd_boolean result = TRUE;
59e6276b
JM
3601 obj_attribute *in_attr;
3602 obj_attribute *out_attr;
87779176
JM
3603 int i;
3604 int array_align_in, array_align_out, array_expect_in, array_expect_out;
59e6276b 3605
6b728d32
AM
3606 /* FIXME: What should be checked when linking shared libraries? */
3607 if ((ibfd->flags & DYNAMIC) != 0)
3608 return TRUE;
3609
59e6276b
JM
3610 if (!elf_known_obj_attributes_proc (obfd)[0].i)
3611 {
3612 /* This is the first object. Copy the attributes. */
3613 _bfd_elf_copy_obj_attributes (ibfd, obfd);
3614
3615 out_attr = elf_known_obj_attributes_proc (obfd);
3616
3617 /* Use the Tag_null value to indicate the attributes have been
3618 initialized. */
3619 out_attr[0].i = 1;
3620
3621 return TRUE;
3622 }
3623
3624 in_attr = elf_known_obj_attributes_proc (ibfd);
3625 out_attr = elf_known_obj_attributes_proc (obfd);
3626
3627 /* No specification yet for handling of unknown attributes, so just
3628 ignore them and handle known ones. */
59e6276b 3629
87779176
JM
3630 if (out_attr[Tag_ABI_stack_align_preserved].i
3631 < in_attr[Tag_ABI_stack_align_needed].i)
3632 {
3633 _bfd_error_handler
695344c0 3634 /* xgettext:c-format */
871b3ab2 3635 (_("error: %pB requires more stack alignment than %pB preserves"),
87779176
JM
3636 ibfd, obfd);
3637 result = FALSE;
3638 }
3639 if (in_attr[Tag_ABI_stack_align_preserved].i
3640 < out_attr[Tag_ABI_stack_align_needed].i)
3641 {
3642 _bfd_error_handler
695344c0 3643 /* xgettext:c-format */
871b3ab2 3644 (_("error: %pB requires more stack alignment than %pB preserves"),
87779176
JM
3645 obfd, ibfd);
3646 result = FALSE;
3647 }
3648
3649 array_align_in = elf32_tic6x_tag_to_array_alignment
3650 (in_attr[Tag_ABI_array_object_alignment].i);
3651 if (array_align_in == -1)
3652 {
3653 _bfd_error_handler
871b3ab2 3654 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
87779176
JM
3655 ibfd);
3656 result = FALSE;
3657 }
3658 array_align_out = elf32_tic6x_tag_to_array_alignment
3659 (out_attr[Tag_ABI_array_object_alignment].i);
3660 if (array_align_out == -1)
3661 {
3662 _bfd_error_handler
871b3ab2 3663 (_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
87779176
JM
3664 obfd);
3665 result = FALSE;
3666 }
3667 array_expect_in = elf32_tic6x_tag_to_array_alignment
3668 (in_attr[Tag_ABI_array_object_align_expected].i);
3669 if (array_expect_in == -1)
3670 {
3671 _bfd_error_handler
871b3ab2 3672 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
87779176
JM
3673 ibfd);
3674 result = FALSE;
3675 }
3676 array_expect_out = elf32_tic6x_tag_to_array_alignment
3677 (out_attr[Tag_ABI_array_object_align_expected].i);
3678 if (array_expect_out == -1)
3679 {
3680 _bfd_error_handler
871b3ab2 3681 (_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
87779176
JM
3682 obfd);
3683 result = FALSE;
3684 }
3685
3686 if (array_align_out < array_expect_in)
3687 {
3688 _bfd_error_handler
695344c0 3689 /* xgettext:c-format */
871b3ab2 3690 (_("error: %pB requires more array alignment than %pB preserves"),
87779176
JM
3691 ibfd, obfd);
3692 result = FALSE;
3693 }
3694 if (array_align_in < array_expect_out)
b5593623
JM
3695 {
3696 _bfd_error_handler
695344c0 3697 /* xgettext:c-format */
871b3ab2 3698 (_("error: %pB requires more array alignment than %pB preserves"),
b5593623 3699 obfd, ibfd);
87779176 3700 result = FALSE;
b5593623 3701 }
87779176
JM
3702
3703 for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
3704 {
3705 switch (i)
3706 {
3707 case Tag_ISA:
3708 out_attr[i].i = elf32_tic6x_merge_arch_attributes (in_attr[i].i,
3709 out_attr[i].i);
3710 break;
3711
3712 case Tag_ABI_wchar_t:
3713 if (out_attr[i].i == 0)
3714 out_attr[i].i = in_attr[i].i;
3715 if (out_attr[i].i != 0
3716 && in_attr[i].i != 0
3717 && out_attr[i].i != in_attr[i].i)
3718 {
3719 _bfd_error_handler
695344c0 3720 /* xgettext:c-format */
871b3ab2 3721 (_("warning: %pB and %pB differ in wchar_t size"), obfd, ibfd);
87779176
JM
3722 }
3723 break;
3724
3725 case Tag_ABI_stack_align_needed:
3726 if (out_attr[i].i < in_attr[i].i)
3727 out_attr[i].i = in_attr[i].i;
3728 break;
3729
3730 case Tag_ABI_stack_align_preserved:
3731 if (out_attr[i].i > in_attr[i].i)
3732 out_attr[i].i = in_attr[i].i;
3733 break;
3734
3735 case Tag_ABI_DSBT:
3736 if (out_attr[i].i != in_attr[i].i)
3737 {
3738 _bfd_error_handler
695344c0 3739 /* xgettext:c-format */
871b3ab2 3740 (_("warning: %pB and %pB differ in whether code is "
87779176
JM
3741 "compiled for DSBT"),
3742 obfd, ibfd);
3743 }
3744 break;
3745
87779176 3746 case Tag_ABI_PIC:
c6a8f6e0 3747 case Tag_ABI_PID:
a8acd6ee
AM
3748 /* Don't transfer these tags from dynamic objects. */
3749 if ((ibfd->flags & DYNAMIC) != 0)
3750 continue;
c6a8f6e0
BS
3751 if (out_attr[i].i > in_attr[i].i)
3752 out_attr[i].i = in_attr[i].i;
87779176
JM
3753 break;
3754
3755 case Tag_ABI_array_object_alignment:
3756 if (array_align_out != -1
3757 && array_align_in != -1
3758 && array_align_out > array_align_in)
3759 out_attr[i].i
3760 = elf32_tic6x_array_alignment_to_tag (array_align_in);
3761 break;
3762
3763 case Tag_ABI_array_object_align_expected:
3764 if (array_expect_out != -1
3765 && array_expect_in != -1
3766 && array_expect_out < array_expect_in)
3767 out_attr[i].i
3768 = elf32_tic6x_array_alignment_to_tag (array_expect_in);
3769 break;
3770
3771 case Tag_ABI_conformance:
3772 /* Merging for this attribute is not specified. As on ARM,
3773 treat a missing attribute as no claim to conform and only
3774 merge identical values. */
3775 if (out_attr[i].s == NULL
3776 || in_attr[i].s == NULL
3777 || strcmp (out_attr[i].s,
3778 in_attr[i].s) != 0)
3779 out_attr[i].s = NULL;
3780 break;
3781
0547accf
JM
3782 case Tag_ABI_compatibility:
3783 /* Merged in _bfd_elf_merge_object_attributes. */
3784 break;
3785
87779176 3786 default:
0547accf
JM
3787 result
3788 = result && _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
87779176
JM
3789 break;
3790 }
3791
3792 if (in_attr[i].type && !out_attr[i].type)
3793 out_attr[i].type = in_attr[i].type;
3794 }
3795
3cbd1c06 3796 /* Merge Tag_ABI_compatibility attributes and any common GNU ones. */
50e03d47 3797 if (!_bfd_elf_merge_object_attributes (ibfd, info))
3cbd1c06 3798 return FALSE;
59e6276b 3799
0547accf
JM
3800 result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd);
3801
87779176 3802 return result;
59e6276b
JM
3803}
3804
3805static bfd_boolean
50e03d47 3806elf32_tic6x_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
59e6276b 3807{
50e03d47 3808 if (!_bfd_generic_verify_endian_match (ibfd, info))
59e6276b
JM
3809 return FALSE;
3810
50e03d47 3811 if (! is_tic6x_elf (ibfd) || ! is_tic6x_elf (info->output_bfd))
b781d74f
JM
3812 return TRUE;
3813
50e03d47 3814 if (!elf32_tic6x_merge_attributes (ibfd, info))
59e6276b
JM
3815 return FALSE;
3816
3817 return TRUE;
3818}
3819
fbd9ad90
PB
3820/* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
3821 adds the edit to the start of the list. (The list must be built in order of
3822 ascending TINDEX: the function's callers are primarily responsible for
3823 maintaining that condition). */
3824
3825static void
3826elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit **head,
3827 tic6x_unwind_table_edit **tail,
3828 tic6x_unwind_edit_type type,
3829 asection *linked_section,
3830 unsigned int tindex)
3831{
3832 tic6x_unwind_table_edit *new_edit = (tic6x_unwind_table_edit *)
3833 xmalloc (sizeof (tic6x_unwind_table_edit));
68ffbac6 3834
fbd9ad90
PB
3835 new_edit->type = type;
3836 new_edit->linked_section = linked_section;
3837 new_edit->index = tindex;
68ffbac6 3838
fbd9ad90
PB
3839 if (tindex > 0)
3840 {
3841 new_edit->next = NULL;
3842
3843 if (*tail)
3844 (*tail)->next = new_edit;
3845
3846 (*tail) = new_edit;
3847
3848 if (!*head)
3849 (*head) = new_edit;
3850 }
3851 else
3852 {
3853 new_edit->next = *head;
3854
3855 if (!*tail)
3856 *tail = new_edit;
3857
3858 *head = new_edit;
3859 }
3860}
3861
3862static _tic6x_elf_section_data *
3863get_tic6x_elf_section_data (asection * sec)
3864{
3865 if (sec && sec->owner && is_tic6x_elf (sec->owner))
3866 return elf32_tic6x_section_data (sec);
3867 else
3868 return NULL;
3869}
3870
3871
3872/* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST must be negative. */
3873static void
3874elf32_tic6x_adjust_exidx_size (asection *exidx_sec, int adjust)
3875{
3876 asection *out_sec;
3877
3878 if (!exidx_sec->rawsize)
3879 exidx_sec->rawsize = exidx_sec->size;
3880
fd361982 3881 bfd_set_section_size (exidx_sec, exidx_sec->size + adjust);
fbd9ad90
PB
3882 out_sec = exidx_sec->output_section;
3883 /* Adjust size of output section. */
fd361982 3884 bfd_set_section_size (out_sec, out_sec->size +adjust);
fbd9ad90
PB
3885}
3886
3887/* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
3888static void
3889elf32_tic6x_insert_cantunwind_after (asection *text_sec, asection *exidx_sec)
3890{
3891 struct _tic6x_elf_section_data *exidx_data;
3892
3893 exidx_data = get_tic6x_elf_section_data (exidx_sec);
3894 elf32_tic6x_add_unwind_table_edit (
3895 &exidx_data->u.exidx.unwind_edit_list,
3896 &exidx_data->u.exidx.unwind_edit_tail,
3897 INSERT_EXIDX_CANTUNWIND_AT_END, text_sec, UINT_MAX);
3898
3899 elf32_tic6x_adjust_exidx_size (exidx_sec, 8);
3900}
3901
3902/* Scan .cx6abi.exidx tables, and create a list describing edits which
3903 should be made to those tables, such that:
68ffbac6 3904
fbd9ad90
PB
3905 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
3906 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
07d6d2b8 3907 codes which have been inlined into the index).
fbd9ad90
PB
3908
3909 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
3910
3911 The edits are applied when the tables are written
3912 (in elf32_tic6x_write_section).
3913*/
3914
3915bfd_boolean
3916elf32_tic6x_fix_exidx_coverage (asection **text_section_order,
3917 unsigned int num_text_sections,
3918 struct bfd_link_info *info,
3919 bfd_boolean merge_exidx_entries)
3920{
3921 bfd *inp;
3922 unsigned int last_second_word = 0, i;
3923 asection *last_exidx_sec = NULL;
3924 asection *last_text_sec = NULL;
3925 int last_unwind_type = -1;
3926
3927 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
3928 text sections. */
c72f2fb2 3929 for (inp = info->input_bfds; inp != NULL; inp = inp->link.next)
fbd9ad90
PB
3930 {
3931 asection *sec;
68ffbac6 3932
fbd9ad90 3933 for (sec = inp->sections; sec != NULL; sec = sec->next)
07d6d2b8 3934 {
fbd9ad90
PB
3935 struct bfd_elf_section_data *elf_sec = elf_section_data (sec);
3936 Elf_Internal_Shdr *hdr = &elf_sec->this_hdr;
68ffbac6 3937
fbd9ad90
PB
3938 if (!hdr || hdr->sh_type != SHT_C6000_UNWIND)
3939 continue;
68ffbac6 3940
fbd9ad90
PB
3941 if (elf_sec->linked_to)
3942 {
3943 Elf_Internal_Shdr *linked_hdr
07d6d2b8 3944 = &elf_section_data (elf_sec->linked_to)->this_hdr;
fbd9ad90 3945 struct _tic6x_elf_section_data *linked_sec_tic6x_data
07d6d2b8 3946 = get_tic6x_elf_section_data (linked_hdr->bfd_section);
fbd9ad90
PB
3947
3948 if (linked_sec_tic6x_data == NULL)
07d6d2b8 3949 continue;
fbd9ad90
PB
3950
3951 /* Link this .c6xabi.exidx section back from the
3952 text section it describes. */
3953 linked_sec_tic6x_data->u.text.tic6x_exidx_sec = sec;
3954 }
3955 }
3956 }
3957
3958 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
3959 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
3960 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
3961
3962 for (i = 0; i < num_text_sections; i++)
3963 {
3964 asection *sec = text_section_order[i];
3965 asection *exidx_sec;
3966 struct _tic6x_elf_section_data *tic6x_data
07d6d2b8 3967 = get_tic6x_elf_section_data (sec);
fbd9ad90
PB
3968 struct _tic6x_elf_section_data *exidx_data;
3969 bfd_byte *contents = NULL;
3970 int deleted_exidx_bytes = 0;
3971 bfd_vma j;
3972 tic6x_unwind_table_edit *unwind_edit_head = NULL;
3973 tic6x_unwind_table_edit *unwind_edit_tail = NULL;
3974 Elf_Internal_Shdr *hdr;
3975 bfd *ibfd;
3976
3977 if (tic6x_data == NULL)
07d6d2b8 3978 continue;
fbd9ad90
PB
3979
3980 exidx_sec = tic6x_data->u.text.tic6x_exidx_sec;
3981 if (exidx_sec == NULL)
3982 {
3983 /* Section has no unwind data. */
3984 if (last_unwind_type == 0 || !last_exidx_sec)
3985 continue;
3986
3987 /* Ignore zero sized sections. */
3988 if (sec->size == 0)
3989 continue;
3990
3991 elf32_tic6x_insert_cantunwind_after (last_text_sec, last_exidx_sec);
3992 last_unwind_type = 0;
3993 continue;
3994 }
3995
3996 /* Skip /DISCARD/ sections. */
3997 if (bfd_is_abs_section (exidx_sec->output_section))
3998 continue;
3999
4000 hdr = &elf_section_data (exidx_sec)->this_hdr;
4001 if (hdr->sh_type != SHT_C6000_UNWIND)
07d6d2b8 4002 continue;
68ffbac6 4003
fbd9ad90
PB
4004 exidx_data = get_tic6x_elf_section_data (exidx_sec);
4005 if (exidx_data == NULL)
07d6d2b8 4006 continue;
68ffbac6 4007
fbd9ad90 4008 ibfd = exidx_sec->owner;
68ffbac6 4009
fbd9ad90
PB
4010 if (hdr->contents != NULL)
4011 contents = hdr->contents;
4012 else if (! bfd_malloc_and_get_section (ibfd, exidx_sec, &contents))
4013 /* An error? */
4014 continue;
4015
4016 for (j = 0; j < hdr->sh_size; j += 8)
4017 {
4018 unsigned int second_word = bfd_get_32 (ibfd, contents + j + 4);
4019 int unwind_type;
4020 int elide = 0;
4021
4022 /* An EXIDX_CANTUNWIND entry. */
4023 if (second_word == 1)
4024 {
4025 if (last_unwind_type == 0)
4026 elide = 1;
4027 unwind_type = 0;
4028 }
4029 /* Inlined unwinding data. Merge if equal to previous. */
4030 else if ((second_word & 0x80000000) != 0)
4031 {
4032 if (merge_exidx_entries
4033 && last_second_word == second_word
4034 && last_unwind_type == 1)
4035 elide = 1;
4036 unwind_type = 1;
4037 last_second_word = second_word;
4038 }
4039 /* Normal table entry. In theory we could merge these too,
4040 but duplicate entries are likely to be much less common. */
4041 else
4042 unwind_type = 2;
4043
4044 if (elide)
4045 {
4046 elf32_tic6x_add_unwind_table_edit (&unwind_edit_head,
4047 &unwind_edit_tail, DELETE_EXIDX_ENTRY, NULL, j / 8);
4048
4049 deleted_exidx_bytes += 8;
4050 }
4051
4052 last_unwind_type = unwind_type;
4053 }
4054
4055 /* Free contents if we allocated it ourselves. */
4056 if (contents != hdr->contents)
07d6d2b8 4057 free (contents);
fbd9ad90
PB
4058
4059 /* Record edits to be applied later (in elf32_tic6x_write_section). */
4060 exidx_data->u.exidx.unwind_edit_list = unwind_edit_head;
4061 exidx_data->u.exidx.unwind_edit_tail = unwind_edit_tail;
68ffbac6 4062
fbd9ad90
PB
4063 if (deleted_exidx_bytes > 0)
4064 elf32_tic6x_adjust_exidx_size (exidx_sec, -deleted_exidx_bytes);
4065
4066 last_exidx_sec = exidx_sec;
4067 last_text_sec = sec;
4068 }
4069
4070 /* Add terminating CANTUNWIND entry. */
4071 if (last_exidx_sec && last_unwind_type != 0)
4072 elf32_tic6x_insert_cantunwind_after (last_text_sec, last_exidx_sec);
4073
4074 return TRUE;
4075}
4076
4077/* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified. */
4078
4079static unsigned long
4080elf32_tic6x_add_low31 (unsigned long val, bfd_vma addend)
4081{
4082 return (val & ~0x7ffffffful) | ((val + addend) & 0x7ffffffful);
4083}
4084
4085/* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
4086 relocations. OFFSET is in bytes, and will be scaled before encoding. */
4087
4088
4089static void
4090elf32_tic6x_copy_exidx_entry (bfd *output_bfd, bfd_byte *to, bfd_byte *from,
4091 bfd_vma offset)
4092{
4093 unsigned long first_word = bfd_get_32 (output_bfd, from);
4094 unsigned long second_word = bfd_get_32 (output_bfd, from + 4);
4095
4096 offset >>= 1;
4097 /* High bit of first word is supposed to be zero. */
4098 if ((first_word & 0x80000000ul) == 0)
4099 first_word = elf32_tic6x_add_low31 (first_word, offset);
68ffbac6 4100
fbd9ad90
PB
4101 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
4102 (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry. */
4103 if ((second_word != 0x1) && ((second_word & 0x80000000ul) == 0))
4104 second_word = elf32_tic6x_add_low31 (second_word, offset);
68ffbac6 4105
fbd9ad90
PB
4106 bfd_put_32 (output_bfd, first_word, to);
4107 bfd_put_32 (output_bfd, second_word, to + 4);
4108}
4109
4110/* Do the actual mangling of exception index tables. */
4111
4112static bfd_boolean
4113elf32_tic6x_write_section (bfd *output_bfd,
4114 struct bfd_link_info *link_info,
4115 asection *sec,
4116 bfd_byte *contents)
4117{
4118 _tic6x_elf_section_data *tic6x_data;
4119 struct elf32_tic6x_link_hash_table *globals
4120 = elf32_tic6x_hash_table (link_info);
4121 bfd_vma offset = sec->output_section->vma + sec->output_offset;
4122
4123 if (globals == NULL)
4124 return FALSE;
4125
4126 /* If this section has not been allocated an _tic6x_elf_section_data
4127 structure then we cannot record anything. */
4128 tic6x_data = get_tic6x_elf_section_data (sec);
4129 if (tic6x_data == NULL)
4130 return FALSE;
4131
4132 if (tic6x_data->elf.this_hdr.sh_type != SHT_C6000_UNWIND)
4133 return FALSE;
4134
4135 tic6x_unwind_table_edit *edit_node
4136 = tic6x_data->u.exidx.unwind_edit_list;
4137 /* Now, sec->size is the size of the section we will write. The original
4138 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
4139 markers) was sec->rawsize. (This isn't the case if we perform no
4140 edits, then rawsize will be zero and we should use size). */
4141 bfd_byte *edited_contents = (bfd_byte *) bfd_malloc (sec->size);
4142 unsigned int input_size = sec->rawsize ? sec->rawsize : sec->size;
4143 unsigned int in_index, out_index;
4144 bfd_vma add_to_offsets = 0;
4145
4146 for (in_index = 0, out_index = 0; in_index * 8 < input_size || edit_node;)
4147 {
4148 if (edit_node)
4149 {
4150 unsigned int edit_index = edit_node->index;
68ffbac6 4151
fbd9ad90
PB
4152 if (in_index < edit_index && in_index * 8 < input_size)
4153 {
4154 elf32_tic6x_copy_exidx_entry (output_bfd,
4155 edited_contents + out_index * 8,
4156 contents + in_index * 8, add_to_offsets);
4157 out_index++;
4158 in_index++;
4159 }
4160 else if (in_index == edit_index
4161 || (in_index * 8 >= input_size
4162 && edit_index == UINT_MAX))
4163 {
4164 switch (edit_node->type)
4165 {
4166 case DELETE_EXIDX_ENTRY:
4167 in_index++;
4168 add_to_offsets += 8;
4169 break;
68ffbac6 4170
fbd9ad90
PB
4171 case INSERT_EXIDX_CANTUNWIND_AT_END:
4172 {
4173 asection *text_sec = edit_node->linked_section;
4174 bfd_vma text_offset = text_sec->output_section->vma
4175 + text_sec->output_offset
4176 + text_sec->size;
4177 bfd_vma exidx_offset = offset + out_index * 8;
4178 unsigned long prel31_offset;
4179
4180 /* Note: this is meant to be equivalent to an
4181 R_C6000_PREL31 relocation. These synthetic
4182 EXIDX_CANTUNWIND markers are not relocated by the
4183 usual BFD method. */
4184 prel31_offset = ((text_offset - exidx_offset) >> 1)
4185 & 0x7ffffffful;
4186
4187 /* First address we can't unwind. */
4188 bfd_put_32 (output_bfd, prel31_offset,
4189 &edited_contents[out_index * 8]);
4190
4191 /* Code for EXIDX_CANTUNWIND. */
4192 bfd_put_32 (output_bfd, 0x1,
4193 &edited_contents[out_index * 8 + 4]);
4194
4195 out_index++;
4196 add_to_offsets -= 8;
4197 }
4198 break;
4199 }
68ffbac6 4200
fbd9ad90
PB
4201 edit_node = edit_node->next;
4202 }
4203 }
4204 else
4205 {
4206 /* No more edits, copy remaining entries verbatim. */
4207 elf32_tic6x_copy_exidx_entry (output_bfd,
4208 edited_contents + out_index * 8,
4209 contents + in_index * 8, add_to_offsets);
4210 out_index++;
4211 in_index++;
4212 }
4213 }
4214
4215 if (!(sec->flags & SEC_EXCLUDE) && !(sec->flags & SEC_NEVER_LOAD))
4216 bfd_set_section_contents (output_bfd, sec->output_section,
4217 edited_contents,
4218 (file_ptr) sec->output_offset, sec->size);
4219
4220 return TRUE;
4221}
4222
845b83d7
L
4223#define elf32_bed elf32_tic6x_bed
4224
6d00b590 4225#define TARGET_LITTLE_SYM tic6x_elf32_le_vec
40b36596 4226#define TARGET_LITTLE_NAME "elf32-tic6x-le"
6d00b590 4227#define TARGET_BIG_SYM tic6x_elf32_be_vec
40b36596
JM
4228#define TARGET_BIG_NAME "elf32-tic6x-be"
4229#define ELF_ARCH bfd_arch_tic6x
ae95ffa6 4230#define ELF_TARGET_ID TIC6X_ELF_DATA
40b36596 4231#define ELF_MACHINE_CODE EM_TI_C6000
ac145307 4232#define ELF_MAXPAGESIZE 0x1000
40b36596
JM
4233#define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
4234#define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
59e6276b 4235#define bfd_elf32_bfd_merge_private_bfd_data elf32_tic6x_merge_private_bfd_data
41820509 4236#define bfd_elf32_mkobject elf32_tic6x_mkobject
ac145307 4237#define bfd_elf32_bfd_link_hash_table_create elf32_tic6x_link_hash_table_create
41820509 4238#define bfd_elf32_new_section_hook elf32_tic6x_new_section_hook
04c3a755 4239#define elf_backend_stack_align 8
40b36596
JM
4240#define elf_backend_can_gc_sections 1
4241#define elf_backend_default_use_rela_p 1
4242#define elf_backend_may_use_rel_p 1
4243#define elf_backend_may_use_rela_p 1
59e6276b 4244#define elf_backend_obj_attrs_arg_type elf32_tic6x_obj_attrs_arg_type
0547accf 4245#define elf_backend_obj_attrs_handle_unknown elf32_tic6x_obj_attrs_handle_unknown
87779176 4246#define elf_backend_obj_attrs_order elf32_tic6x_obj_attrs_order
75fa6dc1 4247#define elf_backend_obj_attrs_section ".c6xabi.attributes"
59e6276b
JM
4248#define elf_backend_obj_attrs_section_type SHT_C6000_ATTRIBUTES
4249#define elf_backend_obj_attrs_vendor "c6xabi"
ac145307
BS
4250#define elf_backend_can_refcount 1
4251#define elf_backend_want_got_plt 1
4252#define elf_backend_want_dynbss 1
5474d94f 4253#define elf_backend_want_dynrelro 1
ac145307 4254#define elf_backend_plt_readonly 1
40b36596 4255#define elf_backend_rela_normal 1
ac145307 4256#define elf_backend_got_header_size 8
1bce6bd8 4257#define elf_backend_fake_sections elf32_tic6x_fake_sections
9cf0e282 4258#define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
ac145307
BS
4259#define elf_backend_create_dynamic_sections \
4260 elf32_tic6x_create_dynamic_sections
4261#define elf_backend_adjust_dynamic_symbol \
4262 elf32_tic6x_adjust_dynamic_symbol
07d6d2b8 4263#define elf_backend_check_relocs elf32_tic6x_check_relocs
ac145307
BS
4264#define elf_backend_add_symbol_hook elf32_tic6x_add_symbol_hook
4265#define elf_backend_symbol_processing elf32_tic6x_symbol_processing
4266#define elf_backend_link_output_symbol_hook \
4267 elf32_tic6x_link_output_symbol_hook
4268#define elf_backend_section_from_bfd_section \
4269 elf32_tic6x_section_from_bfd_section
40b36596 4270#define elf_backend_relocate_section elf32_tic6x_relocate_section
2a616379 4271#define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
ac145307
BS
4272#define elf_backend_finish_dynamic_symbol \
4273 elf32_tic6x_finish_dynamic_symbol
4274#define elf_backend_always_size_sections \
4275 elf32_tic6x_always_size_sections
4276#define elf_backend_size_dynamic_sections \
4277 elf32_tic6x_size_dynamic_sections
4278#define elf_backend_finish_dynamic_sections \
4279 elf32_tic6x_finish_dynamic_sections
c6a8f6e0
BS
4280#define bfd_elf32_bfd_final_link \
4281 elf32_tic6x_final_link
fbd9ad90 4282#define elf_backend_write_section elf32_tic6x_write_section
40b36596 4283#define elf_info_to_howto elf32_tic6x_info_to_howto
41820509 4284#define elf_info_to_howto_rel elf32_tic6x_info_to_howto_rel
40b36596 4285
ac145307
BS
4286#undef elf_backend_omit_section_dynsym
4287#define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
4288#define elf_backend_plt_sym_val elf32_tic6x_plt_sym_val
4289
2a616379
BS
4290#include "elf32-target.h"
4291
4292#undef elf32_bed
4293#define elf32_bed elf32_tic6x_linux_bed
4294
4295#undef TARGET_LITTLE_SYM
6d00b590 4296#define TARGET_LITTLE_SYM tic6x_elf32_linux_le_vec
2a616379
BS
4297#undef TARGET_LITTLE_NAME
4298#define TARGET_LITTLE_NAME "elf32-tic6x-linux-le"
4299#undef TARGET_BIG_SYM
6d00b590 4300#define TARGET_BIG_SYM tic6x_elf32_linux_be_vec
2a616379
BS
4301#undef TARGET_BIG_NAME
4302#define TARGET_BIG_NAME "elf32-tic6x-linux-be"
4303#undef ELF_OSABI
4304#define ELF_OSABI ELFOSABI_C6000_LINUX
4305
2a616379
BS
4306#include "elf32-target.h"
4307
4308#undef elf32_bed
4309#define elf32_bed elf32_tic6x_elf_bed
4310
4311#undef TARGET_LITTLE_SYM
6d00b590 4312#define TARGET_LITTLE_SYM tic6x_elf32_c6000_le_vec
2a616379
BS
4313#undef TARGET_LITTLE_NAME
4314#define TARGET_LITTLE_NAME "elf32-tic6x-elf-le"
4315#undef TARGET_BIG_SYM
6d00b590 4316#define TARGET_BIG_SYM tic6x_elf32_c6000_be_vec
2a616379
BS
4317#undef TARGET_BIG_NAME
4318#define TARGET_BIG_NAME "elf32-tic6x-elf-be"
4319#undef ELF_OSABI
4320#define ELF_OSABI ELFOSABI_C6000_ELFABI
4321
40b36596 4322#include "elf32-target.h"