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