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