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