1 /* CRIS-specific support for 32-bit ELF.
2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 Contributed by Axis Communications AB.
4 Written by Hans-Peter Nilsson, based on elf32-fr30.c
5 PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
32 cris_elf_pcrel_reloc (bfd
*, arelent
*, asymbol
*, void *,
33 asection
*, bfd
*, char **);
35 cris_elf_set_mach_from_flags (bfd
*, unsigned long);
37 /* Forward declarations. */
38 static reloc_howto_type cris_elf_howto_table
[] =
40 /* This reloc does nothing. */
41 HOWTO (R_CRIS_NONE
, /* type */
43 3, /* size (0 = byte, 1 = short, 2 = long) */
45 FALSE
, /* pc_relative */
47 complain_overflow_dont
, /* complain_on_overflow */
48 bfd_elf_generic_reloc
, /* special_function */
49 "R_CRIS_NONE", /* name */
50 FALSE
, /* partial_inplace */
53 FALSE
), /* pcrel_offset */
55 /* An 8 bit absolute relocation. */
56 HOWTO (R_CRIS_8
, /* type */
58 0, /* size (0 = byte, 1 = short, 2 = long) */
60 FALSE
, /* pc_relative */
62 complain_overflow_bitfield
, /* complain_on_overflow */
63 bfd_elf_generic_reloc
, /* special_function */
64 "R_CRIS_8", /* name */
65 FALSE
, /* partial_inplace */
66 0x0000, /* src_mask */
67 0x00ff, /* dst_mask */
68 FALSE
), /* pcrel_offset */
70 /* A 16 bit absolute relocation. */
71 HOWTO (R_CRIS_16
, /* type */
73 1, /* size (0 = byte, 1 = short, 2 = long) */
75 FALSE
, /* pc_relative */
77 complain_overflow_bitfield
, /* complain_on_overflow */
78 bfd_elf_generic_reloc
, /* special_function */
79 "R_CRIS_16", /* name */
80 FALSE
, /* partial_inplace */
81 0x00000000, /* src_mask */
82 0x0000ffff, /* dst_mask */
83 FALSE
), /* pcrel_offset */
85 /* A 32 bit absolute relocation. */
86 HOWTO (R_CRIS_32
, /* type */
88 2, /* size (0 = byte, 1 = short, 2 = long) */
90 FALSE
, /* pc_relative */
92 /* We don't want overflow complaints for 64-bit vma builds
93 for e.g. sym+0x40000000 (or actually sym-0xc0000000 in
94 32-bit ELF) where sym=0xc0001234.
95 Don't do this for the PIC relocs, as we don't expect to
96 see them with large offsets. */
97 complain_overflow_dont
, /* complain_on_overflow */
98 bfd_elf_generic_reloc
, /* special_function */
99 "R_CRIS_32", /* name */
100 FALSE
, /* partial_inplace */
101 0x00000000, /* src_mask */
102 0xffffffff, /* dst_mask */
103 FALSE
), /* pcrel_offset */
105 /* An 8 bit PC-relative relocation. */
106 HOWTO (R_CRIS_8_PCREL
, /* type */
108 0, /* size (0 = byte, 1 = short, 2 = long) */
110 TRUE
, /* pc_relative */
112 complain_overflow_bitfield
, /* complain_on_overflow */
113 cris_elf_pcrel_reloc
, /* special_function */
114 "R_CRIS_8_PCREL", /* name */
115 FALSE
, /* partial_inplace */
116 0x0000, /* src_mask */
117 0x00ff, /* dst_mask */
118 TRUE
), /* pcrel_offset */
120 /* A 16 bit PC-relative relocation. */
121 HOWTO (R_CRIS_16_PCREL
, /* type */
123 1, /* size (0 = byte, 1 = short, 2 = long) */
125 TRUE
, /* pc_relative */
127 complain_overflow_bitfield
, /* complain_on_overflow */
128 cris_elf_pcrel_reloc
, /* special_function */
129 "R_CRIS_16_PCREL", /* name */
130 FALSE
, /* partial_inplace */
131 0x00000000, /* src_mask */
132 0x0000ffff, /* dst_mask */
133 TRUE
), /* pcrel_offset */
135 /* A 32 bit PC-relative relocation. */
136 HOWTO (R_CRIS_32_PCREL
, /* type */
138 2, /* size (0 = byte, 1 = short, 2 = long) */
140 TRUE
, /* pc_relative */
142 complain_overflow_bitfield
, /* complain_on_overflow */
143 cris_elf_pcrel_reloc
, /* special_function */
144 "R_CRIS_32_PCREL", /* name */
145 FALSE
, /* partial_inplace */
146 0x00000000, /* src_mask */
147 0xffffffff, /* dst_mask */
148 TRUE
), /* pcrel_offset */
150 /* GNU extension to record C++ vtable hierarchy. */
151 HOWTO (R_CRIS_GNU_VTINHERIT
, /* type */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
155 FALSE
, /* pc_relative */
157 complain_overflow_dont
, /* complain_on_overflow */
158 NULL
, /* special_function */
159 "R_CRIS_GNU_VTINHERIT", /* name */
160 FALSE
, /* partial_inplace */
163 FALSE
), /* pcrel_offset */
165 /* GNU extension to record C++ vtable member usage. */
166 HOWTO (R_CRIS_GNU_VTENTRY
, /* type */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
170 FALSE
, /* pc_relative */
172 complain_overflow_dont
, /* complain_on_overflow */
173 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
174 "R_CRIS_GNU_VTENTRY", /* name */
175 FALSE
, /* partial_inplace */
178 FALSE
), /* pcrel_offset */
180 /* This is used only by the dynamic linker. The symbol should exist
181 both in the object being run and in some shared library. The
182 dynamic linker copies the data addressed by the symbol from the
183 shared library into the object, because the object being
184 run has to have the data at some particular address. */
185 HOWTO (R_CRIS_COPY
, /* type */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE
, /* pc_relative */
191 complain_overflow_bitfield
, /* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_CRIS_COPY", /* name */
194 FALSE
, /* partial_inplace */
197 FALSE
), /* pcrel_offset */
199 /* Like R_CRIS_32, but used when setting global offset table entries. */
200 HOWTO (R_CRIS_GLOB_DAT
, /* type */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
204 FALSE
, /* pc_relative */
206 complain_overflow_bitfield
, /* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_CRIS_GLOB_DAT", /* name */
209 FALSE
, /* partial_inplace */
211 0xffffffff, /* dst_mask */
212 FALSE
), /* pcrel_offset */
214 /* Marks a procedure linkage table entry for a symbol. */
215 HOWTO (R_CRIS_JUMP_SLOT
, /* type */
217 2, /* size (0 = byte, 1 = short, 2 = long) */
219 FALSE
, /* pc_relative */
221 complain_overflow_bitfield
, /* complain_on_overflow */
222 bfd_elf_generic_reloc
, /* special_function */
223 "R_CRIS_JUMP_SLOT", /* name */
224 FALSE
, /* partial_inplace */
227 FALSE
), /* pcrel_offset */
229 /* Used only by the dynamic linker. When the object is run, this
230 longword is set to the load address of the object, plus the
232 HOWTO (R_CRIS_RELATIVE
, /* type */
234 2, /* size (0 = byte, 1 = short, 2 = long) */
236 FALSE
, /* pc_relative */
238 complain_overflow_bitfield
, /* complain_on_overflow */
239 bfd_elf_generic_reloc
, /* special_function */
240 "R_CRIS_RELATIVE", /* name */
241 FALSE
, /* partial_inplace */
243 0xffffffff, /* dst_mask */
244 FALSE
), /* pcrel_offset */
246 /* Like R_CRIS_32, but referring to the GOT table entry for the symbol. */
247 HOWTO (R_CRIS_16_GOT
, /* type */
249 1, /* size (0 = byte, 1 = short, 2 = long) */
251 FALSE
, /* pc_relative */
253 complain_overflow_bitfield
, /* complain_on_overflow */
254 bfd_elf_generic_reloc
, /* special_function */
255 "R_CRIS_16_GOT", /* name */
256 FALSE
, /* partial_inplace */
258 0xffff, /* dst_mask */
259 FALSE
), /* pcrel_offset */
261 HOWTO (R_CRIS_32_GOT
, /* type */
263 2, /* size (0 = byte, 1 = short, 2 = long) */
265 FALSE
, /* pc_relative */
267 complain_overflow_bitfield
, /* complain_on_overflow */
268 bfd_elf_generic_reloc
, /* special_function */
269 "R_CRIS_32_GOT", /* name */
270 FALSE
, /* partial_inplace */
272 0xffffffff, /* dst_mask */
273 FALSE
), /* pcrel_offset */
275 /* Like R_CRIS_32_GOT, but referring to (and requesting a) PLT part of
276 the GOT table for the symbol. */
277 HOWTO (R_CRIS_16_GOTPLT
, /* type */
279 1, /* size (0 = byte, 1 = short, 2 = long) */
281 FALSE
, /* pc_relative */
283 complain_overflow_bitfield
, /* complain_on_overflow */
284 bfd_elf_generic_reloc
, /* special_function */
285 "R_CRIS_16_GOTPLT", /* name */
286 FALSE
, /* partial_inplace */
288 0xffff, /* dst_mask */
289 FALSE
), /* pcrel_offset */
291 HOWTO (R_CRIS_32_GOTPLT
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE
, /* pc_relative */
297 complain_overflow_bitfield
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_CRIS_32_GOTPLT", /* name */
300 FALSE
, /* partial_inplace */
302 0xffffffff, /* dst_mask */
303 FALSE
), /* pcrel_offset */
305 /* A 32-bit offset from GOT to (local const) symbol: no GOT entry should
307 HOWTO (R_CRIS_32_GOTREL
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 FALSE
, /* pc_relative */
313 complain_overflow_bitfield
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_CRIS_32_GOTREL", /* name */
316 FALSE
, /* partial_inplace */
318 0xffffffff, /* dst_mask */
319 FALSE
), /* pcrel_offset */
321 /* A 32-bit offset from GOT to entry for this symbol in PLT and request
322 to create PLT entry for symbol. */
323 HOWTO (R_CRIS_32_PLT_GOTREL
, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_bitfield
, /* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_CRIS_32_PLT_GOTREL", /* name */
332 FALSE
, /* partial_inplace */
334 0xffffffff, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 /* A 32-bit offset from PC (location after the relocation) + addend to
338 entry for this symbol in PLT and request to create PLT entry for
340 HOWTO (R_CRIS_32_PLT_PCREL
, /* type */
342 2, /* size (0 = byte, 1 = short, 2 = long) */
344 TRUE
, /* pc_relative */
346 complain_overflow_bitfield
, /* complain_on_overflow */
347 cris_elf_pcrel_reloc
, /* special_function */
348 "R_CRIS_32_PLT_PCREL", /* name */
349 FALSE
, /* partial_inplace */
351 0xffffffff, /* dst_mask */
352 TRUE
), /* pcrel_offset */
354 /* We don't handle these in any special manner and cross-format
355 linking is not supported; just recognize them enough to pass them
356 around. FIXME: do the same for most PIC relocs and add sanity
357 tests to actually refuse gracefully to handle these and PIC
358 relocs for cross-format linking. */
359 #define TLSHOWTO32(name) \
360 HOWTO (name, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, \
361 bfd_elf_generic_reloc, #name, FALSE, 0, 0xffffffff, FALSE)
362 #define TLSHOWTO16X(name, X) \
363 HOWTO (name, 0, 1, 16, FALSE, 0, complain_overflow_ ## X, \
364 bfd_elf_generic_reloc, #name, FALSE, 0, 0xffff, FALSE)
365 #define TLSHOWTO16(name) TLSHOWTO16X(name, unsigned)
366 #define TLSHOWTO16S(name) TLSHOWTO16X(name, signed)
368 TLSHOWTO32 (R_CRIS_32_GOT_GD
),
369 TLSHOWTO16 (R_CRIS_16_GOT_GD
),
370 TLSHOWTO32 (R_CRIS_32_GD
),
371 TLSHOWTO32 (R_CRIS_DTP
),
372 TLSHOWTO32 (R_CRIS_32_DTPREL
),
373 TLSHOWTO16S (R_CRIS_16_DTPREL
),
374 TLSHOWTO32 (R_CRIS_32_GOT_TPREL
),
375 TLSHOWTO16S (R_CRIS_16_GOT_TPREL
),
376 TLSHOWTO32 (R_CRIS_32_TPREL
),
377 TLSHOWTO16S (R_CRIS_16_TPREL
),
378 TLSHOWTO32 (R_CRIS_DTPMOD
),
379 TLSHOWTO32 (R_CRIS_32_IE
)
382 /* Map BFD reloc types to CRIS ELF reloc types. */
384 struct cris_reloc_map
386 bfd_reloc_code_real_type bfd_reloc_val
;
387 unsigned int cris_reloc_val
;
390 static const struct cris_reloc_map cris_reloc_map
[] =
392 { BFD_RELOC_NONE
, R_CRIS_NONE
},
393 { BFD_RELOC_8
, R_CRIS_8
},
394 { BFD_RELOC_16
, R_CRIS_16
},
395 { BFD_RELOC_32
, R_CRIS_32
},
396 { BFD_RELOC_8_PCREL
, R_CRIS_8_PCREL
},
397 { BFD_RELOC_16_PCREL
, R_CRIS_16_PCREL
},
398 { BFD_RELOC_32_PCREL
, R_CRIS_32_PCREL
},
399 { BFD_RELOC_VTABLE_INHERIT
, R_CRIS_GNU_VTINHERIT
},
400 { BFD_RELOC_VTABLE_ENTRY
, R_CRIS_GNU_VTENTRY
},
401 { BFD_RELOC_CRIS_COPY
, R_CRIS_COPY
},
402 { BFD_RELOC_CRIS_GLOB_DAT
, R_CRIS_GLOB_DAT
},
403 { BFD_RELOC_CRIS_JUMP_SLOT
, R_CRIS_JUMP_SLOT
},
404 { BFD_RELOC_CRIS_RELATIVE
, R_CRIS_RELATIVE
},
405 { BFD_RELOC_CRIS_16_GOT
, R_CRIS_16_GOT
},
406 { BFD_RELOC_CRIS_32_GOT
, R_CRIS_32_GOT
},
407 { BFD_RELOC_CRIS_16_GOTPLT
, R_CRIS_16_GOTPLT
},
408 { BFD_RELOC_CRIS_32_GOTPLT
, R_CRIS_32_GOTPLT
},
409 { BFD_RELOC_CRIS_32_GOTREL
, R_CRIS_32_GOTREL
},
410 { BFD_RELOC_CRIS_32_PLT_GOTREL
, R_CRIS_32_PLT_GOTREL
},
411 { BFD_RELOC_CRIS_32_PLT_PCREL
, R_CRIS_32_PLT_PCREL
},
412 { BFD_RELOC_CRIS_32_GOT_GD
, R_CRIS_32_GOT_GD
},
413 { BFD_RELOC_CRIS_16_GOT_GD
, R_CRIS_16_GOT_GD
},
414 { BFD_RELOC_CRIS_32_GD
, R_CRIS_32_GD
},
415 { BFD_RELOC_CRIS_DTP
, R_CRIS_DTP
},
416 { BFD_RELOC_CRIS_32_DTPREL
, R_CRIS_32_DTPREL
},
417 { BFD_RELOC_CRIS_16_DTPREL
, R_CRIS_16_DTPREL
},
418 { BFD_RELOC_CRIS_32_GOT_TPREL
, R_CRIS_32_GOT_TPREL
},
419 { BFD_RELOC_CRIS_16_GOT_TPREL
, R_CRIS_16_GOT_TPREL
},
420 { BFD_RELOC_CRIS_32_TPREL
, R_CRIS_32_TPREL
},
421 { BFD_RELOC_CRIS_16_TPREL
, R_CRIS_16_TPREL
},
422 { BFD_RELOC_CRIS_DTPMOD
, R_CRIS_DTPMOD
},
423 { BFD_RELOC_CRIS_32_IE
, R_CRIS_32_IE
}
426 static reloc_howto_type
*
427 cris_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
428 bfd_reloc_code_real_type code
)
432 for (i
= 0; i
< sizeof (cris_reloc_map
) / sizeof (cris_reloc_map
[0]); i
++)
433 if (cris_reloc_map
[i
].bfd_reloc_val
== code
)
434 return & cris_elf_howto_table
[cris_reloc_map
[i
].cris_reloc_val
];
439 static reloc_howto_type
*
440 cris_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
445 i
< sizeof (cris_elf_howto_table
) / sizeof (cris_elf_howto_table
[0]);
447 if (cris_elf_howto_table
[i
].name
!= NULL
448 && strcasecmp (cris_elf_howto_table
[i
].name
, r_name
) == 0)
449 return &cris_elf_howto_table
[i
];
454 /* Set the howto pointer for an CRIS ELF reloc. */
457 cris_info_to_howto_rela (bfd
* abfd ATTRIBUTE_UNUSED
,
459 Elf_Internal_Rela
* dst
)
461 enum elf_cris_reloc_type r_type
;
463 r_type
= ELF32_R_TYPE (dst
->r_info
);
464 if (r_type
>= R_CRIS_max
)
466 _bfd_error_handler (_("%B: invalid CRIS reloc number: %d"), abfd
, r_type
);
469 cache_ptr
->howto
= & cris_elf_howto_table
[r_type
];
472 bfd_reloc_status_type
473 cris_elf_pcrel_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
474 arelent
*reloc_entry
,
476 void * data ATTRIBUTE_UNUSED
,
477 asection
*input_section
,
479 char **error_message ATTRIBUTE_UNUSED
)
481 /* By default (using only bfd_elf_generic_reloc when linking to
482 non-ELF formats) PC-relative relocs are relative to the beginning
483 of the reloc. CRIS PC-relative relocs are relative to the position
484 *after* the reloc because that's what pre-CRISv32 PC points to
485 after reading an insn field with that reloc. (For CRISv32, PC is
486 actually relative to the start of the insn, but we keep the old
487 definition.) Still, we use as much generic machinery as we can.
489 Only adjust when doing a final link. */
490 if (output_bfd
== (bfd
*) NULL
)
491 reloc_entry
->addend
-= 1 << reloc_entry
->howto
->size
;
494 bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
495 input_section
, output_bfd
, error_message
);
498 /* Support for core dump NOTE sections.
499 The slightly unintuitive code layout is an attempt to keep at least
500 some similarities with other ports, hoping to simplify general
501 changes, while still keeping Linux/CRIS and Linux/CRISv32 code apart. */
504 cris_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
509 if (bfd_get_mach (abfd
) == bfd_mach_cris_v32
)
510 switch (note
->descsz
)
515 case 202: /* Linux/CRISv32 */
517 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
520 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 22);
529 switch (note
->descsz
)
534 case 214: /* Linux/CRIS */
536 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
539 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 22);
548 /* Make a ".reg/999" section. */
549 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
550 size
, note
->descpos
+ offset
);
554 cris_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
556 if (bfd_get_mach (abfd
) == bfd_mach_cris_v32
)
557 switch (note
->descsz
)
562 case 124: /* Linux/CRISv32 elf_prpsinfo */
563 elf_tdata (abfd
)->core
->program
564 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
565 elf_tdata (abfd
)->core
->command
566 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
569 switch (note
->descsz
)
574 case 124: /* Linux/CRIS elf_prpsinfo */
575 elf_tdata (abfd
)->core
->program
576 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
577 elf_tdata (abfd
)->core
->command
578 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
581 /* Note that for some reason, a spurious space is tacked
582 onto the end of the args in some (at least one anyway)
583 implementations, so strip it off if it exists. */
586 char *command
= elf_tdata (abfd
)->core
->command
;
587 int n
= strlen (command
);
589 if (0 < n
&& command
[n
- 1] == ' ')
590 command
[n
- 1] = '\0';
596 /* The name of the dynamic interpreter. This is put in the .interp
599 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
601 /* The size in bytes of an entry in the procedure linkage table. */
603 #define PLT_ENTRY_SIZE 20
604 #define PLT_ENTRY_SIZE_V32 26
606 /* The first entry in an absolute procedure linkage table looks like this. */
608 static const bfd_byte elf_cris_plt0_entry
[PLT_ENTRY_SIZE
] =
611 0x7e, 0x7e, /* push mof. */
612 0x7f, 0x0d, /* (dip [pc+]) */
613 0, 0, 0, 0, /* Replaced with address of .got + 4. */
614 0x30, 0x7a, /* move [...],mof */
615 0x7f, 0x0d, /* (dip [pc+]) */
616 0, 0, 0, 0, /* Replaced with address of .got + 8. */
617 0x30, 0x09 /* jump [...] */
620 static const bfd_byte elf_cris_plt0_entry_v32
[PLT_ENTRY_SIZE_V32
] =
622 0x84, 0xe2, /* subq 4,$sp */
623 0x6f, 0xfe, /* move.d 0,$acr */
624 0, 0, 0, 0, /* Replaced by address of .got + 4. */
625 0x7e, 0x7a, /* move $mof,[$sp] */
626 0x3f, 0x7a, /* move [$acr],$mof */
627 0x04, 0xf2, /* addq 4,acr */
628 0x6f, 0xfa, /* move.d [$acr],$acr */
629 0xbf, 0x09, /* jump $acr */
630 0xb0, 0x05, /* nop */
631 0, 0 /* Pad out to 26 bytes. */
634 /* Subsequent entries in an absolute procedure linkage table look like
637 static const bfd_byte elf_cris_plt_entry
[PLT_ENTRY_SIZE
] =
639 0x7f, 0x0d, /* (dip [pc+]) */
640 0, 0, 0, 0, /* Replaced with address of this symbol in .got. */
641 0x30, 0x09, /* jump [...] */
642 0x3f, 0x7e, /* move [pc+],mof */
643 0, 0, 0, 0, /* Replaced with offset into relocation table. */
644 0x2f, 0xfe, /* add.d [pc+],pc */
646 0xff, 0xff /* Replaced with offset to start of .plt. */
649 static const bfd_byte elf_cris_plt_entry_v32
[PLT_ENTRY_SIZE_V32
] =
651 0x6f, 0xfe, /* move.d 0,$acr */
652 0, 0, 0, 0, /* Replaced with address of this symbol in .got. */
653 0x6f, 0xfa, /* move.d [$acr],$acr */
654 0xbf, 0x09, /* jump $acr */
655 0xb0, 0x05, /* nop */
656 0x3f, 0x7e, /* move 0,mof */
657 0, 0, 0, 0, /* Replaced with offset into relocation table. */
658 0xbf, 0x0e, /* ba start_of_plt0_entry */
659 0, 0, 0, 0, /* Replaced with offset to plt0 entry. */
663 /* The first entry in a PIC procedure linkage table looks like this. */
665 static const bfd_byte elf_cris_pic_plt0_entry
[PLT_ENTRY_SIZE
] =
667 0xfc, 0xe1, 0x7e, 0x7e, /* push mof */
668 0x04, 0x01, 0x30, 0x7a, /* move [r0+4],mof */
669 0x08, 0x01, 0x30, 0x09, /* jump [r0+8] */
670 0, 0, 0, 0, 0, 0, 0, 0, /* Pad out to 20 bytes. */
673 static const bfd_byte elf_cris_pic_plt0_entry_v32
[PLT_ENTRY_SIZE_V32
] =
675 0x84, 0xe2, /* subq 4,$sp */
676 0x04, 0x01, /* addoq 4,$r0,$acr */
677 0x7e, 0x7a, /* move $mof,[$sp] */
678 0x3f, 0x7a, /* move [$acr],$mof */
679 0x04, 0xf2, /* addq 4,$acr */
680 0x6f, 0xfa, /* move.d [$acr],$acr */
681 0xbf, 0x09, /* jump $acr */
682 0xb0, 0x05, /* nop */
683 0, 0, /* Pad out to 26 bytes. */
688 /* Subsequent entries in a PIC procedure linkage table look like this. */
690 static const bfd_byte elf_cris_pic_plt_entry
[PLT_ENTRY_SIZE
] =
692 0x6f, 0x0d, /* (bdap [pc+].d,r0) */
693 0, 0, 0, 0, /* Replaced with offset of this symbol in .got. */
694 0x30, 0x09, /* jump [...] */
695 0x3f, 0x7e, /* move [pc+],mof */
696 0, 0, 0, 0, /* Replaced with offset into relocation table. */
697 0x2f, 0xfe, /* add.d [pc+],pc */
698 0xec, 0xff, /* Replaced with offset to start of .plt. */
702 static const bfd_byte elf_cris_pic_plt_entry_v32
[PLT_ENTRY_SIZE_V32
] =
704 0x6f, 0x0d, /* addo.d 0,$r0,$acr */
705 0, 0, 0, 0, /* Replaced with offset of this symbol in .got. */
706 0x6f, 0xfa, /* move.d [$acr],$acr */
707 0xbf, 0x09, /* jump $acr */
708 0xb0, 0x05, /* nop */
709 0x3f, 0x7e, /* move relocoffs,$mof */
710 0, 0, 0, 0, /* Replaced with offset into relocation table. */
711 0xbf, 0x0e, /* ba start_of_plt */
712 0, 0, 0, 0, /* Replaced with offset to start of .plt. */
716 /* We copy elf32-m68k.c and elf32-i386.c for the basic linker hash bits
717 (and most other PIC/shlib stuff). Check that we don't drift away
720 The CRIS linker, like the m68k and i386 linkers (and probably the rest
721 too) needs to keep track of the number of relocs that it decides to
722 copy in check_relocs for each symbol. This is so that it can discard
723 PC relative relocs if it doesn't need them when linking with
724 -Bsymbolic. We store the information in a field extending the regular
725 ELF linker hash table. */
727 /* This structure keeps track of the number of PC relative relocs we have
728 copied for a given symbol. */
730 struct elf_cris_pcrel_relocs_copied
733 struct elf_cris_pcrel_relocs_copied
*next
;
735 /* A section in dynobj. */
738 /* Number of relocs copied in this section. */
741 /* Example of reloc being copied, for message. */
742 enum elf_cris_reloc_type r_type
;
745 /* CRIS ELF linker hash entry. */
747 struct elf_cris_link_hash_entry
749 struct elf_link_hash_entry root
;
751 /* Number of PC relative relocs copied for this symbol. */
752 struct elf_cris_pcrel_relocs_copied
*pcrel_relocs_copied
;
754 /* The GOTPLT references are CRIS-specific; the goal is to avoid having
755 both a general GOT and a PLT-specific GOT entry for the same symbol,
756 when it is referenced both as a function and as a function pointer.
758 Number of GOTPLT references for a function. */
759 bfd_signed_vma gotplt_refcount
;
761 /* Actual GOTPLT index for this symbol, if applicable, or zero if not
762 (zero is never used as an index). FIXME: We should be able to fold
763 this with gotplt_refcount in a union, like the got and plt unions in
764 elf_link_hash_entry. */
765 bfd_size_type gotplt_offset
;
767 /* The root.got.refcount is the sum of the regular reference counts
768 (this) and those members below. We have to keep a separate count
769 to track when we've found the first (or last) reference to a
770 regular got entry. The offset is in root.got.offset. */
771 bfd_signed_vma reg_got_refcount
;
773 /* Similar to the above, the number of reloc references to this
774 symbols that need a R_CRIS_32_TPREL slot. The offset is in
775 root.got.offset, because this and .dtp_refcount can't validly
776 happen when there's also a regular GOT entry; that's invalid
777 input for which an error is emitted. */
778 bfd_signed_vma tprel_refcount
;
780 /* Similar to the above, the number of reloc references to this
781 symbols that need a R_CRIS_DTP slot. The offset is in
782 root.got.offset; plus 4 if .tprel_refcount > 0. */
783 bfd_signed_vma dtp_refcount
;
787 elf_cris_discard_excess_dso_dynamics (struct elf_cris_link_hash_entry
*,
790 elf_cris_discard_excess_program_dynamics (struct elf_cris_link_hash_entry
*,
793 /* The local_got_refcounts and local_got_offsets are a multiple of
794 LSNUM in size, namely LGOT_ALLOC_NELTS_FOR(LSNUM) (plus one for the
795 refcount for GOT itself, see code), with the summary / group offset
796 for local symbols located at offset N, reference counts for
797 ordinary (address) relocs at offset N + LSNUM, for R_CRIS_DTP
798 relocs at offset N + 2*LSNUM, and for R_CRIS_32_TPREL relocs at N +
801 #define LGOT_REG_NDX(x) ((x) + symtab_hdr->sh_info)
802 #define LGOT_DTP_NDX(x) ((x) + 2 * symtab_hdr->sh_info)
803 #define LGOT_TPREL_NDX(x) ((x) + 3 * symtab_hdr->sh_info)
804 #define LGOT_ALLOC_NELTS_FOR(x) ((x) * 4)
806 /* CRIS ELF linker hash table. */
808 struct elf_cris_link_hash_table
810 struct elf_link_hash_table root
;
812 /* We can't use the PLT offset and calculate to get the GOTPLT offset,
813 since we try and avoid creating GOTPLT:s when there's already a GOT.
814 Instead, we keep and update the next available index here. */
815 bfd_size_type next_gotplt_entry
;
817 /* The number of R_CRIS_32_DTPREL and R_CRIS_16_DTPREL that have
818 been seen for any input; if != 0, then the constant-offset
819 R_CRIS_DTPMOD is needed for this DSO/executable. This turns
820 negative at relocation, so that we don't need an extra flag for
821 when the reloc is output. */
822 bfd_signed_vma dtpmod_refcount
;
825 /* Traverse a CRIS ELF linker hash table. */
827 #define elf_cris_link_hash_traverse(table, func, info) \
828 (elf_link_hash_traverse \
830 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
833 /* Get the CRIS ELF linker hash table from a link_info structure. */
835 #define elf_cris_hash_table(p) \
836 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
837 == CRIS_ELF_DATA ? ((struct elf_cris_link_hash_table *) ((p)->hash)) : NULL)
839 /* Get the CRIS ELF linker hash entry from a regular hash entry (the
840 "parent class"). The .root reference is just a simple type
841 check on the argument. */
843 #define elf_cris_hash_entry(p) \
844 ((struct elf_cris_link_hash_entry *) (&(p)->root))
846 /* Create an entry in a CRIS ELF linker hash table. */
848 static struct bfd_hash_entry
*
849 elf_cris_link_hash_newfunc (struct bfd_hash_entry
*entry
,
850 struct bfd_hash_table
*table
,
853 struct elf_cris_link_hash_entry
*ret
=
854 (struct elf_cris_link_hash_entry
*) entry
;
856 /* Allocate the structure if it has not already been allocated by a
858 if (ret
== (struct elf_cris_link_hash_entry
*) NULL
)
859 ret
= ((struct elf_cris_link_hash_entry
*)
860 bfd_hash_allocate (table
,
861 sizeof (struct elf_cris_link_hash_entry
)));
862 if (ret
== (struct elf_cris_link_hash_entry
*) NULL
)
863 return (struct bfd_hash_entry
*) ret
;
865 /* Call the allocation method of the superclass. */
866 ret
= ((struct elf_cris_link_hash_entry
*)
867 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
869 if (ret
!= (struct elf_cris_link_hash_entry
*) NULL
)
871 ret
->pcrel_relocs_copied
= NULL
;
872 ret
->gotplt_refcount
= 0;
873 ret
->gotplt_offset
= 0;
874 ret
->dtp_refcount
= 0;
875 ret
->tprel_refcount
= 0;
876 ret
->reg_got_refcount
= 0;
879 return (struct bfd_hash_entry
*) ret
;
882 /* Create a CRIS ELF linker hash table. */
884 static struct bfd_link_hash_table
*
885 elf_cris_link_hash_table_create (bfd
*abfd
)
887 struct elf_cris_link_hash_table
*ret
;
888 bfd_size_type amt
= sizeof (struct elf_cris_link_hash_table
);
890 ret
= ((struct elf_cris_link_hash_table
*) bfd_zmalloc (amt
));
891 if (ret
== (struct elf_cris_link_hash_table
*) NULL
)
894 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
895 elf_cris_link_hash_newfunc
,
896 sizeof (struct elf_cris_link_hash_entry
),
903 /* Initialize to skip over the first three entries in the gotplt; they
904 are used for run-time symbol evaluation. */
905 ret
->next_gotplt_entry
= 12;
907 return &ret
->root
.root
;
910 /* Perform a single relocation. By default we use the standard BFD
911 routines, with a few tweaks. */
913 static bfd_reloc_status_type
914 cris_final_link_relocate (reloc_howto_type
* howto
,
916 asection
* input_section
,
918 Elf_Internal_Rela
* rel
,
921 bfd_reloc_status_type r
;
922 enum elf_cris_reloc_type r_type
= ELF32_R_TYPE (rel
->r_info
);
924 /* PC-relative relocations are relative to the position *after*
925 the reloc. Note that for R_CRIS_8_PCREL the adjustment is
926 not a single byte, since PC must be 16-bit-aligned. */
929 /* Check that the 16-bit GOT relocs are positive. */
930 case R_CRIS_16_GOTPLT
:
932 if ((bfd_signed_vma
) relocation
< 0)
933 return bfd_reloc_overflow
;
936 case R_CRIS_32_PLT_PCREL
:
937 case R_CRIS_32_PCREL
:
941 case R_CRIS_16_PCREL
:
949 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
950 contents
, rel
->r_offset
,
951 relocation
, rel
->r_addend
);
956 /* The number of errors left before we stop outputting reloc-specific
957 explanatory messages. By coincidence, this works nicely together
958 with the default number of messages you'll get from LD about
959 "relocation truncated to fit" messages before you get an
960 "additional relocation overflows omitted from the output". */
961 static int additional_relocation_error_msg_count
= 10;
963 /* Relocate an CRIS ELF section. See elf32-fr30.c, from where this was
964 copied, for further comments. */
967 cris_elf_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
968 struct bfd_link_info
*info
,
970 asection
*input_section
,
972 Elf_Internal_Rela
*relocs
,
973 Elf_Internal_Sym
*local_syms
,
974 asection
**local_sections
)
976 struct elf_cris_link_hash_table
* htab
;
978 Elf_Internal_Shdr
*symtab_hdr
;
979 struct elf_link_hash_entry
**sym_hashes
;
980 bfd_vma
*local_got_offsets
;
984 Elf_Internal_Rela
*rel
;
985 Elf_Internal_Rela
*relend
;
988 htab
= elf_cris_hash_table (info
);
992 dynobj
= elf_hash_table (info
)->dynobj
;
993 local_got_offsets
= elf_local_got_offsets (input_bfd
);
994 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
995 sym_hashes
= elf_sym_hashes (input_bfd
);
996 relend
= relocs
+ input_section
->reloc_count
;
1005 splt
= bfd_get_linker_section (dynobj
, ".plt");
1006 sgot
= bfd_get_linker_section (dynobj
, ".got");
1009 for (rel
= relocs
; rel
< relend
; rel
++)
1011 reloc_howto_type
*howto
;
1012 unsigned long r_symndx
;
1013 Elf_Internal_Sym
*sym
;
1015 struct elf_link_hash_entry
*h
;
1017 bfd_reloc_status_type r
;
1018 const char *symname
= NULL
;
1019 enum elf_cris_reloc_type r_type
;
1021 r_type
= ELF32_R_TYPE (rel
->r_info
);
1023 if ( r_type
== R_CRIS_GNU_VTINHERIT
1024 || r_type
== R_CRIS_GNU_VTENTRY
)
1027 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1028 howto
= cris_elf_howto_table
+ r_type
;
1033 if (r_symndx
< symtab_hdr
->sh_info
)
1035 sym
= local_syms
+ r_symndx
;
1036 sec
= local_sections
[r_symndx
];
1037 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1039 symname
= (bfd_elf_string_from_elf_section
1040 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
1041 if (symname
== NULL
)
1042 symname
= bfd_section_name (input_bfd
, sec
);
1046 bfd_boolean warned
, ignored
;
1047 bfd_boolean unresolved_reloc
;
1049 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1050 r_symndx
, symtab_hdr
, sym_hashes
,
1052 unresolved_reloc
, warned
, ignored
);
1054 symname
= h
->root
.root
.string
;
1056 if (unresolved_reloc
1057 /* Perhaps we should detect the cases that
1058 sec->output_section is expected to be NULL like i386 and
1059 m68k, but apparently (and according to elfxx-ia64.c) all
1060 valid cases are where the symbol is defined in a shared
1061 object which we link dynamically against. This includes
1062 PLT relocs for which we've created a PLT entry and other
1063 relocs for which we're prepared to create dynamic
1066 For now, new situations cause us to just err when
1067 sec->output_offset is NULL but the object with the symbol
1068 is *not* dynamically linked against. Thus this will
1069 automatically remind us so we can see if there are other
1070 valid cases we need to revisit. */
1071 && (sec
->owner
->flags
& DYNAMIC
) != 0)
1074 else if (h
->root
.type
== bfd_link_hash_defined
1075 || h
->root
.type
== bfd_link_hash_defweak
)
1077 /* Here follow the cases where the relocation value must
1078 be zero (or when further handling is simplified when
1079 zero). I can't claim to understand the various
1080 conditions and they weren't described in the files
1081 where I copied them from (elf32-m68k.c and
1082 elf32-i386.c), but let's mention examples of where
1083 they happen. FIXME: Perhaps define and use a
1084 dynamic_symbol_p function like ia64.
1086 - When creating a shared library, we can have an
1087 ordinary relocation for a symbol defined in a shared
1088 library (perhaps the one we create). We then make
1089 the relocation value zero, as the value seen now will
1090 be added into the relocation addend in this shared
1091 library, but must be handled only at dynamic-link
1092 time. FIXME: Not sure this example covers the
1093 h->elf_link_hash_flags test, though it's there in
1095 if (bfd_link_pic (info
)
1096 && ((!SYMBOLIC_BIND (info
, h
) && h
->dynindx
!= -1)
1098 && (input_section
->flags
& SEC_ALLOC
) != 0
1099 && (r_type
== R_CRIS_8
1100 || r_type
== R_CRIS_16
1101 || r_type
== R_CRIS_32
1102 || r_type
== R_CRIS_8_PCREL
1103 || r_type
== R_CRIS_16_PCREL
1104 || r_type
== R_CRIS_32_PCREL
))
1106 else if (!bfd_link_relocatable (info
) && unresolved_reloc
1107 && (_bfd_elf_section_offset (output_bfd
, info
,
1113 (_("%B, section %A: unresolvable relocation %s against symbol `%s'"),
1116 cris_elf_howto_table
[r_type
].name
,
1118 bfd_set_error (bfd_error_bad_value
);
1124 if (sec
!= NULL
&& discarded_section (sec
))
1125 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
1126 rel
, 1, relend
, howto
, 0, contents
);
1128 if (bfd_link_relocatable (info
))
1133 case R_CRIS_16_GOTPLT
:
1134 case R_CRIS_32_GOTPLT
:
1135 /* This is like the case for R_CRIS_32_GOT and R_CRIS_16_GOT,
1136 but we require a PLT, and the PLT handling will take care of
1137 filling in the PLT-specific GOT entry. For the GOT offset,
1138 calculate it as we do when filling it in for the .got.plt
1139 section. If we don't have a PLT, punt to GOT handling. */
1141 && ((struct elf_cris_link_hash_entry
*) h
)->gotplt_offset
!= 0)
1144 = bfd_get_linker_section (dynobj
, ".got.plt");
1147 BFD_ASSERT (h
->dynindx
!= -1);
1148 BFD_ASSERT (sgotplt
!= NULL
);
1151 = ((struct elf_cris_link_hash_entry
*) h
)->gotplt_offset
;
1153 relocation
= got_offset
;
1157 /* We didn't make a PLT entry for this symbol. Maybe everything is
1158 folded into the GOT. Other than folding, this happens when
1159 statically linking PIC code, or when using -Bsymbolic. Check
1160 that we instead have a GOT entry as done for us by
1161 elf_cris_adjust_dynamic_symbol, and drop through into the
1162 ordinary GOT cases. This must not happen for the
1163 executable, because any reference it does to a function
1164 that is satisfied by a DSO must generate a PLT. We assume
1165 these call-specific relocs don't address non-functions. */
1167 && (h
->got
.offset
== (bfd_vma
) -1
1168 || (!bfd_link_pic (info
)
1171 && h
->root
.type
== bfd_link_hash_undefweak
)))))
1173 (*_bfd_error_handler
)
1174 ((h
->got
.offset
== (bfd_vma
) -1)
1175 ? _("%B, section %A: No PLT nor GOT for relocation %s"
1176 " against symbol `%s'")
1177 : _("%B, section %A: No PLT for relocation %s"
1178 " against symbol `%s'"),
1181 cris_elf_howto_table
[r_type
].name
,
1182 (symname
!= NULL
&& symname
[0] != '\0'
1183 ? symname
: _("[whose name is lost]")));
1185 /* FIXME: Perhaps blaming input is not the right thing to
1186 do; this is probably an internal error. But it is true
1187 that we didn't like that particular input. */
1188 bfd_set_error (bfd_error_bad_value
);
1193 /* The size of the actual relocation is not used here; we only
1194 fill in the GOT table here. */
1200 /* Note that despite using RELA relocations, the .got contents
1201 is always filled in with the link-relative relocation
1202 value; the addend. */
1206 off
= h
->got
.offset
;
1207 BFD_ASSERT (off
!= (bfd_vma
) -1);
1209 if (!elf_hash_table (info
)->dynamic_sections_created
1210 || (! bfd_link_pic (info
)
1212 || h
->type
== STT_FUNC
1214 || (bfd_link_pic (info
)
1215 && (SYMBOLIC_BIND (info
, h
) || h
->dynindx
== -1)
1218 /* This wasn't checked above for ! bfd_link_pic (info), but
1219 must hold there if we get here; the symbol must
1220 be defined in the regular program or be undefweak
1221 or be a function or otherwise need a PLT. */
1222 BFD_ASSERT (!elf_hash_table (info
)->dynamic_sections_created
1223 || bfd_link_pic (info
)
1225 || h
->type
== STT_FUNC
1227 || h
->root
.type
== bfd_link_hash_undefweak
);
1229 /* This is actually a static link, or it is a
1230 -Bsymbolic link and the symbol is defined locally,
1231 or is undefweak, or the symbol was forced to be
1232 local because of a version file, or we're not
1233 creating a dynamic object. We must initialize this
1234 entry in the global offset table. Since the offset
1235 must always be a multiple of 4, we use the least
1236 significant bit to record whether we have
1237 initialized it already.
1239 If this GOT entry should be runtime-initialized, we
1240 will create a .rela.got relocation entry to
1241 initialize the value. This is done in the
1242 finish_dynamic_symbol routine. */
1247 bfd_put_32 (output_bfd
, relocation
,
1248 sgot
->contents
+ off
);
1255 BFD_ASSERT (local_got_offsets
!= NULL
1256 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1258 off
= local_got_offsets
[r_symndx
];
1260 /* The offset must always be a multiple of 4. We use
1261 the least significant bit to record whether we have
1262 already generated the necessary reloc. */
1267 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1269 if (bfd_link_pic (info
))
1271 Elf_Internal_Rela outrel
;
1274 if (srelgot
== NULL
)
1276 = bfd_get_linker_section (dynobj
, ".rela.got");
1277 BFD_ASSERT (srelgot
!= NULL
);
1279 outrel
.r_offset
= (sgot
->output_section
->vma
1280 + sgot
->output_offset
1282 outrel
.r_info
= ELF32_R_INFO (0, R_CRIS_RELATIVE
);
1283 outrel
.r_addend
= relocation
;
1284 loc
= srelgot
->contents
;
1285 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1286 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1289 local_got_offsets
[r_symndx
] |= 1;
1293 relocation
= sgot
->output_offset
+ off
;
1294 if (rel
->r_addend
!= 0)
1296 /* We can't do anything for a relocation which is against
1297 a symbol *plus offset*. GOT holds relocations for
1298 symbols. Make this an error; the compiler isn't
1299 allowed to pass us these kinds of things. */
1301 (*_bfd_error_handler
)
1302 (_("%B, section %A: relocation %s with non-zero addend %d"
1303 " against local symbol"),
1306 cris_elf_howto_table
[r_type
].name
,
1309 (*_bfd_error_handler
)
1310 (_("%B, section %A: relocation %s with non-zero addend %d"
1311 " against symbol `%s'"),
1314 cris_elf_howto_table
[r_type
].name
,
1316 symname
[0] != '\0' ? symname
: _("[whose name is lost]"));
1318 bfd_set_error (bfd_error_bad_value
);
1324 case R_CRIS_32_GOTREL
:
1325 /* This relocation must only be performed against local symbols.
1326 It's also ok when we link a program and the symbol is either
1327 defined in an ordinary (non-DSO) object or is undefined weak. */
1329 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1330 && !(!bfd_link_pic (info
)
1333 && h
->root
.type
== bfd_link_hash_undefweak
))))
1335 (*_bfd_error_handler
)
1336 (_("%B, section %A: relocation %s is"
1337 " not allowed for global symbol: `%s'"),
1340 cris_elf_howto_table
[r_type
].name
,
1342 bfd_set_error (bfd_error_bad_value
);
1346 /* This can happen if we get a link error with the input ELF
1347 variant mismatching the output variant. Emit an error so
1348 it's noticed if it happens elsewhere. */
1351 (*_bfd_error_handler
)
1352 (_("%B, section %A: relocation %s with no GOT created"),
1355 cris_elf_howto_table
[r_type
].name
);
1356 bfd_set_error (bfd_error_bad_value
);
1360 /* This relocation is like a PC-relative one, except the
1361 reference point is the location of GOT. Note that
1362 sgot->output_offset is not involved in this calculation. We
1363 always want the start of entire .got section, not the
1364 position after the reserved header. */
1365 relocation
-= sgot
->output_section
->vma
;
1368 case R_CRIS_32_PLT_PCREL
:
1369 /* Relocation is to the entry for this symbol in the
1370 procedure linkage table. */
1372 /* Resolve a PLT_PCREL reloc against a local symbol directly,
1373 without using the procedure linkage table. */
1374 if (h
== NULL
|| ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
1377 if (h
->plt
.offset
== (bfd_vma
) -1
1380 /* We didn't make a PLT entry for this symbol. This
1381 happens when statically linking PIC code, or when
1382 using -Bsymbolic. */
1386 relocation
= (splt
->output_section
->vma
1387 + splt
->output_offset
1391 case R_CRIS_32_PLT_GOTREL
:
1392 /* Like R_CRIS_32_PLT_PCREL, but the reference point is the
1393 start of the .got section. See also comment at
1395 relocation
-= sgot
->output_section
->vma
;
1397 /* Resolve a PLT_GOTREL reloc against a local symbol directly,
1398 without using the procedure linkage table. */
1399 if (h
== NULL
|| ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
1402 if (h
->plt
.offset
== (bfd_vma
) -1
1405 /* We didn't make a PLT entry for this symbol. This
1406 happens when statically linking PIC code, or when
1407 using -Bsymbolic. */
1411 relocation
= (splt
->output_section
->vma
1412 + splt
->output_offset
1414 - sgot
->output_section
->vma
);
1417 case R_CRIS_8_PCREL
:
1418 case R_CRIS_16_PCREL
:
1419 case R_CRIS_32_PCREL
:
1420 /* If the symbol was local, we need no shlib-specific handling. */
1421 if (h
== NULL
|| ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1422 || h
->dynindx
== -1)
1429 if (bfd_link_pic (info
)
1430 && r_symndx
!= STN_UNDEF
1431 && (input_section
->flags
& SEC_ALLOC
) != 0
1432 && ((r_type
!= R_CRIS_8_PCREL
1433 && r_type
!= R_CRIS_16_PCREL
1434 && r_type
!= R_CRIS_32_PCREL
)
1435 || (!SYMBOLIC_BIND (info
, h
)
1436 || (h
!= NULL
&& !h
->def_regular
))))
1438 Elf_Internal_Rela outrel
;
1440 bfd_boolean skip
, relocate
;
1442 /* When generating a shared object, these relocations
1443 are copied into the output file to be resolved at run
1448 sreloc
= _bfd_elf_get_dynamic_reloc_section
1449 (dynobj
, input_section
, /*rela?*/ TRUE
);
1450 /* The section should have been created in cris_elf_check_relocs,
1451 but that function will not be called for objects which fail in
1452 cris_elf_merge_private_bfd_data. */
1455 bfd_set_error (bfd_error_bad_value
);
1464 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1466 if (outrel
.r_offset
== (bfd_vma
) -1)
1468 else if (outrel
.r_offset
== (bfd_vma
) -2
1469 /* For now, undefined weak symbols with non-default
1470 visibility (yielding 0), like exception info for
1471 discarded sections, will get a R_CRIS_NONE
1472 relocation rather than no relocation, because we
1473 notice too late that the symbol doesn't need a
1476 && h
->root
.type
== bfd_link_hash_undefweak
1477 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
))
1478 skip
= TRUE
, relocate
= TRUE
;
1479 outrel
.r_offset
+= (input_section
->output_section
->vma
1480 + input_section
->output_offset
);
1483 memset (&outrel
, 0, sizeof outrel
);
1484 /* h->dynindx may be -1 if the symbol was marked to
1487 && ((!SYMBOLIC_BIND (info
, h
) && h
->dynindx
!= -1)
1488 || !h
->def_regular
))
1490 BFD_ASSERT (h
->dynindx
!= -1);
1491 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1492 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1496 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1498 if (r_type
== R_CRIS_32
)
1501 outrel
.r_info
= ELF32_R_INFO (0, R_CRIS_RELATIVE
);
1507 if (bfd_is_abs_section (sec
))
1509 else if (sec
== NULL
|| sec
->owner
== NULL
)
1511 bfd_set_error (bfd_error_bad_value
);
1518 /* We are turning this relocation into one
1519 against a section symbol. It would be
1520 proper to subtract the symbol's value,
1521 osec->vma, from the emitted reloc addend,
1522 but ld.so expects buggy relocs. */
1523 osec
= sec
->output_section
;
1524 indx
= elf_section_data (osec
)->dynindx
;
1527 osec
= htab
->root
.text_index_section
;
1528 indx
= elf_section_data (osec
)->dynindx
;
1530 BFD_ASSERT (indx
!= 0);
1533 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1537 loc
= sreloc
->contents
;
1538 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1539 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1541 /* This reloc will be computed at runtime, so there's no
1542 need to do anything now, except for R_CRIS_32 relocations
1543 that have been turned into R_CRIS_RELATIVE. */
1550 case R_CRIS_16_DTPREL
:
1551 case R_CRIS_32_DTPREL
:
1552 /* This relocation must only be performed against local
1553 symbols, or to sections that are not loadable. It's also
1554 ok when we link a program and the symbol is defined in an
1555 ordinary (non-DSO) object (if it's undefined there, we've
1556 already seen an error). */
1558 && (input_section
->flags
& SEC_ALLOC
) != 0
1559 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1560 && (bfd_link_pic (info
)
1562 && h
->root
.type
!= bfd_link_hash_undefined
)))
1564 (*_bfd_error_handler
)
1565 ((h
->root
.type
== bfd_link_hash_undefined
)
1566 /* We shouldn't get here for GCC-emitted code. */
1567 ? _("%B, section %A: relocation %s has an undefined"
1568 " reference to `%s', perhaps a declaration mixup?")
1569 : ("%B, section %A: relocation %s is"
1570 " not allowed for `%s', a global symbol with default"
1571 " visibility, perhaps a declaration mixup?"),
1574 cris_elf_howto_table
[r_type
].name
,
1575 symname
!= NULL
&& symname
[0] != '\0'
1576 ? symname
: _("[whose name is lost]"));
1577 bfd_set_error (bfd_error_bad_value
);
1581 BFD_ASSERT ((input_section
->flags
& SEC_ALLOC
) == 0
1582 || htab
->dtpmod_refcount
!= 0);
1584 /* Fill in a R_CRIS_DTPMOD reloc at offset 3 if we haven't
1585 already done so. Note that we do this in .got.plt, not
1586 in .got, as .got.plt contains the first part, still the
1587 reloc is against .got, because the linker script directs
1588 (is required to direct) them both into .got. */
1589 if (htab
->dtpmod_refcount
> 0
1590 && (input_section
->flags
& SEC_ALLOC
) != 0)
1592 asection
*sgotplt
= bfd_get_linker_section (dynobj
, ".got.plt");
1593 BFD_ASSERT (sgotplt
!= NULL
);
1595 if (bfd_link_pic (info
))
1597 Elf_Internal_Rela outrel
;
1600 if (srelgot
== NULL
)
1601 srelgot
= bfd_get_linker_section (dynobj
, ".rela.got");
1602 BFD_ASSERT (srelgot
!= NULL
);
1603 loc
= srelgot
->contents
;
1604 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1606 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 12);
1607 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 16);
1608 outrel
.r_offset
= (sgotplt
->output_section
->vma
1609 + sgotplt
->output_offset
1611 outrel
.r_info
= ELF32_R_INFO (0, R_CRIS_DTPMOD
);
1612 outrel
.r_addend
= 0;
1613 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1617 /* For an executable, the GOT entry contents is known. */
1618 bfd_put_32 (output_bfd
, (bfd_vma
) 1, sgotplt
->contents
+ 12);
1619 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 16);
1622 /* Reverse the sign to mark that we've emitted the
1623 required GOT entry. */
1624 htab
->dtpmod_refcount
= - htab
->dtpmod_refcount
;
1627 /* The relocation is the offset from the start of the module
1628 TLS block to the (local) symbol. */
1629 relocation
-= elf_hash_table (info
)->tls_sec
== NULL
1630 ? 0 : elf_hash_table (info
)->tls_sec
->vma
;
1634 if (bfd_link_pic (info
))
1636 bfd_set_error (bfd_error_invalid_operation
);
1638 /* We've already informed in cris_elf_check_relocs that
1639 this is an error. */
1644 case R_CRIS_16_GOT_GD
:
1645 case R_CRIS_32_GOT_GD
:
1646 if (rel
->r_addend
!= 0)
1648 /* We can't do anything for a relocation which is against a
1649 symbol *plus offset*. The GOT holds relocations for
1650 symbols. Make this an error; the compiler isn't allowed
1651 to pass us these kinds of things. */
1652 (*_bfd_error_handler
)
1653 (_("%B, section %A: relocation %s with non-zero addend %d"
1654 " against symbol `%s'"),
1657 cris_elf_howto_table
[r_type
].name
,
1659 symname
[0] != '\0' ? symname
: _("[whose name is lost]"));
1661 bfd_set_error (bfd_error_bad_value
);
1665 if (!bfd_link_pic (info
)
1666 && (h
== NULL
|| h
->def_regular
|| ELF_COMMON_DEF_P (h
)))
1668 /* Known contents of the GOT. */
1671 /* The symbol is defined in the program, so just write
1672 (1, known_tpoffset) into the GOT. */
1673 relocation
-= elf_hash_table (info
)->tls_sec
->vma
;
1677 off
= elf_cris_hash_entry (h
)->tprel_refcount
> 0
1678 ? h
->got
.offset
+ 4 : h
->got
.offset
;
1682 off
= local_got_offsets
[r_symndx
];
1683 if (local_got_offsets
[LGOT_TPREL_NDX (r_symndx
)])
1687 /* We use bit 1 of the offset as a flag for GOT entry with
1688 the R_CRIS_DTP reloc, setting it when we've emitted the
1689 GOT entry and reloc. Bit 0 is used for R_CRIS_32_TPREL
1698 local_got_offsets
[r_symndx
] |= 2;
1700 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ off
);
1701 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
+ 4);
1706 relocation
= sgot
->output_offset
+ off
1707 + (r_type
== R_CRIS_32_GD
? sgot
->output_section
->vma
: 0);
1711 /* Not all parts of the GOT entry are known; emit a real
1716 off
= elf_cris_hash_entry (h
)->tprel_refcount
> 0
1717 ? h
->got
.offset
+ 4 : h
->got
.offset
;
1720 off
= local_got_offsets
[r_symndx
];
1721 if (local_got_offsets
[LGOT_TPREL_NDX (r_symndx
)])
1725 /* See above re bit 1 and bit 0 usage. */
1728 Elf_Internal_Rela outrel
;
1736 local_got_offsets
[r_symndx
] |= 2;
1738 /* Clear the target contents of the GOT (just as a
1739 gesture; it's already cleared on allocation): this
1740 relocation is not like the other dynrelocs. */
1741 bfd_put_32 (output_bfd
, 0, sgot
->contents
+ off
);
1742 bfd_put_32 (output_bfd
, 0, sgot
->contents
+ off
+ 4);
1744 if (srelgot
== NULL
)
1745 srelgot
= bfd_get_linker_section (dynobj
, ".rela.got");
1746 BFD_ASSERT (srelgot
!= NULL
);
1748 if (h
!= NULL
&& h
->dynindx
!= -1)
1750 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CRIS_DTP
);
1755 outrel
.r_info
= ELF32_R_INFO (0, R_CRIS_DTP
);
1757 /* NULL if we had an error. */
1758 relocation
-= elf_hash_table (info
)->tls_sec
== NULL
1759 ? 0 : elf_hash_table (info
)->tls_sec
->vma
;
1762 outrel
.r_offset
= (sgot
->output_section
->vma
1763 + sgot
->output_offset
1765 outrel
.r_addend
= relocation
;
1766 loc
= srelgot
->contents
;
1767 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1769 /* NULL if we had an error. */
1770 if (srelgot
->contents
!= NULL
)
1771 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1776 relocation
= sgot
->output_offset
+ off
1777 + (r_type
== R_CRIS_32_GD
? sgot
->output_section
->vma
: 0);
1780 /* The GOT-relative offset to the GOT entry is the
1781 relocation, or for R_CRIS_32_GD, the actual address of
1786 if (bfd_link_pic (info
))
1788 bfd_set_error (bfd_error_invalid_operation
);
1790 /* We've already informed in cris_elf_check_relocs that
1791 this is an error. */
1796 case R_CRIS_32_GOT_TPREL
:
1797 case R_CRIS_16_GOT_TPREL
:
1798 if (rel
->r_addend
!= 0)
1800 /* We can't do anything for a relocation which is
1801 against a symbol *plus offset*. GOT holds
1802 relocations for symbols. Make this an error; the
1803 compiler isn't allowed to pass us these kinds of
1805 (*_bfd_error_handler
)
1806 (_("%B, section %A: relocation %s with non-zero addend %d"
1807 " against symbol `%s'"),
1810 cris_elf_howto_table
[r_type
].name
,
1812 symname
[0] != '\0' ? symname
: _("[whose name is lost]"));
1813 bfd_set_error (bfd_error_bad_value
);
1817 if (!bfd_link_pic (info
)
1818 && (h
== NULL
|| h
->def_regular
|| ELF_COMMON_DEF_P (h
)))
1820 /* Known contents of the GOT. */
1823 /* The symbol is defined in the program, so just write
1824 the -prog_tls_size+known_tpoffset into the GOT. */
1825 relocation
-= elf_hash_table (info
)->tls_sec
->vma
;
1826 relocation
-= elf_hash_table (info
)->tls_size
;
1829 off
= h
->got
.offset
;
1831 off
= local_got_offsets
[r_symndx
];
1833 /* Bit 0 is used to mark whether we've emitted the required
1834 entry (and if needed R_CRIS_32_TPREL reloc). Bit 1
1835 is used similarly for R_CRIS_DTP, see above. */
1843 local_got_offsets
[r_symndx
] |= 1;
1845 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1850 relocation
= sgot
->output_offset
+ off
1851 + (r_type
== R_CRIS_32_IE
? sgot
->output_section
->vma
: 0);
1855 /* Emit a real relocation. */
1859 off
= h
->got
.offset
;
1861 off
= local_got_offsets
[r_symndx
];
1863 /* See above re usage of bit 0 and 1. */
1866 Elf_Internal_Rela outrel
;
1874 local_got_offsets
[r_symndx
] |= 1;
1876 if (srelgot
== NULL
)
1877 srelgot
= bfd_get_linker_section (dynobj
, ".rela.got");
1878 BFD_ASSERT (srelgot
!= NULL
);
1880 if (h
!= NULL
&& h
->dynindx
!= -1)
1882 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CRIS_32_TPREL
);
1887 outrel
.r_info
= ELF32_R_INFO (0, R_CRIS_32_TPREL
);
1889 /* NULL if we had an error. */
1890 relocation
-= elf_hash_table (info
)->tls_sec
== NULL
1891 ? 0 : elf_hash_table (info
)->tls_sec
->vma
;
1894 /* Just "define" the initial contents in some
1895 semi-logical way. */
1896 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1898 outrel
.r_offset
= (sgot
->output_section
->vma
1899 + sgot
->output_offset
1901 outrel
.r_addend
= relocation
;
1902 loc
= srelgot
->contents
;
1903 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1904 /* NULL if we had an error. */
1905 if (srelgot
->contents
!= NULL
)
1906 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1911 relocation
= sgot
->output_offset
+ off
1912 + (r_type
== R_CRIS_32_IE
? sgot
->output_section
->vma
: 0);
1915 /* The GOT-relative offset to the GOT entry is the relocation,
1916 or for R_CRIS_32_GD, the actual address of the GOT entry. */
1919 case R_CRIS_16_TPREL
:
1920 case R_CRIS_32_TPREL
:
1921 /* This relocation must only be performed against symbols
1922 defined in an ordinary (non-DSO) object. */
1923 if (bfd_link_pic (info
))
1925 bfd_set_error (bfd_error_invalid_operation
);
1927 /* We've already informed in cris_elf_check_relocs that
1928 this is an error. */
1933 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1934 && !(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
1935 /* If it's undefined, then an error message has already
1937 && h
->root
.type
!= bfd_link_hash_undefined
)
1939 (*_bfd_error_handler
)
1940 (_("%B, section %A: relocation %s is"
1941 " not allowed for symbol: `%s'"
1942 " which is defined outside the program,"
1943 " perhaps a declaration mixup?"),
1946 cris_elf_howto_table
[r_type
].name
,
1948 bfd_set_error (bfd_error_bad_value
);
1952 /* NULL if we had an error. */
1953 relocation
-= elf_hash_table (info
)->tls_sec
== NULL
1955 : (elf_hash_table (info
)->tls_sec
->vma
1956 + elf_hash_table (info
)->tls_size
);
1958 /* The TLS-relative offset is the relocation. */
1966 r
= cris_final_link_relocate (howto
, input_bfd
, input_section
,
1967 contents
, rel
, relocation
);
1969 if (r
!= bfd_reloc_ok
)
1971 const char * msg
= (const char *) NULL
;
1975 case bfd_reloc_overflow
:
1976 r
= info
->callbacks
->reloc_overflow
1977 (info
, (h
? &h
->root
: NULL
), symname
, howto
->name
,
1978 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
1979 if (additional_relocation_error_msg_count
> 0)
1981 additional_relocation_error_msg_count
--;
1984 case R_CRIS_16_GOTPLT
:
1987 /* Not just TLS is involved here, so we make
1988 generation and message depend on -fPIC/-fpic
1990 case R_CRIS_16_GOT_TPREL
:
1991 case R_CRIS_16_GOT_GD
:
1992 (*_bfd_error_handler
)
1993 (_("(too many global variables for -fpic:"
1994 " recompile with -fPIC)"));
1997 case R_CRIS_16_TPREL
:
1998 case R_CRIS_16_DTPREL
:
1999 (*_bfd_error_handler
)
2000 (_("(thread-local data too big for -fpic or"
2001 " -msmall-tls: recompile with -fPIC or"
2002 " -mno-small-tls)"));
2005 /* No known cause for overflow for other relocs. */
2012 case bfd_reloc_undefined
:
2013 r
= info
->callbacks
->undefined_symbol
2014 (info
, symname
, input_bfd
, input_section
, rel
->r_offset
,
2018 case bfd_reloc_outofrange
:
2019 msg
= _("internal error: out of range error");
2022 case bfd_reloc_notsupported
:
2023 msg
= _("internal error: unsupported relocation error");
2026 case bfd_reloc_dangerous
:
2027 msg
= _("internal error: dangerous relocation");
2031 msg
= _("internal error: unknown error");
2036 r
= info
->callbacks
->warning
2037 (info
, msg
, symname
, input_bfd
, input_section
, rel
->r_offset
);
2047 /* Finish up dynamic symbol handling. We set the contents of various
2048 dynamic sections here. */
2051 elf_cris_finish_dynamic_symbol (bfd
*output_bfd
,
2052 struct bfd_link_info
*info
,
2053 struct elf_link_hash_entry
*h
,
2054 Elf_Internal_Sym
*sym
)
2056 struct elf_cris_link_hash_table
* htab
;
2059 /* Where in the plt entry to put values. */
2060 int plt_off1
= 2, plt_off2
= 10, plt_off3
= 16;
2062 /* What offset to add to the distance to the first PLT entry for the
2063 value at plt_off3. */
2064 int plt_off3_value_bias
= 4;
2066 /* Where in the PLT entry the call-dynlink-stub is (happens to be same
2067 for PIC and non-PIC for v32 and pre-v32). */
2068 int plt_stub_offset
= 8;
2069 int plt_entry_size
= PLT_ENTRY_SIZE
;
2070 const bfd_byte
*plt_entry
= elf_cris_plt_entry
;
2071 const bfd_byte
*plt_pic_entry
= elf_cris_pic_plt_entry
;
2073 htab
= elf_cris_hash_table (info
);
2077 /* Adjust the various PLT entry offsets. */
2078 if (bfd_get_mach (output_bfd
) == bfd_mach_cris_v32
)
2082 plt_off3_value_bias
= -2;
2083 plt_stub_offset
= 12;
2084 plt_entry_size
= PLT_ENTRY_SIZE_V32
;
2085 plt_entry
= elf_cris_plt_entry_v32
;
2086 plt_pic_entry
= elf_cris_pic_plt_entry_v32
;
2089 dynobj
= elf_hash_table (info
)->dynobj
;
2091 if (h
->plt
.offset
!= (bfd_vma
) -1)
2098 bfd_vma gotplt_offset
2099 = elf_cris_hash_entry (h
)->gotplt_offset
;
2100 Elf_Internal_Rela rela
;
2102 bfd_boolean has_gotplt
= gotplt_offset
!= 0;
2104 /* Get the index in the .rela.plt relocations for the .got.plt
2105 entry that corresponds to this symbol.
2106 We have to count backwards here, and the result is only valid
2107 as an index into .rela.plt. We also have to undo the effect
2108 of the R_CRIS_DTPMOD entry at .got index 3 (offset 12 into
2109 .got.plt) for which gotplt_offset is adjusted, because while
2110 that entry goes into .got.plt, its relocation goes into
2111 .rela.got, not .rela.plt. (It's not PLT-specific; not to be
2112 processed as part of the runtime lazy .rela.plt relocation).
2113 FIXME: There be literal constants here... */
2114 bfd_vma rela_plt_index
2115 = (htab
->dtpmod_refcount
!= 0
2116 ? gotplt_offset
/4 - 2 - 3 : gotplt_offset
/4 - 3);
2118 /* Get the offset into the .got table of the entry that corresponds
2119 to this function. Note that we embed knowledge that "incoming"
2120 .got goes after .got.plt in the output without padding (pointer
2121 aligned). However, that knowledge is present in several other
2126 : h
->got
.offset
+ htab
->next_gotplt_entry
);
2128 /* This symbol has an entry in the procedure linkage table. Set it
2131 BFD_ASSERT (h
->dynindx
!= -1);
2133 splt
= bfd_get_linker_section (dynobj
, ".plt");
2134 sgotplt
= bfd_get_linker_section (dynobj
, ".got.plt");
2135 srela
= bfd_get_linker_section (dynobj
, ".rela.plt");
2136 BFD_ASSERT (splt
!= NULL
&& sgotplt
!= NULL
2137 && (! has_gotplt
|| srela
!= NULL
));
2139 got_base
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
;
2141 /* Fill in the entry in the procedure linkage table. */
2142 if (! bfd_link_pic (info
))
2144 memcpy (splt
->contents
+ h
->plt
.offset
, plt_entry
,
2147 /* We need to enter the absolute address of the GOT entry here. */
2148 bfd_put_32 (output_bfd
, got_base
+ got_offset
,
2149 splt
->contents
+ h
->plt
.offset
+ plt_off1
);
2153 memcpy (splt
->contents
+ h
->plt
.offset
, plt_pic_entry
,
2155 bfd_put_32 (output_bfd
, got_offset
,
2156 splt
->contents
+ h
->plt
.offset
+ plt_off1
);
2159 /* Fill in the plt entry and make a relocation, if this is a "real"
2163 /* Fill in the offset to the reloc table. */
2164 bfd_put_32 (output_bfd
,
2165 rela_plt_index
* sizeof (Elf32_External_Rela
),
2166 splt
->contents
+ h
->plt
.offset
+ plt_off2
);
2168 /* Fill in the offset to the first PLT entry, where to "jump". */
2169 bfd_put_32 (output_bfd
,
2170 - (h
->plt
.offset
+ plt_off3
+ plt_off3_value_bias
),
2171 splt
->contents
+ h
->plt
.offset
+ plt_off3
);
2173 /* Fill in the entry in the global offset table with the address of
2174 the relocating stub. */
2175 bfd_put_32 (output_bfd
,
2176 (splt
->output_section
->vma
2177 + splt
->output_offset
2180 sgotplt
->contents
+ got_offset
);
2182 /* Fill in the entry in the .rela.plt section. */
2183 rela
.r_offset
= (sgotplt
->output_section
->vma
2184 + sgotplt
->output_offset
2186 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CRIS_JUMP_SLOT
);
2188 loc
= srela
->contents
+ rela_plt_index
* sizeof (Elf32_External_Rela
);
2189 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2192 if (!h
->def_regular
)
2194 /* Mark the symbol as undefined, rather than as defined in
2195 the .plt section. Leave the value alone. */
2196 sym
->st_shndx
= SHN_UNDEF
;
2198 /* FIXME: From elf32-sparc.c 2001-02-19 (1.18). I still don't
2199 know whether resetting the value is significant; if it really
2200 is, rather than a quirk or bug in the sparc port, then I
2201 believe we'd see this elsewhere. */
2202 /* If the symbol is weak, we do need to clear the value.
2203 Otherwise, the PLT entry would provide a definition for
2204 the symbol even if the symbol wasn't defined anywhere,
2205 and so the symbol would never be NULL. */
2206 if (!h
->ref_regular_nonweak
)
2211 /* For an ordinary program, we emit .got relocs only for symbols that
2212 are in the dynamic-symbols table and are either defined by the
2213 program or are undefined weak symbols, or are function symbols
2214 where we do not output a PLT: the PLT reloc was output above and all
2215 references to the function symbol are redirected to the PLT. */
2216 if (h
->got
.offset
!= (bfd_vma
) -1
2217 && (elf_cris_hash_entry (h
)->reg_got_refcount
> 0)
2218 && (bfd_link_pic (info
)
2219 || (h
->dynindx
!= -1
2220 && h
->plt
.offset
== (bfd_vma
) -1
2222 && h
->root
.type
!= bfd_link_hash_undefweak
)))
2226 Elf_Internal_Rela rela
;
2230 /* This symbol has an entry in the global offset table. Set it up. */
2232 sgot
= bfd_get_linker_section (dynobj
, ".got");
2233 srela
= bfd_get_linker_section (dynobj
, ".rela.got");
2234 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
2236 rela
.r_offset
= (sgot
->output_section
->vma
2237 + sgot
->output_offset
2238 + (h
->got
.offset
&~ (bfd_vma
) 1));
2240 /* If this is a static link, or it is a -Bsymbolic link and the
2241 symbol is defined locally or was forced to be local because
2242 of a version file, we just want to emit a RELATIVE reloc.
2243 The entry in the global offset table will already have been
2244 initialized in the relocate_section function. */
2245 where
= sgot
->contents
+ (h
->got
.offset
&~ (bfd_vma
) 1);
2246 if (! elf_hash_table (info
)->dynamic_sections_created
2247 || (bfd_link_pic (info
)
2248 && (SYMBOLIC_BIND (info
, h
) || h
->dynindx
== -1)
2251 rela
.r_info
= ELF32_R_INFO (0, R_CRIS_RELATIVE
);
2252 rela
.r_addend
= bfd_get_signed_32 (output_bfd
, where
);
2256 bfd_put_32 (output_bfd
, (bfd_vma
) 0, where
);
2257 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CRIS_GLOB_DAT
);
2261 loc
= srela
->contents
;
2262 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2263 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2269 Elf_Internal_Rela rela
;
2272 /* This symbol needs a copy reloc. Set it up. */
2274 BFD_ASSERT (h
->dynindx
!= -1
2275 && (h
->root
.type
== bfd_link_hash_defined
2276 || h
->root
.type
== bfd_link_hash_defweak
));
2278 s
= bfd_get_linker_section (dynobj
, ".rela.bss");
2279 BFD_ASSERT (s
!= NULL
);
2281 rela
.r_offset
= (h
->root
.u
.def
.value
2282 + h
->root
.u
.def
.section
->output_section
->vma
2283 + h
->root
.u
.def
.section
->output_offset
);
2284 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CRIS_COPY
);
2286 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2287 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2290 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2291 if (h
== elf_hash_table (info
)->hdynamic
2292 || h
== elf_hash_table (info
)->hgot
)
2293 sym
->st_shndx
= SHN_ABS
;
2298 /* Finish up the dynamic sections. Do *not* emit relocs here, as their
2299 offsets were changed, as part of -z combreloc handling, from those we
2303 elf_cris_finish_dynamic_sections (bfd
*output_bfd
,
2304 struct bfd_link_info
*info
)
2310 dynobj
= elf_hash_table (info
)->dynobj
;
2312 sgot
= bfd_get_linker_section (dynobj
, ".got.plt");
2313 BFD_ASSERT (sgot
!= NULL
);
2314 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
2316 if (elf_hash_table (info
)->dynamic_sections_created
)
2319 Elf32_External_Dyn
*dyncon
, *dynconend
;
2321 splt
= bfd_get_linker_section (dynobj
, ".plt");
2322 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2324 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2325 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2326 for (; dyncon
< dynconend
; dyncon
++)
2328 Elf_Internal_Dyn dyn
;
2331 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2339 dyn
.d_un
.d_ptr
= sgot
->output_section
->vma
+ sgot
->output_offset
;
2340 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2344 /* Yes, we *can* have a .plt and no .plt.rela, for instance
2345 if all symbols are found in the .got (not .got.plt). */
2346 s
= bfd_get_linker_section (dynobj
, ".rela.plt");
2347 dyn
.d_un
.d_ptr
= s
!= NULL
? (s
->output_section
->vma
2348 + s
->output_offset
) : 0;
2349 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2353 s
= bfd_get_linker_section (dynobj
, ".rela.plt");
2357 dyn
.d_un
.d_val
= s
->size
;
2358 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2362 /* The procedure linkage table relocs (DT_JMPREL) should
2363 not be included in the overall relocs (DT_RELA).
2364 Therefore, we override the DT_RELASZ entry here to
2365 make it not include the JMPREL relocs. Since the
2366 linker script arranges for .rela.plt to follow all
2367 other relocation sections, we don't have to worry
2368 about changing the DT_RELA entry. */
2369 s
= bfd_get_linker_section (dynobj
, ".rela.plt");
2371 dyn
.d_un
.d_val
-= s
->size
;
2372 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2377 /* Fill in the first entry in the procedure linkage table. */
2380 if (bfd_get_mach (output_bfd
) == bfd_mach_cris_v32
)
2382 if (bfd_link_pic (info
))
2383 memcpy (splt
->contents
, elf_cris_pic_plt0_entry_v32
,
2384 PLT_ENTRY_SIZE_V32
);
2387 memcpy (splt
->contents
, elf_cris_plt0_entry_v32
,
2388 PLT_ENTRY_SIZE_V32
);
2389 bfd_put_32 (output_bfd
,
2390 sgot
->output_section
->vma
2391 + sgot
->output_offset
+ 4,
2392 splt
->contents
+ 4);
2394 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
2395 = PLT_ENTRY_SIZE_V32
;
2400 if (bfd_link_pic (info
))
2401 memcpy (splt
->contents
, elf_cris_pic_plt0_entry
,
2405 memcpy (splt
->contents
, elf_cris_plt0_entry
,
2407 bfd_put_32 (output_bfd
,
2408 sgot
->output_section
->vma
2409 + sgot
->output_offset
+ 4,
2410 splt
->contents
+ 6);
2411 bfd_put_32 (output_bfd
,
2412 sgot
->output_section
->vma
2413 + sgot
->output_offset
+ 8,
2414 splt
->contents
+ 14);
2416 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
2423 /* Fill in the first three entries in the global offset table. */
2427 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
2429 bfd_put_32 (output_bfd
,
2430 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2432 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
2433 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
2436 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2441 /* Return the section that should be marked against GC for a given
2445 cris_elf_gc_mark_hook (asection
*sec
,
2446 struct bfd_link_info
*info
,
2447 Elf_Internal_Rela
*rel
,
2448 struct elf_link_hash_entry
*h
,
2449 Elf_Internal_Sym
*sym
)
2451 enum elf_cris_reloc_type r_type
= ELF32_R_TYPE (rel
->r_info
);
2455 case R_CRIS_GNU_VTINHERIT
:
2456 case R_CRIS_GNU_VTENTRY
:
2463 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2466 /* Update the got entry reference counts for the section being removed. */
2469 cris_elf_gc_sweep_hook (bfd
*abfd
,
2470 struct bfd_link_info
*info
,
2472 const Elf_Internal_Rela
*relocs
)
2474 struct elf_cris_link_hash_table
* htab
;
2475 Elf_Internal_Shdr
*symtab_hdr
;
2476 struct elf_link_hash_entry
**sym_hashes
;
2477 bfd_signed_vma
*local_got_refcounts
;
2478 const Elf_Internal_Rela
*rel
, *relend
;
2483 if (bfd_link_relocatable (info
))
2486 dynobj
= elf_hash_table (info
)->dynobj
;
2490 htab
= elf_cris_hash_table (info
);
2494 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2495 sym_hashes
= elf_sym_hashes (abfd
);
2496 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2498 sgot
= bfd_get_linker_section (dynobj
, ".got");
2499 srelgot
= bfd_get_linker_section (dynobj
, ".rela.got");
2501 relend
= relocs
+ sec
->reloc_count
;
2502 for (rel
= relocs
; rel
< relend
; rel
++)
2504 unsigned long r_symndx
;
2505 struct elf_link_hash_entry
*h
= NULL
;
2506 bfd_signed_vma got_element_size
= 4;
2507 bfd_signed_vma
*specific_refcount
= NULL
;
2508 enum elf_cris_reloc_type r_type
;
2510 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2511 if (r_symndx
>= symtab_hdr
->sh_info
)
2513 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2514 while (h
->root
.type
== bfd_link_hash_indirect
2515 || h
->root
.type
== bfd_link_hash_warning
)
2516 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2519 r_type
= ELF32_R_TYPE (rel
->r_info
);
2524 case R_CRIS_16_GOTPLT
:
2525 case R_CRIS_32_GOTPLT
:
2526 specific_refcount
= h
!= NULL
2527 ? &((struct elf_cris_link_hash_entry
*) h
)->reg_got_refcount
2528 : &local_got_refcounts
[LGOT_REG_NDX (r_symndx
)];
2532 case R_CRIS_32_GOT_GD
:
2533 case R_CRIS_16_GOT_GD
:
2534 got_element_size
= 8;
2535 specific_refcount
= h
!= NULL
2536 ? &((struct elf_cris_link_hash_entry
*) h
)->dtp_refcount
2537 : &local_got_refcounts
[LGOT_DTP_NDX (r_symndx
)];
2541 case R_CRIS_16_GOT_TPREL
:
2542 case R_CRIS_32_GOT_TPREL
:
2543 specific_refcount
= h
!= NULL
2544 ? &((struct elf_cris_link_hash_entry
*) h
)->tprel_refcount
2545 : &local_got_refcounts
[LGOT_TPREL_NDX (r_symndx
)];
2556 case R_CRIS_16_GOT_TPREL
:
2557 case R_CRIS_32_GOT_TPREL
:
2558 case R_CRIS_32_GOT_GD
:
2559 case R_CRIS_16_GOT_GD
:
2564 /* If the counters are 0 when we got here, we've
2565 miscounted somehow somewhere, an internal error. */
2566 BFD_ASSERT (h
->got
.refcount
> 0);
2569 BFD_ASSERT (*specific_refcount
> 0);
2570 --*specific_refcount
;
2571 if (*specific_refcount
== 0)
2573 /* We don't need the .got entry any more. */
2574 sgot
->size
-= got_element_size
;
2575 srelgot
->size
-= sizeof (Elf32_External_Rela
);
2581 if (local_got_refcounts
!= NULL
)
2583 /* If the counters are 0 when we got here, we've
2584 miscounted somehow somewhere, an internal error. */
2585 BFD_ASSERT (local_got_refcounts
[r_symndx
] > 0);
2586 --local_got_refcounts
[r_symndx
];
2588 BFD_ASSERT (*specific_refcount
> 0);
2589 --*specific_refcount
;
2590 if (*specific_refcount
== 0)
2592 /* We don't need the .got entry any more. */
2593 sgot
->size
-= got_element_size
;
2594 if (bfd_link_pic (info
))
2595 srelgot
->size
-= sizeof (Elf32_External_Rela
);
2600 case R_CRIS_16_GOTPLT
:
2601 case R_CRIS_32_GOTPLT
:
2602 /* For local symbols, treat these like GOT relocs. */
2604 goto local_got_reloc
;
2606 /* For global symbols, adjust the reloc-specific refcount. */
2607 elf_cris_hash_entry (h
)->gotplt_refcount
--;
2610 case R_CRIS_32_PLT_GOTREL
:
2611 /* FIXME: We don't garbage-collect away the .got section. */
2612 if (local_got_refcounts
!= NULL
)
2613 local_got_refcounts
[-1]--;
2619 case R_CRIS_8_PCREL
:
2620 case R_CRIS_16_PCREL
:
2621 case R_CRIS_32_PCREL
:
2622 case R_CRIS_32_PLT_PCREL
:
2623 /* Negate the increment we did in cris_elf_check_relocs. */
2626 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2627 && h
->plt
.refcount
> 0)
2632 case R_CRIS_32_DTPREL
:
2633 /* This'd be a .dtpreld entry in e.g. debug info. */
2634 if ((sec
->flags
& SEC_ALLOC
) == 0)
2637 case R_CRIS_16_DTPREL
:
2638 htab
->dtpmod_refcount
--;
2639 if (htab
->dtpmod_refcount
== 0)
2640 htab
->next_gotplt_entry
-= 8;
2641 BFD_ASSERT (local_got_refcounts
!= NULL
);
2642 local_got_refcounts
[-1]--;
2653 /* The elf_backend_plt_sym_val hook function. */
2656 cris_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
, const asection
*plt
,
2659 bfd_size_type plt_entry_size
;
2660 bfd_size_type pltoffs
;
2661 bfd
*abfd
= plt
->owner
;
2663 /* Same for CRIS and CRIS v32; see elf_cris_(|pic_)plt_entry(|_v32)[]. */
2664 bfd_size_type plt_entry_got_offset
= 2;
2665 bfd_size_type plt_sec_size
;
2666 bfd_size_type got_vma_for_dyn
;
2669 /* FIXME: the .got section should be readily available also when
2670 we're not linking. */
2671 if ((got
= bfd_get_section_by_name (abfd
, ".got")) == NULL
)
2672 return (bfd_vma
) -1;
2674 plt_sec_size
= bfd_section_size (plt
->owner
, plt
);
2676 = (bfd_get_mach (abfd
) == bfd_mach_cris_v32
2677 ? PLT_ENTRY_SIZE_V32
: PLT_ENTRY_SIZE
);
2679 /* Data in PLT is GOT-relative for DYN, but absolute for EXE. */
2680 got_vma_for_dyn
= (abfd
->flags
& EXEC_P
) ? 0 : got
->vma
;
2682 /* Because we can have merged GOT entries; a single .got entry for
2683 both GOT and the PLT part of the GOT (.got.plt), the index of the
2684 reloc in .rela.plt is not the same as the index in the PLT.
2685 Instead, we have to hunt down the GOT offset in the PLT that
2686 corresponds to that of this reloc. Unfortunately, we will only
2687 be called for the .rela.plt relocs, so we'll miss synthetic
2688 symbols for .plt entries with merged GOT entries. (FIXME:
2689 fixable by providing our own bfd_elf32_get_synthetic_symtab.
2690 Doesn't seem worthwile at time of this writing.) FIXME: we've
2691 gone from O(1) to O(N) (N number of PLT entries) for finding each
2692 PLT address. Shouldn't matter in practice though. */
2694 for (pltoffs
= plt_entry_size
;
2695 pltoffs
< plt_sec_size
;
2696 pltoffs
+= plt_entry_size
)
2698 bfd_size_type got_offset
;
2699 bfd_byte gotoffs_raw
[4];
2701 if (!bfd_get_section_contents (abfd
, (asection
*) plt
, gotoffs_raw
,
2702 pltoffs
+ plt_entry_got_offset
,
2703 sizeof (gotoffs_raw
)))
2704 return (bfd_vma
) -1;
2706 got_offset
= bfd_get_32 (abfd
, gotoffs_raw
);
2707 if (got_offset
+ got_vma_for_dyn
== rel
->address
)
2708 return plt
->vma
+ pltoffs
;
2711 /* While it's tempting to BFD_ASSERT that we shouldn't get here,
2712 that'd not be graceful behavior for invalid input. */
2713 return (bfd_vma
) -1;
2716 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
2717 entry but we found we will not create any. Called when we find we will
2718 not have any PLT for this symbol, by for example
2719 elf_cris_adjust_dynamic_symbol when we're doing a proper dynamic link,
2720 or elf_cris_size_dynamic_sections if no dynamic sections will be
2721 created (we're only linking static objects). */
2724 elf_cris_adjust_gotplt_to_got (struct elf_cris_link_hash_entry
*h
, void * p
)
2726 struct bfd_link_info
*info
= (struct bfd_link_info
*) p
;
2728 /* A GOTPLT reloc, when activated, is supposed to be included into
2729 the PLT refcount. */
2730 BFD_ASSERT (h
->gotplt_refcount
== 0
2731 || h
->gotplt_refcount
<= h
->root
.plt
.refcount
);
2733 /* If nobody wanted a GOTPLT with this symbol, we're done. */
2734 if (h
->gotplt_refcount
<= 0)
2737 if (h
->reg_got_refcount
> 0)
2739 /* There's a GOT entry for this symbol. Just adjust the refcounts.
2740 Probably not necessary at this stage, but keeping them accurate
2741 helps avoiding surprises later. */
2742 h
->root
.got
.refcount
+= h
->gotplt_refcount
;
2743 h
->reg_got_refcount
+= h
->gotplt_refcount
;
2744 h
->gotplt_refcount
= 0;
2748 /* No GOT entry for this symbol. We need to create one. */
2749 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2753 BFD_ASSERT (dynobj
!= NULL
);
2754 sgot
= bfd_get_linker_section (dynobj
, ".got");
2755 srelgot
= bfd_get_linker_section (dynobj
, ".rela.got");
2757 /* Put accurate refcounts there. */
2758 h
->root
.got
.refcount
+= h
->gotplt_refcount
;
2759 h
->reg_got_refcount
= h
->gotplt_refcount
;
2761 h
->gotplt_refcount
= 0;
2763 /* We always have a .got and a .rela.got section if there were
2764 GOTPLT relocs in input. */
2765 BFD_ASSERT (sgot
!= NULL
&& srelgot
!= NULL
);
2767 /* Allocate space in the .got section. */
2770 /* Allocate relocation space. */
2771 srelgot
->size
+= sizeof (Elf32_External_Rela
);
2777 /* Try to fold PLT entries with GOT entries. There are two cases when we
2780 - When all PLT references are GOTPLT references, and there are GOT
2781 references, and this is not the executable. We don't have to
2782 generate a PLT at all.
2784 - When there are both (ordinary) PLT references and GOT references,
2785 and this isn't the executable.
2786 We want to make the PLT reference use the ordinary GOT entry rather
2787 than R_CRIS_JUMP_SLOT, a run-time dynamically resolved GOTPLT entry,
2788 since the GOT entry will have to be resolved at startup anyway.
2790 Though the latter case is handled when room for the PLT is allocated,
2793 By folding into the GOT, we may need a round-trip to a PLT in the
2794 executable for calls, a loss in performance. Still, losing a
2795 reloc is a win in size and at least in start-up time.
2797 Note that this function is called before symbols are forced local by
2798 version scripts. The differing cases are handled by
2799 elf_cris_hide_symbol. */
2802 elf_cris_try_fold_plt_to_got (struct elf_cris_link_hash_entry
*h
, void * p
)
2804 struct bfd_link_info
*info
= (struct bfd_link_info
*) p
;
2806 /* If there are no GOT references for this symbol, we can't fold any
2807 other reference so there's nothing to do. Likewise if there are no
2808 PLT references; GOTPLT references included. */
2809 if (h
->root
.got
.refcount
<= 0 || h
->root
.plt
.refcount
<= 0)
2812 /* GOTPLT relocs are supposed to be included into the PLT refcount. */
2813 BFD_ASSERT (h
->gotplt_refcount
<= h
->root
.plt
.refcount
);
2815 if (h
->gotplt_refcount
== h
->root
.plt
.refcount
)
2817 /* The only PLT references are GOTPLT references, and there are GOT
2818 references. Convert PLT to GOT references. */
2819 if (! elf_cris_adjust_gotplt_to_got (h
, info
))
2822 /* Clear the PLT references, so no PLT will be created. */
2823 h
->root
.plt
.offset
= (bfd_vma
) -1;
2829 /* Our own version of hide_symbol, so that we can adjust a GOTPLT reloc
2830 to use a GOT entry (and create one) rather than requiring a GOTPLT
2834 elf_cris_hide_symbol (struct bfd_link_info
*info
,
2835 struct elf_link_hash_entry
*h
,
2836 bfd_boolean force_local
)
2838 elf_cris_adjust_gotplt_to_got ((struct elf_cris_link_hash_entry
*) h
, info
);
2840 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
2843 /* Adjust a symbol defined by a dynamic object and referenced by a
2844 regular object. The current definition is in some section of the
2845 dynamic object, but we're not including those sections. We have to
2846 change the definition to something the rest of the link can
2850 elf_cris_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2851 struct elf_link_hash_entry
*h
)
2853 struct elf_cris_link_hash_table
* htab
;
2856 bfd_size_type plt_entry_size
;
2858 htab
= elf_cris_hash_table (info
);
2862 dynobj
= elf_hash_table (info
)->dynobj
;
2864 /* Make sure we know what is going on here. */
2865 BFD_ASSERT (dynobj
!= NULL
2867 || h
->u
.weakdef
!= NULL
2870 && !h
->def_regular
)));
2873 = (bfd_get_mach (dynobj
) == bfd_mach_cris_v32
2874 ? PLT_ENTRY_SIZE_V32
: PLT_ENTRY_SIZE
);
2876 /* If this is a function, put it in the procedure linkage table. We
2877 will fill in the contents of the procedure linkage table later,
2878 when we know the address of the .got section. */
2879 if (h
->type
== STT_FUNC
2882 /* If we link a program (not a DSO), we'll get rid of unnecessary
2883 PLT entries; we point to the actual symbols -- even for pic
2884 relocs, because a program built with -fpic should have the same
2885 result as one built without -fpic, specifically considering weak
2887 FIXME: m68k and i386 differ here, for unclear reasons. */
2888 if (! bfd_link_pic (info
)
2891 /* This case can occur if we saw a PLT reloc in an input file,
2892 but the symbol was not defined by a dynamic object. In such
2893 a case, we don't actually need to build a procedure linkage
2894 table, and we can just do an absolute or PC reloc instead, or
2895 change a .got.plt index to a .got index for GOTPLT relocs. */
2896 BFD_ASSERT (h
->needs_plt
);
2898 h
->plt
.offset
= (bfd_vma
) -1;
2900 elf_cris_adjust_gotplt_to_got ((struct
2901 elf_cris_link_hash_entry
*) h
,
2905 /* If we had a R_CRIS_GLOB_DAT that didn't have to point to a PLT;
2906 where a pointer-equivalent symbol was unimportant (i.e. more
2907 like R_CRIS_JUMP_SLOT after symbol evaluation) we could get rid
2908 of the PLT. We can't for the executable, because the GOT
2909 entries will point to the PLT there (and be constant). */
2910 if (bfd_link_pic (info
)
2911 && !elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry
*)
2915 /* GC or folding may have rendered this entry unused. */
2916 if (h
->plt
.refcount
<= 0)
2919 h
->plt
.offset
= (bfd_vma
) -1;
2923 /* Make sure this symbol is output as a dynamic symbol. */
2924 if (h
->dynindx
== -1)
2926 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2930 s
= bfd_get_linker_section (dynobj
, ".plt");
2931 BFD_ASSERT (s
!= NULL
);
2933 /* If this is the first .plt entry, make room for the special
2936 s
->size
+= plt_entry_size
;
2938 /* If this symbol is not defined in a regular file, and we are
2939 not generating a shared library, then set the symbol to this
2940 location in the .plt. */
2941 if (!bfd_link_pic (info
)
2944 h
->root
.u
.def
.section
= s
;
2945 h
->root
.u
.def
.value
= s
->size
;
2948 /* If there's already a GOT entry, use that, not a .got.plt. A
2949 GOT field still has a reference count when we get here; it's
2950 not yet changed to an offset. We can't do this for an
2951 executable, because then the reloc associated with the PLT
2952 would get a non-PLT reloc pointing to the PLT. FIXME: Move
2953 this to elf_cris_try_fold_plt_to_got. */
2954 if (bfd_link_pic (info
) && h
->got
.refcount
> 0)
2956 h
->got
.refcount
+= h
->plt
.refcount
;
2958 /* Mark the PLT offset to use the GOT entry by setting the low
2959 bit in the plt offset; it is always a multiple of
2960 plt_entry_size (which is at least a multiple of 2). */
2961 BFD_ASSERT ((s
->size
% plt_entry_size
) == 0);
2963 /* Change the PLT refcount to an offset. */
2964 h
->plt
.offset
= s
->size
;
2966 /* By not setting gotplt_offset (i.e. it remains at 0), we signal
2967 that the got entry should be used instead. */
2968 BFD_ASSERT (((struct elf_cris_link_hash_entry
*)
2969 h
)->gotplt_offset
== 0);
2971 /* Make room for this entry. */
2972 s
->size
+= plt_entry_size
;
2977 /* No GOT reference for this symbol; prepare for an ordinary PLT. */
2978 h
->plt
.offset
= s
->size
;
2980 /* Make room for this entry. */
2981 s
->size
+= plt_entry_size
;
2983 /* We also need to make an entry in the .got.plt section, which
2984 will be placed in the .got section by the linker script. */
2985 ((struct elf_cris_link_hash_entry
*) h
)->gotplt_offset
2986 = htab
->next_gotplt_entry
;
2987 htab
->next_gotplt_entry
+= 4;
2989 s
= bfd_get_linker_section (dynobj
, ".got.plt");
2990 BFD_ASSERT (s
!= NULL
);
2993 /* We also need to make an entry in the .rela.plt section. */
2995 s
= bfd_get_linker_section (dynobj
, ".rela.plt");
2996 BFD_ASSERT (s
!= NULL
);
2997 s
->size
+= sizeof (Elf32_External_Rela
);
3002 /* Reinitialize the plt offset now that it is not used as a reference
3004 h
->plt
.offset
= (bfd_vma
) -1;
3006 /* If this is a weak symbol, and there is a real definition, the
3007 processor independent code will have arranged for us to see the
3008 real definition first, and we can just use the same value. */
3009 if (h
->u
.weakdef
!= NULL
)
3011 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3012 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3013 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3014 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3018 /* This is a reference to a symbol defined by a dynamic object which
3019 is not a function. */
3021 /* If we are creating a shared library, we must presume that the
3022 only references to the symbol are via the global offset table.
3023 For such cases we need not do anything here; the relocations will
3024 be handled correctly by relocate_section. */
3025 if (bfd_link_pic (info
))
3028 /* If there are no references to this symbol that do not use the
3029 GOT, we don't need to generate a copy reloc. */
3030 if (!h
->non_got_ref
)
3033 /* We must allocate the symbol in our .dynbss section, which will
3034 become part of the .bss section of the executable. There will be
3035 an entry for this symbol in the .dynsym section. The dynamic
3036 object will contain position independent code, so all references
3037 from the dynamic object to this symbol will go through the global
3038 offset table. The dynamic linker will use the .dynsym entry to
3039 determine the address it must put in the global offset table, so
3040 both the dynamic object and the regular object will refer to the
3041 same memory location for the variable. */
3043 s
= bfd_get_linker_section (dynobj
, ".dynbss");
3044 BFD_ASSERT (s
!= NULL
);
3046 /* We must generate a R_CRIS_COPY reloc to tell the dynamic linker to
3047 copy the initial value out of the dynamic object and into the
3048 runtime process image. We need to remember the offset into the
3049 .rela.bss section we are going to use. */
3050 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3054 srel
= bfd_get_linker_section (dynobj
, ".rela.bss");
3055 BFD_ASSERT (srel
!= NULL
);
3056 srel
->size
+= sizeof (Elf32_External_Rela
);
3060 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3063 /* Adjust our "subclass" elements for an indirect symbol. */
3066 elf_cris_copy_indirect_symbol (struct bfd_link_info
*info
,
3067 struct elf_link_hash_entry
*dir
,
3068 struct elf_link_hash_entry
*ind
)
3070 struct elf_cris_link_hash_entry
*edir
, *eind
;
3072 edir
= (struct elf_cris_link_hash_entry
*) dir
;
3073 eind
= (struct elf_cris_link_hash_entry
*) ind
;
3075 /* Only indirect symbols are replaced; we're not interested in
3076 updating any of EIND's fields for other symbols. */
3077 if (eind
->root
.root
.type
!= bfd_link_hash_indirect
)
3079 /* Still, we need to copy flags for e.g. weak definitions. */
3080 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3084 BFD_ASSERT (edir
->gotplt_offset
== 0 || eind
->gotplt_offset
== 0);
3086 #define XMOVOPZ(F, OP, Z) edir->F OP eind->F; eind->F = Z
3087 #define XMOVE(F) XMOVOPZ (F, +=, 0)
3088 if (eind
->pcrel_relocs_copied
!= NULL
)
3090 if (edir
->pcrel_relocs_copied
!= NULL
)
3092 struct elf_cris_pcrel_relocs_copied
**pp
;
3093 struct elf_cris_pcrel_relocs_copied
*p
;
3095 /* Add reloc counts against the indirect sym to the direct sym
3096 list. Merge any entries against the same section. */
3097 for (pp
= &eind
->pcrel_relocs_copied
; *pp
!= NULL
;)
3099 struct elf_cris_pcrel_relocs_copied
*q
;
3101 for (q
= edir
->pcrel_relocs_copied
; q
!= NULL
; q
= q
->next
)
3102 if (q
->section
== p
->section
)
3104 q
->count
+= p
->count
;
3111 *pp
= edir
->pcrel_relocs_copied
;
3113 XMOVOPZ (pcrel_relocs_copied
, =, NULL
);
3115 XMOVE (gotplt_refcount
);
3116 XMOVE (gotplt_offset
);
3117 XMOVE (reg_got_refcount
);
3118 XMOVE (tprel_refcount
);
3119 XMOVE (dtp_refcount
);
3123 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3126 /* Look through the relocs for a section during the first phase. */
3129 cris_elf_check_relocs (bfd
*abfd
,
3130 struct bfd_link_info
*info
,
3132 const Elf_Internal_Rela
*relocs
)
3134 struct elf_cris_link_hash_table
* htab
;
3136 Elf_Internal_Shdr
*symtab_hdr
;
3137 struct elf_link_hash_entry
**sym_hashes
;
3138 bfd_signed_vma
*local_got_refcounts
;
3139 const Elf_Internal_Rela
*rel
;
3140 const Elf_Internal_Rela
*rel_end
;
3145 if (bfd_link_relocatable (info
))
3148 htab
= elf_cris_hash_table (info
);
3152 dynobj
= elf_hash_table (info
)->dynobj
;
3153 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3154 sym_hashes
= elf_sym_hashes (abfd
);
3155 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3161 rel_end
= relocs
+ sec
->reloc_count
;
3162 for (rel
= relocs
; rel
< rel_end
; rel
++)
3164 struct elf_link_hash_entry
*h
;
3165 unsigned long r_symndx
;
3166 enum elf_cris_reloc_type r_type
;
3167 bfd_signed_vma got_element_size
= 4;
3168 unsigned long r_symndx_lgot
= INT_MAX
;
3170 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3171 if (r_symndx
< symtab_hdr
->sh_info
)
3174 r_symndx_lgot
= LGOT_REG_NDX (r_symndx
);
3178 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3179 while (h
->root
.type
== bfd_link_hash_indirect
3180 || h
->root
.type
== bfd_link_hash_warning
)
3181 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3183 /* PR15323, ref flags aren't set for references in the same
3185 h
->root
.non_ir_ref
= 1;
3188 r_type
= ELF32_R_TYPE (rel
->r_info
);
3190 /* Some relocs require linker-created sections; we need to hang them
3191 on the first input bfd we found that contained dynamic relocs. */
3194 case R_CRIS_32_DTPREL
:
3195 if ((sec
->flags
& SEC_ALLOC
) == 0)
3196 /* This'd be a .dtpreld entry in e.g. debug info. We have
3197 several different switch statements below, but none of
3198 that is needed; we need no preparations for resolving
3199 R_CRIS_32_DTPREL into a non-allocated section (debug
3200 info), so let's just move on to the next
3204 case R_CRIS_16_DTPREL
:
3205 /* The first .got.plt entry is right after the R_CRIS_DTPMOD
3206 entry at index 3. */
3207 if (htab
->dtpmod_refcount
== 0)
3208 htab
->next_gotplt_entry
+= 8;
3210 htab
->dtpmod_refcount
++;
3215 case R_CRIS_16_GOT_GD
:
3216 case R_CRIS_32_GOT_GD
:
3217 case R_CRIS_32_GOT_TPREL
:
3218 case R_CRIS_16_GOT_TPREL
:
3221 case R_CRIS_32_GOTREL
:
3222 case R_CRIS_32_PLT_GOTREL
:
3223 case R_CRIS_32_PLT_PCREL
:
3224 case R_CRIS_16_GOTPLT
:
3225 case R_CRIS_32_GOTPLT
:
3228 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
3230 /* We could handle this if we can get a handle on the
3231 output bfd in elf_cris_adjust_dynamic_symbol. Failing
3232 that, we must insist on dynobj being a specific mach. */
3233 if (bfd_get_mach (dynobj
) == bfd_mach_cris_v10_v32
)
3235 (*_bfd_error_handler
)
3236 (_("%B, section %A:\n v10/v32 compatible object %s"
3237 " must not contain a PIC relocation"),
3245 /* We may have a dynobj but no .got section, if machine-
3246 independent parts of the linker found a reason to create
3247 a dynobj. We want to create the .got section now, so we
3248 can assume it's always present whenever there's a dynobj.
3249 It's ok to call this function more than once. */
3250 if (!_bfd_elf_create_got_section (dynobj
, info
))
3253 sgot
= bfd_get_linker_section (dynobj
, ".got");
3256 if (local_got_refcounts
== NULL
)
3260 /* We use index local_got_refcounts[-1] to count all
3261 GOT-relative relocations that do not have explicit
3263 amt
= LGOT_ALLOC_NELTS_FOR (symtab_hdr
->sh_info
) + 1;
3264 amt
*= sizeof (bfd_signed_vma
);
3265 local_got_refcounts
= ((bfd_signed_vma
*) bfd_zalloc (abfd
, amt
));
3266 if (local_got_refcounts
== NULL
)
3269 local_got_refcounts
++;
3270 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3278 /* Some relocs require a global offset table (but perhaps not a
3279 specific GOT entry). */
3282 case R_CRIS_16_DTPREL
:
3283 case R_CRIS_32_DTPREL
:
3284 /* Not requesting .got.rela for an executable: the contents
3285 of the first entry is constant there. For a shared
3286 library, we need .got.rela for the R_CRIS_DTPMOD
3287 relocation at index 3. */
3288 if (!bfd_link_pic (info
))
3294 case R_CRIS_16_GOT_GD
:
3295 case R_CRIS_32_GOT_GD
:
3296 case R_CRIS_32_GOT_TPREL
:
3297 case R_CRIS_16_GOT_TPREL
:
3300 /* For R_CRIS_16_GOTPLT and R_CRIS_32_GOTPLT, we need a GOT
3301 entry only for local symbols. Unfortunately, we don't know
3302 until later on if there's a version script that forces the
3303 symbol local. We must have the .rela.got section in place
3304 before we know if the symbol looks global now, so we need
3305 to treat the reloc just like for R_CRIS_16_GOT and
3307 case R_CRIS_16_GOTPLT
:
3308 case R_CRIS_32_GOTPLT
:
3312 && (h
!= NULL
|| bfd_link_pic (info
)))
3314 srelgot
= bfd_get_linker_section (dynobj
, ".rela.got");
3315 if (srelgot
== NULL
)
3317 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
3318 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
3320 srelgot
= bfd_make_section_anyway_with_flags (dynobj
,
3324 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
3334 /* Warn and error for invalid input. */
3338 case R_CRIS_32_TPREL
:
3339 case R_CRIS_16_TPREL
:
3341 if (bfd_link_pic (info
))
3343 (*_bfd_error_handler
)
3344 (_("%B, section %A:\n relocation %s not valid"
3345 " in a shared object;"
3346 " typically an option mixup, recompile with -fPIC"),
3349 cris_elf_howto_table
[r_type
].name
);
3350 /* Don't return FALSE here; we want messages for all of
3351 these and the error behavior is ungraceful
3361 case R_CRIS_16_GOT_GD
:
3362 case R_CRIS_32_GOT_GD
:
3363 /* These are requests for tls_index entries, run-time R_CRIS_DTP. */
3364 got_element_size
= 8;
3365 r_symndx_lgot
= LGOT_DTP_NDX (r_symndx
);
3368 case R_CRIS_16_DTPREL
:
3369 case R_CRIS_32_DTPREL
:
3370 /* These two just request for the constant-index
3371 module-local tls_index-sized GOT entry, which we add
3376 case R_CRIS_32_GOT_TPREL
:
3377 case R_CRIS_16_GOT_TPREL
:
3378 r_symndx_lgot
= LGOT_TPREL_NDX (r_symndx
);
3380 /* Those relocs also require that a DSO is of type
3381 Initial Exec. Like other targets, we don't reset this
3382 flag even if the relocs are GC:ed away. */
3383 if (bfd_link_pic (info
))
3384 info
->flags
|= DF_STATIC_TLS
;
3387 /* Let's list the other assembler-generated TLS-relocs too,
3388 just to show that they're not forgotten. */
3389 case R_CRIS_16_TPREL
:
3390 case R_CRIS_32_TPREL
:
3397 case R_CRIS_16_GOTPLT
:
3398 case R_CRIS_32_GOTPLT
:
3399 /* Mark that we need a GOT entry if the PLT entry (and its GOT
3400 entry) is eliminated. We can only do this for a non-local
3404 elf_cris_hash_entry (h
)->gotplt_refcount
++;
3405 goto handle_gotplt_reloc
;
3407 /* If h is NULL then this is a local symbol, and we must make a
3408 GOT entry for it, so handle it like a GOT reloc. */
3413 case R_CRIS_16_GOT_GD
:
3414 case R_CRIS_32_GOT_GD
:
3415 case R_CRIS_32_GOT_TPREL
:
3416 case R_CRIS_16_GOT_TPREL
:
3419 /* This symbol requires a global offset table entry. */
3422 if (h
->got
.refcount
== 0)
3424 /* Make sure this symbol is output as a dynamic symbol. */
3425 if (h
->dynindx
== -1)
3427 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3432 /* Update the sum of reloc counts for this symbol. */
3439 if (elf_cris_hash_entry (h
)->reg_got_refcount
== 0)
3441 /* Allocate space in the .got section. */
3442 sgot
->size
+= got_element_size
;
3443 /* Allocate relocation space. */
3444 srelgot
->size
+= sizeof (Elf32_External_Rela
);
3446 elf_cris_hash_entry (h
)->reg_got_refcount
++;
3450 case R_CRIS_16_GOT_GD
:
3451 case R_CRIS_32_GOT_GD
:
3452 if (elf_cris_hash_entry (h
)->dtp_refcount
== 0)
3454 /* Allocate space in the .got section. */
3455 sgot
->size
+= got_element_size
;
3456 /* Allocate relocation space. */
3457 srelgot
->size
+= sizeof (Elf32_External_Rela
);
3459 elf_cris_hash_entry (h
)->dtp_refcount
++;
3463 case R_CRIS_32_GOT_TPREL
:
3464 case R_CRIS_16_GOT_TPREL
:
3465 if (elf_cris_hash_entry (h
)->tprel_refcount
== 0)
3467 /* Allocate space in the .got section. */
3468 sgot
->size
+= got_element_size
;
3469 /* Allocate relocation space. */
3470 srelgot
->size
+= sizeof (Elf32_External_Rela
);
3472 elf_cris_hash_entry (h
)->tprel_refcount
++;
3482 /* This is a global offset table entry for a local symbol. */
3483 if (local_got_refcounts
[r_symndx_lgot
] == 0)
3485 sgot
->size
+= got_element_size
;
3486 if (bfd_link_pic (info
))
3488 /* If we are generating a shared object, we need
3489 to output a R_CRIS_RELATIVE reloc so that the
3490 dynamic linker can adjust this GOT entry.
3491 Similarly for non-regular got entries. */
3492 srelgot
->size
+= sizeof (Elf32_External_Rela
);
3495 /* Update the reloc-specific count. */
3496 local_got_refcounts
[r_symndx_lgot
]++;
3498 /* This one is the sum of all the others. */
3499 local_got_refcounts
[r_symndx
]++;
3503 case R_CRIS_16_DTPREL
:
3504 case R_CRIS_32_DTPREL
:
3505 case R_CRIS_32_GOTREL
:
3506 /* This reference requires a global offset table.
3507 FIXME: The actual refcount isn't used currently; the .got
3508 section can't be removed if there were any references in the
3510 local_got_refcounts
[-1]++;
3513 handle_gotplt_reloc
:
3515 case R_CRIS_32_PLT_GOTREL
:
3516 /* This reference requires a global offset table. */
3517 local_got_refcounts
[-1]++;
3520 case R_CRIS_32_PLT_PCREL
:
3521 /* This symbol requires a procedure linkage table entry. We
3522 actually build the entry in adjust_dynamic_symbol,
3523 because this might be a case of linking PIC code which is
3524 never referenced by a dynamic object, in which case we
3525 don't need to generate a procedure linkage table entry
3528 /* Beware: if we'd check for visibility of the symbol here
3529 (and not marking the need for a PLT when non-visible), we'd
3530 get into trouble with keeping handling consistent with
3531 regards to relocs found before definition and GOTPLT
3532 handling. Eliminable PLT entries will be dealt with later
3544 /* Let's help debug shared library creation. Any of these
3545 relocs *can* be used in shared libs, but pages containing
3546 them cannot be shared, so they're not appropriate for
3547 common use. Don't warn for sections we don't care about,
3548 such as debug sections or non-constant sections. We
3549 can't help tables of (global) function pointers, for
3550 example, though they must be emitted in a (writable) data
3551 section to avoid having impure text sections. */
3552 if (bfd_link_pic (info
)
3553 && (sec
->flags
& SEC_ALLOC
) != 0
3554 && (sec
->flags
& SEC_READONLY
) != 0)
3556 /* FIXME: How do we make this optionally a warning only? */
3557 (*_bfd_error_handler
)
3558 (_("%B, section %A:\n relocation %s should not"
3559 " be used in a shared object; recompile with -fPIC"),
3562 cris_elf_howto_table
[r_type
].name
);
3565 /* We don't need to handle relocs into sections not going into
3566 the "real" output. */
3567 if ((sec
->flags
& SEC_ALLOC
) == 0)
3574 /* Make sure a plt entry is created for this symbol if it
3575 turns out to be a function defined by a dynamic object. */
3576 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3580 /* If we are creating a shared library and this is not a local
3581 symbol, we need to copy the reloc into the shared library.
3582 However when linking with -Bsymbolic and this is a global
3583 symbol which is defined in an object we are including in the
3584 link (i.e., DEF_REGULAR is set), then we can resolve the
3585 reloc directly. At this point we have not seen all the input
3586 files, so it is possible that DEF_REGULAR is not set now but
3587 will be set later (it is never cleared). In case of a weak
3588 definition, DEF_REGULAR may be cleared later by a strong
3589 definition in a shared library. We account for that
3590 possibility below by storing information in the relocs_copied
3591 field of the hash table entry. A similar situation occurs
3592 when creating shared libraries and symbol visibility changes
3593 render the symbol local. */
3595 /* No need to do anything if we're not creating a shared object. */
3596 if (! bfd_link_pic (info
))
3599 /* We may need to create a reloc section in the dynobj and made room
3603 sreloc
= _bfd_elf_make_dynamic_reloc_section
3604 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
3610 if (sec
->flags
& SEC_READONLY
)
3611 info
->flags
|= DF_TEXTREL
;
3613 sreloc
->size
+= sizeof (Elf32_External_Rela
);
3616 case R_CRIS_8_PCREL
:
3617 case R_CRIS_16_PCREL
:
3618 case R_CRIS_32_PCREL
:
3623 /* Make sure a plt entry is created for this symbol if it
3624 turns out to be a function defined by a dynamic object. */
3625 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3629 /* If we are creating a shared library and this is not a local
3630 symbol, we need to copy the reloc into the shared library.
3631 However when linking with -Bsymbolic and this is a global
3632 symbol which is defined in an object we are including in the
3633 link (i.e., DEF_REGULAR is set), then we can resolve the
3634 reloc directly. At this point we have not seen all the input
3635 files, so it is possible that DEF_REGULAR is not set now but
3636 will be set later (it is never cleared). In case of a weak
3637 definition, DEF_REGULAR may be cleared later by a strong
3638 definition in a shared library. We account for that
3639 possibility below by storing information in the relocs_copied
3640 field of the hash table entry. A similar situation occurs
3641 when creating shared libraries and symbol visibility changes
3642 render the symbol local. */
3644 /* No need to do anything if we're not creating a shared object. */
3645 if (! bfd_link_pic (info
))
3648 /* We don't need to handle relocs into sections not going into
3649 the "real" output. */
3650 if ((sec
->flags
& SEC_ALLOC
) == 0)
3653 /* If the symbol is local, then we know already we can
3654 eliminate the reloc. */
3655 if (h
== NULL
|| ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3658 /* If this is with -Bsymbolic and the symbol isn't weak, and
3659 is defined by an ordinary object (the ones we include in
3660 this shared library) then we can also eliminate the
3661 reloc. See comment above for more eliminable cases which
3662 we can't identify at this time. */
3663 if (SYMBOLIC_BIND (info
, h
)
3664 && h
->root
.type
!= bfd_link_hash_defweak
3668 /* We may need to create a reloc section in the dynobj and made room
3672 sreloc
= _bfd_elf_make_dynamic_reloc_section
3673 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
3679 sreloc
->size
+= sizeof (Elf32_External_Rela
);
3681 /* We count the number of PC relative relocations we have
3682 entered for this symbol, so that we can discard them
3683 again if the symbol is later defined by a regular object.
3684 We know that h is really a pointer to an
3685 elf_cris_link_hash_entry. */
3687 struct elf_cris_link_hash_entry
*eh
;
3688 struct elf_cris_pcrel_relocs_copied
*p
;
3690 eh
= elf_cris_hash_entry (h
);
3692 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
3693 if (p
->section
== sec
)
3698 p
= ((struct elf_cris_pcrel_relocs_copied
*)
3699 bfd_alloc (dynobj
, (bfd_size_type
) sizeof *p
));
3702 p
->next
= eh
->pcrel_relocs_copied
;
3703 eh
->pcrel_relocs_copied
= p
;
3713 /* This relocation describes the C++ object vtable hierarchy.
3714 Reconstruct it for later use during GC. */
3715 case R_CRIS_GNU_VTINHERIT
:
3716 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3720 /* This relocation describes which C++ vtable entries are actually
3721 used. Record for later use during GC. */
3722 case R_CRIS_GNU_VTENTRY
:
3723 BFD_ASSERT (h
!= NULL
);
3725 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3729 case R_CRIS_16_TPREL
:
3730 case R_CRIS_32_TPREL
:
3731 /* Already warned above, when necessary. */
3735 /* Other relocs do not appear here. */
3736 bfd_set_error (bfd_error_bad_value
);
3744 /* Set the sizes of the dynamic sections. */
3747 elf_cris_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3748 struct bfd_link_info
*info
)
3750 struct elf_cris_link_hash_table
* htab
;
3756 htab
= elf_cris_hash_table (info
);
3760 dynobj
= elf_hash_table (info
)->dynobj
;
3761 BFD_ASSERT (dynobj
!= NULL
);
3763 if (elf_hash_table (info
)->dynamic_sections_created
)
3765 /* Set the contents of the .interp section to the interpreter. */
3766 if (bfd_link_executable (info
) && !info
->nointerp
)
3768 s
= bfd_get_linker_section (dynobj
, ".interp");
3769 BFD_ASSERT (s
!= NULL
);
3770 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3771 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3776 /* Adjust all expected GOTPLT uses to use a GOT entry instead. */
3777 elf_cris_link_hash_traverse (htab
, elf_cris_adjust_gotplt_to_got
,
3780 /* We may have created entries in the .rela.got section.
3781 However, if we are not creating the dynamic sections, we will
3782 not actually use these entries. Reset the size of .rela.got,
3783 which will cause it to get stripped from the output file
3785 s
= bfd_get_linker_section (dynobj
, ".rela.got");
3790 /* If this is a -Bsymbolic shared link, then we need to discard all PC
3791 relative relocs against symbols defined in a regular object. We
3792 allocated space for them in the check_relocs routine, but we will not
3793 fill them in in the relocate_section routine. We also discard space
3794 for relocs that have become for local symbols due to symbol
3795 visibility changes. For programs, we discard space for relocs for
3796 symbols not referenced by any dynamic object. */
3797 if (bfd_link_pic (info
))
3798 elf_cris_link_hash_traverse (htab
,
3799 elf_cris_discard_excess_dso_dynamics
,
3802 elf_cris_link_hash_traverse (htab
,
3803 elf_cris_discard_excess_program_dynamics
,
3806 /* The check_relocs and adjust_dynamic_symbol entry points have
3807 determined the sizes of the various dynamic sections. Allocate
3811 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3815 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3818 /* It's OK to base decisions on the section name, because none
3819 of the dynobj section names depend upon the input files. */
3820 name
= bfd_get_section_name (dynobj
, s
);
3822 if (strcmp (name
, ".plt") == 0)
3824 /* Remember whether there is a PLT. */
3827 else if (strcmp (name
, ".got.plt") == 0)
3829 /* The .got.plt contains the .got header as well as the
3830 actual .got.plt contents. The .got header may contain a
3831 R_CRIS_DTPMOD entry at index 3. */
3832 s
->size
+= htab
->dtpmod_refcount
!= 0
3835 else if (CONST_STRNEQ (name
, ".rela"))
3837 if (strcmp (name
, ".rela.got") == 0
3838 && htab
->dtpmod_refcount
!= 0
3839 && bfd_link_pic (info
))
3840 s
->size
+= sizeof (Elf32_External_Rela
);
3844 /* Remember whether there are any reloc sections other
3846 if (strcmp (name
, ".rela.plt") != 0)
3849 /* We use the reloc_count field as a counter if we need
3850 to copy relocs into the output file. */
3854 else if (! CONST_STRNEQ (name
, ".got")
3855 && strcmp (name
, ".dynbss") != 0)
3857 /* It's not one of our sections, so don't allocate space. */
3863 /* If we don't need this section, strip it from the
3864 output file. This is mostly to handle .rela.bss and
3865 .rela.plt. We must create both sections in
3866 create_dynamic_sections, because they must be created
3867 before the linker maps input sections to output
3868 sections. The linker does that before
3869 adjust_dynamic_symbol is called, and it is that
3870 function which decides whether anything needs to go
3871 into these sections. */
3872 s
->flags
|= SEC_EXCLUDE
;
3876 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3879 /* Allocate memory for the section contents. We use bfd_zalloc here
3880 in case unused entries are not reclaimed before the section's
3881 contents are written out. This should not happen, but this way
3882 if it does, we will not write out garbage. For reloc sections,
3883 this will make entries have the type R_CRIS_NONE. */
3884 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3885 if (s
->contents
== NULL
)
3889 if (elf_hash_table (info
)->dynamic_sections_created
)
3891 /* Add some entries to the .dynamic section. We fill in the
3892 values later, in elf_cris_finish_dynamic_sections, but we
3893 must add the entries now so that we get the correct size for
3894 the .dynamic section. The DT_DEBUG entry is filled in by the
3895 dynamic linker and used by the debugger. */
3896 #define add_dynamic_entry(TAG, VAL) \
3897 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3899 if (!bfd_link_pic (info
))
3901 if (!add_dynamic_entry (DT_DEBUG
, 0))
3907 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3908 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3909 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3910 || !add_dynamic_entry (DT_JMPREL
, 0))
3916 if (!add_dynamic_entry (DT_RELA
, 0)
3917 || !add_dynamic_entry (DT_RELASZ
, 0)
3918 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3922 if ((info
->flags
& DF_TEXTREL
) != 0)
3924 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3926 info
->flags
|= DF_TEXTREL
;
3929 #undef add_dynamic_entry
3934 /* This function is called via elf_cris_link_hash_traverse if we are
3935 creating a shared object. In the -Bsymbolic case, it discards the
3936 space allocated to copy PC relative relocs against symbols which
3937 are defined in regular objects. For the normal non-symbolic case,
3938 we also discard space for relocs that have become local due to
3939 symbol visibility changes. We allocated space for them in the
3940 check_relocs routine, but we won't fill them in in the
3941 relocate_section routine. */
3944 elf_cris_discard_excess_dso_dynamics (struct elf_cris_link_hash_entry
*h
,
3947 struct elf_cris_pcrel_relocs_copied
*s
;
3948 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3950 /* If a symbol has been forced local or we have found a regular
3951 definition for the symbolic link case, then we won't be needing
3953 if (h
->root
.def_regular
3954 && (h
->root
.forced_local
3955 || SYMBOLIC_BIND (info
, &h
->root
)))
3957 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
3960 = _bfd_elf_get_dynamic_reloc_section (elf_hash_table (info
)
3964 sreloc
->size
-= s
->count
* sizeof (Elf32_External_Rela
);
3969 /* If we have accounted for PC-relative relocs for read-only
3970 sections, now is the time to warn for them. We can't do it in
3971 cris_elf_check_relocs, because we don't know the status of all
3972 symbols at that time (and it's common to force symbols local
3975 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
3976 if ((s
->section
->flags
& SEC_READONLY
) != 0)
3978 /* FIXME: How do we make this optionally a warning only? */
3979 (*_bfd_error_handler
)
3980 (_("%B, section `%A', to symbol `%s':\n"
3981 " relocation %s should not be used"
3982 " in a shared object; recompile with -fPIC"),
3985 h
->root
.root
.root
.string
,
3986 cris_elf_howto_table
[s
->r_type
].name
);
3988 info
->flags
|= DF_TEXTREL
;
3994 /* This function is called via elf_cris_link_hash_traverse if we are *not*
3995 creating a shared object. We discard space for relocs for symbols put
3996 in the .got, but which we found we do not have to resolve at run-time. */
3999 elf_cris_discard_excess_program_dynamics (struct elf_cris_link_hash_entry
*h
,
4002 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4004 /* If we're not creating a shared library and have a symbol which is
4005 referred to by .got references, but the symbol is defined locally,
4006 (or rather, not defined by a DSO) then lose the reloc for the .got
4007 (don't allocate room for it). Likewise for relocs for something
4008 for which we create a PLT. */
4009 if (!h
->root
.def_dynamic
4010 || h
->root
.plt
.refcount
> 0)
4012 if (h
->reg_got_refcount
> 0
4013 /* The size of this section is only valid and in sync with the
4014 various reference counts if we do dynamic; don't decrement it
4016 && elf_hash_table (info
)->dynamic_sections_created
)
4018 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
4021 BFD_ASSERT (dynobj
!= NULL
);
4023 srelgot
= bfd_get_linker_section (dynobj
, ".rela.got");
4025 BFD_ASSERT (srelgot
!= NULL
);
4027 srelgot
->size
-= sizeof (Elf32_External_Rela
);
4030 /* If the locally-defined symbol isn't used by a DSO, then we don't
4031 have to export it as a dynamic symbol. This was already done for
4032 functions; doing this for all symbols would presumably not
4033 introduce new problems. Of course we don't do this if we're
4034 exporting all dynamic symbols, or all data symbols, regardless of
4035 them being referenced or not. */
4036 if (! (info
->export_dynamic
4037 || (h
->root
.type
!= STT_FUNC
&& info
->dynamic_data
))
4038 && h
->root
.dynindx
!= -1
4039 && !h
->root
.def_dynamic
4040 && !h
->root
.ref_dynamic
)
4042 h
->root
.dynindx
= -1;
4043 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4044 h
->root
.dynstr_index
);
4051 /* Reject a file depending on presence and expectation of prefixed
4052 underscores on symbols. */
4055 cris_elf_object_p (bfd
*abfd
)
4057 if (! cris_elf_set_mach_from_flags (abfd
, elf_elfheader (abfd
)->e_flags
))
4060 if ((elf_elfheader (abfd
)->e_flags
& EF_CRIS_UNDERSCORE
))
4061 return (bfd_get_symbol_leading_char (abfd
) == '_');
4063 return (bfd_get_symbol_leading_char (abfd
) == 0);
4066 /* Mark presence or absence of leading underscore. Set machine type
4067 flags from mach type. */
4070 cris_elf_final_write_processing (bfd
*abfd
,
4071 bfd_boolean linker ATTRIBUTE_UNUSED
)
4073 unsigned long e_flags
= elf_elfheader (abfd
)->e_flags
;
4075 e_flags
&= ~EF_CRIS_UNDERSCORE
;
4076 if (bfd_get_symbol_leading_char (abfd
) == '_')
4077 e_flags
|= EF_CRIS_UNDERSCORE
;
4079 switch (bfd_get_mach (abfd
))
4081 case bfd_mach_cris_v0_v10
:
4082 e_flags
|= EF_CRIS_VARIANT_ANY_V0_V10
;
4085 case bfd_mach_cris_v10_v32
:
4086 e_flags
|= EF_CRIS_VARIANT_COMMON_V10_V32
;
4089 case bfd_mach_cris_v32
:
4090 e_flags
|= EF_CRIS_VARIANT_V32
;
4094 _bfd_abort (__FILE__
, __LINE__
,
4095 _("Unexpected machine number"));
4098 elf_elfheader (abfd
)->e_flags
= e_flags
;
4101 /* Set the mach type from e_flags value. */
4104 cris_elf_set_mach_from_flags (bfd
*abfd
,
4105 unsigned long flags
)
4107 switch (flags
& EF_CRIS_VARIANT_MASK
)
4109 case EF_CRIS_VARIANT_ANY_V0_V10
:
4110 bfd_default_set_arch_mach (abfd
, bfd_arch_cris
, bfd_mach_cris_v0_v10
);
4113 case EF_CRIS_VARIANT_V32
:
4114 bfd_default_set_arch_mach (abfd
, bfd_arch_cris
, bfd_mach_cris_v32
);
4117 case EF_CRIS_VARIANT_COMMON_V10_V32
:
4118 bfd_default_set_arch_mach (abfd
, bfd_arch_cris
, bfd_mach_cris_v10_v32
);
4122 /* Since we don't recognize them, we obviously can't support them
4123 with this code; we'd have to require that all future handling
4124 would be optional. */
4125 bfd_set_error (bfd_error_wrong_format
);
4132 /* Display the flags field. */
4135 cris_elf_print_private_bfd_data (bfd
*abfd
, void * ptr
)
4137 FILE *file
= (FILE *) ptr
;
4139 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4141 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4143 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
4145 if (elf_elfheader (abfd
)->e_flags
& EF_CRIS_UNDERSCORE
)
4146 fprintf (file
, _(" [symbols have a _ prefix]"));
4147 if ((elf_elfheader (abfd
)->e_flags
& EF_CRIS_VARIANT_MASK
)
4148 == EF_CRIS_VARIANT_COMMON_V10_V32
)
4149 fprintf (file
, _(" [v10 and v32]"));
4150 if ((elf_elfheader (abfd
)->e_flags
& EF_CRIS_VARIANT_MASK
)
4151 == EF_CRIS_VARIANT_V32
)
4152 fprintf (file
, _(" [v32]"));
4158 /* Don't mix files with and without a leading underscore. */
4161 cris_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4165 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
4168 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4169 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4172 imach
= bfd_get_mach (ibfd
);
4174 if (! elf_flags_init (obfd
))
4176 /* This happens when ld starts out with a 'blank' output file. */
4177 elf_flags_init (obfd
) = TRUE
;
4179 /* We ignore the linker-set mach, and instead set it according to
4180 the first input file. This would also happen if we could
4181 somehow filter out the OUTPUT_ARCH () setting from elf.sc.
4182 This allows us to keep the same linker config across
4183 cris(v0..v10) and crisv32. The drawback is that we can't force
4184 the output type, which might be a sane thing to do for a
4185 v10+v32 compatibility object. */
4186 if (! bfd_set_arch_mach (obfd
, bfd_arch_cris
, imach
))
4190 if (bfd_get_symbol_leading_char (ibfd
)
4191 != bfd_get_symbol_leading_char (obfd
))
4193 (*_bfd_error_handler
)
4194 (bfd_get_symbol_leading_char (ibfd
) == '_'
4195 ? _("%B: uses _-prefixed symbols, but writing file with non-prefixed symbols")
4196 : _("%B: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
4198 bfd_set_error (bfd_error_bad_value
);
4202 omach
= bfd_get_mach (obfd
);
4206 /* We can get an incompatible combination only if either is
4207 bfd_mach_cris_v32, and the other one isn't compatible. */
4208 if ((imach
== bfd_mach_cris_v32
4209 && omach
!= bfd_mach_cris_v10_v32
)
4210 || (omach
== bfd_mach_cris_v32
4211 && imach
!= bfd_mach_cris_v10_v32
))
4213 (*_bfd_error_handler
)
4214 ((imach
== bfd_mach_cris_v32
)
4215 ? _("%B contains CRIS v32 code, incompatible"
4216 " with previous objects")
4217 : _("%B contains non-CRIS-v32 code, incompatible"
4218 " with previous objects"),
4220 bfd_set_error (bfd_error_bad_value
);
4224 /* We don't have to check the case where the input is compatible
4225 with v10 and v32, because the output is already known to be set
4226 to the other (compatible) mach. */
4227 if (omach
== bfd_mach_cris_v10_v32
4228 && ! bfd_set_arch_mach (obfd
, bfd_arch_cris
, imach
))
4235 /* Do side-effects of e_flags copying to obfd. */
4238 cris_elf_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4240 /* Call the base function. */
4241 if (!_bfd_elf_copy_private_bfd_data (ibfd
, obfd
))
4244 /* If output is big-endian for some obscure reason, stop here. */
4245 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == FALSE
)
4248 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4249 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4252 /* Do what we really came here for. */
4253 return bfd_set_arch_mach (obfd
, bfd_arch_cris
, bfd_get_mach (ibfd
));
4256 static enum elf_reloc_type_class
4257 elf_cris_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4258 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4259 const Elf_Internal_Rela
*rela
)
4261 enum elf_cris_reloc_type r_type
= ELF32_R_TYPE (rela
->r_info
);
4264 case R_CRIS_RELATIVE
:
4265 return reloc_class_relative
;
4266 case R_CRIS_JUMP_SLOT
:
4267 return reloc_class_plt
;
4269 return reloc_class_copy
;
4271 return reloc_class_normal
;
4275 /* The elf_backend_got_elt_size worker. For one symbol, we can have up to
4276 two GOT entries from three types with two different sizes. We handle
4277 it as a single entry, so we can use the regular offset-calculation
4281 elf_cris_got_elt_size (bfd
*abfd ATTRIBUTE_UNUSED
,
4282 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4283 struct elf_link_hash_entry
*hr
,
4285 unsigned long symndx
)
4287 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) hr
;
4290 /* We may have one regular GOT entry or up to two TLS GOT
4294 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4295 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (ibfd
);
4297 BFD_ASSERT (local_got_refcounts
!= NULL
);
4299 if (local_got_refcounts
[LGOT_REG_NDX (symndx
)] > 0)
4301 /* We can't have a variable referred to both as a regular
4302 variable and through TLS relocs. */
4303 BFD_ASSERT (local_got_refcounts
[LGOT_DTP_NDX (symndx
)] == 0
4304 && local_got_refcounts
[LGOT_TPREL_NDX (symndx
)] == 0);
4308 if (local_got_refcounts
[LGOT_DTP_NDX (symndx
)] > 0)
4311 if (local_got_refcounts
[LGOT_TPREL_NDX (symndx
)] > 0)
4316 struct elf_cris_link_hash_entry
*hh
= elf_cris_hash_entry (h
);
4317 if (hh
->reg_got_refcount
> 0)
4319 /* The actual error-on-input is emitted elsewhere. */
4320 BFD_ASSERT (hh
->dtp_refcount
== 0 && hh
->tprel_refcount
== 0);
4324 if (hh
->dtp_refcount
> 0)
4327 if (hh
->tprel_refcount
> 0)
4331 /* We're only called when h->got.refcount is non-zero, so we must
4332 have a non-zero size. */
4333 BFD_ASSERT (eltsiz
!= 0);
4337 #define ELF_ARCH bfd_arch_cris
4338 #define ELF_TARGET_ID CRIS_ELF_DATA
4339 #define ELF_MACHINE_CODE EM_CRIS
4340 #define ELF_MAXPAGESIZE 0x2000
4342 #define TARGET_LITTLE_SYM cris_elf32_vec
4343 #define TARGET_LITTLE_NAME "elf32-cris"
4344 #define elf_symbol_leading_char 0
4346 #define elf_info_to_howto_rel NULL
4347 #define elf_info_to_howto cris_info_to_howto_rela
4348 #define elf_backend_relocate_section cris_elf_relocate_section
4349 #define elf_backend_gc_mark_hook cris_elf_gc_mark_hook
4350 #define elf_backend_gc_sweep_hook cris_elf_gc_sweep_hook
4351 #define elf_backend_plt_sym_val cris_elf_plt_sym_val
4352 #define elf_backend_check_relocs cris_elf_check_relocs
4353 #define elf_backend_grok_prstatus cris_elf_grok_prstatus
4354 #define elf_backend_grok_psinfo cris_elf_grok_psinfo
4356 #define elf_backend_can_gc_sections 1
4357 #define elf_backend_can_refcount 1
4359 #define elf_backend_object_p cris_elf_object_p
4360 #define elf_backend_final_write_processing \
4361 cris_elf_final_write_processing
4362 #define bfd_elf32_bfd_print_private_bfd_data \
4363 cris_elf_print_private_bfd_data
4364 #define bfd_elf32_bfd_merge_private_bfd_data \
4365 cris_elf_merge_private_bfd_data
4366 #define bfd_elf32_bfd_copy_private_bfd_data \
4367 cris_elf_copy_private_bfd_data
4369 #define bfd_elf32_bfd_reloc_type_lookup cris_reloc_type_lookup
4370 #define bfd_elf32_bfd_reloc_name_lookup cris_reloc_name_lookup
4372 #define bfd_elf32_bfd_link_hash_table_create \
4373 elf_cris_link_hash_table_create
4374 #define elf_backend_adjust_dynamic_symbol \
4375 elf_cris_adjust_dynamic_symbol
4376 #define elf_backend_copy_indirect_symbol \
4377 elf_cris_copy_indirect_symbol
4378 #define elf_backend_size_dynamic_sections \
4379 elf_cris_size_dynamic_sections
4380 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4381 #define elf_backend_finish_dynamic_symbol \
4382 elf_cris_finish_dynamic_symbol
4383 #define elf_backend_finish_dynamic_sections \
4384 elf_cris_finish_dynamic_sections
4385 #define elf_backend_create_dynamic_sections \
4386 _bfd_elf_create_dynamic_sections
4387 #define bfd_elf32_bfd_final_link \
4388 bfd_elf_gc_common_final_link
4389 #define elf_backend_hide_symbol elf_cris_hide_symbol
4390 #define elf_backend_reloc_type_class elf_cris_reloc_type_class
4392 #define elf_backend_want_got_plt 1
4393 #define elf_backend_plt_readonly 1
4394 #define elf_backend_want_plt_sym 0
4395 #define elf_backend_got_header_size 12
4396 #define elf_backend_got_elt_size elf_cris_got_elt_size
4398 /* Later, we my want to optimize RELA entries into REL entries for dynamic
4399 linking and libraries (if it's a win of any significance). Until then,
4400 take the easy route. */
4401 #define elf_backend_may_use_rel_p 0
4402 #define elf_backend_may_use_rela_p 1
4403 #define elf_backend_rela_normal 1
4405 #include "elf32-target.h"
4407 #undef TARGET_LITTLE_SYM
4408 #undef TARGET_LITTLE_NAME
4409 #undef elf_symbol_leading_char
4411 #define TARGET_LITTLE_SYM cris_elf32_us_vec
4412 #define TARGET_LITTLE_NAME "elf32-us-cris"
4413 #define elf_symbol_leading_char '_'
4415 #define elf32_bed elf32_us_cris_bed
4417 #include "elf32-target.h"