bfd:
[external/binutils.git] / bfd / elf32-tic6x.c
1 /* 32-bit ELF support for TI C6X
2    Copyright 2010
3    Free Software Foundation, Inc.
4
5    This file is part of BFD, the Binary File Descriptor library.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20    MA 02110-1301, USA.  */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libbfd.h"
25 #include "libiberty.h"
26 #include "elf-bfd.h"
27 #include "elf/tic6x.h"
28 #include "elf32-tic6x.h"
29
30 struct elf32_tic6x_obj_tdata
31 {
32   struct elf_obj_tdata root;
33
34   /* Whether to use RELA relocations when generating relocations.
35      This is a per-object flag to allow the assembler to generate REL
36      relocations for use in linker testcases.  */
37   bfd_boolean use_rela_p;
38 };
39
40 #define elf32_tic6x_tdata(abfd) \
41   ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
42
43 static reloc_howto_type elf32_tic6x_howto_table[] =
44 {
45   HOWTO (R_C6000_NONE,          /* type */
46          0,                     /* rightshift */
47          0,                     /* size (0 = byte, 1 = short, 2 = long) */
48          0,                     /* bitsize */
49          FALSE,                 /* pc_relative */
50          0,                     /* bitpos */
51          complain_overflow_dont,/* complain_on_overflow */
52          bfd_elf_generic_reloc, /* special_function */
53          "R_C6000_NONE",        /* name */
54          FALSE,                 /* partial_inplace */
55          0,                     /* src_mask */
56          0,                     /* dst_mask */
57          FALSE),                /* pcrel_offset */
58   HOWTO (R_C6000_ABS32,         /* type */
59          0,                     /* rightshift */
60          2,                     /* size (0 = byte, 1 = short, 2 = long) */
61          32,                    /* bitsize */
62          FALSE,                 /* pc_relative */
63          0,                     /* bitpos */
64          complain_overflow_dont,/* complain_on_overflow */
65          bfd_elf_generic_reloc, /* special_function */
66          "R_C6000_ABS32",       /* name */
67          FALSE,                 /* partial_inplace */
68          0,                     /* src_mask */
69          0xffffffff,            /* dst_mask */
70          FALSE),                /* pcrel_offset */
71   HOWTO (R_C6000_ABS16,         /* type */
72          0,                     /* rightshift */
73          1,                     /* size (0 = byte, 1 = short, 2 = long) */
74          16,                    /* bitsize */
75          FALSE,                 /* pc_relative */
76          0,                     /* bitpos */
77          complain_overflow_bitfield,/* complain_on_overflow */
78          bfd_elf_generic_reloc, /* special_function */
79          "R_C6000_ABS16",       /* name */
80          FALSE,                 /* partial_inplace */
81          0,                     /* src_mask */
82          0x0000ffff,            /* dst_mask */
83          FALSE),                /* pcrel_offset */
84   HOWTO (R_C6000_ABS8,          /* type */
85          0,                     /* rightshift */
86          0,                     /* size (0 = byte, 1 = short, 2 = long) */
87          8,                     /* bitsize */
88          FALSE,                 /* pc_relative */
89          0,                     /* bitpos */
90          complain_overflow_bitfield,/* complain_on_overflow */
91          bfd_elf_generic_reloc, /* special_function */
92          "R_C6000_ABS8",        /* name */
93          FALSE,                 /* partial_inplace */
94          0,                     /* src_mask */
95          0x000000ff,            /* dst_mask */
96          FALSE),                /* pcrel_offset */
97   HOWTO (R_C6000_PCR_S21,       /* type */
98          2,                     /* rightshift */
99          2,                     /* size (0 = byte, 1 = short, 2 = long) */
100          21,                    /* bitsize */
101          TRUE,                  /* pc_relative */
102          7,                     /* bitpos */
103          complain_overflow_signed,/* complain_on_overflow */
104          bfd_elf_generic_reloc, /* special_function */
105          "R_C6000_PCR_S21",     /* name */
106          FALSE,                 /* partial_inplace */
107          0,                     /* src_mask */
108          0x0fffff80,            /* dst_mask */
109          TRUE),                 /* pcrel_offset */
110   HOWTO (R_C6000_PCR_S12,       /* type */
111          2,                     /* rightshift */
112          2,                     /* size (0 = byte, 1 = short, 2 = long) */
113          12,                    /* bitsize */
114          TRUE,                  /* pc_relative */
115          16,                    /* bitpos */
116          complain_overflow_signed,/* complain_on_overflow */
117          bfd_elf_generic_reloc, /* special_function */
118          "R_C6000_PCR_S12",     /* name */
119          FALSE,                 /* partial_inplace */
120          0,                     /* src_mask */
121          0x0fff0000,            /* dst_mask */
122          TRUE),                 /* pcrel_offset */
123   HOWTO (R_C6000_PCR_S10,       /* type */
124          2,                     /* rightshift */
125          2,                     /* size (0 = byte, 1 = short, 2 = long) */
126          10,                    /* bitsize */
127          TRUE,                  /* pc_relative */
128          13,                    /* bitpos */
129          complain_overflow_signed,/* complain_on_overflow */
130          bfd_elf_generic_reloc, /* special_function */
131          "R_C6000_PCR_S10",     /* name */
132          FALSE,                 /* partial_inplace */
133          0,                     /* src_mask */
134          0x007fe000,            /* dst_mask */
135          TRUE),                 /* pcrel_offset */
136   HOWTO (R_C6000_PCR_S7,        /* type */
137          2,                     /* rightshift */
138          2,                     /* size (0 = byte, 1 = short, 2 = long) */
139          7,                     /* bitsize */
140          TRUE,                  /* pc_relative */
141          16,                    /* bitpos */
142          complain_overflow_signed,/* complain_on_overflow */
143          bfd_elf_generic_reloc, /* special_function */
144          "R_C6000_PCR_S7",      /* name */
145          FALSE,                 /* partial_inplace */
146          0,                     /* src_mask */
147          0x007f0000,            /* dst_mask */
148          TRUE),                 /* pcrel_offset */
149   HOWTO (R_C6000_ABS_S16,       /* type */
150          0,                     /* rightshift */
151          2,                     /* size (0 = byte, 1 = short, 2 = long) */
152          16,                    /* bitsize */
153          FALSE,                 /* pc_relative */
154          7,                     /* bitpos */
155          complain_overflow_signed,/* complain_on_overflow */
156          bfd_elf_generic_reloc, /* special_function */
157          "R_C6000_ABS_S16",     /* name */
158          FALSE,                 /* partial_inplace */
159          0,                     /* src_mask */
160          0x007fff80,            /* dst_mask */
161          FALSE),                /* pcrel_offset */
162   HOWTO (R_C6000_ABS_L16,       /* type */
163          0,                     /* rightshift */
164          2,                     /* size (0 = byte, 1 = short, 2 = long) */
165          16,                    /* bitsize */
166          FALSE,                 /* pc_relative */
167          7,                     /* bitpos */
168          complain_overflow_dont,/* complain_on_overflow */
169          bfd_elf_generic_reloc, /* special_function */
170          "R_C6000_ABS_L16",     /* name */
171          FALSE,                 /* partial_inplace */
172          0,                     /* src_mask */
173          0x007fff80,            /* dst_mask */
174          FALSE),                /* pcrel_offset */
175   HOWTO (R_C6000_ABS_H16,       /* type */
176          16,                    /* rightshift */
177          2,                     /* size (0 = byte, 1 = short, 2 = long) */
178          16,                    /* bitsize */
179          FALSE,                 /* pc_relative */
180          7,                     /* bitpos */
181          complain_overflow_dont,/* complain_on_overflow */
182          bfd_elf_generic_reloc, /* special_function */
183          "R_C6000_ABS_H16",     /* name */
184          FALSE,                 /* partial_inplace */
185          0,                     /* src_mask */
186          0x007fff80,            /* dst_mask */
187          FALSE),                /* pcrel_offset */
188   HOWTO (R_C6000_SBR_U15_B,     /* type */
189          0,                     /* rightshift */
190          2,                     /* size (0 = byte, 1 = short, 2 = long) */
191          15,                    /* bitsize */
192          FALSE,                 /* pc_relative */
193          8,                     /* bitpos */
194          complain_overflow_unsigned,/* complain_on_overflow */
195          bfd_elf_generic_reloc, /* special_function */
196          "R_C6000_SBR_U15_B",   /* name */
197          FALSE,                 /* partial_inplace */
198          0,                     /* src_mask */
199          0x007fff00,            /* dst_mask */
200          FALSE),                /* pcrel_offset */
201   HOWTO (R_C6000_SBR_U15_H,     /* type */
202          1,                     /* rightshift */
203          2,                     /* size (0 = byte, 1 = short, 2 = long) */
204          15,                    /* bitsize */
205          FALSE,                 /* pc_relative */
206          8,                     /* bitpos */
207          complain_overflow_unsigned,/* complain_on_overflow */
208          bfd_elf_generic_reloc, /* special_function */
209          "R_C6000_SBR_U15_H",   /* name */
210          FALSE,                 /* partial_inplace */
211          0,                     /* src_mask */
212          0x007fff00,            /* dst_mask */
213          FALSE),                /* pcrel_offset */
214   HOWTO (R_C6000_SBR_U15_W,     /* type */
215          2,                     /* rightshift */
216          2,                     /* size (0 = byte, 1 = short, 2 = long) */
217          15,                    /* bitsize */
218          FALSE,                 /* pc_relative */
219          8,                     /* bitpos */
220          complain_overflow_unsigned,/* complain_on_overflow */
221          bfd_elf_generic_reloc, /* special_function */
222          "R_C6000_SBR_U15_W",   /* name */
223          FALSE,                 /* partial_inplace */
224          0,                     /* src_mask */
225          0x007fff00,            /* dst_mask */
226          FALSE),                /* pcrel_offset */
227   HOWTO (R_C6000_SBR_S16,       /* type */
228          0,                     /* rightshift */
229          2,                     /* size (0 = byte, 1 = short, 2 = long) */
230          16,                    /* bitsize */
231          FALSE,                 /* pc_relative */
232          7,                     /* bitpos */
233          complain_overflow_signed,/* complain_on_overflow */
234          bfd_elf_generic_reloc, /* special_function */
235          "R_C6000_SBR_S16",     /* name */
236          FALSE,                 /* partial_inplace */
237          0,                     /* src_mask */
238          0x007fff80,            /* dst_mask */
239          FALSE),                /* pcrel_offset */
240   HOWTO (R_C6000_SBR_L16_B,     /* type */
241          0,                     /* rightshift */
242          2,                     /* size (0 = byte, 1 = short, 2 = long) */
243          16,                    /* bitsize */
244          FALSE,                 /* pc_relative */
245          7,                     /* bitpos */
246          complain_overflow_dont,/* complain_on_overflow */
247          bfd_elf_generic_reloc, /* special_function */
248          "R_C6000_SBR_L16_B",   /* name */
249          FALSE,                 /* partial_inplace */
250          0,                     /* src_mask */
251          0x007fff80,            /* dst_mask */
252          FALSE),                /* pcrel_offset */
253   HOWTO (R_C6000_SBR_L16_H,     /* type */
254          1,                     /* rightshift */
255          2,                     /* size (0 = byte, 1 = short, 2 = long) */
256          16,                    /* bitsize */
257          FALSE,                 /* pc_relative */
258          7,                     /* bitpos */
259          complain_overflow_dont,/* complain_on_overflow */
260          bfd_elf_generic_reloc, /* special_function */
261          "R_C6000_SBR_L16_H",   /* name */
262          FALSE,                 /* partial_inplace */
263          0,                     /* src_mask */
264          0x007fff80,            /* dst_mask */
265          FALSE),                /* pcrel_offset */
266   HOWTO (R_C6000_SBR_L16_W,     /* type */
267          2,                     /* rightshift */
268          2,                     /* size (0 = byte, 1 = short, 2 = long) */
269          16,                    /* bitsize */
270          FALSE,                 /* pc_relative */
271          7,                     /* bitpos */
272          complain_overflow_dont,/* complain_on_overflow */
273          bfd_elf_generic_reloc, /* special_function */
274          "R_C6000_SBR_L16_W",   /* name */
275          FALSE,                 /* partial_inplace */
276          0,                     /* src_mask */
277          0x007fff80,            /* dst_mask */
278          FALSE),                /* pcrel_offset */
279   HOWTO (R_C6000_SBR_H16_B,     /* type */
280          16,                    /* rightshift */
281          2,                     /* size (0 = byte, 1 = short, 2 = long) */
282          16,                    /* bitsize */
283          FALSE,                 /* pc_relative */
284          7,                     /* bitpos */
285          complain_overflow_dont,/* complain_on_overflow */
286          bfd_elf_generic_reloc, /* special_function */
287          "R_C6000_SBR_H16_B",   /* name */
288          FALSE,                 /* partial_inplace */
289          0,                     /* src_mask */
290          0x007fff80,            /* dst_mask */
291          FALSE),                /* pcrel_offset */
292   HOWTO (R_C6000_SBR_H16_H,     /* type */
293          17,                    /* rightshift */
294          2,                     /* size (0 = byte, 1 = short, 2 = long) */
295          16,                    /* bitsize */
296          FALSE,                 /* pc_relative */
297          7,                     /* bitpos */
298          complain_overflow_dont,/* complain_on_overflow */
299          bfd_elf_generic_reloc, /* special_function */
300          "R_C6000_SBR_H16_H",   /* name */
301          FALSE,                 /* partial_inplace */
302          0,                     /* src_mask */
303          0x007fff80,            /* dst_mask */
304          FALSE),                /* pcrel_offset */
305   HOWTO (R_C6000_SBR_H16_W,     /* type */
306          18,                    /* rightshift */
307          2,                     /* size (0 = byte, 1 = short, 2 = long) */
308          16,                    /* bitsize */
309          FALSE,                 /* pc_relative */
310          7,                     /* bitpos */
311          complain_overflow_dont,/* complain_on_overflow */
312          bfd_elf_generic_reloc, /* special_function */
313          "R_C6000_SBR_H16_W",   /* name */
314          FALSE,                 /* partial_inplace */
315          0,                     /* src_mask */
316          0x007fff80,            /* dst_mask */
317          FALSE),                /* pcrel_offset */
318   HOWTO (R_C6000_SBR_GOT_U15_W, /* type */
319          2,                     /* rightshift */
320          2,                     /* size (0 = byte, 1 = short, 2 = long) */
321          15,                    /* bitsize */
322          FALSE,                 /* pc_relative */
323          8,                     /* bitpos */
324          complain_overflow_unsigned,/* complain_on_overflow */
325          bfd_elf_generic_reloc, /* special_function */
326          "R_C6000_SBR_GOT_U15_W",/* name */
327          FALSE,                 /* partial_inplace */
328          0,                     /* src_mask */
329          0x007fff00,            /* dst_mask */
330          FALSE),                /* pcrel_offset */
331   HOWTO (R_C6000_SBR_GOT_L16_W, /* type */
332          2,                     /* rightshift */
333          2,                     /* size (0 = byte, 1 = short, 2 = long) */
334          16,                    /* bitsize */
335          FALSE,                 /* pc_relative */
336          7,                     /* bitpos */
337          complain_overflow_dont,/* complain_on_overflow */
338          bfd_elf_generic_reloc, /* special_function */
339          "R_C6000_SBR_GOT_L16_W",/* name */
340          FALSE,                 /* partial_inplace */
341          0,                     /* src_mask */
342          0x007fff80,            /* dst_mask */
343          FALSE),                /* pcrel_offset */
344   HOWTO (R_C6000_SBR_GOT_H16_W, /* type */
345          18,                    /* rightshift */
346          2,                     /* size (0 = byte, 1 = short, 2 = long) */
347          16,                    /* bitsize */
348          FALSE,                 /* pc_relative */
349          7,                     /* bitpos */
350          complain_overflow_dont,/* complain_on_overflow */
351          bfd_elf_generic_reloc, /* special_function */
352          "R_C6000_SBR_GOT_H16_W",/* name */
353          FALSE,                 /* partial_inplace */
354          0,                     /* src_mask */
355          0x007fff80,            /* dst_mask */
356          FALSE),                /* pcrel_offset */
357   HOWTO (R_C6000_DSBT_INDEX,    /* type */
358          0,                     /* rightshift */
359          2,                     /* size (0 = byte, 1 = short, 2 = long) */
360          15,                    /* bitsize */
361          FALSE,                 /* pc_relative */
362          8,                     /* bitpos */
363          complain_overflow_unsigned,/* complain_on_overflow */
364          bfd_elf_generic_reloc, /* special_function */
365          "R_C6000_DSBT_INDEX",  /* name */
366          FALSE,                 /* partial_inplace */
367          0,                     /* src_mask */
368          0x007fff00,            /* dst_mask */
369          FALSE),                /* pcrel_offset */
370   HOWTO (R_C6000_PREL31,        /* type */
371          1,                     /* rightshift */
372          2,                     /* size (0 = byte, 1 = short, 2 = long) */
373          31,                    /* bitsize */
374          FALSE,                 /* pc_relative */
375          0,                     /* bitpos */
376          complain_overflow_dont,/* complain_on_overflow */
377          bfd_elf_generic_reloc, /* special_function */
378          "R_C6000_PREL31",      /* name */
379          FALSE,                 /* partial_inplace */
380          0,                     /* src_mask */
381          0x7fffffff,            /* dst_mask */
382          FALSE),                /* pcrel_offset */
383   HOWTO (R_C6000_COPY,          /* type */
384          0,                     /* rightshift */
385          2,                     /* size (0 = byte, 1 = short, 2 = long) */
386          32,                    /* bitsize */
387          FALSE,                 /* pc_relative */
388          0,                     /* bitpos */
389          complain_overflow_dont,/* complain_on_overflow */
390          bfd_elf_generic_reloc, /* special_function */
391          "R_C6000_COPY",        /* name */
392          FALSE,                 /* partial_inplace */
393          0,                     /* src_mask */
394          0xffffffff,            /* dst_mask */
395          FALSE),                /* pcrel_offset */
396   EMPTY_HOWTO (27),
397   EMPTY_HOWTO (28),
398   EMPTY_HOWTO (29),
399   EMPTY_HOWTO (30),
400   EMPTY_HOWTO (31),
401   EMPTY_HOWTO (32),
402   EMPTY_HOWTO (33),
403   EMPTY_HOWTO (34),
404   EMPTY_HOWTO (35),
405   EMPTY_HOWTO (36),
406   EMPTY_HOWTO (37),
407   EMPTY_HOWTO (38),
408   EMPTY_HOWTO (39),
409   EMPTY_HOWTO (40),
410   EMPTY_HOWTO (41),
411   EMPTY_HOWTO (42),
412   EMPTY_HOWTO (43),
413   EMPTY_HOWTO (44),
414   EMPTY_HOWTO (45),
415   EMPTY_HOWTO (46),
416   EMPTY_HOWTO (47),
417   EMPTY_HOWTO (48),
418   EMPTY_HOWTO (49),
419   EMPTY_HOWTO (50),
420   EMPTY_HOWTO (51),
421   EMPTY_HOWTO (52),
422   EMPTY_HOWTO (53),
423   EMPTY_HOWTO (54),
424   EMPTY_HOWTO (55),
425   EMPTY_HOWTO (56),
426   EMPTY_HOWTO (57),
427   EMPTY_HOWTO (58),
428   EMPTY_HOWTO (59),
429   EMPTY_HOWTO (60),
430   EMPTY_HOWTO (61),
431   EMPTY_HOWTO (62),
432   EMPTY_HOWTO (63),
433   EMPTY_HOWTO (64),
434   EMPTY_HOWTO (65),
435   EMPTY_HOWTO (66),
436   EMPTY_HOWTO (67),
437   EMPTY_HOWTO (68),
438   EMPTY_HOWTO (69),
439   EMPTY_HOWTO (70),
440   EMPTY_HOWTO (71),
441   EMPTY_HOWTO (72),
442   EMPTY_HOWTO (73),
443   EMPTY_HOWTO (74),
444   EMPTY_HOWTO (75),
445   EMPTY_HOWTO (76),
446   EMPTY_HOWTO (77),
447   EMPTY_HOWTO (78),
448   EMPTY_HOWTO (79),
449   EMPTY_HOWTO (80),
450   EMPTY_HOWTO (81),
451   EMPTY_HOWTO (82),
452   EMPTY_HOWTO (83),
453   EMPTY_HOWTO (84),
454   EMPTY_HOWTO (85),
455   EMPTY_HOWTO (86),
456   EMPTY_HOWTO (87),
457   EMPTY_HOWTO (88),
458   EMPTY_HOWTO (89),
459   EMPTY_HOWTO (90),
460   EMPTY_HOWTO (91),
461   EMPTY_HOWTO (92),
462   EMPTY_HOWTO (93),
463   EMPTY_HOWTO (94),
464   EMPTY_HOWTO (95),
465   EMPTY_HOWTO (96),
466   EMPTY_HOWTO (97),
467   EMPTY_HOWTO (98),
468   EMPTY_HOWTO (99),
469   EMPTY_HOWTO (100),
470   EMPTY_HOWTO (101),
471   EMPTY_HOWTO (102),
472   EMPTY_HOWTO (103),
473   EMPTY_HOWTO (104),
474   EMPTY_HOWTO (105),
475   EMPTY_HOWTO (106),
476   EMPTY_HOWTO (107),
477   EMPTY_HOWTO (108),
478   EMPTY_HOWTO (109),
479   EMPTY_HOWTO (110),
480   EMPTY_HOWTO (111),
481   EMPTY_HOWTO (112),
482   EMPTY_HOWTO (113),
483   EMPTY_HOWTO (114),
484   EMPTY_HOWTO (115),
485   EMPTY_HOWTO (116),
486   EMPTY_HOWTO (117),
487   EMPTY_HOWTO (118),
488   EMPTY_HOWTO (119),
489   EMPTY_HOWTO (120),
490   EMPTY_HOWTO (121),
491   EMPTY_HOWTO (122),
492   EMPTY_HOWTO (123),
493   EMPTY_HOWTO (124),
494   EMPTY_HOWTO (125),
495   EMPTY_HOWTO (126),
496   EMPTY_HOWTO (127),
497   EMPTY_HOWTO (128),
498   EMPTY_HOWTO (129),
499   EMPTY_HOWTO (130),
500   EMPTY_HOWTO (131),
501   EMPTY_HOWTO (132),
502   EMPTY_HOWTO (133),
503   EMPTY_HOWTO (134),
504   EMPTY_HOWTO (135),
505   EMPTY_HOWTO (136),
506   EMPTY_HOWTO (137),
507   EMPTY_HOWTO (138),
508   EMPTY_HOWTO (139),
509   EMPTY_HOWTO (140),
510   EMPTY_HOWTO (141),
511   EMPTY_HOWTO (142),
512   EMPTY_HOWTO (143),
513   EMPTY_HOWTO (144),
514   EMPTY_HOWTO (145),
515   EMPTY_HOWTO (146),
516   EMPTY_HOWTO (147),
517   EMPTY_HOWTO (148),
518   EMPTY_HOWTO (149),
519   EMPTY_HOWTO (150),
520   EMPTY_HOWTO (151),
521   EMPTY_HOWTO (152),
522   EMPTY_HOWTO (153),
523   EMPTY_HOWTO (154),
524   EMPTY_HOWTO (155),
525   EMPTY_HOWTO (156),
526   EMPTY_HOWTO (157),
527   EMPTY_HOWTO (158),
528   EMPTY_HOWTO (159),
529   EMPTY_HOWTO (160),
530   EMPTY_HOWTO (161),
531   EMPTY_HOWTO (162),
532   EMPTY_HOWTO (163),
533   EMPTY_HOWTO (164),
534   EMPTY_HOWTO (165),
535   EMPTY_HOWTO (166),
536   EMPTY_HOWTO (167),
537   EMPTY_HOWTO (168),
538   EMPTY_HOWTO (169),
539   EMPTY_HOWTO (170),
540   EMPTY_HOWTO (171),
541   EMPTY_HOWTO (172),
542   EMPTY_HOWTO (173),
543   EMPTY_HOWTO (174),
544   EMPTY_HOWTO (175),
545   EMPTY_HOWTO (176),
546   EMPTY_HOWTO (177),
547   EMPTY_HOWTO (178),
548   EMPTY_HOWTO (179),
549   EMPTY_HOWTO (180),
550   EMPTY_HOWTO (181),
551   EMPTY_HOWTO (182),
552   EMPTY_HOWTO (183),
553   EMPTY_HOWTO (184),
554   EMPTY_HOWTO (185),
555   EMPTY_HOWTO (186),
556   EMPTY_HOWTO (187),
557   EMPTY_HOWTO (188),
558   EMPTY_HOWTO (189),
559   EMPTY_HOWTO (190),
560   EMPTY_HOWTO (191),
561   EMPTY_HOWTO (192),
562   EMPTY_HOWTO (193),
563   EMPTY_HOWTO (194),
564   EMPTY_HOWTO (195),
565   EMPTY_HOWTO (196),
566   EMPTY_HOWTO (197),
567   EMPTY_HOWTO (198),
568   EMPTY_HOWTO (199),
569   EMPTY_HOWTO (200),
570   EMPTY_HOWTO (201),
571   EMPTY_HOWTO (202),
572   EMPTY_HOWTO (203),
573   EMPTY_HOWTO (204),
574   EMPTY_HOWTO (205),
575   EMPTY_HOWTO (206),
576   EMPTY_HOWTO (207),
577   EMPTY_HOWTO (208),
578   EMPTY_HOWTO (209),
579   EMPTY_HOWTO (210),
580   EMPTY_HOWTO (211),
581   EMPTY_HOWTO (212),
582   EMPTY_HOWTO (213),
583   EMPTY_HOWTO (214),
584   EMPTY_HOWTO (215),
585   EMPTY_HOWTO (216),
586   EMPTY_HOWTO (217),
587   EMPTY_HOWTO (218),
588   EMPTY_HOWTO (219),
589   EMPTY_HOWTO (220),
590   EMPTY_HOWTO (221),
591   EMPTY_HOWTO (222),
592   EMPTY_HOWTO (223),
593   EMPTY_HOWTO (224),
594   EMPTY_HOWTO (225),
595   EMPTY_HOWTO (226),
596   EMPTY_HOWTO (227),
597   EMPTY_HOWTO (228),
598   EMPTY_HOWTO (229),
599   EMPTY_HOWTO (230),
600   EMPTY_HOWTO (231),
601   EMPTY_HOWTO (232),
602   EMPTY_HOWTO (233),
603   EMPTY_HOWTO (234),
604   EMPTY_HOWTO (235),
605   EMPTY_HOWTO (236),
606   EMPTY_HOWTO (237),
607   EMPTY_HOWTO (238),
608   EMPTY_HOWTO (239),
609   EMPTY_HOWTO (240),
610   EMPTY_HOWTO (241),
611   EMPTY_HOWTO (242),
612   EMPTY_HOWTO (243),
613   EMPTY_HOWTO (244),
614   EMPTY_HOWTO (245),
615   EMPTY_HOWTO (246),
616   EMPTY_HOWTO (247),
617   EMPTY_HOWTO (248),
618   EMPTY_HOWTO (249),
619   EMPTY_HOWTO (250),
620   EMPTY_HOWTO (251),
621   EMPTY_HOWTO (252),
622   HOWTO (R_C6000_ALIGN,         /* type */
623          0,                     /* rightshift */
624          0,                     /* size (0 = byte, 1 = short, 2 = long) */
625          0,                     /* bitsize */
626          FALSE,                 /* pc_relative */
627          0,                     /* bitpos */
628          complain_overflow_dont,/* complain_on_overflow */
629          bfd_elf_generic_reloc, /* special_function */
630          "R_C6000_ALIGN",       /* name */
631          FALSE,                 /* partial_inplace */
632          0,                     /* src_mask */
633          0,                     /* dst_mask */
634          FALSE),                /* pcrel_offset */
635   HOWTO (R_C6000_FPHEAD,        /* type */
636          0,                     /* rightshift */
637          0,                     /* size (0 = byte, 1 = short, 2 = long) */
638          0,                     /* bitsize */
639          FALSE,                 /* pc_relative */
640          0,                     /* bitpos */
641          complain_overflow_dont,/* complain_on_overflow */
642          bfd_elf_generic_reloc, /* special_function */
643          "R_C6000_FPHEAD",      /* name */
644          FALSE,                 /* partial_inplace */
645          0,                     /* src_mask */
646          0,                     /* dst_mask */
647          FALSE),                /* pcrel_offset */
648   HOWTO (R_C6000_NOCMP,         /* type */
649          0,                     /* rightshift */
650          0,                     /* size (0 = byte, 1 = short, 2 = long) */
651          0,                     /* bitsize */
652          FALSE,                 /* pc_relative */
653          0,                     /* bitpos */
654          complain_overflow_dont,/* complain_on_overflow */
655          bfd_elf_generic_reloc, /* special_function */
656          "R_C6000_NOCMP",       /* name */
657          FALSE,                 /* partial_inplace */
658          0,                     /* src_mask */
659          0,                     /* dst_mask */
660          FALSE)                 /* pcrel_offset */
661 };
662
663 static reloc_howto_type elf32_tic6x_howto_table_rel[] =
664 {
665   HOWTO (R_C6000_NONE,          /* type */
666          0,                     /* rightshift */
667          0,                     /* size (0 = byte, 1 = short, 2 = long) */
668          0,                     /* bitsize */
669          FALSE,                 /* pc_relative */
670          0,                     /* bitpos */
671          complain_overflow_dont,/* complain_on_overflow */
672          bfd_elf_generic_reloc, /* special_function */
673          "R_C6000_NONE",        /* name */
674          TRUE,                  /* partial_inplace */
675          0,                     /* src_mask */
676          0,                     /* dst_mask */
677          FALSE),                /* pcrel_offset */
678   HOWTO (R_C6000_ABS32,         /* type */
679          0,                     /* rightshift */
680          2,                     /* size (0 = byte, 1 = short, 2 = long) */
681          32,                    /* bitsize */
682          FALSE,                 /* pc_relative */
683          0,                     /* bitpos */
684          complain_overflow_dont,/* complain_on_overflow */
685          bfd_elf_generic_reloc, /* special_function */
686          "R_C6000_ABS32",       /* name */
687          TRUE,                  /* partial_inplace */
688          0xffffffff,            /* src_mask */
689          0xffffffff,            /* dst_mask */
690          FALSE),                /* pcrel_offset */
691   HOWTO (R_C6000_ABS16,         /* type */
692          0,                     /* rightshift */
693          1,                     /* size (0 = byte, 1 = short, 2 = long) */
694          16,                    /* bitsize */
695          FALSE,                 /* pc_relative */
696          0,                     /* bitpos */
697          complain_overflow_bitfield,/* complain_on_overflow */
698          bfd_elf_generic_reloc, /* special_function */
699          "R_C6000_ABS16",       /* name */
700          TRUE,                  /* partial_inplace */
701          0x0000ffff,            /* src_mask */
702          0x0000ffff,            /* dst_mask */
703          FALSE),                /* pcrel_offset */
704   HOWTO (R_C6000_ABS8,          /* type */
705          0,                     /* rightshift */
706          0,                     /* size (0 = byte, 1 = short, 2 = long) */
707          8,                     /* bitsize */
708          FALSE,                 /* pc_relative */
709          0,                     /* bitpos */
710          complain_overflow_bitfield,/* complain_on_overflow */
711          bfd_elf_generic_reloc, /* special_function */
712          "R_C6000_ABS8",        /* name */
713          TRUE,                  /* partial_inplace */
714          0x000000ff,            /* src_mask */
715          0x000000ff,            /* dst_mask */
716          FALSE),                /* pcrel_offset */
717   HOWTO (R_C6000_PCR_S21,       /* type */
718          2,                     /* rightshift */
719          2,                     /* size (0 = byte, 1 = short, 2 = long) */
720          21,                    /* bitsize */
721          TRUE,                  /* pc_relative */
722          7,                     /* bitpos */
723          complain_overflow_signed,/* complain_on_overflow */
724          bfd_elf_generic_reloc, /* special_function */
725          "R_C6000_PCR_S21",     /* name */
726          TRUE,                  /* partial_inplace */
727          0x0fffff80,            /* src_mask */
728          0x0fffff80,            /* dst_mask */
729          TRUE),                 /* pcrel_offset */
730   HOWTO (R_C6000_PCR_S12,       /* type */
731          2,                     /* rightshift */
732          2,                     /* size (0 = byte, 1 = short, 2 = long) */
733          12,                    /* bitsize */
734          TRUE,                  /* pc_relative */
735          16,                    /* bitpos */
736          complain_overflow_signed,/* complain_on_overflow */
737          bfd_elf_generic_reloc, /* special_function */
738          "R_C6000_PCR_S12",     /* name */
739          TRUE,                  /* partial_inplace */
740          0x0fff0000,            /* src_mask */
741          0x0fff0000,            /* dst_mask */
742          TRUE),                 /* pcrel_offset */
743   HOWTO (R_C6000_PCR_S10,       /* type */
744          2,                     /* rightshift */
745          2,                     /* size (0 = byte, 1 = short, 2 = long) */
746          10,                    /* bitsize */
747          TRUE,                  /* pc_relative */
748          13,                    /* bitpos */
749          complain_overflow_signed,/* complain_on_overflow */
750          bfd_elf_generic_reloc, /* special_function */
751          "R_C6000_PCR_S10",     /* name */
752          TRUE,                  /* partial_inplace */
753          0x007fe000,            /* src_mask */
754          0x007fe000,            /* dst_mask */
755          TRUE),                 /* pcrel_offset */
756   HOWTO (R_C6000_PCR_S7,        /* type */
757          2,                     /* rightshift */
758          2,                     /* size (0 = byte, 1 = short, 2 = long) */
759          7,                     /* bitsize */
760          TRUE,                  /* pc_relative */
761          16,                    /* bitpos */
762          complain_overflow_signed,/* complain_on_overflow */
763          bfd_elf_generic_reloc, /* special_function */
764          "R_C6000_PCR_S7",      /* name */
765          TRUE,                  /* partial_inplace */
766          0x007f0000,            /* src_mask */
767          0x007f0000,            /* dst_mask */
768          TRUE),                 /* pcrel_offset */
769   HOWTO (R_C6000_ABS_S16,       /* type */
770          0,                     /* rightshift */
771          2,                     /* size (0 = byte, 1 = short, 2 = long) */
772          16,                    /* bitsize */
773          FALSE,                 /* pc_relative */
774          7,                     /* bitpos */
775          complain_overflow_signed,/* complain_on_overflow */
776          bfd_elf_generic_reloc, /* special_function */
777          "R_C6000_ABS_S16",     /* name */
778          TRUE,                  /* partial_inplace */
779          0x007fff80,            /* src_mask */
780          0x007fff80,            /* dst_mask */
781          FALSE),                /* pcrel_offset */
782   HOWTO (R_C6000_ABS_L16,       /* type */
783          0,                     /* rightshift */
784          2,                     /* size (0 = byte, 1 = short, 2 = long) */
785          16,                    /* bitsize */
786          FALSE,                 /* pc_relative */
787          7,                     /* bitpos */
788          complain_overflow_dont,/* complain_on_overflow */
789          bfd_elf_generic_reloc, /* special_function */
790          "R_C6000_ABS_L16",     /* name */
791          TRUE,                  /* partial_inplace */
792          0x007fff80,            /* src_mask */
793          0x007fff80,            /* dst_mask */
794          FALSE),                /* pcrel_offset */
795   EMPTY_HOWTO (R_C6000_ABS_H16),
796   HOWTO (R_C6000_SBR_U15_B,     /* type */
797          0,                     /* rightshift */
798          2,                     /* size (0 = byte, 1 = short, 2 = long) */
799          15,                    /* bitsize */
800          FALSE,                 /* pc_relative */
801          8,                     /* bitpos */
802          complain_overflow_unsigned,/* complain_on_overflow */
803          bfd_elf_generic_reloc, /* special_function */
804          "R_C6000_SBR_U15_B",   /* name */
805          TRUE,                  /* partial_inplace */
806          0x007fff00,            /* src_mask */
807          0x007fff00,            /* dst_mask */
808          FALSE),                /* pcrel_offset */
809   HOWTO (R_C6000_SBR_U15_H,     /* type */
810          1,                     /* rightshift */
811          2,                     /* size (0 = byte, 1 = short, 2 = long) */
812          15,                    /* bitsize */
813          FALSE,                 /* pc_relative */
814          8,                     /* bitpos */
815          complain_overflow_unsigned,/* complain_on_overflow */
816          bfd_elf_generic_reloc, /* special_function */
817          "R_C6000_SBR_U15_H",   /* name */
818          TRUE,                  /* partial_inplace */
819          0x007fff00,            /* src_mask */
820          0x007fff00,            /* dst_mask */
821          FALSE),                /* pcrel_offset */
822   HOWTO (R_C6000_SBR_U15_W,     /* type */
823          2,                     /* rightshift */
824          2,                     /* size (0 = byte, 1 = short, 2 = long) */
825          15,                    /* bitsize */
826          FALSE,                 /* pc_relative */
827          8,                     /* bitpos */
828          complain_overflow_unsigned,/* complain_on_overflow */
829          bfd_elf_generic_reloc, /* special_function */
830          "R_C6000_SBR_U15_W",   /* name */
831          TRUE,                  /* partial_inplace */
832          0x007fff00,            /* src_mask */
833          0x007fff00,            /* dst_mask */
834          FALSE),                /* pcrel_offset */
835   HOWTO (R_C6000_SBR_S16,       /* type */
836          0,                     /* rightshift */
837          2,                     /* size (0 = byte, 1 = short, 2 = long) */
838          16,                    /* bitsize */
839          FALSE,                 /* pc_relative */
840          7,                     /* bitpos */
841          complain_overflow_signed,/* complain_on_overflow */
842          bfd_elf_generic_reloc, /* special_function */
843          "R_C6000_SBR_S16",     /* name */
844          TRUE,                  /* partial_inplace */
845          0x007fff80,            /* src_mask */
846          0x007fff80,            /* dst_mask */
847          FALSE),                /* pcrel_offset */
848   HOWTO (R_C6000_SBR_L16_B,     /* type */
849          0,                     /* rightshift */
850          2,                     /* size (0 = byte, 1 = short, 2 = long) */
851          16,                    /* bitsize */
852          FALSE,                 /* pc_relative */
853          7,                     /* bitpos */
854          complain_overflow_dont,/* complain_on_overflow */
855          bfd_elf_generic_reloc, /* special_function */
856          "R_C6000_SBR_L16_B",   /* name */
857          TRUE,                  /* partial_inplace */
858          0x007fff80,            /* src_mask */
859          0x007fff80,            /* dst_mask */
860          FALSE),                /* pcrel_offset */
861   HOWTO (R_C6000_SBR_L16_H,     /* type */
862          1,                     /* rightshift */
863          2,                     /* size (0 = byte, 1 = short, 2 = long) */
864          16,                    /* bitsize */
865          FALSE,                 /* pc_relative */
866          7,                     /* bitpos */
867          complain_overflow_dont,/* complain_on_overflow */
868          bfd_elf_generic_reloc, /* special_function */
869          "R_C6000_SBR_L16_H",   /* name */
870          TRUE,                  /* partial_inplace */
871          0x007fff80,            /* src_mask */
872          0x007fff80,            /* dst_mask */
873          FALSE),                /* pcrel_offset */
874   HOWTO (R_C6000_SBR_L16_W,     /* type */
875          2,                     /* rightshift */
876          2,                     /* size (0 = byte, 1 = short, 2 = long) */
877          16,                    /* bitsize */
878          FALSE,                 /* pc_relative */
879          7,                     /* bitpos */
880          complain_overflow_dont,/* complain_on_overflow */
881          bfd_elf_generic_reloc, /* special_function */
882          "R_C6000_SBR_L16_W",   /* name */
883          TRUE,                  /* partial_inplace */
884          0x007fff80,            /* src_mask */
885          0x007fff80,            /* dst_mask */
886          FALSE),                /* pcrel_offset */
887   EMPTY_HOWTO (R_C6000_SBR_H16_B),
888   EMPTY_HOWTO (R_C6000_SBR_H16_H),
889   EMPTY_HOWTO (R_C6000_SBR_H16_W),
890   HOWTO (R_C6000_SBR_GOT_U15_W, /* type */
891          2,                     /* rightshift */
892          2,                     /* size (0 = byte, 1 = short, 2 = long) */
893          15,                    /* bitsize */
894          FALSE,                 /* pc_relative */
895          8,                     /* bitpos */
896          complain_overflow_unsigned,/* complain_on_overflow */
897          bfd_elf_generic_reloc, /* special_function */
898          "R_C6000_SBR_GOT_U15_W",/* name */
899          TRUE,                  /* partial_inplace */
900          0x007fff00,            /* src_mask */
901          0x007fff00,            /* dst_mask */
902          FALSE),                /* pcrel_offset */
903   HOWTO (R_C6000_SBR_GOT_L16_W, /* type */
904          2,                     /* rightshift */
905          2,                     /* size (0 = byte, 1 = short, 2 = long) */
906          16,                    /* bitsize */
907          FALSE,                 /* pc_relative */
908          7,                     /* bitpos */
909          complain_overflow_dont,/* complain_on_overflow */
910          bfd_elf_generic_reloc, /* special_function */
911          "R_C6000_SBR_GOT_L16_W",/* name */
912          TRUE,                  /* partial_inplace */
913          0x007fff80,            /* src_mask */
914          0x007fff80,            /* dst_mask */
915          FALSE),                /* pcrel_offset */
916   EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W),
917   HOWTO (R_C6000_DSBT_INDEX,    /* type */
918          0,                     /* rightshift */
919          2,                     /* size (0 = byte, 1 = short, 2 = long) */
920          15,                    /* bitsize */
921          FALSE,                 /* pc_relative */
922          8,                     /* bitpos */
923          complain_overflow_unsigned,/* complain_on_overflow */
924          bfd_elf_generic_reloc, /* special_function */
925          "R_C6000_DSBT_INDEX",  /* name */
926          TRUE,                  /* partial_inplace */
927          0,                     /* src_mask */
928          0x007fff00,            /* dst_mask */
929          FALSE),                /* pcrel_offset */
930   HOWTO (R_C6000_PREL31,        /* type */
931          1,                     /* rightshift */
932          2,                     /* size (0 = byte, 1 = short, 2 = long) */
933          31,                    /* bitsize */
934          FALSE,                 /* pc_relative */
935          0,                     /* bitpos */
936          complain_overflow_dont,/* complain_on_overflow */
937          bfd_elf_generic_reloc, /* special_function */
938          "R_C6000_PREL31",      /* name */
939          TRUE,                  /* partial_inplace */
940          0,                     /* src_mask */
941          0x7fffffff,            /* dst_mask */
942          FALSE),                /* pcrel_offset */
943   HOWTO (R_C6000_COPY,          /* type */
944          0,                     /* rightshift */
945          2,                     /* size (0 = byte, 1 = short, 2 = long) */
946          32,                    /* bitsize */
947          FALSE,                 /* pc_relative */
948          0,                     /* bitpos */
949          complain_overflow_dont,/* complain_on_overflow */
950          bfd_elf_generic_reloc, /* special_function */
951          "R_C6000_COPY",        /* name */
952          TRUE,                  /* partial_inplace */
953          0,                     /* src_mask */
954          0xffffffff,            /* dst_mask */
955          FALSE),                /* pcrel_offset */
956   EMPTY_HOWTO (27),
957   EMPTY_HOWTO (28),
958   EMPTY_HOWTO (29),
959   EMPTY_HOWTO (30),
960   EMPTY_HOWTO (31),
961   EMPTY_HOWTO (32),
962   EMPTY_HOWTO (33),
963   EMPTY_HOWTO (34),
964   EMPTY_HOWTO (35),
965   EMPTY_HOWTO (36),
966   EMPTY_HOWTO (37),
967   EMPTY_HOWTO (38),
968   EMPTY_HOWTO (39),
969   EMPTY_HOWTO (40),
970   EMPTY_HOWTO (41),
971   EMPTY_HOWTO (42),
972   EMPTY_HOWTO (43),
973   EMPTY_HOWTO (44),
974   EMPTY_HOWTO (45),
975   EMPTY_HOWTO (46),
976   EMPTY_HOWTO (47),
977   EMPTY_HOWTO (48),
978   EMPTY_HOWTO (49),
979   EMPTY_HOWTO (50),
980   EMPTY_HOWTO (51),
981   EMPTY_HOWTO (52),
982   EMPTY_HOWTO (53),
983   EMPTY_HOWTO (54),
984   EMPTY_HOWTO (55),
985   EMPTY_HOWTO (56),
986   EMPTY_HOWTO (57),
987   EMPTY_HOWTO (58),
988   EMPTY_HOWTO (59),
989   EMPTY_HOWTO (60),
990   EMPTY_HOWTO (61),
991   EMPTY_HOWTO (62),
992   EMPTY_HOWTO (63),
993   EMPTY_HOWTO (64),
994   EMPTY_HOWTO (65),
995   EMPTY_HOWTO (66),
996   EMPTY_HOWTO (67),
997   EMPTY_HOWTO (68),
998   EMPTY_HOWTO (69),
999   EMPTY_HOWTO (70),
1000   EMPTY_HOWTO (71),
1001   EMPTY_HOWTO (72),
1002   EMPTY_HOWTO (73),
1003   EMPTY_HOWTO (74),
1004   EMPTY_HOWTO (75),
1005   EMPTY_HOWTO (76),
1006   EMPTY_HOWTO (77),
1007   EMPTY_HOWTO (78),
1008   EMPTY_HOWTO (79),
1009   EMPTY_HOWTO (80),
1010   EMPTY_HOWTO (81),
1011   EMPTY_HOWTO (82),
1012   EMPTY_HOWTO (83),
1013   EMPTY_HOWTO (84),
1014   EMPTY_HOWTO (85),
1015   EMPTY_HOWTO (86),
1016   EMPTY_HOWTO (87),
1017   EMPTY_HOWTO (88),
1018   EMPTY_HOWTO (89),
1019   EMPTY_HOWTO (90),
1020   EMPTY_HOWTO (91),
1021   EMPTY_HOWTO (92),
1022   EMPTY_HOWTO (93),
1023   EMPTY_HOWTO (94),
1024   EMPTY_HOWTO (95),
1025   EMPTY_HOWTO (96),
1026   EMPTY_HOWTO (97),
1027   EMPTY_HOWTO (98),
1028   EMPTY_HOWTO (99),
1029   EMPTY_HOWTO (100),
1030   EMPTY_HOWTO (101),
1031   EMPTY_HOWTO (102),
1032   EMPTY_HOWTO (103),
1033   EMPTY_HOWTO (104),
1034   EMPTY_HOWTO (105),
1035   EMPTY_HOWTO (106),
1036   EMPTY_HOWTO (107),
1037   EMPTY_HOWTO (108),
1038   EMPTY_HOWTO (109),
1039   EMPTY_HOWTO (110),
1040   EMPTY_HOWTO (111),
1041   EMPTY_HOWTO (112),
1042   EMPTY_HOWTO (113),
1043   EMPTY_HOWTO (114),
1044   EMPTY_HOWTO (115),
1045   EMPTY_HOWTO (116),
1046   EMPTY_HOWTO (117),
1047   EMPTY_HOWTO (118),
1048   EMPTY_HOWTO (119),
1049   EMPTY_HOWTO (120),
1050   EMPTY_HOWTO (121),
1051   EMPTY_HOWTO (122),
1052   EMPTY_HOWTO (123),
1053   EMPTY_HOWTO (124),
1054   EMPTY_HOWTO (125),
1055   EMPTY_HOWTO (126),
1056   EMPTY_HOWTO (127),
1057   EMPTY_HOWTO (128),
1058   EMPTY_HOWTO (129),
1059   EMPTY_HOWTO (130),
1060   EMPTY_HOWTO (131),
1061   EMPTY_HOWTO (132),
1062   EMPTY_HOWTO (133),
1063   EMPTY_HOWTO (134),
1064   EMPTY_HOWTO (135),
1065   EMPTY_HOWTO (136),
1066   EMPTY_HOWTO (137),
1067   EMPTY_HOWTO (138),
1068   EMPTY_HOWTO (139),
1069   EMPTY_HOWTO (140),
1070   EMPTY_HOWTO (141),
1071   EMPTY_HOWTO (142),
1072   EMPTY_HOWTO (143),
1073   EMPTY_HOWTO (144),
1074   EMPTY_HOWTO (145),
1075   EMPTY_HOWTO (146),
1076   EMPTY_HOWTO (147),
1077   EMPTY_HOWTO (148),
1078   EMPTY_HOWTO (149),
1079   EMPTY_HOWTO (150),
1080   EMPTY_HOWTO (151),
1081   EMPTY_HOWTO (152),
1082   EMPTY_HOWTO (153),
1083   EMPTY_HOWTO (154),
1084   EMPTY_HOWTO (155),
1085   EMPTY_HOWTO (156),
1086   EMPTY_HOWTO (157),
1087   EMPTY_HOWTO (158),
1088   EMPTY_HOWTO (159),
1089   EMPTY_HOWTO (160),
1090   EMPTY_HOWTO (161),
1091   EMPTY_HOWTO (162),
1092   EMPTY_HOWTO (163),
1093   EMPTY_HOWTO (164),
1094   EMPTY_HOWTO (165),
1095   EMPTY_HOWTO (166),
1096   EMPTY_HOWTO (167),
1097   EMPTY_HOWTO (168),
1098   EMPTY_HOWTO (169),
1099   EMPTY_HOWTO (170),
1100   EMPTY_HOWTO (171),
1101   EMPTY_HOWTO (172),
1102   EMPTY_HOWTO (173),
1103   EMPTY_HOWTO (174),
1104   EMPTY_HOWTO (175),
1105   EMPTY_HOWTO (176),
1106   EMPTY_HOWTO (177),
1107   EMPTY_HOWTO (178),
1108   EMPTY_HOWTO (179),
1109   EMPTY_HOWTO (180),
1110   EMPTY_HOWTO (181),
1111   EMPTY_HOWTO (182),
1112   EMPTY_HOWTO (183),
1113   EMPTY_HOWTO (184),
1114   EMPTY_HOWTO (185),
1115   EMPTY_HOWTO (186),
1116   EMPTY_HOWTO (187),
1117   EMPTY_HOWTO (188),
1118   EMPTY_HOWTO (189),
1119   EMPTY_HOWTO (190),
1120   EMPTY_HOWTO (191),
1121   EMPTY_HOWTO (192),
1122   EMPTY_HOWTO (193),
1123   EMPTY_HOWTO (194),
1124   EMPTY_HOWTO (195),
1125   EMPTY_HOWTO (196),
1126   EMPTY_HOWTO (197),
1127   EMPTY_HOWTO (198),
1128   EMPTY_HOWTO (199),
1129   EMPTY_HOWTO (200),
1130   EMPTY_HOWTO (201),
1131   EMPTY_HOWTO (202),
1132   EMPTY_HOWTO (203),
1133   EMPTY_HOWTO (204),
1134   EMPTY_HOWTO (205),
1135   EMPTY_HOWTO (206),
1136   EMPTY_HOWTO (207),
1137   EMPTY_HOWTO (208),
1138   EMPTY_HOWTO (209),
1139   EMPTY_HOWTO (210),
1140   EMPTY_HOWTO (211),
1141   EMPTY_HOWTO (212),
1142   EMPTY_HOWTO (213),
1143   EMPTY_HOWTO (214),
1144   EMPTY_HOWTO (215),
1145   EMPTY_HOWTO (216),
1146   EMPTY_HOWTO (217),
1147   EMPTY_HOWTO (218),
1148   EMPTY_HOWTO (219),
1149   EMPTY_HOWTO (220),
1150   EMPTY_HOWTO (221),
1151   EMPTY_HOWTO (222),
1152   EMPTY_HOWTO (223),
1153   EMPTY_HOWTO (224),
1154   EMPTY_HOWTO (225),
1155   EMPTY_HOWTO (226),
1156   EMPTY_HOWTO (227),
1157   EMPTY_HOWTO (228),
1158   EMPTY_HOWTO (229),
1159   EMPTY_HOWTO (230),
1160   EMPTY_HOWTO (231),
1161   EMPTY_HOWTO (232),
1162   EMPTY_HOWTO (233),
1163   EMPTY_HOWTO (234),
1164   EMPTY_HOWTO (235),
1165   EMPTY_HOWTO (236),
1166   EMPTY_HOWTO (237),
1167   EMPTY_HOWTO (238),
1168   EMPTY_HOWTO (239),
1169   EMPTY_HOWTO (240),
1170   EMPTY_HOWTO (241),
1171   EMPTY_HOWTO (242),
1172   EMPTY_HOWTO (243),
1173   EMPTY_HOWTO (244),
1174   EMPTY_HOWTO (245),
1175   EMPTY_HOWTO (246),
1176   EMPTY_HOWTO (247),
1177   EMPTY_HOWTO (248),
1178   EMPTY_HOWTO (249),
1179   EMPTY_HOWTO (250),
1180   EMPTY_HOWTO (251),
1181   EMPTY_HOWTO (252),
1182   HOWTO (R_C6000_ALIGN,         /* type */
1183          0,                     /* rightshift */
1184          0,                     /* size (0 = byte, 1 = short, 2 = long) */
1185          0,                     /* bitsize */
1186          FALSE,                 /* pc_relative */
1187          0,                     /* bitpos */
1188          complain_overflow_dont,/* complain_on_overflow */
1189          bfd_elf_generic_reloc, /* special_function */
1190          "R_C6000_ALIGN",       /* name */
1191          TRUE,                  /* partial_inplace */
1192          0,                     /* src_mask */
1193          0,                     /* dst_mask */
1194          FALSE),                /* pcrel_offset */
1195   HOWTO (R_C6000_FPHEAD,        /* type */
1196          0,                     /* rightshift */
1197          0,                     /* size (0 = byte, 1 = short, 2 = long) */
1198          0,                     /* bitsize */
1199          FALSE,                 /* pc_relative */
1200          0,                     /* bitpos */
1201          complain_overflow_dont,/* complain_on_overflow */
1202          bfd_elf_generic_reloc, /* special_function */
1203          "R_C6000_FPHEAD",      /* name */
1204          TRUE,                  /* partial_inplace */
1205          0,                     /* src_mask */
1206          0,                     /* dst_mask */
1207          FALSE),                /* pcrel_offset */
1208   HOWTO (R_C6000_NOCMP,         /* type */
1209          0,                     /* rightshift */
1210          0,                     /* size (0 = byte, 1 = short, 2 = long) */
1211          0,                     /* bitsize */
1212          FALSE,                 /* pc_relative */
1213          0,                     /* bitpos */
1214          complain_overflow_dont,/* complain_on_overflow */
1215          bfd_elf_generic_reloc, /* special_function */
1216          "R_C6000_NOCMP",       /* name */
1217          TRUE,                  /* partial_inplace */
1218          0,                     /* src_mask */
1219          0,                     /* dst_mask */
1220          FALSE)                 /* pcrel_offset */
1221 };
1222
1223 /* Map BFD relocations to ELF relocations.  */
1224
1225 typedef struct
1226 {
1227   bfd_reloc_code_real_type bfd_reloc_val;
1228   enum elf_tic6x_reloc_type elf_reloc_val;
1229 } tic6x_reloc_map;
1230
1231 static const tic6x_reloc_map elf32_tic6x_reloc_map[] =
1232   {
1233     { BFD_RELOC_NONE, R_C6000_NONE },
1234     { BFD_RELOC_32, R_C6000_ABS32 },
1235     { BFD_RELOC_16, R_C6000_ABS16 },
1236     { BFD_RELOC_8, R_C6000_ABS8 },
1237     { BFD_RELOC_C6000_PCR_S21, R_C6000_PCR_S21 },
1238     { BFD_RELOC_C6000_PCR_S12, R_C6000_PCR_S12 },
1239     { BFD_RELOC_C6000_PCR_S10, R_C6000_PCR_S10 },
1240     { BFD_RELOC_C6000_PCR_S7, R_C6000_PCR_S7 },
1241     { BFD_RELOC_C6000_ABS_S16, R_C6000_ABS_S16 },
1242     { BFD_RELOC_C6000_ABS_L16, R_C6000_ABS_L16 },
1243     { BFD_RELOC_C6000_ABS_H16, R_C6000_ABS_H16 },
1244     { BFD_RELOC_C6000_SBR_U15_B, R_C6000_SBR_U15_B },
1245     { BFD_RELOC_C6000_SBR_U15_H, R_C6000_SBR_U15_H },
1246     { BFD_RELOC_C6000_SBR_U15_W, R_C6000_SBR_U15_W },
1247     { BFD_RELOC_C6000_SBR_S16, R_C6000_SBR_S16 },
1248     { BFD_RELOC_C6000_SBR_L16_B, R_C6000_SBR_L16_B },
1249     { BFD_RELOC_C6000_SBR_L16_H, R_C6000_SBR_L16_H },
1250     { BFD_RELOC_C6000_SBR_L16_W, R_C6000_SBR_L16_W },
1251     { BFD_RELOC_C6000_SBR_H16_B, R_C6000_SBR_H16_B },
1252     { BFD_RELOC_C6000_SBR_H16_H, R_C6000_SBR_H16_H },
1253     { BFD_RELOC_C6000_SBR_H16_W, R_C6000_SBR_H16_W },
1254     { BFD_RELOC_C6000_SBR_GOT_U15_W, R_C6000_SBR_GOT_U15_W },
1255     { BFD_RELOC_C6000_SBR_GOT_L16_W, R_C6000_SBR_GOT_L16_W },
1256     { BFD_RELOC_C6000_SBR_GOT_H16_W, R_C6000_SBR_GOT_H16_W },
1257     { BFD_RELOC_C6000_DSBT_INDEX, R_C6000_DSBT_INDEX },
1258     { BFD_RELOC_C6000_PREL31, R_C6000_PREL31 },
1259     { BFD_RELOC_C6000_COPY, R_C6000_COPY },
1260     { BFD_RELOC_C6000_ALIGN, R_C6000_ALIGN },
1261     { BFD_RELOC_C6000_FPHEAD, R_C6000_FPHEAD },
1262     { BFD_RELOC_C6000_NOCMP, R_C6000_NOCMP }
1263   };
1264
1265 static reloc_howto_type *
1266 elf32_tic6x_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
1267 {
1268   unsigned int i;
1269
1270   for (i = 0; i < ARRAY_SIZE (elf32_tic6x_reloc_map); i++)
1271     if (elf32_tic6x_reloc_map[i].bfd_reloc_val == code)
1272       {
1273         enum elf_tic6x_reloc_type elf_reloc_val;
1274         reloc_howto_type *howto;
1275
1276         elf_reloc_val = elf32_tic6x_reloc_map[i].elf_reloc_val;
1277         if (elf32_tic6x_tdata (abfd)->use_rela_p)
1278           howto = &elf32_tic6x_howto_table[elf_reloc_val];
1279         else
1280           howto = &elf32_tic6x_howto_table_rel[elf_reloc_val];
1281
1282         /* Some relocations are RELA-only; do not return them for
1283            REL.  */
1284         if (howto->name == NULL)
1285           howto = NULL;
1286
1287         return howto;
1288       }
1289
1290   return NULL;
1291 }
1292
1293 static reloc_howto_type *
1294 elf32_tic6x_reloc_name_lookup (bfd *abfd, const char *r_name)
1295 {
1296   if (elf32_tic6x_tdata (abfd)->use_rela_p)
1297     {
1298       unsigned int i;
1299
1300       for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table); i++)
1301         if (elf32_tic6x_howto_table[i].name != NULL
1302             && strcasecmp (elf32_tic6x_howto_table[i].name, r_name) == 0)
1303           return &elf32_tic6x_howto_table[i];
1304     }
1305   else
1306     {
1307       unsigned int i;
1308
1309       for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table_rel); i++)
1310         if (elf32_tic6x_howto_table_rel[i].name != NULL
1311             && strcasecmp (elf32_tic6x_howto_table_rel[i].name, r_name) == 0)
1312           return &elf32_tic6x_howto_table_rel[i];
1313     }
1314
1315   return NULL;
1316 }
1317
1318 static void
1319 elf32_tic6x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1320                            Elf_Internal_Rela *elf_reloc)
1321 {
1322   unsigned int r_type;
1323
1324   r_type = ELF32_R_TYPE (elf_reloc->r_info);
1325   if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table))
1326     bfd_reloc->howto = NULL;
1327   else
1328     bfd_reloc->howto = &elf32_tic6x_howto_table[r_type];
1329 }
1330
1331 static void
1332 elf32_tic6x_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1333                                Elf_Internal_Rela *elf_reloc)
1334 {
1335   unsigned int r_type;
1336
1337   r_type = ELF32_R_TYPE (elf_reloc->r_info);
1338   if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table_rel))
1339     bfd_reloc->howto = NULL;
1340   else
1341     bfd_reloc->howto = &elf32_tic6x_howto_table_rel[r_type];
1342 }
1343
1344 void
1345 elf32_tic6x_set_use_rela_p (bfd *abfd, bfd_boolean use_rela_p)
1346 {
1347   elf32_tic6x_tdata (abfd)->use_rela_p = use_rela_p;
1348 }
1349
1350 static bfd_boolean
1351 elf32_tic6x_mkobject (bfd *abfd)
1352 {
1353   bfd_boolean ret;
1354
1355   ret = bfd_elf_allocate_object (abfd, sizeof (struct elf32_tic6x_obj_tdata),
1356                                  TIC6X_ELF_DATA);
1357   if (ret)
1358     elf32_tic6x_set_use_rela_p (abfd, TRUE);
1359   return ret;
1360 }
1361
1362 static bfd_boolean
1363 elf32_tic6x_new_section_hook (bfd *abfd, asection *sec)
1364 {
1365   bfd_boolean ret;
1366
1367   ret = _bfd_elf_new_section_hook (abfd, sec);
1368   sec->use_rela_p = elf32_tic6x_tdata (abfd)->use_rela_p;
1369
1370   return ret;
1371 }
1372
1373 /* Return true if relocation REL against section SEC is a REL rather
1374    than RELA relocation.  RELOCS is the first relocation in the
1375    section and ABFD is the bfd that contains SEC.  */
1376
1377 static bfd_boolean
1378 elf32_tic6x_rel_relocation_p (bfd *abfd, asection *sec,
1379                               const Elf_Internal_Rela *relocs,
1380                               const Elf_Internal_Rela *rel)
1381 {
1382   Elf_Internal_Shdr *rel_hdr;
1383   const struct elf_backend_data *bed;
1384
1385   /* To determine which flavor of relocation this is, we depend on the
1386      fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR.  */
1387   rel_hdr = elf_section_data (sec)->rel.hdr;
1388   if (rel_hdr == NULL)
1389     return FALSE;
1390   bed = get_elf_backend_data (abfd);
1391   return ((size_t) (rel - relocs)
1392           < NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel);
1393 }
1394
1395 static bfd_boolean
1396 elf32_tic6x_relocate_section (bfd *output_bfd,
1397                               struct bfd_link_info *info,
1398                               bfd *input_bfd,
1399                               asection *input_section,
1400                               bfd_byte *contents,
1401                               Elf_Internal_Rela *relocs,
1402                               Elf_Internal_Sym *local_syms,
1403                               asection **local_sections)
1404 {
1405   Elf_Internal_Shdr *symtab_hdr;
1406   struct elf_link_hash_entry **sym_hashes;
1407   Elf_Internal_Rela *rel;
1408   Elf_Internal_Rela *relend;
1409   bfd_boolean ok = TRUE;
1410
1411   symtab_hdr = & elf_symtab_hdr (input_bfd);
1412   sym_hashes = elf_sym_hashes (input_bfd);
1413
1414   relend = relocs + input_section->reloc_count;
1415
1416   for (rel = relocs; rel < relend; rel ++)
1417     {
1418       int r_type;
1419       unsigned long r_symndx;
1420       arelent bfd_reloc;
1421       reloc_howto_type *howto;
1422       Elf_Internal_Sym *sym;
1423       asection *sec;
1424       struct elf_link_hash_entry *h;
1425       bfd_vma relocation;
1426       bfd_boolean unresolved_reloc;
1427       bfd_reloc_status_type r;
1428       struct bfd_link_hash_entry *sbh;
1429       bfd_boolean is_rel;
1430
1431       r_type = ELF32_R_TYPE (rel->r_info);
1432       r_symndx = ELF32_R_SYM (rel->r_info);
1433
1434       is_rel = elf32_tic6x_rel_relocation_p (input_bfd, input_section,
1435                                              relocs, rel);
1436
1437       if (is_rel)
1438         elf32_tic6x_info_to_howto_rel (input_bfd, &bfd_reloc, rel);
1439       else
1440         elf32_tic6x_info_to_howto (input_bfd, &bfd_reloc, rel);
1441       howto = bfd_reloc.howto;
1442       if (howto == NULL)
1443         {
1444           bfd_set_error (bfd_error_bad_value);
1445           return FALSE;
1446         }
1447
1448       h = NULL;
1449       sym = NULL;
1450       sec = NULL;
1451       unresolved_reloc = FALSE;
1452
1453       if (r_symndx < symtab_hdr->sh_info)
1454         {
1455           sym = local_syms + r_symndx;
1456           sec = local_sections[r_symndx];
1457           relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1458         }
1459       else
1460         {
1461           bfd_boolean warned;
1462
1463           RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1464                                    r_symndx, symtab_hdr, sym_hashes,
1465                                    h, sec, relocation,
1466                                    unresolved_reloc, warned);
1467         }
1468
1469       if (sec != NULL && elf_discarded_section (sec))
1470         {
1471           /* For relocs against symbols from removed linkonce sections,
1472              or sections discarded by a linker script, we just want the
1473              section contents zeroed.  Avoid any special processing.  */
1474           _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
1475           rel->r_info = 0;
1476           rel->r_addend = 0;
1477           continue;
1478         }
1479
1480       if (info->relocatable)
1481         {
1482           if (is_rel
1483               && sym != NULL
1484               && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1485             {
1486               rel->r_addend = 0;
1487               relocation = sec->output_offset + sym->st_value;
1488               r = _bfd_relocate_contents (howto, input_bfd, relocation,
1489                                           contents + rel->r_offset);
1490               goto done_reloc;
1491             }
1492           continue;
1493         }
1494
1495       switch (r_type)
1496         {
1497         case R_C6000_NONE:
1498         case R_C6000_ALIGN:
1499         case R_C6000_FPHEAD:
1500         case R_C6000_NOCMP:
1501           /* No action needed.  */
1502           continue;
1503
1504         case R_C6000_PCR_S21:
1505         case R_C6000_PCR_S12:
1506         case R_C6000_PCR_S10:
1507         case R_C6000_PCR_S7:
1508           /* Generic PC-relative handling produces a value relative to
1509              the exact location of the relocation.  Adjust it to be
1510              relative to the start of the fetch packet instead.  */
1511           relocation += (input_section->output_section->vma
1512                          + input_section->output_offset
1513                          + rel->r_offset) & 0x1f;
1514           /* Fall through.  */
1515         case R_C6000_ABS32:
1516         case R_C6000_ABS16:
1517         case R_C6000_ABS8:
1518         case R_C6000_ABS_S16:
1519         case R_C6000_ABS_L16:
1520         case R_C6000_ABS_H16:
1521           /* Generic logic OK.  */
1522           break;
1523
1524         case R_C6000_SBR_U15_B:
1525         case R_C6000_SBR_U15_H:
1526         case R_C6000_SBR_U15_W:
1527         case R_C6000_SBR_S16:
1528         case R_C6000_SBR_L16_B:
1529         case R_C6000_SBR_L16_H:
1530         case R_C6000_SBR_L16_W:
1531         case R_C6000_SBR_H16_B:
1532         case R_C6000_SBR_H16_H:
1533         case R_C6000_SBR_H16_W:
1534           sbh = bfd_link_hash_lookup (info->hash, "__c6xabi_DSBT_BASE",
1535                                       FALSE, FALSE, TRUE);
1536           if (sbh != NULL
1537               && (sbh->type == bfd_link_hash_defined
1538                   || sbh->type == bfd_link_hash_defweak))
1539             relocation -= (sbh->u.def.value
1540                            + sbh->u.def.section->output_section->vma
1541                            + sbh->u.def.section->output_offset);
1542           else
1543             {
1544               (*_bfd_error_handler) (_("%B: SB-relative relocation but "
1545                                        "__c6xabi_DSBT_BASE not defined"),
1546                                      input_bfd);
1547               ok = FALSE;
1548               continue;
1549             }
1550           break;
1551
1552         case R_C6000_SBR_GOT_U15_W:
1553         case R_C6000_SBR_GOT_L16_W:
1554         case R_C6000_SBR_GOT_H16_W:
1555         case R_C6000_DSBT_INDEX:
1556         case R_C6000_PREL31:
1557           /* Shared libraries and exception handling support not
1558              implemented.  */
1559           (*_bfd_error_handler) (_("%B: relocation type %d not implemented"),
1560                                  input_bfd, r_type);
1561           ok = FALSE;
1562           continue;
1563
1564         case R_C6000_COPY:
1565           /* Invalid in relocatable object.  */
1566         default:
1567           /* Unknown relocation.  */
1568           (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
1569                                  input_bfd, r_type);
1570           ok = FALSE;
1571           continue;
1572         }
1573
1574       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1575                                     contents, rel->r_offset,
1576                                     relocation, rel->r_addend);
1577
1578     done_reloc:
1579       if (r == bfd_reloc_ok
1580           && howto->complain_on_overflow == complain_overflow_bitfield)
1581         {
1582           /* Generic overflow handling accepts cases the ABI says
1583              should be rejected for R_C6000_ABS16 and
1584              R_C6000_ABS8.  */
1585           bfd_vma value = (relocation + rel->r_addend) & 0xffffffff;
1586           bfd_vma sbit = 1 << (howto->bitsize - 1);
1587           bfd_vma sbits = (-(bfd_vma) sbit) & 0xffffffff;
1588           bfd_vma value_sbits = value & sbits;
1589
1590           if (value_sbits != 0
1591               && value_sbits != sbit
1592               && value_sbits != sbits)
1593             r = bfd_reloc_overflow;
1594         }
1595
1596       if (r != bfd_reloc_ok)
1597         {
1598           const char *name;
1599           const char *error_message;
1600
1601           if (h != NULL)
1602             name = h->root.root.string;
1603           else
1604             {
1605               name = bfd_elf_string_from_elf_section (input_bfd,
1606                                                       symtab_hdr->sh_link,
1607                                                       sym->st_name);
1608               if (name == NULL)
1609                 return FALSE;
1610               if (*name == '\0')
1611                 name = bfd_section_name (input_bfd, sec);
1612             }
1613
1614           switch (r)
1615             {
1616             case bfd_reloc_overflow:
1617               /* If the overflowing reloc was to an undefined symbol,
1618                  we have already printed one error message and there
1619                  is no point complaining again.  */
1620               if ((! h ||
1621                    h->root.type != bfd_link_hash_undefined)
1622                   && (!((*info->callbacks->reloc_overflow)
1623                         (info, (h ? &h->root : NULL), name, howto->name,
1624                          (bfd_vma) 0, input_bfd, input_section,
1625                          rel->r_offset))))
1626                   return FALSE;
1627               break;
1628
1629             case bfd_reloc_undefined:
1630               if (!((*info->callbacks->undefined_symbol)
1631                     (info, name, input_bfd, input_section,
1632                      rel->r_offset, TRUE)))
1633                 return FALSE;
1634               break;
1635
1636             case bfd_reloc_outofrange:
1637               error_message = _("out of range");
1638               goto common_error;
1639
1640             case bfd_reloc_notsupported:
1641               error_message = _("unsupported relocation");
1642               goto common_error;
1643
1644             case bfd_reloc_dangerous:
1645               error_message = _("dangerous relocation");
1646               goto common_error;
1647
1648             default:
1649               error_message = _("unknown error");
1650               /* Fall through.  */
1651
1652             common_error:
1653               BFD_ASSERT (error_message != NULL);
1654               if (!((*info->callbacks->reloc_dangerous)
1655                     (info, error_message, input_bfd, input_section,
1656                      rel->r_offset)))
1657                 return FALSE;
1658               break;
1659             }
1660         }
1661     }
1662
1663   return ok;
1664 }
1665
1666 static int
1667 elf32_tic6x_obj_attrs_arg_type (int tag)
1668 {
1669   if (tag == Tag_compatibility)
1670     return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
1671   else
1672     /* Correct for known attributes, arbitrary for others.  */
1673     return ATTR_TYPE_FLAG_INT_VAL;
1674 }
1675
1676 /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
1677    and return the merged value.  At present, all merges succeed, so no
1678    return value for errors is defined.  */
1679
1680 int
1681 elf32_tic6x_merge_arch_attributes (int arch1, int arch2)
1682 {
1683   int min_arch, max_arch;
1684
1685   min_arch = (arch1 < arch2 ? arch1 : arch2);
1686   max_arch = (arch1 > arch2 ? arch1 : arch2);
1687
1688   /* In most cases, the numerically greatest value is the correct
1689      merged value, but merging C64 and C67 results in C674X.  */
1690   if ((min_arch == C6XABI_Tag_ISA_C67X
1691        || min_arch == C6XABI_Tag_ISA_C67XP)
1692       && (max_arch == C6XABI_Tag_ISA_C64X
1693           || max_arch == C6XABI_Tag_ISA_C64XP))
1694     return C6XABI_Tag_ISA_C674X;
1695
1696   return max_arch;
1697 }
1698
1699 /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
1700    succeeded, FALSE otherwise.  */
1701
1702 static bfd_boolean
1703 elf32_tic6x_merge_attributes (bfd *ibfd, bfd *obfd)
1704 {
1705   obj_attribute *in_attr;
1706   obj_attribute *out_attr;
1707
1708   if (!elf_known_obj_attributes_proc (obfd)[0].i)
1709     {
1710       /* This is the first object.  Copy the attributes.  */
1711       _bfd_elf_copy_obj_attributes (ibfd, obfd);
1712
1713       out_attr = elf_known_obj_attributes_proc (obfd);
1714
1715       /* Use the Tag_null value to indicate the attributes have been
1716          initialized.  */
1717       out_attr[0].i = 1;
1718
1719       return TRUE;
1720     }
1721
1722   in_attr = elf_known_obj_attributes_proc (ibfd);
1723   out_attr = elf_known_obj_attributes_proc (obfd);
1724
1725   /* No specification yet for handling of unknown attributes, so just
1726      ignore them and handle known ones.  */
1727   out_attr[Tag_ISA].i
1728     = elf32_tic6x_merge_arch_attributes (in_attr[Tag_ISA].i,
1729                                          out_attr[Tag_ISA].i);
1730
1731   /* Merge Tag_compatibility attributes and any common GNU ones.  */
1732   _bfd_elf_merge_object_attributes (ibfd, obfd);
1733
1734   return TRUE;
1735 }
1736
1737 static bfd_boolean
1738 elf32_tic6x_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
1739 {
1740   if (!_bfd_generic_verify_endian_match (ibfd, obfd))
1741     return FALSE;
1742
1743   if (!elf32_tic6x_merge_attributes (ibfd, obfd))
1744     return FALSE;
1745
1746   return TRUE;
1747 }
1748
1749
1750 #define TARGET_LITTLE_SYM       bfd_elf32_tic6x_le_vec
1751 #define TARGET_LITTLE_NAME      "elf32-tic6x-le"
1752 #define TARGET_BIG_SYM          bfd_elf32_tic6x_be_vec
1753 #define TARGET_BIG_NAME         "elf32-tic6x-be"
1754 #define ELF_ARCH                bfd_arch_tic6x
1755 #define ELF_TARGET_ID           TIC6X_ELF_DATA
1756 #define ELF_MACHINE_CODE        EM_TI_C6000
1757 #define ELF_MAXPAGESIZE         1
1758 #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
1759 #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
1760 #define bfd_elf32_bfd_merge_private_bfd_data    elf32_tic6x_merge_private_bfd_data
1761 #define bfd_elf32_mkobject              elf32_tic6x_mkobject
1762 #define bfd_elf32_new_section_hook      elf32_tic6x_new_section_hook
1763 #define elf_backend_can_gc_sections     1
1764 #define elf_backend_default_use_rela_p  1
1765 #define elf_backend_may_use_rel_p       1
1766 #define elf_backend_may_use_rela_p      1
1767 #define elf_backend_obj_attrs_arg_type  elf32_tic6x_obj_attrs_arg_type
1768 #define elf_backend_obj_attrs_section   ".c6xabi.attributes"
1769 #define elf_backend_obj_attrs_section_type      SHT_C6000_ATTRIBUTES
1770 #define elf_backend_obj_attrs_vendor    "c6xabi"
1771 #define elf_backend_rela_normal         1
1772 #define elf_backend_relocate_section    elf32_tic6x_relocate_section
1773 #define elf_info_to_howto               elf32_tic6x_info_to_howto
1774 #define elf_info_to_howto_rel           elf32_tic6x_info_to_howto_rel
1775
1776 #include "elf32-target.h"