OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [bfd/] [elf32-tic6x.c] - Blame information for rev 161

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.