Commit | Line | Data |
---|---|---|
4e5ba5b7 | 1 | /* FRV-specific support for 32-bit ELF. |
ab96bf03 AM |
2 | Copyright 2002, 2003, 2004, 2005, 2006, 2007 |
3 | Free Software Foundation, Inc. | |
4e5ba5b7 | 4 | |
cd123cb7 | 5 | This file is part of BFD, the Binary File Descriptor library. |
4e5ba5b7 | 6 | |
cd123cb7 NC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
4e5ba5b7 | 11 | |
cd123cb7 NC |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
4e5ba5b7 | 16 | |
cd123cb7 NC |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
20 | MA 02110-1301, USA. */ | |
4e5ba5b7 | 21 | |
4e5ba5b7 | 22 | #include "sysdep.h" |
3db64b00 | 23 | #include "bfd.h" |
4e5ba5b7 DB |
24 | #include "libbfd.h" |
25 | #include "elf-bfd.h" | |
26 | #include "elf/frv.h" | |
ec3391e7 | 27 | #include "elf/dwarf2.h" |
51532845 | 28 | #include "hashtab.h" |
4e5ba5b7 DB |
29 | |
30 | /* Forward declarations. */ | |
31 | static bfd_reloc_status_type elf32_frv_relocate_lo16 | |
32 | PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
33 | static bfd_reloc_status_type elf32_frv_relocate_hi16 | |
34 | PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
35 | static bfd_reloc_status_type elf32_frv_relocate_label24 | |
36 | PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
37 | static bfd_reloc_status_type elf32_frv_relocate_gprel12 | |
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_gprelu12 |
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_gprello |
b34976b6 AM |
44 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
45 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 | 46 | static bfd_reloc_status_type elf32_frv_relocate_gprelhi |
b34976b6 AM |
47 | PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *, |
48 | bfd_byte *, bfd_vma)); | |
4e5ba5b7 DB |
49 | static reloc_howto_type *frv_reloc_type_lookup |
50 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
b34976b6 | 51 | static void frv_info_to_howto_rela |
947216bf | 52 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
b34976b6 AM |
53 | static bfd_boolean elf32_frv_relocate_section |
54 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
55 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
56 | static bfd_boolean elf32_frv_add_symbol_hook | |
555cd476 | 57 | PARAMS (( bfd *, struct bfd_link_info *, Elf_Internal_Sym *, |
b34976b6 | 58 | const char **, flagword *, asection **, bfd_vma *)); |
4e5ba5b7 | 59 | static bfd_reloc_status_type frv_final_link_relocate |
b34976b6 AM |
60 | PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, |
61 | Elf_Internal_Rela *, bfd_vma)); | |
b34976b6 AM |
62 | static bfd_boolean elf32_frv_check_relocs |
63 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
64 | const Elf_Internal_Rela *)); | |
65 | static int elf32_frv_machine | |
66 | PARAMS ((bfd *)); | |
67 | static bfd_boolean elf32_frv_object_p | |
68 | PARAMS ((bfd *)); | |
69 | static bfd_boolean frv_elf_set_private_flags | |
70 | PARAMS ((bfd *, flagword)); | |
71 | static bfd_boolean frv_elf_copy_private_bfd_data | |
72 | PARAMS ((bfd *, bfd *)); | |
73 | static bfd_boolean frv_elf_merge_private_bfd_data | |
74 | PARAMS ((bfd *, bfd *)); | |
75 | static bfd_boolean frv_elf_print_private_bfd_data | |
76 | PARAMS ((bfd *, PTR)); | |
888b45b8 KB |
77 | static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd, |
78 | Elf_Internal_Note * note); | |
79 | static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd, | |
80 | Elf_Internal_Note * note); | |
4e5ba5b7 DB |
81 | |
82 | static reloc_howto_type elf32_frv_howto_table [] = | |
83 | { | |
84 | /* This reloc does nothing. */ | |
85 | HOWTO (R_FRV_NONE, /* type */ | |
86 | 0, /* rightshift */ | |
87 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
88 | 32, /* bitsize */ | |
b34976b6 | 89 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
90 | 0, /* bitpos */ |
91 | complain_overflow_bitfield, /* complain_on_overflow */ | |
92 | bfd_elf_generic_reloc, /* special_function */ | |
93 | "R_FRV_NONE", /* name */ | |
b34976b6 | 94 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
95 | 0, /* src_mask */ |
96 | 0, /* dst_mask */ | |
b34976b6 | 97 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
98 | |
99 | /* A 32 bit absolute relocation. */ | |
100 | HOWTO (R_FRV_32, /* type */ | |
101 | 0, /* rightshift */ | |
102 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
103 | 32, /* bitsize */ | |
b34976b6 | 104 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
105 | 0, /* bitpos */ |
106 | complain_overflow_bitfield, /* complain_on_overflow */ | |
107 | bfd_elf_generic_reloc, /* special_function */ | |
108 | "R_FRV_32", /* name */ | |
b34976b6 | 109 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
110 | 0xffffffff, /* src_mask */ |
111 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 112 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
113 | |
114 | /* A 16 bit pc-relative relocation. */ | |
3b36f7e6 | 115 | HOWTO (R_FRV_LABEL16, /* type */ |
b15b52ef | 116 | 2, /* rightshift */ |
4e5ba5b7 DB |
117 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
118 | 16, /* bitsize */ | |
b34976b6 | 119 | TRUE, /* pc_relative */ |
4e5ba5b7 | 120 | 0, /* bitpos */ |
e6deed0a | 121 | complain_overflow_signed, /* complain_on_overflow */ |
4e5ba5b7 DB |
122 | bfd_elf_generic_reloc, /* special_function */ |
123 | "R_FRV_LABEL16", /* name */ | |
b34976b6 | 124 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
125 | 0xffff, /* src_mask */ |
126 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 127 | TRUE), /* pcrel_offset */ |
4e5ba5b7 DB |
128 | |
129 | /* A 24-bit pc-relative relocation. */ | |
3b36f7e6 | 130 | HOWTO (R_FRV_LABEL24, /* type */ |
4e5ba5b7 DB |
131 | 2, /* rightshift */ |
132 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
133 | 26, /* bitsize */ | |
b34976b6 | 134 | TRUE, /* pc_relative */ |
4e5ba5b7 DB |
135 | 0, /* bitpos */ |
136 | complain_overflow_bitfield, /* complain_on_overflow */ | |
137 | bfd_elf_generic_reloc, /* special_function */ | |
138 | "R_FRV_LABEL24", /* name */ | |
b34976b6 | 139 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
140 | 0x7e03ffff, /* src_mask */ |
141 | 0x7e03ffff, /* dst_mask */ | |
3b36f7e6 | 142 | TRUE), /* pcrel_offset */ |
4e5ba5b7 | 143 | |
3b36f7e6 | 144 | HOWTO (R_FRV_LO16, /* type */ |
4e5ba5b7 DB |
145 | 0, /* rightshift */ |
146 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
147 | 16, /* bitsize */ | |
b34976b6 | 148 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
149 | 0, /* bitpos */ |
150 | complain_overflow_dont, /* complain_on_overflow */ | |
151 | bfd_elf_generic_reloc, /* special_function */ | |
152 | "R_FRV_LO16", /* name */ | |
b34976b6 | 153 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
154 | 0xffff, /* src_mask */ |
155 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 156 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 157 | |
3b36f7e6 | 158 | HOWTO (R_FRV_HI16, /* type */ |
4e5ba5b7 DB |
159 | 0, /* rightshift */ |
160 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
161 | 16, /* bitsize */ | |
b34976b6 | 162 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
163 | 0, /* bitpos */ |
164 | complain_overflow_dont, /* complain_on_overflow */ | |
165 | bfd_elf_generic_reloc, /* special_function */ | |
166 | "R_FRV_HI16", /* name */ | |
b34976b6 | 167 | FALSE, /* partial_inplace */ |
4e5ba5b7 DB |
168 | 0xffff, /* src_mask */ |
169 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 170 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 171 | |
3b36f7e6 | 172 | HOWTO (R_FRV_GPREL12, /* type */ |
4e5ba5b7 DB |
173 | 0, /* rightshift */ |
174 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
175 | 12, /* bitsize */ | |
b34976b6 | 176 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
177 | 0, /* bitpos */ |
178 | complain_overflow_dont, /* complain_on_overflow */ | |
179 | bfd_elf_generic_reloc, /* special_function */ | |
3b36f7e6 | 180 | "R_FRV_GPREL12", /* name */ |
b34976b6 | 181 | FALSE, /* partial_inplace */ |
3b36f7e6 AM |
182 | 0xfff, /* src_mask */ |
183 | 0xfff, /* dst_mask */ | |
184 | FALSE), /* pcrel_offset */ | |
4e5ba5b7 | 185 | |
3b36f7e6 | 186 | HOWTO (R_FRV_GPRELU12, /* type */ |
4e5ba5b7 DB |
187 | 0, /* rightshift */ |
188 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
189 | 12, /* bitsize */ | |
b34976b6 | 190 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
191 | 0, /* bitpos */ |
192 | complain_overflow_dont, /* complain_on_overflow */ | |
193 | bfd_elf_generic_reloc, /* special_function */ | |
3b36f7e6 | 194 | "R_FRV_GPRELU12", /* name */ |
b34976b6 | 195 | FALSE, /* partial_inplace */ |
3b36f7e6 AM |
196 | 0xfff, /* src_mask */ |
197 | 0x3f03f, /* dst_mask */ | |
198 | FALSE), /* pcrel_offset */ | |
4e5ba5b7 | 199 | |
3b36f7e6 | 200 | HOWTO (R_FRV_GPREL32, /* type */ |
4e5ba5b7 DB |
201 | 0, /* rightshift */ |
202 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
203 | 32, /* bitsize */ | |
b34976b6 | 204 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
205 | 0, /* bitpos */ |
206 | complain_overflow_dont, /* complain_on_overflow */ | |
207 | bfd_elf_generic_reloc, /* special_function */ | |
208 | "R_FRV_GPREL32", /* name */ | |
b34976b6 | 209 | FALSE, /* partial_inplace */ |
3b36f7e6 | 210 | 0xffffffff, /* src_mask */ |
4e5ba5b7 | 211 | 0xffffffff, /* dst_mask */ |
3b36f7e6 | 212 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 213 | |
3b36f7e6 | 214 | HOWTO (R_FRV_GPRELHI, /* type */ |
4e5ba5b7 DB |
215 | 0, /* rightshift */ |
216 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
217 | 16, /* bitsize */ | |
b34976b6 | 218 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
219 | 0, /* bitpos */ |
220 | complain_overflow_dont, /* complain_on_overflow */ | |
221 | bfd_elf_generic_reloc, /* special_function */ | |
222 | "R_FRV_GPRELHI", /* name */ | |
b34976b6 | 223 | FALSE, /* partial_inplace */ |
3b36f7e6 | 224 | 0xffff, /* src_mask */ |
4e5ba5b7 | 225 | 0xffff, /* dst_mask */ |
3b36f7e6 | 226 | FALSE), /* pcrel_offset */ |
4e5ba5b7 | 227 | |
3b36f7e6 | 228 | HOWTO (R_FRV_GPRELLO, /* type */ |
4e5ba5b7 DB |
229 | 0, /* rightshift */ |
230 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
231 | 16, /* bitsize */ | |
b34976b6 | 232 | FALSE, /* pc_relative */ |
4e5ba5b7 DB |
233 | 0, /* bitpos */ |
234 | complain_overflow_dont, /* complain_on_overflow */ | |
235 | bfd_elf_generic_reloc, /* special_function */ | |
236 | "R_FRV_GPRELLO", /* name */ | |
b34976b6 | 237 | FALSE, /* partial_inplace */ |
3b36f7e6 | 238 | 0xffff, /* src_mask */ |
4e5ba5b7 | 239 | 0xffff, /* dst_mask */ |
3b36f7e6 | 240 | FALSE), /* pcrel_offset */ |
51532845 AO |
241 | |
242 | /* A 12-bit signed operand with the GOT offset for the address of | |
243 | the symbol. */ | |
3b36f7e6 | 244 | HOWTO (R_FRV_GOT12, /* type */ |
51532845 AO |
245 | 0, /* rightshift */ |
246 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
247 | 12, /* bitsize */ | |
248 | FALSE, /* pc_relative */ | |
249 | 0, /* bitpos */ | |
250 | complain_overflow_signed, /* complain_on_overflow */ | |
251 | bfd_elf_generic_reloc, /* special_function */ | |
252 | "R_FRV_GOT12", /* name */ | |
253 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
254 | 0xfff, /* src_mask */ |
255 | 0xfff, /* dst_mask */ | |
256 | FALSE), /* pcrel_offset */ | |
51532845 AO |
257 | |
258 | /* The upper 16 bits of the GOT offset for the address of the | |
259 | symbol. */ | |
3b36f7e6 | 260 | HOWTO (R_FRV_GOTHI, /* type */ |
51532845 AO |
261 | 0, /* rightshift */ |
262 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
263 | 16, /* bitsize */ | |
264 | FALSE, /* pc_relative */ | |
265 | 0, /* bitpos */ | |
266 | complain_overflow_dont, /* complain_on_overflow */ | |
267 | bfd_elf_generic_reloc, /* special_function */ | |
268 | "R_FRV_GOTHI", /* name */ | |
269 | FALSE, /* partial_inplace */ | |
3b36f7e6 | 270 | 0xffff, /* src_mask */ |
51532845 | 271 | 0xffff, /* dst_mask */ |
3b36f7e6 | 272 | FALSE), /* pcrel_offset */ |
51532845 AO |
273 | |
274 | /* The lower 16 bits of the GOT offset for the address of the | |
275 | symbol. */ | |
3b36f7e6 | 276 | HOWTO (R_FRV_GOTLO, /* type */ |
51532845 AO |
277 | 0, /* rightshift */ |
278 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
279 | 16, /* bitsize */ | |
280 | FALSE, /* pc_relative */ | |
281 | 0, /* bitpos */ | |
282 | complain_overflow_dont, /* complain_on_overflow */ | |
283 | bfd_elf_generic_reloc, /* special_function */ | |
284 | "R_FRV_GOTLO", /* name */ | |
285 | FALSE, /* partial_inplace */ | |
286 | 0xffff, /* src_mask */ | |
287 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 288 | FALSE), /* pcrel_offset */ |
51532845 AO |
289 | |
290 | /* The 32-bit address of the canonical descriptor of a function. */ | |
291 | HOWTO (R_FRV_FUNCDESC, /* type */ | |
292 | 0, /* rightshift */ | |
293 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
294 | 32, /* bitsize */ | |
295 | FALSE, /* pc_relative */ | |
296 | 0, /* bitpos */ | |
297 | complain_overflow_bitfield, /* complain_on_overflow */ | |
298 | bfd_elf_generic_reloc, /* special_function */ | |
299 | "R_FRV_FUNCDESC", /* name */ | |
300 | FALSE, /* partial_inplace */ | |
301 | 0xffffffff, /* src_mask */ | |
302 | 0xffffffff, /* dst_mask */ | |
303 | FALSE), /* pcrel_offset */ | |
304 | ||
305 | /* A 12-bit signed operand with the GOT offset for the address of | |
306 | canonical descriptor of a function. */ | |
307 | HOWTO (R_FRV_FUNCDESC_GOT12, /* type */ | |
308 | 0, /* rightshift */ | |
309 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
310 | 12, /* bitsize */ | |
311 | FALSE, /* pc_relative */ | |
312 | 0, /* bitpos */ | |
313 | complain_overflow_signed, /* complain_on_overflow */ | |
314 | bfd_elf_generic_reloc, /* special_function */ | |
315 | "R_FRV_FUNCDESC_GOT12", /* name */ | |
316 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
317 | 0xfff, /* src_mask */ |
318 | 0xfff, /* dst_mask */ | |
319 | FALSE), /* pcrel_offset */ | |
51532845 AO |
320 | |
321 | /* The upper 16 bits of the GOT offset for the address of the | |
322 | canonical descriptor of a function. */ | |
323 | HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */ | |
324 | 0, /* rightshift */ | |
325 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
326 | 16, /* bitsize */ | |
327 | FALSE, /* pc_relative */ | |
328 | 0, /* bitpos */ | |
329 | complain_overflow_dont, /* complain_on_overflow */ | |
330 | bfd_elf_generic_reloc, /* special_function */ | |
331 | "R_FRV_FUNCDESC_GOTHI", /* name */ | |
332 | FALSE, /* partial_inplace */ | |
333 | 0xffff, /* src_mask */ | |
334 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 335 | FALSE), /* pcrel_offset */ |
51532845 AO |
336 | |
337 | /* The lower 16 bits of the GOT offset for the address of the | |
338 | canonical descriptor of a function. */ | |
339 | HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */ | |
340 | 0, /* rightshift */ | |
341 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
342 | 16, /* bitsize */ | |
343 | FALSE, /* pc_relative */ | |
344 | 0, /* bitpos */ | |
345 | complain_overflow_dont, /* complain_on_overflow */ | |
346 | bfd_elf_generic_reloc, /* special_function */ | |
347 | "R_FRV_FUNCDESC_GOTLO", /* name */ | |
348 | FALSE, /* partial_inplace */ | |
349 | 0xffff, /* src_mask */ | |
350 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 351 | FALSE), /* pcrel_offset */ |
51532845 | 352 | |
90219bd0 | 353 | /* The 64-bit descriptor of a function. */ |
51532845 AO |
354 | HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ |
355 | 0, /* rightshift */ | |
356 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
357 | 64, /* bitsize */ | |
358 | FALSE, /* pc_relative */ | |
359 | 0, /* bitpos */ | |
360 | complain_overflow_bitfield, /* complain_on_overflow */ | |
361 | bfd_elf_generic_reloc, /* special_function */ | |
362 | "R_FRV_FUNCDESC_VALUE", /* name */ | |
363 | FALSE, /* partial_inplace */ | |
364 | 0xffffffff, /* src_mask */ | |
365 | 0xffffffff, /* dst_mask */ | |
366 | FALSE), /* pcrel_offset */ | |
367 | ||
368 | /* A 12-bit signed operand with the GOT offset for the address of | |
369 | canonical descriptor of a function. */ | |
370 | HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */ | |
371 | 0, /* rightshift */ | |
372 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
373 | 12, /* bitsize */ | |
374 | FALSE, /* pc_relative */ | |
375 | 0, /* bitpos */ | |
376 | complain_overflow_signed, /* complain_on_overflow */ | |
377 | bfd_elf_generic_reloc, /* special_function */ | |
378 | "R_FRV_FUNCDESC_GOTOFF12", /* name */ | |
379 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
380 | 0xfff, /* src_mask */ |
381 | 0xfff, /* dst_mask */ | |
382 | FALSE), /* pcrel_offset */ | |
51532845 AO |
383 | |
384 | /* The upper 16 bits of the GOT offset for the address of the | |
385 | canonical descriptor of a function. */ | |
386 | HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */ | |
387 | 0, /* rightshift */ | |
388 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
389 | 16, /* bitsize */ | |
390 | FALSE, /* pc_relative */ | |
391 | 0, /* bitpos */ | |
392 | complain_overflow_dont, /* complain_on_overflow */ | |
393 | bfd_elf_generic_reloc, /* special_function */ | |
394 | "R_FRV_FUNCDESC_GOTOFFHI", /* name */ | |
395 | FALSE, /* partial_inplace */ | |
396 | 0xffff, /* src_mask */ | |
397 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 398 | FALSE), /* pcrel_offset */ |
51532845 AO |
399 | |
400 | /* The lower 16 bits of the GOT offset for the address of the | |
401 | canonical descriptor of a function. */ | |
402 | HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */ | |
403 | 0, /* rightshift */ | |
404 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
405 | 16, /* bitsize */ | |
406 | FALSE, /* pc_relative */ | |
407 | 0, /* bitpos */ | |
408 | complain_overflow_dont, /* complain_on_overflow */ | |
409 | bfd_elf_generic_reloc, /* special_function */ | |
410 | "R_FRV_FUNCDESC_GOTOFFLO", /* name */ | |
411 | FALSE, /* partial_inplace */ | |
412 | 0xffff, /* src_mask */ | |
413 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 414 | FALSE), /* pcrel_offset */ |
51532845 AO |
415 | |
416 | /* A 12-bit signed operand with the GOT offset for the address of | |
417 | the symbol. */ | |
3b36f7e6 | 418 | HOWTO (R_FRV_GOTOFF12, /* type */ |
51532845 AO |
419 | 0, /* rightshift */ |
420 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
421 | 12, /* bitsize */ | |
422 | FALSE, /* pc_relative */ | |
423 | 0, /* bitpos */ | |
424 | complain_overflow_signed, /* complain_on_overflow */ | |
425 | bfd_elf_generic_reloc, /* special_function */ | |
426 | "R_FRV_GOTOFF12", /* name */ | |
427 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
428 | 0xfff, /* src_mask */ |
429 | 0xfff, /* dst_mask */ | |
430 | FALSE), /* pcrel_offset */ | |
51532845 AO |
431 | |
432 | /* The upper 16 bits of the GOT offset for the address of the | |
433 | symbol. */ | |
3b36f7e6 | 434 | HOWTO (R_FRV_GOTOFFHI, /* type */ |
51532845 AO |
435 | 0, /* rightshift */ |
436 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
437 | 16, /* bitsize */ | |
438 | FALSE, /* pc_relative */ | |
439 | 0, /* bitpos */ | |
440 | complain_overflow_dont, /* complain_on_overflow */ | |
441 | bfd_elf_generic_reloc, /* special_function */ | |
442 | "R_FRV_GOTOFFHI", /* name */ | |
443 | FALSE, /* partial_inplace */ | |
444 | 0xffff, /* src_mask */ | |
445 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 446 | FALSE), /* pcrel_offset */ |
51532845 AO |
447 | |
448 | /* The lower 16 bits of the GOT offset for the address of the | |
449 | symbol. */ | |
450 | HOWTO (R_FRV_GOTOFFLO, /* type */ | |
451 | 0, /* rightshift */ | |
452 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
453 | 16, /* bitsize */ | |
454 | FALSE, /* pc_relative */ | |
455 | 0, /* bitpos */ | |
456 | complain_overflow_dont, /* complain_on_overflow */ | |
457 | bfd_elf_generic_reloc, /* special_function */ | |
458 | "R_FRV_GOTOFFLO", /* name */ | |
459 | FALSE, /* partial_inplace */ | |
460 | 0xffff, /* src_mask */ | |
461 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 462 | FALSE), /* pcrel_offset */ |
51532845 | 463 | |
90219bd0 AO |
464 | /* A 24-bit pc-relative relocation referencing the TLS PLT entry for |
465 | a thread-local symbol. If the symbol number is 0, it refers to | |
466 | the module. */ | |
467 | HOWTO (R_FRV_GETTLSOFF, /* type */ | |
468 | 2, /* rightshift */ | |
469 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
470 | 26, /* bitsize */ | |
471 | TRUE, /* pc_relative */ | |
472 | 0, /* bitpos */ | |
473 | complain_overflow_bitfield, /* complain_on_overflow */ | |
474 | bfd_elf_generic_reloc, /* special_function */ | |
475 | "R_FRV_GETTLSOFF", /* name */ | |
476 | FALSE, /* partial_inplace */ | |
477 | 0x7e03ffff, /* src_mask */ | |
478 | 0x7e03ffff, /* dst_mask */ | |
3b36f7e6 | 479 | TRUE), /* pcrel_offset */ |
90219bd0 AO |
480 | |
481 | /* A 64-bit TLS descriptor for a symbol. This relocation is only | |
482 | valid as a REL, dynamic relocation. */ | |
483 | HOWTO (R_FRV_TLSDESC_VALUE, /* type */ | |
484 | 0, /* rightshift */ | |
485 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
486 | 64, /* bitsize */ | |
487 | FALSE, /* pc_relative */ | |
488 | 0, /* bitpos */ | |
489 | complain_overflow_bitfield, /* complain_on_overflow */ | |
490 | bfd_elf_generic_reloc, /* special_function */ | |
491 | "R_FRV_TLSDESC_VALUE", /* name */ | |
492 | FALSE, /* partial_inplace */ | |
493 | 0xffffffff, /* src_mask */ | |
494 | 0xffffffff, /* dst_mask */ | |
495 | FALSE), /* pcrel_offset */ | |
496 | ||
497 | /* A 12-bit signed operand with the GOT offset for the TLS | |
498 | descriptor of the symbol. */ | |
3b36f7e6 | 499 | HOWTO (R_FRV_GOTTLSDESC12, /* type */ |
90219bd0 AO |
500 | 0, /* rightshift */ |
501 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
502 | 12, /* bitsize */ | |
503 | FALSE, /* pc_relative */ | |
504 | 0, /* bitpos */ | |
505 | complain_overflow_signed, /* complain_on_overflow */ | |
506 | bfd_elf_generic_reloc, /* special_function */ | |
507 | "R_FRV_GOTTLSDESC12", /* name */ | |
508 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
509 | 0xfff, /* src_mask */ |
510 | 0xfff, /* dst_mask */ | |
511 | FALSE), /* pcrel_offset */ | |
90219bd0 AO |
512 | |
513 | /* The upper 16 bits of the GOT offset for the TLS descriptor of the | |
514 | symbol. */ | |
3b36f7e6 | 515 | HOWTO (R_FRV_GOTTLSDESCHI, /* type */ |
90219bd0 AO |
516 | 0, /* rightshift */ |
517 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
518 | 16, /* bitsize */ | |
519 | FALSE, /* pc_relative */ | |
520 | 0, /* bitpos */ | |
521 | complain_overflow_dont, /* complain_on_overflow */ | |
522 | bfd_elf_generic_reloc, /* special_function */ | |
523 | "R_FRV_GOTTLSDESCHI", /* name */ | |
524 | FALSE, /* partial_inplace */ | |
525 | 0xffff, /* src_mask */ | |
526 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 527 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
528 | |
529 | /* The lower 16 bits of the GOT offset for the TLS descriptor of the | |
530 | symbol. */ | |
531 | HOWTO (R_FRV_GOTTLSDESCLO, /* type */ | |
532 | 0, /* rightshift */ | |
533 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
534 | 16, /* bitsize */ | |
535 | FALSE, /* pc_relative */ | |
536 | 0, /* bitpos */ | |
537 | complain_overflow_dont, /* complain_on_overflow */ | |
538 | bfd_elf_generic_reloc, /* special_function */ | |
539 | "R_FRV_GOTTLSDESCLO", /* name */ | |
540 | FALSE, /* partial_inplace */ | |
541 | 0xffff, /* src_mask */ | |
542 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 543 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
544 | |
545 | /* A 12-bit signed operand with the offset from the module base | |
546 | address to the thread-local symbol address. */ | |
3b36f7e6 | 547 | HOWTO (R_FRV_TLSMOFF12, /* type */ |
90219bd0 AO |
548 | 0, /* rightshift */ |
549 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
550 | 12, /* bitsize */ | |
551 | FALSE, /* pc_relative */ | |
552 | 0, /* bitpos */ | |
553 | complain_overflow_signed, /* complain_on_overflow */ | |
554 | bfd_elf_generic_reloc, /* special_function */ | |
555 | "R_FRV_TLSMOFF12", /* name */ | |
556 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
557 | 0xfff, /* src_mask */ |
558 | 0xfff, /* dst_mask */ | |
559 | FALSE), /* pcrel_offset */ | |
90219bd0 AO |
560 | |
561 | /* The upper 16 bits of the offset from the module base address to | |
562 | the thread-local symbol address. */ | |
3b36f7e6 | 563 | HOWTO (R_FRV_TLSMOFFHI, /* type */ |
90219bd0 AO |
564 | 0, /* rightshift */ |
565 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
566 | 16, /* bitsize */ | |
567 | FALSE, /* pc_relative */ | |
568 | 0, /* bitpos */ | |
569 | complain_overflow_dont, /* complain_on_overflow */ | |
570 | bfd_elf_generic_reloc, /* special_function */ | |
571 | "R_FRV_TLSMOFFHI", /* name */ | |
572 | FALSE, /* partial_inplace */ | |
573 | 0xffff, /* src_mask */ | |
574 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 575 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
576 | |
577 | /* The lower 16 bits of the offset from the module base address to | |
578 | the thread-local symbol address. */ | |
579 | HOWTO (R_FRV_TLSMOFFLO, /* type */ | |
580 | 0, /* rightshift */ | |
581 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
582 | 16, /* bitsize */ | |
583 | FALSE, /* pc_relative */ | |
584 | 0, /* bitpos */ | |
585 | complain_overflow_dont, /* complain_on_overflow */ | |
586 | bfd_elf_generic_reloc, /* special_function */ | |
587 | "R_FRV_TLSMOFFLO", /* name */ | |
588 | FALSE, /* partial_inplace */ | |
589 | 0xffff, /* src_mask */ | |
590 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 591 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
592 | |
593 | /* A 12-bit signed operand with the GOT offset for the TLSOFF entry | |
594 | for a symbol. */ | |
3b36f7e6 | 595 | HOWTO (R_FRV_GOTTLSOFF12, /* type */ |
90219bd0 AO |
596 | 0, /* rightshift */ |
597 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
598 | 12, /* bitsize */ | |
599 | FALSE, /* pc_relative */ | |
600 | 0, /* bitpos */ | |
601 | complain_overflow_signed, /* complain_on_overflow */ | |
602 | bfd_elf_generic_reloc, /* special_function */ | |
603 | "R_FRV_GOTTLSOFF12", /* name */ | |
604 | FALSE, /* partial_inplace */ | |
3b36f7e6 AM |
605 | 0xfff, /* src_mask */ |
606 | 0xfff, /* dst_mask */ | |
607 | FALSE), /* pcrel_offset */ | |
90219bd0 AO |
608 | |
609 | /* The upper 16 bits of the GOT offset for the TLSOFF entry for a | |
610 | symbol. */ | |
3b36f7e6 | 611 | HOWTO (R_FRV_GOTTLSOFFHI, /* type */ |
90219bd0 AO |
612 | 0, /* rightshift */ |
613 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
614 | 16, /* bitsize */ | |
615 | FALSE, /* pc_relative */ | |
616 | 0, /* bitpos */ | |
617 | complain_overflow_dont, /* complain_on_overflow */ | |
618 | bfd_elf_generic_reloc, /* special_function */ | |
619 | "R_FRV_GOTTLSOFFHI", /* name */ | |
620 | FALSE, /* partial_inplace */ | |
621 | 0xffff, /* src_mask */ | |
622 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 623 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
624 | |
625 | /* The lower 16 bits of the GOT offset for the TLSOFF entry for a | |
626 | symbol. */ | |
627 | HOWTO (R_FRV_GOTTLSOFFLO, /* type */ | |
628 | 0, /* rightshift */ | |
629 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
630 | 16, /* bitsize */ | |
631 | FALSE, /* pc_relative */ | |
632 | 0, /* bitpos */ | |
633 | complain_overflow_dont, /* complain_on_overflow */ | |
634 | bfd_elf_generic_reloc, /* special_function */ | |
635 | "R_FRV_GOTTLSOFFLO", /* name */ | |
636 | FALSE, /* partial_inplace */ | |
637 | 0xffff, /* src_mask */ | |
638 | 0xffff, /* dst_mask */ | |
3b36f7e6 | 639 | FALSE), /* pcrel_offset */ |
90219bd0 AO |
640 | |
641 | /* The 32-bit offset from the thread pointer (not the module base | |
642 | address) to a thread-local symbol. */ | |
643 | HOWTO (R_FRV_TLSOFF, /* type */ | |
644 | 0, /* rightshift */ | |
645 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
646 | 32, /* bitsize */ | |
647 | FALSE, /* pc_relative */ | |
648 | 0, /* bitpos */ | |
649 | complain_overflow_dont, /* complain_on_overflow */ | |
650 | bfd_elf_generic_reloc, /* special_function */ | |
651 | "R_FRV_TLSOFF", /* name */ | |
652 | FALSE, /* partial_inplace */ | |
653 | 0xffffffff, /* src_mask */ | |
654 | 0xffffffff, /* dst_mask */ | |
655 | FALSE), /* pcrel_offset */ | |
656 | ||
657 | /* An annotation for linker relaxation, that denotes the | |
658 | symbol+addend whose TLS descriptor is referenced by the sum of | |
659 | the two input registers of an ldd instruction. */ | |
660 | HOWTO (R_FRV_TLSDESC_RELAX, /* type */ | |
661 | 0, /* rightshift */ | |
662 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
663 | 0, /* bitsize */ | |
664 | FALSE, /* pc_relative */ | |
665 | 0, /* bitpos */ | |
666 | complain_overflow_dont, /* complain_on_overflow */ | |
667 | bfd_elf_generic_reloc, /* special_function */ | |
668 | "R_FRV_TLSDESC_RELAX", /* name */ | |
669 | FALSE, /* partial_inplace */ | |
670 | 0, /* src_mask */ | |
671 | 0, /* dst_mask */ | |
672 | FALSE), /* pcrel_offset */ | |
673 | ||
674 | /* An annotation for linker relaxation, that denotes the | |
675 | symbol+addend whose TLS resolver entry point is given by the sum | |
676 | of the two register operands of an calll instruction. */ | |
677 | HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */ | |
678 | 0, /* rightshift */ | |
679 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
680 | 0, /* bitsize */ | |
681 | FALSE, /* pc_relative */ | |
682 | 0, /* bitpos */ | |
683 | complain_overflow_dont, /* complain_on_overflow */ | |
684 | bfd_elf_generic_reloc, /* special_function */ | |
685 | "R_FRV_GETTLSOFF_RELAX", /* name */ | |
686 | FALSE, /* partial_inplace */ | |
687 | 0, /* src_mask */ | |
688 | 0, /* dst_mask */ | |
689 | FALSE), /* pcrel_offset */ | |
690 | ||
691 | /* An annotation for linker relaxation, that denotes the | |
692 | symbol+addend whose TLS offset GOT entry is given by the sum of | |
693 | the two input registers of an ld instruction. */ | |
694 | HOWTO (R_FRV_TLSOFF_RELAX, /* type */ | |
695 | 0, /* rightshift */ | |
696 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
697 | 0, /* bitsize */ | |
698 | FALSE, /* pc_relative */ | |
699 | 0, /* bitpos */ | |
700 | complain_overflow_bitfield, /* complain_on_overflow */ | |
701 | bfd_elf_generic_reloc, /* special_function */ | |
702 | "R_FRV_TLSOFF_RELAX", /* name */ | |
703 | FALSE, /* partial_inplace */ | |
704 | 0, /* src_mask */ | |
705 | 0, /* dst_mask */ | |
706 | FALSE), /* pcrel_offset */ | |
707 | ||
708 | /* A 32-bit offset from the module base address to | |
709 | the thread-local symbol address. */ | |
3b36f7e6 | 710 | HOWTO (R_FRV_TLSMOFF, /* type */ |
90219bd0 AO |
711 | 0, /* rightshift */ |
712 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
713 | 32, /* bitsize */ | |
714 | FALSE, /* pc_relative */ | |
715 | 0, /* bitpos */ | |
716 | complain_overflow_dont, /* complain_on_overflow */ | |
717 | bfd_elf_generic_reloc, /* special_function */ | |
718 | "R_FRV_TLSMOFF", /* name */ | |
719 | FALSE, /* partial_inplace */ | |
720 | 0xffffffff, /* src_mask */ | |
721 | 0xffffffff, /* dst_mask */ | |
3b36f7e6 | 722 | FALSE), /* pcrel_offset */ |
4e5ba5b7 DB |
723 | }; |
724 | ||
725 | /* GNU extension to record C++ vtable hierarchy. */ | |
726 | static reloc_howto_type elf32_frv_vtinherit_howto = | |
3b36f7e6 AM |
727 | HOWTO (R_FRV_GNU_VTINHERIT, /* type */ |
728 | 0, /* rightshift */ | |
729 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
730 | 0, /* bitsize */ | |
731 | FALSE, /* pc_relative */ | |
732 | 0, /* bitpos */ | |
733 | complain_overflow_dont, /* complain_on_overflow */ | |
734 | NULL, /* special_function */ | |
735 | "R_FRV_GNU_VTINHERIT", /* name */ | |
736 | FALSE, /* partial_inplace */ | |
737 | 0, /* src_mask */ | |
738 | 0, /* dst_mask */ | |
739 | FALSE); /* pcrel_offset */ | |
4e5ba5b7 DB |
740 | |
741 | /* GNU extension to record C++ vtable member usage. */ | |
742 | static reloc_howto_type elf32_frv_vtentry_howto = | |
3b36f7e6 AM |
743 | HOWTO (R_FRV_GNU_VTENTRY, /* type */ |
744 | 0, /* rightshift */ | |
745 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
746 | 0, /* bitsize */ | |
747 | FALSE, /* pc_relative */ | |
748 | 0, /* bitpos */ | |
749 | complain_overflow_dont, /* complain_on_overflow */ | |
750 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
751 | "R_FRV_GNU_VTENTRY", /* name */ | |
752 | FALSE, /* partial_inplace */ | |
753 | 0, /* src_mask */ | |
754 | 0, /* dst_mask */ | |
755 | FALSE); /* pcrel_offset */ | |
51532845 AO |
756 | |
757 | /* The following 3 relocations are REL. The only difference to the | |
758 | entries in the table above are that partial_inplace is TRUE. */ | |
759 | static reloc_howto_type elf32_frv_rel_32_howto = | |
760 | HOWTO (R_FRV_32, /* type */ | |
761 | 0, /* rightshift */ | |
762 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
763 | 32, /* bitsize */ | |
764 | FALSE, /* pc_relative */ | |
765 | 0, /* bitpos */ | |
766 | complain_overflow_bitfield, /* complain_on_overflow */ | |
767 | bfd_elf_generic_reloc, /* special_function */ | |
768 | "R_FRV_32", /* name */ | |
769 | TRUE, /* partial_inplace */ | |
770 | 0xffffffff, /* src_mask */ | |
771 | 0xffffffff, /* dst_mask */ | |
772 | FALSE); /* pcrel_offset */ | |
773 | ||
774 | static reloc_howto_type elf32_frv_rel_funcdesc_howto = | |
775 | HOWTO (R_FRV_FUNCDESC, /* type */ | |
776 | 0, /* rightshift */ | |
777 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
778 | 32, /* bitsize */ | |
779 | FALSE, /* pc_relative */ | |
780 | 0, /* bitpos */ | |
781 | complain_overflow_bitfield, /* complain_on_overflow */ | |
782 | bfd_elf_generic_reloc, /* special_function */ | |
783 | "R_FRV_FUNCDESC", /* name */ | |
784 | TRUE, /* partial_inplace */ | |
785 | 0xffffffff, /* src_mask */ | |
786 | 0xffffffff, /* dst_mask */ | |
787 | FALSE); /* pcrel_offset */ | |
788 | ||
789 | static reloc_howto_type elf32_frv_rel_funcdesc_value_howto = | |
790 | HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ | |
791 | 0, /* rightshift */ | |
792 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
793 | 64, /* bitsize */ | |
794 | FALSE, /* pc_relative */ | |
795 | 0, /* bitpos */ | |
796 | complain_overflow_bitfield, /* complain_on_overflow */ | |
797 | bfd_elf_generic_reloc, /* special_function */ | |
798 | "R_FRV_FUNCDESC_VALUE", /* name */ | |
799 | TRUE, /* partial_inplace */ | |
800 | 0xffffffff, /* src_mask */ | |
801 | 0xffffffff, /* dst_mask */ | |
802 | FALSE); /* pcrel_offset */ | |
803 | ||
90219bd0 AO |
804 | static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto = |
805 | /* A 64-bit TLS descriptor for a symbol. The first word resolves to | |
806 | an entry point, and the second resolves to a special argument. | |
807 | If the symbol turns out to be in static TLS, the entry point is a | |
808 | return instruction, and the special argument is the TLS offset | |
809 | for the symbol. If it's in dynamic TLS, the entry point is a TLS | |
810 | offset resolver, and the special argument is a pointer to a data | |
811 | structure allocated by the dynamic loader, containing the GOT | |
812 | address for the offset resolver, the module id, the offset within | |
813 | the module, and anything else the TLS offset resolver might need | |
814 | to determine the TLS offset for the symbol in the running | |
815 | thread. */ | |
816 | HOWTO (R_FRV_TLSDESC_VALUE, /* type */ | |
817 | 0, /* rightshift */ | |
818 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
819 | 64, /* bitsize */ | |
820 | FALSE, /* pc_relative */ | |
821 | 0, /* bitpos */ | |
822 | complain_overflow_bitfield, /* complain_on_overflow */ | |
823 | bfd_elf_generic_reloc, /* special_function */ | |
824 | "R_FRV_TLSDESC_VALUE", /* name */ | |
825 | TRUE, /* partial_inplace */ | |
826 | 0xffffffff, /* src_mask */ | |
827 | 0xffffffff, /* dst_mask */ | |
828 | FALSE); /* pcrel_offset */ | |
829 | ||
830 | static reloc_howto_type elf32_frv_rel_tlsoff_howto = | |
831 | /* The 32-bit offset from the thread pointer (not the module base | |
832 | address) to a thread-local symbol. */ | |
833 | HOWTO (R_FRV_TLSOFF, /* type */ | |
834 | 0, /* rightshift */ | |
835 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
836 | 32, /* bitsize */ | |
837 | FALSE, /* pc_relative */ | |
838 | 0, /* bitpos */ | |
839 | complain_overflow_bitfield, /* complain_on_overflow */ | |
840 | bfd_elf_generic_reloc, /* special_function */ | |
841 | "R_FRV_TLSOFF", /* name */ | |
842 | TRUE, /* partial_inplace */ | |
843 | 0xffffffff, /* src_mask */ | |
844 | 0xffffffff, /* dst_mask */ | |
845 | FALSE); /* pcrel_offset */ | |
846 | ||
847 | ||
4e5ba5b7 | 848 | \f |
43850d5b AO |
849 | extern const bfd_target bfd_elf32_frvfdpic_vec; |
850 | #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec) | |
4e5ba5b7 | 851 | |
51532845 AO |
852 | /* An extension of the elf hash table data structure, containing some |
853 | additional FRV-specific data. */ | |
43850d5b | 854 | struct frvfdpic_elf_link_hash_table |
4e5ba5b7 | 855 | { |
51532845 AO |
856 | struct elf_link_hash_table elf; |
857 | ||
858 | /* A pointer to the .got section. */ | |
859 | asection *sgot; | |
860 | /* A pointer to the .rel.got section. */ | |
861 | asection *sgotrel; | |
862 | /* A pointer to the .rofixup section. */ | |
863 | asection *sgotfixup; | |
864 | /* A pointer to the .plt section. */ | |
865 | asection *splt; | |
866 | /* A pointer to the .rel.plt section. */ | |
867 | asection *spltrel; | |
868 | /* GOT base offset. */ | |
869 | bfd_vma got0; | |
870 | /* Location of the first non-lazy PLT entry, i.e., the number of | |
90219bd0 AO |
871 | bytes taken by lazy PLT entries. If locally-bound TLS |
872 | descriptors require a ret instruction, it will be placed at this | |
873 | offset. */ | |
51532845 AO |
874 | bfd_vma plt0; |
875 | /* A hash table holding information about which symbols were | |
876 | referenced with which PIC-related relocations. */ | |
877 | struct htab *relocs_info; | |
90219bd0 AO |
878 | /* Summary reloc information collected by |
879 | _frvfdpic_count_got_plt_entries. */ | |
880 | struct _frvfdpic_dynamic_got_info *g; | |
51532845 | 881 | }; |
4e5ba5b7 | 882 | |
51532845 AO |
883 | /* Get the FRV ELF linker hash table from a link_info structure. */ |
884 | ||
43850d5b AO |
885 | #define frvfdpic_hash_table(info) \ |
886 | ((struct frvfdpic_elf_link_hash_table *) ((info)->hash)) | |
887 | ||
888 | #define frvfdpic_got_section(info) \ | |
889 | (frvfdpic_hash_table (info)->sgot) | |
890 | #define frvfdpic_gotrel_section(info) \ | |
891 | (frvfdpic_hash_table (info)->sgotrel) | |
892 | #define frvfdpic_gotfixup_section(info) \ | |
893 | (frvfdpic_hash_table (info)->sgotfixup) | |
894 | #define frvfdpic_plt_section(info) \ | |
895 | (frvfdpic_hash_table (info)->splt) | |
896 | #define frvfdpic_pltrel_section(info) \ | |
897 | (frvfdpic_hash_table (info)->spltrel) | |
898 | #define frvfdpic_relocs_info(info) \ | |
899 | (frvfdpic_hash_table (info)->relocs_info) | |
900 | #define frvfdpic_got_initial_offset(info) \ | |
901 | (frvfdpic_hash_table (info)->got0) | |
902 | #define frvfdpic_plt_initial_offset(info) \ | |
903 | (frvfdpic_hash_table (info)->plt0) | |
90219bd0 AO |
904 | #define frvfdpic_dynamic_got_plt_info(info) \ |
905 | (frvfdpic_hash_table (info)->g) | |
906 | ||
907 | /* Currently it's the same, but if some day we have a reason to change | |
908 | it, we'd better be using a different macro. | |
909 | ||
910 | FIXME: if there's any TLS PLT entry that uses local-exec or | |
911 | initial-exec models, we could use the ret at the end of any of them | |
912 | instead of adding one more. */ | |
913 | #define frvfdpic_plt_tls_ret_offset(info) \ | |
914 | (frvfdpic_plt_initial_offset (info)) | |
915 | ||
916 | /* The name of the dynamic interpreter. This is put in the .interp | |
917 | section. */ | |
918 | ||
919 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" | |
920 | ||
921 | #define DEFAULT_STACK_SIZE 0x20000 | |
922 | ||
923 | /* This structure is used to collect the number of entries present in | |
924 | each addressable range of the got. */ | |
925 | struct _frvfdpic_dynamic_got_info | |
926 | { | |
927 | /* Several bits of information about the current link. */ | |
928 | struct bfd_link_info *info; | |
929 | /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit | |
930 | ranges. */ | |
931 | bfd_vma got12, gotlos, gothilo; | |
932 | /* Total GOT size needed for function descriptor entries within the 12-, | |
933 | 16- or 32-bit ranges. */ | |
934 | bfd_vma fd12, fdlos, fdhilo; | |
935 | /* Total GOT size needed by function descriptor entries referenced | |
936 | in PLT entries, that would be profitable to place in offsets | |
937 | close to the PIC register. */ | |
938 | bfd_vma fdplt; | |
939 | /* Total PLT size needed by lazy PLT entries. */ | |
940 | bfd_vma lzplt; | |
941 | /* Total GOT size needed for TLS descriptor entries within the 12-, | |
942 | 16- or 32-bit ranges. */ | |
943 | bfd_vma tlsd12, tlsdlos, tlsdhilo; | |
944 | /* Total GOT size needed by TLS descriptors referenced in PLT | |
945 | entries, that would be profitable to place in offers close to the | |
946 | PIC register. */ | |
947 | bfd_vma tlsdplt; | |
948 | /* Total PLT size needed by TLS lazy PLT entries. */ | |
949 | bfd_vma tlslzplt; | |
950 | /* Number of relocations carried over from input object files. */ | |
951 | unsigned long relocs; | |
952 | /* Number of fixups introduced by relocations in input object files. */ | |
953 | unsigned long fixups; | |
954 | /* The number of fixups that reference the ret instruction added to | |
955 | the PLT for locally-resolved TLS descriptors. */ | |
956 | unsigned long tls_ret_refs; | |
957 | }; | |
958 | ||
959 | /* This structure is used to assign offsets to got entries, function | |
960 | descriptors, plt entries and lazy plt entries. */ | |
961 | ||
962 | struct _frvfdpic_dynamic_got_plt_info | |
963 | { | |
964 | /* Summary information collected with _frvfdpic_count_got_plt_entries. */ | |
965 | struct _frvfdpic_dynamic_got_info g; | |
966 | ||
967 | /* For each addressable range, we record a MAX (positive) and MIN | |
968 | (negative) value. CUR is used to assign got entries, and it's | |
969 | incremented from an initial positive value to MAX, then from MIN | |
970 | to FDCUR (unless FDCUR wraps around first). FDCUR is used to | |
971 | assign function descriptors, and it's decreased from an initial | |
972 | non-positive value to MIN, then from MAX down to CUR (unless CUR | |
973 | wraps around first). All of MIN, MAX, CUR and FDCUR always point | |
974 | to even words. ODD, if non-zero, indicates an odd word to be | |
975 | used for the next got entry, otherwise CUR is used and | |
976 | incremented by a pair of words, wrapping around when it reaches | |
977 | MAX. FDCUR is decremented (and wrapped) before the next function | |
978 | descriptor is chosen. FDPLT indicates the number of remaining | |
979 | slots that can be used for function descriptors used only by PLT | |
980 | entries. | |
981 | ||
982 | TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR | |
983 | starts as MAX, and grows up to TMAX, then wraps around to TMIN | |
984 | and grows up to MIN. TLSDPLT indicates the number of remaining | |
985 | slots that can be used for TLS descriptors used only by TLS PLT | |
986 | entries. */ | |
987 | struct _frvfdpic_dynamic_got_alloc_data | |
988 | { | |
989 | bfd_signed_vma max, cur, odd, fdcur, min; | |
990 | bfd_signed_vma tmax, tcur, tmin; | |
991 | bfd_vma fdplt, tlsdplt; | |
992 | } got12, gotlos, gothilo; | |
993 | }; | |
51532845 AO |
994 | |
995 | /* Create an FRV ELF linker hash table. */ | |
996 | ||
997 | static struct bfd_link_hash_table * | |
43850d5b | 998 | frvfdpic_elf_link_hash_table_create (bfd *abfd) |
51532845 | 999 | { |
43850d5b AO |
1000 | struct frvfdpic_elf_link_hash_table *ret; |
1001 | bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table); | |
4e5ba5b7 | 1002 | |
51532845 AO |
1003 | ret = bfd_zalloc (abfd, amt); |
1004 | if (ret == NULL) | |
1005 | return NULL; | |
4e5ba5b7 | 1006 | |
66eb6687 AM |
1007 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, |
1008 | _bfd_elf_link_hash_newfunc, | |
1009 | sizeof (struct elf_link_hash_entry))) | |
51532845 AO |
1010 | { |
1011 | free (ret); | |
1012 | return NULL; | |
1013 | } | |
4e5ba5b7 | 1014 | |
51532845 AO |
1015 | return &ret->elf.root; |
1016 | } | |
4e5ba5b7 | 1017 | |
51532845 AO |
1018 | /* Decide whether a reference to a symbol can be resolved locally or |
1019 | not. If the symbol is protected, we want the local address, but | |
1020 | its function descriptor must be assigned by the dynamic linker. */ | |
43850d5b | 1021 | #define FRVFDPIC_SYM_LOCAL(INFO, H) \ |
51532845 | 1022 | (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \ |
303e4c21 | 1023 | || ! elf_hash_table (INFO)->dynamic_sections_created) |
43850d5b | 1024 | #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \ |
51532845 AO |
1025 | ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created) |
1026 | ||
1027 | /* This structure collects information on what kind of GOT, PLT or | |
1028 | function descriptors are required by relocations that reference a | |
1029 | certain symbol. */ | |
43850d5b | 1030 | struct frvfdpic_relocs_info |
51532845 AO |
1031 | { |
1032 | /* The index of the symbol, as stored in the relocation r_info, if | |
1033 | we have a local symbol; -1 otherwise. */ | |
1034 | long symndx; | |
1035 | union | |
1036 | { | |
1037 | /* The input bfd in which the symbol is defined, if it's a local | |
1038 | symbol. */ | |
1039 | bfd *abfd; | |
1040 | /* If symndx == -1, the hash table entry corresponding to a global | |
1041 | symbol (even if it turns out to bind locally, in which case it | |
1042 | should ideally be replaced with section's symndx + addend). */ | |
1043 | struct elf_link_hash_entry *h; | |
1044 | } d; | |
1045 | /* The addend of the relocation that references the symbol. */ | |
1046 | bfd_vma addend; | |
1047 | ||
1048 | /* The fields above are used to identify an entry. The fields below | |
1049 | contain information on how an entry is used and, later on, which | |
1050 | locations it was assigned. */ | |
1051 | /* The following 3 fields record whether the symbol+addend above was | |
1052 | ever referenced with a GOT relocation. The 12 suffix indicates a | |
1053 | GOT12 relocation; los is used for GOTLO relocations that are not | |
1054 | matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI | |
1055 | pairs. */ | |
1056 | unsigned got12:1; | |
1057 | unsigned gotlos:1; | |
1058 | unsigned gothilo:1; | |
1059 | /* Whether a FUNCDESC relocation references symbol+addend. */ | |
1060 | unsigned fd:1; | |
1061 | /* Whether a FUNCDESC_GOT relocation references symbol+addend. */ | |
1062 | unsigned fdgot12:1; | |
1063 | unsigned fdgotlos:1; | |
1064 | unsigned fdgothilo:1; | |
1065 | /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */ | |
1066 | unsigned fdgoff12:1; | |
1067 | unsigned fdgofflos:1; | |
1068 | unsigned fdgoffhilo:1; | |
90219bd0 AO |
1069 | /* Whether a GETTLSOFF relocation references symbol+addend. */ |
1070 | unsigned tlsplt:1; | |
1071 | /* FIXME: we should probably add tlspltdesc, tlspltoff and | |
1072 | tlspltimm, to tell what kind of TLS PLT entry we're generating. | |
1073 | We might instead just pre-compute flags telling whether the | |
1074 | object is suitable for local exec, initial exec or general | |
1075 | dynamic addressing, and use that all over the place. We could | |
1076 | also try to do a better job of merging TLSOFF and TLSDESC entries | |
1077 | in main executables, but perhaps we can get rid of TLSDESC | |
1078 | entirely in them instead. */ | |
1079 | /* Whether a GOTTLSDESC relocation references symbol+addend. */ | |
1080 | unsigned tlsdesc12:1; | |
1081 | unsigned tlsdesclos:1; | |
1082 | unsigned tlsdeschilo:1; | |
1083 | /* Whether a GOTTLSOFF relocation references symbol+addend. */ | |
1084 | unsigned tlsoff12:1; | |
1085 | unsigned tlsofflos:1; | |
1086 | unsigned tlsoffhilo:1; | |
51532845 AO |
1087 | /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or |
1088 | GOTOFFHI relocations. The addend doesn't really matter, since we | |
1089 | envision that this will only be used to check whether the symbol | |
1090 | is mapped to the same segment as the got. */ | |
1091 | unsigned gotoff:1; | |
1092 | /* Whether symbol+addend is referenced by a LABEL24 relocation. */ | |
1093 | unsigned call:1; | |
1094 | /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE | |
1095 | relocation. */ | |
1096 | unsigned sym:1; | |
1097 | /* Whether we need a PLT entry for a symbol. Should be implied by | |
1098 | something like: | |
43850d5b | 1099 | (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */ |
51532845 AO |
1100 | unsigned plt:1; |
1101 | /* Whether a function descriptor should be created in this link unit | |
1102 | for symbol+addend. Should be implied by something like: | |
1103 | (plt || fdgotoff12 || fdgotofflos || fdgotofflohi | |
1104 | || ((fd || fdgot12 || fdgotlos || fdgothilo) | |
43850d5b | 1105 | && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */ |
51532845 AO |
1106 | unsigned privfd:1; |
1107 | /* Whether a lazy PLT entry is needed for this symbol+addend. | |
1108 | Should be implied by something like: | |
43850d5b | 1109 | (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h) |
51532845 AO |
1110 | && ! (info->flags & DF_BIND_NOW)) */ |
1111 | unsigned lazyplt:1; | |
1112 | /* Whether we've already emitted GOT relocations and PLT entries as | |
1113 | needed for this symbol. */ | |
1114 | unsigned done:1; | |
1115 | ||
90219bd0 AO |
1116 | /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and |
1117 | R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing | |
1118 | symbol+addend. */ | |
1119 | unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff; | |
51532845 | 1120 | |
3b712a1a AO |
1121 | /* The number of .rofixups entries and dynamic relocations allocated |
1122 | for this symbol, minus any that might have already been used. */ | |
1123 | unsigned fixups, dynrelocs; | |
1124 | ||
51532845 AO |
1125 | /* The offsets of the GOT entries assigned to symbol+addend, to the |
1126 | function descriptor's address, and to a function descriptor, | |
1127 | respectively. Should be zero if unassigned. The offsets are | |
1128 | counted from the value that will be assigned to the PIC register, | |
1129 | not from the beginning of the .got section. */ | |
1130 | bfd_signed_vma got_entry, fdgot_entry, fd_entry; | |
1131 | /* The offsets of the PLT entries assigned to symbol+addend, | |
1132 | non-lazy and lazy, respectively. If unassigned, should be | |
1133 | (bfd_vma)-1. */ | |
1134 | bfd_vma plt_entry, lzplt_entry; | |
90219bd0 AO |
1135 | /* The offsets of the GOT entries for TLS offset and TLS descriptor. */ |
1136 | bfd_signed_vma tlsoff_entry, tlsdesc_entry; | |
1137 | /* The offset of the TLS offset PLT entry. */ | |
1138 | bfd_vma tlsplt_entry; | |
51532845 | 1139 | }; |
4e5ba5b7 | 1140 | |
43850d5b | 1141 | /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */ |
51532845 | 1142 | static hashval_t |
43850d5b | 1143 | frvfdpic_relocs_info_hash (const void *entry_) |
51532845 | 1144 | { |
43850d5b | 1145 | const struct frvfdpic_relocs_info *entry = entry_; |
4e5ba5b7 | 1146 | |
51532845 | 1147 | return (entry->symndx == -1 |
5ff625e9 AM |
1148 | ? (long) entry->d.h->root.root.hash |
1149 | : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend; | |
4e5ba5b7 DB |
1150 | } |
1151 | ||
43850d5b | 1152 | /* Test whether the key fields of two frvfdpic_relocs_info entries are |
51532845 AO |
1153 | identical. */ |
1154 | static int | |
43850d5b | 1155 | frvfdpic_relocs_info_eq (const void *entry1, const void *entry2) |
51532845 | 1156 | { |
43850d5b AO |
1157 | const struct frvfdpic_relocs_info *e1 = entry1; |
1158 | const struct frvfdpic_relocs_info *e2 = entry2; | |
4e5ba5b7 | 1159 | |
51532845 AO |
1160 | return e1->symndx == e2->symndx && e1->addend == e2->addend |
1161 | && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd); | |
1162 | } | |
1163 | ||
1164 | /* Find or create an entry in a hash table HT that matches the key | |
1165 | fields of the given ENTRY. If it's not found, memory for a new | |
1166 | entry is allocated in ABFD's obstack. */ | |
43850d5b AO |
1167 | static struct frvfdpic_relocs_info * |
1168 | frvfdpic_relocs_info_find (struct htab *ht, | |
1169 | bfd *abfd, | |
1170 | const struct frvfdpic_relocs_info *entry, | |
1171 | enum insert_option insert) | |
4e5ba5b7 | 1172 | { |
43850d5b AO |
1173 | struct frvfdpic_relocs_info **loc = |
1174 | (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert); | |
3b712a1a AO |
1175 | |
1176 | if (! loc) | |
1177 | return NULL; | |
4e5ba5b7 | 1178 | |
51532845 AO |
1179 | if (*loc) |
1180 | return *loc; | |
4e5ba5b7 | 1181 | |
51532845 | 1182 | *loc = bfd_zalloc (abfd, sizeof (**loc)); |
b34976b6 | 1183 | |
51532845 AO |
1184 | if (! *loc) |
1185 | return *loc; | |
1186 | ||
1187 | (*loc)->symndx = entry->symndx; | |
1188 | (*loc)->d = entry->d; | |
1189 | (*loc)->addend = entry->addend; | |
1190 | (*loc)->plt_entry = (bfd_vma)-1; | |
1191 | (*loc)->lzplt_entry = (bfd_vma)-1; | |
90219bd0 | 1192 | (*loc)->tlsplt_entry = (bfd_vma)-1; |
51532845 AO |
1193 | |
1194 | return *loc; | |
1195 | } | |
1196 | ||
1197 | /* Obtain the address of the entry in HT associated with H's symbol + | |
1198 | addend, creating a new entry if none existed. ABFD is only used | |
1199 | for memory allocation purposes. */ | |
43850d5b AO |
1200 | inline static struct frvfdpic_relocs_info * |
1201 | frvfdpic_relocs_info_for_global (struct htab *ht, | |
1202 | bfd *abfd, | |
1203 | struct elf_link_hash_entry *h, | |
1204 | bfd_vma addend, | |
1205 | enum insert_option insert) | |
51532845 | 1206 | { |
43850d5b | 1207 | struct frvfdpic_relocs_info entry; |
51532845 AO |
1208 | |
1209 | entry.symndx = -1; | |
1210 | entry.d.h = h; | |
1211 | entry.addend = addend; | |
1212 | ||
43850d5b | 1213 | return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); |
51532845 AO |
1214 | } |
1215 | ||
1216 | /* Obtain the address of the entry in HT associated with the SYMNDXth | |
1217 | local symbol of the input bfd ABFD, plus the addend, creating a new | |
f12123c0 | 1218 | entry if none existed. */ |
43850d5b AO |
1219 | inline static struct frvfdpic_relocs_info * |
1220 | frvfdpic_relocs_info_for_local (struct htab *ht, | |
1221 | bfd *abfd, | |
1222 | long symndx, | |
1223 | bfd_vma addend, | |
1224 | enum insert_option insert) | |
51532845 | 1225 | { |
43850d5b | 1226 | struct frvfdpic_relocs_info entry; |
51532845 AO |
1227 | |
1228 | entry.symndx = symndx; | |
1229 | entry.d.abfd = abfd; | |
1230 | entry.addend = addend; | |
1231 | ||
43850d5b | 1232 | return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); |
3b712a1a AO |
1233 | } |
1234 | ||
1235 | /* Merge fields set by check_relocs() of two entries that end up being | |
1236 | mapped to the same (presumably global) symbol. */ | |
1237 | ||
1238 | inline static void | |
43850d5b AO |
1239 | frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2, |
1240 | struct frvfdpic_relocs_info const *e1) | |
3b712a1a AO |
1241 | { |
1242 | e2->got12 |= e1->got12; | |
1243 | e2->gotlos |= e1->gotlos; | |
1244 | e2->gothilo |= e1->gothilo; | |
1245 | e2->fd |= e1->fd; | |
1246 | e2->fdgot12 |= e1->fdgot12; | |
1247 | e2->fdgotlos |= e1->fdgotlos; | |
1248 | e2->fdgothilo |= e1->fdgothilo; | |
1249 | e2->fdgoff12 |= e1->fdgoff12; | |
1250 | e2->fdgofflos |= e1->fdgofflos; | |
1251 | e2->fdgoffhilo |= e1->fdgoffhilo; | |
90219bd0 AO |
1252 | e2->tlsplt |= e1->tlsplt; |
1253 | e2->tlsdesc12 |= e1->tlsdesc12; | |
1254 | e2->tlsdesclos |= e1->tlsdesclos; | |
1255 | e2->tlsdeschilo |= e1->tlsdeschilo; | |
1256 | e2->tlsoff12 |= e1->tlsoff12; | |
1257 | e2->tlsofflos |= e1->tlsofflos; | |
1258 | e2->tlsoffhilo |= e1->tlsoffhilo; | |
3b712a1a AO |
1259 | e2->gotoff |= e1->gotoff; |
1260 | e2->call |= e1->call; | |
1261 | e2->sym |= e1->sym; | |
51532845 AO |
1262 | } |
1263 | ||
1264 | /* Every block of 65535 lazy PLT entries shares a single call to the | |
1265 | resolver, inserted in the 32768th lazy PLT entry (i.e., entry # | |
1266 | 32767, counting from 0). All other lazy PLT entries branch to it | |
1267 | in a single instruction. */ | |
1268 | ||
43850d5b AO |
1269 | #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4) |
1270 | #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767) | |
51532845 AO |
1271 | |
1272 | /* Add a dynamic relocation to the SRELOC section. */ | |
1273 | ||
1274 | inline static bfd_vma | |
43850d5b AO |
1275 | _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset, |
1276 | int reloc_type, long dynindx, bfd_vma addend, | |
1277 | struct frvfdpic_relocs_info *entry) | |
51532845 AO |
1278 | { |
1279 | Elf_Internal_Rela outrel; | |
1280 | bfd_vma reloc_offset; | |
1281 | ||
1282 | outrel.r_offset = offset; | |
1283 | outrel.r_info = ELF32_R_INFO (dynindx, reloc_type); | |
1284 | outrel.r_addend = addend; | |
1285 | ||
1286 | reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel); | |
eea6121a | 1287 | BFD_ASSERT (reloc_offset < sreloc->size); |
51532845 AO |
1288 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, |
1289 | sreloc->contents + reloc_offset); | |
1290 | sreloc->reloc_count++; | |
1291 | ||
3f980e41 AO |
1292 | /* If the entry's index is zero, this relocation was probably to a |
1293 | linkonce section that got discarded. We reserved a dynamic | |
1294 | relocation, but it was for another entry than the one we got at | |
1295 | the time of emitting the relocation. Unfortunately there's no | |
1296 | simple way for us to catch this situation, since the relocation | |
1297 | is cleared right before calling relocate_section, at which point | |
1298 | we no longer know what the relocation used to point to. */ | |
1299 | if (entry->symndx) | |
1300 | { | |
1301 | BFD_ASSERT (entry->dynrelocs > 0); | |
1302 | entry->dynrelocs--; | |
1303 | } | |
3b712a1a | 1304 | |
51532845 AO |
1305 | return reloc_offset; |
1306 | } | |
1307 | ||
1308 | /* Add a fixup to the ROFIXUP section. */ | |
1309 | ||
1310 | static bfd_vma | |
43850d5b AO |
1311 | _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset, |
1312 | struct frvfdpic_relocs_info *entry) | |
51532845 AO |
1313 | { |
1314 | bfd_vma fixup_offset; | |
1315 | ||
1316 | if (rofixup->flags & SEC_EXCLUDE) | |
1317 | return -1; | |
1318 | ||
1319 | fixup_offset = rofixup->reloc_count * 4; | |
1320 | if (rofixup->contents) | |
1321 | { | |
eea6121a | 1322 | BFD_ASSERT (fixup_offset < rofixup->size); |
51532845 AO |
1323 | bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset); |
1324 | } | |
1325 | rofixup->reloc_count++; | |
3b712a1a | 1326 | |
3f980e41 | 1327 | if (entry && entry->symndx) |
3b712a1a | 1328 | { |
3f980e41 AO |
1329 | /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc |
1330 | above. */ | |
3b712a1a AO |
1331 | BFD_ASSERT (entry->fixups > 0); |
1332 | entry->fixups--; | |
1333 | } | |
1334 | ||
51532845 AO |
1335 | return fixup_offset; |
1336 | } | |
1337 | ||
1338 | /* Find the segment number in which OSEC, and output section, is | |
1339 | located. */ | |
1340 | ||
1341 | static unsigned | |
43850d5b | 1342 | _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec) |
51532845 AO |
1343 | { |
1344 | struct elf_segment_map *m; | |
1345 | Elf_Internal_Phdr *p; | |
1346 | ||
1347 | /* Find the segment that contains the output_section. */ | |
1348 | for (m = elf_tdata (output_bfd)->segment_map, | |
1349 | p = elf_tdata (output_bfd)->phdr; | |
1350 | m != NULL; | |
1351 | m = m->next, p++) | |
1352 | { | |
1353 | int i; | |
1354 | ||
1355 | for (i = m->count - 1; i >= 0; i--) | |
1356 | if (m->sections[i] == osec) | |
1357 | break; | |
1358 | ||
1359 | if (i >= 0) | |
1360 | break; | |
1361 | } | |
1362 | ||
1363 | return p - elf_tdata (output_bfd)->phdr; | |
1364 | } | |
1365 | ||
1366 | inline static bfd_boolean | |
43850d5b | 1367 | _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec) |
51532845 | 1368 | { |
43850d5b | 1369 | unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec); |
51532845 AO |
1370 | |
1371 | return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W); | |
1372 | } | |
1373 | ||
90219bd0 AO |
1374 | #define FRVFDPIC_TLS_BIAS (2048 - 16) |
1375 | ||
1376 | /* Return the base VMA address which should be subtracted from real addresses | |
1377 | when resolving TLSMOFF relocation. | |
1378 | This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */ | |
1379 | ||
1380 | static bfd_vma | |
1381 | tls_biased_base (struct bfd_link_info *info) | |
1382 | { | |
1383 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
1384 | if (elf_hash_table (info)->tls_sec == NULL) | |
1385 | return FRVFDPIC_TLS_BIAS; | |
1386 | return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS; | |
1387 | } | |
1388 | ||
51532845 AO |
1389 | /* Generate relocations for GOT entries, function descriptors, and |
1390 | code for PLT and lazy PLT entries. */ | |
1391 | ||
1392 | inline static bfd_boolean | |
43850d5b AO |
1393 | _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry, |
1394 | bfd *output_bfd, | |
1395 | struct bfd_link_info *info, | |
1396 | asection *sec, | |
1397 | Elf_Internal_Sym *sym, | |
1398 | bfd_vma addend) | |
f12123c0 | 1399 | |
51532845 AO |
1400 | { |
1401 | bfd_vma fd_lazy_rel_offset = (bfd_vma)-1; | |
1402 | int dynindx = -1; | |
1403 | ||
1404 | if (entry->done) | |
1405 | return TRUE; | |
1406 | entry->done = 1; | |
1407 | ||
90219bd0 AO |
1408 | if (entry->got_entry || entry->fdgot_entry || entry->fd_entry |
1409 | || entry->tlsoff_entry || entry->tlsdesc_entry) | |
51532845 AO |
1410 | { |
1411 | /* If the symbol is dynamic, consider it for dynamic | |
1412 | relocations, otherwise decay to section + offset. */ | |
1413 | if (entry->symndx == -1 && entry->d.h->dynindx != -1) | |
1414 | dynindx = entry->d.h->dynindx; | |
1415 | else | |
1416 | { | |
1417 | if (sec->output_section | |
1418 | && ! bfd_is_abs_section (sec->output_section) | |
1419 | && ! bfd_is_und_section (sec->output_section)) | |
1420 | dynindx = elf_section_data (sec->output_section)->dynindx; | |
1421 | else | |
1422 | dynindx = 0; | |
1423 | } | |
1424 | } | |
1425 | ||
1426 | /* Generate relocation for GOT entry pointing to the symbol. */ | |
1427 | if (entry->got_entry) | |
1428 | { | |
1429 | int idx = dynindx; | |
1430 | bfd_vma ad = addend; | |
1431 | ||
1432 | /* If the symbol is dynamic but binds locally, use | |
1433 | section+offset. */ | |
43850d5b AO |
1434 | if (sec && (entry->symndx != -1 |
1435 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1436 | { |
1437 | if (entry->symndx == -1) | |
1438 | ad += entry->d.h->root.u.def.value; | |
1439 | else | |
1440 | ad += sym->st_value; | |
1441 | ad += sec->output_offset; | |
1442 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1443 | idx = elf_section_data (sec->output_section)->dynindx; | |
1444 | else | |
1445 | idx = 0; | |
1446 | } | |
1447 | ||
1448 | /* If we're linking an executable at a fixed address, we can | |
1449 | omit the dynamic relocation as long as the symbol is local to | |
1450 | this module. */ | |
1451 | if (info->executable && !info->pie | |
43850d5b AO |
1452 | && (entry->symndx != -1 |
1453 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1454 | { |
1455 | if (sec) | |
1456 | ad += sec->output_section->vma; | |
3b712a1a AO |
1457 | if (entry->symndx != -1 |
1458 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
43850d5b AO |
1459 | _frvfdpic_add_rofixup (output_bfd, |
1460 | frvfdpic_gotfixup_section (info), | |
1461 | frvfdpic_got_section (info)->output_section | |
1462 | ->vma | |
1463 | + frvfdpic_got_section (info)->output_offset | |
1464 | + frvfdpic_got_initial_offset (info) | |
1465 | + entry->got_entry, entry); | |
51532845 AO |
1466 | } |
1467 | else | |
43850d5b AO |
1468 | _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), |
1469 | _bfd_elf_section_offset | |
1470 | (output_bfd, info, | |
1471 | frvfdpic_got_section (info), | |
1472 | frvfdpic_got_initial_offset (info) | |
1473 | + entry->got_entry) | |
1474 | + frvfdpic_got_section (info) | |
1475 | ->output_section->vma | |
1476 | + frvfdpic_got_section (info)->output_offset, | |
1477 | R_FRV_32, idx, ad, entry); | |
f12123c0 | 1478 | |
51532845 | 1479 | bfd_put_32 (output_bfd, ad, |
43850d5b AO |
1480 | frvfdpic_got_section (info)->contents |
1481 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1482 | + entry->got_entry); |
1483 | } | |
1484 | ||
1485 | /* Generate relocation for GOT entry pointing to a canonical | |
1486 | function descriptor. */ | |
1487 | if (entry->fdgot_entry) | |
1488 | { | |
1489 | int reloc, idx; | |
072c8903 | 1490 | bfd_vma ad = 0; |
f12123c0 | 1491 | |
072c8903 AO |
1492 | if (! (entry->symndx == -1 |
1493 | && entry->d.h->root.type == bfd_link_hash_undefweak | |
43850d5b | 1494 | && FRVFDPIC_SYM_LOCAL (info, entry->d.h))) |
51532845 | 1495 | { |
072c8903 AO |
1496 | /* If the symbol is dynamic and there may be dynamic symbol |
1497 | resolution because we are, or are linked with, a shared | |
1498 | library, emit a FUNCDESC relocation such that the dynamic | |
1499 | linker will allocate the function descriptor. If the | |
1500 | symbol needs a non-local function descriptor but binds | |
1501 | locally (e.g., its visibility is protected, emit a | |
1502 | dynamic relocation decayed to section+offset. */ | |
43850d5b AO |
1503 | if (entry->symndx == -1 |
1504 | && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h) | |
1505 | && FRVFDPIC_SYM_LOCAL (info, entry->d.h) | |
072c8903 AO |
1506 | && !(info->executable && !info->pie)) |
1507 | { | |
1508 | reloc = R_FRV_FUNCDESC; | |
1509 | idx = elf_section_data (entry->d.h->root.u.def.section | |
1510 | ->output_section)->dynindx; | |
1511 | ad = entry->d.h->root.u.def.section->output_offset | |
1512 | + entry->d.h->root.u.def.value; | |
1513 | } | |
1514 | else if (entry->symndx == -1 | |
43850d5b | 1515 | && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)) |
072c8903 AO |
1516 | { |
1517 | reloc = R_FRV_FUNCDESC; | |
1518 | idx = dynindx; | |
1519 | ad = addend; | |
1520 | if (ad) | |
303e4c21 AO |
1521 | { |
1522 | (*info->callbacks->reloc_dangerous) | |
1523 | (info, _("relocation requires zero addend"), | |
1524 | elf_hash_table (info)->dynobj, | |
1525 | frvfdpic_got_section (info), | |
1526 | entry->fdgot_entry); | |
1527 | return FALSE; | |
1528 | } | |
072c8903 | 1529 | } |
51532845 | 1530 | else |
072c8903 AO |
1531 | { |
1532 | /* Otherwise, we know we have a private function descriptor, | |
1533 | so reference it directly. */ | |
1534 | if (elf_hash_table (info)->dynamic_sections_created) | |
1535 | BFD_ASSERT (entry->privfd); | |
1536 | reloc = R_FRV_32; | |
43850d5b | 1537 | idx = elf_section_data (frvfdpic_got_section (info) |
072c8903 | 1538 | ->output_section)->dynindx; |
43850d5b AO |
1539 | ad = frvfdpic_got_section (info)->output_offset |
1540 | + frvfdpic_got_initial_offset (info) + entry->fd_entry; | |
072c8903 AO |
1541 | } |
1542 | ||
1543 | /* If there is room for dynamic symbol resolution, emit the | |
1544 | dynamic relocation. However, if we're linking an | |
1545 | executable at a fixed location, we won't have emitted a | |
1546 | dynamic symbol entry for the got section, so idx will be | |
1547 | zero, which means we can and should compute the address | |
1548 | of the private descriptor ourselves. */ | |
1549 | if (info->executable && !info->pie | |
1550 | && (entry->symndx != -1 | |
43850d5b | 1551 | || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))) |
51532845 | 1552 | { |
43850d5b AO |
1553 | ad += frvfdpic_got_section (info)->output_section->vma; |
1554 | _frvfdpic_add_rofixup (output_bfd, | |
1555 | frvfdpic_gotfixup_section (info), | |
1556 | frvfdpic_got_section (info) | |
1557 | ->output_section->vma | |
1558 | + frvfdpic_got_section (info) | |
1559 | ->output_offset | |
1560 | + frvfdpic_got_initial_offset (info) | |
1561 | + entry->fdgot_entry, entry); | |
51532845 | 1562 | } |
072c8903 | 1563 | else |
43850d5b AO |
1564 | _frvfdpic_add_dyn_reloc (output_bfd, |
1565 | frvfdpic_gotrel_section (info), | |
1566 | _bfd_elf_section_offset | |
1567 | (output_bfd, info, | |
1568 | frvfdpic_got_section (info), | |
1569 | frvfdpic_got_initial_offset (info) | |
1570 | + entry->fdgot_entry) | |
1571 | + frvfdpic_got_section (info) | |
1572 | ->output_section->vma | |
1573 | + frvfdpic_got_section (info) | |
1574 | ->output_offset, | |
1575 | reloc, idx, ad, entry); | |
51532845 | 1576 | } |
51532845 AO |
1577 | |
1578 | bfd_put_32 (output_bfd, ad, | |
43850d5b AO |
1579 | frvfdpic_got_section (info)->contents |
1580 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1581 | + entry->fdgot_entry); |
1582 | } | |
1583 | ||
1584 | /* Generate relocation to fill in a private function descriptor in | |
1585 | the GOT. */ | |
1586 | if (entry->fd_entry) | |
1587 | { | |
1588 | int idx = dynindx; | |
1589 | bfd_vma ad = addend; | |
1590 | bfd_vma ofst; | |
1591 | long lowword, highword; | |
1592 | ||
1593 | /* If the symbol is dynamic but binds locally, use | |
1594 | section+offset. */ | |
43850d5b AO |
1595 | if (sec && (entry->symndx != -1 |
1596 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
51532845 AO |
1597 | { |
1598 | if (entry->symndx == -1) | |
1599 | ad += entry->d.h->root.u.def.value; | |
1600 | else | |
1601 | ad += sym->st_value; | |
1602 | ad += sec->output_offset; | |
1603 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1604 | idx = elf_section_data (sec->output_section)->dynindx; | |
1605 | else | |
1606 | idx = 0; | |
1607 | } | |
1608 | ||
1609 | /* If we're linking an executable at a fixed address, we can | |
1610 | omit the dynamic relocation as long as the symbol is local to | |
1611 | this module. */ | |
1612 | if (info->executable && !info->pie | |
43850d5b | 1613 | && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) |
51532845 AO |
1614 | { |
1615 | if (sec) | |
1616 | ad += sec->output_section->vma; | |
1617 | ofst = 0; | |
3b712a1a AO |
1618 | if (entry->symndx != -1 |
1619 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
51532845 | 1620 | { |
43850d5b AO |
1621 | _frvfdpic_add_rofixup (output_bfd, |
1622 | frvfdpic_gotfixup_section (info), | |
1623 | frvfdpic_got_section (info) | |
1624 | ->output_section->vma | |
1625 | + frvfdpic_got_section (info) | |
1626 | ->output_offset | |
1627 | + frvfdpic_got_initial_offset (info) | |
1628 | + entry->fd_entry, entry); | |
1629 | _frvfdpic_add_rofixup (output_bfd, | |
1630 | frvfdpic_gotfixup_section (info), | |
1631 | frvfdpic_got_section (info) | |
1632 | ->output_section->vma | |
1633 | + frvfdpic_got_section (info) | |
1634 | ->output_offset | |
1635 | + frvfdpic_got_initial_offset (info) | |
1636 | + entry->fd_entry + 4, entry); | |
51532845 AO |
1637 | } |
1638 | } | |
1639 | else | |
1640 | { | |
1641 | ofst = | |
43850d5b AO |
1642 | _frvfdpic_add_dyn_reloc (output_bfd, |
1643 | entry->lazyplt | |
1644 | ? frvfdpic_pltrel_section (info) | |
1645 | : frvfdpic_gotrel_section (info), | |
1646 | _bfd_elf_section_offset | |
1647 | (output_bfd, info, | |
1648 | frvfdpic_got_section (info), | |
1649 | frvfdpic_got_initial_offset (info) | |
1650 | + entry->fd_entry) | |
1651 | + frvfdpic_got_section (info) | |
1652 | ->output_section->vma | |
1653 | + frvfdpic_got_section (info) | |
1654 | ->output_offset, | |
1655 | R_FRV_FUNCDESC_VALUE, idx, ad, entry); | |
51532845 AO |
1656 | } |
1657 | ||
1658 | /* If we've omitted the dynamic relocation, just emit the fixed | |
1659 | addresses of the symbol and of the local GOT base offset. */ | |
1660 | if (info->executable && !info->pie && sec && sec->output_section) | |
1661 | { | |
1662 | lowword = ad; | |
43850d5b AO |
1663 | highword = frvfdpic_got_section (info)->output_section->vma |
1664 | + frvfdpic_got_section (info)->output_offset | |
1665 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
1666 | } |
1667 | else if (entry->lazyplt) | |
1668 | { | |
1669 | if (ad) | |
303e4c21 AO |
1670 | { |
1671 | (*info->callbacks->reloc_dangerous) | |
1672 | (info, _("relocation requires zero addend"), | |
1673 | elf_hash_table (info)->dynobj, | |
1674 | frvfdpic_got_section (info), | |
1675 | entry->fd_entry); | |
1676 | return FALSE; | |
1677 | } | |
f12123c0 | 1678 | |
51532845 AO |
1679 | fd_lazy_rel_offset = ofst; |
1680 | ||
1681 | /* A function descriptor used for lazy or local resolving is | |
1682 | initialized such that its high word contains the output | |
1683 | section index in which the PLT entries are located, and | |
1684 | the low word contains the address of the lazy PLT entry | |
1685 | entry point, that must be within the memory region | |
1686 | assigned to that section. */ | |
1687 | lowword = entry->lzplt_entry + 4 | |
43850d5b AO |
1688 | + frvfdpic_plt_section (info)->output_offset |
1689 | + frvfdpic_plt_section (info)->output_section->vma; | |
f12123c0 | 1690 | highword = _frvfdpic_osec_to_segment |
43850d5b | 1691 | (output_bfd, frvfdpic_plt_section (info)->output_section); |
51532845 AO |
1692 | } |
1693 | else | |
1694 | { | |
1695 | /* A function descriptor for a local function gets the index | |
1696 | of the section. For a non-local function, it's | |
1697 | disregarded. */ | |
1698 | lowword = ad; | |
1699 | if (entry->symndx == -1 && entry->d.h->dynindx != -1 | |
1700 | && entry->d.h->dynindx == idx) | |
1701 | highword = 0; | |
1702 | else | |
43850d5b AO |
1703 | highword = _frvfdpic_osec_to_segment |
1704 | (output_bfd, sec->output_section); | |
51532845 AO |
1705 | } |
1706 | ||
1707 | bfd_put_32 (output_bfd, lowword, | |
43850d5b AO |
1708 | frvfdpic_got_section (info)->contents |
1709 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1710 | + entry->fd_entry); |
1711 | bfd_put_32 (output_bfd, highword, | |
43850d5b AO |
1712 | frvfdpic_got_section (info)->contents |
1713 | + frvfdpic_got_initial_offset (info) | |
51532845 AO |
1714 | + entry->fd_entry + 4); |
1715 | } | |
1716 | ||
1717 | /* Generate code for the PLT entry. */ | |
1718 | if (entry->plt_entry != (bfd_vma) -1) | |
1719 | { | |
43850d5b AO |
1720 | bfd_byte *plt_code = frvfdpic_plt_section (info)->contents |
1721 | + entry->plt_entry; | |
51532845 AO |
1722 | |
1723 | BFD_ASSERT (entry->fd_entry); | |
1724 | ||
1725 | /* Figure out what kind of PLT entry we need, depending on the | |
1726 | location of the function descriptor within the GOT. */ | |
1727 | if (entry->fd_entry >= -(1 << (12 - 1)) | |
1728 | && entry->fd_entry < (1 << (12 - 1))) | |
1729 | { | |
1730 | /* lddi @(gr15, fd_entry), gr14 */ | |
1731 | bfd_put_32 (output_bfd, | |
1732 | 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)), | |
1733 | plt_code); | |
1734 | plt_code += 4; | |
1735 | } | |
1736 | else | |
1737 | { | |
1738 | if (entry->fd_entry >= -(1 << (16 - 1)) | |
1739 | && entry->fd_entry < (1 << (16 - 1))) | |
1740 | { | |
1741 | /* setlos lo(fd_entry), gr14 */ | |
1742 | bfd_put_32 (output_bfd, | |
1743 | 0x9cfc0000 | |
1744 | | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), | |
1745 | plt_code); | |
1746 | plt_code += 4; | |
1747 | } | |
1748 | else | |
1749 | { | |
1750 | /* sethi.p hi(fd_entry), gr14 | |
1751 | setlo lo(fd_entry), gr14 */ | |
1752 | bfd_put_32 (output_bfd, | |
1753 | 0x1cf80000 | |
1754 | | ((entry->fd_entry >> 16) | |
1755 | & (((bfd_vma)1 << 16) - 1)), | |
1756 | plt_code); | |
90219bd0 | 1757 | plt_code += 4; |
51532845 AO |
1758 | bfd_put_32 (output_bfd, |
1759 | 0x9cf40000 | |
1760 | | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), | |
1761 | plt_code); | |
90219bd0 | 1762 | plt_code += 4; |
51532845 AO |
1763 | } |
1764 | /* ldd @(gr14,gr15),gr14 */ | |
1765 | bfd_put_32 (output_bfd, 0x9c08e14f, plt_code); | |
1766 | plt_code += 4; | |
1767 | } | |
1768 | /* jmpl @(gr14,gr0) */ | |
1769 | bfd_put_32 (output_bfd, 0x8030e000, plt_code); | |
1770 | } | |
1771 | ||
1772 | /* Generate code for the lazy PLT entry. */ | |
1773 | if (entry->lzplt_entry != (bfd_vma) -1) | |
1774 | { | |
43850d5b | 1775 | bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents |
51532845 AO |
1776 | + entry->lzplt_entry; |
1777 | bfd_vma resolverStub_addr; | |
1778 | ||
1779 | bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code); | |
1780 | lzplt_code += 4; | |
1781 | ||
43850d5b AO |
1782 | resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE |
1783 | * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC; | |
1784 | if (resolverStub_addr >= frvfdpic_plt_initial_offset (info)) | |
1785 | resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12; | |
51532845 AO |
1786 | |
1787 | if (entry->lzplt_entry == resolverStub_addr) | |
1788 | { | |
1789 | /* This is a lazy PLT entry that includes a resolver call. */ | |
1790 | /* ldd @(gr15,gr0), gr4 | |
1791 | jmpl @(gr4,gr0) */ | |
1792 | bfd_put_32 (output_bfd, 0x8808f140, lzplt_code); | |
1793 | bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4); | |
1794 | } | |
1795 | else | |
1796 | { | |
90219bd0 AO |
1797 | /* bra resolverStub */ |
1798 | bfd_put_32 (output_bfd, | |
1799 | 0xc01a0000 | |
1800 | | (((resolverStub_addr - entry->lzplt_entry) | |
1801 | / 4) & (((bfd_vma)1 << 16) - 1)), | |
1802 | lzplt_code); | |
1803 | } | |
1804 | } | |
1805 | ||
1806 | /* Generate relocation for GOT entry holding the TLS offset. */ | |
1807 | if (entry->tlsoff_entry) | |
1808 | { | |
1809 | int idx = dynindx; | |
1810 | bfd_vma ad = addend; | |
1811 | ||
1812 | if (entry->symndx != -1 | |
1813 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h)) | |
1814 | { | |
1815 | /* If the symbol is dynamic but binds locally, use | |
1816 | section+offset. */ | |
1817 | if (sec) | |
1818 | { | |
1819 | if (entry->symndx == -1) | |
1820 | ad += entry->d.h->root.u.def.value; | |
1821 | else | |
1822 | ad += sym->st_value; | |
1823 | ad += sec->output_offset; | |
1824 | if (sec->output_section | |
1825 | && elf_section_data (sec->output_section)) | |
1826 | idx = elf_section_data (sec->output_section)->dynindx; | |
1827 | else | |
1828 | idx = 0; | |
1829 | } | |
1830 | } | |
1831 | ||
1832 | /* *ABS*+addend is special for TLS relocations, use only the | |
1833 | addend. */ | |
1834 | if (info->executable | |
1835 | && idx == 0 | |
1836 | && (bfd_is_abs_section (sec) | |
1837 | || bfd_is_und_section (sec))) | |
1838 | ; | |
1839 | /* If we're linking an executable, we can entirely omit the | |
1840 | dynamic relocation if the symbol is local to this module. */ | |
1841 | else if (info->executable | |
1842 | && (entry->symndx != -1 | |
1843 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
1844 | { | |
1845 | if (sec) | |
1846 | ad += sec->output_section->vma - tls_biased_base (info); | |
1847 | } | |
1848 | else | |
1849 | { | |
1850 | if (idx == 0 | |
1851 | && (bfd_is_abs_section (sec) | |
1852 | || bfd_is_und_section (sec))) | |
1853 | { | |
303e4c21 AO |
1854 | if (! elf_hash_table (info)->tls_sec) |
1855 | { | |
1856 | (*info->callbacks->undefined_symbol) | |
1857 | (info, "TLS section", elf_hash_table (info)->dynobj, | |
1858 | frvfdpic_got_section (info), entry->tlsoff_entry, TRUE); | |
1859 | return FALSE; | |
1860 | } | |
90219bd0 AO |
1861 | idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; |
1862 | ad += FRVFDPIC_TLS_BIAS; | |
1863 | } | |
1864 | _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), | |
1865 | _bfd_elf_section_offset | |
1866 | (output_bfd, info, | |
1867 | frvfdpic_got_section (info), | |
1868 | frvfdpic_got_initial_offset (info) | |
1869 | + entry->tlsoff_entry) | |
1870 | + frvfdpic_got_section (info) | |
1871 | ->output_section->vma | |
1872 | + frvfdpic_got_section (info) | |
1873 | ->output_offset, | |
1874 | R_FRV_TLSOFF, idx, ad, entry); | |
1875 | } | |
3b36f7e6 | 1876 | |
90219bd0 AO |
1877 | bfd_put_32 (output_bfd, ad, |
1878 | frvfdpic_got_section (info)->contents | |
1879 | + frvfdpic_got_initial_offset (info) | |
1880 | + entry->tlsoff_entry); | |
1881 | } | |
1882 | ||
1883 | if (entry->tlsdesc_entry) | |
1884 | { | |
1885 | int idx = dynindx; | |
1886 | bfd_vma ad = addend; | |
1887 | ||
1888 | /* If the symbol is dynamic but binds locally, use | |
1889 | section+offset. */ | |
1890 | if (sec && (entry->symndx != -1 | |
1891 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
1892 | { | |
1893 | if (entry->symndx == -1) | |
1894 | ad += entry->d.h->root.u.def.value; | |
1895 | else | |
1896 | ad += sym->st_value; | |
1897 | ad += sec->output_offset; | |
1898 | if (sec->output_section && elf_section_data (sec->output_section)) | |
1899 | idx = elf_section_data (sec->output_section)->dynindx; | |
1900 | else | |
1901 | idx = 0; | |
1902 | } | |
1903 | ||
1904 | /* If we didn't set up a TLS offset entry, but we're linking an | |
1905 | executable and the symbol binds locally, we can use the | |
1906 | module offset in the TLS descriptor in relaxations. */ | |
1907 | if (info->executable && ! entry->tlsoff_entry) | |
1908 | entry->tlsoff_entry = entry->tlsdesc_entry + 4; | |
1909 | ||
1910 | if (info->executable && !info->pie | |
1911 | && ((idx == 0 | |
1912 | && (bfd_is_abs_section (sec) | |
1913 | || bfd_is_und_section (sec))) | |
1914 | || entry->symndx != -1 | |
1915 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
1916 | { | |
1917 | /* *ABS*+addend is special for TLS relocations, use only the | |
1918 | addend for the TLS offset, and take the module id as | |
1919 | 0. */ | |
1920 | if (idx == 0 | |
1921 | && (bfd_is_abs_section (sec) | |
1922 | || bfd_is_und_section (sec))) | |
1923 | ; | |
1924 | /* For other TLS symbols that bind locally, add the section | |
1925 | TLS offset to the addend. */ | |
1926 | else if (sec) | |
1927 | ad += sec->output_section->vma - tls_biased_base (info); | |
1928 | ||
1929 | bfd_put_32 (output_bfd, | |
1930 | frvfdpic_plt_section (info)->output_section->vma | |
1931 | + frvfdpic_plt_section (info)->output_offset | |
1932 | + frvfdpic_plt_tls_ret_offset (info), | |
1933 | frvfdpic_got_section (info)->contents | |
1934 | + frvfdpic_got_initial_offset (info) | |
1935 | + entry->tlsdesc_entry); | |
1936 | ||
1937 | _frvfdpic_add_rofixup (output_bfd, | |
1938 | frvfdpic_gotfixup_section (info), | |
1939 | frvfdpic_got_section (info) | |
1940 | ->output_section->vma | |
1941 | + frvfdpic_got_section (info) | |
1942 | ->output_offset | |
1943 | + frvfdpic_got_initial_offset (info) | |
1944 | + entry->tlsdesc_entry, entry); | |
1945 | ||
1946 | BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs); | |
1947 | ||
1948 | /* We've used one of the reserved fixups, so discount it so | |
1949 | that we can check at the end that we've used them | |
1950 | all. */ | |
1951 | frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--; | |
1952 | ||
1953 | /* While at that, make sure the ret instruction makes to the | |
1954 | right location in the PLT. We could do it only when we | |
1955 | got to 0, but since the check at the end will only print | |
1956 | a warning, make sure we have the ret in place in case the | |
1957 | warning is missed. */ | |
1958 | bfd_put_32 (output_bfd, 0xc03a4000, | |
1959 | frvfdpic_plt_section (info)->contents | |
1960 | + frvfdpic_plt_tls_ret_offset (info)); | |
1961 | } | |
1962 | else | |
1963 | { | |
1964 | if (idx == 0 | |
1965 | && (bfd_is_abs_section (sec) | |
1966 | || bfd_is_und_section (sec))) | |
1967 | { | |
303e4c21 AO |
1968 | if (! elf_hash_table (info)->tls_sec) |
1969 | { | |
1970 | (*info->callbacks->undefined_symbol) | |
1971 | (info, "TLS section", elf_hash_table (info)->dynobj, | |
1972 | frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE); | |
1973 | return FALSE; | |
1974 | } | |
90219bd0 AO |
1975 | idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; |
1976 | ad += FRVFDPIC_TLS_BIAS; | |
1977 | } | |
1978 | ||
1979 | _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), | |
1980 | _bfd_elf_section_offset | |
1981 | (output_bfd, info, | |
1982 | frvfdpic_got_section (info), | |
1983 | frvfdpic_got_initial_offset (info) | |
1984 | + entry->tlsdesc_entry) | |
1985 | + frvfdpic_got_section (info) | |
1986 | ->output_section->vma | |
1987 | + frvfdpic_got_section (info) | |
1988 | ->output_offset, | |
1989 | R_FRV_TLSDESC_VALUE, idx, ad, entry); | |
1990 | ||
1991 | bfd_put_32 (output_bfd, 0, | |
1992 | frvfdpic_got_section (info)->contents | |
1993 | + frvfdpic_got_initial_offset (info) | |
1994 | + entry->tlsdesc_entry); | |
1995 | } | |
1996 | ||
1997 | bfd_put_32 (output_bfd, ad, | |
1998 | frvfdpic_got_section (info)->contents | |
1999 | + frvfdpic_got_initial_offset (info) | |
2000 | + entry->tlsdesc_entry + 4); | |
2001 | } | |
2002 | ||
2003 | /* Generate code for the get-TLS-offset PLT entry. */ | |
2004 | if (entry->tlsplt_entry != (bfd_vma) -1) | |
2005 | { | |
2006 | bfd_byte *plt_code = frvfdpic_plt_section (info)->contents | |
2007 | + entry->tlsplt_entry; | |
3b36f7e6 | 2008 | |
90219bd0 AO |
2009 | if (info->executable |
2010 | && (entry->symndx != -1 | |
2011 | || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) | |
2012 | { | |
2013 | int idx = dynindx; | |
2014 | bfd_vma ad = addend; | |
2015 | ||
2016 | /* sec may be NULL when referencing an undefweak symbol | |
2017 | while linking a static executable. */ | |
2018 | if (!sec) | |
2019 | { | |
2020 | BFD_ASSERT (entry->symndx == -1 | |
2021 | && entry->d.h->root.type == bfd_link_hash_undefweak); | |
2022 | } | |
2023 | else | |
2024 | { | |
2025 | if (entry->symndx == -1) | |
2026 | ad += entry->d.h->root.u.def.value; | |
2027 | else | |
2028 | ad += sym->st_value; | |
2029 | ad += sec->output_offset; | |
2030 | if (sec->output_section | |
2031 | && elf_section_data (sec->output_section)) | |
2032 | idx = elf_section_data (sec->output_section)->dynindx; | |
2033 | else | |
2034 | idx = 0; | |
2035 | } | |
3b36f7e6 | 2036 | |
90219bd0 AO |
2037 | /* *ABS*+addend is special for TLS relocations, use only the |
2038 | addend for the TLS offset, and take the module id as | |
2039 | 0. */ | |
2040 | if (idx == 0 | |
2041 | && (bfd_is_abs_section (sec) | |
2042 | || bfd_is_und_section (sec))) | |
2043 | ; | |
2044 | /* For other TLS symbols that bind locally, add the section | |
2045 | TLS offset to the addend. */ | |
2046 | else if (sec) | |
2047 | ad += sec->output_section->vma - tls_biased_base (info); | |
3b36f7e6 | 2048 | |
90219bd0 AO |
2049 | if ((bfd_signed_vma)ad >= -(1 << (16 - 1)) |
2050 | && (bfd_signed_vma)ad < (1 << (16 - 1))) | |
2051 | { | |
2052 | /* setlos lo(ad), gr9 */ | |
2053 | bfd_put_32 (output_bfd, | |
2054 | 0x92fc0000 | |
2055 | | (ad | |
2056 | & (((bfd_vma)1 << 16) - 1)), | |
2057 | plt_code); | |
2058 | plt_code += 4; | |
2059 | } | |
2060 | else | |
2061 | { | |
2062 | /* sethi.p hi(ad), gr9 | |
2063 | setlo lo(ad), gr9 */ | |
2064 | bfd_put_32 (output_bfd, | |
2065 | 0x12f80000 | |
2066 | | ((ad >> 16) | |
2067 | & (((bfd_vma)1 << 16) - 1)), | |
2068 | plt_code); | |
2069 | plt_code += 4; | |
2070 | bfd_put_32 (output_bfd, | |
2071 | 0x92f40000 | |
2072 | | (ad | |
2073 | & (((bfd_vma)1 << 16) - 1)), | |
2074 | plt_code); | |
2075 | plt_code += 4; | |
2076 | } | |
2077 | /* ret */ | |
2078 | bfd_put_32 (output_bfd, 0xc03a4000, plt_code); | |
2079 | } | |
2080 | else if (entry->tlsoff_entry) | |
2081 | { | |
2082 | /* Figure out what kind of PLT entry we need, depending on the | |
2083 | location of the TLS descriptor within the GOT. */ | |
2084 | if (entry->tlsoff_entry >= -(1 << (12 - 1)) | |
2085 | && entry->tlsoff_entry < (1 << (12 - 1))) | |
2086 | { | |
2087 | /* ldi @(gr15, tlsoff_entry), gr9 */ | |
2088 | bfd_put_32 (output_bfd, | |
2089 | 0x92c8f000 | (entry->tlsoff_entry | |
2090 | & ((1 << 12) - 1)), | |
2091 | plt_code); | |
2092 | plt_code += 4; | |
2093 | } | |
2094 | else | |
2095 | { | |
2096 | if (entry->tlsoff_entry >= -(1 << (16 - 1)) | |
2097 | && entry->tlsoff_entry < (1 << (16 - 1))) | |
2098 | { | |
2099 | /* setlos lo(tlsoff_entry), gr8 */ | |
2100 | bfd_put_32 (output_bfd, | |
2101 | 0x90fc0000 | |
2102 | | (entry->tlsoff_entry | |
2103 | & (((bfd_vma)1 << 16) - 1)), | |
2104 | plt_code); | |
2105 | plt_code += 4; | |
2106 | } | |
2107 | else | |
2108 | { | |
2109 | /* sethi.p hi(tlsoff_entry), gr8 | |
2110 | setlo lo(tlsoff_entry), gr8 */ | |
2111 | bfd_put_32 (output_bfd, | |
2112 | 0x10f80000 | |
2113 | | ((entry->tlsoff_entry >> 16) | |
2114 | & (((bfd_vma)1 << 16) - 1)), | |
2115 | plt_code); | |
2116 | plt_code += 4; | |
2117 | bfd_put_32 (output_bfd, | |
2118 | 0x90f40000 | |
2119 | | (entry->tlsoff_entry | |
2120 | & (((bfd_vma)1 << 16) - 1)), | |
2121 | plt_code); | |
2122 | plt_code += 4; | |
2123 | } | |
2124 | /* ld @(gr15,gr8),gr9 */ | |
2125 | bfd_put_32 (output_bfd, 0x9008f108, plt_code); | |
2126 | plt_code += 4; | |
2127 | } | |
2128 | /* ret */ | |
2129 | bfd_put_32 (output_bfd, 0xc03a4000, plt_code); | |
2130 | } | |
2131 | else | |
2132 | { | |
2133 | BFD_ASSERT (entry->tlsdesc_entry); | |
2134 | ||
2135 | /* Figure out what kind of PLT entry we need, depending on the | |
2136 | location of the TLS descriptor within the GOT. */ | |
2137 | if (entry->tlsdesc_entry >= -(1 << (12 - 1)) | |
2138 | && entry->tlsdesc_entry < (1 << (12 - 1))) | |
2139 | { | |
2140 | /* lddi @(gr15, tlsdesc_entry), gr8 */ | |
2141 | bfd_put_32 (output_bfd, | |
2142 | 0x90ccf000 | (entry->tlsdesc_entry | |
2143 | & ((1 << 12) - 1)), | |
2144 | plt_code); | |
2145 | plt_code += 4; | |
2146 | } | |
2147 | else | |
2148 | { | |
2149 | if (entry->tlsdesc_entry >= -(1 << (16 - 1)) | |
2150 | && entry->tlsdesc_entry < (1 << (16 - 1))) | |
2151 | { | |
2152 | /* setlos lo(tlsdesc_entry), gr8 */ | |
2153 | bfd_put_32 (output_bfd, | |
2154 | 0x90fc0000 | |
2155 | | (entry->tlsdesc_entry | |
2156 | & (((bfd_vma)1 << 16) - 1)), | |
2157 | plt_code); | |
2158 | plt_code += 4; | |
2159 | } | |
2160 | else | |
2161 | { | |
2162 | /* sethi.p hi(tlsdesc_entry), gr8 | |
2163 | setlo lo(tlsdesc_entry), gr8 */ | |
2164 | bfd_put_32 (output_bfd, | |
2165 | 0x10f80000 | |
2166 | | ((entry->tlsdesc_entry >> 16) | |
2167 | & (((bfd_vma)1 << 16) - 1)), | |
2168 | plt_code); | |
2169 | plt_code += 4; | |
2170 | bfd_put_32 (output_bfd, | |
2171 | 0x90f40000 | |
2172 | | (entry->tlsdesc_entry | |
2173 | & (((bfd_vma)1 << 16) - 1)), | |
2174 | plt_code); | |
2175 | plt_code += 4; | |
2176 | } | |
2177 | /* ldd @(gr15,gr8),gr8 */ | |
2178 | bfd_put_32 (output_bfd, 0x9008f148, plt_code); | |
2179 | plt_code += 4; | |
2180 | } | |
2181 | /* jmpl @(gr8,gr0) */ | |
2182 | bfd_put_32 (output_bfd, 0x80308000, plt_code); | |
51532845 AO |
2183 | } |
2184 | } | |
2185 | ||
2186 | return TRUE; | |
2187 | } | |
2188 | ||
2189 | /* Handle an FRV small data reloc. */ | |
2190 | ||
2191 | static bfd_reloc_status_type | |
2192 | elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation, | |
2193 | contents, value) | |
2194 | struct bfd_link_info *info; | |
2195 | bfd *input_bfd; | |
2196 | asection *input_section; | |
2197 | Elf_Internal_Rela *relocation; | |
2198 | bfd_byte *contents; | |
2199 | bfd_vma value; | |
2200 | { | |
2201 | bfd_vma insn; | |
2202 | bfd_vma gp; | |
2203 | struct bfd_link_hash_entry *h; | |
2204 | ||
2205 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); | |
2206 | ||
2207 | gp = (h->u.def.value | |
2208 | + h->u.def.section->output_section->vma | |
2209 | + h->u.def.section->output_offset); | |
2210 | ||
2211 | value -= input_section->output_section->vma; | |
2212 | value -= (gp - input_section->output_section->vma); | |
2213 | ||
2214 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2215 | ||
2216 | value += relocation->r_addend; | |
2217 | ||
2218 | if ((long) value > 0x7ff || (long) value < -0x800) | |
2219 | return bfd_reloc_overflow; | |
2220 | ||
2221 | bfd_put_32 (input_bfd, | |
2222 | (insn & 0xfffff000) | (value & 0xfff), | |
2223 | contents + relocation->r_offset); | |
2224 | ||
2225 | return bfd_reloc_ok; | |
2226 | } | |
2227 | ||
2228 | /* Handle an FRV small data reloc. for the u12 field. */ | |
2229 | ||
2230 | static bfd_reloc_status_type | |
2231 | elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation, | |
2232 | contents, value) | |
2233 | struct bfd_link_info *info; | |
2234 | bfd *input_bfd; | |
2235 | asection *input_section; | |
2236 | Elf_Internal_Rela *relocation; | |
2237 | bfd_byte *contents; | |
2238 | bfd_vma value; | |
2239 | { | |
2240 | bfd_vma insn; | |
2241 | bfd_vma gp; | |
2242 | struct bfd_link_hash_entry *h; | |
2243 | bfd_vma mask; | |
2244 | ||
2245 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); | |
2246 | ||
2247 | gp = (h->u.def.value | |
2248 | + h->u.def.section->output_section->vma | |
2249 | + h->u.def.section->output_offset); | |
2250 | ||
2251 | value -= input_section->output_section->vma; | |
2252 | value -= (gp - input_section->output_section->vma); | |
4e5ba5b7 DB |
2253 | |
2254 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2255 | ||
2256 | value += relocation->r_addend; | |
2257 | ||
2258 | if ((long) value > 0x7ff || (long) value < -0x800) | |
2259 | return bfd_reloc_overflow; | |
2260 | ||
2261 | /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */ | |
2262 | mask = 0x3f03f; | |
2263 | insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f); | |
2264 | ||
2265 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
2266 | ||
2267 | return bfd_reloc_ok; | |
2268 | } | |
2269 | ||
2270 | /* Handle an FRV ELF HI16 reloc. */ | |
2271 | ||
2272 | static bfd_reloc_status_type | |
2273 | elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value) | |
2274 | bfd *input_bfd; | |
2275 | Elf_Internal_Rela *relhi; | |
2276 | bfd_byte *contents; | |
2277 | bfd_vma value; | |
2278 | { | |
2279 | bfd_vma insn; | |
2280 | ||
2281 | insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); | |
2282 | ||
2283 | value += relhi->r_addend; | |
2284 | value = ((value >> 16) & 0xffff); | |
2285 | ||
2286 | insn = (insn & 0xffff0000) | value; | |
2287 | ||
2288 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2289 | return bfd_reloc_overflow; | |
2290 | ||
2291 | bfd_put_32 (input_bfd, insn, contents + relhi->r_offset); | |
2292 | return bfd_reloc_ok; | |
2293 | ||
2294 | } | |
2295 | static bfd_reloc_status_type | |
2296 | elf32_frv_relocate_lo16 (input_bfd, rello, contents, value) | |
2297 | bfd *input_bfd; | |
2298 | Elf_Internal_Rela *rello; | |
2299 | bfd_byte *contents; | |
2300 | bfd_vma value; | |
2301 | { | |
2302 | bfd_vma insn; | |
2303 | ||
2304 | insn = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
2305 | ||
2306 | value += rello->r_addend; | |
2307 | value = value & 0xffff; | |
2308 | ||
2309 | insn = (insn & 0xffff0000) | value; | |
2310 | ||
2311 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2312 | return bfd_reloc_overflow; | |
2313 | ||
2314 | bfd_put_32 (input_bfd, insn, contents + rello->r_offset); | |
2315 | return bfd_reloc_ok; | |
2316 | } | |
2317 | ||
2318 | /* Perform the relocation for the CALL label24 instruction. */ | |
2319 | ||
2320 | static bfd_reloc_status_type | |
2321 | elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value) | |
2322 | bfd *input_bfd; | |
2323 | asection *input_section; | |
2324 | Elf_Internal_Rela *rello; | |
2325 | bfd_byte *contents; | |
2326 | bfd_vma value; | |
2327 | { | |
2328 | bfd_vma insn; | |
2329 | bfd_vma label6; | |
2330 | bfd_vma label18; | |
2331 | ||
2332 | /* The format for the call instruction is: | |
2333 | ||
b34976b6 | 2334 | 0 000000 0001111 000000000000000000 |
4e5ba5b7 DB |
2335 | label6 opcode label18 |
2336 | ||
2337 | The branch calculation is: pc + (4*label24) | |
2338 | where label24 is the concatenation of label6 and label18. */ | |
2339 | ||
2340 | /* Grab the instruction. */ | |
2341 | insn = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
2342 | ||
2343 | value -= input_section->output_section->vma + input_section->output_offset; | |
2344 | value -= rello->r_offset; | |
2345 | value += rello->r_addend; | |
2346 | ||
2347 | value = value >> 2; | |
2348 | ||
2349 | label6 = value & 0xfc0000; | |
2350 | label6 = label6 << 7; | |
2351 | ||
2352 | label18 = value & 0x3ffff; | |
2353 | ||
2354 | insn = insn & 0x803c0000; | |
2355 | insn = insn | label6; | |
2356 | insn = insn | label18; | |
2357 | ||
2358 | bfd_put_32 (input_bfd, insn, contents + rello->r_offset); | |
2359 | ||
2360 | return bfd_reloc_ok; | |
2361 | } | |
2362 | ||
2363 | static bfd_reloc_status_type | |
b34976b6 AM |
2364 | elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation, |
2365 | contents, value) | |
4e5ba5b7 DB |
2366 | struct bfd_link_info *info; |
2367 | bfd *input_bfd; | |
2368 | asection *input_section; | |
2369 | Elf_Internal_Rela *relocation; | |
2370 | bfd_byte *contents; | |
2371 | bfd_vma value; | |
2372 | { | |
2373 | bfd_vma insn; | |
2374 | bfd_vma gp; | |
2375 | struct bfd_link_hash_entry *h; | |
2376 | ||
b34976b6 | 2377 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); |
4e5ba5b7 DB |
2378 | |
2379 | gp = (h->u.def.value | |
2380 | + h->u.def.section->output_section->vma | |
2381 | + h->u.def.section->output_offset); | |
2382 | ||
2383 | value -= input_section->output_section->vma; | |
2384 | value -= (gp - input_section->output_section->vma); | |
2385 | value += relocation->r_addend; | |
2386 | value = ((value >> 16) & 0xffff); | |
2387 | ||
2388 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2389 | return bfd_reloc_overflow; | |
2390 | ||
2391 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2392 | insn = (insn & 0xffff0000) | value; | |
2393 | ||
2394 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
2395 | return bfd_reloc_ok; | |
2396 | } | |
2397 | ||
2398 | static bfd_reloc_status_type | |
b34976b6 AM |
2399 | elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation, |
2400 | contents, value) | |
4e5ba5b7 DB |
2401 | struct bfd_link_info *info; |
2402 | bfd *input_bfd; | |
2403 | asection *input_section; | |
2404 | Elf_Internal_Rela *relocation; | |
2405 | bfd_byte *contents; | |
2406 | bfd_vma value; | |
2407 | { | |
2408 | bfd_vma insn; | |
2409 | bfd_vma gp; | |
2410 | struct bfd_link_hash_entry *h; | |
2411 | ||
b34976b6 | 2412 | h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); |
4e5ba5b7 DB |
2413 | |
2414 | gp = (h->u.def.value | |
2415 | + h->u.def.section->output_section->vma | |
2416 | + h->u.def.section->output_offset); | |
2417 | ||
2418 | value -= input_section->output_section->vma; | |
2419 | value -= (gp - input_section->output_section->vma); | |
2420 | value += relocation->r_addend; | |
2421 | value = value & 0xffff; | |
2422 | ||
2423 | if ((long) value > 0xffff || (long) value < -0x10000) | |
2424 | return bfd_reloc_overflow; | |
2425 | ||
2426 | insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); | |
2427 | insn = (insn & 0xffff0000) | value; | |
2428 | ||
2429 | bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); | |
2430 | ||
2431 | return bfd_reloc_ok; | |
2432 | } | |
2433 | ||
2434 | static reloc_howto_type * | |
2435 | frv_reloc_type_lookup (abfd, code) | |
b34976b6 | 2436 | bfd *abfd ATTRIBUTE_UNUSED; |
4e5ba5b7 DB |
2437 | bfd_reloc_code_real_type code; |
2438 | { | |
2439 | switch (code) | |
2440 | { | |
2441 | default: | |
2442 | break; | |
2443 | ||
2444 | case BFD_RELOC_NONE: | |
2445 | return &elf32_frv_howto_table[ (int) R_FRV_NONE]; | |
b34976b6 | 2446 | |
4e5ba5b7 | 2447 | case BFD_RELOC_32: |
51532845 AO |
2448 | if (elf_elfheader (abfd)->e_type == ET_EXEC |
2449 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2450 | return &elf32_frv_rel_32_howto; | |
2451 | /* Fall through. */ | |
4e5ba5b7 DB |
2452 | case BFD_RELOC_CTOR: |
2453 | return &elf32_frv_howto_table[ (int) R_FRV_32]; | |
2454 | ||
2455 | case BFD_RELOC_FRV_LABEL16: | |
2456 | return &elf32_frv_howto_table[ (int) R_FRV_LABEL16]; | |
2457 | ||
2458 | case BFD_RELOC_FRV_LABEL24: | |
2459 | return &elf32_frv_howto_table[ (int) R_FRV_LABEL24]; | |
2460 | ||
2461 | case BFD_RELOC_FRV_LO16: | |
2462 | return &elf32_frv_howto_table[ (int) R_FRV_LO16]; | |
2463 | ||
2464 | case BFD_RELOC_FRV_HI16: | |
2465 | return &elf32_frv_howto_table[ (int) R_FRV_HI16]; | |
2466 | ||
2467 | case BFD_RELOC_FRV_GPREL12: | |
2468 | return &elf32_frv_howto_table[ (int) R_FRV_GPREL12]; | |
2469 | ||
2470 | case BFD_RELOC_FRV_GPRELU12: | |
2471 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12]; | |
2472 | ||
2473 | case BFD_RELOC_FRV_GPREL32: | |
2474 | return &elf32_frv_howto_table[ (int) R_FRV_GPREL32]; | |
2475 | ||
2476 | case BFD_RELOC_FRV_GPRELHI: | |
2477 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI]; | |
2478 | ||
2479 | case BFD_RELOC_FRV_GPRELLO: | |
2480 | return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO]; | |
2481 | ||
51532845 AO |
2482 | case BFD_RELOC_FRV_GOT12: |
2483 | return &elf32_frv_howto_table[ (int) R_FRV_GOT12]; | |
2484 | ||
2485 | case BFD_RELOC_FRV_GOTHI: | |
2486 | return &elf32_frv_howto_table[ (int) R_FRV_GOTHI]; | |
2487 | ||
2488 | case BFD_RELOC_FRV_GOTLO: | |
2489 | return &elf32_frv_howto_table[ (int) R_FRV_GOTLO]; | |
2490 | ||
2491 | case BFD_RELOC_FRV_FUNCDESC: | |
2492 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2493 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2494 | return &elf32_frv_rel_funcdesc_howto; | |
2495 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC]; | |
2496 | ||
2497 | case BFD_RELOC_FRV_FUNCDESC_GOT12: | |
2498 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12]; | |
2499 | ||
2500 | case BFD_RELOC_FRV_FUNCDESC_GOTHI: | |
2501 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI]; | |
2502 | ||
2503 | case BFD_RELOC_FRV_FUNCDESC_GOTLO: | |
2504 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO]; | |
2505 | ||
2506 | case BFD_RELOC_FRV_FUNCDESC_VALUE: | |
2507 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2508 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2509 | return &elf32_frv_rel_funcdesc_value_howto; | |
2510 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE]; | |
2511 | ||
2512 | case BFD_RELOC_FRV_FUNCDESC_GOTOFF12: | |
2513 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12]; | |
2514 | ||
2515 | case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI: | |
2516 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI]; | |
2517 | ||
2518 | case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO: | |
2519 | return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO]; | |
2520 | ||
2521 | case BFD_RELOC_FRV_GOTOFF12: | |
2522 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12]; | |
2523 | ||
2524 | case BFD_RELOC_FRV_GOTOFFHI: | |
2525 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI]; | |
2526 | ||
2527 | case BFD_RELOC_FRV_GOTOFFLO: | |
2528 | return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO]; | |
2529 | ||
90219bd0 AO |
2530 | case BFD_RELOC_FRV_GETTLSOFF: |
2531 | return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF]; | |
2532 | ||
2533 | case BFD_RELOC_FRV_TLSDESC_VALUE: | |
2534 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2535 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2536 | return &elf32_frv_rel_tlsdesc_value_howto; | |
2537 | return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE]; | |
2538 | ||
2539 | case BFD_RELOC_FRV_GOTTLSDESC12: | |
2540 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12]; | |
2541 | ||
2542 | case BFD_RELOC_FRV_GOTTLSDESCHI: | |
2543 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI]; | |
2544 | ||
2545 | case BFD_RELOC_FRV_GOTTLSDESCLO: | |
2546 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO]; | |
2547 | ||
2548 | case BFD_RELOC_FRV_TLSMOFF12: | |
2549 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12]; | |
2550 | ||
2551 | case BFD_RELOC_FRV_TLSMOFFHI: | |
2552 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI]; | |
2553 | ||
2554 | case BFD_RELOC_FRV_TLSMOFFLO: | |
2555 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO]; | |
2556 | ||
2557 | case BFD_RELOC_FRV_GOTTLSOFF12: | |
2558 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12]; | |
2559 | ||
2560 | case BFD_RELOC_FRV_GOTTLSOFFHI: | |
2561 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI]; | |
2562 | ||
2563 | case BFD_RELOC_FRV_GOTTLSOFFLO: | |
2564 | return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO]; | |
2565 | ||
2566 | case BFD_RELOC_FRV_TLSOFF: | |
2567 | if (elf_elfheader (abfd)->e_type == ET_EXEC | |
2568 | || elf_elfheader (abfd)->e_type == ET_DYN) | |
2569 | return &elf32_frv_rel_tlsoff_howto; | |
2570 | return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF]; | |
2571 | ||
2572 | case BFD_RELOC_FRV_TLSDESC_RELAX: | |
2573 | return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX]; | |
2574 | ||
2575 | case BFD_RELOC_FRV_GETTLSOFF_RELAX: | |
2576 | return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX]; | |
2577 | ||
2578 | case BFD_RELOC_FRV_TLSOFF_RELAX: | |
2579 | return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX]; | |
2580 | ||
2581 | case BFD_RELOC_FRV_TLSMOFF: | |
2582 | return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF]; | |
2583 | ||
4e5ba5b7 DB |
2584 | case BFD_RELOC_VTABLE_INHERIT: |
2585 | return &elf32_frv_vtinherit_howto; | |
2586 | ||
2587 | case BFD_RELOC_VTABLE_ENTRY: | |
2588 | return &elf32_frv_vtentry_howto; | |
2589 | } | |
2590 | ||
2591 | return NULL; | |
2592 | } | |
2593 | ||
157090f7 AM |
2594 | static reloc_howto_type * |
2595 | frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) | |
2596 | { | |
2597 | unsigned int i; | |
2598 | ||
2599 | for (i = 0; | |
2600 | i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]); | |
2601 | i++) | |
2602 | if (elf32_frv_howto_table[i].name != NULL | |
2603 | && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0) | |
2604 | return &elf32_frv_howto_table[i]; | |
2605 | ||
2606 | if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0) | |
2607 | return &elf32_frv_vtinherit_howto; | |
2608 | if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0) | |
2609 | return &elf32_frv_vtentry_howto; | |
2610 | ||
2611 | return NULL; | |
2612 | } | |
2613 | ||
4e5ba5b7 DB |
2614 | /* Set the howto pointer for an FRV ELF reloc. */ |
2615 | ||
2616 | static void | |
2617 | frv_info_to_howto_rela (abfd, cache_ptr, dst) | |
b34976b6 AM |
2618 | bfd *abfd ATTRIBUTE_UNUSED; |
2619 | arelent *cache_ptr; | |
2620 | Elf_Internal_Rela *dst; | |
4e5ba5b7 DB |
2621 | { |
2622 | unsigned int r_type; | |
2623 | ||
2624 | r_type = ELF32_R_TYPE (dst->r_info); | |
2625 | switch (r_type) | |
2626 | { | |
2627 | case R_FRV_GNU_VTINHERIT: | |
2628 | cache_ptr->howto = &elf32_frv_vtinherit_howto; | |
2629 | break; | |
2630 | ||
2631 | case R_FRV_GNU_VTENTRY: | |
2632 | cache_ptr->howto = &elf32_frv_vtentry_howto; | |
2633 | break; | |
2634 | ||
2635 | default: | |
2636 | cache_ptr->howto = & elf32_frv_howto_table [r_type]; | |
2637 | break; | |
2638 | } | |
2639 | } | |
51532845 AO |
2640 | |
2641 | /* Set the howto pointer for an FRV ELF REL reloc. */ | |
2642 | static void | |
43850d5b AO |
2643 | frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, |
2644 | arelent *cache_ptr, Elf_Internal_Rela *dst) | |
51532845 AO |
2645 | { |
2646 | unsigned int r_type; | |
2647 | ||
2648 | r_type = ELF32_R_TYPE (dst->r_info); | |
2649 | switch (r_type) | |
2650 | { | |
2651 | case R_FRV_32: | |
2652 | cache_ptr->howto = &elf32_frv_rel_32_howto; | |
2653 | break; | |
2654 | ||
2655 | case R_FRV_FUNCDESC: | |
2656 | cache_ptr->howto = &elf32_frv_rel_funcdesc_howto; | |
2657 | break; | |
2658 | ||
2659 | case R_FRV_FUNCDESC_VALUE: | |
2660 | cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto; | |
2661 | break; | |
2662 | ||
90219bd0 AO |
2663 | case R_FRV_TLSDESC_VALUE: |
2664 | cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto; | |
2665 | break; | |
2666 | ||
2667 | case R_FRV_TLSOFF: | |
2668 | cache_ptr->howto = &elf32_frv_rel_tlsoff_howto; | |
2669 | break; | |
2670 | ||
51532845 AO |
2671 | default: |
2672 | cache_ptr->howto = NULL; | |
2673 | break; | |
2674 | } | |
2675 | } | |
4e5ba5b7 DB |
2676 | \f |
2677 | /* Perform a single relocation. By default we use the standard BFD | |
2678 | routines, but a few relocs, we have to do them ourselves. */ | |
2679 | ||
2680 | static bfd_reloc_status_type | |
b34976b6 AM |
2681 | frv_final_link_relocate (howto, input_bfd, input_section, contents, rel, |
2682 | relocation) | |
2683 | reloc_howto_type *howto; | |
2684 | bfd *input_bfd; | |
2685 | asection *input_section; | |
2686 | bfd_byte *contents; | |
2687 | Elf_Internal_Rela *rel; | |
2688 | bfd_vma relocation; | |
4e5ba5b7 DB |
2689 | { |
2690 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
2691 | contents, rel->r_offset, relocation, | |
2692 | rel->r_addend); | |
2693 | } | |
2694 | ||
2695 | \f | |
2696 | /* Relocate an FRV ELF section. | |
4e5ba5b7 DB |
2697 | |
2698 | The RELOCATE_SECTION function is called by the new ELF backend linker | |
2699 | to handle the relocations for a section. | |
2700 | ||
2701 | The relocs are always passed as Rela structures; if the section | |
2702 | actually uses Rel structures, the r_addend field will always be | |
2703 | zero. | |
2704 | ||
2705 | This function is responsible for adjusting the section contents as | |
1049f94e | 2706 | necessary, and (if using Rela relocs and generating a relocatable |
4e5ba5b7 DB |
2707 | output file) adjusting the reloc addend as necessary. |
2708 | ||
2709 | This function does not have to worry about setting the reloc | |
2710 | address or the reloc symbol index. | |
2711 | ||
2712 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
2713 | ||
2714 | LOCAL_SECTIONS is an array giving the section in the input file | |
2715 | corresponding to the st_shndx field of each local symbol. | |
2716 | ||
2717 | The global hash table entry for the global symbols can be found | |
2718 | via elf_sym_hashes (input_bfd). | |
2719 | ||
1049f94e | 2720 | When generating relocatable output, this function must handle |
4e5ba5b7 DB |
2721 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
2722 | going to be the section symbol corresponding to the output | |
2723 | section, which means that the addend must be adjusted | |
2724 | accordingly. */ | |
2725 | ||
b34976b6 | 2726 | static bfd_boolean |
4e5ba5b7 | 2727 | elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section, |
de2d743e | 2728 | contents, relocs, local_syms, local_sections) |
b34976b6 AM |
2729 | bfd *output_bfd ATTRIBUTE_UNUSED; |
2730 | struct bfd_link_info *info; | |
2731 | bfd *input_bfd; | |
2732 | asection *input_section; | |
2733 | bfd_byte *contents; | |
2734 | Elf_Internal_Rela *relocs; | |
2735 | Elf_Internal_Sym *local_syms; | |
2736 | asection **local_sections; | |
4e5ba5b7 | 2737 | { |
b34976b6 AM |
2738 | Elf_Internal_Shdr *symtab_hdr; |
2739 | struct elf_link_hash_entry **sym_hashes; | |
2740 | Elf_Internal_Rela *rel; | |
2741 | Elf_Internal_Rela *relend; | |
90219bd0 | 2742 | unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment, |
51532845 AO |
2743 | check_segment[2]; |
2744 | int silence_segment_error = !(info->shared || info->pie); | |
90219bd0 | 2745 | unsigned long insn; |
4e5ba5b7 DB |
2746 | |
2747 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
2748 | sym_hashes = elf_sym_hashes (input_bfd); | |
2749 | relend = relocs + input_section->reloc_count; | |
2750 | ||
43850d5b AO |
2751 | isec_segment = _frvfdpic_osec_to_segment (output_bfd, |
2752 | input_section->output_section); | |
2753 | if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info)) | |
2754 | got_segment = _frvfdpic_osec_to_segment (output_bfd, | |
2755 | frvfdpic_got_section (info) | |
2756 | ->output_section); | |
51532845 AO |
2757 | else |
2758 | got_segment = -1; | |
43850d5b AO |
2759 | if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info)) |
2760 | gprel_segment = _frvfdpic_osec_to_segment (output_bfd, | |
2761 | frvfdpic_gotfixup_section (info) | |
2762 | ->output_section); | |
51532845 AO |
2763 | else |
2764 | gprel_segment = -1; | |
90219bd0 | 2765 | if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info)) |
43850d5b AO |
2766 | plt_segment = _frvfdpic_osec_to_segment (output_bfd, |
2767 | frvfdpic_plt_section (info) | |
2768 | ->output_section); | |
51532845 AO |
2769 | else |
2770 | plt_segment = -1; | |
90219bd0 AO |
2771 | if (elf_hash_table (info)->tls_sec) |
2772 | tls_segment = _frvfdpic_osec_to_segment (output_bfd, | |
2773 | elf_hash_table (info)->tls_sec); | |
2774 | else | |
2775 | tls_segment = -1; | |
51532845 | 2776 | |
4e5ba5b7 DB |
2777 | for (rel = relocs; rel < relend; rel ++) |
2778 | { | |
b34976b6 AM |
2779 | reloc_howto_type *howto; |
2780 | unsigned long r_symndx; | |
2781 | Elf_Internal_Sym *sym; | |
2782 | asection *sec; | |
2783 | struct elf_link_hash_entry *h; | |
2784 | bfd_vma relocation; | |
2785 | bfd_reloc_status_type r; | |
2786 | const char * name = NULL; | |
2787 | int r_type; | |
51532845 | 2788 | asection *osec; |
43850d5b | 2789 | struct frvfdpic_relocs_info *picrel; |
51532845 AO |
2790 | bfd_vma orig_addend = rel->r_addend; |
2791 | ||
2792 | r_type = ELF32_R_TYPE (rel->r_info); | |
2793 | ||
2794 | if ( r_type == R_FRV_GNU_VTINHERIT | |
2795 | || r_type == R_FRV_GNU_VTENTRY) | |
2796 | continue; | |
2797 | ||
51532845 AO |
2798 | r_symndx = ELF32_R_SYM (rel->r_info); |
2799 | howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info); | |
2800 | h = NULL; | |
2801 | sym = NULL; | |
2802 | sec = NULL; | |
2803 | ||
2804 | if (r_symndx < symtab_hdr->sh_info) | |
2805 | { | |
2806 | sym = local_syms + r_symndx; | |
2807 | osec = sec = local_sections [r_symndx]; | |
2808 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
2809 | ||
2810 | name = bfd_elf_string_from_elf_section | |
2811 | (input_bfd, symtab_hdr->sh_link, sym->st_name); | |
2812 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; | |
2813 | } | |
2814 | else | |
2815 | { | |
ab96bf03 AM |
2816 | bfd_boolean warned; |
2817 | bfd_boolean unresolved_reloc; | |
51532845 | 2818 | |
ab96bf03 AM |
2819 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
2820 | r_symndx, symtab_hdr, sym_hashes, | |
2821 | h, sec, relocation, | |
2822 | unresolved_reloc, warned); | |
2823 | osec = sec; | |
2824 | } | |
51532845 | 2825 | |
ab96bf03 AM |
2826 | if (sec != NULL && elf_discarded_section (sec)) |
2827 | { | |
2828 | /* For relocs against symbols from removed linkonce sections, | |
2829 | or sections discarded by a linker script, we just want the | |
2830 | section contents zeroed. Avoid any special processing. */ | |
2831 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); | |
2832 | rel->r_info = 0; | |
2833 | rel->r_addend = 0; | |
2834 | continue; | |
2835 | } | |
51532845 | 2836 | |
ab96bf03 AM |
2837 | if (info->relocatable) |
2838 | continue; | |
2839 | ||
2840 | if (r_type != R_FRV_TLSMOFF | |
2841 | && h != NULL | |
2842 | && (h->root.type == bfd_link_hash_defined | |
2843 | || h->root.type == bfd_link_hash_defweak) | |
2844 | && !FRVFDPIC_SYM_LOCAL (info, h)) | |
2845 | { | |
2846 | osec = sec = NULL; | |
2847 | relocation = 0; | |
90219bd0 AO |
2848 | } |
2849 | ||
2850 | switch (r_type) | |
2851 | { | |
2852 | case R_FRV_LABEL24: | |
2853 | case R_FRV_32: | |
2854 | if (! IS_FDPIC (output_bfd)) | |
2855 | goto non_fdpic; | |
2856 | ||
2857 | case R_FRV_GOT12: | |
2858 | case R_FRV_GOTHI: | |
2859 | case R_FRV_GOTLO: | |
2860 | case R_FRV_FUNCDESC_GOT12: | |
2861 | case R_FRV_FUNCDESC_GOTHI: | |
2862 | case R_FRV_FUNCDESC_GOTLO: | |
2863 | case R_FRV_GOTOFF12: | |
2864 | case R_FRV_GOTOFFHI: | |
2865 | case R_FRV_GOTOFFLO: | |
2866 | case R_FRV_FUNCDESC_GOTOFF12: | |
2867 | case R_FRV_FUNCDESC_GOTOFFHI: | |
2868 | case R_FRV_FUNCDESC_GOTOFFLO: | |
2869 | case R_FRV_FUNCDESC: | |
2870 | case R_FRV_FUNCDESC_VALUE: | |
2871 | case R_FRV_GETTLSOFF: | |
2872 | case R_FRV_TLSDESC_VALUE: | |
2873 | case R_FRV_GOTTLSDESC12: | |
2874 | case R_FRV_GOTTLSDESCHI: | |
2875 | case R_FRV_GOTTLSDESCLO: | |
2876 | case R_FRV_TLSMOFF12: | |
2877 | case R_FRV_TLSMOFFHI: | |
2878 | case R_FRV_TLSMOFFLO: | |
2879 | case R_FRV_GOTTLSOFF12: | |
2880 | case R_FRV_GOTTLSOFFHI: | |
2881 | case R_FRV_GOTTLSOFFLO: | |
2882 | case R_FRV_TLSOFF: | |
2883 | case R_FRV_TLSDESC_RELAX: | |
2884 | case R_FRV_GETTLSOFF_RELAX: | |
2885 | case R_FRV_TLSOFF_RELAX: | |
2886 | case R_FRV_TLSMOFF: | |
2887 | if (h != NULL) | |
2888 | picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info | |
2889 | (info), input_bfd, h, | |
2890 | orig_addend, INSERT); | |
2891 | else | |
2892 | /* In order to find the entry we created before, we must | |
2893 | use the original addend, not the one that may have been | |
2894 | modified by _bfd_elf_rela_local_sym(). */ | |
2895 | picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info | |
2896 | (info), input_bfd, r_symndx, | |
2897 | orig_addend, INSERT); | |
2898 | if (! picrel) | |
2899 | return FALSE; | |
2900 | ||
2901 | if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info, | |
2902 | osec, sym, | |
2903 | rel->r_addend)) | |
2904 | { | |
2905 | (*_bfd_error_handler) | |
303e4c21 AO |
2906 | (_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"), |
2907 | input_bfd, input_section, rel->r_offset, name, rel->r_addend); | |
90219bd0 | 2908 | return FALSE; |
90219bd0 AO |
2909 | } |
2910 | ||
2911 | break; | |
2912 | ||
2913 | default: | |
2914 | non_fdpic: | |
2915 | picrel = NULL; | |
2916 | if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) | |
2917 | { | |
2918 | info->callbacks->warning | |
2919 | (info, _("relocation references symbol not defined in the module"), | |
2920 | name, input_bfd, input_section, rel->r_offset); | |
2921 | return FALSE; | |
2922 | } | |
2923 | break; | |
2924 | } | |
2925 | ||
2926 | switch (r_type) | |
2927 | { | |
2928 | case R_FRV_GETTLSOFF: | |
2929 | case R_FRV_TLSDESC_VALUE: | |
2930 | case R_FRV_GOTTLSDESC12: | |
2931 | case R_FRV_GOTTLSDESCHI: | |
2932 | case R_FRV_GOTTLSDESCLO: | |
2933 | case R_FRV_TLSMOFF12: | |
2934 | case R_FRV_TLSMOFFHI: | |
2935 | case R_FRV_TLSMOFFLO: | |
2936 | case R_FRV_GOTTLSOFF12: | |
2937 | case R_FRV_GOTTLSOFFHI: | |
2938 | case R_FRV_GOTTLSOFFLO: | |
2939 | case R_FRV_TLSOFF: | |
2940 | case R_FRV_TLSDESC_RELAX: | |
2941 | case R_FRV_GETTLSOFF_RELAX: | |
2942 | case R_FRV_TLSOFF_RELAX: | |
2943 | case R_FRV_TLSMOFF: | |
2944 | if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec))) | |
2945 | relocation += tls_biased_base (info); | |
2946 | break; | |
2947 | ||
2948 | default: | |
2949 | break; | |
2950 | } | |
2951 | ||
2952 | /* Try to apply TLS relaxations. */ | |
2953 | if (1) | |
2954 | switch (r_type) | |
2955 | { | |
2956 | ||
2957 | #define LOCAL_EXEC_P(info, picrel) \ | |
2958 | ((info)->executable \ | |
2959 | && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h))) | |
2960 | #define INITIAL_EXEC_P(info, picrel) \ | |
2961 | (((info)->executable || (info)->flags & DF_STATIC_TLS) \ | |
2962 | && (picrel)->tlsoff_entry) | |
2963 | ||
2964 | #define IN_RANGE_FOR_OFST12_P(value) \ | |
2965 | ((bfd_vma)((value) + 2048) < (bfd_vma)4096) | |
2966 | #define IN_RANGE_FOR_SETLOS_P(value) \ | |
2967 | ((bfd_vma)((value) + 32768) < (bfd_vma)65536) | |
2968 | #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \ | |
2969 | (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info))) | |
2970 | ||
2971 | #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ | |
2972 | (LOCAL_EXEC_P ((info), (picrel)) \ | |
2973 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) | |
2974 | #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \ | |
2975 | (INITIAL_EXEC_P ((info), (picrel)) \ | |
2976 | && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry)) | |
2977 | ||
2978 | #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \ | |
2979 | (LOCAL_EXEC_P ((info), (picrel))) | |
2980 | #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \ | |
2981 | (INITIAL_EXEC_P ((info), (picrel))) | |
3b36f7e6 | 2982 | |
90219bd0 AO |
2983 | #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ |
2984 | (LOCAL_EXEC_P ((info), (picrel)) \ | |
2985 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) | |
2986 | ||
2987 | case R_FRV_GETTLSOFF: | |
2988 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
2989 | ||
2990 | /* Is this a call instruction? */ | |
2991 | if ((insn & (unsigned long)0x01fc0000) != 0x003c0000) | |
2992 | { | |
2993 | r = info->callbacks->warning | |
2994 | (info, | |
2995 | _("R_FRV_GETTLSOFF not applied to a call instruction"), | |
2996 | name, input_bfd, input_section, rel->r_offset); | |
2997 | return FALSE; | |
2998 | } | |
3b36f7e6 | 2999 | |
90219bd0 AO |
3000 | if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel, |
3001 | relocation + rel->r_addend)) | |
3002 | { | |
3003 | /* Replace the call instruction (except the packing bit) | |
3004 | with setlos #tlsmofflo(symbol+offset), gr9. */ | |
3005 | insn &= (unsigned long)0x80000000; | |
3006 | insn |= (unsigned long)0x12fc0000; | |
3007 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3008 | ||
3009 | r_type = R_FRV_TLSMOFFLO; | |
3010 | howto = elf32_frv_howto_table + r_type; | |
3011 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3012 | } | |
3013 | ||
3014 | else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel)) | |
3015 | { | |
3016 | /* Replace the call instruction (except the packing bit) | |
3017 | with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */ | |
3018 | insn &= (unsigned long)0x80000000; | |
3019 | insn |= (unsigned long)0x12c8f000; | |
3020 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3021 | ||
3022 | r_type = R_FRV_GOTTLSOFF12; | |
3023 | howto = elf32_frv_howto_table + r_type; | |
3024 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3025 | } | |
3026 | ||
3027 | break; | |
3028 | ||
3029 | case R_FRV_GOTTLSDESC12: | |
3030 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3031 | ||
3032 | /* Is this an lddi instruction? */ | |
3033 | if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000) | |
3034 | { | |
3035 | r = info->callbacks->warning | |
3036 | (info, | |
3037 | _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"), | |
3038 | name, input_bfd, input_section, rel->r_offset); | |
3039 | return FALSE; | |
3040 | } | |
3041 | ||
3042 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3043 | relocation + rel->r_addend) | |
3044 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3045 | info)) | |
3046 | { | |
3047 | /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC | |
3048 | with setlos #tlsmofflo(symbol+offset), gr<C+1>. | |
3049 | Preserve the packing bit. */ | |
3050 | insn = (insn & (unsigned long)0x80000000) | |
3051 | | ((insn + (unsigned long)0x02000000) | |
3052 | & (unsigned long)0x7e000000); | |
3053 | insn |= (unsigned long)0x00fc0000; | |
3054 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3055 | ||
3056 | r_type = R_FRV_TLSMOFFLO; | |
3057 | howto = elf32_frv_howto_table + r_type; | |
3058 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3059 | } | |
3060 | ||
3061 | else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3062 | relocation + rel->r_addend)) | |
3063 | { | |
3064 | /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC | |
3065 | with sethi #tlsmoffhi(symbol+offset), gr<C+1>. | |
3066 | Preserve the packing bit. */ | |
3067 | insn = (insn & (unsigned long)0x80000000) | |
3068 | | ((insn + (unsigned long)0x02000000) | |
3069 | & (unsigned long)0x7e000000); | |
3070 | insn |= (unsigned long)0x00f80000; | |
3071 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3072 | ||
3073 | r_type = R_FRV_TLSMOFFHI; | |
3074 | howto = elf32_frv_howto_table + r_type; | |
3075 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3076 | } | |
3077 | ||
3078 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3079 | { | |
3080 | /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC | |
3081 | with ldi @(grB, #gottlsoff12(symbol+offset), | |
3082 | gr<C+1>. Preserve the packing bit. If gottlsoff12 | |
3083 | overflows, we'll error out, but that's sort-of ok, | |
3084 | since we'd started with gottlsdesc12, that's actually | |
3085 | more demanding. Compiling with -fPIE instead of | |
3086 | -fpie would fix it; linking with --relax should fix | |
3087 | it as well. */ | |
3088 | insn = (insn & (unsigned long)0x80cbf000) | |
3089 | | ((insn + (unsigned long)0x02000000) | |
3090 | & (unsigned long)0x7e000000); | |
3091 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3092 | ||
3093 | r_type = R_FRV_GOTTLSOFF12; | |
3094 | howto = elf32_frv_howto_table + r_type; | |
3095 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3096 | } | |
3097 | ||
3098 | break; | |
3099 | ||
3100 | case R_FRV_GOTTLSDESCHI: | |
3101 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3102 | ||
3103 | /* Is this a sethi instruction? */ | |
3104 | if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) | |
3105 | { | |
3106 | r = info->callbacks->warning | |
3107 | (info, | |
3108 | _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"), | |
3109 | name, input_bfd, input_section, rel->r_offset); | |
3110 | return FALSE; | |
3111 | } | |
3112 | ||
3113 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3114 | relocation + rel->r_addend) | |
3115 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3116 | && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))) | |
3117 | { | |
3118 | /* Replace sethi with a nop. Preserve the packing bit. */ | |
3119 | insn &= (unsigned long)0x80000000; | |
3120 | insn |= (unsigned long)0x00880000; | |
3121 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3122 | ||
3123 | /* Nothing to relocate. */ | |
3124 | continue; | |
3125 | } | |
3126 | ||
3127 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3128 | { | |
3129 | /* Simply decay GOTTLSDESC to GOTTLSOFF. */ | |
3130 | r_type = R_FRV_GOTTLSOFFHI; | |
3131 | howto = elf32_frv_howto_table + r_type; | |
3132 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3133 | } | |
3134 | ||
3135 | break; | |
3b36f7e6 | 3136 | |
90219bd0 AO |
3137 | case R_FRV_GOTTLSDESCLO: |
3138 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3139 | ||
3140 | /* Is this a setlo or setlos instruction? */ | |
3141 | if ((insn & (unsigned long)0x01f70000) != 0x00f40000) | |
3142 | { | |
3143 | r = info->callbacks->warning | |
3144 | (info, | |
3145 | _("R_FRV_GOTTLSDESCLO" | |
3146 | " not applied to a setlo or setlos instruction"), | |
3147 | name, input_bfd, input_section, rel->r_offset); | |
3148 | return FALSE; | |
3149 | } | |
3150 | ||
3151 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3152 | relocation + rel->r_addend) | |
3153 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3154 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) | |
3155 | { | |
3156 | /* Replace setlo/setlos with a nop. Preserve the | |
3157 | packing bit. */ | |
3158 | insn &= (unsigned long)0x80000000; | |
3159 | insn |= (unsigned long)0x00880000; | |
3160 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3161 | ||
3162 | /* Nothing to relocate. */ | |
3163 | continue; | |
3164 | } | |
3165 | ||
3166 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3167 | { | |
3168 | /* If the corresponding sethi (if it exists) decayed | |
3169 | to a nop, make sure this becomes (or already is) a | |
3170 | setlos, not setlo. */ | |
3171 | if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)) | |
3172 | { | |
3173 | insn |= (unsigned long)0x00080000; | |
3174 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3175 | } | |
3176 | ||
3177 | /* Simply decay GOTTLSDESC to GOTTLSOFF. */ | |
3178 | r_type = R_FRV_GOTTLSOFFLO; | |
3179 | howto = elf32_frv_howto_table + r_type; | |
3180 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3181 | } | |
3182 | ||
3183 | break; | |
3b36f7e6 | 3184 | |
90219bd0 AO |
3185 | case R_FRV_TLSDESC_RELAX: |
3186 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3187 | ||
3188 | /* Is this an ldd instruction? */ | |
3189 | if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140) | |
3190 | { | |
3191 | r = info->callbacks->warning | |
3192 | (info, | |
3193 | _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"), | |
3194 | name, input_bfd, input_section, rel->r_offset); | |
3195 | return FALSE; | |
3196 | } | |
3197 | ||
3198 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3199 | relocation + rel->r_addend) | |
3200 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3201 | info)) | |
3202 | { | |
3203 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3204 | with setlos #tlsmofflo(symbol+offset), gr<C+1>. | |
3205 | Preserve the packing bit. */ | |
3206 | insn = (insn & (unsigned long)0x80000000) | |
3207 | | ((insn + (unsigned long)0x02000000) | |
3208 | & (unsigned long)0x7e000000); | |
3209 | insn |= (unsigned long)0x00fc0000; | |
3210 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3211 | ||
3212 | r_type = R_FRV_TLSMOFFLO; | |
3213 | howto = elf32_frv_howto_table + r_type; | |
3214 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3215 | } | |
3216 | ||
3217 | else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3218 | relocation + rel->r_addend)) | |
3219 | { | |
3220 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3221 | with sethi #tlsmoffhi(symbol+offset), gr<C+1>. | |
3222 | Preserve the packing bit. */ | |
3223 | insn = (insn & (unsigned long)0x80000000) | |
3224 | | ((insn + (unsigned long)0x02000000) | |
3225 | & (unsigned long)0x7e000000); | |
3226 | insn |= (unsigned long)0x00f80000; | |
3227 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3228 | ||
3229 | r_type = R_FRV_TLSMOFFHI; | |
3230 | howto = elf32_frv_howto_table + r_type; | |
3231 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3232 | } | |
3233 | ||
3234 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3235 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) | |
3236 | { | |
3237 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3238 | with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>. | |
3239 | Preserve the packing bit. */ | |
3240 | insn = (insn & (unsigned long)0x8003f000) | |
3241 | | (unsigned long)0x00c80000 | |
3242 | | ((insn + (unsigned long)0x02000000) | |
3243 | & (unsigned long)0x7e000000); | |
3244 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3245 | ||
3246 | r_type = R_FRV_GOTTLSOFF12; | |
3247 | howto = elf32_frv_howto_table + r_type; | |
3248 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3249 | } | |
3250 | ||
3251 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3252 | { | |
3253 | /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC | |
3254 | with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>. | |
3255 | Preserve the packing bit. */ | |
3256 | insn = (insn & (unsigned long)0x81ffffbf) | |
3257 | | ((insn + (unsigned long)0x02000000) | |
3258 | & (unsigned long)0x7e000000); | |
3259 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3260 | ||
3261 | /* #tlsoff(symbol+offset) is just a relaxation | |
3262 | annotation, so there's nothing left to | |
3263 | relocate. */ | |
3264 | continue; | |
3265 | } | |
3266 | ||
3267 | break; | |
3268 | ||
3269 | case R_FRV_GETTLSOFF_RELAX: | |
3270 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3271 | ||
3272 | /* Is this a calll or callil instruction? */ | |
3273 | if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000) | |
3274 | { | |
3275 | r = info->callbacks->warning | |
3276 | (info, | |
3277 | _("R_FRV_GETTLSOFF_RELAX" | |
3278 | " not applied to a calll instruction"), | |
3279 | name, input_bfd, input_section, rel->r_offset); | |
3280 | return FALSE; | |
3281 | } | |
3282 | ||
3283 | if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3284 | relocation + rel->r_addend) | |
3285 | && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3286 | info)) | |
3287 | { | |
3288 | /* Replace calll with a nop. Preserve the packing bit. */ | |
3289 | insn &= (unsigned long)0x80000000; | |
3290 | insn |= (unsigned long)0x00880000; | |
3291 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3292 | ||
3293 | /* Nothing to relocate. */ | |
3294 | continue; | |
3295 | } | |
3296 | ||
3297 | else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, | |
3298 | relocation + rel->r_addend)) | |
3299 | { | |
3300 | /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9. | |
3301 | Preserve the packing bit. */ | |
3302 | insn &= (unsigned long)0x80000000; | |
3303 | insn |= (unsigned long)0x12f40000; | |
3304 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3305 | ||
3306 | r_type = R_FRV_TLSMOFFLO; | |
3307 | howto = elf32_frv_howto_table + r_type; | |
3308 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3309 | } | |
3310 | ||
3311 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) | |
3312 | { | |
3313 | /* Replace calll with a nop. Preserve the packing bit. */ | |
3314 | insn &= (unsigned long)0x80000000; | |
3315 | insn |= (unsigned long)0x00880000; | |
3316 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3317 | ||
3318 | /* Nothing to relocate. */ | |
3319 | continue; | |
3320 | } | |
3321 | ||
3322 | break; | |
3323 | ||
3324 | case R_FRV_GOTTLSOFF12: | |
3325 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3326 | ||
3327 | /* Is this an ldi instruction? */ | |
3328 | if ((insn & (unsigned long)0x01fc0000) != 0x00c80000) | |
3329 | { | |
3330 | r = info->callbacks->warning | |
3331 | (info, | |
3332 | _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"), | |
3333 | name, input_bfd, input_section, rel->r_offset); | |
3334 | return FALSE; | |
3335 | } | |
3336 | ||
3337 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, | |
3338 | relocation + rel->r_addend)) | |
3339 | { | |
3340 | /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC | |
3341 | with setlos #tlsmofflo(symbol+offset), grC. | |
3342 | Preserve the packing bit. */ | |
3343 | insn &= (unsigned long)0xfe000000; | |
3344 | insn |= (unsigned long)0x00fc0000; | |
3345 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3346 | ||
3347 | r_type = R_FRV_TLSMOFFLO; | |
3348 | howto = elf32_frv_howto_table + r_type; | |
3349 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3350 | } | |
3351 | ||
3352 | break; | |
3353 | ||
3354 | case R_FRV_GOTTLSOFFHI: | |
3355 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3356 | ||
3357 | /* Is this a sethi instruction? */ | |
3358 | if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) | |
3359 | { | |
3360 | r = info->callbacks->warning | |
3361 | (info, | |
3362 | _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"), | |
3363 | name, input_bfd, input_section, rel->r_offset); | |
3364 | return FALSE; | |
3365 | } | |
3366 | ||
3367 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, | |
3368 | relocation + rel->r_addend) | |
3369 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3370 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) | |
3371 | { | |
3372 | /* Replace sethi with a nop. Preserve the packing bit. */ | |
3373 | insn &= (unsigned long)0x80000000; | |
3374 | insn |= (unsigned long)0x00880000; | |
3375 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3376 | ||
3377 | /* Nothing to relocate. */ | |
3378 | continue; | |
3379 | } | |
3380 | ||
3381 | break; | |
3382 | ||
3383 | case R_FRV_GOTTLSOFFLO: | |
3384 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3385 | ||
3386 | /* Is this a setlo or setlos instruction? */ | |
3387 | if ((insn & (unsigned long)0x01f70000) != 0x00f40000) | |
3388 | { | |
3389 | r = info->callbacks->warning | |
3390 | (info, | |
3391 | _("R_FRV_GOTTLSOFFLO" | |
3392 | " not applied to a setlo or setlos instruction"), | |
3393 | name, input_bfd, input_section, rel->r_offset); | |
3394 | return FALSE; | |
3395 | } | |
3396 | ||
3397 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, | |
3398 | relocation + rel->r_addend) | |
3399 | || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) | |
3400 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) | |
3401 | { | |
3402 | /* Replace setlo/setlos with a nop. Preserve the | |
3403 | packing bit. */ | |
3404 | insn &= (unsigned long)0x80000000; | |
3405 | insn |= (unsigned long)0x00880000; | |
3406 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3407 | ||
3408 | /* Nothing to relocate. */ | |
3409 | continue; | |
3410 | } | |
3411 | ||
3412 | break; | |
3413 | ||
3414 | case R_FRV_TLSOFF_RELAX: | |
3415 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3416 | ||
3417 | /* Is this an ld instruction? */ | |
3418 | if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100) | |
3419 | { | |
3420 | r = info->callbacks->warning | |
3421 | (info, | |
3422 | _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"), | |
3423 | name, input_bfd, input_section, rel->r_offset); | |
3424 | return FALSE; | |
3425 | } | |
51532845 | 3426 | |
90219bd0 AO |
3427 | if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, |
3428 | relocation + rel->r_addend)) | |
3429 | { | |
3430 | /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC | |
3431 | with setlos #tlsmofflo(symbol+offset), grC. | |
3432 | Preserve the packing bit. */ | |
3433 | insn &= (unsigned long)0xfe000000; | |
3434 | insn |= (unsigned long)0x00fc0000; | |
3435 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3436 | ||
3437 | r_type = R_FRV_TLSMOFFLO; | |
3438 | howto = elf32_frv_howto_table + r_type; | |
3439 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3440 | } | |
43850d5b | 3441 | |
90219bd0 AO |
3442 | else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) |
3443 | && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) | |
3444 | { | |
3445 | /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC | |
3446 | with ldi @(grB, #gottlsoff12(symbol+offset), grC. | |
3447 | Preserve the packing bit. */ | |
3448 | insn = (insn & (unsigned long)0xfe03f000) | |
3449 | | (unsigned long)0x00c80000;; | |
3450 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3451 | ||
3452 | r_type = R_FRV_GOTTLSOFF12; | |
3453 | howto = elf32_frv_howto_table + r_type; | |
3454 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
3455 | } | |
51532845 | 3456 | |
90219bd0 | 3457 | break; |
51532845 | 3458 | |
90219bd0 AO |
3459 | case R_FRV_TLSMOFFHI: |
3460 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
51532845 | 3461 | |
90219bd0 AO |
3462 | /* Is this a sethi instruction? */ |
3463 | if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) | |
3464 | { | |
3465 | r = info->callbacks->warning | |
3466 | (info, | |
3467 | _("R_FRV_TLSMOFFHI not applied to a sethi instruction"), | |
3468 | name, input_bfd, input_section, rel->r_offset); | |
3469 | return FALSE; | |
3470 | } | |
51532845 | 3471 | |
90219bd0 AO |
3472 | if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, |
3473 | info)) | |
3474 | { | |
3475 | /* Replace sethi with a nop. Preserve the packing bit. */ | |
3476 | insn &= (unsigned long)0x80000000; | |
3477 | insn |= (unsigned long)0x00880000; | |
3478 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3479 | ||
3480 | /* Nothing to relocate. */ | |
3481 | continue; | |
3482 | } | |
3483 | ||
3484 | break; | |
3485 | ||
3486 | case R_FRV_TLSMOFFLO: | |
3487 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3488 | ||
3489 | /* Is this a setlo or setlos instruction? */ | |
3490 | if ((insn & (unsigned long)0x01f70000) != 0x00f40000) | |
3491 | { | |
3492 | r = info->callbacks->warning | |
3493 | (info, | |
3494 | _("R_FRV_TLSMOFFLO" | |
3495 | " not applied to a setlo or setlos instruction"), | |
3496 | name, input_bfd, input_section, rel->r_offset); | |
3497 | return FALSE; | |
3498 | } | |
3499 | ||
3500 | if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, | |
3501 | info)) | |
3502 | /* If the corresponding sethi (if it exists) decayed | |
3503 | to a nop, make sure this becomes (or already is) a | |
3504 | setlos, not setlo. */ | |
3505 | { | |
3506 | insn |= (unsigned long)0x00080000; | |
3507 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
3508 | } | |
3509 | ||
3510 | break; | |
3511 | ||
0e71e495 BE |
3512 | /* |
3513 | There's nothing to relax in these: | |
3b36f7e6 AM |
3514 | R_FRV_TLSDESC_VALUE |
3515 | R_FRV_TLSOFF | |
3516 | R_FRV_TLSMOFF12 | |
3517 | R_FRV_TLSMOFFHI | |
3518 | R_FRV_TLSMOFFLO | |
3519 | R_FRV_TLSMOFF | |
0e71e495 BE |
3520 | */ |
3521 | ||
90219bd0 AO |
3522 | default: |
3523 | break; | |
3524 | } | |
51532845 AO |
3525 | |
3526 | switch (r_type) | |
3527 | { | |
3528 | case R_FRV_LABEL24: | |
3529 | check_segment[0] = isec_segment; | |
43850d5b AO |
3530 | if (! IS_FDPIC (output_bfd)) |
3531 | check_segment[1] = isec_segment; | |
3532 | else if (picrel->plt) | |
51532845 | 3533 | { |
43850d5b AO |
3534 | relocation = frvfdpic_plt_section (info)->output_section->vma |
3535 | + frvfdpic_plt_section (info)->output_offset | |
51532845 AO |
3536 | + picrel->plt_entry; |
3537 | check_segment[1] = plt_segment; | |
3538 | } | |
3539 | /* We don't want to warn on calls to undefined weak symbols, | |
3540 | as calls to them must be protected by non-NULL tests | |
3541 | anyway, and unprotected calls would invoke undefined | |
3542 | behavior. */ | |
3543 | else if (picrel->symndx == -1 | |
3544 | && picrel->d.h->root.type == bfd_link_hash_undefweak) | |
3545 | check_segment[1] = check_segment[0]; | |
3546 | else | |
3547 | check_segment[1] = sec | |
43850d5b | 3548 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3549 | : (unsigned)-1; |
3550 | break; | |
3551 | ||
3552 | case R_FRV_GOT12: | |
3553 | case R_FRV_GOTHI: | |
3554 | case R_FRV_GOTLO: | |
3555 | relocation = picrel->got_entry; | |
3556 | check_segment[0] = check_segment[1] = got_segment; | |
3557 | break; | |
f12123c0 | 3558 | |
51532845 AO |
3559 | case R_FRV_FUNCDESC_GOT12: |
3560 | case R_FRV_FUNCDESC_GOTHI: | |
3561 | case R_FRV_FUNCDESC_GOTLO: | |
3562 | relocation = picrel->fdgot_entry; | |
3563 | check_segment[0] = check_segment[1] = got_segment; | |
3564 | break; | |
f12123c0 | 3565 | |
51532845 AO |
3566 | case R_FRV_GOTOFFHI: |
3567 | case R_FRV_GOTOFF12: | |
3568 | case R_FRV_GOTOFFLO: | |
43850d5b AO |
3569 | relocation -= frvfdpic_got_section (info)->output_section->vma |
3570 | + frvfdpic_got_section (info)->output_offset | |
3571 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
3572 | check_segment[0] = got_segment; |
3573 | check_segment[1] = sec | |
43850d5b | 3574 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3575 | : (unsigned)-1; |
3576 | break; | |
3577 | ||
3578 | case R_FRV_FUNCDESC_GOTOFF12: | |
3579 | case R_FRV_FUNCDESC_GOTOFFHI: | |
3580 | case R_FRV_FUNCDESC_GOTOFFLO: | |
3581 | relocation = picrel->fd_entry; | |
3582 | check_segment[0] = check_segment[1] = got_segment; | |
3583 | break; | |
3584 | ||
3585 | case R_FRV_FUNCDESC: | |
3586 | { | |
3587 | int dynindx; | |
3588 | bfd_vma addend = rel->r_addend; | |
3589 | ||
072c8903 | 3590 | if (! (h && h->root.type == bfd_link_hash_undefweak |
43850d5b | 3591 | && FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 | 3592 | { |
072c8903 AO |
3593 | /* If the symbol is dynamic and there may be dynamic |
3594 | symbol resolution because we are or are linked with a | |
3595 | shared library, emit a FUNCDESC relocation such that | |
3596 | the dynamic linker will allocate the function | |
3597 | descriptor. If the symbol needs a non-local function | |
3598 | descriptor but binds locally (e.g., its visibility is | |
3599 | protected, emit a dynamic relocation decayed to | |
3600 | section+offset. */ | |
43850d5b AO |
3601 | if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h) |
3602 | && FRVFDPIC_SYM_LOCAL (info, h) | |
072c8903 | 3603 | && !(info->executable && !info->pie)) |
51532845 | 3604 | { |
072c8903 AO |
3605 | dynindx = elf_section_data (h->root.u.def.section |
3606 | ->output_section)->dynindx; | |
3607 | addend += h->root.u.def.section->output_offset | |
3608 | + h->root.u.def.value; | |
3609 | } | |
43850d5b | 3610 | else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)) |
072c8903 AO |
3611 | { |
3612 | if (addend) | |
3613 | { | |
3614 | info->callbacks->warning | |
3615 | (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"), | |
3616 | name, input_bfd, input_section, rel->r_offset); | |
3617 | return FALSE; | |
3618 | } | |
3619 | dynindx = h->dynindx; | |
3620 | } | |
3621 | else | |
3622 | { | |
3623 | /* Otherwise, we know we have a private function | |
3624 | descriptor, so reference it directly. */ | |
3625 | BFD_ASSERT (picrel->privfd); | |
3626 | r_type = R_FRV_32; | |
43850d5b | 3627 | dynindx = elf_section_data (frvfdpic_got_section (info) |
072c8903 | 3628 | ->output_section)->dynindx; |
43850d5b AO |
3629 | addend = frvfdpic_got_section (info)->output_offset |
3630 | + frvfdpic_got_initial_offset (info) | |
072c8903 | 3631 | + picrel->fd_entry; |
51532845 | 3632 | } |
51532845 | 3633 | |
072c8903 AO |
3634 | /* If there is room for dynamic symbol resolution, emit |
3635 | the dynamic relocation. However, if we're linking an | |
3636 | executable at a fixed location, we won't have emitted a | |
3637 | dynamic symbol entry for the got section, so idx will | |
3638 | be zero, which means we can and should compute the | |
3639 | address of the private descriptor ourselves. */ | |
3640 | if (info->executable && !info->pie | |
43850d5b | 3641 | && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h))) |
072c8903 | 3642 | { |
43850d5b | 3643 | addend += frvfdpic_got_section (info)->output_section->vma; |
072c8903 AO |
3644 | if ((bfd_get_section_flags (output_bfd, |
3645 | input_section->output_section) | |
3646 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
3647 | { | |
0d4cc892 AO |
3648 | bfd_vma offset; |
3649 | ||
43850d5b AO |
3650 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3651 | input_section | |
3652 | ->output_section)) | |
072c8903 AO |
3653 | { |
3654 | info->callbacks->warning | |
3655 | (info, | |
3656 | _("cannot emit fixups in read-only section"), | |
3657 | name, input_bfd, input_section, rel->r_offset); | |
3658 | return FALSE; | |
3659 | } | |
0d4cc892 AO |
3660 | |
3661 | offset = _bfd_elf_section_offset | |
3662 | (output_bfd, info, | |
3663 | input_section, rel->r_offset); | |
3664 | ||
3665 | if (offset != (bfd_vma)-1) | |
3666 | _frvfdpic_add_rofixup (output_bfd, | |
3667 | frvfdpic_gotfixup_section | |
3668 | (info), | |
3669 | offset + input_section | |
3670 | ->output_section->vma | |
3671 | + input_section->output_offset, | |
3672 | picrel); | |
072c8903 AO |
3673 | } |
3674 | } | |
3675 | else if ((bfd_get_section_flags (output_bfd, | |
3676 | input_section->output_section) | |
3677 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
51532845 | 3678 | { |
0d4cc892 AO |
3679 | bfd_vma offset; |
3680 | ||
43850d5b AO |
3681 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3682 | input_section | |
3683 | ->output_section)) | |
51532845 AO |
3684 | { |
3685 | info->callbacks->warning | |
3686 | (info, | |
072c8903 | 3687 | _("cannot emit dynamic relocations in read-only section"), |
51532845 AO |
3688 | name, input_bfd, input_section, rel->r_offset); |
3689 | return FALSE; | |
3690 | } | |
0d4cc892 AO |
3691 | |
3692 | offset = _bfd_elf_section_offset | |
3693 | (output_bfd, info, | |
3694 | input_section, rel->r_offset); | |
3695 | ||
3696 | if (offset != (bfd_vma)-1) | |
3697 | _frvfdpic_add_dyn_reloc (output_bfd, | |
3698 | frvfdpic_gotrel_section (info), | |
3699 | offset + input_section | |
3700 | ->output_section->vma | |
3701 | + input_section->output_offset, | |
3702 | r_type, dynindx, addend, picrel); | |
51532845 | 3703 | } |
43850d5b AO |
3704 | else |
3705 | addend += frvfdpic_got_section (info)->output_section->vma; | |
51532845 AO |
3706 | } |
3707 | ||
3708 | /* We want the addend in-place because dynamic | |
3709 | relocations are REL. Setting relocation to it should | |
3710 | arrange for it to be installed. */ | |
3711 | relocation = addend - rel->r_addend; | |
3712 | } | |
3713 | check_segment[0] = check_segment[1] = got_segment; | |
3714 | break; | |
3715 | ||
3716 | case R_FRV_32: | |
43850d5b AO |
3717 | if (! IS_FDPIC (output_bfd)) |
3718 | { | |
3719 | check_segment[0] = check_segment[1] = -1; | |
3720 | break; | |
3721 | } | |
3722 | /* Fall through. */ | |
51532845 AO |
3723 | case R_FRV_FUNCDESC_VALUE: |
3724 | { | |
3725 | int dynindx; | |
3726 | bfd_vma addend = rel->r_addend; | |
3727 | ||
3728 | /* If the symbol is dynamic but binds locally, use | |
3729 | section+offset. */ | |
43850d5b | 3730 | if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) |
51532845 AO |
3731 | { |
3732 | if (addend && r_type == R_FRV_FUNCDESC_VALUE) | |
3733 | { | |
3734 | info->callbacks->warning | |
3735 | (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"), | |
3736 | name, input_bfd, input_section, rel->r_offset); | |
3737 | return FALSE; | |
3738 | } | |
3739 | dynindx = h->dynindx; | |
3740 | } | |
3741 | else | |
3742 | { | |
3743 | if (h) | |
3744 | addend += h->root.u.def.value; | |
3745 | else | |
3746 | addend += sym->st_value; | |
3747 | if (osec) | |
3748 | addend += osec->output_offset; | |
3749 | if (osec && osec->output_section | |
3750 | && ! bfd_is_abs_section (osec->output_section) | |
3751 | && ! bfd_is_und_section (osec->output_section)) | |
3752 | dynindx = elf_section_data (osec->output_section)->dynindx; | |
3753 | else | |
3754 | dynindx = 0; | |
3755 | } | |
3756 | ||
3757 | /* If we're linking an executable at a fixed address, we | |
3758 | can omit the dynamic relocation as long as the symbol | |
3759 | is defined in the current link unit (which is implied | |
3760 | by its output section not being NULL). */ | |
3761 | if (info->executable && !info->pie | |
43850d5b | 3762 | && (!h || FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 AO |
3763 | { |
3764 | if (osec) | |
3765 | addend += osec->output_section->vma; | |
43850d5b | 3766 | if (IS_FDPIC (input_bfd) |
51532845 AO |
3767 | && (bfd_get_section_flags (output_bfd, |
3768 | input_section->output_section) | |
3769 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
3770 | { | |
43850d5b AO |
3771 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3772 | input_section | |
3773 | ->output_section)) | |
51532845 AO |
3774 | { |
3775 | info->callbacks->warning | |
3776 | (info, | |
3777 | _("cannot emit fixups in read-only section"), | |
3778 | name, input_bfd, input_section, rel->r_offset); | |
3779 | return FALSE; | |
3780 | } | |
3781 | if (!h || h->root.type != bfd_link_hash_undefweak) | |
3782 | { | |
0d4cc892 AO |
3783 | bfd_vma offset = _bfd_elf_section_offset |
3784 | (output_bfd, info, | |
3785 | input_section, rel->r_offset); | |
3786 | ||
3787 | if (offset != (bfd_vma)-1) | |
3788 | { | |
3789 | _frvfdpic_add_rofixup (output_bfd, | |
3790 | frvfdpic_gotfixup_section | |
3791 | (info), | |
3792 | offset + input_section | |
3793 | ->output_section->vma | |
3794 | + input_section->output_offset, | |
3795 | picrel); | |
3796 | if (r_type == R_FRV_FUNCDESC_VALUE) | |
3797 | _frvfdpic_add_rofixup | |
3798 | (output_bfd, | |
3799 | frvfdpic_gotfixup_section (info), | |
3800 | offset | |
3801 | + input_section->output_section->vma | |
3802 | + input_section->output_offset + 4, picrel); | |
3803 | } | |
51532845 AO |
3804 | } |
3805 | } | |
3806 | } | |
3807 | else | |
3808 | { | |
3809 | if ((bfd_get_section_flags (output_bfd, | |
3810 | input_section->output_section) | |
3811 | & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) | |
3812 | { | |
0d4cc892 AO |
3813 | bfd_vma offset; |
3814 | ||
43850d5b AO |
3815 | if (_frvfdpic_osec_readonly_p (output_bfd, |
3816 | input_section | |
3817 | ->output_section)) | |
51532845 AO |
3818 | { |
3819 | info->callbacks->warning | |
3820 | (info, | |
3821 | _("cannot emit dynamic relocations in read-only section"), | |
3822 | name, input_bfd, input_section, rel->r_offset); | |
3823 | return FALSE; | |
3824 | } | |
0d4cc892 AO |
3825 | |
3826 | offset = _bfd_elf_section_offset | |
3827 | (output_bfd, info, | |
3828 | input_section, rel->r_offset); | |
3829 | ||
3830 | if (offset != (bfd_vma)-1) | |
3831 | _frvfdpic_add_dyn_reloc (output_bfd, | |
3832 | frvfdpic_gotrel_section (info), | |
3833 | offset + input_section | |
3834 | ->output_section->vma | |
3835 | + input_section->output_offset, | |
3836 | r_type, dynindx, addend, picrel); | |
51532845 | 3837 | } |
43850d5b AO |
3838 | else if (osec) |
3839 | addend += osec->output_section->vma; | |
51532845 AO |
3840 | /* We want the addend in-place because dynamic |
3841 | relocations are REL. Setting relocation to it | |
3842 | should arrange for it to be installed. */ | |
3843 | relocation = addend - rel->r_addend; | |
3844 | } | |
3845 | ||
3846 | if (r_type == R_FRV_FUNCDESC_VALUE) | |
3847 | { | |
3848 | /* If we've omitted the dynamic relocation, just emit | |
3849 | the fixed addresses of the symbol and of the local | |
3850 | GOT base offset. */ | |
3851 | if (info->executable && !info->pie | |
43850d5b | 3852 | && (!h || FRVFDPIC_SYM_LOCAL (info, h))) |
51532845 | 3853 | bfd_put_32 (output_bfd, |
43850d5b AO |
3854 | frvfdpic_got_section (info)->output_section->vma |
3855 | + frvfdpic_got_section (info)->output_offset | |
3856 | + frvfdpic_got_initial_offset (info), | |
51532845 AO |
3857 | contents + rel->r_offset + 4); |
3858 | else | |
3859 | /* A function descriptor used for lazy or local | |
3860 | resolving is initialized such that its high word | |
3861 | contains the output section index in which the | |
3862 | PLT entries are located, and the low word | |
3863 | contains the offset of the lazy PLT entry entry | |
3864 | point into that section. */ | |
3865 | bfd_put_32 (output_bfd, | |
43850d5b | 3866 | h && ! FRVFDPIC_SYM_LOCAL (info, h) |
51532845 | 3867 | ? 0 |
43850d5b AO |
3868 | : _frvfdpic_osec_to_segment (output_bfd, |
3869 | sec | |
3870 | ->output_section), | |
51532845 AO |
3871 | contents + rel->r_offset + 4); |
3872 | } | |
3873 | } | |
3874 | check_segment[0] = check_segment[1] = got_segment; | |
3875 | break; | |
3876 | ||
3877 | case R_FRV_GPREL12: | |
3878 | case R_FRV_GPRELU12: | |
3879 | case R_FRV_GPREL32: | |
3880 | case R_FRV_GPRELHI: | |
3881 | case R_FRV_GPRELLO: | |
3882 | check_segment[0] = gprel_segment; | |
3883 | check_segment[1] = sec | |
43850d5b | 3884 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3885 | : (unsigned)-1; |
3886 | break; | |
3887 | ||
90219bd0 AO |
3888 | case R_FRV_GETTLSOFF: |
3889 | relocation = frvfdpic_plt_section (info)->output_section->vma | |
3890 | + frvfdpic_plt_section (info)->output_offset | |
3891 | + picrel->tlsplt_entry; | |
3892 | BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1 | |
3893 | && picrel->tlsdesc_entry); | |
3894 | check_segment[0] = isec_segment; | |
3895 | check_segment[1] = plt_segment; | |
3896 | break; | |
3897 | ||
3898 | case R_FRV_GOTTLSDESC12: | |
3899 | case R_FRV_GOTTLSDESCHI: | |
3900 | case R_FRV_GOTTLSDESCLO: | |
3901 | BFD_ASSERT (picrel->tlsdesc_entry); | |
3902 | relocation = picrel->tlsdesc_entry; | |
3903 | check_segment[0] = tls_segment; | |
3904 | check_segment[1] = sec | |
3905 | && ! bfd_is_abs_section (sec) | |
3906 | && ! bfd_is_und_section (sec) | |
3907 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) | |
3908 | : tls_segment; | |
3909 | break; | |
3910 | ||
3911 | case R_FRV_TLSMOFF12: | |
3912 | case R_FRV_TLSMOFFHI: | |
3913 | case R_FRV_TLSMOFFLO: | |
3914 | case R_FRV_TLSMOFF: | |
3915 | check_segment[0] = tls_segment; | |
3916 | if (! sec) | |
3917 | check_segment[1] = -1; | |
3918 | else if (bfd_is_abs_section (sec) | |
3919 | || bfd_is_und_section (sec)) | |
3920 | { | |
3921 | relocation = 0; | |
3922 | check_segment[1] = tls_segment; | |
3923 | } | |
3924 | else if (sec->output_section) | |
3925 | { | |
3926 | relocation -= tls_biased_base (info); | |
3927 | check_segment[1] = | |
3928 | _frvfdpic_osec_to_segment (output_bfd, sec->output_section); | |
3929 | } | |
68320ddb AO |
3930 | else |
3931 | check_segment[1] = -1; | |
90219bd0 AO |
3932 | break; |
3933 | ||
3934 | case R_FRV_GOTTLSOFF12: | |
3935 | case R_FRV_GOTTLSOFFHI: | |
3936 | case R_FRV_GOTTLSOFFLO: | |
3937 | BFD_ASSERT (picrel->tlsoff_entry); | |
3938 | relocation = picrel->tlsoff_entry; | |
3939 | check_segment[0] = tls_segment; | |
3940 | check_segment[1] = sec | |
3941 | && ! bfd_is_abs_section (sec) | |
3942 | && ! bfd_is_und_section (sec) | |
3943 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) | |
3944 | : tls_segment; | |
3945 | break; | |
3b36f7e6 | 3946 | |
90219bd0 AO |
3947 | case R_FRV_TLSDESC_VALUE: |
3948 | case R_FRV_TLSOFF: | |
3949 | /* These shouldn't be present in input object files. */ | |
3950 | check_segment[0] = check_segment[1] = isec_segment; | |
3951 | break; | |
3952 | ||
3953 | case R_FRV_TLSDESC_RELAX: | |
3954 | case R_FRV_GETTLSOFF_RELAX: | |
3955 | case R_FRV_TLSOFF_RELAX: | |
3956 | /* These are just annotations for relaxation, nothing to do | |
3957 | here. */ | |
3958 | continue; | |
3959 | ||
51532845 AO |
3960 | default: |
3961 | check_segment[0] = isec_segment; | |
3962 | check_segment[1] = sec | |
43850d5b | 3963 | ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) |
51532845 AO |
3964 | : (unsigned)-1; |
3965 | break; | |
3966 | } | |
3967 | ||
43850d5b | 3968 | if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd)) |
51532845 | 3969 | { |
0e71e495 BE |
3970 | /* If you take this out, remove the #error from fdpic-static-6.d |
3971 | in the ld testsuite. */ | |
51532845 AO |
3972 | /* This helps catch problems in GCC while we can't do more |
3973 | than static linking. The idea is to test whether the | |
3974 | input file basename is crt0.o only once. */ | |
3975 | if (silence_segment_error == 1) | |
3976 | silence_segment_error = | |
3977 | (strlen (input_bfd->filename) == 6 | |
3978 | && strcmp (input_bfd->filename, "crt0.o") == 0) | |
3979 | || (strlen (input_bfd->filename) > 6 | |
3980 | && strcmp (input_bfd->filename | |
3981 | + strlen (input_bfd->filename) - 7, | |
3982 | "/crt0.o") == 0) | |
3983 | ? -1 : 0; | |
51532845 AO |
3984 | if (!silence_segment_error |
3985 | /* We don't want duplicate errors for undefined | |
3986 | symbols. */ | |
3987 | && !(picrel && picrel->symndx == -1 | |
3988 | && picrel->d.h->root.type == bfd_link_hash_undefined)) | |
68320ddb AO |
3989 | { |
3990 | if (info->shared || info->pie) | |
3991 | (*_bfd_error_handler) | |
3992 | (_("%B(%A+0x%lx): reloc against `%s': %s"), | |
3993 | input_bfd, input_section, (long)rel->r_offset, name, | |
3994 | _("relocation references a different segment")); | |
3995 | else | |
3996 | info->callbacks->warning | |
3997 | (info, | |
3998 | _("relocation references a different segment"), | |
3999 | name, input_bfd, input_section, rel->r_offset); | |
4000 | } | |
51532845 AO |
4001 | if (!silence_segment_error && (info->shared || info->pie)) |
4002 | return FALSE; | |
4003 | elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC; | |
4004 | } | |
4005 | ||
4006 | switch (r_type) | |
4007 | { | |
4008 | case R_FRV_GOTOFFHI: | |
90219bd0 | 4009 | case R_FRV_TLSMOFFHI: |
51532845 AO |
4010 | /* We need the addend to be applied before we shift the |
4011 | value right. */ | |
4012 | relocation += rel->r_addend; | |
4013 | /* Fall through. */ | |
4014 | case R_FRV_GOTHI: | |
4015 | case R_FRV_FUNCDESC_GOTHI: | |
4016 | case R_FRV_FUNCDESC_GOTOFFHI: | |
90219bd0 AO |
4017 | case R_FRV_GOTTLSOFFHI: |
4018 | case R_FRV_GOTTLSDESCHI: | |
51532845 AO |
4019 | relocation >>= 16; |
4020 | /* Fall through. */ | |
4021 | ||
4022 | case R_FRV_GOTLO: | |
4023 | case R_FRV_FUNCDESC_GOTLO: | |
4024 | case R_FRV_GOTOFFLO: | |
4025 | case R_FRV_FUNCDESC_GOTOFFLO: | |
90219bd0 AO |
4026 | case R_FRV_GOTTLSOFFLO: |
4027 | case R_FRV_GOTTLSDESCLO: | |
4028 | case R_FRV_TLSMOFFLO: | |
51532845 AO |
4029 | relocation &= 0xffff; |
4030 | break; | |
4031 | ||
4032 | default: | |
4033 | break; | |
4034 | } | |
4035 | ||
4036 | switch (r_type) | |
4037 | { | |
4038 | case R_FRV_LABEL24: | |
43850d5b | 4039 | if (! IS_FDPIC (output_bfd) || ! picrel->plt) |
51532845 AO |
4040 | break; |
4041 | /* Fall through. */ | |
f12123c0 | 4042 | |
51532845 AO |
4043 | /* When referencing a GOT entry, a function descriptor or a |
4044 | PLT, we don't want the addend to apply to the reference, | |
4045 | but rather to the referenced symbol. The actual entry | |
4046 | will have already been created taking the addend into | |
4047 | account, so cancel it out here. */ | |
4048 | case R_FRV_GOT12: | |
4049 | case R_FRV_GOTHI: | |
4050 | case R_FRV_GOTLO: | |
4051 | case R_FRV_FUNCDESC_GOT12: | |
4052 | case R_FRV_FUNCDESC_GOTHI: | |
4053 | case R_FRV_FUNCDESC_GOTLO: | |
4054 | case R_FRV_FUNCDESC_GOTOFF12: | |
4055 | case R_FRV_FUNCDESC_GOTOFFHI: | |
4056 | case R_FRV_FUNCDESC_GOTOFFLO: | |
90219bd0 AO |
4057 | case R_FRV_GETTLSOFF: |
4058 | case R_FRV_GOTTLSDESC12: | |
4059 | case R_FRV_GOTTLSDESCHI: | |
4060 | case R_FRV_GOTTLSDESCLO: | |
4061 | case R_FRV_GOTTLSOFF12: | |
4062 | case R_FRV_GOTTLSOFFHI: | |
4063 | case R_FRV_GOTTLSOFFLO: | |
51532845 AO |
4064 | /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12 |
4065 | here, since we do want to apply the addend to the others. | |
4066 | Note that we've applied the addend to GOTOFFHI before we | |
f12123c0 | 4067 | shifted it right. */ |
51532845 | 4068 | case R_FRV_GOTOFFHI: |
90219bd0 | 4069 | case R_FRV_TLSMOFFHI: |
51532845 AO |
4070 | relocation -= rel->r_addend; |
4071 | break; | |
4072 | ||
4073 | default: | |
4074 | break; | |
4075 | } | |
4076 | ||
4077 | if (r_type == R_FRV_HI16) | |
4078 | r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation); | |
4079 | ||
4080 | else if (r_type == R_FRV_LO16) | |
4081 | r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation); | |
4082 | ||
90219bd0 | 4083 | else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF) |
51532845 AO |
4084 | r = elf32_frv_relocate_label24 (input_bfd, input_section, rel, |
4085 | contents, relocation); | |
4086 | ||
4087 | else if (r_type == R_FRV_GPREL12) | |
4088 | r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel, | |
4089 | contents, relocation); | |
4090 | ||
4091 | else if (r_type == R_FRV_GPRELU12) | |
4092 | r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel, | |
4093 | contents, relocation); | |
4094 | ||
4095 | else if (r_type == R_FRV_GPRELLO) | |
4096 | r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel, | |
4097 | contents, relocation); | |
4098 | ||
4099 | else if (r_type == R_FRV_GPRELHI) | |
4100 | r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel, | |
4101 | contents, relocation); | |
4102 | ||
90219bd0 AO |
4103 | else if (r_type == R_FRV_TLSOFF |
4104 | || r_type == R_FRV_TLSDESC_VALUE) | |
4105 | r = bfd_reloc_notsupported; | |
4106 | ||
51532845 AO |
4107 | else |
4108 | r = frv_final_link_relocate (howto, input_bfd, input_section, contents, | |
4109 | rel, relocation); | |
4110 | ||
4111 | if (r != bfd_reloc_ok) | |
4112 | { | |
4113 | const char * msg = (const char *) NULL; | |
4114 | ||
4115 | switch (r) | |
4116 | { | |
4117 | case bfd_reloc_overflow: | |
4118 | r = info->callbacks->reloc_overflow | |
dfeffb9f L |
4119 | (info, (h ? &h->root : NULL), name, howto->name, |
4120 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); | |
51532845 AO |
4121 | break; |
4122 | ||
4123 | case bfd_reloc_undefined: | |
4124 | r = info->callbacks->undefined_symbol | |
4125 | (info, name, input_bfd, input_section, rel->r_offset, TRUE); | |
4126 | break; | |
4127 | ||
4128 | case bfd_reloc_outofrange: | |
4129 | msg = _("internal error: out of range error"); | |
4130 | break; | |
4131 | ||
4132 | case bfd_reloc_notsupported: | |
4133 | msg = _("internal error: unsupported relocation error"); | |
4134 | break; | |
4135 | ||
4136 | case bfd_reloc_dangerous: | |
4137 | msg = _("internal error: dangerous relocation"); | |
4138 | break; | |
4139 | ||
4140 | default: | |
4141 | msg = _("internal error: unknown error"); | |
4142 | break; | |
4143 | } | |
4144 | ||
4145 | if (msg) | |
68320ddb AO |
4146 | { |
4147 | (*_bfd_error_handler) | |
4148 | (_("%B(%A+0x%lx): reloc against `%s': %s"), | |
4149 | input_bfd, input_section, (long)rel->r_offset, name, msg); | |
4150 | return FALSE; | |
4151 | } | |
51532845 AO |
4152 | |
4153 | if (! r) | |
4154 | return FALSE; | |
4155 | } | |
4156 | } | |
4157 | ||
4158 | return TRUE; | |
4159 | } | |
4160 | \f | |
4161 | /* Return the section that should be marked against GC for a given | |
4162 | relocation. */ | |
4163 | ||
4164 | static asection * | |
07adf181 AM |
4165 | elf32_frv_gc_mark_hook (asection *sec, |
4166 | struct bfd_link_info *info, | |
4167 | Elf_Internal_Rela *rel, | |
4168 | struct elf_link_hash_entry *h, | |
4169 | Elf_Internal_Sym *sym) | |
51532845 AO |
4170 | { |
4171 | if (h != NULL) | |
07adf181 AM |
4172 | switch (ELF32_R_TYPE (rel->r_info)) |
4173 | { | |
4174 | case R_FRV_GNU_VTINHERIT: | |
4175 | case R_FRV_GNU_VTENTRY: | |
4176 | return NULL; | |
4177 | } | |
51532845 | 4178 | |
07adf181 | 4179 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); |
51532845 | 4180 | } |
51532845 AO |
4181 | \f |
4182 | /* Hook called by the linker routine which adds symbols from an object | |
4183 | file. We use it to put .comm items in .scomm, and not .comm. */ | |
4184 | ||
4185 | static bfd_boolean | |
4186 | elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) | |
4187 | bfd *abfd; | |
4188 | struct bfd_link_info *info; | |
555cd476 | 4189 | Elf_Internal_Sym *sym; |
51532845 AO |
4190 | const char **namep ATTRIBUTE_UNUSED; |
4191 | flagword *flagsp ATTRIBUTE_UNUSED; | |
4192 | asection **secp; | |
4193 | bfd_vma *valp; | |
4194 | { | |
4195 | if (sym->st_shndx == SHN_COMMON | |
4196 | && !info->relocatable | |
4197 | && (int)sym->st_size <= (int)bfd_get_gp_size (abfd)) | |
4198 | { | |
4199 | /* Common symbols less than or equal to -G nn bytes are | |
4200 | automatically put into .sbss. */ | |
4201 | ||
4202 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); | |
4203 | ||
4204 | if (scomm == NULL) | |
4205 | { | |
3496cb2a L |
4206 | scomm = bfd_make_section_with_flags (abfd, ".scommon", |
4207 | (SEC_ALLOC | |
4208 | | SEC_IS_COMMON | |
4209 | | SEC_LINKER_CREATED)); | |
4210 | if (scomm == NULL) | |
51532845 AO |
4211 | return FALSE; |
4212 | } | |
4213 | ||
4214 | *secp = scomm; | |
4215 | *valp = sym->st_size; | |
4216 | } | |
4217 | ||
4218 | return TRUE; | |
4219 | } | |
43850d5b | 4220 | |
aee6f5b4 AO |
4221 | /* We need dynamic symbols for every section, since segments can |
4222 | relocate independently. */ | |
4223 | static bfd_boolean | |
4224 | _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED, | |
4225 | struct bfd_link_info *info | |
4226 | ATTRIBUTE_UNUSED, | |
4227 | asection *p ATTRIBUTE_UNUSED) | |
4228 | { | |
4229 | switch (elf_section_data (p)->this_hdr.sh_type) | |
4230 | { | |
4231 | case SHT_PROGBITS: | |
4232 | case SHT_NOBITS: | |
4233 | /* If sh_type is yet undecided, assume it could be | |
4234 | SHT_PROGBITS/SHT_NOBITS. */ | |
4235 | case SHT_NULL: | |
4236 | return FALSE; | |
4237 | ||
4238 | /* There shouldn't be section relative relocations | |
4239 | against any other section. */ | |
4240 | default: | |
4241 | return TRUE; | |
4242 | } | |
4243 | } | |
4244 | ||
43850d5b | 4245 | /* Create a .got section, as well as its additional info field. This |
51532845 AO |
4246 | is almost entirely copied from |
4247 | elflink.c:_bfd_elf_create_got_section(). */ | |
4248 | ||
4249 | static bfd_boolean | |
4250 | _frv_create_got_section (bfd *abfd, struct bfd_link_info *info) | |
4251 | { | |
90219bd0 | 4252 | flagword flags, pltflags; |
51532845 AO |
4253 | asection *s; |
4254 | struct elf_link_hash_entry *h; | |
4255 | struct bfd_link_hash_entry *bh; | |
4256 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
4257 | int ptralign; | |
43850d5b | 4258 | int offset; |
51532845 AO |
4259 | |
4260 | /* This function may be called more than once. */ | |
4261 | s = bfd_get_section_by_name (abfd, ".got"); | |
4262 | if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0) | |
4263 | return TRUE; | |
4264 | ||
4265 | /* Machine specific: although pointers are 32-bits wide, we want the | |
4266 | GOT to be aligned to a 64-bit boundary, such that function | |
4267 | descriptors in it can be accessed with 64-bit loads and | |
4268 | stores. */ | |
4269 | ptralign = 3; | |
4270 | ||
4271 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
4272 | | SEC_LINKER_CREATED); | |
90219bd0 | 4273 | pltflags = flags; |
51532845 | 4274 | |
3496cb2a | 4275 | s = bfd_make_section_with_flags (abfd, ".got", flags); |
51532845 | 4276 | if (s == NULL |
51532845 AO |
4277 | || !bfd_set_section_alignment (abfd, s, ptralign)) |
4278 | return FALSE; | |
4279 | ||
4280 | if (bed->want_got_plt) | |
4281 | { | |
3496cb2a | 4282 | s = bfd_make_section_with_flags (abfd, ".got.plt", flags); |
51532845 | 4283 | if (s == NULL |
51532845 AO |
4284 | || !bfd_set_section_alignment (abfd, s, ptralign)) |
4285 | return FALSE; | |
4286 | } | |
4287 | ||
4288 | if (bed->want_got_sym) | |
4289 | { | |
4290 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | |
4291 | (or .got.plt) section. We don't do this in the linker script | |
4292 | because we don't want to define the symbol if we are not creating | |
4293 | a global offset table. */ | |
d98685ac AM |
4294 | h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); |
4295 | elf_hash_table (info)->hgot = h; | |
4296 | if (h == NULL) | |
51532845 | 4297 | return FALSE; |
51532845 AO |
4298 | |
4299 | /* Machine-specific: we want the symbol for executables as | |
4300 | well. */ | |
c152c796 | 4301 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
51532845 | 4302 | return FALSE; |
51532845 AO |
4303 | } |
4304 | ||
4305 | /* The first bit of the global offset table is the header. */ | |
3b36f7e6 | 4306 | s->size += bed->got_header_size; |
51532845 AO |
4307 | |
4308 | /* This is the machine-specific part. Create and initialize section | |
4309 | data for the got. */ | |
43850d5b AO |
4310 | if (IS_FDPIC (abfd)) |
4311 | { | |
4312 | frvfdpic_got_section (info) = s; | |
90219bd0 AO |
4313 | frvfdpic_relocs_info (info) = htab_try_create (1, |
4314 | frvfdpic_relocs_info_hash, | |
43850d5b AO |
4315 | frvfdpic_relocs_info_eq, |
4316 | (htab_del) NULL); | |
4317 | if (! frvfdpic_relocs_info (info)) | |
4318 | return FALSE; | |
51532845 | 4319 | |
3496cb2a L |
4320 | s = bfd_make_section_with_flags (abfd, ".rel.got", |
4321 | (flags | SEC_READONLY)); | |
43850d5b | 4322 | if (s == NULL |
43850d5b AO |
4323 | || ! bfd_set_section_alignment (abfd, s, 2)) |
4324 | return FALSE; | |
51532845 | 4325 | |
43850d5b | 4326 | frvfdpic_gotrel_section (info) = s; |
51532845 | 4327 | |
43850d5b | 4328 | /* Machine-specific. */ |
3496cb2a L |
4329 | s = bfd_make_section_with_flags (abfd, ".rofixup", |
4330 | (flags | SEC_READONLY)); | |
43850d5b | 4331 | if (s == NULL |
43850d5b AO |
4332 | || ! bfd_set_section_alignment (abfd, s, 2)) |
4333 | return FALSE; | |
51532845 | 4334 | |
43850d5b AO |
4335 | frvfdpic_gotfixup_section (info) = s; |
4336 | offset = -2048; | |
4337 | flags = BSF_GLOBAL; | |
4338 | } | |
4339 | else | |
4340 | { | |
4341 | offset = 2048; | |
4342 | flags = BSF_GLOBAL | BSF_WEAK; | |
4343 | } | |
51532845 | 4344 | |
43850d5b AO |
4345 | /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it |
4346 | turns out that we're linking with a different linker script, the | |
4347 | linker script will override it. */ | |
51532845 AO |
4348 | bh = NULL; |
4349 | if (!(_bfd_generic_link_add_one_symbol | |
43850d5b | 4350 | (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE, |
51532845 AO |
4351 | bed->collect, &bh))) |
4352 | return FALSE; | |
4353 | h = (struct elf_link_hash_entry *) bh; | |
f5385ebf | 4354 | h->def_regular = 1; |
51532845 | 4355 | h->type = STT_OBJECT; |
90219bd0 | 4356 | /* h->other = STV_HIDDEN; */ /* Should we? */ |
51532845 AO |
4357 | |
4358 | /* Machine-specific: we want the symbol for executables as well. */ | |
43850d5b | 4359 | if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h)) |
51532845 | 4360 | return FALSE; |
43850d5b | 4361 | |
90219bd0 AO |
4362 | if (!IS_FDPIC (abfd)) |
4363 | return TRUE; | |
51532845 | 4364 | |
90219bd0 AO |
4365 | /* FDPIC supports Thread Local Storage, and this may require a |
4366 | procedure linkage table for TLS PLT entries. */ | |
51532845 | 4367 | |
51532845 AO |
4368 | /* This is mostly copied from |
4369 | elflink.c:_bfd_elf_create_dynamic_sections(). */ | |
51532845 | 4370 | |
90219bd0 | 4371 | flags = pltflags; |
51532845 AO |
4372 | pltflags |= SEC_CODE; |
4373 | if (bed->plt_not_loaded) | |
4374 | pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); | |
4375 | if (bed->plt_readonly) | |
4376 | pltflags |= SEC_READONLY; | |
4377 | ||
3496cb2a | 4378 | s = bfd_make_section_with_flags (abfd, ".plt", pltflags); |
51532845 | 4379 | if (s == NULL |
51532845 AO |
4380 | || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) |
4381 | return FALSE; | |
4382 | /* FRV-specific: remember it. */ | |
43850d5b | 4383 | frvfdpic_plt_section (info) = s; |
51532845 | 4384 | |
d98685ac AM |
4385 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the |
4386 | .plt section. */ | |
7325306f RS |
4387 | if (bed->want_plt_sym) |
4388 | { | |
4389 | h = _bfd_elf_define_linkage_sym (abfd, info, s, | |
4390 | "_PROCEDURE_LINKAGE_TABLE_"); | |
4391 | elf_hash_table (info)->hplt = h; | |
4392 | if (h == NULL) | |
4393 | return FALSE; | |
4394 | } | |
51532845 AO |
4395 | |
4396 | /* FRV-specific: we want rel relocations for the plt. */ | |
3496cb2a L |
4397 | s = bfd_make_section_with_flags (abfd, ".rel.plt", |
4398 | flags | SEC_READONLY); | |
51532845 | 4399 | if (s == NULL |
51532845 AO |
4400 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) |
4401 | return FALSE; | |
4402 | /* FRV-specific: remember it. */ | |
43850d5b | 4403 | frvfdpic_pltrel_section (info) = s; |
51532845 | 4404 | |
90219bd0 AO |
4405 | return TRUE; |
4406 | } | |
4407 | ||
4408 | /* Make sure the got and plt sections exist, and that our pointers in | |
4409 | the link hash table point to them. */ | |
4410 | ||
4411 | static bfd_boolean | |
4412 | elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |
4413 | { | |
4414 | /* This is mostly copied from | |
4415 | elflink.c:_bfd_elf_create_dynamic_sections(). */ | |
4416 | flagword flags; | |
4417 | asection *s; | |
4418 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
4419 | ||
4420 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
4421 | | SEC_LINKER_CREATED); | |
4422 | ||
4423 | /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and | |
4424 | .rel[a].bss sections. */ | |
4425 | ||
4426 | /* FRV-specific: we want to create the GOT and the PLT in the FRV | |
4427 | way. */ | |
51532845 AO |
4428 | if (! _frv_create_got_section (abfd, info)) |
4429 | return FALSE; | |
4430 | ||
4431 | /* FRV-specific: make sure we created everything we wanted. */ | |
43850d5b AO |
4432 | BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info) |
4433 | && frvfdpic_gotfixup_section (info) | |
4434 | && frvfdpic_plt_section (info) | |
4435 | && frvfdpic_pltrel_section (info)); | |
51532845 AO |
4436 | |
4437 | if (bed->want_dynbss) | |
4438 | { | |
4439 | /* The .dynbss section is a place to put symbols which are defined | |
4440 | by dynamic objects, are referenced by regular objects, and are | |
4441 | not functions. We must allocate space for them in the process | |
4442 | image and use a R_*_COPY reloc to tell the dynamic linker to | |
4443 | initialize them at run time. The linker script puts the .dynbss | |
4444 | section into the .bss section of the final image. */ | |
3496cb2a L |
4445 | s = bfd_make_section_with_flags (abfd, ".dynbss", |
4446 | SEC_ALLOC | SEC_LINKER_CREATED); | |
4447 | if (s == NULL) | |
51532845 AO |
4448 | return FALSE; |
4449 | ||
4450 | /* The .rel[a].bss section holds copy relocs. This section is not | |
4451 | normally needed. We need to create it here, though, so that the | |
4452 | linker will map it to an output section. We can't just create it | |
4453 | only if we need it, because we will not know whether we need it | |
4454 | until we have seen all the input files, and the first time the | |
4455 | main linker code calls BFD after examining all the input files | |
4456 | (size_dynamic_sections) the input sections have already been | |
4457 | mapped to the output sections. If the section turns out not to | |
4458 | be needed, we can discard it later. We will never need this | |
4459 | section when generating a shared object, since they do not use | |
4460 | copy relocs. */ | |
4461 | if (! info->shared) | |
4462 | { | |
3496cb2a L |
4463 | s = bfd_make_section_with_flags (abfd, |
4464 | (bed->default_use_rela_p | |
4465 | ? ".rela.bss" : ".rel.bss"), | |
4466 | flags | SEC_READONLY); | |
51532845 | 4467 | if (s == NULL |
51532845 AO |
4468 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) |
4469 | return FALSE; | |
4470 | } | |
4471 | } | |
4472 | ||
4473 | return TRUE; | |
4474 | } | |
4475 | ||
90219bd0 AO |
4476 | /* Compute the total GOT and PLT size required by each symbol in each |
4477 | range. Symbols may require up to 4 words in the GOT: an entry | |
4478 | pointing to the symbol, an entry pointing to its function | |
4479 | descriptor, and a private function descriptors taking two | |
4480 | words. */ | |
51532845 | 4481 | |
90219bd0 AO |
4482 | static void |
4483 | _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry, | |
4484 | struct _frvfdpic_dynamic_got_info *dinfo) | |
51532845 | 4485 | { |
51532845 AO |
4486 | /* Allocate space for a GOT entry pointing to the symbol. */ |
4487 | if (entry->got12) | |
4488 | dinfo->got12 += 4; | |
4489 | else if (entry->gotlos) | |
4490 | dinfo->gotlos += 4; | |
4491 | else if (entry->gothilo) | |
4492 | dinfo->gothilo += 4; | |
4493 | else | |
4494 | entry->relocs32--; | |
4495 | entry->relocs32++; | |
4496 | ||
4497 | /* Allocate space for a GOT entry pointing to the function | |
4498 | descriptor. */ | |
4499 | if (entry->fdgot12) | |
4500 | dinfo->got12 += 4; | |
4501 | else if (entry->fdgotlos) | |
4502 | dinfo->gotlos += 4; | |
4503 | else if (entry->fdgothilo) | |
4504 | dinfo->gothilo += 4; | |
4505 | else | |
4506 | entry->relocsfd--; | |
4507 | entry->relocsfd++; | |
4508 | ||
4509 | /* Decide whether we need a PLT entry, a function descriptor in the | |
4510 | GOT, and a lazy PLT entry for this symbol. */ | |
4511 | entry->plt = entry->call | |
43850d5b | 4512 | && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) |
51532845 AO |
4513 | && elf_hash_table (dinfo->info)->dynamic_sections_created; |
4514 | entry->privfd = entry->plt | |
4515 | || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo | |
4516 | || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo) | |
4517 | && (entry->symndx != -1 | |
43850d5b | 4518 | || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))); |
51532845 | 4519 | entry->lazyplt = entry->privfd |
43850d5b | 4520 | && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) |
51532845 AO |
4521 | && ! (dinfo->info->flags & DF_BIND_NOW) |
4522 | && elf_hash_table (dinfo->info)->dynamic_sections_created; | |
4523 | ||
4524 | /* Allocate space for a function descriptor. */ | |
4525 | if (entry->fdgoff12) | |
4526 | dinfo->fd12 += 8; | |
4527 | else if (entry->fdgofflos) | |
4528 | dinfo->fdlos += 8; | |
4529 | else if (entry->privfd && entry->plt) | |
4530 | dinfo->fdplt += 8; | |
4531 | else if (entry->privfd) | |
4532 | dinfo->fdhilo += 8; | |
4533 | else | |
4534 | entry->relocsfdv--; | |
4535 | entry->relocsfdv++; | |
4536 | ||
4537 | if (entry->lazyplt) | |
4538 | dinfo->lzplt += 8; | |
90219bd0 AO |
4539 | } |
4540 | ||
4541 | /* Compute the total GOT size required by each TLS symbol in each | |
4542 | range. Symbols may require up to 5 words in the GOT: an entry | |
4543 | holding the TLS offset for the symbol, and an entry with a full TLS | |
4544 | descriptor taking 4 words. */ | |
4545 | ||
4546 | static void | |
4547 | _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry, | |
4548 | struct _frvfdpic_dynamic_got_info *dinfo, | |
4549 | bfd_boolean subtract) | |
4550 | { | |
4551 | const int l = subtract ? -1 : 1; | |
3b36f7e6 | 4552 | |
90219bd0 AO |
4553 | /* Allocate space for a GOT entry with the TLS offset of the |
4554 | symbol. */ | |
4555 | if (entry->tlsoff12) | |
4556 | dinfo->got12 += 4 * l; | |
4557 | else if (entry->tlsofflos) | |
4558 | dinfo->gotlos += 4 * l; | |
4559 | else if (entry->tlsoffhilo) | |
4560 | dinfo->gothilo += 4 * l; | |
4561 | else | |
4562 | entry->relocstlsoff -= l; | |
4563 | entry->relocstlsoff += l; | |
4564 | ||
4565 | /* If there's any TLSOFF relocation, mark the output file as not | |
4566 | suitable for dlopening. This mark will remain even if we relax | |
4567 | all such relocations, but this is not a problem, since we'll only | |
4568 | do so for executables, and we definitely don't want anyone | |
4569 | dlopening executables. */ | |
4570 | if (entry->relocstlsoff) | |
4571 | dinfo->info->flags |= DF_STATIC_TLS; | |
4572 | ||
4573 | /* Allocate space for a TLS descriptor. */ | |
4574 | if (entry->tlsdesc12) | |
4575 | dinfo->tlsd12 += 8 * l; | |
4576 | else if (entry->tlsdesclos) | |
4577 | dinfo->tlsdlos += 8 * l; | |
4578 | else if (entry->tlsplt) | |
4579 | dinfo->tlsdplt += 8 * l; | |
4580 | else if (entry->tlsdeschilo) | |
4581 | dinfo->tlsdhilo += 8 * l; | |
4582 | else | |
4583 | entry->relocstlsd -= l; | |
4584 | entry->relocstlsd += l; | |
4585 | } | |
4586 | ||
4587 | /* Compute the number of dynamic relocations and fixups that a symbol | |
4588 | requires, and add (or subtract) from the grand and per-symbol | |
4589 | totals. */ | |
4590 | ||
4591 | static void | |
4592 | _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry, | |
4593 | struct _frvfdpic_dynamic_got_info *dinfo, | |
4594 | bfd_boolean subtract) | |
4595 | { | |
4596 | bfd_vma relocs = 0, fixups = 0, tlsrets = 0; | |
51532845 AO |
4597 | |
4598 | if (!dinfo->info->executable || dinfo->info->pie) | |
90219bd0 AO |
4599 | { |
4600 | relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv | |
4601 | + entry->relocstlsd; | |
4602 | ||
4603 | /* In the executable, TLS relocations to symbols that bind | |
4604 | locally (including those that resolve to global TLS offsets) | |
4605 | are resolved immediately, without any need for fixups or | |
4606 | dynamic relocations. In shared libraries, however, we must | |
4607 | emit dynamic relocations even for local symbols, because we | |
4608 | don't know the module id the library is going to get at | |
4609 | run-time, nor its TLS base offset. */ | |
4610 | if (!dinfo->info->executable | |
4611 | || (entry->symndx == -1 | |
4612 | && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) | |
4613 | relocs += entry->relocstlsoff; | |
4614 | } | |
51532845 AO |
4615 | else |
4616 | { | |
43850d5b | 4617 | if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)) |
51532845 AO |
4618 | { |
4619 | if (entry->symndx != -1 | |
3b712a1a AO |
4620 | || entry->d.h->root.type != bfd_link_hash_undefweak) |
4621 | fixups += entry->relocs32 + 2 * entry->relocsfdv; | |
90219bd0 AO |
4622 | fixups += entry->relocstlsd; |
4623 | tlsrets += entry->relocstlsd; | |
51532845 AO |
4624 | } |
4625 | else | |
90219bd0 AO |
4626 | { |
4627 | relocs += entry->relocs32 + entry->relocsfdv | |
4628 | + entry->relocstlsoff + entry->relocstlsd; | |
4629 | } | |
3b712a1a | 4630 | |
43850d5b AO |
4631 | if (entry->symndx != -1 |
4632 | || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)) | |
51532845 AO |
4633 | { |
4634 | if (entry->symndx != -1 | |
4635 | || entry->d.h->root.type != bfd_link_hash_undefweak) | |
3b712a1a | 4636 | fixups += entry->relocsfd; |
51532845 AO |
4637 | } |
4638 | else | |
3b712a1a | 4639 | relocs += entry->relocsfd; |
51532845 AO |
4640 | } |
4641 | ||
90219bd0 AO |
4642 | if (subtract) |
4643 | { | |
4644 | relocs = - relocs; | |
4645 | fixups = - fixups; | |
4646 | tlsrets = - tlsrets; | |
4647 | } | |
4648 | ||
3b712a1a AO |
4649 | entry->dynrelocs += relocs; |
4650 | entry->fixups += fixups; | |
4651 | dinfo->relocs += relocs; | |
4652 | dinfo->fixups += fixups; | |
90219bd0 AO |
4653 | dinfo->tls_ret_refs += tlsrets; |
4654 | } | |
3b712a1a | 4655 | |
90219bd0 AO |
4656 | /* Look for opportunities to relax TLS relocations. We can assume |
4657 | we're linking the main executable or a static-tls library, since | |
4658 | otherwise we wouldn't have got here. When relaxing, we have to | |
4659 | first undo any previous accounting of TLS uses of fixups, dynamic | |
4660 | relocations, GOT and PLT entries. */ | |
4661 | ||
4662 | static void | |
4663 | _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry, | |
4664 | struct _frvfdpic_dynamic_got_info *dinfo, | |
4665 | bfd_boolean relaxing) | |
4666 | { | |
4667 | bfd_boolean changed = ! relaxing; | |
4668 | ||
4669 | BFD_ASSERT (dinfo->info->executable | |
4670 | || (dinfo->info->flags & DF_STATIC_TLS)); | |
4671 | ||
4672 | if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo) | |
4673 | { | |
4674 | if (! changed) | |
4675 | { | |
4676 | _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); | |
4677 | _frvfdpic_count_tls_entries (entry, dinfo, TRUE); | |
4678 | changed = TRUE; | |
4679 | } | |
4680 | ||
4681 | /* When linking an executable, we can always decay GOTTLSDESC to | |
4682 | TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise. | |
4683 | When linking a static-tls shared library, using TLSMOFF is | |
4684 | not an option, but we can still use GOTTLSOFF. When decaying | |
4685 | to GOTTLSOFF, we must keep the GOT entry in range. We know | |
4686 | it has to fit because we'll be trading the 4 words of hte TLS | |
4687 | descriptor for a single word in the same range. */ | |
4688 | if (! dinfo->info->executable | |
4689 | || (entry->symndx == -1 | |
4690 | && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) | |
4691 | { | |
4692 | entry->tlsoff12 |= entry->tlsdesc12; | |
4693 | entry->tlsofflos |= entry->tlsdesclos; | |
4694 | entry->tlsoffhilo |= entry->tlsdeschilo; | |
4695 | } | |
4696 | ||
4697 | entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0; | |
4698 | } | |
4699 | ||
4700 | /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the | |
4701 | main executable. We have to check whether the symbol's TLSOFF is | |
4702 | in range for a setlos. For symbols with a hash entry, we can | |
4703 | determine exactly what to do; for others locals, we don't have | |
4704 | addresses handy, so we use the size of the TLS section as an | |
4705 | approximation. If we get it wrong, we'll retain a GOT entry | |
4706 | holding the TLS offset (without dynamic relocations or fixups), | |
4707 | but we'll still optimize away the loads from it. Since TLS sizes | |
4708 | are generally very small, it's probably not worth attempting to | |
4709 | do better than this. */ | |
4710 | if ((entry->tlsplt | |
4711 | || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo) | |
4712 | && dinfo->info->executable && relaxing | |
4713 | && ((entry->symndx == -1 | |
4714 | && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) | |
4715 | /* The above may hold for an undefweak TLS symbol, so make | |
4716 | sure we don't have this case before accessing def.value | |
4717 | and def.section. */ | |
4718 | && (entry->d.h->root.type == bfd_link_hash_undefweak | |
4719 | || (bfd_vma)(entry->d.h->root.u.def.value | |
4720 | + (entry->d.h->root.u.def.section | |
4721 | ->output_section->vma) | |
4722 | + entry->d.h->root.u.def.section->output_offset | |
4723 | + entry->addend | |
4724 | - tls_biased_base (dinfo->info) | |
4725 | + 32768) < (bfd_vma)65536)) | |
4726 | || (entry->symndx != -1 | |
4727 | && (elf_hash_table (dinfo->info)->tls_sec->size | |
4728 | + abs (entry->addend) < 32768 + FRVFDPIC_TLS_BIAS)))) | |
4729 | { | |
4730 | if (! changed) | |
4731 | { | |
4732 | _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); | |
4733 | _frvfdpic_count_tls_entries (entry, dinfo, TRUE); | |
4734 | changed = TRUE; | |
4735 | } | |
3b36f7e6 | 4736 | |
90219bd0 AO |
4737 | entry->tlsplt = |
4738 | entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0; | |
4739 | } | |
4740 | ||
4741 | /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already | |
4742 | have a #gottlsoff12 relocation for this entry, or if we can fit | |
4743 | one more in the 12-bit (and 16-bit) ranges. */ | |
4744 | if (entry->tlsplt | |
4745 | && (entry->tlsoff12 | |
4746 | || (relaxing | |
4747 | && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4 | |
4748 | && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 | |
4749 | + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos | |
4750 | <= 65536 - 12 - 4)))) | |
4751 | { | |
4752 | if (! changed) | |
4753 | { | |
4754 | _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); | |
4755 | _frvfdpic_count_tls_entries (entry, dinfo, TRUE); | |
4756 | changed = TRUE; | |
4757 | } | |
4758 | ||
4759 | entry->tlsoff12 = 1; | |
4760 | entry->tlsplt = 0; | |
4761 | } | |
4762 | ||
4763 | if (changed) | |
4764 | { | |
4765 | _frvfdpic_count_tls_entries (entry, dinfo, FALSE); | |
4766 | _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE); | |
4767 | } | |
4768 | ||
4769 | return; | |
51532845 AO |
4770 | } |
4771 | ||
90219bd0 AO |
4772 | /* Compute the total GOT and PLT size required by each symbol in each range. * |
4773 | Symbols may require up to 4 words in the GOT: an entry pointing to | |
4774 | the symbol, an entry pointing to its function descriptor, and a | |
4775 | private function descriptors taking two words. */ | |
51532845 | 4776 | |
90219bd0 AO |
4777 | static int |
4778 | _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_) | |
51532845 | 4779 | { |
90219bd0 AO |
4780 | struct frvfdpic_relocs_info *entry = *entryp; |
4781 | struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; | |
4782 | ||
4783 | _frvfdpic_count_nontls_entries (entry, dinfo); | |
4784 | ||
4785 | if (dinfo->info->executable || (dinfo->info->flags & DF_STATIC_TLS)) | |
4786 | _frvfdpic_relax_tls_entries (entry, dinfo, FALSE); | |
4787 | else | |
4788 | { | |
4789 | _frvfdpic_count_tls_entries (entry, dinfo, FALSE); | |
4790 | _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE); | |
4791 | } | |
51532845 | 4792 | |
90219bd0 AO |
4793 | return 1; |
4794 | } | |
51532845 AO |
4795 | |
4796 | /* Determine the positive and negative ranges to be used by each | |
4797 | offset range in the GOT. FDCUR and CUR, that must be aligned to a | |
4798 | double-word boundary, are the minimum (negative) and maximum | |
4799 | (positive) GOT offsets already used by previous ranges, except for | |
4800 | an ODD entry that may have been left behind. GOT and FD indicate | |
4801 | the size of GOT entries and function descriptors that must be | |
4802 | placed within the range from -WRAP to WRAP. If there's room left, | |
4803 | up to FDPLT bytes should be reserved for additional function | |
4804 | descriptors. */ | |
4805 | ||
4806 | inline static bfd_signed_vma | |
43850d5b AO |
4807 | _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad, |
4808 | bfd_signed_vma fdcur, | |
4809 | bfd_signed_vma odd, | |
4810 | bfd_signed_vma cur, | |
4811 | bfd_vma got, | |
4812 | bfd_vma fd, | |
4813 | bfd_vma fdplt, | |
90219bd0 AO |
4814 | bfd_vma tlsd, |
4815 | bfd_vma tlsdplt, | |
43850d5b | 4816 | bfd_vma wrap) |
51532845 AO |
4817 | { |
4818 | bfd_signed_vma wrapmin = -wrap; | |
90219bd0 | 4819 | const bfd_vma tdescsz = 8; |
51532845 AO |
4820 | |
4821 | /* Start at the given initial points. */ | |
4822 | gad->fdcur = fdcur; | |
4823 | gad->cur = cur; | |
4824 | ||
4825 | /* If we had an incoming odd word and we have any got entries that | |
4826 | are going to use it, consume it, otherwise leave gad->odd at | |
4827 | zero. We might force gad->odd to zero and return the incoming | |
4828 | odd such that it is used by the next range, but then GOT entries | |
4829 | might appear to be out of order and we wouldn't be able to | |
4830 | shorten the GOT by one word if it turns out to end with an | |
4831 | unpaired GOT entry. */ | |
4832 | if (odd && got) | |
4833 | { | |
4834 | gad->odd = odd; | |
4835 | got -= 4; | |
4836 | odd = 0; | |
4837 | } | |
4838 | else | |
4839 | gad->odd = 0; | |
4840 | ||
4841 | /* If we're left with an unpaired GOT entry, compute its location | |
4842 | such that we can return it. Otherwise, if got doesn't require an | |
4843 | odd number of words here, either odd was already zero in the | |
4844 | block above, or it was set to zero because got was non-zero, or | |
4845 | got was already zero. In the latter case, we want the value of | |
4846 | odd to carry over to the return statement, so we don't want to | |
4847 | reset odd unless the condition below is true. */ | |
4848 | if (got & 4) | |
4849 | { | |
4850 | odd = cur + got; | |
4851 | got += 4; | |
4852 | } | |
f12123c0 | 4853 | |
51532845 AO |
4854 | /* Compute the tentative boundaries of this range. */ |
4855 | gad->max = cur + got; | |
4856 | gad->min = fdcur - fd; | |
4857 | gad->fdplt = 0; | |
4858 | ||
4859 | /* If function descriptors took too much space, wrap some of them | |
4860 | around. */ | |
4861 | if (gad->min < wrapmin) | |
4862 | { | |
4863 | gad->max += wrapmin - gad->min; | |
90219bd0 AO |
4864 | gad->tmin = gad->min = wrapmin; |
4865 | } | |
4866 | ||
4867 | /* If GOT entries took too much space, wrap some of them around. | |
4868 | This may well cause gad->min to become lower than wrapmin. This | |
4869 | will cause a relocation overflow later on, so we don't have to | |
4870 | report it here . */ | |
4871 | if ((bfd_vma) gad->max > wrap) | |
4872 | { | |
4873 | gad->min -= gad->max - wrap; | |
4874 | gad->max = wrap; | |
4875 | } | |
4876 | ||
4877 | /* Add TLS descriptors. */ | |
4878 | gad->tmax = gad->max + tlsd; | |
4879 | gad->tmin = gad->min; | |
4880 | gad->tlsdplt = 0; | |
4881 | ||
4882 | /* If TLS descriptors took too much space, wrap an integral number | |
4883 | of them around. */ | |
4884 | if ((bfd_vma) gad->tmax > wrap) | |
4885 | { | |
4886 | bfd_vma wrapsize = gad->tmax - wrap; | |
4887 | ||
4888 | wrapsize += tdescsz / 2; | |
4889 | wrapsize &= ~ tdescsz / 2; | |
4890 | ||
4891 | gad->tmin -= wrapsize; | |
4892 | gad->tmax -= wrapsize; | |
51532845 | 4893 | } |
90219bd0 | 4894 | |
51532845 AO |
4895 | /* If there is space left and we have function descriptors |
4896 | referenced in PLT entries that could take advantage of shorter | |
90219bd0 AO |
4897 | offsets, place them now. */ |
4898 | if (fdplt && gad->tmin > wrapmin) | |
51532845 AO |
4899 | { |
4900 | bfd_vma fds; | |
90219bd0 AO |
4901 | |
4902 | if ((bfd_vma) (gad->tmin - wrapmin) < fdplt) | |
4903 | fds = gad->tmin - wrapmin; | |
51532845 AO |
4904 | else |
4905 | fds = fdplt; | |
4906 | ||
4907 | fdplt -= fds; | |
4908 | gad->min -= fds; | |
90219bd0 | 4909 | gad->tmin -= fds; |
51532845 AO |
4910 | gad->fdplt += fds; |
4911 | } | |
4912 | ||
51532845 AO |
4913 | /* If there is more space left, try to place some more function |
4914 | descriptors for PLT entries. */ | |
90219bd0 | 4915 | if (fdplt && (bfd_vma) gad->tmax < wrap) |
51532845 AO |
4916 | { |
4917 | bfd_vma fds; | |
90219bd0 AO |
4918 | |
4919 | if ((bfd_vma) (wrap - gad->tmax) < fdplt) | |
4920 | fds = wrap - gad->tmax; | |
51532845 AO |
4921 | else |
4922 | fds = fdplt; | |
4923 | ||
4924 | fdplt -= fds; | |
4925 | gad->max += fds; | |
90219bd0 | 4926 | gad->tmax += fds; |
51532845 AO |
4927 | gad->fdplt += fds; |
4928 | } | |
4929 | ||
90219bd0 AO |
4930 | /* If there is space left and we have TLS descriptors referenced in |
4931 | PLT entries that could take advantage of shorter offsets, place | |
4932 | them now. */ | |
4933 | if (tlsdplt && gad->tmin > wrapmin) | |
4934 | { | |
4935 | bfd_vma tlsds; | |
4936 | ||
4937 | if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt) | |
4938 | tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2); | |
4939 | else | |
4940 | tlsds = tlsdplt; | |
4941 | ||
4942 | tlsdplt -= tlsds; | |
4943 | gad->tmin -= tlsds; | |
4944 | gad->tlsdplt += tlsds; | |
4945 | } | |
4946 | ||
4947 | /* If there is more space left, try to place some more TLS | |
4948 | descriptors for PLT entries. Although we could try to fit an | |
4949 | additional TLS descriptor with half of it just before before the | |
4950 | wrap point and another right past the wrap point, this might | |
4951 | cause us to run out of space for the next region, so don't do | |
4952 | it. */ | |
4953 | if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2) | |
4954 | { | |
4955 | bfd_vma tlsds; | |
4956 | ||
4957 | if ((bfd_vma) (wrap - gad->tmax) < tlsdplt) | |
4958 | tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2); | |
4959 | else | |
4960 | tlsds = tlsdplt; | |
4961 | ||
4962 | tlsdplt -= tlsds; | |
4963 | gad->tmax += tlsds; | |
4964 | gad->tlsdplt += tlsds; | |
4965 | } | |
4966 | ||
51532845 AO |
4967 | /* If odd was initially computed as an offset past the wrap point, |
4968 | wrap it around. */ | |
4969 | if (odd > gad->max) | |
4970 | odd = gad->min + odd - gad->max; | |
4971 | ||
43850d5b | 4972 | /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed |
51532845 AO |
4973 | before returning, so do it here too. This guarantees that, |
4974 | should cur and fdcur meet at the wrap point, they'll both be | |
4975 | equal to min. */ | |
4976 | if (gad->cur == gad->max) | |
4977 | gad->cur = gad->min; | |
4978 | ||
90219bd0 AO |
4979 | /* Ditto for _frvfdpic_get_tlsdesc_entry(). */ |
4980 | gad->tcur = gad->max; | |
4981 | if (gad->tcur == gad->tmax) | |
4982 | gad->tcur = gad->tmin; | |
4983 | ||
51532845 AO |
4984 | return odd; |
4985 | } | |
4986 | ||
4987 | /* Compute the location of the next GOT entry, given the allocation | |
4988 | data for a range. */ | |
4989 | ||
4990 | inline static bfd_signed_vma | |
43850d5b | 4991 | _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) |
51532845 AO |
4992 | { |
4993 | bfd_signed_vma ret; | |
f12123c0 | 4994 | |
51532845 AO |
4995 | if (gad->odd) |
4996 | { | |
4997 | /* If there was an odd word left behind, use it. */ | |
4998 | ret = gad->odd; | |
4999 | gad->odd = 0; | |
5000 | } | |
5001 | else | |
5002 | { | |
5003 | /* Otherwise, use the word pointed to by cur, reserve the next | |
5004 | as an odd word, and skip to the next pair of words, possibly | |
5005 | wrapping around. */ | |
5006 | ret = gad->cur; | |
5007 | gad->odd = gad->cur + 4; | |
5008 | gad->cur += 8; | |
5009 | if (gad->cur == gad->max) | |
5010 | gad->cur = gad->min; | |
5011 | } | |
5012 | ||
5013 | return ret; | |
5014 | } | |
5015 | ||
5016 | /* Compute the location of the next function descriptor entry in the | |
5017 | GOT, given the allocation data for a range. */ | |
5018 | ||
5019 | inline static bfd_signed_vma | |
43850d5b | 5020 | _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) |
51532845 AO |
5021 | { |
5022 | /* If we're at the bottom, wrap around, and only then allocate the | |
5023 | next pair of words. */ | |
5024 | if (gad->fdcur == gad->min) | |
5025 | gad->fdcur = gad->max; | |
5026 | return gad->fdcur -= 8; | |
5027 | } | |
5028 | ||
90219bd0 AO |
5029 | /* Compute the location of the next TLS descriptor entry in the GOT, |
5030 | given the allocation data for a range. */ | |
5031 | inline static bfd_signed_vma | |
5032 | _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) | |
5033 | { | |
5034 | bfd_signed_vma ret; | |
5035 | ||
5036 | ret = gad->tcur; | |
5037 | ||
5038 | gad->tcur += 8; | |
5039 | ||
5040 | /* If we're at the top of the region, wrap around to the bottom. */ | |
5041 | if (gad->tcur == gad->tmax) | |
5042 | gad->tcur = gad->tmin; | |
5043 | ||
5044 | return ret; | |
5045 | } | |
5046 | ||
51532845 AO |
5047 | /* Assign GOT offsets for every GOT entry and function descriptor. |
5048 | Doing everything in a single pass is tricky. */ | |
5049 | ||
5050 | static int | |
43850d5b | 5051 | _frvfdpic_assign_got_entries (void **entryp, void *info_) |
51532845 | 5052 | { |
43850d5b AO |
5053 | struct frvfdpic_relocs_info *entry = *entryp; |
5054 | struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; | |
51532845 AO |
5055 | |
5056 | if (entry->got12) | |
43850d5b | 5057 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12); |
51532845 | 5058 | else if (entry->gotlos) |
43850d5b | 5059 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); |
51532845 | 5060 | else if (entry->gothilo) |
43850d5b | 5061 | entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); |
51532845 AO |
5062 | |
5063 | if (entry->fdgot12) | |
43850d5b | 5064 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12); |
51532845 | 5065 | else if (entry->fdgotlos) |
43850d5b | 5066 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); |
51532845 | 5067 | else if (entry->fdgothilo) |
43850d5b | 5068 | entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); |
51532845 AO |
5069 | |
5070 | if (entry->fdgoff12) | |
43850d5b | 5071 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); |
51532845 AO |
5072 | else if (entry->plt && dinfo->got12.fdplt) |
5073 | { | |
5074 | dinfo->got12.fdplt -= 8; | |
43850d5b | 5075 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); |
51532845 AO |
5076 | } |
5077 | else if (entry->fdgofflos) | |
43850d5b | 5078 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); |
51532845 AO |
5079 | else if (entry->plt && dinfo->gotlos.fdplt) |
5080 | { | |
5081 | dinfo->gotlos.fdplt -= 8; | |
43850d5b | 5082 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); |
51532845 AO |
5083 | } |
5084 | else if (entry->plt) | |
5085 | { | |
5086 | dinfo->gothilo.fdplt -= 8; | |
43850d5b | 5087 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); |
51532845 AO |
5088 | } |
5089 | else if (entry->privfd) | |
43850d5b | 5090 | entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); |
f12123c0 | 5091 | |
90219bd0 AO |
5092 | if (entry->tlsoff12) |
5093 | entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12); | |
5094 | else if (entry->tlsofflos) | |
5095 | entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); | |
5096 | else if (entry->tlsoffhilo) | |
5097 | entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); | |
5098 | ||
5099 | if (entry->tlsdesc12) | |
5100 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); | |
5101 | else if (entry->tlsplt && dinfo->got12.tlsdplt) | |
5102 | { | |
5103 | dinfo->got12.tlsdplt -= 8; | |
5104 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); | |
5105 | } | |
5106 | else if (entry->tlsdesclos) | |
5107 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); | |
5108 | else if (entry->tlsplt && dinfo->gotlos.tlsdplt) | |
5109 | { | |
5110 | dinfo->gotlos.tlsdplt -= 8; | |
5111 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); | |
5112 | } | |
5113 | else if (entry->tlsplt) | |
5114 | { | |
5115 | dinfo->gothilo.tlsdplt -= 8; | |
5116 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); | |
5117 | } | |
5118 | else if (entry->tlsdeschilo) | |
5119 | entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); | |
5120 | ||
51532845 AO |
5121 | return 1; |
5122 | } | |
5123 | ||
5124 | /* Assign GOT offsets to private function descriptors used by PLT | |
5125 | entries (or referenced by 32-bit offsets), as well as PLT entries | |
5126 | and lazy PLT entries. */ | |
5127 | ||
5128 | static int | |
43850d5b | 5129 | _frvfdpic_assign_plt_entries (void **entryp, void *info_) |
51532845 | 5130 | { |
43850d5b AO |
5131 | struct frvfdpic_relocs_info *entry = *entryp; |
5132 | struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; | |
51532845 | 5133 | |
90219bd0 AO |
5134 | if (entry->privfd) |
5135 | BFD_ASSERT (entry->fd_entry); | |
51532845 AO |
5136 | |
5137 | if (entry->plt) | |
5138 | { | |
5139 | int size; | |
5140 | ||
5141 | /* We use the section's raw size to mark the location of the | |
5142 | next PLT entry. */ | |
eea6121a | 5143 | entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size; |
51532845 AO |
5144 | |
5145 | /* Figure out the length of this PLT entry based on the | |
5146 | addressing mode we need to reach the function descriptor. */ | |
5147 | BFD_ASSERT (entry->fd_entry); | |
5148 | if (entry->fd_entry >= -(1 << (12 - 1)) | |
5149 | && entry->fd_entry < (1 << (12 - 1))) | |
5150 | size = 8; | |
5151 | else if (entry->fd_entry >= -(1 << (16 - 1)) | |
5152 | && entry->fd_entry < (1 << (16 - 1))) | |
5153 | size = 12; | |
5154 | else | |
5155 | size = 16; | |
5156 | ||
eea6121a | 5157 | frvfdpic_plt_section (dinfo->g.info)->size += size; |
51532845 AO |
5158 | } |
5159 | ||
5160 | if (entry->lazyplt) | |
5161 | { | |
5162 | entry->lzplt_entry = dinfo->g.lzplt; | |
5163 | dinfo->g.lzplt += 8; | |
5164 | /* If this entry is the one that gets the resolver stub, account | |
5165 | for the additional instruction. */ | |
43850d5b AO |
5166 | if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE |
5167 | == FRVFDPIC_LZPLT_RESOLV_LOC) | |
51532845 AO |
5168 | dinfo->g.lzplt += 4; |
5169 | } | |
f12123c0 | 5170 | |
90219bd0 AO |
5171 | if (entry->tlsplt) |
5172 | { | |
5173 | int size; | |
5174 | ||
5175 | entry->tlsplt_entry | |
5176 | = frvfdpic_plt_section (dinfo->g.info)->size; | |
5177 | ||
5178 | if (dinfo->g.info->executable | |
5179 | && (entry->symndx != -1 | |
5180 | || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h))) | |
5181 | { | |
5182 | if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1)) | |
5183 | /* FIXME: here we use the size of the TLS section | |
5184 | as an upper bound for the value of the TLS | |
5185 | symbol, because we may not know the exact value | |
5186 | yet. If we get it wrong, we'll just waste a | |
5187 | word in the PLT, and we should never get even | |
5188 | close to 32 KiB of TLS anyway. */ | |
5189 | && elf_hash_table (dinfo->g.info)->tls_sec | |
5190 | && (elf_hash_table (dinfo->g.info)->tls_sec->size | |
5191 | + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1)))) | |
5192 | size = 8; | |
5193 | else | |
5194 | size = 12; | |
5195 | } | |
5196 | else if (entry->tlsoff_entry) | |
5197 | { | |
5198 | if (entry->tlsoff_entry >= -(1 << (12 - 1)) | |
5199 | && entry->tlsoff_entry < (1 << (12 - 1))) | |
5200 | size = 8; | |
5201 | else if (entry->tlsoff_entry >= -(1 << (16 - 1)) | |
5202 | && entry->tlsoff_entry < (1 << (16 - 1))) | |
5203 | size = 12; | |
5204 | else | |
5205 | size = 16; | |
5206 | } | |
5207 | else | |
5208 | { | |
5209 | BFD_ASSERT (entry->tlsdesc_entry); | |
5210 | ||
5211 | if (entry->tlsdesc_entry >= -(1 << (12 - 1)) | |
5212 | && entry->tlsdesc_entry < (1 << (12 - 1))) | |
5213 | size = 8; | |
5214 | else if (entry->tlsdesc_entry >= -(1 << (16 - 1)) | |
5215 | && entry->tlsdesc_entry < (1 << (16 - 1))) | |
5216 | size = 12; | |
5217 | else | |
5218 | size = 16; | |
5219 | } | |
3b36f7e6 | 5220 | |
90219bd0 AO |
5221 | frvfdpic_plt_section (dinfo->g.info)->size += size; |
5222 | } | |
5223 | ||
5224 | return 1; | |
5225 | } | |
5226 | ||
5227 | /* Cancel out any effects of calling _frvfdpic_assign_got_entries and | |
5228 | _frvfdpic_assign_plt_entries. */ | |
5229 | ||
5230 | static int | |
5231 | _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED) | |
5232 | { | |
5233 | struct frvfdpic_relocs_info *entry = *entryp; | |
5234 | ||
5235 | entry->got_entry = 0; | |
5236 | entry->fdgot_entry = 0; | |
5237 | entry->fd_entry = 0; | |
5238 | entry->plt_entry = (bfd_vma)-1; | |
5239 | entry->lzplt_entry = (bfd_vma)-1; | |
5240 | entry->tlsoff_entry = 0; | |
5241 | entry->tlsdesc_entry = 0; | |
5242 | entry->tlsplt_entry = (bfd_vma)-1; | |
5243 | ||
51532845 | 5244 | return 1; |
f12123c0 | 5245 | } |
51532845 AO |
5246 | |
5247 | /* Follow indirect and warning hash entries so that each got entry | |
5248 | points to the final symbol definition. P must point to a pointer | |
5249 | to the hash table we're traversing. Since this traversal may | |
5250 | modify the hash table, we set this pointer to NULL to indicate | |
5251 | we've made a potentially-destructive change to the hash table, so | |
5252 | the traversal must be restarted. */ | |
5253 | static int | |
43850d5b | 5254 | _frvfdpic_resolve_final_relocs_info (void **entryp, void *p) |
51532845 | 5255 | { |
43850d5b | 5256 | struct frvfdpic_relocs_info *entry = *entryp; |
51532845 AO |
5257 | htab_t *htab = p; |
5258 | ||
5259 | if (entry->symndx == -1) | |
5260 | { | |
5261 | struct elf_link_hash_entry *h = entry->d.h; | |
43850d5b | 5262 | struct frvfdpic_relocs_info *oentry; |
51532845 AO |
5263 | |
5264 | while (h->root.type == bfd_link_hash_indirect | |
5265 | || h->root.type == bfd_link_hash_warning) | |
5266 | h = (struct elf_link_hash_entry *)h->root.u.i.link; | |
5267 | ||
5268 | if (entry->d.h == h) | |
5269 | return 1; | |
5270 | ||
43850d5b AO |
5271 | oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend, |
5272 | NO_INSERT); | |
3b712a1a AO |
5273 | |
5274 | if (oentry) | |
5275 | { | |
5276 | /* Merge the two entries. */ | |
43850d5b | 5277 | frvfdpic_pic_merge_early_relocs_info (oentry, entry); |
3b712a1a AO |
5278 | htab_clear_slot (*htab, entryp); |
5279 | return 1; | |
5280 | } | |
5281 | ||
51532845 AO |
5282 | entry->d.h = h; |
5283 | ||
5284 | /* If we can't find this entry with the new bfd hash, re-insert | |
5285 | it, and get the traversal restarted. */ | |
5286 | if (! htab_find (*htab, entry)) | |
5287 | { | |
5288 | htab_clear_slot (*htab, entryp); | |
5289 | entryp = htab_find_slot (*htab, entry, INSERT); | |
5290 | if (! *entryp) | |
5291 | *entryp = entry; | |
5292 | /* Abort the traversal, since the whole table may have | |
5293 | moved, and leave it up to the parent to restart the | |
5294 | process. */ | |
5295 | *(htab_t *)p = NULL; | |
5296 | return 0; | |
5297 | } | |
5298 | } | |
5299 | ||
5300 | return 1; | |
5301 | } | |
5302 | ||
90219bd0 AO |
5303 | /* Compute the total size of the GOT, the PLT, the dynamic relocations |
5304 | section and the rofixup section. Assign locations for GOT and PLT | |
5305 | entries. */ | |
51532845 AO |
5306 | |
5307 | static bfd_boolean | |
90219bd0 AO |
5308 | _frvfdpic_size_got_plt (bfd *output_bfd, |
5309 | struct _frvfdpic_dynamic_got_plt_info *gpinfop) | |
51532845 | 5310 | { |
51532845 | 5311 | bfd_signed_vma odd; |
90219bd0 AO |
5312 | bfd_vma limit, tlslimit; |
5313 | struct bfd_link_info *info = gpinfop->g.info; | |
5314 | bfd *dynobj = elf_hash_table (info)->dynobj; | |
51532845 | 5315 | |
90219bd0 AO |
5316 | memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g, |
5317 | sizeof (gpinfop->g)); | |
51532845 AO |
5318 | |
5319 | odd = 12; | |
5320 | /* Compute the total size taken by entries in the 12-bit and 16-bit | |
5321 | ranges, to tell how many PLT function descriptors we can bring | |
5322 | into the 12-bit range without causing the 16-bit range to | |
5323 | overflow. */ | |
90219bd0 AO |
5324 | limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos |
5325 | + gpinfop->g.fd12 + gpinfop->g.fdlos | |
5326 | + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos; | |
51532845 AO |
5327 | if (limit < (bfd_vma)1 << 16) |
5328 | limit = ((bfd_vma)1 << 16) - limit; | |
5329 | else | |
5330 | limit = 0; | |
90219bd0 AO |
5331 | if (gpinfop->g.fdplt < limit) |
5332 | { | |
5333 | tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8; | |
5334 | limit = gpinfop->g.fdplt; | |
5335 | } | |
5336 | else | |
5337 | tlslimit = 0; | |
5338 | if (gpinfop->g.tlsdplt < tlslimit) | |
5339 | tlslimit = gpinfop->g.tlsdplt; | |
51532845 AO |
5340 | |
5341 | /* Determine the ranges of GOT offsets that we can use for each | |
5342 | range of addressing modes. */ | |
90219bd0 | 5343 | odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12, |
43850d5b AO |
5344 | 0, |
5345 | odd, | |
5346 | 16, | |
90219bd0 AO |
5347 | gpinfop->g.got12, |
5348 | gpinfop->g.fd12, | |
43850d5b | 5349 | limit, |
90219bd0 AO |
5350 | gpinfop->g.tlsd12, |
5351 | tlslimit, | |
43850d5b | 5352 | (bfd_vma)1 << (12-1)); |
90219bd0 AO |
5353 | odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos, |
5354 | gpinfop->got12.tmin, | |
43850d5b | 5355 | odd, |
90219bd0 AO |
5356 | gpinfop->got12.tmax, |
5357 | gpinfop->g.gotlos, | |
5358 | gpinfop->g.fdlos, | |
5359 | gpinfop->g.fdplt | |
5360 | - gpinfop->got12.fdplt, | |
5361 | gpinfop->g.tlsdlos, | |
5362 | gpinfop->g.tlsdplt | |
5363 | - gpinfop->got12.tlsdplt, | |
43850d5b | 5364 | (bfd_vma)1 << (16-1)); |
90219bd0 AO |
5365 | odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo, |
5366 | gpinfop->gotlos.tmin, | |
43850d5b | 5367 | odd, |
90219bd0 AO |
5368 | gpinfop->gotlos.tmax, |
5369 | gpinfop->g.gothilo, | |
5370 | gpinfop->g.fdhilo, | |
5371 | gpinfop->g.fdplt | |
5372 | - gpinfop->got12.fdplt | |
5373 | - gpinfop->gotlos.fdplt, | |
5374 | gpinfop->g.tlsdhilo, | |
5375 | gpinfop->g.tlsdplt | |
5376 | - gpinfop->got12.tlsdplt | |
5377 | - gpinfop->gotlos.tlsdplt, | |
43850d5b | 5378 | (bfd_vma)1 << (32-1)); |
51532845 AO |
5379 | |
5380 | /* Now assign (most) GOT offsets. */ | |
43850d5b | 5381 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries, |
90219bd0 | 5382 | gpinfop); |
51532845 | 5383 | |
90219bd0 AO |
5384 | frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax |
5385 | - gpinfop->gothilo.tmin | |
51532845 AO |
5386 | /* If an odd word is the last word of the GOT, we don't need this |
5387 | word to be part of the GOT. */ | |
90219bd0 | 5388 | - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0); |
eea6121a | 5389 | if (frvfdpic_got_section (info)->size == 0) |
43850d5b | 5390 | frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; |
eea6121a | 5391 | else if (frvfdpic_got_section (info)->size == 12 |
51532845 AO |
5392 | && ! elf_hash_table (info)->dynamic_sections_created) |
5393 | { | |
43850d5b | 5394 | frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; |
eea6121a | 5395 | frvfdpic_got_section (info)->size = 0; |
51532845 | 5396 | } |
90219bd0 AO |
5397 | /* This will be non-NULL during relaxation. The assumption is that |
5398 | the size of one of these sections will never grow, only shrink, | |
5399 | so we can use the larger buffer we allocated before. */ | |
5400 | else if (frvfdpic_got_section (info)->contents == NULL) | |
51532845 | 5401 | { |
43850d5b AO |
5402 | frvfdpic_got_section (info)->contents = |
5403 | (bfd_byte *) bfd_zalloc (dynobj, | |
eea6121a | 5404 | frvfdpic_got_section (info)->size); |
43850d5b | 5405 | if (frvfdpic_got_section (info)->contents == NULL) |
51532845 AO |
5406 | return FALSE; |
5407 | } | |
f12123c0 | 5408 | |
90219bd0 | 5409 | if (frvfdpic_gotrel_section (info)) |
51532845 AO |
5410 | /* Subtract the number of lzplt entries, since those will generate |
5411 | relocations in the pltrel section. */ | |
eea6121a | 5412 | frvfdpic_gotrel_section (info)->size = |
90219bd0 | 5413 | (gpinfop->g.relocs - gpinfop->g.lzplt / 8) |
51532845 AO |
5414 | * get_elf_backend_data (output_bfd)->s->sizeof_rel; |
5415 | else | |
90219bd0 | 5416 | BFD_ASSERT (gpinfop->g.relocs == 0); |
eea6121a | 5417 | if (frvfdpic_gotrel_section (info)->size == 0) |
43850d5b | 5418 | frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5419 | else if (frvfdpic_gotrel_section (info)->contents == NULL) |
51532845 | 5420 | { |
43850d5b AO |
5421 | frvfdpic_gotrel_section (info)->contents = |
5422 | (bfd_byte *) bfd_zalloc (dynobj, | |
eea6121a | 5423 | frvfdpic_gotrel_section (info)->size); |
43850d5b | 5424 | if (frvfdpic_gotrel_section (info)->contents == NULL) |
51532845 AO |
5425 | return FALSE; |
5426 | } | |
5427 | ||
90219bd0 | 5428 | frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4; |
eea6121a | 5429 | if (frvfdpic_gotfixup_section (info)->size == 0) |
43850d5b | 5430 | frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5431 | else if (frvfdpic_gotfixup_section (info)->contents == NULL) |
51532845 | 5432 | { |
43850d5b | 5433 | frvfdpic_gotfixup_section (info)->contents = |
51532845 | 5434 | (bfd_byte *) bfd_zalloc (dynobj, |
eea6121a | 5435 | frvfdpic_gotfixup_section (info)->size); |
43850d5b | 5436 | if (frvfdpic_gotfixup_section (info)->contents == NULL) |
51532845 AO |
5437 | return FALSE; |
5438 | } | |
f12123c0 | 5439 | |
90219bd0 | 5440 | if (frvfdpic_pltrel_section (info)) |
51532845 | 5441 | { |
eea6121a | 5442 | frvfdpic_pltrel_section (info)->size = |
90219bd0 AO |
5443 | gpinfop->g.lzplt / 8 |
5444 | * get_elf_backend_data (output_bfd)->s->sizeof_rel; | |
eea6121a | 5445 | if (frvfdpic_pltrel_section (info)->size == 0) |
43850d5b | 5446 | frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5447 | else if (frvfdpic_pltrel_section (info)->contents == NULL) |
51532845 | 5448 | { |
43850d5b | 5449 | frvfdpic_pltrel_section (info)->contents = |
51532845 | 5450 | (bfd_byte *) bfd_zalloc (dynobj, |
eea6121a | 5451 | frvfdpic_pltrel_section (info)->size); |
43850d5b | 5452 | if (frvfdpic_pltrel_section (info)->contents == NULL) |
51532845 AO |
5453 | return FALSE; |
5454 | } | |
5455 | } | |
f12123c0 | 5456 | |
51532845 AO |
5457 | /* Add 4 bytes for every block of at most 65535 lazy PLT entries, |
5458 | such that there's room for the additional instruction needed to | |
43850d5b AO |
5459 | call the resolver. Since _frvfdpic_assign_got_entries didn't |
5460 | account for them, our block size is 4 bytes smaller than the real | |
5461 | block size. */ | |
90219bd0 | 5462 | if (frvfdpic_plt_section (info)) |
51532845 | 5463 | { |
90219bd0 AO |
5464 | frvfdpic_plt_section (info)->size = gpinfop->g.lzplt |
5465 | + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8) | |
43850d5b | 5466 | / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4); |
51532845 | 5467 | } |
b34976b6 | 5468 | |
43850d5b | 5469 | /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to |
51532845 | 5470 | actually assign lazy PLT entries addresses. */ |
90219bd0 | 5471 | gpinfop->g.lzplt = 0; |
b34976b6 | 5472 | |
51532845 AO |
5473 | /* Save information that we're going to need to generate GOT and PLT |
5474 | entries. */ | |
90219bd0 | 5475 | frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin; |
b34976b6 | 5476 | |
51532845 AO |
5477 | if (get_elf_backend_data (output_bfd)->want_got_sym) |
5478 | elf_hash_table (info)->hgot->root.u.def.value | |
90219bd0 | 5479 | = frvfdpic_got_initial_offset (info); |
b34976b6 | 5480 | |
90219bd0 | 5481 | if (frvfdpic_plt_section (info)) |
43850d5b | 5482 | frvfdpic_plt_initial_offset (info) = |
eea6121a | 5483 | frvfdpic_plt_section (info)->size; |
b34976b6 | 5484 | |
90219bd0 AO |
5485 | /* Allocate a ret statement at plt_initial_offset, to be used by |
5486 | locally-resolved TLS descriptors. */ | |
5487 | if (gpinfop->g.tls_ret_refs) | |
5488 | frvfdpic_plt_section (info)->size += 4; | |
5489 | ||
43850d5b | 5490 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries, |
90219bd0 | 5491 | gpinfop); |
51532845 AO |
5492 | |
5493 | /* Allocate the PLT section contents only after | |
43850d5b | 5494 | _frvfdpic_assign_plt_entries has a chance to add the size of the |
51532845 | 5495 | non-lazy PLT entries. */ |
90219bd0 | 5496 | if (frvfdpic_plt_section (info)) |
51532845 | 5497 | { |
eea6121a | 5498 | if (frvfdpic_plt_section (info)->size == 0) |
43850d5b | 5499 | frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE; |
90219bd0 | 5500 | else if (frvfdpic_plt_section (info)->contents == NULL) |
4e5ba5b7 | 5501 | { |
43850d5b AO |
5502 | frvfdpic_plt_section (info)->contents = |
5503 | (bfd_byte *) bfd_zalloc (dynobj, | |
eea6121a | 5504 | frvfdpic_plt_section (info)->size); |
43850d5b | 5505 | if (frvfdpic_plt_section (info)->contents == NULL) |
51532845 AO |
5506 | return FALSE; |
5507 | } | |
5508 | } | |
b34976b6 | 5509 | |
90219bd0 AO |
5510 | return TRUE; |
5511 | } | |
5512 | ||
5513 | /* Set the sizes of the dynamic sections. */ | |
5514 | ||
5515 | static bfd_boolean | |
5516 | elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd, | |
5517 | struct bfd_link_info *info) | |
5518 | { | |
5519 | bfd *dynobj; | |
5520 | asection *s; | |
5521 | struct _frvfdpic_dynamic_got_plt_info gpinfo; | |
5522 | ||
5523 | dynobj = elf_hash_table (info)->dynobj; | |
5524 | BFD_ASSERT (dynobj != NULL); | |
5525 | ||
5526 | if (elf_hash_table (info)->dynamic_sections_created) | |
5527 | { | |
5528 | /* Set the contents of the .interp section to the interpreter. */ | |
5529 | if (info->executable) | |
5530 | { | |
5531 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
5532 | BFD_ASSERT (s != NULL); | |
5533 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5534 | s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER; | |
5535 | } | |
5536 | } | |
5537 | ||
5538 | memset (&gpinfo, 0, sizeof (gpinfo)); | |
5539 | gpinfo.g.info = info; | |
5540 | ||
5541 | for (;;) | |
5542 | { | |
5543 | htab_t relocs = frvfdpic_relocs_info (info); | |
5544 | ||
5545 | htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs); | |
5546 | ||
5547 | if (relocs == frvfdpic_relocs_info (info)) | |
5548 | break; | |
5549 | } | |
5550 | ||
5551 | htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries, | |
5552 | &gpinfo.g); | |
5553 | ||
5554 | /* Allocate space to save the summary information, we're going to | |
5555 | use it if we're doing relaxations. */ | |
5556 | frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g)); | |
5557 | ||
5558 | if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo)) | |
5559 | return FALSE; | |
5560 | ||
51532845 AO |
5561 | if (elf_hash_table (info)->dynamic_sections_created) |
5562 | { | |
eea6121a | 5563 | if (frvfdpic_got_section (info)->size) |
5a580b3a | 5564 | if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)) |
51532845 AO |
5565 | return FALSE; |
5566 | ||
eea6121a | 5567 | if (frvfdpic_pltrel_section (info)->size) |
5a580b3a AM |
5568 | if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0) |
5569 | || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL) | |
5570 | || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0)) | |
51532845 AO |
5571 | return FALSE; |
5572 | ||
eea6121a | 5573 | if (frvfdpic_gotrel_section (info)->size) |
5a580b3a AM |
5574 | if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0) |
5575 | || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0) | |
5576 | || !_bfd_elf_add_dynamic_entry (info, DT_RELENT, | |
5577 | sizeof (Elf32_External_Rel))) | |
51532845 AO |
5578 | return FALSE; |
5579 | } | |
4e5ba5b7 | 5580 | |
51532845 AO |
5581 | return TRUE; |
5582 | } | |
b34976b6 | 5583 | |
51532845 | 5584 | static bfd_boolean |
43850d5b AO |
5585 | elf32_frvfdpic_always_size_sections (bfd *output_bfd, |
5586 | struct bfd_link_info *info) | |
51532845 | 5587 | { |
43850d5b | 5588 | if (!info->relocatable) |
51532845 AO |
5589 | { |
5590 | struct elf_link_hash_entry *h; | |
b34976b6 | 5591 | |
51532845 AO |
5592 | /* Force a PT_GNU_STACK segment to be created. */ |
5593 | if (! elf_tdata (output_bfd)->stack_flags) | |
5594 | elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X; | |
4e5ba5b7 | 5595 | |
51532845 AO |
5596 | /* Define __stacksize if it's not defined yet. */ |
5597 | h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", | |
5598 | FALSE, FALSE, FALSE); | |
5599 | if (! h || h->root.type != bfd_link_hash_defined | |
5600 | || h->type != STT_OBJECT | |
f5385ebf | 5601 | || !h->def_regular) |
51532845 | 5602 | { |
ea01195e | 5603 | struct bfd_link_hash_entry *bh = NULL; |
4e5ba5b7 | 5604 | |
51532845 AO |
5605 | if (!(_bfd_generic_link_add_one_symbol |
5606 | (info, output_bfd, "__stacksize", | |
5607 | BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE, | |
5608 | (const char *) NULL, FALSE, | |
5609 | get_elf_backend_data (output_bfd)->collect, &bh))) | |
5610 | return FALSE; | |
4e5ba5b7 | 5611 | |
51532845 | 5612 | h = (struct elf_link_hash_entry *) bh; |
f5385ebf | 5613 | h->def_regular = 1; |
51532845 | 5614 | h->type = STT_OBJECT; |
90219bd0 | 5615 | /* This one must NOT be hidden. */ |
51532845 | 5616 | } |
51532845 | 5617 | } |
4e5ba5b7 | 5618 | |
51532845 AO |
5619 | return TRUE; |
5620 | } | |
4e5ba5b7 | 5621 | |
88571279 AO |
5622 | /* Check whether any of the relocations was optimized away, and |
5623 | subtract it from the relocation or fixup count. */ | |
5624 | static bfd_boolean | |
5625 | _frvfdpic_check_discarded_relocs (bfd *abfd, asection *sec, | |
5626 | struct bfd_link_info *info, | |
5627 | ||
5628 | bfd_boolean *changed) | |
5629 | { | |
5630 | Elf_Internal_Shdr *symtab_hdr; | |
5631 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
5632 | Elf_Internal_Rela *rel, *erel; | |
5633 | ||
5634 | if ((sec->flags & SEC_RELOC) == 0 | |
5635 | || sec->reloc_count == 0) | |
5636 | return TRUE; | |
5637 | ||
5638 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
5639 | sym_hashes = elf_sym_hashes (abfd); | |
5640 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym); | |
5641 | if (!elf_bad_symtab (abfd)) | |
5642 | sym_hashes_end -= symtab_hdr->sh_info; | |
5643 | ||
5644 | rel = elf_section_data (sec)->relocs; | |
5645 | ||
5646 | /* Now examine each relocation. */ | |
5647 | for (erel = rel + sec->reloc_count; rel < erel; rel++) | |
5648 | { | |
5649 | struct elf_link_hash_entry *h; | |
5650 | unsigned long r_symndx; | |
5651 | struct frvfdpic_relocs_info *picrel; | |
5652 | struct _frvfdpic_dynamic_got_info *dinfo; | |
5653 | ||
5654 | if (ELF32_R_TYPE (rel->r_info) != R_FRV_32 | |
5655 | && ELF32_R_TYPE (rel->r_info) != R_FRV_FUNCDESC) | |
5656 | continue; | |
5657 | ||
5658 | if (_bfd_elf_section_offset (sec->output_section->owner, | |
5659 | info, sec, rel->r_offset) | |
5660 | != (bfd_vma)-1) | |
5661 | continue; | |
5662 | ||
5663 | r_symndx = ELF32_R_SYM (rel->r_info); | |
5664 | if (r_symndx < symtab_hdr->sh_info) | |
5665 | h = NULL; | |
5666 | else | |
5667 | { | |
5668 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5669 | while (h->root.type == bfd_link_hash_indirect | |
5670 | || h->root.type == bfd_link_hash_warning) | |
5671 | h = (struct elf_link_hash_entry *)h->root.u.i.link; | |
5672 | } | |
5673 | ||
5674 | if (h != NULL) | |
5675 | picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), | |
5676 | abfd, h, | |
5677 | rel->r_addend, NO_INSERT); | |
5678 | else | |
5679 | picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info), | |
5680 | abfd, r_symndx, | |
5681 | rel->r_addend, NO_INSERT); | |
5682 | ||
5683 | if (! picrel) | |
5684 | return FALSE; | |
5685 | ||
5686 | *changed = TRUE; | |
5687 | dinfo = frvfdpic_dynamic_got_plt_info (info); | |
5688 | ||
5689 | _frvfdpic_count_relocs_fixups (picrel, dinfo, TRUE); | |
5690 | if (ELF32_R_TYPE (rel->r_info) == R_FRV_32) | |
5691 | picrel->relocs32--; | |
5692 | else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */ | |
5693 | picrel->relocsfd--; | |
5694 | _frvfdpic_count_relocs_fixups (picrel, dinfo, FALSE); | |
5695 | } | |
5696 | ||
5697 | return TRUE; | |
5698 | } | |
5699 | ||
5700 | static bfd_boolean | |
5701 | frvfdpic_elf_discard_info (bfd *ibfd, | |
5702 | struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED, | |
5703 | struct bfd_link_info *info) | |
5704 | { | |
5705 | bfd_boolean changed = FALSE; | |
5706 | asection *s; | |
5707 | bfd *obfd = NULL; | |
5708 | ||
5709 | /* Account for relaxation of .eh_frame section. */ | |
5710 | for (s = ibfd->sections; s; s = s->next) | |
5711 | if (s->sec_info_type == ELF_INFO_TYPE_EH_FRAME) | |
5712 | { | |
5713 | if (!_frvfdpic_check_discarded_relocs (ibfd, s, info, &changed)) | |
5714 | return FALSE; | |
5715 | obfd = s->output_section->owner; | |
5716 | } | |
5717 | ||
5718 | if (changed) | |
5719 | { | |
5720 | struct _frvfdpic_dynamic_got_plt_info gpinfo; | |
5721 | ||
5722 | memset (&gpinfo, 0, sizeof (gpinfo)); | |
5723 | memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), | |
5724 | sizeof (gpinfo.g)); | |
5725 | ||
5726 | /* Clear GOT and PLT assignments. */ | |
5727 | htab_traverse (frvfdpic_relocs_info (info), | |
5728 | _frvfdpic_reset_got_plt_entries, | |
5729 | NULL); | |
5730 | ||
5731 | if (!_frvfdpic_size_got_plt (obfd, &gpinfo)) | |
5732 | return FALSE; | |
5733 | } | |
5734 | ||
5735 | return TRUE; | |
5736 | } | |
5737 | ||
90219bd0 AO |
5738 | /* Look for opportunities to relax TLS relocations. We can assume |
5739 | we're linking the main executable or a static-tls library, since | |
5740 | otherwise we wouldn't have got here. */ | |
5741 | ||
5742 | static int | |
5743 | _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_) | |
5744 | { | |
5745 | struct frvfdpic_relocs_info *entry = *entryp; | |
5746 | struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; | |
5747 | ||
5748 | _frvfdpic_relax_tls_entries (entry, dinfo, TRUE); | |
5749 | ||
5750 | return 1; | |
5751 | } | |
5752 | ||
5753 | static bfd_boolean | |
5754 | elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
5755 | struct bfd_link_info *info, bfd_boolean *again) | |
5756 | { | |
5757 | struct _frvfdpic_dynamic_got_plt_info gpinfo; | |
5758 | ||
5759 | /* If we return early, we didn't change anything. */ | |
5760 | *again = FALSE; | |
5761 | ||
5762 | /* We'll do our thing when requested to relax the GOT section. */ | |
5763 | if (sec != frvfdpic_got_section (info)) | |
5764 | return TRUE; | |
5765 | ||
5766 | /* We can only relax when linking the main executable or a library | |
5767 | that can't be dlopened. */ | |
5768 | if (! info->executable && ! (info->flags & DF_STATIC_TLS)) | |
5769 | return TRUE; | |
5770 | ||
5771 | /* If there isn't a TLS section for this binary, we can't do | |
5772 | anything about its TLS relocations (it probably doesn't have | |
5773 | any. */ | |
5774 | if (elf_hash_table (info)->tls_sec == NULL) | |
5775 | return TRUE; | |
5776 | ||
5777 | memset (&gpinfo, 0, sizeof (gpinfo)); | |
5778 | memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g)); | |
5779 | ||
5780 | /* Now look for opportunities to relax, adjusting the GOT usage | |
5781 | as needed. */ | |
5782 | htab_traverse (frvfdpic_relocs_info (info), | |
5783 | _frvfdpic_relax_got_plt_entries, | |
5784 | &gpinfo.g); | |
5785 | ||
5786 | /* If we changed anything, reset and re-assign GOT and PLT entries. */ | |
5787 | if (memcmp (frvfdpic_dynamic_got_plt_info (info), | |
5788 | &gpinfo.g, sizeof (gpinfo.g)) != 0) | |
5789 | { | |
5790 | /* Clear GOT and PLT assignments. */ | |
5791 | htab_traverse (frvfdpic_relocs_info (info), | |
5792 | _frvfdpic_reset_got_plt_entries, | |
5793 | NULL); | |
5794 | ||
5795 | /* The owner of the TLS section is the output bfd. There should | |
5796 | be a better way to get to it. */ | |
5797 | if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner, | |
5798 | &gpinfo)) | |
5799 | return FALSE; | |
5800 | ||
5801 | /* Repeat until we don't make any further changes. We could fail to | |
5802 | introduce changes in a round if, for example, the 12-bit range is | |
5803 | full, but we later release some space by getting rid of TLS | |
5804 | descriptors in it. We have to repeat the whole process because | |
5805 | we might have changed the size of a section processed before this | |
5806 | one. */ | |
5807 | *again = TRUE; | |
5808 | } | |
5809 | ||
5810 | return TRUE; | |
5811 | } | |
5812 | ||
51532845 | 5813 | static bfd_boolean |
e36284ab AM |
5814 | elf32_frvfdpic_modify_program_headers (bfd *output_bfd, |
5815 | struct bfd_link_info *info) | |
51532845 | 5816 | { |
e36284ab | 5817 | struct elf_obj_tdata *tdata = elf_tdata (output_bfd); |
43850d5b | 5818 | struct elf_segment_map *m; |
e36284ab | 5819 | Elf_Internal_Phdr *p; |
4e5ba5b7 | 5820 | |
7e9f3bd6 AO |
5821 | /* objcopy and strip preserve what's already there using |
5822 | elf32_frvfdpic_copy_private_bfd_data (). */ | |
5823 | if (! info) | |
5824 | return TRUE; | |
5825 | ||
e36284ab | 5826 | for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++) |
43850d5b AO |
5827 | if (m->p_type == PT_GNU_STACK) |
5828 | break; | |
5829 | ||
5830 | if (m) | |
5831 | { | |
43850d5b | 5832 | struct elf_link_hash_entry *h; |
51532845 | 5833 | |
e36284ab AM |
5834 | /* Obtain the pointer to the __stacksize symbol. */ |
5835 | h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", | |
5836 | FALSE, FALSE, FALSE); | |
5837 | if (h) | |
4e5ba5b7 | 5838 | { |
43850d5b AO |
5839 | while (h->root.type == bfd_link_hash_indirect |
5840 | || h->root.type == bfd_link_hash_warning) | |
e36284ab | 5841 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
43850d5b | 5842 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); |
e36284ab | 5843 | } |
4e5ba5b7 | 5844 | |
e36284ab AM |
5845 | /* Set the header p_memsz from the symbol value. We |
5846 | intentionally ignore the symbol section. */ | |
5847 | if (h && h->root.type == bfd_link_hash_defined) | |
5848 | p->p_memsz = h->root.u.def.value; | |
5849 | else | |
5850 | p->p_memsz = DEFAULT_STACK_SIZE; | |
51532845 | 5851 | |
e36284ab | 5852 | p->p_align = 8; |
51532845 | 5853 | } |
b34976b6 | 5854 | |
51532845 AO |
5855 | return TRUE; |
5856 | } | |
b34976b6 | 5857 | |
51532845 | 5858 | /* Fill in code and data in dynamic sections. */ |
4e5ba5b7 | 5859 | |
51532845 | 5860 | static bfd_boolean |
43850d5b AO |
5861 | elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
5862 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
5863 | { | |
5864 | /* Nothing to be done for non-FDPIC. */ | |
5865 | return TRUE; | |
5866 | } | |
5867 | ||
5868 | static bfd_boolean | |
5869 | elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd, | |
5870 | struct bfd_link_info *info) | |
51532845 AO |
5871 | { |
5872 | bfd *dynobj; | |
5873 | asection *sdyn; | |
4e5ba5b7 | 5874 | |
51532845 | 5875 | dynobj = elf_hash_table (info)->dynobj; |
4e5ba5b7 | 5876 | |
90219bd0 AO |
5877 | if (frvfdpic_dynamic_got_plt_info (info)) |
5878 | { | |
5879 | BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0); | |
5880 | } | |
43850d5b | 5881 | if (frvfdpic_got_section (info)) |
51532845 | 5882 | { |
eea6121a | 5883 | BFD_ASSERT (frvfdpic_gotrel_section (info)->size |
43850d5b | 5884 | == (frvfdpic_gotrel_section (info)->reloc_count |
51532845 | 5885 | * sizeof (Elf32_External_Rel))); |
4e5ba5b7 | 5886 | |
43850d5b | 5887 | if (frvfdpic_gotfixup_section (info)) |
51532845 | 5888 | { |
43850d5b AO |
5889 | struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot; |
5890 | bfd_vma got_value = hgot->root.u.def.value | |
5891 | + hgot->root.u.def.section->output_section->vma | |
5892 | + hgot->root.u.def.section->output_offset; | |
90219bd0 | 5893 | struct bfd_link_hash_entry *hend; |
4e5ba5b7 | 5894 | |
43850d5b AO |
5895 | _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info), |
5896 | got_value, 0); | |
51532845 | 5897 | |
eea6121a | 5898 | if (frvfdpic_gotfixup_section (info)->size |
43850d5b | 5899 | != (frvfdpic_gotfixup_section (info)->reloc_count * 4)) |
51532845 | 5900 | { |
90219bd0 | 5901 | error: |
43850d5b AO |
5902 | (*_bfd_error_handler) |
5903 | ("LINKER BUG: .rofixup section size mismatch"); | |
5904 | return FALSE; | |
51532845 | 5905 | } |
90219bd0 AO |
5906 | |
5907 | hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__", | |
5908 | FALSE, FALSE, TRUE); | |
5909 | if (hend | |
5910 | && (hend->type == bfd_link_hash_defined | |
5911 | || hend->type == bfd_link_hash_defweak)) | |
5912 | { | |
3b36f7e6 | 5913 | bfd_vma value = |
90219bd0 AO |
5914 | frvfdpic_gotfixup_section (info)->output_section->vma |
5915 | + frvfdpic_gotfixup_section (info)->output_offset | |
5916 | + frvfdpic_gotfixup_section (info)->size | |
5917 | - hend->u.def.section->output_section->vma | |
5918 | - hend->u.def.section->output_offset; | |
5919 | BFD_ASSERT (hend->u.def.value == value); | |
5920 | if (hend->u.def.value != value) | |
5921 | goto error; | |
5922 | } | |
4e5ba5b7 DB |
5923 | } |
5924 | } | |
90219bd0 | 5925 | if (frvfdpic_pltrel_section (info)) |
51532845 | 5926 | { |
eea6121a | 5927 | BFD_ASSERT (frvfdpic_pltrel_section (info)->size |
43850d5b | 5928 | == (frvfdpic_pltrel_section (info)->reloc_count |
51532845 AO |
5929 | * sizeof (Elf32_External_Rel))); |
5930 | } | |
4e5ba5b7 | 5931 | |
4e5ba5b7 | 5932 | |
51532845 | 5933 | if (elf_hash_table (info)->dynamic_sections_created) |
4e5ba5b7 | 5934 | { |
51532845 AO |
5935 | Elf32_External_Dyn * dyncon; |
5936 | Elf32_External_Dyn * dynconend; | |
5937 | ||
90219bd0 AO |
5938 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
5939 | ||
51532845 AO |
5940 | BFD_ASSERT (sdyn != NULL); |
5941 | ||
5942 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 5943 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
51532845 AO |
5944 | |
5945 | for (; dyncon < dynconend; dyncon++) | |
4e5ba5b7 | 5946 | { |
51532845 | 5947 | Elf_Internal_Dyn dyn; |
4e5ba5b7 | 5948 | |
51532845 AO |
5949 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
5950 | ||
5951 | switch (dyn.d_tag) | |
4e5ba5b7 DB |
5952 | { |
5953 | default: | |
5954 | break; | |
5955 | ||
51532845 | 5956 | case DT_PLTGOT: |
43850d5b AO |
5957 | dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma |
5958 | + frvfdpic_got_section (info)->output_offset | |
5959 | + frvfdpic_got_initial_offset (info); | |
51532845 AO |
5960 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5961 | break; | |
4e5ba5b7 | 5962 | |
51532845 | 5963 | case DT_JMPREL: |
43850d5b AO |
5964 | dyn.d_un.d_ptr = frvfdpic_pltrel_section (info) |
5965 | ->output_section->vma | |
5966 | + frvfdpic_pltrel_section (info)->output_offset; | |
51532845 AO |
5967 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5968 | break; | |
5969 | ||
5970 | case DT_PLTRELSZ: | |
eea6121a | 5971 | dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size; |
51532845 AO |
5972 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5973 | break; | |
4e5ba5b7 DB |
5974 | } |
5975 | } | |
5976 | } | |
4e5ba5b7 | 5977 | |
51532845 | 5978 | return TRUE; |
4e5ba5b7 DB |
5979 | } |
5980 | ||
51532845 AO |
5981 | /* Adjust a symbol defined by a dynamic object and referenced by a |
5982 | regular object. */ | |
4e5ba5b7 | 5983 | |
b34976b6 | 5984 | static bfd_boolean |
43850d5b AO |
5985 | elf32_frvfdpic_adjust_dynamic_symbol |
5986 | (struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
5987 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) | |
4e5ba5b7 | 5988 | { |
51532845 AO |
5989 | bfd * dynobj; |
5990 | ||
5991 | dynobj = elf_hash_table (info)->dynobj; | |
5992 | ||
5993 | /* Make sure we know what is going on here. */ | |
5994 | BFD_ASSERT (dynobj != NULL | |
f6e332e6 | 5995 | && (h->u.weakdef != NULL |
f5385ebf AM |
5996 | || (h->def_dynamic |
5997 | && h->ref_regular | |
5998 | && !h->def_regular))); | |
51532845 AO |
5999 | |
6000 | /* If this is a weak symbol, and there is a real definition, the | |
6001 | processor independent code will have arranged for us to see the | |
6002 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 6003 | if (h->u.weakdef != NULL) |
51532845 | 6004 | { |
f6e332e6 AM |
6005 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
6006 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
6007 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
6008 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
51532845 AO |
6009 | } |
6010 | ||
b34976b6 | 6011 | return TRUE; |
4e5ba5b7 DB |
6012 | } |
6013 | ||
51532845 | 6014 | /* Perform any actions needed for dynamic symbols. */ |
4e5ba5b7 | 6015 | |
b34976b6 | 6016 | static bfd_boolean |
43850d5b AO |
6017 | elf32_frvfdpic_finish_dynamic_symbol |
6018 | (bfd *output_bfd ATTRIBUTE_UNUSED, | |
6019 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
6020 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED, | |
6021 | Elf_Internal_Sym *sym ATTRIBUTE_UNUSED) | |
4e5ba5b7 | 6022 | { |
b34976b6 | 6023 | return TRUE; |
4e5ba5b7 | 6024 | } |
51532845 | 6025 | |
ec3391e7 AO |
6026 | /* Decide whether to attempt to turn absptr or lsda encodings in |
6027 | shared libraries into pcrel within the given input section. */ | |
6028 | ||
6029 | static bfd_boolean | |
43850d5b AO |
6030 | frvfdpic_elf_use_relative_eh_frame |
6031 | (bfd *input_bfd ATTRIBUTE_UNUSED, | |
6032 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
6033 | asection *eh_frame_section ATTRIBUTE_UNUSED) | |
ec3391e7 AO |
6034 | { |
6035 | /* We can't use PC-relative encodings in FDPIC binaries, in general. */ | |
43850d5b | 6036 | return FALSE; |
ec3391e7 AO |
6037 | } |
6038 | ||
6039 | /* Adjust the contents of an eh_frame_hdr section before they're output. */ | |
6040 | ||
6041 | static bfd_byte | |
43850d5b AO |
6042 | frvfdpic_elf_encode_eh_address (bfd *abfd, |
6043 | struct bfd_link_info *info, | |
6044 | asection *osec, bfd_vma offset, | |
6045 | asection *loc_sec, bfd_vma loc_offset, | |
6046 | bfd_vma *encoded) | |
ec3391e7 AO |
6047 | { |
6048 | struct elf_link_hash_entry *h; | |
6049 | ||
ec3391e7 AO |
6050 | h = elf_hash_table (info)->hgot; |
6051 | BFD_ASSERT (h && h->root.type == bfd_link_hash_defined); | |
6052 | ||
43850d5b AO |
6053 | if (! h || (_frvfdpic_osec_to_segment (abfd, osec) |
6054 | == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section))) | |
ec3391e7 AO |
6055 | return _bfd_elf_encode_eh_address (abfd, info, osec, offset, |
6056 | loc_sec, loc_offset, encoded); | |
6057 | ||
43850d5b AO |
6058 | BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec) |
6059 | == (_frvfdpic_osec_to_segment | |
6060 | (abfd, h->root.u.def.section->output_section))); | |
ec3391e7 AO |
6061 | |
6062 | *encoded = osec->vma + offset | |
6063 | - (h->root.u.def.value | |
6064 | + h->root.u.def.section->output_section->vma | |
6065 | + h->root.u.def.section->output_offset); | |
6066 | ||
6067 | return DW_EH_PE_datarel | DW_EH_PE_sdata4; | |
6068 | } | |
6069 | ||
4e5ba5b7 | 6070 | /* Look through the relocs for a section during the first phase. |
51532845 AO |
6071 | |
6072 | Besides handling virtual table relocs for gc, we have to deal with | |
6073 | all sorts of PIC-related relocations. We describe below the | |
6074 | general plan on how to handle such relocations, even though we only | |
6075 | collect information at this point, storing them in hash tables for | |
6076 | perusal of later passes. | |
6077 | ||
6078 | 32 relocations are propagated to the linker output when creating | |
6079 | position-independent output. LO16 and HI16 relocations are not | |
6080 | supposed to be encountered in this case. | |
6081 | ||
6082 | LABEL16 should always be resolvable by the linker, since it's only | |
6083 | used by branches. | |
6084 | ||
6085 | LABEL24, on the other hand, is used by calls. If it turns out that | |
6086 | the target of a call is a dynamic symbol, a PLT entry must be | |
6087 | created for it, which triggers the creation of a private function | |
6088 | descriptor and, unless lazy binding is disabled, a lazy PLT entry. | |
6089 | ||
6090 | GPREL relocations require the referenced symbol to be in the same | |
6091 | segment as _gp, but this can only be checked later. | |
6092 | ||
6093 | All GOT, GOTOFF and FUNCDESC relocations require a .got section to | |
6094 | exist. LABEL24 might as well, since it may require a PLT entry, | |
6095 | that will require a got. | |
6096 | ||
6097 | Non-FUNCDESC GOT relocations require a GOT entry to be created | |
6098 | regardless of whether the symbol is dynamic. However, since a | |
6099 | global symbol that turns out to not be exported may have the same | |
6100 | address of a non-dynamic symbol, we don't assign GOT entries at | |
6101 | this point, such that we can share them in this case. A relocation | |
6102 | for the GOT entry always has to be created, be it to offset a | |
6103 | private symbol by the section load address, be it to get the symbol | |
6104 | resolved dynamically. | |
6105 | ||
6106 | FUNCDESC GOT relocations require a GOT entry to be created, and | |
6107 | handled as if a FUNCDESC relocation was applied to the GOT entry in | |
6108 | an object file. | |
6109 | ||
6110 | FUNCDESC relocations referencing a symbol that turns out to NOT be | |
6111 | dynamic cause a private function descriptor to be created. The | |
6112 | FUNCDESC relocation then decays to a 32 relocation that points at | |
6113 | the private descriptor. If the symbol is dynamic, the FUNCDESC | |
6114 | relocation is propagated to the linker output, such that the | |
6115 | dynamic linker creates the canonical descriptor, pointing to the | |
6116 | dynamically-resolved definition of the function. | |
6117 | ||
6118 | Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic | |
6119 | symbols that are assigned to the same segment as the GOT, but we | |
6120 | can only check this later, after we know the complete set of | |
6121 | symbols defined and/or exported. | |
6122 | ||
6123 | FUNCDESC GOTOFF relocations require a function descriptor to be | |
6124 | created and, unless lazy binding is disabled or the symbol is not | |
6125 | dynamic, a lazy PLT entry. Since we can't tell at this point | |
6126 | whether a symbol is going to be dynamic, we have to decide later | |
6127 | whether to create a lazy PLT entry or bind the descriptor directly | |
6128 | to the private function. | |
6129 | ||
6130 | FUNCDESC_VALUE relocations are not supposed to be present in object | |
6131 | files, but they may very well be simply propagated to the linker | |
6132 | output, since they have no side effect. | |
6133 | ||
6134 | ||
6135 | A function descriptor always requires a FUNCDESC_VALUE relocation. | |
6136 | Whether it's in .plt.rel or not depends on whether lazy binding is | |
6137 | enabled and on whether the referenced symbol is dynamic. | |
6138 | ||
6139 | The existence of a lazy PLT requires the resolverStub lazy PLT | |
6140 | entry to be present. | |
6141 | ||
6142 | ||
6143 | As for assignment of GOT, PLT and lazy PLT entries, and private | |
6144 | descriptors, we might do them all sequentially, but we can do | |
6145 | better than that. For example, we can place GOT entries and | |
6146 | private function descriptors referenced using 12-bit operands | |
6147 | closer to the PIC register value, such that these relocations don't | |
6148 | overflow. Those that are only referenced with LO16 relocations | |
6149 | could come next, but we may as well place PLT-required function | |
6150 | descriptors in the 12-bit range to make them shorter. Symbols | |
6151 | referenced with LO16/HI16 may come next, but we may place | |
6152 | additional function descriptors in the 16-bit range if we can | |
6153 | reliably tell that we've already placed entries that are ever | |
6154 | referenced with only LO16. PLT entries are therefore generated as | |
6155 | small as possible, while not introducing relocation overflows in | |
6156 | GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be | |
6157 | generated before or after PLT entries, but not intermingled with | |
6158 | them, such that we can have more lazy PLT entries in range for a | |
6159 | branch to the resolverStub. The resolverStub should be emitted at | |
6160 | the most distant location from the first lazy PLT entry such that | |
6161 | it's still in range for a branch, or closer, if there isn't a need | |
6162 | for so many lazy PLT entries. Additional lazy PLT entries may be | |
6163 | emitted after the resolverStub, as long as branches are still in | |
6164 | range. If the branch goes out of range, longer lazy PLT entries | |
6165 | are emitted. | |
6166 | ||
6167 | We could further optimize PLT and lazy PLT entries by giving them | |
6168 | priority in assignment to closer-to-gr17 locations depending on the | |
6169 | number of occurrences of references to them (assuming a function | |
6170 | that's called more often is more important for performance, so its | |
6171 | PLT entry should be faster), or taking hints from the compiler. | |
6172 | Given infinite time and money... :-) */ | |
b34976b6 AM |
6173 | |
6174 | static bfd_boolean | |
4e5ba5b7 DB |
6175 | elf32_frv_check_relocs (abfd, info, sec, relocs) |
6176 | bfd *abfd; | |
6177 | struct bfd_link_info *info; | |
6178 | asection *sec; | |
6179 | const Elf_Internal_Rela *relocs; | |
6180 | { | |
6181 | Elf_Internal_Shdr *symtab_hdr; | |
6182 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
6183 | const Elf_Internal_Rela *rel; | |
6184 | const Elf_Internal_Rela *rel_end; | |
51532845 | 6185 | bfd *dynobj; |
43850d5b | 6186 | struct frvfdpic_relocs_info *picrel; |
b34976b6 | 6187 | |
1049f94e | 6188 | if (info->relocatable) |
b34976b6 AM |
6189 | return TRUE; |
6190 | ||
4e5ba5b7 DB |
6191 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
6192 | sym_hashes = elf_sym_hashes (abfd); | |
6193 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym); | |
6194 | if (!elf_bad_symtab (abfd)) | |
6195 | sym_hashes_end -= symtab_hdr->sh_info; | |
b34976b6 | 6196 | |
51532845 | 6197 | dynobj = elf_hash_table (info)->dynobj; |
4e5ba5b7 DB |
6198 | rel_end = relocs + sec->reloc_count; |
6199 | for (rel = relocs; rel < rel_end; rel++) | |
6200 | { | |
6201 | struct elf_link_hash_entry *h; | |
6202 | unsigned long r_symndx; | |
b34976b6 | 6203 | |
4e5ba5b7 DB |
6204 | r_symndx = ELF32_R_SYM (rel->r_info); |
6205 | if (r_symndx < symtab_hdr->sh_info) | |
6206 | h = NULL; | |
6207 | else | |
973a3492 L |
6208 | { |
6209 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
6210 | while (h->root.type == bfd_link_hash_indirect | |
6211 | || h->root.type == bfd_link_hash_warning) | |
6212 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6213 | } | |
b34976b6 | 6214 | |
51532845 AO |
6215 | switch (ELF32_R_TYPE (rel->r_info)) |
6216 | { | |
90219bd0 AO |
6217 | case R_FRV_GETTLSOFF: |
6218 | case R_FRV_TLSDESC_VALUE: | |
6219 | case R_FRV_GOTTLSDESC12: | |
6220 | case R_FRV_GOTTLSDESCHI: | |
6221 | case R_FRV_GOTTLSDESCLO: | |
6222 | case R_FRV_GOTTLSOFF12: | |
6223 | case R_FRV_GOTTLSOFFHI: | |
6224 | case R_FRV_GOTTLSOFFLO: | |
6225 | case R_FRV_TLSOFF: | |
51532845 AO |
6226 | case R_FRV_GOT12: |
6227 | case R_FRV_GOTHI: | |
6228 | case R_FRV_GOTLO: | |
6229 | case R_FRV_FUNCDESC_GOT12: | |
6230 | case R_FRV_FUNCDESC_GOTHI: | |
6231 | case R_FRV_FUNCDESC_GOTLO: | |
6232 | case R_FRV_GOTOFF12: | |
6233 | case R_FRV_GOTOFFHI: | |
6234 | case R_FRV_GOTOFFLO: | |
6235 | case R_FRV_FUNCDESC_GOTOFF12: | |
6236 | case R_FRV_FUNCDESC_GOTOFFHI: | |
6237 | case R_FRV_FUNCDESC_GOTOFFLO: | |
6238 | case R_FRV_FUNCDESC: | |
6239 | case R_FRV_FUNCDESC_VALUE: | |
90219bd0 AO |
6240 | case R_FRV_TLSMOFF12: |
6241 | case R_FRV_TLSMOFFHI: | |
6242 | case R_FRV_TLSMOFFLO: | |
6243 | case R_FRV_TLSMOFF: | |
43850d5b AO |
6244 | if (! IS_FDPIC (abfd)) |
6245 | goto bad_reloc; | |
6246 | /* Fall through. */ | |
6247 | case R_FRV_GPREL12: | |
6248 | case R_FRV_GPRELU12: | |
6249 | case R_FRV_GPRELHI: | |
6250 | case R_FRV_GPRELLO: | |
6251 | case R_FRV_LABEL24: | |
6252 | case R_FRV_32: | |
51532845 AO |
6253 | if (! dynobj) |
6254 | { | |
6255 | elf_hash_table (info)->dynobj = dynobj = abfd; | |
6256 | if (! _frv_create_got_section (abfd, info)) | |
6257 | return FALSE; | |
6258 | } | |
43850d5b AO |
6259 | if (! IS_FDPIC (abfd)) |
6260 | { | |
6261 | picrel = NULL; | |
6262 | break; | |
6263 | } | |
51532845 AO |
6264 | if (h != NULL) |
6265 | { | |
6266 | if (h->dynindx == -1) | |
6267 | switch (ELF_ST_VISIBILITY (h->other)) | |
6268 | { | |
6269 | case STV_INTERNAL: | |
6270 | case STV_HIDDEN: | |
6271 | break; | |
6272 | default: | |
c152c796 | 6273 | bfd_elf_link_record_dynamic_symbol (info, h); |
51532845 AO |
6274 | break; |
6275 | } | |
6276 | picrel | |
43850d5b AO |
6277 | = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), |
6278 | abfd, h, | |
6279 | rel->r_addend, INSERT); | |
51532845 AO |
6280 | } |
6281 | else | |
43850d5b AO |
6282 | picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info |
6283 | (info), abfd, r_symndx, | |
6284 | rel->r_addend, INSERT); | |
51532845 AO |
6285 | if (! picrel) |
6286 | return FALSE; | |
6287 | break; | |
6288 | ||
6289 | default: | |
6290 | picrel = NULL; | |
6291 | break; | |
6292 | } | |
f12123c0 | 6293 | |
4e5ba5b7 DB |
6294 | switch (ELF32_R_TYPE (rel->r_info)) |
6295 | { | |
51532845 | 6296 | case R_FRV_LABEL24: |
43850d5b AO |
6297 | if (IS_FDPIC (abfd)) |
6298 | picrel->call = 1; | |
51532845 | 6299 | break; |
f12123c0 | 6300 | |
51532845 AO |
6301 | case R_FRV_FUNCDESC_VALUE: |
6302 | picrel->relocsfdv++; | |
6303 | if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
6304 | picrel->relocs32--; | |
6305 | /* Fall through. */ | |
43850d5b | 6306 | |
51532845 | 6307 | case R_FRV_32: |
43850d5b AO |
6308 | if (! IS_FDPIC (abfd)) |
6309 | break; | |
6310 | ||
51532845 AO |
6311 | picrel->sym = 1; |
6312 | if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
6313 | picrel->relocs32++; | |
6314 | break; | |
f12123c0 | 6315 | |
51532845 AO |
6316 | case R_FRV_GOT12: |
6317 | picrel->got12 = 1; | |
6318 | break; | |
f12123c0 | 6319 | |
51532845 AO |
6320 | case R_FRV_GOTHI: |
6321 | case R_FRV_GOTLO: | |
6322 | picrel->gothilo = 1; | |
6323 | break; | |
6324 | ||
6325 | case R_FRV_FUNCDESC_GOT12: | |
6326 | picrel->fdgot12 = 1; | |
6327 | break; | |
f12123c0 | 6328 | |
51532845 AO |
6329 | case R_FRV_FUNCDESC_GOTHI: |
6330 | case R_FRV_FUNCDESC_GOTLO: | |
6331 | picrel->fdgothilo = 1; | |
6332 | break; | |
f12123c0 | 6333 | |
51532845 AO |
6334 | case R_FRV_GOTOFF12: |
6335 | case R_FRV_GOTOFFHI: | |
6336 | case R_FRV_GOTOFFLO: | |
6337 | picrel->gotoff = 1; | |
6338 | break; | |
f12123c0 | 6339 | |
51532845 AO |
6340 | case R_FRV_FUNCDESC_GOTOFF12: |
6341 | picrel->fdgoff12 = 1; | |
6342 | break; | |
f12123c0 | 6343 | |
51532845 AO |
6344 | case R_FRV_FUNCDESC_GOTOFFHI: |
6345 | case R_FRV_FUNCDESC_GOTOFFLO: | |
6346 | picrel->fdgoffhilo = 1; | |
6347 | break; | |
f12123c0 | 6348 | |
51532845 AO |
6349 | case R_FRV_FUNCDESC: |
6350 | picrel->fd = 1; | |
6351 | picrel->relocsfd++; | |
6352 | break; | |
f12123c0 | 6353 | |
90219bd0 AO |
6354 | case R_FRV_GETTLSOFF: |
6355 | picrel->tlsplt = 1; | |
6356 | break; | |
6357 | ||
6358 | case R_FRV_TLSDESC_VALUE: | |
6359 | picrel->relocstlsd++; | |
6360 | goto bad_reloc; | |
3b36f7e6 | 6361 | |
90219bd0 AO |
6362 | case R_FRV_GOTTLSDESC12: |
6363 | picrel->tlsdesc12 = 1; | |
6364 | break; | |
6365 | ||
6366 | case R_FRV_GOTTLSDESCHI: | |
6367 | case R_FRV_GOTTLSDESCLO: | |
6368 | picrel->tlsdeschilo = 1; | |
6369 | break; | |
6370 | ||
6371 | case R_FRV_TLSMOFF12: | |
6372 | case R_FRV_TLSMOFFHI: | |
6373 | case R_FRV_TLSMOFFLO: | |
6374 | case R_FRV_TLSMOFF: | |
6375 | break; | |
6376 | ||
6377 | case R_FRV_GOTTLSOFF12: | |
6378 | picrel->tlsoff12 = 1; | |
6379 | info->flags |= DF_STATIC_TLS; | |
6380 | break; | |
3b36f7e6 | 6381 | |
90219bd0 AO |
6382 | case R_FRV_GOTTLSOFFHI: |
6383 | case R_FRV_GOTTLSOFFLO: | |
6384 | picrel->tlsoffhilo = 1; | |
6385 | info->flags |= DF_STATIC_TLS; | |
6386 | break; | |
3b36f7e6 | 6387 | |
90219bd0 AO |
6388 | case R_FRV_TLSOFF: |
6389 | picrel->relocstlsoff++; | |
6390 | info->flags |= DF_STATIC_TLS; | |
6391 | goto bad_reloc; | |
6392 | ||
4e5ba5b7 DB |
6393 | /* This relocation describes the C++ object vtable hierarchy. |
6394 | Reconstruct it for later use during GC. */ | |
6395 | case R_FRV_GNU_VTINHERIT: | |
c152c796 | 6396 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 6397 | return FALSE; |
4e5ba5b7 | 6398 | break; |
b34976b6 | 6399 | |
4e5ba5b7 DB |
6400 | /* This relocation describes which C++ vtable entries are actually |
6401 | used. Record for later use during GC. */ | |
6402 | case R_FRV_GNU_VTENTRY: | |
c152c796 | 6403 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 6404 | return FALSE; |
4e5ba5b7 | 6405 | break; |
43850d5b AO |
6406 | |
6407 | case R_FRV_LABEL16: | |
6408 | case R_FRV_LO16: | |
6409 | case R_FRV_HI16: | |
6410 | case R_FRV_GPREL12: | |
6411 | case R_FRV_GPRELU12: | |
6412 | case R_FRV_GPREL32: | |
6413 | case R_FRV_GPRELHI: | |
6414 | case R_FRV_GPRELLO: | |
90219bd0 AO |
6415 | case R_FRV_TLSDESC_RELAX: |
6416 | case R_FRV_GETTLSOFF_RELAX: | |
6417 | case R_FRV_TLSOFF_RELAX: | |
43850d5b AO |
6418 | break; |
6419 | ||
6420 | default: | |
6421 | bad_reloc: | |
6422 | (*_bfd_error_handler) | |
d003868e AM |
6423 | (_("%B: unsupported relocation type %i"), |
6424 | abfd, ELF32_R_TYPE (rel->r_info)); | |
43850d5b | 6425 | return FALSE; |
4e5ba5b7 DB |
6426 | } |
6427 | } | |
b34976b6 AM |
6428 | |
6429 | return TRUE; | |
4e5ba5b7 DB |
6430 | } |
6431 | ||
6432 | \f | |
6433 | /* Return the machine subcode from the ELF e_flags header. */ | |
6434 | ||
6435 | static int | |
6436 | elf32_frv_machine (abfd) | |
6437 | bfd *abfd; | |
6438 | { | |
6439 | switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK) | |
6440 | { | |
6441 | default: break; | |
9c8ee639 | 6442 | case EF_FRV_CPU_FR550: return bfd_mach_fr550; |
4e5ba5b7 | 6443 | case EF_FRV_CPU_FR500: return bfd_mach_fr500; |
676a64f4 RS |
6444 | case EF_FRV_CPU_FR450: return bfd_mach_fr450; |
6445 | case EF_FRV_CPU_FR405: return bfd_mach_fr400; | |
4e5ba5b7 DB |
6446 | case EF_FRV_CPU_FR400: return bfd_mach_fr400; |
6447 | case EF_FRV_CPU_FR300: return bfd_mach_fr300; | |
6448 | case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple; | |
6449 | case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat; | |
6450 | } | |
6451 | ||
6452 | return bfd_mach_frv; | |
6453 | } | |
6454 | ||
6455 | /* Set the right machine number for a FRV ELF file. */ | |
6456 | ||
b34976b6 | 6457 | static bfd_boolean |
4e5ba5b7 DB |
6458 | elf32_frv_object_p (abfd) |
6459 | bfd *abfd; | |
6460 | { | |
6461 | bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd)); | |
43850d5b AO |
6462 | return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0) |
6463 | == (IS_FDPIC (abfd))); | |
4e5ba5b7 DB |
6464 | } |
6465 | \f | |
6466 | /* Function to set the ELF flag bits. */ | |
6467 | ||
b34976b6 | 6468 | static bfd_boolean |
4e5ba5b7 DB |
6469 | frv_elf_set_private_flags (abfd, flags) |
6470 | bfd *abfd; | |
6471 | flagword flags; | |
6472 | { | |
6473 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 AM |
6474 | elf_flags_init (abfd) = TRUE; |
6475 | return TRUE; | |
4e5ba5b7 DB |
6476 | } |
6477 | ||
6478 | /* Copy backend specific data from one object module to another. */ | |
6479 | ||
b34976b6 | 6480 | static bfd_boolean |
4e5ba5b7 DB |
6481 | frv_elf_copy_private_bfd_data (ibfd, obfd) |
6482 | bfd *ibfd; | |
6483 | bfd *obfd; | |
6484 | { | |
6485 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
6486 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 6487 | return TRUE; |
4e5ba5b7 DB |
6488 | |
6489 | BFD_ASSERT (!elf_flags_init (obfd) | |
6490 | || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags); | |
6491 | ||
6492 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; | |
b34976b6 | 6493 | elf_flags_init (obfd) = TRUE; |
104d59d1 JM |
6494 | |
6495 | /* Copy object attributes. */ | |
6496 | _bfd_elf_copy_obj_attributes (ibfd, obfd); | |
6497 | ||
b34976b6 | 6498 | return TRUE; |
4e5ba5b7 DB |
6499 | } |
6500 | ||
676a64f4 RS |
6501 | /* Return true if the architecture described by elf header flag |
6502 | EXTENSION is an extension of the architecture described by BASE. */ | |
6503 | ||
6504 | static bfd_boolean | |
6505 | frv_elf_arch_extension_p (flagword base, flagword extension) | |
6506 | { | |
6507 | if (base == extension) | |
6508 | return TRUE; | |
6509 | ||
6510 | /* CPU_GENERIC code can be merged with code for a specific | |
6511 | architecture, in which case the result is marked as being | |
6512 | for the specific architecture. Everything is therefore | |
6513 | an extension of CPU_GENERIC. */ | |
6514 | if (base == EF_FRV_CPU_GENERIC) | |
6515 | return TRUE; | |
6516 | ||
6517 | if (extension == EF_FRV_CPU_FR450) | |
6518 | if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405) | |
6519 | return TRUE; | |
6520 | ||
6521 | if (extension == EF_FRV_CPU_FR405) | |
6522 | if (base == EF_FRV_CPU_FR400) | |
6523 | return TRUE; | |
6524 | ||
6525 | return FALSE; | |
6526 | } | |
6527 | ||
7e9f3bd6 AO |
6528 | static bfd_boolean |
6529 | elf32_frvfdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) | |
6530 | { | |
6531 | unsigned i; | |
6532 | ||
6533 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
6534 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
6535 | return TRUE; | |
6536 | ||
6537 | if (! frv_elf_copy_private_bfd_data (ibfd, obfd)) | |
6538 | return FALSE; | |
6539 | ||
6540 | if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr | |
6541 | || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr) | |
6542 | return TRUE; | |
6543 | ||
6544 | /* Copy the stack size. */ | |
6545 | for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++) | |
6546 | if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK) | |
6547 | { | |
6548 | Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i]; | |
6549 | ||
6550 | for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++) | |
6551 | if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK) | |
6552 | { | |
6553 | memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr)); | |
6554 | ||
6555 | /* Rewrite the phdrs, since we're only called after they | |
6556 | were first written. */ | |
6557 | if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd) | |
6558 | ->s->sizeof_ehdr, SEEK_SET) != 0 | |
6559 | || get_elf_backend_data (obfd)->s | |
6560 | ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr, | |
6561 | elf_elfheader (obfd)->e_phnum) != 0) | |
6562 | return FALSE; | |
6563 | break; | |
6564 | } | |
6565 | ||
6566 | break; | |
6567 | } | |
6568 | ||
6569 | return TRUE; | |
6570 | } | |
6571 | ||
4e5ba5b7 DB |
6572 | /* Merge backend specific data from an object file to the output |
6573 | object file when linking. */ | |
6574 | ||
b34976b6 | 6575 | static bfd_boolean |
4e5ba5b7 DB |
6576 | frv_elf_merge_private_bfd_data (ibfd, obfd) |
6577 | bfd *ibfd; | |
6578 | bfd *obfd; | |
6579 | { | |
6580 | flagword old_flags, old_partial; | |
6581 | flagword new_flags, new_partial; | |
b34976b6 | 6582 | bfd_boolean error = FALSE; |
4e5ba5b7 DB |
6583 | char new_opt[80]; |
6584 | char old_opt[80]; | |
6585 | ||
6586 | new_opt[0] = old_opt[0] = '\0'; | |
6587 | new_flags = elf_elfheader (ibfd)->e_flags; | |
6588 | old_flags = elf_elfheader (obfd)->e_flags; | |
6589 | ||
51532845 AO |
6590 | if (new_flags & EF_FRV_FDPIC) |
6591 | new_flags &= ~EF_FRV_PIC; | |
6592 | ||
4e5ba5b7 DB |
6593 | #ifdef DEBUG |
6594 | (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s", | |
6595 | old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no", | |
6596 | bfd_get_filename (ibfd)); | |
6597 | #endif | |
6598 | ||
6599 | if (!elf_flags_init (obfd)) /* First call, no flags set. */ | |
6600 | { | |
b34976b6 | 6601 | elf_flags_init (obfd) = TRUE; |
4e5ba5b7 DB |
6602 | old_flags = new_flags; |
6603 | } | |
6604 | ||
6605 | else if (new_flags == old_flags) /* Compatible flags are ok. */ | |
6606 | ; | |
6607 | ||
6608 | else /* Possibly incompatible flags. */ | |
6609 | { | |
6610 | /* Warn if different # of gprs are used. Note, 0 means nothing is | |
6611 | said about the size of gprs. */ | |
6612 | new_partial = (new_flags & EF_FRV_GPR_MASK); | |
6613 | old_partial = (old_flags & EF_FRV_GPR_MASK); | |
6614 | if (new_partial == old_partial) | |
6615 | ; | |
6616 | ||
6617 | else if (new_partial == 0) | |
6618 | ; | |
6619 | ||
6620 | else if (old_partial == 0) | |
6621 | old_flags |= new_partial; | |
6622 | ||
6623 | else | |
6624 | { | |
6625 | switch (new_partial) | |
6626 | { | |
6627 | default: strcat (new_opt, " -mgpr-??"); break; | |
6628 | case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break; | |
6629 | case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break; | |
6630 | } | |
6631 | ||
6632 | switch (old_partial) | |
6633 | { | |
6634 | default: strcat (old_opt, " -mgpr-??"); break; | |
6635 | case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break; | |
6636 | case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break; | |
6637 | } | |
6638 | } | |
6639 | ||
6640 | /* Warn if different # of fprs are used. Note, 0 means nothing is | |
6641 | said about the size of fprs. */ | |
6642 | new_partial = (new_flags & EF_FRV_FPR_MASK); | |
6643 | old_partial = (old_flags & EF_FRV_FPR_MASK); | |
6644 | if (new_partial == old_partial) | |
6645 | ; | |
6646 | ||
6647 | else if (new_partial == 0) | |
6648 | ; | |
6649 | ||
6650 | else if (old_partial == 0) | |
6651 | old_flags |= new_partial; | |
6652 | ||
6653 | else | |
6654 | { | |
6655 | switch (new_partial) | |
6656 | { | |
6657 | default: strcat (new_opt, " -mfpr-?"); break; | |
6658 | case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break; | |
6659 | case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break; | |
6660 | case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break; | |
6661 | } | |
6662 | ||
6663 | switch (old_partial) | |
6664 | { | |
6665 | default: strcat (old_opt, " -mfpr-?"); break; | |
6666 | case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break; | |
6667 | case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break; | |
6668 | case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break; | |
6669 | } | |
6670 | } | |
6671 | ||
6672 | /* Warn if different dword support was used. Note, 0 means nothing is | |
6673 | said about the dword support. */ | |
6674 | new_partial = (new_flags & EF_FRV_DWORD_MASK); | |
6675 | old_partial = (old_flags & EF_FRV_DWORD_MASK); | |
6676 | if (new_partial == old_partial) | |
6677 | ; | |
6678 | ||
6679 | else if (new_partial == 0) | |
6680 | ; | |
6681 | ||
6682 | else if (old_partial == 0) | |
6683 | old_flags |= new_partial; | |
6684 | ||
6685 | else | |
6686 | { | |
6687 | switch (new_partial) | |
6688 | { | |
6689 | default: strcat (new_opt, " -mdword-?"); break; | |
6690 | case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break; | |
6691 | case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break; | |
6692 | } | |
6693 | ||
6694 | switch (old_partial) | |
6695 | { | |
6696 | default: strcat (old_opt, " -mdword-?"); break; | |
6697 | case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break; | |
6698 | case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break; | |
6699 | } | |
6700 | } | |
6701 | ||
6702 | /* Or in flags that accumulate (ie, if one module uses it, mark that the | |
6703 | feature is used. */ | |
6704 | old_flags |= new_flags & (EF_FRV_DOUBLE | |
6705 | | EF_FRV_MEDIA | |
6706 | | EF_FRV_MULADD | |
6707 | | EF_FRV_NON_PIC_RELOCS); | |
6708 | ||
6709 | /* If any module was compiled without -G0, clear the G0 bit. */ | |
6710 | old_flags = ((old_flags & ~ EF_FRV_G0) | |
6711 | | (old_flags & new_flags & EF_FRV_G0)); | |
6712 | ||
6713 | /* If any module was compiled without -mnopack, clear the mnopack bit. */ | |
6714 | old_flags = ((old_flags & ~ EF_FRV_NOPACK) | |
6715 | | (old_flags & new_flags & EF_FRV_NOPACK)); | |
6716 | ||
6717 | /* We don't have to do anything if the pic flags are the same, or the new | |
6718 | module(s) were compiled with -mlibrary-pic. */ | |
6719 | new_partial = (new_flags & EF_FRV_PIC_FLAGS); | |
6720 | old_partial = (old_flags & EF_FRV_PIC_FLAGS); | |
6721 | if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0)) | |
6722 | ; | |
6723 | ||
6724 | /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic | |
6725 | flags if any from the new module. */ | |
6726 | else if ((old_partial & EF_FRV_LIBPIC) != 0) | |
6727 | old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial; | |
6728 | ||
6729 | /* If we have mixtures of -fpic and -fPIC, or in both bits. */ | |
6730 | else if (new_partial != 0 && old_partial != 0) | |
6731 | old_flags |= new_partial; | |
6732 | ||
6733 | /* One module was compiled for pic and the other was not, see if we have | |
6734 | had any relocations that are not pic-safe. */ | |
6735 | else | |
6736 | { | |
6737 | if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0) | |
6738 | old_flags |= new_partial; | |
6739 | else | |
6740 | { | |
6741 | old_flags &= ~ EF_FRV_PIC_FLAGS; | |
6742 | #ifndef FRV_NO_PIC_ERROR | |
b34976b6 | 6743 | error = TRUE; |
4e5ba5b7 DB |
6744 | (*_bfd_error_handler) |
6745 | (_("%s: compiled with %s and linked with modules that use non-pic relocations"), | |
6746 | bfd_get_filename (ibfd), | |
6747 | (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic"); | |
6748 | #endif | |
6749 | } | |
6750 | } | |
6751 | ||
6752 | /* Warn if different cpu is used (allow a specific cpu to override | |
6753 | the generic cpu). */ | |
6754 | new_partial = (new_flags & EF_FRV_CPU_MASK); | |
6755 | old_partial = (old_flags & EF_FRV_CPU_MASK); | |
676a64f4 | 6756 | if (frv_elf_arch_extension_p (new_partial, old_partial)) |
4e5ba5b7 DB |
6757 | ; |
6758 | ||
676a64f4 | 6759 | else if (frv_elf_arch_extension_p (old_partial, new_partial)) |
4e5ba5b7 DB |
6760 | old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial; |
6761 | ||
6762 | else | |
6763 | { | |
6764 | switch (new_partial) | |
6765 | { | |
6766 | default: strcat (new_opt, " -mcpu=?"); break; | |
6767 | case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break; | |
6768 | case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break; | |
9c8ee639 | 6769 | case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break; |
4e5ba5b7 | 6770 | case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break; |
676a64f4 RS |
6771 | case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break; |
6772 | case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
6773 | case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break; |
6774 | case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break; | |
6775 | case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break; | |
6776 | } | |
6777 | ||
6778 | switch (old_partial) | |
6779 | { | |
6780 | default: strcat (old_opt, " -mcpu=?"); break; | |
6781 | case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break; | |
6782 | case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break; | |
9c8ee639 | 6783 | case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break; |
4e5ba5b7 | 6784 | case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break; |
676a64f4 RS |
6785 | case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break; |
6786 | case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
6787 | case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break; |
6788 | case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break; | |
6789 | case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break; | |
6790 | } | |
6791 | } | |
b34976b6 | 6792 | |
4e5ba5b7 DB |
6793 | /* Print out any mismatches from above. */ |
6794 | if (new_opt[0]) | |
6795 | { | |
b34976b6 | 6796 | error = TRUE; |
4e5ba5b7 DB |
6797 | (*_bfd_error_handler) |
6798 | (_("%s: compiled with %s and linked with modules compiled with %s"), | |
6799 | bfd_get_filename (ibfd), new_opt, old_opt); | |
6800 | } | |
6801 | ||
6802 | /* Warn about any other mismatches */ | |
6803 | new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS); | |
6804 | old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS); | |
6805 | if (new_partial != old_partial) | |
6806 | { | |
6807 | old_flags |= new_partial; | |
b34976b6 | 6808 | error = TRUE; |
4e5ba5b7 DB |
6809 | (*_bfd_error_handler) |
6810 | (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"), | |
6811 | bfd_get_filename (ibfd), (long)new_partial, (long)old_partial); | |
6812 | } | |
6813 | } | |
6814 | ||
6815 | /* If the cpu is -mcpu=simple, then set the -mnopack bit. */ | |
6816 | if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE) | |
6817 | old_flags |= EF_FRV_NOPACK; | |
6818 | ||
6819 | /* Update the old flags now with changes made above. */ | |
6820 | old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK; | |
6821 | elf_elfheader (obfd)->e_flags = old_flags; | |
6822 | if (old_partial != (old_flags & EF_FRV_CPU_MASK)) | |
6823 | bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd)); | |
6824 | ||
43850d5b AO |
6825 | if (((new_flags & EF_FRV_FDPIC) == 0) |
6826 | != (! IS_FDPIC (ibfd))) | |
6827 | { | |
6828 | error = TRUE; | |
6829 | if (IS_FDPIC (obfd)) | |
6830 | (*_bfd_error_handler) | |
6831 | (_("%s: cannot link non-fdpic object file into fdpic executable"), | |
6832 | bfd_get_filename (ibfd)); | |
6833 | else | |
6834 | (*_bfd_error_handler) | |
6835 | (_("%s: cannot link fdpic object file into non-fdpic executable"), | |
6836 | bfd_get_filename (ibfd)); | |
6837 | } | |
6838 | ||
4e5ba5b7 DB |
6839 | if (error) |
6840 | bfd_set_error (bfd_error_bad_value); | |
6841 | ||
6842 | return !error; | |
6843 | } | |
6844 | ||
6845 | \f | |
b34976b6 | 6846 | bfd_boolean |
4e5ba5b7 DB |
6847 | frv_elf_print_private_bfd_data (abfd, ptr) |
6848 | bfd *abfd; | |
6849 | PTR ptr; | |
6850 | { | |
6851 | FILE *file = (FILE *) ptr; | |
6852 | flagword flags; | |
6853 | ||
6854 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
6855 | ||
6856 | /* Print normal ELF private data. */ | |
6857 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
6858 | ||
6859 | flags = elf_elfheader (abfd)->e_flags; | |
6860 | fprintf (file, _("private flags = 0x%lx:"), (long)flags); | |
6861 | ||
6862 | switch (flags & EF_FRV_CPU_MASK) | |
6863 | { | |
6864 | default: break; | |
6865 | case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break; | |
9c8ee639 | 6866 | case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break; |
4e5ba5b7 | 6867 | case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break; |
676a64f4 RS |
6868 | case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break; |
6869 | case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break; | |
4e5ba5b7 DB |
6870 | case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break; |
6871 | case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break; | |
6872 | case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break; | |
6873 | } | |
6874 | ||
6875 | switch (flags & EF_FRV_GPR_MASK) | |
6876 | { | |
6877 | default: break; | |
6878 | case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break; | |
6879 | case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break; | |
6880 | } | |
6881 | ||
6882 | switch (flags & EF_FRV_FPR_MASK) | |
6883 | { | |
6884 | default: break; | |
6885 | case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break; | |
6886 | case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break; | |
6887 | case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break; | |
6888 | } | |
6889 | ||
6890 | switch (flags & EF_FRV_DWORD_MASK) | |
6891 | { | |
6892 | default: break; | |
6893 | case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break; | |
6894 | case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break; | |
6895 | } | |
6896 | ||
6897 | if (flags & EF_FRV_DOUBLE) | |
6898 | fprintf (file, " -mdouble"); | |
6899 | ||
6900 | if (flags & EF_FRV_MEDIA) | |
6901 | fprintf (file, " -mmedia"); | |
6902 | ||
6903 | if (flags & EF_FRV_MULADD) | |
6904 | fprintf (file, " -mmuladd"); | |
6905 | ||
6906 | if (flags & EF_FRV_PIC) | |
6907 | fprintf (file, " -fpic"); | |
6908 | ||
6909 | if (flags & EF_FRV_BIGPIC) | |
6910 | fprintf (file, " -fPIC"); | |
6911 | ||
51532845 AO |
6912 | if (flags & EF_FRV_LIBPIC) |
6913 | fprintf (file, " -mlibrary-pic"); | |
6914 | ||
6915 | if (flags & EF_FRV_FDPIC) | |
6916 | fprintf (file, " -mfdpic"); | |
f12123c0 | 6917 | |
4e5ba5b7 DB |
6918 | if (flags & EF_FRV_NON_PIC_RELOCS) |
6919 | fprintf (file, " non-pic relocations"); | |
6920 | ||
6921 | if (flags & EF_FRV_G0) | |
6922 | fprintf (file, " -G0"); | |
6923 | ||
6924 | fputc ('\n', file); | |
b34976b6 | 6925 | return TRUE; |
4e5ba5b7 DB |
6926 | } |
6927 | ||
6928 | \f | |
888b45b8 KB |
6929 | /* Support for core dump NOTE sections. */ |
6930 | ||
6931 | static bfd_boolean | |
6932 | elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
6933 | { | |
6934 | int offset; | |
6935 | unsigned int raw_size; | |
6936 | ||
6937 | switch (note->descsz) | |
6938 | { | |
6939 | default: | |
6940 | return FALSE; | |
6941 | ||
6942 | /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other | |
6943 | hardcoded offsets and sizes listed below (and contained within | |
6944 | this lexical block) refer to fields in the target's elf_prstatus | |
6945 | struct. */ | |
6946 | case 268: | |
6947 | /* `pr_cursig' is at offset 12. */ | |
6948 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
6949 | ||
6950 | /* `pr_pid' is at offset 24. */ | |
6951 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
6952 | ||
6953 | /* `pr_reg' is at offset 72. */ | |
6954 | offset = 72; | |
6955 | ||
6956 | /* Most grok_prstatus implementations set `raw_size' to the size | |
6957 | of the pr_reg field. For Linux/FRV, we set `raw_size' to be | |
6958 | the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap' | |
6959 | and `pr_interp_fdpic_loadmap', both of which (by design) | |
6960 | immediately follow `pr_reg'. This will allow these fields to | |
6961 | be viewed by GDB as registers. | |
6962 | ||
6963 | `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and | |
6964 | `pr_interp_fdpic_loadmap' are 4 bytes each. */ | |
6965 | raw_size = 184 + 4 + 4; | |
6966 | ||
6967 | break; | |
6968 | } | |
6969 | ||
6970 | /* Make a ".reg/999" section. */ | |
6971 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size, | |
6972 | note->descpos + offset); | |
6973 | } | |
6974 | ||
6975 | static bfd_boolean | |
6976 | elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
6977 | { | |
6978 | switch (note->descsz) | |
6979 | { | |
6980 | default: | |
6981 | return FALSE; | |
6982 | ||
6983 | /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */ | |
6984 | case 124: | |
6985 | ||
6986 | /* `pr_fname' is found at offset 28 and is 16 bytes long. */ | |
6987 | elf_tdata (abfd)->core_program | |
6988 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); | |
6989 | ||
6990 | /* `pr_psargs' is found at offset 44 and is 80 bytes long. */ | |
6991 | elf_tdata (abfd)->core_command | |
6992 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); | |
6993 | } | |
6994 | ||
6995 | /* Note that for some reason, a spurious space is tacked | |
6996 | onto the end of the args in some (at least one anyway) | |
6997 | implementations, so strip it off if it exists. */ | |
6998 | ||
6999 | { | |
7000 | char *command = elf_tdata (abfd)->core_command; | |
7001 | int n = strlen (command); | |
7002 | ||
7003 | if (0 < n && command[n - 1] == ' ') | |
7004 | command[n - 1] = '\0'; | |
7005 | } | |
7006 | ||
7007 | return TRUE; | |
7008 | } | |
4e5ba5b7 DB |
7009 | #define ELF_ARCH bfd_arch_frv |
7010 | #define ELF_MACHINE_CODE EM_CYGNUS_FRV | |
7011 | #define ELF_MAXPAGESIZE 0x1000 | |
7012 | ||
7013 | #define TARGET_BIG_SYM bfd_elf32_frv_vec | |
7014 | #define TARGET_BIG_NAME "elf32-frv" | |
7015 | ||
4e5ba5b7 DB |
7016 | #define elf_info_to_howto frv_info_to_howto_rela |
7017 | #define elf_backend_relocate_section elf32_frv_relocate_section | |
7018 | #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook | |
4e5ba5b7 DB |
7019 | #define elf_backend_check_relocs elf32_frv_check_relocs |
7020 | #define elf_backend_object_p elf32_frv_object_p | |
7021 | #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook | |
7022 | ||
7023 | #define elf_backend_can_gc_sections 1 | |
de2d743e | 7024 | #define elf_backend_rela_normal 1 |
4e5ba5b7 DB |
7025 | |
7026 | #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup | |
157090f7 | 7027 | #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup |
4e5ba5b7 DB |
7028 | #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags |
7029 | #define bfd_elf32_bfd_copy_private_bfd_data frv_elf_copy_private_bfd_data | |
7030 | #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data | |
7031 | #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data | |
7032 | ||
43850d5b AO |
7033 | #define elf_backend_want_got_sym 1 |
7034 | #define elf_backend_got_header_size 0 | |
7035 | #define elf_backend_want_got_plt 0 | |
7036 | #define elf_backend_plt_readonly 1 | |
7037 | #define elf_backend_want_plt_sym 0 | |
7038 | #define elf_backend_plt_header_size 0 | |
7039 | ||
7040 | #define elf_backend_finish_dynamic_sections \ | |
7041 | elf32_frv_finish_dynamic_sections | |
7042 | ||
888b45b8 KB |
7043 | #define elf_backend_grok_prstatus elf32_frv_grok_prstatus |
7044 | #define elf_backend_grok_psinfo elf32_frv_grok_psinfo | |
7045 | ||
43850d5b AO |
7046 | #include "elf32-target.h" |
7047 | ||
7048 | #undef ELF_MAXPAGESIZE | |
7049 | #define ELF_MAXPAGESIZE 0x4000 | |
7050 | ||
7051 | #undef TARGET_BIG_SYM | |
7052 | #define TARGET_BIG_SYM bfd_elf32_frvfdpic_vec | |
7053 | #undef TARGET_BIG_NAME | |
7054 | #define TARGET_BIG_NAME "elf32-frvfdpic" | |
7055 | #undef elf32_bed | |
7056 | #define elf32_bed elf32_frvfdpic_bed | |
7057 | ||
7058 | #undef elf_info_to_howto_rel | |
7059 | #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel | |
7060 | ||
7061 | #undef bfd_elf32_bfd_link_hash_table_create | |
7062 | #define bfd_elf32_bfd_link_hash_table_create \ | |
7063 | frvfdpic_elf_link_hash_table_create | |
7064 | #undef elf_backend_always_size_sections | |
51532845 | 7065 | #define elf_backend_always_size_sections \ |
43850d5b | 7066 | elf32_frvfdpic_always_size_sections |
e36284ab AM |
7067 | #undef elf_backend_modify_program_headers |
7068 | #define elf_backend_modify_program_headers \ | |
7069 | elf32_frvfdpic_modify_program_headers | |
7e9f3bd6 AO |
7070 | #undef bfd_elf32_bfd_copy_private_bfd_data |
7071 | #define bfd_elf32_bfd_copy_private_bfd_data \ | |
7072 | elf32_frvfdpic_copy_private_bfd_data | |
51532845 | 7073 | |
43850d5b | 7074 | #undef elf_backend_create_dynamic_sections |
51532845 | 7075 | #define elf_backend_create_dynamic_sections \ |
43850d5b AO |
7076 | elf32_frvfdpic_create_dynamic_sections |
7077 | #undef elf_backend_adjust_dynamic_symbol | |
51532845 | 7078 | #define elf_backend_adjust_dynamic_symbol \ |
43850d5b AO |
7079 | elf32_frvfdpic_adjust_dynamic_symbol |
7080 | #undef elf_backend_size_dynamic_sections | |
51532845 | 7081 | #define elf_backend_size_dynamic_sections \ |
43850d5b | 7082 | elf32_frvfdpic_size_dynamic_sections |
90219bd0 AO |
7083 | #undef bfd_elf32_bfd_relax_section |
7084 | #define bfd_elf32_bfd_relax_section \ | |
7085 | elf32_frvfdpic_relax_section | |
43850d5b | 7086 | #undef elf_backend_finish_dynamic_symbol |
51532845 | 7087 | #define elf_backend_finish_dynamic_symbol \ |
43850d5b AO |
7088 | elf32_frvfdpic_finish_dynamic_symbol |
7089 | #undef elf_backend_finish_dynamic_sections | |
51532845 | 7090 | #define elf_backend_finish_dynamic_sections \ |
43850d5b | 7091 | elf32_frvfdpic_finish_dynamic_sections |
51532845 | 7092 | |
88571279 AO |
7093 | #undef elf_backend_discard_info |
7094 | #define elf_backend_discard_info \ | |
7095 | frvfdpic_elf_discard_info | |
43850d5b | 7096 | #undef elf_backend_can_make_relative_eh_frame |
ec3391e7 | 7097 | #define elf_backend_can_make_relative_eh_frame \ |
43850d5b AO |
7098 | frvfdpic_elf_use_relative_eh_frame |
7099 | #undef elf_backend_can_make_lsda_relative_eh_frame | |
ec3391e7 | 7100 | #define elf_backend_can_make_lsda_relative_eh_frame \ |
43850d5b AO |
7101 | frvfdpic_elf_use_relative_eh_frame |
7102 | #undef elf_backend_encode_eh_address | |
7103 | #define elf_backend_encode_eh_address \ | |
7104 | frvfdpic_elf_encode_eh_address | |
ec3391e7 | 7105 | |
43850d5b | 7106 | #undef elf_backend_may_use_rel_p |
51532845 | 7107 | #define elf_backend_may_use_rel_p 1 |
43850d5b | 7108 | #undef elf_backend_may_use_rela_p |
51532845 AO |
7109 | #define elf_backend_may_use_rela_p 1 |
7110 | /* We use REL for dynamic relocations only. */ | |
43850d5b | 7111 | #undef elf_backend_default_use_rela_p |
51532845 AO |
7112 | #define elf_backend_default_use_rela_p 1 |
7113 | ||
aee6f5b4 AO |
7114 | #undef elf_backend_omit_section_dynsym |
7115 | #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym | |
7116 | ||
4e5ba5b7 | 7117 | #include "elf32-target.h" |