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