Commit | Line | Data |
---|---|---|
4e5ba5b7 | 1 | /* FRV-specific support for 32-bit ELF. |
5a580b3a | 2 | Copyright 2002, 2003, 2004 Free Software Foundation, Inc. |
4e5ba5b7 DB |
3 | |
4 | This file is part of BFD, the Binary File Descriptor library. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include "bfd.h" | |
21 | #include "sysdep.h" | |
22 | #include "libbfd.h" | |
23 | #include "elf-bfd.h" | |
24 | #include "elf/frv.h" | |
ec3391e7 | 25 | #include "elf/dwarf2.h" |
51532845 | 26 | #include "hashtab.h" |
4e5ba5b7 DB |
27 | |
28 | /* Forward declarations. */ | |
29 | static bfd_reloc_status_type elf32_frv_relocate_lo16 | |
30 | PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
31 | static bfd_reloc_status_type elf32_frv_relocate_hi16 | |
32 | PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
33 | static bfd_reloc_status_type elf32_frv_relocate_label24 | |
34 | PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
35 | static bfd_reloc_status_type elf32_frv_relocate_gprel12 | |
b34976b6 AM |
36 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
37 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 | 38 | static bfd_reloc_status_type elf32_frv_relocate_gprelu12 |
b34976b6 AM |
39 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
40 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 | 41 | static bfd_reloc_status_type elf32_frv_relocate_gprello |
b34976b6 AM |
42 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
43 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 | 44 | static bfd_reloc_status_type elf32_frv_relocate_gprelhi |
b34976b6 AM |
45 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
46 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 DB |
47 | static reloc_howto_type *frv_reloc_type_lookup |
48 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
b34976b6 | 49 | static void frv_info_to_howto_rela |
947216bf | 50 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
b34976b6 AM |
51 | static bfd_boolean elf32_frv_relocate_section |
52 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
53 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
54 | static bfd_boolean elf32_frv_add_symbol_hook | |
555cd476 | 55 | PARAMS (( bfd *, struct bfd_link_info *, Elf_Internal_Sym *, |
b34976b6 | 56 | const char **, flagword *, asection **, bfd_vma *)); |
4e5ba5b7 | 57 | static bfd_reloc_status_type frv_final_link_relocate |
b34976b6 AM |
58 | PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, |
59 | Elf_Internal_Rela *, bfd_vma)); | |
60 | static bfd_boolean elf32_frv_gc_sweep_hook | |
61 | PARAMS ((bfd *, struct bfd_link_info *, asection *, const | |
62 | Elf_Internal_Rela *)); | |
4e5ba5b7 | 63 | static asection * elf32_frv_gc_mark_hook |
b34976b6 AM |
64 | PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
65 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | |
66 | static bfd_boolean elf32_frv_check_relocs | |
67 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
68 | const Elf_Internal_Rela *)); | |
69 | static int elf32_frv_machine | |
70 | PARAMS ((bfd *)); | |
71 | static bfd_boolean elf32_frv_object_p | |
72 | PARAMS ((bfd *)); | |
73 | static bfd_boolean frv_elf_set_private_flags | |
74 | PARAMS ((bfd *, flagword)); | |
75 | static bfd_boolean frv_elf_copy_private_bfd_data | |
76 | PARAMS ((bfd *, bfd *)); | |
77 | static bfd_boolean frv_elf_merge_private_bfd_data | |
78 | PARAMS ((bfd *, bfd *)); | |
79 | static bfd_boolean frv_elf_print_private_bfd_data | |
80 | PARAMS ((bfd *, PTR)); | |
4e5ba5b7 DB |
81 | |
82 | static reloc_howto_type elf32_frv_howto_table [] = | |
83 | { | |
84 | /* This reloc does nothing. */ | |
85 | HOWTO (R_FRV_NONE, /* type */ | |
86 | 0, /* rightshift */ | |
87 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
88 | 32, /* bitsize */ | |
b34976b6 | 89 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
90 | 0, /* bitpos */ |
91 | complain_overflow_bitfield, /* complain_on_overflow */ | |
92 | bfd_elf_generic_reloc, /* special_function */ | |
93 | "R_FRV_NONE", /* name */ | |
b34976b6 | 94 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
95 | 0, /* src_mask */ |
96 | 0, /* dst_mask */ | |
b34976b6 | 97 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
98 | |
99 | /* A 32 bit absolute relocation. */ | |
100 | HOWTO (R_FRV_32, /* type */ | |
101 | 0, /* rightshift */ | |
102 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
103 | 32, /* bitsize */ | |
b34976b6 | 104 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
105 | 0, /* bitpos */ |
106 | complain_overflow_bitfield, /* complain_on_overflow */ | |
107 | bfd_elf_generic_reloc, /* special_function */ | |
108 | "R_FRV_32", /* name */ | |
b34976b6 | 109 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
110 | 0xffffffff, /* src_mask */ |
111 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 112 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
113 | |
114 | /* A 16 bit pc-relative relocation. */ | |
115 | HOWTO (R_FRV_LABEL16, /* type */ | |
b15b52ef | 116 | 2, /* rightshift */ |
4e5ba5b7 DB |
117 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
118 | 16, /* bitsize */ | |
b34976b6 | 119 | TRUE, /* pc_relative */ |
4e5ba5b7 | 120 | 0, /* bitpos */ |
e6deed0a | 121 | complain_overflow_signed, /* complain_on_overflow */ |
4e5ba5b7 DB |
122 | bfd_elf_generic_reloc, /* special_function */ |
123 | "R_FRV_LABEL16", /* name */ | |
b34976b6 | 124 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
125 | 0xffff, /* src_mask */ |
126 | 0xffff, /* dst_mask */ | |
b34976b6 | 127 | TRUE), /* pcrel_offset */ |
4e5ba5b7 DB |
128 | |
129 | /* A 24-bit pc-relative relocation. */ | |
130 | HOWTO (R_FRV_LABEL24, /* type */ | |
131 | 2, /* rightshift */ | |
132 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
133 | 26, /* bitsize */ | |
b34976b6 | 134 | TRUE, /* pc_relative */ |
4e5ba5b7 DB |
135 | 0, /* bitpos */ |
136 | complain_overflow_bitfield, /* complain_on_overflow */ | |
137 | bfd_elf_generic_reloc, /* special_function */ | |
138 | "R_FRV_LABEL24", /* name */ | |
b34976b6 | 139 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
140 | 0x7e03ffff, /* src_mask */ |
141 | 0x7e03ffff, /* dst_mask */ | |
b34976b6 | 142 | TRUE), /* pcrel_offset */ |
4e5ba5b7 DB |
143 | |
144 | HOWTO (R_FRV_LO16, /* type */ | |
145 | 0, /* rightshift */ | |
146 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
147 | 16, /* bitsize */ | |
b34976b6 | 148 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
149 | 0, /* bitpos */ |
150 | complain_overflow_dont, /* complain_on_overflow */ | |
151 | bfd_elf_generic_reloc, /* special_function */ | |
152 | "R_FRV_LO16", /* name */ | |
b34976b6 | 153 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
154 | 0xffff, /* src_mask */ |
155 | 0xffff, /* dst_mask */ | |
b34976b6 | 156 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
157 | |
158 | HOWTO (R_FRV_HI16, /* type */ | |
159 | 0, /* rightshift */ | |
160 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
161 | 16, /* bitsize */ | |
b34976b6 | 162 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
163 | 0, /* bitpos */ |
164 | complain_overflow_dont, /* complain_on_overflow */ | |
165 | bfd_elf_generic_reloc, /* special_function */ | |
166 | "R_FRV_HI16", /* name */ | |
b34976b6 | 167 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
168 | 0xffff, /* src_mask */ |
169 | 0xffff, /* dst_mask */ | |
b34976b6 | 170 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
171 | |
172 | HOWTO (R_FRV_GPREL12, /* type */ | |
173 | 0, /* rightshift */ | |
174 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
175 | 12, /* bitsize */ | |
b34976b6 | 176 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
177 | 0, /* bitpos */ |
178 | complain_overflow_dont, /* complain_on_overflow */ | |
179 | bfd_elf_generic_reloc, /* special_function */ | |
180 | "R_FRV_GPREL12", /* name */ | |
b34976b6 | 181 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
182 | 0xfff, /* src_mask */ |
183 | 0xfff, /* dst_mask */ | |
b34976b6 | 184 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
185 | |
186 | HOWTO (R_FRV_GPRELU12, /* type */ | |
187 | 0, /* rightshift */ | |
188 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
189 | 12, /* bitsize */ | |
b34976b6 | 190 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
191 | 0, /* bitpos */ |
192 | complain_overflow_dont, /* complain_on_overflow */ | |
193 | bfd_elf_generic_reloc, /* special_function */ | |
194 | "R_FRV_GPRELU12", /* name */ | |
b34976b6 | 195 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
196 | 0xfff, /* src_mask */ |
197 | 0x3f03f, /* dst_mask */ | |
b34976b6 | 198 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
199 | |
200 | HOWTO (R_FRV_GPREL32, /* type */ | |
201 | 0, /* rightshift */ | |
202 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
203 | 32, /* bitsize */ | |
b34976b6 | 204 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
205 | 0, /* bitpos */ |
206 | complain_overflow_dont, /* complain_on_overflow */ | |
207 | bfd_elf_generic_reloc, /* special_function */ | |
208 | "R_FRV_GPREL32", /* name */ | |
b34976b6 | 209 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
210 | 0xffffffff, /* src_mask */ |
211 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 212 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
213 | |
214 | HOWTO (R_FRV_GPRELHI, /* type */ | |
215 | 0, /* rightshift */ | |
216 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
217 | 16, /* bitsize */ | |
b34976b6 | 218 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
219 | 0, /* bitpos */ |
220 | complain_overflow_dont, /* complain_on_overflow */ | |
221 | bfd_elf_generic_reloc, /* special_function */ | |
222 | "R_FRV_GPRELHI", /* name */ | |
b34976b6 | 223 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
224 | 0xffff, /* src_mask */ |
225 | 0xffff, /* dst_mask */ | |
b34976b6 | 226 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
227 | |
228 | HOWTO (R_FRV_GPRELLO, /* type */ | |
229 | 0, /* rightshift */ | |
230 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
231 | 16, /* bitsize */ | |
b34976b6 | 232 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
233 | 0, /* bitpos */ |
234 | complain_overflow_dont, /* complain_on_overflow */ | |
235 | bfd_elf_generic_reloc, /* special_function */ | |
236 | "R_FRV_GPRELLO", /* name */ | |
b34976b6 | 237 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
238 | 0xffff, /* src_mask */ |
239 | 0xffff, /* dst_mask */ | |
b34976b6 | 240 | FALSE), /* pcrel_offset */ |
51532845 AO |
241 | |
242 | /* A 12-bit signed operand with the GOT offset for the address of | |
243 | the symbol. */ | |
244 | HOWTO (R_FRV_GOT12, /* type */ | |
245 | 0, /* rightshift */ | |
246 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
247 | 12, /* bitsize */ | |
248 | FALSE, /* pc_relative */ | |
249 | 0, /* bitpos */ | |
250 | complain_overflow_signed, /* complain_on_overflow */ | |
251 | bfd_elf_generic_reloc, /* special_function */ | |
252 | "R_FRV_GOT12", /* name */ | |
253 | FALSE, /* partial_inplace */ | |
254 | 0xfff, /* src_mask */ | |
255 | 0xfff, /* dst_mask */ | |
256 | FALSE), /* pcrel_offset */ | |
257 | ||
258 | /* The upper 16 bits of the GOT offset for the address of the | |
259 | symbol. */ | |
260 | HOWTO (R_FRV_GOTHI, /* type */ | |
261 | 0, /* rightshift */ | |
262 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
263 | 16, /* bitsize */ | |
264 | FALSE, /* pc_relative */ | |
265 | 0, /* bitpos */ | |
266 | complain_overflow_dont, /* complain_on_overflow */ | |
267 | bfd_elf_generic_reloc, /* special_function */ | |
268 | "R_FRV_GOTHI", /* name */ | |
269 | FALSE, /* partial_inplace */ | |
270 | 0xffff, /* src_mask */ | |
271 | 0xffff, /* dst_mask */ | |
272 | FALSE), /* pcrel_offset */ | |
273 | ||
274 | /* The lower 16 bits of the GOT offset for the address of the | |
275 | symbol. */ | |
276 | HOWTO (R_FRV_GOTLO, /* type */ | |
277 | 0, /* rightshift */ | |
278 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
279 | 16, /* bitsize */ | |
280 | FALSE, /* pc_relative */ | |
281 | 0, /* bitpos */ | |
282 | complain_overflow_dont, /* complain_on_overflow */ | |
283 | bfd_elf_generic_reloc, /* special_function */ | |
284 | "R_FRV_GOTLO", /* name */ | |
285 | FALSE, /* partial_inplace */ | |
286 | 0xffff, /* src_mask */ | |
287 | 0xffff, /* dst_mask */ | |
288 | FALSE), /* pcrel_offset */ | |
289 | ||
290 | /* The 32-bit address of the canonical descriptor of a function. */ | |
291 | HOWTO (R_FRV_FUNCDESC, /* type */ | |
292 | 0, /* rightshift */ | |
293 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
294 | 32, /* bitsize */ | |
295 | FALSE, /* pc_relative */ | |
296 | 0, /* bitpos */ | |
297 | complain_overflow_bitfield, /* complain_on_overflow */ | |
298 | bfd_elf_generic_reloc, /* special_function */ | |
299 | "R_FRV_FUNCDESC", /* name */ | |
300 | FALSE, /* partial_inplace */ | |
301 | 0xffffffff, /* src_mask */ | |
302 | 0xffffffff, /* dst_mask */ | |
303 | FALSE), /* pcrel_offset */ | |
304 | ||
305 | /* A 12-bit signed operand with the GOT offset for the address of | |
306 | canonical descriptor of a function. */ | |
307 | HOWTO (R_FRV_FUNCDESC_GOT12, /* type */ | |
308 | 0, /* rightshift */ | |
309 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
310 | 12, /* bitsize */ | |
311 | FALSE, /* pc_relative */ | |
312 | 0, /* bitpos */ | |
313 | complain_overflow_signed, /* complain_on_overflow */ | |
314 | bfd_elf_generic_reloc, /* special_function */ | |
315 | "R_FRV_FUNCDESC_GOT12", /* name */ | |
316 | FALSE, /* partial_inplace */ | |
317 | 0xfff, /* src_mask */ | |
318 | 0xfff, /* dst_mask */ | |
319 | FALSE), /* pcrel_offset */ | |
320 | ||
321 | /* The upper 16 bits of the GOT offset for the address of the | |
322 | canonical descriptor of a function. */ | |
323 | HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */ | |
324 | 0, /* rightshift */ | |
325 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
326 | 16, /* bitsize */ | |
327 | FALSE, /* pc_relative */ | |
328 | 0, /* bitpos */ | |
329 | complain_overflow_dont, /* complain_on_overflow */ | |
330 | bfd_elf_generic_reloc, /* special_function */ | |
331 | "R_FRV_FUNCDESC_GOTHI", /* name */ | |
332 | FALSE, /* partial_inplace */ | |
333 | 0xffff, /* src_mask */ | |
334 | 0xffff, /* dst_mask */ | |
335 | FALSE), /* pcrel_offset */ | |
336 | ||
337 | /* The lower 16 bits of the GOT offset for the address of the | |
338 | canonical descriptor of a function. */ | |
339 | HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */ | |
340 | 0, /* rightshift */ | |
341 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
342 | 16, /* bitsize */ | |
343 | FALSE, /* pc_relative */ | |
344 | 0, /* bitpos */ | |
345 | complain_overflow_dont, /* complain_on_overflow */ | |
346 | bfd_elf_generic_reloc, /* special_function */ | |
347 | "R_FRV_FUNCDESC_GOTLO", /* name */ | |
348 | FALSE, /* partial_inplace */ | |
349 | 0xffff, /* src_mask */ | |
350 | 0xffff, /* dst_mask */ | |
351 | FALSE), /* pcrel_offset */ | |
352 | ||
353 | /* The 32-bit address of the canonical descriptor of a function. */ | |
354 | HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ | |
355 | 0, /* rightshift */ | |
356 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
357 | 64, /* bitsize */ | |
358 | FALSE, /* pc_relative */ | |
359 | 0, /* bitpos */ | |
360 | complain_overflow_bitfield, /* complain_on_overflow */ | |
361 | bfd_elf_generic_reloc, /* special_function */ | |
362 | "R_FRV_FUNCDESC_VALUE", /* name */ | |
363 | FALSE, /* partial_inplace */ | |
364 | 0xffffffff, /* src_mask */ | |
365 | 0xffffffff, /* dst_mask */ | |
366 | FALSE), /* pcrel_offset */ | |
367 | ||
368 | /* A 12-bit signed operand with the GOT offset for the address of | |
369 | canonical descriptor of a function. */ | |
370 | HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */ | |
371 | 0, /* rightshift */ | |
372 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
373 | 12, /* bitsize */ | |
374 | FALSE, /* pc_relative */ | |
375 | 0, /* bitpos */ | |
376 | complain_overflow_signed, /* complain_on_overflow */ | |
377 | bfd_elf_generic_reloc, /* special_function */ | |
378 | "R_FRV_FUNCDESC_GOTOFF12", /* name */ | |
379 | FALSE, /* partial_inplace */ | |
380 | 0xfff, /* src_mask */ | |
381 | 0xfff, /* dst_mask */ | |
382 | FALSE), /* pcrel_offset */ | |
383 | ||
384 | /* The upper 16 bits of the GOT offset for the address of the | |
385 | canonical descriptor of a function. */ | |
386 | HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */ | |
387 | 0, /* rightshift */ | |
388 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
389 | 16, /* bitsize */ | |
390 | FALSE, /* pc_relative */ | |
391 | 0, /* bitpos */ | |
392 | complain_overflow_dont, /* complain_on_overflow */ | |
393 | bfd_elf_generic_reloc, /* special_function */ | |
394 | "R_FRV_FUNCDESC_GOTOFFHI", /* name */ | |
395 | FALSE, /* partial_inplace */ | |
396 | 0xffff, /* src_mask */ | |
397 | 0xffff, /* dst_mask */ | |
398 | FALSE), /* pcrel_offset */ | |
399 | ||
400 | /* The lower 16 bits of the GOT offset for the address of the | |
401 | canonical descriptor of a function. */ | |
402 | HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */ | |
403 | 0, /* rightshift */ | |
404 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
405 | 16, /* bitsize */ | |
406 | FALSE, /* pc_relative */ | |
407 | 0, /* bitpos */ | |
408 | complain_overflow_dont, /* complain_on_overflow */ | |
409 | bfd_elf_generic_reloc, /* special_function */ | |
410 | "R_FRV_FUNCDESC_GOTOFFLO", /* name */ | |
411 | FALSE, /* partial_inplace */ | |
412 | 0xffff, /* src_mask */ | |
413 | 0xffff, /* dst_mask */ | |
414 | FALSE), /* pcrel_offset */ | |
415 | ||
416 | /* A 12-bit signed operand with the GOT offset for the address of | |
417 | the symbol. */ | |
418 | HOWTO (R_FRV_GOTOFF12, /* type */ | |
419 | 0, /* rightshift */ | |
420 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
421 | 12, /* bitsize */ | |
422 | FALSE, /* pc_relative */ | |
423 | 0, /* bitpos */ | |
424 | complain_overflow_signed, /* complain_on_overflow */ | |
425 | bfd_elf_generic_reloc, /* special_function */ | |
426 | "R_FRV_GOTOFF12", /* name */ | |
427 | FALSE, /* partial_inplace */ | |
428 | 0xfff, /* src_mask */ | |
429 | 0xfff, /* dst_mask */ | |
430 | FALSE), /* pcrel_offset */ | |
431 | ||
432 | /* The upper 16 bits of the GOT offset for the address of the | |
433 | symbol. */ | |
434 | HOWTO (R_FRV_GOTOFFHI, /* type */ | |
435 | 0, /* rightshift */ | |
436 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
437 | 16, /* bitsize */ | |
438 | FALSE, /* pc_relative */ | |
439 | 0, /* bitpos */ | |
440 | complain_overflow_dont, /* complain_on_overflow */ | |
441 | bfd_elf_generic_reloc, /* special_function */ | |
442 | "R_FRV_GOTOFFHI", /* name */ | |
443 | FALSE, /* partial_inplace */ | |
444 | 0xffff, /* src_mask */ | |
445 | 0xffff, /* dst_mask */ | |
446 | FALSE), /* pcrel_offset */ | |
447 | ||
448 | /* The lower 16 bits of the GOT offset for the address of the | |
449 | symbol. */ | |
450 | HOWTO (R_FRV_GOTOFFLO, /* type */ | |
451 | 0, /* rightshift */ | |
452 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
453 | 16, /* bitsize */ | |
454 | FALSE, /* pc_relative */ | |
455 | 0, /* bitpos */ | |
456 | complain_overflow_dont, /* complain_on_overflow */ | |
457 | bfd_elf_generic_reloc, /* special_function */ | |
458 | "R_FRV_GOTOFFLO", /* name */ | |
459 | FALSE, /* partial_inplace */ | |
460 | 0xffff, /* src_mask */ | |
461 | 0xffff, /* dst_mask */ | |
462 | FALSE), /* pcrel_offset */ | |
463 | ||
4e5ba5b7 DB |
464 | }; |
465 | ||
466 | /* GNU extension to record C++ vtable hierarchy. */ | |
467 | static reloc_howto_type elf32_frv_vtinherit_howto = | |
468 | HOWTO (R_FRV_GNU_VTINHERIT, /* type */ | |
469 | 0, /* rightshift */ | |
470 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
471 | 0, /* bitsize */ | |
b34976b6 | 472 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
473 | 0, /* bitpos */ |
474 | complain_overflow_dont, /* complain_on_overflow */ | |
475 | NULL, /* special_function */ | |
476 | "R_FRV_GNU_VTINHERIT", /* name */ | |
b34976b6 | 477 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
478 | 0, /* src_mask */ |
479 | 0, /* dst_mask */ | |
b34976b6 | 480 | FALSE); /* pcrel_offset */ |
4e5ba5b7 DB |
481 | |
482 | /* GNU extension to record C++ vtable member usage. */ | |
483 | static reloc_howto_type elf32_frv_vtentry_howto = | |
484 | HOWTO (R_FRV_GNU_VTENTRY, /* type */ | |
485 | 0, /* rightshift */ | |
486 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
487 | 0, /* bitsize */ | |
b34976b6 | 488 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
489 | 0, /* bitpos */ |
490 | complain_overflow_dont, /* complain_on_overflow */ | |
491 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
492 | "R_FRV_GNU_VTENTRY", /* name */ | |
b34976b6 | 493 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
494 | 0, /* src_mask */ |
495 | 0, /* dst_mask */ | |
b34976b6 | 496 | FALSE); /* pcrel_offset */ |
51532845 AO |
497 | |
498 | /* The following 3 relocations are REL. The only difference to the | |
499 | entries in the table above are that partial_inplace is TRUE. */ | |
500 | static reloc_howto_type elf32_frv_rel_32_howto = | |
501 | HOWTO (R_FRV_32, /* type */ | |
502 | 0, /* rightshift */ | |
503 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
504 | 32, /* bitsize */ | |
505 | FALSE, /* pc_relative */ | |
506 | 0, /* bitpos */ | |
507 | complain_overflow_bitfield, /* complain_on_overflow */ | |
508 | bfd_elf_generic_reloc, /* special_function */ | |
509 | "R_FRV_32", /* name */ | |
510 | TRUE, /* partial_inplace */ | |
511 | 0xffffffff, /* src_mask */ | |
512 | 0xffffffff, /* dst_mask */ | |
513 | FALSE); /* pcrel_offset */ | |
514 | ||
515 | static reloc_howto_type elf32_frv_rel_funcdesc_howto = | |
516 | HOWTO (R_FRV_FUNCDESC, /* type */ | |
517 | 0, /* rightshift */ | |
518 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
519 | 32, /* bitsize */ | |
520 | FALSE, /* pc_relative */ | |
521 | 0, /* bitpos */ | |
522 | complain_overflow_bitfield, /* complain_on_overflow */ | |
523 | bfd_elf_generic_reloc, /* special_function */ | |
524 | "R_FRV_FUNCDESC", /* name */ | |
525 | TRUE, /* partial_inplace */ | |
526 | 0xffffffff, /* src_mask */ | |
527 | 0xffffffff, /* dst_mask */ | |
528 | FALSE); /* pcrel_offset */ | |
529 | ||
530 | static reloc_howto_type elf32_frv_rel_funcdesc_value_howto = | |
531 | HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ | |
532 | 0, /* rightshift */ | |
533 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
534 | 64, /* bitsize */ | |
535 | FALSE, /* pc_relative */ | |
536 | 0, /* bitpos */ | |
537 | complain_overflow_bitfield, /* complain_on_overflow */ | |
538 | bfd_elf_generic_reloc, /* special_function */ | |
539 | "R_FRV_FUNCDESC_VALUE", /* name */ | |
540 | TRUE, /* partial_inplace */ | |
541 | 0xffffffff, /* src_mask */ | |
542 | 0xffffffff, /* dst_mask */ | |
543 | FALSE); /* pcrel_offset */ | |
544 | ||
4e5ba5b7 DB |
545 | \f |
546 | /* Map BFD reloc types to FRV ELF reloc types. */ | |
547 | #if 0 | |
548 | struct frv_reloc_map | |
549 | { | |
550 | unsigned int bfd_reloc_val; | |
551 | unsigned int frv_reloc_val; | |
552 | }; | |
553 | ||
554 | static const struct frv_reloc_map frv_reloc_map [] = | |
555 | { | |
556 | { BFD_RELOC_NONE, R_FRV_NONE }, | |
557 | { BFD_RELOC_32, R_FRV_32 }, | |
558 | { BFD_RELOC_FRV_LABEL16, R_FRV_LABEL16 }, | |
559 | { BFD_RELOC_FRV_LABEL24, R_FRV_LABEL24 }, | |
560 | { BFD_RELOC_FRV_LO16, R_FRV_LO16 }, | |
561 | { BFD_RELOC_FRV_HI16, R_FRV_HI16 }, | |
562 | { BFD_RELOC_FRV_GPREL12, R_FRV_GPREL12 }, | |
563 | { BFD_RELOC_FRV_GPRELU12, R_FRV_GPRELU12 }, | |
564 | { BFD_RELOC_FRV_GPREL32, R_FRV_GPREL32 }, | |
565 | { BFD_RELOC_FRV_GPRELHI, R_FRV_GPRELHI }, | |
566 | { BFD_RELOC_FRV_GPRELLO, R_FRV_GPRELLO }, | |
51532845 AO |
567 | { BFD_RELOC_FRV_GOT12, R_FRV_GOT12 }, |
568 | { BFD_RELOC_FRV_GOTHI, R_FRV_GOTHI }, | |
569 | { BFD_RELOC_FRV_GOTLO, R_FRV_GOTLO }, | |
570 | { BFD_RELOC_FRV_FUNCDESC, R_FRV_FUNCDESC }, | |
571 | { BFD_RELOC_FRV_FUNCDESC_GOT12, R_FRV_FUNCDESC_GOT12 }, | |
572 | { BFD_RELOC_FRV_FUNCDESC_GOTHI, R_FRV_FUNCDESC_GOTHI }, | |
573 | { BFD_RELOC_FRV_FUNCDESC_GOTLO, R_FRV_FUNCDESC_GOTLO }, | |
574 | { BFD_RELOC_FRV_FUNCDESC_VALUE, R_FRV_FUNCDESC_VALUE }, | |
575 | { BFD_RELOC_FRV_FUNCDESC_GOTOFF12, R_FRV_FUNCDESC_GOTOFF12 }, | |
576 | { BFD_RELOC_FRV_FUNCDESC_GOTOFFHI, R_FRV_FUNCDESC_GOTOFFHI }, | |
577 | { BFD_RELOC_FRV_FUNCDESC_GOTOFFLO, R_FRV_FUNCDESC_GOTOFFLO }, | |
578 | { BFD_RELOC_FRV_GOTOFF12, R_FRV_GOTOFF12 }, | |
579 | { BFD_RELOC_FRV_GOTOFFHI, R_FRV_GOTOFFHI }, | |
580 | { BFD_RELOC_FRV_GOTOFFLO, R_FRV_GOTOFFLO }, | |
4e5ba5b7 DB |
581 | { BFD_RELOC_VTABLE_INHERIT, R_FRV_GNU_VTINHERIT }, |
582 | { BFD_RELOC_VTABLE_ENTRY, R_FRV_GNU_VTENTRY }, | |
583 | }; | |
584 | #endif | |
585 | ||
43850d5b AO |
586 | extern const bfd_target bfd_elf32_frvfdpic_vec; |
587 | #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec) | |
4e5ba5b7 | 588 | |
51532845 AO |
589 | /* An extension of the elf hash table data structure, containing some |
590 | additional FRV-specific data. */ | |
43850d5b | 591 | struct frvfdpic_elf_link_hash_table |
4e5ba5b7 | 592 | { |
51532845 AO |
593 | struct elf_link_hash_table elf; |
594 | ||
595 | /* A pointer to the .got section. */ | |
596 | asection *sgot; | |
597 | /* A pointer to the .rel.got section. */ | |
598 | asection *sgotrel; | |
599 | /* A pointer to the .rofixup section. */ | |
600 | asection *sgotfixup; | |
601 | /* A pointer to the .plt section. */ | |
602 | asection *splt; | |
603 | /* A pointer to the .rel.plt section. */ | |
604 | asection *spltrel; | |
605 | /* GOT base offset. */ | |
606 | bfd_vma got0; | |
607 | /* Location of the first non-lazy PLT entry, i.e., the number of | |
608 | bytes taken by lazy PLT entries. */ | |
609 | bfd_vma plt0; | |
610 | /* A hash table holding information about which symbols were | |
611 | referenced with which PIC-related relocations. */ | |
612 | struct htab *relocs_info; | |
613 | }; | |
4e5ba5b7 | 614 | |
51532845 AO |
615 | /* Get the FRV ELF linker hash table from a link_info structure. */ |
616 | ||
43850d5b AO |
617 | #define frvfdpic_hash_table(info) \ |
618 | ((struct frvfdpic_elf_link_hash_table *) ((info)->hash)) | |
619 | ||
620 | #define frvfdpic_got_section(info) \ | |
621 | (frvfdpic_hash_table (info)->sgot) | |
622 | #define frvfdpic_gotrel_section(info) \ | |
623 | (frvfdpic_hash_table (info)->sgotrel) | |
624 | #define frvfdpic_gotfixup_section(info) \ | |
625 | (frvfdpic_hash_table (info)->sgotfixup) | |
626 | #define frvfdpic_plt_section(info) \ | |
627 | (frvfdpic_hash_table (info)->splt) | |
628 | #define frvfdpic_pltrel_section(info) \ | |
629 | (frvfdpic_hash_table (info)->spltrel) | |
630 | #define frvfdpic_relocs_info(info) \ | |
631 | (frvfdpic_hash_table (info)->relocs_info) | |
632 | #define frvfdpic_got_initial_offset(info) \ | |
633 | (frvfdpic_hash_table (info)->got0) | |
634 | #define frvfdpic_plt_initial_offset(info) \ | |
635 | (frvfdpic_hash_table (info)->plt0) | |
51532845 AO |
636 | |
637 | /* Create an FRV ELF linker hash table. */ | |
638 | ||
639 | static struct bfd_link_hash_table * | |
43850d5b | 640 | frvfdpic_elf_link_hash_table_create (bfd *abfd) |
51532845 | 641 | { |
43850d5b AO |
642 | struct frvfdpic_elf_link_hash_table *ret; |
643 | bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table); | |
4e5ba5b7 | 644 | |
51532845 AO |
645 | ret = bfd_zalloc (abfd, amt); |
646 | if (ret == NULL) | |
647 | return NULL; | |
4e5ba5b7 | 648 | |
51532845 AO |
649 | if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, |
650 | _bfd_elf_link_hash_newfunc)) | |
651 | { | |
652 | free (ret); | |
653 | return NULL; | |
654 | } | |
4e5ba5b7 | 655 | |
51532845 AO |
656 | return &ret->elf.root; |
657 | } | |
4e5ba5b7 | 658 | |
51532845 AO |
659 | /* Decide whether a reference to a symbol can be resolved locally or |
660 | not. If the symbol is protected, we want the local address, but | |
661 | its function descriptor must be assigned by the dynamic linker. */ | |
43850d5b | 662 | #define FRVFDPIC_SYM_LOCAL(INFO, H) \ |
51532845 AO |
663 | (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \ |
664 | || ! elf_hash_table (INFO)->dynamic_sections_created \ | |
51532845 AO |
665 | || (/* The condition below is an ugly hack to get .scommon data to |
666 | be regarded as local. For some reason the | |
667 | ELF_LINK_HASH_DEF_REGULAR bit is not set on such common | |
668 | symbols, and the SEC_IS_COMMON bit is not set any longer | |
669 | when we need to perform this test. Hopefully this | |
670 | approximation is good enough. */ \ | |
671 | ((H)->root.type == bfd_link_hash_defined \ | |
672 | || (H)->root.type == bfd_link_hash_defweak) \ | |
673 | && (H)->root.u.def.section->output_section \ | |
674 | && ((H)->root.u.def.section->flags & SEC_LINKER_CREATED))) | |
43850d5b | 675 | #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \ |
51532845 AO |
676 | ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created) |
677 | ||
678 | /* This structure collects information on what kind of GOT, PLT or | |
679 | function descriptors are required by relocations that reference a | |
680 | certain symbol. */ | |
43850d5b | 681 | struct frvfdpic_relocs_info |
51532845 AO |
682 | { |
683 | /* The index of the symbol, as stored in the relocation r_info, if | |
684 | we have a local symbol; -1 otherwise. */ | |
685 | long symndx; | |
686 | union | |
687 | { | |
688 | /* The input bfd in which the symbol is defined, if it's a local | |
689 | symbol. */ | |
690 | bfd *abfd; | |
691 | /* If symndx == -1, the hash table entry corresponding to a global | |
692 | symbol (even if it turns out to bind locally, in which case it | |
693 | should ideally be replaced with section's symndx + addend). */ | |
694 | struct elf_link_hash_entry *h; | |
695 | } d; | |
696 | /* The addend of the relocation that references the symbol. */ | |
697 | bfd_vma addend; | |
698 | ||
699 | /* The fields above are used to identify an entry. The fields below | |
700 | contain information on how an entry is used and, later on, which | |
701 | locations it was assigned. */ | |
702 | /* The following 3 fields record whether the symbol+addend above was | |
703 | ever referenced with a GOT relocation. The 12 suffix indicates a | |
704 | GOT12 relocation; los is used for GOTLO relocations that are not | |
705 | matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI | |
706 | pairs. */ | |
707 | unsigned got12:1; | |
708 | unsigned gotlos:1; | |
709 | unsigned gothilo:1; | |
710 | /* Whether a FUNCDESC relocation references symbol+addend. */ | |
711 | unsigned fd:1; | |
712 | /* Whether a FUNCDESC_GOT relocation references symbol+addend. */ | |
713 | unsigned fdgot12:1; | |
714 | unsigned fdgotlos:1; | |
715 | unsigned fdgothilo:1; | |
716 | /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */ | |
717 | unsigned fdgoff12:1; | |
718 | unsigned fdgofflos:1; | |
719 | unsigned fdgoffhilo:1; | |
720 | /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or | |
721 | GOTOFFHI relocations. The addend doesn't really matter, since we | |
722 | envision that this will only be used to check whether the symbol | |
723 | is mapped to the same segment as the got. */ | |
724 | unsigned gotoff:1; | |
725 | /* Whether symbol+addend is referenced by a LABEL24 relocation. */ | |
726 | unsigned call:1; | |
727 | /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE | |
728 | relocation. */ | |
729 | unsigned sym:1; | |
730 | /* Whether we need a PLT entry for a symbol. Should be implied by | |
731 | something like: | |
43850d5b | 732 | (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */ |
51532845 AO |
733 | unsigned plt:1; |
734 | /* Whether a function descriptor should be created in this link unit | |
735 | for symbol+addend. Should be implied by something like: | |
736 | (plt || fdgotoff12 || fdgotofflos || fdgotofflohi | |
737 | || ((fd || fdgot12 || fdgotlos || fdgothilo) | |
43850d5b | 738 | && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */ |
51532845 AO |
739 | unsigned privfd:1; |
740 | /* Whether a lazy PLT entry is needed for this symbol+addend. | |
741 | Should be implied by something like: | |
43850d5b | 742 | (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h) |
51532845 AO |
743 | && ! (info->flags & DF_BIND_NOW)) */ |
744 | unsigned lazyplt:1; | |
745 | /* Whether we've already emitted GOT relocations and PLT entries as | |
746 | needed for this symbol. */ | |
747 | unsigned done:1; | |
748 | ||
749 | /* The number of R_FRV_32, R_FRV_FUNCDESC and R_FRV_FUNCDESC_VALUE | |
750 | relocations referencing the symbol. */ | |
751 | unsigned relocs32, relocsfd, relocsfdv; | |
752 | ||
3b712a1a AO |
753 | /* The number of .rofixups entries and dynamic relocations allocated |
754 | for this symbol, minus any that might have already been used. */ | |
755 | unsigned fixups, dynrelocs; | |
756 | ||
51532845 AO |
757 | /* The offsets of the GOT entries assigned to symbol+addend, to the |
758 | function descriptor's address, and to a function descriptor, | |
759 | respectively. Should be zero if unassigned. The offsets are | |
760 | counted from the value that will be assigned to the PIC register, | |
761 | not from the beginning of the .got section. */ | |
762 | bfd_signed_vma got_entry, fdgot_entry, fd_entry; | |
763 | /* The offsets of the PLT entries assigned to symbol+addend, | |
764 | non-lazy and lazy, respectively. If unassigned, should be | |
765 | (bfd_vma)-1. */ | |
766 | bfd_vma plt_entry, lzplt_entry; | |
767 | }; | |
4e5ba5b7 | 768 | |
43850d5b | 769 | /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */ |
51532845 | 770 | static hashval_t |
43850d5b | 771 | frvfdpic_relocs_info_hash (const void *entry_) |
51532845 | 772 | { |
43850d5b | 773 | const struct frvfdpic_relocs_info *entry = entry_; |
4e5ba5b7 | 774 | |
51532845 AO |
775 | return (entry->symndx == -1 |
776 | ? entry->d.h->root.root.hash | |
777 | : entry->symndx + entry->d.abfd->id * 257) + entry->addend; | |
4e5ba5b7 DB |
778 | } |
779 | ||
43850d5b | 780 | /* Test whether the key fields of two frvfdpic_relocs_info entries are |
51532845 AO |
781 | identical. */ |
782 | static int | |
43850d5b | 783 | frvfdpic_relocs_info_eq (const void *entry1, const void *entry2) |
51532845 | 784 | { |
43850d5b AO |
785 | const struct frvfdpic_relocs_info *e1 = entry1; |
786 | const struct frvfdpic_relocs_info *e2 = entry2; | |
4e5ba5b7 | 787 | |
51532845 AO |
788 | return e1->symndx == e2->symndx && e1->addend == e2->addend |
789 | && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd); | |
790 | } | |
791 | ||
792 | /* Find or create an entry in a hash table HT that matches the key | |
793 | fields of the given ENTRY. If it's not found, memory for a new | |
794 | entry is allocated in ABFD's obstack. */ | |
43850d5b AO |
795 | static struct frvfdpic_relocs_info * |
796 | frvfdpic_relocs_info_find (struct htab *ht, | |
797 | bfd *abfd, | |
798 | const struct frvfdpic_relocs_info *entry, | |
799 | enum insert_option insert) | |
4e5ba5b7 | 800 | { |
43850d5b AO |
801 | struct frvfdpic_relocs_info **loc = |
802 | (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert); | |
3b712a1a AO |
803 | |
804 | if (! loc) | |
805 | return NULL; | |
4e5ba5b7 | 806 | |
51532845 AO |
807 | if (*loc) |
808 | return *loc; | |
4e5ba5b7 | 809 | |
51532845 | 810 | *loc = bfd_zalloc (abfd, sizeof (**loc)); |
b34976b6 | 811 | |
51532845 AO |
812 | if (! *loc) |
813 | return *loc; | |
814 | ||
815 | (*loc)->symndx = entry->symndx; | |
816 | (*loc)->d = entry->d; | |
817 | (*loc)->addend = entry->addend; | |
818 | (*loc)->plt_entry = (bfd_vma)-1; | |
819 | (*loc)->lzplt_entry = (bfd_vma)-1; | |
820 | ||
821 | return *loc; | |
822 | } | |
823 | ||
824 | /* Obtain the address of the entry in HT associated with H's symbol + | |
825 | addend, creating a new entry if none existed. ABFD is only used | |
826 | for memory allocation purposes. */ | |
43850d5b AO |
827 | inline static struct frvfdpic_relocs_info * |
828 | frvfdpic_relocs_info_for_global (struct htab *ht, | |
829 | bfd *abfd, | |
830 | struct elf_link_hash_entry *h, | |
831 | bfd_vma addend, | |
832 | enum insert_option insert) | |
51532845 | 833 | { |
43850d5b | 834 | struct frvfdpic_relocs_info entry; |
51532845 AO |
835 | |
836 | entry.symndx = -1; | |
837 | entry.d.h = h; | |
838 | entry.addend = addend; | |
839 | ||
43850d5b | 840 | return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); |
51532845 AO |
841 | } |
842 | ||
843 | /* Obtain the address of the entry in HT associated with the SYMNDXth | |
844 | local symbol of the input bfd ABFD, plus the addend, creating a new | |
845 | entry if none existed. */ | |
43850d5b AO |
846 | inline static struct frvfdpic_relocs_info * |
847 | frvfdpic_relocs_info_for_local (struct htab *ht, | |
848 | bfd *abfd, | |
849 | long symndx, | |
850 | bfd_vma addend, | |
851 | enum insert_option insert) | |
51532845 | 852 | { |
43850d5b | 853 | struct frvfdpic_relocs_info entry; |
51532845 AO |
854 | |
855 | entry.symndx = symndx; | |
856 | entry.d.abfd = abfd; | |
857 | entry.addend = addend; | |
858 | ||
43850d5b | 859 | return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); |
3b712a1a AO |
860 | } |
861 | ||
862 | /* Merge fields set by check_relocs() of two entries that end up being | |
863 | mapped to the same (presumably global) symbol. */ | |
864 | ||
865 | inline static void | |
43850d5b AO |
866 | frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2, |
867 | struct frvfdpic_relocs_info const *e1) | |
3b712a1a AO |
868 | { |
869 | e2->got12 |= e1->got12; | |
870 | e2->gotlos |= e1->gotlos; | |
871 | e2->gothilo |= e1->gothilo; | |
872 | e2->fd |= e1->fd; | |
873 | e2->fdgot12 |= e1->fdgot12; | |
874 | e2->fdgotlos |= e1->fdgotlos; | |
875 | e2->fdgothilo |= e1->fdgothilo; | |
876 | e2->fdgoff12 |= e1->fdgoff12; | |
877 | e2->fdgofflos |= e1->fdgofflos; | |
878 | e2->fdgoffhilo |= e1->fdgoffhilo; | |
879 | e2->gotoff |= e1->gotoff; | |
880 | e2->call |= e1->call; | |
881 | e2->sym |= e1->sym; | |
882 | ||
883 | #if 0 | |
43850d5b AO |
884 | /* These are set in _frvfdpic_count_got_plt_entries() or later, and this |
885 | function is only called in _frvfdpic_resolve_final_relocs_info(), that | |
3b712a1a AO |
886 | runs just before it, so we don't have to worry about the fields |
887 | below. */ | |
888 | ||
889 | e2->plt |= e1->plt; | |
890 | e2->privfd |= e1->privfd; | |
891 | e2->lazyplt |= e1->lazyplt; | |
892 | e2->done |= e1->done; | |
893 | ||
894 | e2->relocs32 += e1->relocs32; | |
895 | e2->relocsfd += e1->relocsfd; | |
896 | e2->relocsfdv += e1->relocsfdv; | |
897 | e2->fixups += e1->fixups; | |
898 | e2->dynrelocs += e1->dynrelocs; | |
899 | ||
900 | if (abs (e1->got_entry) < abs (e2->got_entry)) | |
901 | e2->got_entry = e1->got_entry; | |
902 | if (abs (e1->fdgot_entry) < abs (e2->fdgot_entry)) | |
903 | e2->fdgot_entry = e1->fdgot_entry; | |
904 | if (abs (e1->fd_entry) < abs (e2->fd_entry)) | |
905 | e2->fd_entry = e1->fd_entry; | |
906 | ||
907 | if (e1->plt_entry < e2->plt_entry) | |
908 | e2->plt_entry = e1->plt_entry; | |
909 | if (e1->lzplt_entry < e2->lzplt_entry) | |
910 | e2->lzplt_entry = e1->lzplt_entry; | |
911 | #endif | |
51532845 AO |
912 | } |
913 | ||
914 | /* Every block of 65535 lazy PLT entries shares a single call to the | |
915 | resolver, inserted in the 32768th lazy PLT entry (i.e., entry # | |
916 | 32767, counting from 0). All other lazy PLT entries branch to it | |
917 | in a single instruction. */ | |
918 | ||
43850d5b AO |
919 | #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4) |
920 | #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767) | |
51532845 AO |
921 | |
922 | /* Add a dynamic relocation to the SRELOC section. */ | |
923 | ||
924 | inline static bfd_vma | |
43850d5b AO |
925 | _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset, |
926 | int reloc_type, long dynindx, bfd_vma addend, | |
927 | struct frvfdpic_relocs_info *entry) | |
51532845 AO |
928 | { |
929 | Elf_Internal_Rela outrel; | |
930 | bfd_vma reloc_offset; | |
931 | ||
932 | outrel.r_offset = offset; | |
933 | outrel.r_info = ELF32_R_INFO (dynindx, reloc_type); | |
934 | outrel.r_addend = addend; | |
935 | ||
936 | reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel); | |
937 | BFD_ASSERT (reloc_offset < sreloc->_raw_size); | |
938 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, | |
939 | sreloc->contents + reloc_offset); | |
940 | sreloc->reloc_count++; | |
941 | ||
3b712a1a AO |
942 | BFD_ASSERT (entry->dynrelocs > 0); |
943 | entry->dynrelocs--; | |
944 | ||
51532845 AO |
945 | return reloc_offset; |
946 | } | |
947 | ||
948 | /* Add a fixup to the ROFIXUP section. */ | |
949 | ||
950 | static bfd_vma | |
43850d5b AO |
951 | _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset, |
952 | struct frvfdpic_relocs_info *entry) | |
51532845 AO |
953 | { |
954 | bfd_vma fixup_offset; | |
955 | ||
956 | if (rofixup->flags & SEC_EXCLUDE) | |
957 | return -1; | |
958 | ||
959 | fixup_offset = rofixup->reloc_count * 4; | |
960 | if (rofixup->contents) | |
961 | { | |
962 | BFD_ASSERT (fixup_offset < rofixup->_raw_size); | |
963 | bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset); | |
964 | } | |
965 | rofixup->reloc_count++; | |
3b712a1a AO |
966 | |
967 | if (entry) | |
968 | { | |
969 | BFD_ASSERT (entry->fixups > 0); | |
970 | entry->fixups--; | |
971 | } | |
972 | ||
51532845 AO |
973 | return fixup_offset; |
974 | } | |
975 | ||
976 | /* Find the segment number in which OSEC, and output section, is | |
977 | located. */ | |
978 | ||
979 | static unsigned | |
43850d5b | 980 | _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec) |
51532845 AO |
981 | { |
982 | struct elf_segment_map *m; | |
983 | Elf_Internal_Phdr *p; | |
984 | ||
985 | /* Find the segment that contains the output_section. */ | |
986 | for (m = elf_tdata (output_bfd)->segment_map, | |
987 | p = elf_tdata (output_bfd)->phdr; | |
988 | m != NULL; | |
989 | m = m->next, p++) | |
990 | { | |
991 | int i; | |
992 | ||
993 | for (i = m->count - 1; i >= 0; i--) | |
994 | if (m->sections[i] == osec) | |
995 | break; | |
996 | ||
997 | if (i >= 0) | |
998 | break; | |
999 | } | |
1000 | ||
1001 | return p - elf_tdata (output_bfd)->phdr; | |
1002 | } | |
1003 | ||
1004 | inline static bfd_boolean | |
43850d5b | 1005 | _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec) |
51532845 | 1006 | { |
43850d5b | 1007 | unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec); |
51532845 AO |
1008 | |
1009 | return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W); | |
1010 | } | |
1011 | ||
1012 | /* Generate relocations for GOT entries, function descriptors, and | |
1013 | code for PLT and lazy PLT entries. */ | |
1014 | ||
1015 | inline static bfd_boolean | |
43850d5b AO |
1016 | _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry, |
1017 | bfd *output_bfd, | |
1018 | struct bfd_link_info *info, | |
1019 | asection *sec, | |
1020 | Elf_Internal_Sym *sym, | |
1021 | bfd_vma addend) | |
51532845 AO |
1022 | |
1023 | { | |
1024 | bfd_vma fd_lazy_rel_offset = (bfd_vma)-1; | |
1025 | int dynindx = -1; | |
1026 | ||
1027 | if (entry->done) | |
1028 | return TRUE; | |
1029 | entry->done = 1; | |
1030 | ||
1031 | if (entry->got_entry || entry->fdgot_entry || entry->fd_entry) | |
1032 | { | |
1033 | /* If the symbol is dynamic, consider it for dynamic | |
1034 | relocations, otherwise decay to section + offset. */ | |
1035 | if (entry->symndx == -1 && entry->d.h->dynindx != -1) | |
1036 | dynindx = entry->d.h->dynindx; | |
1037 | else | |
1038 | { | |
1039 | if (sec->output_section | |
1040 | && ! bfd_is_abs_section (sec->output_section) | |
1041 | && ! bfd_is_und_section (sec->output_section)) | |
1042 | dynindx = elf_section_data (sec->output_section)->dynindx; | |
1043 | else | |
1044 | dynindx = 0; | |
1045 | } | |
1046 | } | |
1047 | ||
1048 | /* Generate relocation for GOT entry pointing to the symbol. */ | |
1049 | if (entry->got_entry) | |
1050 | { | |
1051 | int idx = dynindx; | |
1052 | bfd_vma ad = addend; | |
1053 | ||
1054 | /* If the symbol is dynamic but binds locally, use | |
1055 | section+offset. */ | |
43850d5b AO |
1056 | if (sec && (entry->symndx != -1 |
1057 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1058 | { |
1059 | if (entry->symndx == -1) | |
1060 | ad += entry->d.h->root.u.def.value; | |
1061 | else | |
1062 | ad += sym->st_value; | |
1063 | ad += sec->output_offset; | |
1064 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1065 | idx = elf_section_data (sec->output_section)->dynindx; | |
1066 | else | |
1067 | idx = 0; | |
1068 | } | |
1069 | ||
1070 | /* If we're linking an executable at a fixed address, we can | |
1071 | omit the dynamic relocation as long as the symbol is local to | |
1072 | this module. */ | |
1073 | if (info->executable && !info->pie | |
43850d5b AO |
1074 | && (entry->symndx != -1 |
1075 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1076 | { |
1077 | if (sec) | |
1078 | ad += sec->output_section->vma; | |
3b712a1a AO |
1079 | if (entry->symndx != -1 |
1080 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
43850d5b AO |
1081 | _frvfdpic_add_rofixup (output_bfd, |
1082 | frvfdpic_gotfixup_section (info), | |
1083 | frvfdpic_got_section (info)->output_section | |
1084 | ->vma | |
1085 | + frvfdpic_got_section (info)->output_offset | |
1086 | + frvfdpic_got_initial_offset (info) | |
1087 | + entry->got_entry, entry); | |
51532845 AO |
1088 | } |
1089 | else | |
43850d5b AO |
1090 | _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), |
1091 | _bfd_elf_section_offset | |
1092 | (output_bfd, info, | |
1093 | frvfdpic_got_section (info), | |
1094 | frvfdpic_got_initial_offset (info) | |
1095 | + entry->got_entry) | |
1096 | + frvfdpic_got_section (info) | |
1097 | ->output_section->vma | |
1098 | + frvfdpic_got_section (info)->output_offset, | |
1099 | R_FRV_32, idx, ad, entry); | |
51532845 AO |
1100 | |
1101 | bfd_put_32 (output_bfd, ad, | |
43850d5b AO |
1102 | frvfdpic_got_section (info)->contents |
1103 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1104 | + entry->got_entry); |
1105 | } | |
1106 | ||
1107 | /* Generate relocation for GOT entry pointing to a canonical | |
1108 | function descriptor. */ | |
1109 | if (entry->fdgot_entry) | |
1110 | { | |
1111 | int reloc, idx; | |
072c8903 | 1112 | bfd_vma ad = 0; |
51532845 | 1113 | |
072c8903 AO |
1114 | if (! (entry->symndx == -1 |
1115 | && entry->d.h->root.type == bfd_link_hash_undefweak | |
43850d5b | 1116 | && FRVFDPIC_SYM_LOCAL (info, entry->d.h))) |
51532845 | 1117 | { |
072c8903 AO |
1118 | /* If the symbol is dynamic and there may be dynamic symbol |
1119 | resolution because we are, or are linked with, a shared | |
1120 | library, emit a FUNCDESC relocation such that the dynamic | |
1121 | linker will allocate the function descriptor. If the | |
1122 | symbol needs a non-local function descriptor but binds | |
1123 | locally (e.g., its visibility is protected, emit a | |
1124 | dynamic relocation decayed to section+offset. */ | |
43850d5b AO |
1125 | if (entry->symndx == -1 |
1126 | && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h) | |
1127 | && FRVFDPIC_SYM_LOCAL (info, entry->d.h) | |
072c8903 AO |
1128 | && !(info->executable && !info->pie)) |
1129 | { | |
1130 | reloc = R_FRV_FUNCDESC; | |
1131 | idx = elf_section_data (entry->d.h->root.u.def.section | |
1132 | ->output_section)->dynindx; | |
1133 | ad = entry->d.h->root.u.def.section->output_offset | |
1134 | + entry->d.h->root.u.def.value; | |
1135 | } | |
1136 | else if (entry->symndx == -1 | |
43850d5b | 1137 | && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)) |
072c8903 AO |
1138 | { |
1139 | reloc = R_FRV_FUNCDESC; | |
1140 | idx = dynindx; | |
1141 | ad = addend; | |
1142 | if (ad) | |
1143 | return FALSE; | |
1144 | } | |
51532845 | 1145 | else |
072c8903 AO |
1146 | { |
1147 | /* Otherwise, we know we have a private function descriptor, | |
1148 | so reference it directly. */ | |
1149 | if (elf_hash_table (info)->dynamic_sections_created) | |
1150 | BFD_ASSERT (entry->privfd); | |
1151 | reloc = R_FRV_32; | |
43850d5b | 1152 | idx = elf_section_data (frvfdpic_got_section (info) |
072c8903 | 1153 | ->output_section)->dynindx; |
43850d5b AO |
1154 | ad = frvfdpic_got_section (info)->output_offset |
1155 | + frvfdpic_got_initial_offset (info) + entry->fd_entry; | |
072c8903 AO |
1156 | } |
1157 | ||
1158 | /* If there is room for dynamic symbol resolution, emit the | |
1159 | dynamic relocation. However, if we're linking an | |
1160 | executable at a fixed location, we won't have emitted a | |
1161 | dynamic symbol entry for the got section, so idx will be | |
1162 | zero, which means we can and should compute the address | |
1163 | of the private descriptor ourselves. */ | |
1164 | if (info->executable && !info->pie | |
1165 | && (entry->symndx != -1 | |
43850d5b | 1166 | || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))) |
51532845 | 1167 | { |
43850d5b AO |
1168 | ad += frvfdpic_got_section (info)->output_section->vma; |
1169 | _frvfdpic_add_rofixup (output_bfd, | |
1170 | frvfdpic_gotfixup_section (info), | |
1171 | frvfdpic_got_section (info) | |
1172 | ->output_section->vma | |
1173 | + frvfdpic_got_section (info) | |
1174 | ->output_offset | |
1175 | + frvfdpic_got_initial_offset (info) | |
1176 | + entry->fdgot_entry, entry); | |
51532845 | 1177 | } |
072c8903 | 1178 | else |
43850d5b AO |
1179 | _frvfdpic_add_dyn_reloc (output_bfd, |
1180 | frvfdpic_gotrel_section (info), | |
1181 | _bfd_elf_section_offset | |
1182 | (output_bfd, info, | |
1183 | frvfdpic_got_section (info), | |
1184 | frvfdpic_got_initial_offset (info) | |
1185 | + entry->fdgot_entry) | |
1186 | + frvfdpic_got_section (info) | |
1187 | ->output_section->vma | |
1188 | + frvfdpic_got_section (info) | |
1189 | ->output_offset, | |
1190 | reloc, idx, ad, entry); | |
51532845 | 1191 | } |
51532845 AO |
1192 | |
1193 | bfd_put_32 (output_bfd, ad, | |
43850d5b AO |
1194 | frvfdpic_got_section (info)->contents |
1195 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1196 | + entry->fdgot_entry); |
1197 | } | |
1198 | ||
1199 | /* Generate relocation to fill in a private function descriptor in | |
1200 | the GOT. */ | |
1201 | if (entry->fd_entry) | |
1202 | { | |
1203 | int idx = dynindx; | |
1204 | bfd_vma ad = addend; | |
1205 | bfd_vma ofst; | |
1206 | long lowword, highword; | |
1207 | ||
1208 | /* If the symbol is dynamic but binds locally, use | |
1209 | section+offset. */ | |
43850d5b AO |
1210 | if (sec && (entry->symndx != -1 |
1211 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1212 | { |
1213 | if (entry->symndx == -1) | |
1214 | ad += entry->d.h->root.u.def.value; | |
1215 | else | |
1216 | ad += sym->st_value; | |
1217 | ad += sec->output_offset; | |
1218 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1219 | idx = elf_section_data (sec->output_section)->dynindx; | |
1220 | else | |
1221 | idx = 0; | |
1222 | } | |
1223 | ||
1224 | /* If we're linking an executable at a fixed address, we can | |
1225 | omit the dynamic relocation as long as the symbol is local to | |
1226 | this module. */ | |
1227 | if (info->executable && !info->pie | |
43850d5b | 1228 | && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) |
51532845 AO |
1229 | { |
1230 | if (sec) | |
1231 | ad += sec->output_section->vma; | |
1232 | ofst = 0; | |
3b712a1a AO |
1233 | if (entry->symndx != -1 |
1234 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
51532845 | 1235 | { |
43850d5b AO |
1236 | _frvfdpic_add_rofixup (output_bfd, |
1237 | frvfdpic_gotfixup_section (info), | |
1238 | frvfdpic_got_section (info) | |
1239 | ->output_section->vma | |
1240 | + frvfdpic_got_section (info) | |
1241 | ->output_offset | |
1242 | + frvfdpic_got_initial_offset (info) | |
1243 | + entry->fd_entry, entry); | |
1244 | _frvfdpic_add_rofixup (output_bfd, | |
1245 | frvfdpic_gotfixup_section (info), | |
1246 | frvfdpic_got_section (info) | |
1247 | ->output_section->vma | |
1248 | + frvfdpic_got_section (info) | |
1249 | ->output_offset | |
1250 | + frvfdpic_got_initial_offset (info) | |
1251 | + entry->fd_entry + 4, entry); | |
51532845 AO |
1252 | } |
1253 | } | |
1254 | else | |
1255 | { | |
1256 | ofst = | |
43850d5b AO |
1257 | _frvfdpic_add_dyn_reloc (output_bfd, |
1258 | entry->lazyplt | |
1259 | ? frvfdpic_pltrel_section (info) | |
1260 | : frvfdpic_gotrel_section (info), | |
1261 | _bfd_elf_section_offset | |
1262 | (output_bfd, info, | |
1263 | frvfdpic_got_section (info), | |
1264 | frvfdpic_got_initial_offset (info) | |
1265 | + entry->fd_entry) | |
1266 | + frvfdpic_got_section (info) | |
1267 | ->output_section->vma | |
1268 | + frvfdpic_got_section (info) | |
1269 | ->output_offset, | |
1270 | R_FRV_FUNCDESC_VALUE, idx, ad, entry); | |
51532845 AO |
1271 | } |
1272 | ||
1273 | /* If we've omitted the dynamic relocation, just emit the fixed | |
1274 | addresses of the symbol and of the local GOT base offset. */ | |
1275 | if (info->executable && !info->pie && sec && sec->output_section) | |
1276 | { | |
1277 | lowword = ad; | |
43850d5b AO |
1278 | highword = frvfdpic_got_section (info)->output_section->vma |
1279 | + frvfdpic_got_section (info)->output_offset | |
1280 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
1281 | } |
1282 | else if (entry->lazyplt) | |
1283 | { | |
1284 | if (ad) | |
1285 | return FALSE; | |
1286 | ||
1287 | fd_lazy_rel_offset = ofst; | |
1288 | ||
1289 | /* A function descriptor used for lazy or local resolving is | |
1290 | initialized such that its high word contains the output | |
1291 | section index in which the PLT entries are located, and | |
1292 | the low word contains the address of the lazy PLT entry | |
1293 | entry point, that must be within the memory region | |
1294 | assigned to that section. */ | |
1295 | lowword = entry->lzplt_entry + 4 | |
43850d5b AO |
1296 | + frvfdpic_plt_section (info)->output_offset |
1297 | + frvfdpic_plt_section (info)->output_section->vma; | |
1298 | highword = _frvfdpic_osec_to_segment | |
1299 | (output_bfd, frvfdpic_plt_section (info)->output_section); | |
51532845 AO |
1300 | } |
1301 | else | |
1302 | { | |
1303 | /* A function descriptor for a local function gets the index | |
1304 | of the section. For a non-local function, it's | |
1305 | disregarded. */ | |
1306 | lowword = ad; | |
1307 | if (entry->symndx == -1 && entry->d.h->dynindx != -1 | |
1308 | && entry->d.h->dynindx == idx) | |
1309 | highword = 0; | |
1310 | else | |
43850d5b AO |
1311 | highword = _frvfdpic_osec_to_segment |
1312 | (output_bfd, sec->output_section); | |
51532845 AO |
1313 | } |
1314 | ||
1315 | bfd_put_32 (output_bfd, lowword, | |
43850d5b AO |
1316 | frvfdpic_got_section (info)->contents |
1317 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1318 | + entry->fd_entry); |
1319 | bfd_put_32 (output_bfd, highword, | |
43850d5b AO |
1320 | frvfdpic_got_section (info)->contents |
1321 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1322 | + entry->fd_entry + 4); |
1323 | } | |
1324 | ||
1325 | /* Generate code for the PLT entry. */ | |
1326 | if (entry->plt_entry != (bfd_vma) -1) | |
1327 | { | |
43850d5b AO |
1328 | bfd_byte *plt_code = frvfdpic_plt_section (info)->contents |
1329 | + entry->plt_entry; | |
51532845 AO |
1330 | |
1331 | BFD_ASSERT (entry->fd_entry); | |
1332 | ||
1333 | /* Figure out what kind of PLT entry we need, depending on the | |
1334 | location of the function descriptor within the GOT. */ | |
1335 | if (entry->fd_entry >= -(1 << (12 - 1)) | |
1336 | && entry->fd_entry < (1 << (12 - 1))) | |
1337 | { | |
1338 | /* lddi @(gr15, fd_entry), gr14 */ | |
1339 | bfd_put_32 (output_bfd, | |
1340 | 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)), | |
1341 | plt_code); | |
1342 | plt_code += 4; | |
1343 | } | |
1344 | else | |
1345 | { | |
1346 | if (entry->fd_entry >= -(1 << (16 - 1)) | |
1347 | && entry->fd_entry < (1 << (16 - 1))) | |
1348 | { | |
1349 | /* setlos lo(fd_entry), gr14 */ | |
1350 | bfd_put_32 (output_bfd, | |
1351 | 0x9cfc0000 | |
1352 | | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), | |
1353 | plt_code); | |
1354 | plt_code += 4; | |
1355 | } | |
1356 | else | |
1357 | { | |
1358 | /* sethi.p hi(fd_entry), gr14 | |
1359 | setlo lo(fd_entry), gr14 */ | |
1360 | bfd_put_32 (output_bfd, | |
1361 | 0x1cf80000 | |
1362 | | ((entry->fd_entry >> 16) | |
1363 | & (((bfd_vma)1 << 16) - 1)), | |
1364 | plt_code); | |
1365 | bfd_put_32 (output_bfd, | |
1366 | 0x9cf40000 | |
1367 | | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), | |
1368 | plt_code); | |
1369 | plt_code += 8; | |
1370 | } | |
1371 | /* ldd @(gr14,gr15),gr14 */ | |
1372 | bfd_put_32 (output_bfd, 0x9c08e14f, plt_code); | |
1373 | plt_code += 4; | |
1374 | } | |
1375 | /* jmpl @(gr14,gr0) */ | |
1376 | bfd_put_32 (output_bfd, 0x8030e000, plt_code); | |
1377 | } | |
1378 | ||
1379 | /* Generate code for the lazy PLT entry. */ | |
1380 | if (entry->lzplt_entry != (bfd_vma) -1) | |
1381 | { | |
43850d5b | 1382 | bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents |
51532845 AO |
1383 | + entry->lzplt_entry; |
1384 | bfd_vma resolverStub_addr; | |
1385 | ||
1386 | bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code); | |
1387 | lzplt_code += 4; | |
1388 | ||
43850d5b AO |
1389 | resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE |
1390 | * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC; | |
1391 | if (resolverStub_addr >= frvfdpic_plt_initial_offset (info)) | |
1392 | resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12; | |
51532845 AO |
1393 | |
1394 | if (entry->lzplt_entry == resolverStub_addr) | |
1395 | { | |
1396 | /* This is a lazy PLT entry that includes a resolver call. */ | |
1397 | /* ldd @(gr15,gr0), gr4 | |
1398 | jmpl @(gr4,gr0) */ | |
1399 | bfd_put_32 (output_bfd, 0x8808f140, lzplt_code); | |
1400 | bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4); | |
1401 | } | |
1402 | else | |
1403 | { | |
1404 | /* bra resolverStub */ | |
1405 | bfd_put_32 (output_bfd, | |
1406 | 0xc01a0000 | |
1407 | | (((resolverStub_addr - entry->lzplt_entry) | |
1408 | / 4) & (((bfd_vma)1 << 16) - 1)), | |
1409 | lzplt_code); | |
1410 | } | |
1411 | } | |
1412 | ||
1413 | return TRUE; | |
1414 | } | |
1415 | ||
1416 | /* Handle an FRV small data reloc. */ | |
1417 | ||
1418 | static bfd_reloc_status_type | |
1419 | elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation, | |
1420 | contents, value) | |
1421 | struct bfd_link_info *info; | |
1422 | bfd *input_bfd; | |
1423 | asection *input_section; | |
1424 | Elf_Internal_Rela *relocation; | |
1425 | bfd_byte *contents; | |
1426 | bfd_vma value; | |
1427 | { | |
1428 | bfd_vma insn; | |
1429 | bfd_vma gp; | |
1430 | struct bfd_link_hash_entry *h; | |
1431 | ||
1432 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); | |
1433 | ||
1434 | gp = (h->u.def.value | |
1435 | + h->u.def.section->output_section->vma | |
1436 | + h->u.def.section->output_offset); | |
1437 | ||
1438 | value -= input_section->output_section->vma; | |
1439 | value -= (gp - input_section->output_section->vma); | |
1440 | ||
1441 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
1442 | ||
1443 | value += relocation->r_addend; | |
1444 | ||
1445 | if ((long) value > 0x7ff || (long) value < -0x800) | |
1446 | return bfd_reloc_overflow; | |
1447 | ||
1448 | bfd_put_32 (input_bfd, | |
1449 | (insn & 0xfffff000) | (value & 0xfff), | |
1450 | contents + relocation->r_offset); | |
1451 | ||
1452 | return bfd_reloc_ok; | |
1453 | } | |
1454 | ||
1455 | /* Handle an FRV small data reloc. for the u12 field. */ | |
1456 | ||
1457 | static bfd_reloc_status_type | |
1458 | elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation, | |
1459 | contents, value) | |
1460 | struct bfd_link_info *info; | |
1461 | bfd *input_bfd; | |
1462 | asection *input_section; | |
1463 | Elf_Internal_Rela *relocation; | |
1464 | bfd_byte *contents; | |
1465 | bfd_vma value; | |
1466 | { | |
1467 | bfd_vma insn; | |
1468 | bfd_vma gp; | |
1469 | struct bfd_link_hash_entry *h; | |
1470 | bfd_vma mask; | |
1471 | ||
1472 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); | |
1473 | ||
1474 | gp = (h->u.def.value | |
1475 | + h->u.def.section->output_section->vma | |
1476 | + h->u.def.section->output_offset); | |
1477 | ||
1478 | value -= input_section->output_section->vma; | |
1479 | value -= (gp - input_section->output_section->vma); | |
4e5ba5b7 DB |
1480 | |
1481 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
1482 | ||
1483 | value += relocation->r_addend; | |
1484 | ||
1485 | if ((long) value > 0x7ff || (long) value < -0x800) | |
1486 | return bfd_reloc_overflow; | |
1487 | ||
1488 | /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */ | |
1489 | mask = 0x3f03f; | |
1490 | insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f); | |
1491 | ||
1492 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
1493 | ||
1494 | return bfd_reloc_ok; | |
1495 | } | |
1496 | ||
1497 | /* Handle an FRV ELF HI16 reloc. */ | |
1498 | ||
1499 | static bfd_reloc_status_type | |
1500 | elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value) | |
1501 | bfd *input_bfd; | |
1502 | Elf_Internal_Rela *relhi; | |
1503 | bfd_byte *contents; | |
1504 | bfd_vma value; | |
1505 | { | |
1506 | bfd_vma insn; | |
1507 | ||
1508 | insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); | |
1509 | ||
1510 | value += relhi->r_addend; | |
1511 | value = ((value >> 16) & 0xffff); | |
1512 | ||
1513 | insn = (insn & 0xffff0000) | value; | |
1514 | ||
1515 | if ((long) value > 0xffff || (long) value < -0x10000) | |
1516 | return bfd_reloc_overflow; | |
1517 | ||
1518 | bfd_put_32 (input_bfd, insn, contents + relhi->r_offset); | |
1519 | return bfd_reloc_ok; | |
1520 | ||
1521 | } | |
1522 | static bfd_reloc_status_type | |
1523 | elf32_frv_relocate_lo16 (input_bfd, rello, contents, value) | |
1524 | bfd *input_bfd; | |
1525 | Elf_Internal_Rela *rello; | |
1526 | bfd_byte *contents; | |
1527 | bfd_vma value; | |
1528 | { | |
1529 | bfd_vma insn; | |
1530 | ||
1531 | insn = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
1532 | ||
1533 | value += rello->r_addend; | |
1534 | value = value & 0xffff; | |
1535 | ||
1536 | insn = (insn & 0xffff0000) | value; | |
1537 | ||
1538 | if ((long) value > 0xffff || (long) value < -0x10000) | |
1539 | return bfd_reloc_overflow; | |
1540 | ||
1541 | bfd_put_32 (input_bfd, insn, contents + rello->r_offset); | |
1542 | return bfd_reloc_ok; | |
1543 | } | |
1544 | ||
1545 | /* Perform the relocation for the CALL label24 instruction. */ | |
1546 | ||
1547 | static bfd_reloc_status_type | |
1548 | elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value) | |
1549 | bfd *input_bfd; | |
1550 | asection *input_section; | |
1551 | Elf_Internal_Rela *rello; | |
1552 | bfd_byte *contents; | |
1553 | bfd_vma value; | |
1554 | { | |
1555 | bfd_vma insn; | |
1556 | bfd_vma label6; | |
1557 | bfd_vma label18; | |
1558 | ||
1559 | /* The format for the call instruction is: | |
1560 | ||
b34976b6 | 1561 | 0 000000 0001111 000000000000000000 |
4e5ba5b7 DB |
1562 | label6 opcode label18 |
1563 | ||
1564 | The branch calculation is: pc + (4*label24) | |
1565 | where label24 is the concatenation of label6 and label18. */ | |
1566 | ||
1567 | /* Grab the instruction. */ | |
1568 | insn = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
1569 | ||
1570 | value -= input_section->output_section->vma + input_section->output_offset; | |
1571 | value -= rello->r_offset; | |
1572 | value += rello->r_addend; | |
1573 | ||
1574 | value = value >> 2; | |
1575 | ||
1576 | label6 = value & 0xfc0000; | |
1577 | label6 = label6 << 7; | |
1578 | ||
1579 | label18 = value & 0x3ffff; | |
1580 | ||
1581 | insn = insn & 0x803c0000; | |
1582 | insn = insn | label6; | |
1583 | insn = insn | label18; | |
1584 | ||
1585 | bfd_put_32 (input_bfd, insn, contents + rello->r_offset); | |
1586 | ||
1587 | return bfd_reloc_ok; | |
1588 | } | |
1589 | ||
1590 | static bfd_reloc_status_type | |
b34976b6 AM |
1591 | elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation, |
1592 | contents, value) | |
4e5ba5b7 DB |
1593 | struct bfd_link_info *info; |
1594 | bfd *input_bfd; | |
1595 | asection *input_section; | |
1596 | Elf_Internal_Rela *relocation; | |
1597 | bfd_byte *contents; | |
1598 | bfd_vma value; | |
1599 | { | |
1600 | bfd_vma insn; | |
1601 | bfd_vma gp; | |
1602 | struct bfd_link_hash_entry *h; | |
1603 | ||
b34976b6 | 1604 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); |
4e5ba5b7 DB |
1605 | |
1606 | gp = (h->u.def.value | |
1607 | + h->u.def.section->output_section->vma | |
1608 | + h->u.def.section->output_offset); | |
1609 | ||
1610 | value -= input_section->output_section->vma; | |
1611 | value -= (gp - input_section->output_section->vma); | |
1612 | value += relocation->r_addend; | |
1613 | value = ((value >> 16) & 0xffff); | |
1614 | ||
1615 | if ((long) value > 0xffff || (long) value < -0x10000) | |
1616 | return bfd_reloc_overflow; | |
1617 | ||
1618 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
1619 | insn = (insn & 0xffff0000) | value; | |
1620 | ||
1621 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
1622 | return bfd_reloc_ok; | |
1623 | } | |
1624 | ||
1625 | static bfd_reloc_status_type | |
b34976b6 AM |
1626 | elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation, |
1627 | contents, value) | |
4e5ba5b7 DB |
1628 | struct bfd_link_info *info; |
1629 | bfd *input_bfd; | |
1630 | asection *input_section; | |
1631 | Elf_Internal_Rela *relocation; | |
1632 | bfd_byte *contents; | |
1633 | bfd_vma value; | |
1634 | { | |
1635 | bfd_vma insn; | |
1636 | bfd_vma gp; | |
1637 | struct bfd_link_hash_entry *h; | |
1638 | ||
b34976b6 | 1639 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); |
4e5ba5b7 DB |
1640 | |
1641 | gp = (h->u.def.value | |
1642 | + h->u.def.section->output_section->vma | |
1643 | + h->u.def.section->output_offset); | |
1644 | ||
1645 | value -= input_section->output_section->vma; | |
1646 | value -= (gp - input_section->output_section->vma); | |
1647 | value += relocation->r_addend; | |
1648 | value = value & 0xffff; | |
1649 | ||
1650 | if ((long) value > 0xffff || (long) value < -0x10000) | |
1651 | return bfd_reloc_overflow; | |
1652 | ||
1653 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
1654 | insn = (insn & 0xffff0000) | value; | |
1655 | ||
1656 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
1657 | ||
1658 | return bfd_reloc_ok; | |
1659 | } | |
1660 | ||
1661 | static reloc_howto_type * | |
1662 | frv_reloc_type_lookup (abfd, code) | |
b34976b6 | 1663 | bfd *abfd ATTRIBUTE_UNUSED; |
4e5ba5b7 DB |
1664 | bfd_reloc_code_real_type code; |
1665 | { | |
1666 | switch (code) | |
1667 | { | |
1668 | default: | |
1669 | break; | |
1670 | ||
1671 | case BFD_RELOC_NONE: | |
1672 | return &elf32_frv_howto_table[ (int) R_FRV_NONE]; | |
b34976b6 | 1673 | |
4e5ba5b7 | 1674 | case BFD_RELOC_32: |
51532845 AO |
1675 | if (elf_elfheader (abfd)->e_type == ET_EXEC |
1676 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
1677 | return &elf32_frv_rel_32_howto; | |
1678 | /* Fall through. */ | |
4e5ba5b7 DB |
1679 | case BFD_RELOC_CTOR: |
1680 | return &elf32_frv_howto_table[ (int) R_FRV_32]; | |
1681 | ||
1682 | case BFD_RELOC_FRV_LABEL16: | |
1683 | return &elf32_frv_howto_table[ (int) R_FRV_LABEL16]; | |
1684 | ||
1685 | case BFD_RELOC_FRV_LABEL24: | |
1686 | return &elf32_frv_howto_table[ (int) R_FRV_LABEL24]; | |
1687 | ||
1688 | case BFD_RELOC_FRV_LO16: | |
1689 | return &elf32_frv_howto_table[ (int) R_FRV_LO16]; | |
1690 | ||
1691 | case BFD_RELOC_FRV_HI16: | |
1692 | return &elf32_frv_howto_table[ (int) R_FRV_HI16]; | |
1693 | ||
1694 | case BFD_RELOC_FRV_GPREL12: | |
1695 | return &elf32_frv_howto_table[ (int) R_FRV_GPREL12]; | |
1696 | ||
1697 | case BFD_RELOC_FRV_GPRELU12: | |
1698 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12]; | |
1699 | ||
1700 | case BFD_RELOC_FRV_GPREL32: | |
1701 | return &elf32_frv_howto_table[ (int) R_FRV_GPREL32]; | |
1702 | ||
1703 | case BFD_RELOC_FRV_GPRELHI: | |
1704 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI]; | |
1705 | ||
1706 | case BFD_RELOC_FRV_GPRELLO: | |
1707 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO]; | |
1708 | ||
51532845 AO |
1709 | case BFD_RELOC_FRV_GOT12: |
1710 | return &elf32_frv_howto_table[ (int) R_FRV_GOT12]; | |
1711 | ||
1712 | case BFD_RELOC_FRV_GOTHI: | |
1713 | return &elf32_frv_howto_table[ (int) R_FRV_GOTHI]; | |
1714 | ||
1715 | case BFD_RELOC_FRV_GOTLO: | |
1716 | return &elf32_frv_howto_table[ (int) R_FRV_GOTLO]; | |
1717 | ||
1718 | case BFD_RELOC_FRV_FUNCDESC: | |
1719 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
1720 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
1721 | return &elf32_frv_rel_funcdesc_howto; | |
1722 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC]; | |
1723 | ||
1724 | case BFD_RELOC_FRV_FUNCDESC_GOT12: | |
1725 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12]; | |
1726 | ||
1727 | case BFD_RELOC_FRV_FUNCDESC_GOTHI: | |
1728 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI]; | |
1729 | ||
1730 | case BFD_RELOC_FRV_FUNCDESC_GOTLO: | |
1731 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO]; | |
1732 | ||
1733 | case BFD_RELOC_FRV_FUNCDESC_VALUE: | |
1734 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
1735 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
1736 | return &elf32_frv_rel_funcdesc_value_howto; | |
1737 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE]; | |
1738 | ||
1739 | case BFD_RELOC_FRV_FUNCDESC_GOTOFF12: | |
1740 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12]; | |
1741 | ||
1742 | case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI: | |
1743 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI]; | |
1744 | ||
1745 | case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO: | |
1746 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO]; | |
1747 | ||
1748 | case BFD_RELOC_FRV_GOTOFF12: | |
1749 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12]; | |
1750 | ||
1751 | case BFD_RELOC_FRV_GOTOFFHI: | |
1752 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI]; | |
1753 | ||
1754 | case BFD_RELOC_FRV_GOTOFFLO: | |
1755 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO]; | |
1756 | ||
4e5ba5b7 DB |
1757 | case BFD_RELOC_VTABLE_INHERIT: |
1758 | return &elf32_frv_vtinherit_howto; | |
1759 | ||
1760 | case BFD_RELOC_VTABLE_ENTRY: | |
1761 | return &elf32_frv_vtentry_howto; | |
1762 | } | |
1763 | ||
1764 | return NULL; | |
1765 | } | |
1766 | ||
1767 | /* Set the howto pointer for an FRV ELF reloc. */ | |
1768 | ||
1769 | static void | |
1770 | frv_info_to_howto_rela (abfd, cache_ptr, dst) | |
b34976b6 AM |
1771 | bfd *abfd ATTRIBUTE_UNUSED; |
1772 | arelent *cache_ptr; | |
1773 | Elf_Internal_Rela *dst; | |
4e5ba5b7 DB |
1774 | { |
1775 | unsigned int r_type; | |
1776 | ||
1777 | r_type = ELF32_R_TYPE (dst->r_info); | |
1778 | switch (r_type) | |
1779 | { | |
1780 | case R_FRV_GNU_VTINHERIT: | |
1781 | cache_ptr->howto = &elf32_frv_vtinherit_howto; | |
1782 | break; | |
1783 | ||
1784 | case R_FRV_GNU_VTENTRY: | |
1785 | cache_ptr->howto = &elf32_frv_vtentry_howto; | |
1786 | break; | |
1787 | ||
1788 | default: | |
1789 | cache_ptr->howto = & elf32_frv_howto_table [r_type]; | |
1790 | break; | |
1791 | } | |
1792 | } | |
51532845 AO |
1793 | |
1794 | /* Set the howto pointer for an FRV ELF REL reloc. */ | |
1795 | static void | |
43850d5b AO |
1796 | frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, |
1797 | arelent *cache_ptr, Elf_Internal_Rela *dst) | |
51532845 AO |
1798 | { |
1799 | unsigned int r_type; | |
1800 | ||
1801 | r_type = ELF32_R_TYPE (dst->r_info); | |
1802 | switch (r_type) | |
1803 | { | |
1804 | case R_FRV_32: | |
1805 | cache_ptr->howto = &elf32_frv_rel_32_howto; | |
1806 | break; | |
1807 | ||
1808 | case R_FRV_FUNCDESC: | |
1809 | cache_ptr->howto = &elf32_frv_rel_funcdesc_howto; | |
1810 | break; | |
1811 | ||
1812 | case R_FRV_FUNCDESC_VALUE: | |
1813 | cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto; | |
1814 | break; | |
1815 | ||
1816 | default: | |
1817 | cache_ptr->howto = NULL; | |
1818 | break; | |
1819 | } | |
1820 | } | |
4e5ba5b7 DB |
1821 | \f |
1822 | /* Perform a single relocation. By default we use the standard BFD | |
1823 | routines, but a few relocs, we have to do them ourselves. */ | |
1824 | ||
1825 | static bfd_reloc_status_type | |
b34976b6 AM |
1826 | frv_final_link_relocate (howto, input_bfd, input_section, contents, rel, |
1827 | relocation) | |
1828 | reloc_howto_type *howto; | |
1829 | bfd *input_bfd; | |
1830 | asection *input_section; | |
1831 | bfd_byte *contents; | |
1832 | Elf_Internal_Rela *rel; | |
1833 | bfd_vma relocation; | |
4e5ba5b7 DB |
1834 | { |
1835 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
1836 | contents, rel->r_offset, relocation, | |
1837 | rel->r_addend); | |
1838 | } | |
1839 | ||
1840 | \f | |
1841 | /* Relocate an FRV ELF section. | |
4e5ba5b7 DB |
1842 | |
1843 | The RELOCATE_SECTION function is called by the new ELF backend linker | |
1844 | to handle the relocations for a section. | |
1845 | ||
1846 | The relocs are always passed as Rela structures; if the section | |
1847 | actually uses Rel structures, the r_addend field will always be | |
1848 | zero. | |
1849 | ||
1850 | This function is responsible for adjusting the section contents as | |
1049f94e | 1851 | necessary, and (if using Rela relocs and generating a relocatable |
4e5ba5b7 DB |
1852 | output file) adjusting the reloc addend as necessary. |
1853 | ||
1854 | This function does not have to worry about setting the reloc | |
1855 | address or the reloc symbol index. | |
1856 | ||
1857 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
1858 | ||
1859 | LOCAL_SECTIONS is an array giving the section in the input file | |
1860 | corresponding to the st_shndx field of each local symbol. | |
1861 | ||
1862 | The global hash table entry for the global symbols can be found | |
1863 | via elf_sym_hashes (input_bfd). | |
1864 | ||
1049f94e | 1865 | When generating relocatable output, this function must handle |
4e5ba5b7 DB |
1866 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
1867 | going to be the section symbol corresponding to the output | |
1868 | section, which means that the addend must be adjusted | |
1869 | accordingly. */ | |
1870 | ||
b34976b6 | 1871 | static bfd_boolean |
4e5ba5b7 | 1872 | elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section, |
de2d743e | 1873 | contents, relocs, local_syms, local_sections) |
b34976b6 AM |
1874 | bfd *output_bfd ATTRIBUTE_UNUSED; |
1875 | struct bfd_link_info *info; | |
1876 | bfd *input_bfd; | |
1877 | asection *input_section; | |
1878 | bfd_byte *contents; | |
1879 | Elf_Internal_Rela *relocs; | |
1880 | Elf_Internal_Sym *local_syms; | |
1881 | asection **local_sections; | |
4e5ba5b7 | 1882 | { |
b34976b6 AM |
1883 | Elf_Internal_Shdr *symtab_hdr; |
1884 | struct elf_link_hash_entry **sym_hashes; | |
1885 | Elf_Internal_Rela *rel; | |
1886 | Elf_Internal_Rela *relend; | |
51532845 AO |
1887 | unsigned isec_segment, got_segment, plt_segment, gprel_segment, |
1888 | check_segment[2]; | |
1889 | int silence_segment_error = !(info->shared || info->pie); | |
4e5ba5b7 | 1890 | |
1049f94e | 1891 | if (info->relocatable) |
b34976b6 | 1892 | return TRUE; |
de2d743e | 1893 | |
4e5ba5b7 DB |
1894 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
1895 | sym_hashes = elf_sym_hashes (input_bfd); | |
1896 | relend = relocs + input_section->reloc_count; | |
1897 | ||
43850d5b AO |
1898 | isec_segment = _frvfdpic_osec_to_segment (output_bfd, |
1899 | input_section->output_section); | |
1900 | if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info)) | |
1901 | got_segment = _frvfdpic_osec_to_segment (output_bfd, | |
1902 | frvfdpic_got_section (info) | |
1903 | ->output_section); | |
51532845 AO |
1904 | else |
1905 | got_segment = -1; | |
43850d5b AO |
1906 | if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info)) |
1907 | gprel_segment = _frvfdpic_osec_to_segment (output_bfd, | |
1908 | frvfdpic_gotfixup_section (info) | |
1909 | ->output_section); | |
51532845 AO |
1910 | else |
1911 | gprel_segment = -1; | |
43850d5b AO |
1912 | if (IS_FDPIC (output_bfd) && elf_hash_table (info)->dynamic_sections_created) |
1913 | plt_segment = _frvfdpic_osec_to_segment (output_bfd, | |
1914 | frvfdpic_plt_section (info) | |
1915 | ->output_section); | |
51532845 AO |
1916 | else |
1917 | plt_segment = -1; | |
1918 | ||
4e5ba5b7 DB |
1919 | for (rel = relocs; rel < relend; rel ++) |
1920 | { | |
b34976b6 AM |
1921 | reloc_howto_type *howto; |
1922 | unsigned long r_symndx; | |
1923 | Elf_Internal_Sym *sym; | |
1924 | asection *sec; | |
1925 | struct elf_link_hash_entry *h; | |
1926 | bfd_vma relocation; | |
1927 | bfd_reloc_status_type r; | |
1928 | const char * name = NULL; | |
1929 | int r_type; | |
51532845 | 1930 | asection *osec; |
43850d5b | 1931 | struct frvfdpic_relocs_info *picrel; |
51532845 AO |
1932 | bfd_vma orig_addend = rel->r_addend; |
1933 | ||
1934 | r_type = ELF32_R_TYPE (rel->r_info); | |
1935 | ||
1936 | if ( r_type == R_FRV_GNU_VTINHERIT | |
1937 | || r_type == R_FRV_GNU_VTENTRY) | |
1938 | continue; | |
1939 | ||
1940 | /* This is a final link. */ | |
1941 | r_symndx = ELF32_R_SYM (rel->r_info); | |
1942 | howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info); | |
1943 | h = NULL; | |
1944 | sym = NULL; | |
1945 | sec = NULL; | |
1946 | ||
1947 | if (r_symndx < symtab_hdr->sh_info) | |
1948 | { | |
1949 | sym = local_syms + r_symndx; | |
1950 | osec = sec = local_sections [r_symndx]; | |
1951 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
1952 | ||
1953 | name = bfd_elf_string_from_elf_section | |
1954 | (input_bfd, symtab_hdr->sh_link, sym->st_name); | |
1955 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; | |
1956 | } | |
1957 | else | |
1958 | { | |
1959 | h = sym_hashes [r_symndx - symtab_hdr->sh_info]; | |
1960 | ||
1961 | while (h->root.type == bfd_link_hash_indirect | |
1962 | || h->root.type == bfd_link_hash_warning) | |
1963 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
1964 | ||
1965 | name = h->root.root.string; | |
1966 | ||
1967 | if ((h->root.type == bfd_link_hash_defined | |
1968 | || h->root.type == bfd_link_hash_defweak) | |
43850d5b | 1969 | && ! FRVFDPIC_SYM_LOCAL (info, h)) |
51532845 AO |
1970 | { |
1971 | sec = NULL; | |
1972 | relocation = 0; | |
1973 | } | |
1974 | else | |
1975 | if (h->root.type == bfd_link_hash_defined | |
1976 | || h->root.type == bfd_link_hash_defweak) | |
1977 | { | |
1978 | sec = h->root.u.def.section; | |
1979 | relocation = (h->root.u.def.value | |
1980 | + sec->output_section->vma | |
1981 | + sec->output_offset); | |
1982 | } | |
1983 | else if (h->root.type == bfd_link_hash_undefweak) | |
1984 | { | |
1985 | relocation = 0; | |
1986 | } | |
59c2e50f | 1987 | else if (info->unresolved_syms_in_objects == RM_IGNORE |
51532845 AO |
1988 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
1989 | relocation = 0; | |
1990 | else | |
1991 | { | |
1992 | if (! ((*info->callbacks->undefined_symbol) | |
1993 | (info, h->root.root.string, input_bfd, | |
59c2e50f L |
1994 | input_section, rel->r_offset, |
1995 | (info->unresolved_syms_in_objects == RM_GENERATE_ERROR | |
1996 | || ELF_ST_VISIBILITY (h->other))))) | |
51532845 AO |
1997 | return FALSE; |
1998 | relocation = 0; | |
1999 | } | |
2000 | osec = sec; | |
2001 | } | |
2002 | ||
2003 | switch (r_type) | |
2004 | { | |
2005 | case R_FRV_LABEL24: | |
2006 | case R_FRV_32: | |
43850d5b AO |
2007 | if (! IS_FDPIC (output_bfd)) |
2008 | goto non_fdpic; | |
2009 | ||
51532845 AO |
2010 | case R_FRV_GOT12: |
2011 | case R_FRV_GOTHI: | |
2012 | case R_FRV_GOTLO: | |
2013 | case R_FRV_FUNCDESC_GOT12: | |
2014 | case R_FRV_FUNCDESC_GOTHI: | |
2015 | case R_FRV_FUNCDESC_GOTLO: | |
2016 | case R_FRV_GOTOFF12: | |
2017 | case R_FRV_GOTOFFHI: | |
2018 | case R_FRV_GOTOFFLO: | |
2019 | case R_FRV_FUNCDESC_GOTOFF12: | |
2020 | case R_FRV_FUNCDESC_GOTOFFHI: | |
2021 | case R_FRV_FUNCDESC_GOTOFFLO: | |
2022 | case R_FRV_FUNCDESC: | |
2023 | case R_FRV_FUNCDESC_VALUE: | |
2024 | if (h != NULL) | |
43850d5b AO |
2025 | picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info |
2026 | (info), input_bfd, h, | |
2027 | orig_addend, INSERT); | |
51532845 AO |
2028 | else |
2029 | /* In order to find the entry we created before, we must | |
2030 | use the original addend, not the one that may have been | |
2031 | modified by _bfd_elf_rela_local_sym(). */ | |
43850d5b AO |
2032 | picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info |
2033 | (info), input_bfd, r_symndx, | |
2034 | orig_addend, INSERT); | |
51532845 AO |
2035 | if (! picrel) |
2036 | return FALSE; | |
2037 | ||
43850d5b AO |
2038 | if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info, |
2039 | osec, sym, | |
2040 | rel->r_addend)) | |
51532845 | 2041 | { |
43850d5b AO |
2042 | (*_bfd_error_handler) |
2043 | (_("%s: relocation at `%s+0x%x' references symbol `%s' with nonzero addend"), | |
2044 | bfd_archive_filename (input_bfd), input_section->name, | |
2045 | rel->r_offset, name); | |
51532845 AO |
2046 | return FALSE; |
2047 | ||
2048 | } | |
2049 | ||
2050 | break; | |
2051 | ||
2052 | default: | |
43850d5b | 2053 | non_fdpic: |
51532845 | 2054 | picrel = NULL; |
43850d5b | 2055 | if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) |
51532845 AO |
2056 | { |
2057 | info->callbacks->warning | |
2058 | (info, _("relocation references symbol not defined in the module"), | |
2059 | name, input_bfd, input_section, rel->r_offset); | |
2060 | return FALSE; | |
2061 | } | |
2062 | break; | |
2063 | } | |
2064 | ||
2065 | switch (r_type) | |
2066 | { | |
2067 | case R_FRV_LABEL24: | |
2068 | check_segment[0] = isec_segment; | |
43850d5b AO |
2069 | if (! IS_FDPIC (output_bfd)) |
2070 | check_segment[1] = isec_segment; | |
2071 | else if (picrel->plt) | |
51532845 | 2072 | { |
43850d5b AO |
2073 | relocation = frvfdpic_plt_section (info)->output_section->vma |
2074 | + frvfdpic_plt_section (info)->output_offset | |
51532845 AO |
2075 | + picrel->plt_entry; |
2076 | check_segment[1] = plt_segment; | |
2077 | } | |
2078 | /* We don't want to warn on calls to undefined weak symbols, | |
2079 | as calls to them must be protected by non-NULL tests | |
2080 | anyway, and unprotected calls would invoke undefined | |
2081 | behavior. */ | |
2082 | else if (picrel->symndx == -1 | |
2083 | && picrel->d.h->root.type == bfd_link_hash_undefweak) | |
2084 | check_segment[1] = check_segment[0]; | |
2085 | else | |
2086 | check_segment[1] = sec | |
43850d5b | 2087 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
2088 | : (unsigned)-1; |
2089 | break; | |
2090 | ||
2091 | case R_FRV_GOT12: | |
2092 | case R_FRV_GOTHI: | |
2093 | case R_FRV_GOTLO: | |
2094 | relocation = picrel->got_entry; | |
2095 | check_segment[0] = check_segment[1] = got_segment; | |
2096 | break; | |
2097 | ||
2098 | case R_FRV_FUNCDESC_GOT12: | |
2099 | case R_FRV_FUNCDESC_GOTHI: | |
2100 | case R_FRV_FUNCDESC_GOTLO: | |
2101 | relocation = picrel->fdgot_entry; | |
2102 | check_segment[0] = check_segment[1] = got_segment; | |
2103 | break; | |
2104 | ||
2105 | case R_FRV_GOTOFFHI: | |
2106 | case R_FRV_GOTOFF12: | |
2107 | case R_FRV_GOTOFFLO: | |
43850d5b AO |
2108 | relocation -= frvfdpic_got_section (info)->output_section->vma |
2109 | + frvfdpic_got_section (info)->output_offset | |
2110 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
2111 | check_segment[0] = got_segment; |
2112 | check_segment[1] = sec | |
43850d5b | 2113 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
2114 | : (unsigned)-1; |
2115 | break; | |
2116 | ||
2117 | case R_FRV_FUNCDESC_GOTOFF12: | |
2118 | case R_FRV_FUNCDESC_GOTOFFHI: | |
2119 | case R_FRV_FUNCDESC_GOTOFFLO: | |
2120 | relocation = picrel->fd_entry; | |
2121 | check_segment[0] = check_segment[1] = got_segment; | |
2122 | break; | |
2123 | ||
2124 | case R_FRV_FUNCDESC: | |
2125 | { | |
2126 | int dynindx; | |
2127 | bfd_vma addend = rel->r_addend; | |
2128 | ||
072c8903 | 2129 | if (! (h && h->root.type == bfd_link_hash_undefweak |
43850d5b | 2130 | && FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 | 2131 | { |
072c8903 AO |
2132 | /* If the symbol is dynamic and there may be dynamic |
2133 | symbol resolution because we are or are linked with a | |
2134 | shared library, emit a FUNCDESC relocation such that | |
2135 | the dynamic linker will allocate the function | |
2136 | descriptor. If the symbol needs a non-local function | |
2137 | descriptor but binds locally (e.g., its visibility is | |
2138 | protected, emit a dynamic relocation decayed to | |
2139 | section+offset. */ | |
43850d5b AO |
2140 | if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h) |
2141 | && FRVFDPIC_SYM_LOCAL (info, h) | |
072c8903 | 2142 | && !(info->executable && !info->pie)) |
51532845 | 2143 | { |
072c8903 AO |
2144 | dynindx = elf_section_data (h->root.u.def.section |
2145 | ->output_section)->dynindx; | |
2146 | addend += h->root.u.def.section->output_offset | |
2147 | + h->root.u.def.value; | |
2148 | } | |
43850d5b | 2149 | else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)) |
072c8903 AO |
2150 | { |
2151 | if (addend) | |
2152 | { | |
2153 | info->callbacks->warning | |
2154 | (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"), | |
2155 | name, input_bfd, input_section, rel->r_offset); | |
2156 | return FALSE; | |
2157 | } | |
2158 | dynindx = h->dynindx; | |
2159 | } | |
2160 | else | |
2161 | { | |
2162 | /* Otherwise, we know we have a private function | |
2163 | descriptor, so reference it directly. */ | |
2164 | BFD_ASSERT (picrel->privfd); | |
2165 | r_type = R_FRV_32; | |
43850d5b | 2166 | dynindx = elf_section_data (frvfdpic_got_section (info) |
072c8903 | 2167 | ->output_section)->dynindx; |
43850d5b AO |
2168 | addend = frvfdpic_got_section (info)->output_offset |
2169 | + frvfdpic_got_initial_offset (info) | |
072c8903 | 2170 | + picrel->fd_entry; |
51532845 | 2171 | } |
51532845 | 2172 | |
072c8903 AO |
2173 | /* If there is room for dynamic symbol resolution, emit |
2174 | the dynamic relocation. However, if we're linking an | |
2175 | executable at a fixed location, we won't have emitted a | |
2176 | dynamic symbol entry for the got section, so idx will | |
2177 | be zero, which means we can and should compute the | |
2178 | address of the private descriptor ourselves. */ | |
2179 | if (info->executable && !info->pie | |
43850d5b | 2180 | && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h))) |
072c8903 | 2181 | { |
43850d5b | 2182 | addend += frvfdpic_got_section (info)->output_section->vma; |
072c8903 AO |
2183 | if ((bfd_get_section_flags (output_bfd, |
2184 | input_section->output_section) | |
2185 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
2186 | { | |
43850d5b AO |
2187 | if (_frvfdpic_osec_readonly_p (output_bfd, |
2188 | input_section | |
2189 | ->output_section)) | |
072c8903 AO |
2190 | { |
2191 | info->callbacks->warning | |
2192 | (info, | |
2193 | _("cannot emit fixups in read-only section"), | |
2194 | name, input_bfd, input_section, rel->r_offset); | |
2195 | return FALSE; | |
2196 | } | |
43850d5b AO |
2197 | _frvfdpic_add_rofixup (output_bfd, |
2198 | frvfdpic_gotfixup_section | |
2199 | (info), | |
2200 | _bfd_elf_section_offset | |
2201 | (output_bfd, info, | |
2202 | input_section, rel->r_offset) | |
2203 | + input_section | |
2204 | ->output_section->vma | |
2205 | + input_section->output_offset, | |
2206 | picrel); | |
072c8903 AO |
2207 | } |
2208 | } | |
2209 | else if ((bfd_get_section_flags (output_bfd, | |
2210 | input_section->output_section) | |
2211 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
51532845 | 2212 | { |
43850d5b AO |
2213 | if (_frvfdpic_osec_readonly_p (output_bfd, |
2214 | input_section | |
2215 | ->output_section)) | |
51532845 AO |
2216 | { |
2217 | info->callbacks->warning | |
2218 | (info, | |
072c8903 | 2219 | _("cannot emit dynamic relocations in read-only section"), |
51532845 AO |
2220 | name, input_bfd, input_section, rel->r_offset); |
2221 | return FALSE; | |
2222 | } | |
43850d5b AO |
2223 | _frvfdpic_add_dyn_reloc (output_bfd, |
2224 | frvfdpic_gotrel_section (info), | |
2225 | _bfd_elf_section_offset | |
2226 | (output_bfd, info, | |
2227 | input_section, rel->r_offset) | |
2228 | + input_section | |
2229 | ->output_section->vma | |
2230 | + input_section->output_offset, | |
2231 | r_type, dynindx, addend, picrel); | |
51532845 | 2232 | } |
43850d5b AO |
2233 | else |
2234 | addend += frvfdpic_got_section (info)->output_section->vma; | |
51532845 AO |
2235 | } |
2236 | ||
2237 | /* We want the addend in-place because dynamic | |
2238 | relocations are REL. Setting relocation to it should | |
2239 | arrange for it to be installed. */ | |
2240 | relocation = addend - rel->r_addend; | |
2241 | } | |
2242 | check_segment[0] = check_segment[1] = got_segment; | |
2243 | break; | |
2244 | ||
2245 | case R_FRV_32: | |
43850d5b AO |
2246 | if (! IS_FDPIC (output_bfd)) |
2247 | { | |
2248 | check_segment[0] = check_segment[1] = -1; | |
2249 | break; | |
2250 | } | |
2251 | /* Fall through. */ | |
51532845 AO |
2252 | case R_FRV_FUNCDESC_VALUE: |
2253 | { | |
2254 | int dynindx; | |
2255 | bfd_vma addend = rel->r_addend; | |
2256 | ||
2257 | /* If the symbol is dynamic but binds locally, use | |
2258 | section+offset. */ | |
43850d5b | 2259 | if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) |
51532845 AO |
2260 | { |
2261 | if (addend && r_type == R_FRV_FUNCDESC_VALUE) | |
2262 | { | |
2263 | info->callbacks->warning | |
2264 | (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"), | |
2265 | name, input_bfd, input_section, rel->r_offset); | |
2266 | return FALSE; | |
2267 | } | |
2268 | dynindx = h->dynindx; | |
2269 | } | |
2270 | else | |
2271 | { | |
2272 | if (h) | |
2273 | addend += h->root.u.def.value; | |
2274 | else | |
2275 | addend += sym->st_value; | |
2276 | if (osec) | |
2277 | addend += osec->output_offset; | |
2278 | if (osec && osec->output_section | |
2279 | && ! bfd_is_abs_section (osec->output_section) | |
2280 | && ! bfd_is_und_section (osec->output_section)) | |
2281 | dynindx = elf_section_data (osec->output_section)->dynindx; | |
2282 | else | |
2283 | dynindx = 0; | |
2284 | } | |
2285 | ||
2286 | /* If we're linking an executable at a fixed address, we | |
2287 | can omit the dynamic relocation as long as the symbol | |
2288 | is defined in the current link unit (which is implied | |
2289 | by its output section not being NULL). */ | |
2290 | if (info->executable && !info->pie | |
43850d5b | 2291 | && (!h || FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 AO |
2292 | { |
2293 | if (osec) | |
2294 | addend += osec->output_section->vma; | |
43850d5b | 2295 | if (IS_FDPIC (input_bfd) |
51532845 AO |
2296 | && (bfd_get_section_flags (output_bfd, |
2297 | input_section->output_section) | |
2298 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
2299 | { | |
43850d5b AO |
2300 | if (_frvfdpic_osec_readonly_p (output_bfd, |
2301 | input_section | |
2302 | ->output_section)) | |
51532845 AO |
2303 | { |
2304 | info->callbacks->warning | |
2305 | (info, | |
2306 | _("cannot emit fixups in read-only section"), | |
2307 | name, input_bfd, input_section, rel->r_offset); | |
2308 | return FALSE; | |
2309 | } | |
2310 | if (!h || h->root.type != bfd_link_hash_undefweak) | |
2311 | { | |
43850d5b AO |
2312 | _frvfdpic_add_rofixup (output_bfd, |
2313 | frvfdpic_gotfixup_section | |
2314 | (info), | |
2315 | _bfd_elf_section_offset | |
2316 | (output_bfd, info, | |
2317 | input_section, rel->r_offset) | |
2318 | + input_section | |
2319 | ->output_section->vma | |
2320 | + input_section->output_offset, | |
2321 | picrel); | |
51532845 | 2322 | if (r_type == R_FRV_FUNCDESC_VALUE) |
43850d5b | 2323 | _frvfdpic_add_rofixup |
51532845 | 2324 | (output_bfd, |
43850d5b | 2325 | frvfdpic_gotfixup_section (info), |
51532845 AO |
2326 | _bfd_elf_section_offset |
2327 | (output_bfd, info, | |
2328 | input_section, rel->r_offset) | |
2329 | + input_section->output_section->vma | |
3b712a1a | 2330 | + input_section->output_offset + 4, picrel); |
51532845 AO |
2331 | } |
2332 | } | |
2333 | } | |
2334 | else | |
2335 | { | |
2336 | if ((bfd_get_section_flags (output_bfd, | |
2337 | input_section->output_section) | |
2338 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
2339 | { | |
43850d5b AO |
2340 | if (_frvfdpic_osec_readonly_p (output_bfd, |
2341 | input_section | |
2342 | ->output_section)) | |
51532845 AO |
2343 | { |
2344 | info->callbacks->warning | |
2345 | (info, | |
2346 | _("cannot emit dynamic relocations in read-only section"), | |
2347 | name, input_bfd, input_section, rel->r_offset); | |
2348 | return FALSE; | |
2349 | } | |
43850d5b AO |
2350 | _frvfdpic_add_dyn_reloc (output_bfd, |
2351 | frvfdpic_gotrel_section (info), | |
2352 | _bfd_elf_section_offset | |
2353 | (output_bfd, info, | |
2354 | input_section, rel->r_offset) | |
2355 | + input_section | |
2356 | ->output_section->vma | |
2357 | + input_section->output_offset, | |
2358 | r_type, dynindx, addend, picrel); | |
51532845 | 2359 | } |
43850d5b AO |
2360 | else if (osec) |
2361 | addend += osec->output_section->vma; | |
51532845 AO |
2362 | /* We want the addend in-place because dynamic |
2363 | relocations are REL. Setting relocation to it | |
2364 | should arrange for it to be installed. */ | |
2365 | relocation = addend - rel->r_addend; | |
2366 | } | |
2367 | ||
2368 | if (r_type == R_FRV_FUNCDESC_VALUE) | |
2369 | { | |
2370 | /* If we've omitted the dynamic relocation, just emit | |
2371 | the fixed addresses of the symbol and of the local | |
2372 | GOT base offset. */ | |
2373 | if (info->executable && !info->pie | |
43850d5b | 2374 | && (!h || FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 | 2375 | bfd_put_32 (output_bfd, |
43850d5b AO |
2376 | frvfdpic_got_section (info)->output_section->vma |
2377 | + frvfdpic_got_section (info)->output_offset | |
2378 | + frvfdpic_got_initial_offset (info), | |
51532845 AO |
2379 | contents + rel->r_offset + 4); |
2380 | else | |
2381 | /* A function descriptor used for lazy or local | |
2382 | resolving is initialized such that its high word | |
2383 | contains the output section index in which the | |
2384 | PLT entries are located, and the low word | |
2385 | contains the offset of the lazy PLT entry entry | |
2386 | point into that section. */ | |
2387 | bfd_put_32 (output_bfd, | |
43850d5b | 2388 | h && ! FRVFDPIC_SYM_LOCAL (info, h) |
51532845 | 2389 | ? 0 |
43850d5b AO |
2390 | : _frvfdpic_osec_to_segment (output_bfd, |
2391 | sec | |
2392 | ->output_section), | |
51532845 AO |
2393 | contents + rel->r_offset + 4); |
2394 | } | |
2395 | } | |
2396 | check_segment[0] = check_segment[1] = got_segment; | |
2397 | break; | |
2398 | ||
2399 | case R_FRV_GPREL12: | |
2400 | case R_FRV_GPRELU12: | |
2401 | case R_FRV_GPREL32: | |
2402 | case R_FRV_GPRELHI: | |
2403 | case R_FRV_GPRELLO: | |
2404 | check_segment[0] = gprel_segment; | |
2405 | check_segment[1] = sec | |
43850d5b | 2406 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
2407 | : (unsigned)-1; |
2408 | break; | |
2409 | ||
2410 | default: | |
2411 | check_segment[0] = isec_segment; | |
2412 | check_segment[1] = sec | |
43850d5b | 2413 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
2414 | : (unsigned)-1; |
2415 | break; | |
2416 | } | |
2417 | ||
43850d5b | 2418 | if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd)) |
51532845 | 2419 | { |
43850d5b AO |
2420 | #if 1 /* If you take this out, remove the #error from fdpic-static-6.d |
2421 | in the ld testsuite. */ | |
51532845 AO |
2422 | /* This helps catch problems in GCC while we can't do more |
2423 | than static linking. The idea is to test whether the | |
2424 | input file basename is crt0.o only once. */ | |
2425 | if (silence_segment_error == 1) | |
2426 | silence_segment_error = | |
2427 | (strlen (input_bfd->filename) == 6 | |
2428 | && strcmp (input_bfd->filename, "crt0.o") == 0) | |
2429 | || (strlen (input_bfd->filename) > 6 | |
2430 | && strcmp (input_bfd->filename | |
2431 | + strlen (input_bfd->filename) - 7, | |
2432 | "/crt0.o") == 0) | |
2433 | ? -1 : 0; | |
2434 | #endif | |
2435 | if (!silence_segment_error | |
2436 | /* We don't want duplicate errors for undefined | |
2437 | symbols. */ | |
2438 | && !(picrel && picrel->symndx == -1 | |
2439 | && picrel->d.h->root.type == bfd_link_hash_undefined)) | |
2440 | info->callbacks->warning | |
2441 | (info, | |
2442 | (info->shared || info->pie) | |
2443 | ? _("relocations between different segments are not supported") | |
2444 | : _("warning: relocation references a different segment"), | |
2445 | name, input_bfd, input_section, rel->r_offset); | |
2446 | if (!silence_segment_error && (info->shared || info->pie)) | |
2447 | return FALSE; | |
2448 | elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC; | |
2449 | } | |
2450 | ||
2451 | switch (r_type) | |
2452 | { | |
2453 | case R_FRV_GOTOFFHI: | |
2454 | /* We need the addend to be applied before we shift the | |
2455 | value right. */ | |
2456 | relocation += rel->r_addend; | |
2457 | /* Fall through. */ | |
2458 | case R_FRV_GOTHI: | |
2459 | case R_FRV_FUNCDESC_GOTHI: | |
2460 | case R_FRV_FUNCDESC_GOTOFFHI: | |
2461 | relocation >>= 16; | |
2462 | /* Fall through. */ | |
2463 | ||
2464 | case R_FRV_GOTLO: | |
2465 | case R_FRV_FUNCDESC_GOTLO: | |
2466 | case R_FRV_GOTOFFLO: | |
2467 | case R_FRV_FUNCDESC_GOTOFFLO: | |
2468 | relocation &= 0xffff; | |
2469 | break; | |
2470 | ||
2471 | default: | |
2472 | break; | |
2473 | } | |
2474 | ||
2475 | switch (r_type) | |
2476 | { | |
2477 | case R_FRV_LABEL24: | |
43850d5b | 2478 | if (! IS_FDPIC (output_bfd) || ! picrel->plt) |
51532845 AO |
2479 | break; |
2480 | /* Fall through. */ | |
2481 | ||
2482 | /* When referencing a GOT entry, a function descriptor or a | |
2483 | PLT, we don't want the addend to apply to the reference, | |
2484 | but rather to the referenced symbol. The actual entry | |
2485 | will have already been created taking the addend into | |
2486 | account, so cancel it out here. */ | |
2487 | case R_FRV_GOT12: | |
2488 | case R_FRV_GOTHI: | |
2489 | case R_FRV_GOTLO: | |
2490 | case R_FRV_FUNCDESC_GOT12: | |
2491 | case R_FRV_FUNCDESC_GOTHI: | |
2492 | case R_FRV_FUNCDESC_GOTLO: | |
2493 | case R_FRV_FUNCDESC_GOTOFF12: | |
2494 | case R_FRV_FUNCDESC_GOTOFFHI: | |
2495 | case R_FRV_FUNCDESC_GOTOFFLO: | |
2496 | /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12 | |
2497 | here, since we do want to apply the addend to the others. | |
2498 | Note that we've applied the addend to GOTOFFHI before we | |
2499 | shifted it right. */ | |
2500 | case R_FRV_GOTOFFHI: | |
2501 | relocation -= rel->r_addend; | |
2502 | break; | |
2503 | ||
2504 | default: | |
2505 | break; | |
2506 | } | |
2507 | ||
2508 | if (r_type == R_FRV_HI16) | |
2509 | r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation); | |
2510 | ||
2511 | else if (r_type == R_FRV_LO16) | |
2512 | r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation); | |
2513 | ||
2514 | else if (r_type == R_FRV_LABEL24) | |
2515 | r = elf32_frv_relocate_label24 (input_bfd, input_section, rel, | |
2516 | contents, relocation); | |
2517 | ||
2518 | else if (r_type == R_FRV_GPREL12) | |
2519 | r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel, | |
2520 | contents, relocation); | |
2521 | ||
2522 | else if (r_type == R_FRV_GPRELU12) | |
2523 | r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel, | |
2524 | contents, relocation); | |
2525 | ||
2526 | else if (r_type == R_FRV_GPRELLO) | |
2527 | r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel, | |
2528 | contents, relocation); | |
2529 | ||
2530 | else if (r_type == R_FRV_GPRELHI) | |
2531 | r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel, | |
2532 | contents, relocation); | |
2533 | ||
2534 | else | |
2535 | r = frv_final_link_relocate (howto, input_bfd, input_section, contents, | |
2536 | rel, relocation); | |
2537 | ||
2538 | if (r != bfd_reloc_ok) | |
2539 | { | |
2540 | const char * msg = (const char *) NULL; | |
2541 | ||
2542 | switch (r) | |
2543 | { | |
2544 | case bfd_reloc_overflow: | |
2545 | r = info->callbacks->reloc_overflow | |
2546 | (info, name, howto->name, (bfd_vma) 0, | |
2547 | input_bfd, input_section, rel->r_offset); | |
2548 | break; | |
2549 | ||
2550 | case bfd_reloc_undefined: | |
2551 | r = info->callbacks->undefined_symbol | |
2552 | (info, name, input_bfd, input_section, rel->r_offset, TRUE); | |
2553 | break; | |
2554 | ||
2555 | case bfd_reloc_outofrange: | |
2556 | msg = _("internal error: out of range error"); | |
2557 | break; | |
2558 | ||
2559 | case bfd_reloc_notsupported: | |
2560 | msg = _("internal error: unsupported relocation error"); | |
2561 | break; | |
2562 | ||
2563 | case bfd_reloc_dangerous: | |
2564 | msg = _("internal error: dangerous relocation"); | |
2565 | break; | |
2566 | ||
2567 | default: | |
2568 | msg = _("internal error: unknown error"); | |
2569 | break; | |
2570 | } | |
2571 | ||
2572 | if (msg) | |
2573 | r = info->callbacks->warning | |
2574 | (info, msg, name, input_bfd, input_section, rel->r_offset); | |
2575 | ||
2576 | if (! r) | |
2577 | return FALSE; | |
2578 | } | |
2579 | } | |
2580 | ||
2581 | return TRUE; | |
2582 | } | |
2583 | \f | |
2584 | /* Return the section that should be marked against GC for a given | |
2585 | relocation. */ | |
2586 | ||
2587 | static asection * | |
2588 | elf32_frv_gc_mark_hook (sec, info, rel, h, sym) | |
2589 | asection *sec; | |
2590 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
2591 | Elf_Internal_Rela *rel; | |
2592 | struct elf_link_hash_entry *h; | |
2593 | Elf_Internal_Sym *sym; | |
2594 | { | |
2595 | if (h != NULL) | |
2596 | { | |
2597 | switch (ELF32_R_TYPE (rel->r_info)) | |
2598 | { | |
2599 | case R_FRV_GNU_VTINHERIT: | |
2600 | case R_FRV_GNU_VTENTRY: | |
2601 | break; | |
2602 | ||
2603 | default: | |
2604 | switch (h->root.type) | |
2605 | { | |
2606 | default: | |
2607 | break; | |
2608 | ||
2609 | case bfd_link_hash_defined: | |
2610 | case bfd_link_hash_defweak: | |
2611 | return h->root.u.def.section; | |
2612 | ||
2613 | case bfd_link_hash_common: | |
2614 | return h->root.u.c.p->section; | |
2615 | } | |
2616 | } | |
2617 | } | |
2618 | else | |
2619 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
2620 | ||
2621 | return NULL; | |
2622 | } | |
2623 | ||
2624 | /* Update the got entry reference counts for the section being removed. */ | |
2625 | ||
2626 | static bfd_boolean | |
2627 | elf32_frv_gc_sweep_hook (abfd, info, sec, relocs) | |
2628 | bfd *abfd ATTRIBUTE_UNUSED; | |
2629 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
2630 | asection *sec ATTRIBUTE_UNUSED; | |
2631 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; | |
2632 | { | |
2633 | return TRUE; | |
2634 | } | |
2635 | ||
2636 | \f | |
2637 | /* Hook called by the linker routine which adds symbols from an object | |
2638 | file. We use it to put .comm items in .scomm, and not .comm. */ | |
2639 | ||
2640 | static bfd_boolean | |
2641 | elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) | |
2642 | bfd *abfd; | |
2643 | struct bfd_link_info *info; | |
555cd476 | 2644 | Elf_Internal_Sym *sym; |
51532845 AO |
2645 | const char **namep ATTRIBUTE_UNUSED; |
2646 | flagword *flagsp ATTRIBUTE_UNUSED; | |
2647 | asection **secp; | |
2648 | bfd_vma *valp; | |
2649 | { | |
2650 | if (sym->st_shndx == SHN_COMMON | |
2651 | && !info->relocatable | |
2652 | && (int)sym->st_size <= (int)bfd_get_gp_size (abfd)) | |
2653 | { | |
2654 | /* Common symbols less than or equal to -G nn bytes are | |
2655 | automatically put into .sbss. */ | |
2656 | ||
2657 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); | |
2658 | ||
2659 | if (scomm == NULL) | |
2660 | { | |
2661 | scomm = bfd_make_section (abfd, ".scommon"); | |
2662 | if (scomm == NULL | |
2663 | || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC | |
2664 | | SEC_IS_COMMON | |
2665 | | SEC_LINKER_CREATED))) | |
2666 | return FALSE; | |
2667 | } | |
2668 | ||
2669 | *secp = scomm; | |
2670 | *valp = sym->st_size; | |
2671 | } | |
2672 | ||
2673 | return TRUE; | |
2674 | } | |
43850d5b AO |
2675 | |
2676 | /* Create a .got section, as well as its additional info field. This | |
51532845 AO |
2677 | is almost entirely copied from |
2678 | elflink.c:_bfd_elf_create_got_section(). */ | |
2679 | ||
2680 | static bfd_boolean | |
2681 | _frv_create_got_section (bfd *abfd, struct bfd_link_info *info) | |
2682 | { | |
2683 | flagword flags; | |
2684 | asection *s; | |
2685 | struct elf_link_hash_entry *h; | |
2686 | struct bfd_link_hash_entry *bh; | |
2687 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
2688 | int ptralign; | |
43850d5b | 2689 | int offset; |
51532845 AO |
2690 | |
2691 | /* This function may be called more than once. */ | |
2692 | s = bfd_get_section_by_name (abfd, ".got"); | |
2693 | if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0) | |
2694 | return TRUE; | |
2695 | ||
2696 | /* Machine specific: although pointers are 32-bits wide, we want the | |
2697 | GOT to be aligned to a 64-bit boundary, such that function | |
2698 | descriptors in it can be accessed with 64-bit loads and | |
2699 | stores. */ | |
2700 | ptralign = 3; | |
2701 | ||
2702 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
2703 | | SEC_LINKER_CREATED); | |
2704 | ||
2705 | s = bfd_make_section (abfd, ".got"); | |
2706 | if (s == NULL | |
2707 | || !bfd_set_section_flags (abfd, s, flags) | |
2708 | || !bfd_set_section_alignment (abfd, s, ptralign)) | |
2709 | return FALSE; | |
2710 | ||
2711 | if (bed->want_got_plt) | |
2712 | { | |
2713 | s = bfd_make_section (abfd, ".got.plt"); | |
2714 | if (s == NULL | |
2715 | || !bfd_set_section_flags (abfd, s, flags) | |
2716 | || !bfd_set_section_alignment (abfd, s, ptralign)) | |
2717 | return FALSE; | |
2718 | } | |
2719 | ||
2720 | if (bed->want_got_sym) | |
2721 | { | |
2722 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | |
2723 | (or .got.plt) section. We don't do this in the linker script | |
2724 | because we don't want to define the symbol if we are not creating | |
2725 | a global offset table. */ | |
2726 | bh = NULL; | |
2727 | if (!(_bfd_generic_link_add_one_symbol | |
2728 | (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, | |
2729 | bed->got_symbol_offset, (const char *) NULL, FALSE, | |
2730 | bed->collect, &bh))) | |
2731 | return FALSE; | |
2732 | h = (struct elf_link_hash_entry *) bh; | |
2733 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
2734 | h->type = STT_OBJECT; | |
2735 | ||
2736 | /* Machine-specific: we want the symbol for executables as | |
2737 | well. */ | |
c152c796 | 2738 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
51532845 AO |
2739 | return FALSE; |
2740 | ||
2741 | elf_hash_table (info)->hgot = h; | |
2742 | } | |
2743 | ||
2744 | /* The first bit of the global offset table is the header. */ | |
2745 | s->_raw_size += bed->got_header_size + bed->got_symbol_offset; | |
2746 | ||
2747 | /* This is the machine-specific part. Create and initialize section | |
2748 | data for the got. */ | |
43850d5b AO |
2749 | if (IS_FDPIC (abfd)) |
2750 | { | |
2751 | frvfdpic_got_section (info) = s; | |
2752 | frvfdpic_relocs_info (info) = htab_try_create (1, frvfdpic_relocs_info_hash, | |
2753 | frvfdpic_relocs_info_eq, | |
2754 | (htab_del) NULL); | |
2755 | if (! frvfdpic_relocs_info (info)) | |
2756 | return FALSE; | |
51532845 | 2757 | |
43850d5b AO |
2758 | s = bfd_make_section (abfd, ".rel.got"); |
2759 | if (s == NULL | |
2760 | || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY)) | |
2761 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
2762 | return FALSE; | |
51532845 | 2763 | |
43850d5b | 2764 | frvfdpic_gotrel_section (info) = s; |
51532845 | 2765 | |
43850d5b AO |
2766 | /* Machine-specific. */ |
2767 | s = bfd_make_section (abfd, ".rofixup"); | |
2768 | if (s == NULL | |
2769 | || ! bfd_set_section_flags (abfd, s, (flags | SEC_READONLY)) | |
2770 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
2771 | return FALSE; | |
51532845 | 2772 | |
43850d5b AO |
2773 | frvfdpic_gotfixup_section (info) = s; |
2774 | offset = -2048; | |
2775 | flags = BSF_GLOBAL; | |
2776 | } | |
2777 | else | |
2778 | { | |
2779 | offset = 2048; | |
2780 | flags = BSF_GLOBAL | BSF_WEAK; | |
2781 | } | |
51532845 | 2782 | |
43850d5b AO |
2783 | /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it |
2784 | turns out that we're linking with a different linker script, the | |
2785 | linker script will override it. */ | |
51532845 AO |
2786 | bh = NULL; |
2787 | if (!(_bfd_generic_link_add_one_symbol | |
43850d5b | 2788 | (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE, |
51532845 AO |
2789 | bed->collect, &bh))) |
2790 | return FALSE; | |
2791 | h = (struct elf_link_hash_entry *) bh; | |
2792 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
2793 | h->type = STT_OBJECT; | |
2794 | ||
2795 | /* Machine-specific: we want the symbol for executables as well. */ | |
43850d5b | 2796 | if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h)) |
51532845 | 2797 | return FALSE; |
43850d5b | 2798 | |
51532845 AO |
2799 | return TRUE; |
2800 | } | |
2801 | ||
2802 | /* Make sure the got and plt sections exist, and that our pointers in | |
2803 | the link hash table point to them. */ | |
2804 | ||
2805 | static bfd_boolean | |
43850d5b | 2806 | elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) |
51532845 AO |
2807 | { |
2808 | /* This is mostly copied from | |
2809 | elflink.c:_bfd_elf_create_dynamic_sections(). */ | |
2810 | flagword flags, pltflags; | |
2811 | asection *s; | |
2812 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
2813 | ||
2814 | /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and | |
2815 | .rel[a].bss sections. */ | |
2816 | ||
2817 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
2818 | | SEC_LINKER_CREATED); | |
2819 | ||
2820 | pltflags = flags; | |
2821 | pltflags |= SEC_CODE; | |
2822 | if (bed->plt_not_loaded) | |
2823 | pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); | |
2824 | if (bed->plt_readonly) | |
2825 | pltflags |= SEC_READONLY; | |
2826 | ||
2827 | s = bfd_make_section (abfd, ".plt"); | |
2828 | if (s == NULL | |
2829 | || ! bfd_set_section_flags (abfd, s, pltflags) | |
2830 | || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) | |
2831 | return FALSE; | |
2832 | /* FRV-specific: remember it. */ | |
43850d5b | 2833 | frvfdpic_plt_section (info) = s; |
51532845 AO |
2834 | |
2835 | if (bed->want_plt_sym) | |
2836 | { | |
2837 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the | |
2838 | .plt section. */ | |
2839 | struct elf_link_hash_entry *h; | |
2840 | struct bfd_link_hash_entry *bh = NULL; | |
2841 | ||
2842 | if (! (_bfd_generic_link_add_one_symbol | |
2843 | (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL, | |
2844 | FALSE, get_elf_backend_data (abfd)->collect, &bh))) | |
2845 | return FALSE; | |
2846 | h = (struct elf_link_hash_entry *) bh; | |
2847 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
2848 | h->type = STT_OBJECT; | |
2849 | ||
2850 | if (! info->executable | |
c152c796 | 2851 | && ! bfd_elf_link_record_dynamic_symbol (info, h)) |
51532845 AO |
2852 | return FALSE; |
2853 | } | |
2854 | ||
2855 | /* FRV-specific: we want rel relocations for the plt. */ | |
2856 | s = bfd_make_section (abfd, ".rel.plt"); | |
2857 | if (s == NULL | |
2858 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) | |
2859 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) | |
2860 | return FALSE; | |
2861 | /* FRV-specific: remember it. */ | |
43850d5b | 2862 | frvfdpic_pltrel_section (info) = s; |
51532845 AO |
2863 | |
2864 | /* FRV-specific: we want to create the GOT in the FRV way. */ | |
2865 | if (! _frv_create_got_section (abfd, info)) | |
2866 | return FALSE; | |
2867 | ||
2868 | /* FRV-specific: make sure we created everything we wanted. */ | |
43850d5b AO |
2869 | BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info) |
2870 | && frvfdpic_gotfixup_section (info) | |
2871 | && frvfdpic_plt_section (info) | |
2872 | && frvfdpic_pltrel_section (info)); | |
51532845 AO |
2873 | |
2874 | if (bed->want_dynbss) | |
2875 | { | |
2876 | /* The .dynbss section is a place to put symbols which are defined | |
2877 | by dynamic objects, are referenced by regular objects, and are | |
2878 | not functions. We must allocate space for them in the process | |
2879 | image and use a R_*_COPY reloc to tell the dynamic linker to | |
2880 | initialize them at run time. The linker script puts the .dynbss | |
2881 | section into the .bss section of the final image. */ | |
2882 | s = bfd_make_section (abfd, ".dynbss"); | |
2883 | if (s == NULL | |
2884 | || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED)) | |
2885 | return FALSE; | |
2886 | ||
2887 | /* The .rel[a].bss section holds copy relocs. This section is not | |
2888 | normally needed. We need to create it here, though, so that the | |
2889 | linker will map it to an output section. We can't just create it | |
2890 | only if we need it, because we will not know whether we need it | |
2891 | until we have seen all the input files, and the first time the | |
2892 | main linker code calls BFD after examining all the input files | |
2893 | (size_dynamic_sections) the input sections have already been | |
2894 | mapped to the output sections. If the section turns out not to | |
2895 | be needed, we can discard it later. We will never need this | |
2896 | section when generating a shared object, since they do not use | |
2897 | copy relocs. */ | |
2898 | if (! info->shared) | |
2899 | { | |
2900 | s = bfd_make_section (abfd, | |
2901 | (bed->default_use_rela_p | |
2902 | ? ".rela.bss" : ".rel.bss")); | |
2903 | if (s == NULL | |
2904 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) | |
2905 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) | |
2906 | return FALSE; | |
2907 | } | |
2908 | } | |
2909 | ||
2910 | return TRUE; | |
2911 | } | |
2912 | ||
2913 | /* The name of the dynamic interpreter. This is put in the .interp | |
2914 | section. */ | |
2915 | ||
2916 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" | |
2917 | ||
2918 | #define DEFAULT_STACK_SIZE 0x20000 | |
2919 | ||
2920 | /* This structure is used to collect the number of entries present in | |
2921 | each addressable range of the got. */ | |
43850d5b | 2922 | struct _frvfdpic_dynamic_got_info |
51532845 AO |
2923 | { |
2924 | /* Several bits of information about the current link. */ | |
2925 | struct bfd_link_info *info; | |
2926 | /* Total size needed for GOT entries within the 12-, 16- or 32-bit | |
2927 | ranges. */ | |
2928 | bfd_vma got12, gotlos, gothilo; | |
2929 | /* Total size needed for function descriptor entries within the 12-, | |
2930 | 16- or 32-bit ranges. */ | |
2931 | bfd_vma fd12, fdlos, fdhilo; | |
2932 | /* Total size needed function descriptor entries referenced in PLT | |
2933 | entries, that would be profitable to place in offsets close to | |
2934 | the PIC register. */ | |
2935 | bfd_vma fdplt; | |
2936 | /* Total size needed by lazy PLT entries. */ | |
2937 | bfd_vma lzplt; | |
2938 | /* Number of relocations carried over from input object files. */ | |
2939 | unsigned long relocs; | |
2940 | /* Number of fixups introduced by relocations in input object files. */ | |
2941 | unsigned long fixups; | |
2942 | }; | |
2943 | ||
2944 | /* Compute the total GOT size required by each symbol in each range. | |
2945 | Symbols may require up to 4 words in the GOT: an entry pointing to | |
2946 | the symbol, an entry pointing to its function descriptor, and a | |
2947 | private function descriptors taking two words. */ | |
2948 | ||
2949 | static int | |
43850d5b | 2950 | _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_) |
51532845 | 2951 | { |
43850d5b AO |
2952 | struct frvfdpic_relocs_info *entry = *entryp; |
2953 | struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; | |
3b712a1a | 2954 | unsigned relocs = 0, fixups = 0; |
51532845 AO |
2955 | |
2956 | /* Allocate space for a GOT entry pointing to the symbol. */ | |
2957 | if (entry->got12) | |
2958 | dinfo->got12 += 4; | |
2959 | else if (entry->gotlos) | |
2960 | dinfo->gotlos += 4; | |
2961 | else if (entry->gothilo) | |
2962 | dinfo->gothilo += 4; | |
2963 | else | |
2964 | entry->relocs32--; | |
2965 | entry->relocs32++; | |
2966 | ||
2967 | /* Allocate space for a GOT entry pointing to the function | |
2968 | descriptor. */ | |
2969 | if (entry->fdgot12) | |
2970 | dinfo->got12 += 4; | |
2971 | else if (entry->fdgotlos) | |
2972 | dinfo->gotlos += 4; | |
2973 | else if (entry->fdgothilo) | |
2974 | dinfo->gothilo += 4; | |
2975 | else | |
2976 | entry->relocsfd--; | |
2977 | entry->relocsfd++; | |
2978 | ||
2979 | /* Decide whether we need a PLT entry, a function descriptor in the | |
2980 | GOT, and a lazy PLT entry for this symbol. */ | |
2981 | entry->plt = entry->call | |
43850d5b | 2982 | && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) |
51532845 AO |
2983 | && elf_hash_table (dinfo->info)->dynamic_sections_created; |
2984 | entry->privfd = entry->plt | |
2985 | || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo | |
2986 | || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo) | |
2987 | && (entry->symndx != -1 | |
43850d5b | 2988 | || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))); |
51532845 | 2989 | entry->lazyplt = entry->privfd |
43850d5b | 2990 | && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) |
51532845 AO |
2991 | && ! (dinfo->info->flags & DF_BIND_NOW) |
2992 | && elf_hash_table (dinfo->info)->dynamic_sections_created; | |
2993 | ||
2994 | /* Allocate space for a function descriptor. */ | |
2995 | if (entry->fdgoff12) | |
2996 | dinfo->fd12 += 8; | |
2997 | else if (entry->fdgofflos) | |
2998 | dinfo->fdlos += 8; | |
2999 | else if (entry->privfd && entry->plt) | |
3000 | dinfo->fdplt += 8; | |
3001 | else if (entry->privfd) | |
3002 | dinfo->fdhilo += 8; | |
3003 | else | |
3004 | entry->relocsfdv--; | |
3005 | entry->relocsfdv++; | |
3006 | ||
3007 | if (entry->lazyplt) | |
3008 | dinfo->lzplt += 8; | |
3009 | ||
3010 | if (!dinfo->info->executable || dinfo->info->pie) | |
3b712a1a | 3011 | relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv; |
51532845 AO |
3012 | else |
3013 | { | |
43850d5b | 3014 | if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)) |
51532845 AO |
3015 | { |
3016 | if (entry->symndx != -1 | |
3b712a1a AO |
3017 | || entry->d.h->root.type != bfd_link_hash_undefweak) |
3018 | fixups += entry->relocs32 + 2 * entry->relocsfdv; | |
51532845 AO |
3019 | } |
3020 | else | |
3b712a1a AO |
3021 | relocs += entry->relocs32 + entry->relocsfdv; |
3022 | ||
43850d5b AO |
3023 | if (entry->symndx != -1 |
3024 | || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)) | |
51532845 AO |
3025 | { |
3026 | if (entry->symndx != -1 | |
3027 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
3b712a1a | 3028 | fixups += entry->relocsfd; |
51532845 AO |
3029 | } |
3030 | else | |
3b712a1a | 3031 | relocs += entry->relocsfd; |
51532845 AO |
3032 | } |
3033 | ||
3b712a1a AO |
3034 | entry->dynrelocs += relocs; |
3035 | entry->fixups += fixups; | |
3036 | dinfo->relocs += relocs; | |
3037 | dinfo->fixups += fixups; | |
3038 | ||
51532845 AO |
3039 | return 1; |
3040 | } | |
3041 | ||
3042 | /* This structure is used to assign offsets to got entries, function | |
3043 | descriptors, plt entries and lazy plt entries. */ | |
3044 | ||
43850d5b | 3045 | struct _frvfdpic_dynamic_got_plt_info |
51532845 | 3046 | { |
43850d5b AO |
3047 | /* Summary information collected with _frvfdpic_count_got_plt_entries. */ |
3048 | struct _frvfdpic_dynamic_got_info g; | |
51532845 AO |
3049 | |
3050 | /* For each addressable range, we record a MAX (positive) and MIN | |
3051 | (negative) value. CUR is used to assign got entries, and it's | |
3052 | incremented from an initial positive value to MAX, then from MIN | |
3053 | to FDCUR (unless FDCUR wraps around first). FDCUR is used to | |
3054 | assign function descriptors, and it's decreased from an initial | |
3055 | non-positive value to MIN, then from MAX down to CUR (unless CUR | |
3056 | wraps around first). All of MIN, MAX, CUR and FDCUR always point | |
3057 | to even words. ODD, if non-zero, indicates an odd word to be | |
3058 | used for the next got entry, otherwise CUR is used and | |
3059 | incremented by a pair of words, wrapping around when it reaches | |
3060 | MAX. FDCUR is decremented (and wrapped) before the next function | |
3061 | descriptor is chosen. FDPLT indicates the number of remaining | |
3062 | slots that can be used for function descriptors used only by PLT | |
3063 | entries. */ | |
43850d5b | 3064 | struct _frvfdpic_dynamic_got_alloc_data |
51532845 AO |
3065 | { |
3066 | bfd_signed_vma max, cur, odd, fdcur, min; | |
3067 | bfd_vma fdplt; | |
3068 | } got12, gotlos, gothilo; | |
3069 | }; | |
3070 | ||
3071 | /* Determine the positive and negative ranges to be used by each | |
3072 | offset range in the GOT. FDCUR and CUR, that must be aligned to a | |
3073 | double-word boundary, are the minimum (negative) and maximum | |
3074 | (positive) GOT offsets already used by previous ranges, except for | |
3075 | an ODD entry that may have been left behind. GOT and FD indicate | |
3076 | the size of GOT entries and function descriptors that must be | |
3077 | placed within the range from -WRAP to WRAP. If there's room left, | |
3078 | up to FDPLT bytes should be reserved for additional function | |
3079 | descriptors. */ | |
3080 | ||
3081 | inline static bfd_signed_vma | |
43850d5b AO |
3082 | _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad, |
3083 | bfd_signed_vma fdcur, | |
3084 | bfd_signed_vma odd, | |
3085 | bfd_signed_vma cur, | |
3086 | bfd_vma got, | |
3087 | bfd_vma fd, | |
3088 | bfd_vma fdplt, | |
3089 | bfd_vma wrap) | |
51532845 AO |
3090 | { |
3091 | bfd_signed_vma wrapmin = -wrap; | |
3092 | ||
3093 | /* Start at the given initial points. */ | |
3094 | gad->fdcur = fdcur; | |
3095 | gad->cur = cur; | |
3096 | ||
3097 | /* If we had an incoming odd word and we have any got entries that | |
3098 | are going to use it, consume it, otherwise leave gad->odd at | |
3099 | zero. We might force gad->odd to zero and return the incoming | |
3100 | odd such that it is used by the next range, but then GOT entries | |
3101 | might appear to be out of order and we wouldn't be able to | |
3102 | shorten the GOT by one word if it turns out to end with an | |
3103 | unpaired GOT entry. */ | |
3104 | if (odd && got) | |
3105 | { | |
3106 | gad->odd = odd; | |
3107 | got -= 4; | |
3108 | odd = 0; | |
3109 | } | |
3110 | else | |
3111 | gad->odd = 0; | |
3112 | ||
3113 | /* If we're left with an unpaired GOT entry, compute its location | |
3114 | such that we can return it. Otherwise, if got doesn't require an | |
3115 | odd number of words here, either odd was already zero in the | |
3116 | block above, or it was set to zero because got was non-zero, or | |
3117 | got was already zero. In the latter case, we want the value of | |
3118 | odd to carry over to the return statement, so we don't want to | |
3119 | reset odd unless the condition below is true. */ | |
3120 | if (got & 4) | |
3121 | { | |
3122 | odd = cur + got; | |
3123 | got += 4; | |
3124 | } | |
3125 | ||
3126 | /* Compute the tentative boundaries of this range. */ | |
3127 | gad->max = cur + got; | |
3128 | gad->min = fdcur - fd; | |
3129 | gad->fdplt = 0; | |
3130 | ||
3131 | /* If function descriptors took too much space, wrap some of them | |
3132 | around. */ | |
3133 | if (gad->min < wrapmin) | |
3134 | { | |
3135 | gad->max += wrapmin - gad->min; | |
3136 | gad->min = wrapmin; | |
3137 | } | |
3138 | /* If there is space left and we have function descriptors | |
3139 | referenced in PLT entries that could take advantage of shorter | |
3140 | offsets, place them here. */ | |
3141 | else if (fdplt && gad->min > wrapmin) | |
3142 | { | |
3143 | bfd_vma fds; | |
3144 | if ((bfd_vma) (gad->min - wrapmin) < fdplt) | |
3145 | fds = gad->min - wrapmin; | |
3146 | else | |
3147 | fds = fdplt; | |
3148 | ||
3149 | fdplt -= fds; | |
3150 | gad->min -= fds; | |
3151 | gad->fdplt += fds; | |
3152 | } | |
3153 | ||
3154 | /* If GOT entries took too much space, wrap some of them around. | |
3155 | This may well cause gad->min to become lower than wrapmin. This | |
3156 | will cause a relocation overflow later on, so we don't have to | |
3157 | report it here . */ | |
3158 | if ((bfd_vma) gad->max > wrap) | |
3159 | { | |
3160 | gad->min -= gad->max - wrap; | |
3161 | gad->max = wrap; | |
3162 | } | |
3163 | /* If there is more space left, try to place some more function | |
3164 | descriptors for PLT entries. */ | |
3165 | else if (fdplt && (bfd_vma) gad->max < wrap) | |
3166 | { | |
3167 | bfd_vma fds; | |
3168 | if ((bfd_vma) (wrap - gad->max) < fdplt) | |
3169 | fds = wrap - gad->max; | |
3170 | else | |
3171 | fds = fdplt; | |
3172 | ||
3173 | fdplt -= fds; | |
3174 | gad->max += fds; | |
3175 | gad->fdplt += fds; | |
3176 | } | |
3177 | ||
3178 | /* If odd was initially computed as an offset past the wrap point, | |
3179 | wrap it around. */ | |
3180 | if (odd > gad->max) | |
3181 | odd = gad->min + odd - gad->max; | |
3182 | ||
43850d5b | 3183 | /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed |
51532845 AO |
3184 | before returning, so do it here too. This guarantees that, |
3185 | should cur and fdcur meet at the wrap point, they'll both be | |
3186 | equal to min. */ | |
3187 | if (gad->cur == gad->max) | |
3188 | gad->cur = gad->min; | |
3189 | ||
3190 | return odd; | |
3191 | } | |
3192 | ||
3193 | /* Compute the location of the next GOT entry, given the allocation | |
3194 | data for a range. */ | |
3195 | ||
3196 | inline static bfd_signed_vma | |
43850d5b | 3197 | _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) |
51532845 AO |
3198 | { |
3199 | bfd_signed_vma ret; | |
3200 | ||
3201 | if (gad->odd) | |
3202 | { | |
3203 | /* If there was an odd word left behind, use it. */ | |
3204 | ret = gad->odd; | |
3205 | gad->odd = 0; | |
3206 | } | |
3207 | else | |
3208 | { | |
3209 | /* Otherwise, use the word pointed to by cur, reserve the next | |
3210 | as an odd word, and skip to the next pair of words, possibly | |
3211 | wrapping around. */ | |
3212 | ret = gad->cur; | |
3213 | gad->odd = gad->cur + 4; | |
3214 | gad->cur += 8; | |
3215 | if (gad->cur == gad->max) | |
3216 | gad->cur = gad->min; | |
3217 | } | |
3218 | ||
3219 | return ret; | |
3220 | } | |
3221 | ||
3222 | /* Compute the location of the next function descriptor entry in the | |
3223 | GOT, given the allocation data for a range. */ | |
3224 | ||
3225 | inline static bfd_signed_vma | |
43850d5b | 3226 | _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) |
51532845 AO |
3227 | { |
3228 | /* If we're at the bottom, wrap around, and only then allocate the | |
3229 | next pair of words. */ | |
3230 | if (gad->fdcur == gad->min) | |
3231 | gad->fdcur = gad->max; | |
3232 | return gad->fdcur -= 8; | |
3233 | } | |
3234 | ||
3235 | /* Assign GOT offsets for every GOT entry and function descriptor. | |
3236 | Doing everything in a single pass is tricky. */ | |
3237 | ||
3238 | static int | |
43850d5b | 3239 | _frvfdpic_assign_got_entries (void **entryp, void *info_) |
51532845 | 3240 | { |
43850d5b AO |
3241 | struct frvfdpic_relocs_info *entry = *entryp; |
3242 | struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; | |
51532845 AO |
3243 | |
3244 | if (entry->got12) | |
43850d5b | 3245 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12); |
51532845 | 3246 | else if (entry->gotlos) |
43850d5b | 3247 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); |
51532845 | 3248 | else if (entry->gothilo) |
43850d5b | 3249 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); |
51532845 AO |
3250 | |
3251 | if (entry->fdgot12) | |
43850d5b | 3252 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12); |
51532845 | 3253 | else if (entry->fdgotlos) |
43850d5b | 3254 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); |
51532845 | 3255 | else if (entry->fdgothilo) |
43850d5b | 3256 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); |
51532845 AO |
3257 | |
3258 | if (entry->fdgoff12) | |
43850d5b | 3259 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); |
51532845 AO |
3260 | else if (entry->plt && dinfo->got12.fdplt) |
3261 | { | |
3262 | dinfo->got12.fdplt -= 8; | |
43850d5b | 3263 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); |
51532845 AO |
3264 | } |
3265 | else if (entry->fdgofflos) | |
43850d5b | 3266 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); |
51532845 AO |
3267 | else if (entry->plt && dinfo->gotlos.fdplt) |
3268 | { | |
3269 | dinfo->gotlos.fdplt -= 8; | |
43850d5b | 3270 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); |
51532845 AO |
3271 | } |
3272 | else if (entry->plt) | |
3273 | { | |
3274 | dinfo->gothilo.fdplt -= 8; | |
43850d5b | 3275 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); |
51532845 AO |
3276 | } |
3277 | else if (entry->privfd) | |
43850d5b | 3278 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); |
51532845 AO |
3279 | |
3280 | return 1; | |
3281 | } | |
3282 | ||
3283 | /* Assign GOT offsets to private function descriptors used by PLT | |
3284 | entries (or referenced by 32-bit offsets), as well as PLT entries | |
3285 | and lazy PLT entries. */ | |
3286 | ||
3287 | static int | |
43850d5b | 3288 | _frvfdpic_assign_plt_entries (void **entryp, void *info_) |
51532845 | 3289 | { |
43850d5b AO |
3290 | struct frvfdpic_relocs_info *entry = *entryp; |
3291 | struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; | |
51532845 AO |
3292 | |
3293 | /* If this symbol requires a local function descriptor, allocate | |
3294 | one. */ | |
3295 | if (entry->privfd && entry->fd_entry == 0) | |
3296 | { | |
3297 | if (dinfo->got12.fdplt) | |
3298 | { | |
43850d5b | 3299 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); |
51532845 AO |
3300 | dinfo->got12.fdplt -= 8; |
3301 | } | |
3302 | else if (dinfo->gotlos.fdplt) | |
3303 | { | |
43850d5b | 3304 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); |
51532845 AO |
3305 | dinfo->gotlos.fdplt -= 8; |
3306 | } | |
3307 | else | |
3308 | { | |
3309 | BFD_ASSERT (dinfo->gothilo.fdplt) | |
43850d5b | 3310 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); |
51532845 AO |
3311 | dinfo->gothilo.fdplt -= 8; |
3312 | } | |
3313 | } | |
3314 | ||
3315 | if (entry->plt) | |
3316 | { | |
3317 | int size; | |
3318 | ||
3319 | /* We use the section's raw size to mark the location of the | |
3320 | next PLT entry. */ | |
43850d5b | 3321 | entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->_raw_size; |
51532845 AO |
3322 | |
3323 | /* Figure out the length of this PLT entry based on the | |
3324 | addressing mode we need to reach the function descriptor. */ | |
3325 | BFD_ASSERT (entry->fd_entry); | |
3326 | if (entry->fd_entry >= -(1 << (12 - 1)) | |
3327 | && entry->fd_entry < (1 << (12 - 1))) | |
3328 | size = 8; | |
3329 | else if (entry->fd_entry >= -(1 << (16 - 1)) | |
3330 | && entry->fd_entry < (1 << (16 - 1))) | |
3331 | size = 12; | |
3332 | else | |
3333 | size = 16; | |
3334 | ||
43850d5b | 3335 | frvfdpic_plt_section (dinfo->g.info)->_raw_size += size; |
51532845 AO |
3336 | } |
3337 | ||
3338 | if (entry->lazyplt) | |
3339 | { | |
3340 | entry->lzplt_entry = dinfo->g.lzplt; | |
3341 | dinfo->g.lzplt += 8; | |
3342 | /* If this entry is the one that gets the resolver stub, account | |
3343 | for the additional instruction. */ | |
43850d5b AO |
3344 | if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE |
3345 | == FRVFDPIC_LZPLT_RESOLV_LOC) | |
51532845 AO |
3346 | dinfo->g.lzplt += 4; |
3347 | } | |
3348 | ||
3349 | return 1; | |
3350 | } | |
3351 | ||
3352 | /* Follow indirect and warning hash entries so that each got entry | |
3353 | points to the final symbol definition. P must point to a pointer | |
3354 | to the hash table we're traversing. Since this traversal may | |
3355 | modify the hash table, we set this pointer to NULL to indicate | |
3356 | we've made a potentially-destructive change to the hash table, so | |
3357 | the traversal must be restarted. */ | |
3358 | static int | |
43850d5b | 3359 | _frvfdpic_resolve_final_relocs_info (void **entryp, void *p) |
51532845 | 3360 | { |
43850d5b | 3361 | struct frvfdpic_relocs_info *entry = *entryp; |
51532845 AO |
3362 | htab_t *htab = p; |
3363 | ||
3364 | if (entry->symndx == -1) | |
3365 | { | |
3366 | struct elf_link_hash_entry *h = entry->d.h; | |
43850d5b | 3367 | struct frvfdpic_relocs_info *oentry; |
51532845 AO |
3368 | |
3369 | while (h->root.type == bfd_link_hash_indirect | |
3370 | || h->root.type == bfd_link_hash_warning) | |
3371 | h = (struct elf_link_hash_entry *)h->root.u.i.link; | |
3372 | ||
3373 | if (entry->d.h == h) | |
3374 | return 1; | |
3375 | ||
43850d5b AO |
3376 | oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend, |
3377 | NO_INSERT); | |
3b712a1a AO |
3378 | |
3379 | if (oentry) | |
3380 | { | |
3381 | /* Merge the two entries. */ | |
43850d5b | 3382 | frvfdpic_pic_merge_early_relocs_info (oentry, entry); |
3b712a1a AO |
3383 | htab_clear_slot (*htab, entryp); |
3384 | return 1; | |
3385 | } | |
3386 | ||
51532845 AO |
3387 | entry->d.h = h; |
3388 | ||
3389 | /* If we can't find this entry with the new bfd hash, re-insert | |
3390 | it, and get the traversal restarted. */ | |
3391 | if (! htab_find (*htab, entry)) | |
3392 | { | |
3393 | htab_clear_slot (*htab, entryp); | |
3394 | entryp = htab_find_slot (*htab, entry, INSERT); | |
3395 | if (! *entryp) | |
3396 | *entryp = entry; | |
3397 | /* Abort the traversal, since the whole table may have | |
3398 | moved, and leave it up to the parent to restart the | |
3399 | process. */ | |
3400 | *(htab_t *)p = NULL; | |
3401 | return 0; | |
3402 | } | |
3403 | } | |
3404 | ||
3405 | return 1; | |
3406 | } | |
3407 | ||
3408 | /* Set the sizes of the dynamic sections. */ | |
3409 | ||
3410 | static bfd_boolean | |
43850d5b AO |
3411 | elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd, |
3412 | struct bfd_link_info *info) | |
51532845 AO |
3413 | { |
3414 | bfd *dynobj; | |
3415 | asection *s; | |
43850d5b | 3416 | struct _frvfdpic_dynamic_got_plt_info gpinfo; |
51532845 AO |
3417 | bfd_signed_vma odd; |
3418 | bfd_vma limit; | |
3419 | ||
3420 | dynobj = elf_hash_table (info)->dynobj; | |
3421 | BFD_ASSERT (dynobj != NULL); | |
3422 | ||
3423 | if (elf_hash_table (info)->dynamic_sections_created) | |
3424 | { | |
3425 | /* Set the contents of the .interp section to the interpreter. */ | |
3426 | if (info->executable) | |
3427 | { | |
3428 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
3429 | BFD_ASSERT (s != NULL); | |
3430 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
3431 | s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER; | |
3432 | } | |
3433 | } | |
3434 | ||
3435 | memset (&gpinfo, 0, sizeof (gpinfo)); | |
3436 | gpinfo.g.info = info; | |
3437 | ||
3438 | for (;;) | |
3439 | { | |
43850d5b | 3440 | htab_t relocs = frvfdpic_relocs_info (info); |
51532845 | 3441 | |
43850d5b | 3442 | htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs); |
51532845 | 3443 | |
43850d5b | 3444 | if (relocs == frvfdpic_relocs_info (info)) |
51532845 AO |
3445 | break; |
3446 | } | |
3447 | ||
43850d5b | 3448 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries, |
51532845 AO |
3449 | &gpinfo.g); |
3450 | ||
3451 | odd = 12; | |
3452 | /* Compute the total size taken by entries in the 12-bit and 16-bit | |
3453 | ranges, to tell how many PLT function descriptors we can bring | |
3454 | into the 12-bit range without causing the 16-bit range to | |
3455 | overflow. */ | |
3456 | limit = odd + gpinfo.g.got12 + gpinfo.g.gotlos | |
3457 | + gpinfo.g.fd12 + gpinfo.g.fdlos; | |
3458 | if (limit < (bfd_vma)1 << 16) | |
3459 | limit = ((bfd_vma)1 << 16) - limit; | |
3460 | else | |
3461 | limit = 0; | |
3462 | if (gpinfo.g.fdplt < limit) | |
3463 | limit = gpinfo.g.fdplt; | |
3464 | ||
3465 | /* Determine the ranges of GOT offsets that we can use for each | |
3466 | range of addressing modes. */ | |
43850d5b AO |
3467 | odd = _frvfdpic_compute_got_alloc_data (&gpinfo.got12, |
3468 | 0, | |
3469 | odd, | |
3470 | 16, | |
3471 | gpinfo.g.got12, | |
3472 | gpinfo.g.fd12, | |
3473 | limit, | |
3474 | (bfd_vma)1 << (12-1)); | |
3475 | odd = _frvfdpic_compute_got_alloc_data (&gpinfo.gotlos, | |
3476 | gpinfo.got12.min, | |
3477 | odd, | |
3478 | gpinfo.got12.max, | |
3479 | gpinfo.g.gotlos, | |
3480 | gpinfo.g.fdlos, | |
3481 | gpinfo.g.fdplt - gpinfo.got12.fdplt, | |
3482 | (bfd_vma)1 << (16-1)); | |
3483 | odd = _frvfdpic_compute_got_alloc_data (&gpinfo.gothilo, | |
3484 | gpinfo.gotlos.min, | |
3485 | odd, | |
3486 | gpinfo.gotlos.max, | |
3487 | gpinfo.g.gothilo, | |
3488 | gpinfo.g.fdhilo, | |
3489 | gpinfo.g.fdplt - gpinfo.got12.fdplt | |
3490 | - gpinfo.gotlos.fdplt, | |
3491 | (bfd_vma)1 << (32-1)); | |
51532845 AO |
3492 | |
3493 | /* Now assign (most) GOT offsets. */ | |
43850d5b AO |
3494 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries, |
3495 | &gpinfo); | |
51532845 | 3496 | |
43850d5b AO |
3497 | frvfdpic_got_section (info)->_raw_size = gpinfo.gothilo.max |
3498 | - gpinfo.gothilo.min | |
51532845 AO |
3499 | /* If an odd word is the last word of the GOT, we don't need this |
3500 | word to be part of the GOT. */ | |
3501 | - (odd + 4 == gpinfo.gothilo.max ? 4 : 0); | |
43850d5b AO |
3502 | if (frvfdpic_got_section (info)->_raw_size == 0) |
3503 | frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; | |
3504 | else if (frvfdpic_got_section (info)->_raw_size == 12 | |
51532845 AO |
3505 | && ! elf_hash_table (info)->dynamic_sections_created) |
3506 | { | |
43850d5b AO |
3507 | frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; |
3508 | frvfdpic_got_section (info)->_raw_size = 0; | |
51532845 AO |
3509 | } |
3510 | else | |
3511 | { | |
43850d5b AO |
3512 | frvfdpic_got_section (info)->contents = |
3513 | (bfd_byte *) bfd_zalloc (dynobj, | |
3514 | frvfdpic_got_section (info)->_raw_size); | |
3515 | if (frvfdpic_got_section (info)->contents == NULL) | |
51532845 AO |
3516 | return FALSE; |
3517 | } | |
3518 | ||
3519 | if (elf_hash_table (info)->dynamic_sections_created) | |
3520 | /* Subtract the number of lzplt entries, since those will generate | |
3521 | relocations in the pltrel section. */ | |
43850d5b | 3522 | frvfdpic_gotrel_section (info)->_raw_size = |
51532845 AO |
3523 | (gpinfo.g.relocs - gpinfo.g.lzplt / 8) |
3524 | * get_elf_backend_data (output_bfd)->s->sizeof_rel; | |
3525 | else | |
3526 | BFD_ASSERT (gpinfo.g.relocs == 0); | |
43850d5b AO |
3527 | if (frvfdpic_gotrel_section (info)->_raw_size == 0) |
3528 | frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE; | |
51532845 AO |
3529 | else |
3530 | { | |
43850d5b AO |
3531 | frvfdpic_gotrel_section (info)->contents = |
3532 | (bfd_byte *) bfd_zalloc (dynobj, | |
3533 | frvfdpic_gotrel_section (info)->_raw_size); | |
3534 | if (frvfdpic_gotrel_section (info)->contents == NULL) | |
51532845 AO |
3535 | return FALSE; |
3536 | } | |
3537 | ||
43850d5b AO |
3538 | frvfdpic_gotfixup_section (info)->_raw_size = (gpinfo.g.fixups + 1) * 4; |
3539 | if (frvfdpic_gotfixup_section (info)->_raw_size == 0) | |
3540 | frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE; | |
51532845 AO |
3541 | else |
3542 | { | |
43850d5b | 3543 | frvfdpic_gotfixup_section (info)->contents = |
51532845 | 3544 | (bfd_byte *) bfd_zalloc (dynobj, |
43850d5b AO |
3545 | frvfdpic_gotfixup_section (info)->_raw_size); |
3546 | if (frvfdpic_gotfixup_section (info)->contents == NULL) | |
51532845 AO |
3547 | return FALSE; |
3548 | } | |
3549 | ||
3550 | if (elf_hash_table (info)->dynamic_sections_created) | |
3551 | { | |
43850d5b | 3552 | frvfdpic_pltrel_section (info)->_raw_size = |
51532845 | 3553 | gpinfo.g.lzplt / 8 * get_elf_backend_data (output_bfd)->s->sizeof_rel; |
43850d5b AO |
3554 | if (frvfdpic_pltrel_section (info)->_raw_size == 0) |
3555 | frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE; | |
51532845 AO |
3556 | else |
3557 | { | |
43850d5b | 3558 | frvfdpic_pltrel_section (info)->contents = |
51532845 | 3559 | (bfd_byte *) bfd_zalloc (dynobj, |
43850d5b AO |
3560 | frvfdpic_pltrel_section (info) |
3561 | ->_raw_size); | |
3562 | if (frvfdpic_pltrel_section (info)->contents == NULL) | |
51532845 AO |
3563 | return FALSE; |
3564 | } | |
3565 | } | |
3566 | ||
3567 | /* Add 4 bytes for every block of at most 65535 lazy PLT entries, | |
3568 | such that there's room for the additional instruction needed to | |
43850d5b AO |
3569 | call the resolver. Since _frvfdpic_assign_got_entries didn't |
3570 | account for them, our block size is 4 bytes smaller than the real | |
3571 | block size. */ | |
51532845 AO |
3572 | if (elf_hash_table (info)->dynamic_sections_created) |
3573 | { | |
43850d5b AO |
3574 | frvfdpic_plt_section (info)->_raw_size = gpinfo.g.lzplt |
3575 | + ((gpinfo.g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8) | |
3576 | / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4); | |
51532845 | 3577 | } |
b34976b6 | 3578 | |
43850d5b | 3579 | /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to |
51532845 AO |
3580 | actually assign lazy PLT entries addresses. */ |
3581 | gpinfo.g.lzplt = 0; | |
b34976b6 | 3582 | |
51532845 AO |
3583 | /* Save information that we're going to need to generate GOT and PLT |
3584 | entries. */ | |
43850d5b | 3585 | frvfdpic_got_initial_offset (info) = -gpinfo.gothilo.min; |
b34976b6 | 3586 | |
51532845 AO |
3587 | if (get_elf_backend_data (output_bfd)->want_got_sym) |
3588 | elf_hash_table (info)->hgot->root.u.def.value | |
43850d5b | 3589 | += frvfdpic_got_initial_offset (info); |
b34976b6 | 3590 | |
51532845 | 3591 | if (elf_hash_table (info)->dynamic_sections_created) |
43850d5b AO |
3592 | frvfdpic_plt_initial_offset (info) = |
3593 | frvfdpic_plt_section (info)->_raw_size; | |
b34976b6 | 3594 | |
43850d5b AO |
3595 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries, |
3596 | &gpinfo); | |
51532845 AO |
3597 | |
3598 | /* Allocate the PLT section contents only after | |
43850d5b | 3599 | _frvfdpic_assign_plt_entries has a chance to add the size of the |
51532845 AO |
3600 | non-lazy PLT entries. */ |
3601 | if (elf_hash_table (info)->dynamic_sections_created) | |
3602 | { | |
43850d5b AO |
3603 | if (frvfdpic_plt_section (info)->_raw_size == 0) |
3604 | frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE; | |
4e5ba5b7 DB |
3605 | else |
3606 | { | |
43850d5b AO |
3607 | frvfdpic_plt_section (info)->contents = |
3608 | (bfd_byte *) bfd_zalloc (dynobj, | |
3609 | frvfdpic_plt_section (info)->_raw_size); | |
3610 | if (frvfdpic_plt_section (info)->contents == NULL) | |
51532845 AO |
3611 | return FALSE; |
3612 | } | |
3613 | } | |
b34976b6 | 3614 | |
51532845 AO |
3615 | if (elf_hash_table (info)->dynamic_sections_created) |
3616 | { | |
43850d5b | 3617 | if (frvfdpic_got_section (info)->_raw_size) |
5a580b3a | 3618 | if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)) |
51532845 AO |
3619 | return FALSE; |
3620 | ||
43850d5b | 3621 | if (frvfdpic_pltrel_section (info)->_raw_size) |
5a580b3a AM |
3622 | if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0) |
3623 | || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL) | |
3624 | || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0)) | |
51532845 AO |
3625 | return FALSE; |
3626 | ||
43850d5b | 3627 | if (frvfdpic_gotrel_section (info)->_raw_size) |
5a580b3a AM |
3628 | if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0) |
3629 | || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0) | |
3630 | || !_bfd_elf_add_dynamic_entry (info, DT_RELENT, | |
3631 | sizeof (Elf32_External_Rel))) | |
51532845 AO |
3632 | return FALSE; |
3633 | } | |
4e5ba5b7 | 3634 | |
51532845 AO |
3635 | return TRUE; |
3636 | } | |
b34976b6 | 3637 | |
51532845 | 3638 | static bfd_boolean |
43850d5b AO |
3639 | elf32_frvfdpic_always_size_sections (bfd *output_bfd, |
3640 | struct bfd_link_info *info) | |
51532845 | 3641 | { |
43850d5b | 3642 | if (!info->relocatable) |
51532845 AO |
3643 | { |
3644 | struct elf_link_hash_entry *h; | |
3645 | asection *sec; | |
b34976b6 | 3646 | |
51532845 AO |
3647 | /* Force a PT_GNU_STACK segment to be created. */ |
3648 | if (! elf_tdata (output_bfd)->stack_flags) | |
3649 | elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X; | |
4e5ba5b7 | 3650 | |
51532845 AO |
3651 | /* Define __stacksize if it's not defined yet. */ |
3652 | h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", | |
3653 | FALSE, FALSE, FALSE); | |
3654 | if (! h || h->root.type != bfd_link_hash_defined | |
3655 | || h->type != STT_OBJECT | |
3656 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) | |
3657 | { | |
ea01195e | 3658 | struct bfd_link_hash_entry *bh = NULL; |
4e5ba5b7 | 3659 | |
51532845 AO |
3660 | if (!(_bfd_generic_link_add_one_symbol |
3661 | (info, output_bfd, "__stacksize", | |
3662 | BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE, | |
3663 | (const char *) NULL, FALSE, | |
3664 | get_elf_backend_data (output_bfd)->collect, &bh))) | |
3665 | return FALSE; | |
4e5ba5b7 | 3666 | |
51532845 AO |
3667 | h = (struct elf_link_hash_entry *) bh; |
3668 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
3669 | h->type = STT_OBJECT; | |
3670 | } | |
4e5ba5b7 | 3671 | |
51532845 AO |
3672 | /* Create a stack section, and set its alignment. */ |
3673 | sec = bfd_make_section (output_bfd, ".stack"); | |
4e5ba5b7 | 3674 | |
51532845 AO |
3675 | if (sec == NULL |
3676 | || ! bfd_set_section_alignment (output_bfd, sec, 3)) | |
3677 | return FALSE; | |
3678 | } | |
4e5ba5b7 | 3679 | |
51532845 AO |
3680 | return TRUE; |
3681 | } | |
4e5ba5b7 | 3682 | |
51532845 | 3683 | static bfd_boolean |
43850d5b AO |
3684 | elf32_frvfdpic_modify_segment_map (bfd *output_bfd, |
3685 | struct bfd_link_info *info) | |
51532845 | 3686 | { |
43850d5b | 3687 | struct elf_segment_map *m; |
4e5ba5b7 | 3688 | |
43850d5b AO |
3689 | for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next) |
3690 | if (m->p_type == PT_GNU_STACK) | |
3691 | break; | |
3692 | ||
3693 | if (m) | |
3694 | { | |
3695 | asection *sec = bfd_get_section_by_name (output_bfd, ".stack"); | |
3696 | struct elf_link_hash_entry *h; | |
51532845 | 3697 | |
43850d5b | 3698 | if (sec) |
4e5ba5b7 | 3699 | { |
43850d5b AO |
3700 | /* Obtain the pointer to the __stacksize symbol. */ |
3701 | h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", | |
3702 | FALSE, FALSE, FALSE); | |
3703 | while (h->root.type == bfd_link_hash_indirect | |
3704 | || h->root.type == bfd_link_hash_warning) | |
3705 | h = (struct elf_link_hash_entry *)h->root.u.i.link; | |
3706 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
4e5ba5b7 | 3707 | |
43850d5b AO |
3708 | /* Set the section size from the symbol value. We |
3709 | intentionally ignore the symbol section. */ | |
3710 | if (h->root.type == bfd_link_hash_defined) | |
3711 | sec->_raw_size = h->root.u.def.value; | |
3712 | else | |
3713 | sec->_raw_size = DEFAULT_STACK_SIZE; | |
51532845 | 3714 | |
43850d5b AO |
3715 | /* Add the stack section to the PT_GNU_STACK segment, |
3716 | such that its size and alignment requirements make it | |
3717 | to the segment. */ | |
3718 | m->sections[m->count] = sec; | |
3719 | m->count++; | |
51532845 AO |
3720 | } |
3721 | } | |
b34976b6 | 3722 | |
51532845 AO |
3723 | return TRUE; |
3724 | } | |
b34976b6 | 3725 | |
51532845 | 3726 | /* Fill in code and data in dynamic sections. */ |
4e5ba5b7 | 3727 | |
51532845 | 3728 | static bfd_boolean |
43850d5b AO |
3729 | elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
3730 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
3731 | { | |
3732 | /* Nothing to be done for non-FDPIC. */ | |
3733 | return TRUE; | |
3734 | } | |
3735 | ||
3736 | static bfd_boolean | |
3737 | elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd, | |
3738 | struct bfd_link_info *info) | |
51532845 AO |
3739 | { |
3740 | bfd *dynobj; | |
3741 | asection *sdyn; | |
4e5ba5b7 | 3742 | |
51532845 | 3743 | dynobj = elf_hash_table (info)->dynobj; |
4e5ba5b7 | 3744 | |
43850d5b | 3745 | if (frvfdpic_got_section (info)) |
51532845 | 3746 | { |
43850d5b AO |
3747 | BFD_ASSERT (frvfdpic_gotrel_section (info)->_raw_size |
3748 | == (frvfdpic_gotrel_section (info)->reloc_count | |
51532845 | 3749 | * sizeof (Elf32_External_Rel))); |
4e5ba5b7 | 3750 | |
43850d5b | 3751 | if (frvfdpic_gotfixup_section (info)) |
51532845 | 3752 | { |
43850d5b AO |
3753 | struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot; |
3754 | bfd_vma got_value = hgot->root.u.def.value | |
3755 | + hgot->root.u.def.section->output_section->vma | |
3756 | + hgot->root.u.def.section->output_offset; | |
4e5ba5b7 | 3757 | |
43850d5b AO |
3758 | _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info), |
3759 | got_value, 0); | |
51532845 | 3760 | |
43850d5b AO |
3761 | if (frvfdpic_gotfixup_section (info)->_raw_size |
3762 | != (frvfdpic_gotfixup_section (info)->reloc_count * 4)) | |
51532845 | 3763 | { |
43850d5b AO |
3764 | (*_bfd_error_handler) |
3765 | ("LINKER BUG: .rofixup section size mismatch"); | |
3766 | return FALSE; | |
51532845 | 3767 | } |
4e5ba5b7 DB |
3768 | } |
3769 | } | |
51532845 AO |
3770 | if (elf_hash_table (info)->dynamic_sections_created) |
3771 | { | |
43850d5b AO |
3772 | BFD_ASSERT (frvfdpic_pltrel_section (info)->_raw_size |
3773 | == (frvfdpic_pltrel_section (info)->reloc_count | |
51532845 AO |
3774 | * sizeof (Elf32_External_Rel))); |
3775 | } | |
4e5ba5b7 | 3776 | |
51532845 | 3777 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
4e5ba5b7 | 3778 | |
51532845 | 3779 | if (elf_hash_table (info)->dynamic_sections_created) |
4e5ba5b7 | 3780 | { |
51532845 AO |
3781 | Elf32_External_Dyn * dyncon; |
3782 | Elf32_External_Dyn * dynconend; | |
3783 | ||
3784 | BFD_ASSERT (sdyn != NULL); | |
3785 | ||
3786 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
3787 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
3788 | ||
3789 | for (; dyncon < dynconend; dyncon++) | |
4e5ba5b7 | 3790 | { |
51532845 | 3791 | Elf_Internal_Dyn dyn; |
4e5ba5b7 | 3792 | |
51532845 AO |
3793 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
3794 | ||
3795 | switch (dyn.d_tag) | |
4e5ba5b7 DB |
3796 | { |
3797 | default: | |
3798 | break; | |
3799 | ||
51532845 | 3800 | case DT_PLTGOT: |
43850d5b AO |
3801 | dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma |
3802 | + frvfdpic_got_section (info)->output_offset | |
3803 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
3804 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
3805 | break; | |
4e5ba5b7 | 3806 | |
51532845 | 3807 | case DT_JMPREL: |
43850d5b AO |
3808 | dyn.d_un.d_ptr = frvfdpic_pltrel_section (info) |
3809 | ->output_section->vma | |
3810 | + frvfdpic_pltrel_section (info)->output_offset; | |
51532845 AO |
3811 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
3812 | break; | |
3813 | ||
3814 | case DT_PLTRELSZ: | |
43850d5b AO |
3815 | if (frvfdpic_pltrel_section (info)->_cooked_size != 0) |
3816 | dyn.d_un.d_val = frvfdpic_pltrel_section (info)->_cooked_size; | |
51532845 | 3817 | else |
43850d5b | 3818 | dyn.d_un.d_val = frvfdpic_pltrel_section (info)->_raw_size; |
51532845 AO |
3819 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
3820 | break; | |
4e5ba5b7 DB |
3821 | } |
3822 | } | |
3823 | } | |
4e5ba5b7 | 3824 | |
51532845 | 3825 | return TRUE; |
4e5ba5b7 DB |
3826 | } |
3827 | ||
51532845 AO |
3828 | /* Adjust a symbol defined by a dynamic object and referenced by a |
3829 | regular object. */ | |
4e5ba5b7 | 3830 | |
b34976b6 | 3831 | static bfd_boolean |
43850d5b AO |
3832 | elf32_frvfdpic_adjust_dynamic_symbol |
3833 | (struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
3834 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) | |
4e5ba5b7 | 3835 | { |
51532845 AO |
3836 | bfd * dynobj; |
3837 | ||
3838 | dynobj = elf_hash_table (info)->dynobj; | |
3839 | ||
3840 | /* Make sure we know what is going on here. */ | |
3841 | BFD_ASSERT (dynobj != NULL | |
3842 | && (h->weakdef != NULL | |
3843 | || ((h->elf_link_hash_flags | |
3844 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
3845 | && (h->elf_link_hash_flags | |
3846 | & ELF_LINK_HASH_REF_REGULAR) != 0 | |
3847 | && (h->elf_link_hash_flags | |
3848 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); | |
3849 | ||
3850 | /* If this is a weak symbol, and there is a real definition, the | |
3851 | processor independent code will have arranged for us to see the | |
3852 | real definition first, and we can just use the same value. */ | |
3853 | if (h->weakdef != NULL) | |
3854 | { | |
3855 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
3856 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
3857 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
3858 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
3859 | } | |
3860 | ||
b34976b6 | 3861 | return TRUE; |
4e5ba5b7 DB |
3862 | } |
3863 | ||
51532845 | 3864 | /* Perform any actions needed for dynamic symbols. */ |
4e5ba5b7 | 3865 | |
b34976b6 | 3866 | static bfd_boolean |
43850d5b AO |
3867 | elf32_frvfdpic_finish_dynamic_symbol |
3868 | (bfd *output_bfd ATTRIBUTE_UNUSED, | |
3869 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
3870 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED, | |
3871 | Elf_Internal_Sym *sym ATTRIBUTE_UNUSED) | |
4e5ba5b7 | 3872 | { |
b34976b6 | 3873 | return TRUE; |
4e5ba5b7 | 3874 | } |
51532845 | 3875 | |
ec3391e7 AO |
3876 | /* Decide whether to attempt to turn absptr or lsda encodings in |
3877 | shared libraries into pcrel within the given input section. */ | |
3878 | ||
3879 | static bfd_boolean | |
43850d5b AO |
3880 | frvfdpic_elf_use_relative_eh_frame |
3881 | (bfd *input_bfd ATTRIBUTE_UNUSED, | |
3882 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
3883 | asection *eh_frame_section ATTRIBUTE_UNUSED) | |
ec3391e7 AO |
3884 | { |
3885 | /* We can't use PC-relative encodings in FDPIC binaries, in general. */ | |
43850d5b | 3886 | return FALSE; |
ec3391e7 AO |
3887 | } |
3888 | ||
3889 | /* Adjust the contents of an eh_frame_hdr section before they're output. */ | |
3890 | ||
3891 | static bfd_byte | |
43850d5b AO |
3892 | frvfdpic_elf_encode_eh_address (bfd *abfd, |
3893 | struct bfd_link_info *info, | |
3894 | asection *osec, bfd_vma offset, | |
3895 | asection *loc_sec, bfd_vma loc_offset, | |
3896 | bfd_vma *encoded) | |
ec3391e7 AO |
3897 | { |
3898 | struct elf_link_hash_entry *h; | |
3899 | ||
ec3391e7 AO |
3900 | h = elf_hash_table (info)->hgot; |
3901 | BFD_ASSERT (h && h->root.type == bfd_link_hash_defined); | |
3902 | ||
43850d5b AO |
3903 | if (! h || (_frvfdpic_osec_to_segment (abfd, osec) |
3904 | == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section))) | |
ec3391e7 AO |
3905 | return _bfd_elf_encode_eh_address (abfd, info, osec, offset, |
3906 | loc_sec, loc_offset, encoded); | |
3907 | ||
43850d5b AO |
3908 | BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec) |
3909 | == (_frvfdpic_osec_to_segment | |
3910 | (abfd, h->root.u.def.section->output_section))); | |
ec3391e7 AO |
3911 | |
3912 | *encoded = osec->vma + offset | |
3913 | - (h->root.u.def.value | |
3914 | + h->root.u.def.section->output_section->vma | |
3915 | + h->root.u.def.section->output_offset); | |
3916 | ||
3917 | return DW_EH_PE_datarel | DW_EH_PE_sdata4; | |
3918 | } | |
3919 | ||
4e5ba5b7 | 3920 | /* Look through the relocs for a section during the first phase. |
51532845 AO |
3921 | |
3922 | Besides handling virtual table relocs for gc, we have to deal with | |
3923 | all sorts of PIC-related relocations. We describe below the | |
3924 | general plan on how to handle such relocations, even though we only | |
3925 | collect information at this point, storing them in hash tables for | |
3926 | perusal of later passes. | |
3927 | ||
3928 | 32 relocations are propagated to the linker output when creating | |
3929 | position-independent output. LO16 and HI16 relocations are not | |
3930 | supposed to be encountered in this case. | |
3931 | ||
3932 | LABEL16 should always be resolvable by the linker, since it's only | |
3933 | used by branches. | |
3934 | ||
3935 | LABEL24, on the other hand, is used by calls. If it turns out that | |
3936 | the target of a call is a dynamic symbol, a PLT entry must be | |
3937 | created for it, which triggers the creation of a private function | |
3938 | descriptor and, unless lazy binding is disabled, a lazy PLT entry. | |
3939 | ||
3940 | GPREL relocations require the referenced symbol to be in the same | |
3941 | segment as _gp, but this can only be checked later. | |
3942 | ||
3943 | All GOT, GOTOFF and FUNCDESC relocations require a .got section to | |
3944 | exist. LABEL24 might as well, since it may require a PLT entry, | |
3945 | that will require a got. | |
3946 | ||
3947 | Non-FUNCDESC GOT relocations require a GOT entry to be created | |
3948 | regardless of whether the symbol is dynamic. However, since a | |
3949 | global symbol that turns out to not be exported may have the same | |
3950 | address of a non-dynamic symbol, we don't assign GOT entries at | |
3951 | this point, such that we can share them in this case. A relocation | |
3952 | for the GOT entry always has to be created, be it to offset a | |
3953 | private symbol by the section load address, be it to get the symbol | |
3954 | resolved dynamically. | |
3955 | ||
3956 | FUNCDESC GOT relocations require a GOT entry to be created, and | |
3957 | handled as if a FUNCDESC relocation was applied to the GOT entry in | |
3958 | an object file. | |
3959 | ||
3960 | FUNCDESC relocations referencing a symbol that turns out to NOT be | |
3961 | dynamic cause a private function descriptor to be created. The | |
3962 | FUNCDESC relocation then decays to a 32 relocation that points at | |
3963 | the private descriptor. If the symbol is dynamic, the FUNCDESC | |
3964 | relocation is propagated to the linker output, such that the | |
3965 | dynamic linker creates the canonical descriptor, pointing to the | |
3966 | dynamically-resolved definition of the function. | |
3967 | ||
3968 | Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic | |
3969 | symbols that are assigned to the same segment as the GOT, but we | |
3970 | can only check this later, after we know the complete set of | |
3971 | symbols defined and/or exported. | |
3972 | ||
3973 | FUNCDESC GOTOFF relocations require a function descriptor to be | |
3974 | created and, unless lazy binding is disabled or the symbol is not | |
3975 | dynamic, a lazy PLT entry. Since we can't tell at this point | |
3976 | whether a symbol is going to be dynamic, we have to decide later | |
3977 | whether to create a lazy PLT entry or bind the descriptor directly | |
3978 | to the private function. | |
3979 | ||
3980 | FUNCDESC_VALUE relocations are not supposed to be present in object | |
3981 | files, but they may very well be simply propagated to the linker | |
3982 | output, since they have no side effect. | |
3983 | ||
3984 | ||
3985 | A function descriptor always requires a FUNCDESC_VALUE relocation. | |
3986 | Whether it's in .plt.rel or not depends on whether lazy binding is | |
3987 | enabled and on whether the referenced symbol is dynamic. | |
3988 | ||
3989 | The existence of a lazy PLT requires the resolverStub lazy PLT | |
3990 | entry to be present. | |
3991 | ||
3992 | ||
3993 | As for assignment of GOT, PLT and lazy PLT entries, and private | |
3994 | descriptors, we might do them all sequentially, but we can do | |
3995 | better than that. For example, we can place GOT entries and | |
3996 | private function descriptors referenced using 12-bit operands | |
3997 | closer to the PIC register value, such that these relocations don't | |
3998 | overflow. Those that are only referenced with LO16 relocations | |
3999 | could come next, but we may as well place PLT-required function | |
4000 | descriptors in the 12-bit range to make them shorter. Symbols | |
4001 | referenced with LO16/HI16 may come next, but we may place | |
4002 | additional function descriptors in the 16-bit range if we can | |
4003 | reliably tell that we've already placed entries that are ever | |
4004 | referenced with only LO16. PLT entries are therefore generated as | |
4005 | small as possible, while not introducing relocation overflows in | |
4006 | GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be | |
4007 | generated before or after PLT entries, but not intermingled with | |
4008 | them, such that we can have more lazy PLT entries in range for a | |
4009 | branch to the resolverStub. The resolverStub should be emitted at | |
4010 | the most distant location from the first lazy PLT entry such that | |
4011 | it's still in range for a branch, or closer, if there isn't a need | |
4012 | for so many lazy PLT entries. Additional lazy PLT entries may be | |
4013 | emitted after the resolverStub, as long as branches are still in | |
4014 | range. If the branch goes out of range, longer lazy PLT entries | |
4015 | are emitted. | |
4016 | ||
4017 | We could further optimize PLT and lazy PLT entries by giving them | |
4018 | priority in assignment to closer-to-gr17 locations depending on the | |
4019 | number of occurrences of references to them (assuming a function | |
4020 | that's called more often is more important for performance, so its | |
4021 | PLT entry should be faster), or taking hints from the compiler. | |
4022 | Given infinite time and money... :-) */ | |
b34976b6 AM |
4023 | |
4024 | static bfd_boolean | |
4e5ba5b7 DB |
4025 | elf32_frv_check_relocs (abfd, info, sec, relocs) |
4026 | bfd *abfd; | |
4027 | struct bfd_link_info *info; | |
4028 | asection *sec; | |
4029 | const Elf_Internal_Rela *relocs; | |
4030 | { | |
4031 | Elf_Internal_Shdr *symtab_hdr; | |
4032 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
4033 | const Elf_Internal_Rela *rel; | |
4034 | const Elf_Internal_Rela *rel_end; | |
51532845 | 4035 | bfd *dynobj; |
43850d5b | 4036 | struct frvfdpic_relocs_info *picrel; |
b34976b6 | 4037 | |
1049f94e | 4038 | if (info->relocatable) |
b34976b6 AM |
4039 | return TRUE; |
4040 | ||
4e5ba5b7 DB |
4041 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4042 | sym_hashes = elf_sym_hashes (abfd); | |
4043 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym); | |
4044 | if (!elf_bad_symtab (abfd)) | |
4045 | sym_hashes_end -= symtab_hdr->sh_info; | |
b34976b6 | 4046 | |
51532845 | 4047 | dynobj = elf_hash_table (info)->dynobj; |
4e5ba5b7 DB |
4048 | rel_end = relocs + sec->reloc_count; |
4049 | for (rel = relocs; rel < rel_end; rel++) | |
4050 | { | |
4051 | struct elf_link_hash_entry *h; | |
4052 | unsigned long r_symndx; | |
b34976b6 | 4053 | |
4e5ba5b7 DB |
4054 | r_symndx = ELF32_R_SYM (rel->r_info); |
4055 | if (r_symndx < symtab_hdr->sh_info) | |
4056 | h = NULL; | |
4057 | else | |
4058 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
b34976b6 | 4059 | |
51532845 AO |
4060 | switch (ELF32_R_TYPE (rel->r_info)) |
4061 | { | |
51532845 AO |
4062 | case R_FRV_GOT12: |
4063 | case R_FRV_GOTHI: | |
4064 | case R_FRV_GOTLO: | |
4065 | case R_FRV_FUNCDESC_GOT12: | |
4066 | case R_FRV_FUNCDESC_GOTHI: | |
4067 | case R_FRV_FUNCDESC_GOTLO: | |
4068 | case R_FRV_GOTOFF12: | |
4069 | case R_FRV_GOTOFFHI: | |
4070 | case R_FRV_GOTOFFLO: | |
4071 | case R_FRV_FUNCDESC_GOTOFF12: | |
4072 | case R_FRV_FUNCDESC_GOTOFFHI: | |
4073 | case R_FRV_FUNCDESC_GOTOFFLO: | |
4074 | case R_FRV_FUNCDESC: | |
4075 | case R_FRV_FUNCDESC_VALUE: | |
43850d5b AO |
4076 | if (! IS_FDPIC (abfd)) |
4077 | goto bad_reloc; | |
4078 | /* Fall through. */ | |
4079 | case R_FRV_GPREL12: | |
4080 | case R_FRV_GPRELU12: | |
4081 | case R_FRV_GPRELHI: | |
4082 | case R_FRV_GPRELLO: | |
4083 | case R_FRV_LABEL24: | |
4084 | case R_FRV_32: | |
51532845 AO |
4085 | if (! dynobj) |
4086 | { | |
4087 | elf_hash_table (info)->dynobj = dynobj = abfd; | |
4088 | if (! _frv_create_got_section (abfd, info)) | |
4089 | return FALSE; | |
4090 | } | |
43850d5b AO |
4091 | if (! IS_FDPIC (abfd)) |
4092 | { | |
4093 | picrel = NULL; | |
4094 | break; | |
4095 | } | |
51532845 AO |
4096 | if (h != NULL) |
4097 | { | |
4098 | if (h->dynindx == -1) | |
4099 | switch (ELF_ST_VISIBILITY (h->other)) | |
4100 | { | |
4101 | case STV_INTERNAL: | |
4102 | case STV_HIDDEN: | |
4103 | break; | |
4104 | default: | |
c152c796 | 4105 | bfd_elf_link_record_dynamic_symbol (info, h); |
51532845 AO |
4106 | break; |
4107 | } | |
4108 | picrel | |
43850d5b AO |
4109 | = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), |
4110 | abfd, h, | |
4111 | rel->r_addend, INSERT); | |
51532845 AO |
4112 | } |
4113 | else | |
43850d5b AO |
4114 | picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info |
4115 | (info), abfd, r_symndx, | |
4116 | rel->r_addend, INSERT); | |
51532845 AO |
4117 | if (! picrel) |
4118 | return FALSE; | |
4119 | break; | |
4120 | ||
4121 | default: | |
4122 | picrel = NULL; | |
4123 | break; | |
4124 | } | |
4125 | ||
4e5ba5b7 DB |
4126 | switch (ELF32_R_TYPE (rel->r_info)) |
4127 | { | |
51532845 | 4128 | case R_FRV_LABEL24: |
43850d5b AO |
4129 | if (IS_FDPIC (abfd)) |
4130 | picrel->call = 1; | |
51532845 AO |
4131 | break; |
4132 | ||
4133 | case R_FRV_FUNCDESC_VALUE: | |
4134 | picrel->relocsfdv++; | |
4135 | if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
4136 | picrel->relocs32--; | |
4137 | /* Fall through. */ | |
43850d5b | 4138 | |
51532845 | 4139 | case R_FRV_32: |
43850d5b AO |
4140 | if (! IS_FDPIC (abfd)) |
4141 | break; | |
4142 | ||
51532845 AO |
4143 | picrel->sym = 1; |
4144 | if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
4145 | picrel->relocs32++; | |
4146 | break; | |
4147 | ||
4148 | case R_FRV_GOT12: | |
4149 | picrel->got12 = 1; | |
4150 | break; | |
4151 | ||
4152 | case R_FRV_GOTHI: | |
4153 | case R_FRV_GOTLO: | |
4154 | picrel->gothilo = 1; | |
4155 | break; | |
4156 | ||
4157 | case R_FRV_FUNCDESC_GOT12: | |
4158 | picrel->fdgot12 = 1; | |
4159 | break; | |
4160 | ||
4161 | case R_FRV_FUNCDESC_GOTHI: | |
4162 | case R_FRV_FUNCDESC_GOTLO: | |
4163 | picrel->fdgothilo = 1; | |
4164 | break; | |
4165 | ||
4166 | case R_FRV_GOTOFF12: | |
4167 | case R_FRV_GOTOFFHI: | |
4168 | case R_FRV_GOTOFFLO: | |
4169 | picrel->gotoff = 1; | |
4170 | break; | |
4171 | ||
4172 | case R_FRV_FUNCDESC_GOTOFF12: | |
4173 | picrel->fdgoff12 = 1; | |
4174 | break; | |
4175 | ||
4176 | case R_FRV_FUNCDESC_GOTOFFHI: | |
4177 | case R_FRV_FUNCDESC_GOTOFFLO: | |
4178 | picrel->fdgoffhilo = 1; | |
4179 | break; | |
4180 | ||
4181 | case R_FRV_FUNCDESC: | |
4182 | picrel->fd = 1; | |
4183 | picrel->relocsfd++; | |
4184 | break; | |
4185 | ||
4e5ba5b7 DB |
4186 | /* This relocation describes the C++ object vtable hierarchy. |
4187 | Reconstruct it for later use during GC. */ | |
4188 | case R_FRV_GNU_VTINHERIT: | |
c152c796 | 4189 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 4190 | return FALSE; |
4e5ba5b7 | 4191 | break; |
b34976b6 | 4192 | |
4e5ba5b7 DB |
4193 | /* This relocation describes which C++ vtable entries are actually |
4194 | used. Record for later use during GC. */ | |
4195 | case R_FRV_GNU_VTENTRY: | |
c152c796 | 4196 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 4197 | return FALSE; |
4e5ba5b7 | 4198 | break; |
43850d5b AO |
4199 | |
4200 | case R_FRV_LABEL16: | |
4201 | case R_FRV_LO16: | |
4202 | case R_FRV_HI16: | |
4203 | case R_FRV_GPREL12: | |
4204 | case R_FRV_GPRELU12: | |
4205 | case R_FRV_GPREL32: | |
4206 | case R_FRV_GPRELHI: | |
4207 | case R_FRV_GPRELLO: | |
4208 | break; | |
4209 | ||
4210 | default: | |
4211 | bad_reloc: | |
4212 | (*_bfd_error_handler) | |
4213 | (_("%s: unsupported relocation type %i"), | |
4214 | bfd_archive_filename (abfd), ELF32_R_TYPE (rel->r_info)); | |
4215 | return FALSE; | |
4e5ba5b7 DB |
4216 | } |
4217 | } | |
b34976b6 AM |
4218 | |
4219 | return TRUE; | |
4e5ba5b7 DB |
4220 | } |
4221 | ||
4222 | \f | |
4223 | /* Return the machine subcode from the ELF e_flags header. */ | |
4224 | ||
4225 | static int | |
4226 | elf32_frv_machine (abfd) | |
4227 | bfd *abfd; | |
4228 | { | |
4229 | switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK) | |
4230 | { | |
4231 | default: break; | |
9c8ee639 | 4232 | case EF_FRV_CPU_FR550: return bfd_mach_fr550; |
4e5ba5b7 | 4233 | case EF_FRV_CPU_FR500: return bfd_mach_fr500; |
676a64f4 RS |
4234 | case EF_FRV_CPU_FR450: return bfd_mach_fr450; |
4235 | case EF_FRV_CPU_FR405: return bfd_mach_fr400; | |
4e5ba5b7 DB |
4236 | case EF_FRV_CPU_FR400: return bfd_mach_fr400; |
4237 | case EF_FRV_CPU_FR300: return bfd_mach_fr300; | |
4238 | case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple; | |
4239 | case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat; | |
4240 | } | |
4241 | ||
4242 | return bfd_mach_frv; | |
4243 | } | |
4244 | ||
4245 | /* Set the right machine number for a FRV ELF file. */ | |
4246 | ||
b34976b6 | 4247 | static bfd_boolean |
4e5ba5b7 DB |
4248 | elf32_frv_object_p (abfd) |
4249 | bfd *abfd; | |
4250 | { | |
4251 | bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd)); | |
43850d5b AO |
4252 | return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0) |
4253 | == (IS_FDPIC (abfd))); | |
4e5ba5b7 DB |
4254 | } |
4255 | \f | |
4256 | /* Function to set the ELF flag bits. */ | |
4257 | ||
b34976b6 | 4258 | static bfd_boolean |
4e5ba5b7 DB |
4259 | frv_elf_set_private_flags (abfd, flags) |
4260 | bfd *abfd; | |
4261 | flagword flags; | |
4262 | { | |
4263 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 AM |
4264 | elf_flags_init (abfd) = TRUE; |
4265 | return TRUE; | |
4e5ba5b7 DB |
4266 | } |
4267 | ||
4268 | /* Copy backend specific data from one object module to another. */ | |
4269 | ||
b34976b6 | 4270 | static bfd_boolean |
4e5ba5b7 DB |
4271 | frv_elf_copy_private_bfd_data (ibfd, obfd) |
4272 | bfd *ibfd; | |
4273 | bfd *obfd; | |
4274 | { | |
4275 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
4276 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 4277 | return TRUE; |
4e5ba5b7 DB |
4278 | |
4279 | BFD_ASSERT (!elf_flags_init (obfd) | |
4280 | || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags); | |
4281 | ||
4282 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; | |
b34976b6 AM |
4283 | elf_flags_init (obfd) = TRUE; |
4284 | return TRUE; | |
4e5ba5b7 DB |
4285 | } |
4286 | ||
676a64f4 RS |
4287 | /* Return true if the architecture described by elf header flag |
4288 | EXTENSION is an extension of the architecture described by BASE. */ | |
4289 | ||
4290 | static bfd_boolean | |
4291 | frv_elf_arch_extension_p (flagword base, flagword extension) | |
4292 | { | |
4293 | if (base == extension) | |
4294 | return TRUE; | |
4295 | ||
4296 | /* CPU_GENERIC code can be merged with code for a specific | |
4297 | architecture, in which case the result is marked as being | |
4298 | for the specific architecture. Everything is therefore | |
4299 | an extension of CPU_GENERIC. */ | |
4300 | if (base == EF_FRV_CPU_GENERIC) | |
4301 | return TRUE; | |
4302 | ||
4303 | if (extension == EF_FRV_CPU_FR450) | |
4304 | if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405) | |
4305 | return TRUE; | |
4306 | ||
4307 | if (extension == EF_FRV_CPU_FR405) | |
4308 | if (base == EF_FRV_CPU_FR400) | |
4309 | return TRUE; | |
4310 | ||
4311 | return FALSE; | |
4312 | } | |
4313 | ||
4e5ba5b7 DB |
4314 | /* Merge backend specific data from an object file to the output |
4315 | object file when linking. */ | |
4316 | ||
b34976b6 | 4317 | static bfd_boolean |
4e5ba5b7 DB |
4318 | frv_elf_merge_private_bfd_data (ibfd, obfd) |
4319 | bfd *ibfd; | |
4320 | bfd *obfd; | |
4321 | { | |
4322 | flagword old_flags, old_partial; | |
4323 | flagword new_flags, new_partial; | |
b34976b6 | 4324 | bfd_boolean error = FALSE; |
4e5ba5b7 DB |
4325 | char new_opt[80]; |
4326 | char old_opt[80]; | |
4327 | ||
4328 | new_opt[0] = old_opt[0] = '\0'; | |
4329 | new_flags = elf_elfheader (ibfd)->e_flags; | |
4330 | old_flags = elf_elfheader (obfd)->e_flags; | |
4331 | ||
51532845 AO |
4332 | if (new_flags & EF_FRV_FDPIC) |
4333 | new_flags &= ~EF_FRV_PIC; | |
4334 | ||
4e5ba5b7 DB |
4335 | #ifdef DEBUG |
4336 | (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s", | |
4337 | old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no", | |
4338 | bfd_get_filename (ibfd)); | |
4339 | #endif | |
4340 | ||
4341 | if (!elf_flags_init (obfd)) /* First call, no flags set. */ | |
4342 | { | |
b34976b6 | 4343 | elf_flags_init (obfd) = TRUE; |
4e5ba5b7 DB |
4344 | old_flags = new_flags; |
4345 | } | |
4346 | ||
4347 | else if (new_flags == old_flags) /* Compatible flags are ok. */ | |
4348 | ; | |
4349 | ||
4350 | else /* Possibly incompatible flags. */ | |
4351 | { | |
4352 | /* Warn if different # of gprs are used. Note, 0 means nothing is | |
4353 | said about the size of gprs. */ | |
4354 | new_partial = (new_flags & EF_FRV_GPR_MASK); | |
4355 | old_partial = (old_flags & EF_FRV_GPR_MASK); | |
4356 | if (new_partial == old_partial) | |
4357 | ; | |
4358 | ||
4359 | else if (new_partial == 0) | |
4360 | ; | |
4361 | ||
4362 | else if (old_partial == 0) | |
4363 | old_flags |= new_partial; | |
4364 | ||
4365 | else | |
4366 | { | |
4367 | switch (new_partial) | |
4368 | { | |
4369 | default: strcat (new_opt, " -mgpr-??"); break; | |
4370 | case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break; | |
4371 | case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break; | |
4372 | } | |
4373 | ||
4374 | switch (old_partial) | |
4375 | { | |
4376 | default: strcat (old_opt, " -mgpr-??"); break; | |
4377 | case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break; | |
4378 | case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break; | |
4379 | } | |
4380 | } | |
4381 | ||
4382 | /* Warn if different # of fprs are used. Note, 0 means nothing is | |
4383 | said about the size of fprs. */ | |
4384 | new_partial = (new_flags & EF_FRV_FPR_MASK); | |
4385 | old_partial = (old_flags & EF_FRV_FPR_MASK); | |
4386 | if (new_partial == old_partial) | |
4387 | ; | |
4388 | ||
4389 | else if (new_partial == 0) | |
4390 | ; | |
4391 | ||
4392 | else if (old_partial == 0) | |
4393 | old_flags |= new_partial; | |
4394 | ||
4395 | else | |
4396 | { | |
4397 | switch (new_partial) | |
4398 | { | |
4399 | default: strcat (new_opt, " -mfpr-?"); break; | |
4400 | case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break; | |
4401 | case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break; | |
4402 | case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break; | |
4403 | } | |
4404 | ||
4405 | switch (old_partial) | |
4406 | { | |
4407 | default: strcat (old_opt, " -mfpr-?"); break; | |
4408 | case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break; | |
4409 | case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break; | |
4410 | case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break; | |
4411 | } | |
4412 | } | |
4413 | ||
4414 | /* Warn if different dword support was used. Note, 0 means nothing is | |
4415 | said about the dword support. */ | |
4416 | new_partial = (new_flags & EF_FRV_DWORD_MASK); | |
4417 | old_partial = (old_flags & EF_FRV_DWORD_MASK); | |
4418 | if (new_partial == old_partial) | |
4419 | ; | |
4420 | ||
4421 | else if (new_partial == 0) | |
4422 | ; | |
4423 | ||
4424 | else if (old_partial == 0) | |
4425 | old_flags |= new_partial; | |
4426 | ||
4427 | else | |
4428 | { | |
4429 | switch (new_partial) | |
4430 | { | |
4431 | default: strcat (new_opt, " -mdword-?"); break; | |
4432 | case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break; | |
4433 | case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break; | |
4434 | } | |
4435 | ||
4436 | switch (old_partial) | |
4437 | { | |
4438 | default: strcat (old_opt, " -mdword-?"); break; | |
4439 | case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break; | |
4440 | case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break; | |
4441 | } | |
4442 | } | |
4443 | ||
4444 | /* Or in flags that accumulate (ie, if one module uses it, mark that the | |
4445 | feature is used. */ | |
4446 | old_flags |= new_flags & (EF_FRV_DOUBLE | |
4447 | | EF_FRV_MEDIA | |
4448 | | EF_FRV_MULADD | |
4449 | | EF_FRV_NON_PIC_RELOCS); | |
4450 | ||
4451 | /* If any module was compiled without -G0, clear the G0 bit. */ | |
4452 | old_flags = ((old_flags & ~ EF_FRV_G0) | |
4453 | | (old_flags & new_flags & EF_FRV_G0)); | |
4454 | ||
4455 | /* If any module was compiled without -mnopack, clear the mnopack bit. */ | |
4456 | old_flags = ((old_flags & ~ EF_FRV_NOPACK) | |
4457 | | (old_flags & new_flags & EF_FRV_NOPACK)); | |
4458 | ||
4459 | /* We don't have to do anything if the pic flags are the same, or the new | |
4460 | module(s) were compiled with -mlibrary-pic. */ | |
4461 | new_partial = (new_flags & EF_FRV_PIC_FLAGS); | |
4462 | old_partial = (old_flags & EF_FRV_PIC_FLAGS); | |
4463 | if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0)) | |
4464 | ; | |
4465 | ||
4466 | /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic | |
4467 | flags if any from the new module. */ | |
4468 | else if ((old_partial & EF_FRV_LIBPIC) != 0) | |
4469 | old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial; | |
4470 | ||
4471 | /* If we have mixtures of -fpic and -fPIC, or in both bits. */ | |
4472 | else if (new_partial != 0 && old_partial != 0) | |
4473 | old_flags |= new_partial; | |
4474 | ||
4475 | /* One module was compiled for pic and the other was not, see if we have | |
4476 | had any relocations that are not pic-safe. */ | |
4477 | else | |
4478 | { | |
4479 | if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0) | |
4480 | old_flags |= new_partial; | |
4481 | else | |
4482 | { | |
4483 | old_flags &= ~ EF_FRV_PIC_FLAGS; | |
4484 | #ifndef FRV_NO_PIC_ERROR | |
b34976b6 | 4485 | error = TRUE; |
4e5ba5b7 DB |
4486 | (*_bfd_error_handler) |
4487 | (_("%s: compiled with %s and linked with modules that use non-pic relocations"), | |
4488 | bfd_get_filename (ibfd), | |
4489 | (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic"); | |
4490 | #endif | |
4491 | } | |
4492 | } | |
4493 | ||
4494 | /* Warn if different cpu is used (allow a specific cpu to override | |
4495 | the generic cpu). */ | |
4496 | new_partial = (new_flags & EF_FRV_CPU_MASK); | |
4497 | old_partial = (old_flags & EF_FRV_CPU_MASK); | |
676a64f4 | 4498 | if (frv_elf_arch_extension_p (new_partial, old_partial)) |
4e5ba5b7 DB |
4499 | ; |
4500 | ||
676a64f4 | 4501 | else if (frv_elf_arch_extension_p (old_partial, new_partial)) |
4e5ba5b7 DB |
4502 | old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial; |
4503 | ||
4504 | else | |
4505 | { | |
4506 | switch (new_partial) | |
4507 | { | |
4508 | default: strcat (new_opt, " -mcpu=?"); break; | |
4509 | case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break; | |
4510 | case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break; | |
9c8ee639 | 4511 | case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break; |
4e5ba5b7 | 4512 | case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break; |
676a64f4 RS |
4513 | case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break; |
4514 | case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
4515 | case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break; |
4516 | case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break; | |
4517 | case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break; | |
4518 | } | |
4519 | ||
4520 | switch (old_partial) | |
4521 | { | |
4522 | default: strcat (old_opt, " -mcpu=?"); break; | |
4523 | case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break; | |
4524 | case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break; | |
9c8ee639 | 4525 | case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break; |
4e5ba5b7 | 4526 | case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break; |
676a64f4 RS |
4527 | case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break; |
4528 | case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
4529 | case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break; |
4530 | case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break; | |
4531 | case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break; | |
4532 | } | |
4533 | } | |
b34976b6 | 4534 | |
4e5ba5b7 DB |
4535 | /* Print out any mismatches from above. */ |
4536 | if (new_opt[0]) | |
4537 | { | |
b34976b6 | 4538 | error = TRUE; |
4e5ba5b7 DB |
4539 | (*_bfd_error_handler) |
4540 | (_("%s: compiled with %s and linked with modules compiled with %s"), | |
4541 | bfd_get_filename (ibfd), new_opt, old_opt); | |
4542 | } | |
4543 | ||
4544 | /* Warn about any other mismatches */ | |
4545 | new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS); | |
4546 | old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS); | |
4547 | if (new_partial != old_partial) | |
4548 | { | |
4549 | old_flags |= new_partial; | |
b34976b6 | 4550 | error = TRUE; |
4e5ba5b7 DB |
4551 | (*_bfd_error_handler) |
4552 | (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"), | |
4553 | bfd_get_filename (ibfd), (long)new_partial, (long)old_partial); | |
4554 | } | |
4555 | } | |
4556 | ||
4557 | /* If the cpu is -mcpu=simple, then set the -mnopack bit. */ | |
4558 | if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE) | |
4559 | old_flags |= EF_FRV_NOPACK; | |
4560 | ||
4561 | /* Update the old flags now with changes made above. */ | |
4562 | old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK; | |
4563 | elf_elfheader (obfd)->e_flags = old_flags; | |
4564 | if (old_partial != (old_flags & EF_FRV_CPU_MASK)) | |
4565 | bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd)); | |
4566 | ||
43850d5b AO |
4567 | if (((new_flags & EF_FRV_FDPIC) == 0) |
4568 | != (! IS_FDPIC (ibfd))) | |
4569 | { | |
4570 | error = TRUE; | |
4571 | if (IS_FDPIC (obfd)) | |
4572 | (*_bfd_error_handler) | |
4573 | (_("%s: cannot link non-fdpic object file into fdpic executable"), | |
4574 | bfd_get_filename (ibfd)); | |
4575 | else | |
4576 | (*_bfd_error_handler) | |
4577 | (_("%s: cannot link fdpic object file into non-fdpic executable"), | |
4578 | bfd_get_filename (ibfd)); | |
4579 | } | |
4580 | ||
4e5ba5b7 DB |
4581 | if (error) |
4582 | bfd_set_error (bfd_error_bad_value); | |
4583 | ||
4584 | return !error; | |
4585 | } | |
4586 | ||
4587 | \f | |
b34976b6 | 4588 | bfd_boolean |
4e5ba5b7 DB |
4589 | frv_elf_print_private_bfd_data (abfd, ptr) |
4590 | bfd *abfd; | |
4591 | PTR ptr; | |
4592 | { | |
4593 | FILE *file = (FILE *) ptr; | |
4594 | flagword flags; | |
4595 | ||
4596 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
4597 | ||
4598 | /* Print normal ELF private data. */ | |
4599 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
4600 | ||
4601 | flags = elf_elfheader (abfd)->e_flags; | |
4602 | fprintf (file, _("private flags = 0x%lx:"), (long)flags); | |
4603 | ||
4604 | switch (flags & EF_FRV_CPU_MASK) | |
4605 | { | |
4606 | default: break; | |
4607 | case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break; | |
9c8ee639 | 4608 | case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break; |
4e5ba5b7 | 4609 | case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break; |
676a64f4 RS |
4610 | case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break; |
4611 | case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
4612 | case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break; |
4613 | case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break; | |
4614 | case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break; | |
4615 | } | |
4616 | ||
4617 | switch (flags & EF_FRV_GPR_MASK) | |
4618 | { | |
4619 | default: break; | |
4620 | case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break; | |
4621 | case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break; | |
4622 | } | |
4623 | ||
4624 | switch (flags & EF_FRV_FPR_MASK) | |
4625 | { | |
4626 | default: break; | |
4627 | case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break; | |
4628 | case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break; | |
4629 | case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break; | |
4630 | } | |
4631 | ||
4632 | switch (flags & EF_FRV_DWORD_MASK) | |
4633 | { | |
4634 | default: break; | |
4635 | case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break; | |
4636 | case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break; | |
4637 | } | |
4638 | ||
4639 | if (flags & EF_FRV_DOUBLE) | |
4640 | fprintf (file, " -mdouble"); | |
4641 | ||
4642 | if (flags & EF_FRV_MEDIA) | |
4643 | fprintf (file, " -mmedia"); | |
4644 | ||
4645 | if (flags & EF_FRV_MULADD) | |
4646 | fprintf (file, " -mmuladd"); | |
4647 | ||
4648 | if (flags & EF_FRV_PIC) | |
4649 | fprintf (file, " -fpic"); | |
4650 | ||
4651 | if (flags & EF_FRV_BIGPIC) | |
4652 | fprintf (file, " -fPIC"); | |
4653 | ||
51532845 AO |
4654 | if (flags & EF_FRV_LIBPIC) |
4655 | fprintf (file, " -mlibrary-pic"); | |
4656 | ||
4657 | if (flags & EF_FRV_FDPIC) | |
4658 | fprintf (file, " -mfdpic"); | |
4659 | ||
4e5ba5b7 DB |
4660 | if (flags & EF_FRV_NON_PIC_RELOCS) |
4661 | fprintf (file, " non-pic relocations"); | |
4662 | ||
4663 | if (flags & EF_FRV_G0) | |
4664 | fprintf (file, " -G0"); | |
4665 | ||
4666 | fputc ('\n', file); | |
b34976b6 | 4667 | return TRUE; |
4e5ba5b7 DB |
4668 | } |
4669 | ||
4670 | \f | |
4671 | #define ELF_ARCH bfd_arch_frv | |
4672 | #define ELF_MACHINE_CODE EM_CYGNUS_FRV | |
4673 | #define ELF_MAXPAGESIZE 0x1000 | |
4674 | ||
4675 | #define TARGET_BIG_SYM bfd_elf32_frv_vec | |
4676 | #define TARGET_BIG_NAME "elf32-frv" | |
4677 | ||
4e5ba5b7 DB |
4678 | #define elf_info_to_howto frv_info_to_howto_rela |
4679 | #define elf_backend_relocate_section elf32_frv_relocate_section | |
4680 | #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook | |
4681 | #define elf_backend_gc_sweep_hook elf32_frv_gc_sweep_hook | |
4682 | #define elf_backend_check_relocs elf32_frv_check_relocs | |
4683 | #define elf_backend_object_p elf32_frv_object_p | |
4684 | #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook | |
4685 | ||
4686 | #define elf_backend_can_gc_sections 1 | |
de2d743e | 4687 | #define elf_backend_rela_normal 1 |
4e5ba5b7 DB |
4688 | |
4689 | #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup | |
4690 | #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags | |
4691 | #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data | |
4692 | #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data | |
4693 | #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data | |
4694 | ||
43850d5b AO |
4695 | #define elf_backend_want_got_sym 1 |
4696 | #define elf_backend_got_header_size 0 | |
4697 | #define elf_backend_want_got_plt 0 | |
4698 | #define elf_backend_plt_readonly 1 | |
4699 | #define elf_backend_want_plt_sym 0 | |
4700 | #define elf_backend_plt_header_size 0 | |
4701 | ||
4702 | #define elf_backend_finish_dynamic_sections \ | |
4703 | elf32_frv_finish_dynamic_sections | |
4704 | ||
4705 | #include "elf32-target.h" | |
4706 | ||
4707 | #undef ELF_MAXPAGESIZE | |
4708 | #define ELF_MAXPAGESIZE 0x4000 | |
4709 | ||
4710 | #undef TARGET_BIG_SYM | |
4711 | #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec | |
4712 | #undef TARGET_BIG_NAME | |
4713 | #define TARGET_BIG_NAME "elf32-frvfdpic" | |
4714 | #undef elf32_bed | |
4715 | #define elf32_bed elf32_frvfdpic_bed | |
4716 | ||
4717 | #undef elf_info_to_howto_rel | |
4718 | #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel | |
4719 | ||
4720 | #undef bfd_elf32_bfd_link_hash_table_create | |
4721 | #define bfd_elf32_bfd_link_hash_table_create \ | |
4722 | frvfdpic_elf_link_hash_table_create | |
4723 | #undef elf_backend_always_size_sections | |
51532845 | 4724 | #define elf_backend_always_size_sections \ |
43850d5b AO |
4725 | elf32_frvfdpic_always_size_sections |
4726 | #undef elf_backend_modify_segment_map | |
51532845 | 4727 | #define elf_backend_modify_segment_map \ |
43850d5b | 4728 | elf32_frvfdpic_modify_segment_map |
51532845 | 4729 | |
43850d5b | 4730 | #undef elf_backend_create_dynamic_sections |
51532845 | 4731 | #define elf_backend_create_dynamic_sections \ |
43850d5b AO |
4732 | elf32_frvfdpic_create_dynamic_sections |
4733 | #undef elf_backend_adjust_dynamic_symbol | |
51532845 | 4734 | #define elf_backend_adjust_dynamic_symbol \ |
43850d5b AO |
4735 | elf32_frvfdpic_adjust_dynamic_symbol |
4736 | #undef elf_backend_size_dynamic_sections | |
51532845 | 4737 | #define elf_backend_size_dynamic_sections \ |
43850d5b AO |
4738 | elf32_frvfdpic_size_dynamic_sections |
4739 | #undef elf_backend_finish_dynamic_symbol | |
51532845 | 4740 | #define elf_backend_finish_dynamic_symbol \ |
43850d5b AO |
4741 | elf32_frvfdpic_finish_dynamic_symbol |
4742 | #undef elf_backend_finish_dynamic_sections | |
51532845 | 4743 | #define elf_backend_finish_dynamic_sections \ |
43850d5b | 4744 | elf32_frvfdpic_finish_dynamic_sections |
51532845 | 4745 | |
43850d5b | 4746 | #undef elf_backend_can_make_relative_eh_frame |
ec3391e7 | 4747 | #define elf_backend_can_make_relative_eh_frame \ |
43850d5b AO |
4748 | frvfdpic_elf_use_relative_eh_frame |
4749 | #undef elf_backend_can_make_lsda_relative_eh_frame | |
ec3391e7 | 4750 | #define elf_backend_can_make_lsda_relative_eh_frame \ |
43850d5b AO |
4751 | frvfdpic_elf_use_relative_eh_frame |
4752 | #undef elf_backend_encode_eh_address | |
4753 | #define elf_backend_encode_eh_address \ | |
4754 | frvfdpic_elf_encode_eh_address | |
ec3391e7 | 4755 | |
43850d5b | 4756 | #undef elf_backend_may_use_rel_p |
51532845 | 4757 | #define elf_backend_may_use_rel_p 1 |
43850d5b | 4758 | #undef elf_backend_may_use_rela_p |
51532845 AO |
4759 | #define elf_backend_may_use_rela_p 1 |
4760 | /* We use REL for dynamic relocations only. */ | |
43850d5b | 4761 | #undef elf_backend_default_use_rela_p |
51532845 AO |
4762 | #define elf_backend_default_use_rela_p 1 |
4763 | ||
4e5ba5b7 | 4764 | #include "elf32-target.h" |