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