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