]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* 32-bit ELF support for ARM |
d7f735da | 2 | Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 |
d1f161ea | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
3e110533 | 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 | 20 | |
7f266840 DJ |
21 | #include "bfd.h" |
22 | #include "sysdep.h" | |
00a97672 | 23 | #include "libiberty.h" |
7f266840 DJ |
24 | #include "libbfd.h" |
25 | #include "elf-bfd.h" | |
00a97672 | 26 | #include "elf-vxworks.h" |
ee065d83 | 27 | #include "elf/arm.h" |
7f266840 DJ |
28 | |
29 | #ifndef NUM_ELEM | |
30 | #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0])) | |
31 | #endif | |
32 | ||
00a97672 RS |
33 | /* Return the relocation section associated with NAME. HTAB is the |
34 | bfd's elf32_arm_link_hash_entry. */ | |
35 | #define RELOC_SECTION(HTAB, NAME) \ | |
36 | ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME) | |
37 | ||
38 | /* Return size of a relocation entry. HTAB is the bfd's | |
39 | elf32_arm_link_hash_entry. */ | |
40 | #define RELOC_SIZE(HTAB) \ | |
41 | ((HTAB)->use_rel \ | |
42 | ? sizeof (Elf32_External_Rel) \ | |
43 | : sizeof (Elf32_External_Rela)) | |
44 | ||
45 | /* Return function to swap relocations in. HTAB is the bfd's | |
46 | elf32_arm_link_hash_entry. */ | |
47 | #define SWAP_RELOC_IN(HTAB) \ | |
48 | ((HTAB)->use_rel \ | |
49 | ? bfd_elf32_swap_reloc_in \ | |
50 | : bfd_elf32_swap_reloca_in) | |
51 | ||
52 | /* Return function to swap relocations out. HTAB is the bfd's | |
53 | elf32_arm_link_hash_entry. */ | |
54 | #define SWAP_RELOC_OUT(HTAB) \ | |
55 | ((HTAB)->use_rel \ | |
56 | ? bfd_elf32_swap_reloc_out \ | |
57 | : bfd_elf32_swap_reloca_out) | |
58 | ||
7f266840 DJ |
59 | #define elf_info_to_howto 0 |
60 | #define elf_info_to_howto_rel elf32_arm_info_to_howto | |
61 | ||
62 | #define ARM_ELF_ABI_VERSION 0 | |
63 | #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM | |
64 | ||
24718e3b | 65 | static struct elf_backend_data elf32_arm_vxworks_bed; |
00a97672 | 66 | |
7f266840 DJ |
67 | /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g. |
68 | R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO | |
69 | in that slot. */ | |
70 | ||
c19d1205 | 71 | static reloc_howto_type elf32_arm_howto_table_1[] = |
7f266840 DJ |
72 | { |
73 | /* No relocation */ | |
74 | HOWTO (R_ARM_NONE, /* type */ | |
75 | 0, /* rightshift */ | |
76 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
77 | 0, /* bitsize */ | |
78 | FALSE, /* pc_relative */ | |
79 | 0, /* bitpos */ | |
80 | complain_overflow_dont,/* complain_on_overflow */ | |
81 | bfd_elf_generic_reloc, /* special_function */ | |
82 | "R_ARM_NONE", /* name */ | |
83 | FALSE, /* partial_inplace */ | |
84 | 0, /* src_mask */ | |
85 | 0, /* dst_mask */ | |
86 | FALSE), /* pcrel_offset */ | |
87 | ||
88 | HOWTO (R_ARM_PC24, /* type */ | |
89 | 2, /* rightshift */ | |
90 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
91 | 24, /* bitsize */ | |
92 | TRUE, /* pc_relative */ | |
93 | 0, /* bitpos */ | |
94 | complain_overflow_signed,/* complain_on_overflow */ | |
95 | bfd_elf_generic_reloc, /* special_function */ | |
96 | "R_ARM_PC24", /* name */ | |
97 | FALSE, /* partial_inplace */ | |
98 | 0x00ffffff, /* src_mask */ | |
99 | 0x00ffffff, /* dst_mask */ | |
100 | TRUE), /* pcrel_offset */ | |
101 | ||
102 | /* 32 bit absolute */ | |
103 | HOWTO (R_ARM_ABS32, /* type */ | |
104 | 0, /* rightshift */ | |
105 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
106 | 32, /* bitsize */ | |
107 | FALSE, /* pc_relative */ | |
108 | 0, /* bitpos */ | |
109 | complain_overflow_bitfield,/* complain_on_overflow */ | |
110 | bfd_elf_generic_reloc, /* special_function */ | |
111 | "R_ARM_ABS32", /* name */ | |
112 | FALSE, /* partial_inplace */ | |
113 | 0xffffffff, /* src_mask */ | |
114 | 0xffffffff, /* dst_mask */ | |
115 | FALSE), /* pcrel_offset */ | |
116 | ||
117 | /* standard 32bit pc-relative reloc */ | |
118 | HOWTO (R_ARM_REL32, /* type */ | |
119 | 0, /* rightshift */ | |
120 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
121 | 32, /* bitsize */ | |
122 | TRUE, /* pc_relative */ | |
123 | 0, /* bitpos */ | |
124 | complain_overflow_bitfield,/* complain_on_overflow */ | |
125 | bfd_elf_generic_reloc, /* special_function */ | |
126 | "R_ARM_REL32", /* name */ | |
127 | FALSE, /* partial_inplace */ | |
128 | 0xffffffff, /* src_mask */ | |
129 | 0xffffffff, /* dst_mask */ | |
130 | TRUE), /* pcrel_offset */ | |
131 | ||
c19d1205 | 132 | /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */ |
4962c51a | 133 | HOWTO (R_ARM_LDR_PC_G0, /* type */ |
7f266840 DJ |
134 | 0, /* rightshift */ |
135 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
4962c51a MS |
136 | 32, /* bitsize */ |
137 | TRUE, /* pc_relative */ | |
7f266840 | 138 | 0, /* bitpos */ |
4962c51a | 139 | complain_overflow_dont,/* complain_on_overflow */ |
7f266840 | 140 | bfd_elf_generic_reloc, /* special_function */ |
4962c51a | 141 | "R_ARM_LDR_PC_G0", /* name */ |
7f266840 | 142 | FALSE, /* partial_inplace */ |
4962c51a MS |
143 | 0xffffffff, /* src_mask */ |
144 | 0xffffffff, /* dst_mask */ | |
145 | TRUE), /* pcrel_offset */ | |
7f266840 DJ |
146 | |
147 | /* 16 bit absolute */ | |
148 | HOWTO (R_ARM_ABS16, /* type */ | |
149 | 0, /* rightshift */ | |
150 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
151 | 16, /* bitsize */ | |
152 | FALSE, /* pc_relative */ | |
153 | 0, /* bitpos */ | |
154 | complain_overflow_bitfield,/* complain_on_overflow */ | |
155 | bfd_elf_generic_reloc, /* special_function */ | |
156 | "R_ARM_ABS16", /* name */ | |
157 | FALSE, /* partial_inplace */ | |
158 | 0x0000ffff, /* src_mask */ | |
159 | 0x0000ffff, /* dst_mask */ | |
160 | FALSE), /* pcrel_offset */ | |
161 | ||
162 | /* 12 bit absolute */ | |
163 | HOWTO (R_ARM_ABS12, /* type */ | |
164 | 0, /* rightshift */ | |
165 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
166 | 12, /* bitsize */ | |
167 | FALSE, /* pc_relative */ | |
168 | 0, /* bitpos */ | |
169 | complain_overflow_bitfield,/* complain_on_overflow */ | |
170 | bfd_elf_generic_reloc, /* special_function */ | |
171 | "R_ARM_ABS12", /* name */ | |
172 | FALSE, /* partial_inplace */ | |
00a97672 RS |
173 | 0x00000fff, /* src_mask */ |
174 | 0x00000fff, /* dst_mask */ | |
7f266840 DJ |
175 | FALSE), /* pcrel_offset */ |
176 | ||
177 | HOWTO (R_ARM_THM_ABS5, /* type */ | |
178 | 6, /* rightshift */ | |
179 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
180 | 5, /* bitsize */ | |
181 | FALSE, /* pc_relative */ | |
182 | 0, /* bitpos */ | |
183 | complain_overflow_bitfield,/* complain_on_overflow */ | |
184 | bfd_elf_generic_reloc, /* special_function */ | |
185 | "R_ARM_THM_ABS5", /* name */ | |
186 | FALSE, /* partial_inplace */ | |
187 | 0x000007e0, /* src_mask */ | |
188 | 0x000007e0, /* dst_mask */ | |
189 | FALSE), /* pcrel_offset */ | |
190 | ||
191 | /* 8 bit absolute */ | |
192 | HOWTO (R_ARM_ABS8, /* type */ | |
193 | 0, /* rightshift */ | |
194 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
195 | 8, /* bitsize */ | |
196 | FALSE, /* pc_relative */ | |
197 | 0, /* bitpos */ | |
198 | complain_overflow_bitfield,/* complain_on_overflow */ | |
199 | bfd_elf_generic_reloc, /* special_function */ | |
200 | "R_ARM_ABS8", /* name */ | |
201 | FALSE, /* partial_inplace */ | |
202 | 0x000000ff, /* src_mask */ | |
203 | 0x000000ff, /* dst_mask */ | |
204 | FALSE), /* pcrel_offset */ | |
205 | ||
206 | HOWTO (R_ARM_SBREL32, /* type */ | |
207 | 0, /* rightshift */ | |
208 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
209 | 32, /* bitsize */ | |
210 | FALSE, /* pc_relative */ | |
211 | 0, /* bitpos */ | |
212 | complain_overflow_dont,/* complain_on_overflow */ | |
213 | bfd_elf_generic_reloc, /* special_function */ | |
214 | "R_ARM_SBREL32", /* name */ | |
215 | FALSE, /* partial_inplace */ | |
216 | 0xffffffff, /* src_mask */ | |
217 | 0xffffffff, /* dst_mask */ | |
218 | FALSE), /* pcrel_offset */ | |
219 | ||
c19d1205 ZW |
220 | /* FIXME: Has two more bits of offset in Thumb32. */ |
221 | HOWTO (R_ARM_THM_CALL, /* type */ | |
7f266840 DJ |
222 | 1, /* rightshift */ |
223 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
224 | 23, /* bitsize */ | |
225 | TRUE, /* pc_relative */ | |
226 | 0, /* bitpos */ | |
227 | complain_overflow_signed,/* complain_on_overflow */ | |
228 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 229 | "R_ARM_THM_CALL", /* name */ |
7f266840 DJ |
230 | FALSE, /* partial_inplace */ |
231 | 0x07ff07ff, /* src_mask */ | |
232 | 0x07ff07ff, /* dst_mask */ | |
233 | TRUE), /* pcrel_offset */ | |
234 | ||
235 | HOWTO (R_ARM_THM_PC8, /* type */ | |
236 | 1, /* rightshift */ | |
237 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
238 | 8, /* bitsize */ | |
239 | TRUE, /* pc_relative */ | |
240 | 0, /* bitpos */ | |
241 | complain_overflow_signed,/* complain_on_overflow */ | |
242 | bfd_elf_generic_reloc, /* special_function */ | |
243 | "R_ARM_THM_PC8", /* name */ | |
244 | FALSE, /* partial_inplace */ | |
245 | 0x000000ff, /* src_mask */ | |
246 | 0x000000ff, /* dst_mask */ | |
247 | TRUE), /* pcrel_offset */ | |
248 | ||
c19d1205 | 249 | HOWTO (R_ARM_BREL_ADJ, /* type */ |
7f266840 DJ |
250 | 1, /* rightshift */ |
251 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 ZW |
252 | 32, /* bitsize */ |
253 | FALSE, /* pc_relative */ | |
7f266840 DJ |
254 | 0, /* bitpos */ |
255 | complain_overflow_signed,/* complain_on_overflow */ | |
256 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 257 | "R_ARM_BREL_ADJ", /* name */ |
7f266840 | 258 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
259 | 0xffffffff, /* src_mask */ |
260 | 0xffffffff, /* dst_mask */ | |
261 | FALSE), /* pcrel_offset */ | |
7f266840 DJ |
262 | |
263 | HOWTO (R_ARM_SWI24, /* type */ | |
264 | 0, /* rightshift */ | |
265 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
266 | 0, /* bitsize */ | |
267 | FALSE, /* pc_relative */ | |
268 | 0, /* bitpos */ | |
269 | complain_overflow_signed,/* complain_on_overflow */ | |
270 | bfd_elf_generic_reloc, /* special_function */ | |
271 | "R_ARM_SWI24", /* name */ | |
272 | FALSE, /* partial_inplace */ | |
273 | 0x00000000, /* src_mask */ | |
274 | 0x00000000, /* dst_mask */ | |
275 | FALSE), /* pcrel_offset */ | |
276 | ||
277 | HOWTO (R_ARM_THM_SWI8, /* type */ | |
278 | 0, /* rightshift */ | |
279 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
280 | 0, /* bitsize */ | |
281 | FALSE, /* pc_relative */ | |
282 | 0, /* bitpos */ | |
283 | complain_overflow_signed,/* complain_on_overflow */ | |
284 | bfd_elf_generic_reloc, /* special_function */ | |
285 | "R_ARM_SWI8", /* name */ | |
286 | FALSE, /* partial_inplace */ | |
287 | 0x00000000, /* src_mask */ | |
288 | 0x00000000, /* dst_mask */ | |
289 | FALSE), /* pcrel_offset */ | |
290 | ||
291 | /* BLX instruction for the ARM. */ | |
292 | HOWTO (R_ARM_XPC25, /* type */ | |
293 | 2, /* rightshift */ | |
294 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
295 | 25, /* bitsize */ | |
296 | TRUE, /* pc_relative */ | |
297 | 0, /* bitpos */ | |
298 | complain_overflow_signed,/* complain_on_overflow */ | |
299 | bfd_elf_generic_reloc, /* special_function */ | |
300 | "R_ARM_XPC25", /* name */ | |
301 | FALSE, /* partial_inplace */ | |
302 | 0x00ffffff, /* src_mask */ | |
303 | 0x00ffffff, /* dst_mask */ | |
304 | TRUE), /* pcrel_offset */ | |
305 | ||
306 | /* BLX instruction for the Thumb. */ | |
307 | HOWTO (R_ARM_THM_XPC22, /* type */ | |
308 | 2, /* rightshift */ | |
309 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
310 | 22, /* bitsize */ | |
311 | TRUE, /* pc_relative */ | |
312 | 0, /* bitpos */ | |
313 | complain_overflow_signed,/* complain_on_overflow */ | |
314 | bfd_elf_generic_reloc, /* special_function */ | |
315 | "R_ARM_THM_XPC22", /* name */ | |
316 | FALSE, /* partial_inplace */ | |
317 | 0x07ff07ff, /* src_mask */ | |
318 | 0x07ff07ff, /* dst_mask */ | |
319 | TRUE), /* pcrel_offset */ | |
320 | ||
ba93b8ac | 321 | /* Dynamic TLS relocations. */ |
7f266840 | 322 | |
ba93b8ac DJ |
323 | HOWTO (R_ARM_TLS_DTPMOD32, /* type */ |
324 | 0, /* rightshift */ | |
325 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
326 | 32, /* bitsize */ | |
327 | FALSE, /* pc_relative */ | |
328 | 0, /* bitpos */ | |
329 | complain_overflow_bitfield,/* complain_on_overflow */ | |
330 | bfd_elf_generic_reloc, /* special_function */ | |
331 | "R_ARM_TLS_DTPMOD32", /* name */ | |
332 | TRUE, /* partial_inplace */ | |
333 | 0xffffffff, /* src_mask */ | |
334 | 0xffffffff, /* dst_mask */ | |
335 | FALSE), /* pcrel_offset */ | |
7f266840 | 336 | |
ba93b8ac DJ |
337 | HOWTO (R_ARM_TLS_DTPOFF32, /* type */ |
338 | 0, /* rightshift */ | |
339 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
340 | 32, /* bitsize */ | |
341 | FALSE, /* pc_relative */ | |
342 | 0, /* bitpos */ | |
343 | complain_overflow_bitfield,/* complain_on_overflow */ | |
344 | bfd_elf_generic_reloc, /* special_function */ | |
345 | "R_ARM_TLS_DTPOFF32", /* name */ | |
346 | TRUE, /* partial_inplace */ | |
347 | 0xffffffff, /* src_mask */ | |
348 | 0xffffffff, /* dst_mask */ | |
349 | FALSE), /* pcrel_offset */ | |
7f266840 | 350 | |
ba93b8ac DJ |
351 | HOWTO (R_ARM_TLS_TPOFF32, /* type */ |
352 | 0, /* rightshift */ | |
353 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
354 | 32, /* bitsize */ | |
355 | FALSE, /* pc_relative */ | |
356 | 0, /* bitpos */ | |
357 | complain_overflow_bitfield,/* complain_on_overflow */ | |
358 | bfd_elf_generic_reloc, /* special_function */ | |
359 | "R_ARM_TLS_TPOFF32", /* name */ | |
360 | TRUE, /* partial_inplace */ | |
361 | 0xffffffff, /* src_mask */ | |
362 | 0xffffffff, /* dst_mask */ | |
363 | FALSE), /* pcrel_offset */ | |
7f266840 DJ |
364 | |
365 | /* Relocs used in ARM Linux */ | |
366 | ||
367 | HOWTO (R_ARM_COPY, /* type */ | |
368 | 0, /* rightshift */ | |
369 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
370 | 32, /* bitsize */ | |
371 | FALSE, /* pc_relative */ | |
372 | 0, /* bitpos */ | |
373 | complain_overflow_bitfield,/* complain_on_overflow */ | |
374 | bfd_elf_generic_reloc, /* special_function */ | |
375 | "R_ARM_COPY", /* name */ | |
376 | TRUE, /* partial_inplace */ | |
377 | 0xffffffff, /* src_mask */ | |
378 | 0xffffffff, /* dst_mask */ | |
379 | FALSE), /* pcrel_offset */ | |
380 | ||
381 | HOWTO (R_ARM_GLOB_DAT, /* type */ | |
382 | 0, /* rightshift */ | |
383 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
384 | 32, /* bitsize */ | |
385 | FALSE, /* pc_relative */ | |
386 | 0, /* bitpos */ | |
387 | complain_overflow_bitfield,/* complain_on_overflow */ | |
388 | bfd_elf_generic_reloc, /* special_function */ | |
389 | "R_ARM_GLOB_DAT", /* name */ | |
390 | TRUE, /* partial_inplace */ | |
391 | 0xffffffff, /* src_mask */ | |
392 | 0xffffffff, /* dst_mask */ | |
393 | FALSE), /* pcrel_offset */ | |
394 | ||
395 | HOWTO (R_ARM_JUMP_SLOT, /* type */ | |
396 | 0, /* rightshift */ | |
397 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
398 | 32, /* bitsize */ | |
399 | FALSE, /* pc_relative */ | |
400 | 0, /* bitpos */ | |
401 | complain_overflow_bitfield,/* complain_on_overflow */ | |
402 | bfd_elf_generic_reloc, /* special_function */ | |
403 | "R_ARM_JUMP_SLOT", /* name */ | |
404 | TRUE, /* partial_inplace */ | |
405 | 0xffffffff, /* src_mask */ | |
406 | 0xffffffff, /* dst_mask */ | |
407 | FALSE), /* pcrel_offset */ | |
408 | ||
409 | HOWTO (R_ARM_RELATIVE, /* type */ | |
410 | 0, /* rightshift */ | |
411 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
412 | 32, /* bitsize */ | |
413 | FALSE, /* pc_relative */ | |
414 | 0, /* bitpos */ | |
415 | complain_overflow_bitfield,/* complain_on_overflow */ | |
416 | bfd_elf_generic_reloc, /* special_function */ | |
417 | "R_ARM_RELATIVE", /* name */ | |
418 | TRUE, /* partial_inplace */ | |
419 | 0xffffffff, /* src_mask */ | |
420 | 0xffffffff, /* dst_mask */ | |
421 | FALSE), /* pcrel_offset */ | |
422 | ||
c19d1205 | 423 | HOWTO (R_ARM_GOTOFF32, /* type */ |
7f266840 DJ |
424 | 0, /* rightshift */ |
425 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
426 | 32, /* bitsize */ | |
427 | FALSE, /* pc_relative */ | |
428 | 0, /* bitpos */ | |
429 | complain_overflow_bitfield,/* complain_on_overflow */ | |
430 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 431 | "R_ARM_GOTOFF32", /* name */ |
7f266840 DJ |
432 | TRUE, /* partial_inplace */ |
433 | 0xffffffff, /* src_mask */ | |
434 | 0xffffffff, /* dst_mask */ | |
435 | FALSE), /* pcrel_offset */ | |
436 | ||
437 | HOWTO (R_ARM_GOTPC, /* type */ | |
438 | 0, /* rightshift */ | |
439 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
440 | 32, /* bitsize */ | |
441 | TRUE, /* pc_relative */ | |
442 | 0, /* bitpos */ | |
443 | complain_overflow_bitfield,/* complain_on_overflow */ | |
444 | bfd_elf_generic_reloc, /* special_function */ | |
445 | "R_ARM_GOTPC", /* name */ | |
446 | TRUE, /* partial_inplace */ | |
447 | 0xffffffff, /* src_mask */ | |
448 | 0xffffffff, /* dst_mask */ | |
449 | TRUE), /* pcrel_offset */ | |
450 | ||
451 | HOWTO (R_ARM_GOT32, /* type */ | |
452 | 0, /* rightshift */ | |
453 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
454 | 32, /* bitsize */ | |
455 | FALSE, /* pc_relative */ | |
456 | 0, /* bitpos */ | |
457 | complain_overflow_bitfield,/* complain_on_overflow */ | |
458 | bfd_elf_generic_reloc, /* special_function */ | |
459 | "R_ARM_GOT32", /* name */ | |
460 | TRUE, /* partial_inplace */ | |
461 | 0xffffffff, /* src_mask */ | |
462 | 0xffffffff, /* dst_mask */ | |
463 | FALSE), /* pcrel_offset */ | |
464 | ||
465 | HOWTO (R_ARM_PLT32, /* type */ | |
466 | 2, /* rightshift */ | |
467 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
ce490eda | 468 | 24, /* bitsize */ |
7f266840 DJ |
469 | TRUE, /* pc_relative */ |
470 | 0, /* bitpos */ | |
471 | complain_overflow_bitfield,/* complain_on_overflow */ | |
472 | bfd_elf_generic_reloc, /* special_function */ | |
473 | "R_ARM_PLT32", /* name */ | |
ce490eda | 474 | FALSE, /* partial_inplace */ |
7f266840 DJ |
475 | 0x00ffffff, /* src_mask */ |
476 | 0x00ffffff, /* dst_mask */ | |
477 | TRUE), /* pcrel_offset */ | |
478 | ||
479 | HOWTO (R_ARM_CALL, /* type */ | |
480 | 2, /* rightshift */ | |
481 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
482 | 24, /* bitsize */ | |
483 | TRUE, /* pc_relative */ | |
484 | 0, /* bitpos */ | |
485 | complain_overflow_signed,/* complain_on_overflow */ | |
486 | bfd_elf_generic_reloc, /* special_function */ | |
487 | "R_ARM_CALL", /* name */ | |
488 | FALSE, /* partial_inplace */ | |
489 | 0x00ffffff, /* src_mask */ | |
490 | 0x00ffffff, /* dst_mask */ | |
491 | TRUE), /* pcrel_offset */ | |
492 | ||
493 | HOWTO (R_ARM_JUMP24, /* type */ | |
494 | 2, /* rightshift */ | |
495 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
496 | 24, /* bitsize */ | |
497 | TRUE, /* pc_relative */ | |
498 | 0, /* bitpos */ | |
499 | complain_overflow_signed,/* complain_on_overflow */ | |
500 | bfd_elf_generic_reloc, /* special_function */ | |
501 | "R_ARM_JUMP24", /* name */ | |
502 | FALSE, /* partial_inplace */ | |
503 | 0x00ffffff, /* src_mask */ | |
504 | 0x00ffffff, /* dst_mask */ | |
505 | TRUE), /* pcrel_offset */ | |
506 | ||
c19d1205 ZW |
507 | HOWTO (R_ARM_THM_JUMP24, /* type */ |
508 | 1, /* rightshift */ | |
509 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
510 | 24, /* bitsize */ | |
511 | TRUE, /* pc_relative */ | |
7f266840 | 512 | 0, /* bitpos */ |
c19d1205 | 513 | complain_overflow_signed,/* complain_on_overflow */ |
7f266840 | 514 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 515 | "R_ARM_THM_JUMP24", /* name */ |
7f266840 | 516 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
517 | 0x07ff2fff, /* src_mask */ |
518 | 0x07ff2fff, /* dst_mask */ | |
519 | TRUE), /* pcrel_offset */ | |
7f266840 | 520 | |
c19d1205 | 521 | HOWTO (R_ARM_BASE_ABS, /* type */ |
7f266840 | 522 | 0, /* rightshift */ |
c19d1205 ZW |
523 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
524 | 32, /* bitsize */ | |
7f266840 DJ |
525 | FALSE, /* pc_relative */ |
526 | 0, /* bitpos */ | |
527 | complain_overflow_dont,/* complain_on_overflow */ | |
528 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 529 | "R_ARM_BASE_ABS", /* name */ |
7f266840 | 530 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
531 | 0xffffffff, /* src_mask */ |
532 | 0xffffffff, /* dst_mask */ | |
7f266840 DJ |
533 | FALSE), /* pcrel_offset */ |
534 | ||
535 | HOWTO (R_ARM_ALU_PCREL7_0, /* type */ | |
536 | 0, /* rightshift */ | |
537 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
538 | 12, /* bitsize */ | |
539 | TRUE, /* pc_relative */ | |
540 | 0, /* bitpos */ | |
541 | complain_overflow_dont,/* complain_on_overflow */ | |
542 | bfd_elf_generic_reloc, /* special_function */ | |
543 | "R_ARM_ALU_PCREL_7_0", /* name */ | |
544 | FALSE, /* partial_inplace */ | |
545 | 0x00000fff, /* src_mask */ | |
546 | 0x00000fff, /* dst_mask */ | |
547 | TRUE), /* pcrel_offset */ | |
548 | ||
549 | HOWTO (R_ARM_ALU_PCREL15_8, /* type */ | |
550 | 0, /* rightshift */ | |
551 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
552 | 12, /* bitsize */ | |
553 | TRUE, /* pc_relative */ | |
554 | 8, /* bitpos */ | |
555 | complain_overflow_dont,/* complain_on_overflow */ | |
556 | bfd_elf_generic_reloc, /* special_function */ | |
557 | "R_ARM_ALU_PCREL_15_8",/* name */ | |
558 | FALSE, /* partial_inplace */ | |
559 | 0x00000fff, /* src_mask */ | |
560 | 0x00000fff, /* dst_mask */ | |
561 | TRUE), /* pcrel_offset */ | |
562 | ||
563 | HOWTO (R_ARM_ALU_PCREL23_15, /* type */ | |
564 | 0, /* rightshift */ | |
565 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
566 | 12, /* bitsize */ | |
567 | TRUE, /* pc_relative */ | |
568 | 16, /* bitpos */ | |
569 | complain_overflow_dont,/* complain_on_overflow */ | |
570 | bfd_elf_generic_reloc, /* special_function */ | |
571 | "R_ARM_ALU_PCREL_23_15",/* name */ | |
572 | FALSE, /* partial_inplace */ | |
573 | 0x00000fff, /* src_mask */ | |
574 | 0x00000fff, /* dst_mask */ | |
575 | TRUE), /* pcrel_offset */ | |
576 | ||
577 | HOWTO (R_ARM_LDR_SBREL_11_0, /* type */ | |
578 | 0, /* rightshift */ | |
579 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
580 | 12, /* bitsize */ | |
581 | FALSE, /* pc_relative */ | |
582 | 0, /* bitpos */ | |
583 | complain_overflow_dont,/* complain_on_overflow */ | |
584 | bfd_elf_generic_reloc, /* special_function */ | |
585 | "R_ARM_LDR_SBREL_11_0",/* name */ | |
586 | FALSE, /* partial_inplace */ | |
587 | 0x00000fff, /* src_mask */ | |
588 | 0x00000fff, /* dst_mask */ | |
589 | FALSE), /* pcrel_offset */ | |
590 | ||
591 | HOWTO (R_ARM_ALU_SBREL_19_12, /* type */ | |
592 | 0, /* rightshift */ | |
593 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
594 | 8, /* bitsize */ | |
595 | FALSE, /* pc_relative */ | |
596 | 12, /* bitpos */ | |
597 | complain_overflow_dont,/* complain_on_overflow */ | |
598 | bfd_elf_generic_reloc, /* special_function */ | |
599 | "R_ARM_ALU_SBREL_19_12",/* name */ | |
600 | FALSE, /* partial_inplace */ | |
601 | 0x000ff000, /* src_mask */ | |
602 | 0x000ff000, /* dst_mask */ | |
603 | FALSE), /* pcrel_offset */ | |
604 | ||
605 | HOWTO (R_ARM_ALU_SBREL_27_20, /* type */ | |
606 | 0, /* rightshift */ | |
607 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
608 | 8, /* bitsize */ | |
609 | FALSE, /* pc_relative */ | |
610 | 20, /* bitpos */ | |
611 | complain_overflow_dont,/* complain_on_overflow */ | |
612 | bfd_elf_generic_reloc, /* special_function */ | |
613 | "R_ARM_ALU_SBREL_27_20",/* name */ | |
614 | FALSE, /* partial_inplace */ | |
615 | 0x0ff00000, /* src_mask */ | |
616 | 0x0ff00000, /* dst_mask */ | |
617 | FALSE), /* pcrel_offset */ | |
618 | ||
619 | HOWTO (R_ARM_TARGET1, /* type */ | |
620 | 0, /* rightshift */ | |
621 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
622 | 32, /* bitsize */ | |
623 | FALSE, /* pc_relative */ | |
624 | 0, /* bitpos */ | |
625 | complain_overflow_dont,/* complain_on_overflow */ | |
626 | bfd_elf_generic_reloc, /* special_function */ | |
627 | "R_ARM_TARGET1", /* name */ | |
628 | FALSE, /* partial_inplace */ | |
629 | 0xffffffff, /* src_mask */ | |
630 | 0xffffffff, /* dst_mask */ | |
631 | FALSE), /* pcrel_offset */ | |
632 | ||
633 | HOWTO (R_ARM_ROSEGREL32, /* type */ | |
634 | 0, /* rightshift */ | |
635 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
636 | 32, /* bitsize */ | |
637 | FALSE, /* pc_relative */ | |
638 | 0, /* bitpos */ | |
639 | complain_overflow_dont,/* complain_on_overflow */ | |
640 | bfd_elf_generic_reloc, /* special_function */ | |
641 | "R_ARM_ROSEGREL32", /* name */ | |
642 | FALSE, /* partial_inplace */ | |
643 | 0xffffffff, /* src_mask */ | |
644 | 0xffffffff, /* dst_mask */ | |
645 | FALSE), /* pcrel_offset */ | |
646 | ||
647 | HOWTO (R_ARM_V4BX, /* type */ | |
648 | 0, /* rightshift */ | |
649 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
650 | 32, /* bitsize */ | |
651 | FALSE, /* pc_relative */ | |
652 | 0, /* bitpos */ | |
653 | complain_overflow_dont,/* complain_on_overflow */ | |
654 | bfd_elf_generic_reloc, /* special_function */ | |
655 | "R_ARM_V4BX", /* name */ | |
656 | FALSE, /* partial_inplace */ | |
657 | 0xffffffff, /* src_mask */ | |
658 | 0xffffffff, /* dst_mask */ | |
659 | FALSE), /* pcrel_offset */ | |
660 | ||
661 | HOWTO (R_ARM_TARGET2, /* type */ | |
662 | 0, /* rightshift */ | |
663 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
664 | 32, /* bitsize */ | |
665 | FALSE, /* pc_relative */ | |
666 | 0, /* bitpos */ | |
667 | complain_overflow_signed,/* complain_on_overflow */ | |
668 | bfd_elf_generic_reloc, /* special_function */ | |
669 | "R_ARM_TARGET2", /* name */ | |
670 | FALSE, /* partial_inplace */ | |
671 | 0xffffffff, /* src_mask */ | |
672 | 0xffffffff, /* dst_mask */ | |
673 | TRUE), /* pcrel_offset */ | |
674 | ||
675 | HOWTO (R_ARM_PREL31, /* type */ | |
676 | 0, /* rightshift */ | |
677 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
678 | 31, /* bitsize */ | |
679 | TRUE, /* pc_relative */ | |
680 | 0, /* bitpos */ | |
681 | complain_overflow_signed,/* complain_on_overflow */ | |
682 | bfd_elf_generic_reloc, /* special_function */ | |
683 | "R_ARM_PREL31", /* name */ | |
684 | FALSE, /* partial_inplace */ | |
685 | 0x7fffffff, /* src_mask */ | |
686 | 0x7fffffff, /* dst_mask */ | |
687 | TRUE), /* pcrel_offset */ | |
c19d1205 ZW |
688 | |
689 | HOWTO (R_ARM_MOVW_ABS_NC, /* type */ | |
690 | 0, /* rightshift */ | |
691 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
692 | 16, /* bitsize */ | |
693 | FALSE, /* pc_relative */ | |
694 | 0, /* bitpos */ | |
695 | complain_overflow_dont,/* complain_on_overflow */ | |
696 | bfd_elf_generic_reloc, /* special_function */ | |
697 | "R_ARM_MOVW_ABS_NC", /* name */ | |
698 | FALSE, /* partial_inplace */ | |
699 | 0x0000ffff, /* src_mask */ | |
700 | 0x0000ffff, /* dst_mask */ | |
701 | FALSE), /* pcrel_offset */ | |
702 | ||
703 | HOWTO (R_ARM_MOVT_ABS, /* type */ | |
704 | 0, /* rightshift */ | |
705 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
706 | 16, /* bitsize */ | |
707 | FALSE, /* pc_relative */ | |
708 | 0, /* bitpos */ | |
709 | complain_overflow_bitfield,/* complain_on_overflow */ | |
710 | bfd_elf_generic_reloc, /* special_function */ | |
711 | "R_ARM_MOVT_ABS", /* name */ | |
712 | FALSE, /* partial_inplace */ | |
713 | 0x0000ffff, /* src_mask */ | |
714 | 0x0000ffff, /* dst_mask */ | |
715 | FALSE), /* pcrel_offset */ | |
716 | ||
717 | HOWTO (R_ARM_MOVW_PREL_NC, /* type */ | |
718 | 0, /* rightshift */ | |
719 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
720 | 16, /* bitsize */ | |
721 | TRUE, /* pc_relative */ | |
722 | 0, /* bitpos */ | |
723 | complain_overflow_dont,/* complain_on_overflow */ | |
724 | bfd_elf_generic_reloc, /* special_function */ | |
725 | "R_ARM_MOVW_PREL_NC", /* name */ | |
726 | FALSE, /* partial_inplace */ | |
727 | 0x0000ffff, /* src_mask */ | |
728 | 0x0000ffff, /* dst_mask */ | |
729 | TRUE), /* pcrel_offset */ | |
730 | ||
731 | HOWTO (R_ARM_MOVT_PREL, /* type */ | |
732 | 0, /* rightshift */ | |
733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
734 | 16, /* bitsize */ | |
735 | TRUE, /* pc_relative */ | |
736 | 0, /* bitpos */ | |
737 | complain_overflow_bitfield,/* complain_on_overflow */ | |
738 | bfd_elf_generic_reloc, /* special_function */ | |
739 | "R_ARM_MOVT_PREL", /* name */ | |
740 | FALSE, /* partial_inplace */ | |
741 | 0x0000ffff, /* src_mask */ | |
742 | 0x0000ffff, /* dst_mask */ | |
743 | TRUE), /* pcrel_offset */ | |
744 | ||
745 | HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */ | |
746 | 0, /* rightshift */ | |
747 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
748 | 16, /* bitsize */ | |
749 | FALSE, /* pc_relative */ | |
750 | 0, /* bitpos */ | |
751 | complain_overflow_dont,/* complain_on_overflow */ | |
752 | bfd_elf_generic_reloc, /* special_function */ | |
753 | "R_ARM_THM_MOVW_ABS_NC",/* name */ | |
754 | FALSE, /* partial_inplace */ | |
755 | 0x040f70ff, /* src_mask */ | |
756 | 0x040f70ff, /* dst_mask */ | |
757 | FALSE), /* pcrel_offset */ | |
758 | ||
759 | HOWTO (R_ARM_THM_MOVT_ABS, /* type */ | |
760 | 0, /* rightshift */ | |
761 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
762 | 16, /* bitsize */ | |
763 | FALSE, /* pc_relative */ | |
764 | 0, /* bitpos */ | |
765 | complain_overflow_bitfield,/* complain_on_overflow */ | |
766 | bfd_elf_generic_reloc, /* special_function */ | |
767 | "R_ARM_THM_MOVT_ABS", /* name */ | |
768 | FALSE, /* partial_inplace */ | |
769 | 0x040f70ff, /* src_mask */ | |
770 | 0x040f70ff, /* dst_mask */ | |
771 | FALSE), /* pcrel_offset */ | |
772 | ||
773 | HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */ | |
774 | 0, /* rightshift */ | |
775 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
776 | 16, /* bitsize */ | |
777 | TRUE, /* pc_relative */ | |
778 | 0, /* bitpos */ | |
779 | complain_overflow_dont,/* complain_on_overflow */ | |
780 | bfd_elf_generic_reloc, /* special_function */ | |
781 | "R_ARM_THM_MOVW_PREL_NC",/* name */ | |
782 | FALSE, /* partial_inplace */ | |
783 | 0x040f70ff, /* src_mask */ | |
784 | 0x040f70ff, /* dst_mask */ | |
785 | TRUE), /* pcrel_offset */ | |
786 | ||
787 | HOWTO (R_ARM_THM_MOVT_PREL, /* type */ | |
788 | 0, /* rightshift */ | |
789 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
790 | 16, /* bitsize */ | |
791 | TRUE, /* pc_relative */ | |
792 | 0, /* bitpos */ | |
793 | complain_overflow_bitfield,/* complain_on_overflow */ | |
794 | bfd_elf_generic_reloc, /* special_function */ | |
795 | "R_ARM_THM_MOVT_PREL", /* name */ | |
796 | FALSE, /* partial_inplace */ | |
797 | 0x040f70ff, /* src_mask */ | |
798 | 0x040f70ff, /* dst_mask */ | |
799 | TRUE), /* pcrel_offset */ | |
800 | ||
801 | HOWTO (R_ARM_THM_JUMP19, /* type */ | |
802 | 1, /* rightshift */ | |
803 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
804 | 19, /* bitsize */ | |
805 | TRUE, /* pc_relative */ | |
806 | 0, /* bitpos */ | |
807 | complain_overflow_signed,/* complain_on_overflow */ | |
808 | bfd_elf_generic_reloc, /* special_function */ | |
809 | "R_ARM_THM_JUMP19", /* name */ | |
810 | FALSE, /* partial_inplace */ | |
811 | 0x043f2fff, /* src_mask */ | |
812 | 0x043f2fff, /* dst_mask */ | |
813 | TRUE), /* pcrel_offset */ | |
814 | ||
815 | HOWTO (R_ARM_THM_JUMP6, /* type */ | |
816 | 1, /* rightshift */ | |
817 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
818 | 6, /* bitsize */ | |
819 | TRUE, /* pc_relative */ | |
820 | 0, /* bitpos */ | |
821 | complain_overflow_unsigned,/* complain_on_overflow */ | |
822 | bfd_elf_generic_reloc, /* special_function */ | |
823 | "R_ARM_THM_JUMP6", /* name */ | |
824 | FALSE, /* partial_inplace */ | |
825 | 0x02f8, /* src_mask */ | |
826 | 0x02f8, /* dst_mask */ | |
827 | TRUE), /* pcrel_offset */ | |
828 | ||
829 | /* These are declared as 13-bit signed relocations because we can | |
830 | address -4095 .. 4095(base) by altering ADDW to SUBW or vice | |
831 | versa. */ | |
832 | HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */ | |
833 | 0, /* rightshift */ | |
834 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
835 | 13, /* bitsize */ | |
836 | TRUE, /* pc_relative */ | |
837 | 0, /* bitpos */ | |
838 | complain_overflow_signed,/* complain_on_overflow */ | |
839 | bfd_elf_generic_reloc, /* special_function */ | |
840 | "R_ARM_THM_ALU_PREL_11_0",/* name */ | |
841 | FALSE, /* partial_inplace */ | |
842 | 0x040070ff, /* src_mask */ | |
843 | 0x040070ff, /* dst_mask */ | |
844 | TRUE), /* pcrel_offset */ | |
845 | ||
846 | HOWTO (R_ARM_THM_PC12, /* type */ | |
847 | 0, /* rightshift */ | |
848 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
849 | 13, /* bitsize */ | |
850 | TRUE, /* pc_relative */ | |
851 | 0, /* bitpos */ | |
852 | complain_overflow_signed,/* complain_on_overflow */ | |
853 | bfd_elf_generic_reloc, /* special_function */ | |
854 | "R_ARM_THM_PC12", /* name */ | |
855 | FALSE, /* partial_inplace */ | |
856 | 0x040070ff, /* src_mask */ | |
857 | 0x040070ff, /* dst_mask */ | |
858 | TRUE), /* pcrel_offset */ | |
859 | ||
860 | HOWTO (R_ARM_ABS32_NOI, /* type */ | |
861 | 0, /* rightshift */ | |
862 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
863 | 32, /* bitsize */ | |
864 | FALSE, /* pc_relative */ | |
865 | 0, /* bitpos */ | |
866 | complain_overflow_dont,/* complain_on_overflow */ | |
867 | bfd_elf_generic_reloc, /* special_function */ | |
868 | "R_ARM_ABS32_NOI", /* name */ | |
869 | FALSE, /* partial_inplace */ | |
870 | 0xffffffff, /* src_mask */ | |
871 | 0xffffffff, /* dst_mask */ | |
872 | FALSE), /* pcrel_offset */ | |
873 | ||
874 | HOWTO (R_ARM_REL32_NOI, /* type */ | |
875 | 0, /* rightshift */ | |
876 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
877 | 32, /* bitsize */ | |
878 | TRUE, /* pc_relative */ | |
879 | 0, /* bitpos */ | |
880 | complain_overflow_dont,/* complain_on_overflow */ | |
881 | bfd_elf_generic_reloc, /* special_function */ | |
882 | "R_ARM_REL32_NOI", /* name */ | |
883 | FALSE, /* partial_inplace */ | |
884 | 0xffffffff, /* src_mask */ | |
885 | 0xffffffff, /* dst_mask */ | |
886 | FALSE), /* pcrel_offset */ | |
7f266840 | 887 | |
4962c51a MS |
888 | /* Group relocations. */ |
889 | ||
890 | HOWTO (R_ARM_ALU_PC_G0_NC, /* type */ | |
891 | 0, /* rightshift */ | |
892 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
893 | 32, /* bitsize */ | |
894 | TRUE, /* pc_relative */ | |
895 | 0, /* bitpos */ | |
896 | complain_overflow_dont,/* complain_on_overflow */ | |
897 | bfd_elf_generic_reloc, /* special_function */ | |
898 | "R_ARM_ALU_PC_G0_NC", /* name */ | |
899 | FALSE, /* partial_inplace */ | |
900 | 0xffffffff, /* src_mask */ | |
901 | 0xffffffff, /* dst_mask */ | |
902 | TRUE), /* pcrel_offset */ | |
903 | ||
904 | HOWTO (R_ARM_ALU_PC_G0, /* type */ | |
905 | 0, /* rightshift */ | |
906 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
907 | 32, /* bitsize */ | |
908 | TRUE, /* pc_relative */ | |
909 | 0, /* bitpos */ | |
910 | complain_overflow_dont,/* complain_on_overflow */ | |
911 | bfd_elf_generic_reloc, /* special_function */ | |
912 | "R_ARM_ALU_PC_G0", /* name */ | |
913 | FALSE, /* partial_inplace */ | |
914 | 0xffffffff, /* src_mask */ | |
915 | 0xffffffff, /* dst_mask */ | |
916 | TRUE), /* pcrel_offset */ | |
917 | ||
918 | HOWTO (R_ARM_ALU_PC_G1_NC, /* type */ | |
919 | 0, /* rightshift */ | |
920 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
921 | 32, /* bitsize */ | |
922 | TRUE, /* pc_relative */ | |
923 | 0, /* bitpos */ | |
924 | complain_overflow_dont,/* complain_on_overflow */ | |
925 | bfd_elf_generic_reloc, /* special_function */ | |
926 | "R_ARM_ALU_PC_G1_NC", /* name */ | |
927 | FALSE, /* partial_inplace */ | |
928 | 0xffffffff, /* src_mask */ | |
929 | 0xffffffff, /* dst_mask */ | |
930 | TRUE), /* pcrel_offset */ | |
931 | ||
932 | HOWTO (R_ARM_ALU_PC_G1, /* type */ | |
933 | 0, /* rightshift */ | |
934 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
935 | 32, /* bitsize */ | |
936 | TRUE, /* pc_relative */ | |
937 | 0, /* bitpos */ | |
938 | complain_overflow_dont,/* complain_on_overflow */ | |
939 | bfd_elf_generic_reloc, /* special_function */ | |
940 | "R_ARM_ALU_PC_G1", /* name */ | |
941 | FALSE, /* partial_inplace */ | |
942 | 0xffffffff, /* src_mask */ | |
943 | 0xffffffff, /* dst_mask */ | |
944 | TRUE), /* pcrel_offset */ | |
945 | ||
946 | HOWTO (R_ARM_ALU_PC_G2, /* type */ | |
947 | 0, /* rightshift */ | |
948 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
949 | 32, /* bitsize */ | |
950 | TRUE, /* pc_relative */ | |
951 | 0, /* bitpos */ | |
952 | complain_overflow_dont,/* complain_on_overflow */ | |
953 | bfd_elf_generic_reloc, /* special_function */ | |
954 | "R_ARM_ALU_PC_G2", /* name */ | |
955 | FALSE, /* partial_inplace */ | |
956 | 0xffffffff, /* src_mask */ | |
957 | 0xffffffff, /* dst_mask */ | |
958 | TRUE), /* pcrel_offset */ | |
959 | ||
960 | HOWTO (R_ARM_LDR_PC_G1, /* type */ | |
961 | 0, /* rightshift */ | |
962 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
963 | 32, /* bitsize */ | |
964 | TRUE, /* pc_relative */ | |
965 | 0, /* bitpos */ | |
966 | complain_overflow_dont,/* complain_on_overflow */ | |
967 | bfd_elf_generic_reloc, /* special_function */ | |
968 | "R_ARM_LDR_PC_G1", /* name */ | |
969 | FALSE, /* partial_inplace */ | |
970 | 0xffffffff, /* src_mask */ | |
971 | 0xffffffff, /* dst_mask */ | |
972 | TRUE), /* pcrel_offset */ | |
973 | ||
974 | HOWTO (R_ARM_LDR_PC_G2, /* type */ | |
975 | 0, /* rightshift */ | |
976 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
977 | 32, /* bitsize */ | |
978 | TRUE, /* pc_relative */ | |
979 | 0, /* bitpos */ | |
980 | complain_overflow_dont,/* complain_on_overflow */ | |
981 | bfd_elf_generic_reloc, /* special_function */ | |
982 | "R_ARM_LDR_PC_G2", /* name */ | |
983 | FALSE, /* partial_inplace */ | |
984 | 0xffffffff, /* src_mask */ | |
985 | 0xffffffff, /* dst_mask */ | |
986 | TRUE), /* pcrel_offset */ | |
987 | ||
988 | HOWTO (R_ARM_LDRS_PC_G0, /* type */ | |
989 | 0, /* rightshift */ | |
990 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
991 | 32, /* bitsize */ | |
992 | TRUE, /* pc_relative */ | |
993 | 0, /* bitpos */ | |
994 | complain_overflow_dont,/* complain_on_overflow */ | |
995 | bfd_elf_generic_reloc, /* special_function */ | |
996 | "R_ARM_LDRS_PC_G0", /* name */ | |
997 | FALSE, /* partial_inplace */ | |
998 | 0xffffffff, /* src_mask */ | |
999 | 0xffffffff, /* dst_mask */ | |
1000 | TRUE), /* pcrel_offset */ | |
1001 | ||
1002 | HOWTO (R_ARM_LDRS_PC_G1, /* type */ | |
1003 | 0, /* rightshift */ | |
1004 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1005 | 32, /* bitsize */ | |
1006 | TRUE, /* pc_relative */ | |
1007 | 0, /* bitpos */ | |
1008 | complain_overflow_dont,/* complain_on_overflow */ | |
1009 | bfd_elf_generic_reloc, /* special_function */ | |
1010 | "R_ARM_LDRS_PC_G1", /* name */ | |
1011 | FALSE, /* partial_inplace */ | |
1012 | 0xffffffff, /* src_mask */ | |
1013 | 0xffffffff, /* dst_mask */ | |
1014 | TRUE), /* pcrel_offset */ | |
1015 | ||
1016 | HOWTO (R_ARM_LDRS_PC_G2, /* type */ | |
1017 | 0, /* rightshift */ | |
1018 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1019 | 32, /* bitsize */ | |
1020 | TRUE, /* pc_relative */ | |
1021 | 0, /* bitpos */ | |
1022 | complain_overflow_dont,/* complain_on_overflow */ | |
1023 | bfd_elf_generic_reloc, /* special_function */ | |
1024 | "R_ARM_LDRS_PC_G2", /* name */ | |
1025 | FALSE, /* partial_inplace */ | |
1026 | 0xffffffff, /* src_mask */ | |
1027 | 0xffffffff, /* dst_mask */ | |
1028 | TRUE), /* pcrel_offset */ | |
1029 | ||
1030 | HOWTO (R_ARM_LDC_PC_G0, /* type */ | |
1031 | 0, /* rightshift */ | |
1032 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1033 | 32, /* bitsize */ | |
1034 | TRUE, /* pc_relative */ | |
1035 | 0, /* bitpos */ | |
1036 | complain_overflow_dont,/* complain_on_overflow */ | |
1037 | bfd_elf_generic_reloc, /* special_function */ | |
1038 | "R_ARM_LDC_PC_G0", /* name */ | |
1039 | FALSE, /* partial_inplace */ | |
1040 | 0xffffffff, /* src_mask */ | |
1041 | 0xffffffff, /* dst_mask */ | |
1042 | TRUE), /* pcrel_offset */ | |
1043 | ||
1044 | HOWTO (R_ARM_LDC_PC_G1, /* type */ | |
1045 | 0, /* rightshift */ | |
1046 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1047 | 32, /* bitsize */ | |
1048 | TRUE, /* pc_relative */ | |
1049 | 0, /* bitpos */ | |
1050 | complain_overflow_dont,/* complain_on_overflow */ | |
1051 | bfd_elf_generic_reloc, /* special_function */ | |
1052 | "R_ARM_LDC_PC_G1", /* name */ | |
1053 | FALSE, /* partial_inplace */ | |
1054 | 0xffffffff, /* src_mask */ | |
1055 | 0xffffffff, /* dst_mask */ | |
1056 | TRUE), /* pcrel_offset */ | |
1057 | ||
1058 | HOWTO (R_ARM_LDC_PC_G2, /* type */ | |
1059 | 0, /* rightshift */ | |
1060 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1061 | 32, /* bitsize */ | |
1062 | TRUE, /* pc_relative */ | |
1063 | 0, /* bitpos */ | |
1064 | complain_overflow_dont,/* complain_on_overflow */ | |
1065 | bfd_elf_generic_reloc, /* special_function */ | |
1066 | "R_ARM_LDC_PC_G2", /* name */ | |
1067 | FALSE, /* partial_inplace */ | |
1068 | 0xffffffff, /* src_mask */ | |
1069 | 0xffffffff, /* dst_mask */ | |
1070 | TRUE), /* pcrel_offset */ | |
1071 | ||
1072 | HOWTO (R_ARM_ALU_SB_G0_NC, /* type */ | |
1073 | 0, /* rightshift */ | |
1074 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1075 | 32, /* bitsize */ | |
1076 | TRUE, /* pc_relative */ | |
1077 | 0, /* bitpos */ | |
1078 | complain_overflow_dont,/* complain_on_overflow */ | |
1079 | bfd_elf_generic_reloc, /* special_function */ | |
1080 | "R_ARM_ALU_SB_G0_NC", /* name */ | |
1081 | FALSE, /* partial_inplace */ | |
1082 | 0xffffffff, /* src_mask */ | |
1083 | 0xffffffff, /* dst_mask */ | |
1084 | TRUE), /* pcrel_offset */ | |
1085 | ||
1086 | HOWTO (R_ARM_ALU_SB_G0, /* type */ | |
1087 | 0, /* rightshift */ | |
1088 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1089 | 32, /* bitsize */ | |
1090 | TRUE, /* pc_relative */ | |
1091 | 0, /* bitpos */ | |
1092 | complain_overflow_dont,/* complain_on_overflow */ | |
1093 | bfd_elf_generic_reloc, /* special_function */ | |
1094 | "R_ARM_ALU_SB_G0", /* name */ | |
1095 | FALSE, /* partial_inplace */ | |
1096 | 0xffffffff, /* src_mask */ | |
1097 | 0xffffffff, /* dst_mask */ | |
1098 | TRUE), /* pcrel_offset */ | |
1099 | ||
1100 | HOWTO (R_ARM_ALU_SB_G1_NC, /* type */ | |
1101 | 0, /* rightshift */ | |
1102 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1103 | 32, /* bitsize */ | |
1104 | TRUE, /* pc_relative */ | |
1105 | 0, /* bitpos */ | |
1106 | complain_overflow_dont,/* complain_on_overflow */ | |
1107 | bfd_elf_generic_reloc, /* special_function */ | |
1108 | "R_ARM_ALU_SB_G1_NC", /* name */ | |
1109 | FALSE, /* partial_inplace */ | |
1110 | 0xffffffff, /* src_mask */ | |
1111 | 0xffffffff, /* dst_mask */ | |
1112 | TRUE), /* pcrel_offset */ | |
1113 | ||
1114 | HOWTO (R_ARM_ALU_SB_G1, /* type */ | |
1115 | 0, /* rightshift */ | |
1116 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1117 | 32, /* bitsize */ | |
1118 | TRUE, /* pc_relative */ | |
1119 | 0, /* bitpos */ | |
1120 | complain_overflow_dont,/* complain_on_overflow */ | |
1121 | bfd_elf_generic_reloc, /* special_function */ | |
1122 | "R_ARM_ALU_SB_G1", /* name */ | |
1123 | FALSE, /* partial_inplace */ | |
1124 | 0xffffffff, /* src_mask */ | |
1125 | 0xffffffff, /* dst_mask */ | |
1126 | TRUE), /* pcrel_offset */ | |
1127 | ||
1128 | HOWTO (R_ARM_ALU_SB_G2, /* type */ | |
1129 | 0, /* rightshift */ | |
1130 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1131 | 32, /* bitsize */ | |
1132 | TRUE, /* pc_relative */ | |
1133 | 0, /* bitpos */ | |
1134 | complain_overflow_dont,/* complain_on_overflow */ | |
1135 | bfd_elf_generic_reloc, /* special_function */ | |
1136 | "R_ARM_ALU_SB_G2", /* name */ | |
1137 | FALSE, /* partial_inplace */ | |
1138 | 0xffffffff, /* src_mask */ | |
1139 | 0xffffffff, /* dst_mask */ | |
1140 | TRUE), /* pcrel_offset */ | |
1141 | ||
1142 | HOWTO (R_ARM_LDR_SB_G0, /* type */ | |
1143 | 0, /* rightshift */ | |
1144 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1145 | 32, /* bitsize */ | |
1146 | TRUE, /* pc_relative */ | |
1147 | 0, /* bitpos */ | |
1148 | complain_overflow_dont,/* complain_on_overflow */ | |
1149 | bfd_elf_generic_reloc, /* special_function */ | |
1150 | "R_ARM_LDR_SB_G0", /* name */ | |
1151 | FALSE, /* partial_inplace */ | |
1152 | 0xffffffff, /* src_mask */ | |
1153 | 0xffffffff, /* dst_mask */ | |
1154 | TRUE), /* pcrel_offset */ | |
1155 | ||
1156 | HOWTO (R_ARM_LDR_SB_G1, /* type */ | |
1157 | 0, /* rightshift */ | |
1158 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1159 | 32, /* bitsize */ | |
1160 | TRUE, /* pc_relative */ | |
1161 | 0, /* bitpos */ | |
1162 | complain_overflow_dont,/* complain_on_overflow */ | |
1163 | bfd_elf_generic_reloc, /* special_function */ | |
1164 | "R_ARM_LDR_SB_G1", /* name */ | |
1165 | FALSE, /* partial_inplace */ | |
1166 | 0xffffffff, /* src_mask */ | |
1167 | 0xffffffff, /* dst_mask */ | |
1168 | TRUE), /* pcrel_offset */ | |
1169 | ||
1170 | HOWTO (R_ARM_LDR_SB_G2, /* type */ | |
1171 | 0, /* rightshift */ | |
1172 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1173 | 32, /* bitsize */ | |
1174 | TRUE, /* pc_relative */ | |
1175 | 0, /* bitpos */ | |
1176 | complain_overflow_dont,/* complain_on_overflow */ | |
1177 | bfd_elf_generic_reloc, /* special_function */ | |
1178 | "R_ARM_LDR_SB_G2", /* name */ | |
1179 | FALSE, /* partial_inplace */ | |
1180 | 0xffffffff, /* src_mask */ | |
1181 | 0xffffffff, /* dst_mask */ | |
1182 | TRUE), /* pcrel_offset */ | |
1183 | ||
1184 | HOWTO (R_ARM_LDRS_SB_G0, /* type */ | |
1185 | 0, /* rightshift */ | |
1186 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1187 | 32, /* bitsize */ | |
1188 | TRUE, /* pc_relative */ | |
1189 | 0, /* bitpos */ | |
1190 | complain_overflow_dont,/* complain_on_overflow */ | |
1191 | bfd_elf_generic_reloc, /* special_function */ | |
1192 | "R_ARM_LDRS_SB_G0", /* name */ | |
1193 | FALSE, /* partial_inplace */ | |
1194 | 0xffffffff, /* src_mask */ | |
1195 | 0xffffffff, /* dst_mask */ | |
1196 | TRUE), /* pcrel_offset */ | |
1197 | ||
1198 | HOWTO (R_ARM_LDRS_SB_G1, /* type */ | |
1199 | 0, /* rightshift */ | |
1200 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1201 | 32, /* bitsize */ | |
1202 | TRUE, /* pc_relative */ | |
1203 | 0, /* bitpos */ | |
1204 | complain_overflow_dont,/* complain_on_overflow */ | |
1205 | bfd_elf_generic_reloc, /* special_function */ | |
1206 | "R_ARM_LDRS_SB_G1", /* name */ | |
1207 | FALSE, /* partial_inplace */ | |
1208 | 0xffffffff, /* src_mask */ | |
1209 | 0xffffffff, /* dst_mask */ | |
1210 | TRUE), /* pcrel_offset */ | |
1211 | ||
1212 | HOWTO (R_ARM_LDRS_SB_G2, /* type */ | |
1213 | 0, /* rightshift */ | |
1214 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1215 | 32, /* bitsize */ | |
1216 | TRUE, /* pc_relative */ | |
1217 | 0, /* bitpos */ | |
1218 | complain_overflow_dont,/* complain_on_overflow */ | |
1219 | bfd_elf_generic_reloc, /* special_function */ | |
1220 | "R_ARM_LDRS_SB_G2", /* name */ | |
1221 | FALSE, /* partial_inplace */ | |
1222 | 0xffffffff, /* src_mask */ | |
1223 | 0xffffffff, /* dst_mask */ | |
1224 | TRUE), /* pcrel_offset */ | |
1225 | ||
1226 | HOWTO (R_ARM_LDC_SB_G0, /* type */ | |
1227 | 0, /* rightshift */ | |
1228 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1229 | 32, /* bitsize */ | |
1230 | TRUE, /* pc_relative */ | |
1231 | 0, /* bitpos */ | |
1232 | complain_overflow_dont,/* complain_on_overflow */ | |
1233 | bfd_elf_generic_reloc, /* special_function */ | |
1234 | "R_ARM_LDC_SB_G0", /* name */ | |
1235 | FALSE, /* partial_inplace */ | |
1236 | 0xffffffff, /* src_mask */ | |
1237 | 0xffffffff, /* dst_mask */ | |
1238 | TRUE), /* pcrel_offset */ | |
1239 | ||
1240 | HOWTO (R_ARM_LDC_SB_G1, /* type */ | |
1241 | 0, /* rightshift */ | |
1242 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1243 | 32, /* bitsize */ | |
1244 | TRUE, /* pc_relative */ | |
1245 | 0, /* bitpos */ | |
1246 | complain_overflow_dont,/* complain_on_overflow */ | |
1247 | bfd_elf_generic_reloc, /* special_function */ | |
1248 | "R_ARM_LDC_SB_G1", /* name */ | |
1249 | FALSE, /* partial_inplace */ | |
1250 | 0xffffffff, /* src_mask */ | |
1251 | 0xffffffff, /* dst_mask */ | |
1252 | TRUE), /* pcrel_offset */ | |
1253 | ||
1254 | HOWTO (R_ARM_LDC_SB_G2, /* type */ | |
1255 | 0, /* rightshift */ | |
1256 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1257 | 32, /* bitsize */ | |
1258 | TRUE, /* pc_relative */ | |
1259 | 0, /* bitpos */ | |
1260 | complain_overflow_dont,/* complain_on_overflow */ | |
1261 | bfd_elf_generic_reloc, /* special_function */ | |
1262 | "R_ARM_LDC_SB_G2", /* name */ | |
1263 | FALSE, /* partial_inplace */ | |
1264 | 0xffffffff, /* src_mask */ | |
1265 | 0xffffffff, /* dst_mask */ | |
1266 | TRUE), /* pcrel_offset */ | |
1267 | ||
1268 | /* End of group relocations. */ | |
c19d1205 | 1269 | |
c19d1205 ZW |
1270 | HOWTO (R_ARM_MOVW_BREL_NC, /* type */ |
1271 | 0, /* rightshift */ | |
1272 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1273 | 16, /* bitsize */ | |
1274 | FALSE, /* pc_relative */ | |
1275 | 0, /* bitpos */ | |
1276 | complain_overflow_dont,/* complain_on_overflow */ | |
1277 | bfd_elf_generic_reloc, /* special_function */ | |
1278 | "R_ARM_MOVW_BREL_NC", /* name */ | |
1279 | FALSE, /* partial_inplace */ | |
1280 | 0x0000ffff, /* src_mask */ | |
1281 | 0x0000ffff, /* dst_mask */ | |
1282 | FALSE), /* pcrel_offset */ | |
1283 | ||
1284 | HOWTO (R_ARM_MOVT_BREL, /* type */ | |
1285 | 0, /* rightshift */ | |
1286 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1287 | 16, /* bitsize */ | |
1288 | FALSE, /* pc_relative */ | |
1289 | 0, /* bitpos */ | |
1290 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1291 | bfd_elf_generic_reloc, /* special_function */ | |
1292 | "R_ARM_MOVT_BREL", /* name */ | |
1293 | FALSE, /* partial_inplace */ | |
1294 | 0x0000ffff, /* src_mask */ | |
1295 | 0x0000ffff, /* dst_mask */ | |
1296 | FALSE), /* pcrel_offset */ | |
1297 | ||
1298 | HOWTO (R_ARM_MOVW_BREL, /* type */ | |
1299 | 0, /* rightshift */ | |
1300 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1301 | 16, /* bitsize */ | |
1302 | FALSE, /* pc_relative */ | |
1303 | 0, /* bitpos */ | |
1304 | complain_overflow_dont,/* complain_on_overflow */ | |
1305 | bfd_elf_generic_reloc, /* special_function */ | |
1306 | "R_ARM_MOVW_BREL", /* name */ | |
1307 | FALSE, /* partial_inplace */ | |
1308 | 0x0000ffff, /* src_mask */ | |
1309 | 0x0000ffff, /* dst_mask */ | |
1310 | FALSE), /* pcrel_offset */ | |
1311 | ||
1312 | HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */ | |
1313 | 0, /* rightshift */ | |
1314 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1315 | 16, /* bitsize */ | |
1316 | FALSE, /* pc_relative */ | |
1317 | 0, /* bitpos */ | |
1318 | complain_overflow_dont,/* complain_on_overflow */ | |
1319 | bfd_elf_generic_reloc, /* special_function */ | |
1320 | "R_ARM_THM_MOVW_BREL_NC",/* name */ | |
1321 | FALSE, /* partial_inplace */ | |
1322 | 0x040f70ff, /* src_mask */ | |
1323 | 0x040f70ff, /* dst_mask */ | |
1324 | FALSE), /* pcrel_offset */ | |
1325 | ||
1326 | HOWTO (R_ARM_THM_MOVT_BREL, /* type */ | |
1327 | 0, /* rightshift */ | |
1328 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1329 | 16, /* bitsize */ | |
1330 | FALSE, /* pc_relative */ | |
1331 | 0, /* bitpos */ | |
1332 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1333 | bfd_elf_generic_reloc, /* special_function */ | |
1334 | "R_ARM_THM_MOVT_BREL", /* name */ | |
1335 | FALSE, /* partial_inplace */ | |
1336 | 0x040f70ff, /* src_mask */ | |
1337 | 0x040f70ff, /* dst_mask */ | |
1338 | FALSE), /* pcrel_offset */ | |
1339 | ||
1340 | HOWTO (R_ARM_THM_MOVW_BREL, /* type */ | |
1341 | 0, /* rightshift */ | |
1342 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1343 | 16, /* bitsize */ | |
1344 | FALSE, /* pc_relative */ | |
1345 | 0, /* bitpos */ | |
1346 | complain_overflow_dont,/* complain_on_overflow */ | |
1347 | bfd_elf_generic_reloc, /* special_function */ | |
1348 | "R_ARM_THM_MOVW_BREL", /* name */ | |
1349 | FALSE, /* partial_inplace */ | |
1350 | 0x040f70ff, /* src_mask */ | |
1351 | 0x040f70ff, /* dst_mask */ | |
1352 | FALSE), /* pcrel_offset */ | |
1353 | ||
1354 | EMPTY_HOWTO (90), /* unallocated */ | |
1355 | EMPTY_HOWTO (91), | |
1356 | EMPTY_HOWTO (92), | |
1357 | EMPTY_HOWTO (93), | |
1358 | ||
1359 | HOWTO (R_ARM_PLT32_ABS, /* type */ | |
1360 | 0, /* rightshift */ | |
1361 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1362 | 32, /* bitsize */ | |
1363 | FALSE, /* pc_relative */ | |
1364 | 0, /* bitpos */ | |
1365 | complain_overflow_dont,/* complain_on_overflow */ | |
1366 | bfd_elf_generic_reloc, /* special_function */ | |
1367 | "R_ARM_PLT32_ABS", /* name */ | |
1368 | FALSE, /* partial_inplace */ | |
1369 | 0xffffffff, /* src_mask */ | |
1370 | 0xffffffff, /* dst_mask */ | |
1371 | FALSE), /* pcrel_offset */ | |
1372 | ||
1373 | HOWTO (R_ARM_GOT_ABS, /* type */ | |
1374 | 0, /* rightshift */ | |
1375 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1376 | 32, /* bitsize */ | |
1377 | FALSE, /* pc_relative */ | |
1378 | 0, /* bitpos */ | |
1379 | complain_overflow_dont,/* complain_on_overflow */ | |
1380 | bfd_elf_generic_reloc, /* special_function */ | |
1381 | "R_ARM_GOT_ABS", /* name */ | |
1382 | FALSE, /* partial_inplace */ | |
1383 | 0xffffffff, /* src_mask */ | |
1384 | 0xffffffff, /* dst_mask */ | |
1385 | FALSE), /* pcrel_offset */ | |
1386 | ||
1387 | HOWTO (R_ARM_GOT_PREL, /* type */ | |
1388 | 0, /* rightshift */ | |
1389 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1390 | 32, /* bitsize */ | |
1391 | TRUE, /* pc_relative */ | |
1392 | 0, /* bitpos */ | |
1393 | complain_overflow_dont, /* complain_on_overflow */ | |
1394 | bfd_elf_generic_reloc, /* special_function */ | |
1395 | "R_ARM_GOT_PREL", /* name */ | |
1396 | FALSE, /* partial_inplace */ | |
1397 | 0xffffffff, /* src_mask */ | |
1398 | 0xffffffff, /* dst_mask */ | |
1399 | TRUE), /* pcrel_offset */ | |
1400 | ||
1401 | HOWTO (R_ARM_GOT_BREL12, /* type */ | |
1402 | 0, /* rightshift */ | |
1403 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1404 | 12, /* bitsize */ | |
1405 | FALSE, /* pc_relative */ | |
1406 | 0, /* bitpos */ | |
1407 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1408 | bfd_elf_generic_reloc, /* special_function */ | |
1409 | "R_ARM_GOT_BREL12", /* name */ | |
1410 | FALSE, /* partial_inplace */ | |
1411 | 0x00000fff, /* src_mask */ | |
1412 | 0x00000fff, /* dst_mask */ | |
1413 | FALSE), /* pcrel_offset */ | |
1414 | ||
1415 | HOWTO (R_ARM_GOTOFF12, /* type */ | |
1416 | 0, /* rightshift */ | |
1417 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1418 | 12, /* bitsize */ | |
1419 | FALSE, /* pc_relative */ | |
1420 | 0, /* bitpos */ | |
1421 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1422 | bfd_elf_generic_reloc, /* special_function */ | |
1423 | "R_ARM_GOTOFF12", /* name */ | |
1424 | FALSE, /* partial_inplace */ | |
1425 | 0x00000fff, /* src_mask */ | |
1426 | 0x00000fff, /* dst_mask */ | |
1427 | FALSE), /* pcrel_offset */ | |
1428 | ||
1429 | EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */ | |
1430 | ||
1431 | /* GNU extension to record C++ vtable member usage */ | |
1432 | HOWTO (R_ARM_GNU_VTENTRY, /* type */ | |
ba93b8ac DJ |
1433 | 0, /* rightshift */ |
1434 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1435 | 0, /* bitsize */ |
ba93b8ac DJ |
1436 | FALSE, /* pc_relative */ |
1437 | 0, /* bitpos */ | |
c19d1205 ZW |
1438 | complain_overflow_dont, /* complain_on_overflow */ |
1439 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
1440 | "R_ARM_GNU_VTENTRY", /* name */ | |
1441 | FALSE, /* partial_inplace */ | |
1442 | 0, /* src_mask */ | |
1443 | 0, /* dst_mask */ | |
1444 | FALSE), /* pcrel_offset */ | |
1445 | ||
1446 | /* GNU extension to record C++ vtable hierarchy */ | |
1447 | HOWTO (R_ARM_GNU_VTINHERIT, /* type */ | |
1448 | 0, /* rightshift */ | |
1449 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1450 | 0, /* bitsize */ | |
1451 | FALSE, /* pc_relative */ | |
1452 | 0, /* bitpos */ | |
1453 | complain_overflow_dont, /* complain_on_overflow */ | |
1454 | NULL, /* special_function */ | |
1455 | "R_ARM_GNU_VTINHERIT", /* name */ | |
1456 | FALSE, /* partial_inplace */ | |
1457 | 0, /* src_mask */ | |
1458 | 0, /* dst_mask */ | |
1459 | FALSE), /* pcrel_offset */ | |
1460 | ||
1461 | HOWTO (R_ARM_THM_JUMP11, /* type */ | |
1462 | 1, /* rightshift */ | |
1463 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1464 | 11, /* bitsize */ | |
1465 | TRUE, /* pc_relative */ | |
1466 | 0, /* bitpos */ | |
1467 | complain_overflow_signed, /* complain_on_overflow */ | |
1468 | bfd_elf_generic_reloc, /* special_function */ | |
1469 | "R_ARM_THM_JUMP11", /* name */ | |
1470 | FALSE, /* partial_inplace */ | |
1471 | 0x000007ff, /* src_mask */ | |
1472 | 0x000007ff, /* dst_mask */ | |
1473 | TRUE), /* pcrel_offset */ | |
1474 | ||
1475 | HOWTO (R_ARM_THM_JUMP8, /* type */ | |
1476 | 1, /* rightshift */ | |
1477 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1478 | 8, /* bitsize */ | |
1479 | TRUE, /* pc_relative */ | |
1480 | 0, /* bitpos */ | |
1481 | complain_overflow_signed, /* complain_on_overflow */ | |
1482 | bfd_elf_generic_reloc, /* special_function */ | |
1483 | "R_ARM_THM_JUMP8", /* name */ | |
1484 | FALSE, /* partial_inplace */ | |
1485 | 0x000000ff, /* src_mask */ | |
1486 | 0x000000ff, /* dst_mask */ | |
1487 | TRUE), /* pcrel_offset */ | |
ba93b8ac | 1488 | |
c19d1205 ZW |
1489 | /* TLS relocations */ |
1490 | HOWTO (R_ARM_TLS_GD32, /* type */ | |
ba93b8ac DJ |
1491 | 0, /* rightshift */ |
1492 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1493 | 32, /* bitsize */ | |
1494 | FALSE, /* pc_relative */ | |
1495 | 0, /* bitpos */ | |
1496 | complain_overflow_bitfield,/* complain_on_overflow */ | |
c19d1205 ZW |
1497 | NULL, /* special_function */ |
1498 | "R_ARM_TLS_GD32", /* name */ | |
ba93b8ac DJ |
1499 | TRUE, /* partial_inplace */ |
1500 | 0xffffffff, /* src_mask */ | |
1501 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1502 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1503 | |
ba93b8ac DJ |
1504 | HOWTO (R_ARM_TLS_LDM32, /* type */ |
1505 | 0, /* rightshift */ | |
1506 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1507 | 32, /* bitsize */ | |
1508 | FALSE, /* pc_relative */ | |
1509 | 0, /* bitpos */ | |
1510 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1511 | bfd_elf_generic_reloc, /* special_function */ | |
1512 | "R_ARM_TLS_LDM32", /* name */ | |
1513 | TRUE, /* partial_inplace */ | |
1514 | 0xffffffff, /* src_mask */ | |
1515 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1516 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1517 | |
c19d1205 | 1518 | HOWTO (R_ARM_TLS_LDO32, /* type */ |
ba93b8ac DJ |
1519 | 0, /* rightshift */ |
1520 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1521 | 32, /* bitsize */ | |
1522 | FALSE, /* pc_relative */ | |
1523 | 0, /* bitpos */ | |
1524 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1525 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 1526 | "R_ARM_TLS_LDO32", /* name */ |
ba93b8ac DJ |
1527 | TRUE, /* partial_inplace */ |
1528 | 0xffffffff, /* src_mask */ | |
1529 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1530 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1531 | |
ba93b8ac DJ |
1532 | HOWTO (R_ARM_TLS_IE32, /* type */ |
1533 | 0, /* rightshift */ | |
1534 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1535 | 32, /* bitsize */ | |
1536 | FALSE, /* pc_relative */ | |
1537 | 0, /* bitpos */ | |
1538 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1539 | NULL, /* special_function */ | |
1540 | "R_ARM_TLS_IE32", /* name */ | |
1541 | TRUE, /* partial_inplace */ | |
1542 | 0xffffffff, /* src_mask */ | |
1543 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1544 | FALSE), /* pcrel_offset */ |
7f266840 | 1545 | |
c19d1205 | 1546 | HOWTO (R_ARM_TLS_LE32, /* type */ |
7f266840 DJ |
1547 | 0, /* rightshift */ |
1548 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1549 | 32, /* bitsize */ |
7f266840 DJ |
1550 | FALSE, /* pc_relative */ |
1551 | 0, /* bitpos */ | |
c19d1205 ZW |
1552 | complain_overflow_bitfield,/* complain_on_overflow */ |
1553 | bfd_elf_generic_reloc, /* special_function */ | |
1554 | "R_ARM_TLS_LE32", /* name */ | |
1555 | TRUE, /* partial_inplace */ | |
1556 | 0xffffffff, /* src_mask */ | |
1557 | 0xffffffff, /* dst_mask */ | |
1558 | FALSE), /* pcrel_offset */ | |
7f266840 | 1559 | |
c19d1205 ZW |
1560 | HOWTO (R_ARM_TLS_LDO12, /* type */ |
1561 | 0, /* rightshift */ | |
1562 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1563 | 12, /* bitsize */ | |
1564 | FALSE, /* pc_relative */ | |
7f266840 | 1565 | 0, /* bitpos */ |
c19d1205 | 1566 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1567 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1568 | "R_ARM_TLS_LDO12", /* name */ |
7f266840 | 1569 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1570 | 0x00000fff, /* src_mask */ |
1571 | 0x00000fff, /* dst_mask */ | |
1572 | FALSE), /* pcrel_offset */ | |
7f266840 | 1573 | |
c19d1205 ZW |
1574 | HOWTO (R_ARM_TLS_LE12, /* type */ |
1575 | 0, /* rightshift */ | |
1576 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1577 | 12, /* bitsize */ | |
1578 | FALSE, /* pc_relative */ | |
7f266840 | 1579 | 0, /* bitpos */ |
c19d1205 | 1580 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1581 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1582 | "R_ARM_TLS_LE12", /* name */ |
7f266840 | 1583 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1584 | 0x00000fff, /* src_mask */ |
1585 | 0x00000fff, /* dst_mask */ | |
1586 | FALSE), /* pcrel_offset */ | |
7f266840 | 1587 | |
c19d1205 | 1588 | HOWTO (R_ARM_TLS_IE12GP, /* type */ |
7f266840 DJ |
1589 | 0, /* rightshift */ |
1590 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 ZW |
1591 | 12, /* bitsize */ |
1592 | FALSE, /* pc_relative */ | |
7f266840 | 1593 | 0, /* bitpos */ |
c19d1205 | 1594 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1595 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1596 | "R_ARM_TLS_IE12GP", /* name */ |
7f266840 | 1597 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1598 | 0x00000fff, /* src_mask */ |
1599 | 0x00000fff, /* dst_mask */ | |
1600 | FALSE), /* pcrel_offset */ | |
1601 | }; | |
1602 | ||
1603 | /* 112-127 private relocations | |
1604 | 128 R_ARM_ME_TOO, obsolete | |
1605 | 129-255 unallocated in AAELF. | |
7f266840 | 1606 | |
c19d1205 ZW |
1607 | 249-255 extended, currently unused, relocations: */ |
1608 | ||
4962c51a | 1609 | static reloc_howto_type elf32_arm_howto_table_2[4] = |
7f266840 DJ |
1610 | { |
1611 | HOWTO (R_ARM_RREL32, /* type */ | |
1612 | 0, /* rightshift */ | |
1613 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1614 | 0, /* bitsize */ | |
1615 | FALSE, /* pc_relative */ | |
1616 | 0, /* bitpos */ | |
1617 | complain_overflow_dont,/* complain_on_overflow */ | |
1618 | bfd_elf_generic_reloc, /* special_function */ | |
1619 | "R_ARM_RREL32", /* name */ | |
1620 | FALSE, /* partial_inplace */ | |
1621 | 0, /* src_mask */ | |
1622 | 0, /* dst_mask */ | |
1623 | FALSE), /* pcrel_offset */ | |
1624 | ||
1625 | HOWTO (R_ARM_RABS32, /* type */ | |
1626 | 0, /* rightshift */ | |
1627 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1628 | 0, /* bitsize */ | |
1629 | FALSE, /* pc_relative */ | |
1630 | 0, /* bitpos */ | |
1631 | complain_overflow_dont,/* complain_on_overflow */ | |
1632 | bfd_elf_generic_reloc, /* special_function */ | |
1633 | "R_ARM_RABS32", /* name */ | |
1634 | FALSE, /* partial_inplace */ | |
1635 | 0, /* src_mask */ | |
1636 | 0, /* dst_mask */ | |
1637 | FALSE), /* pcrel_offset */ | |
1638 | ||
1639 | HOWTO (R_ARM_RPC24, /* type */ | |
1640 | 0, /* rightshift */ | |
1641 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1642 | 0, /* bitsize */ | |
1643 | FALSE, /* pc_relative */ | |
1644 | 0, /* bitpos */ | |
1645 | complain_overflow_dont,/* complain_on_overflow */ | |
1646 | bfd_elf_generic_reloc, /* special_function */ | |
1647 | "R_ARM_RPC24", /* name */ | |
1648 | FALSE, /* partial_inplace */ | |
1649 | 0, /* src_mask */ | |
1650 | 0, /* dst_mask */ | |
1651 | FALSE), /* pcrel_offset */ | |
1652 | ||
1653 | HOWTO (R_ARM_RBASE, /* type */ | |
1654 | 0, /* rightshift */ | |
1655 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1656 | 0, /* bitsize */ | |
1657 | FALSE, /* pc_relative */ | |
1658 | 0, /* bitpos */ | |
1659 | complain_overflow_dont,/* complain_on_overflow */ | |
1660 | bfd_elf_generic_reloc, /* special_function */ | |
1661 | "R_ARM_RBASE", /* name */ | |
1662 | FALSE, /* partial_inplace */ | |
1663 | 0, /* src_mask */ | |
1664 | 0, /* dst_mask */ | |
1665 | FALSE) /* pcrel_offset */ | |
1666 | }; | |
1667 | ||
1668 | static reloc_howto_type * | |
1669 | elf32_arm_howto_from_type (unsigned int r_type) | |
1670 | { | |
c19d1205 ZW |
1671 | if (r_type < NUM_ELEM (elf32_arm_howto_table_1)) |
1672 | return &elf32_arm_howto_table_1[r_type]; | |
ba93b8ac | 1673 | |
c19d1205 ZW |
1674 | if (r_type >= R_ARM_RREL32 |
1675 | && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2)) | |
4962c51a | 1676 | return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32]; |
7f266840 | 1677 | |
c19d1205 | 1678 | return NULL; |
7f266840 DJ |
1679 | } |
1680 | ||
1681 | static void | |
1682 | elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, | |
1683 | Elf_Internal_Rela * elf_reloc) | |
1684 | { | |
1685 | unsigned int r_type; | |
1686 | ||
1687 | r_type = ELF32_R_TYPE (elf_reloc->r_info); | |
1688 | bfd_reloc->howto = elf32_arm_howto_from_type (r_type); | |
1689 | } | |
1690 | ||
1691 | struct elf32_arm_reloc_map | |
1692 | { | |
1693 | bfd_reloc_code_real_type bfd_reloc_val; | |
1694 | unsigned char elf_reloc_val; | |
1695 | }; | |
1696 | ||
1697 | /* All entries in this list must also be present in elf32_arm_howto_table. */ | |
1698 | static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = | |
1699 | { | |
1700 | {BFD_RELOC_NONE, R_ARM_NONE}, | |
1701 | {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24}, | |
39b41c9c PB |
1702 | {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL}, |
1703 | {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24}, | |
7f266840 DJ |
1704 | {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25}, |
1705 | {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22}, | |
1706 | {BFD_RELOC_32, R_ARM_ABS32}, | |
1707 | {BFD_RELOC_32_PCREL, R_ARM_REL32}, | |
1708 | {BFD_RELOC_8, R_ARM_ABS8}, | |
1709 | {BFD_RELOC_16, R_ARM_ABS16}, | |
1710 | {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12}, | |
1711 | {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5}, | |
c19d1205 ZW |
1712 | {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24}, |
1713 | {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL}, | |
1714 | {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11}, | |
1715 | {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19}, | |
1716 | {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8}, | |
1717 | {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6}, | |
7f266840 DJ |
1718 | {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT}, |
1719 | {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT}, | |
1720 | {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE}, | |
c19d1205 | 1721 | {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32}, |
7f266840 DJ |
1722 | {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC}, |
1723 | {BFD_RELOC_ARM_GOT32, R_ARM_GOT32}, | |
1724 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1725 | {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1}, | |
1726 | {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32}, | |
1727 | {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32}, | |
1728 | {BFD_RELOC_ARM_PREL31, R_ARM_PREL31}, | |
ba93b8ac DJ |
1729 | {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}, |
1730 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1731 | {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32}, | |
1732 | {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32}, | |
1733 | {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32}, | |
1734 | {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32}, | |
1735 | {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32}, | |
1736 | {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32}, | |
1737 | {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, | |
1738 | {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, | |
c19d1205 ZW |
1739 | {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT}, |
1740 | {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY}, | |
b6895b4f PB |
1741 | {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC}, |
1742 | {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS}, | |
1743 | {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC}, | |
1744 | {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL}, | |
1745 | {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC}, | |
1746 | {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS}, | |
1747 | {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC}, | |
1748 | {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL}, | |
4962c51a MS |
1749 | {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC}, |
1750 | {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0}, | |
1751 | {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC}, | |
1752 | {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1}, | |
1753 | {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2}, | |
1754 | {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0}, | |
1755 | {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1}, | |
1756 | {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2}, | |
1757 | {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0}, | |
1758 | {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1}, | |
1759 | {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2}, | |
1760 | {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0}, | |
1761 | {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1}, | |
1762 | {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2}, | |
1763 | {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC}, | |
1764 | {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0}, | |
1765 | {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC}, | |
1766 | {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1}, | |
1767 | {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2}, | |
1768 | {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0}, | |
1769 | {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1}, | |
1770 | {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2}, | |
1771 | {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0}, | |
1772 | {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1}, | |
1773 | {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2}, | |
1774 | {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0}, | |
1775 | {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1}, | |
1776 | {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2} | |
7f266840 DJ |
1777 | }; |
1778 | ||
1779 | static reloc_howto_type * | |
f1c71a59 ZW |
1780 | elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1781 | bfd_reloc_code_real_type code) | |
7f266840 DJ |
1782 | { |
1783 | unsigned int i; | |
c19d1205 ZW |
1784 | for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++) |
1785 | if (elf32_arm_reloc_map[i].bfd_reloc_val == code) | |
1786 | return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val); | |
7f266840 | 1787 | |
c19d1205 | 1788 | return NULL; |
7f266840 DJ |
1789 | } |
1790 | ||
1791 | /* Support for core dump NOTE sections */ | |
1792 | static bfd_boolean | |
f1c71a59 | 1793 | elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
7f266840 DJ |
1794 | { |
1795 | int offset; | |
1796 | size_t size; | |
1797 | ||
1798 | switch (note->descsz) | |
1799 | { | |
1800 | default: | |
1801 | return FALSE; | |
1802 | ||
1803 | case 148: /* Linux/ARM 32-bit*/ | |
1804 | /* pr_cursig */ | |
1805 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
1806 | ||
1807 | /* pr_pid */ | |
1808 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
1809 | ||
1810 | /* pr_reg */ | |
1811 | offset = 72; | |
1812 | size = 72; | |
1813 | ||
1814 | break; | |
1815 | } | |
1816 | ||
1817 | /* Make a ".reg/999" section. */ | |
1818 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1819 | size, note->descpos + offset); | |
1820 | } | |
1821 | ||
1822 | static bfd_boolean | |
f1c71a59 | 1823 | elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
7f266840 DJ |
1824 | { |
1825 | switch (note->descsz) | |
1826 | { | |
1827 | default: | |
1828 | return FALSE; | |
1829 | ||
1830 | case 124: /* Linux/ARM elf_prpsinfo */ | |
1831 | elf_tdata (abfd)->core_program | |
1832 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); | |
1833 | elf_tdata (abfd)->core_command | |
1834 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); | |
1835 | } | |
1836 | ||
1837 | /* Note that for some reason, a spurious space is tacked | |
1838 | onto the end of the args in some (at least one anyway) | |
1839 | implementations, so strip it off if it exists. */ | |
1840 | ||
1841 | { | |
1842 | char *command = elf_tdata (abfd)->core_command; | |
1843 | int n = strlen (command); | |
1844 | ||
1845 | if (0 < n && command[n - 1] == ' ') | |
1846 | command[n - 1] = '\0'; | |
1847 | } | |
1848 | ||
1849 | return TRUE; | |
1850 | } | |
1851 | ||
1852 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec | |
1853 | #define TARGET_LITTLE_NAME "elf32-littlearm" | |
1854 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vec | |
1855 | #define TARGET_BIG_NAME "elf32-bigarm" | |
1856 | ||
1857 | #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus | |
1858 | #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo | |
1859 | ||
252b5132 RH |
1860 | typedef unsigned long int insn32; |
1861 | typedef unsigned short int insn16; | |
1862 | ||
3a4a14e9 PB |
1863 | /* In lieu of proper flags, assume all EABIv4 or later objects are |
1864 | interworkable. */ | |
57e8b36a | 1865 | #define INTERWORK_FLAG(abfd) \ |
3a4a14e9 | 1866 | (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \ |
85a84e7a | 1867 | || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)) |
9b485d32 | 1868 | |
252b5132 RH |
1869 | /* The linker script knows the section names for placement. |
1870 | The entry_names are used to do simple name mangling on the stubs. | |
1871 | Given a function name, and its type, the stub can be found. The | |
9b485d32 | 1872 | name can be changed. The only requirement is the %s be present. */ |
252b5132 RH |
1873 | #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" |
1874 | #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" | |
1875 | ||
1876 | #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" | |
1877 | #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" | |
1878 | ||
1879 | /* The name of the dynamic interpreter. This is put in the .interp | |
1880 | section. */ | |
1881 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
1882 | ||
5e681ec4 PB |
1883 | #ifdef FOUR_WORD_PLT |
1884 | ||
252b5132 RH |
1885 | /* The first entry in a procedure linkage table looks like |
1886 | this. It is set up so that any shared library function that is | |
59f2c4e7 | 1887 | called before the relocation has been set up calls the dynamic |
9b485d32 | 1888 | linker first. */ |
e5a52504 | 1889 | static const bfd_vma elf32_arm_plt0_entry [] = |
5e681ec4 PB |
1890 | { |
1891 | 0xe52de004, /* str lr, [sp, #-4]! */ | |
1892 | 0xe59fe010, /* ldr lr, [pc, #16] */ | |
1893 | 0xe08fe00e, /* add lr, pc, lr */ | |
1894 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1895 | }; | |
1896 | ||
1897 | /* Subsequent entries in a procedure linkage table look like | |
1898 | this. */ | |
e5a52504 | 1899 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1900 | { |
1901 | 0xe28fc600, /* add ip, pc, #NN */ | |
1902 | 0xe28cca00, /* add ip, ip, #NN */ | |
1903 | 0xe5bcf000, /* ldr pc, [ip, #NN]! */ | |
1904 | 0x00000000, /* unused */ | |
1905 | }; | |
1906 | ||
1907 | #else | |
1908 | ||
5e681ec4 PB |
1909 | /* The first entry in a procedure linkage table looks like |
1910 | this. It is set up so that any shared library function that is | |
1911 | called before the relocation has been set up calls the dynamic | |
1912 | linker first. */ | |
e5a52504 | 1913 | static const bfd_vma elf32_arm_plt0_entry [] = |
917583ad | 1914 | { |
5e681ec4 PB |
1915 | 0xe52de004, /* str lr, [sp, #-4]! */ |
1916 | 0xe59fe004, /* ldr lr, [pc, #4] */ | |
1917 | 0xe08fe00e, /* add lr, pc, lr */ | |
1918 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1919 | 0x00000000, /* &GOT[0] - . */ | |
917583ad | 1920 | }; |
252b5132 RH |
1921 | |
1922 | /* Subsequent entries in a procedure linkage table look like | |
1923 | this. */ | |
e5a52504 | 1924 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1925 | { |
1926 | 0xe28fc600, /* add ip, pc, #0xNN00000 */ | |
1927 | 0xe28cca00, /* add ip, ip, #0xNN000 */ | |
1928 | 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ | |
1929 | }; | |
1930 | ||
1931 | #endif | |
252b5132 | 1932 | |
00a97672 RS |
1933 | /* The format of the first entry in the procedure linkage table |
1934 | for a VxWorks executable. */ | |
1935 | static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] = | |
1936 | { | |
1937 | 0xe52dc008, /* str ip,[sp,#-8]! */ | |
1938 | 0xe59fc000, /* ldr ip,[pc] */ | |
1939 | 0xe59cf008, /* ldr pc,[ip,#8] */ | |
1940 | 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */ | |
1941 | }; | |
1942 | ||
1943 | /* The format of subsequent entries in a VxWorks executable. */ | |
1944 | static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] = | |
1945 | { | |
1946 | 0xe59fc000, /* ldr ip,[pc] */ | |
1947 | 0xe59cf000, /* ldr pc,[ip] */ | |
1948 | 0x00000000, /* .long @got */ | |
1949 | 0xe59fc000, /* ldr ip,[pc] */ | |
1950 | 0xea000000, /* b _PLT */ | |
1951 | 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ | |
1952 | }; | |
1953 | ||
1954 | /* The format of entries in a VxWorks shared library. */ | |
1955 | static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] = | |
1956 | { | |
1957 | 0xe59fc000, /* ldr ip,[pc] */ | |
1958 | 0xe79cf009, /* ldr pc,[ip,r9] */ | |
1959 | 0x00000000, /* .long @got */ | |
1960 | 0xe59fc000, /* ldr ip,[pc] */ | |
1961 | 0xe599f008, /* ldr pc,[r9,#8] */ | |
1962 | 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ | |
1963 | }; | |
1964 | ||
b7693d02 DJ |
1965 | /* An initial stub used if the PLT entry is referenced from Thumb code. */ |
1966 | #define PLT_THUMB_STUB_SIZE 4 | |
1967 | static const bfd_vma elf32_arm_plt_thumb_stub [] = | |
1968 | { | |
1969 | 0x4778, /* bx pc */ | |
1970 | 0x46c0 /* nop */ | |
1971 | }; | |
1972 | ||
e5a52504 MM |
1973 | /* The entries in a PLT when using a DLL-based target with multiple |
1974 | address spaces. */ | |
1975 | static const bfd_vma elf32_arm_symbian_plt_entry [] = | |
1976 | { | |
83a358aa | 1977 | 0xe51ff004, /* ldr pc, [pc, #-4] */ |
e5a52504 MM |
1978 | 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ |
1979 | }; | |
1980 | ||
e489d0ae PB |
1981 | /* Used to build a map of a section. This is required for mixed-endian |
1982 | code/data. */ | |
1983 | ||
1984 | typedef struct elf32_elf_section_map | |
1985 | { | |
1986 | bfd_vma vma; | |
1987 | char type; | |
1988 | } | |
1989 | elf32_arm_section_map; | |
1990 | ||
8e3de13a | 1991 | typedef struct _arm_elf_section_data |
e489d0ae PB |
1992 | { |
1993 | struct bfd_elf_section_data elf; | |
8e3de13a | 1994 | unsigned int mapcount; |
e489d0ae | 1995 | elf32_arm_section_map *map; |
8e3de13a NC |
1996 | } |
1997 | _arm_elf_section_data; | |
e489d0ae PB |
1998 | |
1999 | #define elf32_arm_section_data(sec) \ | |
8e3de13a | 2000 | ((_arm_elf_section_data *) elf_section_data (sec)) |
e489d0ae | 2001 | |
ba93b8ac DJ |
2002 | /* The size of the thread control block. */ |
2003 | #define TCB_SIZE 8 | |
2004 | ||
ee065d83 PB |
2005 | #define NUM_KNOWN_ATTRIBUTES 32 |
2006 | ||
2007 | typedef struct aeabi_attribute | |
2008 | { | |
2009 | int type; | |
2010 | unsigned int i; | |
2011 | char *s; | |
2012 | } aeabi_attribute; | |
2013 | ||
2014 | typedef struct aeabi_attribute_list | |
2015 | { | |
2016 | struct aeabi_attribute_list *next; | |
2017 | int tag; | |
2018 | aeabi_attribute attr; | |
2019 | } aeabi_attribute_list; | |
2020 | ||
ba93b8ac DJ |
2021 | struct elf32_arm_obj_tdata |
2022 | { | |
2023 | struct elf_obj_tdata root; | |
2024 | ||
2025 | /* tls_type for each local got entry. */ | |
2026 | char *local_got_tls_type; | |
ee065d83 PB |
2027 | |
2028 | aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES]; | |
2029 | aeabi_attribute_list *other_eabi_attributes; | |
ba93b8ac DJ |
2030 | }; |
2031 | ||
2032 | #define elf32_arm_tdata(abfd) \ | |
2033 | ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any) | |
2034 | ||
2035 | #define elf32_arm_local_got_tls_type(abfd) \ | |
2036 | (elf32_arm_tdata (abfd)->local_got_tls_type) | |
2037 | ||
2038 | static bfd_boolean | |
2039 | elf32_arm_mkobject (bfd *abfd) | |
2040 | { | |
ba93b8ac | 2041 | if (abfd->tdata.any == NULL) |
62d7a5f6 AM |
2042 | { |
2043 | bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata); | |
2044 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2045 | if (abfd->tdata.any == NULL) | |
2046 | return FALSE; | |
2047 | } | |
2048 | return bfd_elf_mkobject (abfd); | |
ba93b8ac DJ |
2049 | } |
2050 | ||
252b5132 RH |
2051 | /* The ARM linker needs to keep track of the number of relocs that it |
2052 | decides to copy in check_relocs for each symbol. This is so that | |
2053 | it can discard PC relative relocs if it doesn't need them when | |
2054 | linking with -Bsymbolic. We store the information in a field | |
2055 | extending the regular ELF linker hash table. */ | |
2056 | ||
ba93b8ac DJ |
2057 | /* This structure keeps track of the number of relocs we have copied |
2058 | for a given symbol. */ | |
5e681ec4 | 2059 | struct elf32_arm_relocs_copied |
917583ad NC |
2060 | { |
2061 | /* Next section. */ | |
5e681ec4 | 2062 | struct elf32_arm_relocs_copied * next; |
917583ad NC |
2063 | /* A section in dynobj. */ |
2064 | asection * section; | |
2065 | /* Number of relocs copied in this section. */ | |
2066 | bfd_size_type count; | |
ba93b8ac DJ |
2067 | /* Number of PC-relative relocs copied in this section. */ |
2068 | bfd_size_type pc_count; | |
917583ad | 2069 | }; |
252b5132 | 2070 | |
ba93b8ac DJ |
2071 | #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent)) |
2072 | ||
ba96a88f | 2073 | /* Arm ELF linker hash entry. */ |
252b5132 | 2074 | struct elf32_arm_link_hash_entry |
917583ad NC |
2075 | { |
2076 | struct elf_link_hash_entry root; | |
252b5132 | 2077 | |
917583ad | 2078 | /* Number of PC relative relocs copied for this symbol. */ |
5e681ec4 | 2079 | struct elf32_arm_relocs_copied * relocs_copied; |
b7693d02 DJ |
2080 | |
2081 | /* We reference count Thumb references to a PLT entry separately, | |
2082 | so that we can emit the Thumb trampoline only if needed. */ | |
2083 | bfd_signed_vma plt_thumb_refcount; | |
2084 | ||
2085 | /* Since PLT entries have variable size if the Thumb prologue is | |
2086 | used, we need to record the index into .got.plt instead of | |
2087 | recomputing it from the PLT offset. */ | |
2088 | bfd_signed_vma plt_got_offset; | |
ba93b8ac DJ |
2089 | |
2090 | #define GOT_UNKNOWN 0 | |
2091 | #define GOT_NORMAL 1 | |
2092 | #define GOT_TLS_GD 2 | |
2093 | #define GOT_TLS_IE 4 | |
2094 | unsigned char tls_type; | |
a4fd1a8e PB |
2095 | |
2096 | /* The symbol marking the real symbol location for exported thumb | |
2097 | symbols with Arm stubs. */ | |
2098 | struct elf_link_hash_entry *export_glue; | |
917583ad | 2099 | }; |
252b5132 | 2100 | |
252b5132 | 2101 | /* Traverse an arm ELF linker hash table. */ |
252b5132 RH |
2102 | #define elf32_arm_link_hash_traverse(table, func, info) \ |
2103 | (elf_link_hash_traverse \ | |
2104 | (&(table)->root, \ | |
b7693d02 | 2105 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
252b5132 RH |
2106 | (info))) |
2107 | ||
2108 | /* Get the ARM elf linker hash table from a link_info structure. */ | |
2109 | #define elf32_arm_hash_table(info) \ | |
2110 | ((struct elf32_arm_link_hash_table *) ((info)->hash)) | |
2111 | ||
9b485d32 | 2112 | /* ARM ELF linker hash table. */ |
252b5132 | 2113 | struct elf32_arm_link_hash_table |
917583ad NC |
2114 | { |
2115 | /* The main hash table. */ | |
2116 | struct elf_link_hash_table root; | |
252b5132 | 2117 | |
4cc11e76 | 2118 | /* The size in bytes of the section containing the Thumb-to-ARM glue. */ |
dc810e39 | 2119 | bfd_size_type thumb_glue_size; |
252b5132 | 2120 | |
4cc11e76 | 2121 | /* The size in bytes of the section containing the ARM-to-Thumb glue. */ |
dc810e39 | 2122 | bfd_size_type arm_glue_size; |
252b5132 | 2123 | |
4cc11e76 | 2124 | /* An arbitrary input BFD chosen to hold the glue sections. */ |
917583ad | 2125 | bfd * bfd_of_glue_owner; |
ba96a88f | 2126 | |
e489d0ae PB |
2127 | /* Nonzero to output a BE8 image. */ |
2128 | int byteswap_code; | |
2129 | ||
9c504268 PB |
2130 | /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. |
2131 | Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */ | |
2132 | int target1_is_rel; | |
2133 | ||
eb043451 PB |
2134 | /* The relocation to use for R_ARM_TARGET2 relocations. */ |
2135 | int target2_reloc; | |
2136 | ||
319850b4 JB |
2137 | /* Nonzero to fix BX instructions for ARMv4 targets. */ |
2138 | int fix_v4bx; | |
2139 | ||
33bfe774 JB |
2140 | /* Nonzero if the ARM/Thumb BLX instructions are available for use. */ |
2141 | int use_blx; | |
2142 | ||
e5a52504 MM |
2143 | /* The number of bytes in the initial entry in the PLT. */ |
2144 | bfd_size_type plt_header_size; | |
2145 | ||
2146 | /* The number of bytes in the subsequent PLT etries. */ | |
2147 | bfd_size_type plt_entry_size; | |
2148 | ||
00a97672 RS |
2149 | /* True if the target system is VxWorks. */ |
2150 | int vxworks_p; | |
2151 | ||
e5a52504 MM |
2152 | /* True if the target system is Symbian OS. */ |
2153 | int symbian_p; | |
2154 | ||
4e7fd91e PB |
2155 | /* True if the target uses REL relocations. */ |
2156 | int use_rel; | |
2157 | ||
5e681ec4 PB |
2158 | /* Short-cuts to get to dynamic linker sections. */ |
2159 | asection *sgot; | |
2160 | asection *sgotplt; | |
2161 | asection *srelgot; | |
2162 | asection *splt; | |
2163 | asection *srelplt; | |
2164 | asection *sdynbss; | |
2165 | asection *srelbss; | |
2166 | ||
00a97672 RS |
2167 | /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */ |
2168 | asection *srelplt2; | |
2169 | ||
ba93b8ac DJ |
2170 | /* Data for R_ARM_TLS_LDM32 relocations. */ |
2171 | union { | |
2172 | bfd_signed_vma refcount; | |
2173 | bfd_vma offset; | |
2174 | } tls_ldm_got; | |
2175 | ||
5e681ec4 PB |
2176 | /* Small local sym to section mapping cache. */ |
2177 | struct sym_sec_cache sym_sec; | |
b7693d02 DJ |
2178 | |
2179 | /* For convenience in allocate_dynrelocs. */ | |
2180 | bfd * obfd; | |
917583ad | 2181 | }; |
252b5132 | 2182 | |
780a67af NC |
2183 | /* Create an entry in an ARM ELF linker hash table. */ |
2184 | ||
2185 | static struct bfd_hash_entry * | |
57e8b36a NC |
2186 | elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, |
2187 | struct bfd_hash_table * table, | |
2188 | const char * string) | |
780a67af NC |
2189 | { |
2190 | struct elf32_arm_link_hash_entry * ret = | |
2191 | (struct elf32_arm_link_hash_entry *) entry; | |
2192 | ||
2193 | /* Allocate the structure if it has not already been allocated by a | |
2194 | subclass. */ | |
2195 | if (ret == (struct elf32_arm_link_hash_entry *) NULL) | |
57e8b36a NC |
2196 | ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); |
2197 | if (ret == NULL) | |
780a67af NC |
2198 | return (struct bfd_hash_entry *) ret; |
2199 | ||
2200 | /* Call the allocation method of the superclass. */ | |
2201 | ret = ((struct elf32_arm_link_hash_entry *) | |
2202 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
2203 | table, string)); | |
57e8b36a | 2204 | if (ret != NULL) |
b7693d02 DJ |
2205 | { |
2206 | ret->relocs_copied = NULL; | |
ba93b8ac | 2207 | ret->tls_type = GOT_UNKNOWN; |
b7693d02 DJ |
2208 | ret->plt_thumb_refcount = 0; |
2209 | ret->plt_got_offset = -1; | |
a4fd1a8e | 2210 | ret->export_glue = NULL; |
b7693d02 | 2211 | } |
780a67af NC |
2212 | |
2213 | return (struct bfd_hash_entry *) ret; | |
2214 | } | |
2215 | ||
00a97672 RS |
2216 | /* Return true if NAME is the name of the relocation section associated |
2217 | with S. */ | |
2218 | ||
2219 | static bfd_boolean | |
2220 | reloc_section_p (struct elf32_arm_link_hash_table *htab, | |
2221 | const char *name, asection *s) | |
2222 | { | |
2223 | if (htab->use_rel) | |
2224 | return strncmp (name, ".rel", 4) == 0 && strcmp (s->name, name + 4) == 0; | |
2225 | else | |
2226 | return strncmp (name, ".rela", 5) == 0 && strcmp (s->name, name + 5) == 0; | |
2227 | } | |
2228 | ||
2229 | /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up | |
5e681ec4 PB |
2230 | shortcuts to them in our hash table. */ |
2231 | ||
2232 | static bfd_boolean | |
57e8b36a | 2233 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
2234 | { |
2235 | struct elf32_arm_link_hash_table *htab; | |
2236 | ||
e5a52504 MM |
2237 | htab = elf32_arm_hash_table (info); |
2238 | /* BPABI objects never have a GOT, or associated sections. */ | |
2239 | if (htab->symbian_p) | |
2240 | return TRUE; | |
2241 | ||
5e681ec4 PB |
2242 | if (! _bfd_elf_create_got_section (dynobj, info)) |
2243 | return FALSE; | |
2244 | ||
5e681ec4 PB |
2245 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
2246 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
2247 | if (!htab->sgot || !htab->sgotplt) | |
2248 | abort (); | |
2249 | ||
00a97672 RS |
2250 | htab->srelgot = bfd_make_section_with_flags (dynobj, |
2251 | RELOC_SECTION (htab, ".got"), | |
3496cb2a L |
2252 | (SEC_ALLOC | SEC_LOAD |
2253 | | SEC_HAS_CONTENTS | |
2254 | | SEC_IN_MEMORY | |
2255 | | SEC_LINKER_CREATED | |
2256 | | SEC_READONLY)); | |
5e681ec4 | 2257 | if (htab->srelgot == NULL |
5e681ec4 PB |
2258 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) |
2259 | return FALSE; | |
2260 | return TRUE; | |
2261 | } | |
2262 | ||
00a97672 RS |
2263 | /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and |
2264 | .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our | |
5e681ec4 PB |
2265 | hash table. */ |
2266 | ||
2267 | static bfd_boolean | |
57e8b36a | 2268 | elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
2269 | { |
2270 | struct elf32_arm_link_hash_table *htab; | |
2271 | ||
2272 | htab = elf32_arm_hash_table (info); | |
2273 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
2274 | return FALSE; | |
2275 | ||
2276 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
2277 | return FALSE; | |
2278 | ||
2279 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 RS |
2280 | htab->srelplt = bfd_get_section_by_name (dynobj, |
2281 | RELOC_SECTION (htab, ".plt")); | |
5e681ec4 PB |
2282 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
2283 | if (!info->shared) | |
00a97672 RS |
2284 | htab->srelbss = bfd_get_section_by_name (dynobj, |
2285 | RELOC_SECTION (htab, ".bss")); | |
2286 | ||
2287 | if (htab->vxworks_p) | |
2288 | { | |
2289 | if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2)) | |
2290 | return FALSE; | |
2291 | ||
2292 | if (info->shared) | |
2293 | { | |
2294 | htab->plt_header_size = 0; | |
2295 | htab->plt_entry_size | |
2296 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry); | |
2297 | } | |
2298 | else | |
2299 | { | |
2300 | htab->plt_header_size | |
2301 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry); | |
2302 | htab->plt_entry_size | |
2303 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry); | |
2304 | } | |
2305 | } | |
5e681ec4 | 2306 | |
e5a52504 MM |
2307 | if (!htab->splt |
2308 | || !htab->srelplt | |
2309 | || !htab->sdynbss | |
5e681ec4 PB |
2310 | || (!info->shared && !htab->srelbss)) |
2311 | abort (); | |
2312 | ||
2313 | return TRUE; | |
2314 | } | |
2315 | ||
2316 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
2317 | ||
2318 | static void | |
fcfa13d2 | 2319 | elf32_arm_copy_indirect_symbol (struct bfd_link_info *info, |
5e681ec4 PB |
2320 | struct elf_link_hash_entry *dir, |
2321 | struct elf_link_hash_entry *ind) | |
2322 | { | |
2323 | struct elf32_arm_link_hash_entry *edir, *eind; | |
2324 | ||
2325 | edir = (struct elf32_arm_link_hash_entry *) dir; | |
2326 | eind = (struct elf32_arm_link_hash_entry *) ind; | |
2327 | ||
2328 | if (eind->relocs_copied != NULL) | |
2329 | { | |
2330 | if (edir->relocs_copied != NULL) | |
2331 | { | |
2332 | struct elf32_arm_relocs_copied **pp; | |
2333 | struct elf32_arm_relocs_copied *p; | |
2334 | ||
fcfa13d2 | 2335 | /* Add reloc counts against the indirect sym to the direct sym |
5e681ec4 PB |
2336 | list. Merge any entries against the same section. */ |
2337 | for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) | |
2338 | { | |
2339 | struct elf32_arm_relocs_copied *q; | |
2340 | ||
2341 | for (q = edir->relocs_copied; q != NULL; q = q->next) | |
2342 | if (q->section == p->section) | |
2343 | { | |
ba93b8ac | 2344 | q->pc_count += p->pc_count; |
5e681ec4 PB |
2345 | q->count += p->count; |
2346 | *pp = p->next; | |
2347 | break; | |
2348 | } | |
2349 | if (q == NULL) | |
2350 | pp = &p->next; | |
2351 | } | |
2352 | *pp = edir->relocs_copied; | |
2353 | } | |
2354 | ||
2355 | edir->relocs_copied = eind->relocs_copied; | |
2356 | eind->relocs_copied = NULL; | |
2357 | } | |
2358 | ||
fcfa13d2 AM |
2359 | /* Copy over PLT info. */ |
2360 | edir->plt_thumb_refcount += eind->plt_thumb_refcount; | |
2361 | eind->plt_thumb_refcount = 0; | |
b7693d02 | 2362 | |
ba93b8ac DJ |
2363 | if (ind->root.type == bfd_link_hash_indirect |
2364 | && dir->got.refcount <= 0) | |
2365 | { | |
2366 | edir->tls_type = eind->tls_type; | |
2367 | eind->tls_type = GOT_UNKNOWN; | |
2368 | } | |
2369 | ||
fcfa13d2 | 2370 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
5e681ec4 PB |
2371 | } |
2372 | ||
9b485d32 | 2373 | /* Create an ARM elf linker hash table. */ |
252b5132 RH |
2374 | |
2375 | static struct bfd_link_hash_table * | |
57e8b36a | 2376 | elf32_arm_link_hash_table_create (bfd *abfd) |
252b5132 RH |
2377 | { |
2378 | struct elf32_arm_link_hash_table *ret; | |
dc810e39 | 2379 | bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); |
252b5132 | 2380 | |
57e8b36a NC |
2381 | ret = bfd_malloc (amt); |
2382 | if (ret == NULL) | |
252b5132 RH |
2383 | return NULL; |
2384 | ||
57e8b36a | 2385 | if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, |
66eb6687 AM |
2386 | elf32_arm_link_hash_newfunc, |
2387 | sizeof (struct elf32_arm_link_hash_entry))) | |
252b5132 | 2388 | { |
e2d34d7d | 2389 | free (ret); |
252b5132 RH |
2390 | return NULL; |
2391 | } | |
2392 | ||
5e681ec4 PB |
2393 | ret->sgot = NULL; |
2394 | ret->sgotplt = NULL; | |
2395 | ret->srelgot = NULL; | |
2396 | ret->splt = NULL; | |
2397 | ret->srelplt = NULL; | |
2398 | ret->sdynbss = NULL; | |
2399 | ret->srelbss = NULL; | |
00a97672 | 2400 | ret->srelplt2 = NULL; |
252b5132 RH |
2401 | ret->thumb_glue_size = 0; |
2402 | ret->arm_glue_size = 0; | |
2403 | ret->bfd_of_glue_owner = NULL; | |
e489d0ae | 2404 | ret->byteswap_code = 0; |
9c504268 | 2405 | ret->target1_is_rel = 0; |
eb043451 | 2406 | ret->target2_reloc = R_ARM_NONE; |
e5a52504 MM |
2407 | #ifdef FOUR_WORD_PLT |
2408 | ret->plt_header_size = 16; | |
2409 | ret->plt_entry_size = 16; | |
2410 | #else | |
2411 | ret->plt_header_size = 20; | |
2412 | ret->plt_entry_size = 12; | |
2413 | #endif | |
33bfe774 JB |
2414 | ret->fix_v4bx = 0; |
2415 | ret->use_blx = 0; | |
00a97672 | 2416 | ret->vxworks_p = 0; |
e5a52504 | 2417 | ret->symbian_p = 0; |
4e7fd91e | 2418 | ret->use_rel = 1; |
5e681ec4 | 2419 | ret->sym_sec.abfd = NULL; |
b7693d02 | 2420 | ret->obfd = abfd; |
ba93b8ac | 2421 | ret->tls_ldm_got.refcount = 0; |
252b5132 RH |
2422 | |
2423 | return &ret->root.root; | |
2424 | } | |
2425 | ||
9b485d32 NC |
2426 | /* Locate the Thumb encoded calling stub for NAME. */ |
2427 | ||
252b5132 | 2428 | static struct elf_link_hash_entry * |
57e8b36a NC |
2429 | find_thumb_glue (struct bfd_link_info *link_info, |
2430 | const char *name, | |
2431 | bfd *input_bfd) | |
252b5132 RH |
2432 | { |
2433 | char *tmp_name; | |
2434 | struct elf_link_hash_entry *hash; | |
2435 | struct elf32_arm_link_hash_table *hash_table; | |
2436 | ||
2437 | /* We need a pointer to the armelf specific hash table. */ | |
2438 | hash_table = elf32_arm_hash_table (link_info); | |
2439 | ||
57e8b36a NC |
2440 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2441 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2442 | |
2443 | BFD_ASSERT (tmp_name); | |
2444 | ||
2445 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2446 | ||
2447 | hash = elf_link_hash_lookup | |
b34976b6 | 2448 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2449 | |
2450 | if (hash == NULL) | |
2451 | /* xgettext:c-format */ | |
d003868e AM |
2452 | (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"), |
2453 | input_bfd, tmp_name, name); | |
252b5132 RH |
2454 | |
2455 | free (tmp_name); | |
2456 | ||
2457 | return hash; | |
2458 | } | |
2459 | ||
9b485d32 NC |
2460 | /* Locate the ARM encoded calling stub for NAME. */ |
2461 | ||
252b5132 | 2462 | static struct elf_link_hash_entry * |
57e8b36a NC |
2463 | find_arm_glue (struct bfd_link_info *link_info, |
2464 | const char *name, | |
2465 | bfd *input_bfd) | |
252b5132 RH |
2466 | { |
2467 | char *tmp_name; | |
2468 | struct elf_link_hash_entry *myh; | |
2469 | struct elf32_arm_link_hash_table *hash_table; | |
2470 | ||
2471 | /* We need a pointer to the elfarm specific hash table. */ | |
2472 | hash_table = elf32_arm_hash_table (link_info); | |
2473 | ||
57e8b36a NC |
2474 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2475 | + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2476 | |
2477 | BFD_ASSERT (tmp_name); | |
2478 | ||
2479 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2480 | ||
2481 | myh = elf_link_hash_lookup | |
b34976b6 | 2482 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2483 | |
2484 | if (myh == NULL) | |
2485 | /* xgettext:c-format */ | |
d003868e AM |
2486 | (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"), |
2487 | input_bfd, tmp_name, name); | |
252b5132 RH |
2488 | |
2489 | free (tmp_name); | |
2490 | ||
2491 | return myh; | |
2492 | } | |
2493 | ||
8f6277f5 | 2494 | /* ARM->Thumb glue (static images): |
252b5132 RH |
2495 | |
2496 | .arm | |
2497 | __func_from_arm: | |
2498 | ldr r12, __func_addr | |
2499 | bx r12 | |
2500 | __func_addr: | |
8f6277f5 | 2501 | .word func @ behave as if you saw a ARM_32 reloc. |
252b5132 | 2502 | |
8f6277f5 PB |
2503 | (relocatable images) |
2504 | .arm | |
2505 | __func_from_arm: | |
2506 | ldr r12, __func_offset | |
2507 | add r12, r12, pc | |
2508 | bx r12 | |
2509 | __func_offset: | |
2510 | .word func - . | |
2511 | */ | |
2512 | ||
2513 | #define ARM2THUMB_STATIC_GLUE_SIZE 12 | |
252b5132 RH |
2514 | static const insn32 a2t1_ldr_insn = 0xe59fc000; |
2515 | static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; | |
2516 | static const insn32 a2t3_func_addr_insn = 0x00000001; | |
2517 | ||
8f6277f5 PB |
2518 | #define ARM2THUMB_PIC_GLUE_SIZE 16 |
2519 | static const insn32 a2t1p_ldr_insn = 0xe59fc004; | |
2520 | static const insn32 a2t2p_add_pc_insn = 0xe08cc00f; | |
2521 | static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c; | |
2522 | ||
9b485d32 | 2523 | /* Thumb->ARM: Thumb->(non-interworking aware) ARM |
252b5132 RH |
2524 | |
2525 | .thumb .thumb | |
2526 | .align 2 .align 2 | |
2527 | __func_from_thumb: __func_from_thumb: | |
2528 | bx pc push {r6, lr} | |
2529 | nop ldr r6, __func_addr | |
2530 | .arm mov lr, pc | |
2531 | __func_change_to_arm: bx r6 | |
2532 | b func .arm | |
2533 | __func_back_to_thumb: | |
2534 | ldmia r13! {r6, lr} | |
2535 | bx lr | |
2536 | __func_addr: | |
9b485d32 | 2537 | .word func */ |
252b5132 RH |
2538 | |
2539 | #define THUMB2ARM_GLUE_SIZE 8 | |
2540 | static const insn16 t2a1_bx_pc_insn = 0x4778; | |
2541 | static const insn16 t2a2_noop_insn = 0x46c0; | |
2542 | static const insn32 t2a3_b_insn = 0xea000000; | |
2543 | ||
7e392df6 | 2544 | #ifndef ELFARM_NABI_C_INCLUDED |
b34976b6 | 2545 | bfd_boolean |
57e8b36a | 2546 | bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) |
252b5132 RH |
2547 | { |
2548 | asection * s; | |
2549 | bfd_byte * foo; | |
2550 | struct elf32_arm_link_hash_table * globals; | |
2551 | ||
2552 | globals = elf32_arm_hash_table (info); | |
2553 | ||
2554 | BFD_ASSERT (globals != NULL); | |
2555 | ||
2556 | if (globals->arm_glue_size != 0) | |
2557 | { | |
2558 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2559 | ||
dc810e39 AM |
2560 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
2561 | ARM2THUMB_GLUE_SECTION_NAME); | |
252b5132 RH |
2562 | |
2563 | BFD_ASSERT (s != NULL); | |
2564 | ||
57e8b36a | 2565 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); |
252b5132 | 2566 | |
eea6121a | 2567 | s->size = globals->arm_glue_size; |
252b5132 RH |
2568 | s->contents = foo; |
2569 | } | |
2570 | ||
2571 | if (globals->thumb_glue_size != 0) | |
2572 | { | |
2573 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2574 | ||
2575 | s = bfd_get_section_by_name | |
2576 | (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2577 | ||
2578 | BFD_ASSERT (s != NULL); | |
2579 | ||
57e8b36a | 2580 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); |
252b5132 | 2581 | |
eea6121a | 2582 | s->size = globals->thumb_glue_size; |
252b5132 RH |
2583 | s->contents = foo; |
2584 | } | |
2585 | ||
b34976b6 | 2586 | return TRUE; |
252b5132 RH |
2587 | } |
2588 | ||
a4fd1a8e PB |
2589 | /* Allocate space and symbols for calling a Thumb function from Arm mode. |
2590 | returns the symbol identifying teh stub. */ | |
2591 | static struct elf_link_hash_entry * | |
57e8b36a NC |
2592 | record_arm_to_thumb_glue (struct bfd_link_info * link_info, |
2593 | struct elf_link_hash_entry * h) | |
252b5132 RH |
2594 | { |
2595 | const char * name = h->root.root.string; | |
63b0f745 | 2596 | asection * s; |
252b5132 RH |
2597 | char * tmp_name; |
2598 | struct elf_link_hash_entry * myh; | |
14a793b2 | 2599 | struct bfd_link_hash_entry * bh; |
252b5132 | 2600 | struct elf32_arm_link_hash_table * globals; |
dc810e39 | 2601 | bfd_vma val; |
252b5132 RH |
2602 | |
2603 | globals = elf32_arm_hash_table (link_info); | |
2604 | ||
2605 | BFD_ASSERT (globals != NULL); | |
2606 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2607 | ||
2608 | s = bfd_get_section_by_name | |
2609 | (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); | |
2610 | ||
252b5132 RH |
2611 | BFD_ASSERT (s != NULL); |
2612 | ||
57e8b36a | 2613 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
252b5132 RH |
2614 | |
2615 | BFD_ASSERT (tmp_name); | |
2616 | ||
2617 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2618 | ||
2619 | myh = elf_link_hash_lookup | |
b34976b6 | 2620 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2621 | |
2622 | if (myh != NULL) | |
2623 | { | |
9b485d32 | 2624 | /* We've already seen this guy. */ |
252b5132 | 2625 | free (tmp_name); |
a4fd1a8e | 2626 | return myh; |
252b5132 RH |
2627 | } |
2628 | ||
57e8b36a NC |
2629 | /* The only trick here is using hash_table->arm_glue_size as the value. |
2630 | Even though the section isn't allocated yet, this is where we will be | |
2631 | putting it. */ | |
14a793b2 | 2632 | bh = NULL; |
dc810e39 AM |
2633 | val = globals->arm_glue_size + 1; |
2634 | _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, | |
2635 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2636 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2637 | |
b7693d02 DJ |
2638 | myh = (struct elf_link_hash_entry *) bh; |
2639 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
2640 | myh->forced_local = 1; | |
2641 | ||
252b5132 RH |
2642 | free (tmp_name); |
2643 | ||
8f6277f5 PB |
2644 | if ((link_info->shared || globals->root.is_relocatable_executable)) |
2645 | globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE; | |
2646 | else | |
2647 | globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE; | |
252b5132 | 2648 | |
a4fd1a8e | 2649 | return myh; |
252b5132 RH |
2650 | } |
2651 | ||
2652 | static void | |
57e8b36a NC |
2653 | record_thumb_to_arm_glue (struct bfd_link_info *link_info, |
2654 | struct elf_link_hash_entry *h) | |
252b5132 RH |
2655 | { |
2656 | const char *name = h->root.root.string; | |
63b0f745 | 2657 | asection *s; |
252b5132 RH |
2658 | char *tmp_name; |
2659 | struct elf_link_hash_entry *myh; | |
14a793b2 | 2660 | struct bfd_link_hash_entry *bh; |
252b5132 | 2661 | struct elf32_arm_link_hash_table *hash_table; |
dc810e39 | 2662 | bfd_vma val; |
252b5132 RH |
2663 | |
2664 | hash_table = elf32_arm_hash_table (link_info); | |
2665 | ||
2666 | BFD_ASSERT (hash_table != NULL); | |
2667 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); | |
2668 | ||
2669 | s = bfd_get_section_by_name | |
2670 | (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2671 | ||
2672 | BFD_ASSERT (s != NULL); | |
2673 | ||
57e8b36a NC |
2674 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2675 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2676 | |
2677 | BFD_ASSERT (tmp_name); | |
2678 | ||
2679 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2680 | ||
2681 | myh = elf_link_hash_lookup | |
b34976b6 | 2682 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2683 | |
2684 | if (myh != NULL) | |
2685 | { | |
9b485d32 | 2686 | /* We've already seen this guy. */ |
252b5132 | 2687 | free (tmp_name); |
9b485d32 | 2688 | return; |
252b5132 RH |
2689 | } |
2690 | ||
14a793b2 | 2691 | bh = NULL; |
dc810e39 AM |
2692 | val = hash_table->thumb_glue_size + 1; |
2693 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2694 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2695 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2696 | |
9b485d32 | 2697 | /* If we mark it 'Thumb', the disassembler will do a better job. */ |
14a793b2 | 2698 | myh = (struct elf_link_hash_entry *) bh; |
b7693d02 DJ |
2699 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); |
2700 | myh->forced_local = 1; | |
252b5132 RH |
2701 | |
2702 | free (tmp_name); | |
2703 | ||
252b5132 RH |
2704 | #define CHANGE_TO_ARM "__%s_change_to_arm" |
2705 | #define BACK_FROM_ARM "__%s_back_from_arm" | |
2706 | ||
9b485d32 | 2707 | /* Allocate another symbol to mark where we switch to Arm mode. */ |
57e8b36a NC |
2708 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2709 | + strlen (CHANGE_TO_ARM) + 1); | |
252b5132 RH |
2710 | |
2711 | BFD_ASSERT (tmp_name); | |
2712 | ||
2713 | sprintf (tmp_name, CHANGE_TO_ARM, name); | |
2714 | ||
14a793b2 | 2715 | bh = NULL; |
dc810e39 AM |
2716 | val = hash_table->thumb_glue_size + 4, |
2717 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2718 | tmp_name, BSF_LOCAL, s, val, | |
b34976b6 | 2719 | NULL, TRUE, FALSE, &bh); |
252b5132 RH |
2720 | |
2721 | free (tmp_name); | |
2722 | ||
2723 | hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; | |
2724 | ||
2725 | return; | |
2726 | } | |
2727 | ||
8afb0e02 NC |
2728 | /* Add the glue sections to ABFD. This function is called from the |
2729 | linker scripts in ld/emultempl/{armelf}.em. */ | |
9b485d32 | 2730 | |
b34976b6 | 2731 | bfd_boolean |
57e8b36a NC |
2732 | bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, |
2733 | struct bfd_link_info *info) | |
252b5132 | 2734 | { |
252b5132 RH |
2735 | flagword flags; |
2736 | asection *sec; | |
2737 | ||
8afb0e02 NC |
2738 | /* If we are only performing a partial |
2739 | link do not bother adding the glue. */ | |
1049f94e | 2740 | if (info->relocatable) |
b34976b6 | 2741 | return TRUE; |
252b5132 | 2742 | |
252b5132 RH |
2743 | sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
2744 | ||
2745 | if (sec == NULL) | |
2746 | { | |
57db232e NC |
2747 | /* Note: we do not include the flag SEC_LINKER_CREATED, as this |
2748 | will prevent elf_link_input_bfd() from processing the contents | |
2749 | of this section. */ | |
811b4bf6 | 2750 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY; |
252b5132 | 2751 | |
3496cb2a L |
2752 | sec = bfd_make_section_with_flags (abfd, |
2753 | ARM2THUMB_GLUE_SECTION_NAME, | |
2754 | flags); | |
252b5132 RH |
2755 | |
2756 | if (sec == NULL | |
252b5132 | 2757 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2758 | return FALSE; |
9a5aca8c | 2759 | |
57db232e NC |
2760 | /* Set the gc mark to prevent the section from being removed by garbage |
2761 | collection, despite the fact that no relocs refer to this section. */ | |
2762 | sec->gc_mark = 1; | |
252b5132 RH |
2763 | } |
2764 | ||
2765 | sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); | |
2766 | ||
2767 | if (sec == NULL) | |
2768 | { | |
57e8b36a NC |
2769 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
2770 | | SEC_CODE | SEC_READONLY; | |
252b5132 | 2771 | |
3496cb2a L |
2772 | sec = bfd_make_section_with_flags (abfd, |
2773 | THUMB2ARM_GLUE_SECTION_NAME, | |
2774 | flags); | |
252b5132 RH |
2775 | |
2776 | if (sec == NULL | |
252b5132 | 2777 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2778 | return FALSE; |
9a5aca8c | 2779 | |
57db232e | 2780 | sec->gc_mark = 1; |
252b5132 RH |
2781 | } |
2782 | ||
b34976b6 | 2783 | return TRUE; |
8afb0e02 NC |
2784 | } |
2785 | ||
2786 | /* Select a BFD to be used to hold the sections used by the glue code. | |
2787 | This function is called from the linker scripts in ld/emultempl/ | |
2788 | {armelf/pe}.em */ | |
2789 | ||
b34976b6 | 2790 | bfd_boolean |
57e8b36a | 2791 | bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) |
8afb0e02 NC |
2792 | { |
2793 | struct elf32_arm_link_hash_table *globals; | |
2794 | ||
2795 | /* If we are only performing a partial link | |
2796 | do not bother getting a bfd to hold the glue. */ | |
1049f94e | 2797 | if (info->relocatable) |
b34976b6 | 2798 | return TRUE; |
8afb0e02 | 2799 | |
b7693d02 DJ |
2800 | /* Make sure we don't attach the glue sections to a dynamic object. */ |
2801 | BFD_ASSERT (!(abfd->flags & DYNAMIC)); | |
2802 | ||
8afb0e02 NC |
2803 | globals = elf32_arm_hash_table (info); |
2804 | ||
2805 | BFD_ASSERT (globals != NULL); | |
2806 | ||
2807 | if (globals->bfd_of_glue_owner != NULL) | |
b34976b6 | 2808 | return TRUE; |
8afb0e02 | 2809 | |
252b5132 RH |
2810 | /* Save the bfd for later use. */ |
2811 | globals->bfd_of_glue_owner = abfd; | |
cedb70c5 | 2812 | |
b34976b6 | 2813 | return TRUE; |
252b5132 RH |
2814 | } |
2815 | ||
39b41c9c PB |
2816 | static void check_use_blx(struct elf32_arm_link_hash_table *globals) |
2817 | { | |
2818 | if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2) | |
2819 | globals->use_blx = 1; | |
2820 | } | |
2821 | ||
b34976b6 | 2822 | bfd_boolean |
57e8b36a NC |
2823 | bfd_elf32_arm_process_before_allocation (bfd *abfd, |
2824 | struct bfd_link_info *link_info, | |
eb043451 | 2825 | int byteswap_code) |
252b5132 RH |
2826 | { |
2827 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 2828 | Elf_Internal_Rela *internal_relocs = NULL; |
252b5132 RH |
2829 | Elf_Internal_Rela *irel, *irelend; |
2830 | bfd_byte *contents = NULL; | |
252b5132 RH |
2831 | |
2832 | asection *sec; | |
2833 | struct elf32_arm_link_hash_table *globals; | |
2834 | ||
2835 | /* If we are only performing a partial link do not bother | |
2836 | to construct any glue. */ | |
1049f94e | 2837 | if (link_info->relocatable) |
b34976b6 | 2838 | return TRUE; |
252b5132 RH |
2839 | |
2840 | /* Here we have a bfd that is to be included on the link. We have a hook | |
2841 | to do reloc rummaging, before section sizes are nailed down. */ | |
252b5132 | 2842 | globals = elf32_arm_hash_table (link_info); |
39b41c9c | 2843 | check_use_blx (globals); |
252b5132 RH |
2844 | |
2845 | BFD_ASSERT (globals != NULL); | |
2846 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2847 | ||
e489d0ae PB |
2848 | if (byteswap_code && !bfd_big_endian (abfd)) |
2849 | { | |
d003868e AM |
2850 | _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), |
2851 | abfd); | |
e489d0ae PB |
2852 | return FALSE; |
2853 | } | |
2854 | globals->byteswap_code = byteswap_code; | |
f21f3fe0 | 2855 | |
252b5132 RH |
2856 | /* Rummage around all the relocs and map the glue vectors. */ |
2857 | sec = abfd->sections; | |
2858 | ||
2859 | if (sec == NULL) | |
b34976b6 | 2860 | return TRUE; |
252b5132 RH |
2861 | |
2862 | for (; sec != NULL; sec = sec->next) | |
2863 | { | |
2864 | if (sec->reloc_count == 0) | |
2865 | continue; | |
2866 | ||
2867 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
252b5132 | 2868 | |
9b485d32 | 2869 | /* Load the relocs. */ |
6cdc0ccc | 2870 | internal_relocs |
57e8b36a | 2871 | = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, |
45d6a902 | 2872 | (Elf_Internal_Rela *) NULL, FALSE); |
252b5132 | 2873 | |
6cdc0ccc AM |
2874 | if (internal_relocs == NULL) |
2875 | goto error_return; | |
252b5132 | 2876 | |
6cdc0ccc AM |
2877 | irelend = internal_relocs + sec->reloc_count; |
2878 | for (irel = internal_relocs; irel < irelend; irel++) | |
252b5132 RH |
2879 | { |
2880 | long r_type; | |
2881 | unsigned long r_index; | |
252b5132 RH |
2882 | |
2883 | struct elf_link_hash_entry *h; | |
2884 | ||
2885 | r_type = ELF32_R_TYPE (irel->r_info); | |
2886 | r_index = ELF32_R_SYM (irel->r_info); | |
2887 | ||
9b485d32 | 2888 | /* These are the only relocation types we care about. */ |
ba96a88f | 2889 | if ( r_type != R_ARM_PC24 |
b7693d02 | 2890 | && r_type != R_ARM_PLT32 |
5b5bb741 PB |
2891 | && r_type != R_ARM_CALL |
2892 | && r_type != R_ARM_JUMP24 | |
c19d1205 | 2893 | && r_type != R_ARM_THM_CALL) |
252b5132 RH |
2894 | continue; |
2895 | ||
2896 | /* Get the section contents if we haven't done so already. */ | |
2897 | if (contents == NULL) | |
2898 | { | |
2899 | /* Get cached copy if it exists. */ | |
2900 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
2901 | contents = elf_section_data (sec)->this_hdr.contents; | |
2902 | else | |
2903 | { | |
2904 | /* Go get them off disk. */ | |
57e8b36a | 2905 | if (! bfd_malloc_and_get_section (abfd, sec, &contents)) |
252b5132 RH |
2906 | goto error_return; |
2907 | } | |
2908 | } | |
2909 | ||
a7c10850 | 2910 | /* If the relocation is not against a symbol it cannot concern us. */ |
252b5132 RH |
2911 | h = NULL; |
2912 | ||
9b485d32 | 2913 | /* We don't care about local symbols. */ |
252b5132 RH |
2914 | if (r_index < symtab_hdr->sh_info) |
2915 | continue; | |
2916 | ||
9b485d32 | 2917 | /* This is an external symbol. */ |
252b5132 RH |
2918 | r_index -= symtab_hdr->sh_info; |
2919 | h = (struct elf_link_hash_entry *) | |
2920 | elf_sym_hashes (abfd)[r_index]; | |
2921 | ||
2922 | /* If the relocation is against a static symbol it must be within | |
2923 | the current section and so cannot be a cross ARM/Thumb relocation. */ | |
2924 | if (h == NULL) | |
2925 | continue; | |
2926 | ||
b7693d02 DJ |
2927 | /* If the call will go through a PLT entry then we do not need |
2928 | glue. */ | |
2929 | if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1) | |
2930 | continue; | |
2931 | ||
252b5132 RH |
2932 | switch (r_type) |
2933 | { | |
2934 | case R_ARM_PC24: | |
c6596c5e | 2935 | case R_ARM_PLT32: |
5b5bb741 PB |
2936 | case R_ARM_CALL: |
2937 | case R_ARM_JUMP24: | |
252b5132 | 2938 | /* This one is a call from arm code. We need to look up |
2f0ca46a | 2939 | the target of the call. If it is a thumb target, we |
252b5132 | 2940 | insert glue. */ |
39b41c9c PB |
2941 | if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC |
2942 | && !(r_type == R_ARM_CALL && globals->use_blx)) | |
252b5132 RH |
2943 | record_arm_to_thumb_glue (link_info, h); |
2944 | break; | |
2945 | ||
c19d1205 | 2946 | case R_ARM_THM_CALL: |
f21f3fe0 | 2947 | /* This one is a call from thumb code. We look |
2f0ca46a | 2948 | up the target of the call. If it is not a thumb |
bcbdc74c | 2949 | target, we insert glue. */ |
39b41c9c | 2950 | if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx) |
252b5132 RH |
2951 | record_thumb_to_arm_glue (link_info, h); |
2952 | break; | |
2953 | ||
2954 | default: | |
c6596c5e | 2955 | abort (); |
252b5132 RH |
2956 | } |
2957 | } | |
6cdc0ccc AM |
2958 | |
2959 | if (contents != NULL | |
2960 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2961 | free (contents); | |
2962 | contents = NULL; | |
2963 | ||
2964 | if (internal_relocs != NULL | |
2965 | && elf_section_data (sec)->relocs != internal_relocs) | |
2966 | free (internal_relocs); | |
2967 | internal_relocs = NULL; | |
252b5132 RH |
2968 | } |
2969 | ||
b34976b6 | 2970 | return TRUE; |
9a5aca8c | 2971 | |
252b5132 | 2972 | error_return: |
6cdc0ccc AM |
2973 | if (contents != NULL |
2974 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2975 | free (contents); | |
2976 | if (internal_relocs != NULL | |
2977 | && elf_section_data (sec)->relocs != internal_relocs) | |
2978 | free (internal_relocs); | |
9a5aca8c | 2979 | |
b34976b6 | 2980 | return FALSE; |
252b5132 | 2981 | } |
7e392df6 | 2982 | #endif |
252b5132 | 2983 | |
eb043451 | 2984 | |
eb043451 PB |
2985 | /* Set target relocation values needed during linking. */ |
2986 | ||
2987 | void | |
2988 | bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info, | |
2989 | int target1_is_rel, | |
319850b4 | 2990 | char * target2_type, |
33bfe774 JB |
2991 | int fix_v4bx, |
2992 | int use_blx) | |
eb043451 PB |
2993 | { |
2994 | struct elf32_arm_link_hash_table *globals; | |
2995 | ||
2996 | globals = elf32_arm_hash_table (link_info); | |
2997 | ||
2998 | globals->target1_is_rel = target1_is_rel; | |
2999 | if (strcmp (target2_type, "rel") == 0) | |
3000 | globals->target2_reloc = R_ARM_REL32; | |
eeac373a PB |
3001 | else if (strcmp (target2_type, "abs") == 0) |
3002 | globals->target2_reloc = R_ARM_ABS32; | |
eb043451 PB |
3003 | else if (strcmp (target2_type, "got-rel") == 0) |
3004 | globals->target2_reloc = R_ARM_GOT_PREL; | |
3005 | else | |
3006 | { | |
3007 | _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."), | |
3008 | target2_type); | |
3009 | } | |
319850b4 | 3010 | globals->fix_v4bx = fix_v4bx; |
33bfe774 | 3011 | globals->use_blx |= use_blx; |
eb043451 | 3012 | } |
eb043451 | 3013 | |
252b5132 RH |
3014 | /* The thumb form of a long branch is a bit finicky, because the offset |
3015 | encoding is split over two fields, each in it's own instruction. They | |
f21f3fe0 | 3016 | can occur in any order. So given a thumb form of long branch, and an |
252b5132 | 3017 | offset, insert the offset into the thumb branch and return finished |
f21f3fe0 | 3018 | instruction. |
252b5132 | 3019 | |
f21f3fe0 | 3020 | It takes two thumb instructions to encode the target address. Each has |
4cc11e76 | 3021 | 11 bits to invest. The upper 11 bits are stored in one (identified by |
f21f3fe0 UD |
3022 | H-0.. see below), the lower 11 bits are stored in the other (identified |
3023 | by H-1). | |
252b5132 | 3024 | |
f21f3fe0 | 3025 | Combine together and shifted left by 1 (it's a half word address) and |
252b5132 RH |
3026 | there you have it. |
3027 | ||
3028 | Op: 1111 = F, | |
3029 | H-0, upper address-0 = 000 | |
3030 | Op: 1111 = F, | |
3031 | H-1, lower address-0 = 800 | |
3032 | ||
f21f3fe0 | 3033 | They can be ordered either way, but the arm tools I've seen always put |
252b5132 RH |
3034 | the lower one first. It probably doesn't matter. krk@cygnus.com |
3035 | ||
3036 | XXX: Actually the order does matter. The second instruction (H-1) | |
3037 | moves the computed address into the PC, so it must be the second one | |
3038 | in the sequence. The problem, however is that whilst little endian code | |
3039 | stores the instructions in HI then LOW order, big endian code does the | |
dfc5f959 | 3040 | reverse. nickc@cygnus.com. */ |
252b5132 | 3041 | |
dfc5f959 NC |
3042 | #define LOW_HI_ORDER 0xF800F000 |
3043 | #define HI_LOW_ORDER 0xF000F800 | |
252b5132 RH |
3044 | |
3045 | static insn32 | |
57e8b36a | 3046 | insert_thumb_branch (insn32 br_insn, int rel_off) |
252b5132 RH |
3047 | { |
3048 | unsigned int low_bits; | |
3049 | unsigned int high_bits; | |
3050 | ||
252b5132 RH |
3051 | BFD_ASSERT ((rel_off & 1) != 1); |
3052 | ||
dfc5f959 NC |
3053 | rel_off >>= 1; /* Half word aligned address. */ |
3054 | low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ | |
3055 | high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ | |
252b5132 RH |
3056 | |
3057 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) | |
3058 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; | |
3059 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) | |
3060 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; | |
3061 | else | |
9b485d32 | 3062 | /* FIXME: abort is probably not the right call. krk@cygnus.com */ |
57e8b36a | 3063 | abort (); /* Error - not a valid branch instruction form. */ |
252b5132 | 3064 | |
252b5132 RH |
3065 | return br_insn; |
3066 | } | |
3067 | ||
52ab56c2 PB |
3068 | |
3069 | /* Store an Arm insn into an output section not processed by | |
3070 | elf32_arm_write_section. */ | |
3071 | ||
3072 | static void | |
3073 | put_arm_insn (struct elf32_arm_link_hash_table *htab, | |
3074 | bfd * output_bfd, bfd_vma val, void * ptr) | |
3075 | { | |
3076 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
3077 | bfd_putl32 (val, ptr); | |
3078 | else | |
3079 | bfd_putb32 (val, ptr); | |
3080 | } | |
3081 | ||
3082 | ||
3083 | /* Store a 16-bit Thumb insn into an output section not processed by | |
3084 | elf32_arm_write_section. */ | |
3085 | ||
3086 | static void | |
3087 | put_thumb_insn (struct elf32_arm_link_hash_table *htab, | |
3088 | bfd * output_bfd, bfd_vma val, void * ptr) | |
3089 | { | |
3090 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
3091 | bfd_putl16 (val, ptr); | |
3092 | else | |
3093 | bfd_putb16 (val, ptr); | |
3094 | } | |
3095 | ||
3096 | ||
9b485d32 NC |
3097 | /* Thumb code calling an ARM function. */ |
3098 | ||
252b5132 | 3099 | static int |
57e8b36a NC |
3100 | elf32_thumb_to_arm_stub (struct bfd_link_info * info, |
3101 | const char * name, | |
3102 | bfd * input_bfd, | |
3103 | bfd * output_bfd, | |
3104 | asection * input_section, | |
3105 | bfd_byte * hit_data, | |
3106 | asection * sym_sec, | |
3107 | bfd_vma offset, | |
3108 | bfd_signed_vma addend, | |
3109 | bfd_vma val) | |
252b5132 | 3110 | { |
bcbdc74c | 3111 | asection * s = 0; |
dc810e39 | 3112 | bfd_vma my_offset; |
252b5132 RH |
3113 | unsigned long int tmp; |
3114 | long int ret_offset; | |
bcbdc74c NC |
3115 | struct elf_link_hash_entry * myh; |
3116 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
3117 | |
3118 | myh = find_thumb_glue (info, name, input_bfd); | |
3119 | if (myh == NULL) | |
b34976b6 | 3120 | return FALSE; |
252b5132 RH |
3121 | |
3122 | globals = elf32_arm_hash_table (info); | |
3123 | ||
3124 | BFD_ASSERT (globals != NULL); | |
3125 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
3126 | ||
3127 | my_offset = myh->root.u.def.value; | |
3128 | ||
3129 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
3130 | THUMB2ARM_GLUE_SECTION_NAME); | |
3131 | ||
3132 | BFD_ASSERT (s != NULL); | |
3133 | BFD_ASSERT (s->contents != NULL); | |
3134 | BFD_ASSERT (s->output_section != NULL); | |
3135 | ||
3136 | if ((my_offset & 0x01) == 0x01) | |
3137 | { | |
3138 | if (sym_sec != NULL | |
3139 | && sym_sec->owner != NULL | |
3140 | && !INTERWORK_FLAG (sym_sec->owner)) | |
3141 | { | |
8f615d07 | 3142 | (*_bfd_error_handler) |
d003868e AM |
3143 | (_("%B(%s): warning: interworking not enabled.\n" |
3144 | " first occurrence: %B: thumb call to arm"), | |
3145 | sym_sec->owner, input_bfd, name); | |
252b5132 | 3146 | |
b34976b6 | 3147 | return FALSE; |
252b5132 RH |
3148 | } |
3149 | ||
3150 | --my_offset; | |
3151 | myh->root.u.def.value = my_offset; | |
3152 | ||
52ab56c2 PB |
3153 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn, |
3154 | s->contents + my_offset); | |
252b5132 | 3155 | |
52ab56c2 PB |
3156 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn, |
3157 | s->contents + my_offset + 2); | |
252b5132 RH |
3158 | |
3159 | ret_offset = | |
9b485d32 NC |
3160 | /* Address of destination of the stub. */ |
3161 | ((bfd_signed_vma) val) | |
252b5132 | 3162 | - ((bfd_signed_vma) |
57e8b36a NC |
3163 | /* Offset from the start of the current section |
3164 | to the start of the stubs. */ | |
9b485d32 NC |
3165 | (s->output_offset |
3166 | /* Offset of the start of this stub from the start of the stubs. */ | |
3167 | + my_offset | |
3168 | /* Address of the start of the current section. */ | |
3169 | + s->output_section->vma) | |
3170 | /* The branch instruction is 4 bytes into the stub. */ | |
3171 | + 4 | |
3172 | /* ARM branches work from the pc of the instruction + 8. */ | |
3173 | + 8); | |
252b5132 | 3174 | |
52ab56c2 PB |
3175 | put_arm_insn (globals, output_bfd, |
3176 | (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), | |
3177 | s->contents + my_offset + 4); | |
252b5132 RH |
3178 | } |
3179 | ||
3180 | BFD_ASSERT (my_offset <= globals->thumb_glue_size); | |
3181 | ||
427bfd90 NC |
3182 | /* Now go back and fix up the original BL insn to point to here. */ |
3183 | ret_offset = | |
3184 | /* Address of where the stub is located. */ | |
3185 | (s->output_section->vma + s->output_offset + my_offset) | |
3186 | /* Address of where the BL is located. */ | |
57e8b36a NC |
3187 | - (input_section->output_section->vma + input_section->output_offset |
3188 | + offset) | |
427bfd90 NC |
3189 | /* Addend in the relocation. */ |
3190 | - addend | |
3191 | /* Biassing for PC-relative addressing. */ | |
3192 | - 8; | |
252b5132 RH |
3193 | |
3194 | tmp = bfd_get_32 (input_bfd, hit_data | |
3195 | - input_section->vma); | |
3196 | ||
3197 | bfd_put_32 (output_bfd, | |
dc810e39 | 3198 | (bfd_vma) insert_thumb_branch (tmp, ret_offset), |
252b5132 RH |
3199 | hit_data - input_section->vma); |
3200 | ||
b34976b6 | 3201 | return TRUE; |
252b5132 RH |
3202 | } |
3203 | ||
a4fd1a8e | 3204 | /* Populate an Arm to Thumb stub. Returns the stub symbol. */ |
9b485d32 | 3205 | |
a4fd1a8e PB |
3206 | static struct elf_link_hash_entry * |
3207 | elf32_arm_create_thumb_stub (struct bfd_link_info * info, | |
3208 | const char * name, | |
3209 | bfd * input_bfd, | |
3210 | bfd * output_bfd, | |
3211 | asection * sym_sec, | |
3212 | bfd_vma val, | |
3213 | asection *s) | |
252b5132 | 3214 | { |
dc810e39 | 3215 | bfd_vma my_offset; |
252b5132 | 3216 | long int ret_offset; |
bcbdc74c NC |
3217 | struct elf_link_hash_entry * myh; |
3218 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
3219 | |
3220 | myh = find_arm_glue (info, name, input_bfd); | |
3221 | if (myh == NULL) | |
a4fd1a8e | 3222 | return NULL; |
252b5132 RH |
3223 | |
3224 | globals = elf32_arm_hash_table (info); | |
3225 | ||
3226 | BFD_ASSERT (globals != NULL); | |
3227 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
3228 | ||
3229 | my_offset = myh->root.u.def.value; | |
252b5132 RH |
3230 | |
3231 | if ((my_offset & 0x01) == 0x01) | |
3232 | { | |
3233 | if (sym_sec != NULL | |
3234 | && sym_sec->owner != NULL | |
3235 | && !INTERWORK_FLAG (sym_sec->owner)) | |
3236 | { | |
8f615d07 | 3237 | (*_bfd_error_handler) |
d003868e AM |
3238 | (_("%B(%s): warning: interworking not enabled.\n" |
3239 | " first occurrence: %B: arm call to thumb"), | |
3240 | sym_sec->owner, input_bfd, name); | |
252b5132 | 3241 | } |
9b485d32 | 3242 | |
252b5132 RH |
3243 | --my_offset; |
3244 | myh->root.u.def.value = my_offset; | |
3245 | ||
8f6277f5 PB |
3246 | if ((info->shared || globals->root.is_relocatable_executable)) |
3247 | { | |
3248 | /* For relocatable objects we can't use absolute addresses, | |
3249 | so construct the address from a relative offset. */ | |
3250 | /* TODO: If the offset is small it's probably worth | |
3251 | constructing the address with adds. */ | |
52ab56c2 PB |
3252 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn, |
3253 | s->contents + my_offset); | |
3254 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn, | |
3255 | s->contents + my_offset + 4); | |
3256 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn, | |
3257 | s->contents + my_offset + 8); | |
8f6277f5 PB |
3258 | /* Adjust the offset by 4 for the position of the add, |
3259 | and 8 for the pipeline offset. */ | |
3260 | ret_offset = (val - (s->output_offset | |
3261 | + s->output_section->vma | |
3262 | + my_offset + 12)) | |
3263 | | 1; | |
3264 | bfd_put_32 (output_bfd, ret_offset, | |
3265 | s->contents + my_offset + 12); | |
3266 | } | |
3267 | else | |
3268 | { | |
52ab56c2 PB |
3269 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn, |
3270 | s->contents + my_offset); | |
252b5132 | 3271 | |
52ab56c2 PB |
3272 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn, |
3273 | s->contents + my_offset + 4); | |
252b5132 | 3274 | |
8f6277f5 PB |
3275 | /* It's a thumb address. Add the low order bit. */ |
3276 | bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, | |
3277 | s->contents + my_offset + 8); | |
3278 | } | |
252b5132 RH |
3279 | } |
3280 | ||
3281 | BFD_ASSERT (my_offset <= globals->arm_glue_size); | |
3282 | ||
a4fd1a8e PB |
3283 | return myh; |
3284 | } | |
3285 | ||
3286 | /* Arm code calling a Thumb function. */ | |
3287 | ||
3288 | static int | |
3289 | elf32_arm_to_thumb_stub (struct bfd_link_info * info, | |
3290 | const char * name, | |
3291 | bfd * input_bfd, | |
3292 | bfd * output_bfd, | |
3293 | asection * input_section, | |
3294 | bfd_byte * hit_data, | |
3295 | asection * sym_sec, | |
3296 | bfd_vma offset, | |
3297 | bfd_signed_vma addend, | |
3298 | bfd_vma val) | |
3299 | { | |
3300 | unsigned long int tmp; | |
3301 | bfd_vma my_offset; | |
3302 | asection * s; | |
3303 | long int ret_offset; | |
3304 | struct elf_link_hash_entry * myh; | |
3305 | struct elf32_arm_link_hash_table * globals; | |
3306 | ||
3307 | globals = elf32_arm_hash_table (info); | |
3308 | ||
3309 | BFD_ASSERT (globals != NULL); | |
3310 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
3311 | ||
3312 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
3313 | ARM2THUMB_GLUE_SECTION_NAME); | |
3314 | BFD_ASSERT (s != NULL); | |
3315 | BFD_ASSERT (s->contents != NULL); | |
3316 | BFD_ASSERT (s->output_section != NULL); | |
3317 | ||
3318 | myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd, | |
3319 | sym_sec, val, s); | |
3320 | if (!myh) | |
3321 | return FALSE; | |
3322 | ||
3323 | my_offset = myh->root.u.def.value; | |
252b5132 RH |
3324 | tmp = bfd_get_32 (input_bfd, hit_data); |
3325 | tmp = tmp & 0xFF000000; | |
3326 | ||
9b485d32 | 3327 | /* Somehow these are both 4 too far, so subtract 8. */ |
dc810e39 AM |
3328 | ret_offset = (s->output_offset |
3329 | + my_offset | |
3330 | + s->output_section->vma | |
3331 | - (input_section->output_offset | |
3332 | + input_section->output_section->vma | |
3333 | + offset + addend) | |
3334 | - 8); | |
9a5aca8c | 3335 | |
252b5132 RH |
3336 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); |
3337 | ||
dc810e39 | 3338 | bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); |
252b5132 | 3339 | |
b34976b6 | 3340 | return TRUE; |
252b5132 RH |
3341 | } |
3342 | ||
a4fd1a8e PB |
3343 | /* Populate Arm stub for an exported Thumb function. */ |
3344 | ||
3345 | static bfd_boolean | |
3346 | elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf) | |
3347 | { | |
3348 | struct bfd_link_info * info = (struct bfd_link_info *) inf; | |
3349 | asection * s; | |
3350 | struct elf_link_hash_entry * myh; | |
3351 | struct elf32_arm_link_hash_entry *eh; | |
3352 | struct elf32_arm_link_hash_table * globals; | |
3353 | asection *sec; | |
3354 | bfd_vma val; | |
3355 | ||
3356 | eh = elf32_arm_hash_entry(h); | |
3357 | /* Allocate stubs for exported Thumb functions on v4t. */ | |
3358 | if (eh->export_glue == NULL) | |
3359 | return TRUE; | |
3360 | ||
3361 | globals = elf32_arm_hash_table (info); | |
3362 | ||
3363 | BFD_ASSERT (globals != NULL); | |
3364 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
3365 | ||
3366 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
3367 | ARM2THUMB_GLUE_SECTION_NAME); | |
3368 | BFD_ASSERT (s != NULL); | |
3369 | BFD_ASSERT (s->contents != NULL); | |
3370 | BFD_ASSERT (s->output_section != NULL); | |
3371 | ||
3372 | sec = eh->export_glue->root.u.def.section; | |
3373 | val = eh->export_glue->root.u.def.value + sec->output_offset | |
3374 | + sec->output_section->vma; | |
3375 | myh = elf32_arm_create_thumb_stub (info, h->root.root.string, | |
3376 | h->root.u.def.section->owner, | |
3377 | globals->obfd, sec, val, s); | |
3378 | BFD_ASSERT (myh); | |
3379 | return TRUE; | |
3380 | } | |
3381 | ||
3382 | /* Generate Arm stubs for exported Thumb symbols. */ | |
3383 | static void | |
3384 | elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
3385 | struct bfd_link_info *link_info) | |
3386 | { | |
3387 | struct elf32_arm_link_hash_table * globals; | |
3388 | ||
3389 | if (!link_info) | |
3390 | return; | |
3391 | ||
3392 | globals = elf32_arm_hash_table (link_info); | |
3393 | if (globals->use_blx) | |
3394 | return; | |
3395 | ||
3396 | elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub, | |
3397 | link_info); | |
3398 | } | |
3399 | ||
eb043451 PB |
3400 | /* Some relocations map to different relocations depending on the |
3401 | target. Return the real relocation. */ | |
3402 | static int | |
3403 | arm_real_reloc_type (struct elf32_arm_link_hash_table * globals, | |
3404 | int r_type) | |
3405 | { | |
3406 | switch (r_type) | |
3407 | { | |
3408 | case R_ARM_TARGET1: | |
3409 | if (globals->target1_is_rel) | |
3410 | return R_ARM_REL32; | |
3411 | else | |
3412 | return R_ARM_ABS32; | |
3413 | ||
3414 | case R_ARM_TARGET2: | |
3415 | return globals->target2_reloc; | |
3416 | ||
3417 | default: | |
3418 | return r_type; | |
3419 | } | |
3420 | } | |
eb043451 | 3421 | |
ba93b8ac DJ |
3422 | /* Return the base VMA address which should be subtracted from real addresses |
3423 | when resolving @dtpoff relocation. | |
3424 | This is PT_TLS segment p_vaddr. */ | |
3425 | ||
3426 | static bfd_vma | |
3427 | dtpoff_base (struct bfd_link_info *info) | |
3428 | { | |
3429 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3430 | if (elf_hash_table (info)->tls_sec == NULL) | |
3431 | return 0; | |
3432 | return elf_hash_table (info)->tls_sec->vma; | |
3433 | } | |
3434 | ||
3435 | /* Return the relocation value for @tpoff relocation | |
3436 | if STT_TLS virtual address is ADDRESS. */ | |
3437 | ||
3438 | static bfd_vma | |
3439 | tpoff (struct bfd_link_info *info, bfd_vma address) | |
3440 | { | |
3441 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
3442 | bfd_vma base; | |
3443 | ||
3444 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3445 | if (htab->tls_sec == NULL) | |
3446 | return 0; | |
3447 | base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power); | |
3448 | return address - htab->tls_sec->vma + base; | |
3449 | } | |
3450 | ||
00a97672 RS |
3451 | /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA. |
3452 | VALUE is the relocation value. */ | |
3453 | ||
3454 | static bfd_reloc_status_type | |
3455 | elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value) | |
3456 | { | |
3457 | if (value > 0xfff) | |
3458 | return bfd_reloc_overflow; | |
3459 | ||
3460 | value |= bfd_get_32 (abfd, data) & 0xfffff000; | |
3461 | bfd_put_32 (abfd, value, data); | |
3462 | return bfd_reloc_ok; | |
3463 | } | |
3464 | ||
4962c51a MS |
3465 | /* For a given value of n, calculate the value of G_n as required to |
3466 | deal with group relocations. We return it in the form of an | |
3467 | encoded constant-and-rotation, together with the final residual. If n is | |
3468 | specified as less than zero, then final_residual is filled with the | |
3469 | input value and no further action is performed. */ | |
3470 | ||
3471 | static bfd_vma | |
3472 | calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual) | |
3473 | { | |
3474 | int current_n; | |
3475 | bfd_vma g_n; | |
3476 | bfd_vma encoded_g_n = 0; | |
3477 | bfd_vma residual = value; /* Also known as Y_n. */ | |
3478 | ||
3479 | for (current_n = 0; current_n <= n; current_n++) | |
3480 | { | |
3481 | int shift; | |
3482 | ||
3483 | /* Calculate which part of the value to mask. */ | |
3484 | if (residual == 0) | |
3485 | shift = 0; | |
3486 | else | |
3487 | { | |
3488 | int msb; | |
3489 | ||
3490 | /* Determine the most significant bit in the residual and | |
3491 | align the resulting value to a 2-bit boundary. */ | |
3492 | for (msb = 30; msb >= 0; msb -= 2) | |
3493 | if (residual & (3 << msb)) | |
3494 | break; | |
3495 | ||
3496 | /* The desired shift is now (msb - 6), or zero, whichever | |
3497 | is the greater. */ | |
3498 | shift = msb - 6; | |
3499 | if (shift < 0) | |
3500 | shift = 0; | |
3501 | } | |
3502 | ||
3503 | /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */ | |
3504 | g_n = residual & (0xff << shift); | |
3505 | encoded_g_n = (g_n >> shift) | |
3506 | | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8); | |
3507 | ||
3508 | /* Calculate the residual for the next time around. */ | |
3509 | residual &= ~g_n; | |
3510 | } | |
3511 | ||
3512 | *final_residual = residual; | |
3513 | ||
3514 | return encoded_g_n; | |
3515 | } | |
3516 | ||
3517 | /* Given an ARM instruction, determine whether it is an ADD or a SUB. | |
3518 | Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */ | |
3519 | static int | |
3520 | identify_add_or_sub(bfd_vma insn) | |
3521 | { | |
3522 | int opcode = insn & 0x1e00000; | |
3523 | ||
3524 | if (opcode == 1 << 23) /* ADD */ | |
3525 | return 1; | |
3526 | ||
3527 | if (opcode == 1 << 22) /* SUB */ | |
3528 | return -1; | |
3529 | ||
3530 | return 0; | |
3531 | } | |
3532 | ||
252b5132 | 3533 | /* Perform a relocation as part of a final link. */ |
9b485d32 | 3534 | |
252b5132 | 3535 | static bfd_reloc_status_type |
57e8b36a NC |
3536 | elf32_arm_final_link_relocate (reloc_howto_type * howto, |
3537 | bfd * input_bfd, | |
3538 | bfd * output_bfd, | |
3539 | asection * input_section, | |
3540 | bfd_byte * contents, | |
3541 | Elf_Internal_Rela * rel, | |
3542 | bfd_vma value, | |
3543 | struct bfd_link_info * info, | |
3544 | asection * sym_sec, | |
3545 | const char * sym_name, | |
3546 | int sym_flags, | |
0945cdfd DJ |
3547 | struct elf_link_hash_entry * h, |
3548 | bfd_boolean * unresolved_reloc_p) | |
252b5132 RH |
3549 | { |
3550 | unsigned long r_type = howto->type; | |
3551 | unsigned long r_symndx; | |
3552 | bfd_byte * hit_data = contents + rel->r_offset; | |
3553 | bfd * dynobj = NULL; | |
3554 | Elf_Internal_Shdr * symtab_hdr; | |
3555 | struct elf_link_hash_entry ** sym_hashes; | |
3556 | bfd_vma * local_got_offsets; | |
3557 | asection * sgot = NULL; | |
3558 | asection * splt = NULL; | |
3559 | asection * sreloc = NULL; | |
252b5132 | 3560 | bfd_vma addend; |
ba96a88f NC |
3561 | bfd_signed_vma signed_addend; |
3562 | struct elf32_arm_link_hash_table * globals; | |
f21f3fe0 | 3563 | |
9c504268 PB |
3564 | globals = elf32_arm_hash_table (info); |
3565 | ||
9c504268 PB |
3566 | /* Some relocation type map to different relocations depending on the |
3567 | target. We pick the right one here. */ | |
eb043451 PB |
3568 | r_type = arm_real_reloc_type (globals, r_type); |
3569 | if (r_type != howto->type) | |
3570 | howto = elf32_arm_howto_from_type (r_type); | |
9c504268 | 3571 | |
cac15327 NC |
3572 | /* If the start address has been set, then set the EF_ARM_HASENTRY |
3573 | flag. Setting this more than once is redundant, but the cost is | |
3574 | not too high, and it keeps the code simple. | |
99e4ae17 | 3575 | |
cac15327 NC |
3576 | The test is done here, rather than somewhere else, because the |
3577 | start address is only set just before the final link commences. | |
3578 | ||
3579 | Note - if the user deliberately sets a start address of 0, the | |
3580 | flag will not be set. */ | |
3581 | if (bfd_get_start_address (output_bfd) != 0) | |
3582 | elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; | |
99e4ae17 | 3583 | |
252b5132 RH |
3584 | dynobj = elf_hash_table (info)->dynobj; |
3585 | if (dynobj) | |
3586 | { | |
3587 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
3588 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
3589 | } | |
3590 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
3591 | sym_hashes = elf_sym_hashes (input_bfd); | |
3592 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
3593 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3594 | ||
4e7fd91e | 3595 | if (globals->use_rel) |
ba96a88f | 3596 | { |
4e7fd91e PB |
3597 | addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; |
3598 | ||
3599 | if (addend & ((howto->src_mask + 1) >> 1)) | |
3600 | { | |
3601 | signed_addend = -1; | |
3602 | signed_addend &= ~ howto->src_mask; | |
3603 | signed_addend |= addend; | |
3604 | } | |
3605 | else | |
3606 | signed_addend = addend; | |
ba96a88f NC |
3607 | } |
3608 | else | |
4e7fd91e | 3609 | addend = signed_addend = rel->r_addend; |
f21f3fe0 | 3610 | |
252b5132 RH |
3611 | switch (r_type) |
3612 | { | |
3613 | case R_ARM_NONE: | |
28a094c2 DJ |
3614 | /* We don't need to find a value for this symbol. It's just a |
3615 | marker. */ | |
3616 | *unresolved_reloc_p = FALSE; | |
252b5132 RH |
3617 | return bfd_reloc_ok; |
3618 | ||
00a97672 RS |
3619 | case R_ARM_ABS12: |
3620 | if (!globals->vxworks_p) | |
3621 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
3622 | ||
252b5132 RH |
3623 | case R_ARM_PC24: |
3624 | case R_ARM_ABS32: | |
3625 | case R_ARM_REL32: | |
5b5bb741 PB |
3626 | case R_ARM_CALL: |
3627 | case R_ARM_JUMP24: | |
dfc5f959 | 3628 | case R_ARM_XPC25: |
eb043451 | 3629 | case R_ARM_PREL31: |
7359ea65 | 3630 | case R_ARM_PLT32: |
5e681ec4 PB |
3631 | /* r_symndx will be zero only for relocs against symbols |
3632 | from removed linkonce sections, or sections discarded by | |
3633 | a linker script. */ | |
3634 | if (r_symndx == 0) | |
3635 | return bfd_reloc_ok; | |
3636 | ||
7359ea65 DJ |
3637 | /* Handle relocations which should use the PLT entry. ABS32/REL32 |
3638 | will use the symbol's value, which may point to a PLT entry, but we | |
3639 | don't need to handle that here. If we created a PLT entry, all | |
3640 | branches in this object should go to it. */ | |
ee06dc07 | 3641 | if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
7359ea65 | 3642 | && h != NULL |
c84cd8ee | 3643 | && splt != NULL |
7359ea65 DJ |
3644 | && h->plt.offset != (bfd_vma) -1) |
3645 | { | |
c84cd8ee DJ |
3646 | /* If we've created a .plt section, and assigned a PLT entry to |
3647 | this function, it should not be known to bind locally. If | |
3648 | it were, we would have cleared the PLT entry. */ | |
7359ea65 DJ |
3649 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); |
3650 | ||
3651 | value = (splt->output_section->vma | |
3652 | + splt->output_offset | |
3653 | + h->plt.offset); | |
0945cdfd | 3654 | *unresolved_reloc_p = FALSE; |
7359ea65 DJ |
3655 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
3656 | contents, rel->r_offset, value, | |
00a97672 | 3657 | rel->r_addend); |
7359ea65 DJ |
3658 | } |
3659 | ||
67687978 PB |
3660 | /* When generating a shared object or relocatable executable, these |
3661 | relocations are copied into the output file to be resolved at | |
3662 | run time. */ | |
3663 | if ((info->shared || globals->root.is_relocatable_executable) | |
7359ea65 | 3664 | && (input_section->flags & SEC_ALLOC) |
ee06dc07 PB |
3665 | && (r_type != R_ARM_REL32 |
3666 | || !SYMBOL_CALLS_LOCAL (info, h)) | |
7359ea65 DJ |
3667 | && (h == NULL |
3668 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
3669 | || h->root.type != bfd_link_hash_undefweak) | |
3670 | && r_type != R_ARM_PC24 | |
5b5bb741 PB |
3671 | && r_type != R_ARM_CALL |
3672 | && r_type != R_ARM_JUMP24 | |
ee06dc07 | 3673 | && r_type != R_ARM_PREL31 |
7359ea65 | 3674 | && r_type != R_ARM_PLT32) |
252b5132 | 3675 | { |
947216bf AM |
3676 | Elf_Internal_Rela outrel; |
3677 | bfd_byte *loc; | |
b34976b6 | 3678 | bfd_boolean skip, relocate; |
f21f3fe0 | 3679 | |
0945cdfd DJ |
3680 | *unresolved_reloc_p = FALSE; |
3681 | ||
252b5132 RH |
3682 | if (sreloc == NULL) |
3683 | { | |
3684 | const char * name; | |
f21f3fe0 | 3685 | |
252b5132 RH |
3686 | name = (bfd_elf_string_from_elf_section |
3687 | (input_bfd, | |
3688 | elf_elfheader (input_bfd)->e_shstrndx, | |
3689 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
3690 | if (name == NULL) | |
3691 | return bfd_reloc_notsupported; | |
f21f3fe0 | 3692 | |
00a97672 | 3693 | BFD_ASSERT (reloc_section_p (globals, name, input_section)); |
f21f3fe0 | 3694 | |
252b5132 RH |
3695 | sreloc = bfd_get_section_by_name (dynobj, name); |
3696 | BFD_ASSERT (sreloc != NULL); | |
3697 | } | |
f21f3fe0 | 3698 | |
b34976b6 AM |
3699 | skip = FALSE; |
3700 | relocate = FALSE; | |
f21f3fe0 | 3701 | |
00a97672 | 3702 | outrel.r_addend = addend; |
c629eae0 JJ |
3703 | outrel.r_offset = |
3704 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
3705 | rel->r_offset); | |
3706 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 3707 | skip = TRUE; |
0bb2d96a | 3708 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 3709 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
3710 | outrel.r_offset += (input_section->output_section->vma |
3711 | + input_section->output_offset); | |
f21f3fe0 | 3712 | |
252b5132 | 3713 | if (skip) |
0bb2d96a | 3714 | memset (&outrel, 0, sizeof outrel); |
5e681ec4 PB |
3715 | else if (h != NULL |
3716 | && h->dynindx != -1 | |
7359ea65 | 3717 | && (!info->shared |
5e681ec4 | 3718 | || !info->symbolic |
f5385ebf | 3719 | || !h->def_regular)) |
5e681ec4 | 3720 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
252b5132 RH |
3721 | else |
3722 | { | |
a16385dc MM |
3723 | int symbol; |
3724 | ||
5e681ec4 | 3725 | /* This symbol is local, or marked to become local. */ |
b7693d02 DJ |
3726 | if (sym_flags == STT_ARM_TFUNC) |
3727 | value |= 1; | |
a16385dc | 3728 | if (globals->symbian_p) |
6366ff1e MM |
3729 | { |
3730 | /* On Symbian OS, the data segment and text segement | |
3731 | can be relocated independently. Therefore, we | |
3732 | must indicate the segment to which this | |
3733 | relocation is relative. The BPABI allows us to | |
3734 | use any symbol in the right segment; we just use | |
3735 | the section symbol as it is convenient. (We | |
3736 | cannot use the symbol given by "h" directly as it | |
3737 | will not appear in the dynamic symbol table.) */ | |
10dbd1f3 NC |
3738 | if (sym_sec) |
3739 | symbol = elf_section_data (sym_sec->output_section)->dynindx; | |
3740 | else | |
3741 | symbol = elf_section_data (input_section->output_section)->dynindx; | |
6366ff1e MM |
3742 | BFD_ASSERT (symbol != 0); |
3743 | } | |
a16385dc MM |
3744 | else |
3745 | /* On SVR4-ish systems, the dynamic loader cannot | |
3746 | relocate the text and data segments independently, | |
3747 | so the symbol does not matter. */ | |
3748 | symbol = 0; | |
3749 | outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE); | |
00a97672 RS |
3750 | if (globals->use_rel) |
3751 | relocate = TRUE; | |
3752 | else | |
3753 | outrel.r_addend += value; | |
252b5132 | 3754 | } |
f21f3fe0 | 3755 | |
947216bf | 3756 | loc = sreloc->contents; |
00a97672 RS |
3757 | loc += sreloc->reloc_count++ * RELOC_SIZE (globals); |
3758 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
9a5aca8c | 3759 | |
f21f3fe0 | 3760 | /* If this reloc is against an external symbol, we do not want to |
252b5132 | 3761 | fiddle with the addend. Otherwise, we need to include the symbol |
9b485d32 | 3762 | value so that it becomes an addend for the dynamic reloc. */ |
252b5132 RH |
3763 | if (! relocate) |
3764 | return bfd_reloc_ok; | |
9a5aca8c | 3765 | |
f21f3fe0 | 3766 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
252b5132 RH |
3767 | contents, rel->r_offset, value, |
3768 | (bfd_vma) 0); | |
3769 | } | |
3770 | else switch (r_type) | |
3771 | { | |
00a97672 RS |
3772 | case R_ARM_ABS12: |
3773 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
3774 | ||
dfc5f959 | 3775 | case R_ARM_XPC25: /* Arm BLX instruction. */ |
5b5bb741 PB |
3776 | case R_ARM_CALL: |
3777 | case R_ARM_JUMP24: | |
dfc5f959 | 3778 | case R_ARM_PC24: /* Arm B/BL instruction */ |
7359ea65 | 3779 | case R_ARM_PLT32: |
dfc5f959 | 3780 | if (r_type == R_ARM_XPC25) |
252b5132 | 3781 | { |
dfc5f959 NC |
3782 | /* Check for Arm calling Arm function. */ |
3783 | /* FIXME: Should we translate the instruction into a BL | |
3784 | instruction instead ? */ | |
3785 | if (sym_flags != STT_ARM_TFUNC) | |
d003868e AM |
3786 | (*_bfd_error_handler) |
3787 | (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), | |
3788 | input_bfd, | |
3789 | h ? h->root.root.string : "(local)"); | |
dfc5f959 | 3790 | } |
39b41c9c | 3791 | else if (r_type != R_ARM_CALL || !globals->use_blx) |
dfc5f959 NC |
3792 | { |
3793 | /* Check for Arm calling Thumb function. */ | |
3794 | if (sym_flags == STT_ARM_TFUNC) | |
3795 | { | |
57e8b36a NC |
3796 | elf32_arm_to_thumb_stub (info, sym_name, input_bfd, |
3797 | output_bfd, input_section, | |
3798 | hit_data, sym_sec, rel->r_offset, | |
dfc5f959 NC |
3799 | signed_addend, value); |
3800 | return bfd_reloc_ok; | |
3801 | } | |
252b5132 | 3802 | } |
ba96a88f | 3803 | |
dea514f5 PB |
3804 | /* The ARM ELF ABI says that this reloc is computed as: S - P + A |
3805 | where: | |
3806 | S is the address of the symbol in the relocation. | |
3807 | P is address of the instruction being relocated. | |
3808 | A is the addend (extracted from the instruction) in bytes. | |
3809 | ||
3810 | S is held in 'value'. | |
3811 | P is the base address of the section containing the | |
3812 | instruction plus the offset of the reloc into that | |
3813 | section, ie: | |
3814 | (input_section->output_section->vma + | |
3815 | input_section->output_offset + | |
3816 | rel->r_offset). | |
3817 | A is the addend, converted into bytes, ie: | |
3818 | (signed_addend * 4) | |
3819 | ||
3820 | Note: None of these operations have knowledge of the pipeline | |
3821 | size of the processor, thus it is up to the assembler to | |
3822 | encode this information into the addend. */ | |
3823 | value -= (input_section->output_section->vma | |
3824 | + input_section->output_offset); | |
3825 | value -= rel->r_offset; | |
4e7fd91e PB |
3826 | if (globals->use_rel) |
3827 | value += (signed_addend << howto->size); | |
3828 | else | |
3829 | /* RELA addends do not have to be adjusted by howto->size. */ | |
3830 | value += signed_addend; | |
23080146 | 3831 | |
dcb5e6e6 NC |
3832 | signed_addend = value; |
3833 | signed_addend >>= howto->rightshift; | |
9a5aca8c | 3834 | |
59f2c4e7 NC |
3835 | /* It is not an error for an undefined weak reference to be |
3836 | out of range. Any program that branches to such a symbol | |
9a5aca8c AM |
3837 | is going to crash anyway, so there is no point worrying |
3838 | about getting the destination exactly right. */ | |
59f2c4e7 NC |
3839 | if (! h || h->root.type != bfd_link_hash_undefweak) |
3840 | { | |
9b485d32 | 3841 | /* Perform a signed range check. */ |
dcb5e6e6 | 3842 | if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) |
59f2c4e7 NC |
3843 | || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) |
3844 | return bfd_reloc_overflow; | |
3845 | } | |
9a5aca8c | 3846 | |
39b41c9c PB |
3847 | addend = (value & 2); |
3848 | ||
3849 | value = (signed_addend & howto->dst_mask) | |
3850 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); | |
3851 | ||
3852 | /* Set the H bit in the BLX instruction. */ | |
3853 | if (sym_flags == STT_ARM_TFUNC) | |
3854 | { | |
3855 | if (addend) | |
3856 | value |= (1 << 24); | |
3857 | else | |
3858 | value &= ~(bfd_vma)(1 << 24); | |
3859 | } | |
3860 | if (r_type == R_ARM_CALL) | |
3861 | { | |
3862 | /* Select the correct instruction (BL or BLX). */ | |
3863 | if (sym_flags == STT_ARM_TFUNC) | |
3864 | value |= (1 << 28); | |
3865 | else | |
3866 | { | |
3867 | value &= ~(bfd_vma)(1 << 28); | |
3868 | value |= (1 << 24); | |
3869 | } | |
3870 | } | |
252b5132 | 3871 | break; |
f21f3fe0 | 3872 | |
252b5132 RH |
3873 | case R_ARM_ABS32: |
3874 | value += addend; | |
3875 | if (sym_flags == STT_ARM_TFUNC) | |
3876 | value |= 1; | |
3877 | break; | |
f21f3fe0 | 3878 | |
252b5132 | 3879 | case R_ARM_REL32: |
a8bc6c78 PB |
3880 | value += addend; |
3881 | if (sym_flags == STT_ARM_TFUNC) | |
3882 | value |= 1; | |
252b5132 | 3883 | value -= (input_section->output_section->vma |
62efb346 | 3884 | + input_section->output_offset + rel->r_offset); |
252b5132 | 3885 | break; |
eb043451 | 3886 | |
eb043451 PB |
3887 | case R_ARM_PREL31: |
3888 | value -= (input_section->output_section->vma | |
3889 | + input_section->output_offset + rel->r_offset); | |
3890 | value += signed_addend; | |
3891 | if (! h || h->root.type != bfd_link_hash_undefweak) | |
3892 | { | |
3893 | /* Check for overflow */ | |
3894 | if ((value ^ (value >> 1)) & (1 << 30)) | |
3895 | return bfd_reloc_overflow; | |
3896 | } | |
3897 | value &= 0x7fffffff; | |
3898 | value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000); | |
3899 | if (sym_flags == STT_ARM_TFUNC) | |
3900 | value |= 1; | |
3901 | break; | |
252b5132 | 3902 | } |
f21f3fe0 | 3903 | |
252b5132 RH |
3904 | bfd_put_32 (input_bfd, value, hit_data); |
3905 | return bfd_reloc_ok; | |
3906 | ||
3907 | case R_ARM_ABS8: | |
3908 | value += addend; | |
3909 | if ((long) value > 0x7f || (long) value < -0x80) | |
3910 | return bfd_reloc_overflow; | |
3911 | ||
3912 | bfd_put_8 (input_bfd, value, hit_data); | |
3913 | return bfd_reloc_ok; | |
3914 | ||
3915 | case R_ARM_ABS16: | |
3916 | value += addend; | |
3917 | ||
3918 | if ((long) value > 0x7fff || (long) value < -0x8000) | |
3919 | return bfd_reloc_overflow; | |
3920 | ||
3921 | bfd_put_16 (input_bfd, value, hit_data); | |
3922 | return bfd_reloc_ok; | |
3923 | ||
252b5132 | 3924 | case R_ARM_THM_ABS5: |
9b485d32 | 3925 | /* Support ldr and str instructions for the thumb. */ |
4e7fd91e PB |
3926 | if (globals->use_rel) |
3927 | { | |
3928 | /* Need to refetch addend. */ | |
3929 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
3930 | /* ??? Need to determine shift amount from operand size. */ | |
3931 | addend >>= howto->rightshift; | |
3932 | } | |
252b5132 RH |
3933 | value += addend; |
3934 | ||
3935 | /* ??? Isn't value unsigned? */ | |
3936 | if ((long) value > 0x1f || (long) value < -0x10) | |
3937 | return bfd_reloc_overflow; | |
3938 | ||
3939 | /* ??? Value needs to be properly shifted into place first. */ | |
3940 | value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; | |
3941 | bfd_put_16 (input_bfd, value, hit_data); | |
3942 | return bfd_reloc_ok; | |
3943 | ||
dfc5f959 | 3944 | case R_ARM_THM_XPC22: |
c19d1205 | 3945 | case R_ARM_THM_CALL: |
dfc5f959 | 3946 | /* Thumb BL (branch long instruction). */ |
252b5132 | 3947 | { |
b34976b6 AM |
3948 | bfd_vma relocation; |
3949 | bfd_boolean overflow = FALSE; | |
3950 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3951 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
df212a7e | 3952 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; |
ba96a88f | 3953 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; |
b34976b6 | 3954 | bfd_vma check; |
252b5132 | 3955 | bfd_signed_vma signed_check; |
252b5132 | 3956 | |
252b5132 RH |
3957 | /* Need to refetch the addend and squish the two 11 bit pieces |
3958 | together. */ | |
4e7fd91e PB |
3959 | if (globals->use_rel) |
3960 | { | |
3961 | bfd_vma upper = upper_insn & 0x7ff; | |
3962 | bfd_vma lower = lower_insn & 0x7ff; | |
3963 | upper = (upper ^ 0x400) - 0x400; /* Sign extend. */ | |
3964 | addend = (upper << 12) | (lower << 1); | |
3965 | signed_addend = addend; | |
3966 | } | |
cb1afa5c | 3967 | |
dfc5f959 NC |
3968 | if (r_type == R_ARM_THM_XPC22) |
3969 | { | |
3970 | /* Check for Thumb to Thumb call. */ | |
3971 | /* FIXME: Should we translate the instruction into a BL | |
3972 | instruction instead ? */ | |
3973 | if (sym_flags == STT_ARM_TFUNC) | |
d003868e AM |
3974 | (*_bfd_error_handler) |
3975 | (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), | |
3976 | input_bfd, | |
3977 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
3978 | } |
3979 | else | |
252b5132 | 3980 | { |
dfc5f959 NC |
3981 | /* If it is not a call to Thumb, assume call to Arm. |
3982 | If it is a call relative to a section name, then it is not a | |
b7693d02 DJ |
3983 | function call at all, but rather a long jump. Calls through |
3984 | the PLT do not require stubs. */ | |
3985 | if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION | |
3986 | && (h == NULL || splt == NULL | |
3987 | || h->plt.offset == (bfd_vma) -1)) | |
dfc5f959 | 3988 | { |
39b41c9c PB |
3989 | if (globals->use_blx) |
3990 | { | |
3991 | /* Convert BL to BLX. */ | |
3992 | lower_insn = (lower_insn & ~0x1000) | 0x0800; | |
3993 | } | |
3994 | else if (elf32_thumb_to_arm_stub | |
dfc5f959 NC |
3995 | (info, sym_name, input_bfd, output_bfd, input_section, |
3996 | hit_data, sym_sec, rel->r_offset, signed_addend, value)) | |
3997 | return bfd_reloc_ok; | |
3998 | else | |
3999 | return bfd_reloc_dangerous; | |
4000 | } | |
39b41c9c PB |
4001 | else if (sym_flags == STT_ARM_TFUNC && globals->use_blx) |
4002 | { | |
4003 | /* Make sure this is a BL. */ | |
4004 | lower_insn |= 0x1800; | |
4005 | } | |
252b5132 | 4006 | } |
f21f3fe0 | 4007 | |
b7693d02 DJ |
4008 | /* Handle calls via the PLT. */ |
4009 | if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) | |
4010 | { | |
4011 | value = (splt->output_section->vma | |
4012 | + splt->output_offset | |
4013 | + h->plt.offset); | |
33bfe774 JB |
4014 | if (globals->use_blx) |
4015 | { | |
4016 | /* If the Thumb BLX instruction is available, convert the | |
4017 | BL to a BLX instruction to call the ARM-mode PLT entry. */ | |
39b41c9c | 4018 | lower_insn = (lower_insn & ~0x1000) | 0x0800; |
33bfe774 JB |
4019 | } |
4020 | else | |
4021 | /* Target the Thumb stub before the ARM PLT entry. */ | |
4022 | value -= PLT_THUMB_STUB_SIZE; | |
0945cdfd | 4023 | *unresolved_reloc_p = FALSE; |
b7693d02 DJ |
4024 | } |
4025 | ||
ba96a88f | 4026 | relocation = value + signed_addend; |
f21f3fe0 | 4027 | |
252b5132 | 4028 | relocation -= (input_section->output_section->vma |
ba96a88f NC |
4029 | + input_section->output_offset |
4030 | + rel->r_offset); | |
9a5aca8c | 4031 | |
252b5132 RH |
4032 | check = relocation >> howto->rightshift; |
4033 | ||
4034 | /* If this is a signed value, the rightshift just dropped | |
4035 | leading 1 bits (assuming twos complement). */ | |
4036 | if ((bfd_signed_vma) relocation >= 0) | |
4037 | signed_check = check; | |
4038 | else | |
4039 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
4040 | ||
252b5132 | 4041 | /* Assumes two's complement. */ |
ba96a88f | 4042 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
b34976b6 | 4043 | overflow = TRUE; |
252b5132 | 4044 | |
39b41c9c | 4045 | if ((lower_insn & 0x1800) == 0x0800) |
c62e1cc3 NC |
4046 | /* For a BLX instruction, make sure that the relocation is rounded up |
4047 | to a word boundary. This follows the semantics of the instruction | |
4048 | which specifies that bit 1 of the target address will come from bit | |
4049 | 1 of the base address. */ | |
4050 | relocation = (relocation + 2) & ~ 3; | |
cb1afa5c | 4051 | |
c62e1cc3 NC |
4052 | /* Put RELOCATION back into the insn. */ |
4053 | upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff); | |
4054 | lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff); | |
4055 | ||
252b5132 RH |
4056 | /* Put the relocated value back in the object file: */ |
4057 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
4058 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
4059 | ||
4060 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
4061 | } | |
4062 | break; | |
4063 | ||
c19d1205 ZW |
4064 | case R_ARM_THM_JUMP24: |
4065 | /* Thumb32 unconditional branch instruction. */ | |
4066 | { | |
4067 | bfd_vma relocation; | |
4068 | bfd_boolean overflow = FALSE; | |
4069 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
4070 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
4071 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
4072 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
4073 | bfd_vma check; | |
4074 | bfd_signed_vma signed_check; | |
4075 | ||
4076 | /* Need to refetch the addend, reconstruct the top three bits, and glue the | |
4077 | two pieces together. */ | |
4078 | if (globals->use_rel) | |
4079 | { | |
4080 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
4081 | bfd_vma hi = (upper_insn & 0x03ff); | |
4082 | bfd_vma I1 = (lower_insn & 0x2000) >> 13; | |
4083 | bfd_vma I2 = (lower_insn & 0x0800) >> 11; | |
4084 | bfd_vma lo = (lower_insn & 0x07ff); | |
4085 | ||
4086 | I1 = !(I1 ^ S); | |
4087 | I2 = !(I2 ^ S); | |
4088 | S = !S; | |
4089 | ||
4090 | signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1); | |
4091 | signed_addend -= (1 << 24); /* Sign extend. */ | |
4092 | } | |
4093 | ||
4094 | /* ??? Should handle interworking? GCC might someday try to | |
4095 | use this for tail calls. */ | |
4096 | ||
4097 | relocation = value + signed_addend; | |
4098 | relocation -= (input_section->output_section->vma | |
4099 | + input_section->output_offset | |
4100 | + rel->r_offset); | |
4101 | ||
4102 | check = relocation >> howto->rightshift; | |
4103 | ||
4104 | /* If this is a signed value, the rightshift just dropped | |
4105 | leading 1 bits (assuming twos complement). */ | |
4106 | if ((bfd_signed_vma) relocation >= 0) | |
4107 | signed_check = check; | |
4108 | else | |
4109 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
4110 | ||
4111 | /* Assumes two's complement. */ | |
4112 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
4113 | overflow = TRUE; | |
4114 | ||
4115 | /* Put RELOCATION back into the insn. */ | |
4116 | { | |
4117 | bfd_vma S = (relocation & 0x01000000) >> 24; | |
4118 | bfd_vma I1 = (relocation & 0x00800000) >> 23; | |
4119 | bfd_vma I2 = (relocation & 0x00400000) >> 22; | |
4120 | bfd_vma hi = (relocation & 0x003ff000) >> 12; | |
4121 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
4122 | ||
4123 | I1 = !(I1 ^ S); | |
4124 | I2 = !(I2 ^ S); | |
4125 | ||
4126 | upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi; | |
4127 | lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo; | |
4128 | } | |
4129 | ||
4130 | /* Put the relocated value back in the object file: */ | |
4131 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
4132 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
4133 | ||
4134 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
4135 | } | |
4136 | ||
4137 | case R_ARM_THM_JUMP19: | |
4138 | /* Thumb32 conditional branch instruction. */ | |
4139 | { | |
4140 | bfd_vma relocation; | |
4141 | bfd_boolean overflow = FALSE; | |
4142 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
4143 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
4144 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
4145 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
4146 | bfd_vma check; | |
4147 | bfd_signed_vma signed_check; | |
4148 | ||
4149 | /* Need to refetch the addend, reconstruct the top three bits, | |
4150 | and squish the two 11 bit pieces together. */ | |
4151 | if (globals->use_rel) | |
4152 | { | |
4153 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
4154 | bfd_vma upper = (upper_insn & 0x001f); | |
4155 | bfd_vma J1 = (lower_insn & 0x2000) >> 13; | |
4156 | bfd_vma J2 = (lower_insn & 0x0800) >> 11; | |
4157 | bfd_vma lower = (lower_insn & 0x07ff); | |
4158 | ||
4159 | upper |= J2 << 6; | |
4160 | upper |= J1 << 7; | |
4161 | upper |= ~S << 8; | |
4162 | upper -= 0x0100; /* Sign extend. */ | |
4163 | ||
4164 | addend = (upper << 12) | (lower << 1); | |
4165 | signed_addend = addend; | |
4166 | } | |
4167 | ||
4168 | /* ??? Should handle interworking? GCC might someday try to | |
4169 | use this for tail calls. */ | |
4170 | ||
4171 | relocation = value + signed_addend; | |
4172 | relocation -= (input_section->output_section->vma | |
4173 | + input_section->output_offset | |
4174 | + rel->r_offset); | |
4175 | ||
4176 | check = relocation >> howto->rightshift; | |
4177 | ||
4178 | /* If this is a signed value, the rightshift just dropped | |
4179 | leading 1 bits (assuming twos complement). */ | |
4180 | if ((bfd_signed_vma) relocation >= 0) | |
4181 | signed_check = check; | |
4182 | else | |
4183 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
4184 | ||
4185 | /* Assumes two's complement. */ | |
4186 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
4187 | overflow = TRUE; | |
4188 | ||
4189 | /* Put RELOCATION back into the insn. */ | |
4190 | { | |
4191 | bfd_vma S = (relocation & 0x00100000) >> 20; | |
4192 | bfd_vma J2 = (relocation & 0x00080000) >> 19; | |
4193 | bfd_vma J1 = (relocation & 0x00040000) >> 18; | |
4194 | bfd_vma hi = (relocation & 0x0003f000) >> 12; | |
4195 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
4196 | ||
4197 | upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi; | |
4198 | lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo; | |
4199 | } | |
4200 | ||
4201 | /* Put the relocated value back in the object file: */ | |
4202 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
4203 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
4204 | ||
4205 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
4206 | } | |
4207 | ||
4208 | case R_ARM_THM_JUMP11: | |
4209 | case R_ARM_THM_JUMP8: | |
4210 | case R_ARM_THM_JUMP6: | |
51c5503b NC |
4211 | /* Thumb B (branch) instruction). */ |
4212 | { | |
6cf9e9fe | 4213 | bfd_signed_vma relocation; |
51c5503b NC |
4214 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; |
4215 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
51c5503b NC |
4216 | bfd_signed_vma signed_check; |
4217 | ||
c19d1205 ZW |
4218 | /* CZB cannot jump backward. */ |
4219 | if (r_type == R_ARM_THM_JUMP6) | |
4220 | reloc_signed_min = 0; | |
4221 | ||
4e7fd91e | 4222 | if (globals->use_rel) |
6cf9e9fe | 4223 | { |
4e7fd91e PB |
4224 | /* Need to refetch addend. */ |
4225 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
4226 | if (addend & ((howto->src_mask + 1) >> 1)) | |
4227 | { | |
4228 | signed_addend = -1; | |
4229 | signed_addend &= ~ howto->src_mask; | |
4230 | signed_addend |= addend; | |
4231 | } | |
4232 | else | |
4233 | signed_addend = addend; | |
4234 | /* The value in the insn has been right shifted. We need to | |
4235 | undo this, so that we can perform the address calculation | |
4236 | in terms of bytes. */ | |
4237 | signed_addend <<= howto->rightshift; | |
6cf9e9fe | 4238 | } |
6cf9e9fe | 4239 | relocation = value + signed_addend; |
51c5503b NC |
4240 | |
4241 | relocation -= (input_section->output_section->vma | |
4242 | + input_section->output_offset | |
4243 | + rel->r_offset); | |
4244 | ||
6cf9e9fe NC |
4245 | relocation >>= howto->rightshift; |
4246 | signed_check = relocation; | |
c19d1205 ZW |
4247 | |
4248 | if (r_type == R_ARM_THM_JUMP6) | |
4249 | relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3); | |
4250 | else | |
4251 | relocation &= howto->dst_mask; | |
51c5503b | 4252 | relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); |
cedb70c5 | 4253 | |
51c5503b NC |
4254 | bfd_put_16 (input_bfd, relocation, hit_data); |
4255 | ||
4256 | /* Assumes two's complement. */ | |
4257 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
4258 | return bfd_reloc_overflow; | |
4259 | ||
4260 | return bfd_reloc_ok; | |
4261 | } | |
cedb70c5 | 4262 | |
8375c36b PB |
4263 | case R_ARM_ALU_PCREL7_0: |
4264 | case R_ARM_ALU_PCREL15_8: | |
4265 | case R_ARM_ALU_PCREL23_15: | |
4266 | { | |
4267 | bfd_vma insn; | |
4268 | bfd_vma relocation; | |
4269 | ||
4270 | insn = bfd_get_32 (input_bfd, hit_data); | |
4e7fd91e PB |
4271 | if (globals->use_rel) |
4272 | { | |
4273 | /* Extract the addend. */ | |
4274 | addend = (insn & 0xff) << ((insn & 0xf00) >> 7); | |
4275 | signed_addend = addend; | |
4276 | } | |
8375c36b PB |
4277 | relocation = value + signed_addend; |
4278 | ||
4279 | relocation -= (input_section->output_section->vma | |
4280 | + input_section->output_offset | |
4281 | + rel->r_offset); | |
4282 | insn = (insn & ~0xfff) | |
4283 | | ((howto->bitpos << 7) & 0xf00) | |
4284 | | ((relocation >> howto->bitpos) & 0xff); | |
4285 | bfd_put_32 (input_bfd, value, hit_data); | |
4286 | } | |
4287 | return bfd_reloc_ok; | |
4288 | ||
252b5132 RH |
4289 | case R_ARM_GNU_VTINHERIT: |
4290 | case R_ARM_GNU_VTENTRY: | |
4291 | return bfd_reloc_ok; | |
4292 | ||
c19d1205 | 4293 | case R_ARM_GOTOFF32: |
252b5132 RH |
4294 | /* Relocation is relative to the start of the |
4295 | global offset table. */ | |
4296 | ||
4297 | BFD_ASSERT (sgot != NULL); | |
4298 | if (sgot == NULL) | |
4299 | return bfd_reloc_notsupported; | |
9a5aca8c | 4300 | |
cedb70c5 | 4301 | /* If we are addressing a Thumb function, we need to adjust the |
ee29b9fb RE |
4302 | address by one, so that attempts to call the function pointer will |
4303 | correctly interpret it as Thumb code. */ | |
4304 | if (sym_flags == STT_ARM_TFUNC) | |
4305 | value += 1; | |
4306 | ||
252b5132 RH |
4307 | /* Note that sgot->output_offset is not involved in this |
4308 | calculation. We always want the start of .got. If we | |
4309 | define _GLOBAL_OFFSET_TABLE in a different way, as is | |
4310 | permitted by the ABI, we might have to change this | |
9b485d32 | 4311 | calculation. */ |
252b5132 | 4312 | value -= sgot->output_section->vma; |
f21f3fe0 | 4313 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 4314 | contents, rel->r_offset, value, |
00a97672 | 4315 | rel->r_addend); |
252b5132 RH |
4316 | |
4317 | case R_ARM_GOTPC: | |
a7c10850 | 4318 | /* Use global offset table as symbol value. */ |
252b5132 | 4319 | BFD_ASSERT (sgot != NULL); |
f21f3fe0 | 4320 | |
252b5132 RH |
4321 | if (sgot == NULL) |
4322 | return bfd_reloc_notsupported; | |
4323 | ||
0945cdfd | 4324 | *unresolved_reloc_p = FALSE; |
252b5132 | 4325 | value = sgot->output_section->vma; |
f21f3fe0 | 4326 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 4327 | contents, rel->r_offset, value, |
00a97672 | 4328 | rel->r_addend); |
f21f3fe0 | 4329 | |
252b5132 | 4330 | case R_ARM_GOT32: |
eb043451 | 4331 | case R_ARM_GOT_PREL: |
252b5132 | 4332 | /* Relocation is to the entry for this symbol in the |
9b485d32 | 4333 | global offset table. */ |
252b5132 RH |
4334 | if (sgot == NULL) |
4335 | return bfd_reloc_notsupported; | |
f21f3fe0 | 4336 | |
252b5132 RH |
4337 | if (h != NULL) |
4338 | { | |
4339 | bfd_vma off; | |
5e681ec4 | 4340 | bfd_boolean dyn; |
f21f3fe0 | 4341 | |
252b5132 RH |
4342 | off = h->got.offset; |
4343 | BFD_ASSERT (off != (bfd_vma) -1); | |
5e681ec4 | 4344 | dyn = globals->root.dynamic_sections_created; |
f21f3fe0 | 4345 | |
5e681ec4 | 4346 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
50d6c878 | 4347 | || (info->shared |
5e681ec4 PB |
4348 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
4349 | || (ELF_ST_VISIBILITY (h->other) | |
4350 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
4351 | { |
4352 | /* This is actually a static link, or it is a -Bsymbolic link | |
4353 | and the symbol is defined locally. We must initialize this | |
4354 | entry in the global offset table. Since the offset must | |
4355 | always be a multiple of 4, we use the least significant bit | |
4356 | to record whether we have initialized it already. | |
f21f3fe0 | 4357 | |
00a97672 | 4358 | When doing a dynamic link, we create a .rel(a).got relocation |
f21f3fe0 | 4359 | entry to initialize the value. This is done in the |
9b485d32 | 4360 | finish_dynamic_symbol routine. */ |
252b5132 RH |
4361 | if ((off & 1) != 0) |
4362 | off &= ~1; | |
4363 | else | |
4364 | { | |
ee29b9fb RE |
4365 | /* If we are addressing a Thumb function, we need to |
4366 | adjust the address by one, so that attempts to | |
4367 | call the function pointer will correctly | |
4368 | interpret it as Thumb code. */ | |
4369 | if (sym_flags == STT_ARM_TFUNC) | |
4370 | value |= 1; | |
4371 | ||
252b5132 RH |
4372 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
4373 | h->got.offset |= 1; | |
4374 | } | |
4375 | } | |
0945cdfd DJ |
4376 | else |
4377 | *unresolved_reloc_p = FALSE; | |
f21f3fe0 | 4378 | |
252b5132 RH |
4379 | value = sgot->output_offset + off; |
4380 | } | |
4381 | else | |
4382 | { | |
4383 | bfd_vma off; | |
f21f3fe0 | 4384 | |
252b5132 RH |
4385 | BFD_ASSERT (local_got_offsets != NULL && |
4386 | local_got_offsets[r_symndx] != (bfd_vma) -1); | |
f21f3fe0 | 4387 | |
252b5132 | 4388 | off = local_got_offsets[r_symndx]; |
f21f3fe0 | 4389 | |
252b5132 RH |
4390 | /* The offset must always be a multiple of 4. We use the |
4391 | least significant bit to record whether we have already | |
9b485d32 | 4392 | generated the necessary reloc. */ |
252b5132 RH |
4393 | if ((off & 1) != 0) |
4394 | off &= ~1; | |
4395 | else | |
4396 | { | |
b7693d02 DJ |
4397 | /* If we are addressing a Thumb function, we need to |
4398 | adjust the address by one, so that attempts to | |
4399 | call the function pointer will correctly | |
4400 | interpret it as Thumb code. */ | |
4401 | if (sym_flags == STT_ARM_TFUNC) | |
4402 | value |= 1; | |
4403 | ||
00a97672 RS |
4404 | if (globals->use_rel) |
4405 | bfd_put_32 (output_bfd, value, sgot->contents + off); | |
f21f3fe0 | 4406 | |
252b5132 RH |
4407 | if (info->shared) |
4408 | { | |
4409 | asection * srelgot; | |
947216bf AM |
4410 | Elf_Internal_Rela outrel; |
4411 | bfd_byte *loc; | |
f21f3fe0 | 4412 | |
00a97672 RS |
4413 | srelgot = (bfd_get_section_by_name |
4414 | (dynobj, RELOC_SECTION (globals, ".got"))); | |
252b5132 | 4415 | BFD_ASSERT (srelgot != NULL); |
f21f3fe0 | 4416 | |
00a97672 | 4417 | outrel.r_addend = addend + value; |
252b5132 | 4418 | outrel.r_offset = (sgot->output_section->vma |
f21f3fe0 | 4419 | + sgot->output_offset |
252b5132 RH |
4420 | + off); |
4421 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
947216bf | 4422 | loc = srelgot->contents; |
00a97672 RS |
4423 | loc += srelgot->reloc_count++ * RELOC_SIZE (globals); |
4424 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
252b5132 | 4425 | } |
f21f3fe0 | 4426 | |
252b5132 RH |
4427 | local_got_offsets[r_symndx] |= 1; |
4428 | } | |
f21f3fe0 | 4429 | |
252b5132 RH |
4430 | value = sgot->output_offset + off; |
4431 | } | |
eb043451 PB |
4432 | if (r_type != R_ARM_GOT32) |
4433 | value += sgot->output_section->vma; | |
9a5aca8c | 4434 | |
f21f3fe0 | 4435 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 4436 | contents, rel->r_offset, value, |
00a97672 | 4437 | rel->r_addend); |
f21f3fe0 | 4438 | |
ba93b8ac DJ |
4439 | case R_ARM_TLS_LDO32: |
4440 | value = value - dtpoff_base (info); | |
4441 | ||
4442 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
4443 | contents, rel->r_offset, value, |
4444 | rel->r_addend); | |
ba93b8ac DJ |
4445 | |
4446 | case R_ARM_TLS_LDM32: | |
4447 | { | |
4448 | bfd_vma off; | |
4449 | ||
4450 | if (globals->sgot == NULL) | |
4451 | abort (); | |
4452 | ||
4453 | off = globals->tls_ldm_got.offset; | |
4454 | ||
4455 | if ((off & 1) != 0) | |
4456 | off &= ~1; | |
4457 | else | |
4458 | { | |
4459 | /* If we don't know the module number, create a relocation | |
4460 | for it. */ | |
4461 | if (info->shared) | |
4462 | { | |
4463 | Elf_Internal_Rela outrel; | |
4464 | bfd_byte *loc; | |
4465 | ||
4466 | if (globals->srelgot == NULL) | |
4467 | abort (); | |
4468 | ||
00a97672 | 4469 | outrel.r_addend = 0; |
ba93b8ac DJ |
4470 | outrel.r_offset = (globals->sgot->output_section->vma |
4471 | + globals->sgot->output_offset + off); | |
4472 | outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32); | |
4473 | ||
00a97672 RS |
4474 | if (globals->use_rel) |
4475 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4476 | globals->sgot->contents + off); | |
ba93b8ac DJ |
4477 | |
4478 | loc = globals->srelgot->contents; | |
00a97672 RS |
4479 | loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals); |
4480 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac DJ |
4481 | } |
4482 | else | |
4483 | bfd_put_32 (output_bfd, 1, globals->sgot->contents + off); | |
4484 | ||
4485 | globals->tls_ldm_got.offset |= 1; | |
4486 | } | |
4487 | ||
4488 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
4489 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
4490 | ||
4491 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4492 | contents, rel->r_offset, value, | |
00a97672 | 4493 | rel->r_addend); |
ba93b8ac DJ |
4494 | } |
4495 | ||
4496 | case R_ARM_TLS_GD32: | |
4497 | case R_ARM_TLS_IE32: | |
4498 | { | |
4499 | bfd_vma off; | |
4500 | int indx; | |
4501 | char tls_type; | |
4502 | ||
4503 | if (globals->sgot == NULL) | |
4504 | abort (); | |
4505 | ||
4506 | indx = 0; | |
4507 | if (h != NULL) | |
4508 | { | |
4509 | bfd_boolean dyn; | |
4510 | dyn = globals->root.dynamic_sections_created; | |
4511 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
4512 | && (!info->shared | |
4513 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
4514 | { | |
4515 | *unresolved_reloc_p = FALSE; | |
4516 | indx = h->dynindx; | |
4517 | } | |
4518 | off = h->got.offset; | |
4519 | tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type; | |
4520 | } | |
4521 | else | |
4522 | { | |
4523 | if (local_got_offsets == NULL) | |
4524 | abort (); | |
4525 | off = local_got_offsets[r_symndx]; | |
4526 | tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx]; | |
4527 | } | |
4528 | ||
4529 | if (tls_type == GOT_UNKNOWN) | |
4530 | abort (); | |
4531 | ||
4532 | if ((off & 1) != 0) | |
4533 | off &= ~1; | |
4534 | else | |
4535 | { | |
4536 | bfd_boolean need_relocs = FALSE; | |
4537 | Elf_Internal_Rela outrel; | |
4538 | bfd_byte *loc = NULL; | |
4539 | int cur_off = off; | |
4540 | ||
4541 | /* The GOT entries have not been initialized yet. Do it | |
4542 | now, and emit any relocations. If both an IE GOT and a | |
4543 | GD GOT are necessary, we emit the GD first. */ | |
4544 | ||
4545 | if ((info->shared || indx != 0) | |
4546 | && (h == NULL | |
4547 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
4548 | || h->root.type != bfd_link_hash_undefweak)) | |
4549 | { | |
4550 | need_relocs = TRUE; | |
4551 | if (globals->srelgot == NULL) | |
4552 | abort (); | |
4553 | loc = globals->srelgot->contents; | |
00a97672 | 4554 | loc += globals->srelgot->reloc_count * RELOC_SIZE (globals); |
ba93b8ac DJ |
4555 | } |
4556 | ||
4557 | if (tls_type & GOT_TLS_GD) | |
4558 | { | |
4559 | if (need_relocs) | |
4560 | { | |
00a97672 | 4561 | outrel.r_addend = 0; |
ba93b8ac | 4562 | outrel.r_offset = (globals->sgot->output_section->vma |
00a97672 RS |
4563 | + globals->sgot->output_offset |
4564 | + cur_off); | |
ba93b8ac | 4565 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32); |
ba93b8ac | 4566 | |
00a97672 RS |
4567 | if (globals->use_rel) |
4568 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4569 | globals->sgot->contents + cur_off); | |
4570 | ||
4571 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 4572 | globals->srelgot->reloc_count++; |
00a97672 | 4573 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4574 | |
4575 | if (indx == 0) | |
4576 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
4577 | globals->sgot->contents + cur_off + 4); | |
4578 | else | |
4579 | { | |
00a97672 | 4580 | outrel.r_addend = 0; |
ba93b8ac DJ |
4581 | outrel.r_info = ELF32_R_INFO (indx, |
4582 | R_ARM_TLS_DTPOFF32); | |
4583 | outrel.r_offset += 4; | |
00a97672 RS |
4584 | |
4585 | if (globals->use_rel) | |
4586 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4587 | globals->sgot->contents + cur_off + 4); | |
4588 | ||
4589 | ||
4590 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 4591 | globals->srelgot->reloc_count++; |
00a97672 | 4592 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4593 | } |
4594 | } | |
4595 | else | |
4596 | { | |
4597 | /* If we are not emitting relocations for a | |
4598 | general dynamic reference, then we must be in a | |
4599 | static link or an executable link with the | |
4600 | symbol binding locally. Mark it as belonging | |
4601 | to module 1, the executable. */ | |
4602 | bfd_put_32 (output_bfd, 1, | |
4603 | globals->sgot->contents + cur_off); | |
4604 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
4605 | globals->sgot->contents + cur_off + 4); | |
4606 | } | |
4607 | ||
4608 | cur_off += 8; | |
4609 | } | |
4610 | ||
4611 | if (tls_type & GOT_TLS_IE) | |
4612 | { | |
4613 | if (need_relocs) | |
4614 | { | |
00a97672 RS |
4615 | if (indx == 0) |
4616 | outrel.r_addend = value - dtpoff_base (info); | |
4617 | else | |
4618 | outrel.r_addend = 0; | |
ba93b8ac DJ |
4619 | outrel.r_offset = (globals->sgot->output_section->vma |
4620 | + globals->sgot->output_offset | |
4621 | + cur_off); | |
4622 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32); | |
4623 | ||
00a97672 RS |
4624 | if (globals->use_rel) |
4625 | bfd_put_32 (output_bfd, outrel.r_addend, | |
ba93b8ac DJ |
4626 | globals->sgot->contents + cur_off); |
4627 | ||
00a97672 | 4628 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); |
ba93b8ac | 4629 | globals->srelgot->reloc_count++; |
00a97672 | 4630 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4631 | } |
4632 | else | |
4633 | bfd_put_32 (output_bfd, tpoff (info, value), | |
4634 | globals->sgot->contents + cur_off); | |
4635 | cur_off += 4; | |
4636 | } | |
4637 | ||
4638 | if (h != NULL) | |
4639 | h->got.offset |= 1; | |
4640 | else | |
4641 | local_got_offsets[r_symndx] |= 1; | |
4642 | } | |
4643 | ||
4644 | if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32) | |
4645 | off += 8; | |
4646 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
4647 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
4648 | ||
4649 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4650 | contents, rel->r_offset, value, | |
00a97672 | 4651 | rel->r_addend); |
ba93b8ac DJ |
4652 | } |
4653 | ||
4654 | case R_ARM_TLS_LE32: | |
4655 | if (info->shared) | |
4656 | { | |
4657 | (*_bfd_error_handler) | |
4658 | (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"), | |
4659 | input_bfd, input_section, | |
4660 | (long) rel->r_offset, howto->name); | |
4661 | return FALSE; | |
4662 | } | |
4663 | else | |
4664 | value = tpoff (info, value); | |
4665 | ||
4666 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
4667 | contents, rel->r_offset, value, |
4668 | rel->r_addend); | |
ba93b8ac | 4669 | |
319850b4 JB |
4670 | case R_ARM_V4BX: |
4671 | if (globals->fix_v4bx) | |
4672 | { | |
4673 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4674 | ||
4675 | /* Ensure that we have a BX instruction. */ | |
4676 | BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10); | |
4677 | ||
4678 | /* Preserve Rm (lowest four bits) and the condition code | |
4679 | (highest four bits). Other bits encode MOV PC,Rm. */ | |
4680 | insn = (insn & 0xf000000f) | 0x01a0f000; | |
4681 | ||
4682 | bfd_put_32 (input_bfd, insn, hit_data); | |
4683 | } | |
4684 | return bfd_reloc_ok; | |
4685 | ||
b6895b4f PB |
4686 | case R_ARM_MOVW_ABS_NC: |
4687 | case R_ARM_MOVT_ABS: | |
4688 | case R_ARM_MOVW_PREL_NC: | |
4689 | case R_ARM_MOVT_PREL: | |
4690 | { | |
4691 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4692 | ||
4693 | if (globals->use_rel) | |
4694 | { | |
4695 | addend = ((insn >> 4) & 0xf000) | (insn & 0xfff); | |
4696 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
4697 | } | |
4698 | value += signed_addend; | |
4699 | if (sym_flags == STT_ARM_TFUNC) | |
4700 | value |= 1; | |
4701 | ||
4702 | if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL) | |
4703 | value -= (input_section->output_section->vma | |
4704 | + input_section->output_offset + rel->r_offset); | |
4705 | ||
4706 | if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL) | |
4707 | value >>= 16; | |
4708 | ||
4709 | insn &= 0xfff0f000; | |
4710 | insn |= value & 0xfff; | |
4711 | insn |= (value & 0xf000) << 4; | |
4712 | bfd_put_32 (input_bfd, insn, hit_data); | |
4713 | } | |
4714 | return bfd_reloc_ok; | |
4715 | ||
4716 | case R_ARM_THM_MOVW_ABS_NC: | |
4717 | case R_ARM_THM_MOVT_ABS: | |
4718 | case R_ARM_THM_MOVW_PREL_NC: | |
4719 | case R_ARM_THM_MOVT_PREL: | |
4720 | { | |
4721 | bfd_vma insn; | |
4722 | ||
4723 | insn = bfd_get_16 (input_bfd, hit_data) << 16; | |
4724 | insn |= bfd_get_16 (input_bfd, hit_data + 2); | |
4725 | ||
4726 | if (globals->use_rel) | |
4727 | { | |
4728 | addend = ((insn >> 4) & 0xf000) | |
4729 | | ((insn >> 15) & 0x0800) | |
4730 | | ((insn >> 4) & 0x0700) | |
4731 | | (insn & 0x00ff); | |
4732 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
4733 | } | |
4734 | value += signed_addend; | |
4735 | if (sym_flags == STT_ARM_TFUNC) | |
4736 | value |= 1; | |
4737 | ||
4738 | if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL) | |
4739 | value -= (input_section->output_section->vma | |
4740 | + input_section->output_offset + rel->r_offset); | |
4741 | ||
4742 | if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL) | |
4743 | value >>= 16; | |
4744 | ||
4745 | insn &= 0xfbf08f00; | |
4746 | insn |= (value & 0xf000) << 4; | |
4747 | insn |= (value & 0x0800) << 15; | |
4748 | insn |= (value & 0x0700) << 4; | |
4749 | insn |= (value & 0x00ff); | |
4750 | ||
4751 | bfd_put_16 (input_bfd, insn >> 16, hit_data); | |
4752 | bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); | |
4753 | } | |
4754 | return bfd_reloc_ok; | |
4755 | ||
4962c51a MS |
4756 | case R_ARM_ALU_PC_G0_NC: |
4757 | case R_ARM_ALU_PC_G1_NC: | |
4758 | case R_ARM_ALU_PC_G0: | |
4759 | case R_ARM_ALU_PC_G1: | |
4760 | case R_ARM_ALU_PC_G2: | |
4761 | case R_ARM_ALU_SB_G0_NC: | |
4762 | case R_ARM_ALU_SB_G1_NC: | |
4763 | case R_ARM_ALU_SB_G0: | |
4764 | case R_ARM_ALU_SB_G1: | |
4765 | case R_ARM_ALU_SB_G2: | |
4766 | { | |
4767 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4768 | bfd_vma pc = input_section->output_section->vma | |
4769 | + input_section->output_offset + rel->r_offset; | |
4770 | /* sb should be the origin of the *segment* containing the symbol. | |
4771 | It is not clear how to obtain this OS-dependent value, so we | |
4772 | make an arbitrary choice of zero. */ | |
4773 | bfd_vma sb = 0; | |
4774 | bfd_vma residual; | |
4775 | bfd_vma g_n; | |
4776 | bfd_signed_vma signed_value; | |
4777 | int group = 0; | |
4778 | ||
4779 | /* Determine which group of bits to select. */ | |
4780 | switch (r_type) | |
4781 | { | |
4782 | case R_ARM_ALU_PC_G0_NC: | |
4783 | case R_ARM_ALU_PC_G0: | |
4784 | case R_ARM_ALU_SB_G0_NC: | |
4785 | case R_ARM_ALU_SB_G0: | |
4786 | group = 0; | |
4787 | break; | |
4788 | ||
4789 | case R_ARM_ALU_PC_G1_NC: | |
4790 | case R_ARM_ALU_PC_G1: | |
4791 | case R_ARM_ALU_SB_G1_NC: | |
4792 | case R_ARM_ALU_SB_G1: | |
4793 | group = 1; | |
4794 | break; | |
4795 | ||
4796 | case R_ARM_ALU_PC_G2: | |
4797 | case R_ARM_ALU_SB_G2: | |
4798 | group = 2; | |
4799 | break; | |
4800 | ||
4801 | default: | |
4802 | abort(); | |
4803 | } | |
4804 | ||
4805 | /* If REL, extract the addend from the insn. If RELA, it will | |
4806 | have already been fetched for us. */ | |
4807 | if (globals->use_rel) | |
4808 | { | |
4809 | int negative; | |
4810 | bfd_vma constant = insn & 0xff; | |
4811 | bfd_vma rotation = (insn & 0xf00) >> 8; | |
4812 | ||
4813 | if (rotation == 0) | |
4814 | signed_addend = constant; | |
4815 | else | |
4816 | { | |
4817 | /* Compensate for the fact that in the instruction, the | |
4818 | rotation is stored in multiples of 2 bits. */ | |
4819 | rotation *= 2; | |
4820 | ||
4821 | /* Rotate "constant" right by "rotation" bits. */ | |
4822 | signed_addend = (constant >> rotation) | | |
4823 | (constant << (8 * sizeof (bfd_vma) - rotation)); | |
4824 | } | |
4825 | ||
4826 | /* Determine if the instruction is an ADD or a SUB. | |
4827 | (For REL, this determines the sign of the addend.) */ | |
4828 | negative = identify_add_or_sub (insn); | |
4829 | if (negative == 0) | |
4830 | { | |
4831 | (*_bfd_error_handler) | |
4832 | (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"), | |
4833 | input_bfd, input_section, | |
4834 | (long) rel->r_offset, howto->name); | |
4835 | return bfd_reloc_overflow; | |
4836 | } | |
4837 | ||
4838 | signed_addend *= negative; | |
4839 | } | |
4840 | ||
4841 | /* Compute the value (X) to go in the place. */ | |
4842 | if (r_type == R_ARM_ALU_PC_G0_NC | |
4843 | || r_type == R_ARM_ALU_PC_G1_NC | |
4844 | || r_type == R_ARM_ALU_PC_G0 | |
4845 | || r_type == R_ARM_ALU_PC_G1 | |
4846 | || r_type == R_ARM_ALU_PC_G2) | |
4847 | /* PC relative. */ | |
4848 | signed_value = value - pc + signed_addend; | |
4849 | else | |
4850 | /* Section base relative. */ | |
4851 | signed_value = value - sb + signed_addend; | |
4852 | ||
4853 | /* If the target symbol is a Thumb function, then set the | |
4854 | Thumb bit in the address. */ | |
4855 | if (sym_flags == STT_ARM_TFUNC) | |
4856 | signed_value |= 1; | |
4857 | ||
4858 | /* Calculate the value of the relevant G_n, in encoded | |
4859 | constant-with-rotation format. */ | |
4860 | g_n = calculate_group_reloc_mask (abs (signed_value), group, | |
4861 | &residual); | |
4862 | ||
4863 | /* Check for overflow if required. */ | |
4864 | if ((r_type == R_ARM_ALU_PC_G0 | |
4865 | || r_type == R_ARM_ALU_PC_G1 | |
4866 | || r_type == R_ARM_ALU_PC_G2 | |
4867 | || r_type == R_ARM_ALU_SB_G0 | |
4868 | || r_type == R_ARM_ALU_SB_G1 | |
4869 | || r_type == R_ARM_ALU_SB_G2) && residual != 0) | |
4870 | { | |
4871 | (*_bfd_error_handler) | |
4872 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
4873 | input_bfd, input_section, | |
4874 | (long) rel->r_offset, abs (signed_value), howto->name); | |
4875 | return bfd_reloc_overflow; | |
4876 | } | |
4877 | ||
4878 | /* Mask out the value and the ADD/SUB part of the opcode; take care | |
4879 | not to destroy the S bit. */ | |
4880 | insn &= 0xff1ff000; | |
4881 | ||
4882 | /* Set the opcode according to whether the value to go in the | |
4883 | place is negative. */ | |
4884 | if (signed_value < 0) | |
4885 | insn |= 1 << 22; | |
4886 | else | |
4887 | insn |= 1 << 23; | |
4888 | ||
4889 | /* Encode the offset. */ | |
4890 | insn |= g_n; | |
4891 | ||
4892 | bfd_put_32 (input_bfd, insn, hit_data); | |
4893 | } | |
4894 | return bfd_reloc_ok; | |
4895 | ||
4896 | case R_ARM_LDR_PC_G0: | |
4897 | case R_ARM_LDR_PC_G1: | |
4898 | case R_ARM_LDR_PC_G2: | |
4899 | case R_ARM_LDR_SB_G0: | |
4900 | case R_ARM_LDR_SB_G1: | |
4901 | case R_ARM_LDR_SB_G2: | |
4902 | { | |
4903 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4904 | bfd_vma pc = input_section->output_section->vma | |
4905 | + input_section->output_offset + rel->r_offset; | |
4906 | bfd_vma sb = 0; /* See note above. */ | |
4907 | bfd_vma residual; | |
4908 | bfd_signed_vma signed_value; | |
4909 | int group = 0; | |
4910 | ||
4911 | /* Determine which groups of bits to calculate. */ | |
4912 | switch (r_type) | |
4913 | { | |
4914 | case R_ARM_LDR_PC_G0: | |
4915 | case R_ARM_LDR_SB_G0: | |
4916 | group = 0; | |
4917 | break; | |
4918 | ||
4919 | case R_ARM_LDR_PC_G1: | |
4920 | case R_ARM_LDR_SB_G1: | |
4921 | group = 1; | |
4922 | break; | |
4923 | ||
4924 | case R_ARM_LDR_PC_G2: | |
4925 | case R_ARM_LDR_SB_G2: | |
4926 | group = 2; | |
4927 | break; | |
4928 | ||
4929 | default: | |
4930 | abort(); | |
4931 | } | |
4932 | ||
4933 | /* If REL, extract the addend from the insn. If RELA, it will | |
4934 | have already been fetched for us. */ | |
4935 | if (globals->use_rel) | |
4936 | { | |
4937 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
4938 | signed_addend = negative * (insn & 0xfff); | |
4939 | } | |
4940 | ||
4941 | /* Compute the value (X) to go in the place. */ | |
4942 | if (r_type == R_ARM_LDR_PC_G0 | |
4943 | || r_type == R_ARM_LDR_PC_G1 | |
4944 | || r_type == R_ARM_LDR_PC_G2) | |
4945 | /* PC relative. */ | |
4946 | signed_value = value - pc + signed_addend; | |
4947 | else | |
4948 | /* Section base relative. */ | |
4949 | signed_value = value - sb + signed_addend; | |
4950 | ||
4951 | /* Calculate the value of the relevant G_{n-1} to obtain | |
4952 | the residual at that stage. */ | |
4953 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
4954 | ||
4955 | /* Check for overflow. */ | |
4956 | if (residual >= 0x1000) | |
4957 | { | |
4958 | (*_bfd_error_handler) | |
4959 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
4960 | input_bfd, input_section, | |
4961 | (long) rel->r_offset, abs (signed_value), howto->name); | |
4962 | return bfd_reloc_overflow; | |
4963 | } | |
4964 | ||
4965 | /* Mask out the value and U bit. */ | |
4966 | insn &= 0xff7ff000; | |
4967 | ||
4968 | /* Set the U bit if the value to go in the place is non-negative. */ | |
4969 | if (signed_value >= 0) | |
4970 | insn |= 1 << 23; | |
4971 | ||
4972 | /* Encode the offset. */ | |
4973 | insn |= residual; | |
4974 | ||
4975 | bfd_put_32 (input_bfd, insn, hit_data); | |
4976 | } | |
4977 | return bfd_reloc_ok; | |
4978 | ||
4979 | case R_ARM_LDRS_PC_G0: | |
4980 | case R_ARM_LDRS_PC_G1: | |
4981 | case R_ARM_LDRS_PC_G2: | |
4982 | case R_ARM_LDRS_SB_G0: | |
4983 | case R_ARM_LDRS_SB_G1: | |
4984 | case R_ARM_LDRS_SB_G2: | |
4985 | { | |
4986 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4987 | bfd_vma pc = input_section->output_section->vma | |
4988 | + input_section->output_offset + rel->r_offset; | |
4989 | bfd_vma sb = 0; /* See note above. */ | |
4990 | bfd_vma residual; | |
4991 | bfd_signed_vma signed_value; | |
4992 | int group = 0; | |
4993 | ||
4994 | /* Determine which groups of bits to calculate. */ | |
4995 | switch (r_type) | |
4996 | { | |
4997 | case R_ARM_LDRS_PC_G0: | |
4998 | case R_ARM_LDRS_SB_G0: | |
4999 | group = 0; | |
5000 | break; | |
5001 | ||
5002 | case R_ARM_LDRS_PC_G1: | |
5003 | case R_ARM_LDRS_SB_G1: | |
5004 | group = 1; | |
5005 | break; | |
5006 | ||
5007 | case R_ARM_LDRS_PC_G2: | |
5008 | case R_ARM_LDRS_SB_G2: | |
5009 | group = 2; | |
5010 | break; | |
5011 | ||
5012 | default: | |
5013 | abort(); | |
5014 | } | |
5015 | ||
5016 | /* If REL, extract the addend from the insn. If RELA, it will | |
5017 | have already been fetched for us. */ | |
5018 | if (globals->use_rel) | |
5019 | { | |
5020 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
5021 | signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf)); | |
5022 | } | |
5023 | ||
5024 | /* Compute the value (X) to go in the place. */ | |
5025 | if (r_type == R_ARM_LDRS_PC_G0 | |
5026 | || r_type == R_ARM_LDRS_PC_G1 | |
5027 | || r_type == R_ARM_LDRS_PC_G2) | |
5028 | /* PC relative. */ | |
5029 | signed_value = value - pc + signed_addend; | |
5030 | else | |
5031 | /* Section base relative. */ | |
5032 | signed_value = value - sb + signed_addend; | |
5033 | ||
5034 | /* Calculate the value of the relevant G_{n-1} to obtain | |
5035 | the residual at that stage. */ | |
5036 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
5037 | ||
5038 | /* Check for overflow. */ | |
5039 | if (residual >= 0x100) | |
5040 | { | |
5041 | (*_bfd_error_handler) | |
5042 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
5043 | input_bfd, input_section, | |
5044 | (long) rel->r_offset, abs (signed_value), howto->name); | |
5045 | return bfd_reloc_overflow; | |
5046 | } | |
5047 | ||
5048 | /* Mask out the value and U bit. */ | |
5049 | insn &= 0xff7ff0f0; | |
5050 | ||
5051 | /* Set the U bit if the value to go in the place is non-negative. */ | |
5052 | if (signed_value >= 0) | |
5053 | insn |= 1 << 23; | |
5054 | ||
5055 | /* Encode the offset. */ | |
5056 | insn |= ((residual & 0xf0) << 4) | (residual & 0xf); | |
5057 | ||
5058 | bfd_put_32 (input_bfd, insn, hit_data); | |
5059 | } | |
5060 | return bfd_reloc_ok; | |
5061 | ||
5062 | case R_ARM_LDC_PC_G0: | |
5063 | case R_ARM_LDC_PC_G1: | |
5064 | case R_ARM_LDC_PC_G2: | |
5065 | case R_ARM_LDC_SB_G0: | |
5066 | case R_ARM_LDC_SB_G1: | |
5067 | case R_ARM_LDC_SB_G2: | |
5068 | { | |
5069 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
5070 | bfd_vma pc = input_section->output_section->vma | |
5071 | + input_section->output_offset + rel->r_offset; | |
5072 | bfd_vma sb = 0; /* See note above. */ | |
5073 | bfd_vma residual; | |
5074 | bfd_signed_vma signed_value; | |
5075 | int group = 0; | |
5076 | ||
5077 | /* Determine which groups of bits to calculate. */ | |
5078 | switch (r_type) | |
5079 | { | |
5080 | case R_ARM_LDC_PC_G0: | |
5081 | case R_ARM_LDC_SB_G0: | |
5082 | group = 0; | |
5083 | break; | |
5084 | ||
5085 | case R_ARM_LDC_PC_G1: | |
5086 | case R_ARM_LDC_SB_G1: | |
5087 | group = 1; | |
5088 | break; | |
5089 | ||
5090 | case R_ARM_LDC_PC_G2: | |
5091 | case R_ARM_LDC_SB_G2: | |
5092 | group = 2; | |
5093 | break; | |
5094 | ||
5095 | default: | |
5096 | abort(); | |
5097 | } | |
5098 | ||
5099 | /* If REL, extract the addend from the insn. If RELA, it will | |
5100 | have already been fetched for us. */ | |
5101 | if (globals->use_rel) | |
5102 | { | |
5103 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
5104 | signed_addend = negative * ((insn & 0xff) << 2); | |
5105 | } | |
5106 | ||
5107 | /* Compute the value (X) to go in the place. */ | |
5108 | if (r_type == R_ARM_LDC_PC_G0 | |
5109 | || r_type == R_ARM_LDC_PC_G1 | |
5110 | || r_type == R_ARM_LDC_PC_G2) | |
5111 | /* PC relative. */ | |
5112 | signed_value = value - pc + signed_addend; | |
5113 | else | |
5114 | /* Section base relative. */ | |
5115 | signed_value = value - sb + signed_addend; | |
5116 | ||
5117 | /* Calculate the value of the relevant G_{n-1} to obtain | |
5118 | the residual at that stage. */ | |
5119 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
5120 | ||
5121 | /* Check for overflow. (The absolute value to go in the place must be | |
5122 | divisible by four and, after having been divided by four, must | |
5123 | fit in eight bits.) */ | |
5124 | if ((residual & 0x3) != 0 || residual >= 0x400) | |
5125 | { | |
5126 | (*_bfd_error_handler) | |
5127 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
5128 | input_bfd, input_section, | |
5129 | (long) rel->r_offset, abs (signed_value), howto->name); | |
5130 | return bfd_reloc_overflow; | |
5131 | } | |
5132 | ||
5133 | /* Mask out the value and U bit. */ | |
5134 | insn &= 0xff7fff00; | |
5135 | ||
5136 | /* Set the U bit if the value to go in the place is non-negative. */ | |
5137 | if (signed_value >= 0) | |
5138 | insn |= 1 << 23; | |
5139 | ||
5140 | /* Encode the offset. */ | |
5141 | insn |= residual >> 2; | |
5142 | ||
5143 | bfd_put_32 (input_bfd, insn, hit_data); | |
5144 | } | |
5145 | return bfd_reloc_ok; | |
5146 | ||
252b5132 RH |
5147 | default: |
5148 | return bfd_reloc_notsupported; | |
5149 | } | |
5150 | } | |
5151 | ||
ee065d83 PB |
5152 | |
5153 | static int | |
5154 | uleb128_size (unsigned int i) | |
5155 | { | |
5156 | int size; | |
5157 | size = 1; | |
5158 | while (i >= 0x80) | |
5159 | { | |
5160 | i >>= 7; | |
5161 | size++; | |
5162 | } | |
5163 | return size; | |
5164 | } | |
5165 | ||
5166 | /* Return TRUE if the attribute has the default value (0/""). */ | |
5167 | static bfd_boolean | |
5168 | is_default_attr (aeabi_attribute *attr) | |
5169 | { | |
5170 | if ((attr->type & 1) && attr->i != 0) | |
5171 | return FALSE; | |
5172 | if ((attr->type & 2) && attr->s && *attr->s) | |
5173 | return FALSE; | |
5174 | ||
5175 | return TRUE; | |
5176 | } | |
5177 | ||
5178 | /* Return the size of a single attribute. */ | |
5179 | static bfd_vma | |
5180 | eabi_attr_size(int tag, aeabi_attribute *attr) | |
5181 | { | |
5182 | bfd_vma size; | |
5183 | ||
5184 | if (is_default_attr (attr)) | |
5185 | return 0; | |
5186 | ||
5187 | size = uleb128_size (tag); | |
5188 | if (attr->type & 1) | |
5189 | size += uleb128_size (attr->i); | |
5190 | if (attr->type & 2) | |
5191 | size += strlen ((char *)attr->s) + 1; | |
5192 | return size; | |
5193 | } | |
5194 | ||
5195 | /* Returns the size of the eabi object attributess section. */ | |
5196 | bfd_vma | |
5197 | elf32_arm_eabi_attr_size (bfd *abfd) | |
5198 | { | |
5199 | bfd_vma size; | |
5200 | aeabi_attribute *attr; | |
5201 | aeabi_attribute_list *list; | |
5202 | int i; | |
5203 | ||
5204 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
5205 | size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */ | |
5206 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5207 | size += eabi_attr_size (i, &attr[i]); | |
5208 | ||
5209 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5210 | list; | |
5211 | list = list->next) | |
5212 | size += eabi_attr_size (list->tag, &list->attr); | |
5213 | ||
5214 | return size; | |
5215 | } | |
5216 | ||
5217 | static bfd_byte * | |
5218 | write_uleb128 (bfd_byte *p, unsigned int val) | |
5219 | { | |
5220 | bfd_byte c; | |
5221 | do | |
5222 | { | |
5223 | c = val & 0x7f; | |
5224 | val >>= 7; | |
5225 | if (val) | |
5226 | c |= 0x80; | |
5227 | *(p++) = c; | |
5228 | } | |
5229 | while (val); | |
5230 | return p; | |
5231 | } | |
5232 | ||
5233 | /* Write attribute ATTR to butter P, and return a pointer to the following | |
5234 | byte. */ | |
5235 | static bfd_byte * | |
5236 | write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr) | |
5237 | { | |
5238 | /* Suppress default entries. */ | |
5239 | if (is_default_attr(attr)) | |
5240 | return p; | |
5241 | ||
5242 | p = write_uleb128 (p, tag); | |
5243 | if (attr->type & 1) | |
5244 | p = write_uleb128 (p, attr->i); | |
5245 | if (attr->type & 2) | |
5246 | { | |
5247 | int len; | |
5248 | ||
5249 | len = strlen (attr->s) + 1; | |
5250 | memcpy (p, attr->s, len); | |
5251 | p += len; | |
5252 | } | |
5253 | ||
5254 | return p; | |
5255 | } | |
5256 | ||
5257 | /* Write the contents of the eabi attributes section to p. */ | |
5258 | void | |
5259 | elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size) | |
5260 | { | |
5261 | bfd_byte *p; | |
5262 | aeabi_attribute *attr; | |
5263 | aeabi_attribute_list *list; | |
5264 | int i; | |
5265 | ||
5266 | p = contents; | |
5267 | *(p++) = 'A'; | |
5268 | bfd_put_32 (abfd, size - 1, p); | |
5269 | p += 4; | |
5270 | memcpy (p, "aeabi", 6); | |
5271 | p += 6; | |
5272 | *(p++) = Tag_File; | |
5273 | bfd_put_32 (abfd, size - 11, p); | |
5274 | p += 4; | |
5275 | ||
5276 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
5277 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5278 | p = write_eabi_attribute (p, i, &attr[i]); | |
5279 | ||
5280 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5281 | list; | |
5282 | list = list->next) | |
5283 | p = write_eabi_attribute (p, list->tag, &list->attr); | |
5284 | } | |
5285 | ||
5286 | /* Override final_link to handle EABI object attribute sections. */ | |
5287 | ||
5288 | static bfd_boolean | |
5289 | elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info) | |
5290 | { | |
5291 | asection *o; | |
5292 | struct bfd_link_order *p; | |
5293 | asection *attr_section = NULL; | |
5294 | bfd_byte *contents; | |
5295 | bfd_vma size = 0; | |
5296 | ||
5297 | /* elf32_arm_merge_private_bfd_data will already have merged the | |
5298 | object attributes. Remove the input sections from the link, and set | |
5299 | the contents of the output secton. */ | |
5300 | for (o = abfd->sections; o != NULL; o = o->next) | |
5301 | { | |
5302 | if (strcmp (o->name, ".ARM.attributes") == 0) | |
5303 | { | |
5304 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
5305 | { | |
5306 | asection *input_section; | |
5307 | ||
5308 | if (p->type != bfd_indirect_link_order) | |
5309 | continue; | |
5310 | input_section = p->u.indirect.section; | |
5311 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
5312 | elf_link_input_bfd ignores this section. */ | |
5313 | input_section->flags &= ~SEC_HAS_CONTENTS; | |
5314 | } | |
5315 | ||
5316 | size = elf32_arm_eabi_attr_size (abfd); | |
5317 | bfd_set_section_size (abfd, o, size); | |
5318 | attr_section = o; | |
5319 | /* Skip this section later on. */ | |
5320 | o->map_head.link_order = NULL; | |
5321 | } | |
5322 | } | |
5323 | /* Invoke the ELF linker to do all the work. */ | |
5324 | if (!bfd_elf_final_link (abfd, info)) | |
5325 | return FALSE; | |
5326 | ||
5327 | if (attr_section) | |
5328 | { | |
5329 | contents = bfd_malloc(size); | |
5330 | if (contents == NULL) | |
5331 | return FALSE; | |
5332 | elf32_arm_set_eabi_attr_contents (abfd, contents, size); | |
5333 | bfd_set_section_contents (abfd, attr_section, contents, 0, size); | |
5334 | free (contents); | |
5335 | } | |
5336 | return TRUE; | |
5337 | } | |
5338 | ||
5339 | ||
98c1d4aa NC |
5340 | /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ |
5341 | static void | |
57e8b36a NC |
5342 | arm_add_to_rel (bfd * abfd, |
5343 | bfd_byte * address, | |
5344 | reloc_howto_type * howto, | |
5345 | bfd_signed_vma increment) | |
98c1d4aa | 5346 | { |
98c1d4aa NC |
5347 | bfd_signed_vma addend; |
5348 | ||
c19d1205 | 5349 | if (howto->type == R_ARM_THM_CALL) |
98c1d4aa | 5350 | { |
9a5aca8c AM |
5351 | int upper_insn, lower_insn; |
5352 | int upper, lower; | |
98c1d4aa | 5353 | |
9a5aca8c AM |
5354 | upper_insn = bfd_get_16 (abfd, address); |
5355 | lower_insn = bfd_get_16 (abfd, address + 2); | |
5356 | upper = upper_insn & 0x7ff; | |
5357 | lower = lower_insn & 0x7ff; | |
5358 | ||
5359 | addend = (upper << 12) | (lower << 1); | |
ddda4409 | 5360 | addend += increment; |
9a5aca8c | 5361 | addend >>= 1; |
98c1d4aa | 5362 | |
9a5aca8c AM |
5363 | upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); |
5364 | lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); | |
5365 | ||
dc810e39 AM |
5366 | bfd_put_16 (abfd, (bfd_vma) upper_insn, address); |
5367 | bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); | |
9a5aca8c AM |
5368 | } |
5369 | else | |
5370 | { | |
5371 | bfd_vma contents; | |
5372 | ||
5373 | contents = bfd_get_32 (abfd, address); | |
5374 | ||
5375 | /* Get the (signed) value from the instruction. */ | |
5376 | addend = contents & howto->src_mask; | |
5377 | if (addend & ((howto->src_mask + 1) >> 1)) | |
5378 | { | |
5379 | bfd_signed_vma mask; | |
5380 | ||
5381 | mask = -1; | |
5382 | mask &= ~ howto->src_mask; | |
5383 | addend |= mask; | |
5384 | } | |
5385 | ||
5386 | /* Add in the increment, (which is a byte value). */ | |
5387 | switch (howto->type) | |
5388 | { | |
5389 | default: | |
5390 | addend += increment; | |
5391 | break; | |
5392 | ||
5393 | case R_ARM_PC24: | |
c6596c5e | 5394 | case R_ARM_PLT32: |
5b5bb741 PB |
5395 | case R_ARM_CALL: |
5396 | case R_ARM_JUMP24: | |
9a5aca8c | 5397 | addend <<= howto->size; |
dc810e39 | 5398 | addend += increment; |
9a5aca8c AM |
5399 | |
5400 | /* Should we check for overflow here ? */ | |
5401 | ||
5402 | /* Drop any undesired bits. */ | |
5403 | addend >>= howto->rightshift; | |
5404 | break; | |
5405 | } | |
5406 | ||
5407 | contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
5408 | ||
5409 | bfd_put_32 (abfd, contents, address); | |
ddda4409 | 5410 | } |
98c1d4aa | 5411 | } |
252b5132 | 5412 | |
ba93b8ac DJ |
5413 | #define IS_ARM_TLS_RELOC(R_TYPE) \ |
5414 | ((R_TYPE) == R_ARM_TLS_GD32 \ | |
5415 | || (R_TYPE) == R_ARM_TLS_LDO32 \ | |
5416 | || (R_TYPE) == R_ARM_TLS_LDM32 \ | |
5417 | || (R_TYPE) == R_ARM_TLS_DTPOFF32 \ | |
5418 | || (R_TYPE) == R_ARM_TLS_DTPMOD32 \ | |
5419 | || (R_TYPE) == R_ARM_TLS_TPOFF32 \ | |
5420 | || (R_TYPE) == R_ARM_TLS_LE32 \ | |
5421 | || (R_TYPE) == R_ARM_TLS_IE32) | |
5422 | ||
252b5132 | 5423 | /* Relocate an ARM ELF section. */ |
b34976b6 | 5424 | static bfd_boolean |
57e8b36a NC |
5425 | elf32_arm_relocate_section (bfd * output_bfd, |
5426 | struct bfd_link_info * info, | |
5427 | bfd * input_bfd, | |
5428 | asection * input_section, | |
5429 | bfd_byte * contents, | |
5430 | Elf_Internal_Rela * relocs, | |
5431 | Elf_Internal_Sym * local_syms, | |
5432 | asection ** local_sections) | |
252b5132 | 5433 | { |
b34976b6 AM |
5434 | Elf_Internal_Shdr *symtab_hdr; |
5435 | struct elf_link_hash_entry **sym_hashes; | |
5436 | Elf_Internal_Rela *rel; | |
5437 | Elf_Internal_Rela *relend; | |
5438 | const char *name; | |
b32d3aa2 | 5439 | struct elf32_arm_link_hash_table * globals; |
252b5132 | 5440 | |
4e7fd91e PB |
5441 | globals = elf32_arm_hash_table (info); |
5442 | if (info->relocatable && !globals->use_rel) | |
b34976b6 | 5443 | return TRUE; |
b491616a | 5444 | |
252b5132 RH |
5445 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
5446 | sym_hashes = elf_sym_hashes (input_bfd); | |
5447 | ||
5448 | rel = relocs; | |
5449 | relend = relocs + input_section->reloc_count; | |
5450 | for (; rel < relend; rel++) | |
5451 | { | |
ba96a88f NC |
5452 | int r_type; |
5453 | reloc_howto_type * howto; | |
5454 | unsigned long r_symndx; | |
5455 | Elf_Internal_Sym * sym; | |
5456 | asection * sec; | |
252b5132 | 5457 | struct elf_link_hash_entry * h; |
ba96a88f NC |
5458 | bfd_vma relocation; |
5459 | bfd_reloc_status_type r; | |
5460 | arelent bfd_reloc; | |
ba93b8ac | 5461 | char sym_type; |
0945cdfd | 5462 | bfd_boolean unresolved_reloc = FALSE; |
f21f3fe0 | 5463 | |
252b5132 | 5464 | r_symndx = ELF32_R_SYM (rel->r_info); |
ba96a88f | 5465 | r_type = ELF32_R_TYPE (rel->r_info); |
b32d3aa2 | 5466 | r_type = arm_real_reloc_type (globals, r_type); |
252b5132 | 5467 | |
ba96a88f NC |
5468 | if ( r_type == R_ARM_GNU_VTENTRY |
5469 | || r_type == R_ARM_GNU_VTINHERIT) | |
252b5132 RH |
5470 | continue; |
5471 | ||
b32d3aa2 | 5472 | bfd_reloc.howto = elf32_arm_howto_from_type (r_type); |
ba96a88f | 5473 | howto = bfd_reloc.howto; |
252b5132 | 5474 | |
4e7fd91e | 5475 | if (info->relocatable && globals->use_rel) |
252b5132 | 5476 | { |
1049f94e | 5477 | /* This is a relocatable link. We don't have to change |
252b5132 RH |
5478 | anything, unless the reloc is against a section symbol, |
5479 | in which case we have to adjust according to where the | |
5480 | section symbol winds up in the output section. */ | |
5481 | if (r_symndx < symtab_hdr->sh_info) | |
5482 | { | |
5483 | sym = local_syms + r_symndx; | |
5484 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
5485 | { | |
5486 | sec = local_sections[r_symndx]; | |
98c1d4aa | 5487 | arm_add_to_rel (input_bfd, contents + rel->r_offset, |
dc810e39 AM |
5488 | howto, |
5489 | (bfd_signed_vma) (sec->output_offset | |
5490 | + sym->st_value)); | |
252b5132 RH |
5491 | } |
5492 | } | |
5493 | ||
5494 | continue; | |
5495 | } | |
5496 | ||
5497 | /* This is a final link. */ | |
5498 | h = NULL; | |
5499 | sym = NULL; | |
5500 | sec = NULL; | |
9b485d32 | 5501 | |
252b5132 RH |
5502 | if (r_symndx < symtab_hdr->sh_info) |
5503 | { | |
5504 | sym = local_syms + r_symndx; | |
ba93b8ac | 5505 | sym_type = ELF32_ST_TYPE (sym->st_info); |
252b5132 | 5506 | sec = local_sections[r_symndx]; |
4e7fd91e | 5507 | if (globals->use_rel) |
f8df10f4 | 5508 | { |
4e7fd91e PB |
5509 | relocation = (sec->output_section->vma |
5510 | + sec->output_offset | |
5511 | + sym->st_value); | |
5512 | if ((sec->flags & SEC_MERGE) | |
5513 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
f8df10f4 | 5514 | { |
4e7fd91e PB |
5515 | asection *msec; |
5516 | bfd_vma addend, value; | |
5517 | ||
5518 | if (howto->rightshift) | |
5519 | { | |
5520 | (*_bfd_error_handler) | |
5521 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), | |
5522 | input_bfd, input_section, | |
5523 | (long) rel->r_offset, howto->name); | |
5524 | return FALSE; | |
5525 | } | |
f8df10f4 | 5526 | |
4e7fd91e | 5527 | value = bfd_get_32 (input_bfd, contents + rel->r_offset); |
f8df10f4 | 5528 | |
4e7fd91e PB |
5529 | /* Get the (signed) value from the instruction. */ |
5530 | addend = value & howto->src_mask; | |
5531 | if (addend & ((howto->src_mask + 1) >> 1)) | |
5532 | { | |
5533 | bfd_signed_vma mask; | |
f8df10f4 | 5534 | |
4e7fd91e PB |
5535 | mask = -1; |
5536 | mask &= ~ howto->src_mask; | |
5537 | addend |= mask; | |
5538 | } | |
5539 | msec = sec; | |
5540 | addend = | |
5541 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) | |
5542 | - relocation; | |
5543 | addend += msec->output_section->vma + msec->output_offset; | |
5544 | value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
5545 | bfd_put_32 (input_bfd, value, contents + rel->r_offset); | |
f8df10f4 | 5546 | } |
f8df10f4 | 5547 | } |
4e7fd91e PB |
5548 | else |
5549 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
252b5132 RH |
5550 | } |
5551 | else | |
5552 | { | |
560e09e9 | 5553 | bfd_boolean warned; |
560e09e9 | 5554 | |
b2a8e766 AM |
5555 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
5556 | r_symndx, symtab_hdr, sym_hashes, | |
5557 | h, sec, relocation, | |
5558 | unresolved_reloc, warned); | |
ba93b8ac DJ |
5559 | |
5560 | sym_type = h->type; | |
252b5132 RH |
5561 | } |
5562 | ||
5563 | if (h != NULL) | |
5564 | name = h->root.root.string; | |
5565 | else | |
5566 | { | |
5567 | name = (bfd_elf_string_from_elf_section | |
5568 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
5569 | if (name == NULL || *name == '\0') | |
5570 | name = bfd_section_name (input_bfd, sec); | |
5571 | } | |
f21f3fe0 | 5572 | |
ba93b8ac DJ |
5573 | if (r_symndx != 0 |
5574 | && r_type != R_ARM_NONE | |
5575 | && (h == NULL | |
5576 | || h->root.type == bfd_link_hash_defined | |
5577 | || h->root.type == bfd_link_hash_defweak) | |
5578 | && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
5579 | { | |
5580 | (*_bfd_error_handler) | |
5581 | ((sym_type == STT_TLS | |
5582 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") | |
5583 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), | |
5584 | input_bfd, | |
5585 | input_section, | |
5586 | (long) rel->r_offset, | |
5587 | howto->name, | |
5588 | name); | |
5589 | } | |
5590 | ||
252b5132 RH |
5591 | r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, |
5592 | input_section, contents, rel, | |
5593 | relocation, info, sec, name, | |
5594 | (h ? ELF_ST_TYPE (h->type) : | |
0945cdfd DJ |
5595 | ELF_ST_TYPE (sym->st_info)), h, |
5596 | &unresolved_reloc); | |
5597 | ||
5598 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections | |
5599 | because such sections are not SEC_ALLOC and thus ld.so will | |
5600 | not process them. */ | |
5601 | if (unresolved_reloc | |
5602 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
5603 | && h->def_dynamic)) | |
5604 | { | |
5605 | (*_bfd_error_handler) | |
843fe662 L |
5606 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
5607 | input_bfd, | |
5608 | input_section, | |
5609 | (long) rel->r_offset, | |
5610 | howto->name, | |
5611 | h->root.root.string); | |
0945cdfd DJ |
5612 | return FALSE; |
5613 | } | |
252b5132 RH |
5614 | |
5615 | if (r != bfd_reloc_ok) | |
5616 | { | |
5617 | const char * msg = (const char *) 0; | |
5618 | ||
5619 | switch (r) | |
5620 | { | |
5621 | case bfd_reloc_overflow: | |
cf919dfd PB |
5622 | /* If the overflowing reloc was to an undefined symbol, |
5623 | we have already printed one error message and there | |
5624 | is no point complaining again. */ | |
5625 | if ((! h || | |
5626 | h->root.type != bfd_link_hash_undefined) | |
5627 | && (!((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
5628 | (info, (h ? &h->root : NULL), name, howto->name, |
5629 | (bfd_vma) 0, input_bfd, input_section, | |
5630 | rel->r_offset)))) | |
b34976b6 | 5631 | return FALSE; |
252b5132 RH |
5632 | break; |
5633 | ||
5634 | case bfd_reloc_undefined: | |
5635 | if (!((*info->callbacks->undefined_symbol) | |
5636 | (info, name, input_bfd, input_section, | |
b34976b6 AM |
5637 | rel->r_offset, TRUE))) |
5638 | return FALSE; | |
252b5132 RH |
5639 | break; |
5640 | ||
5641 | case bfd_reloc_outofrange: | |
9b485d32 | 5642 | msg = _("internal error: out of range error"); |
252b5132 RH |
5643 | goto common_error; |
5644 | ||
5645 | case bfd_reloc_notsupported: | |
9b485d32 | 5646 | msg = _("internal error: unsupported relocation error"); |
252b5132 RH |
5647 | goto common_error; |
5648 | ||
5649 | case bfd_reloc_dangerous: | |
9b485d32 | 5650 | msg = _("internal error: dangerous error"); |
252b5132 RH |
5651 | goto common_error; |
5652 | ||
5653 | default: | |
9b485d32 | 5654 | msg = _("internal error: unknown error"); |
252b5132 RH |
5655 | /* fall through */ |
5656 | ||
5657 | common_error: | |
5658 | if (!((*info->callbacks->warning) | |
5659 | (info, msg, name, input_bfd, input_section, | |
5660 | rel->r_offset))) | |
b34976b6 | 5661 | return FALSE; |
252b5132 RH |
5662 | break; |
5663 | } | |
5664 | } | |
5665 | } | |
5666 | ||
b34976b6 | 5667 | return TRUE; |
252b5132 RH |
5668 | } |
5669 | ||
ee065d83 PB |
5670 | /* Allocate/find an object attribute. */ |
5671 | static aeabi_attribute * | |
5672 | elf32_arm_new_eabi_attr (bfd *abfd, int tag) | |
5673 | { | |
5674 | aeabi_attribute *attr; | |
5675 | aeabi_attribute_list *list; | |
5676 | aeabi_attribute_list *p; | |
5677 | aeabi_attribute_list **lastp; | |
5678 | ||
5679 | ||
5680 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
5681 | { | |
5682 | /* Knwon tags are preallocated. */ | |
5683 | attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag]; | |
5684 | } | |
5685 | else | |
5686 | { | |
5687 | /* Create a new tag. */ | |
5688 | list = (aeabi_attribute_list *) | |
5689 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
5690 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
5691 | list->tag = tag; | |
5692 | /* Keep the tag list in order. */ | |
5693 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5694 | for (p = *lastp; p; p = p->next) | |
5695 | { | |
5696 | if (tag < p->tag) | |
5697 | break; | |
5698 | lastp = &p->next; | |
5699 | } | |
5700 | list->next = *lastp; | |
5701 | *lastp = list; | |
5702 | attr = &list->attr; | |
5703 | } | |
5704 | ||
5705 | return attr; | |
5706 | } | |
5707 | ||
39b41c9c PB |
5708 | int |
5709 | elf32_arm_get_eabi_attr_int (bfd *abfd, int tag) | |
5710 | { | |
5711 | aeabi_attribute_list *p; | |
5712 | ||
5713 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
5714 | { | |
5715 | /* Knwon tags are preallocated. */ | |
5716 | return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i; | |
5717 | } | |
5718 | else | |
5719 | { | |
5720 | for (p = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5721 | p; | |
5722 | p = p->next) | |
5723 | { | |
5724 | if (tag == p->tag) | |
5725 | return p->attr.i; | |
5726 | if (tag < p->tag) | |
5727 | break; | |
5728 | } | |
5729 | return 0; | |
5730 | } | |
5731 | } | |
5732 | ||
ee065d83 PB |
5733 | void |
5734 | elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i) | |
5735 | { | |
5736 | aeabi_attribute *attr; | |
5737 | ||
5738 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
5739 | attr->type = 1; | |
5740 | attr->i = i; | |
5741 | } | |
5742 | ||
5743 | static char * | |
5744 | attr_strdup (bfd *abfd, const char * s) | |
5745 | { | |
5746 | char * p; | |
5747 | int len; | |
5748 | ||
5749 | len = strlen (s) + 1; | |
5750 | p = (char *)bfd_alloc(abfd, len); | |
5751 | return memcpy (p, s, len); | |
5752 | } | |
5753 | ||
5754 | void | |
5755 | elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s) | |
5756 | { | |
5757 | aeabi_attribute *attr; | |
5758 | ||
5759 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
5760 | attr->type = 2; | |
5761 | attr->s = attr_strdup (abfd, s); | |
5762 | } | |
5763 | ||
5764 | void | |
5765 | elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s) | |
5766 | { | |
5767 | aeabi_attribute_list *list; | |
5768 | aeabi_attribute_list *p; | |
5769 | aeabi_attribute_list **lastp; | |
5770 | ||
5771 | list = (aeabi_attribute_list *) | |
5772 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
5773 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
5774 | list->tag = Tag_compatibility; | |
5775 | list->attr.type = 3; | |
5776 | list->attr.i = i; | |
5777 | list->attr.s = attr_strdup (abfd, s); | |
5778 | ||
5779 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5780 | for (p = *lastp; p; p = p->next) | |
5781 | { | |
5782 | int cmp; | |
5783 | if (p->tag != Tag_compatibility) | |
5784 | break; | |
5785 | cmp = strcmp(s, p->attr.s); | |
5786 | if (cmp < 0 || (cmp == 0 && i < p->attr.i)) | |
5787 | break; | |
5788 | lastp = &p->next; | |
5789 | } | |
5790 | list->next = *lastp; | |
5791 | *lastp = list; | |
5792 | } | |
5793 | ||
c178919b NC |
5794 | /* Set the right machine number. */ |
5795 | ||
5796 | static bfd_boolean | |
57e8b36a | 5797 | elf32_arm_object_p (bfd *abfd) |
c178919b | 5798 | { |
5a6c6817 | 5799 | unsigned int mach; |
57e8b36a | 5800 | |
5a6c6817 | 5801 | mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); |
c178919b | 5802 | |
5a6c6817 NC |
5803 | if (mach != bfd_mach_arm_unknown) |
5804 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); | |
5805 | ||
5806 | else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) | |
5807 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); | |
e16bb312 | 5808 | |
e16bb312 | 5809 | else |
5a6c6817 | 5810 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
c178919b NC |
5811 | |
5812 | return TRUE; | |
5813 | } | |
5814 | ||
fc830a83 | 5815 | /* Function to keep ARM specific flags in the ELF header. */ |
3c9458e9 | 5816 | |
b34976b6 | 5817 | static bfd_boolean |
57e8b36a | 5818 | elf32_arm_set_private_flags (bfd *abfd, flagword flags) |
252b5132 RH |
5819 | { |
5820 | if (elf_flags_init (abfd) | |
5821 | && elf_elfheader (abfd)->e_flags != flags) | |
5822 | { | |
fc830a83 NC |
5823 | if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) |
5824 | { | |
fd2ec330 | 5825 | if (flags & EF_ARM_INTERWORK) |
d003868e AM |
5826 | (*_bfd_error_handler) |
5827 | (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), | |
5828 | abfd); | |
fc830a83 | 5829 | else |
d003868e AM |
5830 | _bfd_error_handler |
5831 | (_("Warning: Clearing the interworking flag of %B due to outside request"), | |
5832 | abfd); | |
fc830a83 | 5833 | } |
252b5132 RH |
5834 | } |
5835 | else | |
5836 | { | |
5837 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 | 5838 | elf_flags_init (abfd) = TRUE; |
252b5132 RH |
5839 | } |
5840 | ||
b34976b6 | 5841 | return TRUE; |
252b5132 RH |
5842 | } |
5843 | ||
ee065d83 PB |
5844 | /* Copy the eabi object attribute from IBFD to OBFD. */ |
5845 | static void | |
5846 | copy_eabi_attributes (bfd *ibfd, bfd *obfd) | |
5847 | { | |
5848 | aeabi_attribute *in_attr; | |
5849 | aeabi_attribute *out_attr; | |
5850 | aeabi_attribute_list *list; | |
5851 | int i; | |
5852 | ||
5853 | in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes; | |
5854 | out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
5855 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5856 | { | |
5857 | out_attr->i = in_attr->i; | |
5858 | if (in_attr->s && *in_attr->s) | |
5859 | out_attr->s = attr_strdup (obfd, in_attr->s); | |
5860 | in_attr++; | |
5861 | out_attr++; | |
5862 | } | |
5863 | ||
5864 | for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
5865 | list; | |
5866 | list = list->next) | |
5867 | { | |
5868 | in_attr = &list->attr; | |
5869 | switch (in_attr->type) | |
5870 | { | |
5871 | case 1: | |
5872 | elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i); | |
5873 | break; | |
5874 | case 2: | |
5875 | elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s); | |
5876 | break; | |
5877 | case 3: | |
5878 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
5879 | break; | |
5880 | default: | |
5881 | abort(); | |
5882 | } | |
5883 | } | |
5884 | } | |
5885 | ||
5886 | ||
fc830a83 | 5887 | /* Copy backend specific data from one object module to another. */ |
9b485d32 | 5888 | |
b34976b6 | 5889 | static bfd_boolean |
57e8b36a | 5890 | elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 RH |
5891 | { |
5892 | flagword in_flags; | |
5893 | flagword out_flags; | |
5894 | ||
fc830a83 | 5895 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
252b5132 | 5896 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
b34976b6 | 5897 | return TRUE; |
252b5132 | 5898 | |
fc830a83 | 5899 | in_flags = elf_elfheader (ibfd)->e_flags; |
252b5132 RH |
5900 | out_flags = elf_elfheader (obfd)->e_flags; |
5901 | ||
fc830a83 NC |
5902 | if (elf_flags_init (obfd) |
5903 | && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN | |
5904 | && in_flags != out_flags) | |
252b5132 | 5905 | { |
252b5132 | 5906 | /* Cannot mix APCS26 and APCS32 code. */ |
fd2ec330 | 5907 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
b34976b6 | 5908 | return FALSE; |
252b5132 RH |
5909 | |
5910 | /* Cannot mix float APCS and non-float APCS code. */ | |
fd2ec330 | 5911 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
b34976b6 | 5912 | return FALSE; |
252b5132 RH |
5913 | |
5914 | /* If the src and dest have different interworking flags | |
5915 | then turn off the interworking bit. */ | |
fd2ec330 | 5916 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
252b5132 | 5917 | { |
fd2ec330 | 5918 | if (out_flags & EF_ARM_INTERWORK) |
d003868e AM |
5919 | _bfd_error_handler |
5920 | (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), | |
5921 | obfd, ibfd); | |
252b5132 | 5922 | |
fd2ec330 | 5923 | in_flags &= ~EF_ARM_INTERWORK; |
252b5132 | 5924 | } |
1006ba19 PB |
5925 | |
5926 | /* Likewise for PIC, though don't warn for this case. */ | |
fd2ec330 PB |
5927 | if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) |
5928 | in_flags &= ~EF_ARM_PIC; | |
252b5132 RH |
5929 | } |
5930 | ||
5931 | elf_elfheader (obfd)->e_flags = in_flags; | |
b34976b6 | 5932 | elf_flags_init (obfd) = TRUE; |
252b5132 | 5933 | |
94a3258f PB |
5934 | /* Also copy the EI_OSABI field. */ |
5935 | elf_elfheader (obfd)->e_ident[EI_OSABI] = | |
5936 | elf_elfheader (ibfd)->e_ident[EI_OSABI]; | |
5937 | ||
ee065d83 PB |
5938 | /* Copy EABI object attributes. */ |
5939 | copy_eabi_attributes (ibfd, obfd); | |
5940 | ||
5941 | return TRUE; | |
5942 | } | |
5943 | ||
5944 | /* Values for Tag_ABI_PCS_R9_use. */ | |
5945 | enum | |
5946 | { | |
5947 | AEABI_R9_V6, | |
5948 | AEABI_R9_SB, | |
5949 | AEABI_R9_TLS, | |
5950 | AEABI_R9_unused | |
5951 | }; | |
5952 | ||
5953 | /* Values for Tag_ABI_PCS_RW_data. */ | |
5954 | enum | |
5955 | { | |
5956 | AEABI_PCS_RW_data_absolute, | |
5957 | AEABI_PCS_RW_data_PCrel, | |
5958 | AEABI_PCS_RW_data_SBrel, | |
5959 | AEABI_PCS_RW_data_unused | |
5960 | }; | |
5961 | ||
5962 | /* Values for Tag_ABI_enum_size. */ | |
5963 | enum | |
5964 | { | |
5965 | AEABI_enum_unused, | |
5966 | AEABI_enum_short, | |
5967 | AEABI_enum_wide, | |
5968 | AEABI_enum_forced_wide | |
5969 | }; | |
5970 | ||
5971 | /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there | |
5972 | are conflicting attributes. */ | |
5973 | static bfd_boolean | |
5974 | elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd) | |
5975 | { | |
5976 | aeabi_attribute *in_attr; | |
5977 | aeabi_attribute *out_attr; | |
5978 | aeabi_attribute_list *in_list; | |
5979 | aeabi_attribute_list *out_list; | |
5980 | /* Some tags have 0 = don't care, 1 = strong requirement, | |
5981 | 2 = weak requirement. */ | |
5982 | static const int order_312[3] = {3, 1, 2}; | |
5983 | int i; | |
5984 | ||
5985 | if (!elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i) | |
5986 | { | |
5987 | /* This is the first object. Copy the attributes. */ | |
5988 | copy_eabi_attributes (ibfd, obfd); | |
5989 | return TRUE; | |
5990 | } | |
5991 | ||
5992 | /* Use the Tag_null value to indicate the attributes have been | |
5993 | initialized. */ | |
5994 | elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i = 1; | |
5995 | ||
5996 | in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes; | |
5997 | out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
5998 | /* This needs to happen before Tag_ABI_FP_number_model is merged. */ | |
5999 | if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i) | |
6000 | { | |
6001 | /* Ignore mismatches if teh object doesn't use floating point. */ | |
6002 | if (out_attr[Tag_ABI_FP_number_model].i == 0) | |
6003 | out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i; | |
6004 | else if (in_attr[Tag_ABI_FP_number_model].i != 0) | |
6005 | { | |
6006 | _bfd_error_handler | |
6007 | (_("ERROR: %B uses VFP register arguments, %B does not"), | |
6008 | ibfd, obfd); | |
6009 | return FALSE; | |
6010 | } | |
6011 | } | |
6012 | ||
6013 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
6014 | { | |
6015 | /* Merge this attribute with existing attributes. */ | |
6016 | switch (i) | |
6017 | { | |
6018 | case Tag_CPU_raw_name: | |
6019 | case Tag_CPU_name: | |
6020 | /* Use whichever has the greatest architecture requirements. */ | |
6021 | if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i) | |
6022 | out_attr[i].s = attr_strdup(obfd, in_attr[i].s); | |
6023 | break; | |
6024 | ||
6025 | case Tag_ABI_optimization_goals: | |
6026 | case Tag_ABI_FP_optimization_goals: | |
6027 | /* Use the first value seen. */ | |
6028 | break; | |
6029 | ||
6030 | case Tag_CPU_arch: | |
6031 | case Tag_ARM_ISA_use: | |
6032 | case Tag_THUMB_ISA_use: | |
6033 | case Tag_VFP_arch: | |
6034 | case Tag_WMMX_arch: | |
6035 | case Tag_NEON_arch: | |
6036 | /* ??? Do NEON and WMMX conflict? */ | |
6037 | case Tag_ABI_FP_rounding: | |
6038 | case Tag_ABI_FP_denormal: | |
6039 | case Tag_ABI_FP_exceptions: | |
6040 | case Tag_ABI_FP_user_exceptions: | |
6041 | case Tag_ABI_FP_number_model: | |
6042 | case Tag_ABI_align8_preserved: | |
6043 | case Tag_ABI_HardFP_use: | |
6044 | /* Use the largest value specified. */ | |
6045 | if (in_attr[i].i > out_attr[i].i) | |
6046 | out_attr[i].i = in_attr[i].i; | |
6047 | break; | |
6048 | ||
6049 | case Tag_CPU_arch_profile: | |
6050 | /* Warn if conflicting architecture profiles used. */ | |
6051 | if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i) | |
6052 | { | |
6053 | _bfd_error_handler | |
6054 | (_("ERROR: %B: Conflicting architecture profiles %c/%c"), | |
6055 | ibfd, in_attr[i].i, out_attr[i].i); | |
6056 | return FALSE; | |
6057 | } | |
6058 | if (in_attr[i].i) | |
6059 | out_attr[i].i = in_attr[i].i; | |
6060 | break; | |
6061 | case Tag_PCS_config: | |
6062 | if (out_attr[i].i == 0) | |
6063 | out_attr[i].i = in_attr[i].i; | |
6064 | else if (in_attr[i].i != 0 && out_attr[i].i != 0) | |
6065 | { | |
6066 | /* It's sometimes ok to mix different configs, so this is only | |
6067 | a warning. */ | |
6068 | _bfd_error_handler | |
6069 | (_("Warning: %B: Conflicting platform configuration"), ibfd); | |
6070 | } | |
6071 | break; | |
6072 | case Tag_ABI_PCS_R9_use: | |
6073 | if (out_attr[i].i != AEABI_R9_unused | |
6074 | && in_attr[i].i != AEABI_R9_unused) | |
6075 | { | |
6076 | _bfd_error_handler | |
6077 | (_("ERROR: %B: Conflicting use of R9"), ibfd); | |
6078 | return FALSE; | |
6079 | } | |
6080 | if (out_attr[i].i == AEABI_R9_unused) | |
6081 | out_attr[i].i = in_attr[i].i; | |
6082 | break; | |
6083 | case Tag_ABI_PCS_RW_data: | |
6084 | if (in_attr[i].i == AEABI_PCS_RW_data_SBrel | |
6085 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB | |
6086 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused) | |
6087 | { | |
6088 | _bfd_error_handler | |
6089 | (_("ERROR: %B: SB relative addressing conflicts with use of R9"), | |
6090 | ibfd); | |
6091 | return FALSE; | |
6092 | } | |
6093 | /* Use the smallest value specified. */ | |
6094 | if (in_attr[i].i < out_attr[i].i) | |
6095 | out_attr[i].i = in_attr[i].i; | |
6096 | break; | |
6097 | case Tag_ABI_PCS_RO_data: | |
6098 | /* Use the smallest value specified. */ | |
6099 | if (in_attr[i].i < out_attr[i].i) | |
6100 | out_attr[i].i = in_attr[i].i; | |
6101 | break; | |
6102 | case Tag_ABI_PCS_GOT_use: | |
6103 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
6104 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
6105 | out_attr[i].i = in_attr[i].i; | |
6106 | break; | |
6107 | case Tag_ABI_PCS_wchar_t: | |
6108 | if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i) | |
6109 | { | |
6110 | _bfd_error_handler | |
6111 | (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd); | |
6112 | return FALSE; | |
6113 | } | |
6114 | if (in_attr[i].i) | |
6115 | out_attr[i].i = in_attr[i].i; | |
6116 | break; | |
6117 | case Tag_ABI_align8_needed: | |
6118 | /* ??? Check against Tag_ABI_align8_preserved. */ | |
6119 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
6120 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
6121 | out_attr[i].i = in_attr[i].i; | |
6122 | break; | |
6123 | case Tag_ABI_enum_size: | |
6124 | if (in_attr[i].i != AEABI_enum_unused) | |
6125 | { | |
6126 | if (out_attr[i].i == AEABI_enum_unused | |
6127 | || out_attr[i].i == AEABI_enum_forced_wide) | |
6128 | { | |
6129 | /* The existing object is compatible with anything. | |
6130 | Use whatever requirements the new object has. */ | |
6131 | out_attr[i].i = in_attr[i].i; | |
6132 | } | |
6133 | else if (in_attr[i].i != AEABI_enum_forced_wide | |
6134 | && out_attr[i].i != in_attr[i].i) | |
6135 | { | |
6136 | _bfd_error_handler | |
6137 | (_("ERROR: %B: Conflicting enum sizes"), ibfd); | |
6138 | } | |
6139 | } | |
6140 | break; | |
6141 | case Tag_ABI_VFP_args: | |
6142 | /* Aready done. */ | |
6143 | break; | |
6144 | case Tag_ABI_WMMX_args: | |
6145 | if (in_attr[i].i != out_attr[i].i) | |
6146 | { | |
6147 | _bfd_error_handler | |
6148 | (_("ERROR: %B uses iWMMXt register arguments, %B does not"), | |
6149 | ibfd, obfd); | |
6150 | return FALSE; | |
6151 | } | |
6152 | break; | |
6153 | default: /* All known attributes should be explicitly covered. */ | |
6154 | abort (); | |
6155 | } | |
6156 | } | |
6157 | ||
6158 | in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
6159 | out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
6160 | while (in_list && in_list->tag == Tag_compatibility) | |
6161 | { | |
6162 | in_attr = &in_list->attr; | |
6163 | if (in_attr->i == 0) | |
6164 | continue; | |
6165 | if (in_attr->i == 1) | |
6166 | { | |
6167 | _bfd_error_handler | |
6168 | (_("ERROR: %B: Must be processed by '%s' toolchain"), | |
6169 | ibfd, in_attr->s); | |
6170 | return FALSE; | |
6171 | } | |
6172 | if (!out_list || out_list->tag != Tag_compatibility | |
6173 | || strcmp (in_attr->s, out_list->attr.s) != 0) | |
6174 | { | |
6175 | /* Add this compatibility tag to the output. */ | |
6176 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
6177 | continue; | |
6178 | } | |
6179 | out_attr = &out_list->attr; | |
6180 | /* Check all the input tags with the same identifier. */ | |
6181 | for (;;) | |
6182 | { | |
6183 | if (out_list->tag != Tag_compatibility | |
6184 | || in_attr->i != out_attr->i | |
6185 | || strcmp (in_attr->s, out_attr->s) != 0) | |
6186 | { | |
6187 | _bfd_error_handler | |
6188 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
6189 | ibfd, in_attr->s, in_attr->i); | |
6190 | return FALSE; | |
6191 | } | |
6192 | in_list = in_list->next; | |
6193 | if (in_list->tag != Tag_compatibility | |
6194 | || strcmp (in_attr->s, in_list->attr.s) != 0) | |
6195 | break; | |
6196 | in_attr = &in_list->attr; | |
6197 | out_list = out_list->next; | |
6198 | if (out_list) | |
6199 | out_attr = &out_list->attr; | |
6200 | } | |
6201 | ||
6202 | /* Check the output doesn't have extra tags with this identifier. */ | |
6203 | if (out_list && out_list->tag == Tag_compatibility | |
6204 | && strcmp (in_attr->s, out_list->attr.s) == 0) | |
6205 | { | |
6206 | _bfd_error_handler | |
6207 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
6208 | ibfd, in_attr->s, out_list->attr.i); | |
6209 | return FALSE; | |
6210 | } | |
6211 | } | |
6212 | ||
6213 | for (; in_list; in_list = in_list->next) | |
6214 | { | |
6215 | if ((in_list->tag & 128) < 64) | |
eb111b1f BE |
6216 | { |
6217 | _bfd_error_handler | |
6218 | (_("Warning: %B: Unknown EABI object attribute %d"), | |
6219 | ibfd, in_list->tag); | |
6220 | break; | |
6221 | } | |
ee065d83 | 6222 | } |
b34976b6 | 6223 | return TRUE; |
252b5132 RH |
6224 | } |
6225 | ||
3a4a14e9 PB |
6226 | |
6227 | /* Return TRUE if the two EABI versions are incompatible. */ | |
6228 | ||
6229 | static bfd_boolean | |
6230 | elf32_arm_versions_compatible (unsigned iver, unsigned over) | |
6231 | { | |
6232 | /* v4 and v5 are the same spec before and after it was released, | |
6233 | so allow mixing them. */ | |
6234 | if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5) | |
6235 | || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4)) | |
6236 | return TRUE; | |
6237 | ||
6238 | return (iver == over); | |
6239 | } | |
6240 | ||
252b5132 RH |
6241 | /* Merge backend specific data from an object file to the output |
6242 | object file when linking. */ | |
9b485d32 | 6243 | |
b34976b6 | 6244 | static bfd_boolean |
57e8b36a | 6245 | elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
252b5132 RH |
6246 | { |
6247 | flagword out_flags; | |
6248 | flagword in_flags; | |
b34976b6 | 6249 | bfd_boolean flags_compatible = TRUE; |
cf919dfd | 6250 | asection *sec; |
252b5132 | 6251 | |
9b485d32 | 6252 | /* Check if we have the same endianess. */ |
82e51918 | 6253 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 6254 | return FALSE; |
1fe494a5 | 6255 | |
252b5132 RH |
6256 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
6257 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 6258 | return TRUE; |
252b5132 | 6259 | |
ee065d83 PB |
6260 | if (!elf32_arm_merge_eabi_attributes (ibfd, obfd)) |
6261 | return FALSE; | |
6262 | ||
252b5132 RH |
6263 | /* The input BFD must have had its flags initialised. */ |
6264 | /* The following seems bogus to me -- The flags are initialized in | |
6265 | the assembler but I don't think an elf_flags_init field is | |
9b485d32 | 6266 | written into the object. */ |
252b5132 RH |
6267 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
6268 | ||
6269 | in_flags = elf_elfheader (ibfd)->e_flags; | |
6270 | out_flags = elf_elfheader (obfd)->e_flags; | |
6271 | ||
6272 | if (!elf_flags_init (obfd)) | |
6273 | { | |
fe077fa6 NC |
6274 | /* If the input is the default architecture and had the default |
6275 | flags then do not bother setting the flags for the output | |
6276 | architecture, instead allow future merges to do this. If no | |
6277 | future merges ever set these flags then they will retain their | |
6278 | uninitialised values, which surprise surprise, correspond | |
252b5132 | 6279 | to the default values. */ |
fe077fa6 NC |
6280 | if (bfd_get_arch_info (ibfd)->the_default |
6281 | && elf_elfheader (ibfd)->e_flags == 0) | |
b34976b6 | 6282 | return TRUE; |
252b5132 | 6283 | |
b34976b6 | 6284 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
6285 | elf_elfheader (obfd)->e_flags = in_flags; |
6286 | ||
6287 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
6288 | && bfd_get_arch_info (obfd)->the_default) | |
6289 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); | |
6290 | ||
b34976b6 | 6291 | return TRUE; |
252b5132 RH |
6292 | } |
6293 | ||
5a6c6817 NC |
6294 | /* Determine what should happen if the input ARM architecture |
6295 | does not match the output ARM architecture. */ | |
6296 | if (! bfd_arm_merge_machines (ibfd, obfd)) | |
6297 | return FALSE; | |
e16bb312 | 6298 | |
1006ba19 | 6299 | /* Identical flags must be compatible. */ |
252b5132 | 6300 | if (in_flags == out_flags) |
b34976b6 | 6301 | return TRUE; |
252b5132 | 6302 | |
35a0f415 DJ |
6303 | /* Check to see if the input BFD actually contains any sections. If |
6304 | not, its flags may not have been initialised either, but it | |
8e3de13a | 6305 | cannot actually cause any incompatiblity. Do not short-circuit |
35a0f415 | 6306 | dynamic objects; their section list may be emptied by |
d1f161ea | 6307 | elf_link_add_object_symbols. |
35a0f415 | 6308 | |
d1f161ea NC |
6309 | Also check to see if there are no code sections in the input. |
6310 | In this case there is no need to check for code specific flags. | |
6311 | XXX - do we need to worry about floating-point format compatability | |
6312 | in data sections ? */ | |
35a0f415 | 6313 | if (!(ibfd->flags & DYNAMIC)) |
cf919dfd | 6314 | { |
35a0f415 | 6315 | bfd_boolean null_input_bfd = TRUE; |
d1f161ea | 6316 | bfd_boolean only_data_sections = TRUE; |
35a0f415 DJ |
6317 | |
6318 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
cf919dfd | 6319 | { |
35a0f415 DJ |
6320 | /* Ignore synthetic glue sections. */ |
6321 | if (strcmp (sec->name, ".glue_7") | |
6322 | && strcmp (sec->name, ".glue_7t")) | |
6323 | { | |
d1f161ea NC |
6324 | if ((bfd_get_section_flags (ibfd, sec) |
6325 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
6326 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
6327 | only_data_sections = FALSE; | |
6328 | ||
35a0f415 DJ |
6329 | null_input_bfd = FALSE; |
6330 | break; | |
6331 | } | |
cf919dfd | 6332 | } |
d1f161ea NC |
6333 | |
6334 | if (null_input_bfd || only_data_sections) | |
35a0f415 | 6335 | return TRUE; |
cf919dfd | 6336 | } |
cf919dfd | 6337 | |
252b5132 | 6338 | /* Complain about various flag mismatches. */ |
3a4a14e9 PB |
6339 | if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags), |
6340 | EF_ARM_EABI_VERSION (out_flags))) | |
fc830a83 | 6341 | { |
d003868e | 6342 | _bfd_error_handler |
3656d5e3 | 6343 | (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"), |
d003868e AM |
6344 | ibfd, obfd, |
6345 | (in_flags & EF_ARM_EABIMASK) >> 24, | |
6346 | (out_flags & EF_ARM_EABIMASK) >> 24); | |
b34976b6 | 6347 | return FALSE; |
fc830a83 | 6348 | } |
252b5132 | 6349 | |
1006ba19 | 6350 | /* Not sure what needs to be checked for EABI versions >= 1. */ |
00a97672 RS |
6351 | /* VxWorks libraries do not use these flags. */ |
6352 | if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed | |
6353 | && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed | |
6354 | && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) | |
1006ba19 | 6355 | { |
fd2ec330 | 6356 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
1006ba19 | 6357 | { |
d003868e AM |
6358 | _bfd_error_handler |
6359 | (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), | |
6360 | ibfd, obfd, | |
6361 | in_flags & EF_ARM_APCS_26 ? 26 : 32, | |
6362 | out_flags & EF_ARM_APCS_26 ? 26 : 32); | |
b34976b6 | 6363 | flags_compatible = FALSE; |
1006ba19 | 6364 | } |
252b5132 | 6365 | |
fd2ec330 | 6366 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
1006ba19 | 6367 | { |
5eefb65f | 6368 | if (in_flags & EF_ARM_APCS_FLOAT) |
d003868e AM |
6369 | _bfd_error_handler |
6370 | (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), | |
6371 | ibfd, obfd); | |
5eefb65f | 6372 | else |
d003868e AM |
6373 | _bfd_error_handler |
6374 | (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), | |
6375 | ibfd, obfd); | |
63b0f745 | 6376 | |
b34976b6 | 6377 | flags_compatible = FALSE; |
1006ba19 | 6378 | } |
252b5132 | 6379 | |
96a846ea | 6380 | if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) |
1006ba19 | 6381 | { |
96a846ea | 6382 | if (in_flags & EF_ARM_VFP_FLOAT) |
d003868e AM |
6383 | _bfd_error_handler |
6384 | (_("ERROR: %B uses VFP instructions, whereas %B does not"), | |
6385 | ibfd, obfd); | |
5eefb65f | 6386 | else |
d003868e AM |
6387 | _bfd_error_handler |
6388 | (_("ERROR: %B uses FPA instructions, whereas %B does not"), | |
6389 | ibfd, obfd); | |
fde78edd NC |
6390 | |
6391 | flags_compatible = FALSE; | |
6392 | } | |
6393 | ||
6394 | if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) | |
6395 | { | |
6396 | if (in_flags & EF_ARM_MAVERICK_FLOAT) | |
d003868e AM |
6397 | _bfd_error_handler |
6398 | (_("ERROR: %B uses Maverick instructions, whereas %B does not"), | |
6399 | ibfd, obfd); | |
fde78edd | 6400 | else |
d003868e AM |
6401 | _bfd_error_handler |
6402 | (_("ERROR: %B does not use Maverick instructions, whereas %B does"), | |
6403 | ibfd, obfd); | |
63b0f745 | 6404 | |
b34976b6 | 6405 | flags_compatible = FALSE; |
1006ba19 | 6406 | } |
96a846ea RE |
6407 | |
6408 | #ifdef EF_ARM_SOFT_FLOAT | |
6409 | if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) | |
6410 | { | |
6411 | /* We can allow interworking between code that is VFP format | |
6412 | layout, and uses either soft float or integer regs for | |
6413 | passing floating point arguments and results. We already | |
6414 | know that the APCS_FLOAT flags match; similarly for VFP | |
6415 | flags. */ | |
6416 | if ((in_flags & EF_ARM_APCS_FLOAT) != 0 | |
6417 | || (in_flags & EF_ARM_VFP_FLOAT) == 0) | |
6418 | { | |
6419 | if (in_flags & EF_ARM_SOFT_FLOAT) | |
d003868e AM |
6420 | _bfd_error_handler |
6421 | (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), | |
6422 | ibfd, obfd); | |
96a846ea | 6423 | else |
d003868e AM |
6424 | _bfd_error_handler |
6425 | (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), | |
6426 | ibfd, obfd); | |
96a846ea | 6427 | |
b34976b6 | 6428 | flags_compatible = FALSE; |
96a846ea RE |
6429 | } |
6430 | } | |
ee43f35e | 6431 | #endif |
252b5132 | 6432 | |
1006ba19 | 6433 | /* Interworking mismatch is only a warning. */ |
fd2ec330 | 6434 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
8f615d07 | 6435 | { |
e3c8793a NC |
6436 | if (in_flags & EF_ARM_INTERWORK) |
6437 | { | |
d003868e AM |
6438 | _bfd_error_handler |
6439 | (_("Warning: %B supports interworking, whereas %B does not"), | |
6440 | ibfd, obfd); | |
e3c8793a NC |
6441 | } |
6442 | else | |
6443 | { | |
d003868e AM |
6444 | _bfd_error_handler |
6445 | (_("Warning: %B does not support interworking, whereas %B does"), | |
6446 | ibfd, obfd); | |
e3c8793a | 6447 | } |
8f615d07 | 6448 | } |
252b5132 | 6449 | } |
63b0f745 | 6450 | |
1006ba19 | 6451 | return flags_compatible; |
252b5132 RH |
6452 | } |
6453 | ||
9b485d32 NC |
6454 | /* Display the flags field. */ |
6455 | ||
b34976b6 | 6456 | static bfd_boolean |
57e8b36a | 6457 | elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) |
252b5132 | 6458 | { |
fc830a83 NC |
6459 | FILE * file = (FILE *) ptr; |
6460 | unsigned long flags; | |
252b5132 RH |
6461 | |
6462 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
6463 | ||
6464 | /* Print normal ELF private data. */ | |
6465 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
6466 | ||
fc830a83 | 6467 | flags = elf_elfheader (abfd)->e_flags; |
9b485d32 NC |
6468 | /* Ignore init flag - it may not be set, despite the flags field |
6469 | containing valid data. */ | |
252b5132 RH |
6470 | |
6471 | /* xgettext:c-format */ | |
9b485d32 | 6472 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
252b5132 | 6473 | |
fc830a83 NC |
6474 | switch (EF_ARM_EABI_VERSION (flags)) |
6475 | { | |
6476 | case EF_ARM_EABI_UNKNOWN: | |
4cc11e76 | 6477 | /* The following flag bits are GNU extensions and not part of the |
fc830a83 NC |
6478 | official ARM ELF extended ABI. Hence they are only decoded if |
6479 | the EABI version is not set. */ | |
fd2ec330 | 6480 | if (flags & EF_ARM_INTERWORK) |
9b485d32 | 6481 | fprintf (file, _(" [interworking enabled]")); |
9a5aca8c | 6482 | |
fd2ec330 | 6483 | if (flags & EF_ARM_APCS_26) |
6c571f00 | 6484 | fprintf (file, " [APCS-26]"); |
fc830a83 | 6485 | else |
6c571f00 | 6486 | fprintf (file, " [APCS-32]"); |
9a5aca8c | 6487 | |
96a846ea RE |
6488 | if (flags & EF_ARM_VFP_FLOAT) |
6489 | fprintf (file, _(" [VFP float format]")); | |
fde78edd NC |
6490 | else if (flags & EF_ARM_MAVERICK_FLOAT) |
6491 | fprintf (file, _(" [Maverick float format]")); | |
96a846ea RE |
6492 | else |
6493 | fprintf (file, _(" [FPA float format]")); | |
6494 | ||
fd2ec330 | 6495 | if (flags & EF_ARM_APCS_FLOAT) |
9b485d32 | 6496 | fprintf (file, _(" [floats passed in float registers]")); |
9a5aca8c | 6497 | |
fd2ec330 | 6498 | if (flags & EF_ARM_PIC) |
9b485d32 | 6499 | fprintf (file, _(" [position independent]")); |
fc830a83 | 6500 | |
fd2ec330 | 6501 | if (flags & EF_ARM_NEW_ABI) |
9b485d32 | 6502 | fprintf (file, _(" [new ABI]")); |
9a5aca8c | 6503 | |
fd2ec330 | 6504 | if (flags & EF_ARM_OLD_ABI) |
9b485d32 | 6505 | fprintf (file, _(" [old ABI]")); |
9a5aca8c | 6506 | |
fd2ec330 | 6507 | if (flags & EF_ARM_SOFT_FLOAT) |
9b485d32 | 6508 | fprintf (file, _(" [software FP]")); |
9a5aca8c | 6509 | |
96a846ea RE |
6510 | flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT |
6511 | | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI | |
fde78edd NC |
6512 | | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT |
6513 | | EF_ARM_MAVERICK_FLOAT); | |
fc830a83 | 6514 | break; |
9a5aca8c | 6515 | |
fc830a83 | 6516 | case EF_ARM_EABI_VER1: |
9b485d32 | 6517 | fprintf (file, _(" [Version1 EABI]")); |
9a5aca8c | 6518 | |
fc830a83 | 6519 | if (flags & EF_ARM_SYMSARESORTED) |
9b485d32 | 6520 | fprintf (file, _(" [sorted symbol table]")); |
fc830a83 | 6521 | else |
9b485d32 | 6522 | fprintf (file, _(" [unsorted symbol table]")); |
9a5aca8c | 6523 | |
fc830a83 NC |
6524 | flags &= ~ EF_ARM_SYMSARESORTED; |
6525 | break; | |
9a5aca8c | 6526 | |
fd2ec330 PB |
6527 | case EF_ARM_EABI_VER2: |
6528 | fprintf (file, _(" [Version2 EABI]")); | |
6529 | ||
6530 | if (flags & EF_ARM_SYMSARESORTED) | |
6531 | fprintf (file, _(" [sorted symbol table]")); | |
6532 | else | |
6533 | fprintf (file, _(" [unsorted symbol table]")); | |
6534 | ||
6535 | if (flags & EF_ARM_DYNSYMSUSESEGIDX) | |
6536 | fprintf (file, _(" [dynamic symbols use segment index]")); | |
6537 | ||
6538 | if (flags & EF_ARM_MAPSYMSFIRST) | |
6539 | fprintf (file, _(" [mapping symbols precede others]")); | |
6540 | ||
99e4ae17 | 6541 | flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX |
fd2ec330 PB |
6542 | | EF_ARM_MAPSYMSFIRST); |
6543 | break; | |
6544 | ||
d507cf36 PB |
6545 | case EF_ARM_EABI_VER3: |
6546 | fprintf (file, _(" [Version3 EABI]")); | |
8cb51566 PB |
6547 | break; |
6548 | ||
6549 | case EF_ARM_EABI_VER4: | |
6550 | fprintf (file, _(" [Version4 EABI]")); | |
3a4a14e9 | 6551 | goto eabi; |
d507cf36 | 6552 | |
3a4a14e9 PB |
6553 | case EF_ARM_EABI_VER5: |
6554 | fprintf (file, _(" [Version5 EABI]")); | |
6555 | eabi: | |
d507cf36 PB |
6556 | if (flags & EF_ARM_BE8) |
6557 | fprintf (file, _(" [BE8]")); | |
6558 | ||
6559 | if (flags & EF_ARM_LE8) | |
6560 | fprintf (file, _(" [LE8]")); | |
6561 | ||
6562 | flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); | |
6563 | break; | |
6564 | ||
fc830a83 | 6565 | default: |
9b485d32 | 6566 | fprintf (file, _(" <EABI version unrecognised>")); |
fc830a83 NC |
6567 | break; |
6568 | } | |
252b5132 | 6569 | |
fc830a83 | 6570 | flags &= ~ EF_ARM_EABIMASK; |
252b5132 | 6571 | |
fc830a83 | 6572 | if (flags & EF_ARM_RELEXEC) |
9b485d32 | 6573 | fprintf (file, _(" [relocatable executable]")); |
252b5132 | 6574 | |
fc830a83 | 6575 | if (flags & EF_ARM_HASENTRY) |
9b485d32 | 6576 | fprintf (file, _(" [has entry point]")); |
252b5132 | 6577 | |
fc830a83 NC |
6578 | flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); |
6579 | ||
6580 | if (flags) | |
9b485d32 | 6581 | fprintf (file, _("<Unrecognised flag bits set>")); |
9a5aca8c | 6582 | |
252b5132 RH |
6583 | fputc ('\n', file); |
6584 | ||
b34976b6 | 6585 | return TRUE; |
252b5132 RH |
6586 | } |
6587 | ||
6588 | static int | |
57e8b36a | 6589 | elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
252b5132 | 6590 | { |
2f0ca46a NC |
6591 | switch (ELF_ST_TYPE (elf_sym->st_info)) |
6592 | { | |
6593 | case STT_ARM_TFUNC: | |
6594 | return ELF_ST_TYPE (elf_sym->st_info); | |
ce855c42 | 6595 | |
2f0ca46a NC |
6596 | case STT_ARM_16BIT: |
6597 | /* If the symbol is not an object, return the STT_ARM_16BIT flag. | |
6598 | This allows us to distinguish between data used by Thumb instructions | |
6599 | and non-data (which is probably code) inside Thumb regions of an | |
6600 | executable. */ | |
1a0eb693 | 6601 | if (type != STT_OBJECT && type != STT_TLS) |
2f0ca46a NC |
6602 | return ELF_ST_TYPE (elf_sym->st_info); |
6603 | break; | |
9a5aca8c | 6604 | |
ce855c42 NC |
6605 | default: |
6606 | break; | |
2f0ca46a NC |
6607 | } |
6608 | ||
6609 | return type; | |
252b5132 | 6610 | } |
f21f3fe0 | 6611 | |
252b5132 | 6612 | static asection * |
57e8b36a NC |
6613 | elf32_arm_gc_mark_hook (asection * sec, |
6614 | struct bfd_link_info * info ATTRIBUTE_UNUSED, | |
6615 | Elf_Internal_Rela * rel, | |
6616 | struct elf_link_hash_entry * h, | |
6617 | Elf_Internal_Sym * sym) | |
252b5132 RH |
6618 | { |
6619 | if (h != NULL) | |
6620 | { | |
6621 | switch (ELF32_R_TYPE (rel->r_info)) | |
6622 | { | |
6623 | case R_ARM_GNU_VTINHERIT: | |
6624 | case R_ARM_GNU_VTENTRY: | |
6625 | break; | |
6626 | ||
6627 | default: | |
6628 | switch (h->root.type) | |
6629 | { | |
6630 | case bfd_link_hash_defined: | |
6631 | case bfd_link_hash_defweak: | |
6632 | return h->root.u.def.section; | |
6633 | ||
6634 | case bfd_link_hash_common: | |
6635 | return h->root.u.c.p->section; | |
e049a0de ILT |
6636 | |
6637 | default: | |
6638 | break; | |
252b5132 RH |
6639 | } |
6640 | } | |
6641 | } | |
6642 | else | |
1e2f5b6e | 6643 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
9ad5cbcf | 6644 | |
252b5132 RH |
6645 | return NULL; |
6646 | } | |
6647 | ||
780a67af NC |
6648 | /* Update the got entry reference counts for the section being removed. */ |
6649 | ||
b34976b6 | 6650 | static bfd_boolean |
ba93b8ac DJ |
6651 | elf32_arm_gc_sweep_hook (bfd * abfd, |
6652 | struct bfd_link_info * info, | |
6653 | asection * sec, | |
6654 | const Elf_Internal_Rela * relocs) | |
252b5132 | 6655 | { |
5e681ec4 PB |
6656 | Elf_Internal_Shdr *symtab_hdr; |
6657 | struct elf_link_hash_entry **sym_hashes; | |
6658 | bfd_signed_vma *local_got_refcounts; | |
6659 | const Elf_Internal_Rela *rel, *relend; | |
eb043451 PB |
6660 | struct elf32_arm_link_hash_table * globals; |
6661 | ||
6662 | globals = elf32_arm_hash_table (info); | |
5e681ec4 PB |
6663 | |
6664 | elf_section_data (sec)->local_dynrel = NULL; | |
6665 | ||
6666 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
6667 | sym_hashes = elf_sym_hashes (abfd); | |
6668 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
6669 | ||
6670 | relend = relocs + sec->reloc_count; | |
6671 | for (rel = relocs; rel < relend; rel++) | |
eb043451 | 6672 | { |
3eb128b2 AM |
6673 | unsigned long r_symndx; |
6674 | struct elf_link_hash_entry *h = NULL; | |
eb043451 | 6675 | int r_type; |
5e681ec4 | 6676 | |
3eb128b2 AM |
6677 | r_symndx = ELF32_R_SYM (rel->r_info); |
6678 | if (r_symndx >= symtab_hdr->sh_info) | |
6679 | { | |
6680 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
6681 | while (h->root.type == bfd_link_hash_indirect | |
6682 | || h->root.type == bfd_link_hash_warning) | |
6683 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6684 | } | |
6685 | ||
eb043451 | 6686 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 6687 | r_type = arm_real_reloc_type (globals, r_type); |
eb043451 PB |
6688 | switch (r_type) |
6689 | { | |
6690 | case R_ARM_GOT32: | |
eb043451 | 6691 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
6692 | case R_ARM_TLS_GD32: |
6693 | case R_ARM_TLS_IE32: | |
3eb128b2 | 6694 | if (h != NULL) |
eb043451 | 6695 | { |
eb043451 PB |
6696 | if (h->got.refcount > 0) |
6697 | h->got.refcount -= 1; | |
6698 | } | |
6699 | else if (local_got_refcounts != NULL) | |
6700 | { | |
6701 | if (local_got_refcounts[r_symndx] > 0) | |
6702 | local_got_refcounts[r_symndx] -= 1; | |
6703 | } | |
6704 | break; | |
6705 | ||
ba93b8ac DJ |
6706 | case R_ARM_TLS_LDM32: |
6707 | elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; | |
6708 | break; | |
6709 | ||
eb043451 PB |
6710 | case R_ARM_ABS32: |
6711 | case R_ARM_REL32: | |
6712 | case R_ARM_PC24: | |
6713 | case R_ARM_PLT32: | |
5b5bb741 PB |
6714 | case R_ARM_CALL: |
6715 | case R_ARM_JUMP24: | |
eb043451 | 6716 | case R_ARM_PREL31: |
c19d1205 | 6717 | case R_ARM_THM_CALL: |
b6895b4f PB |
6718 | case R_ARM_MOVW_ABS_NC: |
6719 | case R_ARM_MOVT_ABS: | |
6720 | case R_ARM_MOVW_PREL_NC: | |
6721 | case R_ARM_MOVT_PREL: | |
6722 | case R_ARM_THM_MOVW_ABS_NC: | |
6723 | case R_ARM_THM_MOVT_ABS: | |
6724 | case R_ARM_THM_MOVW_PREL_NC: | |
6725 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 DJ |
6726 | /* Should the interworking branches be here also? */ |
6727 | ||
3eb128b2 | 6728 | if (h != NULL) |
eb043451 PB |
6729 | { |
6730 | struct elf32_arm_link_hash_entry *eh; | |
6731 | struct elf32_arm_relocs_copied **pp; | |
6732 | struct elf32_arm_relocs_copied *p; | |
5e681ec4 | 6733 | |
b7693d02 | 6734 | eh = (struct elf32_arm_link_hash_entry *) h; |
5e681ec4 | 6735 | |
eb043451 | 6736 | if (h->plt.refcount > 0) |
b7693d02 DJ |
6737 | { |
6738 | h->plt.refcount -= 1; | |
c19d1205 | 6739 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL) |
b7693d02 DJ |
6740 | eh->plt_thumb_refcount--; |
6741 | } | |
5e681ec4 | 6742 | |
eb043451 | 6743 | if (r_type == R_ARM_ABS32 |
eb043451 PB |
6744 | || r_type == R_ARM_REL32) |
6745 | { | |
eb043451 PB |
6746 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; |
6747 | pp = &p->next) | |
6748 | if (p->section == sec) | |
6749 | { | |
6750 | p->count -= 1; | |
ba93b8ac DJ |
6751 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32) |
6752 | p->pc_count -= 1; | |
eb043451 PB |
6753 | if (p->count == 0) |
6754 | *pp = p->next; | |
6755 | break; | |
6756 | } | |
6757 | } | |
6758 | } | |
6759 | break; | |
5e681ec4 | 6760 | |
eb043451 PB |
6761 | default: |
6762 | break; | |
6763 | } | |
6764 | } | |
5e681ec4 | 6765 | |
b34976b6 | 6766 | return TRUE; |
252b5132 RH |
6767 | } |
6768 | ||
780a67af NC |
6769 | /* Look through the relocs for a section during the first phase. */ |
6770 | ||
b34976b6 | 6771 | static bfd_boolean |
57e8b36a NC |
6772 | elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, |
6773 | asection *sec, const Elf_Internal_Rela *relocs) | |
252b5132 | 6774 | { |
b34976b6 AM |
6775 | Elf_Internal_Shdr *symtab_hdr; |
6776 | struct elf_link_hash_entry **sym_hashes; | |
6777 | struct elf_link_hash_entry **sym_hashes_end; | |
6778 | const Elf_Internal_Rela *rel; | |
6779 | const Elf_Internal_Rela *rel_end; | |
6780 | bfd *dynobj; | |
5e681ec4 | 6781 | asection *sreloc; |
b34976b6 | 6782 | bfd_vma *local_got_offsets; |
5e681ec4 | 6783 | struct elf32_arm_link_hash_table *htab; |
9a5aca8c | 6784 | |
1049f94e | 6785 | if (info->relocatable) |
b34976b6 | 6786 | return TRUE; |
9a5aca8c | 6787 | |
5e681ec4 PB |
6788 | htab = elf32_arm_hash_table (info); |
6789 | sreloc = NULL; | |
9a5aca8c | 6790 | |
67687978 PB |
6791 | /* Create dynamic sections for relocatable executables so that we can |
6792 | copy relocations. */ | |
6793 | if (htab->root.is_relocatable_executable | |
6794 | && ! htab->root.dynamic_sections_created) | |
6795 | { | |
6796 | if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) | |
6797 | return FALSE; | |
6798 | } | |
6799 | ||
252b5132 RH |
6800 | dynobj = elf_hash_table (info)->dynobj; |
6801 | local_got_offsets = elf_local_got_offsets (abfd); | |
f21f3fe0 | 6802 | |
252b5132 RH |
6803 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
6804 | sym_hashes = elf_sym_hashes (abfd); | |
9b485d32 NC |
6805 | sym_hashes_end = sym_hashes |
6806 | + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); | |
6807 | ||
252b5132 RH |
6808 | if (!elf_bad_symtab (abfd)) |
6809 | sym_hashes_end -= symtab_hdr->sh_info; | |
9b485d32 | 6810 | |
252b5132 RH |
6811 | rel_end = relocs + sec->reloc_count; |
6812 | for (rel = relocs; rel < rel_end; rel++) | |
6813 | { | |
6814 | struct elf_link_hash_entry *h; | |
b7693d02 | 6815 | struct elf32_arm_link_hash_entry *eh; |
252b5132 | 6816 | unsigned long r_symndx; |
eb043451 | 6817 | int r_type; |
9a5aca8c | 6818 | |
252b5132 | 6819 | r_symndx = ELF32_R_SYM (rel->r_info); |
eb043451 | 6820 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 6821 | r_type = arm_real_reloc_type (htab, r_type); |
ba93b8ac DJ |
6822 | |
6823 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
6824 | { | |
6825 | (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd, | |
6826 | r_symndx); | |
6827 | return FALSE; | |
6828 | } | |
6829 | ||
252b5132 RH |
6830 | if (r_symndx < symtab_hdr->sh_info) |
6831 | h = NULL; | |
6832 | else | |
973a3492 L |
6833 | { |
6834 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
6835 | while (h->root.type == bfd_link_hash_indirect | |
6836 | || h->root.type == bfd_link_hash_warning) | |
6837 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6838 | } | |
9a5aca8c | 6839 | |
b7693d02 DJ |
6840 | eh = (struct elf32_arm_link_hash_entry *) h; |
6841 | ||
eb043451 | 6842 | switch (r_type) |
252b5132 | 6843 | { |
5e681ec4 | 6844 | case R_ARM_GOT32: |
eb043451 | 6845 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
6846 | case R_ARM_TLS_GD32: |
6847 | case R_ARM_TLS_IE32: | |
5e681ec4 | 6848 | /* This symbol requires a global offset table entry. */ |
ba93b8ac DJ |
6849 | { |
6850 | int tls_type, old_tls_type; | |
5e681ec4 | 6851 | |
ba93b8ac DJ |
6852 | switch (r_type) |
6853 | { | |
6854 | case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break; | |
6855 | case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break; | |
6856 | default: tls_type = GOT_NORMAL; break; | |
6857 | } | |
252b5132 | 6858 | |
ba93b8ac DJ |
6859 | if (h != NULL) |
6860 | { | |
6861 | h->got.refcount++; | |
6862 | old_tls_type = elf32_arm_hash_entry (h)->tls_type; | |
6863 | } | |
6864 | else | |
6865 | { | |
6866 | bfd_signed_vma *local_got_refcounts; | |
6867 | ||
6868 | /* This is a global offset table entry for a local symbol. */ | |
6869 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
6870 | if (local_got_refcounts == NULL) | |
6871 | { | |
6872 | bfd_size_type size; | |
6873 | ||
6874 | size = symtab_hdr->sh_info; | |
6875 | size *= (sizeof (bfd_signed_vma) + sizeof(char)); | |
6876 | local_got_refcounts = bfd_zalloc (abfd, size); | |
6877 | if (local_got_refcounts == NULL) | |
6878 | return FALSE; | |
6879 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
6880 | elf32_arm_local_got_tls_type (abfd) | |
6881 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
6882 | } | |
6883 | local_got_refcounts[r_symndx] += 1; | |
6884 | old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx]; | |
6885 | } | |
6886 | ||
6887 | /* We will already have issued an error message if there is a | |
6888 | TLS / non-TLS mismatch, based on the symbol type. We don't | |
6889 | support any linker relaxations. So just combine any TLS | |
6890 | types needed. */ | |
6891 | if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL | |
6892 | && tls_type != GOT_NORMAL) | |
6893 | tls_type |= old_tls_type; | |
6894 | ||
6895 | if (old_tls_type != tls_type) | |
6896 | { | |
6897 | if (h != NULL) | |
6898 | elf32_arm_hash_entry (h)->tls_type = tls_type; | |
6899 | else | |
6900 | elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
6901 | } | |
6902 | } | |
6903 | /* Fall through */ | |
6904 | ||
6905 | case R_ARM_TLS_LDM32: | |
6906 | if (r_type == R_ARM_TLS_LDM32) | |
6907 | htab->tls_ldm_got.refcount++; | |
6908 | /* Fall through */ | |
252b5132 | 6909 | |
c19d1205 | 6910 | case R_ARM_GOTOFF32: |
5e681ec4 PB |
6911 | case R_ARM_GOTPC: |
6912 | if (htab->sgot == NULL) | |
6913 | { | |
6914 | if (htab->root.dynobj == NULL) | |
6915 | htab->root.dynobj = abfd; | |
6916 | if (!create_got_section (htab->root.dynobj, info)) | |
6917 | return FALSE; | |
6918 | } | |
252b5132 RH |
6919 | break; |
6920 | ||
00a97672 RS |
6921 | case R_ARM_ABS12: |
6922 | /* VxWorks uses dynamic R_ARM_ABS12 relocations for | |
6923 | ldr __GOTT_INDEX__ offsets. */ | |
6924 | if (!htab->vxworks_p) | |
6925 | break; | |
6926 | /* Fall through */ | |
6927 | ||
252b5132 RH |
6928 | case R_ARM_ABS32: |
6929 | case R_ARM_REL32: | |
6930 | case R_ARM_PC24: | |
7359ea65 | 6931 | case R_ARM_PLT32: |
5b5bb741 PB |
6932 | case R_ARM_CALL: |
6933 | case R_ARM_JUMP24: | |
eb043451 | 6934 | case R_ARM_PREL31: |
c19d1205 | 6935 | case R_ARM_THM_CALL: |
b6895b4f PB |
6936 | case R_ARM_MOVW_ABS_NC: |
6937 | case R_ARM_MOVT_ABS: | |
6938 | case R_ARM_MOVW_PREL_NC: | |
6939 | case R_ARM_MOVT_PREL: | |
6940 | case R_ARM_THM_MOVW_ABS_NC: | |
6941 | case R_ARM_THM_MOVT_ABS: | |
6942 | case R_ARM_THM_MOVW_PREL_NC: | |
6943 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 | 6944 | /* Should the interworking branches be listed here? */ |
7359ea65 | 6945 | if (h != NULL) |
5e681ec4 PB |
6946 | { |
6947 | /* If this reloc is in a read-only section, we might | |
6948 | need a copy reloc. We can't check reliably at this | |
6949 | stage whether the section is read-only, as input | |
6950 | sections have not yet been mapped to output sections. | |
6951 | Tentatively set the flag for now, and correct in | |
6952 | adjust_dynamic_symbol. */ | |
7359ea65 | 6953 | if (!info->shared) |
f5385ebf | 6954 | h->non_got_ref = 1; |
7359ea65 | 6955 | |
5e681ec4 | 6956 | /* We may need a .plt entry if the function this reloc |
c84cd8ee DJ |
6957 | refers to is in a different object. We can't tell for |
6958 | sure yet, because something later might force the | |
6959 | symbol local. */ | |
b6895b4f | 6960 | if (r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
f5385ebf | 6961 | h->needs_plt = 1; |
4f199be3 DJ |
6962 | |
6963 | /* If we create a PLT entry, this relocation will reference | |
6964 | it, even if it's an ABS32 relocation. */ | |
6965 | h->plt.refcount += 1; | |
b7693d02 | 6966 | |
c19d1205 | 6967 | if (r_type == R_ARM_THM_CALL) |
b7693d02 | 6968 | eh->plt_thumb_refcount += 1; |
5e681ec4 PB |
6969 | } |
6970 | ||
67687978 PB |
6971 | /* If we are creating a shared library or relocatable executable, |
6972 | and this is a reloc against a global symbol, or a non PC | |
6973 | relative reloc against a local symbol, then we need to copy | |
6974 | the reloc into the shared library. However, if we are linking | |
6975 | with -Bsymbolic, we do not need to copy a reloc against a | |
252b5132 RH |
6976 | global symbol which is defined in an object we are |
6977 | including in the link (i.e., DEF_REGULAR is set). At | |
6978 | this point we have not seen all the input files, so it is | |
6979 | possible that DEF_REGULAR is not set now but will be set | |
6980 | later (it is never cleared). We account for that | |
6981 | possibility below by storing information in the | |
5e681ec4 | 6982 | relocs_copied field of the hash table entry. */ |
67687978 | 6983 | if ((info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 6984 | && (sec->flags & SEC_ALLOC) != 0 |
71a976dd DJ |
6985 | && (r_type == R_ARM_ABS32 |
6986 | || (h != NULL && ! h->needs_plt | |
6987 | && (! info->symbolic || ! h->def_regular)))) | |
252b5132 | 6988 | { |
5e681ec4 PB |
6989 | struct elf32_arm_relocs_copied *p, **head; |
6990 | ||
252b5132 RH |
6991 | /* When creating a shared object, we must copy these |
6992 | reloc types into the output file. We create a reloc | |
6993 | section in dynobj and make room for this reloc. */ | |
6994 | if (sreloc == NULL) | |
6995 | { | |
6996 | const char * name; | |
6997 | ||
6998 | name = (bfd_elf_string_from_elf_section | |
6999 | (abfd, | |
7000 | elf_elfheader (abfd)->e_shstrndx, | |
7001 | elf_section_data (sec)->rel_hdr.sh_name)); | |
7002 | if (name == NULL) | |
b34976b6 | 7003 | return FALSE; |
252b5132 | 7004 | |
00a97672 | 7005 | BFD_ASSERT (reloc_section_p (htab, name, sec)); |
252b5132 RH |
7006 | |
7007 | sreloc = bfd_get_section_by_name (dynobj, name); | |
7008 | if (sreloc == NULL) | |
7009 | { | |
7010 | flagword flags; | |
7011 | ||
252b5132 RH |
7012 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
7013 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
e5a52504 MM |
7014 | if ((sec->flags & SEC_ALLOC) != 0 |
7015 | /* BPABI objects never have dynamic | |
7016 | relocations mapped. */ | |
7017 | && !htab->symbian_p) | |
252b5132 | 7018 | flags |= SEC_ALLOC | SEC_LOAD; |
3496cb2a L |
7019 | sreloc = bfd_make_section_with_flags (dynobj, |
7020 | name, | |
7021 | flags); | |
252b5132 | 7022 | if (sreloc == NULL |
252b5132 | 7023 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
b34976b6 | 7024 | return FALSE; |
252b5132 | 7025 | } |
5e681ec4 PB |
7026 | |
7027 | elf_section_data (sec)->sreloc = sreloc; | |
252b5132 RH |
7028 | } |
7029 | ||
5e681ec4 PB |
7030 | /* If this is a global symbol, we count the number of |
7031 | relocations we need for this symbol. */ | |
7032 | if (h != NULL) | |
252b5132 | 7033 | { |
5e681ec4 PB |
7034 | head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; |
7035 | } | |
7036 | else | |
7037 | { | |
7038 | /* Track dynamic relocs needed for local syms too. | |
7039 | We really need local syms available to do this | |
7040 | easily. Oh well. */ | |
57e8b36a | 7041 | |
5e681ec4 | 7042 | asection *s; |
6edfbbad DJ |
7043 | void *vpp; |
7044 | ||
5e681ec4 PB |
7045 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
7046 | sec, r_symndx); | |
7047 | if (s == NULL) | |
7048 | return FALSE; | |
57e8b36a | 7049 | |
6edfbbad DJ |
7050 | vpp = &elf_section_data (s)->local_dynrel; |
7051 | head = (struct elf32_arm_relocs_copied **) vpp; | |
5e681ec4 | 7052 | } |
57e8b36a | 7053 | |
5e681ec4 PB |
7054 | p = *head; |
7055 | if (p == NULL || p->section != sec) | |
7056 | { | |
7057 | bfd_size_type amt = sizeof *p; | |
57e8b36a | 7058 | |
5e681ec4 | 7059 | p = bfd_alloc (htab->root.dynobj, amt); |
252b5132 | 7060 | if (p == NULL) |
5e681ec4 PB |
7061 | return FALSE; |
7062 | p->next = *head; | |
7063 | *head = p; | |
7064 | p->section = sec; | |
7065 | p->count = 0; | |
ba93b8ac | 7066 | p->pc_count = 0; |
252b5132 | 7067 | } |
57e8b36a | 7068 | |
ba93b8ac DJ |
7069 | if (r_type == R_ARM_REL32) |
7070 | p->pc_count += 1; | |
71a976dd | 7071 | p->count += 1; |
252b5132 RH |
7072 | } |
7073 | break; | |
7074 | ||
7075 | /* This relocation describes the C++ object vtable hierarchy. | |
7076 | Reconstruct it for later use during GC. */ | |
7077 | case R_ARM_GNU_VTINHERIT: | |
c152c796 | 7078 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 7079 | return FALSE; |
252b5132 | 7080 | break; |
9a5aca8c | 7081 | |
252b5132 RH |
7082 | /* This relocation describes which C++ vtable entries are actually |
7083 | used. Record for later use during GC. */ | |
7084 | case R_ARM_GNU_VTENTRY: | |
c152c796 | 7085 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
b34976b6 | 7086 | return FALSE; |
252b5132 RH |
7087 | break; |
7088 | } | |
7089 | } | |
f21f3fe0 | 7090 | |
b34976b6 | 7091 | return TRUE; |
252b5132 RH |
7092 | } |
7093 | ||
3c9458e9 NC |
7094 | /* Treat mapping symbols as special target symbols. */ |
7095 | ||
7096 | static bfd_boolean | |
7097 | elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym) | |
7098 | { | |
b0796911 PB |
7099 | return bfd_is_arm_special_symbol_name (sym->name, |
7100 | BFD_ARM_SPECIAL_SYM_TYPE_ANY); | |
3c9458e9 NC |
7101 | } |
7102 | ||
0367ecfb NC |
7103 | /* This is a copy of elf_find_function() from elf.c except that |
7104 | ARM mapping symbols are ignored when looking for function names | |
7105 | and STT_ARM_TFUNC is considered to a function type. */ | |
252b5132 | 7106 | |
0367ecfb NC |
7107 | static bfd_boolean |
7108 | arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, | |
7109 | asection * section, | |
7110 | asymbol ** symbols, | |
7111 | bfd_vma offset, | |
7112 | const char ** filename_ptr, | |
7113 | const char ** functionname_ptr) | |
7114 | { | |
7115 | const char * filename = NULL; | |
7116 | asymbol * func = NULL; | |
7117 | bfd_vma low_func = 0; | |
7118 | asymbol ** p; | |
252b5132 RH |
7119 | |
7120 | for (p = symbols; *p != NULL; p++) | |
7121 | { | |
7122 | elf_symbol_type *q; | |
7123 | ||
7124 | q = (elf_symbol_type *) *p; | |
7125 | ||
252b5132 RH |
7126 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) |
7127 | { | |
7128 | default: | |
7129 | break; | |
7130 | case STT_FILE: | |
7131 | filename = bfd_asymbol_name (&q->symbol); | |
7132 | break; | |
252b5132 RH |
7133 | case STT_FUNC: |
7134 | case STT_ARM_TFUNC: | |
9d2da7ca | 7135 | case STT_NOTYPE: |
b0796911 | 7136 | /* Skip mapping symbols. */ |
0367ecfb | 7137 | if ((q->symbol.flags & BSF_LOCAL) |
b0796911 PB |
7138 | && bfd_is_arm_special_symbol_name (q->symbol.name, |
7139 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
0367ecfb NC |
7140 | continue; |
7141 | /* Fall through. */ | |
6b40fcba | 7142 | if (bfd_get_section (&q->symbol) == section |
252b5132 RH |
7143 | && q->symbol.value >= low_func |
7144 | && q->symbol.value <= offset) | |
7145 | { | |
7146 | func = (asymbol *) q; | |
7147 | low_func = q->symbol.value; | |
7148 | } | |
7149 | break; | |
7150 | } | |
7151 | } | |
7152 | ||
7153 | if (func == NULL) | |
b34976b6 | 7154 | return FALSE; |
252b5132 | 7155 | |
0367ecfb NC |
7156 | if (filename_ptr) |
7157 | *filename_ptr = filename; | |
7158 | if (functionname_ptr) | |
7159 | *functionname_ptr = bfd_asymbol_name (func); | |
7160 | ||
7161 | return TRUE; | |
7162 | } | |
7163 | ||
7164 | ||
7165 | /* Find the nearest line to a particular section and offset, for error | |
7166 | reporting. This code is a duplicate of the code in elf.c, except | |
7167 | that it uses arm_elf_find_function. */ | |
7168 | ||
7169 | static bfd_boolean | |
7170 | elf32_arm_find_nearest_line (bfd * abfd, | |
7171 | asection * section, | |
7172 | asymbol ** symbols, | |
7173 | bfd_vma offset, | |
7174 | const char ** filename_ptr, | |
7175 | const char ** functionname_ptr, | |
7176 | unsigned int * line_ptr) | |
7177 | { | |
7178 | bfd_boolean found = FALSE; | |
7179 | ||
7180 | /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ | |
7181 | ||
7182 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, | |
7183 | filename_ptr, functionname_ptr, | |
7184 | line_ptr, 0, | |
7185 | & elf_tdata (abfd)->dwarf2_find_line_info)) | |
7186 | { | |
7187 | if (!*functionname_ptr) | |
7188 | arm_elf_find_function (abfd, section, symbols, offset, | |
7189 | *filename_ptr ? NULL : filename_ptr, | |
7190 | functionname_ptr); | |
f21f3fe0 | 7191 | |
0367ecfb NC |
7192 | return TRUE; |
7193 | } | |
7194 | ||
7195 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, | |
7196 | & found, filename_ptr, | |
7197 | functionname_ptr, line_ptr, | |
7198 | & elf_tdata (abfd)->line_info)) | |
7199 | return FALSE; | |
7200 | ||
7201 | if (found && (*functionname_ptr || *line_ptr)) | |
7202 | return TRUE; | |
7203 | ||
7204 | if (symbols == NULL) | |
7205 | return FALSE; | |
7206 | ||
7207 | if (! arm_elf_find_function (abfd, section, symbols, offset, | |
7208 | filename_ptr, functionname_ptr)) | |
7209 | return FALSE; | |
7210 | ||
7211 | *line_ptr = 0; | |
b34976b6 | 7212 | return TRUE; |
252b5132 RH |
7213 | } |
7214 | ||
4ab527b0 FF |
7215 | static bfd_boolean |
7216 | elf32_arm_find_inliner_info (bfd * abfd, | |
7217 | const char ** filename_ptr, | |
7218 | const char ** functionname_ptr, | |
7219 | unsigned int * line_ptr) | |
7220 | { | |
7221 | bfd_boolean found; | |
7222 | found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr, | |
7223 | functionname_ptr, line_ptr, | |
7224 | & elf_tdata (abfd)->dwarf2_find_line_info); | |
7225 | return found; | |
7226 | } | |
7227 | ||
252b5132 RH |
7228 | /* Adjust a symbol defined by a dynamic object and referenced by a |
7229 | regular object. The current definition is in some section of the | |
7230 | dynamic object, but we're not including those sections. We have to | |
7231 | change the definition to something the rest of the link can | |
7232 | understand. */ | |
7233 | ||
b34976b6 | 7234 | static bfd_boolean |
57e8b36a NC |
7235 | elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, |
7236 | struct elf_link_hash_entry * h) | |
252b5132 RH |
7237 | { |
7238 | bfd * dynobj; | |
7239 | asection * s; | |
7240 | unsigned int power_of_two; | |
b7693d02 | 7241 | struct elf32_arm_link_hash_entry * eh; |
67687978 | 7242 | struct elf32_arm_link_hash_table *globals; |
252b5132 | 7243 | |
67687978 | 7244 | globals = elf32_arm_hash_table (info); |
252b5132 RH |
7245 | dynobj = elf_hash_table (info)->dynobj; |
7246 | ||
7247 | /* Make sure we know what is going on here. */ | |
7248 | BFD_ASSERT (dynobj != NULL | |
f5385ebf | 7249 | && (h->needs_plt |
f6e332e6 | 7250 | || h->u.weakdef != NULL |
f5385ebf AM |
7251 | || (h->def_dynamic |
7252 | && h->ref_regular | |
7253 | && !h->def_regular))); | |
252b5132 | 7254 | |
b7693d02 DJ |
7255 | eh = (struct elf32_arm_link_hash_entry *) h; |
7256 | ||
252b5132 RH |
7257 | /* If this is a function, put it in the procedure linkage table. We |
7258 | will fill in the contents of the procedure linkage table later, | |
7259 | when we know the address of the .got section. */ | |
b7693d02 | 7260 | if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC |
f5385ebf | 7261 | || h->needs_plt) |
252b5132 | 7262 | { |
5e681ec4 PB |
7263 | if (h->plt.refcount <= 0 |
7264 | || SYMBOL_CALLS_LOCAL (info, h) | |
7265 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
7266 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
7267 | { |
7268 | /* This case can occur if we saw a PLT32 reloc in an input | |
5e681ec4 PB |
7269 | file, but the symbol was never referred to by a dynamic |
7270 | object, or if all references were garbage collected. In | |
7271 | such a case, we don't actually need to build a procedure | |
7272 | linkage table, and we can just do a PC24 reloc instead. */ | |
7273 | h->plt.offset = (bfd_vma) -1; | |
b7693d02 | 7274 | eh->plt_thumb_refcount = 0; |
f5385ebf | 7275 | h->needs_plt = 0; |
252b5132 RH |
7276 | } |
7277 | ||
b34976b6 | 7278 | return TRUE; |
252b5132 | 7279 | } |
5e681ec4 | 7280 | else |
b7693d02 DJ |
7281 | { |
7282 | /* It's possible that we incorrectly decided a .plt reloc was | |
7283 | needed for an R_ARM_PC24 or similar reloc to a non-function sym | |
7284 | in check_relocs. We can't decide accurately between function | |
7285 | and non-function syms in check-relocs; Objects loaded later in | |
7286 | the link may change h->type. So fix it now. */ | |
7287 | h->plt.offset = (bfd_vma) -1; | |
7288 | eh->plt_thumb_refcount = 0; | |
7289 | } | |
252b5132 RH |
7290 | |
7291 | /* If this is a weak symbol, and there is a real definition, the | |
7292 | processor independent code will have arranged for us to see the | |
7293 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 7294 | if (h->u.weakdef != NULL) |
252b5132 | 7295 | { |
f6e332e6 AM |
7296 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
7297 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
7298 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
7299 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
b34976b6 | 7300 | return TRUE; |
252b5132 RH |
7301 | } |
7302 | ||
ba93b8ac DJ |
7303 | /* If there are no non-GOT references, we do not need a copy |
7304 | relocation. */ | |
7305 | if (!h->non_got_ref) | |
7306 | return TRUE; | |
7307 | ||
252b5132 RH |
7308 | /* This is a reference to a symbol defined by a dynamic object which |
7309 | is not a function. */ | |
7310 | ||
7311 | /* If we are creating a shared library, we must presume that the | |
7312 | only references to the symbol are via the global offset table. | |
7313 | For such cases we need not do anything here; the relocations will | |
67687978 PB |
7314 | be handled correctly by relocate_section. Relocatable executables |
7315 | can reference data in shared objects directly, so we don't need to | |
7316 | do anything here. */ | |
7317 | if (info->shared || globals->root.is_relocatable_executable) | |
b34976b6 | 7318 | return TRUE; |
252b5132 | 7319 | |
909272ee AM |
7320 | if (h->size == 0) |
7321 | { | |
7322 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
7323 | h->root.root.string); | |
7324 | return TRUE; | |
7325 | } | |
7326 | ||
252b5132 RH |
7327 | /* We must allocate the symbol in our .dynbss section, which will |
7328 | become part of the .bss section of the executable. There will be | |
7329 | an entry for this symbol in the .dynsym section. The dynamic | |
7330 | object will contain position independent code, so all references | |
7331 | from the dynamic object to this symbol will go through the global | |
7332 | offset table. The dynamic linker will use the .dynsym entry to | |
7333 | determine the address it must put in the global offset table, so | |
7334 | both the dynamic object and the regular object will refer to the | |
7335 | same memory location for the variable. */ | |
252b5132 RH |
7336 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
7337 | BFD_ASSERT (s != NULL); | |
7338 | ||
7339 | /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to | |
7340 | copy the initial value out of the dynamic object and into the | |
7341 | runtime process image. We need to remember the offset into the | |
00a97672 | 7342 | .rel(a).bss section we are going to use. */ |
252b5132 RH |
7343 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
7344 | { | |
7345 | asection *srel; | |
7346 | ||
00a97672 | 7347 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss")); |
252b5132 | 7348 | BFD_ASSERT (srel != NULL); |
00a97672 | 7349 | srel->size += RELOC_SIZE (globals); |
f5385ebf | 7350 | h->needs_copy = 1; |
252b5132 RH |
7351 | } |
7352 | ||
7353 | /* We need to figure out the alignment required for this symbol. I | |
7354 | have no idea how ELF linkers handle this. */ | |
7355 | power_of_two = bfd_log2 (h->size); | |
7356 | if (power_of_two > 3) | |
7357 | power_of_two = 3; | |
7358 | ||
7359 | /* Apply the required alignment. */ | |
eea6121a | 7360 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
252b5132 RH |
7361 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
7362 | { | |
7363 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 7364 | return FALSE; |
252b5132 RH |
7365 | } |
7366 | ||
7367 | /* Define the symbol as being at this point in the section. */ | |
7368 | h->root.u.def.section = s; | |
eea6121a | 7369 | h->root.u.def.value = s->size; |
252b5132 RH |
7370 | |
7371 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 7372 | s->size += h->size; |
252b5132 | 7373 | |
b34976b6 | 7374 | return TRUE; |
252b5132 RH |
7375 | } |
7376 | ||
5e681ec4 PB |
7377 | /* Allocate space in .plt, .got and associated reloc sections for |
7378 | dynamic relocs. */ | |
7379 | ||
7380 | static bfd_boolean | |
57e8b36a | 7381 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
5e681ec4 PB |
7382 | { |
7383 | struct bfd_link_info *info; | |
7384 | struct elf32_arm_link_hash_table *htab; | |
7385 | struct elf32_arm_link_hash_entry *eh; | |
7386 | struct elf32_arm_relocs_copied *p; | |
7387 | ||
b7693d02 DJ |
7388 | eh = (struct elf32_arm_link_hash_entry *) h; |
7389 | ||
5e681ec4 PB |
7390 | if (h->root.type == bfd_link_hash_indirect) |
7391 | return TRUE; | |
7392 | ||
7393 | if (h->root.type == bfd_link_hash_warning) | |
7394 | /* When warning symbols are created, they **replace** the "real" | |
7395 | entry in the hash table, thus we never get to see the real | |
7396 | symbol in a hash traversal. So look at it now. */ | |
7397 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7398 | ||
7399 | info = (struct bfd_link_info *) inf; | |
7400 | htab = elf32_arm_hash_table (info); | |
7401 | ||
7402 | if (htab->root.dynamic_sections_created | |
7403 | && h->plt.refcount > 0) | |
7404 | { | |
7405 | /* Make sure this symbol is output as a dynamic symbol. | |
7406 | Undefined weak syms won't yet be marked as dynamic. */ | |
7407 | if (h->dynindx == -1 | |
f5385ebf | 7408 | && !h->forced_local) |
5e681ec4 | 7409 | { |
c152c796 | 7410 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
7411 | return FALSE; |
7412 | } | |
7413 | ||
7414 | if (info->shared | |
7359ea65 | 7415 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
5e681ec4 PB |
7416 | { |
7417 | asection *s = htab->splt; | |
7418 | ||
7419 | /* If this is the first .plt entry, make room for the special | |
7420 | first entry. */ | |
eea6121a | 7421 | if (s->size == 0) |
e5a52504 | 7422 | s->size += htab->plt_header_size; |
5e681ec4 | 7423 | |
eea6121a | 7424 | h->plt.offset = s->size; |
5e681ec4 | 7425 | |
b7693d02 DJ |
7426 | /* If we will insert a Thumb trampoline before this PLT, leave room |
7427 | for it. */ | |
33bfe774 | 7428 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) |
b7693d02 DJ |
7429 | { |
7430 | h->plt.offset += PLT_THUMB_STUB_SIZE; | |
7431 | s->size += PLT_THUMB_STUB_SIZE; | |
7432 | } | |
7433 | ||
5e681ec4 PB |
7434 | /* If this symbol is not defined in a regular file, and we are |
7435 | not generating a shared library, then set the symbol to this | |
7436 | location in the .plt. This is required to make function | |
7437 | pointers compare as equal between the normal executable and | |
7438 | the shared library. */ | |
7439 | if (! info->shared | |
f5385ebf | 7440 | && !h->def_regular) |
5e681ec4 PB |
7441 | { |
7442 | h->root.u.def.section = s; | |
7443 | h->root.u.def.value = h->plt.offset; | |
b7693d02 DJ |
7444 | |
7445 | /* Make sure the function is not marked as Thumb, in case | |
7446 | it is the target of an ABS32 relocation, which will | |
7447 | point to the PLT entry. */ | |
7448 | if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) | |
7449 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); | |
5e681ec4 PB |
7450 | } |
7451 | ||
7452 | /* Make room for this entry. */ | |
e5a52504 | 7453 | s->size += htab->plt_entry_size; |
5e681ec4 | 7454 | |
e5a52504 | 7455 | if (!htab->symbian_p) |
b7693d02 DJ |
7456 | { |
7457 | /* We also need to make an entry in the .got.plt section, which | |
7458 | will be placed in the .got section by the linker script. */ | |
7459 | eh->plt_got_offset = htab->sgotplt->size; | |
7460 | htab->sgotplt->size += 4; | |
7461 | } | |
5e681ec4 | 7462 | |
00a97672 RS |
7463 | /* We also need to make an entry in the .rel(a).plt section. */ |
7464 | htab->srelplt->size += RELOC_SIZE (htab); | |
7465 | ||
7466 | /* VxWorks executables have a second set of relocations for | |
7467 | each PLT entry. They go in a separate relocation section, | |
7468 | which is processed by the kernel loader. */ | |
7469 | if (htab->vxworks_p && !info->shared) | |
7470 | { | |
7471 | /* There is a relocation for the initial PLT entry: | |
7472 | an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */ | |
7473 | if (h->plt.offset == htab->plt_header_size) | |
7474 | htab->srelplt2->size += RELOC_SIZE (htab); | |
7475 | ||
7476 | /* There are two extra relocations for each subsequent | |
7477 | PLT entry: an R_ARM_32 relocation for the GOT entry, | |
7478 | and an R_ARM_32 relocation for the PLT entry. */ | |
7479 | htab->srelplt2->size += RELOC_SIZE (htab) * 2; | |
7480 | } | |
5e681ec4 PB |
7481 | } |
7482 | else | |
7483 | { | |
7484 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 7485 | h->needs_plt = 0; |
5e681ec4 PB |
7486 | } |
7487 | } | |
7488 | else | |
7489 | { | |
7490 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 7491 | h->needs_plt = 0; |
5e681ec4 PB |
7492 | } |
7493 | ||
7494 | if (h->got.refcount > 0) | |
7495 | { | |
7496 | asection *s; | |
7497 | bfd_boolean dyn; | |
ba93b8ac DJ |
7498 | int tls_type = elf32_arm_hash_entry (h)->tls_type; |
7499 | int indx; | |
5e681ec4 PB |
7500 | |
7501 | /* Make sure this symbol is output as a dynamic symbol. | |
7502 | Undefined weak syms won't yet be marked as dynamic. */ | |
7503 | if (h->dynindx == -1 | |
f5385ebf | 7504 | && !h->forced_local) |
5e681ec4 | 7505 | { |
c152c796 | 7506 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
7507 | return FALSE; |
7508 | } | |
7509 | ||
e5a52504 MM |
7510 | if (!htab->symbian_p) |
7511 | { | |
7512 | s = htab->sgot; | |
7513 | h->got.offset = s->size; | |
ba93b8ac DJ |
7514 | |
7515 | if (tls_type == GOT_UNKNOWN) | |
7516 | abort (); | |
7517 | ||
7518 | if (tls_type == GOT_NORMAL) | |
7519 | /* Non-TLS symbols need one GOT slot. */ | |
7520 | s->size += 4; | |
7521 | else | |
7522 | { | |
7523 | if (tls_type & GOT_TLS_GD) | |
7524 | /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */ | |
7525 | s->size += 8; | |
7526 | if (tls_type & GOT_TLS_IE) | |
7527 | /* R_ARM_TLS_IE32 needs one GOT slot. */ | |
7528 | s->size += 4; | |
7529 | } | |
7530 | ||
e5a52504 | 7531 | dyn = htab->root.dynamic_sections_created; |
ba93b8ac DJ |
7532 | |
7533 | indx = 0; | |
7534 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
7535 | && (!info->shared | |
7536 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
7537 | indx = h->dynindx; | |
7538 | ||
7539 | if (tls_type != GOT_NORMAL | |
7540 | && (info->shared || indx != 0) | |
7541 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
7542 | || h->root.type != bfd_link_hash_undefweak)) | |
7543 | { | |
7544 | if (tls_type & GOT_TLS_IE) | |
00a97672 | 7545 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7546 | |
7547 | if (tls_type & GOT_TLS_GD) | |
00a97672 | 7548 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7549 | |
7550 | if ((tls_type & GOT_TLS_GD) && indx != 0) | |
00a97672 | 7551 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7552 | } |
7553 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
7554 | || h->root.type != bfd_link_hash_undefweak) | |
7555 | && (info->shared | |
7556 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
00a97672 | 7557 | htab->srelgot->size += RELOC_SIZE (htab); |
e5a52504 | 7558 | } |
5e681ec4 PB |
7559 | } |
7560 | else | |
7561 | h->got.offset = (bfd_vma) -1; | |
7562 | ||
a4fd1a8e PB |
7563 | /* Allocate stubs for exported Thumb functions on v4t. */ |
7564 | if (!htab->use_blx && h->dynindx != -1 | |
7565 | && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC | |
7566 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
7567 | { | |
7568 | struct elf_link_hash_entry * th; | |
7569 | struct bfd_link_hash_entry * bh; | |
7570 | struct elf_link_hash_entry * myh; | |
7571 | char name[1024]; | |
7572 | asection *s; | |
7573 | bh = NULL; | |
7574 | /* Create a new symbol to regist the real location of the function. */ | |
7575 | s = h->root.u.def.section; | |
7576 | sprintf(name, "__real_%s", h->root.root.string); | |
7577 | _bfd_generic_link_add_one_symbol (info, s->owner, | |
7578 | name, BSF_GLOBAL, s, | |
7579 | h->root.u.def.value, | |
7580 | NULL, TRUE, FALSE, &bh); | |
7581 | ||
7582 | myh = (struct elf_link_hash_entry *) bh; | |
7583 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); | |
7584 | myh->forced_local = 1; | |
7585 | eh->export_glue = myh; | |
7586 | th = record_arm_to_thumb_glue (info, h); | |
7587 | /* Point the symbol at the stub. */ | |
7588 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); | |
7589 | h->root.u.def.section = th->root.u.def.section; | |
7590 | h->root.u.def.value = th->root.u.def.value & ~1; | |
7591 | } | |
7592 | ||
5e681ec4 PB |
7593 | if (eh->relocs_copied == NULL) |
7594 | return TRUE; | |
7595 | ||
7596 | /* In the shared -Bsymbolic case, discard space allocated for | |
7597 | dynamic pc-relative relocs against symbols which turn out to be | |
7598 | defined in regular objects. For the normal shared case, discard | |
7599 | space for pc-relative relocs that have become local due to symbol | |
7600 | visibility changes. */ | |
7601 | ||
67687978 | 7602 | if (info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 7603 | { |
ba93b8ac DJ |
7604 | /* The only reloc that uses pc_count is R_ARM_REL32, which will |
7605 | appear on something like ".long foo - .". We want calls to | |
7606 | protected symbols to resolve directly to the function rather | |
7607 | than going via the plt. If people want function pointer | |
7608 | comparisons to work as expected then they should avoid | |
7609 | writing assembly like ".long foo - .". */ | |
7610 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
7611 | { | |
7612 | struct elf32_arm_relocs_copied **pp; | |
7613 | ||
7614 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; ) | |
7615 | { | |
7616 | p->count -= p->pc_count; | |
7617 | p->pc_count = 0; | |
7618 | if (p->count == 0) | |
7619 | *pp = p->next; | |
7620 | else | |
7621 | pp = &p->next; | |
7622 | } | |
7623 | } | |
7624 | ||
7625 | /* Also discard relocs on undefined weak syms with non-default | |
7359ea65 | 7626 | visibility. */ |
22d606e9 | 7627 | if (eh->relocs_copied != NULL |
5e681ec4 | 7628 | && h->root.type == bfd_link_hash_undefweak) |
22d606e9 AM |
7629 | { |
7630 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
7631 | eh->relocs_copied = NULL; | |
7632 | ||
7633 | /* Make sure undefined weak symbols are output as a dynamic | |
7634 | symbol in PIEs. */ | |
7635 | else if (h->dynindx == -1 | |
7636 | && !h->forced_local) | |
7637 | { | |
7638 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
7639 | return FALSE; | |
7640 | } | |
7641 | } | |
7642 | ||
67687978 PB |
7643 | else if (htab->root.is_relocatable_executable && h->dynindx == -1 |
7644 | && h->root.type == bfd_link_hash_new) | |
7645 | { | |
7646 | /* Output absolute symbols so that we can create relocations | |
7647 | against them. For normal symbols we output a relocation | |
7648 | against the section that contains them. */ | |
7649 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
7650 | return FALSE; | |
7651 | } | |
7652 | ||
5e681ec4 PB |
7653 | } |
7654 | else | |
7655 | { | |
7656 | /* For the non-shared case, discard space for relocs against | |
7657 | symbols which turn out to need copy relocs or are not | |
7658 | dynamic. */ | |
7659 | ||
f5385ebf AM |
7660 | if (!h->non_got_ref |
7661 | && ((h->def_dynamic | |
7662 | && !h->def_regular) | |
5e681ec4 PB |
7663 | || (htab->root.dynamic_sections_created |
7664 | && (h->root.type == bfd_link_hash_undefweak | |
7665 | || h->root.type == bfd_link_hash_undefined)))) | |
7666 | { | |
7667 | /* Make sure this symbol is output as a dynamic symbol. | |
7668 | Undefined weak syms won't yet be marked as dynamic. */ | |
7669 | if (h->dynindx == -1 | |
f5385ebf | 7670 | && !h->forced_local) |
5e681ec4 | 7671 | { |
c152c796 | 7672 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
7673 | return FALSE; |
7674 | } | |
7675 | ||
7676 | /* If that succeeded, we know we'll be keeping all the | |
7677 | relocs. */ | |
7678 | if (h->dynindx != -1) | |
7679 | goto keep; | |
7680 | } | |
7681 | ||
7682 | eh->relocs_copied = NULL; | |
7683 | ||
7684 | keep: ; | |
7685 | } | |
7686 | ||
7687 | /* Finally, allocate space. */ | |
7688 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
7689 | { | |
7690 | asection *sreloc = elf_section_data (p->section)->sreloc; | |
00a97672 | 7691 | sreloc->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
7692 | } |
7693 | ||
7694 | return TRUE; | |
7695 | } | |
7696 | ||
08d1f311 DJ |
7697 | /* Find any dynamic relocs that apply to read-only sections. */ |
7698 | ||
7699 | static bfd_boolean | |
7700 | elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf) | |
7701 | { | |
7702 | struct elf32_arm_link_hash_entry *eh; | |
7703 | struct elf32_arm_relocs_copied *p; | |
7704 | ||
7705 | if (h->root.type == bfd_link_hash_warning) | |
7706 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7707 | ||
7708 | eh = (struct elf32_arm_link_hash_entry *) h; | |
7709 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
7710 | { | |
7711 | asection *s = p->section; | |
7712 | ||
7713 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
7714 | { | |
7715 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
7716 | ||
7717 | info->flags |= DF_TEXTREL; | |
7718 | ||
7719 | /* Not an error, just cut short the traversal. */ | |
7720 | return FALSE; | |
7721 | } | |
7722 | } | |
7723 | return TRUE; | |
7724 | } | |
7725 | ||
252b5132 RH |
7726 | /* Set the sizes of the dynamic sections. */ |
7727 | ||
b34976b6 | 7728 | static bfd_boolean |
57e8b36a NC |
7729 | elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, |
7730 | struct bfd_link_info * info) | |
252b5132 RH |
7731 | { |
7732 | bfd * dynobj; | |
7733 | asection * s; | |
b34976b6 AM |
7734 | bfd_boolean plt; |
7735 | bfd_boolean relocs; | |
5e681ec4 PB |
7736 | bfd *ibfd; |
7737 | struct elf32_arm_link_hash_table *htab; | |
252b5132 | 7738 | |
5e681ec4 | 7739 | htab = elf32_arm_hash_table (info); |
252b5132 RH |
7740 | dynobj = elf_hash_table (info)->dynobj; |
7741 | BFD_ASSERT (dynobj != NULL); | |
39b41c9c | 7742 | check_use_blx (htab); |
252b5132 RH |
7743 | |
7744 | if (elf_hash_table (info)->dynamic_sections_created) | |
7745 | { | |
7746 | /* Set the contents of the .interp section to the interpreter. */ | |
893c4fe2 | 7747 | if (info->executable) |
252b5132 RH |
7748 | { |
7749 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
7750 | BFD_ASSERT (s != NULL); | |
eea6121a | 7751 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
252b5132 RH |
7752 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
7753 | } | |
7754 | } | |
5e681ec4 PB |
7755 | |
7756 | /* Set up .got offsets for local syms, and space for local dynamic | |
7757 | relocs. */ | |
7758 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
252b5132 | 7759 | { |
5e681ec4 PB |
7760 | bfd_signed_vma *local_got; |
7761 | bfd_signed_vma *end_local_got; | |
7762 | char *local_tls_type; | |
7763 | bfd_size_type locsymcount; | |
7764 | Elf_Internal_Shdr *symtab_hdr; | |
7765 | asection *srel; | |
7766 | ||
7767 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
7768 | continue; | |
7769 | ||
7770 | for (s = ibfd->sections; s != NULL; s = s->next) | |
7771 | { | |
7772 | struct elf32_arm_relocs_copied *p; | |
7773 | ||
6edfbbad | 7774 | for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) |
5e681ec4 PB |
7775 | { |
7776 | if (!bfd_is_abs_section (p->section) | |
7777 | && bfd_is_abs_section (p->section->output_section)) | |
7778 | { | |
7779 | /* Input section has been discarded, either because | |
7780 | it is a copy of a linkonce section or due to | |
7781 | linker script /DISCARD/, so we'll be discarding | |
7782 | the relocs too. */ | |
7783 | } | |
7784 | else if (p->count != 0) | |
7785 | { | |
7786 | srel = elf_section_data (p->section)->sreloc; | |
00a97672 | 7787 | srel->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
7788 | if ((p->section->output_section->flags & SEC_READONLY) != 0) |
7789 | info->flags |= DF_TEXTREL; | |
7790 | } | |
7791 | } | |
7792 | } | |
7793 | ||
7794 | local_got = elf_local_got_refcounts (ibfd); | |
7795 | if (!local_got) | |
7796 | continue; | |
7797 | ||
7798 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
7799 | locsymcount = symtab_hdr->sh_info; | |
7800 | end_local_got = local_got + locsymcount; | |
ba93b8ac | 7801 | local_tls_type = elf32_arm_local_got_tls_type (ibfd); |
5e681ec4 PB |
7802 | s = htab->sgot; |
7803 | srel = htab->srelgot; | |
7804 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) | |
7805 | { | |
7806 | if (*local_got > 0) | |
7807 | { | |
eea6121a | 7808 | *local_got = s->size; |
ba93b8ac DJ |
7809 | if (*local_tls_type & GOT_TLS_GD) |
7810 | /* TLS_GD relocs need an 8-byte structure in the GOT. */ | |
7811 | s->size += 8; | |
7812 | if (*local_tls_type & GOT_TLS_IE) | |
7813 | s->size += 4; | |
7814 | if (*local_tls_type == GOT_NORMAL) | |
7815 | s->size += 4; | |
7816 | ||
7817 | if (info->shared || *local_tls_type == GOT_TLS_GD) | |
00a97672 | 7818 | srel->size += RELOC_SIZE (htab); |
5e681ec4 PB |
7819 | } |
7820 | else | |
7821 | *local_got = (bfd_vma) -1; | |
7822 | } | |
252b5132 RH |
7823 | } |
7824 | ||
ba93b8ac DJ |
7825 | if (htab->tls_ldm_got.refcount > 0) |
7826 | { | |
7827 | /* Allocate two GOT entries and one dynamic relocation (if necessary) | |
7828 | for R_ARM_TLS_LDM32 relocations. */ | |
7829 | htab->tls_ldm_got.offset = htab->sgot->size; | |
7830 | htab->sgot->size += 8; | |
7831 | if (info->shared) | |
00a97672 | 7832 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7833 | } |
7834 | else | |
7835 | htab->tls_ldm_got.offset = -1; | |
7836 | ||
5e681ec4 PB |
7837 | /* Allocate global sym .plt and .got entries, and space for global |
7838 | sym dynamic relocs. */ | |
57e8b36a | 7839 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); |
252b5132 RH |
7840 | |
7841 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
7842 | determined the sizes of the various dynamic sections. Allocate | |
7843 | memory for them. */ | |
b34976b6 AM |
7844 | plt = FALSE; |
7845 | relocs = FALSE; | |
252b5132 RH |
7846 | for (s = dynobj->sections; s != NULL; s = s->next) |
7847 | { | |
7848 | const char * name; | |
252b5132 RH |
7849 | |
7850 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
7851 | continue; | |
7852 | ||
7853 | /* It's OK to base decisions on the section name, because none | |
7854 | of the dynobj section names depend upon the input files. */ | |
7855 | name = bfd_get_section_name (dynobj, s); | |
7856 | ||
24a1ba0f | 7857 | if (strcmp (name, ".plt") == 0) |
252b5132 | 7858 | { |
c456f082 AM |
7859 | /* Remember whether there is a PLT. */ |
7860 | plt = s->size != 0; | |
252b5132 RH |
7861 | } |
7862 | else if (strncmp (name, ".rel", 4) == 0) | |
7863 | { | |
c456f082 | 7864 | if (s->size != 0) |
252b5132 | 7865 | { |
252b5132 | 7866 | /* Remember whether there are any reloc sections other |
00a97672 RS |
7867 | than .rel(a).plt and .rela.plt.unloaded. */ |
7868 | if (s != htab->srelplt && s != htab->srelplt2) | |
b34976b6 | 7869 | relocs = TRUE; |
252b5132 RH |
7870 | |
7871 | /* We use the reloc_count field as a counter if we need | |
7872 | to copy relocs into the output file. */ | |
7873 | s->reloc_count = 0; | |
7874 | } | |
7875 | } | |
c456f082 AM |
7876 | else if (strncmp (name, ".got", 4) != 0 |
7877 | && strcmp (name, ".dynbss") != 0) | |
252b5132 RH |
7878 | { |
7879 | /* It's not one of our sections, so don't allocate space. */ | |
7880 | continue; | |
7881 | } | |
7882 | ||
c456f082 | 7883 | if (s->size == 0) |
252b5132 | 7884 | { |
c456f082 | 7885 | /* If we don't need this section, strip it from the |
00a97672 RS |
7886 | output file. This is mostly to handle .rel(a).bss and |
7887 | .rel(a).plt. We must create both sections in | |
c456f082 AM |
7888 | create_dynamic_sections, because they must be created |
7889 | before the linker maps input sections to output | |
7890 | sections. The linker does that before | |
7891 | adjust_dynamic_symbol is called, and it is that | |
7892 | function which decides whether anything needs to go | |
7893 | into these sections. */ | |
8423293d | 7894 | s->flags |= SEC_EXCLUDE; |
252b5132 RH |
7895 | continue; |
7896 | } | |
7897 | ||
c456f082 AM |
7898 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
7899 | continue; | |
7900 | ||
252b5132 | 7901 | /* Allocate memory for the section contents. */ |
eea6121a | 7902 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
c456f082 | 7903 | if (s->contents == NULL) |
b34976b6 | 7904 | return FALSE; |
252b5132 RH |
7905 | } |
7906 | ||
7907 | if (elf_hash_table (info)->dynamic_sections_created) | |
7908 | { | |
7909 | /* Add some entries to the .dynamic section. We fill in the | |
7910 | values later, in elf32_arm_finish_dynamic_sections, but we | |
7911 | must add the entries now so that we get the correct size for | |
7912 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
7913 | dynamic linker and used by the debugger. */ | |
dc810e39 | 7914 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 7915 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 7916 | |
8532796c | 7917 | if (info->executable) |
252b5132 | 7918 | { |
dc810e39 | 7919 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 7920 | return FALSE; |
252b5132 RH |
7921 | } |
7922 | ||
7923 | if (plt) | |
7924 | { | |
dc810e39 AM |
7925 | if ( !add_dynamic_entry (DT_PLTGOT, 0) |
7926 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
00a97672 RS |
7927 | || !add_dynamic_entry (DT_PLTREL, |
7928 | htab->use_rel ? DT_REL : DT_RELA) | |
dc810e39 | 7929 | || !add_dynamic_entry (DT_JMPREL, 0)) |
b34976b6 | 7930 | return FALSE; |
252b5132 RH |
7931 | } |
7932 | ||
7933 | if (relocs) | |
7934 | { | |
00a97672 RS |
7935 | if (htab->use_rel) |
7936 | { | |
7937 | if (!add_dynamic_entry (DT_REL, 0) | |
7938 | || !add_dynamic_entry (DT_RELSZ, 0) | |
7939 | || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab))) | |
7940 | return FALSE; | |
7941 | } | |
7942 | else | |
7943 | { | |
7944 | if (!add_dynamic_entry (DT_RELA, 0) | |
7945 | || !add_dynamic_entry (DT_RELASZ, 0) | |
7946 | || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab))) | |
7947 | return FALSE; | |
7948 | } | |
252b5132 RH |
7949 | } |
7950 | ||
08d1f311 DJ |
7951 | /* If any dynamic relocs apply to a read-only section, |
7952 | then we need a DT_TEXTREL entry. */ | |
7953 | if ((info->flags & DF_TEXTREL) == 0) | |
7954 | elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, | |
7955 | (PTR) info); | |
7956 | ||
99e4ae17 | 7957 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 7958 | { |
dc810e39 | 7959 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 7960 | return FALSE; |
252b5132 RH |
7961 | } |
7962 | } | |
8532796c | 7963 | #undef add_dynamic_entry |
252b5132 | 7964 | |
b34976b6 | 7965 | return TRUE; |
252b5132 RH |
7966 | } |
7967 | ||
252b5132 RH |
7968 | /* Finish up dynamic symbol handling. We set the contents of various |
7969 | dynamic sections here. */ | |
7970 | ||
b34976b6 | 7971 | static bfd_boolean |
57e8b36a NC |
7972 | elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, |
7973 | struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) | |
252b5132 RH |
7974 | { |
7975 | bfd * dynobj; | |
e5a52504 | 7976 | struct elf32_arm_link_hash_table *htab; |
b7693d02 | 7977 | struct elf32_arm_link_hash_entry *eh; |
252b5132 RH |
7978 | |
7979 | dynobj = elf_hash_table (info)->dynobj; | |
e5a52504 | 7980 | htab = elf32_arm_hash_table (info); |
b7693d02 | 7981 | eh = (struct elf32_arm_link_hash_entry *) h; |
252b5132 RH |
7982 | |
7983 | if (h->plt.offset != (bfd_vma) -1) | |
7984 | { | |
7985 | asection * splt; | |
252b5132 | 7986 | asection * srel; |
e5a52504 | 7987 | bfd_byte *loc; |
24a1ba0f | 7988 | bfd_vma plt_index; |
947216bf | 7989 | Elf_Internal_Rela rel; |
252b5132 RH |
7990 | |
7991 | /* This symbol has an entry in the procedure linkage table. Set | |
7992 | it up. */ | |
7993 | ||
7994 | BFD_ASSERT (h->dynindx != -1); | |
7995 | ||
7996 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 | 7997 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt")); |
e5a52504 | 7998 | BFD_ASSERT (splt != NULL && srel != NULL); |
252b5132 | 7999 | |
e5a52504 MM |
8000 | /* Fill in the entry in the procedure linkage table. */ |
8001 | if (htab->symbian_p) | |
8002 | { | |
52ab56c2 PB |
8003 | put_arm_insn (htab, output_bfd, |
8004 | elf32_arm_symbian_plt_entry[0], | |
8005 | splt->contents + h->plt.offset); | |
8006 | bfd_put_32 (output_bfd, | |
8007 | elf32_arm_symbian_plt_entry[1], | |
8008 | splt->contents + h->plt.offset + 4); | |
e5a52504 MM |
8009 | |
8010 | /* Fill in the entry in the .rel.plt section. */ | |
2a1b9a48 MM |
8011 | rel.r_offset = (splt->output_section->vma |
8012 | + splt->output_offset | |
52ab56c2 | 8013 | + h->plt.offset + 4); |
e5a52504 | 8014 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
b7693d02 DJ |
8015 | |
8016 | /* Get the index in the procedure linkage table which | |
8017 | corresponds to this symbol. This is the index of this symbol | |
8018 | in all the symbols for which we are making plt entries. The | |
8019 | first entry in the procedure linkage table is reserved. */ | |
8020 | plt_index = ((h->plt.offset - htab->plt_header_size) | |
8021 | / htab->plt_entry_size); | |
e5a52504 MM |
8022 | } |
8023 | else | |
8024 | { | |
00a97672 | 8025 | bfd_vma got_offset, got_address, plt_address; |
e5a52504 MM |
8026 | bfd_vma got_displacement; |
8027 | asection * sgot; | |
52ab56c2 | 8028 | bfd_byte * ptr; |
e5a52504 MM |
8029 | |
8030 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
8031 | BFD_ASSERT (sgot != NULL); | |
8032 | ||
b7693d02 DJ |
8033 | /* Get the offset into the .got.plt table of the entry that |
8034 | corresponds to this function. */ | |
8035 | got_offset = eh->plt_got_offset; | |
8036 | ||
8037 | /* Get the index in the procedure linkage table which | |
8038 | corresponds to this symbol. This is the index of this symbol | |
8039 | in all the symbols for which we are making plt entries. The | |
8040 | first three entries in .got.plt are reserved; after that | |
8041 | symbols appear in the same order as in .plt. */ | |
8042 | plt_index = (got_offset - 12) / 4; | |
e5a52504 | 8043 | |
00a97672 RS |
8044 | /* Calculate the address of the GOT entry. */ |
8045 | got_address = (sgot->output_section->vma | |
8046 | + sgot->output_offset | |
8047 | + got_offset); | |
5e681ec4 | 8048 | |
00a97672 RS |
8049 | /* ...and the address of the PLT entry. */ |
8050 | plt_address = (splt->output_section->vma | |
8051 | + splt->output_offset | |
8052 | + h->plt.offset); | |
5e681ec4 | 8053 | |
52ab56c2 | 8054 | ptr = htab->splt->contents + h->plt.offset; |
00a97672 RS |
8055 | if (htab->vxworks_p && info->shared) |
8056 | { | |
8057 | unsigned int i; | |
8058 | bfd_vma val; | |
8059 | ||
52ab56c2 | 8060 | for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4) |
00a97672 RS |
8061 | { |
8062 | val = elf32_arm_vxworks_shared_plt_entry[i]; | |
8063 | if (i == 2) | |
8064 | val |= got_address - sgot->output_section->vma; | |
8065 | if (i == 5) | |
8066 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
8067 | if (i == 2 || i == 5) |
8068 | bfd_put_32 (output_bfd, val, ptr); | |
8069 | else | |
8070 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
8071 | } |
8072 | } | |
8073 | else if (htab->vxworks_p) | |
b7693d02 | 8074 | { |
00a97672 RS |
8075 | unsigned int i; |
8076 | bfd_vma val; | |
8077 | ||
8078 | for (i = 0; i != htab->plt_entry_size / 4; i++) | |
8079 | { | |
8080 | val = elf32_arm_vxworks_exec_plt_entry[i]; | |
8081 | if (i == 2) | |
8082 | val |= got_address; | |
8083 | if (i == 4) | |
8084 | val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2); | |
8085 | if (i == 5) | |
8086 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
8087 | if (i == 2 || i == 5) |
8088 | bfd_put_32 (output_bfd, val, ptr); | |
8089 | else | |
8090 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
8091 | } |
8092 | ||
8093 | loc = (htab->srelplt2->contents | |
8094 | + (plt_index * 2 + 1) * RELOC_SIZE (htab)); | |
8095 | ||
8096 | /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation | |
8097 | referencing the GOT for this PLT entry. */ | |
8098 | rel.r_offset = plt_address + 8; | |
8099 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
8100 | rel.r_addend = got_offset; | |
8101 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
8102 | loc += RELOC_SIZE (htab); | |
8103 | ||
8104 | /* Create the R_ARM_ABS32 relocation referencing the | |
8105 | beginning of the PLT for this GOT entry. */ | |
8106 | rel.r_offset = got_address; | |
8107 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
8108 | rel.r_addend = 0; | |
8109 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
b7693d02 | 8110 | } |
00a97672 RS |
8111 | else |
8112 | { | |
8113 | /* Calculate the displacement between the PLT slot and the | |
8114 | entry in the GOT. The eight-byte offset accounts for the | |
8115 | value produced by adding to pc in the first instruction | |
8116 | of the PLT stub. */ | |
8117 | got_displacement = got_address - (plt_address + 8); | |
b7693d02 | 8118 | |
00a97672 RS |
8119 | BFD_ASSERT ((got_displacement & 0xf0000000) == 0); |
8120 | ||
8121 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) | |
8122 | { | |
52ab56c2 PB |
8123 | put_thumb_insn (htab, output_bfd, |
8124 | elf32_arm_plt_thumb_stub[0], ptr - 4); | |
8125 | put_thumb_insn (htab, output_bfd, | |
8126 | elf32_arm_plt_thumb_stub[1], ptr - 2); | |
00a97672 RS |
8127 | } |
8128 | ||
52ab56c2 PB |
8129 | put_arm_insn (htab, output_bfd, |
8130 | elf32_arm_plt_entry[0] | |
8131 | | ((got_displacement & 0x0ff00000) >> 20), | |
8132 | ptr + 0); | |
8133 | put_arm_insn (htab, output_bfd, | |
8134 | elf32_arm_plt_entry[1] | |
8135 | | ((got_displacement & 0x000ff000) >> 12), | |
8136 | ptr+ 4); | |
8137 | put_arm_insn (htab, output_bfd, | |
8138 | elf32_arm_plt_entry[2] | |
8139 | | (got_displacement & 0x00000fff), | |
8140 | ptr + 8); | |
5e681ec4 | 8141 | #ifdef FOUR_WORD_PLT |
52ab56c2 | 8142 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12); |
5e681ec4 | 8143 | #endif |
00a97672 | 8144 | } |
252b5132 | 8145 | |
e5a52504 MM |
8146 | /* Fill in the entry in the global offset table. */ |
8147 | bfd_put_32 (output_bfd, | |
8148 | (splt->output_section->vma | |
8149 | + splt->output_offset), | |
8150 | sgot->contents + got_offset); | |
8151 | ||
00a97672 RS |
8152 | /* Fill in the entry in the .rel(a).plt section. */ |
8153 | rel.r_addend = 0; | |
8154 | rel.r_offset = got_address; | |
e5a52504 MM |
8155 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); |
8156 | } | |
57e8b36a | 8157 | |
00a97672 RS |
8158 | loc = srel->contents + plt_index * RELOC_SIZE (htab); |
8159 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 | 8160 | |
f5385ebf | 8161 | if (!h->def_regular) |
252b5132 RH |
8162 | { |
8163 | /* Mark the symbol as undefined, rather than as defined in | |
8164 | the .plt section. Leave the value alone. */ | |
8165 | sym->st_shndx = SHN_UNDEF; | |
d982ba73 PB |
8166 | /* If the symbol is weak, we do need to clear the value. |
8167 | Otherwise, the PLT entry would provide a definition for | |
8168 | the symbol even if the symbol wasn't defined anywhere, | |
8169 | and so the symbol would never be NULL. */ | |
f5385ebf | 8170 | if (!h->ref_regular_nonweak) |
d982ba73 | 8171 | sym->st_value = 0; |
252b5132 RH |
8172 | } |
8173 | } | |
8174 | ||
ba93b8ac DJ |
8175 | if (h->got.offset != (bfd_vma) -1 |
8176 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 | |
8177 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) | |
252b5132 RH |
8178 | { |
8179 | asection * sgot; | |
8180 | asection * srel; | |
947216bf AM |
8181 | Elf_Internal_Rela rel; |
8182 | bfd_byte *loc; | |
00a97672 | 8183 | bfd_vma offset; |
252b5132 RH |
8184 | |
8185 | /* This symbol has an entry in the global offset table. Set it | |
8186 | up. */ | |
252b5132 | 8187 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
00a97672 | 8188 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got")); |
252b5132 RH |
8189 | BFD_ASSERT (sgot != NULL && srel != NULL); |
8190 | ||
00a97672 RS |
8191 | offset = (h->got.offset & ~(bfd_vma) 1); |
8192 | rel.r_addend = 0; | |
252b5132 RH |
8193 | rel.r_offset = (sgot->output_section->vma |
8194 | + sgot->output_offset | |
00a97672 | 8195 | + offset); |
252b5132 | 8196 | |
5e681ec4 PB |
8197 | /* If this is a static link, or it is a -Bsymbolic link and the |
8198 | symbol is defined locally or was forced to be local because | |
8199 | of a version file, we just want to emit a RELATIVE reloc. | |
8200 | The entry in the global offset table will already have been | |
8201 | initialized in the relocate_section function. */ | |
252b5132 | 8202 | if (info->shared |
5e681ec4 PB |
8203 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
8204 | { | |
8205 | BFD_ASSERT((h->got.offset & 1) != 0); | |
8206 | rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
00a97672 RS |
8207 | if (!htab->use_rel) |
8208 | { | |
8209 | rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset); | |
8210 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); | |
8211 | } | |
5e681ec4 | 8212 | } |
252b5132 RH |
8213 | else |
8214 | { | |
5e681ec4 | 8215 | BFD_ASSERT((h->got.offset & 1) == 0); |
00a97672 | 8216 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); |
252b5132 RH |
8217 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
8218 | } | |
8219 | ||
00a97672 RS |
8220 | loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab); |
8221 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
8222 | } |
8223 | ||
f5385ebf | 8224 | if (h->needs_copy) |
252b5132 RH |
8225 | { |
8226 | asection * s; | |
947216bf AM |
8227 | Elf_Internal_Rela rel; |
8228 | bfd_byte *loc; | |
252b5132 RH |
8229 | |
8230 | /* This symbol needs a copy reloc. Set it up. */ | |
252b5132 RH |
8231 | BFD_ASSERT (h->dynindx != -1 |
8232 | && (h->root.type == bfd_link_hash_defined | |
8233 | || h->root.type == bfd_link_hash_defweak)); | |
8234 | ||
8235 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
00a97672 | 8236 | RELOC_SECTION (htab, ".bss")); |
252b5132 RH |
8237 | BFD_ASSERT (s != NULL); |
8238 | ||
00a97672 | 8239 | rel.r_addend = 0; |
252b5132 RH |
8240 | rel.r_offset = (h->root.u.def.value |
8241 | + h->root.u.def.section->output_section->vma | |
8242 | + h->root.u.def.section->output_offset); | |
8243 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); | |
00a97672 RS |
8244 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); |
8245 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
8246 | } |
8247 | ||
00a97672 RS |
8248 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks, |
8249 | the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative | |
8250 | to the ".got" section. */ | |
252b5132 | 8251 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
00a97672 | 8252 | || (!htab->vxworks_p && h == htab->root.hgot)) |
252b5132 RH |
8253 | sym->st_shndx = SHN_ABS; |
8254 | ||
b34976b6 | 8255 | return TRUE; |
252b5132 RH |
8256 | } |
8257 | ||
8258 | /* Finish up the dynamic sections. */ | |
8259 | ||
b34976b6 | 8260 | static bfd_boolean |
57e8b36a | 8261 | elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) |
252b5132 RH |
8262 | { |
8263 | bfd * dynobj; | |
8264 | asection * sgot; | |
8265 | asection * sdyn; | |
8266 | ||
8267 | dynobj = elf_hash_table (info)->dynobj; | |
8268 | ||
8269 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
229fcec5 | 8270 | BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); |
252b5132 RH |
8271 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
8272 | ||
8273 | if (elf_hash_table (info)->dynamic_sections_created) | |
8274 | { | |
8275 | asection *splt; | |
8276 | Elf32_External_Dyn *dyncon, *dynconend; | |
229fcec5 | 8277 | struct elf32_arm_link_hash_table *htab; |
252b5132 | 8278 | |
229fcec5 | 8279 | htab = elf32_arm_hash_table (info); |
252b5132 | 8280 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
24a1ba0f | 8281 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
252b5132 RH |
8282 | |
8283 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 8284 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
9b485d32 | 8285 | |
252b5132 RH |
8286 | for (; dyncon < dynconend; dyncon++) |
8287 | { | |
8288 | Elf_Internal_Dyn dyn; | |
8289 | const char * name; | |
8290 | asection * s; | |
8291 | ||
8292 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
8293 | ||
8294 | switch (dyn.d_tag) | |
8295 | { | |
229fcec5 MM |
8296 | unsigned int type; |
8297 | ||
252b5132 RH |
8298 | default: |
8299 | break; | |
8300 | ||
229fcec5 MM |
8301 | case DT_HASH: |
8302 | name = ".hash"; | |
8303 | goto get_vma_if_bpabi; | |
8304 | case DT_STRTAB: | |
8305 | name = ".dynstr"; | |
8306 | goto get_vma_if_bpabi; | |
8307 | case DT_SYMTAB: | |
8308 | name = ".dynsym"; | |
8309 | goto get_vma_if_bpabi; | |
c0042f5d MM |
8310 | case DT_VERSYM: |
8311 | name = ".gnu.version"; | |
8312 | goto get_vma_if_bpabi; | |
8313 | case DT_VERDEF: | |
8314 | name = ".gnu.version_d"; | |
8315 | goto get_vma_if_bpabi; | |
8316 | case DT_VERNEED: | |
8317 | name = ".gnu.version_r"; | |
8318 | goto get_vma_if_bpabi; | |
8319 | ||
252b5132 RH |
8320 | case DT_PLTGOT: |
8321 | name = ".got"; | |
8322 | goto get_vma; | |
8323 | case DT_JMPREL: | |
00a97672 | 8324 | name = RELOC_SECTION (htab, ".plt"); |
252b5132 RH |
8325 | get_vma: |
8326 | s = bfd_get_section_by_name (output_bfd, name); | |
8327 | BFD_ASSERT (s != NULL); | |
229fcec5 MM |
8328 | if (!htab->symbian_p) |
8329 | dyn.d_un.d_ptr = s->vma; | |
8330 | else | |
8331 | /* In the BPABI, tags in the PT_DYNAMIC section point | |
8332 | at the file offset, not the memory address, for the | |
8333 | convenience of the post linker. */ | |
8334 | dyn.d_un.d_ptr = s->filepos; | |
252b5132 RH |
8335 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
8336 | break; | |
8337 | ||
229fcec5 MM |
8338 | get_vma_if_bpabi: |
8339 | if (htab->symbian_p) | |
8340 | goto get_vma; | |
8341 | break; | |
8342 | ||
252b5132 | 8343 | case DT_PLTRELSZ: |
00a97672 RS |
8344 | s = bfd_get_section_by_name (output_bfd, |
8345 | RELOC_SECTION (htab, ".plt")); | |
252b5132 | 8346 | BFD_ASSERT (s != NULL); |
eea6121a | 8347 | dyn.d_un.d_val = s->size; |
252b5132 RH |
8348 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
8349 | break; | |
229fcec5 | 8350 | |
252b5132 | 8351 | case DT_RELSZ: |
00a97672 | 8352 | case DT_RELASZ: |
229fcec5 MM |
8353 | if (!htab->symbian_p) |
8354 | { | |
8355 | /* My reading of the SVR4 ABI indicates that the | |
8356 | procedure linkage table relocs (DT_JMPREL) should be | |
8357 | included in the overall relocs (DT_REL). This is | |
8358 | what Solaris does. However, UnixWare can not handle | |
8359 | that case. Therefore, we override the DT_RELSZ entry | |
8360 | here to make it not include the JMPREL relocs. Since | |
00a97672 | 8361 | the linker script arranges for .rel(a).plt to follow all |
229fcec5 MM |
8362 | other relocation sections, we don't have to worry |
8363 | about changing the DT_REL entry. */ | |
00a97672 RS |
8364 | s = bfd_get_section_by_name (output_bfd, |
8365 | RELOC_SECTION (htab, ".plt")); | |
229fcec5 MM |
8366 | if (s != NULL) |
8367 | dyn.d_un.d_val -= s->size; | |
8368 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
8369 | break; | |
8370 | } | |
8371 | /* Fall through */ | |
8372 | ||
8373 | case DT_REL: | |
8374 | case DT_RELA: | |
229fcec5 MM |
8375 | /* In the BPABI, the DT_REL tag must point at the file |
8376 | offset, not the VMA, of the first relocation | |
8377 | section. So, we use code similar to that in | |
8378 | elflink.c, but do not check for SHF_ALLOC on the | |
8379 | relcoation section, since relocations sections are | |
8380 | never allocated under the BPABI. The comments above | |
8381 | about Unixware notwithstanding, we include all of the | |
8382 | relocations here. */ | |
8383 | if (htab->symbian_p) | |
8384 | { | |
8385 | unsigned int i; | |
8386 | type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) | |
8387 | ? SHT_REL : SHT_RELA); | |
8388 | dyn.d_un.d_val = 0; | |
8389 | for (i = 1; i < elf_numsections (output_bfd); i++) | |
8390 | { | |
8391 | Elf_Internal_Shdr *hdr | |
8392 | = elf_elfsections (output_bfd)[i]; | |
8393 | if (hdr->sh_type == type) | |
8394 | { | |
8395 | if (dyn.d_tag == DT_RELSZ | |
8396 | || dyn.d_tag == DT_RELASZ) | |
8397 | dyn.d_un.d_val += hdr->sh_size; | |
de52dba4 AM |
8398 | else if ((ufile_ptr) hdr->sh_offset |
8399 | <= dyn.d_un.d_val - 1) | |
229fcec5 MM |
8400 | dyn.d_un.d_val = hdr->sh_offset; |
8401 | } | |
8402 | } | |
8403 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
8404 | } | |
252b5132 | 8405 | break; |
88f7bcd5 NC |
8406 | |
8407 | /* Set the bottom bit of DT_INIT/FINI if the | |
8408 | corresponding function is Thumb. */ | |
8409 | case DT_INIT: | |
8410 | name = info->init_function; | |
8411 | goto get_sym; | |
8412 | case DT_FINI: | |
8413 | name = info->fini_function; | |
8414 | get_sym: | |
8415 | /* If it wasn't set by elf_bfd_final_link | |
4cc11e76 | 8416 | then there is nothing to adjust. */ |
88f7bcd5 NC |
8417 | if (dyn.d_un.d_val != 0) |
8418 | { | |
8419 | struct elf_link_hash_entry * eh; | |
8420 | ||
8421 | eh = elf_link_hash_lookup (elf_hash_table (info), name, | |
b34976b6 | 8422 | FALSE, FALSE, TRUE); |
88f7bcd5 NC |
8423 | if (eh != (struct elf_link_hash_entry *) NULL |
8424 | && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) | |
8425 | { | |
8426 | dyn.d_un.d_val |= 1; | |
b34976b6 | 8427 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
88f7bcd5 NC |
8428 | } |
8429 | } | |
8430 | break; | |
252b5132 RH |
8431 | } |
8432 | } | |
8433 | ||
24a1ba0f | 8434 | /* Fill in the first entry in the procedure linkage table. */ |
e5a52504 | 8435 | if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) |
f7a74f8c | 8436 | { |
00a97672 RS |
8437 | const bfd_vma *plt0_entry; |
8438 | bfd_vma got_address, plt_address, got_displacement; | |
8439 | ||
8440 | /* Calculate the addresses of the GOT and PLT. */ | |
8441 | got_address = sgot->output_section->vma + sgot->output_offset; | |
8442 | plt_address = splt->output_section->vma + splt->output_offset; | |
8443 | ||
8444 | if (htab->vxworks_p) | |
8445 | { | |
8446 | /* The VxWorks GOT is relocated by the dynamic linker. | |
8447 | Therefore, we must emit relocations rather than simply | |
8448 | computing the values now. */ | |
8449 | Elf_Internal_Rela rel; | |
8450 | ||
8451 | plt0_entry = elf32_arm_vxworks_exec_plt0_entry; | |
52ab56c2 PB |
8452 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
8453 | splt->contents + 0); | |
8454 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
8455 | splt->contents + 4); | |
8456 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
8457 | splt->contents + 8); | |
00a97672 RS |
8458 | bfd_put_32 (output_bfd, got_address, splt->contents + 12); |
8459 | ||
8460 | /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */ | |
8461 | rel.r_offset = plt_address + 12; | |
8462 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
8463 | rel.r_addend = 0; | |
8464 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, | |
8465 | htab->srelplt2->contents); | |
8466 | } | |
8467 | else | |
8468 | { | |
8469 | got_displacement = got_address - (plt_address + 16); | |
8470 | ||
8471 | plt0_entry = elf32_arm_plt0_entry; | |
52ab56c2 PB |
8472 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
8473 | splt->contents + 0); | |
8474 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
8475 | splt->contents + 4); | |
8476 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
8477 | splt->contents + 8); | |
8478 | put_arm_insn (htab, output_bfd, plt0_entry[3], | |
8479 | splt->contents + 12); | |
5e681ec4 | 8480 | |
5e681ec4 | 8481 | #ifdef FOUR_WORD_PLT |
00a97672 RS |
8482 | /* The displacement value goes in the otherwise-unused |
8483 | last word of the second entry. */ | |
8484 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); | |
5e681ec4 | 8485 | #else |
00a97672 | 8486 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); |
5e681ec4 | 8487 | #endif |
00a97672 | 8488 | } |
f7a74f8c | 8489 | } |
252b5132 RH |
8490 | |
8491 | /* UnixWare sets the entsize of .plt to 4, although that doesn't | |
8492 | really seem like the right value. */ | |
8493 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; | |
00a97672 RS |
8494 | |
8495 | if (htab->vxworks_p && !info->shared && htab->splt->size > 0) | |
8496 | { | |
8497 | /* Correct the .rel(a).plt.unloaded relocations. They will have | |
8498 | incorrect symbol indexes. */ | |
8499 | int num_plts; | |
eed62c48 | 8500 | unsigned char *p; |
00a97672 RS |
8501 | |
8502 | num_plts = ((htab->splt->size - htab->plt_header_size) | |
8503 | / htab->plt_entry_size); | |
8504 | p = htab->srelplt2->contents + RELOC_SIZE (htab); | |
8505 | ||
8506 | for (; num_plts; num_plts--) | |
8507 | { | |
8508 | Elf_Internal_Rela rel; | |
8509 | ||
8510 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
8511 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
8512 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
8513 | p += RELOC_SIZE (htab); | |
8514 | ||
8515 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
8516 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
8517 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
8518 | p += RELOC_SIZE (htab); | |
8519 | } | |
8520 | } | |
252b5132 RH |
8521 | } |
8522 | ||
8523 | /* Fill in the first three entries in the global offset table. */ | |
229fcec5 | 8524 | if (sgot) |
252b5132 | 8525 | { |
229fcec5 MM |
8526 | if (sgot->size > 0) |
8527 | { | |
8528 | if (sdyn == NULL) | |
8529 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
8530 | else | |
8531 | bfd_put_32 (output_bfd, | |
8532 | sdyn->output_section->vma + sdyn->output_offset, | |
8533 | sgot->contents); | |
8534 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
8535 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
8536 | } | |
252b5132 | 8537 | |
229fcec5 MM |
8538 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
8539 | } | |
252b5132 | 8540 | |
b34976b6 | 8541 | return TRUE; |
252b5132 RH |
8542 | } |
8543 | ||
ba96a88f | 8544 | static void |
57e8b36a | 8545 | elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) |
ba96a88f | 8546 | { |
9b485d32 | 8547 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ |
e489d0ae | 8548 | struct elf32_arm_link_hash_table *globals; |
ba96a88f NC |
8549 | |
8550 | i_ehdrp = elf_elfheader (abfd); | |
8551 | ||
94a3258f PB |
8552 | if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN) |
8553 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM; | |
8554 | else | |
8555 | i_ehdrp->e_ident[EI_OSABI] = 0; | |
ba96a88f | 8556 | i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION; |
e489d0ae | 8557 | |
93204d3a PB |
8558 | if (link_info) |
8559 | { | |
8560 | globals = elf32_arm_hash_table (link_info); | |
8561 | if (globals->byteswap_code) | |
8562 | i_ehdrp->e_flags |= EF_ARM_BE8; | |
8563 | } | |
ba96a88f NC |
8564 | } |
8565 | ||
99e4ae17 | 8566 | static enum elf_reloc_type_class |
57e8b36a | 8567 | elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) |
99e4ae17 | 8568 | { |
f51e552e | 8569 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
99e4ae17 AJ |
8570 | { |
8571 | case R_ARM_RELATIVE: | |
8572 | return reloc_class_relative; | |
8573 | case R_ARM_JUMP_SLOT: | |
8574 | return reloc_class_plt; | |
8575 | case R_ARM_COPY: | |
8576 | return reloc_class_copy; | |
8577 | default: | |
8578 | return reloc_class_normal; | |
8579 | } | |
8580 | } | |
8581 | ||
e16bb312 NC |
8582 | /* Set the right machine number for an Arm ELF file. */ |
8583 | ||
8584 | static bfd_boolean | |
57e8b36a | 8585 | elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) |
e16bb312 NC |
8586 | { |
8587 | if (hdr->sh_type == SHT_NOTE) | |
8588 | *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
8589 | ||
8590 | return TRUE; | |
8591 | } | |
8592 | ||
e489d0ae | 8593 | static void |
57e8b36a | 8594 | elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) |
e16bb312 | 8595 | { |
5a6c6817 | 8596 | bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); |
e16bb312 NC |
8597 | } |
8598 | ||
40a18ebd NC |
8599 | /* Return TRUE if this is an unwinding table entry. */ |
8600 | ||
8601 | static bfd_boolean | |
8602 | is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name) | |
8603 | { | |
8604 | size_t len1, len2; | |
8605 | ||
8606 | len1 = sizeof (ELF_STRING_ARM_unwind) - 1; | |
8607 | len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1; | |
8608 | return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0 | |
8609 | || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0); | |
8610 | } | |
8611 | ||
8612 | ||
8613 | /* Set the type and flags for an ARM section. We do this by | |
8614 | the section name, which is a hack, but ought to work. */ | |
8615 | ||
8616 | static bfd_boolean | |
8617 | elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec) | |
8618 | { | |
8619 | const char * name; | |
8620 | ||
8621 | name = bfd_get_section_name (abfd, sec); | |
8622 | ||
8623 | if (is_arm_elf_unwind_section_name (abfd, name)) | |
8624 | { | |
8625 | hdr->sh_type = SHT_ARM_EXIDX; | |
8626 | hdr->sh_flags |= SHF_LINK_ORDER; | |
8627 | } | |
ee065d83 PB |
8628 | else if (strcmp(name, ".ARM.attributes") == 0) |
8629 | { | |
8630 | hdr->sh_type = SHT_ARM_ATTRIBUTES; | |
8631 | } | |
40a18ebd NC |
8632 | return TRUE; |
8633 | } | |
8634 | ||
ee065d83 PB |
8635 | /* Parse an Arm EABI attributes section. */ |
8636 | static void | |
8637 | elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) | |
8638 | { | |
8639 | bfd_byte *contents; | |
8640 | bfd_byte *p; | |
8641 | bfd_vma len; | |
8642 | ||
8643 | contents = bfd_malloc (hdr->sh_size); | |
8644 | if (!contents) | |
8645 | return; | |
8646 | if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0, | |
8647 | hdr->sh_size)) | |
8648 | { | |
8649 | free (contents); | |
8650 | return; | |
8651 | } | |
8652 | p = contents; | |
8653 | if (*(p++) == 'A') | |
8654 | { | |
8655 | len = hdr->sh_size - 1; | |
8656 | while (len > 0) | |
8657 | { | |
8658 | int namelen; | |
8659 | bfd_vma section_len; | |
8660 | ||
8661 | section_len = bfd_get_32 (abfd, p); | |
8662 | p += 4; | |
8663 | if (section_len > len) | |
8664 | section_len = len; | |
8665 | len -= section_len; | |
8666 | namelen = strlen ((char *)p) + 1; | |
8667 | section_len -= namelen + 4; | |
8668 | if (strcmp((char *)p, "aeabi") != 0) | |
8669 | { | |
8670 | /* Vendor section. Ignore it. */ | |
8671 | p += namelen + section_len; | |
8672 | } | |
8673 | else | |
8674 | { | |
8675 | p += namelen; | |
8676 | while (section_len > 0) | |
8677 | { | |
8678 | int tag; | |
8679 | unsigned int n; | |
8680 | unsigned int val; | |
8681 | bfd_vma subsection_len; | |
8682 | bfd_byte *end; | |
8683 | ||
8684 | tag = read_unsigned_leb128 (abfd, p, &n); | |
8685 | p += n; | |
8686 | subsection_len = bfd_get_32 (abfd, p); | |
8687 | p += 4; | |
8688 | if (subsection_len > section_len) | |
8689 | subsection_len = section_len; | |
8690 | section_len -= subsection_len; | |
8691 | subsection_len -= n + 4; | |
8692 | end = p + subsection_len; | |
8693 | switch (tag) | |
8694 | { | |
8695 | case Tag_File: | |
8696 | while (p < end) | |
8697 | { | |
8698 | bfd_boolean is_string; | |
8699 | ||
8700 | tag = read_unsigned_leb128 (abfd, p, &n); | |
8701 | p += n; | |
8702 | if (tag == 4 || tag == 5) | |
8703 | is_string = 1; | |
8704 | else if (tag < 32) | |
8705 | is_string = 0; | |
8706 | else | |
8707 | is_string = (tag & 1) != 0; | |
8708 | if (tag == Tag_compatibility) | |
8709 | { | |
8710 | val = read_unsigned_leb128 (abfd, p, &n); | |
8711 | p += n; | |
8712 | elf32_arm_add_eabi_attr_compat (abfd, val, | |
8713 | (char *)p); | |
8714 | p += strlen ((char *)p) + 1; | |
8715 | } | |
8716 | else if (is_string) | |
8717 | { | |
8718 | elf32_arm_add_eabi_attr_string (abfd, tag, | |
8719 | (char *)p); | |
8720 | p += strlen ((char *)p) + 1; | |
8721 | } | |
8722 | else | |
8723 | { | |
8724 | val = read_unsigned_leb128 (abfd, p, &n); | |
8725 | p += n; | |
8726 | elf32_arm_add_eabi_attr_int (abfd, tag, val); | |
8727 | } | |
8728 | } | |
8729 | break; | |
8730 | case Tag_Section: | |
8731 | case Tag_Symbol: | |
8732 | /* Don't have anywhere convenient to attach these. | |
8733 | Fall through for now. */ | |
8734 | default: | |
8735 | /* Ignore things we don't kow about. */ | |
8736 | p += subsection_len; | |
8737 | subsection_len = 0; | |
8738 | break; | |
8739 | } | |
8740 | } | |
8741 | } | |
8742 | } | |
8743 | } | |
8744 | free (contents); | |
8745 | } | |
8746 | ||
6dc132d9 L |
8747 | /* Handle an ARM specific section when reading an object file. This is |
8748 | called when bfd_section_from_shdr finds a section with an unknown | |
8749 | type. */ | |
40a18ebd NC |
8750 | |
8751 | static bfd_boolean | |
8752 | elf32_arm_section_from_shdr (bfd *abfd, | |
8753 | Elf_Internal_Shdr * hdr, | |
6dc132d9 L |
8754 | const char *name, |
8755 | int shindex) | |
40a18ebd NC |
8756 | { |
8757 | /* There ought to be a place to keep ELF backend specific flags, but | |
8758 | at the moment there isn't one. We just keep track of the | |
8759 | sections by their name, instead. Fortunately, the ABI gives | |
8760 | names for all the ARM specific sections, so we will probably get | |
8761 | away with this. */ | |
8762 | switch (hdr->sh_type) | |
8763 | { | |
8764 | case SHT_ARM_EXIDX: | |
0951f019 RE |
8765 | case SHT_ARM_PREEMPTMAP: |
8766 | case SHT_ARM_ATTRIBUTES: | |
40a18ebd NC |
8767 | break; |
8768 | ||
8769 | default: | |
8770 | return FALSE; | |
8771 | } | |
8772 | ||
6dc132d9 | 8773 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
40a18ebd NC |
8774 | return FALSE; |
8775 | ||
ee065d83 PB |
8776 | if (hdr->sh_type == SHT_ARM_ATTRIBUTES) |
8777 | elf32_arm_parse_attributes(abfd, hdr); | |
40a18ebd NC |
8778 | return TRUE; |
8779 | } | |
e489d0ae | 8780 | |
8e3de13a NC |
8781 | /* A structure used to record a list of sections, independently |
8782 | of the next and prev fields in the asection structure. */ | |
8783 | typedef struct section_list | |
8784 | { | |
8785 | asection * sec; | |
8786 | struct section_list * next; | |
8787 | struct section_list * prev; | |
8788 | } | |
8789 | section_list; | |
8790 | ||
8791 | /* Unfortunately we need to keep a list of sections for which | |
8792 | an _arm_elf_section_data structure has been allocated. This | |
8793 | is because it is possible for functions like elf32_arm_write_section | |
8794 | to be called on a section which has had an elf_data_structure | |
8795 | allocated for it (and so the used_by_bfd field is valid) but | |
8796 | for which the ARM extended version of this structure - the | |
8797 | _arm_elf_section_data structure - has not been allocated. */ | |
8798 | static section_list * sections_with_arm_elf_section_data = NULL; | |
8799 | ||
8800 | static void | |
957c6e41 | 8801 | record_section_with_arm_elf_section_data (asection * sec) |
8e3de13a NC |
8802 | { |
8803 | struct section_list * entry; | |
8804 | ||
957c6e41 | 8805 | entry = bfd_malloc (sizeof (* entry)); |
8e3de13a NC |
8806 | if (entry == NULL) |
8807 | return; | |
8808 | entry->sec = sec; | |
8809 | entry->next = sections_with_arm_elf_section_data; | |
8810 | entry->prev = NULL; | |
8811 | if (entry->next != NULL) | |
8812 | entry->next->prev = entry; | |
8813 | sections_with_arm_elf_section_data = entry; | |
8814 | } | |
8815 | ||
44444f50 NC |
8816 | static struct section_list * |
8817 | find_arm_elf_section_entry (asection * sec) | |
8e3de13a NC |
8818 | { |
8819 | struct section_list * entry; | |
bd4aae00 | 8820 | static struct section_list * last_entry = NULL; |
8e3de13a | 8821 | |
bd4aae00 NC |
8822 | /* This is a short cut for the typical case where the sections are added |
8823 | to the sections_with_arm_elf_section_data list in forward order and | |
8824 | then looked up here in backwards order. This makes a real difference | |
8825 | to the ld-srec/sec64k.exp linker test. */ | |
44444f50 | 8826 | entry = sections_with_arm_elf_section_data; |
bd4aae00 NC |
8827 | if (last_entry != NULL) |
8828 | { | |
8829 | if (last_entry->sec == sec) | |
44444f50 NC |
8830 | entry = last_entry; |
8831 | else if (last_entry->next != NULL | |
8832 | && last_entry->next->sec == sec) | |
8833 | entry = last_entry->next; | |
bd4aae00 | 8834 | } |
44444f50 NC |
8835 | |
8836 | for (; entry; entry = entry->next) | |
8e3de13a | 8837 | if (entry->sec == sec) |
44444f50 | 8838 | break; |
bd4aae00 | 8839 | |
44444f50 NC |
8840 | if (entry) |
8841 | /* Record the entry prior to this one - it is the entry we are most | |
8842 | likely to want to locate next time. Also this way if we have been | |
8843 | called from unrecord_section_with_arm_elf_section_data() we will not | |
8844 | be caching a pointer that is about to be freed. */ | |
8845 | last_entry = entry->prev; | |
8846 | ||
8847 | return entry; | |
8848 | } | |
8849 | ||
8850 | static _arm_elf_section_data * | |
8851 | get_arm_elf_section_data (asection * sec) | |
8852 | { | |
8853 | struct section_list * entry; | |
8854 | ||
8855 | entry = find_arm_elf_section_entry (sec); | |
8856 | ||
8857 | if (entry) | |
8858 | return elf32_arm_section_data (entry->sec); | |
8859 | else | |
8860 | return NULL; | |
8e3de13a NC |
8861 | } |
8862 | ||
8863 | static void | |
8864 | unrecord_section_with_arm_elf_section_data (asection * sec) | |
8865 | { | |
8866 | struct section_list * entry; | |
8867 | ||
44444f50 NC |
8868 | entry = find_arm_elf_section_entry (sec); |
8869 | ||
8870 | if (entry) | |
8871 | { | |
8872 | if (entry->prev != NULL) | |
8873 | entry->prev->next = entry->next; | |
8874 | if (entry->next != NULL) | |
8875 | entry->next->prev = entry->prev; | |
8876 | if (entry == sections_with_arm_elf_section_data) | |
8877 | sections_with_arm_elf_section_data = entry->next; | |
8878 | free (entry); | |
8879 | } | |
8e3de13a NC |
8880 | } |
8881 | ||
e489d0ae PB |
8882 | /* Called for each symbol. Builds a section map based on mapping symbols. |
8883 | Does not alter any of the symbols. */ | |
8884 | ||
8885 | static bfd_boolean | |
8886 | elf32_arm_output_symbol_hook (struct bfd_link_info *info, | |
8887 | const char *name, | |
8888 | Elf_Internal_Sym *elfsym, | |
8889 | asection *input_sec, | |
00a97672 | 8890 | struct elf_link_hash_entry *h) |
e489d0ae PB |
8891 | { |
8892 | int mapcount; | |
8893 | elf32_arm_section_map *map; | |
8e3de13a NC |
8894 | elf32_arm_section_map *newmap; |
8895 | _arm_elf_section_data *arm_data; | |
e489d0ae PB |
8896 | struct elf32_arm_link_hash_table *globals; |
8897 | ||
00a97672 RS |
8898 | globals = elf32_arm_hash_table (info); |
8899 | if (globals->vxworks_p | |
8900 | && !elf_vxworks_link_output_symbol_hook (info, name, elfsym, | |
8901 | input_sec, h)) | |
8902 | return FALSE; | |
8903 | ||
e489d0ae PB |
8904 | /* Only do this on final link. */ |
8905 | if (info->relocatable) | |
8906 | return TRUE; | |
8907 | ||
8908 | /* Only build a map if we need to byteswap code. */ | |
e489d0ae PB |
8909 | if (!globals->byteswap_code) |
8910 | return TRUE; | |
8911 | ||
8912 | /* We only want mapping symbols. */ | |
b0796911 | 8913 | if (!bfd_is_arm_special_symbol_name (name, BFD_ARM_SPECIAL_SYM_TYPE_MAP)) |
e489d0ae PB |
8914 | return TRUE; |
8915 | ||
8e3de13a NC |
8916 | /* If this section has not been allocated an _arm_elf_section_data |
8917 | structure then we cannot record anything. */ | |
8918 | arm_data = get_arm_elf_section_data (input_sec); | |
8919 | if (arm_data == NULL) | |
8920 | return TRUE; | |
8921 | ||
8922 | mapcount = arm_data->mapcount + 1; | |
8923 | map = arm_data->map; | |
d7f735da | 8924 | |
e489d0ae PB |
8925 | /* TODO: This may be inefficient, but we probably don't usually have many |
8926 | mapping symbols per section. */ | |
8e3de13a NC |
8927 | newmap = bfd_realloc (map, mapcount * sizeof (* map)); |
8928 | if (newmap != NULL) | |
8929 | { | |
8930 | arm_data->map = newmap; | |
8931 | arm_data->mapcount = mapcount; | |
8932 | ||
d7f735da NC |
8933 | newmap[mapcount - 1].vma = elfsym->st_value; |
8934 | newmap[mapcount - 1].type = name[1]; | |
8e3de13a | 8935 | } |
57e8b36a | 8936 | |
e489d0ae PB |
8937 | return TRUE; |
8938 | } | |
8939 | ||
4e617b1e PB |
8940 | typedef struct |
8941 | { | |
8942 | void *finfo; | |
8943 | struct bfd_link_info *info; | |
8944 | int plt_shndx; | |
8945 | bfd_vma plt_offset; | |
8946 | bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *, | |
8947 | asection *, struct elf_link_hash_entry *); | |
8948 | } output_arch_syminfo; | |
8949 | ||
8950 | enum map_symbol_type | |
8951 | { | |
8952 | ARM_MAP_ARM, | |
8953 | ARM_MAP_THUMB, | |
8954 | ARM_MAP_DATA | |
8955 | }; | |
8956 | ||
8957 | ||
8958 | /* Output a single PLT mapping symbol. */ | |
8959 | ||
8960 | static bfd_boolean | |
8961 | elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi, | |
8962 | enum map_symbol_type type, | |
8963 | bfd_vma offset) | |
8964 | { | |
8965 | static const char *names[3] = {"$a", "$t", "$d"}; | |
8966 | struct elf32_arm_link_hash_table *htab; | |
8967 | Elf_Internal_Sym sym; | |
8968 | ||
8969 | htab = elf32_arm_hash_table (osi->info); | |
8970 | sym.st_value = osi->plt_offset + offset; | |
8971 | sym.st_size = 0; | |
8972 | sym.st_other = 0; | |
8973 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
8974 | sym.st_shndx = osi->plt_shndx; | |
8975 | if (!osi->func (osi->finfo, names[type], &sym, htab->splt, NULL)) | |
8976 | return FALSE; | |
8977 | return TRUE; | |
8978 | } | |
8979 | ||
8980 | ||
8981 | /* Output mapping symbols for PLT entries associated with H. */ | |
8982 | ||
8983 | static bfd_boolean | |
8984 | elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf) | |
8985 | { | |
8986 | output_arch_syminfo *osi = (output_arch_syminfo *) inf; | |
8987 | struct elf32_arm_link_hash_table *htab; | |
8988 | struct elf32_arm_link_hash_entry *eh; | |
8989 | bfd_vma addr; | |
8990 | ||
8991 | htab = elf32_arm_hash_table (osi->info); | |
8992 | ||
8993 | if (h->root.type == bfd_link_hash_indirect) | |
8994 | return TRUE; | |
8995 | ||
8996 | if (h->root.type == bfd_link_hash_warning) | |
8997 | /* When warning symbols are created, they **replace** the "real" | |
8998 | entry in the hash table, thus we never get to see the real | |
8999 | symbol in a hash traversal. So look at it now. */ | |
9000 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
9001 | ||
9002 | if (h->plt.offset == (bfd_vma) -1) | |
9003 | return TRUE; | |
9004 | ||
9005 | eh = (struct elf32_arm_link_hash_entry *) h; | |
9006 | addr = h->plt.offset; | |
9007 | if (htab->symbian_p) | |
9008 | { | |
9009 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
9010 | return FALSE; | |
9011 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4)) | |
9012 | return FALSE; | |
9013 | } | |
9014 | else if (htab->vxworks_p) | |
9015 | { | |
9016 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
9017 | return FALSE; | |
9018 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8)) | |
9019 | return FALSE; | |
9020 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12)) | |
9021 | return FALSE; | |
9022 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20)) | |
9023 | return FALSE; | |
9024 | } | |
9025 | else | |
9026 | { | |
9027 | bfd_boolean thumb_stub; | |
9028 | ||
9029 | thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx; | |
9030 | if (thumb_stub) | |
9031 | { | |
9032 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4)) | |
9033 | return FALSE; | |
9034 | } | |
9035 | #ifdef FOUR_WORD_PLT | |
9036 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
9037 | return FALSE; | |
9038 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12)) | |
9039 | return FALSE; | |
9040 | #else | |
9041 | /* A three-word PLT with no Thumb thunk contains only Arm code, | |
9042 | so only need to output a mapping symbol for the first PLT entry and | |
9043 | entries with thumb thunks. */ | |
9044 | if (thumb_stub || addr == 20) | |
9045 | { | |
9046 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
9047 | return FALSE; | |
9048 | } | |
9049 | #endif | |
9050 | } | |
9051 | ||
9052 | return TRUE; | |
9053 | } | |
9054 | ||
9055 | ||
9056 | /* Output mapping symbols for the PLT. */ | |
9057 | ||
9058 | static bfd_boolean | |
9059 | elf32_arm_output_arch_local_syms (bfd *output_bfd, | |
9060 | struct bfd_link_info *info, | |
9061 | void *finfo, bfd_boolean (*func) (void *, const char *, | |
9062 | Elf_Internal_Sym *, | |
9063 | asection *, | |
9064 | struct elf_link_hash_entry *)) | |
9065 | { | |
9066 | output_arch_syminfo osi; | |
9067 | struct elf32_arm_link_hash_table *htab; | |
9068 | ||
9069 | htab = elf32_arm_hash_table (info); | |
9070 | if (!htab->splt || htab->splt->size == 0) | |
9071 | return TRUE; | |
9072 | ||
9073 | check_use_blx(htab); | |
9074 | osi.finfo = finfo; | |
9075 | osi.info = info; | |
9076 | osi.func = func; | |
9077 | osi.plt_shndx = _bfd_elf_section_from_bfd_section (output_bfd, | |
9078 | htab->splt->output_section); | |
9079 | osi.plt_offset = htab->splt->output_section->vma; | |
9080 | ||
9081 | /* Output mapping symbols for the plt header. SymbianOS does not have a | |
9082 | plt header. */ | |
9083 | if (htab->vxworks_p) | |
9084 | { | |
9085 | /* VxWorks shared libraries have no PLT header. */ | |
9086 | if (!info->shared) | |
9087 | { | |
9088 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
9089 | return FALSE; | |
9090 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12)) | |
9091 | return FALSE; | |
9092 | } | |
9093 | } | |
9094 | else if (!htab->symbian_p) | |
9095 | { | |
9096 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
9097 | return FALSE; | |
9098 | #ifndef FOUR_WORD_PLT | |
9099 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16)) | |
9100 | return FALSE; | |
9101 | #endif | |
9102 | } | |
9103 | ||
9104 | elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi); | |
9105 | return TRUE; | |
9106 | } | |
9107 | ||
e489d0ae PB |
9108 | /* Allocate target specific section data. */ |
9109 | ||
9110 | static bfd_boolean | |
9111 | elf32_arm_new_section_hook (bfd *abfd, asection *sec) | |
9112 | { | |
f592407e AM |
9113 | if (!sec->used_by_bfd) |
9114 | { | |
9115 | _arm_elf_section_data *sdata; | |
9116 | bfd_size_type amt = sizeof (*sdata); | |
e489d0ae | 9117 | |
f592407e AM |
9118 | sdata = bfd_zalloc (abfd, amt); |
9119 | if (sdata == NULL) | |
9120 | return FALSE; | |
9121 | sec->used_by_bfd = sdata; | |
9122 | } | |
e489d0ae | 9123 | |
957c6e41 | 9124 | record_section_with_arm_elf_section_data (sec); |
8e3de13a | 9125 | |
e489d0ae PB |
9126 | return _bfd_elf_new_section_hook (abfd, sec); |
9127 | } | |
9128 | ||
9129 | ||
9130 | /* Used to order a list of mapping symbols by address. */ | |
9131 | ||
9132 | static int | |
9133 | elf32_arm_compare_mapping (const void * a, const void * b) | |
9134 | { | |
9135 | return ((const elf32_arm_section_map *) a)->vma | |
9136 | > ((const elf32_arm_section_map *) b)->vma; | |
9137 | } | |
9138 | ||
9139 | ||
9140 | /* Do code byteswapping. Return FALSE afterwards so that the section is | |
9141 | written out as normal. */ | |
9142 | ||
9143 | static bfd_boolean | |
9144 | elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec, | |
9145 | bfd_byte *contents) | |
9146 | { | |
9147 | int mapcount; | |
8e3de13a | 9148 | _arm_elf_section_data *arm_data; |
e489d0ae PB |
9149 | elf32_arm_section_map *map; |
9150 | bfd_vma ptr; | |
9151 | bfd_vma end; | |
9152 | bfd_vma offset; | |
9153 | bfd_byte tmp; | |
9154 | int i; | |
57e8b36a | 9155 | |
8e3de13a NC |
9156 | /* If this section has not been allocated an _arm_elf_section_data |
9157 | structure then we cannot record anything. */ | |
9158 | arm_data = get_arm_elf_section_data (sec); | |
9159 | if (arm_data == NULL) | |
9160 | return FALSE; | |
9161 | ||
9162 | mapcount = arm_data->mapcount; | |
9163 | map = arm_data->map; | |
e489d0ae PB |
9164 | |
9165 | if (mapcount == 0) | |
9166 | return FALSE; | |
9167 | ||
8e3de13a | 9168 | qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping); |
e489d0ae PB |
9169 | |
9170 | offset = sec->output_section->vma + sec->output_offset; | |
9171 | ptr = map[0].vma - offset; | |
9172 | for (i = 0; i < mapcount; i++) | |
9173 | { | |
9174 | if (i == mapcount - 1) | |
eea6121a | 9175 | end = sec->size; |
e489d0ae PB |
9176 | else |
9177 | end = map[i + 1].vma - offset; | |
57e8b36a | 9178 | |
e489d0ae PB |
9179 | switch (map[i].type) |
9180 | { | |
9181 | case 'a': | |
9182 | /* Byte swap code words. */ | |
9183 | while (ptr + 3 < end) | |
9184 | { | |
9185 | tmp = contents[ptr]; | |
9186 | contents[ptr] = contents[ptr + 3]; | |
9187 | contents[ptr + 3] = tmp; | |
9188 | tmp = contents[ptr + 1]; | |
9189 | contents[ptr + 1] = contents[ptr + 2]; | |
9190 | contents[ptr + 2] = tmp; | |
9191 | ptr += 4; | |
9192 | } | |
9193 | break; | |
9194 | ||
9195 | case 't': | |
9196 | /* Byte swap code halfwords. */ | |
9197 | while (ptr + 1 < end) | |
9198 | { | |
9199 | tmp = contents[ptr]; | |
9200 | contents[ptr] = contents[ptr + 1]; | |
9201 | contents[ptr + 1] = tmp; | |
9202 | ptr += 2; | |
9203 | } | |
9204 | break; | |
9205 | ||
9206 | case 'd': | |
9207 | /* Leave data alone. */ | |
9208 | break; | |
9209 | } | |
9210 | ptr = end; | |
9211 | } | |
8e3de13a | 9212 | |
93204d3a | 9213 | free (map); |
8e3de13a NC |
9214 | arm_data->mapcount = 0; |
9215 | arm_data->map = NULL; | |
9216 | unrecord_section_with_arm_elf_section_data (sec); | |
9217 | ||
e489d0ae PB |
9218 | return FALSE; |
9219 | } | |
9220 | ||
957c6e41 NC |
9221 | static void |
9222 | unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED, | |
9223 | asection * sec, | |
9224 | void * ignore ATTRIBUTE_UNUSED) | |
9225 | { | |
9226 | unrecord_section_with_arm_elf_section_data (sec); | |
9227 | } | |
9228 | ||
9229 | static bfd_boolean | |
9230 | elf32_arm_close_and_cleanup (bfd * abfd) | |
9231 | { | |
b25e3d87 L |
9232 | if (abfd->sections) |
9233 | bfd_map_over_sections (abfd, | |
9234 | unrecord_section_via_map_over_sections, | |
9235 | NULL); | |
957c6e41 NC |
9236 | |
9237 | return _bfd_elf_close_and_cleanup (abfd); | |
9238 | } | |
9239 | ||
b25e3d87 L |
9240 | static bfd_boolean |
9241 | elf32_arm_bfd_free_cached_info (bfd * abfd) | |
9242 | { | |
9243 | if (abfd->sections) | |
9244 | bfd_map_over_sections (abfd, | |
9245 | unrecord_section_via_map_over_sections, | |
9246 | NULL); | |
9247 | ||
9248 | return _bfd_free_cached_info (abfd); | |
9249 | } | |
9250 | ||
b7693d02 DJ |
9251 | /* Display STT_ARM_TFUNC symbols as functions. */ |
9252 | ||
9253 | static void | |
9254 | elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
9255 | asymbol *asym) | |
9256 | { | |
9257 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; | |
9258 | ||
9259 | if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC) | |
9260 | elfsym->symbol.flags |= BSF_FUNCTION; | |
9261 | } | |
9262 | ||
0beaef2b PB |
9263 | |
9264 | /* Mangle thumb function symbols as we read them in. */ | |
9265 | ||
9266 | static void | |
9267 | elf32_arm_swap_symbol_in (bfd * abfd, | |
9268 | const void *psrc, | |
9269 | const void *pshn, | |
9270 | Elf_Internal_Sym *dst) | |
9271 | { | |
9272 | bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst); | |
9273 | ||
9274 | /* New EABI objects mark thumb function symbols by setting the low bit of | |
9275 | the address. Turn these into STT_ARM_TFUNC. */ | |
9276 | if (ELF_ST_TYPE (dst->st_info) == STT_FUNC | |
9277 | && (dst->st_value & 1)) | |
9278 | { | |
9279 | dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); | |
9280 | dst->st_value &= ~(bfd_vma) 1; | |
9281 | } | |
9282 | } | |
9283 | ||
9284 | ||
9285 | /* Mangle thumb function symbols as we write them out. */ | |
9286 | ||
9287 | static void | |
9288 | elf32_arm_swap_symbol_out (bfd *abfd, | |
9289 | const Elf_Internal_Sym *src, | |
9290 | void *cdst, | |
9291 | void *shndx) | |
9292 | { | |
9293 | Elf_Internal_Sym newsym; | |
9294 | ||
9295 | /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit | |
9296 | of the address set, as per the new EABI. We do this unconditionally | |
9297 | because objcopy does not set the elf header flags until after | |
9298 | it writes out the symbol table. */ | |
9299 | if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) | |
9300 | { | |
9301 | newsym = *src; | |
9302 | newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); | |
0fa3dcad PB |
9303 | if (newsym.st_shndx != SHN_UNDEF) |
9304 | { | |
9305 | /* Do this only for defined symbols. At link type, the static | |
9306 | linker will simulate the work of dynamic linker of resolving | |
9307 | symbols and will carry over the thumbness of found symbols to | |
9308 | the output symbol table. It's not clear how it happens, but | |
9309 | the thumbness of underfined symbols can well be different at | |
9310 | runtime, and writing '1' for them will be confusing for users | |
9311 | and possibly for dynamic linker itself. | |
9312 | */ | |
9313 | newsym.st_value |= 1; | |
9314 | } | |
9315 | ||
0beaef2b PB |
9316 | newsym.st_value |= 1; |
9317 | ||
9318 | src = &newsym; | |
9319 | } | |
9320 | bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); | |
9321 | } | |
9322 | ||
b294bdf8 MM |
9323 | /* Add the PT_ARM_EXIDX program header. */ |
9324 | ||
9325 | static bfd_boolean | |
9326 | elf32_arm_modify_segment_map (bfd *abfd, | |
9327 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
9328 | { | |
9329 | struct elf_segment_map *m; | |
9330 | asection *sec; | |
9331 | ||
9332 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
9333 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
9334 | { | |
9335 | /* If there is already a PT_ARM_EXIDX header, then we do not | |
9336 | want to add another one. This situation arises when running | |
9337 | "strip"; the input binary already has the header. */ | |
9338 | m = elf_tdata (abfd)->segment_map; | |
9339 | while (m && m->p_type != PT_ARM_EXIDX) | |
9340 | m = m->next; | |
9341 | if (!m) | |
9342 | { | |
9343 | m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); | |
9344 | if (m == NULL) | |
9345 | return FALSE; | |
9346 | m->p_type = PT_ARM_EXIDX; | |
9347 | m->count = 1; | |
9348 | m->sections[0] = sec; | |
9349 | ||
9350 | m->next = elf_tdata (abfd)->segment_map; | |
9351 | elf_tdata (abfd)->segment_map = m; | |
9352 | } | |
9353 | } | |
9354 | ||
9355 | return TRUE; | |
9356 | } | |
9357 | ||
9358 | /* We may add a PT_ARM_EXIDX program header. */ | |
9359 | ||
9360 | static int | |
a6b96beb AM |
9361 | elf32_arm_additional_program_headers (bfd *abfd, |
9362 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
b294bdf8 MM |
9363 | { |
9364 | asection *sec; | |
9365 | ||
9366 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
9367 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
9368 | return 1; | |
9369 | else | |
9370 | return 0; | |
9371 | } | |
9372 | ||
0beaef2b PB |
9373 | /* We use this to override swap_symbol_in and swap_symbol_out. */ |
9374 | const struct elf_size_info elf32_arm_size_info = { | |
9375 | sizeof (Elf32_External_Ehdr), | |
9376 | sizeof (Elf32_External_Phdr), | |
9377 | sizeof (Elf32_External_Shdr), | |
9378 | sizeof (Elf32_External_Rel), | |
9379 | sizeof (Elf32_External_Rela), | |
9380 | sizeof (Elf32_External_Sym), | |
9381 | sizeof (Elf32_External_Dyn), | |
9382 | sizeof (Elf_External_Note), | |
9383 | 4, | |
9384 | 1, | |
9385 | 32, 2, | |
9386 | ELFCLASS32, EV_CURRENT, | |
9387 | bfd_elf32_write_out_phdrs, | |
9388 | bfd_elf32_write_shdrs_and_ehdr, | |
9389 | bfd_elf32_write_relocs, | |
9390 | elf32_arm_swap_symbol_in, | |
9391 | elf32_arm_swap_symbol_out, | |
9392 | bfd_elf32_slurp_reloc_table, | |
9393 | bfd_elf32_slurp_symbol_table, | |
9394 | bfd_elf32_swap_dyn_in, | |
9395 | bfd_elf32_swap_dyn_out, | |
9396 | bfd_elf32_swap_reloc_in, | |
9397 | bfd_elf32_swap_reloc_out, | |
9398 | bfd_elf32_swap_reloca_in, | |
9399 | bfd_elf32_swap_reloca_out | |
9400 | }; | |
9401 | ||
252b5132 RH |
9402 | #define ELF_ARCH bfd_arch_arm |
9403 | #define ELF_MACHINE_CODE EM_ARM | |
d0facd1b NC |
9404 | #ifdef __QNXTARGET__ |
9405 | #define ELF_MAXPAGESIZE 0x1000 | |
9406 | #else | |
f21f3fe0 | 9407 | #define ELF_MAXPAGESIZE 0x8000 |
d0facd1b | 9408 | #endif |
b1342370 | 9409 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 9410 | #define ELF_COMMONPAGESIZE 0x1000 |
252b5132 | 9411 | |
ba93b8ac DJ |
9412 | #define bfd_elf32_mkobject elf32_arm_mkobject |
9413 | ||
99e4ae17 AJ |
9414 | #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data |
9415 | #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data | |
252b5132 RH |
9416 | #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags |
9417 | #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data | |
9418 | #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create | |
dc810e39 | 9419 | #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup |
252b5132 | 9420 | #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line |
4ab527b0 | 9421 | #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info |
e489d0ae | 9422 | #define bfd_elf32_new_section_hook elf32_arm_new_section_hook |
3c9458e9 | 9423 | #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol |
957c6e41 | 9424 | #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup |
b25e3d87 | 9425 | #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info |
ee065d83 | 9426 | #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link |
252b5132 RH |
9427 | |
9428 | #define elf_backend_get_symbol_type elf32_arm_get_symbol_type | |
9429 | #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook | |
9430 | #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook | |
9431 | #define elf_backend_check_relocs elf32_arm_check_relocs | |
dc810e39 | 9432 | #define elf_backend_relocate_section elf32_arm_relocate_section |
e489d0ae | 9433 | #define elf_backend_write_section elf32_arm_write_section |
252b5132 | 9434 | #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol |
5e681ec4 | 9435 | #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections |
252b5132 RH |
9436 | #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol |
9437 | #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections | |
e489d0ae | 9438 | #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook |
252b5132 | 9439 | #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections |
ba96a88f | 9440 | #define elf_backend_post_process_headers elf32_arm_post_process_headers |
99e4ae17 | 9441 | #define elf_backend_reloc_type_class elf32_arm_reloc_type_class |
c178919b | 9442 | #define elf_backend_object_p elf32_arm_object_p |
e16bb312 | 9443 | #define elf_backend_section_flags elf32_arm_section_flags |
40a18ebd NC |
9444 | #define elf_backend_fake_sections elf32_arm_fake_sections |
9445 | #define elf_backend_section_from_shdr elf32_arm_section_from_shdr | |
e16bb312 | 9446 | #define elf_backend_final_write_processing elf32_arm_final_write_processing |
5e681ec4 | 9447 | #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol |
b7693d02 | 9448 | #define elf_backend_symbol_processing elf32_arm_symbol_processing |
0beaef2b | 9449 | #define elf_backend_size_info elf32_arm_size_info |
b294bdf8 MM |
9450 | #define elf_backend_modify_segment_map elf32_arm_modify_segment_map |
9451 | #define elf_backend_additional_program_headers \ | |
9452 | elf32_arm_additional_program_headers | |
4e617b1e PB |
9453 | #define elf_backend_output_arch_local_syms \ |
9454 | elf32_arm_output_arch_local_syms | |
a4fd1a8e PB |
9455 | #define elf_backend_begin_write_processing \ |
9456 | elf32_arm_begin_write_processing | |
252b5132 | 9457 | |
5e681ec4 | 9458 | #define elf_backend_can_refcount 1 |
252b5132 RH |
9459 | #define elf_backend_can_gc_sections 1 |
9460 | #define elf_backend_plt_readonly 1 | |
9461 | #define elf_backend_want_got_plt 1 | |
9462 | #define elf_backend_want_plt_sym 0 | |
4e7fd91e PB |
9463 | #define elf_backend_may_use_rel_p 1 |
9464 | #define elf_backend_may_use_rela_p 0 | |
9465 | #define elf_backend_default_use_rela_p 0 | |
9466 | #define elf_backend_rela_normal 0 | |
252b5132 | 9467 | |
04f7c78d | 9468 | #define elf_backend_got_header_size 12 |
04f7c78d | 9469 | |
252b5132 | 9470 | #include "elf32-target.h" |
7f266840 | 9471 | |
4e7fd91e PB |
9472 | /* VxWorks Targets */ |
9473 | ||
9474 | #undef TARGET_LITTLE_SYM | |
9475 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec | |
9476 | #undef TARGET_LITTLE_NAME | |
9477 | #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks" | |
9478 | #undef TARGET_BIG_SYM | |
9479 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec | |
9480 | #undef TARGET_BIG_NAME | |
9481 | #define TARGET_BIG_NAME "elf32-bigarm-vxworks" | |
9482 | ||
9483 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
9484 | appropriately for VxWorks. */ | |
9485 | static struct bfd_link_hash_table * | |
9486 | elf32_arm_vxworks_link_hash_table_create (bfd *abfd) | |
9487 | { | |
9488 | struct bfd_link_hash_table *ret; | |
9489 | ||
9490 | ret = elf32_arm_link_hash_table_create (abfd); | |
9491 | if (ret) | |
9492 | { | |
9493 | struct elf32_arm_link_hash_table *htab | |
00a97672 | 9494 | = (struct elf32_arm_link_hash_table *) ret; |
4e7fd91e | 9495 | htab->use_rel = 0; |
00a97672 | 9496 | htab->vxworks_p = 1; |
4e7fd91e PB |
9497 | } |
9498 | return ret; | |
9499 | } | |
9500 | ||
00a97672 RS |
9501 | static void |
9502 | elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
9503 | { | |
9504 | elf32_arm_final_write_processing (abfd, linker); | |
9505 | elf_vxworks_final_write_processing (abfd, linker); | |
9506 | } | |
9507 | ||
4e7fd91e PB |
9508 | #undef elf32_bed |
9509 | #define elf32_bed elf32_arm_vxworks_bed | |
9510 | ||
9511 | #undef bfd_elf32_bfd_link_hash_table_create | |
9512 | #define bfd_elf32_bfd_link_hash_table_create \ | |
9513 | elf32_arm_vxworks_link_hash_table_create | |
00a97672 RS |
9514 | #undef elf_backend_add_symbol_hook |
9515 | #define elf_backend_add_symbol_hook \ | |
9516 | elf_vxworks_add_symbol_hook | |
9517 | #undef elf_backend_final_write_processing | |
9518 | #define elf_backend_final_write_processing \ | |
9519 | elf32_arm_vxworks_final_write_processing | |
9520 | #undef elf_backend_emit_relocs | |
9521 | #define elf_backend_emit_relocs \ | |
9522 | elf_vxworks_emit_relocs | |
4e7fd91e PB |
9523 | |
9524 | #undef elf_backend_may_use_rel_p | |
00a97672 | 9525 | #define elf_backend_may_use_rel_p 0 |
4e7fd91e | 9526 | #undef elf_backend_may_use_rela_p |
00a97672 | 9527 | #define elf_backend_may_use_rela_p 1 |
4e7fd91e | 9528 | #undef elf_backend_default_use_rela_p |
00a97672 | 9529 | #define elf_backend_default_use_rela_p 1 |
4e7fd91e | 9530 | #undef elf_backend_rela_normal |
00a97672 RS |
9531 | #define elf_backend_rela_normal 1 |
9532 | #undef elf_backend_want_plt_sym | |
9533 | #define elf_backend_want_plt_sym 1 | |
9534 | #undef ELF_MAXPAGESIZE | |
9535 | #define ELF_MAXPAGESIZE 0x1000 | |
4e7fd91e PB |
9536 | |
9537 | #include "elf32-target.h" | |
9538 | ||
9539 | ||
7f266840 DJ |
9540 | /* Symbian OS Targets */ |
9541 | ||
9542 | #undef TARGET_LITTLE_SYM | |
9543 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec | |
9544 | #undef TARGET_LITTLE_NAME | |
9545 | #define TARGET_LITTLE_NAME "elf32-littlearm-symbian" | |
9546 | #undef TARGET_BIG_SYM | |
9547 | #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec | |
9548 | #undef TARGET_BIG_NAME | |
9549 | #define TARGET_BIG_NAME "elf32-bigarm-symbian" | |
9550 | ||
9551 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
9552 | appropriately for Symbian OS. */ | |
9553 | static struct bfd_link_hash_table * | |
9554 | elf32_arm_symbian_link_hash_table_create (bfd *abfd) | |
9555 | { | |
9556 | struct bfd_link_hash_table *ret; | |
9557 | ||
9558 | ret = elf32_arm_link_hash_table_create (abfd); | |
9559 | if (ret) | |
9560 | { | |
9561 | struct elf32_arm_link_hash_table *htab | |
9562 | = (struct elf32_arm_link_hash_table *)ret; | |
9563 | /* There is no PLT header for Symbian OS. */ | |
9564 | htab->plt_header_size = 0; | |
9565 | /* The PLT entries are each three instructions. */ | |
9566 | htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); | |
9567 | htab->symbian_p = 1; | |
33bfe774 JB |
9568 | /* Symbian uses armv5t or above, so use_blx is always true. */ |
9569 | htab->use_blx = 1; | |
67687978 | 9570 | htab->root.is_relocatable_executable = 1; |
7f266840 DJ |
9571 | } |
9572 | return ret; | |
9573 | } | |
9574 | ||
b35d266b | 9575 | static const struct bfd_elf_special_section |
551b43fd | 9576 | elf32_arm_symbian_special_sections[] = |
7f266840 | 9577 | { |
5cd3778d MM |
9578 | /* In a BPABI executable, the dynamic linking sections do not go in |
9579 | the loadable read-only segment. The post-linker may wish to | |
9580 | refer to these sections, but they are not part of the final | |
9581 | program image. */ | |
7f266840 DJ |
9582 | { ".dynamic", 8, 0, SHT_DYNAMIC, 0 }, |
9583 | { ".dynstr", 7, 0, SHT_STRTAB, 0 }, | |
9584 | { ".dynsym", 7, 0, SHT_DYNSYM, 0 }, | |
9585 | { ".got", 4, 0, SHT_PROGBITS, 0 }, | |
9586 | { ".hash", 5, 0, SHT_HASH, 0 }, | |
5cd3778d MM |
9587 | /* These sections do not need to be writable as the SymbianOS |
9588 | postlinker will arrange things so that no dynamic relocation is | |
9589 | required. */ | |
9590 | { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC }, | |
9591 | { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC }, | |
9592 | { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC }, | |
7f266840 DJ |
9593 | { NULL, 0, 0, 0, 0 } |
9594 | }; | |
9595 | ||
c3c76620 | 9596 | static void |
b34af79c | 9597 | elf32_arm_symbian_begin_write_processing (bfd *abfd, |
a4fd1a8e | 9598 | struct bfd_link_info *link_info) |
c3c76620 MM |
9599 | { |
9600 | /* BPABI objects are never loaded directly by an OS kernel; they are | |
9601 | processed by a postlinker first, into an OS-specific format. If | |
9602 | the D_PAGED bit is set on the file, BFD will align segments on | |
9603 | page boundaries, so that an OS can directly map the file. With | |
9604 | BPABI objects, that just results in wasted space. In addition, | |
9605 | because we clear the D_PAGED bit, map_sections_to_segments will | |
9606 | recognize that the program headers should not be mapped into any | |
9607 | loadable segment. */ | |
9608 | abfd->flags &= ~D_PAGED; | |
a4fd1a8e | 9609 | elf32_arm_begin_write_processing(abfd, link_info); |
c3c76620 | 9610 | } |
7f266840 DJ |
9611 | |
9612 | static bfd_boolean | |
b34af79c | 9613 | elf32_arm_symbian_modify_segment_map (bfd *abfd, |
b294bdf8 | 9614 | struct bfd_link_info *info) |
7f266840 DJ |
9615 | { |
9616 | struct elf_segment_map *m; | |
9617 | asection *dynsec; | |
9618 | ||
7f266840 DJ |
9619 | /* BPABI shared libraries and executables should have a PT_DYNAMIC |
9620 | segment. However, because the .dynamic section is not marked | |
9621 | with SEC_LOAD, the generic ELF code will not create such a | |
9622 | segment. */ | |
9623 | dynsec = bfd_get_section_by_name (abfd, ".dynamic"); | |
9624 | if (dynsec) | |
9625 | { | |
8ded5a0f AM |
9626 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) |
9627 | if (m->p_type == PT_DYNAMIC) | |
9628 | break; | |
9629 | ||
9630 | if (m == NULL) | |
9631 | { | |
9632 | m = _bfd_elf_make_dynamic_segment (abfd, dynsec); | |
9633 | m->next = elf_tdata (abfd)->segment_map; | |
9634 | elf_tdata (abfd)->segment_map = m; | |
9635 | } | |
7f266840 DJ |
9636 | } |
9637 | ||
b294bdf8 MM |
9638 | /* Also call the generic arm routine. */ |
9639 | return elf32_arm_modify_segment_map (abfd, info); | |
7f266840 DJ |
9640 | } |
9641 | ||
9642 | #undef elf32_bed | |
9643 | #define elf32_bed elf32_arm_symbian_bed | |
9644 | ||
9645 | /* The dynamic sections are not allocated on SymbianOS; the postlinker | |
9646 | will process them and then discard them. */ | |
9647 | #undef ELF_DYNAMIC_SEC_FLAGS | |
9648 | #define ELF_DYNAMIC_SEC_FLAGS \ | |
9649 | (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED) | |
9650 | ||
9651 | #undef bfd_elf32_bfd_link_hash_table_create | |
9652 | #define bfd_elf32_bfd_link_hash_table_create \ | |
9653 | elf32_arm_symbian_link_hash_table_create | |
00a97672 | 9654 | #undef elf_backend_add_symbol_hook |
7f266840 | 9655 | |
29ef7005 L |
9656 | #undef elf_backend_special_sections |
9657 | #define elf_backend_special_sections elf32_arm_symbian_special_sections | |
7f266840 | 9658 | |
c3c76620 MM |
9659 | #undef elf_backend_begin_write_processing |
9660 | #define elf_backend_begin_write_processing \ | |
9661 | elf32_arm_symbian_begin_write_processing | |
00a97672 RS |
9662 | #undef elf_backend_final_write_processing |
9663 | #define elf_backend_final_write_processing \ | |
9664 | elf32_arm_final_write_processing | |
9665 | #undef elf_backend_emit_relocs | |
c3c76620 | 9666 | |
7f266840 DJ |
9667 | #undef elf_backend_modify_segment_map |
9668 | #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map | |
9669 | ||
9670 | /* There is no .got section for BPABI objects, and hence no header. */ | |
9671 | #undef elf_backend_got_header_size | |
9672 | #define elf_backend_got_header_size 0 | |
9673 | ||
9674 | /* Similarly, there is no .got.plt section. */ | |
9675 | #undef elf_backend_want_got_plt | |
9676 | #define elf_backend_want_got_plt 0 | |
9677 | ||
4e7fd91e | 9678 | #undef elf_backend_may_use_rel_p |
00a97672 | 9679 | #define elf_backend_may_use_rel_p 1 |
4e7fd91e | 9680 | #undef elf_backend_may_use_rela_p |
00a97672 | 9681 | #define elf_backend_may_use_rela_p 0 |
4e7fd91e | 9682 | #undef elf_backend_default_use_rela_p |
00a97672 | 9683 | #define elf_backend_default_use_rela_p 0 |
4e7fd91e | 9684 | #undef elf_backend_rela_normal |
00a97672 RS |
9685 | #define elf_backend_rela_normal 0 |
9686 | #undef elf_backend_want_plt_sym | |
9687 | #define elf_backend_want_plt_sym 0 | |
9688 | #undef ELF_MAXPAGESIZE | |
9689 | #define ELF_MAXPAGESIZE 0x8000 | |
4e7fd91e | 9690 | |
7f266840 | 9691 | #include "elf32-target.h" |