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