Add c-format tags to translatable strings with more than one argument-using formattin...
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
1 /* CRIS-specific support for 32-bit ELF.
2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 Contributed by Axis Communications AB.
4 Written by Hans-Peter Nilsson, based on elf32-fr30.c
5 PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
6
7 This file is part of BFD, the Binary File Descriptor library.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
23
24 #include "sysdep.h"
25 #include "bfd.h"
26 #include "libbfd.h"
27 #include "elf-bfd.h"
28 #include "elf/cris.h"
29 #include <limits.h>
30
31 bfd_reloc_status_type
32 cris_elf_pcrel_reloc (bfd *, arelent *, asymbol *, void *,
33 asection *, bfd *, char **);
34 static bfd_boolean
35 cris_elf_set_mach_from_flags (bfd *, unsigned long);
36
37 /* Forward declarations. */
38 static reloc_howto_type cris_elf_howto_table [] =
39 {
40 /* This reloc does nothing. */
41 HOWTO (R_CRIS_NONE, /* type */
42 0, /* rightshift */
43 3, /* size (0 = byte, 1 = short, 2 = long) */
44 0, /* bitsize */
45 FALSE, /* pc_relative */
46 0, /* bitpos */
47 complain_overflow_dont, /* complain_on_overflow */
48 bfd_elf_generic_reloc, /* special_function */
49 "R_CRIS_NONE", /* name */
50 FALSE, /* partial_inplace */
51 0, /* src_mask */
52 0, /* dst_mask */
53 FALSE), /* pcrel_offset */
54
55 /* An 8 bit absolute relocation. */
56 HOWTO (R_CRIS_8, /* type */
57 0, /* rightshift */
58 0, /* size (0 = byte, 1 = short, 2 = long) */
59 8, /* bitsize */
60 FALSE, /* pc_relative */
61 0, /* bitpos */
62 complain_overflow_bitfield, /* complain_on_overflow */
63 bfd_elf_generic_reloc, /* special_function */
64 "R_CRIS_8", /* name */
65 FALSE, /* partial_inplace */
66 0x0000, /* src_mask */
67 0x00ff, /* dst_mask */
68 FALSE), /* pcrel_offset */
69
70 /* A 16 bit absolute relocation. */
71 HOWTO (R_CRIS_16, /* type */
72 0, /* rightshift */
73 1, /* size (0 = byte, 1 = short, 2 = long) */
74 16, /* bitsize */
75 FALSE, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_bitfield, /* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_CRIS_16", /* name */
80 FALSE, /* partial_inplace */
81 0x00000000, /* src_mask */
82 0x0000ffff, /* dst_mask */
83 FALSE), /* pcrel_offset */
84
85 /* A 32 bit absolute relocation. */
86 HOWTO (R_CRIS_32, /* type */
87 0, /* rightshift */
88 2, /* size (0 = byte, 1 = short, 2 = long) */
89 32, /* bitsize */
90 FALSE, /* pc_relative */
91 0, /* bitpos */
92 /* We don't want overflow complaints for 64-bit vma builds
93 for e.g. sym+0x40000000 (or actually sym-0xc0000000 in
94 32-bit ELF) where sym=0xc0001234.
95 Don't do this for the PIC relocs, as we don't expect to
96 see them with large offsets. */
97 complain_overflow_dont, /* complain_on_overflow */
98 bfd_elf_generic_reloc, /* special_function */
99 "R_CRIS_32", /* name */
100 FALSE, /* partial_inplace */
101 0x00000000, /* src_mask */
102 0xffffffff, /* dst_mask */
103 FALSE), /* pcrel_offset */
104
105 /* An 8 bit PC-relative relocation. */
106 HOWTO (R_CRIS_8_PCREL, /* type */
107 0, /* rightshift */
108 0, /* size (0 = byte, 1 = short, 2 = long) */
109 8, /* bitsize */
110 TRUE, /* pc_relative */
111 0, /* bitpos */
112 complain_overflow_bitfield, /* complain_on_overflow */
113 cris_elf_pcrel_reloc, /* special_function */
114 "R_CRIS_8_PCREL", /* name */
115 FALSE, /* partial_inplace */
116 0x0000, /* src_mask */
117 0x00ff, /* dst_mask */
118 TRUE), /* pcrel_offset */
119
120 /* A 16 bit PC-relative relocation. */
121 HOWTO (R_CRIS_16_PCREL, /* type */
122 0, /* rightshift */
123 1, /* size (0 = byte, 1 = short, 2 = long) */
124 16, /* bitsize */
125 TRUE, /* pc_relative */
126 0, /* bitpos */
127 complain_overflow_bitfield, /* complain_on_overflow */
128 cris_elf_pcrel_reloc, /* special_function */
129 "R_CRIS_16_PCREL", /* name */
130 FALSE, /* partial_inplace */
131 0x00000000, /* src_mask */
132 0x0000ffff, /* dst_mask */
133 TRUE), /* pcrel_offset */
134
135 /* A 32 bit PC-relative relocation. */
136 HOWTO (R_CRIS_32_PCREL, /* type */
137 0, /* rightshift */
138 2, /* size (0 = byte, 1 = short, 2 = long) */
139 32, /* bitsize */
140 TRUE, /* pc_relative */
141 0, /* bitpos */
142 complain_overflow_bitfield, /* complain_on_overflow */
143 cris_elf_pcrel_reloc, /* special_function */
144 "R_CRIS_32_PCREL", /* name */
145 FALSE, /* partial_inplace */
146 0x00000000, /* src_mask */
147 0xffffffff, /* dst_mask */
148 TRUE), /* pcrel_offset */
149
150 /* GNU extension to record C++ vtable hierarchy. */
151 HOWTO (R_CRIS_GNU_VTINHERIT, /* type */
152 0, /* rightshift */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
154 0, /* bitsize */
155 FALSE, /* pc_relative */
156 0, /* bitpos */
157 complain_overflow_dont, /* complain_on_overflow */
158 NULL, /* special_function */
159 "R_CRIS_GNU_VTINHERIT", /* name */
160 FALSE, /* partial_inplace */
161 0, /* src_mask */
162 0, /* dst_mask */
163 FALSE), /* pcrel_offset */
164
165 /* GNU extension to record C++ vtable member usage. */
166 HOWTO (R_CRIS_GNU_VTENTRY, /* type */
167 0, /* rightshift */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
169 0, /* bitsize */
170 FALSE, /* pc_relative */
171 0, /* bitpos */
172 complain_overflow_dont, /* complain_on_overflow */
173 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
174 "R_CRIS_GNU_VTENTRY", /* name */
175 FALSE, /* partial_inplace */
176 0, /* src_mask */
177 0, /* dst_mask */
178 FALSE), /* pcrel_offset */
179
180 /* This is used only by the dynamic linker. The symbol should exist
181 both in the object being run and in some shared library. The
182 dynamic linker copies the data addressed by the symbol from the
183 shared library into the object, because the object being
184 run has to have the data at some particular address. */
185 HOWTO (R_CRIS_COPY, /* type */
186 0, /* rightshift */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
188 32, /* bitsize */
189 FALSE, /* pc_relative */
190 0, /* bitpos */
191 complain_overflow_bitfield, /* complain_on_overflow */
192 bfd_elf_generic_reloc, /* special_function */
193 "R_CRIS_COPY", /* name */
194 FALSE, /* partial_inplace */
195 0, /* src_mask */
196 0, /* dst_mask */
197 FALSE), /* pcrel_offset */
198
199 /* Like R_CRIS_32, but used when setting global offset table entries. */
200 HOWTO (R_CRIS_GLOB_DAT, /* type */
201 0, /* rightshift */
202 2, /* size (0 = byte, 1 = short, 2 = long) */
203 32, /* bitsize */
204 FALSE, /* pc_relative */
205 0, /* bitpos */
206 complain_overflow_bitfield, /* complain_on_overflow */
207 bfd_elf_generic_reloc, /* special_function */
208 "R_CRIS_GLOB_DAT", /* name */
209 FALSE, /* partial_inplace */
210 0, /* src_mask */
211 0xffffffff, /* dst_mask */
212 FALSE), /* pcrel_offset */
213
214 /* Marks a procedure linkage table entry for a symbol. */
215 HOWTO (R_CRIS_JUMP_SLOT, /* type */
216 0, /* rightshift */
217 2, /* size (0 = byte, 1 = short, 2 = long) */
218 32, /* bitsize */
219 FALSE, /* pc_relative */
220 0, /* bitpos */
221 complain_overflow_bitfield, /* complain_on_overflow */
222 bfd_elf_generic_reloc, /* special_function */
223 "R_CRIS_JUMP_SLOT", /* name */
224 FALSE, /* partial_inplace */
225 0, /* src_mask */
226 0, /* dst_mask */
227 FALSE), /* pcrel_offset */
228
229 /* Used only by the dynamic linker. When the object is run, this
230 longword is set to the load address of the object, plus the
231 addend. */
232 HOWTO (R_CRIS_RELATIVE, /* type */
233 0, /* rightshift */
234 2, /* size (0 = byte, 1 = short, 2 = long) */
235 32, /* bitsize */
236 FALSE, /* pc_relative */
237 0, /* bitpos */
238 complain_overflow_bitfield, /* complain_on_overflow */
239 bfd_elf_generic_reloc, /* special_function */
240 "R_CRIS_RELATIVE", /* name */
241 FALSE, /* partial_inplace */
242 0, /* src_mask */
243 0xffffffff, /* dst_mask */
244 FALSE), /* pcrel_offset */
245
246 /* Like R_CRIS_32, but referring to the GOT table entry for the symbol. */
247 HOWTO (R_CRIS_16_GOT, /* type */
248 0, /* rightshift */
249 1, /* size (0 = byte, 1 = short, 2 = long) */
250 16, /* bitsize */
251 FALSE, /* pc_relative */
252 0, /* bitpos */
253 complain_overflow_bitfield, /* complain_on_overflow */
254 bfd_elf_generic_reloc, /* special_function */
255 "R_CRIS_16_GOT", /* name */
256 FALSE, /* partial_inplace */
257 0, /* src_mask */
258 0xffff, /* dst_mask */
259 FALSE), /* pcrel_offset */
260
261 HOWTO (R_CRIS_32_GOT, /* type */
262 0, /* rightshift */
263 2, /* size (0 = byte, 1 = short, 2 = long) */
264 32, /* bitsize */
265 FALSE, /* pc_relative */
266 0, /* bitpos */
267 complain_overflow_bitfield, /* complain_on_overflow */
268 bfd_elf_generic_reloc, /* special_function */
269 "R_CRIS_32_GOT", /* name */
270 FALSE, /* partial_inplace */
271 0, /* src_mask */
272 0xffffffff, /* dst_mask */
273 FALSE), /* pcrel_offset */
274
275 /* Like R_CRIS_32_GOT, but referring to (and requesting a) PLT part of
276 the GOT table for the symbol. */
277 HOWTO (R_CRIS_16_GOTPLT, /* type */
278 0, /* rightshift */
279 1, /* size (0 = byte, 1 = short, 2 = long) */
280 16, /* bitsize */
281 FALSE, /* pc_relative */
282 0, /* bitpos */
283 complain_overflow_bitfield, /* complain_on_overflow */
284 bfd_elf_generic_reloc, /* special_function */
285 "R_CRIS_16_GOTPLT", /* name */
286 FALSE, /* partial_inplace */
287 0, /* src_mask */
288 0xffff, /* dst_mask */
289 FALSE), /* pcrel_offset */
290
291 HOWTO (R_CRIS_32_GOTPLT, /* type */
292 0, /* rightshift */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
294 32, /* bitsize */
295 FALSE, /* pc_relative */
296 0, /* bitpos */
297 complain_overflow_bitfield, /* complain_on_overflow */
298 bfd_elf_generic_reloc, /* special_function */
299 "R_CRIS_32_GOTPLT", /* name */
300 FALSE, /* partial_inplace */
301 0, /* src_mask */
302 0xffffffff, /* dst_mask */
303 FALSE), /* pcrel_offset */
304
305 /* A 32-bit offset from GOT to (local const) symbol: no GOT entry should
306 be necessary. */
307 HOWTO (R_CRIS_32_GOTREL, /* type */
308 0, /* rightshift */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
310 32, /* bitsize */
311 FALSE, /* pc_relative */
312 0, /* bitpos */
313 complain_overflow_bitfield, /* complain_on_overflow */
314 bfd_elf_generic_reloc, /* special_function */
315 "R_CRIS_32_GOTREL", /* name */
316 FALSE, /* partial_inplace */
317 0, /* src_mask */
318 0xffffffff, /* dst_mask */
319 FALSE), /* pcrel_offset */
320
321 /* A 32-bit offset from GOT to entry for this symbol in PLT and request
322 to create PLT entry for symbol. */
323 HOWTO (R_CRIS_32_PLT_GOTREL, /* type */
324 0, /* rightshift */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
326 32, /* bitsize */
327 FALSE, /* pc_relative */
328 0, /* bitpos */
329 complain_overflow_bitfield, /* complain_on_overflow */
330 bfd_elf_generic_reloc, /* special_function */
331 "R_CRIS_32_PLT_GOTREL", /* name */
332 FALSE, /* partial_inplace */
333 0, /* src_mask */
334 0xffffffff, /* dst_mask */
335 FALSE), /* pcrel_offset */
336
337 /* A 32-bit offset from PC (location after the relocation) + addend to
338 entry for this symbol in PLT and request to create PLT entry for
339 symbol. */
340 HOWTO (R_CRIS_32_PLT_PCREL, /* type */
341 0, /* rightshift */
342 2, /* size (0 = byte, 1 = short, 2 = long) */
343 32, /* bitsize */
344 TRUE, /* pc_relative */
345 0, /* bitpos */
346 complain_overflow_bitfield, /* complain_on_overflow */
347 cris_elf_pcrel_reloc, /* special_function */
348 "R_CRIS_32_PLT_PCREL", /* name */
349 FALSE, /* partial_inplace */
350 0, /* src_mask */
351 0xffffffff, /* dst_mask */
352 TRUE), /* pcrel_offset */
353
354 /* We don't handle these in any special manner and cross-format
355 linking is not supported; just recognize them enough to pass them
356 around. FIXME: do the same for most PIC relocs and add sanity
357 tests to actually refuse gracefully to handle these and PIC
358 relocs for cross-format linking. */
359 #define TLSHOWTO32(name) \
360 HOWTO (name, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, \
361 bfd_elf_generic_reloc, #name, FALSE, 0, 0xffffffff, FALSE)
362 #define TLSHOWTO16X(name, X) \
363 HOWTO (name, 0, 1, 16, FALSE, 0, complain_overflow_ ## X, \
364 bfd_elf_generic_reloc, #name, FALSE, 0, 0xffff, FALSE)
365 #define TLSHOWTO16(name) TLSHOWTO16X(name, unsigned)
366 #define TLSHOWTO16S(name) TLSHOWTO16X(name, signed)
367
368 TLSHOWTO32 (R_CRIS_32_GOT_GD),
369 TLSHOWTO16 (R_CRIS_16_GOT_GD),
370 TLSHOWTO32 (R_CRIS_32_GD),
371 TLSHOWTO32 (R_CRIS_DTP),
372 TLSHOWTO32 (R_CRIS_32_DTPREL),
373 TLSHOWTO16S (R_CRIS_16_DTPREL),
374 TLSHOWTO32 (R_CRIS_32_GOT_TPREL),
375 TLSHOWTO16S (R_CRIS_16_GOT_TPREL),
376 TLSHOWTO32 (R_CRIS_32_TPREL),
377 TLSHOWTO16S (R_CRIS_16_TPREL),
378 TLSHOWTO32 (R_CRIS_DTPMOD),
379 TLSHOWTO32 (R_CRIS_32_IE)
380 };
381 \f
382 /* Map BFD reloc types to CRIS ELF reloc types. */
383
384 struct cris_reloc_map
385 {
386 bfd_reloc_code_real_type bfd_reloc_val;
387 unsigned int cris_reloc_val;
388 };
389
390 static const struct cris_reloc_map cris_reloc_map [] =
391 {
392 { BFD_RELOC_NONE, R_CRIS_NONE },
393 { BFD_RELOC_8, R_CRIS_8 },
394 { BFD_RELOC_16, R_CRIS_16 },
395 { BFD_RELOC_32, R_CRIS_32 },
396 { BFD_RELOC_8_PCREL, R_CRIS_8_PCREL },
397 { BFD_RELOC_16_PCREL, R_CRIS_16_PCREL },
398 { BFD_RELOC_32_PCREL, R_CRIS_32_PCREL },
399 { BFD_RELOC_VTABLE_INHERIT, R_CRIS_GNU_VTINHERIT },
400 { BFD_RELOC_VTABLE_ENTRY, R_CRIS_GNU_VTENTRY },
401 { BFD_RELOC_CRIS_COPY, R_CRIS_COPY },
402 { BFD_RELOC_CRIS_GLOB_DAT, R_CRIS_GLOB_DAT },
403 { BFD_RELOC_CRIS_JUMP_SLOT, R_CRIS_JUMP_SLOT },
404 { BFD_RELOC_CRIS_RELATIVE, R_CRIS_RELATIVE },
405 { BFD_RELOC_CRIS_16_GOT, R_CRIS_16_GOT },
406 { BFD_RELOC_CRIS_32_GOT, R_CRIS_32_GOT },
407 { BFD_RELOC_CRIS_16_GOTPLT, R_CRIS_16_GOTPLT },
408 { BFD_RELOC_CRIS_32_GOTPLT, R_CRIS_32_GOTPLT },
409 { BFD_RELOC_CRIS_32_GOTREL, R_CRIS_32_GOTREL },
410 { BFD_RELOC_CRIS_32_PLT_GOTREL, R_CRIS_32_PLT_GOTREL },
411 { BFD_RELOC_CRIS_32_PLT_PCREL, R_CRIS_32_PLT_PCREL },
412 { BFD_RELOC_CRIS_32_GOT_GD, R_CRIS_32_GOT_GD },
413 { BFD_RELOC_CRIS_16_GOT_GD, R_CRIS_16_GOT_GD },
414 { BFD_RELOC_CRIS_32_GD, R_CRIS_32_GD },
415 { BFD_RELOC_CRIS_DTP, R_CRIS_DTP },
416 { BFD_RELOC_CRIS_32_DTPREL, R_CRIS_32_DTPREL },
417 { BFD_RELOC_CRIS_16_DTPREL, R_CRIS_16_DTPREL },
418 { BFD_RELOC_CRIS_32_GOT_TPREL, R_CRIS_32_GOT_TPREL },
419 { BFD_RELOC_CRIS_16_GOT_TPREL, R_CRIS_16_GOT_TPREL },
420 { BFD_RELOC_CRIS_32_TPREL, R_CRIS_32_TPREL },
421 { BFD_RELOC_CRIS_16_TPREL, R_CRIS_16_TPREL },
422 { BFD_RELOC_CRIS_DTPMOD, R_CRIS_DTPMOD },
423 { BFD_RELOC_CRIS_32_IE, R_CRIS_32_IE }
424 };
425
426 static reloc_howto_type *
427 cris_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
428 bfd_reloc_code_real_type code)
429 {
430 unsigned int i;
431
432 for (i = 0; i < sizeof (cris_reloc_map) / sizeof (cris_reloc_map[0]); i++)
433 if (cris_reloc_map [i].bfd_reloc_val == code)
434 return & cris_elf_howto_table [cris_reloc_map[i].cris_reloc_val];
435
436 return NULL;
437 }
438
439 static reloc_howto_type *
440 cris_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
441 {
442 unsigned int i;
443
444 for (i = 0;
445 i < sizeof (cris_elf_howto_table) / sizeof (cris_elf_howto_table[0]);
446 i++)
447 if (cris_elf_howto_table[i].name != NULL
448 && strcasecmp (cris_elf_howto_table[i].name, r_name) == 0)
449 return &cris_elf_howto_table[i];
450
451 return NULL;
452 }
453
454 /* Set the howto pointer for an CRIS ELF reloc. */
455
456 static void
457 cris_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
458 arelent * cache_ptr,
459 Elf_Internal_Rela * dst)
460 {
461 enum elf_cris_reloc_type r_type;
462
463 r_type = ELF32_R_TYPE (dst->r_info);
464 if (r_type >= R_CRIS_max)
465 {
466 /* xgettext:c-format */
467 _bfd_error_handler (_("%B: invalid CRIS reloc number: %d"), abfd, r_type);
468 r_type = 0;
469 }
470 cache_ptr->howto = & cris_elf_howto_table [r_type];
471 }
472
473 bfd_reloc_status_type
474 cris_elf_pcrel_reloc (bfd *abfd ATTRIBUTE_UNUSED,
475 arelent *reloc_entry,
476 asymbol *symbol,
477 void * data ATTRIBUTE_UNUSED,
478 asection *input_section,
479 bfd *output_bfd,
480 char **error_message ATTRIBUTE_UNUSED)
481 {
482 /* By default (using only bfd_elf_generic_reloc when linking to
483 non-ELF formats) PC-relative relocs are relative to the beginning
484 of the reloc. CRIS PC-relative relocs are relative to the position
485 *after* the reloc because that's what pre-CRISv32 PC points to
486 after reading an insn field with that reloc. (For CRISv32, PC is
487 actually relative to the start of the insn, but we keep the old
488 definition.) Still, we use as much generic machinery as we can.
489
490 Only adjust when doing a final link. */
491 if (output_bfd == (bfd *) NULL)
492 reloc_entry->addend -= 1 << reloc_entry->howto->size;
493
494 return
495 bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
496 input_section, output_bfd, error_message);
497 }
498 \f
499 /* Support for core dump NOTE sections.
500 The slightly unintuitive code layout is an attempt to keep at least
501 some similarities with other ports, hoping to simplify general
502 changes, while still keeping Linux/CRIS and Linux/CRISv32 code apart. */
503
504 static bfd_boolean
505 cris_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
506 {
507 int offset;
508 size_t size;
509
510 if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
511 switch (note->descsz)
512 {
513 default:
514 return FALSE;
515
516 case 202: /* Linux/CRISv32 */
517 /* pr_cursig */
518 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
519
520 /* pr_pid */
521 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22);
522
523 /* pr_reg */
524 offset = 70;
525 size = 128;
526
527 break;
528 }
529 else
530 switch (note->descsz)
531 {
532 default:
533 return FALSE;
534
535 case 214: /* Linux/CRIS */
536 /* pr_cursig */
537 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
538
539 /* pr_pid */
540 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22);
541
542 /* pr_reg */
543 offset = 70;
544 size = 140;
545
546 break;
547 }
548
549 /* Make a ".reg/999" section. */
550 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
551 size, note->descpos + offset);
552 }
553
554 static bfd_boolean
555 cris_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
556 {
557 if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
558 switch (note->descsz)
559 {
560 default:
561 return FALSE;
562
563 case 124: /* Linux/CRISv32 elf_prpsinfo */
564 elf_tdata (abfd)->core->program
565 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
566 elf_tdata (abfd)->core->command
567 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
568 }
569 else
570 switch (note->descsz)
571 {
572 default:
573 return FALSE;
574
575 case 124: /* Linux/CRIS elf_prpsinfo */
576 elf_tdata (abfd)->core->program
577 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
578 elf_tdata (abfd)->core->command
579 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
580 }
581
582 /* Note that for some reason, a spurious space is tacked
583 onto the end of the args in some (at least one anyway)
584 implementations, so strip it off if it exists. */
585
586 {
587 char *command = elf_tdata (abfd)->core->command;
588 int n = strlen (command);
589
590 if (0 < n && command[n - 1] == ' ')
591 command[n - 1] = '\0';
592 }
593
594 return TRUE;
595 }
596 \f
597 /* The name of the dynamic interpreter. This is put in the .interp
598 section. */
599
600 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
601
602 /* The size in bytes of an entry in the procedure linkage table. */
603
604 #define PLT_ENTRY_SIZE 20
605 #define PLT_ENTRY_SIZE_V32 26
606
607 /* The first entry in an absolute procedure linkage table looks like this. */
608
609 static const bfd_byte elf_cris_plt0_entry[PLT_ENTRY_SIZE] =
610 {
611 0xfc, 0xe1,
612 0x7e, 0x7e, /* push mof. */
613 0x7f, 0x0d, /* (dip [pc+]) */
614 0, 0, 0, 0, /* Replaced with address of .got + 4. */
615 0x30, 0x7a, /* move [...],mof */
616 0x7f, 0x0d, /* (dip [pc+]) */
617 0, 0, 0, 0, /* Replaced with address of .got + 8. */
618 0x30, 0x09 /* jump [...] */
619 };
620
621 static const bfd_byte elf_cris_plt0_entry_v32[PLT_ENTRY_SIZE_V32] =
622 {
623 0x84, 0xe2, /* subq 4,$sp */
624 0x6f, 0xfe, /* move.d 0,$acr */
625 0, 0, 0, 0, /* Replaced by address of .got + 4. */
626 0x7e, 0x7a, /* move $mof,[$sp] */
627 0x3f, 0x7a, /* move [$acr],$mof */
628 0x04, 0xf2, /* addq 4,acr */
629 0x6f, 0xfa, /* move.d [$acr],$acr */
630 0xbf, 0x09, /* jump $acr */
631 0xb0, 0x05, /* nop */
632 0, 0 /* Pad out to 26 bytes. */
633 };
634
635 /* Subsequent entries in an absolute procedure linkage table look like
636 this. */
637
638 static const bfd_byte elf_cris_plt_entry[PLT_ENTRY_SIZE] =
639 {
640 0x7f, 0x0d, /* (dip [pc+]) */
641 0, 0, 0, 0, /* Replaced with address of this symbol in .got. */
642 0x30, 0x09, /* jump [...] */
643 0x3f, 0x7e, /* move [pc+],mof */
644 0, 0, 0, 0, /* Replaced with offset into relocation table. */
645 0x2f, 0xfe, /* add.d [pc+],pc */
646 0xec, 0xff,
647 0xff, 0xff /* Replaced with offset to start of .plt. */
648 };
649
650 static const bfd_byte elf_cris_plt_entry_v32[PLT_ENTRY_SIZE_V32] =
651 {
652 0x6f, 0xfe, /* move.d 0,$acr */
653 0, 0, 0, 0, /* Replaced with address of this symbol in .got. */
654 0x6f, 0xfa, /* move.d [$acr],$acr */
655 0xbf, 0x09, /* jump $acr */
656 0xb0, 0x05, /* nop */
657 0x3f, 0x7e, /* move 0,mof */
658 0, 0, 0, 0, /* Replaced with offset into relocation table. */
659 0xbf, 0x0e, /* ba start_of_plt0_entry */
660 0, 0, 0, 0, /* Replaced with offset to plt0 entry. */
661 0xb0, 0x05 /* nop */
662 };
663
664 /* The first entry in a PIC procedure linkage table looks like this. */
665
666 static const bfd_byte elf_cris_pic_plt0_entry[PLT_ENTRY_SIZE] =
667 {
668 0xfc, 0xe1, 0x7e, 0x7e, /* push mof */
669 0x04, 0x01, 0x30, 0x7a, /* move [r0+4],mof */
670 0x08, 0x01, 0x30, 0x09, /* jump [r0+8] */
671 0, 0, 0, 0, 0, 0, 0, 0, /* Pad out to 20 bytes. */
672 };
673
674 static const bfd_byte elf_cris_pic_plt0_entry_v32[PLT_ENTRY_SIZE_V32] =
675 {
676 0x84, 0xe2, /* subq 4,$sp */
677 0x04, 0x01, /* addoq 4,$r0,$acr */
678 0x7e, 0x7a, /* move $mof,[$sp] */
679 0x3f, 0x7a, /* move [$acr],$mof */
680 0x04, 0xf2, /* addq 4,$acr */
681 0x6f, 0xfa, /* move.d [$acr],$acr */
682 0xbf, 0x09, /* jump $acr */
683 0xb0, 0x05, /* nop */
684 0, 0, /* Pad out to 26 bytes. */
685 0, 0, 0, 0,
686 0, 0, 0, 0
687 };
688
689 /* Subsequent entries in a PIC procedure linkage table look like this. */
690
691 static const bfd_byte elf_cris_pic_plt_entry[PLT_ENTRY_SIZE] =
692 {
693 0x6f, 0x0d, /* (bdap [pc+].d,r0) */
694 0, 0, 0, 0, /* Replaced with offset of this symbol in .got. */
695 0x30, 0x09, /* jump [...] */
696 0x3f, 0x7e, /* move [pc+],mof */
697 0, 0, 0, 0, /* Replaced with offset into relocation table. */
698 0x2f, 0xfe, /* add.d [pc+],pc */
699 0xec, 0xff, /* Replaced with offset to start of .plt. */
700 0xff, 0xff
701 };
702
703 static const bfd_byte elf_cris_pic_plt_entry_v32[PLT_ENTRY_SIZE_V32] =
704 {
705 0x6f, 0x0d, /* addo.d 0,$r0,$acr */
706 0, 0, 0, 0, /* Replaced with offset of this symbol in .got. */
707 0x6f, 0xfa, /* move.d [$acr],$acr */
708 0xbf, 0x09, /* jump $acr */
709 0xb0, 0x05, /* nop */
710 0x3f, 0x7e, /* move relocoffs,$mof */
711 0, 0, 0, 0, /* Replaced with offset into relocation table. */
712 0xbf, 0x0e, /* ba start_of_plt */
713 0, 0, 0, 0, /* Replaced with offset to start of .plt. */
714 0xb0, 0x05 /* nop */
715 };
716 \f
717 /* We copy elf32-m68k.c and elf32-i386.c for the basic linker hash bits
718 (and most other PIC/shlib stuff). Check that we don't drift away
719 without reason.
720
721 The CRIS linker, like the m68k and i386 linkers (and probably the rest
722 too) needs to keep track of the number of relocs that it decides to
723 copy in check_relocs for each symbol. This is so that it can discard
724 PC relative relocs if it doesn't need them when linking with
725 -Bsymbolic. We store the information in a field extending the regular
726 ELF linker hash table. */
727
728 /* This structure keeps track of the number of PC relative relocs we have
729 copied for a given symbol. */
730
731 struct elf_cris_pcrel_relocs_copied
732 {
733 /* Next section. */
734 struct elf_cris_pcrel_relocs_copied *next;
735
736 /* A section in dynobj. */
737 asection *section;
738
739 /* Number of relocs copied in this section. */
740 bfd_size_type count;
741
742 /* Example of reloc being copied, for message. */
743 enum elf_cris_reloc_type r_type;
744 };
745
746 /* CRIS ELF linker hash entry. */
747
748 struct elf_cris_link_hash_entry
749 {
750 struct elf_link_hash_entry root;
751
752 /* Number of PC relative relocs copied for this symbol. */
753 struct elf_cris_pcrel_relocs_copied *pcrel_relocs_copied;
754
755 /* The GOTPLT references are CRIS-specific; the goal is to avoid having
756 both a general GOT and a PLT-specific GOT entry for the same symbol,
757 when it is referenced both as a function and as a function pointer.
758
759 Number of GOTPLT references for a function. */
760 bfd_signed_vma gotplt_refcount;
761
762 /* Actual GOTPLT index for this symbol, if applicable, or zero if not
763 (zero is never used as an index). FIXME: We should be able to fold
764 this with gotplt_refcount in a union, like the got and plt unions in
765 elf_link_hash_entry. */
766 bfd_size_type gotplt_offset;
767
768 /* The root.got.refcount is the sum of the regular reference counts
769 (this) and those members below. We have to keep a separate count
770 to track when we've found the first (or last) reference to a
771 regular got entry. The offset is in root.got.offset. */
772 bfd_signed_vma reg_got_refcount;
773
774 /* Similar to the above, the number of reloc references to this
775 symbols that need a R_CRIS_32_TPREL slot. The offset is in
776 root.got.offset, because this and .dtp_refcount can't validly
777 happen when there's also a regular GOT entry; that's invalid
778 input for which an error is emitted. */
779 bfd_signed_vma tprel_refcount;
780
781 /* Similar to the above, the number of reloc references to this
782 symbols that need a R_CRIS_DTP slot. The offset is in
783 root.got.offset; plus 4 if .tprel_refcount > 0. */
784 bfd_signed_vma dtp_refcount;
785 };
786
787 static bfd_boolean
788 elf_cris_discard_excess_dso_dynamics (struct elf_cris_link_hash_entry *,
789 void * );
790 static bfd_boolean
791 elf_cris_discard_excess_program_dynamics (struct elf_cris_link_hash_entry *,
792 void *);
793
794 /* The local_got_refcounts and local_got_offsets are a multiple of
795 LSNUM in size, namely LGOT_ALLOC_NELTS_FOR(LSNUM) (plus one for the
796 refcount for GOT itself, see code), with the summary / group offset
797 for local symbols located at offset N, reference counts for
798 ordinary (address) relocs at offset N + LSNUM, for R_CRIS_DTP
799 relocs at offset N + 2*LSNUM, and for R_CRIS_32_TPREL relocs at N +
800 3*LSNUM. */
801
802 #define LGOT_REG_NDX(x) ((x) + symtab_hdr->sh_info)
803 #define LGOT_DTP_NDX(x) ((x) + 2 * symtab_hdr->sh_info)
804 #define LGOT_TPREL_NDX(x) ((x) + 3 * symtab_hdr->sh_info)
805 #define LGOT_ALLOC_NELTS_FOR(x) ((x) * 4)
806
807 /* CRIS ELF linker hash table. */
808
809 struct elf_cris_link_hash_table
810 {
811 struct elf_link_hash_table root;
812
813 /* We can't use the PLT offset and calculate to get the GOTPLT offset,
814 since we try and avoid creating GOTPLT:s when there's already a GOT.
815 Instead, we keep and update the next available index here. */
816 bfd_size_type next_gotplt_entry;
817
818 /* The number of R_CRIS_32_DTPREL and R_CRIS_16_DTPREL that have
819 been seen for any input; if != 0, then the constant-offset
820 R_CRIS_DTPMOD is needed for this DSO/executable. This turns
821 negative at relocation, so that we don't need an extra flag for
822 when the reloc is output. */
823 bfd_signed_vma dtpmod_refcount;
824 };
825
826 /* Traverse a CRIS ELF linker hash table. */
827
828 #define elf_cris_link_hash_traverse(table, func, info) \
829 (elf_link_hash_traverse \
830 (&(table)->root, \
831 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
832 (info)))
833
834 /* Get the CRIS ELF linker hash table from a link_info structure. */
835
836 #define elf_cris_hash_table(p) \
837 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
838 == CRIS_ELF_DATA ? ((struct elf_cris_link_hash_table *) ((p)->hash)) : NULL)
839
840 /* Get the CRIS ELF linker hash entry from a regular hash entry (the
841 "parent class"). The .root reference is just a simple type
842 check on the argument. */
843
844 #define elf_cris_hash_entry(p) \
845 ((struct elf_cris_link_hash_entry *) (&(p)->root))
846
847 /* Create an entry in a CRIS ELF linker hash table. */
848
849 static struct bfd_hash_entry *
850 elf_cris_link_hash_newfunc (struct bfd_hash_entry *entry,
851 struct bfd_hash_table *table,
852 const char *string)
853 {
854 struct elf_cris_link_hash_entry *ret =
855 (struct elf_cris_link_hash_entry *) entry;
856
857 /* Allocate the structure if it has not already been allocated by a
858 subclass. */
859 if (ret == (struct elf_cris_link_hash_entry *) NULL)
860 ret = ((struct elf_cris_link_hash_entry *)
861 bfd_hash_allocate (table,
862 sizeof (struct elf_cris_link_hash_entry)));
863 if (ret == (struct elf_cris_link_hash_entry *) NULL)
864 return (struct bfd_hash_entry *) ret;
865
866 /* Call the allocation method of the superclass. */
867 ret = ((struct elf_cris_link_hash_entry *)
868 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
869 table, string));
870 if (ret != (struct elf_cris_link_hash_entry *) NULL)
871 {
872 ret->pcrel_relocs_copied = NULL;
873 ret->gotplt_refcount = 0;
874 ret->gotplt_offset = 0;
875 ret->dtp_refcount = 0;
876 ret->tprel_refcount = 0;
877 ret->reg_got_refcount = 0;
878 }
879
880 return (struct bfd_hash_entry *) ret;
881 }
882
883 /* Create a CRIS ELF linker hash table. */
884
885 static struct bfd_link_hash_table *
886 elf_cris_link_hash_table_create (bfd *abfd)
887 {
888 struct elf_cris_link_hash_table *ret;
889 bfd_size_type amt = sizeof (struct elf_cris_link_hash_table);
890
891 ret = ((struct elf_cris_link_hash_table *) bfd_zmalloc (amt));
892 if (ret == (struct elf_cris_link_hash_table *) NULL)
893 return NULL;
894
895 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
896 elf_cris_link_hash_newfunc,
897 sizeof (struct elf_cris_link_hash_entry),
898 CRIS_ELF_DATA))
899 {
900 free (ret);
901 return NULL;
902 }
903
904 /* Initialize to skip over the first three entries in the gotplt; they
905 are used for run-time symbol evaluation. */
906 ret->next_gotplt_entry = 12;
907
908 return &ret->root.root;
909 }
910 \f
911 /* Perform a single relocation. By default we use the standard BFD
912 routines, with a few tweaks. */
913
914 static bfd_reloc_status_type
915 cris_final_link_relocate (reloc_howto_type * howto,
916 bfd * input_bfd,
917 asection * input_section,
918 bfd_byte * contents,
919 Elf_Internal_Rela * rel,
920 bfd_vma relocation)
921 {
922 bfd_reloc_status_type r;
923 enum elf_cris_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
924
925 /* PC-relative relocations are relative to the position *after*
926 the reloc. Note that for R_CRIS_8_PCREL the adjustment is
927 not a single byte, since PC must be 16-bit-aligned. */
928 switch (r_type)
929 {
930 /* Check that the 16-bit GOT relocs are positive. */
931 case R_CRIS_16_GOTPLT:
932 case R_CRIS_16_GOT:
933 if ((bfd_signed_vma) relocation < 0)
934 return bfd_reloc_overflow;
935 break;
936
937 case R_CRIS_32_PLT_PCREL:
938 case R_CRIS_32_PCREL:
939 relocation -= 2;
940 /* Fall through. */
941 case R_CRIS_8_PCREL:
942 case R_CRIS_16_PCREL:
943 relocation -= 2;
944 break;
945
946 default:
947 break;
948 }
949
950 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
951 contents, rel->r_offset,
952 relocation, rel->r_addend);
953 return r;
954 }
955 \f
956
957 /* The number of errors left before we stop outputting reloc-specific
958 explanatory messages. By coincidence, this works nicely together
959 with the default number of messages you'll get from LD about
960 "relocation truncated to fit" messages before you get an
961 "additional relocation overflows omitted from the output". */
962 static int additional_relocation_error_msg_count = 10;
963
964 /* Relocate an CRIS ELF section. See elf32-fr30.c, from where this was
965 copied, for further comments. */
966
967 static bfd_boolean
968 cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
969 struct bfd_link_info *info,
970 bfd *input_bfd,
971 asection *input_section,
972 bfd_byte *contents,
973 Elf_Internal_Rela *relocs,
974 Elf_Internal_Sym *local_syms,
975 asection **local_sections)
976 {
977 struct elf_cris_link_hash_table * htab;
978 bfd *dynobj;
979 Elf_Internal_Shdr *symtab_hdr;
980 struct elf_link_hash_entry **sym_hashes;
981 bfd_vma *local_got_offsets;
982 asection *sgot;
983 asection *splt;
984 asection *sreloc;
985 Elf_Internal_Rela *rel;
986 Elf_Internal_Rela *relend;
987 asection *srelgot;
988
989 htab = elf_cris_hash_table (info);
990 if (htab == NULL)
991 return FALSE;
992
993 dynobj = elf_hash_table (info)->dynobj;
994 local_got_offsets = elf_local_got_offsets (input_bfd);
995 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
996 sym_hashes = elf_sym_hashes (input_bfd);
997 relend = relocs + input_section->reloc_count;
998
999 sgot = NULL;
1000 splt = NULL;
1001 sreloc = NULL;
1002 srelgot = NULL;
1003
1004 if (dynobj != NULL)
1005 {
1006 splt = bfd_get_linker_section (dynobj, ".plt");
1007 sgot = bfd_get_linker_section (dynobj, ".got");
1008 }
1009
1010 for (rel = relocs; rel < relend; rel ++)
1011 {
1012 reloc_howto_type *howto;
1013 unsigned long r_symndx;
1014 Elf_Internal_Sym *sym;
1015 asection *sec;
1016 struct elf_link_hash_entry *h;
1017 bfd_vma relocation;
1018 bfd_reloc_status_type r;
1019 const char *symname = NULL;
1020 enum elf_cris_reloc_type r_type;
1021
1022 r_type = ELF32_R_TYPE (rel->r_info);
1023
1024 if ( r_type == R_CRIS_GNU_VTINHERIT
1025 || r_type == R_CRIS_GNU_VTENTRY)
1026 continue;
1027
1028 r_symndx = ELF32_R_SYM (rel->r_info);
1029 howto = cris_elf_howto_table + r_type;
1030 h = NULL;
1031 sym = NULL;
1032 sec = NULL;
1033
1034 if (r_symndx < symtab_hdr->sh_info)
1035 {
1036 sym = local_syms + r_symndx;
1037 sec = local_sections [r_symndx];
1038 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1039
1040 symname = (bfd_elf_string_from_elf_section
1041 (input_bfd, symtab_hdr->sh_link, sym->st_name));
1042 if (symname == NULL)
1043 symname = bfd_section_name (input_bfd, sec);
1044 }
1045 else
1046 {
1047 bfd_boolean warned, ignored;
1048 bfd_boolean unresolved_reloc;
1049
1050 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1051 r_symndx, symtab_hdr, sym_hashes,
1052 h, sec, relocation,
1053 unresolved_reloc, warned, ignored);
1054
1055 symname = h->root.root.string;
1056
1057 if (unresolved_reloc
1058 /* Perhaps we should detect the cases that
1059 sec->output_section is expected to be NULL like i386 and
1060 m68k, but apparently (and according to elfxx-ia64.c) all
1061 valid cases are where the symbol is defined in a shared
1062 object which we link dynamically against. This includes
1063 PLT relocs for which we've created a PLT entry and other
1064 relocs for which we're prepared to create dynamic
1065 relocations.
1066
1067 For now, new situations cause us to just err when
1068 sec->output_offset is NULL but the object with the symbol
1069 is *not* dynamically linked against. Thus this will
1070 automatically remind us so we can see if there are other
1071 valid cases we need to revisit. */
1072 && (sec->owner->flags & DYNAMIC) != 0)
1073 relocation = 0;
1074
1075 else if (h->root.type == bfd_link_hash_defined
1076 || h->root.type == bfd_link_hash_defweak)
1077 {
1078 /* Here follow the cases where the relocation value must
1079 be zero (or when further handling is simplified when
1080 zero). I can't claim to understand the various
1081 conditions and they weren't described in the files
1082 where I copied them from (elf32-m68k.c and
1083 elf32-i386.c), but let's mention examples of where
1084 they happen. FIXME: Perhaps define and use a
1085 dynamic_symbol_p function like ia64.
1086
1087 - When creating a shared library, we can have an
1088 ordinary relocation for a symbol defined in a shared
1089 library (perhaps the one we create). We then make
1090 the relocation value zero, as the value seen now will
1091 be added into the relocation addend in this shared
1092 library, but must be handled only at dynamic-link
1093 time. FIXME: Not sure this example covers the
1094 h->elf_link_hash_flags test, though it's there in
1095 other targets. */
1096 if (bfd_link_pic (info)
1097 && ((!SYMBOLIC_BIND (info, h) && h->dynindx != -1)
1098 || !h->def_regular)
1099 && (input_section->flags & SEC_ALLOC) != 0
1100 && (r_type == R_CRIS_8
1101 || r_type == R_CRIS_16
1102 || r_type == R_CRIS_32
1103 || r_type == R_CRIS_8_PCREL
1104 || r_type == R_CRIS_16_PCREL
1105 || r_type == R_CRIS_32_PCREL))
1106 relocation = 0;
1107 else if (!bfd_link_relocatable (info) && unresolved_reloc
1108 && (_bfd_elf_section_offset (output_bfd, info,
1109 input_section,
1110 rel->r_offset)
1111 != (bfd_vma) -1))
1112 {
1113 _bfd_error_handler
1114 /* xgettext:c-format */
1115 (_("%B, section %A: unresolvable relocation %s against symbol `%s'"),
1116 input_bfd,
1117 input_section,
1118 cris_elf_howto_table[r_type].name,
1119 symname);
1120 bfd_set_error (bfd_error_bad_value);
1121 return FALSE;
1122 }
1123 }
1124 }
1125
1126 if (sec != NULL && discarded_section (sec))
1127 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1128 rel, 1, relend, howto, 0, contents);
1129
1130 if (bfd_link_relocatable (info))
1131 continue;
1132
1133 switch (r_type)
1134 {
1135 case R_CRIS_16_GOTPLT:
1136 case R_CRIS_32_GOTPLT:
1137 /* This is like the case for R_CRIS_32_GOT and R_CRIS_16_GOT,
1138 but we require a PLT, and the PLT handling will take care of
1139 filling in the PLT-specific GOT entry. For the GOT offset,
1140 calculate it as we do when filling it in for the .got.plt
1141 section. If we don't have a PLT, punt to GOT handling. */
1142 if (h != NULL
1143 && ((struct elf_cris_link_hash_entry *) h)->gotplt_offset != 0)
1144 {
1145 asection *sgotplt
1146 = bfd_get_linker_section (dynobj, ".got.plt");
1147 bfd_vma got_offset;
1148
1149 BFD_ASSERT (h->dynindx != -1);
1150 BFD_ASSERT (sgotplt != NULL);
1151
1152 got_offset
1153 = ((struct elf_cris_link_hash_entry *) h)->gotplt_offset;
1154
1155 relocation = got_offset;
1156 break;
1157 }
1158
1159 /* We didn't make a PLT entry for this symbol. Maybe everything is
1160 folded into the GOT. Other than folding, this happens when
1161 statically linking PIC code, or when using -Bsymbolic. Check
1162 that we instead have a GOT entry as done for us by
1163 elf_cris_adjust_dynamic_symbol, and drop through into the
1164 ordinary GOT cases. This must not happen for the
1165 executable, because any reference it does to a function
1166 that is satisfied by a DSO must generate a PLT. We assume
1167 these call-specific relocs don't address non-functions. */
1168 if (h != NULL
1169 && (h->got.offset == (bfd_vma) -1
1170 || (!bfd_link_pic (info)
1171 && !(h->def_regular
1172 || (!h->def_dynamic
1173 && h->root.type == bfd_link_hash_undefweak)))))
1174 {
1175 _bfd_error_handler
1176 ((h->got.offset == (bfd_vma) -1)
1177 /* xgettext:c-format */
1178 ? _("%B, section %A: No PLT nor GOT for relocation %s"
1179 " against symbol `%s'")
1180 /* xgettext:c-format */
1181 : _("%B, section %A: No PLT for relocation %s"
1182 " against symbol `%s'"),
1183 input_bfd,
1184 input_section,
1185 cris_elf_howto_table[r_type].name,
1186 (symname != NULL && symname[0] != '\0'
1187 ? symname : _("[whose name is lost]")));
1188
1189 /* FIXME: Perhaps blaming input is not the right thing to
1190 do; this is probably an internal error. But it is true
1191 that we didn't like that particular input. */
1192 bfd_set_error (bfd_error_bad_value);
1193 return FALSE;
1194 }
1195 /* Fall through. */
1196
1197 /* The size of the actual relocation is not used here; we only
1198 fill in the GOT table here. */
1199 case R_CRIS_16_GOT:
1200 case R_CRIS_32_GOT:
1201 {
1202 bfd_vma off;
1203
1204 /* Note that despite using RELA relocations, the .got contents
1205 is always filled in with the link-relative relocation
1206 value; the addend. */
1207
1208 if (h != NULL)
1209 {
1210 off = h->got.offset;
1211 BFD_ASSERT (off != (bfd_vma) -1);
1212
1213 if (!elf_hash_table (info)->dynamic_sections_created
1214 || (! bfd_link_pic (info)
1215 && (h->def_regular
1216 || h->type == STT_FUNC
1217 || h->needs_plt))
1218 || (bfd_link_pic (info)
1219 && (SYMBOLIC_BIND (info, h) || h->dynindx == -1)
1220 && h->def_regular))
1221 {
1222 /* This wasn't checked above for ! bfd_link_pic (info), but
1223 must hold there if we get here; the symbol must
1224 be defined in the regular program or be undefweak
1225 or be a function or otherwise need a PLT. */
1226 BFD_ASSERT (!elf_hash_table (info)->dynamic_sections_created
1227 || bfd_link_pic (info)
1228 || h->def_regular
1229 || h->type == STT_FUNC
1230 || h->needs_plt
1231 || h->root.type == bfd_link_hash_undefweak);
1232
1233 /* This is actually a static link, or it is a
1234 -Bsymbolic link and the symbol is defined locally,
1235 or is undefweak, or the symbol was forced to be
1236 local because of a version file, or we're not
1237 creating a dynamic object. We must initialize this
1238 entry in the global offset table. Since the offset
1239 must always be a multiple of 4, we use the least
1240 significant bit to record whether we have
1241 initialized it already.
1242
1243 If this GOT entry should be runtime-initialized, we
1244 will create a .rela.got relocation entry to
1245 initialize the value. This is done in the
1246 finish_dynamic_symbol routine. */
1247 if ((off & 1) != 0)
1248 off &= ~1;
1249 else
1250 {
1251 bfd_put_32 (output_bfd, relocation,
1252 sgot->contents + off);
1253 h->got.offset |= 1;
1254 }
1255 }
1256 }
1257 else
1258 {
1259 BFD_ASSERT (local_got_offsets != NULL
1260 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1261
1262 off = local_got_offsets[r_symndx];
1263
1264 /* The offset must always be a multiple of 4. We use
1265 the least significant bit to record whether we have
1266 already generated the necessary reloc. */
1267 if ((off & 1) != 0)
1268 off &= ~1;
1269 else
1270 {
1271 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1272
1273 if (bfd_link_pic (info))
1274 {
1275 Elf_Internal_Rela outrel;
1276 bfd_byte *loc;
1277
1278 if (srelgot == NULL)
1279 srelgot
1280 = bfd_get_linker_section (dynobj, ".rela.got");
1281 BFD_ASSERT (srelgot != NULL);
1282
1283 outrel.r_offset = (sgot->output_section->vma
1284 + sgot->output_offset
1285 + off);
1286 outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
1287 outrel.r_addend = relocation;
1288 loc = srelgot->contents;
1289 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
1290 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1291 }
1292
1293 local_got_offsets[r_symndx] |= 1;
1294 }
1295 }
1296
1297 relocation = sgot->output_offset + off;
1298 if (rel->r_addend != 0)
1299 {
1300 /* We can't do anything for a relocation which is against
1301 a symbol *plus offset*. GOT holds relocations for
1302 symbols. Make this an error; the compiler isn't
1303 allowed to pass us these kinds of things. */
1304 if (h == NULL)
1305 _bfd_error_handler
1306 /* xgettext:c-format */
1307 (_("%B, section %A: relocation %s with non-zero addend %d"
1308 " against local symbol"),
1309 input_bfd,
1310 input_section,
1311 cris_elf_howto_table[r_type].name,
1312 rel->r_addend);
1313 else
1314 _bfd_error_handler
1315 /* xgettext:c-format */
1316 (_("%B, section %A: relocation %s with non-zero addend %d"
1317 " against symbol `%s'"),
1318 input_bfd,
1319 input_section,
1320 cris_elf_howto_table[r_type].name,
1321 rel->r_addend,
1322 symname[0] != '\0' ? symname : _("[whose name is lost]"));
1323
1324 bfd_set_error (bfd_error_bad_value);
1325 return FALSE;
1326 }
1327 }
1328 break;
1329
1330 case R_CRIS_32_GOTREL:
1331 /* This relocation must only be performed against local symbols.
1332 It's also ok when we link a program and the symbol is either
1333 defined in an ordinary (non-DSO) object or is undefined weak. */
1334 if (h != NULL
1335 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1336 && !(!bfd_link_pic (info)
1337 && (h->def_regular
1338 || (!h->def_dynamic
1339 && h->root.type == bfd_link_hash_undefweak))))
1340 {
1341 _bfd_error_handler
1342 /* xgettext:c-format */
1343 (_("%B, section %A: relocation %s is"
1344 " not allowed for global symbol: `%s'"),
1345 input_bfd,
1346 input_section,
1347 cris_elf_howto_table[r_type].name,
1348 symname);
1349 bfd_set_error (bfd_error_bad_value);
1350 return FALSE;
1351 }
1352
1353 /* This can happen if we get a link error with the input ELF
1354 variant mismatching the output variant. Emit an error so
1355 it's noticed if it happens elsewhere. */
1356 if (sgot == NULL)
1357 {
1358 _bfd_error_handler
1359 /* xgettext:c-format */
1360 (_("%B, section %A: relocation %s with no GOT created"),
1361 input_bfd,
1362 input_section,
1363 cris_elf_howto_table[r_type].name);
1364 bfd_set_error (bfd_error_bad_value);
1365 return FALSE;
1366 }
1367
1368 /* This relocation is like a PC-relative one, except the
1369 reference point is the location of GOT. Note that
1370 sgot->output_offset is not involved in this calculation. We
1371 always want the start of entire .got section, not the
1372 position after the reserved header. */
1373 relocation -= sgot->output_section->vma;
1374 break;
1375
1376 case R_CRIS_32_PLT_PCREL:
1377 /* Relocation is to the entry for this symbol in the
1378 procedure linkage table. */
1379
1380 /* Resolve a PLT_PCREL reloc against a local symbol directly,
1381 without using the procedure linkage table. */
1382 if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
1383 break;
1384
1385 if (h->plt.offset == (bfd_vma) -1
1386 || splt == NULL)
1387 {
1388 /* We didn't make a PLT entry for this symbol. This
1389 happens when statically linking PIC code, or when
1390 using -Bsymbolic. */
1391 break;
1392 }
1393
1394 relocation = (splt->output_section->vma
1395 + splt->output_offset
1396 + h->plt.offset);
1397 break;
1398
1399 case R_CRIS_32_PLT_GOTREL:
1400 /* Like R_CRIS_32_PLT_PCREL, but the reference point is the
1401 start of the .got section. See also comment at
1402 R_CRIS_32_GOT. */
1403 relocation -= sgot->output_section->vma;
1404
1405 /* Resolve a PLT_GOTREL reloc against a local symbol directly,
1406 without using the procedure linkage table. */
1407 if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
1408 break;
1409
1410 if (h->plt.offset == (bfd_vma) -1
1411 || splt == NULL)
1412 {
1413 /* We didn't make a PLT entry for this symbol. This
1414 happens when statically linking PIC code, or when
1415 using -Bsymbolic. */
1416 break;
1417 }
1418
1419 relocation = (splt->output_section->vma
1420 + splt->output_offset
1421 + h->plt.offset
1422 - sgot->output_section->vma);
1423 break;
1424
1425 case R_CRIS_8_PCREL:
1426 case R_CRIS_16_PCREL:
1427 case R_CRIS_32_PCREL:
1428 /* If the symbol was local, we need no shlib-specific handling. */
1429 if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1430 || h->dynindx == -1)
1431 break;
1432
1433 /* Fall through. */
1434 case R_CRIS_8:
1435 case R_CRIS_16:
1436 case R_CRIS_32:
1437 if (bfd_link_pic (info)
1438 && r_symndx != STN_UNDEF
1439 && (input_section->flags & SEC_ALLOC) != 0
1440 && ((r_type != R_CRIS_8_PCREL
1441 && r_type != R_CRIS_16_PCREL
1442 && r_type != R_CRIS_32_PCREL)
1443 || (!SYMBOLIC_BIND (info, h)
1444 || (h != NULL && !h->def_regular))))
1445 {
1446 Elf_Internal_Rela outrel;
1447 bfd_byte *loc;
1448 bfd_boolean skip, relocate;
1449
1450 /* When generating a shared object, these relocations
1451 are copied into the output file to be resolved at run
1452 time. */
1453
1454 if (sreloc == NULL)
1455 {
1456 sreloc = _bfd_elf_get_dynamic_reloc_section
1457 (dynobj, input_section, /*rela?*/ TRUE);
1458 /* The section should have been created in cris_elf_check_relocs,
1459 but that function will not be called for objects which fail in
1460 cris_elf_merge_private_bfd_data. */
1461 if (sreloc == NULL)
1462 {
1463 bfd_set_error (bfd_error_bad_value);
1464 return FALSE;
1465 }
1466 }
1467
1468 skip = FALSE;
1469 relocate = FALSE;
1470
1471 outrel.r_offset =
1472 _bfd_elf_section_offset (output_bfd, info, input_section,
1473 rel->r_offset);
1474 if (outrel.r_offset == (bfd_vma) -1)
1475 skip = TRUE;
1476 else if (outrel.r_offset == (bfd_vma) -2
1477 /* For now, undefined weak symbols with non-default
1478 visibility (yielding 0), like exception info for
1479 discarded sections, will get a R_CRIS_NONE
1480 relocation rather than no relocation, because we
1481 notice too late that the symbol doesn't need a
1482 relocation. */
1483 || (h != NULL
1484 && h->root.type == bfd_link_hash_undefweak
1485 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT))
1486 skip = TRUE, relocate = TRUE;
1487 outrel.r_offset += (input_section->output_section->vma
1488 + input_section->output_offset);
1489
1490 if (skip)
1491 memset (&outrel, 0, sizeof outrel);
1492 /* h->dynindx may be -1 if the symbol was marked to
1493 become local. */
1494 else if (h != NULL
1495 && ((!SYMBOLIC_BIND (info, h) && h->dynindx != -1)
1496 || !h->def_regular))
1497 {
1498 BFD_ASSERT (h->dynindx != -1);
1499 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1500 outrel.r_addend = relocation + rel->r_addend;
1501 }
1502 else
1503 {
1504 outrel.r_addend = relocation + rel->r_addend;
1505
1506 if (r_type == R_CRIS_32)
1507 {
1508 relocate = TRUE;
1509 outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
1510 }
1511 else
1512 {
1513 long indx;
1514
1515 if (bfd_is_abs_section (sec))
1516 indx = 0;
1517 else if (sec == NULL || sec->owner == NULL)
1518 {
1519 bfd_set_error (bfd_error_bad_value);
1520 return FALSE;
1521 }
1522 else
1523 {
1524 asection *osec;
1525
1526 /* We are turning this relocation into one
1527 against a section symbol. It would be
1528 proper to subtract the symbol's value,
1529 osec->vma, from the emitted reloc addend,
1530 but ld.so expects buggy relocs. */
1531 osec = sec->output_section;
1532 indx = elf_section_data (osec)->dynindx;
1533 if (indx == 0)
1534 {
1535 osec = htab->root.text_index_section;
1536 indx = elf_section_data (osec)->dynindx;
1537 }
1538 BFD_ASSERT (indx != 0);
1539 }
1540
1541 outrel.r_info = ELF32_R_INFO (indx, r_type);
1542 }
1543 }
1544
1545 loc = sreloc->contents;
1546 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1547 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1548
1549 /* This reloc will be computed at runtime, so there's no
1550 need to do anything now, except for R_CRIS_32 relocations
1551 that have been turned into R_CRIS_RELATIVE. */
1552 if (!relocate)
1553 continue;
1554 }
1555
1556 break;
1557
1558 case R_CRIS_16_DTPREL:
1559 case R_CRIS_32_DTPREL:
1560 /* This relocation must only be performed against local
1561 symbols, or to sections that are not loadable. It's also
1562 ok when we link a program and the symbol is defined in an
1563 ordinary (non-DSO) object (if it's undefined there, we've
1564 already seen an error). */
1565 if (h != NULL
1566 && (input_section->flags & SEC_ALLOC) != 0
1567 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1568 && (bfd_link_pic (info)
1569 || (!h->def_regular
1570 && h->root.type != bfd_link_hash_undefined)))
1571 {
1572 _bfd_error_handler
1573 ((h->root.type == bfd_link_hash_undefined)
1574 /* We shouldn't get here for GCC-emitted code. */
1575 /* xgettext:c-format */
1576 ? _("%B, section %A: relocation %s has an undefined"
1577 " reference to `%s', perhaps a declaration mixup?")
1578 /* xgettext:c-format */
1579 : _("%B, section %A: relocation %s is"
1580 " not allowed for `%s', a global symbol with default"
1581 " visibility, perhaps a declaration mixup?"),
1582 input_bfd,
1583 input_section,
1584 cris_elf_howto_table[r_type].name,
1585 symname != NULL && symname[0] != '\0'
1586 ? symname : _("[whose name is lost]"));
1587 bfd_set_error (bfd_error_bad_value);
1588 return FALSE;
1589 }
1590
1591 BFD_ASSERT ((input_section->flags & SEC_ALLOC) == 0
1592 || htab->dtpmod_refcount != 0);
1593
1594 /* Fill in a R_CRIS_DTPMOD reloc at offset 3 if we haven't
1595 already done so. Note that we do this in .got.plt, not
1596 in .got, as .got.plt contains the first part, still the
1597 reloc is against .got, because the linker script directs
1598 (is required to direct) them both into .got. */
1599 if (htab->dtpmod_refcount > 0
1600 && (input_section->flags & SEC_ALLOC) != 0)
1601 {
1602 asection *sgotplt = bfd_get_linker_section (dynobj, ".got.plt");
1603 BFD_ASSERT (sgotplt != NULL);
1604
1605 if (bfd_link_pic (info))
1606 {
1607 Elf_Internal_Rela outrel;
1608 bfd_byte *loc;
1609
1610 if (srelgot == NULL)
1611 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
1612 BFD_ASSERT (srelgot != NULL);
1613 loc = srelgot->contents;
1614 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
1615
1616 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 12);
1617 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 16);
1618 outrel.r_offset = (sgotplt->output_section->vma
1619 + sgotplt->output_offset
1620 + 12);
1621 outrel.r_info = ELF32_R_INFO (0, R_CRIS_DTPMOD);
1622 outrel.r_addend = 0;
1623 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1624 }
1625 else
1626 {
1627 /* For an executable, the GOT entry contents is known. */
1628 bfd_put_32 (output_bfd, (bfd_vma) 1, sgotplt->contents + 12);
1629 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 16);
1630 }
1631
1632 /* Reverse the sign to mark that we've emitted the
1633 required GOT entry. */
1634 htab->dtpmod_refcount = - htab->dtpmod_refcount;
1635 }
1636
1637 /* The relocation is the offset from the start of the module
1638 TLS block to the (local) symbol. */
1639 relocation -= elf_hash_table (info)->tls_sec == NULL
1640 ? 0 : elf_hash_table (info)->tls_sec->vma;
1641 break;
1642
1643 case R_CRIS_32_GD:
1644 if (bfd_link_pic (info))
1645 {
1646 bfd_set_error (bfd_error_invalid_operation);
1647
1648 /* We've already informed in cris_elf_check_relocs that
1649 this is an error. */
1650 return FALSE;
1651 }
1652 /* Fall through. */
1653
1654 case R_CRIS_16_GOT_GD:
1655 case R_CRIS_32_GOT_GD:
1656 if (rel->r_addend != 0)
1657 {
1658 /* We can't do anything for a relocation which is against a
1659 symbol *plus offset*. The GOT holds relocations for
1660 symbols. Make this an error; the compiler isn't allowed
1661 to pass us these kinds of things. */
1662 _bfd_error_handler
1663 /* xgettext:c-format */
1664 (_("%B, section %A: relocation %s with non-zero addend %d"
1665 " against symbol `%s'"),
1666 input_bfd,
1667 input_section,
1668 cris_elf_howto_table[r_type].name,
1669 rel->r_addend,
1670 symname[0] != '\0' ? symname : _("[whose name is lost]"));
1671
1672 bfd_set_error (bfd_error_bad_value);
1673 return FALSE;
1674 }
1675
1676 if (!bfd_link_pic (info)
1677 && (h == NULL || h->def_regular || ELF_COMMON_DEF_P (h)))
1678 {
1679 /* Known contents of the GOT. */
1680 bfd_vma off;
1681
1682 /* The symbol is defined in the program, so just write
1683 (1, known_tpoffset) into the GOT. */
1684 relocation -= elf_hash_table (info)->tls_sec->vma;
1685
1686 if (h != NULL)
1687 {
1688 off = elf_cris_hash_entry (h)->tprel_refcount > 0
1689 ? h->got.offset + 4 : h->got.offset;
1690 }
1691 else
1692 {
1693 off = local_got_offsets[r_symndx];
1694 if (local_got_offsets[LGOT_TPREL_NDX (r_symndx)])
1695 off += 4;
1696 }
1697
1698 /* We use bit 1 of the offset as a flag for GOT entry with
1699 the R_CRIS_DTP reloc, setting it when we've emitted the
1700 GOT entry and reloc. Bit 0 is used for R_CRIS_32_TPREL
1701 relocs. */
1702 if ((off & 2) == 0)
1703 {
1704 off &= ~3;
1705
1706 if (h != NULL)
1707 h->got.offset |= 2;
1708 else
1709 local_got_offsets[r_symndx] |= 2;
1710
1711 bfd_put_32 (output_bfd, 1, sgot->contents + off);
1712 bfd_put_32 (output_bfd, relocation, sgot->contents + off + 4);
1713 }
1714 else
1715 off &= ~3;
1716
1717 relocation = sgot->output_offset + off
1718 + (r_type == R_CRIS_32_GD ? sgot->output_section->vma : 0);
1719 }
1720 else
1721 {
1722 /* Not all parts of the GOT entry are known; emit a real
1723 relocation. */
1724 bfd_vma off;
1725
1726 if (h != NULL)
1727 off = elf_cris_hash_entry (h)->tprel_refcount > 0
1728 ? h->got.offset + 4 : h->got.offset;
1729 else
1730 {
1731 off = local_got_offsets[r_symndx];
1732 if (local_got_offsets[LGOT_TPREL_NDX (r_symndx)])
1733 off += 4;
1734 }
1735
1736 /* See above re bit 1 and bit 0 usage. */
1737 if ((off & 2) == 0)
1738 {
1739 Elf_Internal_Rela outrel;
1740 bfd_byte *loc;
1741
1742 off &= ~3;
1743
1744 if (h != NULL)
1745 h->got.offset |= 2;
1746 else
1747 local_got_offsets[r_symndx] |= 2;
1748
1749 /* Clear the target contents of the GOT (just as a
1750 gesture; it's already cleared on allocation): this
1751 relocation is not like the other dynrelocs. */
1752 bfd_put_32 (output_bfd, 0, sgot->contents + off);
1753 bfd_put_32 (output_bfd, 0, sgot->contents + off + 4);
1754
1755 if (srelgot == NULL)
1756 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
1757 BFD_ASSERT (srelgot != NULL);
1758
1759 if (h != NULL && h->dynindx != -1)
1760 {
1761 outrel.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_DTP);
1762 relocation = 0;
1763 }
1764 else
1765 {
1766 outrel.r_info = ELF32_R_INFO (0, R_CRIS_DTP);
1767
1768 /* NULL if we had an error. */
1769 relocation -= elf_hash_table (info)->tls_sec == NULL
1770 ? 0 : elf_hash_table (info)->tls_sec->vma;
1771 }
1772
1773 outrel.r_offset = (sgot->output_section->vma
1774 + sgot->output_offset
1775 + off);
1776 outrel.r_addend = relocation;
1777 loc = srelgot->contents;
1778 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
1779
1780 /* NULL if we had an error. */
1781 if (srelgot->contents != NULL)
1782 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1783 }
1784 else
1785 off &= ~3;
1786
1787 relocation = sgot->output_offset + off
1788 + (r_type == R_CRIS_32_GD ? sgot->output_section->vma : 0);
1789 }
1790
1791 /* The GOT-relative offset to the GOT entry is the
1792 relocation, or for R_CRIS_32_GD, the actual address of
1793 the GOT entry. */
1794 break;
1795
1796 case R_CRIS_32_IE:
1797 if (bfd_link_pic (info))
1798 {
1799 bfd_set_error (bfd_error_invalid_operation);
1800
1801 /* We've already informed in cris_elf_check_relocs that
1802 this is an error. */
1803 return FALSE;
1804 }
1805 /* Fall through. */
1806
1807 case R_CRIS_32_GOT_TPREL:
1808 case R_CRIS_16_GOT_TPREL:
1809 if (rel->r_addend != 0)
1810 {
1811 /* We can't do anything for a relocation which is
1812 against a symbol *plus offset*. GOT holds
1813 relocations for symbols. Make this an error; the
1814 compiler isn't allowed to pass us these kinds of
1815 things. */
1816 _bfd_error_handler
1817 /* xgettext:c-format */
1818 (_("%B, section %A: relocation %s with non-zero addend %d"
1819 " against symbol `%s'"),
1820 input_bfd,
1821 input_section,
1822 cris_elf_howto_table[r_type].name,
1823 rel->r_addend,
1824 symname[0] != '\0' ? symname : _("[whose name is lost]"));
1825 bfd_set_error (bfd_error_bad_value);
1826 return FALSE;
1827 }
1828
1829 if (!bfd_link_pic (info)
1830 && (h == NULL || h->def_regular || ELF_COMMON_DEF_P (h)))
1831 {
1832 /* Known contents of the GOT. */
1833 bfd_vma off;
1834
1835 /* The symbol is defined in the program, so just write
1836 the -prog_tls_size+known_tpoffset into the GOT. */
1837 relocation -= elf_hash_table (info)->tls_sec->vma;
1838 relocation -= elf_hash_table (info)->tls_size;
1839
1840 if (h != NULL)
1841 off = h->got.offset;
1842 else
1843 off = local_got_offsets[r_symndx];
1844
1845 /* Bit 0 is used to mark whether we've emitted the required
1846 entry (and if needed R_CRIS_32_TPREL reloc). Bit 1
1847 is used similarly for R_CRIS_DTP, see above. */
1848 if ((off & 1) == 0)
1849 {
1850 off &= ~3;
1851
1852 if (h != NULL)
1853 h->got.offset |= 1;
1854 else
1855 local_got_offsets[r_symndx] |= 1;
1856
1857 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1858 }
1859 else
1860 off &= ~3;
1861
1862 relocation = sgot->output_offset + off
1863 + (r_type == R_CRIS_32_IE ? sgot->output_section->vma : 0);
1864 }
1865 else
1866 {
1867 /* Emit a real relocation. */
1868 bfd_vma off;
1869
1870 if (h != NULL)
1871 off = h->got.offset;
1872 else
1873 off = local_got_offsets[r_symndx];
1874
1875 /* See above re usage of bit 0 and 1. */
1876 if ((off & 1) == 0)
1877 {
1878 Elf_Internal_Rela outrel;
1879 bfd_byte *loc;
1880
1881 off &= ~3;
1882
1883 if (h != NULL)
1884 h->got.offset |= 1;
1885 else
1886 local_got_offsets[r_symndx] |= 1;
1887
1888 if (srelgot == NULL)
1889 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
1890 BFD_ASSERT (srelgot != NULL);
1891
1892 if (h != NULL && h->dynindx != -1)
1893 {
1894 outrel.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_32_TPREL);
1895 relocation = 0;
1896 }
1897 else
1898 {
1899 outrel.r_info = ELF32_R_INFO (0, R_CRIS_32_TPREL);
1900
1901 /* NULL if we had an error. */
1902 relocation -= elf_hash_table (info)->tls_sec == NULL
1903 ? 0 : elf_hash_table (info)->tls_sec->vma;
1904 }
1905
1906 /* Just "define" the initial contents in some
1907 semi-logical way. */
1908 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1909
1910 outrel.r_offset = (sgot->output_section->vma
1911 + sgot->output_offset
1912 + off);
1913 outrel.r_addend = relocation;
1914 loc = srelgot->contents;
1915 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
1916 /* NULL if we had an error. */
1917 if (srelgot->contents != NULL)
1918 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1919 }
1920 else
1921 off &= ~3;
1922
1923 relocation = sgot->output_offset + off
1924 + (r_type == R_CRIS_32_IE ? sgot->output_section->vma : 0);
1925 }
1926
1927 /* The GOT-relative offset to the GOT entry is the relocation,
1928 or for R_CRIS_32_GD, the actual address of the GOT entry. */
1929 break;
1930
1931 case R_CRIS_16_TPREL:
1932 case R_CRIS_32_TPREL:
1933 /* This relocation must only be performed against symbols
1934 defined in an ordinary (non-DSO) object. */
1935 if (bfd_link_pic (info))
1936 {
1937 bfd_set_error (bfd_error_invalid_operation);
1938
1939 /* We've already informed in cris_elf_check_relocs that
1940 this is an error. */
1941 return FALSE;
1942 }
1943
1944 if (h != NULL
1945 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1946 && !(h->def_regular || ELF_COMMON_DEF_P (h))
1947 /* If it's undefined, then an error message has already
1948 been emitted. */
1949 && h->root.type != bfd_link_hash_undefined)
1950 {
1951 _bfd_error_handler
1952 /* xgettext:c-format */
1953 (_("%B, section %A: relocation %s is"
1954 " not allowed for symbol: `%s'"
1955 " which is defined outside the program,"
1956 " perhaps a declaration mixup?"),
1957 input_bfd,
1958 input_section,
1959 cris_elf_howto_table[r_type].name,
1960 symname);
1961 bfd_set_error (bfd_error_bad_value);
1962 return FALSE;
1963 }
1964
1965 /* NULL if we had an error. */
1966 relocation -= elf_hash_table (info)->tls_sec == NULL
1967 ? 0
1968 : (elf_hash_table (info)->tls_sec->vma
1969 + elf_hash_table (info)->tls_size);
1970
1971 /* The TLS-relative offset is the relocation. */
1972 break;
1973
1974 default:
1975 BFD_FAIL ();
1976 return FALSE;
1977 }
1978
1979 r = cris_final_link_relocate (howto, input_bfd, input_section,
1980 contents, rel, relocation);
1981
1982 if (r != bfd_reloc_ok)
1983 {
1984 const char * msg = (const char *) NULL;
1985
1986 switch (r)
1987 {
1988 case bfd_reloc_overflow:
1989 (*info->callbacks->reloc_overflow)
1990 (info, (h ? &h->root : NULL), symname, howto->name,
1991 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1992 if (additional_relocation_error_msg_count > 0)
1993 {
1994 additional_relocation_error_msg_count--;
1995 switch (r_type)
1996 {
1997 case R_CRIS_16_GOTPLT:
1998 case R_CRIS_16_GOT:
1999
2000 /* Not just TLS is involved here, so we make
2001 generation and message depend on -fPIC/-fpic
2002 only. */
2003 case R_CRIS_16_GOT_TPREL:
2004 case R_CRIS_16_GOT_GD:
2005 _bfd_error_handler
2006 (_("(too many global variables for -fpic:"
2007 " recompile with -fPIC)"));
2008 break;
2009
2010 case R_CRIS_16_TPREL:
2011 case R_CRIS_16_DTPREL:
2012 _bfd_error_handler
2013 (_("(thread-local data too big for -fpic or"
2014 " -msmall-tls: recompile with -fPIC or"
2015 " -mno-small-tls)"));
2016 break;
2017
2018 /* No known cause for overflow for other relocs. */
2019 default:
2020 break;
2021 }
2022 }
2023 break;
2024
2025 case bfd_reloc_undefined:
2026 (*info->callbacks->undefined_symbol)
2027 (info, symname, input_bfd, input_section, rel->r_offset, TRUE);
2028 break;
2029
2030 case bfd_reloc_outofrange:
2031 msg = _("internal error: out of range error");
2032 break;
2033
2034 case bfd_reloc_notsupported:
2035 msg = _("internal error: unsupported relocation error");
2036 break;
2037
2038 case bfd_reloc_dangerous:
2039 msg = _("internal error: dangerous relocation");
2040 break;
2041
2042 default:
2043 msg = _("internal error: unknown error");
2044 break;
2045 }
2046
2047 if (msg)
2048 (*info->callbacks->warning) (info, msg, symname, input_bfd,
2049 input_section, rel->r_offset);
2050 }
2051 }
2052
2053 return TRUE;
2054 }
2055 \f
2056 /* Finish up dynamic symbol handling. We set the contents of various
2057 dynamic sections here. */
2058
2059 static bfd_boolean
2060 elf_cris_finish_dynamic_symbol (bfd *output_bfd,
2061 struct bfd_link_info *info,
2062 struct elf_link_hash_entry *h,
2063 Elf_Internal_Sym *sym)
2064 {
2065 struct elf_cris_link_hash_table * htab;
2066 bfd *dynobj;
2067
2068 /* Where in the plt entry to put values. */
2069 int plt_off1 = 2, plt_off2 = 10, plt_off3 = 16;
2070
2071 /* What offset to add to the distance to the first PLT entry for the
2072 value at plt_off3. */
2073 int plt_off3_value_bias = 4;
2074
2075 /* Where in the PLT entry the call-dynlink-stub is (happens to be same
2076 for PIC and non-PIC for v32 and pre-v32). */
2077 int plt_stub_offset = 8;
2078 int plt_entry_size = PLT_ENTRY_SIZE;
2079 const bfd_byte *plt_entry = elf_cris_plt_entry;
2080 const bfd_byte *plt_pic_entry = elf_cris_pic_plt_entry;
2081
2082 htab = elf_cris_hash_table (info);
2083 if (htab == NULL)
2084 return FALSE;
2085
2086 /* Adjust the various PLT entry offsets. */
2087 if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32)
2088 {
2089 plt_off2 = 14;
2090 plt_off3 = 20;
2091 plt_off3_value_bias = -2;
2092 plt_stub_offset = 12;
2093 plt_entry_size = PLT_ENTRY_SIZE_V32;
2094 plt_entry = elf_cris_plt_entry_v32;
2095 plt_pic_entry = elf_cris_pic_plt_entry_v32;
2096 }
2097
2098 dynobj = elf_hash_table (info)->dynobj;
2099
2100 if (h->plt.offset != (bfd_vma) -1)
2101 {
2102 asection *splt;
2103 asection *sgotplt;
2104 asection *srela;
2105 bfd_vma got_base;
2106
2107 bfd_vma gotplt_offset
2108 = elf_cris_hash_entry (h)->gotplt_offset;
2109 Elf_Internal_Rela rela;
2110 bfd_byte *loc;
2111 bfd_boolean has_gotplt = gotplt_offset != 0;
2112
2113 /* Get the index in the .rela.plt relocations for the .got.plt
2114 entry that corresponds to this symbol.
2115 We have to count backwards here, and the result is only valid
2116 as an index into .rela.plt. We also have to undo the effect
2117 of the R_CRIS_DTPMOD entry at .got index 3 (offset 12 into
2118 .got.plt) for which gotplt_offset is adjusted, because while
2119 that entry goes into .got.plt, its relocation goes into
2120 .rela.got, not .rela.plt. (It's not PLT-specific; not to be
2121 processed as part of the runtime lazy .rela.plt relocation).
2122 FIXME: There be literal constants here... */
2123 bfd_vma rela_plt_index
2124 = (htab->dtpmod_refcount != 0
2125 ? gotplt_offset/4 - 2 - 3 : gotplt_offset/4 - 3);
2126
2127 /* Get the offset into the .got table of the entry that corresponds
2128 to this function. Note that we embed knowledge that "incoming"
2129 .got goes after .got.plt in the output without padding (pointer
2130 aligned). However, that knowledge is present in several other
2131 places too. */
2132 bfd_vma got_offset
2133 = (has_gotplt
2134 ? gotplt_offset
2135 : h->got.offset + htab->next_gotplt_entry);
2136
2137 /* This symbol has an entry in the procedure linkage table. Set it
2138 up. */
2139
2140 BFD_ASSERT (h->dynindx != -1);
2141
2142 splt = bfd_get_linker_section (dynobj, ".plt");
2143 sgotplt = bfd_get_linker_section (dynobj, ".got.plt");
2144 srela = bfd_get_linker_section (dynobj, ".rela.plt");
2145 BFD_ASSERT (splt != NULL && sgotplt != NULL
2146 && (! has_gotplt || srela != NULL));
2147
2148 got_base = sgotplt->output_section->vma + sgotplt->output_offset;
2149
2150 /* Fill in the entry in the procedure linkage table. */
2151 if (! bfd_link_pic (info))
2152 {
2153 memcpy (splt->contents + h->plt.offset, plt_entry,
2154 plt_entry_size);
2155
2156 /* We need to enter the absolute address of the GOT entry here. */
2157 bfd_put_32 (output_bfd, got_base + got_offset,
2158 splt->contents + h->plt.offset + plt_off1);
2159 }
2160 else
2161 {
2162 memcpy (splt->contents + h->plt.offset, plt_pic_entry,
2163 plt_entry_size);
2164 bfd_put_32 (output_bfd, got_offset,
2165 splt->contents + h->plt.offset + plt_off1);
2166 }
2167
2168 /* Fill in the plt entry and make a relocation, if this is a "real"
2169 PLT entry. */
2170 if (has_gotplt)
2171 {
2172 /* Fill in the offset to the reloc table. */
2173 bfd_put_32 (output_bfd,
2174 rela_plt_index * sizeof (Elf32_External_Rela),
2175 splt->contents + h->plt.offset + plt_off2);
2176
2177 /* Fill in the offset to the first PLT entry, where to "jump". */
2178 bfd_put_32 (output_bfd,
2179 - (h->plt.offset + plt_off3 + plt_off3_value_bias),
2180 splt->contents + h->plt.offset + plt_off3);
2181
2182 /* Fill in the entry in the global offset table with the address of
2183 the relocating stub. */
2184 bfd_put_32 (output_bfd,
2185 (splt->output_section->vma
2186 + splt->output_offset
2187 + h->plt.offset
2188 + plt_stub_offset),
2189 sgotplt->contents + got_offset);
2190
2191 /* Fill in the entry in the .rela.plt section. */
2192 rela.r_offset = (sgotplt->output_section->vma
2193 + sgotplt->output_offset
2194 + got_offset);
2195 rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_JUMP_SLOT);
2196 rela.r_addend = 0;
2197 loc = srela->contents + rela_plt_index * sizeof (Elf32_External_Rela);
2198 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2199 }
2200
2201 if (!h->def_regular)
2202 {
2203 /* Mark the symbol as undefined, rather than as defined in
2204 the .plt section. Leave the value alone. */
2205 sym->st_shndx = SHN_UNDEF;
2206
2207 /* FIXME: From elf32-sparc.c 2001-02-19 (1.18). I still don't
2208 know whether resetting the value is significant; if it really
2209 is, rather than a quirk or bug in the sparc port, then I
2210 believe we'd see this elsewhere. */
2211 /* If the symbol is weak, we do need to clear the value.
2212 Otherwise, the PLT entry would provide a definition for
2213 the symbol even if the symbol wasn't defined anywhere,
2214 and so the symbol would never be NULL. */
2215 if (!h->ref_regular_nonweak)
2216 sym->st_value = 0;
2217 }
2218 }
2219
2220 /* For an ordinary program, we emit .got relocs only for symbols that
2221 are in the dynamic-symbols table and are either defined by the
2222 program or are undefined weak symbols, or are function symbols
2223 where we do not output a PLT: the PLT reloc was output above and all
2224 references to the function symbol are redirected to the PLT. */
2225 if (h->got.offset != (bfd_vma) -1
2226 && (elf_cris_hash_entry (h)->reg_got_refcount > 0)
2227 && (bfd_link_pic (info)
2228 || (h->dynindx != -1
2229 && h->plt.offset == (bfd_vma) -1
2230 && !h->def_regular
2231 && h->root.type != bfd_link_hash_undefweak)))
2232 {
2233 asection *sgot;
2234 asection *srela;
2235 Elf_Internal_Rela rela;
2236 bfd_byte *loc;
2237 bfd_byte *where;
2238
2239 /* This symbol has an entry in the global offset table. Set it up. */
2240
2241 sgot = bfd_get_linker_section (dynobj, ".got");
2242 srela = bfd_get_linker_section (dynobj, ".rela.got");
2243 BFD_ASSERT (sgot != NULL && srela != NULL);
2244
2245 rela.r_offset = (sgot->output_section->vma
2246 + sgot->output_offset
2247 + (h->got.offset &~ (bfd_vma) 1));
2248
2249 /* If this is a static link, or it is a -Bsymbolic link and the
2250 symbol is defined locally or was forced to be local because
2251 of a version file, we just want to emit a RELATIVE reloc.
2252 The entry in the global offset table will already have been
2253 initialized in the relocate_section function. */
2254 where = sgot->contents + (h->got.offset &~ (bfd_vma) 1);
2255 if (! elf_hash_table (info)->dynamic_sections_created
2256 || (bfd_link_pic (info)
2257 && (SYMBOLIC_BIND (info, h) || h->dynindx == -1)
2258 && h->def_regular))
2259 {
2260 rela.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
2261 rela.r_addend = bfd_get_signed_32 (output_bfd, where);
2262 }
2263 else
2264 {
2265 bfd_put_32 (output_bfd, (bfd_vma) 0, where);
2266 rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_GLOB_DAT);
2267 rela.r_addend = 0;
2268 }
2269
2270 loc = srela->contents;
2271 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
2272 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2273 }
2274
2275 if (h->needs_copy)
2276 {
2277 asection *s;
2278 Elf_Internal_Rela rela;
2279 bfd_byte *loc;
2280
2281 /* This symbol needs a copy reloc. Set it up. */
2282
2283 BFD_ASSERT (h->dynindx != -1
2284 && (h->root.type == bfd_link_hash_defined
2285 || h->root.type == bfd_link_hash_defweak));
2286
2287 s = bfd_get_linker_section (dynobj, ".rela.bss");
2288 BFD_ASSERT (s != NULL);
2289
2290 rela.r_offset = (h->root.u.def.value
2291 + h->root.u.def.section->output_section->vma
2292 + h->root.u.def.section->output_offset);
2293 rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_COPY);
2294 rela.r_addend = 0;
2295 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
2296 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2297 }
2298
2299 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2300 if (h == elf_hash_table (info)->hdynamic
2301 || h == elf_hash_table (info)->hgot)
2302 sym->st_shndx = SHN_ABS;
2303
2304 return TRUE;
2305 }
2306 \f
2307 /* Finish up the dynamic sections. Do *not* emit relocs here, as their
2308 offsets were changed, as part of -z combreloc handling, from those we
2309 computed. */
2310
2311 static bfd_boolean
2312 elf_cris_finish_dynamic_sections (bfd *output_bfd,
2313 struct bfd_link_info *info)
2314 {
2315 bfd *dynobj;
2316 asection *sgot;
2317 asection *sdyn;
2318
2319 dynobj = elf_hash_table (info)->dynobj;
2320
2321 sgot = bfd_get_linker_section (dynobj, ".got.plt");
2322 BFD_ASSERT (sgot != NULL);
2323 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
2324
2325 if (elf_hash_table (info)->dynamic_sections_created)
2326 {
2327 asection *splt;
2328 Elf32_External_Dyn *dyncon, *dynconend;
2329
2330 splt = bfd_get_linker_section (dynobj, ".plt");
2331 BFD_ASSERT (splt != NULL && sdyn != NULL);
2332
2333 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2334 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
2335 for (; dyncon < dynconend; dyncon++)
2336 {
2337 Elf_Internal_Dyn dyn;
2338 asection *s;
2339
2340 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2341
2342 switch (dyn.d_tag)
2343 {
2344 default:
2345 break;
2346
2347 case DT_PLTGOT:
2348 dyn.d_un.d_ptr = sgot->output_section->vma + sgot->output_offset;
2349 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2350 break;
2351
2352 case DT_JMPREL:
2353 /* Yes, we *can* have a .plt and no .plt.rela, for instance
2354 if all symbols are found in the .got (not .got.plt). */
2355 s = bfd_get_linker_section (dynobj, ".rela.plt");
2356 dyn.d_un.d_ptr = s != NULL ? (s->output_section->vma
2357 + s->output_offset) : 0;
2358 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2359 break;
2360
2361 case DT_PLTRELSZ:
2362 s = bfd_get_linker_section (dynobj, ".rela.plt");
2363 if (s == NULL)
2364 dyn.d_un.d_val = 0;
2365 else
2366 dyn.d_un.d_val = s->size;
2367 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2368 break;
2369
2370 case DT_RELASZ:
2371 /* The procedure linkage table relocs (DT_JMPREL) should
2372 not be included in the overall relocs (DT_RELA).
2373 Therefore, we override the DT_RELASZ entry here to
2374 make it not include the JMPREL relocs. Since the
2375 linker script arranges for .rela.plt to follow all
2376 other relocation sections, we don't have to worry
2377 about changing the DT_RELA entry. */
2378 s = bfd_get_linker_section (dynobj, ".rela.plt");
2379 if (s != NULL)
2380 dyn.d_un.d_val -= s->size;
2381 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2382 break;
2383 }
2384 }
2385
2386 /* Fill in the first entry in the procedure linkage table. */
2387 if (splt->size > 0)
2388 {
2389 if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32)
2390 {
2391 if (bfd_link_pic (info))
2392 memcpy (splt->contents, elf_cris_pic_plt0_entry_v32,
2393 PLT_ENTRY_SIZE_V32);
2394 else
2395 {
2396 memcpy (splt->contents, elf_cris_plt0_entry_v32,
2397 PLT_ENTRY_SIZE_V32);
2398 bfd_put_32 (output_bfd,
2399 sgot->output_section->vma
2400 + sgot->output_offset + 4,
2401 splt->contents + 4);
2402
2403 elf_section_data (splt->output_section)->this_hdr.sh_entsize
2404 = PLT_ENTRY_SIZE_V32;
2405 }
2406 }
2407 else
2408 {
2409 if (bfd_link_pic (info))
2410 memcpy (splt->contents, elf_cris_pic_plt0_entry,
2411 PLT_ENTRY_SIZE);
2412 else
2413 {
2414 memcpy (splt->contents, elf_cris_plt0_entry,
2415 PLT_ENTRY_SIZE);
2416 bfd_put_32 (output_bfd,
2417 sgot->output_section->vma
2418 + sgot->output_offset + 4,
2419 splt->contents + 6);
2420 bfd_put_32 (output_bfd,
2421 sgot->output_section->vma
2422 + sgot->output_offset + 8,
2423 splt->contents + 14);
2424
2425 elf_section_data (splt->output_section)->this_hdr.sh_entsize
2426 = PLT_ENTRY_SIZE;
2427 }
2428 }
2429 }
2430 }
2431
2432 /* Fill in the first three entries in the global offset table. */
2433 if (sgot->size > 0)
2434 {
2435 if (sdyn == NULL)
2436 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2437 else
2438 bfd_put_32 (output_bfd,
2439 sdyn->output_section->vma + sdyn->output_offset,
2440 sgot->contents);
2441 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
2442 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
2443 }
2444
2445 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2446
2447 return TRUE;
2448 }
2449 \f
2450 /* Return the section that should be marked against GC for a given
2451 relocation. */
2452
2453 static asection *
2454 cris_elf_gc_mark_hook (asection *sec,
2455 struct bfd_link_info *info,
2456 Elf_Internal_Rela *rel,
2457 struct elf_link_hash_entry *h,
2458 Elf_Internal_Sym *sym)
2459 {
2460 enum elf_cris_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
2461 if (h != NULL)
2462 switch (r_type)
2463 {
2464 case R_CRIS_GNU_VTINHERIT:
2465 case R_CRIS_GNU_VTENTRY:
2466 return NULL;
2467
2468 default:
2469 break;
2470 }
2471
2472 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2473 }
2474
2475 /* Update the got entry reference counts for the section being removed. */
2476
2477 static bfd_boolean
2478 cris_elf_gc_sweep_hook (bfd *abfd,
2479 struct bfd_link_info *info,
2480 asection *sec,
2481 const Elf_Internal_Rela *relocs)
2482 {
2483 struct elf_cris_link_hash_table * htab;
2484 Elf_Internal_Shdr *symtab_hdr;
2485 struct elf_link_hash_entry **sym_hashes;
2486 bfd_signed_vma *local_got_refcounts;
2487 const Elf_Internal_Rela *rel, *relend;
2488 bfd *dynobj;
2489 asection *sgot;
2490 asection *srelgot;
2491
2492 if (bfd_link_relocatable (info))
2493 return TRUE;
2494
2495 dynobj = elf_hash_table (info)->dynobj;
2496 if (dynobj == NULL)
2497 return TRUE;
2498
2499 htab = elf_cris_hash_table (info);
2500 if (htab == NULL)
2501 return FALSE;
2502
2503 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2504 sym_hashes = elf_sym_hashes (abfd);
2505 local_got_refcounts = elf_local_got_refcounts (abfd);
2506
2507 sgot = bfd_get_linker_section (dynobj, ".got");
2508 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
2509
2510 relend = relocs + sec->reloc_count;
2511 for (rel = relocs; rel < relend; rel++)
2512 {
2513 unsigned long r_symndx;
2514 struct elf_link_hash_entry *h = NULL;
2515 bfd_signed_vma got_element_size = 4;
2516 bfd_signed_vma *specific_refcount = NULL;
2517 enum elf_cris_reloc_type r_type;
2518
2519 r_symndx = ELF32_R_SYM (rel->r_info);
2520 if (r_symndx >= symtab_hdr->sh_info)
2521 {
2522 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2523 while (h->root.type == bfd_link_hash_indirect
2524 || h->root.type == bfd_link_hash_warning)
2525 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2526 }
2527
2528 r_type = ELF32_R_TYPE (rel->r_info);
2529 switch (r_type)
2530 {
2531 case R_CRIS_32_GOT:
2532 case R_CRIS_16_GOT:
2533 case R_CRIS_16_GOTPLT:
2534 case R_CRIS_32_GOTPLT:
2535 specific_refcount = h != NULL
2536 ? &((struct elf_cris_link_hash_entry *) h)->reg_got_refcount
2537 : &local_got_refcounts[LGOT_REG_NDX (r_symndx)];
2538 break;
2539
2540 case R_CRIS_32_GD:
2541 case R_CRIS_32_GOT_GD:
2542 case R_CRIS_16_GOT_GD:
2543 got_element_size = 8;
2544 specific_refcount = h != NULL
2545 ? &((struct elf_cris_link_hash_entry *) h)->dtp_refcount
2546 : &local_got_refcounts[LGOT_DTP_NDX (r_symndx)];
2547 break;
2548
2549 case R_CRIS_32_IE:
2550 case R_CRIS_16_GOT_TPREL:
2551 case R_CRIS_32_GOT_TPREL:
2552 specific_refcount = h != NULL
2553 ? &((struct elf_cris_link_hash_entry *) h)->tprel_refcount
2554 : &local_got_refcounts[LGOT_TPREL_NDX (r_symndx)];
2555 break;
2556
2557 default:
2558 break;
2559 }
2560
2561 switch (r_type)
2562 {
2563 case R_CRIS_32_IE:
2564 case R_CRIS_32_GD:
2565 case R_CRIS_16_GOT_TPREL:
2566 case R_CRIS_32_GOT_TPREL:
2567 case R_CRIS_32_GOT_GD:
2568 case R_CRIS_16_GOT_GD:
2569 case R_CRIS_16_GOT:
2570 case R_CRIS_32_GOT:
2571 if (h != NULL)
2572 {
2573 /* If the counters are 0 when we got here, we've
2574 miscounted somehow somewhere, an internal error. */
2575 BFD_ASSERT (h->got.refcount > 0);
2576 --h->got.refcount;
2577
2578 BFD_ASSERT (*specific_refcount > 0);
2579 --*specific_refcount;
2580 if (*specific_refcount == 0)
2581 {
2582 /* We don't need the .got entry any more. */
2583 sgot->size -= got_element_size;
2584 srelgot->size -= sizeof (Elf32_External_Rela);
2585 }
2586 break;
2587 }
2588
2589 local_got_reloc:
2590 if (local_got_refcounts != NULL)
2591 {
2592 /* If the counters are 0 when we got here, we've
2593 miscounted somehow somewhere, an internal error. */
2594 BFD_ASSERT (local_got_refcounts[r_symndx] > 0);
2595 --local_got_refcounts[r_symndx];
2596
2597 BFD_ASSERT (*specific_refcount > 0);
2598 --*specific_refcount;
2599 if (*specific_refcount == 0)
2600 {
2601 /* We don't need the .got entry any more. */
2602 sgot->size -= got_element_size;
2603 if (bfd_link_pic (info))
2604 srelgot->size -= sizeof (Elf32_External_Rela);
2605 }
2606 }
2607 break;
2608
2609 case R_CRIS_16_GOTPLT:
2610 case R_CRIS_32_GOTPLT:
2611 /* For local symbols, treat these like GOT relocs. */
2612 if (h == NULL)
2613 goto local_got_reloc;
2614 else
2615 /* For global symbols, adjust the reloc-specific refcount. */
2616 elf_cris_hash_entry (h)->gotplt_refcount--;
2617 /* Fall through. */
2618
2619 case R_CRIS_32_PLT_GOTREL:
2620 /* FIXME: We don't garbage-collect away the .got section. */
2621 if (local_got_refcounts != NULL)
2622 local_got_refcounts[-1]--;
2623 /* Fall through. */
2624
2625 case R_CRIS_8:
2626 case R_CRIS_16:
2627 case R_CRIS_32:
2628 case R_CRIS_8_PCREL:
2629 case R_CRIS_16_PCREL:
2630 case R_CRIS_32_PCREL:
2631 case R_CRIS_32_PLT_PCREL:
2632 /* Negate the increment we did in cris_elf_check_relocs. */
2633 if (h != NULL)
2634 {
2635 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2636 && h->plt.refcount > 0)
2637 --h->plt.refcount;
2638 }
2639 break;
2640
2641 case R_CRIS_32_DTPREL:
2642 /* This'd be a .dtpreld entry in e.g. debug info. */
2643 if ((sec->flags & SEC_ALLOC) == 0)
2644 break;
2645 /* Fall through. */
2646 case R_CRIS_16_DTPREL:
2647 htab->dtpmod_refcount--;
2648 if (htab->dtpmod_refcount == 0)
2649 htab->next_gotplt_entry -= 8;
2650 BFD_ASSERT (local_got_refcounts != NULL);
2651 local_got_refcounts[-1]--;
2652 break;
2653
2654 default:
2655 break;
2656 }
2657 }
2658
2659 return TRUE;
2660 }
2661
2662 /* The elf_backend_plt_sym_val hook function. */
2663
2664 static bfd_vma
2665 cris_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, const asection *plt,
2666 const arelent *rel)
2667 {
2668 bfd_size_type plt_entry_size;
2669 bfd_size_type pltoffs;
2670 bfd *abfd = plt->owner;
2671
2672 /* Same for CRIS and CRIS v32; see elf_cris_(|pic_)plt_entry(|_v32)[]. */
2673 bfd_size_type plt_entry_got_offset = 2;
2674 bfd_size_type plt_sec_size;
2675 bfd_size_type got_vma_for_dyn;
2676 asection *got;
2677
2678 /* FIXME: the .got section should be readily available also when
2679 we're not linking. */
2680 if ((got = bfd_get_section_by_name (abfd, ".got")) == NULL)
2681 return (bfd_vma) -1;
2682
2683 plt_sec_size = bfd_section_size (plt->owner, plt);
2684 plt_entry_size
2685 = (bfd_get_mach (abfd) == bfd_mach_cris_v32
2686 ? PLT_ENTRY_SIZE_V32 : PLT_ENTRY_SIZE);
2687
2688 /* Data in PLT is GOT-relative for DYN, but absolute for EXE. */
2689 got_vma_for_dyn = (abfd->flags & EXEC_P) ? 0 : got->vma;
2690
2691 /* Because we can have merged GOT entries; a single .got entry for
2692 both GOT and the PLT part of the GOT (.got.plt), the index of the
2693 reloc in .rela.plt is not the same as the index in the PLT.
2694 Instead, we have to hunt down the GOT offset in the PLT that
2695 corresponds to that of this reloc. Unfortunately, we will only
2696 be called for the .rela.plt relocs, so we'll miss synthetic
2697 symbols for .plt entries with merged GOT entries. (FIXME:
2698 fixable by providing our own bfd_elf32_get_synthetic_symtab.
2699 Doesn't seem worthwile at time of this writing.) FIXME: we've
2700 gone from O(1) to O(N) (N number of PLT entries) for finding each
2701 PLT address. Shouldn't matter in practice though. */
2702
2703 for (pltoffs = plt_entry_size;
2704 pltoffs < plt_sec_size;
2705 pltoffs += plt_entry_size)
2706 {
2707 bfd_size_type got_offset;
2708 bfd_byte gotoffs_raw[4];
2709
2710 if (!bfd_get_section_contents (abfd, (asection *) plt, gotoffs_raw,
2711 pltoffs + plt_entry_got_offset,
2712 sizeof (gotoffs_raw)))
2713 return (bfd_vma) -1;
2714
2715 got_offset = bfd_get_32 (abfd, gotoffs_raw);
2716 if (got_offset + got_vma_for_dyn == rel->address)
2717 return plt->vma + pltoffs;
2718 }
2719
2720 /* While it's tempting to BFD_ASSERT that we shouldn't get here,
2721 that'd not be graceful behavior for invalid input. */
2722 return (bfd_vma) -1;
2723 }
2724
2725 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
2726 entry but we found we will not create any. Called when we find we will
2727 not have any PLT for this symbol, by for example
2728 elf_cris_adjust_dynamic_symbol when we're doing a proper dynamic link,
2729 or elf_cris_size_dynamic_sections if no dynamic sections will be
2730 created (we're only linking static objects). */
2731
2732 static bfd_boolean
2733 elf_cris_adjust_gotplt_to_got (struct elf_cris_link_hash_entry *h, void * p)
2734 {
2735 struct bfd_link_info *info = (struct bfd_link_info *) p;
2736
2737 /* A GOTPLT reloc, when activated, is supposed to be included into
2738 the PLT refcount. */
2739 BFD_ASSERT (h->gotplt_refcount == 0
2740 || h->gotplt_refcount <= h->root.plt.refcount);
2741
2742 /* If nobody wanted a GOTPLT with this symbol, we're done. */
2743 if (h->gotplt_refcount <= 0)
2744 return TRUE;
2745
2746 if (h->reg_got_refcount > 0)
2747 {
2748 /* There's a GOT entry for this symbol. Just adjust the refcounts.
2749 Probably not necessary at this stage, but keeping them accurate
2750 helps avoiding surprises later. */
2751 h->root.got.refcount += h->gotplt_refcount;
2752 h->reg_got_refcount += h->gotplt_refcount;
2753 h->gotplt_refcount = 0;
2754 }
2755 else
2756 {
2757 /* No GOT entry for this symbol. We need to create one. */
2758 bfd *dynobj = elf_hash_table (info)->dynobj;
2759 asection *sgot;
2760 asection *srelgot;
2761
2762 BFD_ASSERT (dynobj != NULL);
2763 sgot = bfd_get_linker_section (dynobj, ".got");
2764 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
2765
2766 /* Put accurate refcounts there. */
2767 h->root.got.refcount += h->gotplt_refcount;
2768 h->reg_got_refcount = h->gotplt_refcount;
2769
2770 h->gotplt_refcount = 0;
2771
2772 /* We always have a .got and a .rela.got section if there were
2773 GOTPLT relocs in input. */
2774 BFD_ASSERT (sgot != NULL && srelgot != NULL);
2775
2776 /* Allocate space in the .got section. */
2777 sgot->size += 4;
2778
2779 /* Allocate relocation space. */
2780 srelgot->size += sizeof (Elf32_External_Rela);
2781 }
2782
2783 return TRUE;
2784 }
2785
2786 /* Try to fold PLT entries with GOT entries. There are two cases when we
2787 want to do this:
2788
2789 - When all PLT references are GOTPLT references, and there are GOT
2790 references, and this is not the executable. We don't have to
2791 generate a PLT at all.
2792
2793 - When there are both (ordinary) PLT references and GOT references,
2794 and this isn't the executable.
2795 We want to make the PLT reference use the ordinary GOT entry rather
2796 than R_CRIS_JUMP_SLOT, a run-time dynamically resolved GOTPLT entry,
2797 since the GOT entry will have to be resolved at startup anyway.
2798
2799 Though the latter case is handled when room for the PLT is allocated,
2800 not here.
2801
2802 By folding into the GOT, we may need a round-trip to a PLT in the
2803 executable for calls, a loss in performance. Still, losing a
2804 reloc is a win in size and at least in start-up time.
2805
2806 Note that this function is called before symbols are forced local by
2807 version scripts. The differing cases are handled by
2808 elf_cris_hide_symbol. */
2809
2810 static bfd_boolean
2811 elf_cris_try_fold_plt_to_got (struct elf_cris_link_hash_entry *h, void * p)
2812 {
2813 struct bfd_link_info *info = (struct bfd_link_info *) p;
2814
2815 /* If there are no GOT references for this symbol, we can't fold any
2816 other reference so there's nothing to do. Likewise if there are no
2817 PLT references; GOTPLT references included. */
2818 if (h->root.got.refcount <= 0 || h->root.plt.refcount <= 0)
2819 return TRUE;
2820
2821 /* GOTPLT relocs are supposed to be included into the PLT refcount. */
2822 BFD_ASSERT (h->gotplt_refcount <= h->root.plt.refcount);
2823
2824 if (h->gotplt_refcount == h->root.plt.refcount)
2825 {
2826 /* The only PLT references are GOTPLT references, and there are GOT
2827 references. Convert PLT to GOT references. */
2828 if (! elf_cris_adjust_gotplt_to_got (h, info))
2829 return FALSE;
2830
2831 /* Clear the PLT references, so no PLT will be created. */
2832 h->root.plt.offset = (bfd_vma) -1;
2833 }
2834
2835 return TRUE;
2836 }
2837
2838 /* Our own version of hide_symbol, so that we can adjust a GOTPLT reloc
2839 to use a GOT entry (and create one) rather than requiring a GOTPLT
2840 entry. */
2841
2842 static void
2843 elf_cris_hide_symbol (struct bfd_link_info *info,
2844 struct elf_link_hash_entry *h,
2845 bfd_boolean force_local)
2846 {
2847 elf_cris_adjust_gotplt_to_got ((struct elf_cris_link_hash_entry *) h, info);
2848
2849 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
2850 }
2851
2852 /* Adjust a symbol defined by a dynamic object and referenced by a
2853 regular object. The current definition is in some section of the
2854 dynamic object, but we're not including those sections. We have to
2855 change the definition to something the rest of the link can
2856 understand. */
2857
2858 static bfd_boolean
2859 elf_cris_adjust_dynamic_symbol (struct bfd_link_info *info,
2860 struct elf_link_hash_entry *h)
2861 {
2862 struct elf_cris_link_hash_table * htab;
2863 bfd *dynobj;
2864 asection *s;
2865 bfd_size_type plt_entry_size;
2866
2867 htab = elf_cris_hash_table (info);
2868 if (htab == NULL)
2869 return FALSE;
2870
2871 dynobj = elf_hash_table (info)->dynobj;
2872
2873 /* Make sure we know what is going on here. */
2874 BFD_ASSERT (dynobj != NULL
2875 && (h->needs_plt
2876 || h->u.weakdef != NULL
2877 || (h->def_dynamic
2878 && h->ref_regular
2879 && !h->def_regular)));
2880
2881 plt_entry_size
2882 = (bfd_get_mach (dynobj) == bfd_mach_cris_v32
2883 ? PLT_ENTRY_SIZE_V32 : PLT_ENTRY_SIZE);
2884
2885 /* If this is a function, put it in the procedure linkage table. We
2886 will fill in the contents of the procedure linkage table later,
2887 when we know the address of the .got section. */
2888 if (h->type == STT_FUNC
2889 || h->needs_plt)
2890 {
2891 /* If we link a program (not a DSO), we'll get rid of unnecessary
2892 PLT entries; we point to the actual symbols -- even for pic
2893 relocs, because a program built with -fpic should have the same
2894 result as one built without -fpic, specifically considering weak
2895 symbols.
2896 FIXME: m68k and i386 differ here, for unclear reasons. */
2897 if (! bfd_link_pic (info)
2898 && !h->def_dynamic)
2899 {
2900 /* This case can occur if we saw a PLT reloc in an input file,
2901 but the symbol was not defined by a dynamic object. In such
2902 a case, we don't actually need to build a procedure linkage
2903 table, and we can just do an absolute or PC reloc instead, or
2904 change a .got.plt index to a .got index for GOTPLT relocs. */
2905 BFD_ASSERT (h->needs_plt);
2906 h->needs_plt = 0;
2907 h->plt.offset = (bfd_vma) -1;
2908 return
2909 elf_cris_adjust_gotplt_to_got ((struct
2910 elf_cris_link_hash_entry *) h,
2911 info);
2912 }
2913
2914 /* If we had a R_CRIS_GLOB_DAT that didn't have to point to a PLT;
2915 where a pointer-equivalent symbol was unimportant (i.e. more
2916 like R_CRIS_JUMP_SLOT after symbol evaluation) we could get rid
2917 of the PLT. We can't for the executable, because the GOT
2918 entries will point to the PLT there (and be constant). */
2919 if (bfd_link_pic (info)
2920 && !elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry*)
2921 h, info))
2922 return FALSE;
2923
2924 /* GC or folding may have rendered this entry unused. */
2925 if (h->plt.refcount <= 0)
2926 {
2927 h->needs_plt = 0;
2928 h->plt.offset = (bfd_vma) -1;
2929 return TRUE;
2930 }
2931
2932 /* Make sure this symbol is output as a dynamic symbol. */
2933 if (h->dynindx == -1)
2934 {
2935 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2936 return FALSE;
2937 }
2938
2939 s = bfd_get_linker_section (dynobj, ".plt");
2940 BFD_ASSERT (s != NULL);
2941
2942 /* If this is the first .plt entry, make room for the special
2943 first entry. */
2944 if (s->size == 0)
2945 s->size += plt_entry_size;
2946
2947 /* If this symbol is not defined in a regular file, and we are
2948 not generating a shared library, then set the symbol to this
2949 location in the .plt. */
2950 if (!bfd_link_pic (info)
2951 && !h->def_regular)
2952 {
2953 h->root.u.def.section = s;
2954 h->root.u.def.value = s->size;
2955 }
2956
2957 /* If there's already a GOT entry, use that, not a .got.plt. A
2958 GOT field still has a reference count when we get here; it's
2959 not yet changed to an offset. We can't do this for an
2960 executable, because then the reloc associated with the PLT
2961 would get a non-PLT reloc pointing to the PLT. FIXME: Move
2962 this to elf_cris_try_fold_plt_to_got. */
2963 if (bfd_link_pic (info) && h->got.refcount > 0)
2964 {
2965 h->got.refcount += h->plt.refcount;
2966
2967 /* Mark the PLT offset to use the GOT entry by setting the low
2968 bit in the plt offset; it is always a multiple of
2969 plt_entry_size (which is at least a multiple of 2). */
2970 BFD_ASSERT ((s->size % plt_entry_size) == 0);
2971
2972 /* Change the PLT refcount to an offset. */
2973 h->plt.offset = s->size;
2974
2975 /* By not setting gotplt_offset (i.e. it remains at 0), we signal
2976 that the got entry should be used instead. */
2977 BFD_ASSERT (((struct elf_cris_link_hash_entry *)
2978 h)->gotplt_offset == 0);
2979
2980 /* Make room for this entry. */
2981 s->size += plt_entry_size;
2982
2983 return TRUE;
2984 }
2985
2986 /* No GOT reference for this symbol; prepare for an ordinary PLT. */
2987 h->plt.offset = s->size;
2988
2989 /* Make room for this entry. */
2990 s->size += plt_entry_size;
2991
2992 /* We also need to make an entry in the .got.plt section, which
2993 will be placed in the .got section by the linker script. */
2994 ((struct elf_cris_link_hash_entry *) h)->gotplt_offset
2995 = htab->next_gotplt_entry;
2996 htab->next_gotplt_entry += 4;
2997
2998 s = bfd_get_linker_section (dynobj, ".got.plt");
2999 BFD_ASSERT (s != NULL);
3000 s->size += 4;
3001
3002 /* We also need to make an entry in the .rela.plt section. */
3003
3004 s = bfd_get_linker_section (dynobj, ".rela.plt");
3005 BFD_ASSERT (s != NULL);
3006 s->size += sizeof (Elf32_External_Rela);
3007
3008 return TRUE;
3009 }
3010
3011 /* Reinitialize the plt offset now that it is not used as a reference
3012 count any more. */
3013 h->plt.offset = (bfd_vma) -1;
3014
3015 /* If this is a weak symbol, and there is a real definition, the
3016 processor independent code will have arranged for us to see the
3017 real definition first, and we can just use the same value. */
3018 if (h->u.weakdef != NULL)
3019 {
3020 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3021 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3022 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3023 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3024 return TRUE;
3025 }
3026
3027 /* This is a reference to a symbol defined by a dynamic object which
3028 is not a function. */
3029
3030 /* If we are creating a shared library, we must presume that the
3031 only references to the symbol are via the global offset table.
3032 For such cases we need not do anything here; the relocations will
3033 be handled correctly by relocate_section. */
3034 if (bfd_link_pic (info))
3035 return TRUE;
3036
3037 /* If there are no references to this symbol that do not use the
3038 GOT, we don't need to generate a copy reloc. */
3039 if (!h->non_got_ref)
3040 return TRUE;
3041
3042 /* We must allocate the symbol in our .dynbss section, which will
3043 become part of the .bss section of the executable. There will be
3044 an entry for this symbol in the .dynsym section. The dynamic
3045 object will contain position independent code, so all references
3046 from the dynamic object to this symbol will go through the global
3047 offset table. The dynamic linker will use the .dynsym entry to
3048 determine the address it must put in the global offset table, so
3049 both the dynamic object and the regular object will refer to the
3050 same memory location for the variable. */
3051
3052 s = bfd_get_linker_section (dynobj, ".dynbss");
3053 BFD_ASSERT (s != NULL);
3054
3055 /* We must generate a R_CRIS_COPY reloc to tell the dynamic linker to
3056 copy the initial value out of the dynamic object and into the
3057 runtime process image. We need to remember the offset into the
3058 .rela.bss section we are going to use. */
3059 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
3060 {
3061 asection *srel;
3062
3063 srel = bfd_get_linker_section (dynobj, ".rela.bss");
3064 BFD_ASSERT (srel != NULL);
3065 srel->size += sizeof (Elf32_External_Rela);
3066 h->needs_copy = 1;
3067 }
3068
3069 return _bfd_elf_adjust_dynamic_copy (info, h, s);
3070 }
3071
3072 /* Adjust our "subclass" elements for an indirect symbol. */
3073
3074 static void
3075 elf_cris_copy_indirect_symbol (struct bfd_link_info *info,
3076 struct elf_link_hash_entry *dir,
3077 struct elf_link_hash_entry *ind)
3078 {
3079 struct elf_cris_link_hash_entry *edir, *eind;
3080
3081 edir = (struct elf_cris_link_hash_entry *) dir;
3082 eind = (struct elf_cris_link_hash_entry *) ind;
3083
3084 /* Only indirect symbols are replaced; we're not interested in
3085 updating any of EIND's fields for other symbols. */
3086 if (eind->root.root.type != bfd_link_hash_indirect)
3087 {
3088 /* Still, we need to copy flags for e.g. weak definitions. */
3089 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3090 return;
3091 }
3092
3093 BFD_ASSERT (edir->gotplt_offset == 0 || eind->gotplt_offset == 0);
3094
3095 #define XMOVOPZ(F, OP, Z) edir->F OP eind->F; eind->F = Z
3096 #define XMOVE(F) XMOVOPZ (F, +=, 0)
3097 if (eind->pcrel_relocs_copied != NULL)
3098 {
3099 if (edir->pcrel_relocs_copied != NULL)
3100 {
3101 struct elf_cris_pcrel_relocs_copied **pp;
3102 struct elf_cris_pcrel_relocs_copied *p;
3103
3104 /* Add reloc counts against the indirect sym to the direct sym
3105 list. Merge any entries against the same section. */
3106 for (pp = &eind->pcrel_relocs_copied; *pp != NULL;)
3107 {
3108 struct elf_cris_pcrel_relocs_copied *q;
3109 p = *pp;
3110 for (q = edir->pcrel_relocs_copied; q != NULL; q = q->next)
3111 if (q->section == p->section)
3112 {
3113 q->count += p->count;
3114 *pp = p->next;
3115 break;
3116 }
3117 if (q == NULL)
3118 pp = &p->next;
3119 }
3120 *pp = edir->pcrel_relocs_copied;
3121 }
3122 XMOVOPZ (pcrel_relocs_copied, =, NULL);
3123 }
3124 XMOVE (gotplt_refcount);
3125 XMOVE (gotplt_offset);
3126 XMOVE (reg_got_refcount);
3127 XMOVE (tprel_refcount);
3128 XMOVE (dtp_refcount);
3129 #undef XMOVE
3130 #undef XMOVOPZ
3131
3132 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3133 }
3134
3135 /* Look through the relocs for a section during the first phase. */
3136
3137 static bfd_boolean
3138 cris_elf_check_relocs (bfd *abfd,
3139 struct bfd_link_info *info,
3140 asection *sec,
3141 const Elf_Internal_Rela *relocs)
3142 {
3143 struct elf_cris_link_hash_table * htab;
3144 bfd *dynobj;
3145 Elf_Internal_Shdr *symtab_hdr;
3146 struct elf_link_hash_entry **sym_hashes;
3147 bfd_signed_vma *local_got_refcounts;
3148 const Elf_Internal_Rela *rel;
3149 const Elf_Internal_Rela *rel_end;
3150 asection *sgot;
3151 asection *srelgot;
3152 asection *sreloc;
3153
3154 if (bfd_link_relocatable (info))
3155 return TRUE;
3156
3157 htab = elf_cris_hash_table (info);
3158 if (htab == NULL)
3159 return FALSE;
3160
3161 dynobj = elf_hash_table (info)->dynobj;
3162 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3163 sym_hashes = elf_sym_hashes (abfd);
3164 local_got_refcounts = elf_local_got_refcounts (abfd);
3165
3166 sgot = NULL;
3167 srelgot = NULL;
3168 sreloc = NULL;
3169
3170 rel_end = relocs + sec->reloc_count;
3171 for (rel = relocs; rel < rel_end; rel++)
3172 {
3173 struct elf_link_hash_entry *h;
3174 unsigned long r_symndx;
3175 enum elf_cris_reloc_type r_type;
3176 bfd_signed_vma got_element_size = 4;
3177 unsigned long r_symndx_lgot = INT_MAX;
3178
3179 r_symndx = ELF32_R_SYM (rel->r_info);
3180 if (r_symndx < symtab_hdr->sh_info)
3181 {
3182 h = NULL;
3183 r_symndx_lgot = LGOT_REG_NDX (r_symndx);
3184 }
3185 else
3186 {
3187 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3188 while (h->root.type == bfd_link_hash_indirect
3189 || h->root.type == bfd_link_hash_warning)
3190 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3191
3192 /* PR15323, ref flags aren't set for references in the same
3193 object. */
3194 h->root.non_ir_ref = 1;
3195 }
3196
3197 r_type = ELF32_R_TYPE (rel->r_info);
3198
3199 /* Some relocs require linker-created sections; we need to hang them
3200 on the first input bfd we found that contained dynamic relocs. */
3201 switch (r_type)
3202 {
3203 case R_CRIS_32_DTPREL:
3204 if ((sec->flags & SEC_ALLOC) == 0)
3205 /* This'd be a .dtpreld entry in e.g. debug info. We have
3206 several different switch statements below, but none of
3207 that is needed; we need no preparations for resolving
3208 R_CRIS_32_DTPREL into a non-allocated section (debug
3209 info), so let's just move on to the next
3210 relocation. */
3211 continue;
3212 /* Fall through. */
3213 case R_CRIS_16_DTPREL:
3214 /* The first .got.plt entry is right after the R_CRIS_DTPMOD
3215 entry at index 3. */
3216 if (htab->dtpmod_refcount == 0)
3217 htab->next_gotplt_entry += 8;
3218
3219 htab->dtpmod_refcount++;
3220 /* Fall through. */
3221
3222 case R_CRIS_32_IE:
3223 case R_CRIS_32_GD:
3224 case R_CRIS_16_GOT_GD:
3225 case R_CRIS_32_GOT_GD:
3226 case R_CRIS_32_GOT_TPREL:
3227 case R_CRIS_16_GOT_TPREL:
3228 case R_CRIS_16_GOT:
3229 case R_CRIS_32_GOT:
3230 case R_CRIS_32_GOTREL:
3231 case R_CRIS_32_PLT_GOTREL:
3232 case R_CRIS_32_PLT_PCREL:
3233 case R_CRIS_16_GOTPLT:
3234 case R_CRIS_32_GOTPLT:
3235 if (dynobj == NULL)
3236 {
3237 elf_hash_table (info)->dynobj = dynobj = abfd;
3238
3239 /* We could handle this if we can get a handle on the
3240 output bfd in elf_cris_adjust_dynamic_symbol. Failing
3241 that, we must insist on dynobj being a specific mach. */
3242 if (bfd_get_mach (dynobj) == bfd_mach_cris_v10_v32)
3243 {
3244 _bfd_error_handler
3245 /* xgettext:c-format */
3246 (_("%B, section %A:\n v10/v32 compatible object %s"
3247 " must not contain a PIC relocation"),
3248 abfd, sec);
3249 return FALSE;
3250 }
3251 }
3252
3253 if (sgot == NULL)
3254 {
3255 /* We may have a dynobj but no .got section, if machine-
3256 independent parts of the linker found a reason to create
3257 a dynobj. We want to create the .got section now, so we
3258 can assume it's always present whenever there's a dynobj.
3259 It's ok to call this function more than once. */
3260 if (!_bfd_elf_create_got_section (dynobj, info))
3261 return FALSE;
3262
3263 sgot = bfd_get_linker_section (dynobj, ".got");
3264 }
3265
3266 if (local_got_refcounts == NULL)
3267 {
3268 bfd_size_type amt;
3269
3270 /* We use index local_got_refcounts[-1] to count all
3271 GOT-relative relocations that do not have explicit
3272 GOT entries. */
3273 amt = LGOT_ALLOC_NELTS_FOR (symtab_hdr->sh_info) + 1;
3274 amt *= sizeof (bfd_signed_vma);
3275 local_got_refcounts = ((bfd_signed_vma *) bfd_zalloc (abfd, amt));
3276 if (local_got_refcounts == NULL)
3277 return FALSE;
3278
3279 local_got_refcounts++;
3280 elf_local_got_refcounts (abfd) = local_got_refcounts;
3281 }
3282 break;
3283
3284 default:
3285 break;
3286 }
3287
3288 /* Some relocs require a global offset table (but perhaps not a
3289 specific GOT entry). */
3290 switch (r_type)
3291 {
3292 case R_CRIS_16_DTPREL:
3293 case R_CRIS_32_DTPREL:
3294 /* Not requesting .got.rela for an executable: the contents
3295 of the first entry is constant there. For a shared
3296 library, we need .got.rela for the R_CRIS_DTPMOD
3297 relocation at index 3. */
3298 if (!bfd_link_pic (info))
3299 break;
3300 /* Fall through. */
3301
3302 case R_CRIS_32_IE:
3303 case R_CRIS_32_GD:
3304 case R_CRIS_16_GOT_GD:
3305 case R_CRIS_32_GOT_GD:
3306 case R_CRIS_32_GOT_TPREL:
3307 case R_CRIS_16_GOT_TPREL:
3308 /* Fall through. */
3309
3310 /* For R_CRIS_16_GOTPLT and R_CRIS_32_GOTPLT, we need a GOT
3311 entry only for local symbols. Unfortunately, we don't know
3312 until later on if there's a version script that forces the
3313 symbol local. We must have the .rela.got section in place
3314 before we know if the symbol looks global now, so we need
3315 to treat the reloc just like for R_CRIS_16_GOT and
3316 R_CRIS_32_GOT. */
3317 case R_CRIS_16_GOTPLT:
3318 case R_CRIS_32_GOTPLT:
3319 case R_CRIS_16_GOT:
3320 case R_CRIS_32_GOT:
3321 if (srelgot == NULL
3322 && (h != NULL || bfd_link_pic (info)))
3323 {
3324 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
3325 if (srelgot == NULL)
3326 {
3327 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
3328 | SEC_IN_MEMORY | SEC_LINKER_CREATED
3329 | SEC_READONLY);
3330 srelgot = bfd_make_section_anyway_with_flags (dynobj,
3331 ".rela.got",
3332 flags);
3333 if (srelgot == NULL
3334 || !bfd_set_section_alignment (dynobj, srelgot, 2))
3335 return FALSE;
3336 }
3337 }
3338 break;
3339
3340 default:
3341 break;
3342 }
3343
3344 /* Warn and error for invalid input. */
3345 switch (r_type)
3346 {
3347 case R_CRIS_32_IE:
3348 case R_CRIS_32_TPREL:
3349 case R_CRIS_16_TPREL:
3350 case R_CRIS_32_GD:
3351 if (bfd_link_pic (info))
3352 {
3353 _bfd_error_handler
3354 /* xgettext:c-format */
3355 (_("%B, section %A:\n relocation %s not valid"
3356 " in a shared object;"
3357 " typically an option mixup, recompile with -fPIC"),
3358 abfd,
3359 sec,
3360 cris_elf_howto_table[r_type].name);
3361 /* Don't return FALSE here; we want messages for all of
3362 these and the error behavior is ungraceful
3363 anyway. */
3364 }
3365 default:
3366 break;
3367 }
3368
3369 switch (r_type)
3370 {
3371 case R_CRIS_32_GD:
3372 case R_CRIS_16_GOT_GD:
3373 case R_CRIS_32_GOT_GD:
3374 /* These are requests for tls_index entries, run-time R_CRIS_DTP. */
3375 got_element_size = 8;
3376 r_symndx_lgot = LGOT_DTP_NDX (r_symndx);
3377 break;
3378
3379 case R_CRIS_16_DTPREL:
3380 case R_CRIS_32_DTPREL:
3381 /* These two just request for the constant-index
3382 module-local tls_index-sized GOT entry, which we add
3383 elsewhere. */
3384 break;
3385
3386 case R_CRIS_32_IE:
3387 case R_CRIS_32_GOT_TPREL:
3388 case R_CRIS_16_GOT_TPREL:
3389 r_symndx_lgot = LGOT_TPREL_NDX (r_symndx);
3390
3391 /* Those relocs also require that a DSO is of type
3392 Initial Exec. Like other targets, we don't reset this
3393 flag even if the relocs are GC:ed away. */
3394 if (bfd_link_pic (info))
3395 info->flags |= DF_STATIC_TLS;
3396 break;
3397
3398 /* Let's list the other assembler-generated TLS-relocs too,
3399 just to show that they're not forgotten. */
3400 case R_CRIS_16_TPREL:
3401 case R_CRIS_32_TPREL:
3402 default:
3403 break;
3404 }
3405
3406 switch (r_type)
3407 {
3408 case R_CRIS_16_GOTPLT:
3409 case R_CRIS_32_GOTPLT:
3410 /* Mark that we need a GOT entry if the PLT entry (and its GOT
3411 entry) is eliminated. We can only do this for a non-local
3412 symbol. */
3413 if (h != NULL)
3414 {
3415 elf_cris_hash_entry (h)->gotplt_refcount++;
3416 goto handle_gotplt_reloc;
3417 }
3418 /* If h is NULL then this is a local symbol, and we must make a
3419 GOT entry for it, so handle it like a GOT reloc. */
3420 /* Fall through. */
3421
3422 case R_CRIS_32_IE:
3423 case R_CRIS_32_GD:
3424 case R_CRIS_16_GOT_GD:
3425 case R_CRIS_32_GOT_GD:
3426 case R_CRIS_32_GOT_TPREL:
3427 case R_CRIS_16_GOT_TPREL:
3428 case R_CRIS_16_GOT:
3429 case R_CRIS_32_GOT:
3430 /* This symbol requires a global offset table entry. */
3431 if (h != NULL)
3432 {
3433 if (h->got.refcount == 0)
3434 {
3435 /* Make sure this symbol is output as a dynamic symbol. */
3436 if (h->dynindx == -1)
3437 {
3438 if (!bfd_elf_link_record_dynamic_symbol (info, h))
3439 return FALSE;
3440 }
3441 }
3442
3443 /* Update the sum of reloc counts for this symbol. */
3444 h->got.refcount++;
3445
3446 switch (r_type)
3447 {
3448 case R_CRIS_16_GOT:
3449 case R_CRIS_32_GOT:
3450 if (elf_cris_hash_entry (h)->reg_got_refcount == 0)
3451 {
3452 /* Allocate space in the .got section. */
3453 sgot->size += got_element_size;
3454 /* Allocate relocation space. */
3455 srelgot->size += sizeof (Elf32_External_Rela);
3456 }
3457 elf_cris_hash_entry (h)->reg_got_refcount++;
3458 break;
3459
3460 case R_CRIS_32_GD:
3461 case R_CRIS_16_GOT_GD:
3462 case R_CRIS_32_GOT_GD:
3463 if (elf_cris_hash_entry (h)->dtp_refcount == 0)
3464 {
3465 /* Allocate space in the .got section. */
3466 sgot->size += got_element_size;
3467 /* Allocate relocation space. */
3468 srelgot->size += sizeof (Elf32_External_Rela);
3469 }
3470 elf_cris_hash_entry (h)->dtp_refcount++;
3471 break;
3472
3473 case R_CRIS_32_IE:
3474 case R_CRIS_32_GOT_TPREL:
3475 case R_CRIS_16_GOT_TPREL:
3476 if (elf_cris_hash_entry (h)->tprel_refcount == 0)
3477 {
3478 /* Allocate space in the .got section. */
3479 sgot->size += got_element_size;
3480 /* Allocate relocation space. */
3481 srelgot->size += sizeof (Elf32_External_Rela);
3482 }
3483 elf_cris_hash_entry (h)->tprel_refcount++;
3484 break;
3485
3486 default:
3487 BFD_FAIL ();
3488 break;
3489 }
3490 }
3491 else
3492 {
3493 /* This is a global offset table entry for a local symbol. */
3494 if (local_got_refcounts[r_symndx_lgot] == 0)
3495 {
3496 sgot->size += got_element_size;
3497 if (bfd_link_pic (info))
3498 {
3499 /* If we are generating a shared object, we need
3500 to output a R_CRIS_RELATIVE reloc so that the
3501 dynamic linker can adjust this GOT entry.
3502 Similarly for non-regular got entries. */
3503 srelgot->size += sizeof (Elf32_External_Rela);
3504 }
3505 }
3506 /* Update the reloc-specific count. */
3507 local_got_refcounts[r_symndx_lgot]++;
3508
3509 /* This one is the sum of all the others. */
3510 local_got_refcounts[r_symndx]++;
3511 }
3512 break;
3513
3514 case R_CRIS_16_DTPREL:
3515 case R_CRIS_32_DTPREL:
3516 case R_CRIS_32_GOTREL:
3517 /* This reference requires a global offset table.
3518 FIXME: The actual refcount isn't used currently; the .got
3519 section can't be removed if there were any references in the
3520 input. */
3521 local_got_refcounts[-1]++;
3522 break;
3523
3524 handle_gotplt_reloc:
3525
3526 case R_CRIS_32_PLT_GOTREL:
3527 /* This reference requires a global offset table. */
3528 local_got_refcounts[-1]++;
3529 /* Fall through. */
3530
3531 case R_CRIS_32_PLT_PCREL:
3532 /* This symbol requires a procedure linkage table entry. We
3533 actually build the entry in adjust_dynamic_symbol,
3534 because this might be a case of linking PIC code which is
3535 never referenced by a dynamic object, in which case we
3536 don't need to generate a procedure linkage table entry
3537 after all. */
3538
3539 /* Beware: if we'd check for visibility of the symbol here
3540 (and not marking the need for a PLT when non-visible), we'd
3541 get into trouble with keeping handling consistent with
3542 regards to relocs found before definition and GOTPLT
3543 handling. Eliminable PLT entries will be dealt with later
3544 anyway. */
3545 if (h == NULL)
3546 continue;
3547
3548 h->needs_plt = 1;
3549 h->plt.refcount++;
3550 break;
3551
3552 case R_CRIS_8:
3553 case R_CRIS_16:
3554 case R_CRIS_32:
3555 /* Let's help debug shared library creation. Any of these
3556 relocs *can* be used in shared libs, but pages containing
3557 them cannot be shared, so they're not appropriate for
3558 common use. Don't warn for sections we don't care about,
3559 such as debug sections or non-constant sections. We
3560 can't help tables of (global) function pointers, for
3561 example, though they must be emitted in a (writable) data
3562 section to avoid having impure text sections. */
3563 if (bfd_link_pic (info)
3564 && (sec->flags & SEC_ALLOC) != 0
3565 && (sec->flags & SEC_READONLY) != 0)
3566 {
3567 /* FIXME: How do we make this optionally a warning only? */
3568 _bfd_error_handler
3569 /* xgettext:c-format */
3570 (_("%B, section %A:\n relocation %s should not"
3571 " be used in a shared object; recompile with -fPIC"),
3572 abfd,
3573 sec,
3574 cris_elf_howto_table[r_type].name);
3575 }
3576
3577 /* We don't need to handle relocs into sections not going into
3578 the "real" output. */
3579 if ((sec->flags & SEC_ALLOC) == 0)
3580 break;
3581
3582 if (h != NULL)
3583 {
3584 h->non_got_ref = 1;
3585
3586 /* Make sure a plt entry is created for this symbol if it
3587 turns out to be a function defined by a dynamic object. */
3588 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3589 h->plt.refcount++;
3590 }
3591
3592 /* If we are creating a shared library and this is not a local
3593 symbol, we need to copy the reloc into the shared library.
3594 However when linking with -Bsymbolic and this is a global
3595 symbol which is defined in an object we are including in the
3596 link (i.e., DEF_REGULAR is set), then we can resolve the
3597 reloc directly. At this point we have not seen all the input
3598 files, so it is possible that DEF_REGULAR is not set now but
3599 will be set later (it is never cleared). In case of a weak
3600 definition, DEF_REGULAR may be cleared later by a strong
3601 definition in a shared library. We account for that
3602 possibility below by storing information in the relocs_copied
3603 field of the hash table entry. A similar situation occurs
3604 when creating shared libraries and symbol visibility changes
3605 render the symbol local. */
3606
3607 /* No need to do anything if we're not creating a shared object. */
3608 if (! bfd_link_pic (info))
3609 break;
3610
3611 /* We may need to create a reloc section in the dynobj and made room
3612 for this reloc. */
3613 if (sreloc == NULL)
3614 {
3615 sreloc = _bfd_elf_make_dynamic_reloc_section
3616 (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
3617
3618 if (sreloc == NULL)
3619 return FALSE;
3620 }
3621
3622 if (sec->flags & SEC_READONLY)
3623 info->flags |= DF_TEXTREL;
3624
3625 sreloc->size += sizeof (Elf32_External_Rela);
3626 break;
3627
3628 case R_CRIS_8_PCREL:
3629 case R_CRIS_16_PCREL:
3630 case R_CRIS_32_PCREL:
3631 if (h != NULL)
3632 {
3633 h->non_got_ref = 1;
3634
3635 /* Make sure a plt entry is created for this symbol if it
3636 turns out to be a function defined by a dynamic object. */
3637 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3638 h->plt.refcount++;
3639 }
3640
3641 /* If we are creating a shared library and this is not a local
3642 symbol, we need to copy the reloc into the shared library.
3643 However when linking with -Bsymbolic and this is a global
3644 symbol which is defined in an object we are including in the
3645 link (i.e., DEF_REGULAR is set), then we can resolve the
3646 reloc directly. At this point we have not seen all the input
3647 files, so it is possible that DEF_REGULAR is not set now but
3648 will be set later (it is never cleared). In case of a weak
3649 definition, DEF_REGULAR may be cleared later by a strong
3650 definition in a shared library. We account for that
3651 possibility below by storing information in the relocs_copied
3652 field of the hash table entry. A similar situation occurs
3653 when creating shared libraries and symbol visibility changes
3654 render the symbol local. */
3655
3656 /* No need to do anything if we're not creating a shared object. */
3657 if (! bfd_link_pic (info))
3658 break;
3659
3660 /* We don't need to handle relocs into sections not going into
3661 the "real" output. */
3662 if ((sec->flags & SEC_ALLOC) == 0)
3663 break;
3664
3665 /* If the symbol is local, then we know already we can
3666 eliminate the reloc. */
3667 if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
3668 break;
3669
3670 /* If this is with -Bsymbolic and the symbol isn't weak, and
3671 is defined by an ordinary object (the ones we include in
3672 this shared library) then we can also eliminate the
3673 reloc. See comment above for more eliminable cases which
3674 we can't identify at this time. */
3675 if (SYMBOLIC_BIND (info, h)
3676 && h->root.type != bfd_link_hash_defweak
3677 && h->def_regular)
3678 break;
3679
3680 /* We may need to create a reloc section in the dynobj and made room
3681 for this reloc. */
3682 if (sreloc == NULL)
3683 {
3684 sreloc = _bfd_elf_make_dynamic_reloc_section
3685 (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
3686
3687 if (sreloc == NULL)
3688 return FALSE;
3689 }
3690
3691 sreloc->size += sizeof (Elf32_External_Rela);
3692
3693 /* We count the number of PC relative relocations we have
3694 entered for this symbol, so that we can discard them
3695 again if the symbol is later defined by a regular object.
3696 We know that h is really a pointer to an
3697 elf_cris_link_hash_entry. */
3698 {
3699 struct elf_cris_link_hash_entry *eh;
3700 struct elf_cris_pcrel_relocs_copied *p;
3701
3702 eh = elf_cris_hash_entry (h);
3703
3704 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
3705 if (p->section == sec)
3706 break;
3707
3708 if (p == NULL)
3709 {
3710 p = ((struct elf_cris_pcrel_relocs_copied *)
3711 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
3712 if (p == NULL)
3713 return FALSE;
3714 p->next = eh->pcrel_relocs_copied;
3715 eh->pcrel_relocs_copied = p;
3716 p->section = sec;
3717 p->count = 0;
3718 p->r_type = r_type;
3719 }
3720
3721 ++p->count;
3722 }
3723 break;
3724
3725 /* This relocation describes the C++ object vtable hierarchy.
3726 Reconstruct it for later use during GC. */
3727 case R_CRIS_GNU_VTINHERIT:
3728 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3729 return FALSE;
3730 break;
3731
3732 /* This relocation describes which C++ vtable entries are actually
3733 used. Record for later use during GC. */
3734 case R_CRIS_GNU_VTENTRY:
3735 BFD_ASSERT (h != NULL);
3736 if (h != NULL
3737 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3738 return FALSE;
3739 break;
3740
3741 case R_CRIS_16_TPREL:
3742 case R_CRIS_32_TPREL:
3743 /* Already warned above, when necessary. */
3744 break;
3745
3746 default:
3747 /* Other relocs do not appear here. */
3748 bfd_set_error (bfd_error_bad_value);
3749 return FALSE;
3750 }
3751 }
3752
3753 return TRUE;
3754 }
3755
3756 /* Set the sizes of the dynamic sections. */
3757
3758 static bfd_boolean
3759 elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3760 struct bfd_link_info *info)
3761 {
3762 struct elf_cris_link_hash_table * htab;
3763 bfd *dynobj;
3764 asection *s;
3765 bfd_boolean plt;
3766 bfd_boolean relocs;
3767
3768 htab = elf_cris_hash_table (info);
3769 if (htab == NULL)
3770 return FALSE;
3771
3772 dynobj = elf_hash_table (info)->dynobj;
3773 BFD_ASSERT (dynobj != NULL);
3774
3775 if (elf_hash_table (info)->dynamic_sections_created)
3776 {
3777 /* Set the contents of the .interp section to the interpreter. */
3778 if (bfd_link_executable (info) && !info->nointerp)
3779 {
3780 s = bfd_get_linker_section (dynobj, ".interp");
3781 BFD_ASSERT (s != NULL);
3782 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3783 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3784 }
3785 }
3786 else
3787 {
3788 /* Adjust all expected GOTPLT uses to use a GOT entry instead. */
3789 elf_cris_link_hash_traverse (htab, elf_cris_adjust_gotplt_to_got,
3790 info);
3791
3792 /* We may have created entries in the .rela.got section.
3793 However, if we are not creating the dynamic sections, we will
3794 not actually use these entries. Reset the size of .rela.got,
3795 which will cause it to get stripped from the output file
3796 below. */
3797 s = bfd_get_linker_section (dynobj, ".rela.got");
3798 if (s != NULL)
3799 s->size = 0;
3800 }
3801
3802 /* If this is a -Bsymbolic shared link, then we need to discard all PC
3803 relative relocs against symbols defined in a regular object. We
3804 allocated space for them in the check_relocs routine, but we will not
3805 fill them in in the relocate_section routine. We also discard space
3806 for relocs that have become for local symbols due to symbol
3807 visibility changes. For programs, we discard space for relocs for
3808 symbols not referenced by any dynamic object. */
3809 if (bfd_link_pic (info))
3810 elf_cris_link_hash_traverse (htab,
3811 elf_cris_discard_excess_dso_dynamics,
3812 info);
3813 else
3814 elf_cris_link_hash_traverse (htab,
3815 elf_cris_discard_excess_program_dynamics,
3816 info);
3817
3818 /* The check_relocs and adjust_dynamic_symbol entry points have
3819 determined the sizes of the various dynamic sections. Allocate
3820 memory for them. */
3821 plt = FALSE;
3822 relocs = FALSE;
3823 for (s = dynobj->sections; s != NULL; s = s->next)
3824 {
3825 const char *name;
3826
3827 if ((s->flags & SEC_LINKER_CREATED) == 0)
3828 continue;
3829
3830 /* It's OK to base decisions on the section name, because none
3831 of the dynobj section names depend upon the input files. */
3832 name = bfd_get_section_name (dynobj, s);
3833
3834 if (strcmp (name, ".plt") == 0)
3835 {
3836 /* Remember whether there is a PLT. */
3837 plt = s->size != 0;
3838 }
3839 else if (strcmp (name, ".got.plt") == 0)
3840 {
3841 /* The .got.plt contains the .got header as well as the
3842 actual .got.plt contents. The .got header may contain a
3843 R_CRIS_DTPMOD entry at index 3. */
3844 s->size += htab->dtpmod_refcount != 0
3845 ? 8 : 0;
3846 }
3847 else if (CONST_STRNEQ (name, ".rela"))
3848 {
3849 if (strcmp (name, ".rela.got") == 0
3850 && htab->dtpmod_refcount != 0
3851 && bfd_link_pic (info))
3852 s->size += sizeof (Elf32_External_Rela);
3853
3854 if (s->size != 0)
3855 {
3856 /* Remember whether there are any reloc sections other
3857 than .rela.plt. */
3858 if (strcmp (name, ".rela.plt") != 0)
3859 relocs = TRUE;
3860
3861 /* We use the reloc_count field as a counter if we need
3862 to copy relocs into the output file. */
3863 s->reloc_count = 0;
3864 }
3865 }
3866 else if (! CONST_STRNEQ (name, ".got")
3867 && strcmp (name, ".dynbss") != 0)
3868 {
3869 /* It's not one of our sections, so don't allocate space. */
3870 continue;
3871 }
3872
3873 if (s->size == 0)
3874 {
3875 /* If we don't need this section, strip it from the
3876 output file. This is mostly to handle .rela.bss and
3877 .rela.plt. We must create both sections in
3878 create_dynamic_sections, because they must be created
3879 before the linker maps input sections to output
3880 sections. The linker does that before
3881 adjust_dynamic_symbol is called, and it is that
3882 function which decides whether anything needs to go
3883 into these sections. */
3884 s->flags |= SEC_EXCLUDE;
3885 continue;
3886 }
3887
3888 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3889 continue;
3890
3891 /* Allocate memory for the section contents. We use bfd_zalloc here
3892 in case unused entries are not reclaimed before the section's
3893 contents are written out. This should not happen, but this way
3894 if it does, we will not write out garbage. For reloc sections,
3895 this will make entries have the type R_CRIS_NONE. */
3896 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3897 if (s->contents == NULL)
3898 return FALSE;
3899 }
3900
3901 if (elf_hash_table (info)->dynamic_sections_created)
3902 {
3903 /* Add some entries to the .dynamic section. We fill in the
3904 values later, in elf_cris_finish_dynamic_sections, but we
3905 must add the entries now so that we get the correct size for
3906 the .dynamic section. The DT_DEBUG entry is filled in by the
3907 dynamic linker and used by the debugger. */
3908 #define add_dynamic_entry(TAG, VAL) \
3909 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3910
3911 if (!bfd_link_pic (info))
3912 {
3913 if (!add_dynamic_entry (DT_DEBUG, 0))
3914 return FALSE;
3915 }
3916
3917 if (plt)
3918 {
3919 if (!add_dynamic_entry (DT_PLTGOT, 0)
3920 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3921 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3922 || !add_dynamic_entry (DT_JMPREL, 0))
3923 return FALSE;
3924 }
3925
3926 if (relocs)
3927 {
3928 if (!add_dynamic_entry (DT_RELA, 0)
3929 || !add_dynamic_entry (DT_RELASZ, 0)
3930 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3931 return FALSE;
3932 }
3933
3934 if ((info->flags & DF_TEXTREL) != 0)
3935 {
3936 if (!add_dynamic_entry (DT_TEXTREL, 0))
3937 return FALSE;
3938 info->flags |= DF_TEXTREL;
3939 }
3940 }
3941 #undef add_dynamic_entry
3942
3943 return TRUE;
3944 }
3945
3946 /* This function is called via elf_cris_link_hash_traverse if we are
3947 creating a shared object. In the -Bsymbolic case, it discards the
3948 space allocated to copy PC relative relocs against symbols which
3949 are defined in regular objects. For the normal non-symbolic case,
3950 we also discard space for relocs that have become local due to
3951 symbol visibility changes. We allocated space for them in the
3952 check_relocs routine, but we won't fill them in in the
3953 relocate_section routine. */
3954
3955 static bfd_boolean
3956 elf_cris_discard_excess_dso_dynamics (struct elf_cris_link_hash_entry *h,
3957 void * inf)
3958 {
3959 struct elf_cris_pcrel_relocs_copied *s;
3960 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3961
3962 /* If a symbol has been forced local or we have found a regular
3963 definition for the symbolic link case, then we won't be needing
3964 any relocs. */
3965 if (h->root.def_regular
3966 && (h->root.forced_local
3967 || SYMBOLIC_BIND (info, &h->root)))
3968 {
3969 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
3970 {
3971 asection *sreloc
3972 = _bfd_elf_get_dynamic_reloc_section (elf_hash_table (info)
3973 ->dynobj,
3974 s->section,
3975 /*rela?*/ TRUE);
3976 sreloc->size -= s->count * sizeof (Elf32_External_Rela);
3977 }
3978 return TRUE;
3979 }
3980
3981 /* If we have accounted for PC-relative relocs for read-only
3982 sections, now is the time to warn for them. We can't do it in
3983 cris_elf_check_relocs, because we don't know the status of all
3984 symbols at that time (and it's common to force symbols local
3985 late). */
3986
3987 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
3988 if ((s->section->flags & SEC_READONLY) != 0)
3989 {
3990 /* FIXME: How do we make this optionally a warning only? */
3991 _bfd_error_handler
3992 /* xgettext:c-format */
3993 (_("%B, section `%A', to symbol `%s':\n"
3994 " relocation %s should not be used"
3995 " in a shared object; recompile with -fPIC"),
3996 s->section->owner,
3997 s->section,
3998 h->root.root.root.string,
3999 cris_elf_howto_table[s->r_type].name);
4000
4001 info->flags |= DF_TEXTREL;
4002 }
4003
4004 return TRUE;
4005 }
4006
4007 /* This function is called via elf_cris_link_hash_traverse if we are *not*
4008 creating a shared object. We discard space for relocs for symbols put
4009 in the .got, but which we found we do not have to resolve at run-time. */
4010
4011 static bfd_boolean
4012 elf_cris_discard_excess_program_dynamics (struct elf_cris_link_hash_entry *h,
4013 void * inf)
4014 {
4015 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4016
4017 /* If we're not creating a shared library and have a symbol which is
4018 referred to by .got references, but the symbol is defined locally,
4019 (or rather, not defined by a DSO) then lose the reloc for the .got
4020 (don't allocate room for it). Likewise for relocs for something
4021 for which we create a PLT. */
4022 if (!h->root.def_dynamic
4023 || h->root.plt.refcount > 0)
4024 {
4025 if (h->reg_got_refcount > 0
4026 /* The size of this section is only valid and in sync with the
4027 various reference counts if we do dynamic; don't decrement it
4028 otherwise. */
4029 && elf_hash_table (info)->dynamic_sections_created)
4030 {
4031 bfd *dynobj = elf_hash_table (info)->dynobj;
4032 asection *srelgot;
4033
4034 BFD_ASSERT (dynobj != NULL);
4035
4036 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
4037
4038 BFD_ASSERT (srelgot != NULL);
4039
4040 srelgot->size -= sizeof (Elf32_External_Rela);
4041 }
4042
4043 /* If the locally-defined symbol isn't used by a DSO, then we don't
4044 have to export it as a dynamic symbol. This was already done for
4045 functions; doing this for all symbols would presumably not
4046 introduce new problems. Of course we don't do this if we're
4047 exporting all dynamic symbols, or all data symbols, regardless of
4048 them being referenced or not. */
4049 if (! (info->export_dynamic
4050 || (h->root.type != STT_FUNC && info->dynamic_data))
4051 && h->root.dynindx != -1
4052 && !h->root.def_dynamic
4053 && !h->root.ref_dynamic)
4054 {
4055 h->root.dynindx = -1;
4056 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
4057 h->root.dynstr_index);
4058 }
4059 }
4060
4061 return TRUE;
4062 }
4063
4064 /* Reject a file depending on presence and expectation of prefixed
4065 underscores on symbols. */
4066
4067 static bfd_boolean
4068 cris_elf_object_p (bfd *abfd)
4069 {
4070 if (! cris_elf_set_mach_from_flags (abfd, elf_elfheader (abfd)->e_flags))
4071 return FALSE;
4072
4073 if ((elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE))
4074 return (bfd_get_symbol_leading_char (abfd) == '_');
4075 else
4076 return (bfd_get_symbol_leading_char (abfd) == 0);
4077 }
4078
4079 /* Mark presence or absence of leading underscore. Set machine type
4080 flags from mach type. */
4081
4082 static void
4083 cris_elf_final_write_processing (bfd *abfd,
4084 bfd_boolean linker ATTRIBUTE_UNUSED)
4085 {
4086 unsigned long e_flags = elf_elfheader (abfd)->e_flags;
4087
4088 e_flags &= ~EF_CRIS_UNDERSCORE;
4089 if (bfd_get_symbol_leading_char (abfd) == '_')
4090 e_flags |= EF_CRIS_UNDERSCORE;
4091
4092 switch (bfd_get_mach (abfd))
4093 {
4094 case bfd_mach_cris_v0_v10:
4095 e_flags |= EF_CRIS_VARIANT_ANY_V0_V10;
4096 break;
4097
4098 case bfd_mach_cris_v10_v32:
4099 e_flags |= EF_CRIS_VARIANT_COMMON_V10_V32;
4100 break;
4101
4102 case bfd_mach_cris_v32:
4103 e_flags |= EF_CRIS_VARIANT_V32;
4104 break;
4105
4106 default:
4107 _bfd_abort (__FILE__, __LINE__,
4108 _("Unexpected machine number"));
4109 }
4110
4111 elf_elfheader (abfd)->e_flags = e_flags;
4112 }
4113
4114 /* Set the mach type from e_flags value. */
4115
4116 static bfd_boolean
4117 cris_elf_set_mach_from_flags (bfd *abfd,
4118 unsigned long flags)
4119 {
4120 switch (flags & EF_CRIS_VARIANT_MASK)
4121 {
4122 case EF_CRIS_VARIANT_ANY_V0_V10:
4123 bfd_default_set_arch_mach (abfd, bfd_arch_cris, bfd_mach_cris_v0_v10);
4124 break;
4125
4126 case EF_CRIS_VARIANT_V32:
4127 bfd_default_set_arch_mach (abfd, bfd_arch_cris, bfd_mach_cris_v32);
4128 break;
4129
4130 case EF_CRIS_VARIANT_COMMON_V10_V32:
4131 bfd_default_set_arch_mach (abfd, bfd_arch_cris, bfd_mach_cris_v10_v32);
4132 break;
4133
4134 default:
4135 /* Since we don't recognize them, we obviously can't support them
4136 with this code; we'd have to require that all future handling
4137 would be optional. */
4138 bfd_set_error (bfd_error_wrong_format);
4139 return FALSE;
4140 }
4141
4142 return TRUE;
4143 }
4144
4145 /* Display the flags field. */
4146
4147 static bfd_boolean
4148 cris_elf_print_private_bfd_data (bfd *abfd, void * ptr)
4149 {
4150 FILE *file = (FILE *) ptr;
4151
4152 BFD_ASSERT (abfd != NULL && ptr != NULL);
4153
4154 _bfd_elf_print_private_bfd_data (abfd, ptr);
4155
4156 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
4157
4158 if (elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE)
4159 fprintf (file, _(" [symbols have a _ prefix]"));
4160 if ((elf_elfheader (abfd)->e_flags & EF_CRIS_VARIANT_MASK)
4161 == EF_CRIS_VARIANT_COMMON_V10_V32)
4162 fprintf (file, _(" [v10 and v32]"));
4163 if ((elf_elfheader (abfd)->e_flags & EF_CRIS_VARIANT_MASK)
4164 == EF_CRIS_VARIANT_V32)
4165 fprintf (file, _(" [v32]"));
4166
4167 fputc ('\n', file);
4168 return TRUE;
4169 }
4170
4171 /* Don't mix files with and without a leading underscore. */
4172
4173 static bfd_boolean
4174 cris_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
4175 {
4176 bfd *obfd = info->output_bfd;
4177 int imach, omach;
4178
4179 if (! _bfd_generic_verify_endian_match (ibfd, info))
4180 return FALSE;
4181
4182 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4183 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4184 return TRUE;
4185
4186 imach = bfd_get_mach (ibfd);
4187
4188 if (! elf_flags_init (obfd))
4189 {
4190 /* This happens when ld starts out with a 'blank' output file. */
4191 elf_flags_init (obfd) = TRUE;
4192
4193 /* We ignore the linker-set mach, and instead set it according to
4194 the first input file. This would also happen if we could
4195 somehow filter out the OUTPUT_ARCH () setting from elf.sc.
4196 This allows us to keep the same linker config across
4197 cris(v0..v10) and crisv32. The drawback is that we can't force
4198 the output type, which might be a sane thing to do for a
4199 v10+v32 compatibility object. */
4200 if (! bfd_set_arch_mach (obfd, bfd_arch_cris, imach))
4201 return FALSE;
4202 }
4203
4204 if (bfd_get_symbol_leading_char (ibfd)
4205 != bfd_get_symbol_leading_char (obfd))
4206 {
4207 _bfd_error_handler
4208 (bfd_get_symbol_leading_char (ibfd) == '_'
4209 ? _("%B: uses _-prefixed symbols, but writing file with non-prefixed symbols")
4210 : _("%B: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
4211 ibfd);
4212 bfd_set_error (bfd_error_bad_value);
4213 return FALSE;
4214 }
4215
4216 omach = bfd_get_mach (obfd);
4217
4218 if (imach != omach)
4219 {
4220 /* We can get an incompatible combination only if either is
4221 bfd_mach_cris_v32, and the other one isn't compatible. */
4222 if ((imach == bfd_mach_cris_v32
4223 && omach != bfd_mach_cris_v10_v32)
4224 || (omach == bfd_mach_cris_v32
4225 && imach != bfd_mach_cris_v10_v32))
4226 {
4227 _bfd_error_handler
4228 ((imach == bfd_mach_cris_v32)
4229 ? _("%B contains CRIS v32 code, incompatible"
4230 " with previous objects")
4231 : _("%B contains non-CRIS-v32 code, incompatible"
4232 " with previous objects"),
4233 ibfd);
4234 bfd_set_error (bfd_error_bad_value);
4235 return FALSE;
4236 }
4237
4238 /* We don't have to check the case where the input is compatible
4239 with v10 and v32, because the output is already known to be set
4240 to the other (compatible) mach. */
4241 if (omach == bfd_mach_cris_v10_v32
4242 && ! bfd_set_arch_mach (obfd, bfd_arch_cris, imach))
4243 return FALSE;
4244 }
4245
4246 return TRUE;
4247 }
4248
4249 /* Do side-effects of e_flags copying to obfd. */
4250
4251 static bfd_boolean
4252 cris_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
4253 {
4254 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4255 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4256 return TRUE;
4257
4258 /* Call the base function. */
4259 if (!_bfd_elf_copy_private_bfd_data (ibfd, obfd))
4260 return FALSE;
4261
4262 /* Do what we really came here for. */
4263 return bfd_set_arch_mach (obfd, bfd_arch_cris, bfd_get_mach (ibfd));
4264 }
4265
4266 static enum elf_reloc_type_class
4267 elf_cris_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
4268 const asection *rel_sec ATTRIBUTE_UNUSED,
4269 const Elf_Internal_Rela *rela)
4270 {
4271 enum elf_cris_reloc_type r_type = ELF32_R_TYPE (rela->r_info);
4272 switch (r_type)
4273 {
4274 case R_CRIS_RELATIVE:
4275 return reloc_class_relative;
4276 case R_CRIS_JUMP_SLOT:
4277 return reloc_class_plt;
4278 case R_CRIS_COPY:
4279 return reloc_class_copy;
4280 default:
4281 return reloc_class_normal;
4282 }
4283 }
4284
4285 /* The elf_backend_got_elt_size worker. For one symbol, we can have up to
4286 two GOT entries from three types with two different sizes. We handle
4287 it as a single entry, so we can use the regular offset-calculation
4288 machinery. */
4289
4290 static bfd_vma
4291 elf_cris_got_elt_size (bfd *abfd ATTRIBUTE_UNUSED,
4292 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4293 struct elf_link_hash_entry *hr,
4294 bfd *ibfd,
4295 unsigned long symndx)
4296 {
4297 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) hr;
4298 bfd_vma eltsiz = 0;
4299
4300 /* We may have one regular GOT entry or up to two TLS GOT
4301 entries. */
4302 if (h == NULL)
4303 {
4304 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4305 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (ibfd);
4306
4307 BFD_ASSERT (local_got_refcounts != NULL);
4308
4309 if (local_got_refcounts[LGOT_REG_NDX (symndx)] > 0)
4310 {
4311 /* We can't have a variable referred to both as a regular
4312 variable and through TLS relocs. */
4313 BFD_ASSERT (local_got_refcounts[LGOT_DTP_NDX (symndx)] == 0
4314 && local_got_refcounts[LGOT_TPREL_NDX (symndx)] == 0);
4315 return 4;
4316 }
4317
4318 if (local_got_refcounts[LGOT_DTP_NDX (symndx)] > 0)
4319 eltsiz += 8;
4320
4321 if (local_got_refcounts[LGOT_TPREL_NDX (symndx)] > 0)
4322 eltsiz += 4;
4323 }
4324 else
4325 {
4326 struct elf_cris_link_hash_entry *hh = elf_cris_hash_entry (h);
4327 if (hh->reg_got_refcount > 0)
4328 {
4329 /* The actual error-on-input is emitted elsewhere. */
4330 BFD_ASSERT (hh->dtp_refcount == 0 && hh->tprel_refcount == 0);
4331 return 4;
4332 }
4333
4334 if (hh->dtp_refcount > 0)
4335 eltsiz += 8;
4336
4337 if (hh->tprel_refcount > 0)
4338 eltsiz += 4;
4339 }
4340
4341 /* We're only called when h->got.refcount is non-zero, so we must
4342 have a non-zero size. */
4343 BFD_ASSERT (eltsiz != 0);
4344 return eltsiz;
4345 }
4346 \f
4347 #define ELF_ARCH bfd_arch_cris
4348 #define ELF_TARGET_ID CRIS_ELF_DATA
4349 #define ELF_MACHINE_CODE EM_CRIS
4350 #define ELF_MAXPAGESIZE 0x2000
4351
4352 #define TARGET_LITTLE_SYM cris_elf32_vec
4353 #define TARGET_LITTLE_NAME "elf32-cris"
4354 #define elf_symbol_leading_char 0
4355
4356 #define elf_info_to_howto_rel NULL
4357 #define elf_info_to_howto cris_info_to_howto_rela
4358 #define elf_backend_relocate_section cris_elf_relocate_section
4359 #define elf_backend_gc_mark_hook cris_elf_gc_mark_hook
4360 #define elf_backend_gc_sweep_hook cris_elf_gc_sweep_hook
4361 #define elf_backend_plt_sym_val cris_elf_plt_sym_val
4362 #define elf_backend_check_relocs cris_elf_check_relocs
4363 #define elf_backend_grok_prstatus cris_elf_grok_prstatus
4364 #define elf_backend_grok_psinfo cris_elf_grok_psinfo
4365
4366 #define elf_backend_can_gc_sections 1
4367 #define elf_backend_can_refcount 1
4368
4369 #define elf_backend_object_p cris_elf_object_p
4370 #define elf_backend_final_write_processing \
4371 cris_elf_final_write_processing
4372 #define bfd_elf32_bfd_print_private_bfd_data \
4373 cris_elf_print_private_bfd_data
4374 #define bfd_elf32_bfd_merge_private_bfd_data \
4375 cris_elf_merge_private_bfd_data
4376 #define bfd_elf32_bfd_copy_private_bfd_data \
4377 cris_elf_copy_private_bfd_data
4378
4379 #define bfd_elf32_bfd_reloc_type_lookup cris_reloc_type_lookup
4380 #define bfd_elf32_bfd_reloc_name_lookup cris_reloc_name_lookup
4381
4382 #define bfd_elf32_bfd_link_hash_table_create \
4383 elf_cris_link_hash_table_create
4384 #define elf_backend_adjust_dynamic_symbol \
4385 elf_cris_adjust_dynamic_symbol
4386 #define elf_backend_copy_indirect_symbol \
4387 elf_cris_copy_indirect_symbol
4388 #define elf_backend_size_dynamic_sections \
4389 elf_cris_size_dynamic_sections
4390 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4391 #define elf_backend_finish_dynamic_symbol \
4392 elf_cris_finish_dynamic_symbol
4393 #define elf_backend_finish_dynamic_sections \
4394 elf_cris_finish_dynamic_sections
4395 #define elf_backend_create_dynamic_sections \
4396 _bfd_elf_create_dynamic_sections
4397 #define bfd_elf32_bfd_final_link \
4398 bfd_elf_gc_common_final_link
4399 #define elf_backend_hide_symbol elf_cris_hide_symbol
4400 #define elf_backend_reloc_type_class elf_cris_reloc_type_class
4401
4402 #define elf_backend_want_got_plt 1
4403 #define elf_backend_plt_readonly 1
4404 #define elf_backend_want_plt_sym 0
4405 #define elf_backend_got_header_size 12
4406 #define elf_backend_got_elt_size elf_cris_got_elt_size
4407
4408 /* Later, we my want to optimize RELA entries into REL entries for dynamic
4409 linking and libraries (if it's a win of any significance). Until then,
4410 take the easy route. */
4411 #define elf_backend_may_use_rel_p 0
4412 #define elf_backend_may_use_rela_p 1
4413 #define elf_backend_rela_normal 1
4414
4415 #include "elf32-target.h"
4416
4417 #undef TARGET_LITTLE_SYM
4418 #undef TARGET_LITTLE_NAME
4419 #undef elf_symbol_leading_char
4420
4421 #define TARGET_LITTLE_SYM cris_elf32_us_vec
4422 #define TARGET_LITTLE_NAME "elf32-us-cris"
4423 #define elf_symbol_leading_char '_'
4424 #undef elf32_bed
4425 #define elf32_bed elf32_us_cris_bed
4426
4427 #include "elf32-target.h"
This page took 0.12146 seconds and 4 git commands to generate.