Coverage Report

Created: 2026-09-14 08:07

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