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-or1k.c
Line
Count
Source
1
/* Or1k-specific support for 32-bit ELF.
2
   Copyright (C) 2001-2026 Free Software Foundation, Inc.
3
   Contributed for OR32 by Johan Rydberg, jrydberg@opencores.org
4
5
   PIC parts added by Stefan Kristiansson, stefan.kristiansson@saunalahti.fi,
6
   largely based on elf32-m32r.c and elf32-microblaze.c.
7
8
   This file is part of BFD, the Binary File Descriptor library.
9
10
   This program is free software; you can redistribute it and/or modify
11
   it under the terms of the GNU General Public License as published by
12
   the Free Software Foundation; either version 3 of the License, or
13
   (at your option) any later version.
14
15
   This program is distributed in the hope that it will be useful,
16
   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
   GNU General Public License for more details.
19
20
   You should have received a copy of the GNU General Public License
21
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
22
23
#include "sysdep.h"
24
#include "bfd.h"
25
#include "libbfd.h"
26
#include "elf-bfd.h"
27
#include "elf/or1k.h"
28
#include "libiberty.h"
29
30
0
#define N_ONES(X) (((bfd_vma)2 << (X)) - 1)
31
32
0
#define PLT_ENTRY_SIZE 16
33
0
#define PLT_ENTRY_SIZE_LARGE (6*4)
34
#define PLT_MAX_INSN_COUNT 6
35
36
0
#define OR1K_MOVHI(D)   (0x18000000 | (D << 21))
37
0
#define OR1K_ADRP(D)    (0x08000000 | (D << 21))
38
0
#define OR1K_LWZ(D,A)   (0x84000000 | (D << 21) | (A << 16))
39
0
#define OR1K_ADD(D,A,B)   (0xE0000000 | (D << 21) | (A << 16) | (B << 11))
40
0
#define OR1K_ORI(D,A)   (0xA8000000 | (D << 21) | (A << 16))
41
0
#define OR1K_ORI0(D)    (0xA8000000 | (D << 21))
42
0
#define OR1K_JR(B)    (0x44000000 | (B << 11))
43
0
#define OR1K_NOP    0x15000000
44
45
0
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
46
47
static reloc_howto_type or1k_elf_howto_table[] =
48
{
49
  /* This reloc does nothing.  */
50
  HOWTO (R_OR1K_NONE,   /* type */
51
   0,     /* rightshift */
52
   0,     /* size */
53
   0,     /* bitsize */
54
   false,     /* pc_relative */
55
   0,     /* bitpos */
56
   complain_overflow_dont, /* complain_on_overflow */
57
   bfd_elf_generic_reloc, /* special_function */
58
   "R_OR1K_NONE",   /* name */
59
   false,     /* partial_inplace */
60
   0,     /* src_mask */
61
   0,     /* dst_mask */
62
   false),    /* pcrel_offset */
63
64
  HOWTO (R_OR1K_32,
65
   0,     /* rightshift */
66
   4,     /* size */
67
   32,      /* bitsize */
68
   false,     /* pc_relative */
69
   0,     /* bitpos */
70
   complain_overflow_unsigned, /* complain_on_overflow */
71
   bfd_elf_generic_reloc, /* special_function */
72
   "R_OR1K_32",   /* name */
73
   false,     /* partial_inplace */
74
   0,     /* src_mask */
75
   0xffffffff,    /* dst_mask */
76
   false),    /* pcrel_offset */
77
78
  HOWTO (R_OR1K_16,
79
   0,     /* rightshift */
80
   2,     /* size */
81
   16,      /* bitsize */
82
   false,     /* pc_relative */
83
   0,     /* bitpos */
84
   complain_overflow_unsigned, /* complain_on_overflow */
85
   bfd_elf_generic_reloc, /* special_function */
86
   "R_OR1K_16",   /* name */
87
   false,     /* partial_inplace */
88
   0,     /* src_mask */
89
   0xffff,    /* dst_mask */
90
   false),    /* pcrel_offset */
91
92
  HOWTO (R_OR1K_8,
93
   0,     /* rightshift */
94
   1,     /* size */
95
   8,     /* bitsize */
96
   false,     /* pc_relative */
97
   0,     /* bitpos */
98
   complain_overflow_unsigned, /* complain_on_overflow */
99
   bfd_elf_generic_reloc, /* special_function */
100
   "R_OR1K_8",    /* name */
101
   false,     /* partial_inplace */
102
   0,     /* src_mask */
103
   0xff,      /* dst_mask */
104
   false),    /* pcrel_offset */
105
106
  HOWTO (R_OR1K_LO_16_IN_INSN, /* type */
107
   0,     /* rightshift */
108
   4,     /* size */
109
   16,      /* bitsize */
110
   false,     /* pc_relative */
111
   0,     /* bitpos */
112
   complain_overflow_dont, /* complain_on_overflow */
113
   bfd_elf_generic_reloc, /* special_function */
114
   "R_OR1K_LO_16_IN_INSN", /* name */
115
   false,     /* partial_inplace */
116
   0,     /* src_mask */
117
   0x0000ffff,    /* dst_mask */
118
   false),    /* pcrel_offset */
119
120
  HOWTO (R_OR1K_HI_16_IN_INSN, /* type */
121
   16,      /* rightshift */
122
   4,     /* size */
123
   16,      /* bitsize */
124
   false,     /* pc_relative */
125
   0,     /* bitpos */
126
   complain_overflow_dont, /* complain_on_overflow */
127
   bfd_elf_generic_reloc, /* special_function */
128
   "R_OR1K_HI_16_IN_INSN", /* name */
129
   false,     /* partial_inplace */
130
   0,     /* src_mask */
131
   0x0000ffff,    /* dst_mask */
132
   false),    /* pcrel_offset */
133
134
  /* A PC relative 26 bit relocation, right shifted by 2.  */
135
  HOWTO (R_OR1K_INSN_REL_26, /* type */
136
   2,     /* rightshift */
137
   4,     /* size */
138
   26,      /* bitsize */
139
   true,      /* pc_relative */
140
   0,     /* bitpos */
141
   complain_overflow_signed, /* complain_on_overflow */
142
   bfd_elf_generic_reloc, /* special_function */
143
   "R_OR1K_INSN_REL_26", /* name */
144
   false,     /* partial_inplace */
145
   0,     /* src_mask */
146
   0x03ffffff,    /* dst_mask */
147
   true),     /* pcrel_offset */
148
149
  /* GNU extension to record C++ vtable hierarchy.  */
150
  HOWTO (R_OR1K_GNU_VTINHERIT, /* type */
151
   0,     /* rightshift */
152
   4,     /* size */
153
   0,     /* bitsize */
154
   false,     /* pc_relative */
155
   0,     /* bitpos */
156
   complain_overflow_dont, /* complain_on_overflow */
157
   NULL,      /* special_function */
158
   "R_OR1K_GNU_VTINHERIT", /* name */
159
   false,     /* partial_inplace */
160
   0,     /* src_mask */
161
   0,     /* dst_mask */
162
   false),    /* pcrel_offset */
163
164
  /* GNU extension to record C++ vtable member usage.  */
165
  HOWTO (R_OR1K_GNU_VTENTRY, /* type */
166
   0,     /* rightshift */
167
   4,     /* size */
168
   0,     /* bitsize */
169
   false,     /* pc_relative */
170
   0,     /* bitpos */
171
   complain_overflow_dont, /* complain_on_overflow */
172
   _bfd_elf_rel_vtable_reloc_fn, /* special_function */
173
   "R_OR1K_GNU_VTENTRY", /* name */
174
   false,     /* partial_inplace */
175
   0,     /* src_mask */
176
   0,     /* dst_mask */
177
   false),    /* pcrel_offset */
178
179
  HOWTO (R_OR1K_32_PCREL,
180
   0,     /* rightshift */
181
   4,     /* size */
182
   32,      /* bitsize */
183
   true,      /* pc_relative */
184
   0,     /* bitpos */
185
   complain_overflow_signed, /* complain_on_overflow */
186
   bfd_elf_generic_reloc, /* special_function */
187
   "R_OR1K_32_PCREL", /* name */
188
   false,     /* partial_inplace */
189
   0,     /* src_mask */
190
   0xffffffff,    /* dst_mask */
191
   true),     /* pcrel_offset */
192
193
  HOWTO (R_OR1K_16_PCREL,
194
   0,     /* rightshift */
195
   2,     /* size */
196
   16,      /* bitsize */
197
   true,      /* pc_relative */
198
   0,     /* bitpos */
199
   complain_overflow_signed, /* complain_on_overflow */
200
   bfd_elf_generic_reloc, /* special_function */
201
   "R_OR1K_16_PCREL", /* name */
202
   false,     /* partial_inplace */
203
   0,     /* src_mask */
204
   0xffff,    /* dst_mask */
205
   true),     /* pcrel_offset */
206
207
  HOWTO (R_OR1K_8_PCREL,
208
   0,     /* rightshift */
209
   1,     /* size */
210
   8,     /* bitsize */
211
   true,      /* pc_relative */
212
   0,     /* bitpos */
213
   complain_overflow_signed, /* complain_on_overflow */
214
   bfd_elf_generic_reloc, /* special_function */
215
   "R_OR1K_8_PCREL",  /* name */
216
   false,     /* partial_inplace */
217
   0,     /* src_mask */
218
   0xff,      /* dst_mask */
219
   true),     /* pcrel_offset */
220
221
   HOWTO (R_OR1K_GOTPC_HI16,  /* Type.  */
222
   16,      /* Rightshift.  */
223
   4,     /* Size.  */
224
   16,      /* Bitsize.  */
225
   true,      /* PC_relative.  */
226
   0,     /* Bitpos.  */
227
   complain_overflow_dont, /* Complain on overflow.  */
228
   bfd_elf_generic_reloc, /* Special Function.  */
229
   "R_OR1K_GOTPC_HI16", /* Name.  */
230
   false,   /* Partial Inplace.  */
231
   0,     /* Source Mask.  */
232
   0xffff,    /* Dest Mask.  */
233
   true),     /* PC relative offset?  */
234
235
   HOWTO (R_OR1K_GOTPC_LO16,  /* Type.  */
236
   0,     /* Rightshift.  */
237
   4,     /* Size.  */
238
   16,      /* Bitsize.  */
239
   true,      /* PC_relative.  */
240
   0,     /* Bitpos.  */
241
   complain_overflow_dont, /* Complain on overflow.  */
242
   bfd_elf_generic_reloc, /* Special Function.  */
243
   "R_OR1K_GOTPC_LO16", /* Name.  */
244
   false,   /* Partial Inplace.  */
245
   0,     /* Source Mask.  */
246
   0xffff,    /* Dest Mask.  */
247
   true),     /* PC relative offset?  */
248
249
  HOWTO (R_OR1K_GOT16,    /* type */
250
   0,     /* rightshift */
251
   4,     /* size */
252
   16,      /* bitsize */
253
   false,     /* pc_relative */
254
   0,     /* bitpos */
255
   complain_overflow_signed, /* complain_on_overflow */
256
   bfd_elf_generic_reloc, /* special_function */
257
   "R_OR1K_GOT16",  /* name */
258
   false,     /* partial_inplace */
259
   0,     /* src_mask */
260
   0xffff,    /* dst_mask */
261
   false),    /* pcrel_offset */
262
263
  /* A 26 bit PLT relocation.  Shifted by 2.  */
264
  HOWTO (R_OR1K_PLT26,    /* Type.  */
265
   2,     /* Rightshift.  */
266
   4,     /* Size.  */
267
   26,      /* Bitsize.  */
268
   true,      /* pc_relative.  */
269
   0,     /* Bitpos.  */
270
   complain_overflow_signed, /* Complain on overflow.  */
271
   bfd_elf_generic_reloc, /* Special Function.  */
272
   "R_OR1K_PLT26",  /* Name.  */
273
   false,     /* Partial Inplace.  */
274
   0,     /* Source Mask.  */
275
   0x03ffffff,    /* Dest Mask.  */
276
   true),     /* PC relative offset?  */
277
278
  HOWTO (R_OR1K_GOTOFF_HI16,  /* type */
279
   16,      /* rightshift */
280
   4,     /* size */
281
   16,      /* bitsize */
282
   false,     /* pc_relative */
283
   0,     /* bitpos */
284
   complain_overflow_dont, /* complain_on_overflow */
285
   bfd_elf_generic_reloc, /* special_function */
286
   "R_OR1K_GOTOFF_HI16",  /* name */
287
   false,     /* partial_inplace */
288
   0x0,     /* src_mask */
289
   0xffff,    /* dst_mask */
290
   false),    /* pcrel_offset */
291
292
  HOWTO (R_OR1K_GOTOFF_LO16,  /* type */
293
   0,     /* rightshift */
294
   4,     /* size */
295
   16,      /* bitsize */
296
   false,     /* pc_relative */
297
   0,     /* bitpos */
298
   complain_overflow_dont, /* complain_on_overflow */
299
   bfd_elf_generic_reloc, /* special_function */
300
   "R_OR1K_GOTOFF_LO16",  /* name */
301
   false,     /* partial_inplace */
302
   0x0,     /* src_mask */
303
   0xffff,    /* dst_mask */
304
   false),    /* pcrel_offset */
305
306
  HOWTO (R_OR1K_COPY,   /* type */
307
   0,     /* rightshift */
308
   4,     /* size */
309
   32,      /* bitsize */
310
   false,     /* pc_relative */
311
   0,     /* bitpos */
312
   complain_overflow_bitfield, /* complain_on_overflow */
313
   bfd_elf_generic_reloc, /* special_function */
314
   "R_OR1K_COPY",   /* name */
315
   false,     /* partial_inplace */
316
   0xffffffff,    /* src_mask */
317
   0xffffffff,    /* dst_mask */
318
   false),    /* pcrel_offset */
319
320
  HOWTO (R_OR1K_GLOB_DAT, /* type */
321
   0,     /* rightshift */
322
   4,     /* size */
323
   32,      /* bitsize */
324
   false,     /* pc_relative */
325
   0,     /* bitpos */
326
   complain_overflow_bitfield, /* complain_on_overflow */
327
   bfd_elf_generic_reloc, /* special_function */
328
   "R_OR1K_GLOB_DAT", /* name */
329
   false,     /* partial_inplace */
330
   0xffffffff,    /* src_mask */
331
   0xffffffff,    /* dst_mask */
332
   false),    /* pcrel_offset */
333
334
  HOWTO (R_OR1K_JMP_SLOT, /* type */
335
   0,     /* rightshift */
336
   4,     /* size */
337
   32,      /* bitsize */
338
   false,     /* pc_relative */
339
   0,     /* bitpos */
340
   complain_overflow_bitfield, /* complain_on_overflow */
341
   bfd_elf_generic_reloc, /* special_function */
342
   "R_OR1K_JMP_SLOT", /* name */
343
   false,     /* partial_inplace */
344
   0xffffffff,    /* src_mask */
345
   0xffffffff,    /* dst_mask */
346
   false),    /* pcrel_offset */
347
348
  HOWTO (R_OR1K_RELATIVE, /* type */
349
   0,     /* rightshift */
350
   4,     /* size */
351
   32,      /* bitsize */
352
   false,     /* pc_relative */
353
   0,     /* bitpos */
354
   complain_overflow_bitfield, /* complain_on_overflow */
355
   bfd_elf_generic_reloc, /* special_function */
356
   "R_OR1K_RELATIVE", /* name */
357
   false,     /* partial_inplace */
358
   0xffffffff,    /* src_mask */
359
   0xffffffff,    /* dst_mask */
360
   false),    /* pcrel_offset */
361
362
  HOWTO (R_OR1K_TLS_GD_HI16,  /* type */
363
   16,      /* rightshift */
364
   4,     /* size */
365
   16,      /* bitsize */
366
   false,     /* pc_relative */
367
   0,     /* bitpos */
368
   complain_overflow_dont, /* complain_on_overflow */
369
   bfd_elf_generic_reloc, /* special_function */
370
   "R_OR1K_TLS_GD_HI16",  /* name */
371
   false,     /* partial_inplace */
372
   0x0,     /* src_mask */
373
   0xffff,    /* dst_mask */
374
   false),    /* pcrel_offset */
375
376
  HOWTO (R_OR1K_TLS_GD_LO16,  /* type */
377
   0,     /* rightshift */
378
   4,     /* size */
379
   16,      /* bitsize */
380
   false,     /* pc_relative */
381
   0,     /* bitpos */
382
   complain_overflow_dont, /* complain_on_overflow */
383
   bfd_elf_generic_reloc, /* special_function */
384
   "R_OR1K_TLS_GD_LO16",  /* name */
385
   false,     /* partial_inplace */
386
   0x0,     /* src_mask */
387
   0xffff,    /* dst_mask */
388
   false),    /* pcrel_offset */
389
390
  HOWTO (R_OR1K_TLS_LDM_HI16, /* type */
391
   16,      /* rightshift */
392
   4,     /* size */
393
   16,      /* bitsize */
394
   false,     /* pc_relative */
395
   0,     /* bitpos */
396
   complain_overflow_dont, /* complain_on_overflow */
397
   bfd_elf_generic_reloc, /* special_function */
398
   "R_OR1K_TLS_LDM_HI16", /* name */
399
   false,     /* partial_inplace */
400
   0x0,     /* src_mask */
401
   0xffff,    /* dst_mask */
402
   false),    /* pcrel_offset */
403
404
  HOWTO (R_OR1K_TLS_LDM_LO16, /* type */
405
   0,     /* rightshift */
406
   4,     /* size */
407
   16,      /* bitsize */
408
   false,     /* pc_relative */
409
   0,     /* bitpos */
410
   complain_overflow_dont, /* complain_on_overflow */
411
   bfd_elf_generic_reloc, /* special_function */
412
   "R_OR1K_TLS_LDM_LO16", /* name */
413
   false,     /* partial_inplace */
414
   0x0,     /* src_mask */
415
   0xffff,    /* dst_mask */
416
   false),    /* pcrel_offset */
417
418
  HOWTO (R_OR1K_TLS_LDO_HI16, /* type */
419
   16,      /* rightshift */
420
   4,     /* size */
421
   16,      /* bitsize */
422
   false,     /* pc_relative */
423
   0,     /* bitpos */
424
   complain_overflow_dont, /* complain_on_overflow */
425
   bfd_elf_generic_reloc, /* special_function */
426
   "R_OR1K_TLS_LDO_HI16", /* name */
427
   false,     /* partial_inplace */
428
   0x0,     /* src_mask */
429
   0xffff,    /* dst_mask */
430
   false),    /* pcrel_offset */
431
432
  HOWTO (R_OR1K_TLS_LDO_LO16, /* type */
433
   0,     /* rightshift */
434
   4,     /* size */
435
   16,      /* bitsize */
436
   false,     /* pc_relative */
437
   0,     /* bitpos */
438
   complain_overflow_dont, /* complain_on_overflow */
439
   bfd_elf_generic_reloc, /* special_function */
440
   "R_OR1K_TLS_LDO_LO16", /* name */
441
   false,     /* partial_inplace */
442
   0x0,     /* src_mask */
443
   0xffff,    /* dst_mask */
444
   false),    /* pcrel_offset */
445
446
  HOWTO (R_OR1K_TLS_IE_HI16,  /* type */
447
   16,      /* rightshift */
448
   4,     /* size */
449
   16,      /* bitsize */
450
   false,     /* pc_relative */
451
   0,     /* bitpos */
452
   complain_overflow_dont, /* complain_on_overflow */
453
   bfd_elf_generic_reloc, /* special_function */
454
   "R_OR1K_TLS_IE_HI16",  /* name */
455
   false,     /* partial_inplace */
456
   0x0,     /* src_mask */
457
   0xffff,    /* dst_mask */
458
   false),    /* pcrel_offset */
459
460
  HOWTO (R_OR1K_TLS_IE_LO16,  /* type */
461
   0,     /* rightshift */
462
   4,     /* size */
463
   16,      /* bitsize */
464
   false,     /* pc_relative */
465
   0,     /* bitpos */
466
   complain_overflow_dont, /* complain_on_overflow */
467
   bfd_elf_generic_reloc, /* special_function */
468
   "R_OR1K_TLS_IE_LO16",  /* name */
469
   false,     /* partial_inplace */
470
   0x0,     /* src_mask */
471
   0xffff,    /* dst_mask */
472
   false),    /* pcrel_offset */
473
474
  HOWTO (R_OR1K_TLS_LE_HI16,  /* type */
475
   16,      /* rightshift */
476
   4,     /* size */
477
   16,      /* bitsize */
478
   false,     /* pc_relative */
479
   0,     /* bitpos */
480
   complain_overflow_dont, /* complain_on_overflow */
481
   bfd_elf_generic_reloc, /* special_function */
482
   "R_OR1K_TLS_LE_HI16",  /* name */
483
   false,     /* partial_inplace */
484
   0x0,     /* src_mask */
485
   0xffff,    /* dst_mask */
486
   false),    /* pcrel_offset */
487
488
  HOWTO (R_OR1K_TLS_LE_LO16,  /* type */
489
   0,     /* rightshift */
490
   4,     /* size */
491
   16,      /* bitsize */
492
   false,     /* pc_relative */
493
   0,     /* bitpos */
494
   complain_overflow_dont, /* complain_on_overflow */
495
   bfd_elf_generic_reloc, /* special_function */
496
   "R_OR1K_TLS_LE_LO16",  /* name */
497
   false,     /* partial_inplace */
498
   0x0,     /* src_mask */
499
   0xffff,    /* dst_mask */
500
   false),    /* pcrel_offset */
501
502
  HOWTO (R_OR1K_TLS_TPOFF,  /* type */
503
   0,     /* rightshift */
504
   4,     /* size */
505
   32,      /* bitsize */
506
   false,     /* pc_relative */
507
   0,     /* bitpos */
508
   complain_overflow_bitfield, /* complain_on_overflow */
509
   bfd_elf_generic_reloc, /* special_function */
510
   "R_OR1K_TLS_TPOFF",    /* name */
511
   false,     /* partial_inplace */
512
   0xffffffff,    /* src_mask */
513
   0xffffffff,    /* dst_mask */
514
   false),    /* pcrel_offset */
515
516
  HOWTO (R_OR1K_TLS_DTPOFF, /* type */
517
   0,     /* rightshift */
518
   4,     /* size */
519
   32,      /* bitsize */
520
   false,     /* pc_relative */
521
   0,     /* bitpos */
522
   complain_overflow_bitfield, /* complain_on_overflow */
523
   bfd_elf_generic_reloc, /* special_function */
524
   "R_OR1K_TLS_DTPOFF",   /* name */
525
   false,     /* partial_inplace */
526
   0xffffffff,    /* src_mask */
527
   0xffffffff,    /* dst_mask */
528
   false),    /* pcrel_offset */
529
530
  HOWTO (R_OR1K_TLS_DTPMOD, /* type */
531
   0,     /* rightshift */
532
   4,     /* size */
533
   32,      /* bitsize */
534
   false,     /* pc_relative */
535
   0,     /* bitpos */
536
   complain_overflow_bitfield, /* complain_on_overflow */
537
   bfd_elf_generic_reloc, /* special_function */
538
   "R_OR1K_TLS_DTPMOD",   /* name */
539
   false,     /* partial_inplace */
540
   0xffffffff,    /* src_mask */
541
   0xffffffff,    /* dst_mask */
542
   false),    /* pcrel_offset */
543
544
  HOWTO (R_OR1K_AHI16,    /* type */
545
   16,      /* rightshift */
546
   4,     /* size */
547
   16,      /* bitsize */
548
   false,     /* pc_relative */
549
   0,     /* bitpos */
550
   complain_overflow_dont, /* complain_on_overflow */
551
   bfd_elf_generic_reloc, /* special_function */
552
   "R_OR1K_AHI16",  /* name */
553
   false,     /* partial_inplace */
554
   0x0,     /* src_mask */
555
   0xffff,    /* dst_mask */
556
   false),    /* pcrel_offset */
557
558
  HOWTO (R_OR1K_GOTOFF_AHI16, /* type */
559
   16,      /* rightshift */
560
   4,     /* size */
561
   16,      /* bitsize */
562
   false,     /* pc_relative */
563
   0,     /* bitpos */
564
   complain_overflow_dont, /* complain_on_overflow */
565
   bfd_elf_generic_reloc, /* special_function */
566
   "R_OR1K_GOTOFF_AHI16", /* name */
567
   false,     /* partial_inplace */
568
   0x0,     /* src_mask */
569
   0xffff,    /* dst_mask */
570
   false),    /* pcrel_offset */
571
572
  HOWTO (R_OR1K_TLS_IE_AHI16,   /* type */
573
   16,      /* rightshift */
574
   4,     /* size */
575
   16,      /* bitsize */
576
   false,     /* pc_relative */
577
   0,     /* bitpos */
578
   complain_overflow_dont, /* complain_on_overflow */
579
   bfd_elf_generic_reloc, /* special_function */
580
   "R_OR1K_TLS_IE_AHI16", /* name */
581
   false,     /* partial_inplace */
582
   0x0,     /* src_mask */
583
   0xffff,    /* dst_mask */
584
   false),    /* pcrel_offset */
585
586
  HOWTO (R_OR1K_TLS_LE_AHI16, /* type */
587
   16,      /* rightshift */
588
   4,     /* size */
589
   16,      /* bitsize */
590
   false,     /* pc_relative */
591
   0,     /* bitpos */
592
   complain_overflow_dont, /* complain_on_overflow */
593
   bfd_elf_generic_reloc, /* special_function */
594
   "R_OR1K_TLS_LE_AHI16", /* name */
595
   false,     /* partial_inplace */
596
   0x0,     /* src_mask */
597
   0xffff,    /* dst_mask */
598
   false),    /* pcrel_offset */
599
600
  HOWTO (R_OR1K_SLO16,    /* type */
601
   0,     /* rightshift */
602
   4,     /* size */
603
   16,      /* bitsize */
604
   false,     /* pc_relative */
605
   0,     /* bitpos */
606
   complain_overflow_dont, /* complain_on_overflow */
607
   bfd_elf_generic_reloc, /* special_function */
608
   "R_OR1K_SLO16",  /* name */
609
   false,     /* partial_inplace */
610
   0x0,     /* src_mask */
611
   0xffff,    /* dst_mask */
612
   false),    /* pcrel_offset */
613
614
  HOWTO (R_OR1K_GOTOFF_SLO16, /* type */
615
   0,     /* rightshift */
616
   4,     /* size */
617
   16,      /* bitsize */
618
   false,     /* pc_relative */
619
   0,     /* bitpos */
620
   complain_overflow_dont, /* complain_on_overflow */
621
   bfd_elf_generic_reloc, /* special_function */
622
   "R_OR1K_GOTOFF_SLO16", /* name */
623
   false,     /* partial_inplace */
624
   0x0,     /* src_mask */
625
   0xffff,    /* dst_mask */
626
   false),    /* pcrel_offset */
627
628
  HOWTO (R_OR1K_TLS_LE_SLO16,   /* type */
629
   0,     /* rightshift */
630
   4,     /* size */
631
   16,      /* bitsize */
632
   false,     /* pc_relative */
633
   0,     /* bitpos */
634
   complain_overflow_dont, /* complain_on_overflow */
635
   bfd_elf_generic_reloc, /* special_function */
636
   "R_OR1K_TLS_LE_SLO16", /* name */
637
   false,     /* partial_inplace */
638
   0x0,     /* src_mask */
639
   0xffff,    /* dst_mask */
640
   false),    /* pcrel_offset */
641
642
  /* A page relative 21 bit relocation, right shifted by 13, aligned.
643
     Note that this is *page* relative, not pc relative.  The idea is
644
     similar, but normally the section alignment is not such that the
645
     assembler can infer a final value, which it attempts to do with
646
     pc-relative relocations to local symbols.  */
647
  HOWTO (R_OR1K_PCREL_PG21,    /* type */
648
   13,      /* rightshift */
649
   4,     /* size */
650
   21,      /* bitsize */
651
   false,     /* pc_relative */
652
   0,     /* bitpos */
653
   complain_overflow_signed, /* complain_on_overflow */
654
   bfd_elf_generic_reloc, /* special_function */
655
   "R_OR1K_PCREL_PG21",   /* name */
656
   false,     /* partial_inplace */
657
   0,     /* src_mask */
658
   0x001fffff,    /* dst_mask */
659
   true),     /* pcrel_offset */
660
661
  HOWTO (R_OR1K_GOT_PG21,       /* type */
662
   13,      /* rightshift */
663
   4,     /* size */
664
   21,      /* bitsize */
665
   false,     /* pc_relative */
666
   0,     /* bitpos */
667
   complain_overflow_signed, /* complain_on_overflow */
668
   bfd_elf_generic_reloc, /* special_function */
669
   "R_OR1K_GOT_PG21",     /* name */
670
   false,     /* partial_inplace */
671
   0,     /* src_mask */
672
   0x001fffff,    /* dst_mask */
673
   true),     /* pcrel_offset */
674
675
  HOWTO (R_OR1K_TLS_GD_PG21,    /* type */
676
   13,      /* rightshift */
677
   4,     /* size */
678
   21,      /* bitsize */
679
   false,     /* pc_relative */
680
   0,     /* bitpos */
681
   complain_overflow_signed, /* complain_on_overflow */
682
   bfd_elf_generic_reloc, /* special_function */
683
   "R_OR1K_TLS_GD_PG21",  /* name */
684
   false,     /* partial_inplace */
685
   0,     /* src_mask */
686
   0x001fffff,    /* dst_mask */
687
   true),     /* pcrel_offset */
688
689
  HOWTO (R_OR1K_TLS_LDM_PG21,   /* type */
690
   13,      /* rightshift */
691
   4,     /* size */
692
   21,      /* bitsize */
693
   false,     /* pc_relative */
694
   0,     /* bitpos */
695
   complain_overflow_signed, /* complain_on_overflow */
696
   bfd_elf_generic_reloc, /* special_function */
697
   "R_OR1K_TLS_LDM_PG21", /* name */
698
   false,     /* partial_inplace */
699
   0,     /* src_mask */
700
   0x001fffff,    /* dst_mask */
701
   true),     /* pcrel_offset */
702
703
  HOWTO (R_OR1K_TLS_IE_PG21,    /* type */
704
   13,      /* rightshift */
705
   4,     /* size */
706
   21,      /* bitsize */
707
   false,     /* pc_relative */
708
   0,     /* bitpos */
709
   complain_overflow_signed, /* complain_on_overflow */
710
   bfd_elf_generic_reloc, /* special_function */
711
   "R_OR1K_TLS_IE_PG21",  /* name */
712
   false,     /* partial_inplace */
713
   0,     /* src_mask */
714
   0x001fffff,    /* dst_mask */
715
   true),     /* pcrel_offset */
716
717
  HOWTO (R_OR1K_LO13,   /* type */
718
   0,     /* rightshift */
719
   4,     /* size */
720
   16,      /* bitsize */
721
   false,     /* pc_relative */
722
   0,     /* bitpos */
723
   complain_overflow_dont, /* complain_on_overflow */
724
   bfd_elf_generic_reloc, /* special_function */
725
   "R_OR1K_LO13",   /* name */
726
   false,     /* partial_inplace */
727
   0x0,     /* src_mask */
728
   0xffff,    /* dst_mask */
729
   false),    /* pcrel_offset */
730
731
  HOWTO (R_OR1K_GOT_LO13,       /* type */
732
   0,     /* rightshift */
733
   4,     /* size */
734
   16,      /* bitsize */
735
   false,     /* pc_relative */
736
   0,     /* bitpos */
737
   complain_overflow_dont, /* complain_on_overflow */
738
   bfd_elf_generic_reloc, /* special_function */
739
   "R_OR1K_GOT_LO13",     /* name */
740
   false,     /* partial_inplace */
741
   0x0,     /* src_mask */
742
   0xffff,    /* dst_mask */
743
   false),    /* pcrel_offset */
744
745
  HOWTO (R_OR1K_TLS_GD_LO13,    /* type */
746
   0,     /* rightshift */
747
   4,     /* size */
748
   16,      /* bitsize */
749
   false,     /* pc_relative */
750
   0,     /* bitpos */
751
   complain_overflow_dont, /* complain_on_overflow */
752
   bfd_elf_generic_reloc, /* special_function */
753
   "R_OR1K_TLS_GD_LO13",  /* name */
754
   false,     /* partial_inplace */
755
   0x0,     /* src_mask */
756
   0xffff,    /* dst_mask */
757
   false),    /* pcrel_offset */
758
759
  HOWTO (R_OR1K_TLS_LDM_LO13,   /* type */
760
   0,     /* rightshift */
761
   4,     /* size */
762
   16,      /* bitsize */
763
   false,     /* pc_relative */
764
   0,     /* bitpos */
765
   complain_overflow_dont, /* complain_on_overflow */
766
   bfd_elf_generic_reloc, /* special_function */
767
   "R_OR1K_TLD_LDM_LO13", /* name */
768
   false,     /* partial_inplace */
769
   0x0,     /* src_mask */
770
   0xffff,    /* dst_mask */
771
   false),    /* pcrel_offset */
772
773
  HOWTO (R_OR1K_TLS_IE_LO13,    /* type */
774
   0,     /* rightshift */
775
   4,     /* size */
776
   16,      /* bitsize */
777
   false,     /* pc_relative */
778
   0,     /* bitpos */
779
   complain_overflow_dont, /* complain_on_overflow */
780
   bfd_elf_generic_reloc, /* special_function */
781
   "R_OR1K_TLS_IE_LO13",  /* name */
782
   false,     /* partial_inplace */
783
   0x0,     /* src_mask */
784
   0xffff,    /* dst_mask */
785
   false),    /* pcrel_offset */
786
787
  HOWTO (R_OR1K_SLO13,    /* type */
788
   0,     /* rightshift */
789
   4,     /* size */
790
   16,      /* bitsize */
791
   false,     /* pc_relative */
792
   0,     /* bitpos */
793
   complain_overflow_dont, /* complain_on_overflow */
794
   bfd_elf_generic_reloc, /* special_function */
795
   "R_OR1K_SLO13",  /* name */
796
   false,     /* partial_inplace */
797
   0x0,     /* src_mask */
798
   0xffff,    /* dst_mask */
799
   false),    /* pcrel_offset */
800
801
  /* A 26 bit PLT relocation, using ADRP.  Shifted by 2.  */
802
  HOWTO (R_OR1K_PLTA26,   /* Type.  */
803
   2,     /* Rightshift.  */
804
   4,     /* Size.  */
805
   26,      /* Bitsize.  */
806
   true,      /* pc_relative.  */
807
   0,     /* Bitpos.  */
808
   complain_overflow_signed, /* Complain on overflow.  */
809
   bfd_elf_generic_reloc, /* Special Function.  */
810
   "R_OR1K_PLTA26", /* Name.  */
811
   false,     /* Partial Inplace.  */
812
   0,     /* Source Mask.  */
813
   0x03ffffff,    /* Dest Mask.  */
814
   true),     /* PC relative offset?  */
815
816
  HOWTO (R_OR1K_GOT_AHI16,  /* type */
817
   16,      /* rightshift */
818
   4,     /* size */
819
   16,      /* bitsize */
820
   false,     /* pc_relative */
821
   0,     /* bitpos */
822
   complain_overflow_signed, /* complain_on_overflow */
823
   bfd_elf_generic_reloc, /* special_function */
824
   "R_OR1K_GOT_AHI16",  /* name */
825
   false,     /* partial_inplace */
826
   0,     /* src_mask */
827
   0xffff,    /* dst_mask */
828
   false),    /* pcrel_offset */
829
};
830
831
/* A copy of the R_OR1K_GOT16 used in the presense of R_OR1K_GOT_AHI16
832
   relocations when we know we can ignore overflows.  */
833
static reloc_howto_type or1k_elf_got16_no_overflow_howto =
834
  HOWTO (R_OR1K_GOT16,    /* type */
835
   0,     /* rightshift */
836
   4,     /* size */
837
   16,      /* bitsize */
838
   false,     /* pc_relative */
839
   0,     /* bitpos */
840
   complain_overflow_dont, /* complain_on_overflow */
841
   bfd_elf_generic_reloc, /* special_function */
842
   "R_OR1K_GOT16",  /* name */
843
   false,     /* partial_inplace */
844
   0,     /* src_mask */
845
   0xffff,    /* dst_mask */
846
   false);    /* pcrel_offset */
847
848
/* Map BFD reloc types to Or1k ELF reloc types.  */
849
850
struct or1k_reloc_map
851
{
852
  bfd_reloc_code_real_type bfd_reloc_val;
853
  unsigned int or1k_reloc_val;
854
};
855
856
static const struct or1k_reloc_map or1k_reloc_map[] =
857
{
858
  { BFD_RELOC_NONE,   R_OR1K_NONE },
859
  { BFD_RELOC_32,   R_OR1K_32 },
860
  { BFD_RELOC_16,   R_OR1K_16 },
861
  { BFD_RELOC_8,    R_OR1K_8 },
862
  { BFD_RELOC_LO16,   R_OR1K_LO_16_IN_INSN },
863
  { BFD_RELOC_HI16,   R_OR1K_HI_16_IN_INSN },
864
  { BFD_RELOC_HI16_S,   R_OR1K_AHI16 },
865
  { BFD_RELOC_OR1K_REL_26,  R_OR1K_INSN_REL_26 },
866
  { BFD_RELOC_VTABLE_ENTRY, R_OR1K_GNU_VTENTRY },
867
  { BFD_RELOC_VTABLE_INHERIT, R_OR1K_GNU_VTINHERIT },
868
  { BFD_RELOC_32_PCREL,   R_OR1K_32_PCREL },
869
  { BFD_RELOC_16_PCREL,   R_OR1K_16_PCREL },
870
  { BFD_RELOC_8_PCREL,    R_OR1K_8_PCREL },
871
  { BFD_RELOC_LO16_GOTOFF,  R_OR1K_GOTOFF_LO16 },
872
  { BFD_RELOC_HI16_GOTOFF,  R_OR1K_GOTOFF_HI16 },
873
  { BFD_RELOC_HI16_S_GOTOFF,  R_OR1K_GOTOFF_AHI16 },
874
  { BFD_RELOC_OR1K_GOTPC_HI16,  R_OR1K_GOTPC_HI16 },
875
  { BFD_RELOC_OR1K_GOTPC_LO16,  R_OR1K_GOTPC_LO16 },
876
  { BFD_RELOC_OR1K_GOT16, R_OR1K_GOT16 },
877
  { BFD_RELOC_OR1K_PLT26, R_OR1K_PLT26 },
878
  { BFD_RELOC_GLOB_DAT,   R_OR1K_GLOB_DAT },
879
  { BFD_RELOC_COPY,   R_OR1K_COPY },
880
  { BFD_RELOC_JMP_SLOT,   R_OR1K_JMP_SLOT },
881
  { BFD_RELOC_RELATIVE,   R_OR1K_RELATIVE },
882
  { BFD_RELOC_OR1K_TLS_GD_HI16, R_OR1K_TLS_GD_HI16 },
883
  { BFD_RELOC_OR1K_TLS_GD_LO16, R_OR1K_TLS_GD_LO16 },
884
  { BFD_RELOC_OR1K_TLS_LDM_HI16,  R_OR1K_TLS_LDM_HI16 },
885
  { BFD_RELOC_OR1K_TLS_LDM_LO16,  R_OR1K_TLS_LDM_LO16 },
886
  { BFD_RELOC_OR1K_TLS_LDO_HI16,  R_OR1K_TLS_LDO_HI16 },
887
  { BFD_RELOC_OR1K_TLS_LDO_LO16,  R_OR1K_TLS_LDO_LO16 },
888
  { BFD_RELOC_OR1K_TLS_IE_HI16, R_OR1K_TLS_IE_HI16 },
889
  { BFD_RELOC_OR1K_TLS_IE_LO16, R_OR1K_TLS_IE_LO16 },
890
  { BFD_RELOC_OR1K_TLS_IE_AHI16, R_OR1K_TLS_IE_AHI16 },
891
  { BFD_RELOC_OR1K_TLS_LE_HI16, R_OR1K_TLS_LE_HI16 },
892
  { BFD_RELOC_OR1K_TLS_LE_LO16, R_OR1K_TLS_LE_LO16 },
893
  { BFD_RELOC_OR1K_TLS_LE_AHI16, R_OR1K_TLS_LE_AHI16 },
894
  { BFD_RELOC_OR1K_SLO16, R_OR1K_SLO16 },
895
  { BFD_RELOC_OR1K_GOTOFF_SLO16, R_OR1K_GOTOFF_SLO16 },
896
  { BFD_RELOC_OR1K_TLS_LE_SLO16, R_OR1K_TLS_LE_SLO16 },
897
  { BFD_RELOC_OR1K_PCREL_PG21,  R_OR1K_PCREL_PG21 },
898
  { BFD_RELOC_OR1K_GOT_PG21,  R_OR1K_GOT_PG21 },
899
  { BFD_RELOC_OR1K_TLS_GD_PG21, R_OR1K_TLS_GD_PG21 },
900
  { BFD_RELOC_OR1K_TLS_LDM_PG21, R_OR1K_TLS_LDM_PG21 },
901
  { BFD_RELOC_OR1K_TLS_IE_PG21, R_OR1K_TLS_IE_PG21 },
902
  { BFD_RELOC_OR1K_LO13,  R_OR1K_LO13 },
903
  { BFD_RELOC_OR1K_GOT_LO13,  R_OR1K_GOT_LO13 },
904
  { BFD_RELOC_OR1K_TLS_GD_LO13, R_OR1K_TLS_GD_LO13 },
905
  { BFD_RELOC_OR1K_TLS_LDM_LO13, R_OR1K_TLS_LDM_LO13 },
906
  { BFD_RELOC_OR1K_TLS_IE_LO13, R_OR1K_TLS_IE_LO13 },
907
  { BFD_RELOC_OR1K_SLO13, R_OR1K_SLO13 },
908
  { BFD_RELOC_OR1K_PLTA26,  R_OR1K_PLTA26 },
909
  { BFD_RELOC_OR1K_GOT_AHI16, R_OR1K_GOT_AHI16 },
910
};
911
912
/* tls_type is a mask used to track how each symbol is accessed,
913
   it may be accessed via multiple types of TLS access methods.
914
   We track this for sizing (allocating got + relocation section space) and
915
   for how to process relocations.  */
916
0
#define TLS_UNKNOWN    0
917
0
#define TLS_NONE       1
918
0
#define TLS_GD         2
919
0
#define TLS_LD         4
920
0
#define TLS_IE         8
921
0
#define TLS_LE        16
922
923
/* The size of the TLS thread control block, used to offset LE access.  */
924
0
#define TCB_SIZE      16
925
926
/* ELF linker hash entry.  */
927
struct elf_or1k_link_hash_entry
928
{
929
  struct elf_link_hash_entry root;
930
931
  /* For calculating PLT size.  */
932
  bfd_vma plt_index;
933
  /* Track type of TLS access.  */
934
  unsigned char tls_type;
935
};
936
937
/* ELF object data.  */
938
struct elf_or1k_obj_tdata
939
{
940
  struct elf_obj_tdata root;
941
942
  /* tls_type for each local got entry.  */
943
  unsigned char *local_tls_type;
944
};
945
946
#define elf_or1k_tdata(abfd) \
947
0
  ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
948
949
#define elf_or1k_local_tls_type(abfd) \
950
0
  (elf_or1k_tdata (abfd)->local_tls_type)
951
952
/* ELF linker hash table.  */
953
struct elf_or1k_link_hash_table
954
{
955
  struct elf_link_hash_table root;
956
957
  bfd_vma plt_count;
958
  bool saw_plta;
959
};
960
961
static size_t
962
elf_or1k_plt_entry_size (bfd_vma plt_index)
963
0
{
964
0
  bfd_vma plt_reloc;
965
966
0
  plt_reloc = plt_index * sizeof (Elf32_External_Rela);
967
968
0
  return (plt_reloc > 0xffff) ? PLT_ENTRY_SIZE_LARGE : PLT_ENTRY_SIZE;
969
0
}
970
971
/* Get the ELF linker hash table from a link_info structure.  */
972
#define or1k_elf_hash_table(p) \
973
0
  ((is_elf_hash_table ((p)->hash)          \
974
0
    && elf_hash_table_id (elf_hash_table (p)) == OR1K_ELF_DATA)   \
975
0
   ? (struct elf_or1k_link_hash_table *) (p)->hash : NULL)
976
977
static bool
978
elf_or1k_mkobject (bfd *abfd)
979
22.6k
{
980
22.6k
  return bfd_elf_allocate_object (abfd, sizeof (struct elf_or1k_obj_tdata));
981
22.6k
}
982
983
/* Create an entry in an or1k ELF linker hash table.  */
984
985
static struct bfd_hash_entry *
986
or1k_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
987
          struct bfd_hash_table *table,
988
          const char *string)
989
0
{
990
0
  struct elf_or1k_link_hash_entry *ret =
991
0
    (struct elf_or1k_link_hash_entry *) entry;
992
993
  /* Allocate the structure if it has not already been allocated by a
994
     subclass.  */
995
0
  if (ret == NULL)
996
0
    ret = bfd_hash_allocate (table,
997
0
           sizeof (struct elf_or1k_link_hash_entry));
998
0
  if (ret == NULL)
999
0
    return NULL;
1000
1001
  /* Call the allocation method of the superclass.  */
1002
0
  ret = ((struct elf_or1k_link_hash_entry *)
1003
0
   _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1004
0
             table, string));
1005
0
  if (ret != NULL)
1006
0
    {
1007
0
      struct elf_or1k_link_hash_entry *eh;
1008
1009
0
      eh = (struct elf_or1k_link_hash_entry *) ret;
1010
0
      eh->tls_type = TLS_UNKNOWN;
1011
0
    }
1012
1013
0
  return (struct bfd_hash_entry *) ret;
1014
0
}
1015
1016
/* Create an or1k ELF linker hash table.  */
1017
1018
static struct bfd_link_hash_table *
1019
or1k_elf_link_hash_table_create (bfd *abfd)
1020
0
{
1021
0
  struct elf_or1k_link_hash_table *ret;
1022
0
  size_t amt = sizeof (struct elf_or1k_link_hash_table);
1023
1024
0
  ret = bfd_zmalloc (amt);
1025
0
  if (ret == NULL)
1026
0
    return NULL;
1027
1028
0
  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
1029
0
              or1k_elf_link_hash_newfunc,
1030
0
              sizeof (struct elf_or1k_link_hash_entry)))
1031
0
    {
1032
0
      free (ret);
1033
0
      return NULL;
1034
0
    }
1035
1036
0
  return &ret->root.root;
1037
0
}
1038
1039
static reloc_howto_type *
1040
or1k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
1041
      bfd_reloc_code_real_type bcode)
1042
0
{
1043
0
  unsigned int i;
1044
1045
0
  for (i = 0; i < ARRAY_SIZE (or1k_reloc_map); i++)
1046
0
    if (or1k_reloc_map[i].bfd_reloc_val == bcode)
1047
0
      {
1048
0
  unsigned int ocode = or1k_reloc_map[i].or1k_reloc_val;
1049
0
  if (ocode < (unsigned int) R_OR1K_max)
1050
0
    return &or1k_elf_howto_table[ocode];
1051
0
  else
1052
0
    break;
1053
0
      }
1054
1055
0
  return NULL;
1056
0
}
1057
1058
static reloc_howto_type *
1059
or1k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1060
      const char *r_name)
1061
0
{
1062
0
  unsigned int i;
1063
1064
0
  for (i = 0; i < R_OR1K_max; i++)
1065
0
    if (or1k_elf_howto_table[i].name != NULL
1066
0
  && strcasecmp (or1k_elf_howto_table[i].name, r_name) == 0)
1067
0
      return &or1k_elf_howto_table[i];
1068
1069
0
  return NULL;
1070
0
}
1071
1072
/* Set the howto pointer for an Or1k ELF reloc.  */
1073
1074
static bool
1075
or1k_info_to_howto_rela (bfd * abfd,
1076
       arelent * cache_ptr,
1077
       Elf_Internal_Rela * dst)
1078
250
{
1079
250
  unsigned int r_type;
1080
1081
250
  r_type = ELF32_R_TYPE (dst->r_info);
1082
250
  if (r_type >= (unsigned int) R_OR1K_max)
1083
13
    {
1084
      /* xgettext:c-format */
1085
13
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1086
13
        abfd, r_type);
1087
13
      bfd_set_error (bfd_error_bad_value);
1088
13
      return false;
1089
13
    }
1090
237
  cache_ptr->howto = & or1k_elf_howto_table[r_type];
1091
237
  return true;
1092
250
}
1093
1094
/* Return the relocation value for @tpoff relocations..  */
1095
static bfd_vma
1096
tpoff (struct bfd_link_info *info, bfd_vma address, bool dynamic)
1097
0
{
1098
0
  struct elf_link_hash_table *htab = elf_hash_table (info);
1099
0
  bfd_vma base;
1100
1101
  /* If tls_sec is NULL, we should have signalled an error already.  */
1102
0
  if (htab->tls_sec == NULL)
1103
0
    return 0;
1104
1105
0
  if (dynamic)
1106
0
    return address - htab->tls_sec->vma;
1107
0
  else
1108
0
    {
1109
      /* On or1k, the tp points to just after the tcb, if we have an alignment
1110
   greater than the tcb size we need to offset by the alignment difference.  */
1111
0
      base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power)
1112
0
       - TCB_SIZE;
1113
1114
      /* The thread pointer on or1k stores the address after the TCB where
1115
   the data is, just compute the difference. No need to compensate
1116
   for the size of TCB.  */
1117
0
      return address - htab->tls_sec->vma + base;
1118
0
    }
1119
0
}
1120
1121
/* If we have both IE and GD accesses to a symbol the IE relocations should be
1122
   offset by 8 bytes because the got contains both GD and IE entries.  */
1123
static bfd_vma
1124
or1k_initial_exec_offset (reloc_howto_type *howto, unsigned char tls_type_mask)
1125
0
{
1126
0
   switch (howto->type)
1127
0
     {
1128
0
     case R_OR1K_TLS_IE_HI16:
1129
0
     case R_OR1K_TLS_IE_LO16:
1130
0
     case R_OR1K_TLS_IE_PG21:
1131
0
     case R_OR1K_TLS_IE_LO13:
1132
0
     case R_OR1K_TLS_IE_AHI16:
1133
0
       return (tls_type_mask & TLS_GD) != 0 ? 8 : 0;
1134
0
     default:
1135
0
       return 0;
1136
0
     }
1137
0
}
1138
1139
/* Like _bfd_final_link_relocate, but handles non-contiguous fields.  */
1140
1141
static bfd_reloc_status_type
1142
or1k_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
1143
        asection *input_section, bfd_byte *contents,
1144
        bfd_vma offset, bfd_vma value)
1145
0
{
1146
0
  bfd_reloc_status_type status = bfd_reloc_ok;
1147
0
  int size = bfd_get_reloc_size (howto);
1148
0
  bfd_vma x, place;
1149
1150
  /* Sanity check the address.  */
1151
0
  if (offset + size > bfd_get_section_limit_octets (input_bfd, input_section))
1152
0
    return bfd_reloc_outofrange;
1153
1154
0
  place = (input_section->output_section->vma
1155
0
     + input_section->output_offset
1156
0
     + (howto->pcrel_offset ? offset : 0));
1157
1158
0
  switch (howto->type)
1159
0
    {
1160
0
    case R_OR1K_AHI16:
1161
0
    case R_OR1K_GOT_AHI16:
1162
0
    case R_OR1K_GOTOFF_AHI16:
1163
0
    case R_OR1K_TLS_IE_AHI16:
1164
0
    case R_OR1K_TLS_LE_AHI16:
1165
      /* Adjust the operand to match with a signed LO16.  */
1166
0
      value += 0x8000;
1167
0
      break;
1168
1169
0
    case R_OR1K_INSN_REL_26:
1170
0
      value -= place;
1171
      /* Diagnose mis-aligned branch targets.  */
1172
0
      if (value & 3)
1173
0
  status = bfd_reloc_dangerous;
1174
0
      break;
1175
1176
0
    case R_OR1K_PCREL_PG21:
1177
0
    case R_OR1K_GOT_PG21:
1178
0
    case R_OR1K_TLS_GD_PG21:
1179
0
    case R_OR1K_TLS_LDM_PG21:
1180
0
    case R_OR1K_TLS_IE_PG21:
1181
0
      value = (value & -8192) - (place & -8192);
1182
0
      break;
1183
1184
0
    case R_OR1K_LO13:
1185
0
    case R_OR1K_GOT_LO13:
1186
0
    case R_OR1K_TLS_GD_LO13:
1187
0
    case R_OR1K_TLS_LDM_LO13:
1188
0
    case R_OR1K_TLS_IE_LO13:
1189
0
    case R_OR1K_SLO13:
1190
0
      value &= 8191;
1191
0
      break;
1192
1193
0
    default:
1194
0
      if (howto->pc_relative)
1195
0
  value -= place;
1196
0
      break;
1197
0
    }
1198
1199
0
  status = bfd_check_overflow (howto->complain_on_overflow,
1200
0
             howto->bitsize,
1201
0
             howto->rightshift,
1202
0
             bfd_arch_bits_per_address (input_bfd),
1203
0
             value);
1204
0
  value >>= howto->rightshift;
1205
1206
  /* If we're overwriting the entire destination,
1207
     then no need to read the current contents.  */
1208
0
  if (size == 0 || howto->dst_mask == N_ONES (size))
1209
0
    x = 0;
1210
0
  else
1211
0
    {
1212
0
      BFD_ASSERT (size == 4);
1213
0
      x = bfd_get_32 (input_bfd, contents + offset);
1214
0
    }
1215
1216
0
  switch (howto->type)
1217
0
    {
1218
0
    case R_OR1K_SLO16:
1219
0
    case R_OR1K_GOTOFF_SLO16:
1220
0
    case R_OR1K_TLS_LE_SLO16:
1221
0
    case R_OR1K_SLO13:
1222
      /* The split imm16 field used for stores.  */
1223
0
      x = (x & ~0x3e007ff) | ((value & 0xf800) << 10) | (value & 0x7ff);
1224
0
      break;
1225
1226
0
    default:
1227
0
      {
1228
0
  bfd_vma fieldmask = howto->dst_mask;
1229
0
  value <<= howto->bitpos;
1230
0
  x = (x & ~fieldmask) | (value & fieldmask);
1231
0
      }
1232
0
      break;
1233
0
    }
1234
1235
  /* Put the relocated value back in the object file.  */
1236
0
  switch (size)
1237
0
    {
1238
0
    case 0:
1239
0
      break;
1240
0
    case 1:
1241
0
      bfd_put_8 (input_bfd, x, contents + offset);
1242
0
      break;
1243
0
    case 2:
1244
0
      bfd_put_16 (input_bfd, x, contents + offset);
1245
0
      break;
1246
0
    case 4:
1247
0
      bfd_put_32 (input_bfd, x, contents + offset);
1248
0
      break;
1249
0
#ifdef BFD64
1250
0
    case 8:
1251
0
      bfd_put_64 (input_bfd, x, contents + offset);
1252
0
      break;
1253
0
#endif
1254
0
    default:
1255
0
      _bfd_error_handler
1256
0
  (_("%pB: Cannot handle relocation value size of %d"),
1257
0
   input_bfd, size);
1258
0
      abort ();
1259
0
    }
1260
0
  return status;
1261
0
}
1262
1263
/* Relocate an Or1k ELF section.
1264
1265
   The RELOCATE_SECTION function is called by the new ELF backend linker
1266
   to handle the relocations for a section.
1267
1268
   The relocs are always passed as Rela structures; if the section
1269
   actually uses Rel structures, the r_addend field will always be
1270
   zero.
1271
1272
   This function is responsible for adjusting the section contents as
1273
   necessary, and (if using Rela relocs and generating a relocatable
1274
   output file) adjusting the reloc addend as necessary.
1275
1276
   This function does not have to worry about setting the reloc
1277
   address or the reloc symbol index.
1278
1279
   LOCAL_SYMS is a pointer to the swapped in local symbols.
1280
1281
   LOCAL_SECTIONS is an array giving the section in the input file
1282
   corresponding to the st_shndx field of each local symbol.
1283
1284
   The global hash table entry for the global symbols can be found
1285
   via elf_sym_hashes (input_bfd).
1286
1287
   When generating relocatable output, this function must handle
1288
   STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
1289
   going to be the section symbol corresponding to the output
1290
   section, which means that the addend must be adjusted
1291
   accordingly.  */
1292
1293
static int
1294
or1k_elf_relocate_section (struct bfd_link_info *info,
1295
         bfd *input_bfd,
1296
         asection *input_section,
1297
         bfd_byte *contents,
1298
         Elf_Internal_Rela *relocs,
1299
         Elf_Internal_Sym *local_syms,
1300
         asection **local_sections)
1301
0
{
1302
0
  Elf_Internal_Shdr *symtab_hdr;
1303
0
  struct elf_link_hash_entry **sym_hashes;
1304
0
  Elf_Internal_Rela *rel;
1305
0
  Elf_Internal_Rela *relend;
1306
0
  struct elf_or1k_link_hash_table *htab = or1k_elf_hash_table (info);
1307
0
  asection *sreloc;
1308
0
  bfd_vma *local_got_offsets;
1309
0
  asection *sgot, *splt;
1310
0
  bfd_vma plt_base, got_base, got_sym_value;
1311
0
  bool ret_val = true;
1312
0
  bool saw_gotha = false;
1313
1314
0
  if (htab == NULL)
1315
0
    return false;
1316
1317
0
  local_got_offsets = elf_local_got_offsets (input_bfd);
1318
1319
0
  sreloc = elf_section_data (input_section)->sreloc;
1320
1321
0
  splt = htab->root.splt;
1322
0
  plt_base = 0;
1323
0
  if (splt != NULL)
1324
0
    plt_base = splt->output_section->vma + splt->output_offset;
1325
1326
0
  sgot = htab->root.sgot;
1327
0
  got_sym_value = got_base = 0;
1328
0
  if (sgot != NULL)
1329
0
    {
1330
0
      struct elf_link_hash_entry *hgot = htab->root.hgot;
1331
0
      got_sym_value = (hgot->root.u.def.value
1332
0
           + hgot->root.u.def.section->output_section->vma
1333
0
           + hgot->root.u.def.section->output_offset);
1334
0
      got_base = sgot->output_section->vma + sgot->output_offset;
1335
0
    }
1336
1337
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
1338
0
  sym_hashes = elf_sym_hashes (input_bfd);
1339
0
  relend = relocs + input_section->reloc_count;
1340
1341
  /* Make a full scan for R_OR1K_GOT_AHI16, since it could be AFTER R_OR1K_GOT16.  */
1342
0
  for (rel = relocs; rel < relend; rel++)
1343
0
    {
1344
0
      int r_type = ELF32_R_TYPE (rel->r_info);
1345
0
      if (r_type==R_OR1K_GOT_AHI16)
1346
0
        {
1347
0
    saw_gotha = true;
1348
0
    break;
1349
0
        }
1350
0
    }
1351
1352
0
  for (rel = relocs; rel < relend; rel++)
1353
0
    {
1354
0
      reloc_howto_type *howto;
1355
0
      unsigned long r_symndx;
1356
0
      Elf_Internal_Sym *sym;
1357
0
      asection *sec;
1358
0
      struct elf_link_hash_entry *h;
1359
0
      bfd_vma relocation;
1360
0
      bfd_reloc_status_type r;
1361
0
      const char *name = NULL;
1362
0
      int r_type;
1363
1364
0
      r_type = ELF32_R_TYPE (rel->r_info);
1365
0
      r_symndx = ELF32_R_SYM (rel->r_info);
1366
1367
0
      if (r_type == R_OR1K_GNU_VTINHERIT
1368
0
    || r_type == R_OR1K_GNU_VTENTRY)
1369
0
  continue;
1370
1371
0
      if (r_type < 0 || r_type >= (int) R_OR1K_max)
1372
0
  {
1373
0
    _bfd_error_handler
1374
0
      (_("%pB: unknown relocation type %d"),
1375
0
       input_bfd, (int) r_type);
1376
0
    bfd_set_error (bfd_error_bad_value);
1377
0
    ret_val = false;
1378
0
    continue;
1379
0
  }
1380
1381
0
      howto = or1k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
1382
0
      h = NULL;
1383
0
      sym = NULL;
1384
0
      sec = NULL;
1385
1386
0
      if (r_symndx < symtab_hdr->sh_info)
1387
0
  {
1388
0
    sym = local_syms + r_symndx;
1389
0
    sec = local_sections[r_symndx];
1390
0
    relocation = _bfd_elf_rela_local_sym (info->output_bfd,
1391
0
            sym, &sec, rel);
1392
1393
0
    name = bfd_elf_string_from_elf_section
1394
0
      (input_bfd, symtab_hdr->sh_link, sym->st_name);
1395
0
    name = name == NULL ? bfd_section_name (sec) : name;
1396
0
  }
1397
0
      else
1398
0
  {
1399
0
    bool unresolved_reloc, warned, ignored;
1400
1401
0
    RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1402
0
           r_symndx, symtab_hdr, sym_hashes,
1403
0
           h, sec, relocation,
1404
0
           unresolved_reloc, warned, ignored);
1405
0
    name = h->root.root.string;
1406
0
  }
1407
1408
0
      if (sec != NULL && discarded_section (sec))
1409
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1410
0
           rel, 1, relend, R_OR1K_NONE,
1411
0
           howto, 0, contents);
1412
1413
0
      if (bfd_link_relocatable (info))
1414
0
  continue;
1415
1416
0
      switch (howto->type)
1417
0
  {
1418
0
  case R_OR1K_PLT26:
1419
0
  case R_OR1K_PLTA26:
1420
    /* If the call is not local, redirect the branch to the PLT.
1421
       Otherwise do nothing to send the branch to the symbol direct.  */
1422
0
    if (!SYMBOL_CALLS_LOCAL (info, h)
1423
0
        && h->plt.offset != (bfd_vma) -1)
1424
0
      relocation = plt_base + h->plt.offset;
1425
1426
    /* Addend should be zero.  */
1427
0
    if (rel->r_addend != 0)
1428
0
      {
1429
0
        _bfd_error_handler
1430
0
    (_("%pB: addend should be zero for plt relocations"),
1431
0
     input_bfd);
1432
0
        bfd_set_error (bfd_error_bad_value);
1433
0
        ret_val = false;
1434
0
      }
1435
0
    break;
1436
1437
0
  case R_OR1K_GOT_AHI16:
1438
0
  case R_OR1K_GOT16:
1439
0
  case R_OR1K_GOT_PG21:
1440
0
  case R_OR1K_GOT_LO13:
1441
0
    {
1442
0
      bfd_vma off;
1443
1444
      /* Relocation is to the entry for this symbol
1445
         in the global offset table.  */
1446
0
    BFD_ASSERT (sgot != NULL);
1447
0
    if (h != NULL)
1448
0
      {
1449
0
        bool dyn;
1450
1451
0
        off = h->got.offset;
1452
0
        BFD_ASSERT (off != (bfd_vma) -1);
1453
1454
0
        dyn = htab->root.dynamic_sections_created;
1455
0
        if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
1456
0
                 bfd_link_pic (info),
1457
0
                 h)
1458
0
      || (bfd_link_pic (info)
1459
0
          && SYMBOL_REFERENCES_LOCAL (info, h)))
1460
0
    {
1461
        /* This is actually a static link, or it is a -Bsymbolic
1462
           link and the symbol is defined locally, or the symbol
1463
           was forced to be local because of a version file.
1464
           We must initialize this entry in the GOT.  Since the
1465
           offset must always be a multiple of 4, we use the least
1466
           significant bit to record whether we have initialized
1467
           it already.
1468
1469
         When doing a dynamic link, we create a .rela.got
1470
         relocation entry to initialize the value.  This
1471
         is done in the finish_dynamic_symbol routine.  */
1472
0
      if ((off & 1) != 0)
1473
0
        off &= ~1;
1474
0
      else
1475
0
        {
1476
          /* Write entry in GOT.  */
1477
0
          bfd_put_32 (info->output_bfd, relocation,
1478
0
          sgot->contents + off);
1479
          /* Mark GOT entry as having been written.  */
1480
0
          h->got.offset |= 1;
1481
0
        }
1482
0
    }
1483
0
      }
1484
0
    else
1485
0
      {
1486
0
        bfd_byte *loc;
1487
1488
0
        BFD_ASSERT (local_got_offsets != NULL
1489
0
        && local_got_offsets[r_symndx] != (bfd_vma) -1);
1490
1491
        /* Get offset into GOT table.  */
1492
0
        off = local_got_offsets[r_symndx];
1493
1494
        /* The offset must always be a multiple of 4.  We use
1495
     the least significant bit to record whether we have
1496
     already processed this entry.  */
1497
0
        if ((off & 1) != 0)
1498
0
    off &= ~1;
1499
0
        else
1500
0
    {
1501
      /* Write entry in GOT.  */
1502
0
      bfd_put_32 (info->output_bfd, relocation,
1503
0
            sgot->contents + off);
1504
0
      if (bfd_link_pic (info))
1505
0
        {
1506
0
          asection *srelgot;
1507
0
          Elf_Internal_Rela outrel;
1508
1509
          /* We need to generate a R_OR1K_RELATIVE reloc
1510
       for the dynamic linker.  */
1511
0
          srelgot = htab->root.srelgot;
1512
0
          BFD_ASSERT (srelgot != NULL);
1513
1514
0
          outrel.r_offset = got_base + off;
1515
0
          outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
1516
0
          outrel.r_addend = relocation;
1517
0
          loc = srelgot->contents;
1518
0
          loc += (srelgot->reloc_count
1519
0
            * sizeof (Elf32_External_Rela));
1520
0
          bfd_elf32_swap_reloca_out (info->output_bfd, &outrel, loc);
1521
0
          ++srelgot->reloc_count;
1522
0
        }
1523
0
      local_got_offsets[r_symndx] |= 1;
1524
0
    }
1525
0
      }
1526
1527
      /* The GOT_PG21 and GOT_LO13 relocs are pc-relative,
1528
         while the GOT16 reloc is GOT relative.  */
1529
0
      relocation = got_base + off;
1530
0
      if (r_type == R_OR1K_GOT16
1531
0
    || r_type == R_OR1K_GOT_AHI16)
1532
0
        relocation -= got_sym_value;
1533
1534
      /* If we have a R_OR1K_GOT16 following a R_OR1K_GOT_AHI16
1535
         relocation we assume the code is doing the right thing to avoid
1536
         overflows.  */
1537
0
      if (r_type == R_OR1K_GOT16 && saw_gotha)
1538
0
        howto = &or1k_elf_got16_no_overflow_howto;
1539
1540
    /* Addend should be zero.  */
1541
0
    if (rel->r_addend != 0)
1542
0
      {
1543
0
        _bfd_error_handler
1544
0
    (_("%pB: addend should be zero for got relocations"),
1545
0
     input_bfd);
1546
0
        bfd_set_error (bfd_error_bad_value);
1547
0
        ret_val = false;
1548
0
      }
1549
0
    }
1550
0
    break;
1551
1552
0
  case R_OR1K_GOTOFF_LO16:
1553
0
  case R_OR1K_GOTOFF_HI16:
1554
0
  case R_OR1K_GOTOFF_AHI16:
1555
0
  case R_OR1K_GOTOFF_SLO16:
1556
    /* Relocation is offset from GOT.  */
1557
0
    BFD_ASSERT (sgot != NULL);
1558
0
    if (!SYMBOL_REFERENCES_LOCAL (info, h))
1559
0
      {
1560
0
        _bfd_error_handler
1561
0
    (_("%pB: gotoff relocation against dynamic symbol %s"),
1562
0
     input_bfd, h->root.root.string);
1563
0
        ret_val = false;
1564
0
        bfd_set_error (bfd_error_bad_value);
1565
0
      }
1566
0
    relocation -= got_sym_value;
1567
0
    break;
1568
1569
0
  case R_OR1K_INSN_REL_26:
1570
    /* For a non-shared link, these will reference plt or call the
1571
       version of actual object.  */
1572
0
    if (bfd_link_pic (info) && !SYMBOL_CALLS_LOCAL (info, h))
1573
0
      {
1574
0
        _bfd_error_handler
1575
0
    (_("%pB: pc-relative relocation against dynamic symbol %s"),
1576
0
     input_bfd, name);
1577
0
        ret_val = false;
1578
0
        bfd_set_error (bfd_error_bad_value);
1579
0
      }
1580
0
    break;
1581
1582
0
  case R_OR1K_PCREL_PG21:
1583
0
  case R_OR1K_LO13:
1584
0
  case R_OR1K_SLO13:
1585
    /* For a non-shared link, these will reference either the plt
1586
       or a .dynbss copy of the symbol.  */
1587
0
    if (bfd_link_pic (info) && !SYMBOL_REFERENCES_LOCAL (info, h))
1588
0
      {
1589
0
        _bfd_error_handler
1590
0
    (_("%pB: pc-relative relocation against dynamic symbol %s"),
1591
0
     input_bfd, name);
1592
0
        ret_val = false;
1593
0
        bfd_set_error (bfd_error_bad_value);
1594
0
      }
1595
0
    break;
1596
1597
0
  case R_OR1K_HI_16_IN_INSN:
1598
0
  case R_OR1K_LO_16_IN_INSN:
1599
0
  case R_OR1K_AHI16:
1600
0
  case R_OR1K_SLO16:
1601
0
    if (bfd_link_pic (info))
1602
0
      {
1603
0
        _bfd_error_handler
1604
0
    (_("%pB: non-pic relocation against symbol %s"),
1605
0
     input_bfd, name);
1606
0
        ret_val = false;
1607
0
        bfd_set_error (bfd_error_bad_value);
1608
0
      }
1609
0
    break;
1610
1611
0
  case R_OR1K_32:
1612
    /* R_OR1K_16? */
1613
0
    {
1614
      /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
1615
         from removed linkonce sections, or sections discarded by
1616
         a linker script.  */
1617
0
      if (r_symndx == STN_UNDEF
1618
0
    || (input_section->flags & SEC_ALLOC) == 0)
1619
0
        break;
1620
1621
      /* Emit a direct relocation if the symbol is dynamic,
1622
         or a RELATIVE reloc for shared objects.  We can omit
1623
         RELATIVE relocs to local undefweak symbols.  */
1624
0
      if (bfd_link_pic (info)
1625
0
    ? (h == NULL
1626
0
         || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1627
0
         || h->root.type != bfd_link_hash_undefweak)
1628
0
    : (h != NULL
1629
0
        && h->dynindx != -1
1630
0
        && !h->non_got_ref
1631
0
       && ((h->def_dynamic && !h->def_regular)
1632
0
      || h->root.type == bfd_link_hash_undefweak
1633
0
      || h->root.type == bfd_link_hash_undefined)))
1634
0
        {
1635
0
    Elf_Internal_Rela outrel;
1636
0
    bfd_byte *loc;
1637
0
    bool skip;
1638
1639
    /* When generating a shared object, these relocations
1640
       are copied into the output file to be resolved at run
1641
       time.  */
1642
1643
0
    BFD_ASSERT (sreloc != NULL);
1644
1645
0
    skip = false;
1646
1647
0
    outrel.r_offset =
1648
0
      _bfd_elf_section_offset (info->output_bfd, info,
1649
0
             input_section, rel->r_offset);
1650
0
    if (outrel.r_offset == (bfd_vma) -1)
1651
0
      skip = true;
1652
0
    else if (outrel.r_offset == (bfd_vma) -2)
1653
0
      skip = true;
1654
0
    outrel.r_offset += (input_section->output_section->vma
1655
0
            + input_section->output_offset);
1656
1657
0
    if (skip)
1658
0
      memset (&outrel, 0, sizeof outrel);
1659
0
    else if (SYMBOL_REFERENCES_LOCAL (info, h))
1660
0
      {
1661
0
        outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
1662
0
        outrel.r_addend = relocation + rel->r_addend;
1663
0
      }
1664
0
    else
1665
0
      {
1666
0
        BFD_ASSERT (h->dynindx != -1);
1667
0
        outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1668
0
        outrel.r_addend = rel->r_addend;
1669
0
      }
1670
1671
0
    loc = sreloc->contents;
1672
0
    loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1673
0
    bfd_elf32_swap_reloca_out (info->output_bfd, &outrel, loc);
1674
0
    break;
1675
0
        }
1676
0
      break;
1677
0
    }
1678
1679
0
  case R_OR1K_TLS_LDM_HI16:
1680
0
  case R_OR1K_TLS_LDM_LO16:
1681
0
  case R_OR1K_TLS_LDM_PG21:
1682
0
  case R_OR1K_TLS_LDM_LO13:
1683
0
  case R_OR1K_TLS_LDO_HI16:
1684
0
  case R_OR1K_TLS_LDO_LO16:
1685
    /* TODO: implement support for local dynamic.  */
1686
0
    BFD_FAIL ();
1687
0
    _bfd_error_handler
1688
0
      (_("%pB: support for local dynamic not implemented"),
1689
0
       input_bfd);
1690
0
    bfd_set_error (bfd_error_bad_value);
1691
0
    return false;
1692
1693
0
  case R_OR1K_TLS_GD_HI16:
1694
0
  case R_OR1K_TLS_GD_LO16:
1695
0
  case R_OR1K_TLS_GD_PG21:
1696
0
  case R_OR1K_TLS_GD_LO13:
1697
0
  case R_OR1K_TLS_IE_HI16:
1698
0
  case R_OR1K_TLS_IE_LO16:
1699
0
  case R_OR1K_TLS_IE_PG21:
1700
0
  case R_OR1K_TLS_IE_LO13:
1701
0
  case R_OR1K_TLS_IE_AHI16:
1702
0
    {
1703
0
      bfd_vma gotoff;
1704
0
      Elf_Internal_Rela rela;
1705
0
      asection *srelgot;
1706
0
      bfd_byte *loc;
1707
0
      bool dynamic;
1708
0
      int indx = 0;
1709
0
      unsigned char tls_type;
1710
1711
0
      srelgot = htab->root.srelgot;
1712
1713
      /* Mark as TLS related GOT entry by setting
1714
         bit 2 to indcate TLS and bit 1 to indicate GOT.  */
1715
0
      if (h != NULL)
1716
0
        {
1717
0
    gotoff = h->got.offset;
1718
0
    tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
1719
0
    h->got.offset |= 3;
1720
0
        }
1721
0
      else
1722
0
        {
1723
0
    unsigned char *local_tls_type;
1724
1725
0
    gotoff = local_got_offsets[r_symndx];
1726
0
    local_tls_type = (unsigned char *) elf_or1k_local_tls_type (input_bfd);
1727
0
    tls_type = local_tls_type == NULL ? TLS_NONE
1728
0
              : local_tls_type[r_symndx];
1729
0
    local_got_offsets[r_symndx] |= 3;
1730
0
        }
1731
1732
      /* Only process the relocation once.  */
1733
0
      if ((gotoff & 1) != 0)
1734
0
        {
1735
0
    gotoff += or1k_initial_exec_offset (howto, tls_type);
1736
1737
    /* The PG21 and LO13 relocs are pc-relative, while the
1738
       rest are GOT relative.  */
1739
0
    relocation = got_base + (gotoff & ~3);
1740
0
    if (!(r_type == R_OR1K_TLS_GD_PG21
1741
0
        || r_type == R_OR1K_TLS_GD_LO13
1742
0
        || r_type == R_OR1K_TLS_IE_PG21
1743
0
        || r_type == R_OR1K_TLS_IE_LO13))
1744
0
      relocation -= got_sym_value;
1745
0
    break;
1746
0
        }
1747
1748
0
      BFD_ASSERT (elf_hash_table (info)->hgot == NULL
1749
0
      || elf_hash_table (info)->hgot->root.u.def.value == 0);
1750
1751
0
      if (h != NULL)
1752
0
        {
1753
0
    bool dyn = htab->root.dynamic_sections_created;
1754
0
    bool pic = bfd_link_pic (info);
1755
1756
0
    if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, pic, h)
1757
0
        && (!pic || !SYMBOL_REFERENCES_LOCAL (info, h)))
1758
0
      indx = h->dynindx;
1759
0
        }
1760
1761
      /* Dynamic entries will require relocations.  If we do not need
1762
         them we will just use the default R_OR1K_NONE and
1763
         not set anything.  */
1764
0
      dynamic = (bfd_link_pic (info) || indx != 0)
1765
0
           && (h == NULL
1766
0
         || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1767
0
         || h->root.type != bfd_link_hash_undefweak);
1768
1769
      /* Shared GD.  */
1770
0
      if (dynamic && ((tls_type & TLS_GD) != 0))
1771
0
        {
1772
0
    int i;
1773
1774
    /* Add DTPMOD and DTPOFF GOT and rela entries.  */
1775
0
    for (i = 0; i < 2; ++i)
1776
0
      {
1777
0
        BFD_ASSERT (srelgot->contents != NULL);
1778
1779
0
        rela.r_offset = got_base + gotoff + i*4;
1780
0
        if (h != NULL && h->dynindx != -1)
1781
0
          {
1782
0
      rela.r_info = ELF32_R_INFO (h->dynindx,
1783
0
          (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
1784
0
      rela.r_addend = 0;
1785
0
          }
1786
0
        else
1787
0
          {
1788
0
      rela.r_info = ELF32_R_INFO (0,
1789
0
          (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
1790
0
      rela.r_addend =
1791
0
          (i == 0 ? 0 : tpoff (info, relocation, dynamic));
1792
0
          }
1793
1794
0
        loc = srelgot->contents;
1795
0
        loc += (srelgot->reloc_count++
1796
0
          * sizeof (Elf32_External_Rela));
1797
1798
0
        bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1799
0
        bfd_put_32 (info->output_bfd, 0,
1800
0
        sgot->contents + gotoff + i*4);
1801
0
      }
1802
0
        }
1803
      /* Static GD.  */
1804
0
      else if ((tls_type & TLS_GD) != 0)
1805
0
        {
1806
0
    bfd_put_32 (info->output_bfd, 1, sgot->contents + gotoff);
1807
0
    bfd_put_32 (info->output_bfd, tpoff (info, relocation, dynamic),
1808
0
        sgot->contents + gotoff + 4);
1809
0
        }
1810
1811
0
      gotoff += or1k_initial_exec_offset (howto, tls_type);
1812
1813
      /* Shared IE.  */
1814
0
      if (dynamic && ((tls_type & TLS_IE) != 0))
1815
0
        {
1816
0
    BFD_ASSERT (srelgot->contents != NULL);
1817
1818
    /* Add TPOFF GOT and rela entries.  */
1819
0
    rela.r_offset = got_base + gotoff;
1820
0
    if (h != NULL && h->dynindx != -1)
1821
0
      {
1822
0
        rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_TLS_TPOFF);
1823
0
        rela.r_addend = 0;
1824
0
      }
1825
0
    else
1826
0
      {
1827
0
        rela.r_info = ELF32_R_INFO (0, R_OR1K_TLS_TPOFF);
1828
0
        rela.r_addend = tpoff (info, relocation, dynamic);
1829
0
      }
1830
1831
0
    loc = srelgot->contents;
1832
0
    loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
1833
1834
0
    bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1835
0
    bfd_put_32 (info->output_bfd, 0, sgot->contents + gotoff);
1836
0
        }
1837
      /* Static IE.  */
1838
0
      else if ((tls_type & TLS_IE) != 0)
1839
0
        bfd_put_32 (info->output_bfd, tpoff (info, relocation, dynamic),
1840
0
        sgot->contents + gotoff);
1841
1842
      /* The PG21 and LO13 relocs are pc-relative, while the
1843
         rest are GOT relative.  */
1844
0
      relocation = got_base + gotoff;
1845
0
      if (!(r_type == R_OR1K_TLS_GD_PG21
1846
0
      || r_type == R_OR1K_TLS_GD_LO13
1847
0
      || r_type == R_OR1K_TLS_IE_PG21
1848
0
      || r_type == R_OR1K_TLS_IE_LO13))
1849
0
        relocation -= got_sym_value;
1850
0
    }
1851
0
    break;
1852
1853
0
  case R_OR1K_TLS_LE_HI16:
1854
0
  case R_OR1K_TLS_LE_LO16:
1855
0
  case R_OR1K_TLS_LE_AHI16:
1856
0
  case R_OR1K_TLS_LE_SLO16:
1857
    /* Relocation is offset from TP.  */
1858
0
    relocation = tpoff (info, relocation, 0);
1859
0
    break;
1860
1861
0
  case R_OR1K_TLS_DTPMOD:
1862
0
  case R_OR1K_TLS_DTPOFF:
1863
0
  case R_OR1K_TLS_TPOFF:
1864
    /* These are resolved dynamically on load and shouldn't
1865
       be used as linker input.  */
1866
0
    BFD_FAIL ();
1867
0
    _bfd_error_handler
1868
0
      (_("%pB: will not resolve runtime TLS relocation"),
1869
0
       input_bfd);
1870
0
    bfd_set_error (bfd_error_bad_value);
1871
0
    return false;
1872
1873
0
  default:
1874
0
    break;
1875
0
  }
1876
1877
0
      r = or1k_final_link_relocate (howto, input_bfd, input_section, contents,
1878
0
            rel->r_offset, relocation + rel->r_addend);
1879
1880
0
      if (r != bfd_reloc_ok)
1881
0
  {
1882
0
    const char *msg = NULL;
1883
1884
0
    switch (r)
1885
0
      {
1886
0
      case bfd_reloc_overflow:
1887
0
        (*info->callbacks->reloc_overflow)
1888
0
    (info, (h ? &h->root : NULL), name, howto->name,
1889
0
     (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1890
0
        break;
1891
1892
0
      case bfd_reloc_undefined:
1893
0
        (*info->callbacks->undefined_symbol)
1894
0
    (info, name, input_bfd, input_section, rel->r_offset, true);
1895
0
        break;
1896
1897
0
      case bfd_reloc_outofrange:
1898
0
        msg = _("internal error: out of range error");
1899
0
        break;
1900
1901
0
      case bfd_reloc_notsupported:
1902
0
        msg = _("internal error: unsupported relocation error");
1903
0
        break;
1904
1905
0
      case bfd_reloc_dangerous:
1906
0
        msg = _("internal error: dangerous relocation");
1907
0
        break;
1908
1909
0
      default:
1910
0
        msg = _("internal error: unknown error");
1911
0
        break;
1912
0
      }
1913
1914
0
    if (msg)
1915
0
      (*info->callbacks->warning) (info, msg, name, input_bfd,
1916
0
           input_section, rel->r_offset);
1917
0
  }
1918
0
    }
1919
1920
0
  return ret_val;
1921
0
}
1922
1923
/* Return the section that should be marked against GC for a given
1924
   relocation.  */
1925
1926
static asection *
1927
or1k_elf_gc_mark_hook (asection *sec,
1928
           struct bfd_link_info *info,
1929
           struct elf_reloc_cookie *cookie,
1930
           struct elf_link_hash_entry *h,
1931
           unsigned int symndx)
1932
0
{
1933
0
  if (h != NULL)
1934
0
    switch (ELF32_R_TYPE (cookie->rel->r_info))
1935
0
      {
1936
0
      case R_OR1K_GNU_VTINHERIT:
1937
0
      case R_OR1K_GNU_VTENTRY:
1938
0
  return NULL;
1939
0
      }
1940
1941
0
  return _bfd_elf_gc_mark_hook (sec, info, cookie, h, symndx);
1942
0
}
1943
1944
/* Look through the relocs for a section during the first phase.  */
1945
1946
static bool
1947
or1k_elf_check_relocs (bfd *abfd,
1948
           struct bfd_link_info *info,
1949
           asection *sec,
1950
           const Elf_Internal_Rela *relocs)
1951
0
{
1952
0
  Elf_Internal_Shdr *symtab_hdr;
1953
0
  struct elf_link_hash_entry **sym_hashes;
1954
0
  const Elf_Internal_Rela *rel;
1955
1956
0
  const Elf_Internal_Rela *rel_end;
1957
0
  struct elf_or1k_link_hash_table *htab;
1958
0
  bfd *dynobj;
1959
0
  asection *sreloc = NULL;
1960
1961
0
  if (bfd_link_relocatable (info))
1962
0
    return true;
1963
1964
0
  symtab_hdr = &elf_symtab_hdr (abfd);
1965
0
  sym_hashes = elf_sym_hashes (abfd);
1966
1967
0
  htab = or1k_elf_hash_table (info);
1968
0
  if (htab == NULL)
1969
0
    return false;
1970
1971
0
  dynobj = htab->root.dynobj;
1972
1973
0
  rel_end = relocs + sec->reloc_count;
1974
0
  for (rel = relocs; rel < rel_end; rel++)
1975
0
    {
1976
0
      struct elf_link_hash_entry *h;
1977
0
      unsigned long r_symndx;
1978
0
      unsigned char tls_type;
1979
0
      int r_type;
1980
1981
0
      r_symndx = ELF32_R_SYM (rel->r_info);
1982
0
      if (r_symndx < symtab_hdr->sh_info)
1983
0
  h = NULL;
1984
0
      else
1985
0
  {
1986
0
    h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1987
0
    while (h->root.type == bfd_link_hash_indirect
1988
0
     || h->root.type == bfd_link_hash_warning)
1989
0
      h = (struct elf_link_hash_entry *) h->root.u.i.link;
1990
0
  }
1991
1992
0
      r_type = ELF32_R_TYPE (rel->r_info);
1993
0
      switch (r_type)
1994
0
  {
1995
0
  case R_OR1K_TLS_GD_HI16:
1996
0
  case R_OR1K_TLS_GD_LO16:
1997
0
  case R_OR1K_TLS_GD_PG21:
1998
0
  case R_OR1K_TLS_GD_LO13:
1999
0
    tls_type = TLS_GD;
2000
0
    break;
2001
0
  case R_OR1K_TLS_LDM_HI16:
2002
0
  case R_OR1K_TLS_LDM_LO16:
2003
0
  case R_OR1K_TLS_LDM_PG21:
2004
0
  case R_OR1K_TLS_LDM_LO13:
2005
0
  case R_OR1K_TLS_LDO_HI16:
2006
0
  case R_OR1K_TLS_LDO_LO16:
2007
0
    tls_type = TLS_LD;
2008
0
    break;
2009
0
  case R_OR1K_TLS_IE_HI16:
2010
0
  case R_OR1K_TLS_IE_LO16:
2011
0
  case R_OR1K_TLS_IE_PG21:
2012
0
  case R_OR1K_TLS_IE_LO13:
2013
0
  case R_OR1K_TLS_IE_AHI16:
2014
0
    tls_type = TLS_IE;
2015
0
    break;
2016
0
  case R_OR1K_TLS_LE_HI16:
2017
0
  case R_OR1K_TLS_LE_LO16:
2018
0
  case R_OR1K_TLS_LE_AHI16:
2019
0
  case R_OR1K_TLS_LE_SLO16:
2020
0
    tls_type = TLS_LE;
2021
0
    break;
2022
0
  default:
2023
0
    tls_type = TLS_NONE;
2024
0
  }
2025
2026
      /* Record TLS type.  */
2027
0
      if (h != NULL)
2028
0
    ((struct elf_or1k_link_hash_entry *) h)->tls_type |= tls_type;
2029
0
      else
2030
0
  {
2031
0
    unsigned char *local_tls_type;
2032
2033
    /* This is a TLS type record for a local symbol.  */
2034
0
    local_tls_type = (unsigned char *) elf_or1k_local_tls_type (abfd);
2035
0
    if (local_tls_type == NULL)
2036
0
      {
2037
0
        bfd_size_type size;
2038
2039
0
        size = symtab_hdr->sh_info;
2040
0
        local_tls_type = bfd_zalloc (abfd, size);
2041
0
        if (local_tls_type == NULL)
2042
0
    return false;
2043
0
        elf_or1k_local_tls_type (abfd) = local_tls_type;
2044
0
      }
2045
0
    local_tls_type[r_symndx] |= tls_type;
2046
0
  }
2047
2048
0
      switch (r_type)
2049
0
  {
2050
    /* This relocation describes the C++ object vtable hierarchy.
2051
       Reconstruct it for later use during GC.  */
2052
0
  case R_OR1K_GNU_VTINHERIT:
2053
0
    if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2054
0
      return false;
2055
0
    break;
2056
2057
    /* This relocation describes which C++ vtable entries are actually
2058
       used.  Record for later use during GC.  */
2059
0
  case R_OR1K_GNU_VTENTRY:
2060
0
    if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2061
0
      return false;
2062
0
    break;
2063
2064
    /* This relocation requires .plt entry.  */
2065
0
  case R_OR1K_PLTA26:
2066
0
    htab->saw_plta = true;
2067
    /* FALLTHRU */
2068
0
  case R_OR1K_PLT26:
2069
0
    if (h != NULL)
2070
0
      {
2071
0
        h->needs_plt = 1;
2072
0
        h->plt.refcount += 1;
2073
0
      }
2074
0
    break;
2075
2076
0
  case R_OR1K_GOT_AHI16:
2077
0
  case R_OR1K_GOT16:
2078
0
  case R_OR1K_GOT_PG21:
2079
0
  case R_OR1K_GOT_LO13:
2080
0
  case R_OR1K_TLS_GD_HI16:
2081
0
  case R_OR1K_TLS_GD_LO16:
2082
0
  case R_OR1K_TLS_GD_PG21:
2083
0
  case R_OR1K_TLS_GD_LO13:
2084
0
  case R_OR1K_TLS_IE_HI16:
2085
0
  case R_OR1K_TLS_IE_LO16:
2086
0
  case R_OR1K_TLS_IE_PG21:
2087
0
  case R_OR1K_TLS_IE_LO13:
2088
0
  case R_OR1K_TLS_IE_AHI16:
2089
0
        if (h != NULL)
2090
0
    h->got.refcount += 1;
2091
0
        else
2092
0
    {
2093
0
      bfd_signed_vma *local_got_refcounts;
2094
2095
      /* This is a global offset table entry for a local symbol.  */
2096
0
      local_got_refcounts = elf_local_got_refcounts (abfd);
2097
0
      if (local_got_refcounts == NULL)
2098
0
        {
2099
0
          bfd_size_type size;
2100
2101
0
          size = symtab_hdr->sh_info;
2102
0
          size *= sizeof (bfd_signed_vma);
2103
0
          local_got_refcounts = bfd_zalloc (abfd, size);
2104
0
          if (local_got_refcounts == NULL)
2105
0
      return false;
2106
0
          elf_local_got_refcounts (abfd) = local_got_refcounts;
2107
0
        }
2108
0
      local_got_refcounts[r_symndx] += 1;
2109
0
    }
2110
    /* FALLTHRU */
2111
2112
0
  case R_OR1K_GOTOFF_HI16:
2113
0
  case R_OR1K_GOTOFF_LO16:
2114
0
  case R_OR1K_GOTOFF_AHI16:
2115
0
  case R_OR1K_GOTOFF_SLO16:
2116
0
    if (htab->root.sgot == NULL)
2117
0
      {
2118
0
        if (dynobj == NULL)
2119
0
    {
2120
0
      dynobj = _bfd_elf_link_dynobj (info);
2121
0
      if (dynobj == NULL)
2122
0
        return false;
2123
0
    }
2124
0
        if (!_bfd_elf_create_got_section (dynobj, info))
2125
0
    return false;
2126
0
      }
2127
0
    break;
2128
2129
0
  case R_OR1K_INSN_REL_26:
2130
0
  case R_OR1K_HI_16_IN_INSN:
2131
0
  case R_OR1K_LO_16_IN_INSN:
2132
0
  case R_OR1K_AHI16:
2133
0
  case R_OR1K_SLO16:
2134
0
  case R_OR1K_32:
2135
0
  case R_OR1K_PCREL_PG21:
2136
0
  case R_OR1K_LO13:
2137
0
  case R_OR1K_SLO13:
2138
0
    {
2139
0
      if (h != NULL && !bfd_link_pic (info))
2140
0
        {
2141
    /* We may need a copy reloc.  */
2142
0
    h->non_got_ref = 1;
2143
2144
    /* We may also need a .plt entry.  */
2145
0
    h->plt.refcount += 1;
2146
0
    if (r_type != R_OR1K_INSN_REL_26)
2147
0
      h->pointer_equality_needed = 1;
2148
0
        }
2149
2150
      /* If we are creating a shared library, and this is a reloc
2151
         against a global symbol, or a non PC relative reloc
2152
         against a local symbol, then we need to copy the reloc
2153
         into the shared library.  However, if we are linking with
2154
         -Bsymbolic, we do not need to copy a reloc against a
2155
         global symbol which is defined in an object we are
2156
         including in the link (i.e., DEF_REGULAR is set).  At
2157
         this point we have not seen all the input files, so it is
2158
         possible that DEF_REGULAR is not set now but will be set
2159
         later (it is never cleared).  In case of a weak definition,
2160
         DEF_REGULAR may be cleared later by a strong definition in
2161
         a shared library.  We account for that possibility below by
2162
         storing information in the relocs_copied field of the hash
2163
         table entry.  A similar situation occurs when creating
2164
         shared libraries and symbol visibility changes render the
2165
         symbol local.
2166
2167
         If on the other hand, we are creating an executable, we
2168
         may need to keep relocations for symbols satisfied by a
2169
         dynamic library if we manage to avoid copy relocs for the
2170
         symbol.  */
2171
2172
0
      if ((bfd_link_pic (info)
2173
0
     && (sec->flags & SEC_ALLOC) != 0
2174
0
     && (r_type != R_OR1K_INSN_REL_26
2175
0
         || (h != NULL
2176
0
       && (!SYMBOLIC_BIND (info, h)
2177
0
           || h->root.type == bfd_link_hash_defweak
2178
0
           || !h->def_regular))))
2179
0
    || (!bfd_link_pic (info)
2180
0
        && (sec->flags & SEC_ALLOC) != 0
2181
0
        && h != NULL
2182
0
        && (h->root.type == bfd_link_hash_defweak
2183
0
      || !h->def_regular)))
2184
0
        {
2185
0
    struct elf_dyn_relocs *sec_relocs;
2186
0
    struct elf_dyn_relocs **head;
2187
2188
    /* When creating a shared object, we must copy these
2189
       relocs into the output file.  We create a reloc
2190
       section in dynobj and make room for the reloc.  */
2191
0
    if (sreloc == NULL)
2192
0
      {
2193
0
        const char *name;
2194
0
        unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
2195
0
        unsigned int shnam = _bfd_elf_single_rel_hdr (sec)->sh_name;
2196
2197
0
        name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
2198
0
        if (name == NULL)
2199
0
          return false;
2200
2201
0
        if (!startswith (name, ".rela")
2202
0
      || strcmp (bfd_section_name (sec), name + 5) != 0)
2203
0
          {
2204
0
      _bfd_error_handler
2205
        /* xgettext:c-format */
2206
0
        (_("%pB: bad relocation section name `%s\'"),
2207
0
         abfd, name);
2208
0
          }
2209
2210
0
        if (dynobj == NULL)
2211
0
          {
2212
0
      dynobj = _bfd_elf_link_dynobj (info);
2213
0
      if (dynobj == NULL)
2214
0
        return false;
2215
0
          }
2216
2217
0
        sreloc = bfd_get_section_by_name (dynobj, name);
2218
0
        if (sreloc == NULL)
2219
0
          {
2220
0
      sreloc = _bfd_elf_make_dynamic_reloc_section
2221
0
        (sec, dynobj, 2, abfd, /*rela?*/ true);
2222
2223
0
      if (sreloc == NULL)
2224
0
        return false;
2225
0
          }
2226
0
        elf_section_data (sec)->sreloc = sreloc;
2227
0
      }
2228
2229
    /* If this is a global symbol, we count the number of
2230
       relocations we need for this symbol.  */
2231
0
    if (h != NULL)
2232
0
      head = &h->dyn_relocs;
2233
0
    else
2234
0
      {
2235
        /* Track dynamic relocs needed for local syms too.
2236
           We really need local syms available to do this
2237
           easily.  Oh well.  */
2238
2239
0
        asection *s;
2240
0
        Elf_Internal_Sym *isym;
2241
0
        void *vpp;
2242
2243
0
        isym = bfd_sym_from_r_symndx (&htab->root.sym_cache,
2244
0
              abfd, r_symndx);
2245
0
        if (isym == NULL)
2246
0
          return false;
2247
2248
0
        s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2249
0
        if (s == NULL)
2250
0
          return false;
2251
2252
0
        vpp = &elf_section_data (s)->local_dynrel;
2253
0
        head = (struct elf_dyn_relocs **) vpp;
2254
0
      }
2255
2256
0
    sec_relocs = *head;
2257
    /* Allocate this sections dynamic reolcations structure if this
2258
       is a new section.  */
2259
0
    if (sec_relocs == NULL || sec_relocs->sec != sec)
2260
0
      {
2261
0
        size_t amt = sizeof *sec_relocs;
2262
0
        sec_relocs = ((struct elf_dyn_relocs *)
2263
0
          bfd_alloc (htab->root.dynobj, amt));
2264
0
        if (sec_relocs == NULL)
2265
0
          return false;
2266
0
        sec_relocs->next = *head;
2267
0
        *head = sec_relocs;
2268
0
        sec_relocs->sec = sec;
2269
0
        sec_relocs->count = 0;
2270
0
        sec_relocs->pc_count = 0;
2271
0
      }
2272
2273
0
    sec_relocs->count += 1;
2274
0
    if (r_type == R_OR1K_INSN_REL_26)
2275
0
      sec_relocs->pc_count += 1;
2276
0
        }
2277
0
    }
2278
0
    break;
2279
0
  }
2280
0
    }
2281
2282
0
  return true;
2283
0
}
2284
2285
static void
2286
or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
2287
          unsigned insns[], size_t insn_count)
2288
0
{
2289
0
  unsigned nodelay = elf_elfheader (output_bfd)->e_flags & EF_OR1K_NODELAY;
2290
0
  unsigned output_insns[PLT_MAX_INSN_COUNT];
2291
2292
  /* Copy instructions into the output buffer.  */
2293
0
  for (size_t i = 0; i < insn_count; i++)
2294
0
    output_insns[i] = insns[i];
2295
2296
  /* Honor the no-delay-slot setting.  */
2297
0
  if (insns[insn_count-1] == OR1K_NOP)
2298
0
    {
2299
0
      unsigned slot1, slot2;
2300
2301
0
      if (nodelay)
2302
0
  slot1 = insns[insn_count-2], slot2 = insnj;
2303
0
      else
2304
0
  slot1 = insnj, slot2 = insns[insn_count-2];
2305
2306
0
      output_insns[insn_count-2] = slot1;
2307
0
      output_insns[insn_count-1] = slot2;
2308
0
      output_insns[insn_count]   = OR1K_NOP;
2309
0
    }
2310
0
  else
2311
0
    {
2312
0
      unsigned slot1, slot2;
2313
2314
0
      if (nodelay)
2315
0
  slot1 = insns[insn_count-1], slot2 = insnj;
2316
0
      else
2317
0
  slot1 = insnj, slot2 = insns[insn_count-1];
2318
2319
0
      output_insns[insn_count-1] = slot1;
2320
0
      output_insns[insn_count]   = slot2;
2321
0
    }
2322
2323
  /* Write out the output buffer.  */
2324
0
  for (size_t i = 0; i < (insn_count+1); i++)
2325
0
    bfd_put_32 (output_bfd, output_insns[i], contents + (i*4));
2326
0
}
2327
2328
/* Finish up the dynamic sections.  */
2329
2330
static bool
2331
or1k_elf_finish_dynamic_sections (struct bfd_link_info *info,
2332
          bfd_byte *buf ATTRIBUTE_UNUSED)
2333
0
{
2334
0
  bfd *dynobj;
2335
0
  asection *sdyn, *sgot;
2336
0
  struct elf_or1k_link_hash_table *htab;
2337
2338
0
  htab = or1k_elf_hash_table (info);
2339
0
  if (htab == NULL)
2340
0
    return false;
2341
2342
0
  dynobj = htab->root.dynobj;
2343
2344
0
  sgot = htab->root.sgotplt;
2345
0
  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2346
2347
0
  if (htab->root.dynamic_sections_created)
2348
0
    {
2349
0
      asection *splt;
2350
0
      Elf32_External_Dyn *dyncon, *dynconend;
2351
2352
0
      BFD_ASSERT (sgot != NULL && sdyn != NULL);
2353
2354
0
      dyncon = (Elf32_External_Dyn *) sdyn->contents;
2355
0
      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
2356
2357
0
      for (; dyncon < dynconend; dyncon++)
2358
0
  {
2359
0
    Elf_Internal_Dyn dyn;
2360
0
    asection *s;
2361
2362
0
    bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2363
2364
0
    switch (dyn.d_tag)
2365
0
      {
2366
0
      default:
2367
0
        continue;
2368
2369
0
      case DT_PLTGOT:
2370
0
        s = htab->root.sgotplt;
2371
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2372
0
        break;
2373
2374
0
      case DT_JMPREL:
2375
0
        s = htab->root.srelplt;
2376
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2377
0
        break;
2378
2379
0
      case DT_PLTRELSZ:
2380
0
        s = htab->root.srelplt;
2381
0
        dyn.d_un.d_val = s->size;
2382
0
        break;
2383
0
      }
2384
0
    bfd_elf32_swap_dyn_out (info->output_bfd, &dyn, dyncon);
2385
0
  }
2386
2387
2388
      /* Fill in the first entry in the procedure linkage table.  */
2389
0
      splt = htab->root.splt;
2390
0
      if (splt && splt->size > 0)
2391
0
  {
2392
0
    unsigned plt[PLT_MAX_INSN_COUNT];
2393
0
    size_t plt_insn_count = 3;
2394
0
    bfd_vma got_addr = sgot->output_section->vma + sgot->output_offset;
2395
2396
    /* Note we force 16 byte alignment on the .got, so that
2397
       the movhi/adrp can be shared between the two loads.  */
2398
2399
0
    if (htab->saw_plta)
2400
0
      {
2401
0
        bfd_vma pc = splt->output_section->vma + splt->output_offset;
2402
0
        unsigned pa = ((got_addr >> 13) - (pc >> 13)) & 0x1fffff;
2403
0
        unsigned po = got_addr & 0x1fff;
2404
0
        plt[0] = OR1K_ADRP(12) | pa;
2405
0
        plt[1] = OR1K_LWZ(15,12) | (po + 8);
2406
0
        plt[2] = OR1K_LWZ(12,12) | (po + 4);
2407
0
      }
2408
0
    else if (bfd_link_pic (info))
2409
0
      {
2410
0
        plt[0] = OR1K_LWZ(15, 16) | 8; /* .got+8 */
2411
0
        plt[1] = OR1K_LWZ(12, 16) | 4; /* .got+4 */
2412
0
        plt[2] = OR1K_NOP;
2413
0
      }
2414
0
    else
2415
0
      {
2416
0
        unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
2417
0
        unsigned lo = got_addr & 0xffff;
2418
0
        plt[0] = OR1K_MOVHI(12) | ha;
2419
0
        plt[1] = OR1K_LWZ(15,12) | (lo + 8);
2420
0
        plt[2] = OR1K_LWZ(12,12) | (lo + 4);
2421
0
      }
2422
2423
0
    or1k_write_plt_entry (info->output_bfd, splt->contents, OR1K_JR(15),
2424
0
        plt, plt_insn_count);
2425
2426
0
    elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
2427
0
  }
2428
0
    }
2429
2430
  /* Set the first entry in the global offset table to the address of
2431
     the dynamic section.  */
2432
0
  if (sgot && sgot->size > 0)
2433
0
    {
2434
0
      if (sdyn == NULL)
2435
0
  bfd_put_32 (info->output_bfd, 0, sgot->contents);
2436
0
      else
2437
0
  bfd_put_32 (info->output_bfd,
2438
0
        sdyn->output_section->vma + sdyn->output_offset,
2439
0
        sgot->contents);
2440
0
      elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2441
0
    }
2442
2443
0
  if (htab->root.sgot && htab->root.sgot->size > 0)
2444
0
    elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize = 4;
2445
2446
0
  return true;
2447
0
}
2448
2449
/* Finish up dynamic symbol handling.  We set the contents of various
2450
   dynamic sections here.  */
2451
2452
static bool
2453
or1k_elf_finish_dynamic_symbol (struct bfd_link_info *info,
2454
        struct elf_link_hash_entry *h,
2455
        Elf_Internal_Sym *sym)
2456
0
{
2457
0
  struct elf_or1k_link_hash_table *htab;
2458
0
  bfd_byte *loc;
2459
2460
0
  htab = or1k_elf_hash_table (info);
2461
2462
0
  if (h->plt.offset != (bfd_vma) -1)
2463
0
    {
2464
0
      unsigned int plt[PLT_MAX_INSN_COUNT];
2465
0
      size_t plt_insn_count = 3;
2466
0
      asection *splt;
2467
0
      asection *sgot;
2468
0
      asection *srela;
2469
0
      bfd_vma plt_base_addr;
2470
0
      bfd_vma plt_addr;
2471
0
      bfd_vma plt_index;
2472
0
      bfd_vma plt_reloc;
2473
0
      bfd_vma got_base_addr;
2474
0
      bfd_vma got_offset;
2475
0
      bfd_vma got_addr;
2476
0
      Elf_Internal_Rela rela;
2477
0
      bool large_plt_entry;
2478
2479
      /* This symbol has an entry in the procedure linkage table.  Set
2480
   it up.  */
2481
0
      BFD_ASSERT (h->dynindx != -1);
2482
2483
0
      splt = htab->root.splt;
2484
0
      sgot = htab->root.sgotplt;
2485
0
      srela = htab->root.srelplt;
2486
0
      BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
2487
2488
0
      plt_base_addr = splt->output_section->vma + splt->output_offset;
2489
0
      got_base_addr = sgot->output_section->vma + sgot->output_offset;
2490
2491
      /* Get the index in the procedure linkage table which
2492
   corresponds to this symbol.  This is the index of this symbol
2493
   in all the symbols for which we are making plt entries.  The
2494
   first entry in the procedure linkage table is reserved.  */
2495
0
      plt_index = ((struct elf_or1k_link_hash_entry *) h)->plt_index;
2496
0
      plt_addr = plt_base_addr + h->plt.offset;
2497
0
      plt_reloc = plt_index * sizeof (Elf32_External_Rela);
2498
2499
0
      large_plt_entry = (elf_or1k_plt_entry_size (plt_index)
2500
0
       == PLT_ENTRY_SIZE_LARGE);
2501
2502
      /* Get the offset into the .got table of the entry that
2503
  corresponds to this function.  Each .got entry is 4 bytes.
2504
  The first three are reserved.  */
2505
0
      got_offset = (plt_index + 3) * 4;
2506
0
      got_addr = got_base_addr + got_offset;
2507
2508
      /* Fill in the entry in the procedure linkage table.  */
2509
0
      if (htab->saw_plta)
2510
0
  {
2511
0
    unsigned pa = ((got_addr >> 13) - (plt_addr >> 13)) & 0x1fffff;
2512
0
    unsigned po = (got_addr & 0x1fff);
2513
0
    plt[0] = OR1K_ADRP(12) | pa;
2514
0
    plt[1] = OR1K_LWZ(12,12) | po;
2515
0
    plt[2] = OR1K_ORI0(11) | plt_reloc;
2516
0
  }
2517
0
      else if (bfd_link_pic (info))
2518
0
  {
2519
0
    if (large_plt_entry)
2520
0
      {
2521
0
        unsigned gotha = ((got_offset + 0x8000) >> 16) & 0xffff;
2522
0
        unsigned got = got_offset & 0xffff;
2523
0
        unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
2524
0
        unsigned pltrello = plt_reloc & 0xffff;
2525
2526
0
        plt[0] = OR1K_MOVHI(12) | gotha;
2527
0
        plt[1] = OR1K_ADD(12,12,16);
2528
0
        plt[2] = OR1K_LWZ(12,12) | got;
2529
0
        plt[3] = OR1K_MOVHI(11) | pltrelhi;
2530
0
        plt[4] = OR1K_ORI(11,11) | pltrello;
2531
0
        plt_insn_count = 5;
2532
0
      }
2533
0
    else
2534
0
      {
2535
0
        plt[0] = OR1K_LWZ(12,16) | got_offset;
2536
0
        plt[1] = OR1K_ORI0(11) | plt_reloc;
2537
0
        plt[2] = OR1K_NOP;
2538
0
      }
2539
0
  }
2540
0
      else
2541
0
  {
2542
0
    unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
2543
0
    unsigned lo = got_addr & 0xffff;
2544
0
    plt[0] = OR1K_MOVHI(12) | ha;
2545
0
    plt[1] = OR1K_LWZ(12,12) | lo;
2546
0
    plt[2] = OR1K_ORI0(11) | plt_reloc;
2547
0
  }
2548
2549
      /* For large code model we fixup the non-PIC PLT relocation instructions
2550
   here.  */
2551
0
      if (large_plt_entry && !bfd_link_pic (info))
2552
0
  {
2553
0
    unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
2554
0
    unsigned pltrello = plt_reloc & 0xffff;
2555
2556
0
    plt[2] = OR1K_MOVHI(11) | pltrelhi;
2557
0
    plt[3] = OR1K_ORI(11,11) | pltrello;
2558
0
    plt[4] = OR1K_NOP;
2559
0
    plt_insn_count = 5;
2560
0
  }
2561
2562
0
      or1k_write_plt_entry (info->output_bfd, splt->contents + h->plt.offset,
2563
0
          OR1K_JR(12), plt, plt_insn_count);
2564
2565
      /* Fill in the entry in the global offset table.  We initialize it to
2566
   point to the top of the plt.  This is done to lazy lookup the actual
2567
   symbol as the first plt entry will be setup by libc to call the
2568
   runtime dynamic linker.  */
2569
0
      bfd_put_32 (info->output_bfd, plt_base_addr, sgot->contents + got_offset);
2570
2571
      /* Fill in the entry in the .rela.plt section.  */
2572
0
      rela.r_offset = got_addr;
2573
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_JMP_SLOT);
2574
0
      rela.r_addend = 0;
2575
0
      loc = srela->contents;
2576
0
      loc += plt_index * sizeof (Elf32_External_Rela);
2577
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
2578
2579
0
      if (!h->def_regular)
2580
0
  {
2581
    /* Mark the symbol as undefined, rather than as defined in
2582
       the .plt section.  Leave the value alone.  */
2583
0
    sym->st_shndx = SHN_UNDEF;
2584
0
  }
2585
0
    }
2586
2587
0
  if (h->got.offset != (bfd_vma) -1
2588
0
      && (h->got.offset & 2) == 0) /* Homemade TLS check.  */
2589
0
    {
2590
0
      asection *sgot;
2591
0
      asection *srelgot;
2592
0
      Elf_Internal_Rela rela;
2593
2594
      /* This symbol has an entry in the global offset table.  Set it
2595
   up.  */
2596
0
      sgot = htab->root.sgot;
2597
0
      srelgot = htab->root.srelgot;
2598
0
      BFD_ASSERT (sgot != NULL && srelgot != NULL);
2599
2600
0
      rela.r_offset = (sgot->output_section->vma
2601
0
           + sgot->output_offset
2602
0
           + (h->got.offset &~ 1));
2603
2604
      /* If this is a -Bsymbolic link, and the symbol is defined
2605
   locally, we just want to emit a RELATIVE reloc.  Likewise if
2606
   the symbol was forced to be local because of a version file.
2607
   The entry in the global offset table will already have been
2608
   initialized in the relocate_section function.  */
2609
0
      if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
2610
0
  {
2611
0
    rela.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
2612
0
    rela.r_addend = (h->root.u.def.value
2613
0
         + h->root.u.def.section->output_section->vma
2614
0
         + h->root.u.def.section->output_offset);
2615
0
  }
2616
0
      else
2617
0
  {
2618
0
    BFD_ASSERT ((h->got.offset & 1) == 0);
2619
0
    bfd_put_32 (info->output_bfd, 0, sgot->contents + h->got.offset);
2620
0
    rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_GLOB_DAT);
2621
0
    rela.r_addend = 0;
2622
0
  }
2623
2624
0
      loc = srelgot->contents;
2625
0
      loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
2626
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
2627
0
      ++srelgot->reloc_count;
2628
0
    }
2629
2630
0
  if (h->needs_copy)
2631
0
    {
2632
0
      asection *s;
2633
0
      Elf_Internal_Rela rela;
2634
2635
      /* This symbols needs a copy reloc.  Set it up.  */
2636
0
      BFD_ASSERT (h->dynindx != -1
2637
0
      && (h->root.type == bfd_link_hash_defined
2638
0
          || h->root.type == bfd_link_hash_defweak));
2639
2640
0
      rela.r_offset = (h->root.u.def.value
2641
0
           + h->root.u.def.section->output_section->vma
2642
0
           + h->root.u.def.section->output_offset);
2643
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_COPY);
2644
0
      rela.r_addend = 0;
2645
0
      if (h->root.u.def.section == htab->root.sdynrelro)
2646
0
  s = htab->root.sreldynrelro;
2647
0
      else
2648
0
  s = htab->root.srelbss;
2649
0
      loc = s->contents + s->reloc_count * sizeof (Elf32_External_Rela);
2650
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
2651
0
      ++s->reloc_count;
2652
0
    }
2653
2654
  /* Mark some specially defined symbols as absolute.  */
2655
0
  if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2656
0
      || h == htab->root.hgot)
2657
0
    sym->st_shndx = SHN_ABS;
2658
2659
0
  return true;
2660
0
}
2661
2662
static enum elf_reloc_type_class
2663
or1k_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
2664
         const asection *rel_sec ATTRIBUTE_UNUSED,
2665
         const Elf_Internal_Rela *rela)
2666
0
{
2667
0
  switch ((int) ELF32_R_TYPE (rela->r_info))
2668
0
    {
2669
0
    case R_OR1K_RELATIVE:  return reloc_class_relative;
2670
0
    case R_OR1K_JMP_SLOT:  return reloc_class_plt;
2671
0
    case R_OR1K_COPY:    return reloc_class_copy;
2672
0
    default:       return reloc_class_normal;
2673
0
    }
2674
0
}
2675
2676
/* Adjust a symbol defined by a dynamic object and referenced by a
2677
   regular object.  The current definition is in some section of the
2678
   dynamic object, but we're not including those sections.  We have to
2679
   change the definition to something the rest of the link can
2680
   understand.  */
2681
2682
static bool
2683
or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2684
        struct elf_link_hash_entry *h)
2685
0
{
2686
0
  struct elf_or1k_link_hash_table *htab;
2687
0
  bfd *dynobj;
2688
0
  asection *s, *srel;
2689
2690
0
  dynobj = elf_hash_table (info)->dynobj;
2691
2692
  /* Make sure we know what is going on here.  */
2693
0
  BFD_ASSERT (dynobj != NULL
2694
0
        && (h->needs_plt
2695
0
      || h->is_weakalias
2696
0
      || (h->def_dynamic
2697
0
          && h->ref_regular
2698
0
          && !h->def_regular)));
2699
2700
  /* If this is a function, put it in the procedure linkage table.  We
2701
     will fill in the contents of the procedure linkage table later,
2702
     when we know the address of the .got section.  */
2703
0
  if (h->type == STT_FUNC
2704
0
      || h->needs_plt)
2705
0
    {
2706
0
      if (h->plt.refcount <= 0
2707
0
    || (SYMBOL_CALLS_LOCAL (info, h)
2708
0
    || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2709
0
        && h->root.type == bfd_link_hash_undefweak)))
2710
0
  {
2711
    /* This case can occur if we saw a PLT reloc in an input
2712
       file, but the symbol was never referred to by a dynamic
2713
       object.  In such a case, we don't actually need to build
2714
       a procedure linkage table, and we can just do a PCREL
2715
       reloc instead.  */
2716
0
    h->plt.offset = (bfd_vma) -1;
2717
0
    h->needs_plt = 0;
2718
0
  }
2719
2720
0
      return true;
2721
0
    }
2722
0
  else
2723
0
    h->plt.offset = (bfd_vma) -1;
2724
2725
  /* If this is a weak symbol, and there is a real definition, the
2726
     processor independent code will have arranged for us to see the
2727
     real definition first, and we can just use the same value.  */
2728
0
  if (h->is_weakalias)
2729
0
    {
2730
0
      struct elf_link_hash_entry *def = weakdef (h);
2731
0
      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
2732
0
      h->root.u.def.section = def->root.u.def.section;
2733
0
      h->root.u.def.value = def->root.u.def.value;
2734
0
      return true;
2735
0
    }
2736
2737
  /* This is a reference to a symbol defined by a dynamic object which
2738
     is not a function.  */
2739
2740
  /* If we are creating a shared library, we must presume that the
2741
     only references to the symbol are via the global offset table.
2742
     For such cases we need not do anything here; the relocations will
2743
     be handled correctly by relocate_section.  */
2744
0
  if (bfd_link_pic (info))
2745
0
    return true;
2746
2747
  /* If there are no references to this symbol that do not use the
2748
     GOT, we don't need to generate a copy reloc.  */
2749
0
  if (!h->non_got_ref)
2750
0
    return true;
2751
2752
  /* If -z nocopyreloc was given, we won't generate them either.  */
2753
0
  if (info->nocopyreloc)
2754
0
    {
2755
0
      h->non_got_ref = 0;
2756
0
      return true;
2757
0
    }
2758
2759
  /* If we don't find any dynamic relocs in read-only sections, then
2760
     we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
2761
0
  if (!_bfd_elf_readonly_dynrelocs (h))
2762
0
    {
2763
0
      h->non_got_ref = 0;
2764
0
      return true;
2765
0
    }
2766
2767
  /* We must allocate the symbol in our .dynbss section, which will
2768
     become part of the .bss section of the executable.  There will be
2769
     an entry for this symbol in the .dynsym section.  The dynamic
2770
     object will contain position independent code, so all references
2771
     from the dynamic object to this symbol will go through the global
2772
     offset table.  The dynamic linker will use the .dynsym entry to
2773
     determine the address it must put in the global offset table, so
2774
     both the dynamic object and the regular object will refer to the
2775
     same memory location for the variable.  */
2776
2777
0
  htab = or1k_elf_hash_table (info);
2778
0
  if (htab == NULL)
2779
0
    return false;
2780
2781
  /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
2782
     to copy the initial value out of the dynamic object and into the
2783
     runtime process image.  We need to remember the offset into the
2784
     .rela.bss section we are going to use.  */
2785
0
  if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2786
0
    {
2787
0
      s = htab->root.sdynrelro;
2788
0
      srel = htab->root.sreldynrelro;
2789
0
    }
2790
0
  else
2791
0
    {
2792
0
      s = htab->root.sdynbss;
2793
0
      srel = htab->root.srelbss;
2794
0
    }
2795
0
  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2796
0
    {
2797
0
      srel->size += sizeof (Elf32_External_Rela);
2798
0
      h->needs_copy = 1;
2799
0
    }
2800
2801
0
  return _bfd_elf_adjust_dynamic_copy (info, h, s);
2802
0
}
2803
2804
/* Caclulate an update the sizes required for a symbol in the GOT and
2805
   RELA relocation section based on the TLS_TYPE and whether or not the symbol
2806
   is DYNAMIC.
2807
2808
   Symbols with TLS_GD access require 8 bytes in the GOT and, if dynamic,
2809
   require two relocation entries.  Symbols with TLS_IE access require 4 bytes
2810
   in the GOT and, if dynamic, require one relocation entry.  Symbols may have
2811
   both TLS_GD and TLS_IE access to be accounted for.
2812
2813
   Other symbols require 4 bytes in the GOT table and, if dynamic, require one
2814
   relocation entry.  */
2815
2816
static void
2817
or1k_set_got_and_rela_sizes (const unsigned char tls_type,
2818
           const bool dynamic,
2819
           bfd_vma *got_size,
2820
           bfd_vma *rela_size)
2821
0
{
2822
0
  bool is_tls_entry = false;
2823
2824
  /* TLS GD requires two GOT entries and two relocs.  */
2825
0
  if ((tls_type & TLS_GD) != 0)
2826
0
    {
2827
0
      *got_size += 8;
2828
0
      is_tls_entry = true;
2829
0
    }
2830
2831
0
  if ((tls_type & TLS_IE) != 0)
2832
0
    {
2833
0
      *got_size += 4;
2834
0
      is_tls_entry = true;
2835
0
    }
2836
2837
0
  if (!is_tls_entry)
2838
0
    *got_size += 4;
2839
2840
0
  if (dynamic)
2841
0
    {
2842
0
      if ((tls_type & TLS_GD) != 0)
2843
0
  *rela_size += 2 * sizeof (Elf32_External_Rela);
2844
2845
0
      if ((tls_type & TLS_IE) != 0)
2846
0
  *rela_size += sizeof (Elf32_External_Rela);
2847
2848
0
      if (!is_tls_entry)
2849
0
  *rela_size += sizeof (Elf32_External_Rela);
2850
0
    }
2851
0
}
2852
2853
2854
/* Allocate space in .plt, .got and associated reloc sections for
2855
   dynamic relocs.  */
2856
2857
static bool
2858
allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2859
0
{
2860
0
  struct bfd_link_info *info;
2861
0
  struct elf_or1k_link_hash_table *htab;
2862
0
  struct elf_dyn_relocs *sec_relocs;
2863
2864
0
  if (h->root.type == bfd_link_hash_indirect)
2865
0
    return true;
2866
2867
0
  info = (struct bfd_link_info *) inf;
2868
0
  htab = or1k_elf_hash_table (info);
2869
0
  if (htab == NULL)
2870
0
    return false;
2871
2872
0
  if (htab->root.dynamic_sections_created
2873
0
      && h->plt.refcount > 0)
2874
0
    {
2875
      /* Make sure this symbol is output as a dynamic symbol.
2876
   Undefined weak syms won't yet be marked as dynamic.  */
2877
0
      if (h->dynindx == -1
2878
0
    && !h->forced_local)
2879
0
  {
2880
0
    if (! bfd_elf_link_record_dynamic_symbol (info, h))
2881
0
      return false;
2882
0
  }
2883
2884
0
      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
2885
0
  {
2886
0
    asection *splt = htab->root.splt;
2887
0
    bfd_vma plt_index;
2888
2889
    /* Track the index of our plt entry for use in calculating size.  */
2890
0
    plt_index = htab->plt_count++;
2891
0
    ((struct elf_or1k_link_hash_entry *) h)->plt_index = plt_index;
2892
2893
    /* If this is the first .plt entry, make room for the special
2894
       first entry.  */
2895
0
    if (splt->size == 0)
2896
0
      splt->size = elf_or1k_plt_entry_size (plt_index);
2897
2898
0
    h->plt.offset = splt->size;
2899
2900
    /* If this symbol is not defined in a regular file, and we are
2901
       not generating a shared library, then set the symbol to this
2902
       location in the .plt.  This is required to make function
2903
       pointers compare as equal between the normal executable and
2904
       the shared library.  */
2905
0
    if (! bfd_link_pic (info)
2906
0
        && !h->def_regular)
2907
0
      {
2908
0
        h->root.u.def.section = splt;
2909
0
        h->root.u.def.value = h->plt.offset;
2910
0
      }
2911
2912
    /* Make room for this entry.  */
2913
0
    splt->size += elf_or1k_plt_entry_size (plt_index);
2914
2915
    /* We also need to make an entry in the .got.plt section, which
2916
       will be placed in the .got section by the linker script.  */
2917
0
    htab->root.sgotplt->size += 4;
2918
2919
    /* We also need to make an entry in the .rel.plt section.  */
2920
0
    htab->root.srelplt->size += sizeof (Elf32_External_Rela);
2921
0
  }
2922
0
      else
2923
0
  {
2924
0
    h->plt.offset = (bfd_vma) -1;
2925
0
    h->needs_plt = 0;
2926
0
  }
2927
0
    }
2928
0
  else
2929
0
    {
2930
0
      h->plt.offset = (bfd_vma) -1;
2931
0
      h->needs_plt = 0;
2932
0
    }
2933
2934
0
  if (h->got.refcount > 0)
2935
0
    {
2936
0
      asection *sgot;
2937
0
      bool dyn;
2938
0
      unsigned char tls_type;
2939
2940
      /* Make sure this symbol is output as a dynamic symbol.
2941
   Undefined weak syms won't yet be marked as dynamic.  */
2942
0
      if (h->dynindx == -1
2943
0
    && !h->forced_local)
2944
0
  {
2945
0
    if (! bfd_elf_link_record_dynamic_symbol (info, h))
2946
0
      return false;
2947
0
  }
2948
2949
0
      sgot = htab->root.sgot;
2950
2951
0
      h->got.offset = sgot->size;
2952
2953
0
      tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
2954
2955
0
      dyn = htab->root.dynamic_sections_created;
2956
0
      dyn = WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h);
2957
0
      or1k_set_got_and_rela_sizes (tls_type, dyn,
2958
0
           &sgot->size, &htab->root.srelgot->size);
2959
0
    }
2960
0
  else
2961
0
    h->got.offset = (bfd_vma) -1;
2962
2963
0
  if (h->dyn_relocs == NULL)
2964
0
    return true;
2965
2966
  /* In the shared -Bsymbolic case, discard space allocated for
2967
     dynamic pc-relative relocs against symbols which turn out to be
2968
     defined in regular objects.  For the normal shared case, discard
2969
     space for pc-relative relocs that have become local due to symbol
2970
     visibility changes.  */
2971
2972
0
  if (bfd_link_pic (info))
2973
0
    {
2974
0
      if (SYMBOL_CALLS_LOCAL (info, h))
2975
0
  {
2976
0
    struct elf_dyn_relocs **pp;
2977
2978
0
    for (pp = &h->dyn_relocs; (sec_relocs = *pp) != NULL;)
2979
0
      {
2980
0
        sec_relocs->count -= sec_relocs->pc_count;
2981
0
        sec_relocs->pc_count = 0;
2982
0
        if (sec_relocs->count == 0)
2983
0
    *pp = sec_relocs->next;
2984
0
        else
2985
0
    pp = &sec_relocs->next;
2986
0
      }
2987
0
  }
2988
2989
      /* Also discard relocs on undefined weak syms with non-default
2990
   visibility.  */
2991
0
      if (h->dyn_relocs != NULL
2992
0
    && h->root.type == bfd_link_hash_undefweak)
2993
0
  {
2994
0
    if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2995
0
      h->dyn_relocs = NULL;
2996
2997
    /* Make sure undefined weak symbols are output as a dynamic
2998
       symbol in PIEs.  */
2999
0
    else if (h->dynindx == -1
3000
0
       && !h->forced_local)
3001
0
      {
3002
0
        if (! bfd_elf_link_record_dynamic_symbol (info, h))
3003
0
    return false;
3004
0
      }
3005
0
  }
3006
0
    }
3007
0
  else
3008
0
    {
3009
      /* For the non-shared case, discard space for relocs against
3010
   symbols which turn out to need copy relocs or are not
3011
   dynamic.  */
3012
3013
0
      if (!h->non_got_ref
3014
0
    && ((h->def_dynamic
3015
0
         && !h->def_regular)
3016
0
        || (htab->root.dynamic_sections_created
3017
0
      && (h->root.type == bfd_link_hash_undefweak
3018
0
          || h->root.type == bfd_link_hash_undefined))))
3019
0
  {
3020
    /* Make sure this symbol is output as a dynamic symbol.
3021
       Undefined weak syms won't yet be marked as dynamic.  */
3022
0
    if (h->dynindx == -1
3023
0
        && !h->forced_local)
3024
0
      {
3025
0
        if (! bfd_elf_link_record_dynamic_symbol (info, h))
3026
0
    return false;
3027
0
      }
3028
3029
    /* If that succeeded, we know we'll be keeping all the
3030
       relocs.  */
3031
0
    if (h->dynindx != -1)
3032
0
      goto keep;
3033
0
  }
3034
3035
0
      h->dyn_relocs = NULL;
3036
3037
0
    keep: ;
3038
0
    }
3039
3040
  /* Finally, allocate space.  */
3041
0
  for (sec_relocs = h->dyn_relocs;
3042
0
       sec_relocs != NULL;
3043
0
       sec_relocs = sec_relocs->next)
3044
0
    {
3045
0
      asection *sreloc = elf_section_data (sec_relocs->sec)->sreloc;
3046
0
      sreloc->size += sec_relocs->count * sizeof (Elf32_External_Rela);
3047
0
    }
3048
3049
0
  return true;
3050
0
}
3051
3052
/* Set the sizes of the dynamic sections.  */
3053
3054
static bool
3055
or1k_elf_late_size_sections (struct bfd_link_info *info)
3056
0
{
3057
0
  struct elf_or1k_link_hash_table *htab;
3058
0
  bfd *dynobj;
3059
0
  asection *s;
3060
0
  bool relocs;
3061
0
  bfd *ibfd;
3062
3063
0
  htab = or1k_elf_hash_table (info);
3064
0
  if (htab == NULL)
3065
0
    return false;
3066
3067
0
  dynobj = htab->root.dynobj;
3068
0
  if (dynobj == NULL)
3069
0
    return true;
3070
3071
0
  if (htab->root.dynamic_sections_created)
3072
0
    {
3073
      /* Set the contents of the .interp section to the interpreter.  */
3074
0
      if (bfd_link_executable (info) && !info->nointerp)
3075
0
  {
3076
0
    s = htab->root.interp;
3077
0
    BFD_ASSERT (s != NULL);
3078
0
    s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3079
0
    s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3080
0
    s->alloced = 1;
3081
0
  }
3082
0
    }
3083
3084
  /* Set up .got offsets for local syms, and space for local dynamic
3085
     relocs.  */
3086
0
  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3087
0
    {
3088
0
      bfd_signed_vma *local_got;
3089
0
      bfd_signed_vma *end_local_got;
3090
0
      bfd_size_type locsymcount;
3091
0
      Elf_Internal_Shdr *symtab_hdr;
3092
0
      unsigned char *local_tls_type;
3093
0
      asection *srel;
3094
3095
0
      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3096
0
  continue;
3097
3098
0
      for (s = ibfd->sections; s != NULL; s = s->next)
3099
0
  {
3100
0
    struct elf_dyn_relocs *sec_relocs;
3101
3102
0
    for (sec_relocs = ((struct elf_dyn_relocs *)
3103
0
           elf_section_data (s)->local_dynrel);
3104
0
         sec_relocs != NULL;
3105
0
         sec_relocs = sec_relocs->next)
3106
0
      {
3107
0
        if (! bfd_is_abs_section (sec_relocs->sec)
3108
0
      && bfd_is_abs_section (sec_relocs->sec->output_section))
3109
0
    {
3110
      /* Input section has been discarded, either because
3111
         it is a copy of a linkonce section or due to
3112
         linker script /DISCARD/, so we'll be discarding
3113
         the relocs too.  */
3114
0
    }
3115
0
        else if (sec_relocs->count != 0)
3116
0
    {
3117
0
      srel = elf_section_data (sec_relocs->sec)->sreloc;
3118
0
      srel->size += sec_relocs->count
3119
0
        * sizeof (Elf32_External_Rela);
3120
0
      if ((sec_relocs->sec->output_section->flags & SEC_READONLY)
3121
0
          != 0)
3122
0
        info->flags |= DF_TEXTREL;
3123
0
    }
3124
0
      }
3125
0
  }
3126
3127
0
      local_got = elf_local_got_refcounts (ibfd);
3128
0
      if (!local_got)
3129
0
  continue;
3130
3131
0
      symtab_hdr = &elf_symtab_hdr (ibfd);
3132
0
      locsymcount = symtab_hdr->sh_info;
3133
0
      end_local_got = local_got + locsymcount;
3134
0
      s = htab->root.sgot;
3135
0
      srel = htab->root.srelgot;
3136
0
      local_tls_type = (unsigned char *) elf_or1k_local_tls_type (ibfd);
3137
0
      for (; local_got < end_local_got; ++local_got)
3138
0
  {
3139
0
    if (*local_got > 0)
3140
0
      {
3141
0
        unsigned char tls_type = (local_tls_type == NULL)
3142
0
          ? TLS_UNKNOWN
3143
0
          : *local_tls_type;
3144
3145
0
        *local_got = s->size;
3146
0
        or1k_set_got_and_rela_sizes (tls_type, bfd_link_pic (info),
3147
0
             &s->size, &srel->size);
3148
0
      }
3149
0
    else
3150
3151
0
      *local_got = (bfd_vma) -1;
3152
3153
0
    if (local_tls_type)
3154
0
      ++local_tls_type;
3155
0
  }
3156
0
    }
3157
3158
  /* Allocate global sym .plt and .got entries, and space for global
3159
     sym dynamic relocs.  */
3160
0
  elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
3161
3162
  /* We now have determined the sizes of the various dynamic sections.
3163
     Allocate memory for them.  */
3164
0
  relocs = false;
3165
0
  for (s = dynobj->sections; s != NULL; s = s->next)
3166
0
    {
3167
0
      if ((s->flags & SEC_LINKER_CREATED) == 0)
3168
0
  continue;
3169
3170
0
      if (s == htab->root.splt
3171
0
    || s == htab->root.sgot
3172
0
    || s == htab->root.sgotplt
3173
0
    || s == htab->root.sdynbss
3174
0
    || s == htab->root.sdynrelro)
3175
0
  {
3176
    /* Strip this section if we don't need it; see the
3177
       comment below.  */
3178
0
  }
3179
0
      else if (startswith (bfd_section_name (s), ".rela"))
3180
0
  {
3181
0
    if (s->size != 0 && s != htab->root.srelplt)
3182
0
      relocs = true;
3183
3184
    /* We use the reloc_count field as a counter if we need
3185
       to copy relocs into the output file.  */
3186
0
    s->reloc_count = 0;
3187
0
  }
3188
0
      else
3189
  /* It's not one of our sections, so don't allocate space.  */
3190
0
  continue;
3191
3192
0
      if (s->size == 0)
3193
0
  {
3194
    /* If we don't need this section, strip it from the
3195
       output file.  This is mostly to handle .rela.bss and
3196
       .rela.plt.  We must create both sections in
3197
       create_dynamic_sections, because they must be created
3198
       before the linker maps input sections to output
3199
       sections.  The linker does that before
3200
       adjust_dynamic_symbol is called, and it is that
3201
       function which decides whether anything needs to go
3202
       into these sections.  */
3203
0
    s->flags |= SEC_EXCLUDE;
3204
0
    continue;
3205
0
  }
3206
3207
0
      if ((s->flags & SEC_HAS_CONTENTS) == 0)
3208
0
  continue;
3209
3210
      /* Allocate memory for the section contents.  We use bfd_zalloc
3211
   here in case unused entries are not reclaimed before the
3212
   section's contents are written out.  This should not happen,
3213
   but this way if it does, we get a R_OR1K_NONE reloc instead
3214
   of garbage.  */
3215
0
      s->contents = bfd_zalloc (dynobj, s->size);
3216
0
      if (s->contents == NULL)
3217
0
  return false;
3218
0
      s->alloced = 1;
3219
0
    }
3220
3221
0
  return _bfd_elf_add_dynamic_tags (info, relocs);
3222
0
}
3223
3224
/* Copy the extra info we tack onto an elf_link_hash_entry.  */
3225
3226
static void
3227
or1k_elf_copy_indirect_symbol (struct bfd_link_info *info,
3228
             struct elf_link_hash_entry *dir,
3229
             struct elf_link_hash_entry *ind)
3230
0
{
3231
0
  struct elf_or1k_link_hash_entry * edir;
3232
0
  struct elf_or1k_link_hash_entry * eind;
3233
3234
0
  edir = (struct elf_or1k_link_hash_entry *) dir;
3235
0
  eind = (struct elf_or1k_link_hash_entry *) ind;
3236
3237
0
  if (ind->root.type == bfd_link_hash_indirect)
3238
0
    {
3239
0
      if (dir->got.refcount <= 0)
3240
0
  {
3241
0
    edir->tls_type = eind->tls_type;
3242
0
    eind->tls_type = TLS_UNKNOWN;
3243
0
  }
3244
0
    }
3245
3246
0
  _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3247
0
}
3248
3249
/* Set the right machine number.  */
3250
3251
static bool
3252
or1k_elf_object_p (bfd *abfd)
3253
133
{
3254
133
  unsigned long mach = bfd_mach_or1k;
3255
3256
133
  if (elf_elfheader (abfd)->e_flags & EF_OR1K_NODELAY)
3257
26
    mach = bfd_mach_or1knd;
3258
3259
133
  return bfd_default_set_arch_mach (abfd, bfd_arch_or1k, mach);
3260
133
}
3261
3262
/* Store the machine number in the flags field.  */
3263
3264
static bool
3265
or1k_elf_final_write_processing (bfd *abfd)
3266
3
{
3267
3
  switch (bfd_get_mach (abfd))
3268
3
    {
3269
0
    default:
3270
2
    case bfd_mach_or1k:
3271
2
      break;
3272
1
    case bfd_mach_or1knd:
3273
1
      elf_elfheader (abfd)->e_flags |= EF_OR1K_NODELAY;
3274
1
      break;
3275
3
    }
3276
3
  return _bfd_elf_final_write_processing (abfd);
3277
3
}
3278
3279
static bool
3280
or1k_elf_set_private_flags (bfd *abfd, flagword flags)
3281
0
{
3282
0
  BFD_ASSERT (!elf_flags_init (abfd)
3283
0
        || elf_elfheader (abfd)->e_flags == flags);
3284
3285
0
  elf_elfheader (abfd)->e_flags = flags;
3286
0
  elf_flags_init (abfd) = true;
3287
0
  return true;
3288
0
}
3289
3290
/* Make sure all input files are consistent with respect to
3291
   EF_OR1K_NODELAY flag setting.  */
3292
3293
static bool
3294
elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
3295
0
{
3296
0
  bfd *obfd = info->output_bfd;
3297
0
  flagword out_flags;
3298
0
  flagword in_flags;
3299
3300
0
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3301
0
    return true;
3302
3303
0
  in_flags  = elf_elfheader (ibfd)->e_flags;
3304
0
  out_flags = elf_elfheader (obfd)->e_flags;
3305
3306
0
  if (!elf_flags_init (obfd))
3307
0
    {
3308
0
      elf_flags_init (obfd) = true;
3309
0
      elf_elfheader (obfd)->e_flags = in_flags;
3310
3311
0
      return true;
3312
0
    }
3313
3314
0
  if (in_flags == out_flags)
3315
0
    return true;
3316
3317
0
  if ((in_flags & EF_OR1K_NODELAY) != (out_flags & EF_OR1K_NODELAY))
3318
0
    {
3319
0
      _bfd_error_handler
3320
0
  (_("%pB: %s flag mismatch with previous modules"),
3321
0
   ibfd, "EF_OR1K_NODELAY");
3322
3323
0
      bfd_set_error (bfd_error_bad_value);
3324
0
      return false;
3325
0
    }
3326
3327
0
  return true;
3328
3329
0
}
3330
3331
/* Implement elf_backend_grok_prstatus:
3332
   Support for core dump NOTE sections.  */
3333
static bool
3334
or1k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3335
0
{
3336
0
  int offset;
3337
0
  size_t size;
3338
3339
0
  switch (note->descsz)
3340
0
    {
3341
0
    default:
3342
0
      return false;
3343
3344
0
    case 212:       /* Linux/OpenRISC */
3345
      /* pr_cursig */
3346
0
      elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
3347
3348
      /* pr_pid */
3349
0
      elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
3350
3351
      /* pr_reg */
3352
0
      offset = 72;
3353
0
      size = 132;
3354
3355
0
      break;
3356
0
    }
3357
3358
  /* Make a ".reg/999" section.  */
3359
0
  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
3360
0
            size, note->descpos + offset);
3361
0
}
3362
3363
/* Implement elf_backend_grok_psinfo.  */
3364
static bool
3365
or1k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3366
0
{
3367
0
  switch (note->descsz)
3368
0
    {
3369
0
    default:
3370
0
      return false;
3371
3372
0
    case 128:       /* Linux/OpenRISC elf_prpsinfo */
3373
0
      elf_tdata (abfd)->core->program
3374
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
3375
0
      elf_tdata (abfd)->core->command
3376
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
3377
0
    }
3378
3379
0
  return true;
3380
0
}
3381
3382
3383
#define ELF_ARCH      bfd_arch_or1k
3384
#define ELF_MACHINE_CODE    EM_OR1K
3385
#define ELF_TARGET_ID     OR1K_ELF_DATA
3386
#define ELF_MAXPAGESIZE     0x2000
3387
3388
#define TARGET_BIG_SYM      or1k_elf32_vec
3389
#define TARGET_BIG_NAME     "elf32-or1k"
3390
3391
#define elf_info_to_howto_rel   NULL
3392
#define elf_info_to_howto   or1k_info_to_howto_rela
3393
#define elf_backend_relocate_section  or1k_elf_relocate_section
3394
#define elf_backend_gc_mark_hook  or1k_elf_gc_mark_hook
3395
#define elf_backend_check_relocs  or1k_elf_check_relocs
3396
#define elf_backend_reloc_type_class  or1k_elf_reloc_type_class
3397
#define elf_backend_can_gc_sections 1
3398
#define elf_backend_rela_normal   1
3399
3400
#define bfd_elf32_mkobject         elf_or1k_mkobject
3401
3402
#define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
3403
#define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
3404
#define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
3405
#define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
3406
3407
#define elf_backend_object_p        or1k_elf_object_p
3408
#define elf_backend_final_write_processing  or1k_elf_final_write_processing
3409
#define elf_backend_can_refcount    1
3410
3411
#define elf_backend_plt_readonly    1
3412
#define elf_backend_want_got_plt    1
3413
#define elf_backend_want_plt_sym    0
3414
#define elf_backend_got_header_size   12
3415
#define elf_backend_dtrel_excludes_plt    1
3416
#define elf_backend_want_dynrelro   1
3417
3418
#define bfd_elf32_bfd_link_hash_table_create  or1k_elf_link_hash_table_create
3419
#define elf_backend_copy_indirect_symbol  or1k_elf_copy_indirect_symbol
3420
#define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3421
#define elf_backend_finish_dynamic_sections or1k_elf_finish_dynamic_sections
3422
#define elf_backend_late_size_sections    or1k_elf_late_size_sections
3423
#define elf_backend_adjust_dynamic_symbol or1k_elf_adjust_dynamic_symbol
3424
#define elf_backend_finish_dynamic_symbol or1k_elf_finish_dynamic_symbol
3425
3426
#define elf_backend_grok_prstatus   or1k_grok_prstatus
3427
#define elf_backend_grok_psinfo     or1k_grok_psinfo
3428
3429
#include "elf32-target.h"