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