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