1 /* TILE-Gx-specific support for ELF.
2 Copyright 2011 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
25 #include "elf/tilegx.h"
26 #include "opcode/tilegx.h"
27 #include "libiberty.h"
28 #include "elfxx-tilegx.h"
30 #define ABI_64_P(abfd) \
31 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
33 #define TILEGX_ELF_WORD_BYTES(htab) \
34 ((htab)->bytes_per_word)
36 /* The size of an external RELA relocation. */
37 #define TILEGX_ELF_RELA_BYTES(htab) \
38 ((htab)->bytes_per_rela)
40 /* Both 32-bit and 64-bit tilegx encode this in an identical manner,
41 so just take advantage of that. */
42 #define TILEGX_ELF_R_TYPE(r_info) \
45 #define TILEGX_ELF_R_INFO(htab, in_rel, index, type) \
46 ((htab)->r_info (in_rel, index, type))
48 #define TILEGX_ELF_R_SYMNDX(htab, r_info) \
49 ((htab)->r_symndx(r_info))
51 #define TILEGX_ELF_DTPOFF_RELOC(htab) \
52 ((htab)->dtpoff_reloc)
54 #define TILEGX_ELF_DTPMOD_RELOC(htab) \
55 ((htab)->dtpmod_reloc)
57 #define TILEGX_ELF_TPOFF_RELOC(htab) \
60 #define TILEGX_ELF_PUT_WORD(htab, bfd, val, ptr) \
61 ((htab)->put_word (bfd, val, ptr))
63 /* The name of the dynamic interpreter. This is put in the .interp
66 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld.so.1"
67 #define ELF32_DYNAMIC_INTERPRETER "/lib32/ld.so.1"
70 static reloc_howto_type tilegx_elf_howto_table
[] =
72 /* This reloc does nothing. */
73 HOWTO (R_TILEGX_NONE
, /* type */
75 2, /* size (0 = byte, 1 = short, 2 = long) */
77 FALSE
, /* pc_relative */
79 complain_overflow_bitfield
, /* complain_on_overflow */
80 bfd_elf_generic_reloc
, /* special_function */
81 "R_TILEGX_NONE", /* name */
82 FALSE
, /* partial_inplace */
85 FALSE
), /* pcrel_offset */
87 /* A 64 bit absolute relocation. */
88 HOWTO (R_TILEGX_64
, /* type */
90 4, /* size (0 = byte, 1 = short, 2 = long) */
92 FALSE
, /* pc_relative */
94 complain_overflow_dont
, /* complain_on_overflow */
95 bfd_elf_generic_reloc
, /* special_function */
96 "R_TILEGX_64", /* name */
97 FALSE
, /* partial_inplace */
99 0xffffffffffffffffULL
, /* dst_mask */
100 FALSE
), /* pcrel_offset */
102 /* A 32 bit absolute relocation. */
103 HOWTO (R_TILEGX_32
, /* type */
105 2, /* size (0 = byte, 1 = short, 2 = long) */
107 FALSE
, /* pc_relative */
109 complain_overflow_dont
, /* complain_on_overflow */
110 bfd_elf_generic_reloc
, /* special_function */
111 "R_TILEGX_32", /* name */
112 FALSE
, /* partial_inplace */
114 0xffffffff, /* dst_mask */
115 FALSE
), /* pcrel_offset */
117 /* A 16 bit absolute relocation. */
118 HOWTO (R_TILEGX_16
, /* type */
120 1, /* size (0 = byte, 1 = short, 2 = long) */
122 FALSE
, /* pc_relative */
124 complain_overflow_bitfield
, /* complain_on_overflow */
125 bfd_elf_generic_reloc
, /* special_function */
126 "R_TILEGX_16", /* name */
127 FALSE
, /* partial_inplace */
129 0xffff, /* dst_mask */
130 FALSE
), /* pcrel_offset */
132 /* An 8 bit absolute relocation. */
133 HOWTO (R_TILEGX_8
, /* type */
135 0, /* size (0 = byte, 1 = short, 2 = long) */
137 FALSE
, /* pc_relative */
139 complain_overflow_unsigned
, /* complain_on_overflow */
140 bfd_elf_generic_reloc
, /* special_function */
141 "R_TILEGX_8", /* name */
142 FALSE
, /* partial_inplace */
145 FALSE
), /* pcrel_offset */
147 /* A 64 bit pc-relative relocation. */
148 HOWTO (R_TILEGX_64_PCREL
,/* type */
150 4, /* size (0 = byte, 1 = short, 2 = long) */
152 TRUE
, /* pc_relative */
154 complain_overflow_dont
, /* complain_on_overflow */
155 bfd_elf_generic_reloc
, /* special_function */
156 "R_TILEGX_32_PCREL", /* name */
157 FALSE
, /* partial_inplace */
159 0xffffffffffffffffULL
, /* dst_mask */
160 TRUE
), /* pcrel_offset */
162 /* A 32 bit pc-relative relocation. */
163 HOWTO (R_TILEGX_32_PCREL
,/* type */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
167 TRUE
, /* pc_relative */
169 complain_overflow_dont
, /* complain_on_overflow */
170 bfd_elf_generic_reloc
, /* special_function */
171 "R_TILEGX_32_PCREL", /* name */
172 FALSE
, /* partial_inplace */
174 0xffffffff, /* dst_mask */
175 TRUE
), /* pcrel_offset */
177 /* A 16 bit pc-relative relocation. */
178 HOWTO (R_TILEGX_16_PCREL
,/* type */
180 1, /* size (0 = byte, 1 = short, 2 = long) */
182 TRUE
, /* pc_relative */
184 complain_overflow_signed
, /* complain_on_overflow */
185 bfd_elf_generic_reloc
, /* special_function */
186 "R_TILEGX_16_PCREL", /* name */
187 FALSE
, /* partial_inplace */
189 0xffff, /* dst_mask */
190 TRUE
), /* pcrel_offset */
192 /* An 8 bit pc-relative relocation. */
193 HOWTO (R_TILEGX_8_PCREL
, /* type */
195 0, /* size (0 = byte, 1 = short, 2 = long) */
197 TRUE
, /* pc_relative */
199 complain_overflow_signed
, /* complain_on_overflow */
200 bfd_elf_generic_reloc
, /* special_function */
201 "R_TILEGX_8_PCREL",/* name */
202 FALSE
, /* partial_inplace */
205 TRUE
), /* pcrel_offset */
207 /* A 16 bit relocation without overflow. */
208 HOWTO (R_TILEGX_HW0
, /* type */
210 1, /* size (0 = byte, 1 = short, 2 = long) */
212 FALSE
, /* pc_relative */
214 complain_overflow_dont
,/* complain_on_overflow */
215 bfd_elf_generic_reloc
, /* special_function */
216 "R_TILEGX_HW0", /* name */
217 FALSE
, /* partial_inplace */
219 0xffff, /* dst_mask */
220 FALSE
), /* pcrel_offset */
222 /* A 16 bit relocation without overflow. */
223 HOWTO (R_TILEGX_HW1
, /* type */
225 1, /* size (0 = byte, 1 = short, 2 = long) */
227 FALSE
, /* pc_relative */
229 complain_overflow_dont
,/* complain_on_overflow */
230 bfd_elf_generic_reloc
, /* special_function */
231 "R_TILEGX_HW1", /* name */
232 FALSE
, /* partial_inplace */
234 0xffff, /* dst_mask */
235 FALSE
), /* pcrel_offset */
237 /* A 16 bit relocation without overflow. */
238 HOWTO (R_TILEGX_HW2
, /* type */
240 1, /* size (0 = byte, 1 = short, 2 = long) */
242 FALSE
, /* pc_relative */
244 complain_overflow_dont
,/* complain_on_overflow */
245 bfd_elf_generic_reloc
, /* special_function */
246 "R_TILEGX_HW2", /* name */
247 FALSE
, /* partial_inplace */
249 0xffff, /* dst_mask */
250 FALSE
), /* pcrel_offset */
252 /* A 16 bit relocation without overflow. */
253 HOWTO (R_TILEGX_HW3
, /* type */
255 1, /* size (0 = byte, 1 = short, 2 = long) */
257 FALSE
, /* pc_relative */
259 complain_overflow_dont
,/* complain_on_overflow */
260 bfd_elf_generic_reloc
, /* special_function */
261 "R_TILEGX_HW3", /* name */
262 FALSE
, /* partial_inplace */
264 0xffff, /* dst_mask */
265 FALSE
), /* pcrel_offset */
267 /* A 16 bit relocation with overflow. */
268 HOWTO (R_TILEGX_HW0_LAST
, /* type */
270 1, /* size (0 = byte, 1 = short, 2 = long) */
272 FALSE
, /* pc_relative */
274 complain_overflow_signed
,/* complain_on_overflow */
275 bfd_elf_generic_reloc
, /* special_function */
276 "R_TILEGX_HW0_LAST", /* name */
277 FALSE
, /* partial_inplace */
279 0xffff, /* dst_mask */
280 FALSE
), /* pcrel_offset */
282 /* A 16 bit relocation with overflow. */
283 HOWTO (R_TILEGX_HW1_LAST
, /* type */
285 1, /* size (0 = byte, 1 = short, 2 = long) */
287 FALSE
, /* pc_relative */
289 complain_overflow_signed
,/* complain_on_overflow */
290 bfd_elf_generic_reloc
, /* special_function */
291 "R_TILEGX_HW1_LAST", /* name */
292 FALSE
, /* partial_inplace */
294 0xffff, /* dst_mask */
295 FALSE
), /* pcrel_offset */
297 /* A 16 bit relocation with overflow. */
298 HOWTO (R_TILEGX_HW2_LAST
, /* type */
300 1, /* size (0 = byte, 1 = short, 2 = long) */
302 FALSE
, /* pc_relative */
304 complain_overflow_signed
,/* complain_on_overflow */
305 bfd_elf_generic_reloc
, /* special_function */
306 "R_TILEGX_HW2_LAST", /* name */
307 FALSE
, /* partial_inplace */
309 0xffff, /* dst_mask */
310 FALSE
), /* pcrel_offset */
312 HOWTO (R_TILEGX_COPY
, /* type */
314 0, /* size (0 = byte, 1 = short, 2 = long) */
316 FALSE
, /* pc_relative */
318 complain_overflow_dont
, /* complain_on_overflow */
319 bfd_elf_generic_reloc
, /* special_function */
320 "R_TILEGX_COPY", /* name */
321 FALSE
, /* partial_inplace */
324 TRUE
), /* pcrel_offset */
326 HOWTO (R_TILEGX_GLOB_DAT
, /* type */
328 0, /* size (0 = byte, 1 = short, 2 = long) */
330 FALSE
, /* pc_relative */
332 complain_overflow_dont
, /* complain_on_overflow */
333 bfd_elf_generic_reloc
, /* special_function */
334 "R_TILEGX_GLOB_DAT", /* name */
335 FALSE
, /* partial_inplace */
338 TRUE
), /* pcrel_offset */
340 HOWTO (R_TILEGX_JMP_SLOT
, /* type */
342 0, /* size (0 = byte, 1 = short, 2 = long) */
344 FALSE
, /* pc_relative */
346 complain_overflow_dont
, /* complain_on_overflow */
347 bfd_elf_generic_reloc
, /* special_function */
348 "R_TILEGX_JMP_SLOT", /* name */
349 FALSE
, /* partial_inplace */
352 TRUE
), /* pcrel_offset */
354 HOWTO (R_TILEGX_RELATIVE
, /* type */
356 0, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_dont
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_TILEGX_RELATIVE", /* name */
363 FALSE
, /* partial_inplace */
366 TRUE
), /* pcrel_offset */
368 HOWTO (R_TILEGX_BROFF_X1
, /* type */
369 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
, /* rightshift */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
372 TRUE
, /* pc_relative */
374 complain_overflow_signed
, /* complain_on_overflow */
375 bfd_elf_generic_reloc
, /* special_function */
376 "R_TILEGX_BROFF_X1", /* name */
377 FALSE
, /* partial_inplace */
380 TRUE
), /* pcrel_offset */
382 HOWTO (R_TILEGX_JUMPOFF_X1
, /* type */
383 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
, /* rightshift */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 TRUE
, /* pc_relative */
388 complain_overflow_signed
,/* complain_on_overflow */
389 bfd_elf_generic_reloc
, /* special_function */
390 "R_TILEGX_JUMPOFF_X1", /* name */
391 FALSE
, /* partial_inplace */
394 TRUE
), /* pcrel_offset */
396 HOWTO (R_TILEGX_JUMPOFF_X1_PLT
, /* type */
397 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
, /* rightshift */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 TRUE
, /* pc_relative */
402 complain_overflow_signed
,/* complain_on_overflow */
403 bfd_elf_generic_reloc
, /* special_function */
404 "R_TILEGX_JUMPOFF_X1_PLT", /* name */
405 FALSE
, /* partial_inplace */
408 TRUE
), /* pcrel_offset */
410 #define TILEGX_IMM_HOWTO(name, size, bitsize) \
411 HOWTO (name, 0, size, bitsize, FALSE, 0, \
412 complain_overflow_signed, bfd_elf_generic_reloc, \
413 #name, FALSE, 0, -1, FALSE)
415 #define TILEGX_UIMM_HOWTO(name, size, bitsize) \
416 HOWTO (name, 0, size, bitsize, FALSE, 0, \
417 complain_overflow_unsigned, bfd_elf_generic_reloc, \
418 #name, FALSE, 0, -1, FALSE)
420 TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X0
, 0, 8),
421 TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y0
, 0, 8),
422 TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X1
, 0, 8),
423 TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y1
, 0, 8),
424 TILEGX_IMM_HOWTO(R_TILEGX_DEST_IMM8_X1
, 0, 8),
426 TILEGX_UIMM_HOWTO(R_TILEGX_MT_IMM14_X1
, 1, 14),
427 TILEGX_UIMM_HOWTO(R_TILEGX_MF_IMM14_X1
, 1, 14),
429 TILEGX_UIMM_HOWTO(R_TILEGX_MMSTART_X0
, 0, 6),
430 TILEGX_UIMM_HOWTO(R_TILEGX_MMEND_X0
, 0, 6),
432 TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_X0
, 0, 6),
433 TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_X1
, 0, 6),
434 TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_Y0
, 0, 6),
435 TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_Y1
, 0, 6),
437 #define TILEGX_IMM16_HOWTO(name, rshift) \
438 HOWTO (name, rshift, 1, 16, FALSE, 0, \
439 complain_overflow_dont, bfd_elf_generic_reloc, \
440 #name, FALSE, 0, 0xffff, FALSE)
442 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0
, 0),
443 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0
, 0),
444 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW1
, 16),
445 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW1
, 16),
446 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW2
, 32),
447 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW2
, 32),
448 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW3
, 48),
449 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW3
, 48),
451 #define TILEGX_IMM16_HOWTO_LAST(name, rshift) \
452 HOWTO (name, rshift, 1, 16, FALSE, 0, \
453 complain_overflow_signed, bfd_elf_generic_reloc, \
454 #name, FALSE, 0, 0xffff, FALSE)
456 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST
, 0),
457 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST
, 0),
458 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST
, 16),
459 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST
, 16),
460 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW2_LAST
, 32),
461 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW2_LAST
, 32),
463 /* PC-relative offsets. */
465 #define TILEGX_IMM16_HOWTO_PCREL(name, rshift) \
466 HOWTO (name, rshift, 1, 16, TRUE, 0, \
467 complain_overflow_dont, bfd_elf_generic_reloc, \
468 #name, FALSE, 0, 0xffff, TRUE)
470 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW0_PCREL
, 0),
471 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW0_PCREL
, 0),
472 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW1_PCREL
, 16),
473 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW1_PCREL
, 16),
474 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW2_PCREL
, 32),
475 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW2_PCREL
, 32),
476 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW3_PCREL
, 48),
477 TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW3_PCREL
, 48),
479 #define TILEGX_IMM16_HOWTO_LAST_PCREL(name, rshift) \
480 HOWTO (name, rshift, 1, 16, TRUE, 0, \
481 complain_overflow_signed, bfd_elf_generic_reloc, \
482 #name, FALSE, 0, 0xffff, TRUE)
484 TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW0_LAST_PCREL
, 0),
485 TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW0_LAST_PCREL
, 0),
486 TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW1_LAST_PCREL
, 16),
487 TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW1_LAST_PCREL
, 16),
488 TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW2_LAST_PCREL
, 32),
489 TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW2_LAST_PCREL
, 32),
491 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_GOT
, 0),
492 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_GOT
, 0),
493 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW1_GOT
, 16),
494 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW1_GOT
, 16),
495 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW2_GOT
, 32),
496 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW2_GOT
, 32),
497 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW3_GOT
, 48),
498 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW3_GOT
, 48),
500 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_GOT
, 0),
501 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_GOT
, 0),
502 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_GOT
, 16),
503 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_GOT
, 16),
504 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW2_LAST_GOT
, 32),
505 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW2_LAST_GOT
, 32),
507 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_TLS_GD
, 0),
508 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_TLS_GD
, 0),
509 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW1_TLS_GD
, 16),
510 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW1_TLS_GD
, 16),
511 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW2_TLS_GD
, 32),
512 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW2_TLS_GD
, 32),
513 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW3_TLS_GD
, 48),
514 TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW3_TLS_GD
, 48),
516 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
, 0),
517 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
, 0),
518 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
, 16),
519 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
, 16),
520 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
, 32),
521 TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
, 32),
523 #define TILEGX_IMM16_HOWTO_TLS_IE(name, rshift) \
524 HOWTO (name, rshift, 1, 16, FALSE, 0, \
525 complain_overflow_dont, bfd_elf_generic_reloc, \
526 #name, FALSE, 0, 0xffff, TRUE)
528 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X0_HW0_TLS_IE
, 0),
529 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X1_HW0_TLS_IE
, 0),
530 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X0_HW1_TLS_IE
, 16),
531 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X1_HW1_TLS_IE
, 16),
532 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X0_HW2_TLS_IE
, 32),
533 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X1_HW2_TLS_IE
, 32),
534 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X0_HW3_TLS_IE
, 48),
535 TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X1_HW3_TLS_IE
, 48),
537 #define TILEGX_IMM16_HOWTO_LAST_TLS_IE(name, rshift) \
538 HOWTO (name, rshift, 1, 16, FALSE, 0, \
539 complain_overflow_signed, bfd_elf_generic_reloc, \
540 #name, FALSE, 0, 0xffff, TRUE)
542 TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
, 0),
543 TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
, 0),
544 TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
, 16),
545 TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
, 16),
546 TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
, 32),
547 TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
, 32),
549 HOWTO(R_TILEGX_TLS_DTPMOD64
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
550 bfd_elf_generic_reloc
, "R_TILEGX_TLS_DTPMOD64",
552 HOWTO(R_TILEGX_TLS_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
553 bfd_elf_generic_reloc
, "R_TILEGX_TLS_DTPOFF64",
555 HOWTO(R_TILEGX_TLS_TPOFF64
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
556 bfd_elf_generic_reloc
, "R_TILEGX_TLS_TPOFF64",
559 HOWTO(R_TILEGX_TLS_DTPMOD32
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
560 bfd_elf_generic_reloc
, "R_TILEGX_TLS_DTPMOD32",
562 HOWTO(R_TILEGX_TLS_DTPOFF32
, 0, 4, 32, FALSE
, 0, complain_overflow_bitfield
,
563 bfd_elf_generic_reloc
, "R_TILEGX_TLS_DTPOFF32",
565 HOWTO(R_TILEGX_TLS_TPOFF32
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
566 bfd_elf_generic_reloc
, "R_TILEGX_TLS_TPOFF32",
570 static reloc_howto_type tilegx_elf_howto_table2
[] =
572 /* GNU extension to record C++ vtable hierarchy */
573 HOWTO (R_TILEGX_GNU_VTINHERIT
, /* type */
575 4, /* size (0 = byte, 1 = short, 2 = long) */
577 FALSE
, /* pc_relative */
579 complain_overflow_dont
, /* complain_on_overflow */
580 NULL
, /* special_function */
581 "R_TILEGX_GNU_VTINHERIT", /* name */
582 FALSE
, /* partial_inplace */
585 FALSE
), /* pcrel_offset */
587 /* GNU extension to record C++ vtable member usage */
588 HOWTO (R_TILEGX_GNU_VTENTRY
, /* type */
590 4, /* size (0 = byte, 1 = short, 2 = long) */
592 FALSE
, /* pc_relative */
594 complain_overflow_dont
, /* complain_on_overflow */
595 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
596 "R_TILEGX_GNU_VTENTRY", /* name */
597 FALSE
, /* partial_inplace */
600 FALSE
), /* pcrel_offset */
604 /* Map BFD reloc types to TILEGX ELF reloc types. */
606 typedef struct tilegx_reloc_map
608 bfd_reloc_code_real_type bfd_reloc_val
;
609 unsigned int tilegx_reloc_val
;
610 reloc_howto_type
* table
;
613 static const reloc_map tilegx_reloc_map
[] =
615 #define TH_REMAP(bfd, tilegx) \
616 { bfd, tilegx, tilegx_elf_howto_table },
618 /* Standard relocations. */
619 TH_REMAP (BFD_RELOC_NONE
, R_TILEGX_NONE
)
620 TH_REMAP (BFD_RELOC_64
, R_TILEGX_64
)
621 TH_REMAP (BFD_RELOC_32
, R_TILEGX_32
)
622 TH_REMAP (BFD_RELOC_16
, R_TILEGX_16
)
623 TH_REMAP (BFD_RELOC_8
, R_TILEGX_8
)
624 TH_REMAP (BFD_RELOC_64_PCREL
, R_TILEGX_64_PCREL
)
625 TH_REMAP (BFD_RELOC_32_PCREL
, R_TILEGX_32_PCREL
)
626 TH_REMAP (BFD_RELOC_16_PCREL
, R_TILEGX_16_PCREL
)
627 TH_REMAP (BFD_RELOC_8_PCREL
, R_TILEGX_8_PCREL
)
629 #define SIMPLE_REMAP(t) TH_REMAP (BFD_RELOC_##t, R_##t)
631 /* Custom relocations. */
632 SIMPLE_REMAP (TILEGX_HW0
)
633 SIMPLE_REMAP (TILEGX_HW1
)
634 SIMPLE_REMAP (TILEGX_HW2
)
635 SIMPLE_REMAP (TILEGX_HW3
)
636 SIMPLE_REMAP (TILEGX_HW0_LAST
)
637 SIMPLE_REMAP (TILEGX_HW1_LAST
)
638 SIMPLE_REMAP (TILEGX_HW2_LAST
)
639 SIMPLE_REMAP (TILEGX_COPY
)
640 SIMPLE_REMAP (TILEGX_GLOB_DAT
)
641 SIMPLE_REMAP (TILEGX_JMP_SLOT
)
642 SIMPLE_REMAP (TILEGX_RELATIVE
)
643 SIMPLE_REMAP (TILEGX_BROFF_X1
)
644 SIMPLE_REMAP (TILEGX_JUMPOFF_X1
)
645 SIMPLE_REMAP (TILEGX_JUMPOFF_X1_PLT
)
646 SIMPLE_REMAP (TILEGX_IMM8_X0
)
647 SIMPLE_REMAP (TILEGX_IMM8_Y0
)
648 SIMPLE_REMAP (TILEGX_IMM8_X1
)
649 SIMPLE_REMAP (TILEGX_IMM8_Y1
)
650 SIMPLE_REMAP (TILEGX_DEST_IMM8_X1
)
651 SIMPLE_REMAP (TILEGX_MT_IMM14_X1
)
652 SIMPLE_REMAP (TILEGX_MF_IMM14_X1
)
653 SIMPLE_REMAP (TILEGX_MMSTART_X0
)
654 SIMPLE_REMAP (TILEGX_MMEND_X0
)
655 SIMPLE_REMAP (TILEGX_SHAMT_X0
)
656 SIMPLE_REMAP (TILEGX_SHAMT_X1
)
657 SIMPLE_REMAP (TILEGX_SHAMT_Y0
)
658 SIMPLE_REMAP (TILEGX_SHAMT_Y1
)
659 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0
)
660 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0
)
661 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1
)
662 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1
)
663 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2
)
664 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2
)
665 SIMPLE_REMAP (TILEGX_IMM16_X0_HW3
)
666 SIMPLE_REMAP (TILEGX_IMM16_X1_HW3
)
667 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST
)
668 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST
)
669 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST
)
670 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST
)
671 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST
)
672 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST
)
673 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_PCREL
)
674 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_PCREL
)
675 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_PCREL
)
676 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_PCREL
)
677 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_PCREL
)
678 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_PCREL
)
679 SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_PCREL
)
680 SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_PCREL
)
681 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_PCREL
)
682 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_PCREL
)
683 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_PCREL
)
684 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_PCREL
)
685 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_PCREL
)
686 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_PCREL
)
687 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_GOT
)
688 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_GOT
)
689 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_GOT
)
690 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_GOT
)
691 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_GOT
)
692 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_GOT
)
693 SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_GOT
)
694 SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_GOT
)
695 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_GOT
)
696 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_GOT
)
697 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_GOT
)
698 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_GOT
)
699 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_GOT
)
700 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_GOT
)
701 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_GD
)
702 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_GD
)
703 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_TLS_GD
)
704 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_TLS_GD
)
705 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_TLS_GD
)
706 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_TLS_GD
)
707 SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_TLS_GD
)
708 SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_TLS_GD
)
709 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_GD
)
710 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_GD
)
711 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_GD
)
712 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_GD
)
713 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_TLS_GD
)
714 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_TLS_GD
)
715 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_IE
)
716 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_IE
)
717 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_TLS_IE
)
718 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_TLS_IE
)
719 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_TLS_IE
)
720 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_TLS_IE
)
721 SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_TLS_IE
)
722 SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_TLS_IE
)
723 SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_IE
)
724 SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_IE
)
725 SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_IE
)
726 SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_IE
)
727 SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_TLS_IE
)
728 SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_TLS_IE
)
730 SIMPLE_REMAP (TILEGX_TLS_DTPMOD64
)
731 SIMPLE_REMAP (TILEGX_TLS_DTPOFF64
)
732 SIMPLE_REMAP (TILEGX_TLS_TPOFF64
)
734 SIMPLE_REMAP (TILEGX_TLS_DTPMOD32
)
735 SIMPLE_REMAP (TILEGX_TLS_DTPOFF32
)
736 SIMPLE_REMAP (TILEGX_TLS_TPOFF32
)
741 { BFD_RELOC_VTABLE_INHERIT
, R_TILEGX_GNU_VTINHERIT
, tilegx_elf_howto_table2
},
742 { BFD_RELOC_VTABLE_ENTRY
, R_TILEGX_GNU_VTENTRY
, tilegx_elf_howto_table2
},
747 /* The TILE-Gx linker needs to keep track of the number of relocs that it
748 decides to copy as dynamic relocs in check_relocs for each symbol.
749 This is so that it can later discard them if they are found to be
750 unnecessary. We store the information in a field extending the
751 regular ELF linker hash table. */
753 struct tilegx_elf_dyn_relocs
755 struct tilegx_elf_dyn_relocs
*next
;
757 /* The input section of the reloc. */
760 /* Total number of relocs copied for the input section. */
763 /* Number of pc-relative relocs copied for the input section. */
764 bfd_size_type pc_count
;
767 /* TILEGX ELF linker hash entry. */
769 struct tilegx_elf_link_hash_entry
771 struct elf_link_hash_entry elf
;
773 /* Track dynamic relocs copied for this symbol. */
774 struct tilegx_elf_dyn_relocs
*dyn_relocs
;
776 #define GOT_UNKNOWN 0
780 unsigned char tls_type
;
783 #define tilegx_elf_hash_entry(ent) \
784 ((struct tilegx_elf_link_hash_entry *)(ent))
786 struct _bfd_tilegx_elf_obj_tdata
788 struct elf_obj_tdata root
;
790 /* tls_type for each local got entry. */
791 char *local_got_tls_type
;
794 #define _bfd_tilegx_elf_tdata(abfd) \
795 ((struct _bfd_tilegx_elf_obj_tdata *) (abfd)->tdata.any)
797 #define _bfd_tilegx_elf_local_got_tls_type(abfd) \
798 (_bfd_tilegx_elf_tdata (abfd)->local_got_tls_type)
800 #define is_tilegx_elf(bfd) \
801 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
802 && elf_tdata (bfd) != NULL \
803 && elf_object_id (bfd) == TILEGX_ELF_DATA)
805 #include "elf/common.h"
806 #include "elf/internal.h"
808 struct tilegx_elf_link_hash_table
810 struct elf_link_hash_table elf
;
813 int word_align_power
;
818 bfd_vma (*r_info
) (Elf_Internal_Rela
*, bfd_vma
, bfd_vma
);
819 bfd_vma (*r_symndx
) (bfd_vma
);
820 void (*put_word
) (bfd
*, bfd_vma
, void *);
821 const char *dynamic_interpreter
;
823 /* Short-cuts to get to dynamic linker sections. */
827 /* Small local sym to section mapping cache. */
828 struct sym_cache sym_cache
;
832 /* Get the Tile ELF linker hash table from a link_info structure. */
833 #define tilegx_elf_hash_table(p) \
834 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
835 == TILEGX_ELF_DATA ? ((struct tilegx_elf_link_hash_table *) ((p)->hash)) : NULL)
839 tilegx_elf_r_info_64 (Elf_Internal_Rela
*in_rel ATTRIBUTE_UNUSED
,
843 return ELF64_R_INFO (rel_index
, type
);
847 tilegx_elf_r_symndx_64 (bfd_vma r_info
)
849 return ELF64_R_SYM (r_info
);
853 tilegx_put_word_64 (bfd
*abfd
, bfd_vma val
, void *ptr
)
855 bfd_put_64 (abfd
, val
, ptr
);
860 tilegx_elf_r_info_32 (Elf_Internal_Rela
*in_rel ATTRIBUTE_UNUSED
,
864 return ELF32_R_INFO (rel_index
, type
);
868 tilegx_elf_r_symndx_32 (bfd_vma r_info
)
870 return ELF32_R_SYM (r_info
);
874 tilegx_put_word_32 (bfd
*abfd
, bfd_vma val
, void *ptr
)
876 bfd_put_32 (abfd
, val
, ptr
);
880 tilegx_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
881 bfd_reloc_code_real_type code
)
885 for (i
= ARRAY_SIZE (tilegx_reloc_map
); --i
;)
887 const reloc_map
* entry
;
889 entry
= tilegx_reloc_map
+ i
;
891 if (entry
->bfd_reloc_val
== code
)
892 return entry
->table
+ (entry
->tilegx_reloc_val
893 - entry
->table
[0].type
);
900 tilegx_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
906 i
< (sizeof (tilegx_elf_howto_table
)
907 / sizeof (tilegx_elf_howto_table
[0]));
909 if (tilegx_elf_howto_table
[i
].name
!= NULL
910 && strcasecmp (tilegx_elf_howto_table
[i
].name
, r_name
) == 0)
911 return &tilegx_elf_howto_table
[i
];
917 tilegx_info_to_howto_rela (bfd
*abfd ATTRIBUTE_UNUSED
,
919 Elf_Internal_Rela
*dst
)
921 unsigned int r_type
= TILEGX_ELF_R_TYPE (dst
->r_info
);
923 if (r_type
<= (unsigned int) R_TILEGX_TLS_TPOFF32
)
924 cache_ptr
->howto
= &tilegx_elf_howto_table
[r_type
];
925 else if (r_type
- R_TILEGX_GNU_VTINHERIT
926 <= (unsigned int) R_TILEGX_GNU_VTENTRY
)
928 = &tilegx_elf_howto_table2
[r_type
- R_TILEGX_GNU_VTINHERIT
];
933 typedef tilegx_bundle_bits (*tilegx_create_func
)(int);
935 static const tilegx_create_func reloc_to_create_func
[] =
937 /* The first twenty relocation types don't correspond to operands */
959 /* The remaining relocations are used for immediate operands */
1049 tilegx_elf_append_rela (bfd
*abfd
, asection
*s
, Elf_Internal_Rela
*rel
)
1051 const struct elf_backend_data
*bed
;
1054 bed
= get_elf_backend_data (abfd
);
1055 loc
= s
->contents
+ (s
->reloc_count
++ * bed
->s
->sizeof_rela
);
1056 bed
->s
->swap_reloca_out (abfd
, rel
, loc
);
1061 /* The procedure linkage table starts with the following header:
1067 info 10 ## SP not offset, return PC in LR
1070 Subsequent entries are the following, jumping to the header at the end:
1073 moveli r28, <_GLOBAL_OFFSET_TABLE_ - 1f + MY_GOT_OFFSET>
1078 moveli r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
1079 shl16insli r28, r28, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
1083 shl16insli r27, r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
1088 info 10 ## SP not offset, return PC in LR
1091 shl16insli r29, zero, MY_PLT_INDEX
1095 This code sequence lets the code at at the start of the PLT determine
1096 which PLT entry was executed by examining 'r29'.
1098 Note that MY_PLT_INDEX skips over the header entries, so the first
1099 actual jump table entry has index zero.
1101 If the offset fits in 16 bits,
1106 addli r28, r26, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
1107 moveli r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
1110 shl16insli r29, zero, MY_PLT_INDEX
1117 info 10 ## SP not offset, return PC in LR
1119 For the purpose of backtracing, the procedure linkage table ends with the
1120 following tail entry:
1122 info 10 ## SP not offset, return PC in LR
1124 The 32-bit versions are similar, with ld4s replacing ld, and offsets into
1125 the GOT being multiples of 4 instead of 8.
1129 #define PLT_HEADER_SIZE_IN_BUNDLES 3
1130 #define PLT_ENTRY_SIZE_IN_BUNDLES 5
1131 #define PLT_TAIL_SIZE_IN_BUNDLES 1
1133 #define PLT_HEADER_SIZE \
1134 (PLT_HEADER_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
1135 #define PLT_ENTRY_SIZE \
1136 (PLT_ENTRY_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
1137 #define PLT_TAIL_SIZE \
1138 (PLT_TAIL_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
1140 #define GOT_ENTRY_SIZE(htab) TILEGX_ELF_WORD_BYTES (htab)
1142 #define GOTPLT_HEADER_SIZE(htab) (2 * GOT_ENTRY_SIZE (htab))
1144 static const bfd_byte
1145 tilegx64_plt0_entry
[PLT_HEADER_SIZE
] =
1147 0x00, 0x30, 0x48, 0x51,
1148 0x6e, 0x43, 0xa0, 0x18, /* { ld_add r28, r27, 8 } */
1149 0x00, 0x30, 0xbc, 0x35,
1150 0x00, 0x40, 0xde, 0x9e, /* { ld r27, r27 } */
1151 0xff, 0xaf, 0x30, 0x40,
1152 0x60, 0x73, 0x6a, 0x28, /* { info 10 ; jr r27 } */
1155 static const bfd_byte
1156 tilegx64_long_plt_entry
[PLT_ENTRY_SIZE
] =
1158 0xdc, 0x0f, 0x00, 0x10,
1159 0x0d, 0xf0, 0x6a, 0x28, /* { moveli r28, 0 ; lnk r26 } */
1160 0xdb, 0x0f, 0x00, 0x10,
1161 0x8e, 0x03, 0x00, 0x38, /* { moveli r27, 0 ; shl16insli r28, r28, 0 } */
1162 0x9c, 0xc6, 0x0d, 0xd0,
1163 0x6d, 0x03, 0x00, 0x38, /* { add r28, r26, r28 ; shl16insli r27, r27, 0 } */
1164 0x9b, 0xb6, 0xc5, 0xad,
1165 0xff, 0x57, 0xe0, 0x8e, /* { add r27, r26, r27 ; info 10 ; ld r28, r28 } */
1166 0xdd, 0x0f, 0x00, 0x70,
1167 0x80, 0x73, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; jr r28 } */
1170 static const bfd_byte
1171 tilegx64_short_plt_entry
[PLT_ENTRY_SIZE
] =
1173 0x00, 0x30, 0x48, 0x51,
1174 0x0d, 0xf0, 0x6a, 0x28, /* { lnk r26 } */
1175 0x9c, 0x06, 0x00, 0x90,
1176 0xed, 0x07, 0x00, 0x00, /* { addli r28, r26, 0 ; moveli r27, 0 } */
1177 0xdd, 0x0f, 0x00, 0x70,
1178 0x8e, 0xeb, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; ld r28, r28 } */
1179 0x9b, 0xb6, 0x0d, 0x50,
1180 0x80, 0x73, 0x6a, 0x28, /* { add r27, r26, r27 ; jr r28 } */
1181 0x00, 0x30, 0x48, 0xd1,
1182 0xff, 0x57, 0x18, 0x18, /* { info 10 } */
1185 /* Reuse an existing info 10 bundle. */
1186 static const bfd_byte
const *tilegx64_plt_tail_entry
=
1187 &tilegx64_short_plt_entry
[4 * TILEGX_BUNDLE_SIZE_IN_BYTES
];
1189 static const bfd_byte
1190 tilegx32_plt0_entry
[PLT_HEADER_SIZE
] =
1192 0x00, 0x30, 0x48, 0x51,
1193 0x6e, 0x23, 0x58, 0x18, /* { ld4s_add r28, r27, 4 } */
1194 0x00, 0x30, 0xbc, 0x35,
1195 0x00, 0x40, 0xde, 0x9c, /* { ld4s r27, r27 } */
1196 0xff, 0xaf, 0x30, 0x40,
1197 0x60, 0x73, 0x6a, 0x28, /* { info 10 ; jr r27 } */
1200 static const bfd_byte
1201 tilegx32_long_plt_entry
[PLT_ENTRY_SIZE
] =
1203 0xdc, 0x0f, 0x00, 0x10,
1204 0x0d, 0xf0, 0x6a, 0x28, /* { moveli r28, 0 ; lnk r26 } */
1205 0xdb, 0x0f, 0x00, 0x10,
1206 0x8e, 0x03, 0x00, 0x38, /* { moveli r27, 0 ; shl16insli r28, r28, 0 } */
1207 0x9c, 0xc6, 0x0d, 0xd0,
1208 0x6d, 0x03, 0x00, 0x38, /* { add r28, r26, r28 ; shl16insli r27, r27, 0 } */
1209 0x9b, 0xb6, 0xc5, 0xad,
1210 0xff, 0x57, 0xe0, 0x8c, /* { add r27, r26, r27 ; info 10 ; ld4s r28, r28 } */
1211 0xdd, 0x0f, 0x00, 0x70,
1212 0x80, 0x73, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; jr r28 } */
1215 static const bfd_byte
1216 tilegx32_short_plt_entry
[PLT_ENTRY_SIZE
] =
1218 0x00, 0x30, 0x48, 0x51,
1219 0x0d, 0xf0, 0x6a, 0x28, /* { lnk r26 } */
1220 0x9c, 0x06, 0x00, 0x90,
1221 0xed, 0x07, 0x00, 0x00, /* { addli r28, r26, 0 ; moveli r27, 0 } */
1222 0xdd, 0x0f, 0x00, 0x70,
1223 0x8e, 0x9b, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; ld4s r28, r28 } */
1224 0x9b, 0xb6, 0x0d, 0x50,
1225 0x80, 0x73, 0x6a, 0x28, /* { add r27, r26, r27 ; jr r28 } */
1226 0x00, 0x30, 0x48, 0xd1,
1227 0xff, 0x57, 0x18, 0x18, /* { info 10 } */
1230 /* Reuse an existing info 10 bundle. */
1231 static const bfd_byte
const *tilegx32_plt_tail_entry
=
1232 &tilegx64_short_plt_entry
[4 * TILEGX_BUNDLE_SIZE_IN_BYTES
];
1235 tilegx_plt_entry_build (bfd
*output_bfd
,
1236 struct tilegx_elf_link_hash_table
*htab
,
1237 asection
*splt
, asection
*sgotplt
,
1238 bfd_vma offset
, bfd_vma
*r_offset
)
1240 int plt_index
= (offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
1241 int got_offset
= (plt_index
* GOT_ENTRY_SIZE (htab
)
1242 + GOTPLT_HEADER_SIZE (htab
));
1243 tilegx_bundle_bits
*pc
;
1245 /* Compute the distance from the got entry to the lnk. */
1246 bfd_signed_vma dist_got_entry
= sgotplt
->output_section
->vma
1247 + sgotplt
->output_offset
1249 - splt
->output_section
->vma
1250 - splt
->output_offset
1252 - TILEGX_BUNDLE_SIZE_IN_BYTES
;
1254 /* Compute the distance to GOTPLT[0]. */
1255 bfd_signed_vma dist_got0
= dist_got_entry
- got_offset
;
1257 /* Check whether we can use the short plt entry with 16-bit offset. */
1258 bfd_boolean short_plt_entry
=
1259 (dist_got_entry
<= 0x7fff && dist_got0
>= -0x8000);
1261 const tilegx_bundle_bits
*plt_entry
= (tilegx_bundle_bits
*)
1262 (ABI_64_P (output_bfd
) ?
1263 (short_plt_entry
? tilegx64_short_plt_entry
: tilegx64_long_plt_entry
) :
1264 (short_plt_entry
? tilegx32_short_plt_entry
: tilegx32_long_plt_entry
));
1266 /* Copy the plt entry template. */
1267 memcpy (splt
->contents
+ offset
, plt_entry
, PLT_ENTRY_SIZE
);
1269 /* Write the immediate offsets. */
1270 pc
= (tilegx_bundle_bits
*)(splt
->contents
+ offset
);
1272 if (short_plt_entry
)
1277 /* { addli r28, r28, &GOTPLT[MY_GOT_INDEX] ; moveli r27, &GOTPLT[0] } */
1278 *pc
++ |= create_Imm16_X0 (dist_got_entry
)
1279 | create_Imm16_X1 (dist_got0
);
1281 /* { shl16insli r29, zero, MY_PLT_INDEX ; ld r28, r28 } */
1282 *pc
++ |= create_Imm16_X0 (plt_index
);
1286 /* { moveli r28, &GOTPLT[MY_GOT_INDEX] ; lnk r26 } */
1287 *pc
++ |= create_Imm16_X0 (dist_got_entry
>> 16);
1289 /* { moveli r27, &GOTPLT[0] ;
1290 shl16insli r28, r28, &GOTPLT[MY_GOT_INDEX] } */
1291 *pc
++ |= create_Imm16_X0 (dist_got0
>> 16)
1292 | create_Imm16_X1 (dist_got_entry
);
1294 /* { add r28, r26, r28 ; shl16insli r27, r27, &GOTPLT[0] } */
1295 *pc
++ |= create_Imm16_X1 (dist_got0
);
1297 /* { add r27, r26, r27 ; info 10 ; ld r28, r28 } */
1300 /* { shl16insli r29, zero, MY_GOT_INDEX ; jr r28 } */
1301 *pc
++ |= create_Imm16_X0 (plt_index
);
1304 /* Set the relocation offset. */
1305 *r_offset
= got_offset
;
1310 /* Create an entry in an TILEGX ELF linker hash table. */
1312 static struct bfd_hash_entry
*
1313 link_hash_newfunc (struct bfd_hash_entry
*entry
,
1314 struct bfd_hash_table
*table
, const char *string
)
1316 /* Allocate the structure if it has not already been allocated by a
1321 bfd_hash_allocate (table
,
1322 sizeof (struct tilegx_elf_link_hash_entry
));
1327 /* Call the allocation method of the superclass. */
1328 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1331 struct tilegx_elf_link_hash_entry
*eh
;
1333 eh
= (struct tilegx_elf_link_hash_entry
*) entry
;
1334 eh
->dyn_relocs
= NULL
;
1335 eh
->tls_type
= GOT_UNKNOWN
;
1341 /* Create a TILEGX ELF linker hash table. */
1343 struct bfd_link_hash_table
*
1344 tilegx_elf_link_hash_table_create (bfd
*abfd
)
1346 struct tilegx_elf_link_hash_table
*ret
;
1347 bfd_size_type amt
= sizeof (struct tilegx_elf_link_hash_table
);
1349 ret
= (struct tilegx_elf_link_hash_table
*) bfd_zmalloc (amt
);
1354 if (ABI_64_P (abfd
))
1356 ret
->bytes_per_word
= 8;
1357 ret
->word_align_power
= 3;
1358 ret
->bytes_per_rela
= sizeof (Elf64_External_Rela
);
1359 ret
->dtpoff_reloc
= R_TILEGX_TLS_DTPOFF64
;
1360 ret
->dtpmod_reloc
= R_TILEGX_TLS_DTPMOD64
;
1361 ret
->tpoff_reloc
= R_TILEGX_TLS_TPOFF64
;
1362 ret
->r_info
= tilegx_elf_r_info_64
;
1363 ret
->r_symndx
= tilegx_elf_r_symndx_64
;
1364 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
1365 ret
->put_word
= tilegx_put_word_64
;
1370 ret
->bytes_per_word
= 4;
1371 ret
->word_align_power
= 2;
1372 ret
->bytes_per_rela
= sizeof (Elf32_External_Rela
);
1373 ret
->dtpoff_reloc
= R_TILEGX_TLS_DTPOFF32
;
1374 ret
->dtpmod_reloc
= R_TILEGX_TLS_DTPMOD32
;
1375 ret
->tpoff_reloc
= R_TILEGX_TLS_TPOFF32
;
1376 ret
->r_info
= tilegx_elf_r_info_32
;
1377 ret
->r_symndx
= tilegx_elf_r_symndx_32
;
1378 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1379 ret
->put_word
= tilegx_put_word_32
;
1382 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
,
1383 sizeof (struct tilegx_elf_link_hash_entry
),
1390 return &ret
->elf
.root
;
1393 /* Create the .got section. */
1396 tilegx_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
1399 asection
*s
, *s_got
;
1400 struct elf_link_hash_entry
*h
;
1401 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1402 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1404 /* This function may be called more than once. */
1405 s
= bfd_get_section_by_name (abfd
, ".got");
1406 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
1409 flags
= bed
->dynamic_sec_flags
;
1411 s
= bfd_make_section_with_flags (abfd
,
1412 (bed
->rela_plts_and_copies_p
1413 ? ".rela.got" : ".rel.got"),
1414 (bed
->dynamic_sec_flags
1417 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
1421 s
= s_got
= bfd_make_section_with_flags (abfd
, ".got", flags
);
1423 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
1427 /* The first bit of the global offset table is the header. */
1428 s
->size
+= bed
->got_header_size
;
1430 if (bed
->want_got_plt
)
1432 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
1434 || !bfd_set_section_alignment (abfd
, s
,
1435 bed
->s
->log_file_align
))
1439 /* Reserve room for the header. */
1440 s
->size
+= GOTPLT_HEADER_SIZE (tilegx_elf_hash_table (info
));
1443 if (bed
->want_got_sym
)
1445 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
1446 section. We don't do this in the linker script because we don't want
1447 to define the symbol if we are not creating a global offset
1449 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s_got
,
1450 "_GLOBAL_OFFSET_TABLE_");
1451 elf_hash_table (info
)->hgot
= h
;
1459 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1460 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1464 tilegx_elf_create_dynamic_sections (bfd
*dynobj
,
1465 struct bfd_link_info
*info
)
1467 struct tilegx_elf_link_hash_table
*htab
;
1469 htab
= tilegx_elf_hash_table (info
);
1470 BFD_ASSERT (htab
!= NULL
);
1472 if (!tilegx_elf_create_got_section (dynobj
, info
))
1475 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1478 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1480 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1482 if (!htab
->elf
.splt
|| !htab
->elf
.srelplt
|| !htab
->sdynbss
1483 || (!info
->shared
&& !htab
->srelbss
))
1489 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1492 tilegx_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
1493 struct elf_link_hash_entry
*dir
,
1494 struct elf_link_hash_entry
*ind
)
1496 struct tilegx_elf_link_hash_entry
*edir
, *eind
;
1498 edir
= (struct tilegx_elf_link_hash_entry
*) dir
;
1499 eind
= (struct tilegx_elf_link_hash_entry
*) ind
;
1501 if (eind
->dyn_relocs
!= NULL
)
1503 if (edir
->dyn_relocs
!= NULL
)
1505 struct tilegx_elf_dyn_relocs
**pp
;
1506 struct tilegx_elf_dyn_relocs
*p
;
1508 /* Add reloc counts against the indirect sym to the direct sym
1509 list. Merge any entries against the same section. */
1510 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1512 struct tilegx_elf_dyn_relocs
*q
;
1514 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1515 if (q
->sec
== p
->sec
)
1517 q
->pc_count
+= p
->pc_count
;
1518 q
->count
+= p
->count
;
1525 *pp
= edir
->dyn_relocs
;
1528 edir
->dyn_relocs
= eind
->dyn_relocs
;
1529 eind
->dyn_relocs
= NULL
;
1532 if (ind
->root
.type
== bfd_link_hash_indirect
1533 && dir
->got
.refcount
<= 0)
1535 edir
->tls_type
= eind
->tls_type
;
1536 eind
->tls_type
= GOT_UNKNOWN
;
1538 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1541 /* Look through the relocs for a section during the first phase, and
1542 allocate space in the global offset table or procedure linkage
1546 tilegx_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1547 asection
*sec
, const Elf_Internal_Rela
*relocs
)
1549 struct tilegx_elf_link_hash_table
*htab
;
1550 Elf_Internal_Shdr
*symtab_hdr
;
1551 struct elf_link_hash_entry
**sym_hashes
;
1552 const Elf_Internal_Rela
*rel
;
1553 const Elf_Internal_Rela
*rel_end
;
1557 if (info
->relocatable
)
1560 htab
= tilegx_elf_hash_table (info
);
1561 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1562 sym_hashes
= elf_sym_hashes (abfd
);
1566 num_relocs
= sec
->reloc_count
;
1568 BFD_ASSERT (is_tilegx_elf (abfd
) || num_relocs
== 0);
1570 if (htab
->elf
.dynobj
== NULL
)
1571 htab
->elf
.dynobj
= abfd
;
1573 rel_end
= relocs
+ num_relocs
;
1574 for (rel
= relocs
; rel
< rel_end
; rel
++)
1576 unsigned int r_type
;
1577 unsigned long r_symndx
;
1578 struct elf_link_hash_entry
*h
;
1581 r_symndx
= TILEGX_ELF_R_SYMNDX (htab
, rel
->r_info
);
1582 r_type
= TILEGX_ELF_R_TYPE (rel
->r_info
);
1584 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1586 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1591 if (r_symndx
< symtab_hdr
->sh_info
)
1595 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1596 while (h
->root
.type
== bfd_link_hash_indirect
1597 || h
->root
.type
== bfd_link_hash_warning
)
1598 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1603 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
1604 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
1605 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
1606 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
1607 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
1608 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
1609 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
1610 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
1611 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
1612 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
1613 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
1614 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
1615 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
1616 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
1617 tls_type
= GOT_TLS_GD
;
1618 goto have_got_reference
;
1620 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
1621 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
1622 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
1623 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
1624 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
1625 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
1626 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
1627 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
1628 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
1629 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
1630 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
1631 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
1632 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
1633 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
1634 tls_type
= GOT_TLS_IE
;
1636 info
->flags
|= DF_STATIC_TLS
;
1637 goto have_got_reference
;
1639 case R_TILEGX_IMM16_X0_HW0_GOT
:
1640 case R_TILEGX_IMM16_X1_HW0_GOT
:
1641 case R_TILEGX_IMM16_X0_HW1_GOT
:
1642 case R_TILEGX_IMM16_X1_HW1_GOT
:
1643 case R_TILEGX_IMM16_X0_HW2_GOT
:
1644 case R_TILEGX_IMM16_X1_HW2_GOT
:
1645 case R_TILEGX_IMM16_X0_HW3_GOT
:
1646 case R_TILEGX_IMM16_X1_HW3_GOT
:
1647 case R_TILEGX_IMM16_X0_HW0_LAST_GOT
:
1648 case R_TILEGX_IMM16_X1_HW0_LAST_GOT
:
1649 case R_TILEGX_IMM16_X0_HW1_LAST_GOT
:
1650 case R_TILEGX_IMM16_X1_HW1_LAST_GOT
:
1651 case R_TILEGX_IMM16_X0_HW2_LAST_GOT
:
1652 case R_TILEGX_IMM16_X1_HW2_LAST_GOT
:
1653 tls_type
= GOT_NORMAL
;
1657 /* This symbol requires a global offset table entry. */
1663 h
->got
.refcount
+= 1;
1664 old_tls_type
= tilegx_elf_hash_entry(h
)->tls_type
;
1668 bfd_signed_vma
*local_got_refcounts
;
1670 /* This is a global offset table entry for a local symbol. */
1671 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1672 if (local_got_refcounts
== NULL
)
1676 size
= symtab_hdr
->sh_info
;
1677 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
1678 local_got_refcounts
= ((bfd_signed_vma
*)
1679 bfd_zalloc (abfd
, size
));
1680 if (local_got_refcounts
== NULL
)
1682 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1683 _bfd_tilegx_elf_local_got_tls_type (abfd
)
1684 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1686 local_got_refcounts
[r_symndx
] += 1;
1687 old_tls_type
= _bfd_tilegx_elf_local_got_tls_type (abfd
) [r_symndx
];
1690 /* If a TLS symbol is accessed using IE at least once,
1691 there is no point to use dynamic model for it. */
1692 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1693 && (old_tls_type
!= GOT_TLS_GD
1694 || tls_type
!= GOT_TLS_IE
))
1696 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
1697 tls_type
= old_tls_type
;
1700 (*_bfd_error_handler
)
1701 (_("%B: `%s' accessed both as normal and thread local symbol"),
1702 abfd
, h
? h
->root
.root
.string
: "<local>");
1707 if (old_tls_type
!= tls_type
)
1710 tilegx_elf_hash_entry (h
)->tls_type
= tls_type
;
1712 _bfd_tilegx_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1716 if (htab
->elf
.sgot
== NULL
)
1718 if (!tilegx_elf_create_got_section (htab
->elf
.dynobj
, info
))
1723 case R_TILEGX_JUMPOFF_X1_PLT
:
1724 /* This symbol requires a procedure linkage table entry. We
1725 actually build the entry in adjust_dynamic_symbol,
1726 because this might be a case of linking PIC code without
1727 linking in any dynamic objects, in which case we don't
1728 need to generate a procedure linkage table after all. */
1733 h
->plt
.refcount
+= 1;
1737 case R_TILEGX_64_PCREL
:
1738 case R_TILEGX_32_PCREL
:
1739 case R_TILEGX_16_PCREL
:
1740 case R_TILEGX_8_PCREL
:
1741 case R_TILEGX_IMM16_X0_HW0_PCREL
:
1742 case R_TILEGX_IMM16_X1_HW0_PCREL
:
1743 case R_TILEGX_IMM16_X0_HW1_PCREL
:
1744 case R_TILEGX_IMM16_X1_HW1_PCREL
:
1745 case R_TILEGX_IMM16_X0_HW2_PCREL
:
1746 case R_TILEGX_IMM16_X1_HW2_PCREL
:
1747 case R_TILEGX_IMM16_X0_HW3_PCREL
:
1748 case R_TILEGX_IMM16_X1_HW3_PCREL
:
1749 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
1750 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
1751 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
1752 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
1753 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
1754 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
1759 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1771 case R_TILEGX_HW0_LAST
:
1772 case R_TILEGX_HW1_LAST
:
1773 case R_TILEGX_HW2_LAST
:
1775 case R_TILEGX_GLOB_DAT
:
1776 case R_TILEGX_JMP_SLOT
:
1777 case R_TILEGX_RELATIVE
:
1778 case R_TILEGX_BROFF_X1
:
1779 case R_TILEGX_JUMPOFF_X1
:
1780 case R_TILEGX_IMM8_X0
:
1781 case R_TILEGX_IMM8_Y0
:
1782 case R_TILEGX_IMM8_X1
:
1783 case R_TILEGX_IMM8_Y1
:
1784 case R_TILEGX_DEST_IMM8_X1
:
1785 case R_TILEGX_MT_IMM14_X1
:
1786 case R_TILEGX_MF_IMM14_X1
:
1787 case R_TILEGX_MMSTART_X0
:
1788 case R_TILEGX_MMEND_X0
:
1789 case R_TILEGX_SHAMT_X0
:
1790 case R_TILEGX_SHAMT_X1
:
1791 case R_TILEGX_SHAMT_Y0
:
1792 case R_TILEGX_SHAMT_Y1
:
1793 case R_TILEGX_IMM16_X0_HW0
:
1794 case R_TILEGX_IMM16_X1_HW0
:
1795 case R_TILEGX_IMM16_X0_HW1
:
1796 case R_TILEGX_IMM16_X1_HW1
:
1797 case R_TILEGX_IMM16_X0_HW2
:
1798 case R_TILEGX_IMM16_X1_HW2
:
1799 case R_TILEGX_IMM16_X0_HW3
:
1800 case R_TILEGX_IMM16_X1_HW3
:
1801 case R_TILEGX_IMM16_X0_HW0_LAST
:
1802 case R_TILEGX_IMM16_X1_HW0_LAST
:
1803 case R_TILEGX_IMM16_X0_HW1_LAST
:
1804 case R_TILEGX_IMM16_X1_HW1_LAST
:
1805 case R_TILEGX_IMM16_X0_HW2_LAST
:
1806 case R_TILEGX_IMM16_X1_HW2_LAST
:
1813 /* We may need a .plt entry if the function this reloc
1814 refers to is in a shared lib. */
1815 h
->plt
.refcount
+= 1;
1819 /* If we are creating a shared library, and this is a reloc
1820 against a global symbol, or a non PC relative reloc
1821 against a local symbol, then we need to copy the reloc
1822 into the shared library. However, if we are linking with
1823 -Bsymbolic, we do not need to copy a reloc against a
1824 global symbol which is defined in an object we are
1825 including in the link (i.e., DEF_REGULAR is set). At
1826 this point we have not seen all the input files, so it is
1827 possible that DEF_REGULAR is not set now but will be set
1828 later (it is never cleared). In case of a weak definition,
1829 DEF_REGULAR may be cleared later by a strong definition in
1830 a shared library. We account for that possibility below by
1831 storing information in the relocs_copied field of the hash
1832 table entry. A similar situation occurs when creating
1833 shared libraries and symbol visibility changes render the
1836 If on the other hand, we are creating an executable, we
1837 may need to keep relocations for symbols satisfied by a
1838 dynamic library if we manage to avoid copy relocs for the
1841 && (sec
->flags
& SEC_ALLOC
) != 0
1842 && (! tilegx_elf_howto_table
[r_type
].pc_relative
1844 && (! info
->symbolic
1845 || h
->root
.type
== bfd_link_hash_defweak
1846 || !h
->def_regular
))))
1848 && (sec
->flags
& SEC_ALLOC
) != 0
1850 && (h
->root
.type
== bfd_link_hash_defweak
1851 || !h
->def_regular
)))
1853 struct tilegx_elf_dyn_relocs
*p
;
1854 struct tilegx_elf_dyn_relocs
**head
;
1856 /* When creating a shared object, we must copy these
1857 relocs into the output file. We create a reloc
1858 section in dynobj and make room for the reloc. */
1861 sreloc
= _bfd_elf_make_dynamic_reloc_section
1862 (sec
, htab
->elf
.dynobj
, htab
->word_align_power
, abfd
,
1869 /* If this is a global symbol, we count the number of
1870 relocations we need for this symbol. */
1873 &((struct tilegx_elf_link_hash_entry
*) h
)->dyn_relocs
;
1876 /* Track dynamic relocs needed for local syms too.
1877 We really need local syms available to do this
1882 Elf_Internal_Sym
*isym
;
1884 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1889 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1893 vpp
= &elf_section_data (s
)->local_dynrel
;
1894 head
= (struct tilegx_elf_dyn_relocs
**) vpp
;
1898 if (p
== NULL
|| p
->sec
!= sec
)
1900 bfd_size_type amt
= sizeof *p
;
1901 p
= ((struct tilegx_elf_dyn_relocs
*)
1902 bfd_alloc (htab
->elf
.dynobj
, amt
));
1913 if (tilegx_elf_howto_table
[r_type
].pc_relative
)
1919 case R_TILEGX_GNU_VTINHERIT
:
1920 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1924 case R_TILEGX_GNU_VTENTRY
:
1925 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1939 tilegx_elf_gc_mark_hook (asection
*sec
,
1940 struct bfd_link_info
*info
,
1941 Elf_Internal_Rela
*rel
,
1942 struct elf_link_hash_entry
*h
,
1943 Elf_Internal_Sym
*sym
)
1947 switch (TILEGX_ELF_R_TYPE (rel
->r_info
))
1949 case R_TILEGX_GNU_VTINHERIT
:
1950 case R_TILEGX_GNU_VTENTRY
:
1955 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1958 /* Update the got entry reference counts for the section being removed. */
1960 tilegx_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1961 asection
*sec
, const Elf_Internal_Rela
*relocs
)
1963 struct tilegx_elf_link_hash_table
*htab
;
1964 Elf_Internal_Shdr
*symtab_hdr
;
1965 struct elf_link_hash_entry
**sym_hashes
;
1966 bfd_signed_vma
*local_got_refcounts
;
1967 const Elf_Internal_Rela
*rel
, *relend
;
1969 if (info
->relocatable
)
1972 BFD_ASSERT (is_tilegx_elf (abfd
) || sec
->reloc_count
== 0);
1974 elf_section_data (sec
)->local_dynrel
= NULL
;
1976 htab
= tilegx_elf_hash_table (info
);
1977 BFD_ASSERT (htab
!= NULL
);
1978 symtab_hdr
= &elf_symtab_hdr (abfd
);
1979 sym_hashes
= elf_sym_hashes (abfd
);
1980 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1982 relend
= relocs
+ sec
->reloc_count
;
1983 for (rel
= relocs
; rel
< relend
; rel
++)
1985 unsigned long r_symndx
;
1986 unsigned int r_type
;
1987 struct elf_link_hash_entry
*h
= NULL
;
1989 r_symndx
= TILEGX_ELF_R_SYMNDX (htab
, rel
->r_info
);
1990 if (r_symndx
>= symtab_hdr
->sh_info
)
1992 struct tilegx_elf_link_hash_entry
*eh
;
1993 struct tilegx_elf_dyn_relocs
**pp
;
1994 struct tilegx_elf_dyn_relocs
*p
;
1996 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1997 while (h
->root
.type
== bfd_link_hash_indirect
1998 || h
->root
.type
== bfd_link_hash_warning
)
1999 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2000 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2001 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2004 /* Everything must go for SEC. */
2010 r_type
= TILEGX_ELF_R_TYPE (rel
->r_info
);
2014 case R_TILEGX_IMM16_X0_HW0_GOT
:
2015 case R_TILEGX_IMM16_X1_HW0_GOT
:
2016 case R_TILEGX_IMM16_X0_HW1_GOT
:
2017 case R_TILEGX_IMM16_X1_HW1_GOT
:
2018 case R_TILEGX_IMM16_X0_HW2_GOT
:
2019 case R_TILEGX_IMM16_X1_HW2_GOT
:
2020 case R_TILEGX_IMM16_X0_HW3_GOT
:
2021 case R_TILEGX_IMM16_X1_HW3_GOT
:
2022 case R_TILEGX_IMM16_X0_HW0_LAST_GOT
:
2023 case R_TILEGX_IMM16_X1_HW0_LAST_GOT
:
2024 case R_TILEGX_IMM16_X0_HW1_LAST_GOT
:
2025 case R_TILEGX_IMM16_X1_HW1_LAST_GOT
:
2026 case R_TILEGX_IMM16_X0_HW2_LAST_GOT
:
2027 case R_TILEGX_IMM16_X1_HW2_LAST_GOT
:
2028 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
2029 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
2030 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
2031 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
2032 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
2033 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
2034 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
2035 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
2036 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
2037 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
2038 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
2039 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
2040 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
2041 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
2042 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
2043 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
2044 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
2045 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
2046 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
2047 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
2048 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
2049 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
2050 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
2051 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
2052 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
2053 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
2054 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
2055 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
2058 if (h
->got
.refcount
> 0)
2063 if (local_got_refcounts
[r_symndx
] > 0)
2064 local_got_refcounts
[r_symndx
]--;
2068 case R_TILEGX_64_PCREL
:
2069 case R_TILEGX_32_PCREL
:
2070 case R_TILEGX_16_PCREL
:
2071 case R_TILEGX_8_PCREL
:
2072 case R_TILEGX_IMM16_X0_HW0_PCREL
:
2073 case R_TILEGX_IMM16_X1_HW0_PCREL
:
2074 case R_TILEGX_IMM16_X0_HW1_PCREL
:
2075 case R_TILEGX_IMM16_X1_HW1_PCREL
:
2076 case R_TILEGX_IMM16_X0_HW2_PCREL
:
2077 case R_TILEGX_IMM16_X1_HW2_PCREL
:
2078 case R_TILEGX_IMM16_X0_HW3_PCREL
:
2079 case R_TILEGX_IMM16_X1_HW3_PCREL
:
2080 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
2081 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
2082 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
2083 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
2084 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
2085 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
2087 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2099 case R_TILEGX_HW0_LAST
:
2100 case R_TILEGX_HW1_LAST
:
2101 case R_TILEGX_HW2_LAST
:
2103 case R_TILEGX_GLOB_DAT
:
2104 case R_TILEGX_JMP_SLOT
:
2105 case R_TILEGX_RELATIVE
:
2106 case R_TILEGX_BROFF_X1
:
2107 case R_TILEGX_JUMPOFF_X1
:
2108 case R_TILEGX_IMM8_X0
:
2109 case R_TILEGX_IMM8_Y0
:
2110 case R_TILEGX_IMM8_X1
:
2111 case R_TILEGX_IMM8_Y1
:
2112 case R_TILEGX_DEST_IMM8_X1
:
2113 case R_TILEGX_MT_IMM14_X1
:
2114 case R_TILEGX_MF_IMM14_X1
:
2115 case R_TILEGX_MMSTART_X0
:
2116 case R_TILEGX_MMEND_X0
:
2117 case R_TILEGX_SHAMT_X0
:
2118 case R_TILEGX_SHAMT_X1
:
2119 case R_TILEGX_SHAMT_Y0
:
2120 case R_TILEGX_SHAMT_Y1
:
2121 case R_TILEGX_IMM16_X0_HW0
:
2122 case R_TILEGX_IMM16_X1_HW0
:
2123 case R_TILEGX_IMM16_X0_HW1
:
2124 case R_TILEGX_IMM16_X1_HW1
:
2125 case R_TILEGX_IMM16_X0_HW2
:
2126 case R_TILEGX_IMM16_X1_HW2
:
2127 case R_TILEGX_IMM16_X0_HW3
:
2128 case R_TILEGX_IMM16_X1_HW3
:
2129 case R_TILEGX_IMM16_X0_HW0_LAST
:
2130 case R_TILEGX_IMM16_X1_HW0_LAST
:
2131 case R_TILEGX_IMM16_X0_HW1_LAST
:
2132 case R_TILEGX_IMM16_X1_HW1_LAST
:
2133 case R_TILEGX_IMM16_X0_HW2_LAST
:
2134 case R_TILEGX_IMM16_X1_HW2_LAST
:
2139 case R_TILEGX_JUMPOFF_X1_PLT
:
2142 if (h
->plt
.refcount
> 0)
2155 /* Adjust a symbol defined by a dynamic object and referenced by a
2156 regular object. The current definition is in some section of the
2157 dynamic object, but we're not including those sections. We have to
2158 change the definition to something the rest of the link can
2162 tilegx_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2163 struct elf_link_hash_entry
*h
)
2165 struct tilegx_elf_link_hash_table
*htab
;
2166 struct tilegx_elf_link_hash_entry
* eh
;
2167 struct tilegx_elf_dyn_relocs
*p
;
2171 htab
= tilegx_elf_hash_table (info
);
2172 BFD_ASSERT (htab
!= NULL
);
2174 dynobj
= htab
->elf
.dynobj
;
2176 /* Make sure we know what is going on here. */
2177 BFD_ASSERT (dynobj
!= NULL
2179 || h
->u
.weakdef
!= NULL
2182 && !h
->def_regular
)));
2184 /* If this is a function, put it in the procedure linkage table. We
2185 will fill in the contents of the procedure linkage table later
2186 (although we could actually do it here). */
2187 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
2189 if (h
->plt
.refcount
<= 0
2190 || SYMBOL_CALLS_LOCAL (info
, h
)
2191 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2192 && h
->root
.type
== bfd_link_hash_undefweak
))
2194 /* This case can occur if we saw a R_TILEGX_JUMPOFF_X1_PLT
2195 reloc in an input file, but the symbol was never referred
2196 to by a dynamic object, or if all references were garbage
2197 collected. In such a case, we don't actually need to build
2198 a procedure linkage table, and we can just do a
2199 R_TILEGX_JUMPOFF_X1 relocation instead. */
2200 h
->plt
.offset
= (bfd_vma
) -1;
2207 h
->plt
.offset
= (bfd_vma
) -1;
2209 /* If this is a weak symbol, and there is a real definition, the
2210 processor independent code will have arranged for us to see the
2211 real definition first, and we can just use the same value. */
2212 if (h
->u
.weakdef
!= NULL
)
2214 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2215 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2216 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2217 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2221 /* This is a reference to a symbol defined by a dynamic object which
2222 is not a function. */
2224 /* If we are creating a shared library, we must presume that the
2225 only references to the symbol are via the global offset table.
2226 For such cases we need not do anything here; the relocations will
2227 be handled correctly by relocate_section. */
2231 /* If there are no references to this symbol that do not use the
2232 GOT, we don't need to generate a copy reloc. */
2233 if (!h
->non_got_ref
)
2236 /* If -z nocopyreloc was given, we won't generate them either. */
2237 if (info
->nocopyreloc
)
2243 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2244 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2246 s
= p
->sec
->output_section
;
2247 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2251 /* If we didn't find any dynamic relocs in read-only sections, then
2252 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2261 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2262 h
->root
.root
.string
);
2266 /* We must allocate the symbol in our .dynbss section, which will
2267 become part of the .bss section of the executable. There will be
2268 an entry for this symbol in the .dynsym section. The dynamic
2269 object will contain position independent code, so all references
2270 from the dynamic object to this symbol will go through the global
2271 offset table. The dynamic linker will use the .dynsym entry to
2272 determine the address it must put in the global offset table, so
2273 both the dynamic object and the regular object will refer to the
2274 same memory location for the variable. */
2276 /* We must generate a R_TILEGX_COPY reloc to tell the dynamic linker
2277 to copy the initial value out of the dynamic object and into the
2278 runtime process image. We need to remember the offset into the
2279 .rel.bss section we are going to use. */
2280 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2282 htab
->srelbss
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2286 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
2289 /* Allocate space in .plt, .got and associated reloc sections for
2293 allocate_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
2295 struct bfd_link_info
*info
;
2296 struct tilegx_elf_link_hash_table
*htab
;
2297 struct tilegx_elf_link_hash_entry
*eh
;
2298 struct tilegx_elf_dyn_relocs
*p
;
2300 if (h
->root
.type
== bfd_link_hash_indirect
)
2303 if (h
->root
.type
== bfd_link_hash_warning
)
2304 /* When warning symbols are created, they **replace** the "real"
2305 entry in the hash table, thus we never get to see the real
2306 symbol in a hash traversal. So look at it now. */
2307 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2309 info
= (struct bfd_link_info
*) inf
;
2310 htab
= tilegx_elf_hash_table (info
);
2311 BFD_ASSERT (htab
!= NULL
);
2313 if (htab
->elf
.dynamic_sections_created
2314 && h
->plt
.refcount
> 0)
2316 /* Make sure this symbol is output as a dynamic symbol.
2317 Undefined weak syms won't yet be marked as dynamic. */
2318 if (h
->dynindx
== -1
2319 && !h
->forced_local
)
2321 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2325 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
2327 asection
*s
= htab
->elf
.splt
;
2329 /* Allocate room for the header and tail. */
2332 s
->size
= PLT_HEADER_SIZE
+ PLT_TAIL_SIZE
;
2335 h
->plt
.offset
= s
->size
- PLT_TAIL_SIZE
;
2337 /* If this symbol is not defined in a regular file, and we are
2338 not generating a shared library, then set the symbol to this
2339 location in the .plt. This is required to make function
2340 pointers compare as equal between the normal executable and
2341 the shared library. */
2345 h
->root
.u
.def
.section
= s
;
2346 h
->root
.u
.def
.value
= h
->plt
.offset
;
2349 /* Make room for this entry. */
2350 s
->size
+= PLT_ENTRY_SIZE
;
2352 /* We also need to make an entry in the .got.plt section. */
2353 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE (htab
);
2355 /* We also need to make an entry in the .rela.plt section. */
2356 htab
->elf
.srelplt
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2360 h
->plt
.offset
= (bfd_vma
) -1;
2366 h
->plt
.offset
= (bfd_vma
) -1;
2370 if (h
->got
.refcount
> 0)
2374 int tls_type
= tilegx_elf_hash_entry(h
)->tls_type
;
2376 /* Make sure this symbol is output as a dynamic symbol.
2377 Undefined weak syms won't yet be marked as dynamic. */
2378 if (h
->dynindx
== -1
2379 && !h
->forced_local
)
2381 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2386 h
->got
.offset
= s
->size
;
2387 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2388 /* TLS_GD entries need 2 consecutive GOT slots. */
2389 if (tls_type
== GOT_TLS_GD
)
2390 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2391 dyn
= htab
->elf
.dynamic_sections_created
;
2392 /* TLS_IE needs one dynamic relocation,
2393 TLS_GD needs two if local symbol and two if global. */
2394 if (tls_type
== GOT_TLS_GD
|| tls_type
== GOT_TLS_IE
)
2395 htab
->elf
.srelgot
->size
+= 2 * TILEGX_ELF_RELA_BYTES (htab
);
2396 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
2397 htab
->elf
.srelgot
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2400 h
->got
.offset
= (bfd_vma
) -1;
2402 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2403 if (eh
->dyn_relocs
== NULL
)
2406 /* In the shared -Bsymbolic case, discard space allocated for
2407 dynamic pc-relative relocs against symbols which turn out to be
2408 defined in regular objects. For the normal shared case, discard
2409 space for pc-relative relocs that have become local due to symbol
2410 visibility changes. */
2414 if (SYMBOL_CALLS_LOCAL (info
, h
))
2416 struct tilegx_elf_dyn_relocs
**pp
;
2418 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2420 p
->count
-= p
->pc_count
;
2429 /* Also discard relocs on undefined weak syms with non-default
2431 if (eh
->dyn_relocs
!= NULL
2432 && h
->root
.type
== bfd_link_hash_undefweak
)
2434 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2435 eh
->dyn_relocs
= NULL
;
2437 /* Make sure undefined weak symbols are output as a dynamic
2439 else if (h
->dynindx
== -1
2440 && !h
->forced_local
)
2442 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2449 /* For the non-shared case, discard space for relocs against
2450 symbols which turn out to need copy relocs or are not
2456 || (htab
->elf
.dynamic_sections_created
2457 && (h
->root
.type
== bfd_link_hash_undefweak
2458 || h
->root
.type
== bfd_link_hash_undefined
))))
2460 /* Make sure this symbol is output as a dynamic symbol.
2461 Undefined weak syms won't yet be marked as dynamic. */
2462 if (h
->dynindx
== -1
2463 && !h
->forced_local
)
2465 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2469 /* If that succeeded, we know we'll be keeping all the
2471 if (h
->dynindx
!= -1)
2475 eh
->dyn_relocs
= NULL
;
2480 /* Finally, allocate space. */
2481 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2483 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2484 sreloc
->size
+= p
->count
* TILEGX_ELF_RELA_BYTES (htab
);
2490 /* Find any dynamic relocs that apply to read-only sections. */
2493 readonly_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
2495 struct tilegx_elf_link_hash_entry
*eh
;
2496 struct tilegx_elf_dyn_relocs
*p
;
2498 if (h
->root
.type
== bfd_link_hash_warning
)
2499 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2501 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2502 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2504 asection
*s
= p
->sec
->output_section
;
2506 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2508 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2510 info
->flags
|= DF_TEXTREL
;
2512 /* Not an error, just cut short the traversal. */
2519 /* Return true if the dynamic symbol for a given section should be
2520 omitted when creating a shared library. */
2523 tilegx_elf_omit_section_dynsym (bfd
*output_bfd
,
2524 struct bfd_link_info
*info
,
2527 /* We keep the .got section symbol so that explicit relocations
2528 against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
2529 can be turned into relocations against the .got symbol. */
2530 if (strcmp (p
->name
, ".got") == 0)
2533 return _bfd_elf_link_omit_section_dynsym (output_bfd
, info
, p
);
2537 tilegx_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2538 struct bfd_link_info
*info
)
2540 struct tilegx_elf_link_hash_table
*htab
;
2545 htab
= tilegx_elf_hash_table (info
);
2546 BFD_ASSERT (htab
!= NULL
);
2547 dynobj
= htab
->elf
.dynobj
;
2548 BFD_ASSERT (dynobj
!= NULL
);
2550 if (elf_hash_table (info
)->dynamic_sections_created
)
2552 /* Set the contents of the .interp section to the interpreter. */
2553 if (info
->executable
)
2555 s
= bfd_get_section_by_name (dynobj
, ".interp");
2556 BFD_ASSERT (s
!= NULL
);
2557 s
->size
= strlen (htab
->dynamic_interpreter
) + 1;
2558 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2562 /* Set up .got offsets for local syms, and space for local dynamic
2564 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2566 bfd_signed_vma
*local_got
;
2567 bfd_signed_vma
*end_local_got
;
2568 char *local_tls_type
;
2569 bfd_size_type locsymcount
;
2570 Elf_Internal_Shdr
*symtab_hdr
;
2573 if (! is_tilegx_elf (ibfd
))
2576 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2578 struct tilegx_elf_dyn_relocs
*p
;
2580 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
2582 if (!bfd_is_abs_section (p
->sec
)
2583 && bfd_is_abs_section (p
->sec
->output_section
))
2585 /* Input section has been discarded, either because
2586 it is a copy of a linkonce section or due to
2587 linker script /DISCARD/, so we'll be discarding
2590 else if (p
->count
!= 0)
2592 srel
= elf_section_data (p
->sec
)->sreloc
;
2593 srel
->size
+= p
->count
* TILEGX_ELF_RELA_BYTES (htab
);
2594 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2595 info
->flags
|= DF_TEXTREL
;
2600 local_got
= elf_local_got_refcounts (ibfd
);
2604 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2605 locsymcount
= symtab_hdr
->sh_info
;
2606 end_local_got
= local_got
+ locsymcount
;
2607 local_tls_type
= _bfd_tilegx_elf_local_got_tls_type (ibfd
);
2609 srel
= htab
->elf
.srelgot
;
2610 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
2614 *local_got
= s
->size
;
2615 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2616 if (*local_tls_type
== GOT_TLS_GD
)
2617 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2619 || *local_tls_type
== GOT_TLS_GD
2620 || *local_tls_type
== GOT_TLS_IE
)
2621 srel
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2624 *local_got
= (bfd_vma
) -1;
2628 /* Allocate global sym .plt and .got entries, and space for global
2629 sym dynamic relocs. */
2630 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
2632 if (elf_hash_table (info
)->dynamic_sections_created
)
2634 /* If the .got section is more than 0x8000 bytes, we add
2635 0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16
2636 bit relocations have a greater chance of working. */
2637 if (htab
->elf
.sgot
->size
>= 0x8000
2638 && elf_hash_table (info
)->hgot
->root
.u
.def
.value
== 0)
2639 elf_hash_table (info
)->hgot
->root
.u
.def
.value
= 0x8000;
2642 if (htab
->elf
.sgotplt
)
2644 struct elf_link_hash_entry
*got
;
2645 got
= elf_link_hash_lookup (elf_hash_table (info
),
2646 "_GLOBAL_OFFSET_TABLE_",
2647 FALSE
, FALSE
, FALSE
);
2649 /* Don't allocate .got.plt section if there are no GOT nor PLT
2650 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2652 || !got
->ref_regular_nonweak
)
2653 && (htab
->elf
.sgotplt
->size
2654 == (unsigned)GOTPLT_HEADER_SIZE (htab
))
2655 && (htab
->elf
.splt
== NULL
2656 || htab
->elf
.splt
->size
== 0)
2657 && (htab
->elf
.sgot
== NULL
2658 || (htab
->elf
.sgot
->size
2659 == get_elf_backend_data (output_bfd
)->got_header_size
)))
2660 htab
->elf
.sgotplt
->size
= 0;
2663 /* The check_relocs and adjust_dynamic_symbol entry points have
2664 determined the sizes of the various dynamic sections. Allocate
2666 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2668 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2671 if (s
== htab
->elf
.splt
2672 || s
== htab
->elf
.sgot
2673 || s
== htab
->elf
.sgotplt
2674 || s
== htab
->sdynbss
)
2676 /* Strip this section if we don't need it; see the
2679 else if (strncmp (s
->name
, ".rela", 5) == 0)
2683 /* We use the reloc_count field as a counter if we need
2684 to copy relocs into the output file. */
2690 /* It's not one of our sections. */
2696 /* If we don't need this section, strip it from the
2697 output file. This is mostly to handle .rela.bss and
2698 .rela.plt. We must create both sections in
2699 create_dynamic_sections, because they must be created
2700 before the linker maps input sections to output
2701 sections. The linker does that before
2702 adjust_dynamic_symbol is called, and it is that
2703 function which decides whether anything needs to go
2704 into these sections. */
2705 s
->flags
|= SEC_EXCLUDE
;
2709 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2712 /* Allocate memory for the section contents. Zero the memory
2713 for the benefit of .rela.plt, which has 4 unused entries
2714 at the beginning, and we don't want garbage. */
2715 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2716 if (s
->contents
== NULL
)
2720 if (elf_hash_table (info
)->dynamic_sections_created
)
2722 /* Add some entries to the .dynamic section. We fill in the
2723 values later, in tilegx_elf_finish_dynamic_sections, but we
2724 must add the entries now so that we get the correct size for
2725 the .dynamic section. The DT_DEBUG entry is filled in by the
2726 dynamic linker and used by the debugger. */
2727 #define add_dynamic_entry(TAG, VAL) \
2728 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2730 if (info
->executable
)
2732 if (!add_dynamic_entry (DT_DEBUG
, 0))
2736 if (htab
->elf
.srelplt
->size
!= 0)
2738 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2739 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2740 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2741 || !add_dynamic_entry (DT_JMPREL
, 0))
2745 if (!add_dynamic_entry (DT_RELA
, 0)
2746 || !add_dynamic_entry (DT_RELASZ
, 0)
2747 || !add_dynamic_entry (DT_RELAENT
, TILEGX_ELF_RELA_BYTES (htab
)))
2750 /* If any dynamic relocs apply to a read-only section,
2751 then we need a DT_TEXTREL entry. */
2752 if ((info
->flags
& DF_TEXTREL
) == 0)
2753 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2756 if (info
->flags
& DF_TEXTREL
)
2758 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2762 #undef add_dynamic_entry
2767 /* Return the base VMA address which should be subtracted from real addresses
2768 when resolving @dtpoff relocation.
2769 This is PT_TLS segment p_vaddr. */
2772 dtpoff_base (struct bfd_link_info
*info
)
2774 /* If tls_sec is NULL, we should have signalled an error already. */
2775 if (elf_hash_table (info
)->tls_sec
== NULL
)
2777 return elf_hash_table (info
)->tls_sec
->vma
;
2780 /* Return the relocation value for @tpoff relocation. */
2783 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2785 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2787 /* If tls_sec is NULL, we should have signalled an error already. */
2788 if (htab
->tls_sec
== NULL
)
2791 return (address
- htab
->tls_sec
->vma
);
2794 /* Relocate an TILEGX ELF section.
2796 The RELOCATE_SECTION function is called by the new ELF backend linker
2797 to handle the relocations for a section.
2799 The relocs are always passed as Rela structures.
2801 This function is responsible for adjusting the section contents as
2802 necessary, and (if generating a relocatable output file) adjusting
2803 the reloc addend as necessary.
2805 This function does not have to worry about setting the reloc
2806 address or the reloc symbol index.
2808 LOCAL_SYMS is a pointer to the swapped in local symbols.
2810 LOCAL_SECTIONS is an array giving the section in the input file
2811 corresponding to the st_shndx field of each local symbol.
2813 The global hash table entry for the global symbols can be found
2814 via elf_sym_hashes (input_bfd).
2816 When generating relocatable output, this function must handle
2817 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2818 going to be the section symbol corresponding to the output
2819 section, which means that the addend must be adjusted
2823 tilegx_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
2824 bfd
*input_bfd
, asection
*input_section
,
2825 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
2826 Elf_Internal_Sym
*local_syms
,
2827 asection
**local_sections
)
2829 struct tilegx_elf_link_hash_table
*htab
;
2830 Elf_Internal_Shdr
*symtab_hdr
;
2831 struct elf_link_hash_entry
**sym_hashes
;
2832 bfd_vma
*local_got_offsets
;
2835 Elf_Internal_Rela
*rel
;
2836 Elf_Internal_Rela
*relend
;
2839 htab
= tilegx_elf_hash_table (info
);
2840 BFD_ASSERT (htab
!= NULL
);
2841 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2842 sym_hashes
= elf_sym_hashes (input_bfd
);
2843 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2845 if (elf_hash_table (info
)->hgot
== NULL
)
2848 got_base
= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
2850 sreloc
= elf_section_data (input_section
)->sreloc
;
2853 num_relocs
= input_section
->reloc_count
;
2854 relend
= relocs
+ num_relocs
;
2855 for (; rel
< relend
; rel
++)
2857 int r_type
, tls_type
;
2858 reloc_howto_type
*howto
;
2859 unsigned long r_symndx
;
2860 struct elf_link_hash_entry
*h
;
2861 Elf_Internal_Sym
*sym
;
2862 tilegx_create_func create_func
;
2865 bfd_reloc_status_type r
;
2868 bfd_boolean is_plt
= FALSE
;
2870 bfd_boolean unresolved_reloc
;
2872 r_type
= TILEGX_ELF_R_TYPE (rel
->r_info
);
2873 if (r_type
== R_TILEGX_GNU_VTINHERIT
2874 || r_type
== R_TILEGX_GNU_VTENTRY
)
2877 if ((unsigned int)r_type
>= ARRAY_SIZE (tilegx_elf_howto_table
))
2879 /* Not clear if we need to check here, but just be paranoid. */
2880 (*_bfd_error_handler
)
2881 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2882 input_bfd
, r_type
, input_section
);
2883 bfd_set_error (bfd_error_bad_value
);
2887 howto
= tilegx_elf_howto_table
+ r_type
;
2889 /* This is a final link. */
2890 r_symndx
= TILEGX_ELF_R_SYMNDX (htab
, rel
->r_info
);
2894 unresolved_reloc
= FALSE
;
2895 if (r_symndx
< symtab_hdr
->sh_info
)
2897 sym
= local_syms
+ r_symndx
;
2898 sec
= local_sections
[r_symndx
];
2899 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2905 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2906 r_symndx
, symtab_hdr
, sym_hashes
,
2908 unresolved_reloc
, warned
);
2911 /* To avoid generating warning messages about truncated
2912 relocations, set the relocation's address to be the same as
2913 the start of this section. */
2914 if (input_section
->output_section
!= NULL
)
2915 relocation
= input_section
->output_section
->vma
;
2921 if (sec
!= NULL
&& elf_discarded_section (sec
))
2922 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2923 rel
, relend
, howto
, contents
);
2925 if (info
->relocatable
)
2929 name
= h
->root
.root
.string
;
2932 name
= (bfd_elf_string_from_elf_section
2933 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2934 if (name
== NULL
|| *name
== '\0')
2935 name
= bfd_section_name (input_bfd
, sec
);
2940 case R_TILEGX_IMM16_X0_HW0_GOT
:
2941 case R_TILEGX_IMM16_X1_HW0_GOT
:
2942 case R_TILEGX_IMM16_X0_HW1_GOT
:
2943 case R_TILEGX_IMM16_X1_HW1_GOT
:
2944 case R_TILEGX_IMM16_X0_HW2_GOT
:
2945 case R_TILEGX_IMM16_X1_HW2_GOT
:
2946 case R_TILEGX_IMM16_X0_HW3_GOT
:
2947 case R_TILEGX_IMM16_X1_HW3_GOT
:
2948 case R_TILEGX_IMM16_X0_HW0_LAST_GOT
:
2949 case R_TILEGX_IMM16_X1_HW0_LAST_GOT
:
2950 case R_TILEGX_IMM16_X0_HW1_LAST_GOT
:
2951 case R_TILEGX_IMM16_X1_HW1_LAST_GOT
:
2952 case R_TILEGX_IMM16_X0_HW2_LAST_GOT
:
2953 case R_TILEGX_IMM16_X1_HW2_LAST_GOT
:
2954 /* Relocation is to the entry for this symbol in the global
2956 if (htab
->elf
.sgot
== NULL
)
2963 off
= h
->got
.offset
;
2964 BFD_ASSERT (off
!= (bfd_vma
) -1);
2965 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2967 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2969 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
2971 /* This is actually a static link, or it is a
2972 -Bsymbolic link and the symbol is defined
2973 locally, or the symbol was forced to be local
2974 because of a version file. We must initialize
2975 this entry in the global offset table. Since the
2976 offset must always be a multiple
2977 of 8 for 64-bit, we use the least significant bit
2978 to record whether we have initialized it already.
2980 When doing a dynamic link, we create a .rela.got
2981 relocation entry to initialize the value. This
2982 is done in the finish_dynamic_symbol routine. */
2987 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, relocation
,
2988 htab
->elf
.sgot
->contents
+ off
);
2993 unresolved_reloc
= FALSE
;
2997 BFD_ASSERT (local_got_offsets
!= NULL
2998 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3000 off
= local_got_offsets
[r_symndx
];
3002 /* The offset must always be a multiple of 8 on 64-bit.
3003 We use the least significant bit to record
3004 whether we have already processed this entry. */
3012 Elf_Internal_Rela outrel
;
3014 /* We need to generate a R_TILEGX_RELATIVE reloc
3015 for the dynamic linker. */
3016 s
= htab
->elf
.srelgot
;
3017 BFD_ASSERT (s
!= NULL
);
3019 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3020 + htab
->elf
.sgot
->output_offset
3023 TILEGX_ELF_R_INFO (htab
, NULL
, 0, R_TILEGX_RELATIVE
);
3024 outrel
.r_addend
= relocation
;
3026 tilegx_elf_append_rela (output_bfd
, s
, &outrel
);
3029 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, relocation
,
3030 htab
->elf
.sgot
->contents
+ off
);
3031 local_got_offsets
[r_symndx
] |= 1;
3034 relocation
= htab
->elf
.sgot
->output_offset
+ off
- got_base
;
3037 case R_TILEGX_JUMPOFF_X1_PLT
:
3038 /* Relocation is to the entry for this symbol in the
3039 procedure linkage table. */
3040 BFD_ASSERT (h
!= NULL
);
3042 if (h
->plt
.offset
== (bfd_vma
) -1 || htab
->elf
.splt
== NULL
)
3044 /* We didn't make a PLT entry for this symbol. This
3045 happens when statically linking PIC code, or when
3046 using -Bsymbolic. */
3050 relocation
= (htab
->elf
.splt
->output_section
->vma
3051 + htab
->elf
.splt
->output_offset
3053 unresolved_reloc
= FALSE
;
3056 case R_TILEGX_64_PCREL
:
3057 case R_TILEGX_32_PCREL
:
3058 case R_TILEGX_16_PCREL
:
3059 case R_TILEGX_8_PCREL
:
3060 case R_TILEGX_IMM16_X0_HW0_PCREL
:
3061 case R_TILEGX_IMM16_X1_HW0_PCREL
:
3062 case R_TILEGX_IMM16_X0_HW1_PCREL
:
3063 case R_TILEGX_IMM16_X1_HW1_PCREL
:
3064 case R_TILEGX_IMM16_X0_HW2_PCREL
:
3065 case R_TILEGX_IMM16_X1_HW2_PCREL
:
3066 case R_TILEGX_IMM16_X0_HW3_PCREL
:
3067 case R_TILEGX_IMM16_X1_HW3_PCREL
:
3068 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
3069 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
3070 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
3071 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
3072 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
3073 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
3075 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3086 case R_TILEGX_HW0_LAST
:
3087 case R_TILEGX_HW1_LAST
:
3088 case R_TILEGX_HW2_LAST
:
3090 case R_TILEGX_GLOB_DAT
:
3091 case R_TILEGX_JMP_SLOT
:
3092 case R_TILEGX_RELATIVE
:
3093 case R_TILEGX_BROFF_X1
:
3094 case R_TILEGX_JUMPOFF_X1
:
3095 case R_TILEGX_IMM8_X0
:
3096 case R_TILEGX_IMM8_Y0
:
3097 case R_TILEGX_IMM8_X1
:
3098 case R_TILEGX_IMM8_Y1
:
3099 case R_TILEGX_DEST_IMM8_X1
:
3100 case R_TILEGX_MT_IMM14_X1
:
3101 case R_TILEGX_MF_IMM14_X1
:
3102 case R_TILEGX_MMSTART_X0
:
3103 case R_TILEGX_MMEND_X0
:
3104 case R_TILEGX_SHAMT_X0
:
3105 case R_TILEGX_SHAMT_X1
:
3106 case R_TILEGX_SHAMT_Y0
:
3107 case R_TILEGX_SHAMT_Y1
:
3108 case R_TILEGX_IMM16_X0_HW0
:
3109 case R_TILEGX_IMM16_X1_HW0
:
3110 case R_TILEGX_IMM16_X0_HW1
:
3111 case R_TILEGX_IMM16_X1_HW1
:
3112 case R_TILEGX_IMM16_X0_HW2
:
3113 case R_TILEGX_IMM16_X1_HW2
:
3114 case R_TILEGX_IMM16_X0_HW3
:
3115 case R_TILEGX_IMM16_X1_HW3
:
3116 case R_TILEGX_IMM16_X0_HW0_LAST
:
3117 case R_TILEGX_IMM16_X1_HW0_LAST
:
3118 case R_TILEGX_IMM16_X0_HW1_LAST
:
3119 case R_TILEGX_IMM16_X1_HW1_LAST
:
3120 case R_TILEGX_IMM16_X0_HW2_LAST
:
3121 case R_TILEGX_IMM16_X1_HW2_LAST
:
3122 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3127 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3128 || h
->root
.type
!= bfd_link_hash_undefweak
)
3129 && (! howto
->pc_relative
3130 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3137 || h
->root
.type
== bfd_link_hash_undefweak
3138 || h
->root
.type
== bfd_link_hash_undefined
)))
3140 Elf_Internal_Rela outrel
;
3141 bfd_boolean skip
, relocate
= FALSE
;
3143 /* When generating a shared object, these relocations
3144 are copied into the output file to be resolved at run
3147 BFD_ASSERT (sreloc
!= NULL
);
3152 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3154 if (outrel
.r_offset
== (bfd_vma
) -1)
3156 else if (outrel
.r_offset
== (bfd_vma
) -2)
3157 skip
= TRUE
, relocate
= TRUE
;
3158 outrel
.r_offset
+= (input_section
->output_section
->vma
3159 + input_section
->output_offset
);
3163 case R_TILEGX_64_PCREL
:
3164 case R_TILEGX_32_PCREL
:
3165 case R_TILEGX_16_PCREL
:
3166 case R_TILEGX_8_PCREL
:
3167 /* If the symbol is not dynamic, we should not keep
3168 a dynamic relocation. But an .rela.* slot has been
3169 allocated for it, output R_TILEGX_NONE.
3170 FIXME: Add code tracking needed dynamic relocs as
3172 if (h
->dynindx
== -1)
3173 skip
= TRUE
, relocate
= TRUE
;
3178 memset (&outrel
, 0, sizeof outrel
);
3179 /* h->dynindx may be -1 if the symbol was marked to
3181 else if (h
!= NULL
&&
3185 || !SYMBOLIC_BIND (info
, h
)
3186 || !h
->def_regular
))
3188 BFD_ASSERT (h
->dynindx
!= -1);
3189 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, rel
, h
->dynindx
, r_type
);
3190 outrel
.r_addend
= rel
->r_addend
;
3194 if (r_type
== R_TILEGX_32
|| r_type
== R_TILEGX_64
)
3196 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, 0,
3198 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3204 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3207 sec
= htab
->elf
.splt
;
3209 if (bfd_is_abs_section (sec
))
3211 else if (sec
== NULL
|| sec
->owner
== NULL
)
3213 bfd_set_error (bfd_error_bad_value
);
3220 /* We are turning this relocation into one
3221 against a section symbol. It would be
3222 proper to subtract the symbol's value,
3223 osec->vma, from the emitted reloc addend,
3224 but ld.so expects buggy relocs. */
3225 osec
= sec
->output_section
;
3226 indx
= elf_section_data (osec
)->dynindx
;
3230 osec
= htab
->elf
.text_index_section
;
3231 indx
= elf_section_data (osec
)->dynindx
;
3234 /* FIXME: we really should be able to link non-pic
3235 shared libraries. */
3239 (*_bfd_error_handler
)
3240 (_("%B: probably compiled without -fPIC?"),
3242 bfd_set_error (bfd_error_bad_value
);
3247 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, rel
, indx
,
3252 tilegx_elf_append_rela (output_bfd
, sreloc
, &outrel
);
3254 /* This reloc will be computed at runtime, so there's no
3255 need to do anything now. */
3261 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
3262 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
3263 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
3264 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
3265 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
3266 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
3267 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
3268 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
3269 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
3270 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
3271 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
3272 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
3273 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
3274 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
3275 tls_type
= GOT_TLS_GD
;
3276 goto have_tls_reference
;
3278 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
3279 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
3280 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
3281 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
3282 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
3283 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
3284 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
3285 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
3286 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
3287 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
3288 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
3289 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
3290 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
3291 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
3292 tls_type
= GOT_TLS_IE
;
3296 if (h
== NULL
&& local_got_offsets
)
3297 tls_type
= _bfd_tilegx_elf_local_got_tls_type (input_bfd
) [r_symndx
];
3299 tls_type
= tilegx_elf_hash_entry(h
)->tls_type
;
3301 if (tls_type
== GOT_TLS_IE
)
3304 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
3305 r_type
= R_TILEGX_IMM16_X0_HW0_TLS_IE
;
3307 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
3308 r_type
= R_TILEGX_IMM16_X1_HW0_TLS_IE
;
3310 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
3311 r_type
= R_TILEGX_IMM16_X0_HW1_TLS_IE
;
3313 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
3314 r_type
= R_TILEGX_IMM16_X1_HW1_TLS_IE
;
3316 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
3317 r_type
= R_TILEGX_IMM16_X0_HW2_TLS_IE
;
3319 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
3320 r_type
= R_TILEGX_IMM16_X1_HW2_TLS_IE
;
3322 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
3323 r_type
= R_TILEGX_IMM16_X0_HW3_TLS_IE
;
3325 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
3326 r_type
= R_TILEGX_IMM16_X1_HW3_TLS_IE
;
3328 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
3329 r_type
= R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
;
3331 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
3332 r_type
= R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
;
3334 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
3335 r_type
= R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
;
3337 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
3338 r_type
= R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
;
3340 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
3341 r_type
= R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
;
3343 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
3344 r_type
= R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
;
3350 off
= h
->got
.offset
;
3355 BFD_ASSERT (local_got_offsets
!= NULL
);
3356 off
= local_got_offsets
[r_symndx
];
3357 local_got_offsets
[r_symndx
] |= 1;
3360 if (htab
->elf
.sgot
== NULL
)
3367 Elf_Internal_Rela outrel
;
3369 bfd_boolean need_relocs
= FALSE
;
3371 if (htab
->elf
.srelgot
== NULL
)
3377 dyn
= htab
->elf
.dynamic_sections_created
;
3379 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3381 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
3387 /* The GOT entries have not been initialized yet. Do it
3388 now, and emit any relocations. */
3389 if ((info
->shared
|| indx
!= 0)
3391 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3392 || h
->root
.type
!= bfd_link_hash_undefweak
))
3397 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
3398 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
3399 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
3400 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
3401 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
3402 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
3403 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
3404 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
3405 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
3406 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
3407 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
3408 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
3409 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
3410 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
3412 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3413 htab
->elf
.sgot
->contents
+ off
);
3414 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3415 + htab
->elf
.sgot
->output_offset
+ off
);
3416 outrel
.r_addend
= 0;
3418 outrel
.r_addend
= relocation
- dtpoff_base (info
);
3419 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, indx
,
3420 TILEGX_ELF_TPOFF_RELOC (htab
));
3421 tilegx_elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3423 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3424 tpoff (info
, relocation
),
3425 htab
->elf
.sgot
->contents
+ off
);
3429 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
3430 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
3431 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
3432 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
3433 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
3434 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
3435 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
3436 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
3437 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
3438 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
3439 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
3440 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
3441 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
3442 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
3444 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3445 + htab
->elf
.sgot
->output_offset
+ off
);
3446 outrel
.r_addend
= 0;
3447 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, indx
,
3448 TILEGX_ELF_DTPMOD_RELOC (htab
));
3449 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3450 htab
->elf
.sgot
->contents
+ off
);
3451 tilegx_elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3454 BFD_ASSERT (! unresolved_reloc
);
3455 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3456 relocation
- dtpoff_base (info
),
3457 (htab
->elf
.sgot
->contents
+ off
+
3458 TILEGX_ELF_WORD_BYTES (htab
)));
3462 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3463 (htab
->elf
.sgot
->contents
+ off
+
3464 TILEGX_ELF_WORD_BYTES (htab
)));
3465 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, indx
,
3466 TILEGX_ELF_DTPOFF_RELOC (htab
));
3467 outrel
.r_offset
+= TILEGX_ELF_WORD_BYTES (htab
);
3468 tilegx_elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3473 /* If we are not emitting relocations for a
3474 general dynamic reference, then we must be in a
3475 static link or an executable link with the
3476 symbol binding locally. Mark it as belonging
3477 to module 1, the executable. */
3478 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 1,
3479 htab
->elf
.sgot
->contents
+ off
);
3480 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3481 relocation
- dtpoff_base (info
),
3482 htab
->elf
.sgot
->contents
+ off
+
3483 TILEGX_ELF_WORD_BYTES (htab
));
3489 if (off
>= (bfd_vma
) -2)
3492 relocation
= htab
->elf
.sgot
->output_offset
+ off
- got_base
;
3493 unresolved_reloc
= FALSE
;
3494 howto
= tilegx_elf_howto_table
+ r_type
;
3501 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3502 because such sections are not SEC_ALLOC and thus ld.so will
3503 not process them. */
3504 if (unresolved_reloc
3505 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3507 (*_bfd_error_handler
)
3508 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3511 (long) rel
->r_offset
,
3513 h
->root
.root
.string
);
3515 r
= bfd_reloc_continue
;
3517 /* Get the operand creation function, if any. */
3518 create_func
= reloc_to_create_func
[r_type
];
3519 if (create_func
== NULL
)
3521 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3522 contents
, rel
->r_offset
,
3523 relocation
, rel
->r_addend
);
3527 if (howto
->pc_relative
)
3530 input_section
->output_section
->vma
+ input_section
->output_offset
;
3531 if (howto
->pcrel_offset
)
3532 relocation
-= rel
->r_offset
;
3537 /* Add the relocation addend if any to the final target value */
3538 relocation
+= rel
->r_addend
;
3540 /* Do basic range checking */
3541 r
= bfd_check_overflow (howto
->complain_on_overflow
,
3544 TILEGX_ELF_WORD_BYTES (htab
) * 8,
3548 * Write the relocated value out into the raw section data.
3549 * Don't put a relocation out in the .rela section.
3551 tilegx_bundle_bits mask
= create_func(-1);
3552 tilegx_bundle_bits value
= create_func(relocation
>> howto
->rightshift
);
3554 /* Only touch bytes while the mask is not 0, so we
3555 don't write to out of bounds memory if this is actually
3556 a 16-bit switch instruction. */
3557 for (data
= contents
+ rel
->r_offset
; mask
!= 0; data
++)
3559 bfd_byte byte_mask
= (bfd_byte
)mask
;
3560 *data
= (*data
& ~byte_mask
) | ((bfd_byte
)value
& byte_mask
);
3566 if (r
!= bfd_reloc_ok
)
3568 const char *msg
= NULL
;
3572 case bfd_reloc_overflow
:
3573 r
= info
->callbacks
->reloc_overflow
3574 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3575 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3578 case bfd_reloc_undefined
:
3579 r
= info
->callbacks
->undefined_symbol
3580 (info
, name
, input_bfd
, input_section
, rel
->r_offset
,
3584 case bfd_reloc_outofrange
:
3585 msg
= _("internal error: out of range error");
3588 case bfd_reloc_notsupported
:
3589 msg
= _("internal error: unsupported relocation error");
3592 case bfd_reloc_dangerous
:
3593 msg
= _("internal error: dangerous relocation");
3597 msg
= _("internal error: unknown error");
3602 r
= info
->callbacks
->warning
3603 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
3613 /* Finish up dynamic symbol handling. We set the contents of various
3614 dynamic sections here. */
3617 tilegx_elf_finish_dynamic_symbol (bfd
*output_bfd
,
3618 struct bfd_link_info
*info
,
3619 struct elf_link_hash_entry
*h
,
3620 Elf_Internal_Sym
*sym
)
3622 struct tilegx_elf_link_hash_table
*htab
;
3624 htab
= tilegx_elf_hash_table (info
);
3625 BFD_ASSERT (htab
!= NULL
);
3627 if (h
->plt
.offset
!= (bfd_vma
) -1)
3632 Elf_Internal_Rela rela
;
3635 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
3640 /* This symbol has an entry in the PLT. Set it up. */
3642 BFD_ASSERT (h
->dynindx
!= -1);
3644 splt
= htab
->elf
.splt
;
3645 srela
= htab
->elf
.srelplt
;
3646 sgotplt
= htab
->elf
.sgotplt
;
3648 if (splt
== NULL
|| srela
== NULL
)
3651 /* Fill in the entry in the procedure linkage table. */
3652 rela_index
= tilegx_plt_entry_build (output_bfd
, htab
, splt
, sgotplt
,
3653 h
->plt
.offset
, &r_offset
);
3655 /* Fill in the entry in the global offset table, which initially points
3656 to the beginning of the plt. */
3657 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3658 splt
->output_section
->vma
+ splt
->output_offset
,
3659 sgotplt
->contents
+ r_offset
);
3661 /* Fill in the entry in the .rela.plt section. */
3662 rela
.r_offset
= (sgotplt
->output_section
->vma
3663 + sgotplt
->output_offset
3666 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, h
->dynindx
, R_TILEGX_JMP_SLOT
);
3668 loc
= srela
->contents
+ rela_index
* TILEGX_ELF_RELA_BYTES (htab
);
3669 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
3671 if (!h
->def_regular
)
3673 /* Mark the symbol as undefined, rather than as defined in
3674 the .plt section. Leave the value alone. */
3675 sym
->st_shndx
= SHN_UNDEF
;
3676 /* If the symbol is weak, we do need to clear the value.
3677 Otherwise, the PLT entry would provide a definition for
3678 the symbol even if the symbol wasn't defined anywhere,
3679 and so the symbol would never be NULL. */
3680 if (!h
->ref_regular_nonweak
)
3685 if (h
->got
.offset
!= (bfd_vma
) -1
3686 && tilegx_elf_hash_entry(h
)->tls_type
!= GOT_TLS_GD
3687 && tilegx_elf_hash_entry(h
)->tls_type
!= GOT_TLS_IE
)
3691 Elf_Internal_Rela rela
;
3693 /* This symbol has an entry in the GOT. Set it up. */
3695 sgot
= htab
->elf
.sgot
;
3696 srela
= htab
->elf
.srelgot
;
3697 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
3699 rela
.r_offset
= (sgot
->output_section
->vma
3700 + sgot
->output_offset
3701 + (h
->got
.offset
&~ (bfd_vma
) 1));
3703 /* If this is a -Bsymbolic link, and the symbol is defined
3704 locally, we just want to emit a RELATIVE reloc. Likewise if
3705 the symbol was forced to be local because of a version file.
3706 The entry in the global offset table will already have been
3707 initialized in the relocate_section function. */
3709 && (info
->symbolic
|| h
->dynindx
== -1)
3712 asection
*sec
= h
->root
.u
.def
.section
;
3713 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, 0, R_TILEGX_RELATIVE
);
3714 rela
.r_addend
= (h
->root
.u
.def
.value
3715 + sec
->output_section
->vma
3716 + sec
->output_offset
);
3720 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, h
->dynindx
, R_TILEGX_GLOB_DAT
);
3724 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3725 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
3726 tilegx_elf_append_rela (output_bfd
, srela
, &rela
);
3732 Elf_Internal_Rela rela
;
3734 /* This symbols needs a copy reloc. Set it up. */
3735 BFD_ASSERT (h
->dynindx
!= -1);
3737 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3739 BFD_ASSERT (s
!= NULL
);
3741 rela
.r_offset
= (h
->root
.u
.def
.value
3742 + h
->root
.u
.def
.section
->output_section
->vma
3743 + h
->root
.u
.def
.section
->output_offset
);
3744 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, h
->dynindx
, R_TILEGX_COPY
);
3746 tilegx_elf_append_rela (output_bfd
, s
, &rela
);
3749 /* Mark some specially defined symbols as absolute. */
3750 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3751 || (h
== htab
->elf
.hgot
|| h
== htab
->elf
.hplt
))
3752 sym
->st_shndx
= SHN_ABS
;
3757 /* Finish up the dynamic sections. */
3760 tilegx_finish_dyn (bfd
*output_bfd
, struct bfd_link_info
*info
,
3761 bfd
*dynobj
, asection
*sdyn
,
3762 asection
*splt ATTRIBUTE_UNUSED
)
3764 struct tilegx_elf_link_hash_table
*htab
;
3765 const struct elf_backend_data
*bed
;
3766 bfd_byte
*dyncon
, *dynconend
;
3769 htab
= tilegx_elf_hash_table (info
);
3770 BFD_ASSERT (htab
!= NULL
);
3771 bed
= get_elf_backend_data (output_bfd
);
3772 dynsize
= bed
->s
->sizeof_dyn
;
3773 dynconend
= sdyn
->contents
+ sdyn
->size
;
3775 for (dyncon
= sdyn
->contents
; dyncon
< dynconend
; dyncon
+= dynsize
)
3777 Elf_Internal_Dyn dyn
;
3780 bed
->s
->swap_dyn_in (dynobj
, dyncon
, &dyn
);
3785 s
= htab
->elf
.sgotplt
;
3786 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3789 s
= htab
->elf
.srelplt
;
3790 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3793 s
= htab
->elf
.srelplt
;
3794 dyn
.d_un
.d_val
= s
->size
;
3800 bed
->s
->swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3806 tilegx_elf_finish_dynamic_sections (bfd
*output_bfd
,
3807 struct bfd_link_info
*info
)
3811 struct tilegx_elf_link_hash_table
*htab
;
3813 htab
= tilegx_elf_hash_table (info
);
3814 BFD_ASSERT (htab
!= NULL
);
3815 dynobj
= htab
->elf
.dynobj
;
3817 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3819 if (elf_hash_table (info
)->dynamic_sections_created
)
3824 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3825 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3827 ret
= tilegx_finish_dyn (output_bfd
, info
, dynobj
, sdyn
, splt
);
3832 /* Fill in the head and tail entries in the procedure linkage table. */
3835 memcpy (splt
->contents
,
3836 ABI_64_P (output_bfd
) ?
3837 tilegx64_plt0_entry
: tilegx32_plt0_entry
,
3840 memcpy (splt
->contents
+ splt
->size
- PLT_TAIL_SIZE
,
3841 ABI_64_P (output_bfd
) ?
3842 tilegx64_plt_tail_entry
: tilegx32_plt_tail_entry
,
3846 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
3850 if (htab
->elf
.sgotplt
)
3852 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
3854 (*_bfd_error_handler
)
3855 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
3859 if (htab
->elf
.sgotplt
->size
> 0)
3861 /* Write the first two entries in .got.plt, needed for the dynamic
3863 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, (bfd_vma
) -1,
3864 htab
->elf
.sgotplt
->contents
);
3865 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, (bfd_vma
) 0,
3866 htab
->elf
.sgotplt
->contents
3867 + GOT_ENTRY_SIZE (htab
));
3870 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
3871 GOT_ENTRY_SIZE (htab
);
3876 if (htab
->elf
.sgot
->size
> 0)
3878 /* Set the first entry in the global offset table to the address of
3879 the dynamic section. */
3880 bfd_vma val
= (sdyn
?
3881 sdyn
->output_section
->vma
+ sdyn
->output_offset
:
3883 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, val
,
3884 htab
->elf
.sgot
->contents
);
3887 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
=
3888 GOT_ENTRY_SIZE (htab
);
3896 /* Return address for Ith PLT stub in section PLT, for relocation REL
3897 or (bfd_vma) -1 if it should not be included. */
3900 tilegx_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
3901 const arelent
*rel ATTRIBUTE_UNUSED
)
3903 return plt
->vma
+ PLT_HEADER_SIZE
+ i
* PLT_ENTRY_SIZE
;
3906 enum elf_reloc_type_class
3907 tilegx_reloc_type_class (const Elf_Internal_Rela
*rela
)
3909 switch ((int) TILEGX_ELF_R_TYPE (rela
->r_info
))
3911 case R_TILEGX_RELATIVE
:
3912 return reloc_class_relative
;
3913 case R_TILEGX_JMP_SLOT
:
3914 return reloc_class_plt
;
3916 return reloc_class_copy
;
3918 return reloc_class_normal
;
3923 tilegx_additional_program_headers (bfd
*abfd
,
3924 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3926 /* Each .intrpt section specified by the user adds another PT_LOAD
3927 header since the sections are discontiguous. */
3928 static const char intrpt_sections
[4][9] =
3930 ".intrpt0", ".intrpt1", ".intrpt2", ".intrpt3"
3935 for (i
= 0; i
< 4; i
++)
3937 asection
*sec
= bfd_get_section_by_name (abfd
, intrpt_sections
[i
]);
3938 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
3942 /* Add four "padding" headers in to leave room in case a custom linker
3943 script does something fancy. Otherwise ld complains that it ran
3944 out of program headers and refuses to link. */
3952 _bfd_tilegx_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3954 const char *targ1
= bfd_get_target (ibfd
);
3955 const char *targ2
= bfd_get_target (obfd
);
3957 if (strcmp (targ1
, targ2
) != 0)
3959 (*_bfd_error_handler
)
3960 (_("%B: Cannot link together %s and %s objects."),
3961 ibfd
, targ1
, targ2
);
3962 bfd_set_error (bfd_error_bad_value
);