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