* elf32-arm.h (elf32_arm_final_link_relocate): Don't copy STN_UNDEF
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
CommitLineData
06c15ad7 1/* CRIS-specific support for 32-bit ELF.
915e5146 2 Copyright 2000, 2001 Free Software Foundation, Inc.
06c15ad7
HPN
3 Contributed by Axis Communications AB.
4 Written by Hans-Peter Nilsson, based on elf32-fr30.c
915e5146 5 PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
06c15ad7
HPN
6
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23#include "bfd.h"
24#include "sysdep.h"
25#include "libbfd.h"
26#include "elf-bfd.h"
27#include "elf/cris.h"
28
29/* Forward declarations. */
30static reloc_howto_type * cris_reloc_type_lookup
31 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
32
a7c10850 33static void cris_info_to_howto_rela
06c15ad7
HPN
34 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
35
72209a1f
HPN
36static boolean cris_elf_grok_prstatus
37 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
38
39static boolean cris_elf_grok_psinfo
40 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
41
a7c10850 42static boolean cris_elf_relocate_section
06c15ad7
HPN
43 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
44 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
45
46static bfd_reloc_status_type cris_final_link_relocate
47 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
48 Elf_Internal_Rela *, bfd_vma));
49
50static boolean cris_elf_gc_sweep_hook
51 PARAMS ((bfd *, struct bfd_link_info *, asection *,
52 const Elf_Internal_Rela *));
53
54static asection * cris_elf_gc_mark_hook
55 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
56 struct elf_link_hash_entry *, Elf_Internal_Sym *));
57
4da81684
HPN
58static boolean cris_elf_object_p PARAMS ((bfd *));
59
60static void cris_elf_final_write_processing PARAMS ((bfd *, boolean));
61
62static boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
63
64static boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
65
915e5146 66struct elf_cris_link_hash_entry;
4d96d128
HPN
67static boolean elf_cris_discard_excess_dso_dynamics
68 PARAMS ((struct elf_cris_link_hash_entry *, PTR));
69static boolean elf_cris_discard_excess_program_dynamics
915e5146
HPN
70 PARAMS ((struct elf_cris_link_hash_entry *, PTR));
71static boolean elf_cris_adjust_gotplt_to_got
72 PARAMS ((struct elf_cris_link_hash_entry *, PTR));
73static boolean elf_cris_try_fold_plt_to_got
74 PARAMS ((struct elf_cris_link_hash_entry *, PTR));
75static struct bfd_hash_entry *elf_cris_link_hash_newfunc
76 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
77static struct bfd_link_hash_table *elf_cris_link_hash_table_create
78 PARAMS ((bfd *));
79static boolean elf_cris_adjust_dynamic_symbol
80 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
99c79b2e
AJ
81static boolean cris_elf_check_relocs
82 PARAMS ((bfd *, struct bfd_link_info *, asection *,
83 const Elf_Internal_Rela *));
84
915e5146
HPN
85static boolean elf_cris_size_dynamic_sections
86 PARAMS ((bfd *, struct bfd_link_info *));
87static boolean elf_cris_finish_dynamic_symbol
88 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
89 Elf_Internal_Sym *));
90static boolean elf_cris_finish_dynamic_sections
91 PARAMS ((bfd *, struct bfd_link_info *));
92static void elf_cris_hide_symbol
93 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
99e4ae17 94static enum elf_reloc_type_class elf_cris_reloc_type_class
f51e552e 95 PARAMS ((const Elf_Internal_Rela *));
915e5146 96
06c15ad7
HPN
97static reloc_howto_type cris_elf_howto_table [] =
98{
99 /* This reloc does nothing. */
100 HOWTO (R_CRIS_NONE, /* type */
101 0, /* rightshift */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
103 32, /* bitsize */
104 false, /* pc_relative */
105 0, /* bitpos */
106 complain_overflow_bitfield, /* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_CRIS_NONE", /* name */
109 false, /* partial_inplace */
110 0, /* src_mask */
111 0, /* dst_mask */
112 false), /* pcrel_offset */
113
114 /* An 8 bit absolute relocation. */
115 HOWTO (R_CRIS_8, /* type */
116 0, /* rightshift */
117 0, /* size (0 = byte, 1 = short, 2 = long) */
118 8, /* bitsize */
119 false, /* pc_relative */
120 0, /* bitpos */
121 complain_overflow_bitfield, /* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_CRIS_8", /* name */
124 false, /* partial_inplace */
125 0x0000, /* src_mask */
126 0x00ff, /* dst_mask */
127 false), /* pcrel_offset */
128
129 /* A 16 bit absolute relocation. */
130 HOWTO (R_CRIS_16, /* type */
131 0, /* rightshift */
132 1, /* size (0 = byte, 1 = short, 2 = long) */
133 16, /* bitsize */
134 false, /* pc_relative */
135 0, /* bitpos */
136 complain_overflow_bitfield, /* complain_on_overflow */
137 bfd_elf_generic_reloc, /* special_function */
138 "R_CRIS_16", /* name */
139 false, /* partial_inplace */
140 0x00000000, /* src_mask */
141 0x0000ffff, /* dst_mask */
142 false), /* pcrel_offset */
143
144 /* A 32 bit absolute relocation. */
145 HOWTO (R_CRIS_32, /* type */
146 0, /* rightshift */
147 2, /* size (0 = byte, 1 = short, 2 = long) */
148 32, /* bitsize */
149 false, /* pc_relative */
150 0, /* bitpos */
151 complain_overflow_bitfield, /* complain_on_overflow */
152 bfd_elf_generic_reloc, /* special_function */
153 "R_CRIS_32", /* name */
154 false, /* partial_inplace */
155 0x00000000, /* src_mask */
156 0xffffffff, /* dst_mask */
157 false), /* pcrel_offset */
158
915e5146 159 /* An 8 bit PC-relative relocation. */
06c15ad7
HPN
160 HOWTO (R_CRIS_8_PCREL, /* type */
161 0, /* rightshift */
162 0, /* size (0 = byte, 1 = short, 2 = long) */
163 8, /* bitsize */
164 true, /* pc_relative */
165 0, /* bitpos */
166 complain_overflow_bitfield, /* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_CRIS_8_PCREL", /* name */
169 false, /* partial_inplace */
170 0x0000, /* src_mask */
171 0x00ff, /* dst_mask */
915e5146 172 true), /* pcrel_offset */
06c15ad7 173
915e5146 174 /* A 16 bit PC-relative relocation. */
06c15ad7
HPN
175 HOWTO (R_CRIS_16_PCREL, /* type */
176 0, /* rightshift */
177 1, /* size (0 = byte, 1 = short, 2 = long) */
178 16, /* bitsize */
179 true, /* pc_relative */
180 0, /* bitpos */
181 complain_overflow_bitfield, /* complain_on_overflow */
182 bfd_elf_generic_reloc, /* special_function */
183 "R_CRIS_16", /* name */
184 false, /* partial_inplace */
185 0x00000000, /* src_mask */
186 0x0000ffff, /* dst_mask */
915e5146 187 true), /* pcrel_offset */
06c15ad7 188
915e5146 189 /* A 32 bit PC-relative relocation. */
06c15ad7
HPN
190 HOWTO (R_CRIS_32_PCREL, /* type */
191 0, /* rightshift */
192 2, /* size (0 = byte, 1 = short, 2 = long) */
193 32, /* bitsize */
194 true, /* pc_relative */
195 0, /* bitpos */
196 complain_overflow_bitfield, /* complain_on_overflow */
197 bfd_elf_generic_reloc, /* special_function */
198 "R_CRIS_32", /* name */
199 false, /* partial_inplace */
200 0x00000000, /* src_mask */
201 0xffffffff, /* dst_mask */
915e5146 202 true), /* pcrel_offset */
06c15ad7 203
915e5146
HPN
204 /* GNU extension to record C++ vtable hierarchy. */
205 HOWTO (R_CRIS_GNU_VTINHERIT, /* type */
06c15ad7
HPN
206 0, /* rightshift */
207 2, /* size (0 = byte, 1 = short, 2 = long) */
208 0, /* bitsize */
209 false, /* pc_relative */
210 0, /* bitpos */
211 complain_overflow_dont, /* complain_on_overflow */
212 NULL, /* special_function */
213 "R_CRIS_GNU_VTINHERIT", /* name */
214 false, /* partial_inplace */
215 0, /* src_mask */
216 0, /* dst_mask */
217 false), /* pcrel_offset */
218
915e5146
HPN
219 /* GNU extension to record C++ vtable member usage. */
220 HOWTO (R_CRIS_GNU_VTENTRY, /* type */
06c15ad7
HPN
221 0, /* rightshift */
222 2, /* size (0 = byte, 1 = short, 2 = long) */
223 0, /* bitsize */
224 false, /* pc_relative */
225 0, /* bitpos */
226 complain_overflow_dont, /* complain_on_overflow */
227 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
228 "R_CRIS_GNU_VTENTRY", /* name */
229 false, /* partial_inplace */
230 0, /* src_mask */
231 0, /* dst_mask */
915e5146
HPN
232 false), /* pcrel_offset */
233
234 /* This is used only by the dynamic linker. The symbol should exist
235 both in the object being run and in some shared library. The
236 dynamic linker copies the data addressed by the symbol from the
237 shared library into the object, because the object being
238 run has to have the data at some particular address. */
239 HOWTO (R_CRIS_COPY, /* type */
240 0, /* rightshift */
241 2, /* size (0 = byte, 1 = short, 2 = long) */
242 32, /* bitsize */
243 false, /* pc_relative */
244 0, /* bitpos */
245 complain_overflow_bitfield, /* complain_on_overflow */
246 bfd_elf_generic_reloc, /* special_function */
247 "R_CRIS_COPY", /* name */
248 false, /* partial_inplace */
249 0, /* src_mask */
250 0, /* dst_mask */
251 false), /* pcrel_offset */
252
253 /* Like R_CRIS_32, but used when setting global offset table entries. */
254 HOWTO (R_CRIS_GLOB_DAT, /* type */
255 0, /* rightshift */
256 2, /* size (0 = byte, 1 = short, 2 = long) */
257 32, /* bitsize */
258 false, /* pc_relative */
259 0, /* bitpos */
260 complain_overflow_bitfield, /* complain_on_overflow */
261 bfd_elf_generic_reloc, /* special_function */
262 "R_CRIS_GLOB_DAT", /* name */
263 false, /* partial_inplace */
264 0, /* src_mask */
265 0xffffffff, /* dst_mask */
266 false), /* pcrel_offset */
267
268 /* Marks a procedure linkage table entry for a symbol. */
269 HOWTO (R_CRIS_JUMP_SLOT, /* type */
270 0, /* rightshift */
271 2, /* size (0 = byte, 1 = short, 2 = long) */
272 32, /* bitsize */
273 false, /* pc_relative */
274 0, /* bitpos */
275 complain_overflow_bitfield, /* complain_on_overflow */
276 bfd_elf_generic_reloc, /* special_function */
277 "R_CRIS_JUMP_SLOT", /* name */
278 false, /* partial_inplace */
279 0, /* src_mask */
280 0, /* dst_mask */
281 false), /* pcrel_offset */
282
283 /* Used only by the dynamic linker. When the object is run, this
284 longword is set to the load address of the object, plus the
285 addend. */
286 HOWTO (R_CRIS_RELATIVE, /* type */
287 0, /* rightshift */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
289 32, /* bitsize */
290 false, /* pc_relative */
291 0, /* bitpos */
292 complain_overflow_bitfield, /* complain_on_overflow */
293 bfd_elf_generic_reloc, /* special_function */
294 "R_CRIS_RELATIVE", /* name */
295 false, /* partial_inplace */
296 0, /* src_mask */
297 0xffffffff, /* dst_mask */
298 false), /* pcrel_offset */
299
300 /* Like R_CRIS_32, but referring to the GOT table entry for the symbol. */
301 HOWTO (R_CRIS_16_GOT, /* type */
302 0, /* rightshift */
303 1, /* size (0 = byte, 1 = short, 2 = long) */
304 16, /* bitsize */
305 false, /* pc_relative */
306 0, /* bitpos */
307 complain_overflow_bitfield, /* complain_on_overflow */
308 bfd_elf_generic_reloc, /* special_function */
309 "R_CRIS_16_GOT", /* name */
310 false, /* partial_inplace */
311 0, /* src_mask */
312 0xffff, /* dst_mask */
313 false), /* pcrel_offset */
314
315 HOWTO (R_CRIS_32_GOT, /* type */
316 0, /* rightshift */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
318 32, /* bitsize */
319 false, /* pc_relative */
320 0, /* bitpos */
321 complain_overflow_bitfield, /* complain_on_overflow */
322 bfd_elf_generic_reloc, /* special_function */
323 "R_CRIS_32_GOT", /* name */
324 false, /* partial_inplace */
325 0, /* src_mask */
326 0xffffffff, /* dst_mask */
327 false), /* pcrel_offset */
328
329 /* Like R_CRIS_32_GOT, but referring to (and requesting a) PLT part of
330 the GOT table for the symbol. */
331 HOWTO (R_CRIS_16_GOTPLT, /* type */
332 0, /* rightshift */
333 1, /* size (0 = byte, 1 = short, 2 = long) */
334 16, /* bitsize */
335 false, /* pc_relative */
336 0, /* bitpos */
337 complain_overflow_bitfield, /* complain_on_overflow */
338 bfd_elf_generic_reloc, /* special_function */
339 "R_CRIS_16_GOTPLT", /* name */
340 false, /* partial_inplace */
341 0, /* src_mask */
342 0xffff, /* dst_mask */
343 false), /* pcrel_offset */
344
345 HOWTO (R_CRIS_32_GOTPLT, /* type */
346 0, /* rightshift */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
348 32, /* bitsize */
349 false, /* pc_relative */
350 0, /* bitpos */
351 complain_overflow_bitfield, /* complain_on_overflow */
352 bfd_elf_generic_reloc, /* special_function */
353 "R_CRIS_32_GOTPLT", /* name */
354 false, /* partial_inplace */
355 0, /* src_mask */
356 0xffffffff, /* dst_mask */
357 false), /* pcrel_offset */
358
359 /* A 32-bit offset from GOT to (local const) symbol: no GOT entry should
360 be necessary. */
361 HOWTO (R_CRIS_32_GOTREL, /* type */
362 0, /* rightshift */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
364 32, /* bitsize */
365 false, /* pc_relative */
366 0, /* bitpos */
367 complain_overflow_bitfield, /* complain_on_overflow */
368 bfd_elf_generic_reloc, /* special_function */
369 "R_CRIS_32_GOTREL", /* name */
370 false, /* partial_inplace */
371 0, /* src_mask */
372 0xffffffff, /* dst_mask */
373 false), /* pcrel_offset */
374
375 /* A 32-bit offset from GOT to entry for this symbol in PLT and request
376 to create PLT entry for symbol. */
377 HOWTO (R_CRIS_32_PLT_GOTREL, /* type */
378 0, /* rightshift */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
380 32, /* bitsize */
381 false, /* pc_relative */
382 0, /* bitpos */
383 complain_overflow_bitfield, /* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_CRIS_32_PLT_GOTREL", /* name */
386 false, /* partial_inplace */
387 0, /* src_mask */
388 0xffffffff, /* dst_mask */
389 false), /* pcrel_offset */
390
391 /* A 32-bit offset from PC (location after the relocation) + addend to
392 entry for this symbol in PLT and request to create PLT entry for
393 symbol. */
394 HOWTO (R_CRIS_32_PLT_PCREL, /* type */
395 0, /* rightshift */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
397 32, /* bitsize */
398 true, /* pc_relative */
399 0, /* bitpos */
400 complain_overflow_bitfield, /* complain_on_overflow */
401 bfd_elf_generic_reloc, /* special_function */
402 "R_CRIS_32_PLT_PCREL", /* name */
403 false, /* partial_inplace */
404 0, /* src_mask */
405 0xffffffff, /* dst_mask */
406 true) /* pcrel_offset */
06c15ad7
HPN
407};
408\f
409/* Map BFD reloc types to CRIS ELF reloc types. */
410
411struct cris_reloc_map
412{
413 bfd_reloc_code_real_type bfd_reloc_val;
414 unsigned int cris_reloc_val;
415};
416
417static const struct cris_reloc_map cris_reloc_map [] =
418{
419 { BFD_RELOC_NONE, R_CRIS_NONE },
420 { BFD_RELOC_8, R_CRIS_8 },
421 { BFD_RELOC_16, R_CRIS_16 },
422 { BFD_RELOC_32, R_CRIS_32 },
423 { BFD_RELOC_8_PCREL, R_CRIS_8_PCREL },
424 { BFD_RELOC_16_PCREL, R_CRIS_16_PCREL },
425 { BFD_RELOC_32_PCREL, R_CRIS_32_PCREL },
426 { BFD_RELOC_VTABLE_INHERIT, R_CRIS_GNU_VTINHERIT },
915e5146
HPN
427 { BFD_RELOC_VTABLE_ENTRY, R_CRIS_GNU_VTENTRY },
428 { BFD_RELOC_CRIS_COPY, R_CRIS_COPY },
429 { BFD_RELOC_CRIS_GLOB_DAT, R_CRIS_GLOB_DAT },
430 { BFD_RELOC_CRIS_JUMP_SLOT, R_CRIS_JUMP_SLOT },
431 { BFD_RELOC_CRIS_RELATIVE, R_CRIS_RELATIVE },
432 { BFD_RELOC_CRIS_16_GOT, R_CRIS_16_GOT },
433 { BFD_RELOC_CRIS_32_GOT, R_CRIS_32_GOT },
434 { BFD_RELOC_CRIS_16_GOTPLT, R_CRIS_16_GOTPLT },
435 { BFD_RELOC_CRIS_32_GOTPLT, R_CRIS_32_GOTPLT },
436 { BFD_RELOC_CRIS_32_GOTREL, R_CRIS_32_GOTREL },
437 { BFD_RELOC_CRIS_32_PLT_GOTREL, R_CRIS_32_PLT_GOTREL },
438 { BFD_RELOC_CRIS_32_PLT_PCREL, R_CRIS_32_PLT_PCREL }
06c15ad7
HPN
439};
440
441static reloc_howto_type *
442cris_reloc_type_lookup (abfd, code)
443 bfd * abfd ATTRIBUTE_UNUSED;
444 bfd_reloc_code_real_type code;
445{
908d94bf 446 unsigned int i;
06c15ad7 447
908d94bf 448 for (i = 0; i < sizeof (cris_reloc_map) / sizeof (cris_reloc_map[0]); i++)
06c15ad7
HPN
449 if (cris_reloc_map [i].bfd_reloc_val == code)
450 return & cris_elf_howto_table [cris_reloc_map[i].cris_reloc_val];
a7c10850 451
06c15ad7
HPN
452 return NULL;
453}
454
455/* Set the howto pointer for an CRIS ELF reloc. */
456
457static void
458cris_info_to_howto_rela (abfd, cache_ptr, dst)
459 bfd * abfd ATTRIBUTE_UNUSED;
460 arelent * cache_ptr;
461 Elf32_Internal_Rela * dst;
462{
463 unsigned int r_type;
464
465 r_type = ELF32_R_TYPE (dst->r_info);
466 BFD_ASSERT (r_type < (unsigned int) R_CRIS_max);
467 cache_ptr->howto = & cris_elf_howto_table [r_type];
468}
469\f
72209a1f
HPN
470/* Support for core dump NOTE sections. */
471
472static boolean
473cris_elf_grok_prstatus (abfd, note)
474 bfd *abfd;
475 Elf_Internal_Note *note;
476{
477 int offset;
478 size_t raw_size;
479
480 switch (note->descsz)
481 {
482 default:
483 return false;
484
485 case 166: /* Linux/CRIS */
486 /* pr_cursig */
487 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
488
489 /* pr_pid */
490 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 22);
491
492 /* pr_reg */
493 offset = 70;
494 raw_size = 92;
495
496 break;
497 }
498
499 /* Make a ".reg/999" section. */
500 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
501 raw_size, note->descpos + offset);
502}
503
504static boolean
505cris_elf_grok_psinfo (abfd, note)
506 bfd *abfd;
507 Elf_Internal_Note *note;
508{
509 switch (note->descsz)
510 {
511 default:
512 return false;
513
514 case 124: /* Linux/CRIS elf_prpsinfo */
515 elf_tdata (abfd)->core_program
516 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
517 elf_tdata (abfd)->core_command
518 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
519 }
520
521 /* Note that for some reason, a spurious space is tacked
522 onto the end of the args in some (at least one anyway)
523 implementations, so strip it off if it exists. */
524
525 {
526 char *command = elf_tdata (abfd)->core_command;
527 int n = strlen (command);
528
529 if (0 < n && command[n - 1] == ' ')
530 command[n - 1] = '\0';
531 }
532
533 return true;
534}
535\f
915e5146
HPN
536/* The name of the dynamic interpreter. This is put in the .interp
537 section. */
538
539#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
540
541/* The size in bytes of an entry in the procedure linkage table. */
542
543#define PLT_ENTRY_SIZE 20
544
545/* The first entry in an absolute procedure linkage table looks like this. */
546
547static const bfd_byte elf_cris_plt0_entry[PLT_ENTRY_SIZE] =
548{
549 0xfc, 0xe1,
550 0x7e, 0x7e, /* push mof. */
551 0x7f, 0x0d, /* (dip [pc+]) */
552 0, 0, 0, 0, /* Replaced with address of .got + 4. */
553 0x30, 0x7a, /* move [...],mof */
554 0x7f, 0x0d, /* (dip [pc+]) */
555 0, 0, 0, 0, /* Replaced with address of .got + 8. */
556 0x30, 0x09, /* jump [...] */
557};
558
559/* Subsequent entries in an absolute procedure linkage table look like
560 this. */
561
562static const bfd_byte elf_cris_plt_entry[PLT_ENTRY_SIZE] =
563{
564 0x7f, 0x0d, /* (dip [pc+]) */
565 0, 0, 0, 0, /* Replaced with address of this symbol in .got. */
566 0x30, 0x09, /* jump [...] */
567 0x3f, 0x7e, /* move [pc+],mof */
568 0, 0, 0, 0, /* Replaced with offset into relocation table. */
569 0x2f, 0xfe, /* add.d [pc+],pc */
570 0xec, 0xff,
571 0xff, 0xff /* Replaced with offset to start of .plt. */
572};
573
574/* The first entry in a PIC procedure linkage table looks like this. */
575
576static const bfd_byte elf_cris_pic_plt0_entry[PLT_ENTRY_SIZE] =
577{
578 0xfc, 0xe1, 0x7e, 0x7e, /* push mof */
579 0x04, 0x01, 0x30, 0x7a, /* move [r0+4],mof */
580 0x08, 0x01, 0x30, 0x09, /* jump [r0+8] */
581 0, 0, 0, 0, 0, 0, 0, 0, /* Pad out to 20 bytes. */
582};
583
584/* Subsequent entries in a PIC procedure linkage table look like this. */
585
586static const bfd_byte elf_cris_pic_plt_entry[PLT_ENTRY_SIZE] =
587{
588 0x6f, 0x0d, /* (bdap [pc+].d,r0) */
589 0, 0, 0, 0, /* Replaced with offset of this symbol in .got. */
590 0x30, 0x09, /* jump [...] */
591 0x3f, 0x7e, /* move [pc+],mof */
592 0, 0, 0, 0, /* Replaced with offset into relocation table. */
593 0x2f, 0xfe, /* add.d [pc+],pc */
594 0xec, 0xff, /* Replaced with offset to start of .plt. */
595 0xff, 0xff
596};
597\f
598/* We copy elf32-m68k.c and elf32-i386.c for the basic linker hash bits
599 (and most other PIC/shlib stuff). Check that we don't drift away
600 without reason.
601
602 The CRIS linker, like the m68k and i386 linkers (and probably the rest
603 too) needs to keep track of the number of relocs that it decides to
604 copy in check_relocs for each symbol. This is so that it can discard
605 PC relative relocs if it doesn't need them when linking with
606 -Bsymbolic. We store the information in a field extending the regular
607 ELF linker hash table. */
608
609/* This structure keeps track of the number of PC relative relocs we have
610 copied for a given symbol. */
611
612struct elf_cris_pcrel_relocs_copied
613{
614 /* Next section. */
615 struct elf_cris_pcrel_relocs_copied *next;
616 /* A section in dynobj. */
617 asection *section;
618 /* Number of relocs copied in this section. */
619 bfd_size_type count;
620};
621
622/* CRIS ELF linker hash entry. */
623
624struct elf_cris_link_hash_entry
625{
626 struct elf_link_hash_entry root;
627
628 /* Number of PC relative relocs copied for this symbol. */
629 struct elf_cris_pcrel_relocs_copied *pcrel_relocs_copied;
630
631 /* The GOTPLT references are CRIS-specific; the goal is to avoid having
632 both a general GOT and a PLT-specific GOT entry for the same symbol,
633 when it is referenced both as a function and as a function pointer.
634
635 Number of GOTPLT references for a function. */
636 bfd_signed_vma gotplt_refcount;
637
638 /* Actual GOTPLT index for this symbol, if applicable, or zero if not
639 (zero is never used as an index). FIXME: We should be able to fold
640 this with gotplt_refcount in a union, like the got and plt unions in
641 elf_link_hash_entry. */
642 bfd_size_type gotplt_offset;
643};
644
645/* CRIS ELF linker hash table. */
646
647struct elf_cris_link_hash_table
648{
649 struct elf_link_hash_table root;
650
651 /* We can't use the PLT offset and calculate to get the GOTPLT offset,
652 since we try and avoid creating GOTPLT:s when there's already a GOT.
653 Instead, we keep and update the next available index here. */
654 bfd_size_type next_gotplt_entry;
655};
656
657/* Traverse a CRIS ELF linker hash table. */
658
659#define elf_cris_link_hash_traverse(table, func, info) \
660 (elf_link_hash_traverse \
661 (&(table)->root, \
662 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
663 (info)))
664
665/* Get the CRIS ELF linker hash table from a link_info structure. */
666
667#define elf_cris_hash_table(p) \
668 ((struct elf_cris_link_hash_table *) (p)->hash)
669
670/* Create an entry in a CRIS ELF linker hash table. */
671
672static struct bfd_hash_entry *
673elf_cris_link_hash_newfunc (entry, table, string)
674 struct bfd_hash_entry *entry;
675 struct bfd_hash_table *table;
676 const char *string;
677{
678 struct elf_cris_link_hash_entry *ret =
679 (struct elf_cris_link_hash_entry *) entry;
680
681 /* Allocate the structure if it has not already been allocated by a
682 subclass. */
683 if (ret == (struct elf_cris_link_hash_entry *) NULL)
684 ret = ((struct elf_cris_link_hash_entry *)
685 bfd_hash_allocate (table,
686 sizeof (struct elf_cris_link_hash_entry)));
687 if (ret == (struct elf_cris_link_hash_entry *) NULL)
688 return (struct bfd_hash_entry *) ret;
689
690 /* Call the allocation method of the superclass. */
691 ret = ((struct elf_cris_link_hash_entry *)
692 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
693 table, string));
694 if (ret != (struct elf_cris_link_hash_entry *) NULL)
695 {
696 ret->pcrel_relocs_copied = NULL;
697 ret->gotplt_refcount = 0;
698 ret->gotplt_offset = 0;
699 }
700
701 return (struct bfd_hash_entry *) ret;
702}
703
704/* Create a CRIS ELF linker hash table. */
705
706static struct bfd_link_hash_table *
707elf_cris_link_hash_table_create (abfd)
708 bfd *abfd;
709{
710 struct elf_cris_link_hash_table *ret;
dc810e39 711 bfd_size_type amt = sizeof (struct elf_cris_link_hash_table);
915e5146 712
dc810e39 713 ret = ((struct elf_cris_link_hash_table *) bfd_alloc (abfd, amt));
915e5146
HPN
714 if (ret == (struct elf_cris_link_hash_table *) NULL)
715 return NULL;
716
717 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
718 elf_cris_link_hash_newfunc))
719 {
720 bfd_release (abfd, ret);
721 return NULL;
722 }
723
724 /* Initialize to skip over the first three entries in the gotplt; they
725 are used for run-time symbol evaluation. */
726 ret->next_gotplt_entry = 12;
727
728 return &ret->root.root;
729}
730\f
06c15ad7 731/* Perform a single relocation. By default we use the standard BFD
915e5146 732 routines, with a few tweaks. */
06c15ad7
HPN
733
734static bfd_reloc_status_type
735cris_final_link_relocate (howto, input_bfd, input_section, contents, rel,
736 relocation)
737 reloc_howto_type * howto;
738 bfd * input_bfd;
739 asection * input_section;
740 bfd_byte * contents;
741 Elf_Internal_Rela * rel;
742 bfd_vma relocation;
743{
915e5146
HPN
744 bfd_reloc_status_type r;
745
746 /* PC-relative relocations are relative to the position *after*
747 the reloc. Note that for R_CRIS_8_PCREL the adjustment is
748 not a single byte, since PC must be 16-bit-aligned. */
749 switch (ELF32_R_TYPE (rel->r_info))
750 {
751 /* Check that the 16-bit GOT relocs are positive. */
752 case R_CRIS_16_GOTPLT:
753 case R_CRIS_16_GOT:
754 if ((bfd_signed_vma) relocation < 0)
755 return bfd_reloc_overflow;
756 break;
757
758 case R_CRIS_32_PLT_PCREL:
759 case R_CRIS_32_PCREL:
760 relocation -= 2;
761 /* Fall through. */
762 case R_CRIS_8_PCREL:
763 case R_CRIS_16_PCREL:
764 relocation -= 2;
765 break;
766
767 default:
768 break;
769 }
770
771 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
06c15ad7
HPN
772 contents, rel->r_offset,
773 relocation, rel->r_addend);
774 return r;
775}
776\f
777/* Relocate an CRIS ELF section. See elf32-fr30.c, from where this was
778 copied, for further comments. */
779
780static boolean
781cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
782 contents, relocs, local_syms, local_sections)
783 bfd * output_bfd ATTRIBUTE_UNUSED;
784 struct bfd_link_info * info;
785 bfd * input_bfd;
786 asection * input_section;
787 bfd_byte * contents;
788 Elf_Internal_Rela * relocs;
789 Elf_Internal_Sym * local_syms;
790 asection ** local_sections;
791{
915e5146 792 bfd *dynobj;
06c15ad7
HPN
793 Elf_Internal_Shdr * symtab_hdr;
794 struct elf_link_hash_entry ** sym_hashes;
915e5146
HPN
795 bfd_vma *local_got_offsets;
796 asection *sgot;
797 asection *splt;
798 asection *sreloc;
06c15ad7
HPN
799 Elf_Internal_Rela * rel;
800 Elf_Internal_Rela * relend;
801
915e5146
HPN
802 dynobj = elf_hash_table (info)->dynobj;
803 local_got_offsets = elf_local_got_offsets (input_bfd);
06c15ad7
HPN
804 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
805 sym_hashes = elf_sym_hashes (input_bfd);
806 relend = relocs + input_section->reloc_count;
807
808 /* It seems this can happen with erroneous or unsupported input (mixing
809 a.out and elf in an archive, for example.) */
810 if (sym_hashes == NULL)
811 return false;
812
915e5146
HPN
813 sgot = NULL;
814 splt = NULL;
815 sreloc = NULL;
816
817 if (dynobj != NULL)
818 {
819 splt = bfd_get_section_by_name (dynobj, ".plt");
820 sgot = bfd_get_section_by_name (dynobj, ".got");
821 }
822
06c15ad7
HPN
823 for (rel = relocs; rel < relend; rel ++)
824 {
825 reloc_howto_type * howto;
826 unsigned long r_symndx;
827 Elf_Internal_Sym * sym;
828 asection * sec;
829 struct elf_link_hash_entry * h;
830 bfd_vma relocation;
831 bfd_reloc_status_type r;
dc810e39 832 const char * symname = NULL;
06c15ad7 833 int r_type;
a7c10850 834
06c15ad7 835 r_type = ELF32_R_TYPE (rel->r_info);
a7c10850 836
06c15ad7
HPN
837 if ( r_type == R_CRIS_GNU_VTINHERIT
838 || r_type == R_CRIS_GNU_VTENTRY)
839 continue;
a7c10850 840
06c15ad7
HPN
841 r_symndx = ELF32_R_SYM (rel->r_info);
842
843 if (info->relocateable)
844 {
845 /* This is a relocateable link. We don't have to change
846 anything, unless the reloc is against a section symbol,
847 in which case we have to adjust according to where the
848 section symbol winds up in the output section. */
849 if (r_symndx < symtab_hdr->sh_info)
850 {
851 sym = local_syms + r_symndx;
a7c10850 852
06c15ad7
HPN
853 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
854 {
855 sec = local_sections [r_symndx];
856 rel->r_addend += sec->output_offset + sym->st_value;
857 }
858 }
859
860 continue;
861 }
862
863 /* This is a final link. */
915e5146 864 howto = cris_elf_howto_table + r_type;
06c15ad7
HPN
865 h = NULL;
866 sym = NULL;
867 sec = NULL;
a7c10850 868
06c15ad7
HPN
869 if (r_symndx < symtab_hdr->sh_info)
870 {
871 sym = local_syms + r_symndx;
872 sec = local_sections [r_symndx];
873 relocation = (sec->output_section->vma
874 + sec->output_offset
875 + sym->st_value);
a7c10850 876
dc810e39
AM
877 symname = (bfd_elf_string_from_elf_section
878 (input_bfd, symtab_hdr->sh_link, sym->st_name));
879 if (symname == NULL)
880 symname = bfd_section_name (input_bfd, sec);
06c15ad7
HPN
881 }
882 else
883 {
884 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
a7c10850 885
06c15ad7
HPN
886 while (h->root.type == bfd_link_hash_indirect
887 || h->root.type == bfd_link_hash_warning)
888 h = (struct elf_link_hash_entry *) h->root.u.i.link;
889
dc810e39 890 symname = h->root.root.string;
a7c10850 891
06c15ad7
HPN
892 if (h->root.type == bfd_link_hash_defined
893 || h->root.type == bfd_link_hash_defweak)
894 {
895 sec = h->root.u.def.section;
915e5146
HPN
896
897 /* Perhaps we should detect the cases that
898 sec->output_section is expected to be NULL like i386 and
899 m68k, but apparently (and according to elfxx-ia64.c) all
900 valid cases are where the symbol is defined in a shared
901 object which we link dynamically against. This includes
902 PLT relocs for which we've created a PLT entry and other
903 relocs for which we're prepared to create dynamic
904 relocations.
905
906 For now, new situations cause us to just err when
907 sec->output_offset is NULL but the object with the symbol
908 is *not* dynamically linked against. Thus this will
909 automatically remind us so we can see if there are other
910 valid cases we need to revisit. */
911 if ((sec->output_section == NULL
912 && (sec->owner->flags & DYNAMIC) != 0)
913
914 /* Here follow the cases where the relocation value must
915 be zero (or when further handling is simplified when
916 zero). I can't claim to understand the various
917 conditions and they weren't described in the files
918 where I copied them from (elf32-m68k.c and
919 elf32-i386.c), but let's mention examples of where
920 they happen. FIXME: Perhaps define and use a
921 dynamic_symbol_p function like ia64.
922
923 - When creating a shared library, we can have an
924 ordinary relocation for a symbol defined in a shared
925 library (perhaps the one we create). We then make
926 the relocation value zero, as the value seen now will
927 be added into the relocation addend in this shared
928 library, but must be handled only at dynamic-link
929 time. FIXME: Not sure this example covers the
930 h->elf_link_hash_flags test, though it's there in
931 other targets. */
932 || (info->shared
933 && ((! info->symbolic && h->dynindx != -1)
934 || (h->elf_link_hash_flags
935 & ELF_LINK_HASH_DEF_REGULAR) == 0)
936 && (input_section->flags & SEC_ALLOC) != 0
937 && (r_type == R_CRIS_8
938 || r_type == R_CRIS_16
939 || r_type == R_CRIS_32
940 || r_type == R_CRIS_8_PCREL
941 || r_type == R_CRIS_16_PCREL
942 || r_type == R_CRIS_32_PCREL)))
943 relocation = 0;
944 else if (sec->output_section != NULL)
945 relocation = (h->root.u.def.value
946 + sec->output_section->vma
947 + sec->output_offset);
948 else
949 {
8f615d07
AM
950 (*_bfd_error_handler)
951 (_("%s: unresolvable relocation %s against symbol `%s' from %s section"),
952 bfd_archive_filename (input_bfd),
953 cris_elf_howto_table[r_type].name,
954 symname,
955 bfd_get_section_name (input_bfd, input_section));
915e5146
HPN
956 bfd_set_error (bfd_error_bad_value);
957 return false;
958 }
06c15ad7
HPN
959 }
960 else if (h->root.type == bfd_link_hash_undefweak)
915e5146 961 relocation = 0;
06c15ad7 962 else if (info->shared
671bae9c 963 && (!info->symbolic || info->allow_shlib_undefined)
915e5146 964 && !info->no_undefined
06c15ad7
HPN
965 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
966 relocation = 0;
967 else
968 {
915e5146 969 if (!(info->callbacks->undefined_symbol
dc810e39 970 (info, symname, input_bfd,
915e5146
HPN
971 input_section, rel->r_offset,
972 (!info->shared || info->no_undefined
973 || ELF_ST_VISIBILITY (h->other)))))
06c15ad7 974 return false;
06c15ad7
HPN
975 relocation = 0;
976 }
977 }
a7c10850 978
915e5146 979 switch (r_type)
06c15ad7 980 {
915e5146
HPN
981 case R_CRIS_16_GOTPLT:
982 case R_CRIS_32_GOTPLT:
983 /* This is like the case for R_CRIS_32_GOT and R_CRIS_16_GOT,
984 but we require a PLT, and the PLT handling will take care of
985 filling in the PLT-specific GOT entry. For the GOT offset,
986 calculate it as we do when filling it in for the .got.plt
987 section. If we don't have a PLT, punt to GOT handling. */
988 if (h != NULL
989 && ((struct elf_cris_link_hash_entry *) h)->gotplt_offset != 0)
06c15ad7 990 {
915e5146
HPN
991 asection *sgotplt
992 = bfd_get_section_by_name (dynobj, ".got.plt");
993 bfd_vma got_offset;
a7c10850 994
915e5146
HPN
995 BFD_ASSERT (h->dynindx != -1);
996 BFD_ASSERT (sgotplt != NULL);
a7c10850 997
915e5146
HPN
998 got_offset
999 = ((struct elf_cris_link_hash_entry *) h)->gotplt_offset;
06c15ad7 1000
915e5146 1001 relocation = got_offset;
06c15ad7 1002 break;
915e5146 1003 }
06c15ad7 1004
4d96d128 1005 /* We didn't make a PLT entry for this symbol. Maybe everything is
915e5146
HPN
1006 folded into the GOT. Other than folding, this happens when
1007 statically linking PIC code, or when using -Bsymbolic. Check
1008 that we instead have a GOT entry as done for us by
1009 elf_cris_adjust_dynamic_symbol, and drop through into the
1010 ordinary GOT cases. */
1011 if (h != NULL && h->got.offset == (bfd_vma) -1)
1012 {
1013 (*_bfd_error_handler)
1014 (_("%s: No PLT nor GOT for relocation %s against symbol `%s' from %s section"),
8f615d07 1015 bfd_archive_filename (input_bfd),
915e5146 1016 cris_elf_howto_table[r_type].name,
dc810e39 1017 symname[0] != '\0' ? symname : _("[whose name is lost]"),
915e5146
HPN
1018 bfd_get_section_name (input_bfd, input_section));
1019
1020 /* FIXME: Perhaps blaming input is not the right thing to
1021 do; this is probably an internal error. But it is true
1022 that we didn't like that particular input. */
1023 bfd_set_error (bfd_error_bad_value);
1024 return false;
1025 }
1026 /* Fall through. */
1027
1028 /* The size of the actual relocation is not used here; we only
1029 fill in the GOT table here. */
1030 case R_CRIS_16_GOT:
1031 case R_CRIS_32_GOT:
1032 {
1033 bfd_vma off;
1034
1035 /* Note that despite using RELA relocations, the .got contents
1036 is always filled in with the link-relative relocation
1037 value; the addend. */
1038
1039 if (h != NULL)
1040 {
1041 off = h->got.offset;
1042 BFD_ASSERT (off != (bfd_vma) -1);
1043
1044 if (!elf_hash_table (info)->dynamic_sections_created
4d96d128 1045 || (! info->shared && h->dynindx == -1)
915e5146
HPN
1046 || (info->shared
1047 && (info->symbolic || h->dynindx == -1)
1048 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1049 {
4d96d128
HPN
1050 /* This wasn't checked above for ! info->shared, but
1051 must hold there if we get here; the symbol must not
1052 be used in, or defined by a DSO. (Note that
1053 checking for ELF_LINK_HASH_DEF_REGULAR doesn't
1054 catch all cases.) */
1055 BFD_ASSERT (info->shared
1056 || (h->elf_link_hash_flags
1057 & (ELF_LINK_HASH_REF_DYNAMIC
1058 | ELF_LINK_HASH_DEF_DYNAMIC)) == 0);
1059
915e5146
HPN
1060 /* This is actually a static link, or it is a
1061 -Bsymbolic link and the symbol is defined
1062 locally, or the symbol was forced to be local
4d96d128
HPN
1063 because of a version file, or we're not creating a
1064 dynamic object and the symbol isn't referred to by
1065 a dynamic object. We must initialize
915e5146
HPN
1066 this entry in the global offset table. Since
1067 the offset must always be a multiple of 4, we
1068 use the least significant bit to record whether
1069 we have initialized it already.
1070
1071 When doing a dynamic link, we create a .rela.got
1072 relocation entry to initialize the value. This
1073 is done in the finish_dynamic_symbol routine. */
1074 if ((off & 1) != 0)
1075 off &= ~1;
1076 else
1077 {
1078 bfd_put_32 (output_bfd, relocation,
1079 sgot->contents + off);
1080 h->got.offset |= 1;
1081 }
1082 }
1083 }
1084 else
1085 {
1086 BFD_ASSERT (local_got_offsets != NULL
1087 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1088
1089 off = local_got_offsets[r_symndx];
1090
1091 /* The offset must always be a multiple of 4. We use
1092 the least significant bit to record whether we have
1093 already generated the necessary reloc. */
1094 if ((off & 1) != 0)
1095 off &= ~1;
1096 else
1097 {
1098 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1099
1100 if (info->shared)
1101 {
1102 asection *srelgot;
1103 Elf_Internal_Rela outrel;
1104
1105 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1106 BFD_ASSERT (srelgot != NULL);
1107
1108 outrel.r_offset = (sgot->output_section->vma
1109 + sgot->output_offset
1110 + off);
1111 outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
1112 outrel.r_addend = relocation;
1113 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1114 (((Elf32_External_Rela *)
1115 srelgot->contents)
1116 + srelgot->reloc_count));
1117 ++srelgot->reloc_count;
1118 }
1119
1120 local_got_offsets[r_symndx] |= 1;
1121 }
1122 }
1123
1124 relocation = sgot->output_offset + off;
1125 if (rel->r_addend != 0)
1126 {
1127 /* We can't do anything for a relocation which is against
1128 a symbol *plus offset*. GOT holds relocations for
1129 symbols. Make this an error; the compiler isn't
1130 allowed to pass us these kinds of things. */
1131 if (h == NULL)
1132 (*_bfd_error_handler)
1133 (_("%s: relocation %s with non-zero addend %d against local symbol from %s section"),
8f615d07 1134 bfd_archive_filename (input_bfd),
915e5146
HPN
1135 cris_elf_howto_table[r_type].name,
1136 rel->r_addend,
1137 bfd_get_section_name (input_bfd, input_section));
1138 else
1139 (*_bfd_error_handler)
1140 (_("%s: relocation %s with non-zero addend %d against symbol `%s' from %s section"),
8f615d07 1141 bfd_archive_filename (input_bfd),
915e5146
HPN
1142 cris_elf_howto_table[r_type].name,
1143 rel->r_addend,
dc810e39 1144 symname[0] != '\0' ? symname : _("[whose name is lost]"),
915e5146
HPN
1145 bfd_get_section_name (input_bfd, input_section));
1146
1147 bfd_set_error (bfd_error_bad_value);
1148 return false;
1149 }
1150 }
1151 break;
06c15ad7 1152
915e5146
HPN
1153 case R_CRIS_32_GOTREL:
1154 /* This relocation must only be performed against local symbols. */
1155 if (h != NULL)
1156 {
1157 (*_bfd_error_handler)
1158 (_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
8f615d07 1159 bfd_archive_filename (input_bfd),
915e5146 1160 cris_elf_howto_table[r_type].name,
dc810e39 1161 symname,
915e5146
HPN
1162 bfd_get_section_name (input_bfd, input_section));
1163 bfd_set_error (bfd_error_bad_value);
1164 return false;
06c15ad7
HPN
1165 }
1166
915e5146
HPN
1167 /* This relocation is like a PC-relative one, except the
1168 reference point is the location of GOT. Note that
1169 sgot->output_offset is not involved in this calculation. We
1170 always want the start of entire .got section, not the
1171 position after the reserved header. */
1172 relocation -= sgot->output_section->vma;
1173 break;
06c15ad7 1174
915e5146
HPN
1175 case R_CRIS_32_PLT_PCREL:
1176 /* Relocation is to the entry for this symbol in the
1177 procedure linkage table. */
06c15ad7 1178
915e5146
HPN
1179 /* Resolve a PLT_PCREL reloc against a local symbol directly,
1180 without using the procedure linkage table. */
1181 if (h == NULL)
1182 break;
1183
1184 if (h->plt.offset == (bfd_vma) -1
1185 || splt == NULL)
1186 {
1187 /* We didn't make a PLT entry for this symbol. This
1188 happens when statically linking PIC code, or when
1189 using -Bsymbolic. */
1190 break;
1191 }
1192
1193 relocation = (splt->output_section->vma
1194 + splt->output_offset
1195 + h->plt.offset);
1196 break;
1197
1198 case R_CRIS_32_PLT_GOTREL:
1199 /* Like R_CRIS_32_PLT_PCREL, but the reference point is the
1200 start of the .got section. See also comment at
1201 R_CRIS_32_GOT. */
1202 relocation -= sgot->output_section->vma;
1203
1204 /* Resolve a PLT_GOTREL reloc against a local symbol directly,
1205 without using the procedure linkage table. */
1206 if (h == NULL)
1207 break;
1208
1209 if (h->plt.offset == (bfd_vma) -1
1210 || splt == NULL)
1211 {
1212 /* We didn't make a PLT entry for this symbol. This
1213 happens when statically linking PIC code, or when
1214 using -Bsymbolic. */
1215 break;
1216 }
1217
1218 relocation = (splt->output_section->vma
1219 + splt->output_offset
1220 + h->plt.offset
1221 - sgot->output_section->vma);
1222 break;
1223
1224 case R_CRIS_8_PCREL:
1225 case R_CRIS_16_PCREL:
1226 case R_CRIS_32_PCREL:
1227 /* If the symbol was local, we need no shlib-specific handling. */
1228 if (h == NULL)
1229 break;
1230
1231 /* Fall through. */
1232 case R_CRIS_8:
1233 case R_CRIS_16:
1234 case R_CRIS_32:
1235 if (info->shared
ec338859 1236 && r_symndx != 0
915e5146
HPN
1237 && (input_section->flags & SEC_ALLOC) != 0
1238 && ((r_type != R_CRIS_8_PCREL
1239 && r_type != R_CRIS_16_PCREL
1240 && r_type != R_CRIS_32_PCREL)
1241 || (!info->symbolic
1242 || (h->elf_link_hash_flags
1243 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
1244 {
1245 Elf_Internal_Rela outrel;
1246 boolean skip, relocate;
1247
1248 /* When generating a shared object, these relocations
1249 are copied into the output file to be resolved at run
1250 time. */
1251
1252 if (sreloc == NULL)
1253 {
1254 const char *name;
1255
1256 name = (bfd_elf_string_from_elf_section
1257 (input_bfd,
1258 elf_elfheader (input_bfd)->e_shstrndx,
1259 elf_section_data (input_section)->rel_hdr.sh_name));
1260 if (name == NULL)
1261 return false;
1262
1263 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1264 && strcmp (bfd_get_section_name (input_bfd,
1265 input_section),
1266 name + 5) == 0);
1267
1268 sreloc = bfd_get_section_by_name (dynobj, name);
1269
1270 /* That section should have been created in
1271 cris_elf_check_relocs, but that function will not be
1272 called for objects which fail in
1273 cris_elf_merge_private_bfd_data. */
1274 if (sreloc == NULL)
1275 {
1276 (*_bfd_error_handler)
1277 (_("%s: Internal inconsistency; no relocation section %s"),
8f615d07 1278 bfd_archive_filename (input_bfd),
915e5146
HPN
1279 name);
1280
1281 bfd_set_error (bfd_error_bad_value);
1282 return false;
1283 }
1284 }
1285
1286 skip = false;
1287
1288 if (elf_section_data (input_section)->stab_info == NULL)
1289 outrel.r_offset = rel->r_offset;
1290 else
1291 {
1292 bfd_vma off;
1293
1294 off = (_bfd_stab_section_offset
1295 (output_bfd, &elf_hash_table (info)->stab_info,
1296 input_section,
1297 &elf_section_data (input_section)->stab_info,
1298 rel->r_offset));
1299 if (off == (bfd_vma) -1)
1300 skip = true;
1301 outrel.r_offset = off;
1302 }
1303
1304 outrel.r_offset += (input_section->output_section->vma
1305 + input_section->output_offset);
1306
1307 if (skip)
1308 {
1309 memset (&outrel, 0, sizeof outrel);
1310 relocate = false;
1311 }
1312 /* h->dynindx may be -1 if the symbol was marked to
1313 become local. */
1314 else if (h != NULL
1315 && ((! info->symbolic && h->dynindx != -1)
1316 || (h->elf_link_hash_flags
1317 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1318 {
1319 BFD_ASSERT (h->dynindx != -1);
1320 relocate = false;
1321 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1322 outrel.r_addend = relocation + rel->r_addend;
1323 }
1324 else
1325 {
1326 if (r_type == R_CRIS_32)
1327 {
1328 relocate = true;
1329 outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
1330 outrel.r_addend = relocation + rel->r_addend;
1331 }
1332 else
1333 {
1334 long indx;
1335
1336 if (h == NULL)
1337 sec = local_sections[r_symndx];
1338 else
1339 {
1340 BFD_ASSERT (h->root.type == bfd_link_hash_defined
1341 || (h->root.type
1342 == bfd_link_hash_defweak));
1343 sec = h->root.u.def.section;
1344 }
1345 if (sec != NULL && bfd_is_abs_section (sec))
1346 indx = 0;
1347 else if (sec == NULL || sec->owner == NULL)
1348 {
1349 bfd_set_error (bfd_error_bad_value);
1350 return false;
1351 }
1352 else
1353 {
1354 asection *osec;
1355
1356 osec = sec->output_section;
1357 indx = elf_section_data (osec)->dynindx;
1358 BFD_ASSERT (indx > 0);
1359 }
1360
1361 relocate = false;
1362 outrel.r_info = ELF32_R_INFO (indx, r_type);
1363 outrel.r_addend = relocation + rel->r_addend;
1364 }
1365 }
1366
1367 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1368 (((Elf32_External_Rela *)
1369 sreloc->contents)
1370 + sreloc->reloc_count));
1371 ++sreloc->reloc_count;
1372
1373 /* This reloc will be computed at runtime, so there's no
1374 need to do anything now, except for R_CRIS_32 relocations
1375 that have been turned into R_CRIS_RELATIVE. */
1376 if (!relocate)
1377 continue;
1378 }
1379
1380 break;
1381 }
1382
1383 r = cris_final_link_relocate (howto, input_bfd, input_section,
1384 contents, rel, relocation);
1385
1386 if (r != bfd_reloc_ok)
1387 {
1388 const char * msg = (const char *) NULL;
1389
1390 switch (r)
1391 {
1392 case bfd_reloc_overflow:
1393 r = info->callbacks->reloc_overflow
dc810e39 1394 (info, symname, howto->name, (bfd_vma) 0,
915e5146
HPN
1395 input_bfd, input_section, rel->r_offset);
1396 break;
1397
1398 case bfd_reloc_undefined:
1399 r = info->callbacks->undefined_symbol
dc810e39 1400 (info, symname, input_bfd, input_section, rel->r_offset,
915e5146
HPN
1401 true);
1402 break;
1403
1404 case bfd_reloc_outofrange:
1405 msg = _("internal error: out of range error");
1406 break;
1407
1408 case bfd_reloc_notsupported:
1409 msg = _("internal error: unsupported relocation error");
1410 break;
1411
1412 case bfd_reloc_dangerous:
1413 msg = _("internal error: dangerous relocation");
1414 break;
1415
1416 default:
1417 msg = _("internal error: unknown error");
1418 break;
1419 }
1420
1421 if (msg)
1422 r = info->callbacks->warning
dc810e39 1423 (info, msg, symname, input_bfd, input_section, rel->r_offset);
915e5146
HPN
1424
1425 if (! r)
1426 return false;
1427 }
1428 }
1429
1430 return true;
1431}
1432\f
1433/* Finish up dynamic symbol handling. We set the contents of various
1434 dynamic sections here. */
1435
1436static boolean
1437elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
1438 bfd *output_bfd;
1439 struct bfd_link_info *info;
1440 struct elf_link_hash_entry *h;
1441 Elf_Internal_Sym *sym;
1442{
1443 bfd *dynobj;
1444 int plt_off1 = 2, plt_off2 = 10, plt_off3 = 16;
1445
1446 dynobj = elf_hash_table (info)->dynobj;
1447
1448 if (h->plt.offset != (bfd_vma) -1)
1449 {
1450 asection *splt;
1451 asection *sgotplt;
1452 asection *sgot;
1453 asection *srela;
1454 bfd_vma got_base;
1455
1456 bfd_vma gotplt_offset
1457 = ((struct elf_cris_link_hash_entry *) h)->gotplt_offset;
1458 Elf_Internal_Rela rela;
1459 boolean has_gotplt = gotplt_offset != 0;
1460
1461 /* Get the index in the procedure linkage table which
1462 corresponds to this symbol. This is the index of this symbol
1463 in all the symbols for which we are making plt entries. The
1464 first entry in the procedure linkage table is reserved. */
1465 /* We have to count backwards here, and the result is only valid as
1466 an index into .got.plt and its relocations. FIXME: Constants... */
1467 bfd_vma gotplt_index = gotplt_offset/4 - 3;
1468
1469 /* Get the offset into the .got table of the entry that corresponds
1470 to this function. Note that we embed knowledge that "incoming"
1471 .got goes after .got.plt in the output without padding (pointer
1472 aligned). However, that knowledge is present in several other
1473 places too, here and in elflink.h at least. */
1474 bfd_vma got_offset
1475 = (has_gotplt
1476 ? gotplt_offset
1477 : h->got.offset + elf_cris_hash_table(info)->next_gotplt_entry);
1478
1479 /* This symbol has an entry in the procedure linkage table. Set it
1480 up. */
1481
1482 BFD_ASSERT (h->dynindx != -1);
1483
1484 splt = bfd_get_section_by_name (dynobj, ".plt");
1485 sgot = bfd_get_section_by_name (dynobj, ".got");
1486 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1487 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1488 BFD_ASSERT (splt != NULL && sgotplt != NULL
1489 && (! has_gotplt || srela != NULL));
1490
1491 got_base = sgotplt->output_section->vma + sgotplt->output_offset;
1492
1493 /* Fill in the entry in the procedure linkage table. */
1494 if (! info->shared)
1495 {
1496 memcpy (splt->contents + h->plt.offset, elf_cris_plt_entry,
1497 PLT_ENTRY_SIZE);
1498
1499 /* We need to enter the absolute address of the GOT entry here. */
1500 bfd_put_32 (output_bfd, got_base + got_offset,
1501 splt->contents + h->plt.offset + plt_off1);
1502 }
1503 else
1504 {
1505 memcpy (splt->contents + h->plt.offset, elf_cris_pic_plt_entry,
1506 PLT_ENTRY_SIZE);
1507 bfd_put_32 (output_bfd, got_offset,
1508 splt->contents + h->plt.offset + plt_off1);
1509 }
1510
1511 /* Fill in the plt entry and make a relocation, if this is a "real"
1512 PLT entry. */
1513 if (has_gotplt)
1514 {
1515 /* Fill in the offset into the reloc table. */
1516 bfd_put_32 (output_bfd,
1517 gotplt_index * sizeof (Elf32_External_Rela),
1518 splt->contents + h->plt.offset + plt_off2);
1519
1520 /* Fill in the offset to the first PLT entry, where to "jump". */
1521 bfd_put_32 (output_bfd, - (h->plt.offset + plt_off3 + 4),
1522 splt->contents + h->plt.offset + plt_off3);
1523
1524 /* Fill in the entry in the global offset table with the address of
1525 the relocating stub. */
1526 bfd_put_32 (output_bfd,
1527 (splt->output_section->vma
1528 + splt->output_offset
1529 + h->plt.offset
1530 + 8),
1531 sgotplt->contents + got_offset);
1532
1533 /* Fill in the entry in the .rela.plt section. */
1534 rela.r_offset = (sgotplt->output_section->vma
1535 + sgotplt->output_offset
1536 + got_offset);
1537 rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_JUMP_SLOT);
1538 rela.r_addend = 0;
1539 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1540 ((Elf32_External_Rela *) srela->contents
1541 + gotplt_index));
1542 }
1543
1544 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1545 {
1546 /* Mark the symbol as undefined, rather than as defined in
1547 the .plt section. Leave the value alone. */
1548 sym->st_shndx = SHN_UNDEF;
1549
1550 /* FIXME: From elf32-sparc.c 2001-02-19 (1.18). I still don't
1551 know whether resetting the value is significant; if it really
1552 is, rather than a quirk or bug in the sparc port, then I
1553 believe we'd see this elsewhere. */
1554 /* If the symbol is weak, we do need to clear the value.
1555 Otherwise, the PLT entry would provide a definition for
1556 the symbol even if the symbol wasn't defined anywhere,
1557 and so the symbol would never be NULL. */
1558 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
1559 == 0)
1560 sym->st_value = 0;
1561 }
1562 }
1563
4d96d128
HPN
1564 /* We don't emit .got relocs for symbols that aren't in the
1565 dynamic-symbols table for an ordinary program. */
1566 if (h->got.offset != (bfd_vma) -1
1567 && (info->shared || h->dynindx != -1))
915e5146
HPN
1568 {
1569 asection *sgot;
1570 asection *srela;
1571 Elf_Internal_Rela rela;
dc810e39 1572 bfd_byte *where;
915e5146
HPN
1573
1574 /* This symbol has an entry in the global offset table. Set it up. */
1575
1576 sgot = bfd_get_section_by_name (dynobj, ".got");
1577 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1578 BFD_ASSERT (sgot != NULL && srela != NULL);
1579
1580 rela.r_offset = (sgot->output_section->vma
1581 + sgot->output_offset
dc810e39 1582 + (h->got.offset &~ (bfd_vma) 1));
915e5146
HPN
1583
1584 /* If this is a static link, or it is a -Bsymbolic link and the
1585 symbol is defined locally or was forced to be local because
1586 of a version file, we just want to emit a RELATIVE reloc.
1587 The entry in the global offset table will already have been
1588 initialized in the relocate_section function. */
dc810e39 1589 where = sgot->contents + (h->got.offset &~ (bfd_vma) 1);
915e5146
HPN
1590 if (! elf_hash_table (info)->dynamic_sections_created
1591 || (info->shared
1592 && (info->symbolic || h->dynindx == -1)
1593 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1594 {
1595 rela.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
dc810e39 1596 rela.r_addend = bfd_get_signed_32 (output_bfd, where);
915e5146
HPN
1597 }
1598 else
1599 {
dc810e39 1600 bfd_put_32 (output_bfd, (bfd_vma) 0, where);
915e5146
HPN
1601 rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_GLOB_DAT);
1602 rela.r_addend = 0;
1603 }
1604
1605 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1606 ((Elf32_External_Rela *) srela->contents
1607 + srela->reloc_count));
1608 ++srela->reloc_count;
1609 }
1610
1611 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1612 {
1613 asection *s;
1614 Elf_Internal_Rela rela;
1615
1616 /* This symbol needs a copy reloc. Set it up. */
1617
1618 BFD_ASSERT (h->dynindx != -1
1619 && (h->root.type == bfd_link_hash_defined
1620 || h->root.type == bfd_link_hash_defweak));
1621
1622 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1623 ".rela.bss");
1624 BFD_ASSERT (s != NULL);
1625
1626 rela.r_offset = (h->root.u.def.value
1627 + h->root.u.def.section->output_section->vma
1628 + h->root.u.def.section->output_offset);
1629 rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_COPY);
1630 rela.r_addend = 0;
1631 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1632 ((Elf32_External_Rela *) s->contents
1633 + s->reloc_count));
1634 ++s->reloc_count;
1635 }
1636
1637 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1638 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1639 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1640 sym->st_shndx = SHN_ABS;
1641
1642 return true;
1643}
1644\f
1645/* Finish up the dynamic sections. */
1646
1647static boolean
1648elf_cris_finish_dynamic_sections (output_bfd, info)
1649 bfd *output_bfd;
1650 struct bfd_link_info *info;
1651{
1652 bfd *dynobj;
1653 asection *sgot;
1654 asection *sdyn;
1655
1656 dynobj = elf_hash_table (info)->dynobj;
1657
1658 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1659 BFD_ASSERT (sgot != NULL);
1660 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1661
1662 if (elf_hash_table (info)->dynamic_sections_created)
1663 {
1664 asection *splt;
1665 Elf32_External_Dyn *dyncon, *dynconend;
1666
1667 splt = bfd_get_section_by_name (dynobj, ".plt");
1668 BFD_ASSERT (splt != NULL && sdyn != NULL);
1669
1670 dyncon = (Elf32_External_Dyn *) sdyn->contents;
1671 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1672 for (; dyncon < dynconend; dyncon++)
1673 {
1674 Elf_Internal_Dyn dyn;
1675 asection *s;
1676
1677 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1678
1679 switch (dyn.d_tag)
1680 {
1681 default:
1682 break;
1683
1684 case DT_PLTGOT:
1685 s = bfd_get_section_by_name (output_bfd, ".got");
1686 BFD_ASSERT (s != NULL);
1687 dyn.d_un.d_ptr = s->vma;
1688 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1689 break;
1690
1691 case DT_JMPREL:
1692 /* Yes, we *can* have a .plt and no .plt.rela, for instance
1693 if all symbols are found in the .got (not .got.plt). */
1694 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1695 dyn.d_un.d_ptr = s != NULL ? s->vma : 0;
1696 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1697 break;
1698
1699 case DT_PLTRELSZ:
1700 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1701 if (s == NULL)
1702 dyn.d_un.d_val = 0;
1703 else if (s->_cooked_size != 0)
1704 dyn.d_un.d_val = s->_cooked_size;
1705 else
1706 dyn.d_un.d_val = s->_raw_size;
1707 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1708 break;
1709
1710 case DT_RELASZ:
1711 /* The procedure linkage table relocs (DT_JMPREL) should
1712 not be included in the overall relocs (DT_RELA).
1713 Therefore, we override the DT_RELASZ entry here to
1714 make it not include the JMPREL relocs. Since the
1715 linker script arranges for .rela.plt to follow all
1716 other relocation sections, we don't have to worry
1717 about changing the DT_RELA entry. */
1718 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1719 if (s != NULL)
1720 {
1721 if (s->_cooked_size != 0)
1722 dyn.d_un.d_val -= s->_cooked_size;
1723 else
1724 dyn.d_un.d_val -= s->_raw_size;
1725 }
1726 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1727 break;
1728 }
1729 }
1730
1731 /* Fill in the first entry in the procedure linkage table. */
1732 if (splt->_raw_size > 0)
1733 {
1734 if (info->shared)
1735 memcpy (splt->contents, elf_cris_pic_plt0_entry, PLT_ENTRY_SIZE);
1736 else
1737 {
1738 memcpy (splt->contents, elf_cris_plt0_entry, PLT_ENTRY_SIZE);
1739 bfd_put_32 (output_bfd,
1740 sgot->output_section->vma + sgot->output_offset + 4,
1741 splt->contents + 6);
1742 bfd_put_32 (output_bfd,
1743 sgot->output_section->vma + sgot->output_offset + 8,
1744 splt->contents + 14);
1745
1746 elf_section_data (splt->output_section)->this_hdr.sh_entsize
1747 = PLT_ENTRY_SIZE;
1748 }
1749 }
1750 }
1751
1752 /* Fill in the first three entries in the global offset table. */
1753 if (sgot->_raw_size > 0)
1754 {
1755 if (sdyn == NULL)
1756 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
1757 else
1758 bfd_put_32 (output_bfd,
1759 sdyn->output_section->vma + sdyn->output_offset,
1760 sgot->contents);
1761 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
1762 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
1763 }
1764
1765 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
1766
1767 return true;
06c15ad7
HPN
1768}
1769\f
1770/* Return the section that should be marked against GC for a given
1771 relocation. */
1772
1773static asection *
1774cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
1775 bfd * abfd;
1776 struct bfd_link_info * info ATTRIBUTE_UNUSED;
1777 Elf_Internal_Rela * rel;
1778 struct elf_link_hash_entry * h;
1779 Elf_Internal_Sym * sym;
1780{
1781 if (h != NULL)
1782 {
1783 switch (ELF32_R_TYPE (rel->r_info))
1784 {
1785 case R_CRIS_GNU_VTINHERIT:
1786 case R_CRIS_GNU_VTENTRY:
1787 break;
1788
1789 default:
1790 switch (h->root.type)
1791 {
1792 case bfd_link_hash_defined:
1793 case bfd_link_hash_defweak:
1794 return h->root.u.def.section;
1795
1796 case bfd_link_hash_common:
1797 return h->root.u.c.p->section;
1798
1799 default:
1800 break;
1801 }
1802 }
1803 }
1804 else
1805 {
1806 if (!(elf_bad_symtab (abfd)
1807 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
1808 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
1809 && sym->st_shndx != SHN_COMMON))
1810 {
1811 return bfd_section_from_elf_index (abfd, sym->st_shndx);
1812 }
1813 }
1814
1815 return NULL;
1816}
1817
1818/* Update the got entry reference counts for the section being removed. */
1819
1820static boolean
1821cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
1822 bfd * abfd ATTRIBUTE_UNUSED;
1823 struct bfd_link_info * info ATTRIBUTE_UNUSED;
1824 asection * sec ATTRIBUTE_UNUSED;
1825 const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED;
1826{
915e5146
HPN
1827 Elf_Internal_Shdr *symtab_hdr;
1828 struct elf_link_hash_entry **sym_hashes;
1829 bfd_signed_vma *local_got_refcounts;
1830 const Elf_Internal_Rela *rel, *relend;
1831 unsigned long r_symndx;
1832 struct elf_link_hash_entry *h;
1833 bfd *dynobj;
1834 asection *sgot;
1835 asection *srelgot;
1836
1837 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1838 sym_hashes = elf_sym_hashes (abfd);
1839 local_got_refcounts = elf_local_got_refcounts (abfd);
1840
1841 dynobj = elf_hash_table (info)->dynobj;
1842 if (dynobj == NULL)
1843 return true;
1844
1845 sgot = bfd_get_section_by_name (dynobj, ".got");
1846 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1847
1848 relend = relocs + sec->reloc_count;
1849 for (rel = relocs; rel < relend; rel++)
1850 {
1851 switch (ELF32_R_TYPE (rel->r_info))
1852 {
1853 case R_CRIS_16_GOT:
1854 case R_CRIS_32_GOT:
1855 r_symndx = ELF32_R_SYM (rel->r_info);
1856 if (r_symndx >= symtab_hdr->sh_info)
1857 {
1858 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1859 if (h->got.refcount > 0)
1860 {
1861 --h->got.refcount;
1862 if (h->got.refcount == 0)
1863 {
1864 /* We don't need the .got entry any more. */
1865 sgot->_raw_size -= 4;
1866 srelgot->_raw_size -= sizeof (Elf32_External_Rela);
1867 }
1868 }
1869 break;
1870 }
1871
1872 local_got_reloc:
1873 if (local_got_refcounts != NULL)
1874 {
1875 if (local_got_refcounts[r_symndx] > 0)
1876 {
1877 --local_got_refcounts[r_symndx];
1878 if (local_got_refcounts[r_symndx] == 0)
1879 {
1880 /* We don't need the .got entry any more. */
1881 sgot->_raw_size -= 4;
1882 if (info->shared)
1883 srelgot->_raw_size -= sizeof (Elf32_External_Rela);
1884 }
1885 }
1886 }
1887 break;
1888
1889 case R_CRIS_16_GOTPLT:
1890 case R_CRIS_32_GOTPLT:
1891 /* For local symbols, treat these like GOT relocs. */
1892 r_symndx = ELF32_R_SYM (rel->r_info);
1893 if (r_symndx < symtab_hdr->sh_info)
1894 goto local_got_reloc;
1895
1896 case R_CRIS_32_PLT_GOTREL:
1897 /* FIXME: We don't garbage-collect away the .got section. */
1898 if (local_got_refcounts != NULL)
1899 local_got_refcounts[-1]--;
1900 /* Fall through. */
1901
1902 case R_CRIS_8_PCREL:
1903 case R_CRIS_16_PCREL:
1904 case R_CRIS_32_PCREL:
1905 case R_CRIS_32_PLT_PCREL:
1906 r_symndx = ELF32_R_SYM (rel->r_info);
1907 if (r_symndx >= symtab_hdr->sh_info)
1908 {
1909 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1910 if (h->plt.refcount > 0)
1911 --h->plt.refcount;
1912 }
1913 break;
1914
1915 default:
1916 break;
1917 }
1918 }
1919
06c15ad7
HPN
1920 return true;
1921}
1922
915e5146
HPN
1923/* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1924 entry but we found we will not create any. Called when we find we will
4d96d128
HPN
1925 not have any PLT for this symbol, by for example
1926 elf_cris_adjust_dynamic_symbol when we're doing a proper dynamic link,
1927 or elf_cris_size_dynamic_sections if no dynamic sections will be
1928 created (we're only linking static objects). */
915e5146
HPN
1929
1930static boolean
1931elf_cris_adjust_gotplt_to_got (h, p)
1932 struct elf_cris_link_hash_entry *h;
1933 PTR p;
1934{
1935 struct bfd_link_info *info = (struct bfd_link_info *) p;
1936 bfd *dynobj = elf_hash_table (info)->dynobj;
1937
1938 BFD_ASSERT (dynobj != NULL);
1939
1940 /* If nobody wanted a GOTPLT with this symbol, we're done. */
1941 if (h->gotplt_refcount <= 0)
1942 return true;
1943
1944 if (h->root.got.refcount > 0)
1945 {
1946 /* There's a GOT entry for this symbol. Just adjust the refcount.
1947 Probably not necessary at this stage, but keeping it accurate
1948 helps avoiding surprises later. */
1949 h->root.got.refcount += h->gotplt_refcount;
1950 h->gotplt_refcount = -1;
1951 }
1952 else
1953 {
4d96d128 1954 /* No GOT entry for this symbol. We need to create one. */
915e5146
HPN
1955 asection *sgot = bfd_get_section_by_name (dynobj, ".got");
1956 asection *srelgot
1957 = bfd_get_section_by_name (dynobj, ".rela.got");
1958
1959 /* Put an accurate refcount there. */
1960 h->root.got.refcount = h->gotplt_refcount;
1961
1962 h->gotplt_refcount = -1;
1963
1964 /* We always have a .got section when there are dynamic
1965 relocs. */
1966 BFD_ASSERT (sgot != NULL /* Surely have .got section. */);
1967
1968 /* We might have had a PLT but with no GOT entry and
1969 further no GOT reloc section at all needed before.
1970 Add it. */
1971 if (srelgot == NULL)
1972 {
1973 srelgot = bfd_make_section (dynobj, ".rela.got");
1974
1975 if (srelgot == NULL
1976 || !bfd_set_section_flags (dynobj, srelgot,
1977 (SEC_ALLOC
1978 | SEC_LOAD
1979 | SEC_HAS_CONTENTS
1980 | SEC_IN_MEMORY
1981 | SEC_LINKER_CREATED
1982 | SEC_READONLY))
1983 || !bfd_set_section_alignment (dynobj, srelgot, 2))
1984 return false;
1985 }
1986
1987 /* Allocate space in the .got section. */
1988 sgot->_raw_size += 4;
1989
1990 /* Allocate relocation space. */
1991 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1992 }
1993
1994 return true;
1995}
1996
1997/* Try to fold PLT entries with GOT entries. There are two cases when we
1998 want to do this:
1999
2000 - When all PLT references are GOTPLT references, and there are GOT
2001 references. We don't have to generate a PLT at all.
2002
2003 - When there are both (ordinary) PLT references and GOT references.
2004 We want to make the PLT reference use the ordinary GOT entry rather
2005 than a run-time dynamically resolved GOTPLT entry (since the GOT
2006 entry will have to be resolved at startup anyway).
2007
2008 Though the latter case is handled when room for the PLT is allocated,
2009 not here.
2010
2011 Note that this function is called before symbols are forced local by
2012 version scripts. The differing cases are handled by
2013 elf_cris_hide_symbol. */
2014
2015static boolean
2016elf_cris_try_fold_plt_to_got (h, p)
2017 struct elf_cris_link_hash_entry *h;
2018 PTR p;
2019{
2020 struct bfd_link_info *info = (struct bfd_link_info *) p;
2021
2022 /* If there are no GOT references for this symbol, we can't fold any
2023 other reference so there's nothing to do. Likewise if there are no
2024 PLT references; GOTPLT references included. */
2025 if (h->root.got.refcount <= 0 || h->root.plt.refcount <= 0)
2026 return true;
2027
2028 /* GOTPLT relocs are supposed to be included into the PLT refcount. */
2029 BFD_ASSERT (h->gotplt_refcount <= h->root.plt.refcount);
2030
2031 if (h->gotplt_refcount == h->root.plt.refcount)
2032 {
4d96d128 2033 /* The only PLT references are GOTPLT references, and there are GOT
915e5146
HPN
2034 references. Convert PLT to GOT references. */
2035 if (! elf_cris_adjust_gotplt_to_got (h, info))
2036 return false;
2037
2038 /* Clear the PLT references, so no PLT will be created. */
2039 h->root.plt.offset = (bfd_vma) -1;
2040 }
2041
2042 return true;
2043}
2044
2045/* Our own version of hide_symbol, so that we can adjust a GOTPLT reloc
2046 to use a GOT entry (and create one) rather than requiring a GOTPLT
2047 entry. */
2048
2049static void
2050elf_cris_hide_symbol (info, h)
2051 struct bfd_link_info *info;
2052 struct elf_link_hash_entry *h;
2053{
2054 elf_cris_adjust_gotplt_to_got ((struct elf_cris_link_hash_entry *) h, info);
2055
2056 _bfd_elf_link_hash_hide_symbol (info, h);
2057}
2058
2059/* Adjust a symbol defined by a dynamic object and referenced by a
2060 regular object. The current definition is in some section of the
2061 dynamic object, but we're not including those sections. We have to
2062 change the definition to something the rest of the link can
2063 understand. */
2064
2065static boolean
2066elf_cris_adjust_dynamic_symbol (info, h)
2067 struct bfd_link_info *info;
2068 struct elf_link_hash_entry *h;
2069{
2070 bfd *dynobj;
2071 asection *s;
2072 unsigned int power_of_two;
2073
2074 dynobj = elf_hash_table (info)->dynobj;
2075
2076 /* Make sure we know what is going on here. */
2077 BFD_ASSERT (dynobj != NULL
2078 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
2079 || h->weakdef != NULL
2080 || ((h->elf_link_hash_flags
2081 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2082 && (h->elf_link_hash_flags
2083 & ELF_LINK_HASH_REF_REGULAR) != 0
2084 && (h->elf_link_hash_flags
2085 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
2086
2087 /* If this is a function, put it in the procedure linkage table. We
2088 will fill in the contents of the procedure linkage table later,
2089 when we know the address of the .got section. */
2090 if (h->type == STT_FUNC
2091 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2092 {
2093 if (! info->shared
2094 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
2095 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
2096 /* We must always create the plt entry if it was referenced by a
2097 PLT relocation. In this case we already recorded it as a
2098 dynamic symbol. */
2099 /* FIXME: m68k and i386 differ here, for unclear reasons. */
2100 && h->dynindx == -1)
2101 {
2102 /* This case can occur if we saw a PLT reloc in an input file,
2103 but the symbol was never referred to by a dynamic object. In
2104 such a case, we don't actually need to build a procedure
4d96d128
HPN
2105 linkage table, and we can just do a PC reloc instead, or
2106 change a .got.plt index to a .got index for GOTPLT relocs. */
915e5146
HPN
2107 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
2108 h->plt.offset = (bfd_vma) -1;
2109
2110 return
2111 elf_cris_adjust_gotplt_to_got ((struct
2112 elf_cris_link_hash_entry *) h,
2113 info);
2114 }
2115
2116 /* If there are only GOT references and GOTPLT references to this
2117 PLT entry, get rid of the PLT. */
2118 if (! elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry *)
2119 h, info))
2120 return false;
2121
2122 /* GC or folding may have rendered this entry unused. */
2123 if (h->plt.refcount <= 0)
2124 {
2125 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2126 h->plt.offset = (bfd_vma) -1;
2127 return true;
2128 }
2129
2130 /* Make sure this symbol is output as a dynamic symbol. */
2131 if (h->dynindx == -1)
2132 {
2133 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
2134 return false;
2135 }
2136
2137 s = bfd_get_section_by_name (dynobj, ".plt");
2138 BFD_ASSERT (s != NULL);
2139
2140 /* If this is the first .plt entry, make room for the special
2141 first entry. */
2142 if (s->_raw_size == 0)
2143 s->_raw_size += PLT_ENTRY_SIZE;
2144
2145 /* If this symbol is not defined in a regular file, and we are
2146 not generating a shared library, then set the symbol to this
2147 location in the .plt. This is required to make function
2148 pointers compare as equal between the normal executable and
2149 the shared library. */
2150 if (!info->shared
2151 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2152 {
2153 h->root.u.def.section = s;
2154 h->root.u.def.value = s->_raw_size;
2155 }
2156
4d96d128
HPN
2157 /* If there's already a GOT entry, use that, not a .got.plt. A
2158 GOT field still has a reference count when we get here; it's
2159 not yet changed to an offset. */
915e5146
HPN
2160 if (h->got.refcount > 0)
2161 {
2162 h->got.refcount += h->plt.refcount;
2163
2164 /* Mark the PLT offset to use the GOT entry by setting the low
2165 bit in the plt offset; it is always a multiple of
2166 pointer-size. */
2167 BFD_ASSERT ((s->_raw_size & 3) == 0);
2168
2169 /* Change the PLT refcount to an offset. */
2170 h->plt.offset = s->_raw_size;
2171
2172 /* By not setting gotplt_offset (i.e. it remains at 0), we signal
2173 that the got entry should be used instead. */
2174 BFD_ASSERT (((struct elf_cris_link_hash_entry *)
2175 h)->gotplt_offset == 0);
2176
2177 /* Make room for this entry. */
2178 s->_raw_size += PLT_ENTRY_SIZE;
2179
2180 return true;
2181 }
2182
2183 /* No GOT reference for this symbol; prepare for an ordinary PLT. */
2184 h->plt.offset = s->_raw_size;
2185
2186 /* Make room for this entry. */
2187 s->_raw_size += PLT_ENTRY_SIZE;
2188
2189 /* We also need to make an entry in the .got.plt section, which
2190 will be placed in the .got section by the linker script. */
2191 ((struct elf_cris_link_hash_entry *) h)->gotplt_offset
2192 = elf_cris_hash_table (info)->next_gotplt_entry;
2193 elf_cris_hash_table (info)->next_gotplt_entry += 4;
2194
2195 s = bfd_get_section_by_name (dynobj, ".got.plt");
2196 BFD_ASSERT (s != NULL);
2197 s->_raw_size += 4;
2198
2199 /* We also need to make an entry in the .rela.plt section. */
2200
2201 s = bfd_get_section_by_name (dynobj, ".rela.plt");
2202 BFD_ASSERT (s != NULL);
2203 s->_raw_size += sizeof (Elf32_External_Rela);
2204
2205 return true;
2206 }
2207
2208 /* Reinitialize the plt offset now that it is not used as a reference
2209 count any more. */
2210 h->plt.offset = (bfd_vma) -1;
2211
2212 /* If this is a weak symbol, and there is a real definition, the
2213 processor independent code will have arranged for us to see the
2214 real definition first, and we can just use the same value. */
2215 if (h->weakdef != NULL)
2216 {
2217 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2218 || h->weakdef->root.type == bfd_link_hash_defweak);
2219 h->root.u.def.section = h->weakdef->root.u.def.section;
2220 h->root.u.def.value = h->weakdef->root.u.def.value;
2221 return true;
2222 }
2223
2224 /* This is a reference to a symbol defined by a dynamic object which
2225 is not a function. */
2226
2227 /* If we are creating a shared library, we must presume that the
2228 only references to the symbol are via the global offset table.
2229 For such cases we need not do anything here; the relocations will
2230 be handled correctly by relocate_section. */
2231 if (info->shared)
2232 return true;
2233
2234 /* If there are no references to this symbol that do not use the
2235 GOT, we don't need to generate a copy reloc. */
2236 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
2237 return true;
2238
2239 /* We must allocate the symbol in our .dynbss section, which will
2240 become part of the .bss section of the executable. There will be
2241 an entry for this symbol in the .dynsym section. The dynamic
2242 object will contain position independent code, so all references
2243 from the dynamic object to this symbol will go through the global
2244 offset table. The dynamic linker will use the .dynsym entry to
2245 determine the address it must put in the global offset table, so
2246 both the dynamic object and the regular object will refer to the
2247 same memory location for the variable. */
2248
2249 s = bfd_get_section_by_name (dynobj, ".dynbss");
2250 BFD_ASSERT (s != NULL);
2251
2252 /* We must generate a R_CRIS_COPY reloc to tell the dynamic linker to
2253 copy the initial value out of the dynamic object and into the
2254 runtime process image. We need to remember the offset into the
2255 .rela.bss section we are going to use. */
2256 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2257 {
2258 asection *srel;
2259
2260 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
2261 BFD_ASSERT (srel != NULL);
2262 srel->_raw_size += sizeof (Elf32_External_Rela);
2263 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
2264 }
2265
2266 /* Historic precedent: m68k and i386 allow max 8-byte alignment for the
2267 thing to copy; so do we. */
2268
2269 /* We need to figure out the alignment required for this symbol. I
2270 have no idea how ELF linkers handle this. */
2271 power_of_two = bfd_log2 (h->size);
2272 if (power_of_two > 3)
2273 power_of_two = 3;
2274
2275 /* Apply the required alignment. */
2276 s->_raw_size = BFD_ALIGN (s->_raw_size,
2277 (bfd_size_type) (1 << power_of_two));
2278 if (power_of_two > bfd_get_section_alignment (dynobj, s))
2279 {
2280 if (!bfd_set_section_alignment (dynobj, s, power_of_two))
2281 return false;
2282 }
2283
2284 /* Define the symbol as being at this point in the section. */
2285 h->root.u.def.section = s;
2286 h->root.u.def.value = s->_raw_size;
2287
2288 /* Increment the section size to make room for the symbol. */
2289 s->_raw_size += h->size;
2290
2291 return true;
2292}
2293
2294/* Look through the relocs for a section during the first phase. */
a7c10850 2295
06c15ad7
HPN
2296static boolean
2297cris_elf_check_relocs (abfd, info, sec, relocs)
2298 bfd *abfd;
2299 struct bfd_link_info *info;
2300 asection *sec;
2301 const Elf_Internal_Rela *relocs;
2302{
915e5146 2303 bfd *dynobj;
06c15ad7
HPN
2304 Elf_Internal_Shdr *symtab_hdr;
2305 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
915e5146 2306 bfd_signed_vma *local_got_refcounts;
06c15ad7
HPN
2307 const Elf_Internal_Rela *rel;
2308 const Elf_Internal_Rela *rel_end;
915e5146
HPN
2309 asection *sgot;
2310 asection *srelgot;
2311 asection *sreloc;
a7c10850 2312
06c15ad7
HPN
2313 if (info->relocateable)
2314 return true;
a7c10850 2315
915e5146 2316 dynobj = elf_hash_table (info)->dynobj;
06c15ad7
HPN
2317 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2318 sym_hashes = elf_sym_hashes (abfd);
a7c10850 2319 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
915e5146
HPN
2320 local_got_refcounts = elf_local_got_refcounts (abfd);
2321
2322 sgot = NULL;
2323 srelgot = NULL;
2324 sreloc = NULL;
2325
06c15ad7
HPN
2326 if (!elf_bad_symtab (abfd))
2327 sym_hashes_end -= symtab_hdr->sh_info;
a7c10850 2328
06c15ad7
HPN
2329 rel_end = relocs + sec->reloc_count;
2330 for (rel = relocs; rel < rel_end; rel++)
2331 {
2332 struct elf_link_hash_entry *h;
2333 unsigned long r_symndx;
915e5146 2334 enum elf_cris_reloc_type r_type;
a7c10850 2335
06c15ad7
HPN
2336 r_symndx = ELF32_R_SYM (rel->r_info);
2337 if (r_symndx < symtab_hdr->sh_info)
2338 h = NULL;
2339 else
2340 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
a7c10850 2341
915e5146
HPN
2342 r_type = ELF32_R_TYPE (rel->r_info);
2343
2344 /* Some relocs require linker-created sections; we need to hang them
2345 on the first input bfd we found that contained dynamic relocs. */
2346 switch (r_type)
2347 {
2348 case R_CRIS_16_GOT:
2349 case R_CRIS_32_GOT:
2350 case R_CRIS_32_GOTREL:
2351 case R_CRIS_32_PLT_GOTREL:
2352 case R_CRIS_32_PLT_PCREL:
2353 case R_CRIS_16_GOTPLT:
2354 case R_CRIS_32_GOTPLT:
2355 if (dynobj == NULL)
2356 {
2357 elf_hash_table (info)->dynobj = dynobj = abfd;
2358
2359 /* Create the .got section, so we can assume it's always
2360 present whenever there's a dynobj. */
2361 if (!_bfd_elf_create_got_section (dynobj, info))
2362 return false;
2363 }
2364 break;
2365
2366 default:
2367 break;
2368 }
2369
2370 /* Some relocs require a global offset table (but perhaps not a
2371 specific GOT entry). */
4d96d128 2372 switch (r_type)
915e5146
HPN
2373 {
2374 case R_CRIS_16_GOT:
2375 case R_CRIS_32_GOT:
2376 case R_CRIS_32_GOTREL:
2377 case R_CRIS_32_PLT_GOTREL:
2378 if (sgot == NULL)
2379 sgot = bfd_get_section_by_name (dynobj, ".got");
2380
2381 if (local_got_refcounts == NULL)
2382 {
dc810e39 2383 bfd_size_type amt;
915e5146
HPN
2384
2385 /* We use index local_got_refcounts[-1] to count all
2386 GOT-relative relocations that do not have explicit
2387 GOT entries. */
dc810e39
AM
2388 amt = symtab_hdr->sh_info + 1;
2389 amt *= sizeof (bfd_signed_vma);
51b64d56 2390 local_got_refcounts = ((bfd_signed_vma *) bfd_zalloc (abfd, amt));
915e5146
HPN
2391 if (local_got_refcounts == NULL)
2392 return false;
915e5146
HPN
2393
2394 local_got_refcounts++;
2395 elf_local_got_refcounts (abfd) = local_got_refcounts;
2396 }
2397 break;
2398
2399 default:
2400 break;
2401 }
2402
4d96d128 2403 switch (r_type)
06c15ad7 2404 {
915e5146
HPN
2405 case R_CRIS_16_GOTPLT:
2406 case R_CRIS_32_GOTPLT:
2407 /* Mark that we need a GOT entry if the PLT entry (and its GOT
2408 entry) is eliminated. We can only do this for a non-local
2409 symbol. */
2410 if (h != NULL)
2411 {
2412 ((struct elf_cris_link_hash_entry *) h)->gotplt_refcount++;
2413 goto handle_gotplt_reloc;
2414 }
2415 /* If h is NULL then this is a local symbol, and we must make a
2416 GOT entry for it, so handle it like a GOT reloc. */
2417 /* Fall through. */
2418
2419 case R_CRIS_16_GOT:
2420 case R_CRIS_32_GOT:
2421 /* This symbol requires a global offset table entry. */
2422
2423 if (srelgot == NULL
2424 && (h != NULL || info->shared))
2425 {
2426 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2427 if (srelgot == NULL)
2428 {
2429 srelgot = bfd_make_section (dynobj, ".rela.got");
2430 if (srelgot == NULL
2431 || !bfd_set_section_flags (dynobj, srelgot,
2432 (SEC_ALLOC
2433 | SEC_LOAD
2434 | SEC_HAS_CONTENTS
2435 | SEC_IN_MEMORY
2436 | SEC_LINKER_CREATED
2437 | SEC_READONLY))
2438 || !bfd_set_section_alignment (dynobj, srelgot, 2))
2439 return false;
2440 }
2441 }
2442
2443 if (h != NULL)
2444 {
51b64d56 2445 if (h->got.refcount == 0)
915e5146 2446 {
915e5146
HPN
2447 /* Make sure this symbol is output as a dynamic symbol. */
2448 if (h->dynindx == -1)
2449 {
2450 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
2451 return false;
2452 }
2453
2454 /* Allocate space in the .got section. */
2455 sgot->_raw_size += 4;
2456 /* Allocate relocation space. */
2457 srelgot->_raw_size += sizeof (Elf32_External_Rela);
2458 }
51b64d56 2459 h->got.refcount++;
915e5146
HPN
2460 }
2461 else
2462 {
2463 /* This is a global offset table entry for a local symbol. */
51b64d56 2464 if (local_got_refcounts[r_symndx] == 0)
915e5146 2465 {
915e5146
HPN
2466 sgot->_raw_size += 4;
2467 if (info->shared)
2468 {
2469 /* If we are generating a shared object, we need to
2470 output a R_CRIS_RELATIVE reloc so that the dynamic
2471 linker can adjust this GOT entry. */
2472 srelgot->_raw_size += sizeof (Elf32_External_Rela);
2473 }
2474 }
51b64d56 2475 local_got_refcounts[r_symndx]++;
915e5146
HPN
2476 }
2477 break;
2478
2479 case R_CRIS_32_GOTREL:
2480 /* This reference requires a global offset table.
2481 FIXME: The actual refcount isn't used currently; the .got
2482 section can't be removed if there were any references in the
2483 input. */
2484 local_got_refcounts[-1]++;
2485 break;
2486
2487 handle_gotplt_reloc:
2488
2489 case R_CRIS_32_PLT_GOTREL:
2490 /* This reference requires a global offset table. */
2491 local_got_refcounts[-1]++;
2492 /* Fall through. */
2493
2494 case R_CRIS_32_PLT_PCREL:
2495 /* This symbol requires a procedure linkage table entry. We
2496 actually build the entry in adjust_dynamic_symbol,
2497 because this might be a case of linking PIC code which is
2498 never referenced by a dynamic object, in which case we
2499 don't need to generate a procedure linkage table entry
2500 after all. */
2501
2502 /* If this is a local symbol, we resolve it directly without
2503 creating a procedure linkage table entry. */
2504 if (h == NULL)
2505 continue;
2506
2507 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
51b64d56 2508 h->plt.refcount++;
915e5146
HPN
2509 break;
2510
2511 case R_CRIS_8:
2512 case R_CRIS_16:
2513 case R_CRIS_32:
2514 /* Let's help debug shared library creation. Any of these
2515 relocs can be used in shared libs, but pages containing them
2516 cannot be shared. Don't warn for sections we don't care
2517 about, such as debug sections or non-constant sections. We
2518 can't help tables of (global) function pointers, for example,
2519 though they must be emitted in a data section to avoid having
2520 impure text sections. */
2521 if (info->shared
2522 && (sec->flags & SEC_ALLOC) != 0
2523 && (sec->flags & SEC_READONLY) != 0)
2524 {
2525 /* FIXME: How do we make this optionally a warning only? */
8f615d07
AM
2526 (*_bfd_error_handler)
2527 (_("%s, section %s:\n relocation %s should not be used in a shared object; recompile with -fPIC"),
2528 bfd_archive_filename (abfd),
2529 sec->name,
2530 cris_elf_howto_table[r_type].name);
915e5146
HPN
2531 }
2532 /* Fall through. */
2533
2534 case R_CRIS_8_PCREL:
2535 case R_CRIS_16_PCREL:
2536 case R_CRIS_32_PCREL:
2537 if (h != NULL)
2538 {
2539 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
2540
2541 /* Make sure a plt entry is created for this symbol if it
2542 turns out to be a function defined by a dynamic object. */
51b64d56 2543 h->plt.refcount++;
915e5146
HPN
2544 }
2545
2546 /* If we are creating a shared library and this is not a local
2547 symbol, we need to copy the reloc into the shared library.
2548 However when linking with -Bsymbolic and this is a global
2549 symbol which is defined in an object we are including in the
2550 link (i.e., DEF_REGULAR is set), then we can resolve the
2551 reloc directly. At this point we have not seen all the input
2552 files, so it is possible that DEF_REGULAR is not set now but
2553 will be set later (it is never cleared). In case of a weak
2554 definition, DEF_REGULAR may be cleared later by a strong
2555 definition in a shared library. We account for that
2556 possibility below by storing information in the relocs_copied
2557 field of the hash table entry. A similar situation occurs
2558 when creating shared libraries and symbol visibility changes
2559 render the symbol local. */
2560
2561 /* No need to do anything if we're not creating a shared object. */
2562 if (! info->shared)
2563 break;
2564
2565 /* We don't need to handle relocs into sections not going into
2566 the "real" output. */
2567 if ((sec->flags & SEC_ALLOC) == 0)
2568 break;
2569
2570 /* We can only eliminate PC-relative relocs. */
2571 if (r_type == R_CRIS_8_PCREL
2572 || r_type == R_CRIS_16_PCREL
2573 || r_type == R_CRIS_32_PCREL)
2574 {
2575 /* If the symbol is local, then we can eliminate the reloc. */
2576 if (h == NULL)
2577 break;
2578
2579 /* If this is with -Bsymbolic and the symbol isn't weak, and
2580 is defined by an ordinary object (the ones we include in
2581 this shared library) then we can also eliminate the
2582 reloc. See comment above for more eliminable cases which
2583 we can't identify at this time. */
2584 if (info->symbolic
2585 && h->root.type != bfd_link_hash_defweak
2586 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
2587 break;
2588 }
2589
2590 /* We create a reloc section in dynobj and make room for this
2591 reloc. */
2592 if (sreloc == NULL)
2593 {
2594 const char *name;
2595
2596 name = (bfd_elf_string_from_elf_section
2597 (abfd,
2598 elf_elfheader (abfd)->e_shstrndx,
2599 elf_section_data (sec)->rel_hdr.sh_name));
2600 if (name == NULL)
2601 return false;
2602
2603 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
2604 && strcmp (bfd_get_section_name (abfd, sec),
2605 name + 5) == 0);
2606
2607 sreloc = bfd_get_section_by_name (dynobj, name);
2608 if (sreloc == NULL)
2609 {
2610 sreloc = bfd_make_section (dynobj, name);
2611 if (sreloc == NULL
2612 || !bfd_set_section_flags (dynobj, sreloc,
2613 (SEC_ALLOC
2614 | SEC_LOAD
2615 | SEC_HAS_CONTENTS
2616 | SEC_IN_MEMORY
2617 | SEC_LINKER_CREATED
2618 | SEC_READONLY))
2619 || !bfd_set_section_alignment (dynobj, sreloc, 2))
2620 return false;
2621 }
99e4ae17
AJ
2622 if (sec->flags & SEC_READONLY)
2623 info->flags |= DF_TEXTREL;
915e5146
HPN
2624 }
2625
2626 sreloc->_raw_size += sizeof (Elf32_External_Rela);
2627
2628 /* If we are linking with -Bsymbolic, we count the number of PC
2629 relative relocations we have entered for this symbol, so that
2630 we can discard them again if the symbol is later defined by a
2631 regular object. We know that h is really a pointer to an
2632 elf_cris_link_hash_entry. */
4d96d128
HPN
2633 if ((r_type == R_CRIS_8_PCREL
2634 || r_type == R_CRIS_16_PCREL
2635 || r_type == R_CRIS_32_PCREL)
915e5146
HPN
2636 && info->symbolic)
2637 {
2638 struct elf_cris_link_hash_entry *eh;
2639 struct elf_cris_pcrel_relocs_copied *p;
2640
2641 eh = (struct elf_cris_link_hash_entry *) h;
2642
2643 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
2644 if (p->section == sreloc)
2645 break;
2646
2647 if (p == NULL)
2648 {
2649 p = ((struct elf_cris_pcrel_relocs_copied *)
dc810e39 2650 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
915e5146
HPN
2651 if (p == NULL)
2652 return false;
2653 p->next = eh->pcrel_relocs_copied;
2654 eh->pcrel_relocs_copied = p;
2655 p->section = sreloc;
2656 p->count = 0;
2657 }
2658
2659 ++p->count;
2660 }
2661 break;
2662
06c15ad7
HPN
2663 /* This relocation describes the C++ object vtable hierarchy.
2664 Reconstruct it for later use during GC. */
2665 case R_CRIS_GNU_VTINHERIT:
2666 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2667 return false;
2668 break;
a7c10850 2669
06c15ad7
HPN
2670 /* This relocation describes which C++ vtable entries are actually
2671 used. Record for later use during GC. */
2672 case R_CRIS_GNU_VTENTRY:
2673 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2674 return false;
2675 break;
4d96d128
HPN
2676
2677 default:
2678 /* Other relocs do not appear here. */
2679 bfd_set_error (bfd_error_bad_value);
2680 return false;
06c15ad7
HPN
2681 }
2682 }
a7c10850 2683
06c15ad7
HPN
2684 return true;
2685}
4da81684 2686
915e5146
HPN
2687/* Set the sizes of the dynamic sections. */
2688
2689static boolean
2690elf_cris_size_dynamic_sections (output_bfd, info)
99e4ae17 2691 bfd *output_bfd ATTRIBUTE_UNUSED;
915e5146
HPN
2692 struct bfd_link_info *info;
2693{
2694 bfd *dynobj;
2695 asection *s;
2696 boolean plt;
2697 boolean relocs;
915e5146
HPN
2698
2699 dynobj = elf_hash_table (info)->dynobj;
2700 BFD_ASSERT (dynobj != NULL);
2701
2702 if (elf_hash_table (info)->dynamic_sections_created)
2703 {
2704 /* Set the contents of the .interp section to the interpreter. */
2705 if (!info->shared)
2706 {
2707 s = bfd_get_section_by_name (dynobj, ".interp");
2708 BFD_ASSERT (s != NULL);
2709 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
2710 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2711 }
2712 }
2713 else
2714 {
2715 /* Adjust all expected GOTPLT uses to use a GOT entry instead. */
2716 elf_cris_link_hash_traverse (elf_cris_hash_table (info),
2717 elf_cris_adjust_gotplt_to_got,
2718 (PTR) info);
2719
2720 /* We may have created entries in the .rela.got section.
2721 However, if we are not creating the dynamic sections, we will
2722 not actually use these entries. Reset the size of .rela.got,
2723 which will cause it to get stripped from the output file
2724 below. */
2725 s = bfd_get_section_by_name (dynobj, ".rela.got");
2726 if (s != NULL)
2727 s->_raw_size = 0;
2728 }
2729
2730 /* If this is a -Bsymbolic shared link, then we need to discard all PC
2731 relative relocs against symbols defined in a regular object. We
2732 allocated space for them in the check_relocs routine, but we will not
2733 fill them in in the relocate_section routine. We also discard space
2734 for relocs that have become for local symbols due to symbol
4d96d128
HPN
2735 visibility changes. For programs, we discard space for relocs for
2736 symbols not referenced by any dynamic object. */
915e5146
HPN
2737 if (info->shared)
2738 elf_cris_link_hash_traverse (elf_cris_hash_table (info),
4d96d128
HPN
2739 elf_cris_discard_excess_dso_dynamics,
2740 (PTR) info);
2741 else
2742 elf_cris_link_hash_traverse (elf_cris_hash_table (info),
2743 elf_cris_discard_excess_program_dynamics,
915e5146
HPN
2744 (PTR) info);
2745
2746 /* The check_relocs and adjust_dynamic_symbol entry points have
2747 determined the sizes of the various dynamic sections. Allocate
2748 memory for them. */
2749 plt = false;
2750 relocs = false;
915e5146
HPN
2751 for (s = dynobj->sections; s != NULL; s = s->next)
2752 {
2753 const char *name;
2754 boolean strip;
2755
2756 if ((s->flags & SEC_LINKER_CREATED) == 0)
2757 continue;
2758
2759 /* It's OK to base decisions on the section name, because none
2760 of the dynobj section names depend upon the input files. */
2761 name = bfd_get_section_name (dynobj, s);
2762
2763 strip = false;
2764
2765 if (strcmp (name, ".plt") == 0)
2766 {
2767 if (s->_raw_size == 0)
2768 {
2769 /* Strip this section if we don't need it; see the
2770 comment below. */
2771 strip = true;
2772 }
2773 else
2774 {
2775 /* Remember whether there is a PLT. */
2776 plt = true;
2777 }
2778 }
2779 else if (strncmp (name, ".rela", 5) == 0)
2780 {
2781 if (s->_raw_size == 0)
2782 {
2783 /* If we don't need this section, strip it from the
2784 output file. This is mostly to handle .rela.bss and
2785 .rela.plt. We must create both sections in
2786 create_dynamic_sections, because they must be created
2787 before the linker maps input sections to output
2788 sections. The linker does that before
2789 adjust_dynamic_symbol is called, and it is that
2790 function which decides whether anything needs to go
2791 into these sections. */
2792 strip = true;
2793 }
2794 else
2795 {
915e5146
HPN
2796 /* Remember whether there are any reloc sections other
2797 than .rela.plt. */
2798 if (strcmp (name, ".rela.plt") != 0)
915e5146
HPN
2799 relocs = true;
2800
915e5146
HPN
2801 /* We use the reloc_count field as a counter if we need
2802 to copy relocs into the output file. */
2803 s->reloc_count = 0;
2804 }
2805 }
2806 else if (strncmp (name, ".got", 4) != 0)
2807 {
2808 /* It's not one of our sections, so don't allocate space. */
2809 continue;
2810 }
2811
2812 if (strip)
2813 {
2814 _bfd_strip_section_from_output (info, s);
2815 continue;
2816 }
2817
2818 /* Allocate memory for the section contents. We use bfd_zalloc here
2819 in case unused entries are not reclaimed before the section's
2820 contents are written out. This should not happen, but this way
2821 if it does, we will not write out garbage. For reloc sections,
2822 this will make entries have the type R_CRIS_NONE. */
2823 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
2824 if (s->contents == NULL && s->_raw_size != 0)
2825 return false;
2826 }
2827
2828 if (elf_hash_table (info)->dynamic_sections_created)
2829 {
2830 /* Add some entries to the .dynamic section. We fill in the
2831 values later, in elf_cris_finish_dynamic_sections, but we
2832 must add the entries now so that we get the correct size for
2833 the .dynamic section. The DT_DEBUG entry is filled in by the
2834 dynamic linker and used by the debugger. */
dc810e39
AM
2835#define add_dynamic_entry(TAG, VAL) \
2836 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2837
915e5146
HPN
2838 if (!info->shared)
2839 {
dc810e39 2840 if (!add_dynamic_entry (DT_DEBUG, 0))
915e5146
HPN
2841 return false;
2842 }
2843
2844 if (plt)
2845 {
dc810e39
AM
2846 if (!add_dynamic_entry (DT_PLTGOT, 0)
2847 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2848 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2849 || !add_dynamic_entry (DT_JMPREL, 0))
915e5146
HPN
2850 return false;
2851 }
2852
2853 if (relocs)
2854 {
dc810e39
AM
2855 if (!add_dynamic_entry (DT_RELA, 0)
2856 || !add_dynamic_entry (DT_RELASZ, 0)
2857 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
915e5146
HPN
2858 return false;
2859 }
2860
99e4ae17 2861 if ((info->flags & DF_TEXTREL) != 0)
915e5146 2862 {
dc810e39 2863 if (!add_dynamic_entry (DT_TEXTREL, 0))
915e5146
HPN
2864 return false;
2865 info->flags |= DF_TEXTREL;
2866 }
2867 }
dc810e39 2868#undef add_dynamic_entry
915e5146
HPN
2869
2870 return true;
2871}
2872
2873/* This function is called via elf_cris_link_hash_traverse if we are
2874 creating a shared object. In the -Bsymbolic case, it discards the
2875 space allocated to copy PC relative relocs against symbols which
2876 are defined in regular objects. For the normal non-symbolic case,
2877 we also discard space for relocs that have become local due to
2878 symbol visibility changes. We allocated space for them in the
2879 check_relocs routine, but we won't fill them in in the
2880 relocate_section routine. */
2881
2882static boolean
4d96d128 2883elf_cris_discard_excess_dso_dynamics (h, inf)
915e5146
HPN
2884 struct elf_cris_link_hash_entry *h;
2885 PTR inf;
2886{
2887 struct elf_cris_pcrel_relocs_copied *s;
2888 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2889
2890 /* If a symbol has been forced local or we have found a regular
2891 definition for the symbolic link case, then we won't be needing
2892 any relocs. */
2893 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
2894 && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
2895 || info->symbolic))
2896 {
2897 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
4d96d128
HPN
2898 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
2899 }
2900
2901 return true;
2902}
2903
2904/* This function is called via elf_cris_link_hash_traverse if we are *not*
2905 creating a shared object. We discard space for relocs for symbols put
2906 in the .got, but which we found we do not have to resolve at run-time. */
2907
2908static boolean
2909elf_cris_discard_excess_program_dynamics (h, inf)
2910 struct elf_cris_link_hash_entry *h;
2911 PTR inf;
2912{
2913 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2914
2915 /* If we're not creating a shared library and have a symbol which is
2916 referred to by .got references, but the symbol is defined locally,
2917 (or rather, not referred to by a DSO and not defined by a DSO) then
2918 lose the reloc for the .got (don't allocate room for it). */
2919 if ((h->root.elf_link_hash_flags
2920 & (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_DEF_DYNAMIC)) == 0)
2921 {
2922 if (h->root.got.refcount > 0
2923 /* The size of this section is only valid and in sync with the
2924 various reference counts if we do dynamic; don't decrement it
2925 otherwise. */
2926 && elf_hash_table (info)->dynamic_sections_created)
2927 {
2928 bfd *dynobj = elf_hash_table (info)->dynobj;
2929 asection *srelgot;
2930
2931 BFD_ASSERT (dynobj != NULL);
99c79b2e 2932
4d96d128
HPN
2933 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2934
2935 BFD_ASSERT (srelgot != NULL);
2936
2937 srelgot->_raw_size -= sizeof (Elf32_External_Rela);
2938 }
2939
2940 /* If the locally-defined symbol isn't used by a DSO, then we don't
2941 have to export it as a dynamic symbol. This was already done for
2942 functions; doing this for all symbols would presumably not
2943 introduce new problems. */
2944 h->root.dynindx = -1;
915e5146
HPN
2945 }
2946
2947 return true;
2948}
2949
2950/* Reject a file depending on presence and expectation of prefixed
2951 underscores on symbols. */
4da81684
HPN
2952
2953static boolean
2954cris_elf_object_p (abfd)
2955 bfd *abfd;
2956{
2957 if ((elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE))
2958 return (bfd_get_symbol_leading_char (abfd) == '_');
2959 else
2960 return (bfd_get_symbol_leading_char (abfd) == 0);
2961}
2962
2963/* Mark presence or absence of leading underscore. */
2964
2965static void
2966cris_elf_final_write_processing (abfd, linker)
2967 bfd *abfd;
2968 boolean linker ATTRIBUTE_UNUSED;
2969{
2970 if (bfd_get_symbol_leading_char (abfd) == '_')
2971 elf_elfheader (abfd)->e_flags |= EF_CRIS_UNDERSCORE;
2972 else
2973 elf_elfheader (abfd)->e_flags &= ~EF_CRIS_UNDERSCORE;
2974}
2975
2976/* Display the flags field. */
2977
2978static boolean
2979cris_elf_print_private_bfd_data (abfd, ptr)
2980 bfd *abfd;
2981 PTR ptr;
2982{
2983 FILE *file = (FILE *) ptr;
2984
2985 BFD_ASSERT (abfd != NULL && ptr != NULL)
2986
2987 _bfd_elf_print_private_bfd_data (abfd, ptr);
2988
2989 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
2990
2991 if (elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE)
2992 fprintf (file, _(" [symbols have a _ prefix]"));
2993
2994 fputc ('\n', file);
2995 return true;
2996}
2997
2998/* Don't mix files with and without a leading underscore. */
2999
3000static boolean
3001cris_elf_merge_private_bfd_data (ibfd, obfd)
3002 bfd *ibfd;
3003 bfd *obfd;
3004{
3005 flagword old_flags, new_flags;
3006
3007 if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
3008 return false;
3009
3010 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3011 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3012 return true;
3013
3014 if (! elf_flags_init (obfd))
3015 {
3016 /* This happens when ld starts out with a 'blank' output file. */
3017 elf_flags_init (obfd) = true;
3018
3019 /* Set flags according to current bfd_target. */
3020 cris_elf_final_write_processing (obfd, false);
3021 }
3022
3023 old_flags = elf_elfheader (obfd)->e_flags;
3024 new_flags = elf_elfheader (ibfd)->e_flags;
3025
3026 /* Is this good or bad? We'll follow with other excluding flags. */
3027 if ((old_flags & EF_CRIS_UNDERSCORE) != (new_flags & EF_CRIS_UNDERSCORE))
3028 {
3029 (*_bfd_error_handler)
3030 ((new_flags & EF_CRIS_UNDERSCORE)
3031 ? _("%s: uses _-prefixed symbols, but writing file with non-prefixed symbols")
3032 : _("%s: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
8f615d07 3033 bfd_archive_filename (ibfd));
4da81684
HPN
3034 bfd_set_error (bfd_error_bad_value);
3035 return false;
3036 }
3037
3038 return true;
3039}
99e4ae17
AJ
3040
3041
3042static enum elf_reloc_type_class
f51e552e
AM
3043elf_cris_reloc_type_class (rela)
3044 const Elf_Internal_Rela *rela;
99e4ae17 3045{
f51e552e 3046 switch ((int) ELF32_R_TYPE (rela->r_info))
99e4ae17
AJ
3047 {
3048 case R_CRIS_RELATIVE:
3049 return reloc_class_relative;
3050 case R_CRIS_JUMP_SLOT:
3051 return reloc_class_plt;
3052 case R_CRIS_COPY:
3053 return reloc_class_copy;
3054 default:
3055 return reloc_class_normal;
3056 }
3057}
06c15ad7
HPN
3058\f
3059#define ELF_ARCH bfd_arch_cris
3060#define ELF_MACHINE_CODE EM_CRIS
3061#define ELF_MAXPAGESIZE 0x2000
3062
3063#define TARGET_LITTLE_SYM bfd_elf32_cris_vec
3064#define TARGET_LITTLE_NAME "elf32-cris"
4da81684 3065#define elf_symbol_leading_char 0
06c15ad7
HPN
3066
3067#define elf_info_to_howto_rel NULL
3068#define elf_info_to_howto cris_info_to_howto_rela
3069#define elf_backend_relocate_section cris_elf_relocate_section
3070#define elf_backend_gc_mark_hook cris_elf_gc_mark_hook
3071#define elf_backend_gc_sweep_hook cris_elf_gc_sweep_hook
3072#define elf_backend_check_relocs cris_elf_check_relocs
72209a1f
HPN
3073#define elf_backend_grok_prstatus cris_elf_grok_prstatus
3074#define elf_backend_grok_psinfo cris_elf_grok_psinfo
06c15ad7
HPN
3075
3076#define elf_backend_can_gc_sections 1
51b64d56 3077#define elf_backend_can_refcount 1
06c15ad7 3078
4da81684
HPN
3079#define elf_backend_object_p cris_elf_object_p
3080#define elf_backend_final_write_processing \
3081 cris_elf_final_write_processing
3082#define bfd_elf32_bfd_print_private_bfd_data \
3083 cris_elf_print_private_bfd_data
3084#define bfd_elf32_bfd_merge_private_bfd_data \
3085 cris_elf_merge_private_bfd_data
3086
06c15ad7
HPN
3087#define bfd_elf32_bfd_reloc_type_lookup cris_reloc_type_lookup
3088
915e5146
HPN
3089#define bfd_elf32_bfd_link_hash_table_create \
3090 elf_cris_link_hash_table_create
3091#define elf_backend_adjust_dynamic_symbol \
3092 elf_cris_adjust_dynamic_symbol
3093#define elf_backend_size_dynamic_sections \
3094 elf_cris_size_dynamic_sections
3095#define elf_backend_finish_dynamic_symbol \
3096 elf_cris_finish_dynamic_symbol
3097#define elf_backend_finish_dynamic_sections \
3098 elf_cris_finish_dynamic_sections
3099#define elf_backend_create_dynamic_sections \
3100 _bfd_elf_create_dynamic_sections
3101#define bfd_elf32_bfd_final_link \
3102 _bfd_elf32_gc_common_final_link
3103#define elf_backend_hide_symbol elf_cris_hide_symbol
99e4ae17 3104#define elf_backend_reloc_type_class elf_cris_reloc_type_class
915e5146
HPN
3105
3106#define elf_backend_want_got_plt 1
3107#define elf_backend_plt_readonly 1
3108#define elf_backend_want_plt_sym 0
3109#define elf_backend_got_header_size 12
3110#define elf_backend_plt_header_size PLT_ENTRY_SIZE
3111
06c15ad7
HPN
3112/* Later, we my want to optimize RELA entries into REL entries for dynamic
3113 linking and libraries (if it's a win of any significance). Until then,
3114 take the easy route. */
3115#define elf_backend_may_use_rel_p 0
3116#define elf_backend_may_use_rela_p 1
3117
3118#include "elf32-target.h"
4da81684
HPN
3119
3120#define INCLUDED_TARGET_FILE
3121
3122#undef TARGET_LITTLE_SYM
3123#undef TARGET_LITTLE_NAME
3124#undef elf_symbol_leading_char
3125
3126#define TARGET_LITTLE_SYM bfd_elf32_us_cris_vec
3127#define TARGET_LITTLE_NAME "elf32-us-cris"
3128#define elf_symbol_leading_char '_'
3129
3130#include "elf32-target.h"
This page took 0.219828 seconds and 4 git commands to generate.