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 bfd_vma
*local_got_offsets
;
1553 const Elf_Internal_Rela
*rel
;
1554 const Elf_Internal_Rela
*rel_end
;
1558 if (info
->relocatable
)
1561 htab
= tilegx_elf_hash_table (info
);
1562 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1563 sym_hashes
= elf_sym_hashes (abfd
);
1564 local_got_offsets
= elf_local_got_offsets (abfd
);
1568 num_relocs
= sec
->reloc_count
;
1570 BFD_ASSERT (is_tilegx_elf (abfd
) || num_relocs
== 0);
1572 if (htab
->elf
.dynobj
== NULL
)
1573 htab
->elf
.dynobj
= abfd
;
1575 rel_end
= relocs
+ num_relocs
;
1576 for (rel
= relocs
; rel
< rel_end
; rel
++)
1578 unsigned int r_type
;
1579 unsigned long r_symndx
;
1580 struct elf_link_hash_entry
*h
;
1583 r_symndx
= TILEGX_ELF_R_SYMNDX (htab
, rel
->r_info
);
1584 r_type
= TILEGX_ELF_R_TYPE (rel
->r_info
);
1586 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1588 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1593 if (r_symndx
< symtab_hdr
->sh_info
)
1597 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1598 while (h
->root
.type
== bfd_link_hash_indirect
1599 || h
->root
.type
== bfd_link_hash_warning
)
1600 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1605 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
1606 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
1607 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
1608 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
1609 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
1610 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
1611 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
1612 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
1613 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
1614 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
1615 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
1616 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
1617 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
1618 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
1619 tls_type
= GOT_TLS_GD
;
1620 goto have_got_reference
;
1622 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
1623 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
1624 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
1625 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
1626 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
1627 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
1628 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
1629 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
1630 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
1631 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
1632 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
1633 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
1634 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
1635 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
1636 tls_type
= GOT_TLS_IE
;
1638 info
->flags
|= DF_STATIC_TLS
;
1639 goto have_got_reference
;
1641 case R_TILEGX_IMM16_X0_HW0_GOT
:
1642 case R_TILEGX_IMM16_X1_HW0_GOT
:
1643 case R_TILEGX_IMM16_X0_HW1_GOT
:
1644 case R_TILEGX_IMM16_X1_HW1_GOT
:
1645 case R_TILEGX_IMM16_X0_HW2_GOT
:
1646 case R_TILEGX_IMM16_X1_HW2_GOT
:
1647 case R_TILEGX_IMM16_X0_HW3_GOT
:
1648 case R_TILEGX_IMM16_X1_HW3_GOT
:
1649 case R_TILEGX_IMM16_X0_HW0_LAST_GOT
:
1650 case R_TILEGX_IMM16_X1_HW0_LAST_GOT
:
1651 case R_TILEGX_IMM16_X0_HW1_LAST_GOT
:
1652 case R_TILEGX_IMM16_X1_HW1_LAST_GOT
:
1653 case R_TILEGX_IMM16_X0_HW2_LAST_GOT
:
1654 case R_TILEGX_IMM16_X1_HW2_LAST_GOT
:
1655 tls_type
= GOT_NORMAL
;
1659 /* This symbol requires a global offset table entry. */
1665 h
->got
.refcount
+= 1;
1666 old_tls_type
= tilegx_elf_hash_entry(h
)->tls_type
;
1670 bfd_signed_vma
*local_got_refcounts
;
1672 /* This is a global offset table entry for a local symbol. */
1673 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1674 if (local_got_refcounts
== NULL
)
1678 size
= symtab_hdr
->sh_info
;
1679 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
1680 local_got_refcounts
= ((bfd_signed_vma
*)
1681 bfd_zalloc (abfd
, size
));
1682 if (local_got_refcounts
== NULL
)
1684 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1685 _bfd_tilegx_elf_local_got_tls_type (abfd
)
1686 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1688 local_got_refcounts
[r_symndx
] += 1;
1689 old_tls_type
= _bfd_tilegx_elf_local_got_tls_type (abfd
) [r_symndx
];
1692 /* If a TLS symbol is accessed using IE at least once,
1693 there is no point to use dynamic model for it. */
1694 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1695 && (old_tls_type
!= GOT_TLS_GD
1696 || tls_type
!= GOT_TLS_IE
))
1698 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
1699 tls_type
= old_tls_type
;
1702 (*_bfd_error_handler
)
1703 (_("%B: `%s' accessed both as normal and thread local symbol"),
1704 abfd
, h
? h
->root
.root
.string
: "<local>");
1709 if (old_tls_type
!= tls_type
)
1712 tilegx_elf_hash_entry (h
)->tls_type
= tls_type
;
1714 _bfd_tilegx_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1718 if (htab
->elf
.sgot
== NULL
)
1720 if (!tilegx_elf_create_got_section (htab
->elf
.dynobj
, info
))
1725 case R_TILEGX_JUMPOFF_X1_PLT
:
1726 /* This symbol requires a procedure linkage table entry. We
1727 actually build the entry in adjust_dynamic_symbol,
1728 because this might be a case of linking PIC code without
1729 linking in any dynamic objects, in which case we don't
1730 need to generate a procedure linkage table after all. */
1735 h
->plt
.refcount
+= 1;
1739 case R_TILEGX_64_PCREL
:
1740 case R_TILEGX_32_PCREL
:
1741 case R_TILEGX_16_PCREL
:
1742 case R_TILEGX_8_PCREL
:
1743 case R_TILEGX_IMM16_X0_HW0_PCREL
:
1744 case R_TILEGX_IMM16_X1_HW0_PCREL
:
1745 case R_TILEGX_IMM16_X0_HW1_PCREL
:
1746 case R_TILEGX_IMM16_X1_HW1_PCREL
:
1747 case R_TILEGX_IMM16_X0_HW2_PCREL
:
1748 case R_TILEGX_IMM16_X1_HW2_PCREL
:
1749 case R_TILEGX_IMM16_X0_HW3_PCREL
:
1750 case R_TILEGX_IMM16_X1_HW3_PCREL
:
1751 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
1752 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
1753 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
1754 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
1755 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
1756 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
1761 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1773 case R_TILEGX_HW0_LAST
:
1774 case R_TILEGX_HW1_LAST
:
1775 case R_TILEGX_HW2_LAST
:
1777 case R_TILEGX_GLOB_DAT
:
1778 case R_TILEGX_JMP_SLOT
:
1779 case R_TILEGX_RELATIVE
:
1780 case R_TILEGX_BROFF_X1
:
1781 case R_TILEGX_JUMPOFF_X1
:
1782 case R_TILEGX_IMM8_X0
:
1783 case R_TILEGX_IMM8_Y0
:
1784 case R_TILEGX_IMM8_X1
:
1785 case R_TILEGX_IMM8_Y1
:
1786 case R_TILEGX_DEST_IMM8_X1
:
1787 case R_TILEGX_MT_IMM14_X1
:
1788 case R_TILEGX_MF_IMM14_X1
:
1789 case R_TILEGX_MMSTART_X0
:
1790 case R_TILEGX_MMEND_X0
:
1791 case R_TILEGX_SHAMT_X0
:
1792 case R_TILEGX_SHAMT_X1
:
1793 case R_TILEGX_SHAMT_Y0
:
1794 case R_TILEGX_SHAMT_Y1
:
1795 case R_TILEGX_IMM16_X0_HW0
:
1796 case R_TILEGX_IMM16_X1_HW0
:
1797 case R_TILEGX_IMM16_X0_HW1
:
1798 case R_TILEGX_IMM16_X1_HW1
:
1799 case R_TILEGX_IMM16_X0_HW2
:
1800 case R_TILEGX_IMM16_X1_HW2
:
1801 case R_TILEGX_IMM16_X0_HW3
:
1802 case R_TILEGX_IMM16_X1_HW3
:
1803 case R_TILEGX_IMM16_X0_HW0_LAST
:
1804 case R_TILEGX_IMM16_X1_HW0_LAST
:
1805 case R_TILEGX_IMM16_X0_HW1_LAST
:
1806 case R_TILEGX_IMM16_X1_HW1_LAST
:
1807 case R_TILEGX_IMM16_X0_HW2_LAST
:
1808 case R_TILEGX_IMM16_X1_HW2_LAST
:
1815 /* We may need a .plt entry if the function this reloc
1816 refers to is in a shared lib. */
1817 h
->plt
.refcount
+= 1;
1821 /* If we are creating a shared library, and this is a reloc
1822 against a global symbol, or a non PC relative reloc
1823 against a local symbol, then we need to copy the reloc
1824 into the shared library. However, if we are linking with
1825 -Bsymbolic, we do not need to copy a reloc against a
1826 global symbol which is defined in an object we are
1827 including in the link (i.e., DEF_REGULAR is set). At
1828 this point we have not seen all the input files, so it is
1829 possible that DEF_REGULAR is not set now but will be set
1830 later (it is never cleared). In case of a weak definition,
1831 DEF_REGULAR may be cleared later by a strong definition in
1832 a shared library. We account for that possibility below by
1833 storing information in the relocs_copied field of the hash
1834 table entry. A similar situation occurs when creating
1835 shared libraries and symbol visibility changes render the
1838 If on the other hand, we are creating an executable, we
1839 may need to keep relocations for symbols satisfied by a
1840 dynamic library if we manage to avoid copy relocs for the
1843 && (sec
->flags
& SEC_ALLOC
) != 0
1844 && (! tilegx_elf_howto_table
[r_type
].pc_relative
1846 && (! info
->symbolic
1847 || h
->root
.type
== bfd_link_hash_defweak
1848 || !h
->def_regular
))))
1850 && (sec
->flags
& SEC_ALLOC
) != 0
1852 && (h
->root
.type
== bfd_link_hash_defweak
1853 || !h
->def_regular
)))
1855 struct tilegx_elf_dyn_relocs
*p
;
1856 struct tilegx_elf_dyn_relocs
**head
;
1858 /* When creating a shared object, we must copy these
1859 relocs into the output file. We create a reloc
1860 section in dynobj and make room for the reloc. */
1863 sreloc
= _bfd_elf_make_dynamic_reloc_section
1864 (sec
, htab
->elf
.dynobj
, htab
->word_align_power
, abfd
,
1871 /* If this is a global symbol, we count the number of
1872 relocations we need for this symbol. */
1875 &((struct tilegx_elf_link_hash_entry
*) h
)->dyn_relocs
;
1878 /* Track dynamic relocs needed for local syms too.
1879 We really need local syms available to do this
1884 Elf_Internal_Sym
*isym
;
1886 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1891 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1895 vpp
= &elf_section_data (s
)->local_dynrel
;
1896 head
= (struct tilegx_elf_dyn_relocs
**) vpp
;
1900 if (p
== NULL
|| p
->sec
!= sec
)
1902 bfd_size_type amt
= sizeof *p
;
1903 p
= ((struct tilegx_elf_dyn_relocs
*)
1904 bfd_alloc (htab
->elf
.dynobj
, amt
));
1915 if (tilegx_elf_howto_table
[r_type
].pc_relative
)
1921 case R_TILEGX_GNU_VTINHERIT
:
1922 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1926 case R_TILEGX_GNU_VTENTRY
:
1927 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1941 tilegx_elf_gc_mark_hook (asection
*sec
,
1942 struct bfd_link_info
*info
,
1943 Elf_Internal_Rela
*rel
,
1944 struct elf_link_hash_entry
*h
,
1945 Elf_Internal_Sym
*sym
)
1949 switch (TILEGX_ELF_R_TYPE (rel
->r_info
))
1951 case R_TILEGX_GNU_VTINHERIT
:
1952 case R_TILEGX_GNU_VTENTRY
:
1957 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1960 /* Update the got entry reference counts for the section being removed. */
1962 tilegx_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1963 asection
*sec
, const Elf_Internal_Rela
*relocs
)
1965 struct tilegx_elf_link_hash_table
*htab
;
1966 Elf_Internal_Shdr
*symtab_hdr
;
1967 struct elf_link_hash_entry
**sym_hashes
;
1968 bfd_signed_vma
*local_got_refcounts
;
1969 const Elf_Internal_Rela
*rel
, *relend
;
1971 if (info
->relocatable
)
1974 BFD_ASSERT (is_tilegx_elf (abfd
) || sec
->reloc_count
== 0);
1976 elf_section_data (sec
)->local_dynrel
= NULL
;
1978 htab
= tilegx_elf_hash_table (info
);
1979 BFD_ASSERT (htab
!= NULL
);
1980 symtab_hdr
= &elf_symtab_hdr (abfd
);
1981 sym_hashes
= elf_sym_hashes (abfd
);
1982 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1984 relend
= relocs
+ sec
->reloc_count
;
1985 for (rel
= relocs
; rel
< relend
; rel
++)
1987 unsigned long r_symndx
;
1988 unsigned int r_type
;
1989 struct elf_link_hash_entry
*h
= NULL
;
1991 r_symndx
= TILEGX_ELF_R_SYMNDX (htab
, rel
->r_info
);
1992 if (r_symndx
>= symtab_hdr
->sh_info
)
1994 struct tilegx_elf_link_hash_entry
*eh
;
1995 struct tilegx_elf_dyn_relocs
**pp
;
1996 struct tilegx_elf_dyn_relocs
*p
;
1998 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1999 while (h
->root
.type
== bfd_link_hash_indirect
2000 || h
->root
.type
== bfd_link_hash_warning
)
2001 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2002 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2003 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2006 /* Everything must go for SEC. */
2012 r_type
= TILEGX_ELF_R_TYPE (rel
->r_info
);
2016 case R_TILEGX_IMM16_X0_HW0_GOT
:
2017 case R_TILEGX_IMM16_X1_HW0_GOT
:
2018 case R_TILEGX_IMM16_X0_HW1_GOT
:
2019 case R_TILEGX_IMM16_X1_HW1_GOT
:
2020 case R_TILEGX_IMM16_X0_HW2_GOT
:
2021 case R_TILEGX_IMM16_X1_HW2_GOT
:
2022 case R_TILEGX_IMM16_X0_HW3_GOT
:
2023 case R_TILEGX_IMM16_X1_HW3_GOT
:
2024 case R_TILEGX_IMM16_X0_HW0_LAST_GOT
:
2025 case R_TILEGX_IMM16_X1_HW0_LAST_GOT
:
2026 case R_TILEGX_IMM16_X0_HW1_LAST_GOT
:
2027 case R_TILEGX_IMM16_X1_HW1_LAST_GOT
:
2028 case R_TILEGX_IMM16_X0_HW2_LAST_GOT
:
2029 case R_TILEGX_IMM16_X1_HW2_LAST_GOT
:
2030 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
2031 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
2032 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
2033 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
2034 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
2035 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
2036 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
2037 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
2038 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
2039 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
2040 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
2041 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
2042 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
2043 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
2044 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
2045 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
2046 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
2047 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
2048 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
2049 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
2050 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
2051 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
2052 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
2053 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
2054 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
2055 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
2056 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
2057 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
2060 if (h
->got
.refcount
> 0)
2065 if (local_got_refcounts
[r_symndx
] > 0)
2066 local_got_refcounts
[r_symndx
]--;
2070 case R_TILEGX_64_PCREL
:
2071 case R_TILEGX_32_PCREL
:
2072 case R_TILEGX_16_PCREL
:
2073 case R_TILEGX_8_PCREL
:
2074 case R_TILEGX_IMM16_X0_HW0_PCREL
:
2075 case R_TILEGX_IMM16_X1_HW0_PCREL
:
2076 case R_TILEGX_IMM16_X0_HW1_PCREL
:
2077 case R_TILEGX_IMM16_X1_HW1_PCREL
:
2078 case R_TILEGX_IMM16_X0_HW2_PCREL
:
2079 case R_TILEGX_IMM16_X1_HW2_PCREL
:
2080 case R_TILEGX_IMM16_X0_HW3_PCREL
:
2081 case R_TILEGX_IMM16_X1_HW3_PCREL
:
2082 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
2083 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
2084 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
2085 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
2086 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
2087 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
2089 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2101 case R_TILEGX_HW0_LAST
:
2102 case R_TILEGX_HW1_LAST
:
2103 case R_TILEGX_HW2_LAST
:
2105 case R_TILEGX_GLOB_DAT
:
2106 case R_TILEGX_JMP_SLOT
:
2107 case R_TILEGX_RELATIVE
:
2108 case R_TILEGX_BROFF_X1
:
2109 case R_TILEGX_JUMPOFF_X1
:
2110 case R_TILEGX_IMM8_X0
:
2111 case R_TILEGX_IMM8_Y0
:
2112 case R_TILEGX_IMM8_X1
:
2113 case R_TILEGX_IMM8_Y1
:
2114 case R_TILEGX_DEST_IMM8_X1
:
2115 case R_TILEGX_MT_IMM14_X1
:
2116 case R_TILEGX_MF_IMM14_X1
:
2117 case R_TILEGX_MMSTART_X0
:
2118 case R_TILEGX_MMEND_X0
:
2119 case R_TILEGX_SHAMT_X0
:
2120 case R_TILEGX_SHAMT_X1
:
2121 case R_TILEGX_SHAMT_Y0
:
2122 case R_TILEGX_SHAMT_Y1
:
2123 case R_TILEGX_IMM16_X0_HW0
:
2124 case R_TILEGX_IMM16_X1_HW0
:
2125 case R_TILEGX_IMM16_X0_HW1
:
2126 case R_TILEGX_IMM16_X1_HW1
:
2127 case R_TILEGX_IMM16_X0_HW2
:
2128 case R_TILEGX_IMM16_X1_HW2
:
2129 case R_TILEGX_IMM16_X0_HW3
:
2130 case R_TILEGX_IMM16_X1_HW3
:
2131 case R_TILEGX_IMM16_X0_HW0_LAST
:
2132 case R_TILEGX_IMM16_X1_HW0_LAST
:
2133 case R_TILEGX_IMM16_X0_HW1_LAST
:
2134 case R_TILEGX_IMM16_X1_HW1_LAST
:
2135 case R_TILEGX_IMM16_X0_HW2_LAST
:
2136 case R_TILEGX_IMM16_X1_HW2_LAST
:
2141 case R_TILEGX_JUMPOFF_X1_PLT
:
2144 if (h
->plt
.refcount
> 0)
2157 /* Adjust a symbol defined by a dynamic object and referenced by a
2158 regular object. The current definition is in some section of the
2159 dynamic object, but we're not including those sections. We have to
2160 change the definition to something the rest of the link can
2164 tilegx_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2165 struct elf_link_hash_entry
*h
)
2167 struct tilegx_elf_link_hash_table
*htab
;
2168 struct tilegx_elf_link_hash_entry
* eh
;
2169 struct tilegx_elf_dyn_relocs
*p
;
2173 htab
= tilegx_elf_hash_table (info
);
2174 BFD_ASSERT (htab
!= NULL
);
2176 dynobj
= htab
->elf
.dynobj
;
2178 /* Make sure we know what is going on here. */
2179 BFD_ASSERT (dynobj
!= NULL
2181 || h
->u
.weakdef
!= NULL
2184 && !h
->def_regular
)));
2186 /* If this is a function, put it in the procedure linkage table. We
2187 will fill in the contents of the procedure linkage table later
2188 (although we could actually do it here). */
2189 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
2191 if (h
->plt
.refcount
<= 0
2192 || SYMBOL_CALLS_LOCAL (info
, h
)
2193 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2194 && h
->root
.type
== bfd_link_hash_undefweak
))
2196 /* This case can occur if we saw a R_TILEGX_JUMPOFF_X1_PLT
2197 reloc in an input file, but the symbol was never referred
2198 to by a dynamic object, or if all references were garbage
2199 collected. In such a case, we don't actually need to build
2200 a procedure linkage table, and we can just do a
2201 R_TILEGX_JUMPOFF_X1 relocation instead. */
2202 h
->plt
.offset
= (bfd_vma
) -1;
2209 h
->plt
.offset
= (bfd_vma
) -1;
2211 /* If this is a weak symbol, and there is a real definition, the
2212 processor independent code will have arranged for us to see the
2213 real definition first, and we can just use the same value. */
2214 if (h
->u
.weakdef
!= NULL
)
2216 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2217 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2218 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2219 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2223 /* This is a reference to a symbol defined by a dynamic object which
2224 is not a function. */
2226 /* If we are creating a shared library, we must presume that the
2227 only references to the symbol are via the global offset table.
2228 For such cases we need not do anything here; the relocations will
2229 be handled correctly by relocate_section. */
2233 /* If there are no references to this symbol that do not use the
2234 GOT, we don't need to generate a copy reloc. */
2235 if (!h
->non_got_ref
)
2238 /* If -z nocopyreloc was given, we won't generate them either. */
2239 if (info
->nocopyreloc
)
2245 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2246 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2248 s
= p
->sec
->output_section
;
2249 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2253 /* If we didn't find any dynamic relocs in read-only sections, then
2254 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2263 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2264 h
->root
.root
.string
);
2268 /* We must allocate the symbol in our .dynbss section, which will
2269 become part of the .bss section of the executable. There will be
2270 an entry for this symbol in the .dynsym section. The dynamic
2271 object will contain position independent code, so all references
2272 from the dynamic object to this symbol will go through the global
2273 offset table. The dynamic linker will use the .dynsym entry to
2274 determine the address it must put in the global offset table, so
2275 both the dynamic object and the regular object will refer to the
2276 same memory location for the variable. */
2278 /* We must generate a R_TILEGX_COPY reloc to tell the dynamic linker
2279 to copy the initial value out of the dynamic object and into the
2280 runtime process image. We need to remember the offset into the
2281 .rel.bss section we are going to use. */
2282 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2284 htab
->srelbss
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2288 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
2291 /* Allocate space in .plt, .got and associated reloc sections for
2295 allocate_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
2297 struct bfd_link_info
*info
;
2298 struct tilegx_elf_link_hash_table
*htab
;
2299 struct tilegx_elf_link_hash_entry
*eh
;
2300 struct tilegx_elf_dyn_relocs
*p
;
2302 if (h
->root
.type
== bfd_link_hash_indirect
)
2305 if (h
->root
.type
== bfd_link_hash_warning
)
2306 /* When warning symbols are created, they **replace** the "real"
2307 entry in the hash table, thus we never get to see the real
2308 symbol in a hash traversal. So look at it now. */
2309 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2311 info
= (struct bfd_link_info
*) inf
;
2312 htab
= tilegx_elf_hash_table (info
);
2313 BFD_ASSERT (htab
!= NULL
);
2315 if (htab
->elf
.dynamic_sections_created
2316 && h
->plt
.refcount
> 0)
2318 /* Make sure this symbol is output as a dynamic symbol.
2319 Undefined weak syms won't yet be marked as dynamic. */
2320 if (h
->dynindx
== -1
2321 && !h
->forced_local
)
2323 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2327 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
2329 asection
*s
= htab
->elf
.splt
;
2331 /* Allocate room for the header and tail. */
2334 s
->size
= PLT_HEADER_SIZE
+ PLT_TAIL_SIZE
;
2337 h
->plt
.offset
= s
->size
- PLT_TAIL_SIZE
;
2339 /* If this symbol is not defined in a regular file, and we are
2340 not generating a shared library, then set the symbol to this
2341 location in the .plt. This is required to make function
2342 pointers compare as equal between the normal executable and
2343 the shared library. */
2347 h
->root
.u
.def
.section
= s
;
2348 h
->root
.u
.def
.value
= h
->plt
.offset
;
2351 /* Make room for this entry. */
2352 s
->size
+= PLT_ENTRY_SIZE
;
2354 /* We also need to make an entry in the .got.plt section. */
2355 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE (htab
);
2357 /* We also need to make an entry in the .rela.plt section. */
2358 htab
->elf
.srelplt
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2362 h
->plt
.offset
= (bfd_vma
) -1;
2368 h
->plt
.offset
= (bfd_vma
) -1;
2372 if (h
->got
.refcount
> 0)
2376 int tls_type
= tilegx_elf_hash_entry(h
)->tls_type
;
2378 /* Make sure this symbol is output as a dynamic symbol.
2379 Undefined weak syms won't yet be marked as dynamic. */
2380 if (h
->dynindx
== -1
2381 && !h
->forced_local
)
2383 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2388 h
->got
.offset
= s
->size
;
2389 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2390 /* TLS_GD entries need 2 consecutive GOT slots. */
2391 if (tls_type
== GOT_TLS_GD
)
2392 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2393 dyn
= htab
->elf
.dynamic_sections_created
;
2394 /* TLS_IE needs one dynamic relocation,
2395 TLS_GD needs two if local symbol and two if global. */
2396 if (tls_type
== GOT_TLS_GD
|| tls_type
== GOT_TLS_IE
)
2397 htab
->elf
.srelgot
->size
+= 2 * TILEGX_ELF_RELA_BYTES (htab
);
2398 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
2399 htab
->elf
.srelgot
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2402 h
->got
.offset
= (bfd_vma
) -1;
2404 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2405 if (eh
->dyn_relocs
== NULL
)
2408 /* In the shared -Bsymbolic case, discard space allocated for
2409 dynamic pc-relative relocs against symbols which turn out to be
2410 defined in regular objects. For the normal shared case, discard
2411 space for pc-relative relocs that have become local due to symbol
2412 visibility changes. */
2416 if (SYMBOL_CALLS_LOCAL (info
, h
))
2418 struct tilegx_elf_dyn_relocs
**pp
;
2420 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2422 p
->count
-= p
->pc_count
;
2431 /* Also discard relocs on undefined weak syms with non-default
2433 if (eh
->dyn_relocs
!= NULL
2434 && h
->root
.type
== bfd_link_hash_undefweak
)
2436 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2437 eh
->dyn_relocs
= NULL
;
2439 /* Make sure undefined weak symbols are output as a dynamic
2441 else if (h
->dynindx
== -1
2442 && !h
->forced_local
)
2444 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2451 /* For the non-shared case, discard space for relocs against
2452 symbols which turn out to need copy relocs or are not
2458 || (htab
->elf
.dynamic_sections_created
2459 && (h
->root
.type
== bfd_link_hash_undefweak
2460 || h
->root
.type
== bfd_link_hash_undefined
))))
2462 /* Make sure this symbol is output as a dynamic symbol.
2463 Undefined weak syms won't yet be marked as dynamic. */
2464 if (h
->dynindx
== -1
2465 && !h
->forced_local
)
2467 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2471 /* If that succeeded, we know we'll be keeping all the
2473 if (h
->dynindx
!= -1)
2477 eh
->dyn_relocs
= NULL
;
2482 /* Finally, allocate space. */
2483 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2485 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2486 sreloc
->size
+= p
->count
* TILEGX_ELF_RELA_BYTES (htab
);
2492 /* Find any dynamic relocs that apply to read-only sections. */
2495 readonly_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
2497 struct tilegx_elf_link_hash_entry
*eh
;
2498 struct tilegx_elf_dyn_relocs
*p
;
2500 if (h
->root
.type
== bfd_link_hash_warning
)
2501 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2503 eh
= (struct tilegx_elf_link_hash_entry
*) h
;
2504 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2506 asection
*s
= p
->sec
->output_section
;
2508 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2510 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2512 info
->flags
|= DF_TEXTREL
;
2514 /* Not an error, just cut short the traversal. */
2521 /* Return true if the dynamic symbol for a given section should be
2522 omitted when creating a shared library. */
2525 tilegx_elf_omit_section_dynsym (bfd
*output_bfd
,
2526 struct bfd_link_info
*info
,
2529 /* We keep the .got section symbol so that explicit relocations
2530 against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
2531 can be turned into relocations against the .got symbol. */
2532 if (strcmp (p
->name
, ".got") == 0)
2535 return _bfd_elf_link_omit_section_dynsym (output_bfd
, info
, p
);
2539 tilegx_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2540 struct bfd_link_info
*info
)
2542 struct tilegx_elf_link_hash_table
*htab
;
2547 htab
= tilegx_elf_hash_table (info
);
2548 BFD_ASSERT (htab
!= NULL
);
2549 dynobj
= htab
->elf
.dynobj
;
2550 BFD_ASSERT (dynobj
!= NULL
);
2552 if (elf_hash_table (info
)->dynamic_sections_created
)
2554 /* Set the contents of the .interp section to the interpreter. */
2555 if (info
->executable
)
2557 s
= bfd_get_section_by_name (dynobj
, ".interp");
2558 BFD_ASSERT (s
!= NULL
);
2559 s
->size
= strlen (htab
->dynamic_interpreter
) + 1;
2560 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2564 /* Set up .got offsets for local syms, and space for local dynamic
2566 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2568 bfd_signed_vma
*local_got
;
2569 bfd_signed_vma
*end_local_got
;
2570 char *local_tls_type
;
2571 bfd_size_type locsymcount
;
2572 Elf_Internal_Shdr
*symtab_hdr
;
2575 if (! is_tilegx_elf (ibfd
))
2578 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2580 struct tilegx_elf_dyn_relocs
*p
;
2582 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
2584 if (!bfd_is_abs_section (p
->sec
)
2585 && bfd_is_abs_section (p
->sec
->output_section
))
2587 /* Input section has been discarded, either because
2588 it is a copy of a linkonce section or due to
2589 linker script /DISCARD/, so we'll be discarding
2592 else if (p
->count
!= 0)
2594 srel
= elf_section_data (p
->sec
)->sreloc
;
2595 srel
->size
+= p
->count
* TILEGX_ELF_RELA_BYTES (htab
);
2596 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2597 info
->flags
|= DF_TEXTREL
;
2602 local_got
= elf_local_got_refcounts (ibfd
);
2606 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2607 locsymcount
= symtab_hdr
->sh_info
;
2608 end_local_got
= local_got
+ locsymcount
;
2609 local_tls_type
= _bfd_tilegx_elf_local_got_tls_type (ibfd
);
2611 srel
= htab
->elf
.srelgot
;
2612 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
2616 *local_got
= s
->size
;
2617 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2618 if (*local_tls_type
== GOT_TLS_GD
)
2619 s
->size
+= TILEGX_ELF_WORD_BYTES (htab
);
2621 || *local_tls_type
== GOT_TLS_GD
2622 || *local_tls_type
== GOT_TLS_IE
)
2623 srel
->size
+= TILEGX_ELF_RELA_BYTES (htab
);
2626 *local_got
= (bfd_vma
) -1;
2630 /* Allocate global sym .plt and .got entries, and space for global
2631 sym dynamic relocs. */
2632 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
2634 if (elf_hash_table (info
)->dynamic_sections_created
)
2636 /* If the .got section is more than 0x8000 bytes, we add
2637 0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16
2638 bit relocations have a greater chance of working. */
2639 if (htab
->elf
.sgot
->size
>= 0x8000
2640 && elf_hash_table (info
)->hgot
->root
.u
.def
.value
== 0)
2641 elf_hash_table (info
)->hgot
->root
.u
.def
.value
= 0x8000;
2644 if (htab
->elf
.sgotplt
)
2646 struct elf_link_hash_entry
*got
;
2647 got
= elf_link_hash_lookup (elf_hash_table (info
),
2648 "_GLOBAL_OFFSET_TABLE_",
2649 FALSE
, FALSE
, FALSE
);
2651 /* Don't allocate .got.plt section if there are no GOT nor PLT
2652 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2654 || !got
->ref_regular_nonweak
)
2655 && (htab
->elf
.sgotplt
->size
2656 == (unsigned)GOTPLT_HEADER_SIZE (htab
))
2657 && (htab
->elf
.splt
== NULL
2658 || htab
->elf
.splt
->size
== 0)
2659 && (htab
->elf
.sgot
== NULL
2660 || (htab
->elf
.sgot
->size
2661 == get_elf_backend_data (output_bfd
)->got_header_size
)))
2662 htab
->elf
.sgotplt
->size
= 0;
2665 /* The check_relocs and adjust_dynamic_symbol entry points have
2666 determined the sizes of the various dynamic sections. Allocate
2668 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2670 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2673 if (s
== htab
->elf
.splt
2674 || s
== htab
->elf
.sgot
2675 || s
== htab
->elf
.sgotplt
2676 || s
== htab
->sdynbss
)
2678 /* Strip this section if we don't need it; see the
2681 else if (strncmp (s
->name
, ".rela", 5) == 0)
2685 /* We use the reloc_count field as a counter if we need
2686 to copy relocs into the output file. */
2692 /* It's not one of our sections. */
2698 /* If we don't need this section, strip it from the
2699 output file. This is mostly to handle .rela.bss and
2700 .rela.plt. We must create both sections in
2701 create_dynamic_sections, because they must be created
2702 before the linker maps input sections to output
2703 sections. The linker does that before
2704 adjust_dynamic_symbol is called, and it is that
2705 function which decides whether anything needs to go
2706 into these sections. */
2707 s
->flags
|= SEC_EXCLUDE
;
2711 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2714 /* Allocate memory for the section contents. Zero the memory
2715 for the benefit of .rela.plt, which has 4 unused entries
2716 at the beginning, and we don't want garbage. */
2717 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2718 if (s
->contents
== NULL
)
2722 if (elf_hash_table (info
)->dynamic_sections_created
)
2724 /* Add some entries to the .dynamic section. We fill in the
2725 values later, in tilegx_elf_finish_dynamic_sections, but we
2726 must add the entries now so that we get the correct size for
2727 the .dynamic section. The DT_DEBUG entry is filled in by the
2728 dynamic linker and used by the debugger. */
2729 #define add_dynamic_entry(TAG, VAL) \
2730 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2732 if (info
->executable
)
2734 if (!add_dynamic_entry (DT_DEBUG
, 0))
2738 if (htab
->elf
.srelplt
->size
!= 0)
2740 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2741 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2742 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2743 || !add_dynamic_entry (DT_JMPREL
, 0))
2747 if (!add_dynamic_entry (DT_RELA
, 0)
2748 || !add_dynamic_entry (DT_RELASZ
, 0)
2749 || !add_dynamic_entry (DT_RELAENT
, TILEGX_ELF_RELA_BYTES (htab
)))
2752 /* If any dynamic relocs apply to a read-only section,
2753 then we need a DT_TEXTREL entry. */
2754 if ((info
->flags
& DF_TEXTREL
) == 0)
2755 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2758 if (info
->flags
& DF_TEXTREL
)
2760 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2764 #undef add_dynamic_entry
2769 /* Return the base VMA address which should be subtracted from real addresses
2770 when resolving @dtpoff relocation.
2771 This is PT_TLS segment p_vaddr. */
2774 dtpoff_base (struct bfd_link_info
*info
)
2776 /* If tls_sec is NULL, we should have signalled an error already. */
2777 if (elf_hash_table (info
)->tls_sec
== NULL
)
2779 return elf_hash_table (info
)->tls_sec
->vma
;
2782 /* Return the relocation value for @tpoff relocation. */
2785 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2787 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2789 /* If tls_sec is NULL, we should have signalled an error already. */
2790 if (htab
->tls_sec
== NULL
)
2793 return (address
- htab
->tls_sec
->vma
);
2796 /* Relocate an TILEGX ELF section.
2798 The RELOCATE_SECTION function is called by the new ELF backend linker
2799 to handle the relocations for a section.
2801 The relocs are always passed as Rela structures.
2803 This function is responsible for adjusting the section contents as
2804 necessary, and (if generating a relocatable output file) adjusting
2805 the reloc addend as necessary.
2807 This function does not have to worry about setting the reloc
2808 address or the reloc symbol index.
2810 LOCAL_SYMS is a pointer to the swapped in local symbols.
2812 LOCAL_SECTIONS is an array giving the section in the input file
2813 corresponding to the st_shndx field of each local symbol.
2815 The global hash table entry for the global symbols can be found
2816 via elf_sym_hashes (input_bfd).
2818 When generating relocatable output, this function must handle
2819 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2820 going to be the section symbol corresponding to the output
2821 section, which means that the addend must be adjusted
2825 tilegx_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
2826 bfd
*input_bfd
, asection
*input_section
,
2827 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
2828 Elf_Internal_Sym
*local_syms
,
2829 asection
**local_sections
)
2831 struct tilegx_elf_link_hash_table
*htab
;
2832 Elf_Internal_Shdr
*symtab_hdr
;
2833 struct elf_link_hash_entry
**sym_hashes
;
2834 bfd_vma
*local_got_offsets
;
2837 Elf_Internal_Rela
*rel
;
2838 Elf_Internal_Rela
*relend
;
2841 htab
= tilegx_elf_hash_table (info
);
2842 BFD_ASSERT (htab
!= NULL
);
2843 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2844 sym_hashes
= elf_sym_hashes (input_bfd
);
2845 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2847 if (elf_hash_table (info
)->hgot
== NULL
)
2850 got_base
= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
2852 sreloc
= elf_section_data (input_section
)->sreloc
;
2855 num_relocs
= input_section
->reloc_count
;
2856 relend
= relocs
+ num_relocs
;
2857 for (; rel
< relend
; rel
++)
2859 int r_type
, tls_type
;
2860 reloc_howto_type
*howto
;
2861 unsigned long r_symndx
;
2862 struct elf_link_hash_entry
*h
;
2863 Elf_Internal_Sym
*sym
;
2864 tilegx_create_func create_func
;
2867 bfd_reloc_status_type r
;
2870 bfd_boolean is_plt
= FALSE
;
2872 bfd_boolean unresolved_reloc
;
2874 r_type
= TILEGX_ELF_R_TYPE (rel
->r_info
);
2875 if (r_type
== R_TILEGX_GNU_VTINHERIT
2876 || r_type
== R_TILEGX_GNU_VTENTRY
)
2879 if ((unsigned int)r_type
>= ARRAY_SIZE (tilegx_elf_howto_table
))
2881 /* Not clear if we need to check here, but just be paranoid. */
2882 (*_bfd_error_handler
)
2883 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
2884 input_bfd
, r_type
, input_section
);
2885 bfd_set_error (bfd_error_bad_value
);
2889 howto
= tilegx_elf_howto_table
+ r_type
;
2891 /* This is a final link. */
2892 r_symndx
= TILEGX_ELF_R_SYMNDX (htab
, rel
->r_info
);
2896 unresolved_reloc
= FALSE
;
2897 if (r_symndx
< symtab_hdr
->sh_info
)
2899 sym
= local_syms
+ r_symndx
;
2900 sec
= local_sections
[r_symndx
];
2901 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2907 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2908 r_symndx
, symtab_hdr
, sym_hashes
,
2910 unresolved_reloc
, warned
);
2913 /* To avoid generating warning messages about truncated
2914 relocations, set the relocation's address to be the same as
2915 the start of this section. */
2916 if (input_section
->output_section
!= NULL
)
2917 relocation
= input_section
->output_section
->vma
;
2923 if (sec
!= NULL
&& elf_discarded_section (sec
))
2924 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2925 rel
, relend
, howto
, contents
);
2927 if (info
->relocatable
)
2931 name
= h
->root
.root
.string
;
2934 name
= (bfd_elf_string_from_elf_section
2935 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2936 if (name
== NULL
|| *name
== '\0')
2937 name
= bfd_section_name (input_bfd
, sec
);
2942 case R_TILEGX_IMM16_X0_HW0_GOT
:
2943 case R_TILEGX_IMM16_X1_HW0_GOT
:
2944 case R_TILEGX_IMM16_X0_HW1_GOT
:
2945 case R_TILEGX_IMM16_X1_HW1_GOT
:
2946 case R_TILEGX_IMM16_X0_HW2_GOT
:
2947 case R_TILEGX_IMM16_X1_HW2_GOT
:
2948 case R_TILEGX_IMM16_X0_HW3_GOT
:
2949 case R_TILEGX_IMM16_X1_HW3_GOT
:
2950 case R_TILEGX_IMM16_X0_HW0_LAST_GOT
:
2951 case R_TILEGX_IMM16_X1_HW0_LAST_GOT
:
2952 case R_TILEGX_IMM16_X0_HW1_LAST_GOT
:
2953 case R_TILEGX_IMM16_X1_HW1_LAST_GOT
:
2954 case R_TILEGX_IMM16_X0_HW2_LAST_GOT
:
2955 case R_TILEGX_IMM16_X1_HW2_LAST_GOT
:
2956 /* Relocation is to the entry for this symbol in the global
2958 if (htab
->elf
.sgot
== NULL
)
2965 off
= h
->got
.offset
;
2966 BFD_ASSERT (off
!= (bfd_vma
) -1);
2967 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2969 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2971 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
2973 /* This is actually a static link, or it is a
2974 -Bsymbolic link and the symbol is defined
2975 locally, or the symbol was forced to be local
2976 because of a version file. We must initialize
2977 this entry in the global offset table. Since the
2978 offset must always be a multiple
2979 of 8 for 64-bit, we use the least significant bit
2980 to record whether we have initialized it already.
2982 When doing a dynamic link, we create a .rela.got
2983 relocation entry to initialize the value. This
2984 is done in the finish_dynamic_symbol routine. */
2989 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, relocation
,
2990 htab
->elf
.sgot
->contents
+ off
);
2995 unresolved_reloc
= FALSE
;
2999 BFD_ASSERT (local_got_offsets
!= NULL
3000 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3002 off
= local_got_offsets
[r_symndx
];
3004 /* The offset must always be a multiple of 8 on 64-bit.
3005 We use the least significant bit to record
3006 whether we have already processed this entry. */
3014 Elf_Internal_Rela outrel
;
3016 /* We need to generate a R_TILEGX_RELATIVE reloc
3017 for the dynamic linker. */
3018 s
= htab
->elf
.srelgot
;
3019 BFD_ASSERT (s
!= NULL
);
3021 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3022 + htab
->elf
.sgot
->output_offset
3025 TILEGX_ELF_R_INFO (htab
, NULL
, 0, R_TILEGX_RELATIVE
);
3026 outrel
.r_addend
= relocation
;
3028 tilegx_elf_append_rela (output_bfd
, s
, &outrel
);
3031 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, relocation
,
3032 htab
->elf
.sgot
->contents
+ off
);
3033 local_got_offsets
[r_symndx
] |= 1;
3036 relocation
= htab
->elf
.sgot
->output_offset
+ off
- got_base
;
3039 case R_TILEGX_JUMPOFF_X1_PLT
:
3040 /* Relocation is to the entry for this symbol in the
3041 procedure linkage table. */
3042 BFD_ASSERT (h
!= NULL
);
3044 if (h
->plt
.offset
== (bfd_vma
) -1 || htab
->elf
.splt
== NULL
)
3046 /* We didn't make a PLT entry for this symbol. This
3047 happens when statically linking PIC code, or when
3048 using -Bsymbolic. */
3052 relocation
= (htab
->elf
.splt
->output_section
->vma
3053 + htab
->elf
.splt
->output_offset
3055 unresolved_reloc
= FALSE
;
3058 case R_TILEGX_64_PCREL
:
3059 case R_TILEGX_32_PCREL
:
3060 case R_TILEGX_16_PCREL
:
3061 case R_TILEGX_8_PCREL
:
3062 case R_TILEGX_IMM16_X0_HW0_PCREL
:
3063 case R_TILEGX_IMM16_X1_HW0_PCREL
:
3064 case R_TILEGX_IMM16_X0_HW1_PCREL
:
3065 case R_TILEGX_IMM16_X1_HW1_PCREL
:
3066 case R_TILEGX_IMM16_X0_HW2_PCREL
:
3067 case R_TILEGX_IMM16_X1_HW2_PCREL
:
3068 case R_TILEGX_IMM16_X0_HW3_PCREL
:
3069 case R_TILEGX_IMM16_X1_HW3_PCREL
:
3070 case R_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
3071 case R_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
3072 case R_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
3073 case R_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
3074 case R_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
3075 case R_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
3077 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3088 case R_TILEGX_HW0_LAST
:
3089 case R_TILEGX_HW1_LAST
:
3090 case R_TILEGX_HW2_LAST
:
3092 case R_TILEGX_GLOB_DAT
:
3093 case R_TILEGX_JMP_SLOT
:
3094 case R_TILEGX_RELATIVE
:
3095 case R_TILEGX_BROFF_X1
:
3096 case R_TILEGX_JUMPOFF_X1
:
3097 case R_TILEGX_IMM8_X0
:
3098 case R_TILEGX_IMM8_Y0
:
3099 case R_TILEGX_IMM8_X1
:
3100 case R_TILEGX_IMM8_Y1
:
3101 case R_TILEGX_DEST_IMM8_X1
:
3102 case R_TILEGX_MT_IMM14_X1
:
3103 case R_TILEGX_MF_IMM14_X1
:
3104 case R_TILEGX_MMSTART_X0
:
3105 case R_TILEGX_MMEND_X0
:
3106 case R_TILEGX_SHAMT_X0
:
3107 case R_TILEGX_SHAMT_X1
:
3108 case R_TILEGX_SHAMT_Y0
:
3109 case R_TILEGX_SHAMT_Y1
:
3110 case R_TILEGX_IMM16_X0_HW0
:
3111 case R_TILEGX_IMM16_X1_HW0
:
3112 case R_TILEGX_IMM16_X0_HW1
:
3113 case R_TILEGX_IMM16_X1_HW1
:
3114 case R_TILEGX_IMM16_X0_HW2
:
3115 case R_TILEGX_IMM16_X1_HW2
:
3116 case R_TILEGX_IMM16_X0_HW3
:
3117 case R_TILEGX_IMM16_X1_HW3
:
3118 case R_TILEGX_IMM16_X0_HW0_LAST
:
3119 case R_TILEGX_IMM16_X1_HW0_LAST
:
3120 case R_TILEGX_IMM16_X0_HW1_LAST
:
3121 case R_TILEGX_IMM16_X1_HW1_LAST
:
3122 case R_TILEGX_IMM16_X0_HW2_LAST
:
3123 case R_TILEGX_IMM16_X1_HW2_LAST
:
3124 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3129 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3130 || h
->root
.type
!= bfd_link_hash_undefweak
)
3131 && (! howto
->pc_relative
3132 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3139 || h
->root
.type
== bfd_link_hash_undefweak
3140 || h
->root
.type
== bfd_link_hash_undefined
)))
3142 Elf_Internal_Rela outrel
;
3143 bfd_boolean skip
, relocate
= FALSE
;
3145 /* When generating a shared object, these relocations
3146 are copied into the output file to be resolved at run
3149 BFD_ASSERT (sreloc
!= NULL
);
3154 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3156 if (outrel
.r_offset
== (bfd_vma
) -1)
3158 else if (outrel
.r_offset
== (bfd_vma
) -2)
3159 skip
= TRUE
, relocate
= TRUE
;
3160 outrel
.r_offset
+= (input_section
->output_section
->vma
3161 + input_section
->output_offset
);
3165 case R_TILEGX_64_PCREL
:
3166 case R_TILEGX_32_PCREL
:
3167 case R_TILEGX_16_PCREL
:
3168 case R_TILEGX_8_PCREL
:
3169 /* If the symbol is not dynamic, we should not keep
3170 a dynamic relocation. But an .rela.* slot has been
3171 allocated for it, output R_TILEGX_NONE.
3172 FIXME: Add code tracking needed dynamic relocs as
3174 if (h
->dynindx
== -1)
3175 skip
= TRUE
, relocate
= TRUE
;
3180 memset (&outrel
, 0, sizeof outrel
);
3181 /* h->dynindx may be -1 if the symbol was marked to
3183 else if (h
!= NULL
&&
3187 || !SYMBOLIC_BIND (info
, h
)
3188 || !h
->def_regular
))
3190 BFD_ASSERT (h
->dynindx
!= -1);
3191 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, rel
, h
->dynindx
, r_type
);
3192 outrel
.r_addend
= rel
->r_addend
;
3196 if (r_type
== R_TILEGX_32
|| r_type
== R_TILEGX_64
)
3198 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, 0,
3200 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3206 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3209 sec
= htab
->elf
.splt
;
3211 if (bfd_is_abs_section (sec
))
3213 else if (sec
== NULL
|| sec
->owner
== NULL
)
3215 bfd_set_error (bfd_error_bad_value
);
3222 /* We are turning this relocation into one
3223 against a section symbol. It would be
3224 proper to subtract the symbol's value,
3225 osec->vma, from the emitted reloc addend,
3226 but ld.so expects buggy relocs. */
3227 osec
= sec
->output_section
;
3228 indx
= elf_section_data (osec
)->dynindx
;
3232 osec
= htab
->elf
.text_index_section
;
3233 indx
= elf_section_data (osec
)->dynindx
;
3236 /* FIXME: we really should be able to link non-pic
3237 shared libraries. */
3241 (*_bfd_error_handler
)
3242 (_("%B: probably compiled without -fPIC?"),
3244 bfd_set_error (bfd_error_bad_value
);
3249 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, rel
, indx
,
3254 tilegx_elf_append_rela (output_bfd
, sreloc
, &outrel
);
3256 /* This reloc will be computed at runtime, so there's no
3257 need to do anything now. */
3263 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
3264 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
3265 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
3266 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
3267 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
3268 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
3269 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
3270 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
3271 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
3272 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
3273 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
3274 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
3275 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
3276 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
3277 tls_type
= GOT_TLS_GD
;
3278 goto have_tls_reference
;
3280 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
3281 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
3282 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
3283 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
3284 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
3285 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
3286 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
3287 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
3288 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
3289 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
3290 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
3291 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
3292 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
3293 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
3294 tls_type
= GOT_TLS_IE
;
3298 if (h
== NULL
&& local_got_offsets
)
3299 tls_type
= _bfd_tilegx_elf_local_got_tls_type (input_bfd
) [r_symndx
];
3301 tls_type
= tilegx_elf_hash_entry(h
)->tls_type
;
3303 if (tls_type
== GOT_TLS_IE
)
3306 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
3307 r_type
= R_TILEGX_IMM16_X0_HW0_TLS_IE
;
3309 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
3310 r_type
= R_TILEGX_IMM16_X1_HW0_TLS_IE
;
3312 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
3313 r_type
= R_TILEGX_IMM16_X0_HW1_TLS_IE
;
3315 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
3316 r_type
= R_TILEGX_IMM16_X1_HW1_TLS_IE
;
3318 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
3319 r_type
= R_TILEGX_IMM16_X0_HW2_TLS_IE
;
3321 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
3322 r_type
= R_TILEGX_IMM16_X1_HW2_TLS_IE
;
3324 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
3325 r_type
= R_TILEGX_IMM16_X0_HW3_TLS_IE
;
3327 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
3328 r_type
= R_TILEGX_IMM16_X1_HW3_TLS_IE
;
3330 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
3331 r_type
= R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
;
3333 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
3334 r_type
= R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
;
3336 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
3337 r_type
= R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
;
3339 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
3340 r_type
= R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
;
3342 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
3343 r_type
= R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
;
3345 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
3346 r_type
= R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
;
3352 off
= h
->got
.offset
;
3357 BFD_ASSERT (local_got_offsets
!= NULL
);
3358 off
= local_got_offsets
[r_symndx
];
3359 local_got_offsets
[r_symndx
] |= 1;
3362 if (htab
->elf
.sgot
== NULL
)
3369 Elf_Internal_Rela outrel
;
3371 bfd_boolean need_relocs
= FALSE
;
3373 if (htab
->elf
.srelgot
== NULL
)
3379 dyn
= htab
->elf
.dynamic_sections_created
;
3381 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3383 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
3389 /* The GOT entries have not been initialized yet. Do it
3390 now, and emit any relocations. */
3391 if ((info
->shared
|| indx
!= 0)
3393 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3394 || h
->root
.type
!= bfd_link_hash_undefweak
))
3399 case R_TILEGX_IMM16_X0_HW0_TLS_IE
:
3400 case R_TILEGX_IMM16_X1_HW0_TLS_IE
:
3401 case R_TILEGX_IMM16_X0_HW1_TLS_IE
:
3402 case R_TILEGX_IMM16_X1_HW1_TLS_IE
:
3403 case R_TILEGX_IMM16_X0_HW2_TLS_IE
:
3404 case R_TILEGX_IMM16_X1_HW2_TLS_IE
:
3405 case R_TILEGX_IMM16_X0_HW3_TLS_IE
:
3406 case R_TILEGX_IMM16_X1_HW3_TLS_IE
:
3407 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
3408 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
3409 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
3410 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
3411 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
3412 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
3414 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3415 htab
->elf
.sgot
->contents
+ off
);
3416 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3417 + htab
->elf
.sgot
->output_offset
+ off
);
3418 outrel
.r_addend
= 0;
3420 outrel
.r_addend
= relocation
- dtpoff_base (info
);
3421 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, indx
,
3422 TILEGX_ELF_TPOFF_RELOC (htab
));
3423 tilegx_elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3425 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3426 tpoff (info
, relocation
),
3427 htab
->elf
.sgot
->contents
+ off
);
3431 case R_TILEGX_IMM16_X0_HW0_TLS_GD
:
3432 case R_TILEGX_IMM16_X1_HW0_TLS_GD
:
3433 case R_TILEGX_IMM16_X0_HW1_TLS_GD
:
3434 case R_TILEGX_IMM16_X1_HW1_TLS_GD
:
3435 case R_TILEGX_IMM16_X0_HW2_TLS_GD
:
3436 case R_TILEGX_IMM16_X1_HW2_TLS_GD
:
3437 case R_TILEGX_IMM16_X0_HW3_TLS_GD
:
3438 case R_TILEGX_IMM16_X1_HW3_TLS_GD
:
3439 case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
3440 case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
3441 case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
3442 case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
3443 case R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
3444 case R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
3446 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3447 + htab
->elf
.sgot
->output_offset
+ off
);
3448 outrel
.r_addend
= 0;
3449 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, indx
,
3450 TILEGX_ELF_DTPMOD_RELOC (htab
));
3451 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3452 htab
->elf
.sgot
->contents
+ off
);
3453 tilegx_elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3456 BFD_ASSERT (! unresolved_reloc
);
3457 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3458 relocation
- dtpoff_base (info
),
3459 (htab
->elf
.sgot
->contents
+ off
+
3460 TILEGX_ELF_WORD_BYTES (htab
)));
3464 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3465 (htab
->elf
.sgot
->contents
+ off
+
3466 TILEGX_ELF_WORD_BYTES (htab
)));
3467 outrel
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, indx
,
3468 TILEGX_ELF_DTPOFF_RELOC (htab
));
3469 outrel
.r_offset
+= TILEGX_ELF_WORD_BYTES (htab
);
3470 tilegx_elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &outrel
);
3475 /* If we are not emitting relocations for a
3476 general dynamic reference, then we must be in a
3477 static link or an executable link with the
3478 symbol binding locally. Mark it as belonging
3479 to module 1, the executable. */
3480 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 1,
3481 htab
->elf
.sgot
->contents
+ off
);
3482 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3483 relocation
- dtpoff_base (info
),
3484 htab
->elf
.sgot
->contents
+ off
+
3485 TILEGX_ELF_WORD_BYTES (htab
));
3491 if (off
>= (bfd_vma
) -2)
3494 relocation
= htab
->elf
.sgot
->output_offset
+ off
- got_base
;
3495 unresolved_reloc
= FALSE
;
3496 howto
= tilegx_elf_howto_table
+ r_type
;
3503 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3504 because such sections are not SEC_ALLOC and thus ld.so will
3505 not process them. */
3506 if (unresolved_reloc
3507 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3509 (*_bfd_error_handler
)
3510 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3513 (long) rel
->r_offset
,
3515 h
->root
.root
.string
);
3517 r
= bfd_reloc_continue
;
3519 /* Get the operand creation function, if any. */
3520 create_func
= reloc_to_create_func
[r_type
];
3521 if (create_func
== NULL
)
3523 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3524 contents
, rel
->r_offset
,
3525 relocation
, rel
->r_addend
);
3529 if (howto
->pc_relative
)
3532 input_section
->output_section
->vma
+ input_section
->output_offset
;
3533 if (howto
->pcrel_offset
)
3534 relocation
-= rel
->r_offset
;
3539 /* Add the relocation addend if any to the final target value */
3540 relocation
+= rel
->r_addend
;
3542 /* Do basic range checking */
3543 r
= bfd_check_overflow (howto
->complain_on_overflow
,
3546 TILEGX_ELF_WORD_BYTES (htab
) * 8,
3550 * Write the relocated value out into the raw section data.
3551 * Don't put a relocation out in the .rela section.
3553 tilegx_bundle_bits mask
= create_func(-1);
3554 tilegx_bundle_bits value
= create_func(relocation
>> howto
->rightshift
);
3556 /* Only touch bytes while the mask is not 0, so we
3557 don't write to out of bounds memory if this is actually
3558 a 16-bit switch instruction. */
3559 for (data
= contents
+ rel
->r_offset
; mask
!= 0; data
++)
3561 bfd_byte byte_mask
= (bfd_byte
)mask
;
3562 *data
= (*data
& ~byte_mask
) | ((bfd_byte
)value
& byte_mask
);
3568 if (r
!= bfd_reloc_ok
)
3570 const char *msg
= NULL
;
3574 case bfd_reloc_overflow
:
3575 r
= info
->callbacks
->reloc_overflow
3576 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3577 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3580 case bfd_reloc_undefined
:
3581 r
= info
->callbacks
->undefined_symbol
3582 (info
, name
, input_bfd
, input_section
, rel
->r_offset
,
3586 case bfd_reloc_outofrange
:
3587 msg
= _("internal error: out of range error");
3590 case bfd_reloc_notsupported
:
3591 msg
= _("internal error: unsupported relocation error");
3594 case bfd_reloc_dangerous
:
3595 msg
= _("internal error: dangerous relocation");
3599 msg
= _("internal error: unknown error");
3604 r
= info
->callbacks
->warning
3605 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
3615 /* Finish up dynamic symbol handling. We set the contents of various
3616 dynamic sections here. */
3619 tilegx_elf_finish_dynamic_symbol (bfd
*output_bfd
,
3620 struct bfd_link_info
*info
,
3621 struct elf_link_hash_entry
*h
,
3622 Elf_Internal_Sym
*sym
)
3624 struct tilegx_elf_link_hash_table
*htab
;
3626 htab
= tilegx_elf_hash_table (info
);
3627 BFD_ASSERT (htab
!= NULL
);
3629 if (h
->plt
.offset
!= (bfd_vma
) -1)
3634 Elf_Internal_Rela rela
;
3637 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
3642 /* This symbol has an entry in the PLT. Set it up. */
3644 BFD_ASSERT (h
->dynindx
!= -1);
3646 splt
= htab
->elf
.splt
;
3647 srela
= htab
->elf
.srelplt
;
3648 sgotplt
= htab
->elf
.sgotplt
;
3650 if (splt
== NULL
|| srela
== NULL
)
3653 /* Fill in the entry in the procedure linkage table. */
3654 rela_index
= tilegx_plt_entry_build (output_bfd
, htab
, splt
, sgotplt
,
3655 h
->plt
.offset
, &r_offset
);
3657 /* Fill in the entry in the global offset table, which initially points
3658 to the beginning of the plt. */
3659 TILEGX_ELF_PUT_WORD (htab
, output_bfd
,
3660 splt
->output_section
->vma
+ splt
->output_offset
,
3661 sgotplt
->contents
+ r_offset
);
3663 /* Fill in the entry in the .rela.plt section. */
3664 rela
.r_offset
= (sgotplt
->output_section
->vma
3665 + sgotplt
->output_offset
3668 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, h
->dynindx
, R_TILEGX_JMP_SLOT
);
3670 loc
= srela
->contents
+ rela_index
* TILEGX_ELF_RELA_BYTES (htab
);
3671 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
3673 if (!h
->def_regular
)
3675 /* Mark the symbol as undefined, rather than as defined in
3676 the .plt section. Leave the value alone. */
3677 sym
->st_shndx
= SHN_UNDEF
;
3678 /* If the symbol is weak, we do need to clear the value.
3679 Otherwise, the PLT entry would provide a definition for
3680 the symbol even if the symbol wasn't defined anywhere,
3681 and so the symbol would never be NULL. */
3682 if (!h
->ref_regular_nonweak
)
3687 if (h
->got
.offset
!= (bfd_vma
) -1
3688 && tilegx_elf_hash_entry(h
)->tls_type
!= GOT_TLS_GD
3689 && tilegx_elf_hash_entry(h
)->tls_type
!= GOT_TLS_IE
)
3693 Elf_Internal_Rela rela
;
3695 /* This symbol has an entry in the GOT. Set it up. */
3697 sgot
= htab
->elf
.sgot
;
3698 srela
= htab
->elf
.srelgot
;
3699 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
3701 rela
.r_offset
= (sgot
->output_section
->vma
3702 + sgot
->output_offset
3703 + (h
->got
.offset
&~ (bfd_vma
) 1));
3705 /* If this is a -Bsymbolic link, and the symbol is defined
3706 locally, we just want to emit a RELATIVE reloc. Likewise if
3707 the symbol was forced to be local because of a version file.
3708 The entry in the global offset table will already have been
3709 initialized in the relocate_section function. */
3711 && (info
->symbolic
|| h
->dynindx
== -1)
3714 asection
*sec
= h
->root
.u
.def
.section
;
3715 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, 0, R_TILEGX_RELATIVE
);
3716 rela
.r_addend
= (h
->root
.u
.def
.value
3717 + sec
->output_section
->vma
3718 + sec
->output_offset
);
3722 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, h
->dynindx
, R_TILEGX_GLOB_DAT
);
3726 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, 0,
3727 sgot
->contents
+ (h
->got
.offset
& ~(bfd_vma
) 1));
3728 tilegx_elf_append_rela (output_bfd
, srela
, &rela
);
3734 Elf_Internal_Rela rela
;
3736 /* This symbols needs a copy reloc. Set it up. */
3737 BFD_ASSERT (h
->dynindx
!= -1);
3739 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3741 BFD_ASSERT (s
!= NULL
);
3743 rela
.r_offset
= (h
->root
.u
.def
.value
3744 + h
->root
.u
.def
.section
->output_section
->vma
3745 + h
->root
.u
.def
.section
->output_offset
);
3746 rela
.r_info
= TILEGX_ELF_R_INFO (htab
, NULL
, h
->dynindx
, R_TILEGX_COPY
);
3748 tilegx_elf_append_rela (output_bfd
, s
, &rela
);
3751 /* Mark some specially defined symbols as absolute. */
3752 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3753 || (h
== htab
->elf
.hgot
|| h
== htab
->elf
.hplt
))
3754 sym
->st_shndx
= SHN_ABS
;
3759 /* Finish up the dynamic sections. */
3762 tilegx_finish_dyn (bfd
*output_bfd
, struct bfd_link_info
*info
,
3763 bfd
*dynobj
, asection
*sdyn
,
3764 asection
*splt ATTRIBUTE_UNUSED
)
3766 struct tilegx_elf_link_hash_table
*htab
;
3767 const struct elf_backend_data
*bed
;
3768 bfd_byte
*dyncon
, *dynconend
;
3770 bfd_boolean abi_64_p
;
3772 htab
= tilegx_elf_hash_table (info
);
3773 BFD_ASSERT (htab
!= NULL
);
3774 bed
= get_elf_backend_data (output_bfd
);
3775 dynsize
= bed
->s
->sizeof_dyn
;
3776 dynconend
= sdyn
->contents
+ sdyn
->size
;
3777 abi_64_p
= ABI_64_P (output_bfd
);
3779 for (dyncon
= sdyn
->contents
; dyncon
< dynconend
; dyncon
+= dynsize
)
3781 Elf_Internal_Dyn dyn
;
3784 bed
->s
->swap_dyn_in (dynobj
, dyncon
, &dyn
);
3789 s
= htab
->elf
.sgotplt
;
3790 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3793 s
= htab
->elf
.srelplt
;
3794 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3797 s
= htab
->elf
.srelplt
;
3798 dyn
.d_un
.d_val
= s
->size
;
3804 bed
->s
->swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3810 tilegx_elf_finish_dynamic_sections (bfd
*output_bfd
,
3811 struct bfd_link_info
*info
)
3815 struct tilegx_elf_link_hash_table
*htab
;
3817 htab
= tilegx_elf_hash_table (info
);
3818 BFD_ASSERT (htab
!= NULL
);
3819 dynobj
= htab
->elf
.dynobj
;
3821 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3823 if (elf_hash_table (info
)->dynamic_sections_created
)
3828 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3829 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3831 ret
= tilegx_finish_dyn (output_bfd
, info
, dynobj
, sdyn
, splt
);
3836 /* Fill in the head and tail entries in the procedure linkage table. */
3839 memcpy (splt
->contents
,
3840 ABI_64_P (output_bfd
) ?
3841 tilegx64_plt0_entry
: tilegx32_plt0_entry
,
3844 memcpy (splt
->contents
+ splt
->size
- PLT_TAIL_SIZE
,
3845 ABI_64_P (output_bfd
) ?
3846 tilegx64_plt_tail_entry
: tilegx32_plt_tail_entry
,
3850 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
3854 if (htab
->elf
.sgotplt
)
3856 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
3858 (*_bfd_error_handler
)
3859 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
3863 if (htab
->elf
.sgotplt
->size
> 0)
3865 /* Write the first two entries in .got.plt, needed for the dynamic
3867 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, (bfd_vma
) -1,
3868 htab
->elf
.sgotplt
->contents
);
3869 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, (bfd_vma
) 0,
3870 htab
->elf
.sgotplt
->contents
3871 + GOT_ENTRY_SIZE (htab
));
3874 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
3875 GOT_ENTRY_SIZE (htab
);
3880 if (htab
->elf
.sgot
->size
> 0)
3882 /* Set the first entry in the global offset table to the address of
3883 the dynamic section. */
3884 bfd_vma val
= (sdyn
?
3885 sdyn
->output_section
->vma
+ sdyn
->output_offset
:
3887 TILEGX_ELF_PUT_WORD (htab
, output_bfd
, val
,
3888 htab
->elf
.sgot
->contents
);
3891 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
=
3892 GOT_ENTRY_SIZE (htab
);
3900 /* Return address for Ith PLT stub in section PLT, for relocation REL
3901 or (bfd_vma) -1 if it should not be included. */
3904 tilegx_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
3905 const arelent
*rel ATTRIBUTE_UNUSED
)
3907 return plt
->vma
+ PLT_HEADER_SIZE
+ i
* PLT_ENTRY_SIZE
;
3910 enum elf_reloc_type_class
3911 tilegx_reloc_type_class (const Elf_Internal_Rela
*rela
)
3913 switch ((int) TILEGX_ELF_R_TYPE (rela
->r_info
))
3915 case R_TILEGX_RELATIVE
:
3916 return reloc_class_relative
;
3917 case R_TILEGX_JMP_SLOT
:
3918 return reloc_class_plt
;
3920 return reloc_class_copy
;
3922 return reloc_class_normal
;
3927 tilegx_additional_program_headers (bfd
*abfd
,
3928 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3930 /* Each .intrpt section specified by the user adds another PT_LOAD
3931 header since the sections are discontiguous. */
3932 static const char intrpt_sections
[4][9] =
3934 ".intrpt0", ".intrpt1", ".intrpt2", ".intrpt3"
3939 for (i
= 0; i
< 4; i
++)
3941 asection
*sec
= bfd_get_section_by_name (abfd
, intrpt_sections
[i
]);
3942 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
3946 /* Add four "padding" headers in to leave room in case a custom linker
3947 script does something fancy. Otherwise ld complains that it ran
3948 out of program headers and refuses to link. */
3956 _bfd_tilegx_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3958 const char *targ1
= bfd_get_target (ibfd
);
3959 const char *targ2
= bfd_get_target (obfd
);
3961 if (strcmp (targ1
, targ2
) != 0)
3963 (*_bfd_error_handler
)
3964 (_("%B: Cannot link together %s and %s objects."),
3965 ibfd
, targ1
, targ2
);
3966 bfd_set_error (bfd_error_bad_value
);