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; | |
917583ad | 2095 | }; |
252b5132 | 2096 | |
252b5132 | 2097 | /* Traverse an arm ELF linker hash table. */ |
252b5132 RH |
2098 | #define elf32_arm_link_hash_traverse(table, func, info) \ |
2099 | (elf_link_hash_traverse \ | |
2100 | (&(table)->root, \ | |
b7693d02 | 2101 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
252b5132 RH |
2102 | (info))) |
2103 | ||
2104 | /* Get the ARM elf linker hash table from a link_info structure. */ | |
2105 | #define elf32_arm_hash_table(info) \ | |
2106 | ((struct elf32_arm_link_hash_table *) ((info)->hash)) | |
2107 | ||
9b485d32 | 2108 | /* ARM ELF linker hash table. */ |
252b5132 | 2109 | struct elf32_arm_link_hash_table |
917583ad NC |
2110 | { |
2111 | /* The main hash table. */ | |
2112 | struct elf_link_hash_table root; | |
252b5132 | 2113 | |
4cc11e76 | 2114 | /* The size in bytes of the section containing the Thumb-to-ARM glue. */ |
dc810e39 | 2115 | bfd_size_type thumb_glue_size; |
252b5132 | 2116 | |
4cc11e76 | 2117 | /* The size in bytes of the section containing the ARM-to-Thumb glue. */ |
dc810e39 | 2118 | bfd_size_type arm_glue_size; |
252b5132 | 2119 | |
4cc11e76 | 2120 | /* An arbitrary input BFD chosen to hold the glue sections. */ |
917583ad | 2121 | bfd * bfd_of_glue_owner; |
ba96a88f | 2122 | |
e489d0ae PB |
2123 | /* Nonzero to output a BE8 image. */ |
2124 | int byteswap_code; | |
2125 | ||
9c504268 PB |
2126 | /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. |
2127 | Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */ | |
2128 | int target1_is_rel; | |
2129 | ||
eb043451 PB |
2130 | /* The relocation to use for R_ARM_TARGET2 relocations. */ |
2131 | int target2_reloc; | |
2132 | ||
319850b4 JB |
2133 | /* Nonzero to fix BX instructions for ARMv4 targets. */ |
2134 | int fix_v4bx; | |
2135 | ||
33bfe774 JB |
2136 | /* Nonzero if the ARM/Thumb BLX instructions are available for use. */ |
2137 | int use_blx; | |
2138 | ||
e5a52504 MM |
2139 | /* The number of bytes in the initial entry in the PLT. */ |
2140 | bfd_size_type plt_header_size; | |
2141 | ||
2142 | /* The number of bytes in the subsequent PLT etries. */ | |
2143 | bfd_size_type plt_entry_size; | |
2144 | ||
00a97672 RS |
2145 | /* True if the target system is VxWorks. */ |
2146 | int vxworks_p; | |
2147 | ||
e5a52504 MM |
2148 | /* True if the target system is Symbian OS. */ |
2149 | int symbian_p; | |
2150 | ||
4e7fd91e PB |
2151 | /* True if the target uses REL relocations. */ |
2152 | int use_rel; | |
2153 | ||
5e681ec4 PB |
2154 | /* Short-cuts to get to dynamic linker sections. */ |
2155 | asection *sgot; | |
2156 | asection *sgotplt; | |
2157 | asection *srelgot; | |
2158 | asection *splt; | |
2159 | asection *srelplt; | |
2160 | asection *sdynbss; | |
2161 | asection *srelbss; | |
2162 | ||
00a97672 RS |
2163 | /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */ |
2164 | asection *srelplt2; | |
2165 | ||
ba93b8ac DJ |
2166 | /* Data for R_ARM_TLS_LDM32 relocations. */ |
2167 | union { | |
2168 | bfd_signed_vma refcount; | |
2169 | bfd_vma offset; | |
2170 | } tls_ldm_got; | |
2171 | ||
5e681ec4 PB |
2172 | /* Small local sym to section mapping cache. */ |
2173 | struct sym_sec_cache sym_sec; | |
b7693d02 DJ |
2174 | |
2175 | /* For convenience in allocate_dynrelocs. */ | |
2176 | bfd * obfd; | |
917583ad | 2177 | }; |
252b5132 | 2178 | |
780a67af NC |
2179 | /* Create an entry in an ARM ELF linker hash table. */ |
2180 | ||
2181 | static struct bfd_hash_entry * | |
57e8b36a NC |
2182 | elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, |
2183 | struct bfd_hash_table * table, | |
2184 | const char * string) | |
780a67af NC |
2185 | { |
2186 | struct elf32_arm_link_hash_entry * ret = | |
2187 | (struct elf32_arm_link_hash_entry *) entry; | |
2188 | ||
2189 | /* Allocate the structure if it has not already been allocated by a | |
2190 | subclass. */ | |
2191 | if (ret == (struct elf32_arm_link_hash_entry *) NULL) | |
57e8b36a NC |
2192 | ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); |
2193 | if (ret == NULL) | |
780a67af NC |
2194 | return (struct bfd_hash_entry *) ret; |
2195 | ||
2196 | /* Call the allocation method of the superclass. */ | |
2197 | ret = ((struct elf32_arm_link_hash_entry *) | |
2198 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
2199 | table, string)); | |
57e8b36a | 2200 | if (ret != NULL) |
b7693d02 DJ |
2201 | { |
2202 | ret->relocs_copied = NULL; | |
ba93b8ac | 2203 | ret->tls_type = GOT_UNKNOWN; |
b7693d02 DJ |
2204 | ret->plt_thumb_refcount = 0; |
2205 | ret->plt_got_offset = -1; | |
2206 | } | |
780a67af NC |
2207 | |
2208 | return (struct bfd_hash_entry *) ret; | |
2209 | } | |
2210 | ||
00a97672 RS |
2211 | /* Return true if NAME is the name of the relocation section associated |
2212 | with S. */ | |
2213 | ||
2214 | static bfd_boolean | |
2215 | reloc_section_p (struct elf32_arm_link_hash_table *htab, | |
2216 | const char *name, asection *s) | |
2217 | { | |
2218 | if (htab->use_rel) | |
2219 | return strncmp (name, ".rel", 4) == 0 && strcmp (s->name, name + 4) == 0; | |
2220 | else | |
2221 | return strncmp (name, ".rela", 5) == 0 && strcmp (s->name, name + 5) == 0; | |
2222 | } | |
2223 | ||
2224 | /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up | |
5e681ec4 PB |
2225 | shortcuts to them in our hash table. */ |
2226 | ||
2227 | static bfd_boolean | |
57e8b36a | 2228 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
2229 | { |
2230 | struct elf32_arm_link_hash_table *htab; | |
2231 | ||
e5a52504 MM |
2232 | htab = elf32_arm_hash_table (info); |
2233 | /* BPABI objects never have a GOT, or associated sections. */ | |
2234 | if (htab->symbian_p) | |
2235 | return TRUE; | |
2236 | ||
5e681ec4 PB |
2237 | if (! _bfd_elf_create_got_section (dynobj, info)) |
2238 | return FALSE; | |
2239 | ||
5e681ec4 PB |
2240 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
2241 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
2242 | if (!htab->sgot || !htab->sgotplt) | |
2243 | abort (); | |
2244 | ||
00a97672 RS |
2245 | htab->srelgot = bfd_make_section_with_flags (dynobj, |
2246 | RELOC_SECTION (htab, ".got"), | |
3496cb2a L |
2247 | (SEC_ALLOC | SEC_LOAD |
2248 | | SEC_HAS_CONTENTS | |
2249 | | SEC_IN_MEMORY | |
2250 | | SEC_LINKER_CREATED | |
2251 | | SEC_READONLY)); | |
5e681ec4 | 2252 | if (htab->srelgot == NULL |
5e681ec4 PB |
2253 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) |
2254 | return FALSE; | |
2255 | return TRUE; | |
2256 | } | |
2257 | ||
00a97672 RS |
2258 | /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and |
2259 | .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our | |
5e681ec4 PB |
2260 | hash table. */ |
2261 | ||
2262 | static bfd_boolean | |
57e8b36a | 2263 | elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
2264 | { |
2265 | struct elf32_arm_link_hash_table *htab; | |
2266 | ||
2267 | htab = elf32_arm_hash_table (info); | |
2268 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
2269 | return FALSE; | |
2270 | ||
2271 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
2272 | return FALSE; | |
2273 | ||
2274 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 RS |
2275 | htab->srelplt = bfd_get_section_by_name (dynobj, |
2276 | RELOC_SECTION (htab, ".plt")); | |
5e681ec4 PB |
2277 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
2278 | if (!info->shared) | |
00a97672 RS |
2279 | htab->srelbss = bfd_get_section_by_name (dynobj, |
2280 | RELOC_SECTION (htab, ".bss")); | |
2281 | ||
2282 | if (htab->vxworks_p) | |
2283 | { | |
2284 | if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2)) | |
2285 | return FALSE; | |
2286 | ||
2287 | if (info->shared) | |
2288 | { | |
2289 | htab->plt_header_size = 0; | |
2290 | htab->plt_entry_size | |
2291 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry); | |
2292 | } | |
2293 | else | |
2294 | { | |
2295 | htab->plt_header_size | |
2296 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry); | |
2297 | htab->plt_entry_size | |
2298 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry); | |
2299 | } | |
2300 | } | |
5e681ec4 | 2301 | |
e5a52504 MM |
2302 | if (!htab->splt |
2303 | || !htab->srelplt | |
2304 | || !htab->sdynbss | |
5e681ec4 PB |
2305 | || (!info->shared && !htab->srelbss)) |
2306 | abort (); | |
2307 | ||
2308 | return TRUE; | |
2309 | } | |
2310 | ||
2311 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
2312 | ||
2313 | static void | |
fcfa13d2 | 2314 | elf32_arm_copy_indirect_symbol (struct bfd_link_info *info, |
5e681ec4 PB |
2315 | struct elf_link_hash_entry *dir, |
2316 | struct elf_link_hash_entry *ind) | |
2317 | { | |
2318 | struct elf32_arm_link_hash_entry *edir, *eind; | |
2319 | ||
2320 | edir = (struct elf32_arm_link_hash_entry *) dir; | |
2321 | eind = (struct elf32_arm_link_hash_entry *) ind; | |
2322 | ||
2323 | if (eind->relocs_copied != NULL) | |
2324 | { | |
2325 | if (edir->relocs_copied != NULL) | |
2326 | { | |
2327 | struct elf32_arm_relocs_copied **pp; | |
2328 | struct elf32_arm_relocs_copied *p; | |
2329 | ||
fcfa13d2 | 2330 | /* Add reloc counts against the indirect sym to the direct sym |
5e681ec4 PB |
2331 | list. Merge any entries against the same section. */ |
2332 | for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) | |
2333 | { | |
2334 | struct elf32_arm_relocs_copied *q; | |
2335 | ||
2336 | for (q = edir->relocs_copied; q != NULL; q = q->next) | |
2337 | if (q->section == p->section) | |
2338 | { | |
ba93b8ac | 2339 | q->pc_count += p->pc_count; |
5e681ec4 PB |
2340 | q->count += p->count; |
2341 | *pp = p->next; | |
2342 | break; | |
2343 | } | |
2344 | if (q == NULL) | |
2345 | pp = &p->next; | |
2346 | } | |
2347 | *pp = edir->relocs_copied; | |
2348 | } | |
2349 | ||
2350 | edir->relocs_copied = eind->relocs_copied; | |
2351 | eind->relocs_copied = NULL; | |
2352 | } | |
2353 | ||
fcfa13d2 AM |
2354 | /* Copy over PLT info. */ |
2355 | edir->plt_thumb_refcount += eind->plt_thumb_refcount; | |
2356 | eind->plt_thumb_refcount = 0; | |
b7693d02 | 2357 | |
ba93b8ac DJ |
2358 | if (ind->root.type == bfd_link_hash_indirect |
2359 | && dir->got.refcount <= 0) | |
2360 | { | |
2361 | edir->tls_type = eind->tls_type; | |
2362 | eind->tls_type = GOT_UNKNOWN; | |
2363 | } | |
2364 | ||
fcfa13d2 | 2365 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
5e681ec4 PB |
2366 | } |
2367 | ||
9b485d32 | 2368 | /* Create an ARM elf linker hash table. */ |
252b5132 RH |
2369 | |
2370 | static struct bfd_link_hash_table * | |
57e8b36a | 2371 | elf32_arm_link_hash_table_create (bfd *abfd) |
252b5132 RH |
2372 | { |
2373 | struct elf32_arm_link_hash_table *ret; | |
dc810e39 | 2374 | bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); |
252b5132 | 2375 | |
57e8b36a NC |
2376 | ret = bfd_malloc (amt); |
2377 | if (ret == NULL) | |
252b5132 RH |
2378 | return NULL; |
2379 | ||
57e8b36a | 2380 | if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, |
66eb6687 AM |
2381 | elf32_arm_link_hash_newfunc, |
2382 | sizeof (struct elf32_arm_link_hash_entry))) | |
252b5132 | 2383 | { |
e2d34d7d | 2384 | free (ret); |
252b5132 RH |
2385 | return NULL; |
2386 | } | |
2387 | ||
5e681ec4 PB |
2388 | ret->sgot = NULL; |
2389 | ret->sgotplt = NULL; | |
2390 | ret->srelgot = NULL; | |
2391 | ret->splt = NULL; | |
2392 | ret->srelplt = NULL; | |
2393 | ret->sdynbss = NULL; | |
2394 | ret->srelbss = NULL; | |
00a97672 | 2395 | ret->srelplt2 = NULL; |
252b5132 RH |
2396 | ret->thumb_glue_size = 0; |
2397 | ret->arm_glue_size = 0; | |
2398 | ret->bfd_of_glue_owner = NULL; | |
e489d0ae | 2399 | ret->byteswap_code = 0; |
9c504268 | 2400 | ret->target1_is_rel = 0; |
eb043451 | 2401 | ret->target2_reloc = R_ARM_NONE; |
e5a52504 MM |
2402 | #ifdef FOUR_WORD_PLT |
2403 | ret->plt_header_size = 16; | |
2404 | ret->plt_entry_size = 16; | |
2405 | #else | |
2406 | ret->plt_header_size = 20; | |
2407 | ret->plt_entry_size = 12; | |
2408 | #endif | |
33bfe774 JB |
2409 | ret->fix_v4bx = 0; |
2410 | ret->use_blx = 0; | |
00a97672 | 2411 | ret->vxworks_p = 0; |
e5a52504 | 2412 | ret->symbian_p = 0; |
4e7fd91e | 2413 | ret->use_rel = 1; |
5e681ec4 | 2414 | ret->sym_sec.abfd = NULL; |
b7693d02 | 2415 | ret->obfd = abfd; |
ba93b8ac | 2416 | ret->tls_ldm_got.refcount = 0; |
252b5132 RH |
2417 | |
2418 | return &ret->root.root; | |
2419 | } | |
2420 | ||
9b485d32 NC |
2421 | /* Locate the Thumb encoded calling stub for NAME. */ |
2422 | ||
252b5132 | 2423 | static struct elf_link_hash_entry * |
57e8b36a NC |
2424 | find_thumb_glue (struct bfd_link_info *link_info, |
2425 | const char *name, | |
2426 | bfd *input_bfd) | |
252b5132 RH |
2427 | { |
2428 | char *tmp_name; | |
2429 | struct elf_link_hash_entry *hash; | |
2430 | struct elf32_arm_link_hash_table *hash_table; | |
2431 | ||
2432 | /* We need a pointer to the armelf specific hash table. */ | |
2433 | hash_table = elf32_arm_hash_table (link_info); | |
2434 | ||
57e8b36a NC |
2435 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2436 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2437 | |
2438 | BFD_ASSERT (tmp_name); | |
2439 | ||
2440 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2441 | ||
2442 | hash = elf_link_hash_lookup | |
b34976b6 | 2443 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2444 | |
2445 | if (hash == NULL) | |
2446 | /* xgettext:c-format */ | |
d003868e AM |
2447 | (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"), |
2448 | input_bfd, tmp_name, name); | |
252b5132 RH |
2449 | |
2450 | free (tmp_name); | |
2451 | ||
2452 | return hash; | |
2453 | } | |
2454 | ||
9b485d32 NC |
2455 | /* Locate the ARM encoded calling stub for NAME. */ |
2456 | ||
252b5132 | 2457 | static struct elf_link_hash_entry * |
57e8b36a NC |
2458 | find_arm_glue (struct bfd_link_info *link_info, |
2459 | const char *name, | |
2460 | bfd *input_bfd) | |
252b5132 RH |
2461 | { |
2462 | char *tmp_name; | |
2463 | struct elf_link_hash_entry *myh; | |
2464 | struct elf32_arm_link_hash_table *hash_table; | |
2465 | ||
2466 | /* We need a pointer to the elfarm specific hash table. */ | |
2467 | hash_table = elf32_arm_hash_table (link_info); | |
2468 | ||
57e8b36a NC |
2469 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2470 | + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2471 | |
2472 | BFD_ASSERT (tmp_name); | |
2473 | ||
2474 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2475 | ||
2476 | myh = elf_link_hash_lookup | |
b34976b6 | 2477 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2478 | |
2479 | if (myh == NULL) | |
2480 | /* xgettext:c-format */ | |
d003868e AM |
2481 | (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"), |
2482 | input_bfd, tmp_name, name); | |
252b5132 RH |
2483 | |
2484 | free (tmp_name); | |
2485 | ||
2486 | return myh; | |
2487 | } | |
2488 | ||
8f6277f5 | 2489 | /* ARM->Thumb glue (static images): |
252b5132 RH |
2490 | |
2491 | .arm | |
2492 | __func_from_arm: | |
2493 | ldr r12, __func_addr | |
2494 | bx r12 | |
2495 | __func_addr: | |
8f6277f5 | 2496 | .word func @ behave as if you saw a ARM_32 reloc. |
252b5132 | 2497 | |
8f6277f5 PB |
2498 | (relocatable images) |
2499 | .arm | |
2500 | __func_from_arm: | |
2501 | ldr r12, __func_offset | |
2502 | add r12, r12, pc | |
2503 | bx r12 | |
2504 | __func_offset: | |
2505 | .word func - . | |
2506 | */ | |
2507 | ||
2508 | #define ARM2THUMB_STATIC_GLUE_SIZE 12 | |
252b5132 RH |
2509 | static const insn32 a2t1_ldr_insn = 0xe59fc000; |
2510 | static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; | |
2511 | static const insn32 a2t3_func_addr_insn = 0x00000001; | |
2512 | ||
8f6277f5 PB |
2513 | #define ARM2THUMB_PIC_GLUE_SIZE 16 |
2514 | static const insn32 a2t1p_ldr_insn = 0xe59fc004; | |
2515 | static const insn32 a2t2p_add_pc_insn = 0xe08cc00f; | |
2516 | static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c; | |
2517 | ||
9b485d32 | 2518 | /* Thumb->ARM: Thumb->(non-interworking aware) ARM |
252b5132 RH |
2519 | |
2520 | .thumb .thumb | |
2521 | .align 2 .align 2 | |
2522 | __func_from_thumb: __func_from_thumb: | |
2523 | bx pc push {r6, lr} | |
2524 | nop ldr r6, __func_addr | |
2525 | .arm mov lr, pc | |
2526 | __func_change_to_arm: bx r6 | |
2527 | b func .arm | |
2528 | __func_back_to_thumb: | |
2529 | ldmia r13! {r6, lr} | |
2530 | bx lr | |
2531 | __func_addr: | |
9b485d32 | 2532 | .word func */ |
252b5132 RH |
2533 | |
2534 | #define THUMB2ARM_GLUE_SIZE 8 | |
2535 | static const insn16 t2a1_bx_pc_insn = 0x4778; | |
2536 | static const insn16 t2a2_noop_insn = 0x46c0; | |
2537 | static const insn32 t2a3_b_insn = 0xea000000; | |
2538 | ||
7e392df6 | 2539 | #ifndef ELFARM_NABI_C_INCLUDED |
b34976b6 | 2540 | bfd_boolean |
57e8b36a | 2541 | bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) |
252b5132 RH |
2542 | { |
2543 | asection * s; | |
2544 | bfd_byte * foo; | |
2545 | struct elf32_arm_link_hash_table * globals; | |
2546 | ||
2547 | globals = elf32_arm_hash_table (info); | |
2548 | ||
2549 | BFD_ASSERT (globals != NULL); | |
2550 | ||
2551 | if (globals->arm_glue_size != 0) | |
2552 | { | |
2553 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2554 | ||
dc810e39 AM |
2555 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
2556 | ARM2THUMB_GLUE_SECTION_NAME); | |
252b5132 RH |
2557 | |
2558 | BFD_ASSERT (s != NULL); | |
2559 | ||
57e8b36a | 2560 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); |
252b5132 | 2561 | |
eea6121a | 2562 | s->size = globals->arm_glue_size; |
252b5132 RH |
2563 | s->contents = foo; |
2564 | } | |
2565 | ||
2566 | if (globals->thumb_glue_size != 0) | |
2567 | { | |
2568 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2569 | ||
2570 | s = bfd_get_section_by_name | |
2571 | (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2572 | ||
2573 | BFD_ASSERT (s != NULL); | |
2574 | ||
57e8b36a | 2575 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); |
252b5132 | 2576 | |
eea6121a | 2577 | s->size = globals->thumb_glue_size; |
252b5132 RH |
2578 | s->contents = foo; |
2579 | } | |
2580 | ||
b34976b6 | 2581 | return TRUE; |
252b5132 RH |
2582 | } |
2583 | ||
2584 | static void | |
57e8b36a NC |
2585 | record_arm_to_thumb_glue (struct bfd_link_info * link_info, |
2586 | struct elf_link_hash_entry * h) | |
252b5132 RH |
2587 | { |
2588 | const char * name = h->root.root.string; | |
63b0f745 | 2589 | asection * s; |
252b5132 RH |
2590 | char * tmp_name; |
2591 | struct elf_link_hash_entry * myh; | |
14a793b2 | 2592 | struct bfd_link_hash_entry * bh; |
252b5132 | 2593 | struct elf32_arm_link_hash_table * globals; |
dc810e39 | 2594 | bfd_vma val; |
252b5132 RH |
2595 | |
2596 | globals = elf32_arm_hash_table (link_info); | |
2597 | ||
2598 | BFD_ASSERT (globals != NULL); | |
2599 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2600 | ||
2601 | s = bfd_get_section_by_name | |
2602 | (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); | |
2603 | ||
252b5132 RH |
2604 | BFD_ASSERT (s != NULL); |
2605 | ||
57e8b36a | 2606 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
252b5132 RH |
2607 | |
2608 | BFD_ASSERT (tmp_name); | |
2609 | ||
2610 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2611 | ||
2612 | myh = elf_link_hash_lookup | |
b34976b6 | 2613 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2614 | |
2615 | if (myh != NULL) | |
2616 | { | |
9b485d32 | 2617 | /* We've already seen this guy. */ |
252b5132 | 2618 | free (tmp_name); |
9b485d32 | 2619 | return; |
252b5132 RH |
2620 | } |
2621 | ||
57e8b36a NC |
2622 | /* The only trick here is using hash_table->arm_glue_size as the value. |
2623 | Even though the section isn't allocated yet, this is where we will be | |
2624 | putting it. */ | |
14a793b2 | 2625 | bh = NULL; |
dc810e39 AM |
2626 | val = globals->arm_glue_size + 1; |
2627 | _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, | |
2628 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2629 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2630 | |
b7693d02 DJ |
2631 | myh = (struct elf_link_hash_entry *) bh; |
2632 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
2633 | myh->forced_local = 1; | |
2634 | ||
252b5132 RH |
2635 | free (tmp_name); |
2636 | ||
8f6277f5 PB |
2637 | if ((link_info->shared || globals->root.is_relocatable_executable)) |
2638 | globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE; | |
2639 | else | |
2640 | globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE; | |
252b5132 RH |
2641 | |
2642 | return; | |
2643 | } | |
2644 | ||
2645 | static void | |
57e8b36a NC |
2646 | record_thumb_to_arm_glue (struct bfd_link_info *link_info, |
2647 | struct elf_link_hash_entry *h) | |
252b5132 RH |
2648 | { |
2649 | const char *name = h->root.root.string; | |
63b0f745 | 2650 | asection *s; |
252b5132 RH |
2651 | char *tmp_name; |
2652 | struct elf_link_hash_entry *myh; | |
14a793b2 | 2653 | struct bfd_link_hash_entry *bh; |
252b5132 | 2654 | struct elf32_arm_link_hash_table *hash_table; |
dc810e39 | 2655 | bfd_vma val; |
252b5132 RH |
2656 | |
2657 | hash_table = elf32_arm_hash_table (link_info); | |
2658 | ||
2659 | BFD_ASSERT (hash_table != NULL); | |
2660 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); | |
2661 | ||
2662 | s = bfd_get_section_by_name | |
2663 | (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2664 | ||
2665 | BFD_ASSERT (s != NULL); | |
2666 | ||
57e8b36a NC |
2667 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2668 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2669 | |
2670 | BFD_ASSERT (tmp_name); | |
2671 | ||
2672 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2673 | ||
2674 | myh = elf_link_hash_lookup | |
b34976b6 | 2675 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2676 | |
2677 | if (myh != NULL) | |
2678 | { | |
9b485d32 | 2679 | /* We've already seen this guy. */ |
252b5132 | 2680 | free (tmp_name); |
9b485d32 | 2681 | return; |
252b5132 RH |
2682 | } |
2683 | ||
14a793b2 | 2684 | bh = NULL; |
dc810e39 AM |
2685 | val = hash_table->thumb_glue_size + 1; |
2686 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2687 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2688 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2689 | |
9b485d32 | 2690 | /* If we mark it 'Thumb', the disassembler will do a better job. */ |
14a793b2 | 2691 | myh = (struct elf_link_hash_entry *) bh; |
b7693d02 DJ |
2692 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); |
2693 | myh->forced_local = 1; | |
252b5132 RH |
2694 | |
2695 | free (tmp_name); | |
2696 | ||
252b5132 RH |
2697 | #define CHANGE_TO_ARM "__%s_change_to_arm" |
2698 | #define BACK_FROM_ARM "__%s_back_from_arm" | |
2699 | ||
9b485d32 | 2700 | /* Allocate another symbol to mark where we switch to Arm mode. */ |
57e8b36a NC |
2701 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2702 | + strlen (CHANGE_TO_ARM) + 1); | |
252b5132 RH |
2703 | |
2704 | BFD_ASSERT (tmp_name); | |
2705 | ||
2706 | sprintf (tmp_name, CHANGE_TO_ARM, name); | |
2707 | ||
14a793b2 | 2708 | bh = NULL; |
dc810e39 AM |
2709 | val = hash_table->thumb_glue_size + 4, |
2710 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2711 | tmp_name, BSF_LOCAL, s, val, | |
b34976b6 | 2712 | NULL, TRUE, FALSE, &bh); |
252b5132 RH |
2713 | |
2714 | free (tmp_name); | |
2715 | ||
2716 | hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; | |
2717 | ||
2718 | return; | |
2719 | } | |
2720 | ||
8afb0e02 NC |
2721 | /* Add the glue sections to ABFD. This function is called from the |
2722 | linker scripts in ld/emultempl/{armelf}.em. */ | |
9b485d32 | 2723 | |
b34976b6 | 2724 | bfd_boolean |
57e8b36a NC |
2725 | bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, |
2726 | struct bfd_link_info *info) | |
252b5132 | 2727 | { |
252b5132 RH |
2728 | flagword flags; |
2729 | asection *sec; | |
2730 | ||
8afb0e02 NC |
2731 | /* If we are only performing a partial |
2732 | link do not bother adding the glue. */ | |
1049f94e | 2733 | if (info->relocatable) |
b34976b6 | 2734 | return TRUE; |
252b5132 | 2735 | |
252b5132 RH |
2736 | sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
2737 | ||
2738 | if (sec == NULL) | |
2739 | { | |
57db232e NC |
2740 | /* Note: we do not include the flag SEC_LINKER_CREATED, as this |
2741 | will prevent elf_link_input_bfd() from processing the contents | |
2742 | of this section. */ | |
811b4bf6 | 2743 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY; |
252b5132 | 2744 | |
3496cb2a L |
2745 | sec = bfd_make_section_with_flags (abfd, |
2746 | ARM2THUMB_GLUE_SECTION_NAME, | |
2747 | flags); | |
252b5132 RH |
2748 | |
2749 | if (sec == NULL | |
252b5132 | 2750 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2751 | return FALSE; |
9a5aca8c | 2752 | |
57db232e NC |
2753 | /* Set the gc mark to prevent the section from being removed by garbage |
2754 | collection, despite the fact that no relocs refer to this section. */ | |
2755 | sec->gc_mark = 1; | |
252b5132 RH |
2756 | } |
2757 | ||
2758 | sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); | |
2759 | ||
2760 | if (sec == NULL) | |
2761 | { | |
57e8b36a NC |
2762 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
2763 | | SEC_CODE | SEC_READONLY; | |
252b5132 | 2764 | |
3496cb2a L |
2765 | sec = bfd_make_section_with_flags (abfd, |
2766 | THUMB2ARM_GLUE_SECTION_NAME, | |
2767 | flags); | |
252b5132 RH |
2768 | |
2769 | if (sec == NULL | |
252b5132 | 2770 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2771 | return FALSE; |
9a5aca8c | 2772 | |
57db232e | 2773 | sec->gc_mark = 1; |
252b5132 RH |
2774 | } |
2775 | ||
b34976b6 | 2776 | return TRUE; |
8afb0e02 NC |
2777 | } |
2778 | ||
2779 | /* Select a BFD to be used to hold the sections used by the glue code. | |
2780 | This function is called from the linker scripts in ld/emultempl/ | |
2781 | {armelf/pe}.em */ | |
2782 | ||
b34976b6 | 2783 | bfd_boolean |
57e8b36a | 2784 | bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) |
8afb0e02 NC |
2785 | { |
2786 | struct elf32_arm_link_hash_table *globals; | |
2787 | ||
2788 | /* If we are only performing a partial link | |
2789 | do not bother getting a bfd to hold the glue. */ | |
1049f94e | 2790 | if (info->relocatable) |
b34976b6 | 2791 | return TRUE; |
8afb0e02 | 2792 | |
b7693d02 DJ |
2793 | /* Make sure we don't attach the glue sections to a dynamic object. */ |
2794 | BFD_ASSERT (!(abfd->flags & DYNAMIC)); | |
2795 | ||
8afb0e02 NC |
2796 | globals = elf32_arm_hash_table (info); |
2797 | ||
2798 | BFD_ASSERT (globals != NULL); | |
2799 | ||
2800 | if (globals->bfd_of_glue_owner != NULL) | |
b34976b6 | 2801 | return TRUE; |
8afb0e02 | 2802 | |
252b5132 RH |
2803 | /* Save the bfd for later use. */ |
2804 | globals->bfd_of_glue_owner = abfd; | |
cedb70c5 | 2805 | |
b34976b6 | 2806 | return TRUE; |
252b5132 RH |
2807 | } |
2808 | ||
39b41c9c PB |
2809 | static void check_use_blx(struct elf32_arm_link_hash_table *globals) |
2810 | { | |
2811 | if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2) | |
2812 | globals->use_blx = 1; | |
2813 | } | |
2814 | ||
b34976b6 | 2815 | bfd_boolean |
57e8b36a NC |
2816 | bfd_elf32_arm_process_before_allocation (bfd *abfd, |
2817 | struct bfd_link_info *link_info, | |
eb043451 | 2818 | int byteswap_code) |
252b5132 RH |
2819 | { |
2820 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 2821 | Elf_Internal_Rela *internal_relocs = NULL; |
252b5132 RH |
2822 | Elf_Internal_Rela *irel, *irelend; |
2823 | bfd_byte *contents = NULL; | |
252b5132 RH |
2824 | |
2825 | asection *sec; | |
2826 | struct elf32_arm_link_hash_table *globals; | |
2827 | ||
2828 | /* If we are only performing a partial link do not bother | |
2829 | to construct any glue. */ | |
1049f94e | 2830 | if (link_info->relocatable) |
b34976b6 | 2831 | return TRUE; |
252b5132 RH |
2832 | |
2833 | /* Here we have a bfd that is to be included on the link. We have a hook | |
2834 | to do reloc rummaging, before section sizes are nailed down. */ | |
252b5132 | 2835 | globals = elf32_arm_hash_table (link_info); |
39b41c9c | 2836 | check_use_blx (globals); |
252b5132 RH |
2837 | |
2838 | BFD_ASSERT (globals != NULL); | |
2839 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2840 | ||
e489d0ae PB |
2841 | if (byteswap_code && !bfd_big_endian (abfd)) |
2842 | { | |
d003868e AM |
2843 | _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), |
2844 | abfd); | |
e489d0ae PB |
2845 | return FALSE; |
2846 | } | |
2847 | globals->byteswap_code = byteswap_code; | |
f21f3fe0 | 2848 | |
252b5132 RH |
2849 | /* Rummage around all the relocs and map the glue vectors. */ |
2850 | sec = abfd->sections; | |
2851 | ||
2852 | if (sec == NULL) | |
b34976b6 | 2853 | return TRUE; |
252b5132 RH |
2854 | |
2855 | for (; sec != NULL; sec = sec->next) | |
2856 | { | |
2857 | if (sec->reloc_count == 0) | |
2858 | continue; | |
2859 | ||
2860 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
252b5132 | 2861 | |
9b485d32 | 2862 | /* Load the relocs. */ |
6cdc0ccc | 2863 | internal_relocs |
57e8b36a | 2864 | = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, |
45d6a902 | 2865 | (Elf_Internal_Rela *) NULL, FALSE); |
252b5132 | 2866 | |
6cdc0ccc AM |
2867 | if (internal_relocs == NULL) |
2868 | goto error_return; | |
252b5132 | 2869 | |
6cdc0ccc AM |
2870 | irelend = internal_relocs + sec->reloc_count; |
2871 | for (irel = internal_relocs; irel < irelend; irel++) | |
252b5132 RH |
2872 | { |
2873 | long r_type; | |
2874 | unsigned long r_index; | |
252b5132 RH |
2875 | |
2876 | struct elf_link_hash_entry *h; | |
2877 | ||
2878 | r_type = ELF32_R_TYPE (irel->r_info); | |
2879 | r_index = ELF32_R_SYM (irel->r_info); | |
2880 | ||
9b485d32 | 2881 | /* These are the only relocation types we care about. */ |
ba96a88f | 2882 | if ( r_type != R_ARM_PC24 |
b7693d02 | 2883 | && r_type != R_ARM_PLT32 |
5b5bb741 PB |
2884 | && r_type != R_ARM_CALL |
2885 | && r_type != R_ARM_JUMP24 | |
c19d1205 | 2886 | && r_type != R_ARM_THM_CALL) |
252b5132 RH |
2887 | continue; |
2888 | ||
2889 | /* Get the section contents if we haven't done so already. */ | |
2890 | if (contents == NULL) | |
2891 | { | |
2892 | /* Get cached copy if it exists. */ | |
2893 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
2894 | contents = elf_section_data (sec)->this_hdr.contents; | |
2895 | else | |
2896 | { | |
2897 | /* Go get them off disk. */ | |
57e8b36a | 2898 | if (! bfd_malloc_and_get_section (abfd, sec, &contents)) |
252b5132 RH |
2899 | goto error_return; |
2900 | } | |
2901 | } | |
2902 | ||
a7c10850 | 2903 | /* If the relocation is not against a symbol it cannot concern us. */ |
252b5132 RH |
2904 | h = NULL; |
2905 | ||
9b485d32 | 2906 | /* We don't care about local symbols. */ |
252b5132 RH |
2907 | if (r_index < symtab_hdr->sh_info) |
2908 | continue; | |
2909 | ||
9b485d32 | 2910 | /* This is an external symbol. */ |
252b5132 RH |
2911 | r_index -= symtab_hdr->sh_info; |
2912 | h = (struct elf_link_hash_entry *) | |
2913 | elf_sym_hashes (abfd)[r_index]; | |
2914 | ||
2915 | /* If the relocation is against a static symbol it must be within | |
2916 | the current section and so cannot be a cross ARM/Thumb relocation. */ | |
2917 | if (h == NULL) | |
2918 | continue; | |
2919 | ||
b7693d02 DJ |
2920 | /* If the call will go through a PLT entry then we do not need |
2921 | glue. */ | |
2922 | if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1) | |
2923 | continue; | |
2924 | ||
252b5132 RH |
2925 | switch (r_type) |
2926 | { | |
2927 | case R_ARM_PC24: | |
c6596c5e | 2928 | case R_ARM_PLT32: |
5b5bb741 PB |
2929 | case R_ARM_CALL: |
2930 | case R_ARM_JUMP24: | |
252b5132 | 2931 | /* This one is a call from arm code. We need to look up |
2f0ca46a | 2932 | the target of the call. If it is a thumb target, we |
252b5132 | 2933 | insert glue. */ |
39b41c9c PB |
2934 | if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC |
2935 | && !(r_type == R_ARM_CALL && globals->use_blx)) | |
252b5132 RH |
2936 | record_arm_to_thumb_glue (link_info, h); |
2937 | break; | |
2938 | ||
c19d1205 | 2939 | case R_ARM_THM_CALL: |
f21f3fe0 | 2940 | /* This one is a call from thumb code. We look |
2f0ca46a | 2941 | up the target of the call. If it is not a thumb |
bcbdc74c | 2942 | target, we insert glue. */ |
39b41c9c | 2943 | if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx) |
252b5132 RH |
2944 | record_thumb_to_arm_glue (link_info, h); |
2945 | break; | |
2946 | ||
2947 | default: | |
c6596c5e | 2948 | abort (); |
252b5132 RH |
2949 | } |
2950 | } | |
6cdc0ccc AM |
2951 | |
2952 | if (contents != NULL | |
2953 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2954 | free (contents); | |
2955 | contents = NULL; | |
2956 | ||
2957 | if (internal_relocs != NULL | |
2958 | && elf_section_data (sec)->relocs != internal_relocs) | |
2959 | free (internal_relocs); | |
2960 | internal_relocs = NULL; | |
252b5132 RH |
2961 | } |
2962 | ||
b34976b6 | 2963 | return TRUE; |
9a5aca8c | 2964 | |
252b5132 | 2965 | error_return: |
6cdc0ccc AM |
2966 | if (contents != NULL |
2967 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2968 | free (contents); | |
2969 | if (internal_relocs != NULL | |
2970 | && elf_section_data (sec)->relocs != internal_relocs) | |
2971 | free (internal_relocs); | |
9a5aca8c | 2972 | |
b34976b6 | 2973 | return FALSE; |
252b5132 | 2974 | } |
7e392df6 | 2975 | #endif |
252b5132 | 2976 | |
eb043451 | 2977 | |
eb043451 PB |
2978 | /* Set target relocation values needed during linking. */ |
2979 | ||
2980 | void | |
2981 | bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info, | |
2982 | int target1_is_rel, | |
319850b4 | 2983 | char * target2_type, |
33bfe774 JB |
2984 | int fix_v4bx, |
2985 | int use_blx) | |
eb043451 PB |
2986 | { |
2987 | struct elf32_arm_link_hash_table *globals; | |
2988 | ||
2989 | globals = elf32_arm_hash_table (link_info); | |
2990 | ||
2991 | globals->target1_is_rel = target1_is_rel; | |
2992 | if (strcmp (target2_type, "rel") == 0) | |
2993 | globals->target2_reloc = R_ARM_REL32; | |
eeac373a PB |
2994 | else if (strcmp (target2_type, "abs") == 0) |
2995 | globals->target2_reloc = R_ARM_ABS32; | |
eb043451 PB |
2996 | else if (strcmp (target2_type, "got-rel") == 0) |
2997 | globals->target2_reloc = R_ARM_GOT_PREL; | |
2998 | else | |
2999 | { | |
3000 | _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."), | |
3001 | target2_type); | |
3002 | } | |
319850b4 | 3003 | globals->fix_v4bx = fix_v4bx; |
33bfe774 | 3004 | globals->use_blx |= use_blx; |
eb043451 | 3005 | } |
eb043451 | 3006 | |
252b5132 RH |
3007 | /* The thumb form of a long branch is a bit finicky, because the offset |
3008 | encoding is split over two fields, each in it's own instruction. They | |
f21f3fe0 | 3009 | can occur in any order. So given a thumb form of long branch, and an |
252b5132 | 3010 | offset, insert the offset into the thumb branch and return finished |
f21f3fe0 | 3011 | instruction. |
252b5132 | 3012 | |
f21f3fe0 | 3013 | It takes two thumb instructions to encode the target address. Each has |
4cc11e76 | 3014 | 11 bits to invest. The upper 11 bits are stored in one (identified by |
f21f3fe0 UD |
3015 | H-0.. see below), the lower 11 bits are stored in the other (identified |
3016 | by H-1). | |
252b5132 | 3017 | |
f21f3fe0 | 3018 | Combine together and shifted left by 1 (it's a half word address) and |
252b5132 RH |
3019 | there you have it. |
3020 | ||
3021 | Op: 1111 = F, | |
3022 | H-0, upper address-0 = 000 | |
3023 | Op: 1111 = F, | |
3024 | H-1, lower address-0 = 800 | |
3025 | ||
f21f3fe0 | 3026 | They can be ordered either way, but the arm tools I've seen always put |
252b5132 RH |
3027 | the lower one first. It probably doesn't matter. krk@cygnus.com |
3028 | ||
3029 | XXX: Actually the order does matter. The second instruction (H-1) | |
3030 | moves the computed address into the PC, so it must be the second one | |
3031 | in the sequence. The problem, however is that whilst little endian code | |
3032 | stores the instructions in HI then LOW order, big endian code does the | |
dfc5f959 | 3033 | reverse. nickc@cygnus.com. */ |
252b5132 | 3034 | |
dfc5f959 NC |
3035 | #define LOW_HI_ORDER 0xF800F000 |
3036 | #define HI_LOW_ORDER 0xF000F800 | |
252b5132 RH |
3037 | |
3038 | static insn32 | |
57e8b36a | 3039 | insert_thumb_branch (insn32 br_insn, int rel_off) |
252b5132 RH |
3040 | { |
3041 | unsigned int low_bits; | |
3042 | unsigned int high_bits; | |
3043 | ||
252b5132 RH |
3044 | BFD_ASSERT ((rel_off & 1) != 1); |
3045 | ||
dfc5f959 NC |
3046 | rel_off >>= 1; /* Half word aligned address. */ |
3047 | low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ | |
3048 | high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ | |
252b5132 RH |
3049 | |
3050 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) | |
3051 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; | |
3052 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) | |
3053 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; | |
3054 | else | |
9b485d32 | 3055 | /* FIXME: abort is probably not the right call. krk@cygnus.com */ |
57e8b36a | 3056 | abort (); /* Error - not a valid branch instruction form. */ |
252b5132 | 3057 | |
252b5132 RH |
3058 | return br_insn; |
3059 | } | |
3060 | ||
52ab56c2 PB |
3061 | |
3062 | /* Store an Arm insn into an output section not processed by | |
3063 | elf32_arm_write_section. */ | |
3064 | ||
3065 | static void | |
3066 | put_arm_insn (struct elf32_arm_link_hash_table *htab, | |
3067 | bfd * output_bfd, bfd_vma val, void * ptr) | |
3068 | { | |
3069 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
3070 | bfd_putl32 (val, ptr); | |
3071 | else | |
3072 | bfd_putb32 (val, ptr); | |
3073 | } | |
3074 | ||
3075 | ||
3076 | /* Store a 16-bit Thumb insn into an output section not processed by | |
3077 | elf32_arm_write_section. */ | |
3078 | ||
3079 | static void | |
3080 | put_thumb_insn (struct elf32_arm_link_hash_table *htab, | |
3081 | bfd * output_bfd, bfd_vma val, void * ptr) | |
3082 | { | |
3083 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
3084 | bfd_putl16 (val, ptr); | |
3085 | else | |
3086 | bfd_putb16 (val, ptr); | |
3087 | } | |
3088 | ||
3089 | ||
9b485d32 NC |
3090 | /* Thumb code calling an ARM function. */ |
3091 | ||
252b5132 | 3092 | static int |
57e8b36a NC |
3093 | elf32_thumb_to_arm_stub (struct bfd_link_info * info, |
3094 | const char * name, | |
3095 | bfd * input_bfd, | |
3096 | bfd * output_bfd, | |
3097 | asection * input_section, | |
3098 | bfd_byte * hit_data, | |
3099 | asection * sym_sec, | |
3100 | bfd_vma offset, | |
3101 | bfd_signed_vma addend, | |
3102 | bfd_vma val) | |
252b5132 | 3103 | { |
bcbdc74c | 3104 | asection * s = 0; |
dc810e39 | 3105 | bfd_vma my_offset; |
252b5132 RH |
3106 | unsigned long int tmp; |
3107 | long int ret_offset; | |
bcbdc74c NC |
3108 | struct elf_link_hash_entry * myh; |
3109 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
3110 | |
3111 | myh = find_thumb_glue (info, name, input_bfd); | |
3112 | if (myh == NULL) | |
b34976b6 | 3113 | return FALSE; |
252b5132 RH |
3114 | |
3115 | globals = elf32_arm_hash_table (info); | |
3116 | ||
3117 | BFD_ASSERT (globals != NULL); | |
3118 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
3119 | ||
3120 | my_offset = myh->root.u.def.value; | |
3121 | ||
3122 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
3123 | THUMB2ARM_GLUE_SECTION_NAME); | |
3124 | ||
3125 | BFD_ASSERT (s != NULL); | |
3126 | BFD_ASSERT (s->contents != NULL); | |
3127 | BFD_ASSERT (s->output_section != NULL); | |
3128 | ||
3129 | if ((my_offset & 0x01) == 0x01) | |
3130 | { | |
3131 | if (sym_sec != NULL | |
3132 | && sym_sec->owner != NULL | |
3133 | && !INTERWORK_FLAG (sym_sec->owner)) | |
3134 | { | |
8f615d07 | 3135 | (*_bfd_error_handler) |
d003868e AM |
3136 | (_("%B(%s): warning: interworking not enabled.\n" |
3137 | " first occurrence: %B: thumb call to arm"), | |
3138 | sym_sec->owner, input_bfd, name); | |
252b5132 | 3139 | |
b34976b6 | 3140 | return FALSE; |
252b5132 RH |
3141 | } |
3142 | ||
3143 | --my_offset; | |
3144 | myh->root.u.def.value = my_offset; | |
3145 | ||
52ab56c2 PB |
3146 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn, |
3147 | s->contents + my_offset); | |
252b5132 | 3148 | |
52ab56c2 PB |
3149 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn, |
3150 | s->contents + my_offset + 2); | |
252b5132 RH |
3151 | |
3152 | ret_offset = | |
9b485d32 NC |
3153 | /* Address of destination of the stub. */ |
3154 | ((bfd_signed_vma) val) | |
252b5132 | 3155 | - ((bfd_signed_vma) |
57e8b36a NC |
3156 | /* Offset from the start of the current section |
3157 | to the start of the stubs. */ | |
9b485d32 NC |
3158 | (s->output_offset |
3159 | /* Offset of the start of this stub from the start of the stubs. */ | |
3160 | + my_offset | |
3161 | /* Address of the start of the current section. */ | |
3162 | + s->output_section->vma) | |
3163 | /* The branch instruction is 4 bytes into the stub. */ | |
3164 | + 4 | |
3165 | /* ARM branches work from the pc of the instruction + 8. */ | |
3166 | + 8); | |
252b5132 | 3167 | |
52ab56c2 PB |
3168 | put_arm_insn (globals, output_bfd, |
3169 | (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), | |
3170 | s->contents + my_offset + 4); | |
252b5132 RH |
3171 | } |
3172 | ||
3173 | BFD_ASSERT (my_offset <= globals->thumb_glue_size); | |
3174 | ||
427bfd90 NC |
3175 | /* Now go back and fix up the original BL insn to point to here. */ |
3176 | ret_offset = | |
3177 | /* Address of where the stub is located. */ | |
3178 | (s->output_section->vma + s->output_offset + my_offset) | |
3179 | /* Address of where the BL is located. */ | |
57e8b36a NC |
3180 | - (input_section->output_section->vma + input_section->output_offset |
3181 | + offset) | |
427bfd90 NC |
3182 | /* Addend in the relocation. */ |
3183 | - addend | |
3184 | /* Biassing for PC-relative addressing. */ | |
3185 | - 8; | |
252b5132 RH |
3186 | |
3187 | tmp = bfd_get_32 (input_bfd, hit_data | |
3188 | - input_section->vma); | |
3189 | ||
3190 | bfd_put_32 (output_bfd, | |
dc810e39 | 3191 | (bfd_vma) insert_thumb_branch (tmp, ret_offset), |
252b5132 RH |
3192 | hit_data - input_section->vma); |
3193 | ||
b34976b6 | 3194 | return TRUE; |
252b5132 RH |
3195 | } |
3196 | ||
9b485d32 NC |
3197 | /* Arm code calling a Thumb function. */ |
3198 | ||
252b5132 | 3199 | static int |
57e8b36a NC |
3200 | elf32_arm_to_thumb_stub (struct bfd_link_info * info, |
3201 | const char * name, | |
3202 | bfd * input_bfd, | |
3203 | bfd * output_bfd, | |
3204 | asection * input_section, | |
3205 | bfd_byte * hit_data, | |
3206 | asection * sym_sec, | |
3207 | bfd_vma offset, | |
3208 | bfd_signed_vma addend, | |
3209 | bfd_vma val) | |
252b5132 RH |
3210 | { |
3211 | unsigned long int tmp; | |
dc810e39 | 3212 | bfd_vma my_offset; |
bcbdc74c | 3213 | asection * s; |
252b5132 | 3214 | long int ret_offset; |
bcbdc74c NC |
3215 | struct elf_link_hash_entry * myh; |
3216 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
3217 | |
3218 | myh = find_arm_glue (info, name, input_bfd); | |
3219 | if (myh == NULL) | |
b34976b6 | 3220 | return FALSE; |
252b5132 RH |
3221 | |
3222 | globals = elf32_arm_hash_table (info); | |
3223 | ||
3224 | BFD_ASSERT (globals != NULL); | |
3225 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
3226 | ||
3227 | my_offset = myh->root.u.def.value; | |
3228 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
3229 | ARM2THUMB_GLUE_SECTION_NAME); | |
3230 | BFD_ASSERT (s != NULL); | |
3231 | BFD_ASSERT (s->contents != NULL); | |
3232 | BFD_ASSERT (s->output_section != NULL); | |
3233 | ||
3234 | if ((my_offset & 0x01) == 0x01) | |
3235 | { | |
3236 | if (sym_sec != NULL | |
3237 | && sym_sec->owner != NULL | |
3238 | && !INTERWORK_FLAG (sym_sec->owner)) | |
3239 | { | |
8f615d07 | 3240 | (*_bfd_error_handler) |
d003868e AM |
3241 | (_("%B(%s): warning: interworking not enabled.\n" |
3242 | " first occurrence: %B: arm call to thumb"), | |
3243 | sym_sec->owner, input_bfd, name); | |
252b5132 | 3244 | } |
9b485d32 | 3245 | |
252b5132 RH |
3246 | --my_offset; |
3247 | myh->root.u.def.value = my_offset; | |
3248 | ||
8f6277f5 PB |
3249 | if ((info->shared || globals->root.is_relocatable_executable)) |
3250 | { | |
3251 | /* For relocatable objects we can't use absolute addresses, | |
3252 | so construct the address from a relative offset. */ | |
3253 | /* TODO: If the offset is small it's probably worth | |
3254 | constructing the address with adds. */ | |
52ab56c2 PB |
3255 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn, |
3256 | s->contents + my_offset); | |
3257 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn, | |
3258 | s->contents + my_offset + 4); | |
3259 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn, | |
3260 | s->contents + my_offset + 8); | |
8f6277f5 PB |
3261 | /* Adjust the offset by 4 for the position of the add, |
3262 | and 8 for the pipeline offset. */ | |
3263 | ret_offset = (val - (s->output_offset | |
3264 | + s->output_section->vma | |
3265 | + my_offset + 12)) | |
3266 | | 1; | |
3267 | bfd_put_32 (output_bfd, ret_offset, | |
3268 | s->contents + my_offset + 12); | |
3269 | } | |
3270 | else | |
3271 | { | |
52ab56c2 PB |
3272 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn, |
3273 | s->contents + my_offset); | |
252b5132 | 3274 | |
52ab56c2 PB |
3275 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn, |
3276 | s->contents + my_offset + 4); | |
252b5132 | 3277 | |
8f6277f5 PB |
3278 | /* It's a thumb address. Add the low order bit. */ |
3279 | bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, | |
3280 | s->contents + my_offset + 8); | |
3281 | } | |
252b5132 RH |
3282 | } |
3283 | ||
3284 | BFD_ASSERT (my_offset <= globals->arm_glue_size); | |
3285 | ||
3286 | tmp = bfd_get_32 (input_bfd, hit_data); | |
3287 | tmp = tmp & 0xFF000000; | |
3288 | ||
9b485d32 | 3289 | /* Somehow these are both 4 too far, so subtract 8. */ |
dc810e39 AM |
3290 | ret_offset = (s->output_offset |
3291 | + my_offset | |
3292 | + s->output_section->vma | |
3293 | - (input_section->output_offset | |
3294 | + input_section->output_section->vma | |
3295 | + offset + addend) | |
3296 | - 8); | |
9a5aca8c | 3297 | |
252b5132 RH |
3298 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); |
3299 | ||
dc810e39 | 3300 | bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); |
252b5132 | 3301 | |
b34976b6 | 3302 | return TRUE; |
252b5132 RH |
3303 | } |
3304 | ||
eb043451 PB |
3305 | /* Some relocations map to different relocations depending on the |
3306 | target. Return the real relocation. */ | |
3307 | static int | |
3308 | arm_real_reloc_type (struct elf32_arm_link_hash_table * globals, | |
3309 | int r_type) | |
3310 | { | |
3311 | switch (r_type) | |
3312 | { | |
3313 | case R_ARM_TARGET1: | |
3314 | if (globals->target1_is_rel) | |
3315 | return R_ARM_REL32; | |
3316 | else | |
3317 | return R_ARM_ABS32; | |
3318 | ||
3319 | case R_ARM_TARGET2: | |
3320 | return globals->target2_reloc; | |
3321 | ||
3322 | default: | |
3323 | return r_type; | |
3324 | } | |
3325 | } | |
eb043451 | 3326 | |
ba93b8ac DJ |
3327 | /* Return the base VMA address which should be subtracted from real addresses |
3328 | when resolving @dtpoff relocation. | |
3329 | This is PT_TLS segment p_vaddr. */ | |
3330 | ||
3331 | static bfd_vma | |
3332 | dtpoff_base (struct bfd_link_info *info) | |
3333 | { | |
3334 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3335 | if (elf_hash_table (info)->tls_sec == NULL) | |
3336 | return 0; | |
3337 | return elf_hash_table (info)->tls_sec->vma; | |
3338 | } | |
3339 | ||
3340 | /* Return the relocation value for @tpoff relocation | |
3341 | if STT_TLS virtual address is ADDRESS. */ | |
3342 | ||
3343 | static bfd_vma | |
3344 | tpoff (struct bfd_link_info *info, bfd_vma address) | |
3345 | { | |
3346 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
3347 | bfd_vma base; | |
3348 | ||
3349 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3350 | if (htab->tls_sec == NULL) | |
3351 | return 0; | |
3352 | base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power); | |
3353 | return address - htab->tls_sec->vma + base; | |
3354 | } | |
3355 | ||
00a97672 RS |
3356 | /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA. |
3357 | VALUE is the relocation value. */ | |
3358 | ||
3359 | static bfd_reloc_status_type | |
3360 | elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value) | |
3361 | { | |
3362 | if (value > 0xfff) | |
3363 | return bfd_reloc_overflow; | |
3364 | ||
3365 | value |= bfd_get_32 (abfd, data) & 0xfffff000; | |
3366 | bfd_put_32 (abfd, value, data); | |
3367 | return bfd_reloc_ok; | |
3368 | } | |
3369 | ||
4962c51a MS |
3370 | /* For a given value of n, calculate the value of G_n as required to |
3371 | deal with group relocations. We return it in the form of an | |
3372 | encoded constant-and-rotation, together with the final residual. If n is | |
3373 | specified as less than zero, then final_residual is filled with the | |
3374 | input value and no further action is performed. */ | |
3375 | ||
3376 | static bfd_vma | |
3377 | calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual) | |
3378 | { | |
3379 | int current_n; | |
3380 | bfd_vma g_n; | |
3381 | bfd_vma encoded_g_n = 0; | |
3382 | bfd_vma residual = value; /* Also known as Y_n. */ | |
3383 | ||
3384 | for (current_n = 0; current_n <= n; current_n++) | |
3385 | { | |
3386 | int shift; | |
3387 | ||
3388 | /* Calculate which part of the value to mask. */ | |
3389 | if (residual == 0) | |
3390 | shift = 0; | |
3391 | else | |
3392 | { | |
3393 | int msb; | |
3394 | ||
3395 | /* Determine the most significant bit in the residual and | |
3396 | align the resulting value to a 2-bit boundary. */ | |
3397 | for (msb = 30; msb >= 0; msb -= 2) | |
3398 | if (residual & (3 << msb)) | |
3399 | break; | |
3400 | ||
3401 | /* The desired shift is now (msb - 6), or zero, whichever | |
3402 | is the greater. */ | |
3403 | shift = msb - 6; | |
3404 | if (shift < 0) | |
3405 | shift = 0; | |
3406 | } | |
3407 | ||
3408 | /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */ | |
3409 | g_n = residual & (0xff << shift); | |
3410 | encoded_g_n = (g_n >> shift) | |
3411 | | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8); | |
3412 | ||
3413 | /* Calculate the residual for the next time around. */ | |
3414 | residual &= ~g_n; | |
3415 | } | |
3416 | ||
3417 | *final_residual = residual; | |
3418 | ||
3419 | return encoded_g_n; | |
3420 | } | |
3421 | ||
3422 | /* Given an ARM instruction, determine whether it is an ADD or a SUB. | |
3423 | Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */ | |
3424 | static int | |
3425 | identify_add_or_sub(bfd_vma insn) | |
3426 | { | |
3427 | int opcode = insn & 0x1e00000; | |
3428 | ||
3429 | if (opcode == 1 << 23) /* ADD */ | |
3430 | return 1; | |
3431 | ||
3432 | if (opcode == 1 << 22) /* SUB */ | |
3433 | return -1; | |
3434 | ||
3435 | return 0; | |
3436 | } | |
3437 | ||
252b5132 | 3438 | /* Perform a relocation as part of a final link. */ |
9b485d32 | 3439 | |
252b5132 | 3440 | static bfd_reloc_status_type |
57e8b36a NC |
3441 | elf32_arm_final_link_relocate (reloc_howto_type * howto, |
3442 | bfd * input_bfd, | |
3443 | bfd * output_bfd, | |
3444 | asection * input_section, | |
3445 | bfd_byte * contents, | |
3446 | Elf_Internal_Rela * rel, | |
3447 | bfd_vma value, | |
3448 | struct bfd_link_info * info, | |
3449 | asection * sym_sec, | |
3450 | const char * sym_name, | |
3451 | int sym_flags, | |
0945cdfd DJ |
3452 | struct elf_link_hash_entry * h, |
3453 | bfd_boolean * unresolved_reloc_p) | |
252b5132 RH |
3454 | { |
3455 | unsigned long r_type = howto->type; | |
3456 | unsigned long r_symndx; | |
3457 | bfd_byte * hit_data = contents + rel->r_offset; | |
3458 | bfd * dynobj = NULL; | |
3459 | Elf_Internal_Shdr * symtab_hdr; | |
3460 | struct elf_link_hash_entry ** sym_hashes; | |
3461 | bfd_vma * local_got_offsets; | |
3462 | asection * sgot = NULL; | |
3463 | asection * splt = NULL; | |
3464 | asection * sreloc = NULL; | |
252b5132 | 3465 | bfd_vma addend; |
ba96a88f NC |
3466 | bfd_signed_vma signed_addend; |
3467 | struct elf32_arm_link_hash_table * globals; | |
f21f3fe0 | 3468 | |
9c504268 PB |
3469 | globals = elf32_arm_hash_table (info); |
3470 | ||
9c504268 PB |
3471 | /* Some relocation type map to different relocations depending on the |
3472 | target. We pick the right one here. */ | |
eb043451 PB |
3473 | r_type = arm_real_reloc_type (globals, r_type); |
3474 | if (r_type != howto->type) | |
3475 | howto = elf32_arm_howto_from_type (r_type); | |
9c504268 | 3476 | |
cac15327 NC |
3477 | /* If the start address has been set, then set the EF_ARM_HASENTRY |
3478 | flag. Setting this more than once is redundant, but the cost is | |
3479 | not too high, and it keeps the code simple. | |
99e4ae17 | 3480 | |
cac15327 NC |
3481 | The test is done here, rather than somewhere else, because the |
3482 | start address is only set just before the final link commences. | |
3483 | ||
3484 | Note - if the user deliberately sets a start address of 0, the | |
3485 | flag will not be set. */ | |
3486 | if (bfd_get_start_address (output_bfd) != 0) | |
3487 | elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; | |
99e4ae17 | 3488 | |
252b5132 RH |
3489 | dynobj = elf_hash_table (info)->dynobj; |
3490 | if (dynobj) | |
3491 | { | |
3492 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
3493 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
3494 | } | |
3495 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
3496 | sym_hashes = elf_sym_hashes (input_bfd); | |
3497 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
3498 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3499 | ||
4e7fd91e | 3500 | if (globals->use_rel) |
ba96a88f | 3501 | { |
4e7fd91e PB |
3502 | addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; |
3503 | ||
3504 | if (addend & ((howto->src_mask + 1) >> 1)) | |
3505 | { | |
3506 | signed_addend = -1; | |
3507 | signed_addend &= ~ howto->src_mask; | |
3508 | signed_addend |= addend; | |
3509 | } | |
3510 | else | |
3511 | signed_addend = addend; | |
ba96a88f NC |
3512 | } |
3513 | else | |
4e7fd91e | 3514 | addend = signed_addend = rel->r_addend; |
f21f3fe0 | 3515 | |
252b5132 RH |
3516 | switch (r_type) |
3517 | { | |
3518 | case R_ARM_NONE: | |
28a094c2 DJ |
3519 | /* We don't need to find a value for this symbol. It's just a |
3520 | marker. */ | |
3521 | *unresolved_reloc_p = FALSE; | |
252b5132 RH |
3522 | return bfd_reloc_ok; |
3523 | ||
00a97672 RS |
3524 | case R_ARM_ABS12: |
3525 | if (!globals->vxworks_p) | |
3526 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
3527 | ||
252b5132 RH |
3528 | case R_ARM_PC24: |
3529 | case R_ARM_ABS32: | |
3530 | case R_ARM_REL32: | |
5b5bb741 PB |
3531 | case R_ARM_CALL: |
3532 | case R_ARM_JUMP24: | |
dfc5f959 | 3533 | case R_ARM_XPC25: |
eb043451 | 3534 | case R_ARM_PREL31: |
7359ea65 | 3535 | case R_ARM_PLT32: |
5e681ec4 PB |
3536 | /* r_symndx will be zero only for relocs against symbols |
3537 | from removed linkonce sections, or sections discarded by | |
3538 | a linker script. */ | |
3539 | if (r_symndx == 0) | |
3540 | return bfd_reloc_ok; | |
3541 | ||
7359ea65 DJ |
3542 | /* Handle relocations which should use the PLT entry. ABS32/REL32 |
3543 | will use the symbol's value, which may point to a PLT entry, but we | |
3544 | don't need to handle that here. If we created a PLT entry, all | |
3545 | branches in this object should go to it. */ | |
ee06dc07 | 3546 | if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
7359ea65 | 3547 | && h != NULL |
c84cd8ee | 3548 | && splt != NULL |
7359ea65 DJ |
3549 | && h->plt.offset != (bfd_vma) -1) |
3550 | { | |
c84cd8ee DJ |
3551 | /* If we've created a .plt section, and assigned a PLT entry to |
3552 | this function, it should not be known to bind locally. If | |
3553 | it were, we would have cleared the PLT entry. */ | |
7359ea65 DJ |
3554 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); |
3555 | ||
3556 | value = (splt->output_section->vma | |
3557 | + splt->output_offset | |
3558 | + h->plt.offset); | |
0945cdfd | 3559 | *unresolved_reloc_p = FALSE; |
7359ea65 DJ |
3560 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
3561 | contents, rel->r_offset, value, | |
00a97672 | 3562 | rel->r_addend); |
7359ea65 DJ |
3563 | } |
3564 | ||
67687978 PB |
3565 | /* When generating a shared object or relocatable executable, these |
3566 | relocations are copied into the output file to be resolved at | |
3567 | run time. */ | |
3568 | if ((info->shared || globals->root.is_relocatable_executable) | |
7359ea65 | 3569 | && (input_section->flags & SEC_ALLOC) |
ee06dc07 PB |
3570 | && (r_type != R_ARM_REL32 |
3571 | || !SYMBOL_CALLS_LOCAL (info, h)) | |
7359ea65 DJ |
3572 | && (h == NULL |
3573 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
3574 | || h->root.type != bfd_link_hash_undefweak) | |
3575 | && r_type != R_ARM_PC24 | |
5b5bb741 PB |
3576 | && r_type != R_ARM_CALL |
3577 | && r_type != R_ARM_JUMP24 | |
ee06dc07 | 3578 | && r_type != R_ARM_PREL31 |
7359ea65 | 3579 | && r_type != R_ARM_PLT32) |
252b5132 | 3580 | { |
947216bf AM |
3581 | Elf_Internal_Rela outrel; |
3582 | bfd_byte *loc; | |
b34976b6 | 3583 | bfd_boolean skip, relocate; |
f21f3fe0 | 3584 | |
0945cdfd DJ |
3585 | *unresolved_reloc_p = FALSE; |
3586 | ||
252b5132 RH |
3587 | if (sreloc == NULL) |
3588 | { | |
3589 | const char * name; | |
f21f3fe0 | 3590 | |
252b5132 RH |
3591 | name = (bfd_elf_string_from_elf_section |
3592 | (input_bfd, | |
3593 | elf_elfheader (input_bfd)->e_shstrndx, | |
3594 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
3595 | if (name == NULL) | |
3596 | return bfd_reloc_notsupported; | |
f21f3fe0 | 3597 | |
00a97672 | 3598 | BFD_ASSERT (reloc_section_p (globals, name, input_section)); |
f21f3fe0 | 3599 | |
252b5132 RH |
3600 | sreloc = bfd_get_section_by_name (dynobj, name); |
3601 | BFD_ASSERT (sreloc != NULL); | |
3602 | } | |
f21f3fe0 | 3603 | |
b34976b6 AM |
3604 | skip = FALSE; |
3605 | relocate = FALSE; | |
f21f3fe0 | 3606 | |
00a97672 | 3607 | outrel.r_addend = addend; |
c629eae0 JJ |
3608 | outrel.r_offset = |
3609 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
3610 | rel->r_offset); | |
3611 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 3612 | skip = TRUE; |
0bb2d96a | 3613 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 3614 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
3615 | outrel.r_offset += (input_section->output_section->vma |
3616 | + input_section->output_offset); | |
f21f3fe0 | 3617 | |
252b5132 | 3618 | if (skip) |
0bb2d96a | 3619 | memset (&outrel, 0, sizeof outrel); |
5e681ec4 PB |
3620 | else if (h != NULL |
3621 | && h->dynindx != -1 | |
7359ea65 | 3622 | && (!info->shared |
5e681ec4 | 3623 | || !info->symbolic |
f5385ebf | 3624 | || !h->def_regular)) |
5e681ec4 | 3625 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
252b5132 RH |
3626 | else |
3627 | { | |
a16385dc MM |
3628 | int symbol; |
3629 | ||
5e681ec4 | 3630 | /* This symbol is local, or marked to become local. */ |
b7693d02 DJ |
3631 | if (sym_flags == STT_ARM_TFUNC) |
3632 | value |= 1; | |
a16385dc | 3633 | if (globals->symbian_p) |
6366ff1e MM |
3634 | { |
3635 | /* On Symbian OS, the data segment and text segement | |
3636 | can be relocated independently. Therefore, we | |
3637 | must indicate the segment to which this | |
3638 | relocation is relative. The BPABI allows us to | |
3639 | use any symbol in the right segment; we just use | |
3640 | the section symbol as it is convenient. (We | |
3641 | cannot use the symbol given by "h" directly as it | |
3642 | will not appear in the dynamic symbol table.) */ | |
10dbd1f3 NC |
3643 | if (sym_sec) |
3644 | symbol = elf_section_data (sym_sec->output_section)->dynindx; | |
3645 | else | |
3646 | symbol = elf_section_data (input_section->output_section)->dynindx; | |
6366ff1e MM |
3647 | BFD_ASSERT (symbol != 0); |
3648 | } | |
a16385dc MM |
3649 | else |
3650 | /* On SVR4-ish systems, the dynamic loader cannot | |
3651 | relocate the text and data segments independently, | |
3652 | so the symbol does not matter. */ | |
3653 | symbol = 0; | |
3654 | outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE); | |
00a97672 RS |
3655 | if (globals->use_rel) |
3656 | relocate = TRUE; | |
3657 | else | |
3658 | outrel.r_addend += value; | |
252b5132 | 3659 | } |
f21f3fe0 | 3660 | |
947216bf | 3661 | loc = sreloc->contents; |
00a97672 RS |
3662 | loc += sreloc->reloc_count++ * RELOC_SIZE (globals); |
3663 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
9a5aca8c | 3664 | |
f21f3fe0 | 3665 | /* If this reloc is against an external symbol, we do not want to |
252b5132 | 3666 | fiddle with the addend. Otherwise, we need to include the symbol |
9b485d32 | 3667 | value so that it becomes an addend for the dynamic reloc. */ |
252b5132 RH |
3668 | if (! relocate) |
3669 | return bfd_reloc_ok; | |
9a5aca8c | 3670 | |
f21f3fe0 | 3671 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
252b5132 RH |
3672 | contents, rel->r_offset, value, |
3673 | (bfd_vma) 0); | |
3674 | } | |
3675 | else switch (r_type) | |
3676 | { | |
00a97672 RS |
3677 | case R_ARM_ABS12: |
3678 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
3679 | ||
dfc5f959 | 3680 | case R_ARM_XPC25: /* Arm BLX instruction. */ |
5b5bb741 PB |
3681 | case R_ARM_CALL: |
3682 | case R_ARM_JUMP24: | |
dfc5f959 | 3683 | case R_ARM_PC24: /* Arm B/BL instruction */ |
7359ea65 | 3684 | case R_ARM_PLT32: |
dfc5f959 | 3685 | if (r_type == R_ARM_XPC25) |
252b5132 | 3686 | { |
dfc5f959 NC |
3687 | /* Check for Arm calling Arm function. */ |
3688 | /* FIXME: Should we translate the instruction into a BL | |
3689 | instruction instead ? */ | |
3690 | if (sym_flags != STT_ARM_TFUNC) | |
d003868e AM |
3691 | (*_bfd_error_handler) |
3692 | (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), | |
3693 | input_bfd, | |
3694 | h ? h->root.root.string : "(local)"); | |
dfc5f959 | 3695 | } |
39b41c9c | 3696 | else if (r_type != R_ARM_CALL || !globals->use_blx) |
dfc5f959 NC |
3697 | { |
3698 | /* Check for Arm calling Thumb function. */ | |
3699 | if (sym_flags == STT_ARM_TFUNC) | |
3700 | { | |
57e8b36a NC |
3701 | elf32_arm_to_thumb_stub (info, sym_name, input_bfd, |
3702 | output_bfd, input_section, | |
3703 | hit_data, sym_sec, rel->r_offset, | |
dfc5f959 NC |
3704 | signed_addend, value); |
3705 | return bfd_reloc_ok; | |
3706 | } | |
252b5132 | 3707 | } |
ba96a88f | 3708 | |
dea514f5 PB |
3709 | /* The ARM ELF ABI says that this reloc is computed as: S - P + A |
3710 | where: | |
3711 | S is the address of the symbol in the relocation. | |
3712 | P is address of the instruction being relocated. | |
3713 | A is the addend (extracted from the instruction) in bytes. | |
3714 | ||
3715 | S is held in 'value'. | |
3716 | P is the base address of the section containing the | |
3717 | instruction plus the offset of the reloc into that | |
3718 | section, ie: | |
3719 | (input_section->output_section->vma + | |
3720 | input_section->output_offset + | |
3721 | rel->r_offset). | |
3722 | A is the addend, converted into bytes, ie: | |
3723 | (signed_addend * 4) | |
3724 | ||
3725 | Note: None of these operations have knowledge of the pipeline | |
3726 | size of the processor, thus it is up to the assembler to | |
3727 | encode this information into the addend. */ | |
3728 | value -= (input_section->output_section->vma | |
3729 | + input_section->output_offset); | |
3730 | value -= rel->r_offset; | |
4e7fd91e PB |
3731 | if (globals->use_rel) |
3732 | value += (signed_addend << howto->size); | |
3733 | else | |
3734 | /* RELA addends do not have to be adjusted by howto->size. */ | |
3735 | value += signed_addend; | |
23080146 | 3736 | |
dcb5e6e6 NC |
3737 | signed_addend = value; |
3738 | signed_addend >>= howto->rightshift; | |
9a5aca8c | 3739 | |
59f2c4e7 NC |
3740 | /* It is not an error for an undefined weak reference to be |
3741 | out of range. Any program that branches to such a symbol | |
9a5aca8c AM |
3742 | is going to crash anyway, so there is no point worrying |
3743 | about getting the destination exactly right. */ | |
59f2c4e7 NC |
3744 | if (! h || h->root.type != bfd_link_hash_undefweak) |
3745 | { | |
9b485d32 | 3746 | /* Perform a signed range check. */ |
dcb5e6e6 | 3747 | if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) |
59f2c4e7 NC |
3748 | || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) |
3749 | return bfd_reloc_overflow; | |
3750 | } | |
9a5aca8c | 3751 | |
39b41c9c PB |
3752 | addend = (value & 2); |
3753 | ||
3754 | value = (signed_addend & howto->dst_mask) | |
3755 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); | |
3756 | ||
3757 | /* Set the H bit in the BLX instruction. */ | |
3758 | if (sym_flags == STT_ARM_TFUNC) | |
3759 | { | |
3760 | if (addend) | |
3761 | value |= (1 << 24); | |
3762 | else | |
3763 | value &= ~(bfd_vma)(1 << 24); | |
3764 | } | |
3765 | if (r_type == R_ARM_CALL) | |
3766 | { | |
3767 | /* Select the correct instruction (BL or BLX). */ | |
3768 | if (sym_flags == STT_ARM_TFUNC) | |
3769 | value |= (1 << 28); | |
3770 | else | |
3771 | { | |
3772 | value &= ~(bfd_vma)(1 << 28); | |
3773 | value |= (1 << 24); | |
3774 | } | |
3775 | } | |
252b5132 | 3776 | break; |
f21f3fe0 | 3777 | |
252b5132 RH |
3778 | case R_ARM_ABS32: |
3779 | value += addend; | |
3780 | if (sym_flags == STT_ARM_TFUNC) | |
3781 | value |= 1; | |
3782 | break; | |
f21f3fe0 | 3783 | |
252b5132 | 3784 | case R_ARM_REL32: |
a8bc6c78 PB |
3785 | value += addend; |
3786 | if (sym_flags == STT_ARM_TFUNC) | |
3787 | value |= 1; | |
252b5132 | 3788 | value -= (input_section->output_section->vma |
62efb346 | 3789 | + input_section->output_offset + rel->r_offset); |
252b5132 | 3790 | break; |
eb043451 | 3791 | |
eb043451 PB |
3792 | case R_ARM_PREL31: |
3793 | value -= (input_section->output_section->vma | |
3794 | + input_section->output_offset + rel->r_offset); | |
3795 | value += signed_addend; | |
3796 | if (! h || h->root.type != bfd_link_hash_undefweak) | |
3797 | { | |
3798 | /* Check for overflow */ | |
3799 | if ((value ^ (value >> 1)) & (1 << 30)) | |
3800 | return bfd_reloc_overflow; | |
3801 | } | |
3802 | value &= 0x7fffffff; | |
3803 | value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000); | |
3804 | if (sym_flags == STT_ARM_TFUNC) | |
3805 | value |= 1; | |
3806 | break; | |
252b5132 | 3807 | } |
f21f3fe0 | 3808 | |
252b5132 RH |
3809 | bfd_put_32 (input_bfd, value, hit_data); |
3810 | return bfd_reloc_ok; | |
3811 | ||
3812 | case R_ARM_ABS8: | |
3813 | value += addend; | |
3814 | if ((long) value > 0x7f || (long) value < -0x80) | |
3815 | return bfd_reloc_overflow; | |
3816 | ||
3817 | bfd_put_8 (input_bfd, value, hit_data); | |
3818 | return bfd_reloc_ok; | |
3819 | ||
3820 | case R_ARM_ABS16: | |
3821 | value += addend; | |
3822 | ||
3823 | if ((long) value > 0x7fff || (long) value < -0x8000) | |
3824 | return bfd_reloc_overflow; | |
3825 | ||
3826 | bfd_put_16 (input_bfd, value, hit_data); | |
3827 | return bfd_reloc_ok; | |
3828 | ||
252b5132 | 3829 | case R_ARM_THM_ABS5: |
9b485d32 | 3830 | /* Support ldr and str instructions for the thumb. */ |
4e7fd91e PB |
3831 | if (globals->use_rel) |
3832 | { | |
3833 | /* Need to refetch addend. */ | |
3834 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
3835 | /* ??? Need to determine shift amount from operand size. */ | |
3836 | addend >>= howto->rightshift; | |
3837 | } | |
252b5132 RH |
3838 | value += addend; |
3839 | ||
3840 | /* ??? Isn't value unsigned? */ | |
3841 | if ((long) value > 0x1f || (long) value < -0x10) | |
3842 | return bfd_reloc_overflow; | |
3843 | ||
3844 | /* ??? Value needs to be properly shifted into place first. */ | |
3845 | value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; | |
3846 | bfd_put_16 (input_bfd, value, hit_data); | |
3847 | return bfd_reloc_ok; | |
3848 | ||
dfc5f959 | 3849 | case R_ARM_THM_XPC22: |
c19d1205 | 3850 | case R_ARM_THM_CALL: |
dfc5f959 | 3851 | /* Thumb BL (branch long instruction). */ |
252b5132 | 3852 | { |
b34976b6 AM |
3853 | bfd_vma relocation; |
3854 | bfd_boolean overflow = FALSE; | |
3855 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3856 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
df212a7e | 3857 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; |
ba96a88f | 3858 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; |
b34976b6 | 3859 | bfd_vma check; |
252b5132 | 3860 | bfd_signed_vma signed_check; |
252b5132 | 3861 | |
252b5132 RH |
3862 | /* Need to refetch the addend and squish the two 11 bit pieces |
3863 | together. */ | |
4e7fd91e PB |
3864 | if (globals->use_rel) |
3865 | { | |
3866 | bfd_vma upper = upper_insn & 0x7ff; | |
3867 | bfd_vma lower = lower_insn & 0x7ff; | |
3868 | upper = (upper ^ 0x400) - 0x400; /* Sign extend. */ | |
3869 | addend = (upper << 12) | (lower << 1); | |
3870 | signed_addend = addend; | |
3871 | } | |
cb1afa5c | 3872 | |
dfc5f959 NC |
3873 | if (r_type == R_ARM_THM_XPC22) |
3874 | { | |
3875 | /* Check for Thumb to Thumb call. */ | |
3876 | /* FIXME: Should we translate the instruction into a BL | |
3877 | instruction instead ? */ | |
3878 | if (sym_flags == STT_ARM_TFUNC) | |
d003868e AM |
3879 | (*_bfd_error_handler) |
3880 | (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), | |
3881 | input_bfd, | |
3882 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
3883 | } |
3884 | else | |
252b5132 | 3885 | { |
dfc5f959 NC |
3886 | /* If it is not a call to Thumb, assume call to Arm. |
3887 | If it is a call relative to a section name, then it is not a | |
b7693d02 DJ |
3888 | function call at all, but rather a long jump. Calls through |
3889 | the PLT do not require stubs. */ | |
3890 | if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION | |
3891 | && (h == NULL || splt == NULL | |
3892 | || h->plt.offset == (bfd_vma) -1)) | |
dfc5f959 | 3893 | { |
39b41c9c PB |
3894 | if (globals->use_blx) |
3895 | { | |
3896 | /* Convert BL to BLX. */ | |
3897 | lower_insn = (lower_insn & ~0x1000) | 0x0800; | |
3898 | } | |
3899 | else if (elf32_thumb_to_arm_stub | |
dfc5f959 NC |
3900 | (info, sym_name, input_bfd, output_bfd, input_section, |
3901 | hit_data, sym_sec, rel->r_offset, signed_addend, value)) | |
3902 | return bfd_reloc_ok; | |
3903 | else | |
3904 | return bfd_reloc_dangerous; | |
3905 | } | |
39b41c9c PB |
3906 | else if (sym_flags == STT_ARM_TFUNC && globals->use_blx) |
3907 | { | |
3908 | /* Make sure this is a BL. */ | |
3909 | lower_insn |= 0x1800; | |
3910 | } | |
252b5132 | 3911 | } |
f21f3fe0 | 3912 | |
b7693d02 DJ |
3913 | /* Handle calls via the PLT. */ |
3914 | if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) | |
3915 | { | |
3916 | value = (splt->output_section->vma | |
3917 | + splt->output_offset | |
3918 | + h->plt.offset); | |
33bfe774 JB |
3919 | if (globals->use_blx) |
3920 | { | |
3921 | /* If the Thumb BLX instruction is available, convert the | |
3922 | BL to a BLX instruction to call the ARM-mode PLT entry. */ | |
39b41c9c | 3923 | lower_insn = (lower_insn & ~0x1000) | 0x0800; |
33bfe774 JB |
3924 | } |
3925 | else | |
3926 | /* Target the Thumb stub before the ARM PLT entry. */ | |
3927 | value -= PLT_THUMB_STUB_SIZE; | |
0945cdfd | 3928 | *unresolved_reloc_p = FALSE; |
b7693d02 DJ |
3929 | } |
3930 | ||
ba96a88f | 3931 | relocation = value + signed_addend; |
f21f3fe0 | 3932 | |
252b5132 | 3933 | relocation -= (input_section->output_section->vma |
ba96a88f NC |
3934 | + input_section->output_offset |
3935 | + rel->r_offset); | |
9a5aca8c | 3936 | |
252b5132 RH |
3937 | check = relocation >> howto->rightshift; |
3938 | ||
3939 | /* If this is a signed value, the rightshift just dropped | |
3940 | leading 1 bits (assuming twos complement). */ | |
3941 | if ((bfd_signed_vma) relocation >= 0) | |
3942 | signed_check = check; | |
3943 | else | |
3944 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
3945 | ||
252b5132 | 3946 | /* Assumes two's complement. */ |
ba96a88f | 3947 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
b34976b6 | 3948 | overflow = TRUE; |
252b5132 | 3949 | |
39b41c9c | 3950 | if ((lower_insn & 0x1800) == 0x0800) |
c62e1cc3 NC |
3951 | /* For a BLX instruction, make sure that the relocation is rounded up |
3952 | to a word boundary. This follows the semantics of the instruction | |
3953 | which specifies that bit 1 of the target address will come from bit | |
3954 | 1 of the base address. */ | |
3955 | relocation = (relocation + 2) & ~ 3; | |
cb1afa5c | 3956 | |
c62e1cc3 NC |
3957 | /* Put RELOCATION back into the insn. */ |
3958 | upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff); | |
3959 | lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff); | |
3960 | ||
252b5132 RH |
3961 | /* Put the relocated value back in the object file: */ |
3962 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
3963 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
3964 | ||
3965 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
3966 | } | |
3967 | break; | |
3968 | ||
c19d1205 ZW |
3969 | case R_ARM_THM_JUMP24: |
3970 | /* Thumb32 unconditional branch instruction. */ | |
3971 | { | |
3972 | bfd_vma relocation; | |
3973 | bfd_boolean overflow = FALSE; | |
3974 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3975 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
3976 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
3977 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
3978 | bfd_vma check; | |
3979 | bfd_signed_vma signed_check; | |
3980 | ||
3981 | /* Need to refetch the addend, reconstruct the top three bits, and glue the | |
3982 | two pieces together. */ | |
3983 | if (globals->use_rel) | |
3984 | { | |
3985 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
3986 | bfd_vma hi = (upper_insn & 0x03ff); | |
3987 | bfd_vma I1 = (lower_insn & 0x2000) >> 13; | |
3988 | bfd_vma I2 = (lower_insn & 0x0800) >> 11; | |
3989 | bfd_vma lo = (lower_insn & 0x07ff); | |
3990 | ||
3991 | I1 = !(I1 ^ S); | |
3992 | I2 = !(I2 ^ S); | |
3993 | S = !S; | |
3994 | ||
3995 | signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1); | |
3996 | signed_addend -= (1 << 24); /* Sign extend. */ | |
3997 | } | |
3998 | ||
3999 | /* ??? Should handle interworking? GCC might someday try to | |
4000 | use this for tail calls. */ | |
4001 | ||
4002 | relocation = value + signed_addend; | |
4003 | relocation -= (input_section->output_section->vma | |
4004 | + input_section->output_offset | |
4005 | + rel->r_offset); | |
4006 | ||
4007 | check = relocation >> howto->rightshift; | |
4008 | ||
4009 | /* If this is a signed value, the rightshift just dropped | |
4010 | leading 1 bits (assuming twos complement). */ | |
4011 | if ((bfd_signed_vma) relocation >= 0) | |
4012 | signed_check = check; | |
4013 | else | |
4014 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
4015 | ||
4016 | /* Assumes two's complement. */ | |
4017 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
4018 | overflow = TRUE; | |
4019 | ||
4020 | /* Put RELOCATION back into the insn. */ | |
4021 | { | |
4022 | bfd_vma S = (relocation & 0x01000000) >> 24; | |
4023 | bfd_vma I1 = (relocation & 0x00800000) >> 23; | |
4024 | bfd_vma I2 = (relocation & 0x00400000) >> 22; | |
4025 | bfd_vma hi = (relocation & 0x003ff000) >> 12; | |
4026 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
4027 | ||
4028 | I1 = !(I1 ^ S); | |
4029 | I2 = !(I2 ^ S); | |
4030 | ||
4031 | upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi; | |
4032 | lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo; | |
4033 | } | |
4034 | ||
4035 | /* Put the relocated value back in the object file: */ | |
4036 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
4037 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
4038 | ||
4039 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
4040 | } | |
4041 | ||
4042 | case R_ARM_THM_JUMP19: | |
4043 | /* Thumb32 conditional branch instruction. */ | |
4044 | { | |
4045 | bfd_vma relocation; | |
4046 | bfd_boolean overflow = FALSE; | |
4047 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
4048 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
4049 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
4050 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
4051 | bfd_vma check; | |
4052 | bfd_signed_vma signed_check; | |
4053 | ||
4054 | /* Need to refetch the addend, reconstruct the top three bits, | |
4055 | and squish the two 11 bit pieces together. */ | |
4056 | if (globals->use_rel) | |
4057 | { | |
4058 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
4059 | bfd_vma upper = (upper_insn & 0x001f); | |
4060 | bfd_vma J1 = (lower_insn & 0x2000) >> 13; | |
4061 | bfd_vma J2 = (lower_insn & 0x0800) >> 11; | |
4062 | bfd_vma lower = (lower_insn & 0x07ff); | |
4063 | ||
4064 | upper |= J2 << 6; | |
4065 | upper |= J1 << 7; | |
4066 | upper |= ~S << 8; | |
4067 | upper -= 0x0100; /* Sign extend. */ | |
4068 | ||
4069 | addend = (upper << 12) | (lower << 1); | |
4070 | signed_addend = addend; | |
4071 | } | |
4072 | ||
4073 | /* ??? Should handle interworking? GCC might someday try to | |
4074 | use this for tail calls. */ | |
4075 | ||
4076 | relocation = value + signed_addend; | |
4077 | relocation -= (input_section->output_section->vma | |
4078 | + input_section->output_offset | |
4079 | + rel->r_offset); | |
4080 | ||
4081 | check = relocation >> howto->rightshift; | |
4082 | ||
4083 | /* If this is a signed value, the rightshift just dropped | |
4084 | leading 1 bits (assuming twos complement). */ | |
4085 | if ((bfd_signed_vma) relocation >= 0) | |
4086 | signed_check = check; | |
4087 | else | |
4088 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
4089 | ||
4090 | /* Assumes two's complement. */ | |
4091 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
4092 | overflow = TRUE; | |
4093 | ||
4094 | /* Put RELOCATION back into the insn. */ | |
4095 | { | |
4096 | bfd_vma S = (relocation & 0x00100000) >> 20; | |
4097 | bfd_vma J2 = (relocation & 0x00080000) >> 19; | |
4098 | bfd_vma J1 = (relocation & 0x00040000) >> 18; | |
4099 | bfd_vma hi = (relocation & 0x0003f000) >> 12; | |
4100 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
4101 | ||
4102 | upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi; | |
4103 | lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo; | |
4104 | } | |
4105 | ||
4106 | /* Put the relocated value back in the object file: */ | |
4107 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
4108 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
4109 | ||
4110 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
4111 | } | |
4112 | ||
4113 | case R_ARM_THM_JUMP11: | |
4114 | case R_ARM_THM_JUMP8: | |
4115 | case R_ARM_THM_JUMP6: | |
51c5503b NC |
4116 | /* Thumb B (branch) instruction). */ |
4117 | { | |
6cf9e9fe | 4118 | bfd_signed_vma relocation; |
51c5503b NC |
4119 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; |
4120 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
51c5503b NC |
4121 | bfd_signed_vma signed_check; |
4122 | ||
c19d1205 ZW |
4123 | /* CZB cannot jump backward. */ |
4124 | if (r_type == R_ARM_THM_JUMP6) | |
4125 | reloc_signed_min = 0; | |
4126 | ||
4e7fd91e | 4127 | if (globals->use_rel) |
6cf9e9fe | 4128 | { |
4e7fd91e PB |
4129 | /* Need to refetch addend. */ |
4130 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
4131 | if (addend & ((howto->src_mask + 1) >> 1)) | |
4132 | { | |
4133 | signed_addend = -1; | |
4134 | signed_addend &= ~ howto->src_mask; | |
4135 | signed_addend |= addend; | |
4136 | } | |
4137 | else | |
4138 | signed_addend = addend; | |
4139 | /* The value in the insn has been right shifted. We need to | |
4140 | undo this, so that we can perform the address calculation | |
4141 | in terms of bytes. */ | |
4142 | signed_addend <<= howto->rightshift; | |
6cf9e9fe | 4143 | } |
6cf9e9fe | 4144 | relocation = value + signed_addend; |
51c5503b NC |
4145 | |
4146 | relocation -= (input_section->output_section->vma | |
4147 | + input_section->output_offset | |
4148 | + rel->r_offset); | |
4149 | ||
6cf9e9fe NC |
4150 | relocation >>= howto->rightshift; |
4151 | signed_check = relocation; | |
c19d1205 ZW |
4152 | |
4153 | if (r_type == R_ARM_THM_JUMP6) | |
4154 | relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3); | |
4155 | else | |
4156 | relocation &= howto->dst_mask; | |
51c5503b | 4157 | relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); |
cedb70c5 | 4158 | |
51c5503b NC |
4159 | bfd_put_16 (input_bfd, relocation, hit_data); |
4160 | ||
4161 | /* Assumes two's complement. */ | |
4162 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
4163 | return bfd_reloc_overflow; | |
4164 | ||
4165 | return bfd_reloc_ok; | |
4166 | } | |
cedb70c5 | 4167 | |
8375c36b PB |
4168 | case R_ARM_ALU_PCREL7_0: |
4169 | case R_ARM_ALU_PCREL15_8: | |
4170 | case R_ARM_ALU_PCREL23_15: | |
4171 | { | |
4172 | bfd_vma insn; | |
4173 | bfd_vma relocation; | |
4174 | ||
4175 | insn = bfd_get_32 (input_bfd, hit_data); | |
4e7fd91e PB |
4176 | if (globals->use_rel) |
4177 | { | |
4178 | /* Extract the addend. */ | |
4179 | addend = (insn & 0xff) << ((insn & 0xf00) >> 7); | |
4180 | signed_addend = addend; | |
4181 | } | |
8375c36b PB |
4182 | relocation = value + signed_addend; |
4183 | ||
4184 | relocation -= (input_section->output_section->vma | |
4185 | + input_section->output_offset | |
4186 | + rel->r_offset); | |
4187 | insn = (insn & ~0xfff) | |
4188 | | ((howto->bitpos << 7) & 0xf00) | |
4189 | | ((relocation >> howto->bitpos) & 0xff); | |
4190 | bfd_put_32 (input_bfd, value, hit_data); | |
4191 | } | |
4192 | return bfd_reloc_ok; | |
4193 | ||
252b5132 RH |
4194 | case R_ARM_GNU_VTINHERIT: |
4195 | case R_ARM_GNU_VTENTRY: | |
4196 | return bfd_reloc_ok; | |
4197 | ||
c19d1205 | 4198 | case R_ARM_GOTOFF32: |
252b5132 RH |
4199 | /* Relocation is relative to the start of the |
4200 | global offset table. */ | |
4201 | ||
4202 | BFD_ASSERT (sgot != NULL); | |
4203 | if (sgot == NULL) | |
4204 | return bfd_reloc_notsupported; | |
9a5aca8c | 4205 | |
cedb70c5 | 4206 | /* If we are addressing a Thumb function, we need to adjust the |
ee29b9fb RE |
4207 | address by one, so that attempts to call the function pointer will |
4208 | correctly interpret it as Thumb code. */ | |
4209 | if (sym_flags == STT_ARM_TFUNC) | |
4210 | value += 1; | |
4211 | ||
252b5132 RH |
4212 | /* Note that sgot->output_offset is not involved in this |
4213 | calculation. We always want the start of .got. If we | |
4214 | define _GLOBAL_OFFSET_TABLE in a different way, as is | |
4215 | permitted by the ABI, we might have to change this | |
9b485d32 | 4216 | calculation. */ |
252b5132 | 4217 | value -= sgot->output_section->vma; |
f21f3fe0 | 4218 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 4219 | contents, rel->r_offset, value, |
00a97672 | 4220 | rel->r_addend); |
252b5132 RH |
4221 | |
4222 | case R_ARM_GOTPC: | |
a7c10850 | 4223 | /* Use global offset table as symbol value. */ |
252b5132 | 4224 | BFD_ASSERT (sgot != NULL); |
f21f3fe0 | 4225 | |
252b5132 RH |
4226 | if (sgot == NULL) |
4227 | return bfd_reloc_notsupported; | |
4228 | ||
0945cdfd | 4229 | *unresolved_reloc_p = FALSE; |
252b5132 | 4230 | value = sgot->output_section->vma; |
f21f3fe0 | 4231 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 4232 | contents, rel->r_offset, value, |
00a97672 | 4233 | rel->r_addend); |
f21f3fe0 | 4234 | |
252b5132 | 4235 | case R_ARM_GOT32: |
eb043451 | 4236 | case R_ARM_GOT_PREL: |
252b5132 | 4237 | /* Relocation is to the entry for this symbol in the |
9b485d32 | 4238 | global offset table. */ |
252b5132 RH |
4239 | if (sgot == NULL) |
4240 | return bfd_reloc_notsupported; | |
f21f3fe0 | 4241 | |
252b5132 RH |
4242 | if (h != NULL) |
4243 | { | |
4244 | bfd_vma off; | |
5e681ec4 | 4245 | bfd_boolean dyn; |
f21f3fe0 | 4246 | |
252b5132 RH |
4247 | off = h->got.offset; |
4248 | BFD_ASSERT (off != (bfd_vma) -1); | |
5e681ec4 | 4249 | dyn = globals->root.dynamic_sections_created; |
f21f3fe0 | 4250 | |
5e681ec4 | 4251 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
50d6c878 | 4252 | || (info->shared |
5e681ec4 PB |
4253 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
4254 | || (ELF_ST_VISIBILITY (h->other) | |
4255 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
4256 | { |
4257 | /* This is actually a static link, or it is a -Bsymbolic link | |
4258 | and the symbol is defined locally. We must initialize this | |
4259 | entry in the global offset table. Since the offset must | |
4260 | always be a multiple of 4, we use the least significant bit | |
4261 | to record whether we have initialized it already. | |
f21f3fe0 | 4262 | |
00a97672 | 4263 | When doing a dynamic link, we create a .rel(a).got relocation |
f21f3fe0 | 4264 | entry to initialize the value. This is done in the |
9b485d32 | 4265 | finish_dynamic_symbol routine. */ |
252b5132 RH |
4266 | if ((off & 1) != 0) |
4267 | off &= ~1; | |
4268 | else | |
4269 | { | |
ee29b9fb RE |
4270 | /* If we are addressing a Thumb function, we need to |
4271 | adjust the address by one, so that attempts to | |
4272 | call the function pointer will correctly | |
4273 | interpret it as Thumb code. */ | |
4274 | if (sym_flags == STT_ARM_TFUNC) | |
4275 | value |= 1; | |
4276 | ||
252b5132 RH |
4277 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
4278 | h->got.offset |= 1; | |
4279 | } | |
4280 | } | |
0945cdfd DJ |
4281 | else |
4282 | *unresolved_reloc_p = FALSE; | |
f21f3fe0 | 4283 | |
252b5132 RH |
4284 | value = sgot->output_offset + off; |
4285 | } | |
4286 | else | |
4287 | { | |
4288 | bfd_vma off; | |
f21f3fe0 | 4289 | |
252b5132 RH |
4290 | BFD_ASSERT (local_got_offsets != NULL && |
4291 | local_got_offsets[r_symndx] != (bfd_vma) -1); | |
f21f3fe0 | 4292 | |
252b5132 | 4293 | off = local_got_offsets[r_symndx]; |
f21f3fe0 | 4294 | |
252b5132 RH |
4295 | /* The offset must always be a multiple of 4. We use the |
4296 | least significant bit to record whether we have already | |
9b485d32 | 4297 | generated the necessary reloc. */ |
252b5132 RH |
4298 | if ((off & 1) != 0) |
4299 | off &= ~1; | |
4300 | else | |
4301 | { | |
b7693d02 DJ |
4302 | /* If we are addressing a Thumb function, we need to |
4303 | adjust the address by one, so that attempts to | |
4304 | call the function pointer will correctly | |
4305 | interpret it as Thumb code. */ | |
4306 | if (sym_flags == STT_ARM_TFUNC) | |
4307 | value |= 1; | |
4308 | ||
00a97672 RS |
4309 | if (globals->use_rel) |
4310 | bfd_put_32 (output_bfd, value, sgot->contents + off); | |
f21f3fe0 | 4311 | |
252b5132 RH |
4312 | if (info->shared) |
4313 | { | |
4314 | asection * srelgot; | |
947216bf AM |
4315 | Elf_Internal_Rela outrel; |
4316 | bfd_byte *loc; | |
f21f3fe0 | 4317 | |
00a97672 RS |
4318 | srelgot = (bfd_get_section_by_name |
4319 | (dynobj, RELOC_SECTION (globals, ".got"))); | |
252b5132 | 4320 | BFD_ASSERT (srelgot != NULL); |
f21f3fe0 | 4321 | |
00a97672 | 4322 | outrel.r_addend = addend + value; |
252b5132 | 4323 | outrel.r_offset = (sgot->output_section->vma |
f21f3fe0 | 4324 | + sgot->output_offset |
252b5132 RH |
4325 | + off); |
4326 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
947216bf | 4327 | loc = srelgot->contents; |
00a97672 RS |
4328 | loc += srelgot->reloc_count++ * RELOC_SIZE (globals); |
4329 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
252b5132 | 4330 | } |
f21f3fe0 | 4331 | |
252b5132 RH |
4332 | local_got_offsets[r_symndx] |= 1; |
4333 | } | |
f21f3fe0 | 4334 | |
252b5132 RH |
4335 | value = sgot->output_offset + off; |
4336 | } | |
eb043451 PB |
4337 | if (r_type != R_ARM_GOT32) |
4338 | value += sgot->output_section->vma; | |
9a5aca8c | 4339 | |
f21f3fe0 | 4340 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 4341 | contents, rel->r_offset, value, |
00a97672 | 4342 | rel->r_addend); |
f21f3fe0 | 4343 | |
ba93b8ac DJ |
4344 | case R_ARM_TLS_LDO32: |
4345 | value = value - dtpoff_base (info); | |
4346 | ||
4347 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
4348 | contents, rel->r_offset, value, |
4349 | rel->r_addend); | |
ba93b8ac DJ |
4350 | |
4351 | case R_ARM_TLS_LDM32: | |
4352 | { | |
4353 | bfd_vma off; | |
4354 | ||
4355 | if (globals->sgot == NULL) | |
4356 | abort (); | |
4357 | ||
4358 | off = globals->tls_ldm_got.offset; | |
4359 | ||
4360 | if ((off & 1) != 0) | |
4361 | off &= ~1; | |
4362 | else | |
4363 | { | |
4364 | /* If we don't know the module number, create a relocation | |
4365 | for it. */ | |
4366 | if (info->shared) | |
4367 | { | |
4368 | Elf_Internal_Rela outrel; | |
4369 | bfd_byte *loc; | |
4370 | ||
4371 | if (globals->srelgot == NULL) | |
4372 | abort (); | |
4373 | ||
00a97672 | 4374 | outrel.r_addend = 0; |
ba93b8ac DJ |
4375 | outrel.r_offset = (globals->sgot->output_section->vma |
4376 | + globals->sgot->output_offset + off); | |
4377 | outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32); | |
4378 | ||
00a97672 RS |
4379 | if (globals->use_rel) |
4380 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4381 | globals->sgot->contents + off); | |
ba93b8ac DJ |
4382 | |
4383 | loc = globals->srelgot->contents; | |
00a97672 RS |
4384 | loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals); |
4385 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac DJ |
4386 | } |
4387 | else | |
4388 | bfd_put_32 (output_bfd, 1, globals->sgot->contents + off); | |
4389 | ||
4390 | globals->tls_ldm_got.offset |= 1; | |
4391 | } | |
4392 | ||
4393 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
4394 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
4395 | ||
4396 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4397 | contents, rel->r_offset, value, | |
00a97672 | 4398 | rel->r_addend); |
ba93b8ac DJ |
4399 | } |
4400 | ||
4401 | case R_ARM_TLS_GD32: | |
4402 | case R_ARM_TLS_IE32: | |
4403 | { | |
4404 | bfd_vma off; | |
4405 | int indx; | |
4406 | char tls_type; | |
4407 | ||
4408 | if (globals->sgot == NULL) | |
4409 | abort (); | |
4410 | ||
4411 | indx = 0; | |
4412 | if (h != NULL) | |
4413 | { | |
4414 | bfd_boolean dyn; | |
4415 | dyn = globals->root.dynamic_sections_created; | |
4416 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
4417 | && (!info->shared | |
4418 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
4419 | { | |
4420 | *unresolved_reloc_p = FALSE; | |
4421 | indx = h->dynindx; | |
4422 | } | |
4423 | off = h->got.offset; | |
4424 | tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type; | |
4425 | } | |
4426 | else | |
4427 | { | |
4428 | if (local_got_offsets == NULL) | |
4429 | abort (); | |
4430 | off = local_got_offsets[r_symndx]; | |
4431 | tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx]; | |
4432 | } | |
4433 | ||
4434 | if (tls_type == GOT_UNKNOWN) | |
4435 | abort (); | |
4436 | ||
4437 | if ((off & 1) != 0) | |
4438 | off &= ~1; | |
4439 | else | |
4440 | { | |
4441 | bfd_boolean need_relocs = FALSE; | |
4442 | Elf_Internal_Rela outrel; | |
4443 | bfd_byte *loc = NULL; | |
4444 | int cur_off = off; | |
4445 | ||
4446 | /* The GOT entries have not been initialized yet. Do it | |
4447 | now, and emit any relocations. If both an IE GOT and a | |
4448 | GD GOT are necessary, we emit the GD first. */ | |
4449 | ||
4450 | if ((info->shared || indx != 0) | |
4451 | && (h == NULL | |
4452 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
4453 | || h->root.type != bfd_link_hash_undefweak)) | |
4454 | { | |
4455 | need_relocs = TRUE; | |
4456 | if (globals->srelgot == NULL) | |
4457 | abort (); | |
4458 | loc = globals->srelgot->contents; | |
00a97672 | 4459 | loc += globals->srelgot->reloc_count * RELOC_SIZE (globals); |
ba93b8ac DJ |
4460 | } |
4461 | ||
4462 | if (tls_type & GOT_TLS_GD) | |
4463 | { | |
4464 | if (need_relocs) | |
4465 | { | |
00a97672 | 4466 | outrel.r_addend = 0; |
ba93b8ac | 4467 | outrel.r_offset = (globals->sgot->output_section->vma |
00a97672 RS |
4468 | + globals->sgot->output_offset |
4469 | + cur_off); | |
ba93b8ac | 4470 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32); |
ba93b8ac | 4471 | |
00a97672 RS |
4472 | if (globals->use_rel) |
4473 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4474 | globals->sgot->contents + cur_off); | |
4475 | ||
4476 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 4477 | globals->srelgot->reloc_count++; |
00a97672 | 4478 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4479 | |
4480 | if (indx == 0) | |
4481 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
4482 | globals->sgot->contents + cur_off + 4); | |
4483 | else | |
4484 | { | |
00a97672 | 4485 | outrel.r_addend = 0; |
ba93b8ac DJ |
4486 | outrel.r_info = ELF32_R_INFO (indx, |
4487 | R_ARM_TLS_DTPOFF32); | |
4488 | outrel.r_offset += 4; | |
00a97672 RS |
4489 | |
4490 | if (globals->use_rel) | |
4491 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4492 | globals->sgot->contents + cur_off + 4); | |
4493 | ||
4494 | ||
4495 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 4496 | globals->srelgot->reloc_count++; |
00a97672 | 4497 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4498 | } |
4499 | } | |
4500 | else | |
4501 | { | |
4502 | /* If we are not emitting relocations for a | |
4503 | general dynamic reference, then we must be in a | |
4504 | static link or an executable link with the | |
4505 | symbol binding locally. Mark it as belonging | |
4506 | to module 1, the executable. */ | |
4507 | bfd_put_32 (output_bfd, 1, | |
4508 | globals->sgot->contents + cur_off); | |
4509 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
4510 | globals->sgot->contents + cur_off + 4); | |
4511 | } | |
4512 | ||
4513 | cur_off += 8; | |
4514 | } | |
4515 | ||
4516 | if (tls_type & GOT_TLS_IE) | |
4517 | { | |
4518 | if (need_relocs) | |
4519 | { | |
00a97672 RS |
4520 | if (indx == 0) |
4521 | outrel.r_addend = value - dtpoff_base (info); | |
4522 | else | |
4523 | outrel.r_addend = 0; | |
ba93b8ac DJ |
4524 | outrel.r_offset = (globals->sgot->output_section->vma |
4525 | + globals->sgot->output_offset | |
4526 | + cur_off); | |
4527 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32); | |
4528 | ||
00a97672 RS |
4529 | if (globals->use_rel) |
4530 | bfd_put_32 (output_bfd, outrel.r_addend, | |
ba93b8ac DJ |
4531 | globals->sgot->contents + cur_off); |
4532 | ||
00a97672 | 4533 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); |
ba93b8ac | 4534 | globals->srelgot->reloc_count++; |
00a97672 | 4535 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4536 | } |
4537 | else | |
4538 | bfd_put_32 (output_bfd, tpoff (info, value), | |
4539 | globals->sgot->contents + cur_off); | |
4540 | cur_off += 4; | |
4541 | } | |
4542 | ||
4543 | if (h != NULL) | |
4544 | h->got.offset |= 1; | |
4545 | else | |
4546 | local_got_offsets[r_symndx] |= 1; | |
4547 | } | |
4548 | ||
4549 | if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32) | |
4550 | off += 8; | |
4551 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
4552 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
4553 | ||
4554 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4555 | contents, rel->r_offset, value, | |
00a97672 | 4556 | rel->r_addend); |
ba93b8ac DJ |
4557 | } |
4558 | ||
4559 | case R_ARM_TLS_LE32: | |
4560 | if (info->shared) | |
4561 | { | |
4562 | (*_bfd_error_handler) | |
4563 | (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"), | |
4564 | input_bfd, input_section, | |
4565 | (long) rel->r_offset, howto->name); | |
4566 | return FALSE; | |
4567 | } | |
4568 | else | |
4569 | value = tpoff (info, value); | |
4570 | ||
4571 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
4572 | contents, rel->r_offset, value, |
4573 | rel->r_addend); | |
ba93b8ac | 4574 | |
319850b4 JB |
4575 | case R_ARM_V4BX: |
4576 | if (globals->fix_v4bx) | |
4577 | { | |
4578 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4579 | ||
4580 | /* Ensure that we have a BX instruction. */ | |
4581 | BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10); | |
4582 | ||
4583 | /* Preserve Rm (lowest four bits) and the condition code | |
4584 | (highest four bits). Other bits encode MOV PC,Rm. */ | |
4585 | insn = (insn & 0xf000000f) | 0x01a0f000; | |
4586 | ||
4587 | bfd_put_32 (input_bfd, insn, hit_data); | |
4588 | } | |
4589 | return bfd_reloc_ok; | |
4590 | ||
b6895b4f PB |
4591 | case R_ARM_MOVW_ABS_NC: |
4592 | case R_ARM_MOVT_ABS: | |
4593 | case R_ARM_MOVW_PREL_NC: | |
4594 | case R_ARM_MOVT_PREL: | |
4595 | { | |
4596 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4597 | ||
4598 | if (globals->use_rel) | |
4599 | { | |
4600 | addend = ((insn >> 4) & 0xf000) | (insn & 0xfff); | |
4601 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
4602 | } | |
4603 | value += signed_addend; | |
4604 | if (sym_flags == STT_ARM_TFUNC) | |
4605 | value |= 1; | |
4606 | ||
4607 | if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL) | |
4608 | value -= (input_section->output_section->vma | |
4609 | + input_section->output_offset + rel->r_offset); | |
4610 | ||
4611 | if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL) | |
4612 | value >>= 16; | |
4613 | ||
4614 | insn &= 0xfff0f000; | |
4615 | insn |= value & 0xfff; | |
4616 | insn |= (value & 0xf000) << 4; | |
4617 | bfd_put_32 (input_bfd, insn, hit_data); | |
4618 | } | |
4619 | return bfd_reloc_ok; | |
4620 | ||
4621 | case R_ARM_THM_MOVW_ABS_NC: | |
4622 | case R_ARM_THM_MOVT_ABS: | |
4623 | case R_ARM_THM_MOVW_PREL_NC: | |
4624 | case R_ARM_THM_MOVT_PREL: | |
4625 | { | |
4626 | bfd_vma insn; | |
4627 | ||
4628 | insn = bfd_get_16 (input_bfd, hit_data) << 16; | |
4629 | insn |= bfd_get_16 (input_bfd, hit_data + 2); | |
4630 | ||
4631 | if (globals->use_rel) | |
4632 | { | |
4633 | addend = ((insn >> 4) & 0xf000) | |
4634 | | ((insn >> 15) & 0x0800) | |
4635 | | ((insn >> 4) & 0x0700) | |
4636 | | (insn & 0x00ff); | |
4637 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
4638 | } | |
4639 | value += signed_addend; | |
4640 | if (sym_flags == STT_ARM_TFUNC) | |
4641 | value |= 1; | |
4642 | ||
4643 | if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL) | |
4644 | value -= (input_section->output_section->vma | |
4645 | + input_section->output_offset + rel->r_offset); | |
4646 | ||
4647 | if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL) | |
4648 | value >>= 16; | |
4649 | ||
4650 | insn &= 0xfbf08f00; | |
4651 | insn |= (value & 0xf000) << 4; | |
4652 | insn |= (value & 0x0800) << 15; | |
4653 | insn |= (value & 0x0700) << 4; | |
4654 | insn |= (value & 0x00ff); | |
4655 | ||
4656 | bfd_put_16 (input_bfd, insn >> 16, hit_data); | |
4657 | bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); | |
4658 | } | |
4659 | return bfd_reloc_ok; | |
4660 | ||
4962c51a MS |
4661 | case R_ARM_ALU_PC_G0_NC: |
4662 | case R_ARM_ALU_PC_G1_NC: | |
4663 | case R_ARM_ALU_PC_G0: | |
4664 | case R_ARM_ALU_PC_G1: | |
4665 | case R_ARM_ALU_PC_G2: | |
4666 | case R_ARM_ALU_SB_G0_NC: | |
4667 | case R_ARM_ALU_SB_G1_NC: | |
4668 | case R_ARM_ALU_SB_G0: | |
4669 | case R_ARM_ALU_SB_G1: | |
4670 | case R_ARM_ALU_SB_G2: | |
4671 | { | |
4672 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4673 | bfd_vma pc = input_section->output_section->vma | |
4674 | + input_section->output_offset + rel->r_offset; | |
4675 | /* sb should be the origin of the *segment* containing the symbol. | |
4676 | It is not clear how to obtain this OS-dependent value, so we | |
4677 | make an arbitrary choice of zero. */ | |
4678 | bfd_vma sb = 0; | |
4679 | bfd_vma residual; | |
4680 | bfd_vma g_n; | |
4681 | bfd_signed_vma signed_value; | |
4682 | int group = 0; | |
4683 | ||
4684 | /* Determine which group of bits to select. */ | |
4685 | switch (r_type) | |
4686 | { | |
4687 | case R_ARM_ALU_PC_G0_NC: | |
4688 | case R_ARM_ALU_PC_G0: | |
4689 | case R_ARM_ALU_SB_G0_NC: | |
4690 | case R_ARM_ALU_SB_G0: | |
4691 | group = 0; | |
4692 | break; | |
4693 | ||
4694 | case R_ARM_ALU_PC_G1_NC: | |
4695 | case R_ARM_ALU_PC_G1: | |
4696 | case R_ARM_ALU_SB_G1_NC: | |
4697 | case R_ARM_ALU_SB_G1: | |
4698 | group = 1; | |
4699 | break; | |
4700 | ||
4701 | case R_ARM_ALU_PC_G2: | |
4702 | case R_ARM_ALU_SB_G2: | |
4703 | group = 2; | |
4704 | break; | |
4705 | ||
4706 | default: | |
4707 | abort(); | |
4708 | } | |
4709 | ||
4710 | /* If REL, extract the addend from the insn. If RELA, it will | |
4711 | have already been fetched for us. */ | |
4712 | if (globals->use_rel) | |
4713 | { | |
4714 | int negative; | |
4715 | bfd_vma constant = insn & 0xff; | |
4716 | bfd_vma rotation = (insn & 0xf00) >> 8; | |
4717 | ||
4718 | if (rotation == 0) | |
4719 | signed_addend = constant; | |
4720 | else | |
4721 | { | |
4722 | /* Compensate for the fact that in the instruction, the | |
4723 | rotation is stored in multiples of 2 bits. */ | |
4724 | rotation *= 2; | |
4725 | ||
4726 | /* Rotate "constant" right by "rotation" bits. */ | |
4727 | signed_addend = (constant >> rotation) | | |
4728 | (constant << (8 * sizeof (bfd_vma) - rotation)); | |
4729 | } | |
4730 | ||
4731 | /* Determine if the instruction is an ADD or a SUB. | |
4732 | (For REL, this determines the sign of the addend.) */ | |
4733 | negative = identify_add_or_sub (insn); | |
4734 | if (negative == 0) | |
4735 | { | |
4736 | (*_bfd_error_handler) | |
4737 | (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"), | |
4738 | input_bfd, input_section, | |
4739 | (long) rel->r_offset, howto->name); | |
4740 | return bfd_reloc_overflow; | |
4741 | } | |
4742 | ||
4743 | signed_addend *= negative; | |
4744 | } | |
4745 | ||
4746 | /* Compute the value (X) to go in the place. */ | |
4747 | if (r_type == R_ARM_ALU_PC_G0_NC | |
4748 | || r_type == R_ARM_ALU_PC_G1_NC | |
4749 | || r_type == R_ARM_ALU_PC_G0 | |
4750 | || r_type == R_ARM_ALU_PC_G1 | |
4751 | || r_type == R_ARM_ALU_PC_G2) | |
4752 | /* PC relative. */ | |
4753 | signed_value = value - pc + signed_addend; | |
4754 | else | |
4755 | /* Section base relative. */ | |
4756 | signed_value = value - sb + signed_addend; | |
4757 | ||
4758 | /* If the target symbol is a Thumb function, then set the | |
4759 | Thumb bit in the address. */ | |
4760 | if (sym_flags == STT_ARM_TFUNC) | |
4761 | signed_value |= 1; | |
4762 | ||
4763 | /* Calculate the value of the relevant G_n, in encoded | |
4764 | constant-with-rotation format. */ | |
4765 | g_n = calculate_group_reloc_mask (abs (signed_value), group, | |
4766 | &residual); | |
4767 | ||
4768 | /* Check for overflow if required. */ | |
4769 | if ((r_type == R_ARM_ALU_PC_G0 | |
4770 | || r_type == R_ARM_ALU_PC_G1 | |
4771 | || r_type == R_ARM_ALU_PC_G2 | |
4772 | || r_type == R_ARM_ALU_SB_G0 | |
4773 | || r_type == R_ARM_ALU_SB_G1 | |
4774 | || r_type == R_ARM_ALU_SB_G2) && residual != 0) | |
4775 | { | |
4776 | (*_bfd_error_handler) | |
4777 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
4778 | input_bfd, input_section, | |
4779 | (long) rel->r_offset, abs (signed_value), howto->name); | |
4780 | return bfd_reloc_overflow; | |
4781 | } | |
4782 | ||
4783 | /* Mask out the value and the ADD/SUB part of the opcode; take care | |
4784 | not to destroy the S bit. */ | |
4785 | insn &= 0xff1ff000; | |
4786 | ||
4787 | /* Set the opcode according to whether the value to go in the | |
4788 | place is negative. */ | |
4789 | if (signed_value < 0) | |
4790 | insn |= 1 << 22; | |
4791 | else | |
4792 | insn |= 1 << 23; | |
4793 | ||
4794 | /* Encode the offset. */ | |
4795 | insn |= g_n; | |
4796 | ||
4797 | bfd_put_32 (input_bfd, insn, hit_data); | |
4798 | } | |
4799 | return bfd_reloc_ok; | |
4800 | ||
4801 | case R_ARM_LDR_PC_G0: | |
4802 | case R_ARM_LDR_PC_G1: | |
4803 | case R_ARM_LDR_PC_G2: | |
4804 | case R_ARM_LDR_SB_G0: | |
4805 | case R_ARM_LDR_SB_G1: | |
4806 | case R_ARM_LDR_SB_G2: | |
4807 | { | |
4808 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4809 | bfd_vma pc = input_section->output_section->vma | |
4810 | + input_section->output_offset + rel->r_offset; | |
4811 | bfd_vma sb = 0; /* See note above. */ | |
4812 | bfd_vma residual; | |
4813 | bfd_signed_vma signed_value; | |
4814 | int group = 0; | |
4815 | ||
4816 | /* Determine which groups of bits to calculate. */ | |
4817 | switch (r_type) | |
4818 | { | |
4819 | case R_ARM_LDR_PC_G0: | |
4820 | case R_ARM_LDR_SB_G0: | |
4821 | group = 0; | |
4822 | break; | |
4823 | ||
4824 | case R_ARM_LDR_PC_G1: | |
4825 | case R_ARM_LDR_SB_G1: | |
4826 | group = 1; | |
4827 | break; | |
4828 | ||
4829 | case R_ARM_LDR_PC_G2: | |
4830 | case R_ARM_LDR_SB_G2: | |
4831 | group = 2; | |
4832 | break; | |
4833 | ||
4834 | default: | |
4835 | abort(); | |
4836 | } | |
4837 | ||
4838 | /* If REL, extract the addend from the insn. If RELA, it will | |
4839 | have already been fetched for us. */ | |
4840 | if (globals->use_rel) | |
4841 | { | |
4842 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
4843 | signed_addend = negative * (insn & 0xfff); | |
4844 | } | |
4845 | ||
4846 | /* Compute the value (X) to go in the place. */ | |
4847 | if (r_type == R_ARM_LDR_PC_G0 | |
4848 | || r_type == R_ARM_LDR_PC_G1 | |
4849 | || r_type == R_ARM_LDR_PC_G2) | |
4850 | /* PC relative. */ | |
4851 | signed_value = value - pc + signed_addend; | |
4852 | else | |
4853 | /* Section base relative. */ | |
4854 | signed_value = value - sb + signed_addend; | |
4855 | ||
4856 | /* Calculate the value of the relevant G_{n-1} to obtain | |
4857 | the residual at that stage. */ | |
4858 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
4859 | ||
4860 | /* Check for overflow. */ | |
4861 | if (residual >= 0x1000) | |
4862 | { | |
4863 | (*_bfd_error_handler) | |
4864 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
4865 | input_bfd, input_section, | |
4866 | (long) rel->r_offset, abs (signed_value), howto->name); | |
4867 | return bfd_reloc_overflow; | |
4868 | } | |
4869 | ||
4870 | /* Mask out the value and U bit. */ | |
4871 | insn &= 0xff7ff000; | |
4872 | ||
4873 | /* Set the U bit if the value to go in the place is non-negative. */ | |
4874 | if (signed_value >= 0) | |
4875 | insn |= 1 << 23; | |
4876 | ||
4877 | /* Encode the offset. */ | |
4878 | insn |= residual; | |
4879 | ||
4880 | bfd_put_32 (input_bfd, insn, hit_data); | |
4881 | } | |
4882 | return bfd_reloc_ok; | |
4883 | ||
4884 | case R_ARM_LDRS_PC_G0: | |
4885 | case R_ARM_LDRS_PC_G1: | |
4886 | case R_ARM_LDRS_PC_G2: | |
4887 | case R_ARM_LDRS_SB_G0: | |
4888 | case R_ARM_LDRS_SB_G1: | |
4889 | case R_ARM_LDRS_SB_G2: | |
4890 | { | |
4891 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4892 | bfd_vma pc = input_section->output_section->vma | |
4893 | + input_section->output_offset + rel->r_offset; | |
4894 | bfd_vma sb = 0; /* See note above. */ | |
4895 | bfd_vma residual; | |
4896 | bfd_signed_vma signed_value; | |
4897 | int group = 0; | |
4898 | ||
4899 | /* Determine which groups of bits to calculate. */ | |
4900 | switch (r_type) | |
4901 | { | |
4902 | case R_ARM_LDRS_PC_G0: | |
4903 | case R_ARM_LDRS_SB_G0: | |
4904 | group = 0; | |
4905 | break; | |
4906 | ||
4907 | case R_ARM_LDRS_PC_G1: | |
4908 | case R_ARM_LDRS_SB_G1: | |
4909 | group = 1; | |
4910 | break; | |
4911 | ||
4912 | case R_ARM_LDRS_PC_G2: | |
4913 | case R_ARM_LDRS_SB_G2: | |
4914 | group = 2; | |
4915 | break; | |
4916 | ||
4917 | default: | |
4918 | abort(); | |
4919 | } | |
4920 | ||
4921 | /* If REL, extract the addend from the insn. If RELA, it will | |
4922 | have already been fetched for us. */ | |
4923 | if (globals->use_rel) | |
4924 | { | |
4925 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
4926 | signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf)); | |
4927 | } | |
4928 | ||
4929 | /* Compute the value (X) to go in the place. */ | |
4930 | if (r_type == R_ARM_LDRS_PC_G0 | |
4931 | || r_type == R_ARM_LDRS_PC_G1 | |
4932 | || r_type == R_ARM_LDRS_PC_G2) | |
4933 | /* PC relative. */ | |
4934 | signed_value = value - pc + signed_addend; | |
4935 | else | |
4936 | /* Section base relative. */ | |
4937 | signed_value = value - sb + signed_addend; | |
4938 | ||
4939 | /* Calculate the value of the relevant G_{n-1} to obtain | |
4940 | the residual at that stage. */ | |
4941 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
4942 | ||
4943 | /* Check for overflow. */ | |
4944 | if (residual >= 0x100) | |
4945 | { | |
4946 | (*_bfd_error_handler) | |
4947 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
4948 | input_bfd, input_section, | |
4949 | (long) rel->r_offset, abs (signed_value), howto->name); | |
4950 | return bfd_reloc_overflow; | |
4951 | } | |
4952 | ||
4953 | /* Mask out the value and U bit. */ | |
4954 | insn &= 0xff7ff0f0; | |
4955 | ||
4956 | /* Set the U bit if the value to go in the place is non-negative. */ | |
4957 | if (signed_value >= 0) | |
4958 | insn |= 1 << 23; | |
4959 | ||
4960 | /* Encode the offset. */ | |
4961 | insn |= ((residual & 0xf0) << 4) | (residual & 0xf); | |
4962 | ||
4963 | bfd_put_32 (input_bfd, insn, hit_data); | |
4964 | } | |
4965 | return bfd_reloc_ok; | |
4966 | ||
4967 | case R_ARM_LDC_PC_G0: | |
4968 | case R_ARM_LDC_PC_G1: | |
4969 | case R_ARM_LDC_PC_G2: | |
4970 | case R_ARM_LDC_SB_G0: | |
4971 | case R_ARM_LDC_SB_G1: | |
4972 | case R_ARM_LDC_SB_G2: | |
4973 | { | |
4974 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4975 | bfd_vma pc = input_section->output_section->vma | |
4976 | + input_section->output_offset + rel->r_offset; | |
4977 | bfd_vma sb = 0; /* See note above. */ | |
4978 | bfd_vma residual; | |
4979 | bfd_signed_vma signed_value; | |
4980 | int group = 0; | |
4981 | ||
4982 | /* Determine which groups of bits to calculate. */ | |
4983 | switch (r_type) | |
4984 | { | |
4985 | case R_ARM_LDC_PC_G0: | |
4986 | case R_ARM_LDC_SB_G0: | |
4987 | group = 0; | |
4988 | break; | |
4989 | ||
4990 | case R_ARM_LDC_PC_G1: | |
4991 | case R_ARM_LDC_SB_G1: | |
4992 | group = 1; | |
4993 | break; | |
4994 | ||
4995 | case R_ARM_LDC_PC_G2: | |
4996 | case R_ARM_LDC_SB_G2: | |
4997 | group = 2; | |
4998 | break; | |
4999 | ||
5000 | default: | |
5001 | abort(); | |
5002 | } | |
5003 | ||
5004 | /* If REL, extract the addend from the insn. If RELA, it will | |
5005 | have already been fetched for us. */ | |
5006 | if (globals->use_rel) | |
5007 | { | |
5008 | int negative = (insn & (1 << 23)) ? 1 : -1; | |
5009 | signed_addend = negative * ((insn & 0xff) << 2); | |
5010 | } | |
5011 | ||
5012 | /* Compute the value (X) to go in the place. */ | |
5013 | if (r_type == R_ARM_LDC_PC_G0 | |
5014 | || r_type == R_ARM_LDC_PC_G1 | |
5015 | || r_type == R_ARM_LDC_PC_G2) | |
5016 | /* PC relative. */ | |
5017 | signed_value = value - pc + signed_addend; | |
5018 | else | |
5019 | /* Section base relative. */ | |
5020 | signed_value = value - sb + signed_addend; | |
5021 | ||
5022 | /* Calculate the value of the relevant G_{n-1} to obtain | |
5023 | the residual at that stage. */ | |
5024 | calculate_group_reloc_mask (abs (signed_value), group - 1, &residual); | |
5025 | ||
5026 | /* Check for overflow. (The absolute value to go in the place must be | |
5027 | divisible by four and, after having been divided by four, must | |
5028 | fit in eight bits.) */ | |
5029 | if ((residual & 0x3) != 0 || residual >= 0x400) | |
5030 | { | |
5031 | (*_bfd_error_handler) | |
5032 | (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), | |
5033 | input_bfd, input_section, | |
5034 | (long) rel->r_offset, abs (signed_value), howto->name); | |
5035 | return bfd_reloc_overflow; | |
5036 | } | |
5037 | ||
5038 | /* Mask out the value and U bit. */ | |
5039 | insn &= 0xff7fff00; | |
5040 | ||
5041 | /* Set the U bit if the value to go in the place is non-negative. */ | |
5042 | if (signed_value >= 0) | |
5043 | insn |= 1 << 23; | |
5044 | ||
5045 | /* Encode the offset. */ | |
5046 | insn |= residual >> 2; | |
5047 | ||
5048 | bfd_put_32 (input_bfd, insn, hit_data); | |
5049 | } | |
5050 | return bfd_reloc_ok; | |
5051 | ||
252b5132 RH |
5052 | default: |
5053 | return bfd_reloc_notsupported; | |
5054 | } | |
5055 | } | |
5056 | ||
ee065d83 PB |
5057 | |
5058 | static int | |
5059 | uleb128_size (unsigned int i) | |
5060 | { | |
5061 | int size; | |
5062 | size = 1; | |
5063 | while (i >= 0x80) | |
5064 | { | |
5065 | i >>= 7; | |
5066 | size++; | |
5067 | } | |
5068 | return size; | |
5069 | } | |
5070 | ||
5071 | /* Return TRUE if the attribute has the default value (0/""). */ | |
5072 | static bfd_boolean | |
5073 | is_default_attr (aeabi_attribute *attr) | |
5074 | { | |
5075 | if ((attr->type & 1) && attr->i != 0) | |
5076 | return FALSE; | |
5077 | if ((attr->type & 2) && attr->s && *attr->s) | |
5078 | return FALSE; | |
5079 | ||
5080 | return TRUE; | |
5081 | } | |
5082 | ||
5083 | /* Return the size of a single attribute. */ | |
5084 | static bfd_vma | |
5085 | eabi_attr_size(int tag, aeabi_attribute *attr) | |
5086 | { | |
5087 | bfd_vma size; | |
5088 | ||
5089 | if (is_default_attr (attr)) | |
5090 | return 0; | |
5091 | ||
5092 | size = uleb128_size (tag); | |
5093 | if (attr->type & 1) | |
5094 | size += uleb128_size (attr->i); | |
5095 | if (attr->type & 2) | |
5096 | size += strlen ((char *)attr->s) + 1; | |
5097 | return size; | |
5098 | } | |
5099 | ||
5100 | /* Returns the size of the eabi object attributess section. */ | |
5101 | bfd_vma | |
5102 | elf32_arm_eabi_attr_size (bfd *abfd) | |
5103 | { | |
5104 | bfd_vma size; | |
5105 | aeabi_attribute *attr; | |
5106 | aeabi_attribute_list *list; | |
5107 | int i; | |
5108 | ||
5109 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
5110 | size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */ | |
5111 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5112 | size += eabi_attr_size (i, &attr[i]); | |
5113 | ||
5114 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5115 | list; | |
5116 | list = list->next) | |
5117 | size += eabi_attr_size (list->tag, &list->attr); | |
5118 | ||
5119 | return size; | |
5120 | } | |
5121 | ||
5122 | static bfd_byte * | |
5123 | write_uleb128 (bfd_byte *p, unsigned int val) | |
5124 | { | |
5125 | bfd_byte c; | |
5126 | do | |
5127 | { | |
5128 | c = val & 0x7f; | |
5129 | val >>= 7; | |
5130 | if (val) | |
5131 | c |= 0x80; | |
5132 | *(p++) = c; | |
5133 | } | |
5134 | while (val); | |
5135 | return p; | |
5136 | } | |
5137 | ||
5138 | /* Write attribute ATTR to butter P, and return a pointer to the following | |
5139 | byte. */ | |
5140 | static bfd_byte * | |
5141 | write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr) | |
5142 | { | |
5143 | /* Suppress default entries. */ | |
5144 | if (is_default_attr(attr)) | |
5145 | return p; | |
5146 | ||
5147 | p = write_uleb128 (p, tag); | |
5148 | if (attr->type & 1) | |
5149 | p = write_uleb128 (p, attr->i); | |
5150 | if (attr->type & 2) | |
5151 | { | |
5152 | int len; | |
5153 | ||
5154 | len = strlen (attr->s) + 1; | |
5155 | memcpy (p, attr->s, len); | |
5156 | p += len; | |
5157 | } | |
5158 | ||
5159 | return p; | |
5160 | } | |
5161 | ||
5162 | /* Write the contents of the eabi attributes section to p. */ | |
5163 | void | |
5164 | elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size) | |
5165 | { | |
5166 | bfd_byte *p; | |
5167 | aeabi_attribute *attr; | |
5168 | aeabi_attribute_list *list; | |
5169 | int i; | |
5170 | ||
5171 | p = contents; | |
5172 | *(p++) = 'A'; | |
5173 | bfd_put_32 (abfd, size - 1, p); | |
5174 | p += 4; | |
5175 | memcpy (p, "aeabi", 6); | |
5176 | p += 6; | |
5177 | *(p++) = Tag_File; | |
5178 | bfd_put_32 (abfd, size - 11, p); | |
5179 | p += 4; | |
5180 | ||
5181 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
5182 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5183 | p = write_eabi_attribute (p, i, &attr[i]); | |
5184 | ||
5185 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5186 | list; | |
5187 | list = list->next) | |
5188 | p = write_eabi_attribute (p, list->tag, &list->attr); | |
5189 | } | |
5190 | ||
5191 | /* Override final_link to handle EABI object attribute sections. */ | |
5192 | ||
5193 | static bfd_boolean | |
5194 | elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info) | |
5195 | { | |
5196 | asection *o; | |
5197 | struct bfd_link_order *p; | |
5198 | asection *attr_section = NULL; | |
5199 | bfd_byte *contents; | |
5200 | bfd_vma size = 0; | |
5201 | ||
5202 | /* elf32_arm_merge_private_bfd_data will already have merged the | |
5203 | object attributes. Remove the input sections from the link, and set | |
5204 | the contents of the output secton. */ | |
5205 | for (o = abfd->sections; o != NULL; o = o->next) | |
5206 | { | |
5207 | if (strcmp (o->name, ".ARM.attributes") == 0) | |
5208 | { | |
5209 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
5210 | { | |
5211 | asection *input_section; | |
5212 | ||
5213 | if (p->type != bfd_indirect_link_order) | |
5214 | continue; | |
5215 | input_section = p->u.indirect.section; | |
5216 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
5217 | elf_link_input_bfd ignores this section. */ | |
5218 | input_section->flags &= ~SEC_HAS_CONTENTS; | |
5219 | } | |
5220 | ||
5221 | size = elf32_arm_eabi_attr_size (abfd); | |
5222 | bfd_set_section_size (abfd, o, size); | |
5223 | attr_section = o; | |
5224 | /* Skip this section later on. */ | |
5225 | o->map_head.link_order = NULL; | |
5226 | } | |
5227 | } | |
5228 | /* Invoke the ELF linker to do all the work. */ | |
5229 | if (!bfd_elf_final_link (abfd, info)) | |
5230 | return FALSE; | |
5231 | ||
5232 | if (attr_section) | |
5233 | { | |
5234 | contents = bfd_malloc(size); | |
5235 | if (contents == NULL) | |
5236 | return FALSE; | |
5237 | elf32_arm_set_eabi_attr_contents (abfd, contents, size); | |
5238 | bfd_set_section_contents (abfd, attr_section, contents, 0, size); | |
5239 | free (contents); | |
5240 | } | |
5241 | return TRUE; | |
5242 | } | |
5243 | ||
5244 | ||
98c1d4aa NC |
5245 | /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ |
5246 | static void | |
57e8b36a NC |
5247 | arm_add_to_rel (bfd * abfd, |
5248 | bfd_byte * address, | |
5249 | reloc_howto_type * howto, | |
5250 | bfd_signed_vma increment) | |
98c1d4aa | 5251 | { |
98c1d4aa NC |
5252 | bfd_signed_vma addend; |
5253 | ||
c19d1205 | 5254 | if (howto->type == R_ARM_THM_CALL) |
98c1d4aa | 5255 | { |
9a5aca8c AM |
5256 | int upper_insn, lower_insn; |
5257 | int upper, lower; | |
98c1d4aa | 5258 | |
9a5aca8c AM |
5259 | upper_insn = bfd_get_16 (abfd, address); |
5260 | lower_insn = bfd_get_16 (abfd, address + 2); | |
5261 | upper = upper_insn & 0x7ff; | |
5262 | lower = lower_insn & 0x7ff; | |
5263 | ||
5264 | addend = (upper << 12) | (lower << 1); | |
ddda4409 | 5265 | addend += increment; |
9a5aca8c | 5266 | addend >>= 1; |
98c1d4aa | 5267 | |
9a5aca8c AM |
5268 | upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); |
5269 | lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); | |
5270 | ||
dc810e39 AM |
5271 | bfd_put_16 (abfd, (bfd_vma) upper_insn, address); |
5272 | bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); | |
9a5aca8c AM |
5273 | } |
5274 | else | |
5275 | { | |
5276 | bfd_vma contents; | |
5277 | ||
5278 | contents = bfd_get_32 (abfd, address); | |
5279 | ||
5280 | /* Get the (signed) value from the instruction. */ | |
5281 | addend = contents & howto->src_mask; | |
5282 | if (addend & ((howto->src_mask + 1) >> 1)) | |
5283 | { | |
5284 | bfd_signed_vma mask; | |
5285 | ||
5286 | mask = -1; | |
5287 | mask &= ~ howto->src_mask; | |
5288 | addend |= mask; | |
5289 | } | |
5290 | ||
5291 | /* Add in the increment, (which is a byte value). */ | |
5292 | switch (howto->type) | |
5293 | { | |
5294 | default: | |
5295 | addend += increment; | |
5296 | break; | |
5297 | ||
5298 | case R_ARM_PC24: | |
c6596c5e | 5299 | case R_ARM_PLT32: |
5b5bb741 PB |
5300 | case R_ARM_CALL: |
5301 | case R_ARM_JUMP24: | |
9a5aca8c | 5302 | addend <<= howto->size; |
dc810e39 | 5303 | addend += increment; |
9a5aca8c AM |
5304 | |
5305 | /* Should we check for overflow here ? */ | |
5306 | ||
5307 | /* Drop any undesired bits. */ | |
5308 | addend >>= howto->rightshift; | |
5309 | break; | |
5310 | } | |
5311 | ||
5312 | contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
5313 | ||
5314 | bfd_put_32 (abfd, contents, address); | |
ddda4409 | 5315 | } |
98c1d4aa | 5316 | } |
252b5132 | 5317 | |
ba93b8ac DJ |
5318 | #define IS_ARM_TLS_RELOC(R_TYPE) \ |
5319 | ((R_TYPE) == R_ARM_TLS_GD32 \ | |
5320 | || (R_TYPE) == R_ARM_TLS_LDO32 \ | |
5321 | || (R_TYPE) == R_ARM_TLS_LDM32 \ | |
5322 | || (R_TYPE) == R_ARM_TLS_DTPOFF32 \ | |
5323 | || (R_TYPE) == R_ARM_TLS_DTPMOD32 \ | |
5324 | || (R_TYPE) == R_ARM_TLS_TPOFF32 \ | |
5325 | || (R_TYPE) == R_ARM_TLS_LE32 \ | |
5326 | || (R_TYPE) == R_ARM_TLS_IE32) | |
5327 | ||
252b5132 | 5328 | /* Relocate an ARM ELF section. */ |
b34976b6 | 5329 | static bfd_boolean |
57e8b36a NC |
5330 | elf32_arm_relocate_section (bfd * output_bfd, |
5331 | struct bfd_link_info * info, | |
5332 | bfd * input_bfd, | |
5333 | asection * input_section, | |
5334 | bfd_byte * contents, | |
5335 | Elf_Internal_Rela * relocs, | |
5336 | Elf_Internal_Sym * local_syms, | |
5337 | asection ** local_sections) | |
252b5132 | 5338 | { |
b34976b6 AM |
5339 | Elf_Internal_Shdr *symtab_hdr; |
5340 | struct elf_link_hash_entry **sym_hashes; | |
5341 | Elf_Internal_Rela *rel; | |
5342 | Elf_Internal_Rela *relend; | |
5343 | const char *name; | |
b32d3aa2 | 5344 | struct elf32_arm_link_hash_table * globals; |
252b5132 | 5345 | |
4e7fd91e PB |
5346 | globals = elf32_arm_hash_table (info); |
5347 | if (info->relocatable && !globals->use_rel) | |
b34976b6 | 5348 | return TRUE; |
b491616a | 5349 | |
252b5132 RH |
5350 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
5351 | sym_hashes = elf_sym_hashes (input_bfd); | |
5352 | ||
5353 | rel = relocs; | |
5354 | relend = relocs + input_section->reloc_count; | |
5355 | for (; rel < relend; rel++) | |
5356 | { | |
ba96a88f NC |
5357 | int r_type; |
5358 | reloc_howto_type * howto; | |
5359 | unsigned long r_symndx; | |
5360 | Elf_Internal_Sym * sym; | |
5361 | asection * sec; | |
252b5132 | 5362 | struct elf_link_hash_entry * h; |
ba96a88f NC |
5363 | bfd_vma relocation; |
5364 | bfd_reloc_status_type r; | |
5365 | arelent bfd_reloc; | |
ba93b8ac | 5366 | char sym_type; |
0945cdfd | 5367 | bfd_boolean unresolved_reloc = FALSE; |
f21f3fe0 | 5368 | |
252b5132 | 5369 | r_symndx = ELF32_R_SYM (rel->r_info); |
ba96a88f | 5370 | r_type = ELF32_R_TYPE (rel->r_info); |
b32d3aa2 | 5371 | r_type = arm_real_reloc_type (globals, r_type); |
252b5132 | 5372 | |
ba96a88f NC |
5373 | if ( r_type == R_ARM_GNU_VTENTRY |
5374 | || r_type == R_ARM_GNU_VTINHERIT) | |
252b5132 RH |
5375 | continue; |
5376 | ||
b32d3aa2 | 5377 | bfd_reloc.howto = elf32_arm_howto_from_type (r_type); |
ba96a88f | 5378 | howto = bfd_reloc.howto; |
252b5132 | 5379 | |
4e7fd91e | 5380 | if (info->relocatable && globals->use_rel) |
252b5132 | 5381 | { |
1049f94e | 5382 | /* This is a relocatable link. We don't have to change |
252b5132 RH |
5383 | anything, unless the reloc is against a section symbol, |
5384 | in which case we have to adjust according to where the | |
5385 | section symbol winds up in the output section. */ | |
5386 | if (r_symndx < symtab_hdr->sh_info) | |
5387 | { | |
5388 | sym = local_syms + r_symndx; | |
5389 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
5390 | { | |
5391 | sec = local_sections[r_symndx]; | |
98c1d4aa | 5392 | arm_add_to_rel (input_bfd, contents + rel->r_offset, |
dc810e39 AM |
5393 | howto, |
5394 | (bfd_signed_vma) (sec->output_offset | |
5395 | + sym->st_value)); | |
252b5132 RH |
5396 | } |
5397 | } | |
5398 | ||
5399 | continue; | |
5400 | } | |
5401 | ||
5402 | /* This is a final link. */ | |
5403 | h = NULL; | |
5404 | sym = NULL; | |
5405 | sec = NULL; | |
9b485d32 | 5406 | |
252b5132 RH |
5407 | if (r_symndx < symtab_hdr->sh_info) |
5408 | { | |
5409 | sym = local_syms + r_symndx; | |
ba93b8ac | 5410 | sym_type = ELF32_ST_TYPE (sym->st_info); |
252b5132 | 5411 | sec = local_sections[r_symndx]; |
4e7fd91e | 5412 | if (globals->use_rel) |
f8df10f4 | 5413 | { |
4e7fd91e PB |
5414 | relocation = (sec->output_section->vma |
5415 | + sec->output_offset | |
5416 | + sym->st_value); | |
5417 | if ((sec->flags & SEC_MERGE) | |
5418 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
f8df10f4 | 5419 | { |
4e7fd91e PB |
5420 | asection *msec; |
5421 | bfd_vma addend, value; | |
5422 | ||
5423 | if (howto->rightshift) | |
5424 | { | |
5425 | (*_bfd_error_handler) | |
5426 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), | |
5427 | input_bfd, input_section, | |
5428 | (long) rel->r_offset, howto->name); | |
5429 | return FALSE; | |
5430 | } | |
f8df10f4 | 5431 | |
4e7fd91e | 5432 | value = bfd_get_32 (input_bfd, contents + rel->r_offset); |
f8df10f4 | 5433 | |
4e7fd91e PB |
5434 | /* Get the (signed) value from the instruction. */ |
5435 | addend = value & howto->src_mask; | |
5436 | if (addend & ((howto->src_mask + 1) >> 1)) | |
5437 | { | |
5438 | bfd_signed_vma mask; | |
f8df10f4 | 5439 | |
4e7fd91e PB |
5440 | mask = -1; |
5441 | mask &= ~ howto->src_mask; | |
5442 | addend |= mask; | |
5443 | } | |
5444 | msec = sec; | |
5445 | addend = | |
5446 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) | |
5447 | - relocation; | |
5448 | addend += msec->output_section->vma + msec->output_offset; | |
5449 | value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
5450 | bfd_put_32 (input_bfd, value, contents + rel->r_offset); | |
f8df10f4 | 5451 | } |
f8df10f4 | 5452 | } |
4e7fd91e PB |
5453 | else |
5454 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
252b5132 RH |
5455 | } |
5456 | else | |
5457 | { | |
560e09e9 | 5458 | bfd_boolean warned; |
560e09e9 | 5459 | |
b2a8e766 AM |
5460 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
5461 | r_symndx, symtab_hdr, sym_hashes, | |
5462 | h, sec, relocation, | |
5463 | unresolved_reloc, warned); | |
ba93b8ac DJ |
5464 | |
5465 | sym_type = h->type; | |
252b5132 RH |
5466 | } |
5467 | ||
5468 | if (h != NULL) | |
5469 | name = h->root.root.string; | |
5470 | else | |
5471 | { | |
5472 | name = (bfd_elf_string_from_elf_section | |
5473 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
5474 | if (name == NULL || *name == '\0') | |
5475 | name = bfd_section_name (input_bfd, sec); | |
5476 | } | |
f21f3fe0 | 5477 | |
ba93b8ac DJ |
5478 | if (r_symndx != 0 |
5479 | && r_type != R_ARM_NONE | |
5480 | && (h == NULL | |
5481 | || h->root.type == bfd_link_hash_defined | |
5482 | || h->root.type == bfd_link_hash_defweak) | |
5483 | && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
5484 | { | |
5485 | (*_bfd_error_handler) | |
5486 | ((sym_type == STT_TLS | |
5487 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") | |
5488 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), | |
5489 | input_bfd, | |
5490 | input_section, | |
5491 | (long) rel->r_offset, | |
5492 | howto->name, | |
5493 | name); | |
5494 | } | |
5495 | ||
252b5132 RH |
5496 | r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, |
5497 | input_section, contents, rel, | |
5498 | relocation, info, sec, name, | |
5499 | (h ? ELF_ST_TYPE (h->type) : | |
0945cdfd DJ |
5500 | ELF_ST_TYPE (sym->st_info)), h, |
5501 | &unresolved_reloc); | |
5502 | ||
5503 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections | |
5504 | because such sections are not SEC_ALLOC and thus ld.so will | |
5505 | not process them. */ | |
5506 | if (unresolved_reloc | |
5507 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
5508 | && h->def_dynamic)) | |
5509 | { | |
5510 | (*_bfd_error_handler) | |
843fe662 L |
5511 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
5512 | input_bfd, | |
5513 | input_section, | |
5514 | (long) rel->r_offset, | |
5515 | howto->name, | |
5516 | h->root.root.string); | |
0945cdfd DJ |
5517 | return FALSE; |
5518 | } | |
252b5132 RH |
5519 | |
5520 | if (r != bfd_reloc_ok) | |
5521 | { | |
5522 | const char * msg = (const char *) 0; | |
5523 | ||
5524 | switch (r) | |
5525 | { | |
5526 | case bfd_reloc_overflow: | |
cf919dfd PB |
5527 | /* If the overflowing reloc was to an undefined symbol, |
5528 | we have already printed one error message and there | |
5529 | is no point complaining again. */ | |
5530 | if ((! h || | |
5531 | h->root.type != bfd_link_hash_undefined) | |
5532 | && (!((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
5533 | (info, (h ? &h->root : NULL), name, howto->name, |
5534 | (bfd_vma) 0, input_bfd, input_section, | |
5535 | rel->r_offset)))) | |
b34976b6 | 5536 | return FALSE; |
252b5132 RH |
5537 | break; |
5538 | ||
5539 | case bfd_reloc_undefined: | |
5540 | if (!((*info->callbacks->undefined_symbol) | |
5541 | (info, name, input_bfd, input_section, | |
b34976b6 AM |
5542 | rel->r_offset, TRUE))) |
5543 | return FALSE; | |
252b5132 RH |
5544 | break; |
5545 | ||
5546 | case bfd_reloc_outofrange: | |
9b485d32 | 5547 | msg = _("internal error: out of range error"); |
252b5132 RH |
5548 | goto common_error; |
5549 | ||
5550 | case bfd_reloc_notsupported: | |
9b485d32 | 5551 | msg = _("internal error: unsupported relocation error"); |
252b5132 RH |
5552 | goto common_error; |
5553 | ||
5554 | case bfd_reloc_dangerous: | |
9b485d32 | 5555 | msg = _("internal error: dangerous error"); |
252b5132 RH |
5556 | goto common_error; |
5557 | ||
5558 | default: | |
9b485d32 | 5559 | msg = _("internal error: unknown error"); |
252b5132 RH |
5560 | /* fall through */ |
5561 | ||
5562 | common_error: | |
5563 | if (!((*info->callbacks->warning) | |
5564 | (info, msg, name, input_bfd, input_section, | |
5565 | rel->r_offset))) | |
b34976b6 | 5566 | return FALSE; |
252b5132 RH |
5567 | break; |
5568 | } | |
5569 | } | |
5570 | } | |
5571 | ||
b34976b6 | 5572 | return TRUE; |
252b5132 RH |
5573 | } |
5574 | ||
ee065d83 PB |
5575 | /* Allocate/find an object attribute. */ |
5576 | static aeabi_attribute * | |
5577 | elf32_arm_new_eabi_attr (bfd *abfd, int tag) | |
5578 | { | |
5579 | aeabi_attribute *attr; | |
5580 | aeabi_attribute_list *list; | |
5581 | aeabi_attribute_list *p; | |
5582 | aeabi_attribute_list **lastp; | |
5583 | ||
5584 | ||
5585 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
5586 | { | |
5587 | /* Knwon tags are preallocated. */ | |
5588 | attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag]; | |
5589 | } | |
5590 | else | |
5591 | { | |
5592 | /* Create a new tag. */ | |
5593 | list = (aeabi_attribute_list *) | |
5594 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
5595 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
5596 | list->tag = tag; | |
5597 | /* Keep the tag list in order. */ | |
5598 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5599 | for (p = *lastp; p; p = p->next) | |
5600 | { | |
5601 | if (tag < p->tag) | |
5602 | break; | |
5603 | lastp = &p->next; | |
5604 | } | |
5605 | list->next = *lastp; | |
5606 | *lastp = list; | |
5607 | attr = &list->attr; | |
5608 | } | |
5609 | ||
5610 | return attr; | |
5611 | } | |
5612 | ||
39b41c9c PB |
5613 | int |
5614 | elf32_arm_get_eabi_attr_int (bfd *abfd, int tag) | |
5615 | { | |
5616 | aeabi_attribute_list *p; | |
5617 | ||
5618 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
5619 | { | |
5620 | /* Knwon tags are preallocated. */ | |
5621 | return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i; | |
5622 | } | |
5623 | else | |
5624 | { | |
5625 | for (p = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5626 | p; | |
5627 | p = p->next) | |
5628 | { | |
5629 | if (tag == p->tag) | |
5630 | return p->attr.i; | |
5631 | if (tag < p->tag) | |
5632 | break; | |
5633 | } | |
5634 | return 0; | |
5635 | } | |
5636 | } | |
5637 | ||
ee065d83 PB |
5638 | void |
5639 | elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i) | |
5640 | { | |
5641 | aeabi_attribute *attr; | |
5642 | ||
5643 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
5644 | attr->type = 1; | |
5645 | attr->i = i; | |
5646 | } | |
5647 | ||
5648 | static char * | |
5649 | attr_strdup (bfd *abfd, const char * s) | |
5650 | { | |
5651 | char * p; | |
5652 | int len; | |
5653 | ||
5654 | len = strlen (s) + 1; | |
5655 | p = (char *)bfd_alloc(abfd, len); | |
5656 | return memcpy (p, s, len); | |
5657 | } | |
5658 | ||
5659 | void | |
5660 | elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s) | |
5661 | { | |
5662 | aeabi_attribute *attr; | |
5663 | ||
5664 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
5665 | attr->type = 2; | |
5666 | attr->s = attr_strdup (abfd, s); | |
5667 | } | |
5668 | ||
5669 | void | |
5670 | elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s) | |
5671 | { | |
5672 | aeabi_attribute_list *list; | |
5673 | aeabi_attribute_list *p; | |
5674 | aeabi_attribute_list **lastp; | |
5675 | ||
5676 | list = (aeabi_attribute_list *) | |
5677 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
5678 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
5679 | list->tag = Tag_compatibility; | |
5680 | list->attr.type = 3; | |
5681 | list->attr.i = i; | |
5682 | list->attr.s = attr_strdup (abfd, s); | |
5683 | ||
5684 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
5685 | for (p = *lastp; p; p = p->next) | |
5686 | { | |
5687 | int cmp; | |
5688 | if (p->tag != Tag_compatibility) | |
5689 | break; | |
5690 | cmp = strcmp(s, p->attr.s); | |
5691 | if (cmp < 0 || (cmp == 0 && i < p->attr.i)) | |
5692 | break; | |
5693 | lastp = &p->next; | |
5694 | } | |
5695 | list->next = *lastp; | |
5696 | *lastp = list; | |
5697 | } | |
5698 | ||
c178919b NC |
5699 | /* Set the right machine number. */ |
5700 | ||
5701 | static bfd_boolean | |
57e8b36a | 5702 | elf32_arm_object_p (bfd *abfd) |
c178919b | 5703 | { |
5a6c6817 | 5704 | unsigned int mach; |
57e8b36a | 5705 | |
5a6c6817 | 5706 | mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); |
c178919b | 5707 | |
5a6c6817 NC |
5708 | if (mach != bfd_mach_arm_unknown) |
5709 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); | |
5710 | ||
5711 | else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) | |
5712 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); | |
e16bb312 | 5713 | |
e16bb312 | 5714 | else |
5a6c6817 | 5715 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
c178919b NC |
5716 | |
5717 | return TRUE; | |
5718 | } | |
5719 | ||
fc830a83 | 5720 | /* Function to keep ARM specific flags in the ELF header. */ |
3c9458e9 | 5721 | |
b34976b6 | 5722 | static bfd_boolean |
57e8b36a | 5723 | elf32_arm_set_private_flags (bfd *abfd, flagword flags) |
252b5132 RH |
5724 | { |
5725 | if (elf_flags_init (abfd) | |
5726 | && elf_elfheader (abfd)->e_flags != flags) | |
5727 | { | |
fc830a83 NC |
5728 | if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) |
5729 | { | |
fd2ec330 | 5730 | if (flags & EF_ARM_INTERWORK) |
d003868e AM |
5731 | (*_bfd_error_handler) |
5732 | (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), | |
5733 | abfd); | |
fc830a83 | 5734 | else |
d003868e AM |
5735 | _bfd_error_handler |
5736 | (_("Warning: Clearing the interworking flag of %B due to outside request"), | |
5737 | abfd); | |
fc830a83 | 5738 | } |
252b5132 RH |
5739 | } |
5740 | else | |
5741 | { | |
5742 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 | 5743 | elf_flags_init (abfd) = TRUE; |
252b5132 RH |
5744 | } |
5745 | ||
b34976b6 | 5746 | return TRUE; |
252b5132 RH |
5747 | } |
5748 | ||
ee065d83 PB |
5749 | /* Copy the eabi object attribute from IBFD to OBFD. */ |
5750 | static void | |
5751 | copy_eabi_attributes (bfd *ibfd, bfd *obfd) | |
5752 | { | |
5753 | aeabi_attribute *in_attr; | |
5754 | aeabi_attribute *out_attr; | |
5755 | aeabi_attribute_list *list; | |
5756 | int i; | |
5757 | ||
5758 | in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes; | |
5759 | out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
5760 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5761 | { | |
5762 | out_attr->i = in_attr->i; | |
5763 | if (in_attr->s && *in_attr->s) | |
5764 | out_attr->s = attr_strdup (obfd, in_attr->s); | |
5765 | in_attr++; | |
5766 | out_attr++; | |
5767 | } | |
5768 | ||
5769 | for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
5770 | list; | |
5771 | list = list->next) | |
5772 | { | |
5773 | in_attr = &list->attr; | |
5774 | switch (in_attr->type) | |
5775 | { | |
5776 | case 1: | |
5777 | elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i); | |
5778 | break; | |
5779 | case 2: | |
5780 | elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s); | |
5781 | break; | |
5782 | case 3: | |
5783 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
5784 | break; | |
5785 | default: | |
5786 | abort(); | |
5787 | } | |
5788 | } | |
5789 | } | |
5790 | ||
5791 | ||
fc830a83 | 5792 | /* Copy backend specific data from one object module to another. */ |
9b485d32 | 5793 | |
b34976b6 | 5794 | static bfd_boolean |
57e8b36a | 5795 | elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 RH |
5796 | { |
5797 | flagword in_flags; | |
5798 | flagword out_flags; | |
5799 | ||
fc830a83 | 5800 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
252b5132 | 5801 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
b34976b6 | 5802 | return TRUE; |
252b5132 | 5803 | |
fc830a83 | 5804 | in_flags = elf_elfheader (ibfd)->e_flags; |
252b5132 RH |
5805 | out_flags = elf_elfheader (obfd)->e_flags; |
5806 | ||
fc830a83 NC |
5807 | if (elf_flags_init (obfd) |
5808 | && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN | |
5809 | && in_flags != out_flags) | |
252b5132 | 5810 | { |
252b5132 | 5811 | /* Cannot mix APCS26 and APCS32 code. */ |
fd2ec330 | 5812 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
b34976b6 | 5813 | return FALSE; |
252b5132 RH |
5814 | |
5815 | /* Cannot mix float APCS and non-float APCS code. */ | |
fd2ec330 | 5816 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
b34976b6 | 5817 | return FALSE; |
252b5132 RH |
5818 | |
5819 | /* If the src and dest have different interworking flags | |
5820 | then turn off the interworking bit. */ | |
fd2ec330 | 5821 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
252b5132 | 5822 | { |
fd2ec330 | 5823 | if (out_flags & EF_ARM_INTERWORK) |
d003868e AM |
5824 | _bfd_error_handler |
5825 | (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), | |
5826 | obfd, ibfd); | |
252b5132 | 5827 | |
fd2ec330 | 5828 | in_flags &= ~EF_ARM_INTERWORK; |
252b5132 | 5829 | } |
1006ba19 PB |
5830 | |
5831 | /* Likewise for PIC, though don't warn for this case. */ | |
fd2ec330 PB |
5832 | if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) |
5833 | in_flags &= ~EF_ARM_PIC; | |
252b5132 RH |
5834 | } |
5835 | ||
5836 | elf_elfheader (obfd)->e_flags = in_flags; | |
b34976b6 | 5837 | elf_flags_init (obfd) = TRUE; |
252b5132 | 5838 | |
94a3258f PB |
5839 | /* Also copy the EI_OSABI field. */ |
5840 | elf_elfheader (obfd)->e_ident[EI_OSABI] = | |
5841 | elf_elfheader (ibfd)->e_ident[EI_OSABI]; | |
5842 | ||
ee065d83 PB |
5843 | /* Copy EABI object attributes. */ |
5844 | copy_eabi_attributes (ibfd, obfd); | |
5845 | ||
5846 | return TRUE; | |
5847 | } | |
5848 | ||
5849 | /* Values for Tag_ABI_PCS_R9_use. */ | |
5850 | enum | |
5851 | { | |
5852 | AEABI_R9_V6, | |
5853 | AEABI_R9_SB, | |
5854 | AEABI_R9_TLS, | |
5855 | AEABI_R9_unused | |
5856 | }; | |
5857 | ||
5858 | /* Values for Tag_ABI_PCS_RW_data. */ | |
5859 | enum | |
5860 | { | |
5861 | AEABI_PCS_RW_data_absolute, | |
5862 | AEABI_PCS_RW_data_PCrel, | |
5863 | AEABI_PCS_RW_data_SBrel, | |
5864 | AEABI_PCS_RW_data_unused | |
5865 | }; | |
5866 | ||
5867 | /* Values for Tag_ABI_enum_size. */ | |
5868 | enum | |
5869 | { | |
5870 | AEABI_enum_unused, | |
5871 | AEABI_enum_short, | |
5872 | AEABI_enum_wide, | |
5873 | AEABI_enum_forced_wide | |
5874 | }; | |
5875 | ||
5876 | /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there | |
5877 | are conflicting attributes. */ | |
5878 | static bfd_boolean | |
5879 | elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd) | |
5880 | { | |
5881 | aeabi_attribute *in_attr; | |
5882 | aeabi_attribute *out_attr; | |
5883 | aeabi_attribute_list *in_list; | |
5884 | aeabi_attribute_list *out_list; | |
5885 | /* Some tags have 0 = don't care, 1 = strong requirement, | |
5886 | 2 = weak requirement. */ | |
5887 | static const int order_312[3] = {3, 1, 2}; | |
5888 | int i; | |
5889 | ||
5890 | if (!elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i) | |
5891 | { | |
5892 | /* This is the first object. Copy the attributes. */ | |
5893 | copy_eabi_attributes (ibfd, obfd); | |
5894 | return TRUE; | |
5895 | } | |
5896 | ||
5897 | /* Use the Tag_null value to indicate the attributes have been | |
5898 | initialized. */ | |
5899 | elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i = 1; | |
5900 | ||
5901 | in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes; | |
5902 | out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
5903 | /* This needs to happen before Tag_ABI_FP_number_model is merged. */ | |
5904 | if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i) | |
5905 | { | |
5906 | /* Ignore mismatches if teh object doesn't use floating point. */ | |
5907 | if (out_attr[Tag_ABI_FP_number_model].i == 0) | |
5908 | out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i; | |
5909 | else if (in_attr[Tag_ABI_FP_number_model].i != 0) | |
5910 | { | |
5911 | _bfd_error_handler | |
5912 | (_("ERROR: %B uses VFP register arguments, %B does not"), | |
5913 | ibfd, obfd); | |
5914 | return FALSE; | |
5915 | } | |
5916 | } | |
5917 | ||
5918 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5919 | { | |
5920 | /* Merge this attribute with existing attributes. */ | |
5921 | switch (i) | |
5922 | { | |
5923 | case Tag_CPU_raw_name: | |
5924 | case Tag_CPU_name: | |
5925 | /* Use whichever has the greatest architecture requirements. */ | |
5926 | if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i) | |
5927 | out_attr[i].s = attr_strdup(obfd, in_attr[i].s); | |
5928 | break; | |
5929 | ||
5930 | case Tag_ABI_optimization_goals: | |
5931 | case Tag_ABI_FP_optimization_goals: | |
5932 | /* Use the first value seen. */ | |
5933 | break; | |
5934 | ||
5935 | case Tag_CPU_arch: | |
5936 | case Tag_ARM_ISA_use: | |
5937 | case Tag_THUMB_ISA_use: | |
5938 | case Tag_VFP_arch: | |
5939 | case Tag_WMMX_arch: | |
5940 | case Tag_NEON_arch: | |
5941 | /* ??? Do NEON and WMMX conflict? */ | |
5942 | case Tag_ABI_FP_rounding: | |
5943 | case Tag_ABI_FP_denormal: | |
5944 | case Tag_ABI_FP_exceptions: | |
5945 | case Tag_ABI_FP_user_exceptions: | |
5946 | case Tag_ABI_FP_number_model: | |
5947 | case Tag_ABI_align8_preserved: | |
5948 | case Tag_ABI_HardFP_use: | |
5949 | /* Use the largest value specified. */ | |
5950 | if (in_attr[i].i > out_attr[i].i) | |
5951 | out_attr[i].i = in_attr[i].i; | |
5952 | break; | |
5953 | ||
5954 | case Tag_CPU_arch_profile: | |
5955 | /* Warn if conflicting architecture profiles used. */ | |
5956 | if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i) | |
5957 | { | |
5958 | _bfd_error_handler | |
5959 | (_("ERROR: %B: Conflicting architecture profiles %c/%c"), | |
5960 | ibfd, in_attr[i].i, out_attr[i].i); | |
5961 | return FALSE; | |
5962 | } | |
5963 | if (in_attr[i].i) | |
5964 | out_attr[i].i = in_attr[i].i; | |
5965 | break; | |
5966 | case Tag_PCS_config: | |
5967 | if (out_attr[i].i == 0) | |
5968 | out_attr[i].i = in_attr[i].i; | |
5969 | else if (in_attr[i].i != 0 && out_attr[i].i != 0) | |
5970 | { | |
5971 | /* It's sometimes ok to mix different configs, so this is only | |
5972 | a warning. */ | |
5973 | _bfd_error_handler | |
5974 | (_("Warning: %B: Conflicting platform configuration"), ibfd); | |
5975 | } | |
5976 | break; | |
5977 | case Tag_ABI_PCS_R9_use: | |
5978 | if (out_attr[i].i != AEABI_R9_unused | |
5979 | && in_attr[i].i != AEABI_R9_unused) | |
5980 | { | |
5981 | _bfd_error_handler | |
5982 | (_("ERROR: %B: Conflicting use of R9"), ibfd); | |
5983 | return FALSE; | |
5984 | } | |
5985 | if (out_attr[i].i == AEABI_R9_unused) | |
5986 | out_attr[i].i = in_attr[i].i; | |
5987 | break; | |
5988 | case Tag_ABI_PCS_RW_data: | |
5989 | if (in_attr[i].i == AEABI_PCS_RW_data_SBrel | |
5990 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB | |
5991 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused) | |
5992 | { | |
5993 | _bfd_error_handler | |
5994 | (_("ERROR: %B: SB relative addressing conflicts with use of R9"), | |
5995 | ibfd); | |
5996 | return FALSE; | |
5997 | } | |
5998 | /* Use the smallest value specified. */ | |
5999 | if (in_attr[i].i < out_attr[i].i) | |
6000 | out_attr[i].i = in_attr[i].i; | |
6001 | break; | |
6002 | case Tag_ABI_PCS_RO_data: | |
6003 | /* Use the smallest value specified. */ | |
6004 | if (in_attr[i].i < out_attr[i].i) | |
6005 | out_attr[i].i = in_attr[i].i; | |
6006 | break; | |
6007 | case Tag_ABI_PCS_GOT_use: | |
6008 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
6009 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
6010 | out_attr[i].i = in_attr[i].i; | |
6011 | break; | |
6012 | case Tag_ABI_PCS_wchar_t: | |
6013 | if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i) | |
6014 | { | |
6015 | _bfd_error_handler | |
6016 | (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd); | |
6017 | return FALSE; | |
6018 | } | |
6019 | if (in_attr[i].i) | |
6020 | out_attr[i].i = in_attr[i].i; | |
6021 | break; | |
6022 | case Tag_ABI_align8_needed: | |
6023 | /* ??? Check against Tag_ABI_align8_preserved. */ | |
6024 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
6025 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
6026 | out_attr[i].i = in_attr[i].i; | |
6027 | break; | |
6028 | case Tag_ABI_enum_size: | |
6029 | if (in_attr[i].i != AEABI_enum_unused) | |
6030 | { | |
6031 | if (out_attr[i].i == AEABI_enum_unused | |
6032 | || out_attr[i].i == AEABI_enum_forced_wide) | |
6033 | { | |
6034 | /* The existing object is compatible with anything. | |
6035 | Use whatever requirements the new object has. */ | |
6036 | out_attr[i].i = in_attr[i].i; | |
6037 | } | |
6038 | else if (in_attr[i].i != AEABI_enum_forced_wide | |
6039 | && out_attr[i].i != in_attr[i].i) | |
6040 | { | |
6041 | _bfd_error_handler | |
6042 | (_("ERROR: %B: Conflicting enum sizes"), ibfd); | |
6043 | } | |
6044 | } | |
6045 | break; | |
6046 | case Tag_ABI_VFP_args: | |
6047 | /* Aready done. */ | |
6048 | break; | |
6049 | case Tag_ABI_WMMX_args: | |
6050 | if (in_attr[i].i != out_attr[i].i) | |
6051 | { | |
6052 | _bfd_error_handler | |
6053 | (_("ERROR: %B uses iWMMXt register arguments, %B does not"), | |
6054 | ibfd, obfd); | |
6055 | return FALSE; | |
6056 | } | |
6057 | break; | |
6058 | default: /* All known attributes should be explicitly covered. */ | |
6059 | abort (); | |
6060 | } | |
6061 | } | |
6062 | ||
6063 | in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
6064 | out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
6065 | while (in_list && in_list->tag == Tag_compatibility) | |
6066 | { | |
6067 | in_attr = &in_list->attr; | |
6068 | if (in_attr->i == 0) | |
6069 | continue; | |
6070 | if (in_attr->i == 1) | |
6071 | { | |
6072 | _bfd_error_handler | |
6073 | (_("ERROR: %B: Must be processed by '%s' toolchain"), | |
6074 | ibfd, in_attr->s); | |
6075 | return FALSE; | |
6076 | } | |
6077 | if (!out_list || out_list->tag != Tag_compatibility | |
6078 | || strcmp (in_attr->s, out_list->attr.s) != 0) | |
6079 | { | |
6080 | /* Add this compatibility tag to the output. */ | |
6081 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
6082 | continue; | |
6083 | } | |
6084 | out_attr = &out_list->attr; | |
6085 | /* Check all the input tags with the same identifier. */ | |
6086 | for (;;) | |
6087 | { | |
6088 | if (out_list->tag != Tag_compatibility | |
6089 | || in_attr->i != out_attr->i | |
6090 | || strcmp (in_attr->s, out_attr->s) != 0) | |
6091 | { | |
6092 | _bfd_error_handler | |
6093 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
6094 | ibfd, in_attr->s, in_attr->i); | |
6095 | return FALSE; | |
6096 | } | |
6097 | in_list = in_list->next; | |
6098 | if (in_list->tag != Tag_compatibility | |
6099 | || strcmp (in_attr->s, in_list->attr.s) != 0) | |
6100 | break; | |
6101 | in_attr = &in_list->attr; | |
6102 | out_list = out_list->next; | |
6103 | if (out_list) | |
6104 | out_attr = &out_list->attr; | |
6105 | } | |
6106 | ||
6107 | /* Check the output doesn't have extra tags with this identifier. */ | |
6108 | if (out_list && out_list->tag == Tag_compatibility | |
6109 | && strcmp (in_attr->s, out_list->attr.s) == 0) | |
6110 | { | |
6111 | _bfd_error_handler | |
6112 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
6113 | ibfd, in_attr->s, out_list->attr.i); | |
6114 | return FALSE; | |
6115 | } | |
6116 | } | |
6117 | ||
6118 | for (; in_list; in_list = in_list->next) | |
6119 | { | |
6120 | if ((in_list->tag & 128) < 64) | |
eb111b1f BE |
6121 | { |
6122 | _bfd_error_handler | |
6123 | (_("Warning: %B: Unknown EABI object attribute %d"), | |
6124 | ibfd, in_list->tag); | |
6125 | break; | |
6126 | } | |
ee065d83 | 6127 | } |
b34976b6 | 6128 | return TRUE; |
252b5132 RH |
6129 | } |
6130 | ||
3a4a14e9 PB |
6131 | |
6132 | /* Return TRUE if the two EABI versions are incompatible. */ | |
6133 | ||
6134 | static bfd_boolean | |
6135 | elf32_arm_versions_compatible (unsigned iver, unsigned over) | |
6136 | { | |
6137 | /* v4 and v5 are the same spec before and after it was released, | |
6138 | so allow mixing them. */ | |
6139 | if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5) | |
6140 | || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4)) | |
6141 | return TRUE; | |
6142 | ||
6143 | return (iver == over); | |
6144 | } | |
6145 | ||
252b5132 RH |
6146 | /* Merge backend specific data from an object file to the output |
6147 | object file when linking. */ | |
9b485d32 | 6148 | |
b34976b6 | 6149 | static bfd_boolean |
57e8b36a | 6150 | elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
252b5132 RH |
6151 | { |
6152 | flagword out_flags; | |
6153 | flagword in_flags; | |
b34976b6 | 6154 | bfd_boolean flags_compatible = TRUE; |
cf919dfd | 6155 | asection *sec; |
252b5132 | 6156 | |
9b485d32 | 6157 | /* Check if we have the same endianess. */ |
82e51918 | 6158 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 6159 | return FALSE; |
1fe494a5 | 6160 | |
252b5132 RH |
6161 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
6162 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 6163 | return TRUE; |
252b5132 | 6164 | |
ee065d83 PB |
6165 | if (!elf32_arm_merge_eabi_attributes (ibfd, obfd)) |
6166 | return FALSE; | |
6167 | ||
252b5132 RH |
6168 | /* The input BFD must have had its flags initialised. */ |
6169 | /* The following seems bogus to me -- The flags are initialized in | |
6170 | the assembler but I don't think an elf_flags_init field is | |
9b485d32 | 6171 | written into the object. */ |
252b5132 RH |
6172 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
6173 | ||
6174 | in_flags = elf_elfheader (ibfd)->e_flags; | |
6175 | out_flags = elf_elfheader (obfd)->e_flags; | |
6176 | ||
6177 | if (!elf_flags_init (obfd)) | |
6178 | { | |
fe077fa6 NC |
6179 | /* If the input is the default architecture and had the default |
6180 | flags then do not bother setting the flags for the output | |
6181 | architecture, instead allow future merges to do this. If no | |
6182 | future merges ever set these flags then they will retain their | |
6183 | uninitialised values, which surprise surprise, correspond | |
252b5132 | 6184 | to the default values. */ |
fe077fa6 NC |
6185 | if (bfd_get_arch_info (ibfd)->the_default |
6186 | && elf_elfheader (ibfd)->e_flags == 0) | |
b34976b6 | 6187 | return TRUE; |
252b5132 | 6188 | |
b34976b6 | 6189 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
6190 | elf_elfheader (obfd)->e_flags = in_flags; |
6191 | ||
6192 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
6193 | && bfd_get_arch_info (obfd)->the_default) | |
6194 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); | |
6195 | ||
b34976b6 | 6196 | return TRUE; |
252b5132 RH |
6197 | } |
6198 | ||
5a6c6817 NC |
6199 | /* Determine what should happen if the input ARM architecture |
6200 | does not match the output ARM architecture. */ | |
6201 | if (! bfd_arm_merge_machines (ibfd, obfd)) | |
6202 | return FALSE; | |
e16bb312 | 6203 | |
1006ba19 | 6204 | /* Identical flags must be compatible. */ |
252b5132 | 6205 | if (in_flags == out_flags) |
b34976b6 | 6206 | return TRUE; |
252b5132 | 6207 | |
35a0f415 DJ |
6208 | /* Check to see if the input BFD actually contains any sections. If |
6209 | not, its flags may not have been initialised either, but it | |
8e3de13a | 6210 | cannot actually cause any incompatiblity. Do not short-circuit |
35a0f415 | 6211 | dynamic objects; their section list may be emptied by |
d1f161ea | 6212 | elf_link_add_object_symbols. |
35a0f415 | 6213 | |
d1f161ea NC |
6214 | Also check to see if there are no code sections in the input. |
6215 | In this case there is no need to check for code specific flags. | |
6216 | XXX - do we need to worry about floating-point format compatability | |
6217 | in data sections ? */ | |
35a0f415 | 6218 | if (!(ibfd->flags & DYNAMIC)) |
cf919dfd | 6219 | { |
35a0f415 | 6220 | bfd_boolean null_input_bfd = TRUE; |
d1f161ea | 6221 | bfd_boolean only_data_sections = TRUE; |
35a0f415 DJ |
6222 | |
6223 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
cf919dfd | 6224 | { |
35a0f415 DJ |
6225 | /* Ignore synthetic glue sections. */ |
6226 | if (strcmp (sec->name, ".glue_7") | |
6227 | && strcmp (sec->name, ".glue_7t")) | |
6228 | { | |
d1f161ea NC |
6229 | if ((bfd_get_section_flags (ibfd, sec) |
6230 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
6231 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
6232 | only_data_sections = FALSE; | |
6233 | ||
35a0f415 DJ |
6234 | null_input_bfd = FALSE; |
6235 | break; | |
6236 | } | |
cf919dfd | 6237 | } |
d1f161ea NC |
6238 | |
6239 | if (null_input_bfd || only_data_sections) | |
35a0f415 | 6240 | return TRUE; |
cf919dfd | 6241 | } |
cf919dfd | 6242 | |
252b5132 | 6243 | /* Complain about various flag mismatches. */ |
3a4a14e9 PB |
6244 | if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags), |
6245 | EF_ARM_EABI_VERSION (out_flags))) | |
fc830a83 | 6246 | { |
d003868e | 6247 | _bfd_error_handler |
3656d5e3 | 6248 | (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"), |
d003868e AM |
6249 | ibfd, obfd, |
6250 | (in_flags & EF_ARM_EABIMASK) >> 24, | |
6251 | (out_flags & EF_ARM_EABIMASK) >> 24); | |
b34976b6 | 6252 | return FALSE; |
fc830a83 | 6253 | } |
252b5132 | 6254 | |
1006ba19 | 6255 | /* Not sure what needs to be checked for EABI versions >= 1. */ |
00a97672 RS |
6256 | /* VxWorks libraries do not use these flags. */ |
6257 | if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed | |
6258 | && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed | |
6259 | && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) | |
1006ba19 | 6260 | { |
fd2ec330 | 6261 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
1006ba19 | 6262 | { |
d003868e AM |
6263 | _bfd_error_handler |
6264 | (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), | |
6265 | ibfd, obfd, | |
6266 | in_flags & EF_ARM_APCS_26 ? 26 : 32, | |
6267 | out_flags & EF_ARM_APCS_26 ? 26 : 32); | |
b34976b6 | 6268 | flags_compatible = FALSE; |
1006ba19 | 6269 | } |
252b5132 | 6270 | |
fd2ec330 | 6271 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
1006ba19 | 6272 | { |
5eefb65f | 6273 | if (in_flags & EF_ARM_APCS_FLOAT) |
d003868e AM |
6274 | _bfd_error_handler |
6275 | (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), | |
6276 | ibfd, obfd); | |
5eefb65f | 6277 | else |
d003868e AM |
6278 | _bfd_error_handler |
6279 | (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), | |
6280 | ibfd, obfd); | |
63b0f745 | 6281 | |
b34976b6 | 6282 | flags_compatible = FALSE; |
1006ba19 | 6283 | } |
252b5132 | 6284 | |
96a846ea | 6285 | if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) |
1006ba19 | 6286 | { |
96a846ea | 6287 | if (in_flags & EF_ARM_VFP_FLOAT) |
d003868e AM |
6288 | _bfd_error_handler |
6289 | (_("ERROR: %B uses VFP instructions, whereas %B does not"), | |
6290 | ibfd, obfd); | |
5eefb65f | 6291 | else |
d003868e AM |
6292 | _bfd_error_handler |
6293 | (_("ERROR: %B uses FPA instructions, whereas %B does not"), | |
6294 | ibfd, obfd); | |
fde78edd NC |
6295 | |
6296 | flags_compatible = FALSE; | |
6297 | } | |
6298 | ||
6299 | if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) | |
6300 | { | |
6301 | if (in_flags & EF_ARM_MAVERICK_FLOAT) | |
d003868e AM |
6302 | _bfd_error_handler |
6303 | (_("ERROR: %B uses Maverick instructions, whereas %B does not"), | |
6304 | ibfd, obfd); | |
fde78edd | 6305 | else |
d003868e AM |
6306 | _bfd_error_handler |
6307 | (_("ERROR: %B does not use Maverick instructions, whereas %B does"), | |
6308 | ibfd, obfd); | |
63b0f745 | 6309 | |
b34976b6 | 6310 | flags_compatible = FALSE; |
1006ba19 | 6311 | } |
96a846ea RE |
6312 | |
6313 | #ifdef EF_ARM_SOFT_FLOAT | |
6314 | if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) | |
6315 | { | |
6316 | /* We can allow interworking between code that is VFP format | |
6317 | layout, and uses either soft float or integer regs for | |
6318 | passing floating point arguments and results. We already | |
6319 | know that the APCS_FLOAT flags match; similarly for VFP | |
6320 | flags. */ | |
6321 | if ((in_flags & EF_ARM_APCS_FLOAT) != 0 | |
6322 | || (in_flags & EF_ARM_VFP_FLOAT) == 0) | |
6323 | { | |
6324 | if (in_flags & EF_ARM_SOFT_FLOAT) | |
d003868e AM |
6325 | _bfd_error_handler |
6326 | (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), | |
6327 | ibfd, obfd); | |
96a846ea | 6328 | else |
d003868e AM |
6329 | _bfd_error_handler |
6330 | (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), | |
6331 | ibfd, obfd); | |
96a846ea | 6332 | |
b34976b6 | 6333 | flags_compatible = FALSE; |
96a846ea RE |
6334 | } |
6335 | } | |
ee43f35e | 6336 | #endif |
252b5132 | 6337 | |
1006ba19 | 6338 | /* Interworking mismatch is only a warning. */ |
fd2ec330 | 6339 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
8f615d07 | 6340 | { |
e3c8793a NC |
6341 | if (in_flags & EF_ARM_INTERWORK) |
6342 | { | |
d003868e AM |
6343 | _bfd_error_handler |
6344 | (_("Warning: %B supports interworking, whereas %B does not"), | |
6345 | ibfd, obfd); | |
e3c8793a NC |
6346 | } |
6347 | else | |
6348 | { | |
d003868e AM |
6349 | _bfd_error_handler |
6350 | (_("Warning: %B does not support interworking, whereas %B does"), | |
6351 | ibfd, obfd); | |
e3c8793a | 6352 | } |
8f615d07 | 6353 | } |
252b5132 | 6354 | } |
63b0f745 | 6355 | |
1006ba19 | 6356 | return flags_compatible; |
252b5132 RH |
6357 | } |
6358 | ||
9b485d32 NC |
6359 | /* Display the flags field. */ |
6360 | ||
b34976b6 | 6361 | static bfd_boolean |
57e8b36a | 6362 | elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) |
252b5132 | 6363 | { |
fc830a83 NC |
6364 | FILE * file = (FILE *) ptr; |
6365 | unsigned long flags; | |
252b5132 RH |
6366 | |
6367 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
6368 | ||
6369 | /* Print normal ELF private data. */ | |
6370 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
6371 | ||
fc830a83 | 6372 | flags = elf_elfheader (abfd)->e_flags; |
9b485d32 NC |
6373 | /* Ignore init flag - it may not be set, despite the flags field |
6374 | containing valid data. */ | |
252b5132 RH |
6375 | |
6376 | /* xgettext:c-format */ | |
9b485d32 | 6377 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
252b5132 | 6378 | |
fc830a83 NC |
6379 | switch (EF_ARM_EABI_VERSION (flags)) |
6380 | { | |
6381 | case EF_ARM_EABI_UNKNOWN: | |
4cc11e76 | 6382 | /* The following flag bits are GNU extensions and not part of the |
fc830a83 NC |
6383 | official ARM ELF extended ABI. Hence they are only decoded if |
6384 | the EABI version is not set. */ | |
fd2ec330 | 6385 | if (flags & EF_ARM_INTERWORK) |
9b485d32 | 6386 | fprintf (file, _(" [interworking enabled]")); |
9a5aca8c | 6387 | |
fd2ec330 | 6388 | if (flags & EF_ARM_APCS_26) |
6c571f00 | 6389 | fprintf (file, " [APCS-26]"); |
fc830a83 | 6390 | else |
6c571f00 | 6391 | fprintf (file, " [APCS-32]"); |
9a5aca8c | 6392 | |
96a846ea RE |
6393 | if (flags & EF_ARM_VFP_FLOAT) |
6394 | fprintf (file, _(" [VFP float format]")); | |
fde78edd NC |
6395 | else if (flags & EF_ARM_MAVERICK_FLOAT) |
6396 | fprintf (file, _(" [Maverick float format]")); | |
96a846ea RE |
6397 | else |
6398 | fprintf (file, _(" [FPA float format]")); | |
6399 | ||
fd2ec330 | 6400 | if (flags & EF_ARM_APCS_FLOAT) |
9b485d32 | 6401 | fprintf (file, _(" [floats passed in float registers]")); |
9a5aca8c | 6402 | |
fd2ec330 | 6403 | if (flags & EF_ARM_PIC) |
9b485d32 | 6404 | fprintf (file, _(" [position independent]")); |
fc830a83 | 6405 | |
fd2ec330 | 6406 | if (flags & EF_ARM_NEW_ABI) |
9b485d32 | 6407 | fprintf (file, _(" [new ABI]")); |
9a5aca8c | 6408 | |
fd2ec330 | 6409 | if (flags & EF_ARM_OLD_ABI) |
9b485d32 | 6410 | fprintf (file, _(" [old ABI]")); |
9a5aca8c | 6411 | |
fd2ec330 | 6412 | if (flags & EF_ARM_SOFT_FLOAT) |
9b485d32 | 6413 | fprintf (file, _(" [software FP]")); |
9a5aca8c | 6414 | |
96a846ea RE |
6415 | flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT |
6416 | | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI | |
fde78edd NC |
6417 | | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT |
6418 | | EF_ARM_MAVERICK_FLOAT); | |
fc830a83 | 6419 | break; |
9a5aca8c | 6420 | |
fc830a83 | 6421 | case EF_ARM_EABI_VER1: |
9b485d32 | 6422 | fprintf (file, _(" [Version1 EABI]")); |
9a5aca8c | 6423 | |
fc830a83 | 6424 | if (flags & EF_ARM_SYMSARESORTED) |
9b485d32 | 6425 | fprintf (file, _(" [sorted symbol table]")); |
fc830a83 | 6426 | else |
9b485d32 | 6427 | fprintf (file, _(" [unsorted symbol table]")); |
9a5aca8c | 6428 | |
fc830a83 NC |
6429 | flags &= ~ EF_ARM_SYMSARESORTED; |
6430 | break; | |
9a5aca8c | 6431 | |
fd2ec330 PB |
6432 | case EF_ARM_EABI_VER2: |
6433 | fprintf (file, _(" [Version2 EABI]")); | |
6434 | ||
6435 | if (flags & EF_ARM_SYMSARESORTED) | |
6436 | fprintf (file, _(" [sorted symbol table]")); | |
6437 | else | |
6438 | fprintf (file, _(" [unsorted symbol table]")); | |
6439 | ||
6440 | if (flags & EF_ARM_DYNSYMSUSESEGIDX) | |
6441 | fprintf (file, _(" [dynamic symbols use segment index]")); | |
6442 | ||
6443 | if (flags & EF_ARM_MAPSYMSFIRST) | |
6444 | fprintf (file, _(" [mapping symbols precede others]")); | |
6445 | ||
99e4ae17 | 6446 | flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX |
fd2ec330 PB |
6447 | | EF_ARM_MAPSYMSFIRST); |
6448 | break; | |
6449 | ||
d507cf36 PB |
6450 | case EF_ARM_EABI_VER3: |
6451 | fprintf (file, _(" [Version3 EABI]")); | |
8cb51566 PB |
6452 | break; |
6453 | ||
6454 | case EF_ARM_EABI_VER4: | |
6455 | fprintf (file, _(" [Version4 EABI]")); | |
3a4a14e9 | 6456 | goto eabi; |
d507cf36 | 6457 | |
3a4a14e9 PB |
6458 | case EF_ARM_EABI_VER5: |
6459 | fprintf (file, _(" [Version5 EABI]")); | |
6460 | eabi: | |
d507cf36 PB |
6461 | if (flags & EF_ARM_BE8) |
6462 | fprintf (file, _(" [BE8]")); | |
6463 | ||
6464 | if (flags & EF_ARM_LE8) | |
6465 | fprintf (file, _(" [LE8]")); | |
6466 | ||
6467 | flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); | |
6468 | break; | |
6469 | ||
fc830a83 | 6470 | default: |
9b485d32 | 6471 | fprintf (file, _(" <EABI version unrecognised>")); |
fc830a83 NC |
6472 | break; |
6473 | } | |
252b5132 | 6474 | |
fc830a83 | 6475 | flags &= ~ EF_ARM_EABIMASK; |
252b5132 | 6476 | |
fc830a83 | 6477 | if (flags & EF_ARM_RELEXEC) |
9b485d32 | 6478 | fprintf (file, _(" [relocatable executable]")); |
252b5132 | 6479 | |
fc830a83 | 6480 | if (flags & EF_ARM_HASENTRY) |
9b485d32 | 6481 | fprintf (file, _(" [has entry point]")); |
252b5132 | 6482 | |
fc830a83 NC |
6483 | flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); |
6484 | ||
6485 | if (flags) | |
9b485d32 | 6486 | fprintf (file, _("<Unrecognised flag bits set>")); |
9a5aca8c | 6487 | |
252b5132 RH |
6488 | fputc ('\n', file); |
6489 | ||
b34976b6 | 6490 | return TRUE; |
252b5132 RH |
6491 | } |
6492 | ||
6493 | static int | |
57e8b36a | 6494 | elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
252b5132 | 6495 | { |
2f0ca46a NC |
6496 | switch (ELF_ST_TYPE (elf_sym->st_info)) |
6497 | { | |
6498 | case STT_ARM_TFUNC: | |
6499 | return ELF_ST_TYPE (elf_sym->st_info); | |
ce855c42 | 6500 | |
2f0ca46a NC |
6501 | case STT_ARM_16BIT: |
6502 | /* If the symbol is not an object, return the STT_ARM_16BIT flag. | |
6503 | This allows us to distinguish between data used by Thumb instructions | |
6504 | and non-data (which is probably code) inside Thumb regions of an | |
6505 | executable. */ | |
1a0eb693 | 6506 | if (type != STT_OBJECT && type != STT_TLS) |
2f0ca46a NC |
6507 | return ELF_ST_TYPE (elf_sym->st_info); |
6508 | break; | |
9a5aca8c | 6509 | |
ce855c42 NC |
6510 | default: |
6511 | break; | |
2f0ca46a NC |
6512 | } |
6513 | ||
6514 | return type; | |
252b5132 | 6515 | } |
f21f3fe0 | 6516 | |
252b5132 | 6517 | static asection * |
57e8b36a NC |
6518 | elf32_arm_gc_mark_hook (asection * sec, |
6519 | struct bfd_link_info * info ATTRIBUTE_UNUSED, | |
6520 | Elf_Internal_Rela * rel, | |
6521 | struct elf_link_hash_entry * h, | |
6522 | Elf_Internal_Sym * sym) | |
252b5132 RH |
6523 | { |
6524 | if (h != NULL) | |
6525 | { | |
6526 | switch (ELF32_R_TYPE (rel->r_info)) | |
6527 | { | |
6528 | case R_ARM_GNU_VTINHERIT: | |
6529 | case R_ARM_GNU_VTENTRY: | |
6530 | break; | |
6531 | ||
6532 | default: | |
6533 | switch (h->root.type) | |
6534 | { | |
6535 | case bfd_link_hash_defined: | |
6536 | case bfd_link_hash_defweak: | |
6537 | return h->root.u.def.section; | |
6538 | ||
6539 | case bfd_link_hash_common: | |
6540 | return h->root.u.c.p->section; | |
e049a0de ILT |
6541 | |
6542 | default: | |
6543 | break; | |
252b5132 RH |
6544 | } |
6545 | } | |
6546 | } | |
6547 | else | |
1e2f5b6e | 6548 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
9ad5cbcf | 6549 | |
252b5132 RH |
6550 | return NULL; |
6551 | } | |
6552 | ||
780a67af NC |
6553 | /* Update the got entry reference counts for the section being removed. */ |
6554 | ||
b34976b6 | 6555 | static bfd_boolean |
ba93b8ac DJ |
6556 | elf32_arm_gc_sweep_hook (bfd * abfd, |
6557 | struct bfd_link_info * info, | |
6558 | asection * sec, | |
6559 | const Elf_Internal_Rela * relocs) | |
252b5132 | 6560 | { |
5e681ec4 PB |
6561 | Elf_Internal_Shdr *symtab_hdr; |
6562 | struct elf_link_hash_entry **sym_hashes; | |
6563 | bfd_signed_vma *local_got_refcounts; | |
6564 | const Elf_Internal_Rela *rel, *relend; | |
eb043451 PB |
6565 | struct elf32_arm_link_hash_table * globals; |
6566 | ||
6567 | globals = elf32_arm_hash_table (info); | |
5e681ec4 PB |
6568 | |
6569 | elf_section_data (sec)->local_dynrel = NULL; | |
6570 | ||
6571 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
6572 | sym_hashes = elf_sym_hashes (abfd); | |
6573 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
6574 | ||
6575 | relend = relocs + sec->reloc_count; | |
6576 | for (rel = relocs; rel < relend; rel++) | |
eb043451 | 6577 | { |
3eb128b2 AM |
6578 | unsigned long r_symndx; |
6579 | struct elf_link_hash_entry *h = NULL; | |
eb043451 | 6580 | int r_type; |
5e681ec4 | 6581 | |
3eb128b2 AM |
6582 | r_symndx = ELF32_R_SYM (rel->r_info); |
6583 | if (r_symndx >= symtab_hdr->sh_info) | |
6584 | { | |
6585 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
6586 | while (h->root.type == bfd_link_hash_indirect | |
6587 | || h->root.type == bfd_link_hash_warning) | |
6588 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6589 | } | |
6590 | ||
eb043451 | 6591 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 6592 | r_type = arm_real_reloc_type (globals, r_type); |
eb043451 PB |
6593 | switch (r_type) |
6594 | { | |
6595 | case R_ARM_GOT32: | |
eb043451 | 6596 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
6597 | case R_ARM_TLS_GD32: |
6598 | case R_ARM_TLS_IE32: | |
3eb128b2 | 6599 | if (h != NULL) |
eb043451 | 6600 | { |
eb043451 PB |
6601 | if (h->got.refcount > 0) |
6602 | h->got.refcount -= 1; | |
6603 | } | |
6604 | else if (local_got_refcounts != NULL) | |
6605 | { | |
6606 | if (local_got_refcounts[r_symndx] > 0) | |
6607 | local_got_refcounts[r_symndx] -= 1; | |
6608 | } | |
6609 | break; | |
6610 | ||
ba93b8ac DJ |
6611 | case R_ARM_TLS_LDM32: |
6612 | elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; | |
6613 | break; | |
6614 | ||
eb043451 PB |
6615 | case R_ARM_ABS32: |
6616 | case R_ARM_REL32: | |
6617 | case R_ARM_PC24: | |
6618 | case R_ARM_PLT32: | |
5b5bb741 PB |
6619 | case R_ARM_CALL: |
6620 | case R_ARM_JUMP24: | |
eb043451 | 6621 | case R_ARM_PREL31: |
c19d1205 | 6622 | case R_ARM_THM_CALL: |
b6895b4f PB |
6623 | case R_ARM_MOVW_ABS_NC: |
6624 | case R_ARM_MOVT_ABS: | |
6625 | case R_ARM_MOVW_PREL_NC: | |
6626 | case R_ARM_MOVT_PREL: | |
6627 | case R_ARM_THM_MOVW_ABS_NC: | |
6628 | case R_ARM_THM_MOVT_ABS: | |
6629 | case R_ARM_THM_MOVW_PREL_NC: | |
6630 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 DJ |
6631 | /* Should the interworking branches be here also? */ |
6632 | ||
3eb128b2 | 6633 | if (h != NULL) |
eb043451 PB |
6634 | { |
6635 | struct elf32_arm_link_hash_entry *eh; | |
6636 | struct elf32_arm_relocs_copied **pp; | |
6637 | struct elf32_arm_relocs_copied *p; | |
5e681ec4 | 6638 | |
b7693d02 | 6639 | eh = (struct elf32_arm_link_hash_entry *) h; |
5e681ec4 | 6640 | |
eb043451 | 6641 | if (h->plt.refcount > 0) |
b7693d02 DJ |
6642 | { |
6643 | h->plt.refcount -= 1; | |
c19d1205 | 6644 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL) |
b7693d02 DJ |
6645 | eh->plt_thumb_refcount--; |
6646 | } | |
5e681ec4 | 6647 | |
eb043451 | 6648 | if (r_type == R_ARM_ABS32 |
eb043451 PB |
6649 | || r_type == R_ARM_REL32) |
6650 | { | |
eb043451 PB |
6651 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; |
6652 | pp = &p->next) | |
6653 | if (p->section == sec) | |
6654 | { | |
6655 | p->count -= 1; | |
ba93b8ac DJ |
6656 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32) |
6657 | p->pc_count -= 1; | |
eb043451 PB |
6658 | if (p->count == 0) |
6659 | *pp = p->next; | |
6660 | break; | |
6661 | } | |
6662 | } | |
6663 | } | |
6664 | break; | |
5e681ec4 | 6665 | |
eb043451 PB |
6666 | default: |
6667 | break; | |
6668 | } | |
6669 | } | |
5e681ec4 | 6670 | |
b34976b6 | 6671 | return TRUE; |
252b5132 RH |
6672 | } |
6673 | ||
780a67af NC |
6674 | /* Look through the relocs for a section during the first phase. */ |
6675 | ||
b34976b6 | 6676 | static bfd_boolean |
57e8b36a NC |
6677 | elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, |
6678 | asection *sec, const Elf_Internal_Rela *relocs) | |
252b5132 | 6679 | { |
b34976b6 AM |
6680 | Elf_Internal_Shdr *symtab_hdr; |
6681 | struct elf_link_hash_entry **sym_hashes; | |
6682 | struct elf_link_hash_entry **sym_hashes_end; | |
6683 | const Elf_Internal_Rela *rel; | |
6684 | const Elf_Internal_Rela *rel_end; | |
6685 | bfd *dynobj; | |
5e681ec4 | 6686 | asection *sreloc; |
b34976b6 | 6687 | bfd_vma *local_got_offsets; |
5e681ec4 | 6688 | struct elf32_arm_link_hash_table *htab; |
9a5aca8c | 6689 | |
1049f94e | 6690 | if (info->relocatable) |
b34976b6 | 6691 | return TRUE; |
9a5aca8c | 6692 | |
5e681ec4 PB |
6693 | htab = elf32_arm_hash_table (info); |
6694 | sreloc = NULL; | |
9a5aca8c | 6695 | |
67687978 PB |
6696 | /* Create dynamic sections for relocatable executables so that we can |
6697 | copy relocations. */ | |
6698 | if (htab->root.is_relocatable_executable | |
6699 | && ! htab->root.dynamic_sections_created) | |
6700 | { | |
6701 | if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) | |
6702 | return FALSE; | |
6703 | } | |
6704 | ||
252b5132 RH |
6705 | dynobj = elf_hash_table (info)->dynobj; |
6706 | local_got_offsets = elf_local_got_offsets (abfd); | |
f21f3fe0 | 6707 | |
252b5132 RH |
6708 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
6709 | sym_hashes = elf_sym_hashes (abfd); | |
9b485d32 NC |
6710 | sym_hashes_end = sym_hashes |
6711 | + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); | |
6712 | ||
252b5132 RH |
6713 | if (!elf_bad_symtab (abfd)) |
6714 | sym_hashes_end -= symtab_hdr->sh_info; | |
9b485d32 | 6715 | |
252b5132 RH |
6716 | rel_end = relocs + sec->reloc_count; |
6717 | for (rel = relocs; rel < rel_end; rel++) | |
6718 | { | |
6719 | struct elf_link_hash_entry *h; | |
b7693d02 | 6720 | struct elf32_arm_link_hash_entry *eh; |
252b5132 | 6721 | unsigned long r_symndx; |
eb043451 | 6722 | int r_type; |
9a5aca8c | 6723 | |
252b5132 | 6724 | r_symndx = ELF32_R_SYM (rel->r_info); |
eb043451 | 6725 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 6726 | r_type = arm_real_reloc_type (htab, r_type); |
ba93b8ac DJ |
6727 | |
6728 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
6729 | { | |
6730 | (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd, | |
6731 | r_symndx); | |
6732 | return FALSE; | |
6733 | } | |
6734 | ||
252b5132 RH |
6735 | if (r_symndx < symtab_hdr->sh_info) |
6736 | h = NULL; | |
6737 | else | |
973a3492 L |
6738 | { |
6739 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
6740 | while (h->root.type == bfd_link_hash_indirect | |
6741 | || h->root.type == bfd_link_hash_warning) | |
6742 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6743 | } | |
9a5aca8c | 6744 | |
b7693d02 DJ |
6745 | eh = (struct elf32_arm_link_hash_entry *) h; |
6746 | ||
eb043451 | 6747 | switch (r_type) |
252b5132 | 6748 | { |
5e681ec4 | 6749 | case R_ARM_GOT32: |
eb043451 | 6750 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
6751 | case R_ARM_TLS_GD32: |
6752 | case R_ARM_TLS_IE32: | |
5e681ec4 | 6753 | /* This symbol requires a global offset table entry. */ |
ba93b8ac DJ |
6754 | { |
6755 | int tls_type, old_tls_type; | |
5e681ec4 | 6756 | |
ba93b8ac DJ |
6757 | switch (r_type) |
6758 | { | |
6759 | case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break; | |
6760 | case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break; | |
6761 | default: tls_type = GOT_NORMAL; break; | |
6762 | } | |
252b5132 | 6763 | |
ba93b8ac DJ |
6764 | if (h != NULL) |
6765 | { | |
6766 | h->got.refcount++; | |
6767 | old_tls_type = elf32_arm_hash_entry (h)->tls_type; | |
6768 | } | |
6769 | else | |
6770 | { | |
6771 | bfd_signed_vma *local_got_refcounts; | |
6772 | ||
6773 | /* This is a global offset table entry for a local symbol. */ | |
6774 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
6775 | if (local_got_refcounts == NULL) | |
6776 | { | |
6777 | bfd_size_type size; | |
6778 | ||
6779 | size = symtab_hdr->sh_info; | |
6780 | size *= (sizeof (bfd_signed_vma) + sizeof(char)); | |
6781 | local_got_refcounts = bfd_zalloc (abfd, size); | |
6782 | if (local_got_refcounts == NULL) | |
6783 | return FALSE; | |
6784 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
6785 | elf32_arm_local_got_tls_type (abfd) | |
6786 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
6787 | } | |
6788 | local_got_refcounts[r_symndx] += 1; | |
6789 | old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx]; | |
6790 | } | |
6791 | ||
6792 | /* We will already have issued an error message if there is a | |
6793 | TLS / non-TLS mismatch, based on the symbol type. We don't | |
6794 | support any linker relaxations. So just combine any TLS | |
6795 | types needed. */ | |
6796 | if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL | |
6797 | && tls_type != GOT_NORMAL) | |
6798 | tls_type |= old_tls_type; | |
6799 | ||
6800 | if (old_tls_type != tls_type) | |
6801 | { | |
6802 | if (h != NULL) | |
6803 | elf32_arm_hash_entry (h)->tls_type = tls_type; | |
6804 | else | |
6805 | elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
6806 | } | |
6807 | } | |
6808 | /* Fall through */ | |
6809 | ||
6810 | case R_ARM_TLS_LDM32: | |
6811 | if (r_type == R_ARM_TLS_LDM32) | |
6812 | htab->tls_ldm_got.refcount++; | |
6813 | /* Fall through */ | |
252b5132 | 6814 | |
c19d1205 | 6815 | case R_ARM_GOTOFF32: |
5e681ec4 PB |
6816 | case R_ARM_GOTPC: |
6817 | if (htab->sgot == NULL) | |
6818 | { | |
6819 | if (htab->root.dynobj == NULL) | |
6820 | htab->root.dynobj = abfd; | |
6821 | if (!create_got_section (htab->root.dynobj, info)) | |
6822 | return FALSE; | |
6823 | } | |
252b5132 RH |
6824 | break; |
6825 | ||
00a97672 RS |
6826 | case R_ARM_ABS12: |
6827 | /* VxWorks uses dynamic R_ARM_ABS12 relocations for | |
6828 | ldr __GOTT_INDEX__ offsets. */ | |
6829 | if (!htab->vxworks_p) | |
6830 | break; | |
6831 | /* Fall through */ | |
6832 | ||
252b5132 RH |
6833 | case R_ARM_ABS32: |
6834 | case R_ARM_REL32: | |
6835 | case R_ARM_PC24: | |
7359ea65 | 6836 | case R_ARM_PLT32: |
5b5bb741 PB |
6837 | case R_ARM_CALL: |
6838 | case R_ARM_JUMP24: | |
eb043451 | 6839 | case R_ARM_PREL31: |
c19d1205 | 6840 | case R_ARM_THM_CALL: |
b6895b4f PB |
6841 | case R_ARM_MOVW_ABS_NC: |
6842 | case R_ARM_MOVT_ABS: | |
6843 | case R_ARM_MOVW_PREL_NC: | |
6844 | case R_ARM_MOVT_PREL: | |
6845 | case R_ARM_THM_MOVW_ABS_NC: | |
6846 | case R_ARM_THM_MOVT_ABS: | |
6847 | case R_ARM_THM_MOVW_PREL_NC: | |
6848 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 | 6849 | /* Should the interworking branches be listed here? */ |
7359ea65 | 6850 | if (h != NULL) |
5e681ec4 PB |
6851 | { |
6852 | /* If this reloc is in a read-only section, we might | |
6853 | need a copy reloc. We can't check reliably at this | |
6854 | stage whether the section is read-only, as input | |
6855 | sections have not yet been mapped to output sections. | |
6856 | Tentatively set the flag for now, and correct in | |
6857 | adjust_dynamic_symbol. */ | |
7359ea65 | 6858 | if (!info->shared) |
f5385ebf | 6859 | h->non_got_ref = 1; |
7359ea65 | 6860 | |
5e681ec4 | 6861 | /* We may need a .plt entry if the function this reloc |
c84cd8ee DJ |
6862 | refers to is in a different object. We can't tell for |
6863 | sure yet, because something later might force the | |
6864 | symbol local. */ | |
b6895b4f | 6865 | if (r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
f5385ebf | 6866 | h->needs_plt = 1; |
4f199be3 DJ |
6867 | |
6868 | /* If we create a PLT entry, this relocation will reference | |
6869 | it, even if it's an ABS32 relocation. */ | |
6870 | h->plt.refcount += 1; | |
b7693d02 | 6871 | |
c19d1205 | 6872 | if (r_type == R_ARM_THM_CALL) |
b7693d02 | 6873 | eh->plt_thumb_refcount += 1; |
5e681ec4 PB |
6874 | } |
6875 | ||
67687978 PB |
6876 | /* If we are creating a shared library or relocatable executable, |
6877 | and this is a reloc against a global symbol, or a non PC | |
6878 | relative reloc against a local symbol, then we need to copy | |
6879 | the reloc into the shared library. However, if we are linking | |
6880 | with -Bsymbolic, we do not need to copy a reloc against a | |
252b5132 RH |
6881 | global symbol which is defined in an object we are |
6882 | including in the link (i.e., DEF_REGULAR is set). At | |
6883 | this point we have not seen all the input files, so it is | |
6884 | possible that DEF_REGULAR is not set now but will be set | |
6885 | later (it is never cleared). We account for that | |
6886 | possibility below by storing information in the | |
5e681ec4 | 6887 | relocs_copied field of the hash table entry. */ |
67687978 | 6888 | if ((info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 6889 | && (sec->flags & SEC_ALLOC) != 0 |
71a976dd DJ |
6890 | && (r_type == R_ARM_ABS32 |
6891 | || (h != NULL && ! h->needs_plt | |
6892 | && (! info->symbolic || ! h->def_regular)))) | |
252b5132 | 6893 | { |
5e681ec4 PB |
6894 | struct elf32_arm_relocs_copied *p, **head; |
6895 | ||
252b5132 RH |
6896 | /* When creating a shared object, we must copy these |
6897 | reloc types into the output file. We create a reloc | |
6898 | section in dynobj and make room for this reloc. */ | |
6899 | if (sreloc == NULL) | |
6900 | { | |
6901 | const char * name; | |
6902 | ||
6903 | name = (bfd_elf_string_from_elf_section | |
6904 | (abfd, | |
6905 | elf_elfheader (abfd)->e_shstrndx, | |
6906 | elf_section_data (sec)->rel_hdr.sh_name)); | |
6907 | if (name == NULL) | |
b34976b6 | 6908 | return FALSE; |
252b5132 | 6909 | |
00a97672 | 6910 | BFD_ASSERT (reloc_section_p (htab, name, sec)); |
252b5132 RH |
6911 | |
6912 | sreloc = bfd_get_section_by_name (dynobj, name); | |
6913 | if (sreloc == NULL) | |
6914 | { | |
6915 | flagword flags; | |
6916 | ||
252b5132 RH |
6917 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
6918 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
e5a52504 MM |
6919 | if ((sec->flags & SEC_ALLOC) != 0 |
6920 | /* BPABI objects never have dynamic | |
6921 | relocations mapped. */ | |
6922 | && !htab->symbian_p) | |
252b5132 | 6923 | flags |= SEC_ALLOC | SEC_LOAD; |
3496cb2a L |
6924 | sreloc = bfd_make_section_with_flags (dynobj, |
6925 | name, | |
6926 | flags); | |
252b5132 | 6927 | if (sreloc == NULL |
252b5132 | 6928 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
b34976b6 | 6929 | return FALSE; |
252b5132 | 6930 | } |
5e681ec4 PB |
6931 | |
6932 | elf_section_data (sec)->sreloc = sreloc; | |
252b5132 RH |
6933 | } |
6934 | ||
5e681ec4 PB |
6935 | /* If this is a global symbol, we count the number of |
6936 | relocations we need for this symbol. */ | |
6937 | if (h != NULL) | |
252b5132 | 6938 | { |
5e681ec4 PB |
6939 | head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; |
6940 | } | |
6941 | else | |
6942 | { | |
6943 | /* Track dynamic relocs needed for local syms too. | |
6944 | We really need local syms available to do this | |
6945 | easily. Oh well. */ | |
57e8b36a | 6946 | |
5e681ec4 | 6947 | asection *s; |
6edfbbad DJ |
6948 | void *vpp; |
6949 | ||
5e681ec4 PB |
6950 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
6951 | sec, r_symndx); | |
6952 | if (s == NULL) | |
6953 | return FALSE; | |
57e8b36a | 6954 | |
6edfbbad DJ |
6955 | vpp = &elf_section_data (s)->local_dynrel; |
6956 | head = (struct elf32_arm_relocs_copied **) vpp; | |
5e681ec4 | 6957 | } |
57e8b36a | 6958 | |
5e681ec4 PB |
6959 | p = *head; |
6960 | if (p == NULL || p->section != sec) | |
6961 | { | |
6962 | bfd_size_type amt = sizeof *p; | |
57e8b36a | 6963 | |
5e681ec4 | 6964 | p = bfd_alloc (htab->root.dynobj, amt); |
252b5132 | 6965 | if (p == NULL) |
5e681ec4 PB |
6966 | return FALSE; |
6967 | p->next = *head; | |
6968 | *head = p; | |
6969 | p->section = sec; | |
6970 | p->count = 0; | |
ba93b8ac | 6971 | p->pc_count = 0; |
252b5132 | 6972 | } |
57e8b36a | 6973 | |
ba93b8ac DJ |
6974 | if (r_type == R_ARM_REL32) |
6975 | p->pc_count += 1; | |
71a976dd | 6976 | p->count += 1; |
252b5132 RH |
6977 | } |
6978 | break; | |
6979 | ||
6980 | /* This relocation describes the C++ object vtable hierarchy. | |
6981 | Reconstruct it for later use during GC. */ | |
6982 | case R_ARM_GNU_VTINHERIT: | |
c152c796 | 6983 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 6984 | return FALSE; |
252b5132 | 6985 | break; |
9a5aca8c | 6986 | |
252b5132 RH |
6987 | /* This relocation describes which C++ vtable entries are actually |
6988 | used. Record for later use during GC. */ | |
6989 | case R_ARM_GNU_VTENTRY: | |
c152c796 | 6990 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
b34976b6 | 6991 | return FALSE; |
252b5132 RH |
6992 | break; |
6993 | } | |
6994 | } | |
f21f3fe0 | 6995 | |
b34976b6 | 6996 | return TRUE; |
252b5132 RH |
6997 | } |
6998 | ||
3c9458e9 NC |
6999 | /* Treat mapping symbols as special target symbols. */ |
7000 | ||
7001 | static bfd_boolean | |
7002 | elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym) | |
7003 | { | |
b0796911 PB |
7004 | return bfd_is_arm_special_symbol_name (sym->name, |
7005 | BFD_ARM_SPECIAL_SYM_TYPE_ANY); | |
3c9458e9 NC |
7006 | } |
7007 | ||
0367ecfb NC |
7008 | /* This is a copy of elf_find_function() from elf.c except that |
7009 | ARM mapping symbols are ignored when looking for function names | |
7010 | and STT_ARM_TFUNC is considered to a function type. */ | |
252b5132 | 7011 | |
0367ecfb NC |
7012 | static bfd_boolean |
7013 | arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, | |
7014 | asection * section, | |
7015 | asymbol ** symbols, | |
7016 | bfd_vma offset, | |
7017 | const char ** filename_ptr, | |
7018 | const char ** functionname_ptr) | |
7019 | { | |
7020 | const char * filename = NULL; | |
7021 | asymbol * func = NULL; | |
7022 | bfd_vma low_func = 0; | |
7023 | asymbol ** p; | |
252b5132 RH |
7024 | |
7025 | for (p = symbols; *p != NULL; p++) | |
7026 | { | |
7027 | elf_symbol_type *q; | |
7028 | ||
7029 | q = (elf_symbol_type *) *p; | |
7030 | ||
252b5132 RH |
7031 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) |
7032 | { | |
7033 | default: | |
7034 | break; | |
7035 | case STT_FILE: | |
7036 | filename = bfd_asymbol_name (&q->symbol); | |
7037 | break; | |
252b5132 RH |
7038 | case STT_FUNC: |
7039 | case STT_ARM_TFUNC: | |
9d2da7ca | 7040 | case STT_NOTYPE: |
b0796911 | 7041 | /* Skip mapping symbols. */ |
0367ecfb | 7042 | if ((q->symbol.flags & BSF_LOCAL) |
b0796911 PB |
7043 | && bfd_is_arm_special_symbol_name (q->symbol.name, |
7044 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
0367ecfb NC |
7045 | continue; |
7046 | /* Fall through. */ | |
6b40fcba | 7047 | if (bfd_get_section (&q->symbol) == section |
252b5132 RH |
7048 | && q->symbol.value >= low_func |
7049 | && q->symbol.value <= offset) | |
7050 | { | |
7051 | func = (asymbol *) q; | |
7052 | low_func = q->symbol.value; | |
7053 | } | |
7054 | break; | |
7055 | } | |
7056 | } | |
7057 | ||
7058 | if (func == NULL) | |
b34976b6 | 7059 | return FALSE; |
252b5132 | 7060 | |
0367ecfb NC |
7061 | if (filename_ptr) |
7062 | *filename_ptr = filename; | |
7063 | if (functionname_ptr) | |
7064 | *functionname_ptr = bfd_asymbol_name (func); | |
7065 | ||
7066 | return TRUE; | |
7067 | } | |
7068 | ||
7069 | ||
7070 | /* Find the nearest line to a particular section and offset, for error | |
7071 | reporting. This code is a duplicate of the code in elf.c, except | |
7072 | that it uses arm_elf_find_function. */ | |
7073 | ||
7074 | static bfd_boolean | |
7075 | elf32_arm_find_nearest_line (bfd * abfd, | |
7076 | asection * section, | |
7077 | asymbol ** symbols, | |
7078 | bfd_vma offset, | |
7079 | const char ** filename_ptr, | |
7080 | const char ** functionname_ptr, | |
7081 | unsigned int * line_ptr) | |
7082 | { | |
7083 | bfd_boolean found = FALSE; | |
7084 | ||
7085 | /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ | |
7086 | ||
7087 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, | |
7088 | filename_ptr, functionname_ptr, | |
7089 | line_ptr, 0, | |
7090 | & elf_tdata (abfd)->dwarf2_find_line_info)) | |
7091 | { | |
7092 | if (!*functionname_ptr) | |
7093 | arm_elf_find_function (abfd, section, symbols, offset, | |
7094 | *filename_ptr ? NULL : filename_ptr, | |
7095 | functionname_ptr); | |
f21f3fe0 | 7096 | |
0367ecfb NC |
7097 | return TRUE; |
7098 | } | |
7099 | ||
7100 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, | |
7101 | & found, filename_ptr, | |
7102 | functionname_ptr, line_ptr, | |
7103 | & elf_tdata (abfd)->line_info)) | |
7104 | return FALSE; | |
7105 | ||
7106 | if (found && (*functionname_ptr || *line_ptr)) | |
7107 | return TRUE; | |
7108 | ||
7109 | if (symbols == NULL) | |
7110 | return FALSE; | |
7111 | ||
7112 | if (! arm_elf_find_function (abfd, section, symbols, offset, | |
7113 | filename_ptr, functionname_ptr)) | |
7114 | return FALSE; | |
7115 | ||
7116 | *line_ptr = 0; | |
b34976b6 | 7117 | return TRUE; |
252b5132 RH |
7118 | } |
7119 | ||
4ab527b0 FF |
7120 | static bfd_boolean |
7121 | elf32_arm_find_inliner_info (bfd * abfd, | |
7122 | const char ** filename_ptr, | |
7123 | const char ** functionname_ptr, | |
7124 | unsigned int * line_ptr) | |
7125 | { | |
7126 | bfd_boolean found; | |
7127 | found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr, | |
7128 | functionname_ptr, line_ptr, | |
7129 | & elf_tdata (abfd)->dwarf2_find_line_info); | |
7130 | return found; | |
7131 | } | |
7132 | ||
252b5132 RH |
7133 | /* Adjust a symbol defined by a dynamic object and referenced by a |
7134 | regular object. The current definition is in some section of the | |
7135 | dynamic object, but we're not including those sections. We have to | |
7136 | change the definition to something the rest of the link can | |
7137 | understand. */ | |
7138 | ||
b34976b6 | 7139 | static bfd_boolean |
57e8b36a NC |
7140 | elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, |
7141 | struct elf_link_hash_entry * h) | |
252b5132 RH |
7142 | { |
7143 | bfd * dynobj; | |
7144 | asection * s; | |
7145 | unsigned int power_of_two; | |
b7693d02 | 7146 | struct elf32_arm_link_hash_entry * eh; |
67687978 | 7147 | struct elf32_arm_link_hash_table *globals; |
252b5132 | 7148 | |
67687978 | 7149 | globals = elf32_arm_hash_table (info); |
252b5132 RH |
7150 | dynobj = elf_hash_table (info)->dynobj; |
7151 | ||
7152 | /* Make sure we know what is going on here. */ | |
7153 | BFD_ASSERT (dynobj != NULL | |
f5385ebf | 7154 | && (h->needs_plt |
f6e332e6 | 7155 | || h->u.weakdef != NULL |
f5385ebf AM |
7156 | || (h->def_dynamic |
7157 | && h->ref_regular | |
7158 | && !h->def_regular))); | |
252b5132 | 7159 | |
b7693d02 DJ |
7160 | eh = (struct elf32_arm_link_hash_entry *) h; |
7161 | ||
252b5132 RH |
7162 | /* If this is a function, put it in the procedure linkage table. We |
7163 | will fill in the contents of the procedure linkage table later, | |
7164 | when we know the address of the .got section. */ | |
b7693d02 | 7165 | if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC |
f5385ebf | 7166 | || h->needs_plt) |
252b5132 | 7167 | { |
5e681ec4 PB |
7168 | if (h->plt.refcount <= 0 |
7169 | || SYMBOL_CALLS_LOCAL (info, h) | |
7170 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
7171 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
7172 | { |
7173 | /* This case can occur if we saw a PLT32 reloc in an input | |
5e681ec4 PB |
7174 | file, but the symbol was never referred to by a dynamic |
7175 | object, or if all references were garbage collected. In | |
7176 | such a case, we don't actually need to build a procedure | |
7177 | linkage table, and we can just do a PC24 reloc instead. */ | |
7178 | h->plt.offset = (bfd_vma) -1; | |
b7693d02 | 7179 | eh->plt_thumb_refcount = 0; |
f5385ebf | 7180 | h->needs_plt = 0; |
252b5132 RH |
7181 | } |
7182 | ||
b34976b6 | 7183 | return TRUE; |
252b5132 | 7184 | } |
5e681ec4 | 7185 | else |
b7693d02 DJ |
7186 | { |
7187 | /* It's possible that we incorrectly decided a .plt reloc was | |
7188 | needed for an R_ARM_PC24 or similar reloc to a non-function sym | |
7189 | in check_relocs. We can't decide accurately between function | |
7190 | and non-function syms in check-relocs; Objects loaded later in | |
7191 | the link may change h->type. So fix it now. */ | |
7192 | h->plt.offset = (bfd_vma) -1; | |
7193 | eh->plt_thumb_refcount = 0; | |
7194 | } | |
252b5132 RH |
7195 | |
7196 | /* If this is a weak symbol, and there is a real definition, the | |
7197 | processor independent code will have arranged for us to see the | |
7198 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 7199 | if (h->u.weakdef != NULL) |
252b5132 | 7200 | { |
f6e332e6 AM |
7201 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
7202 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
7203 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
7204 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
b34976b6 | 7205 | return TRUE; |
252b5132 RH |
7206 | } |
7207 | ||
ba93b8ac DJ |
7208 | /* If there are no non-GOT references, we do not need a copy |
7209 | relocation. */ | |
7210 | if (!h->non_got_ref) | |
7211 | return TRUE; | |
7212 | ||
252b5132 RH |
7213 | /* This is a reference to a symbol defined by a dynamic object which |
7214 | is not a function. */ | |
7215 | ||
7216 | /* If we are creating a shared library, we must presume that the | |
7217 | only references to the symbol are via the global offset table. | |
7218 | For such cases we need not do anything here; the relocations will | |
67687978 PB |
7219 | be handled correctly by relocate_section. Relocatable executables |
7220 | can reference data in shared objects directly, so we don't need to | |
7221 | do anything here. */ | |
7222 | if (info->shared || globals->root.is_relocatable_executable) | |
b34976b6 | 7223 | return TRUE; |
252b5132 | 7224 | |
909272ee AM |
7225 | if (h->size == 0) |
7226 | { | |
7227 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
7228 | h->root.root.string); | |
7229 | return TRUE; | |
7230 | } | |
7231 | ||
252b5132 RH |
7232 | /* We must allocate the symbol in our .dynbss section, which will |
7233 | become part of the .bss section of the executable. There will be | |
7234 | an entry for this symbol in the .dynsym section. The dynamic | |
7235 | object will contain position independent code, so all references | |
7236 | from the dynamic object to this symbol will go through the global | |
7237 | offset table. The dynamic linker will use the .dynsym entry to | |
7238 | determine the address it must put in the global offset table, so | |
7239 | both the dynamic object and the regular object will refer to the | |
7240 | same memory location for the variable. */ | |
252b5132 RH |
7241 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
7242 | BFD_ASSERT (s != NULL); | |
7243 | ||
7244 | /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to | |
7245 | copy the initial value out of the dynamic object and into the | |
7246 | runtime process image. We need to remember the offset into the | |
00a97672 | 7247 | .rel(a).bss section we are going to use. */ |
252b5132 RH |
7248 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
7249 | { | |
7250 | asection *srel; | |
7251 | ||
00a97672 | 7252 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss")); |
252b5132 | 7253 | BFD_ASSERT (srel != NULL); |
00a97672 | 7254 | srel->size += RELOC_SIZE (globals); |
f5385ebf | 7255 | h->needs_copy = 1; |
252b5132 RH |
7256 | } |
7257 | ||
7258 | /* We need to figure out the alignment required for this symbol. I | |
7259 | have no idea how ELF linkers handle this. */ | |
7260 | power_of_two = bfd_log2 (h->size); | |
7261 | if (power_of_two > 3) | |
7262 | power_of_two = 3; | |
7263 | ||
7264 | /* Apply the required alignment. */ | |
eea6121a | 7265 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
252b5132 RH |
7266 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
7267 | { | |
7268 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 7269 | return FALSE; |
252b5132 RH |
7270 | } |
7271 | ||
7272 | /* Define the symbol as being at this point in the section. */ | |
7273 | h->root.u.def.section = s; | |
eea6121a | 7274 | h->root.u.def.value = s->size; |
252b5132 RH |
7275 | |
7276 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 7277 | s->size += h->size; |
252b5132 | 7278 | |
b34976b6 | 7279 | return TRUE; |
252b5132 RH |
7280 | } |
7281 | ||
5e681ec4 PB |
7282 | /* Allocate space in .plt, .got and associated reloc sections for |
7283 | dynamic relocs. */ | |
7284 | ||
7285 | static bfd_boolean | |
57e8b36a | 7286 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
5e681ec4 PB |
7287 | { |
7288 | struct bfd_link_info *info; | |
7289 | struct elf32_arm_link_hash_table *htab; | |
7290 | struct elf32_arm_link_hash_entry *eh; | |
7291 | struct elf32_arm_relocs_copied *p; | |
7292 | ||
b7693d02 DJ |
7293 | eh = (struct elf32_arm_link_hash_entry *) h; |
7294 | ||
5e681ec4 PB |
7295 | if (h->root.type == bfd_link_hash_indirect) |
7296 | return TRUE; | |
7297 | ||
7298 | if (h->root.type == bfd_link_hash_warning) | |
7299 | /* When warning symbols are created, they **replace** the "real" | |
7300 | entry in the hash table, thus we never get to see the real | |
7301 | symbol in a hash traversal. So look at it now. */ | |
7302 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7303 | ||
7304 | info = (struct bfd_link_info *) inf; | |
7305 | htab = elf32_arm_hash_table (info); | |
7306 | ||
7307 | if (htab->root.dynamic_sections_created | |
7308 | && h->plt.refcount > 0) | |
7309 | { | |
7310 | /* Make sure this symbol is output as a dynamic symbol. | |
7311 | Undefined weak syms won't yet be marked as dynamic. */ | |
7312 | if (h->dynindx == -1 | |
f5385ebf | 7313 | && !h->forced_local) |
5e681ec4 | 7314 | { |
c152c796 | 7315 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
7316 | return FALSE; |
7317 | } | |
7318 | ||
7319 | if (info->shared | |
7359ea65 | 7320 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
5e681ec4 PB |
7321 | { |
7322 | asection *s = htab->splt; | |
7323 | ||
7324 | /* If this is the first .plt entry, make room for the special | |
7325 | first entry. */ | |
eea6121a | 7326 | if (s->size == 0) |
e5a52504 | 7327 | s->size += htab->plt_header_size; |
5e681ec4 | 7328 | |
eea6121a | 7329 | h->plt.offset = s->size; |
5e681ec4 | 7330 | |
b7693d02 DJ |
7331 | /* If we will insert a Thumb trampoline before this PLT, leave room |
7332 | for it. */ | |
33bfe774 | 7333 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) |
b7693d02 DJ |
7334 | { |
7335 | h->plt.offset += PLT_THUMB_STUB_SIZE; | |
7336 | s->size += PLT_THUMB_STUB_SIZE; | |
7337 | } | |
7338 | ||
5e681ec4 PB |
7339 | /* If this symbol is not defined in a regular file, and we are |
7340 | not generating a shared library, then set the symbol to this | |
7341 | location in the .plt. This is required to make function | |
7342 | pointers compare as equal between the normal executable and | |
7343 | the shared library. */ | |
7344 | if (! info->shared | |
f5385ebf | 7345 | && !h->def_regular) |
5e681ec4 PB |
7346 | { |
7347 | h->root.u.def.section = s; | |
7348 | h->root.u.def.value = h->plt.offset; | |
b7693d02 DJ |
7349 | |
7350 | /* Make sure the function is not marked as Thumb, in case | |
7351 | it is the target of an ABS32 relocation, which will | |
7352 | point to the PLT entry. */ | |
7353 | if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) | |
7354 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); | |
5e681ec4 PB |
7355 | } |
7356 | ||
7357 | /* Make room for this entry. */ | |
e5a52504 | 7358 | s->size += htab->plt_entry_size; |
5e681ec4 | 7359 | |
e5a52504 | 7360 | if (!htab->symbian_p) |
b7693d02 DJ |
7361 | { |
7362 | /* We also need to make an entry in the .got.plt section, which | |
7363 | will be placed in the .got section by the linker script. */ | |
7364 | eh->plt_got_offset = htab->sgotplt->size; | |
7365 | htab->sgotplt->size += 4; | |
7366 | } | |
5e681ec4 | 7367 | |
00a97672 RS |
7368 | /* We also need to make an entry in the .rel(a).plt section. */ |
7369 | htab->srelplt->size += RELOC_SIZE (htab); | |
7370 | ||
7371 | /* VxWorks executables have a second set of relocations for | |
7372 | each PLT entry. They go in a separate relocation section, | |
7373 | which is processed by the kernel loader. */ | |
7374 | if (htab->vxworks_p && !info->shared) | |
7375 | { | |
7376 | /* There is a relocation for the initial PLT entry: | |
7377 | an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */ | |
7378 | if (h->plt.offset == htab->plt_header_size) | |
7379 | htab->srelplt2->size += RELOC_SIZE (htab); | |
7380 | ||
7381 | /* There are two extra relocations for each subsequent | |
7382 | PLT entry: an R_ARM_32 relocation for the GOT entry, | |
7383 | and an R_ARM_32 relocation for the PLT entry. */ | |
7384 | htab->srelplt2->size += RELOC_SIZE (htab) * 2; | |
7385 | } | |
5e681ec4 PB |
7386 | } |
7387 | else | |
7388 | { | |
7389 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 7390 | h->needs_plt = 0; |
5e681ec4 PB |
7391 | } |
7392 | } | |
7393 | else | |
7394 | { | |
7395 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 7396 | h->needs_plt = 0; |
5e681ec4 PB |
7397 | } |
7398 | ||
7399 | if (h->got.refcount > 0) | |
7400 | { | |
7401 | asection *s; | |
7402 | bfd_boolean dyn; | |
ba93b8ac DJ |
7403 | int tls_type = elf32_arm_hash_entry (h)->tls_type; |
7404 | int indx; | |
5e681ec4 PB |
7405 | |
7406 | /* Make sure this symbol is output as a dynamic symbol. | |
7407 | Undefined weak syms won't yet be marked as dynamic. */ | |
7408 | if (h->dynindx == -1 | |
f5385ebf | 7409 | && !h->forced_local) |
5e681ec4 | 7410 | { |
c152c796 | 7411 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
7412 | return FALSE; |
7413 | } | |
7414 | ||
e5a52504 MM |
7415 | if (!htab->symbian_p) |
7416 | { | |
7417 | s = htab->sgot; | |
7418 | h->got.offset = s->size; | |
ba93b8ac DJ |
7419 | |
7420 | if (tls_type == GOT_UNKNOWN) | |
7421 | abort (); | |
7422 | ||
7423 | if (tls_type == GOT_NORMAL) | |
7424 | /* Non-TLS symbols need one GOT slot. */ | |
7425 | s->size += 4; | |
7426 | else | |
7427 | { | |
7428 | if (tls_type & GOT_TLS_GD) | |
7429 | /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */ | |
7430 | s->size += 8; | |
7431 | if (tls_type & GOT_TLS_IE) | |
7432 | /* R_ARM_TLS_IE32 needs one GOT slot. */ | |
7433 | s->size += 4; | |
7434 | } | |
7435 | ||
e5a52504 | 7436 | dyn = htab->root.dynamic_sections_created; |
ba93b8ac DJ |
7437 | |
7438 | indx = 0; | |
7439 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
7440 | && (!info->shared | |
7441 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
7442 | indx = h->dynindx; | |
7443 | ||
7444 | if (tls_type != GOT_NORMAL | |
7445 | && (info->shared || indx != 0) | |
7446 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
7447 | || h->root.type != bfd_link_hash_undefweak)) | |
7448 | { | |
7449 | if (tls_type & GOT_TLS_IE) | |
00a97672 | 7450 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7451 | |
7452 | if (tls_type & GOT_TLS_GD) | |
00a97672 | 7453 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7454 | |
7455 | if ((tls_type & GOT_TLS_GD) && indx != 0) | |
00a97672 | 7456 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7457 | } |
7458 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
7459 | || h->root.type != bfd_link_hash_undefweak) | |
7460 | && (info->shared | |
7461 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
00a97672 | 7462 | htab->srelgot->size += RELOC_SIZE (htab); |
e5a52504 | 7463 | } |
5e681ec4 PB |
7464 | } |
7465 | else | |
7466 | h->got.offset = (bfd_vma) -1; | |
7467 | ||
5e681ec4 PB |
7468 | if (eh->relocs_copied == NULL) |
7469 | return TRUE; | |
7470 | ||
7471 | /* In the shared -Bsymbolic case, discard space allocated for | |
7472 | dynamic pc-relative relocs against symbols which turn out to be | |
7473 | defined in regular objects. For the normal shared case, discard | |
7474 | space for pc-relative relocs that have become local due to symbol | |
7475 | visibility changes. */ | |
7476 | ||
67687978 | 7477 | if (info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 7478 | { |
ba93b8ac DJ |
7479 | /* The only reloc that uses pc_count is R_ARM_REL32, which will |
7480 | appear on something like ".long foo - .". We want calls to | |
7481 | protected symbols to resolve directly to the function rather | |
7482 | than going via the plt. If people want function pointer | |
7483 | comparisons to work as expected then they should avoid | |
7484 | writing assembly like ".long foo - .". */ | |
7485 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
7486 | { | |
7487 | struct elf32_arm_relocs_copied **pp; | |
7488 | ||
7489 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; ) | |
7490 | { | |
7491 | p->count -= p->pc_count; | |
7492 | p->pc_count = 0; | |
7493 | if (p->count == 0) | |
7494 | *pp = p->next; | |
7495 | else | |
7496 | pp = &p->next; | |
7497 | } | |
7498 | } | |
7499 | ||
7500 | /* Also discard relocs on undefined weak syms with non-default | |
7359ea65 | 7501 | visibility. */ |
22d606e9 | 7502 | if (eh->relocs_copied != NULL |
5e681ec4 | 7503 | && h->root.type == bfd_link_hash_undefweak) |
22d606e9 AM |
7504 | { |
7505 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
7506 | eh->relocs_copied = NULL; | |
7507 | ||
7508 | /* Make sure undefined weak symbols are output as a dynamic | |
7509 | symbol in PIEs. */ | |
7510 | else if (h->dynindx == -1 | |
7511 | && !h->forced_local) | |
7512 | { | |
7513 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
7514 | return FALSE; | |
7515 | } | |
7516 | } | |
7517 | ||
67687978 PB |
7518 | else if (htab->root.is_relocatable_executable && h->dynindx == -1 |
7519 | && h->root.type == bfd_link_hash_new) | |
7520 | { | |
7521 | /* Output absolute symbols so that we can create relocations | |
7522 | against them. For normal symbols we output a relocation | |
7523 | against the section that contains them. */ | |
7524 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
7525 | return FALSE; | |
7526 | } | |
7527 | ||
5e681ec4 PB |
7528 | } |
7529 | else | |
7530 | { | |
7531 | /* For the non-shared case, discard space for relocs against | |
7532 | symbols which turn out to need copy relocs or are not | |
7533 | dynamic. */ | |
7534 | ||
f5385ebf AM |
7535 | if (!h->non_got_ref |
7536 | && ((h->def_dynamic | |
7537 | && !h->def_regular) | |
5e681ec4 PB |
7538 | || (htab->root.dynamic_sections_created |
7539 | && (h->root.type == bfd_link_hash_undefweak | |
7540 | || h->root.type == bfd_link_hash_undefined)))) | |
7541 | { | |
7542 | /* Make sure this symbol is output as a dynamic symbol. | |
7543 | Undefined weak syms won't yet be marked as dynamic. */ | |
7544 | if (h->dynindx == -1 | |
f5385ebf | 7545 | && !h->forced_local) |
5e681ec4 | 7546 | { |
c152c796 | 7547 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
7548 | return FALSE; |
7549 | } | |
7550 | ||
7551 | /* If that succeeded, we know we'll be keeping all the | |
7552 | relocs. */ | |
7553 | if (h->dynindx != -1) | |
7554 | goto keep; | |
7555 | } | |
7556 | ||
7557 | eh->relocs_copied = NULL; | |
7558 | ||
7559 | keep: ; | |
7560 | } | |
7561 | ||
7562 | /* Finally, allocate space. */ | |
7563 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
7564 | { | |
7565 | asection *sreloc = elf_section_data (p->section)->sreloc; | |
00a97672 | 7566 | sreloc->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
7567 | } |
7568 | ||
7569 | return TRUE; | |
7570 | } | |
7571 | ||
08d1f311 DJ |
7572 | /* Find any dynamic relocs that apply to read-only sections. */ |
7573 | ||
7574 | static bfd_boolean | |
7575 | elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf) | |
7576 | { | |
7577 | struct elf32_arm_link_hash_entry *eh; | |
7578 | struct elf32_arm_relocs_copied *p; | |
7579 | ||
7580 | if (h->root.type == bfd_link_hash_warning) | |
7581 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7582 | ||
7583 | eh = (struct elf32_arm_link_hash_entry *) h; | |
7584 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
7585 | { | |
7586 | asection *s = p->section; | |
7587 | ||
7588 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
7589 | { | |
7590 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
7591 | ||
7592 | info->flags |= DF_TEXTREL; | |
7593 | ||
7594 | /* Not an error, just cut short the traversal. */ | |
7595 | return FALSE; | |
7596 | } | |
7597 | } | |
7598 | return TRUE; | |
7599 | } | |
7600 | ||
252b5132 RH |
7601 | /* Set the sizes of the dynamic sections. */ |
7602 | ||
b34976b6 | 7603 | static bfd_boolean |
57e8b36a NC |
7604 | elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, |
7605 | struct bfd_link_info * info) | |
252b5132 RH |
7606 | { |
7607 | bfd * dynobj; | |
7608 | asection * s; | |
b34976b6 AM |
7609 | bfd_boolean plt; |
7610 | bfd_boolean relocs; | |
5e681ec4 PB |
7611 | bfd *ibfd; |
7612 | struct elf32_arm_link_hash_table *htab; | |
252b5132 | 7613 | |
5e681ec4 | 7614 | htab = elf32_arm_hash_table (info); |
252b5132 RH |
7615 | dynobj = elf_hash_table (info)->dynobj; |
7616 | BFD_ASSERT (dynobj != NULL); | |
39b41c9c | 7617 | check_use_blx (htab); |
252b5132 RH |
7618 | |
7619 | if (elf_hash_table (info)->dynamic_sections_created) | |
7620 | { | |
7621 | /* Set the contents of the .interp section to the interpreter. */ | |
893c4fe2 | 7622 | if (info->executable) |
252b5132 RH |
7623 | { |
7624 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
7625 | BFD_ASSERT (s != NULL); | |
eea6121a | 7626 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
252b5132 RH |
7627 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
7628 | } | |
7629 | } | |
5e681ec4 PB |
7630 | |
7631 | /* Set up .got offsets for local syms, and space for local dynamic | |
7632 | relocs. */ | |
7633 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
252b5132 | 7634 | { |
5e681ec4 PB |
7635 | bfd_signed_vma *local_got; |
7636 | bfd_signed_vma *end_local_got; | |
7637 | char *local_tls_type; | |
7638 | bfd_size_type locsymcount; | |
7639 | Elf_Internal_Shdr *symtab_hdr; | |
7640 | asection *srel; | |
7641 | ||
7642 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
7643 | continue; | |
7644 | ||
7645 | for (s = ibfd->sections; s != NULL; s = s->next) | |
7646 | { | |
7647 | struct elf32_arm_relocs_copied *p; | |
7648 | ||
6edfbbad | 7649 | for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) |
5e681ec4 PB |
7650 | { |
7651 | if (!bfd_is_abs_section (p->section) | |
7652 | && bfd_is_abs_section (p->section->output_section)) | |
7653 | { | |
7654 | /* Input section has been discarded, either because | |
7655 | it is a copy of a linkonce section or due to | |
7656 | linker script /DISCARD/, so we'll be discarding | |
7657 | the relocs too. */ | |
7658 | } | |
7659 | else if (p->count != 0) | |
7660 | { | |
7661 | srel = elf_section_data (p->section)->sreloc; | |
00a97672 | 7662 | srel->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
7663 | if ((p->section->output_section->flags & SEC_READONLY) != 0) |
7664 | info->flags |= DF_TEXTREL; | |
7665 | } | |
7666 | } | |
7667 | } | |
7668 | ||
7669 | local_got = elf_local_got_refcounts (ibfd); | |
7670 | if (!local_got) | |
7671 | continue; | |
7672 | ||
7673 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
7674 | locsymcount = symtab_hdr->sh_info; | |
7675 | end_local_got = local_got + locsymcount; | |
ba93b8ac | 7676 | local_tls_type = elf32_arm_local_got_tls_type (ibfd); |
5e681ec4 PB |
7677 | s = htab->sgot; |
7678 | srel = htab->srelgot; | |
7679 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) | |
7680 | { | |
7681 | if (*local_got > 0) | |
7682 | { | |
eea6121a | 7683 | *local_got = s->size; |
ba93b8ac DJ |
7684 | if (*local_tls_type & GOT_TLS_GD) |
7685 | /* TLS_GD relocs need an 8-byte structure in the GOT. */ | |
7686 | s->size += 8; | |
7687 | if (*local_tls_type & GOT_TLS_IE) | |
7688 | s->size += 4; | |
7689 | if (*local_tls_type == GOT_NORMAL) | |
7690 | s->size += 4; | |
7691 | ||
7692 | if (info->shared || *local_tls_type == GOT_TLS_GD) | |
00a97672 | 7693 | srel->size += RELOC_SIZE (htab); |
5e681ec4 PB |
7694 | } |
7695 | else | |
7696 | *local_got = (bfd_vma) -1; | |
7697 | } | |
252b5132 RH |
7698 | } |
7699 | ||
ba93b8ac DJ |
7700 | if (htab->tls_ldm_got.refcount > 0) |
7701 | { | |
7702 | /* Allocate two GOT entries and one dynamic relocation (if necessary) | |
7703 | for R_ARM_TLS_LDM32 relocations. */ | |
7704 | htab->tls_ldm_got.offset = htab->sgot->size; | |
7705 | htab->sgot->size += 8; | |
7706 | if (info->shared) | |
00a97672 | 7707 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
7708 | } |
7709 | else | |
7710 | htab->tls_ldm_got.offset = -1; | |
7711 | ||
5e681ec4 PB |
7712 | /* Allocate global sym .plt and .got entries, and space for global |
7713 | sym dynamic relocs. */ | |
57e8b36a | 7714 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); |
252b5132 RH |
7715 | |
7716 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
7717 | determined the sizes of the various dynamic sections. Allocate | |
7718 | memory for them. */ | |
b34976b6 AM |
7719 | plt = FALSE; |
7720 | relocs = FALSE; | |
252b5132 RH |
7721 | for (s = dynobj->sections; s != NULL; s = s->next) |
7722 | { | |
7723 | const char * name; | |
252b5132 RH |
7724 | |
7725 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
7726 | continue; | |
7727 | ||
7728 | /* It's OK to base decisions on the section name, because none | |
7729 | of the dynobj section names depend upon the input files. */ | |
7730 | name = bfd_get_section_name (dynobj, s); | |
7731 | ||
24a1ba0f | 7732 | if (strcmp (name, ".plt") == 0) |
252b5132 | 7733 | { |
c456f082 AM |
7734 | /* Remember whether there is a PLT. */ |
7735 | plt = s->size != 0; | |
252b5132 RH |
7736 | } |
7737 | else if (strncmp (name, ".rel", 4) == 0) | |
7738 | { | |
c456f082 | 7739 | if (s->size != 0) |
252b5132 | 7740 | { |
252b5132 | 7741 | /* Remember whether there are any reloc sections other |
00a97672 RS |
7742 | than .rel(a).plt and .rela.plt.unloaded. */ |
7743 | if (s != htab->srelplt && s != htab->srelplt2) | |
b34976b6 | 7744 | relocs = TRUE; |
252b5132 RH |
7745 | |
7746 | /* We use the reloc_count field as a counter if we need | |
7747 | to copy relocs into the output file. */ | |
7748 | s->reloc_count = 0; | |
7749 | } | |
7750 | } | |
c456f082 AM |
7751 | else if (strncmp (name, ".got", 4) != 0 |
7752 | && strcmp (name, ".dynbss") != 0) | |
252b5132 RH |
7753 | { |
7754 | /* It's not one of our sections, so don't allocate space. */ | |
7755 | continue; | |
7756 | } | |
7757 | ||
c456f082 | 7758 | if (s->size == 0) |
252b5132 | 7759 | { |
c456f082 | 7760 | /* If we don't need this section, strip it from the |
00a97672 RS |
7761 | output file. This is mostly to handle .rel(a).bss and |
7762 | .rel(a).plt. We must create both sections in | |
c456f082 AM |
7763 | create_dynamic_sections, because they must be created |
7764 | before the linker maps input sections to output | |
7765 | sections. The linker does that before | |
7766 | adjust_dynamic_symbol is called, and it is that | |
7767 | function which decides whether anything needs to go | |
7768 | into these sections. */ | |
8423293d | 7769 | s->flags |= SEC_EXCLUDE; |
252b5132 RH |
7770 | continue; |
7771 | } | |
7772 | ||
c456f082 AM |
7773 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
7774 | continue; | |
7775 | ||
252b5132 | 7776 | /* Allocate memory for the section contents. */ |
eea6121a | 7777 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
c456f082 | 7778 | if (s->contents == NULL) |
b34976b6 | 7779 | return FALSE; |
252b5132 RH |
7780 | } |
7781 | ||
7782 | if (elf_hash_table (info)->dynamic_sections_created) | |
7783 | { | |
7784 | /* Add some entries to the .dynamic section. We fill in the | |
7785 | values later, in elf32_arm_finish_dynamic_sections, but we | |
7786 | must add the entries now so that we get the correct size for | |
7787 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
7788 | dynamic linker and used by the debugger. */ | |
dc810e39 | 7789 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 7790 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 7791 | |
8532796c | 7792 | if (info->executable) |
252b5132 | 7793 | { |
dc810e39 | 7794 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 7795 | return FALSE; |
252b5132 RH |
7796 | } |
7797 | ||
7798 | if (plt) | |
7799 | { | |
dc810e39 AM |
7800 | if ( !add_dynamic_entry (DT_PLTGOT, 0) |
7801 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
00a97672 RS |
7802 | || !add_dynamic_entry (DT_PLTREL, |
7803 | htab->use_rel ? DT_REL : DT_RELA) | |
dc810e39 | 7804 | || !add_dynamic_entry (DT_JMPREL, 0)) |
b34976b6 | 7805 | return FALSE; |
252b5132 RH |
7806 | } |
7807 | ||
7808 | if (relocs) | |
7809 | { | |
00a97672 RS |
7810 | if (htab->use_rel) |
7811 | { | |
7812 | if (!add_dynamic_entry (DT_REL, 0) | |
7813 | || !add_dynamic_entry (DT_RELSZ, 0) | |
7814 | || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab))) | |
7815 | return FALSE; | |
7816 | } | |
7817 | else | |
7818 | { | |
7819 | if (!add_dynamic_entry (DT_RELA, 0) | |
7820 | || !add_dynamic_entry (DT_RELASZ, 0) | |
7821 | || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab))) | |
7822 | return FALSE; | |
7823 | } | |
252b5132 RH |
7824 | } |
7825 | ||
08d1f311 DJ |
7826 | /* If any dynamic relocs apply to a read-only section, |
7827 | then we need a DT_TEXTREL entry. */ | |
7828 | if ((info->flags & DF_TEXTREL) == 0) | |
7829 | elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, | |
7830 | (PTR) info); | |
7831 | ||
99e4ae17 | 7832 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 7833 | { |
dc810e39 | 7834 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 7835 | return FALSE; |
252b5132 RH |
7836 | } |
7837 | } | |
8532796c | 7838 | #undef add_dynamic_entry |
252b5132 | 7839 | |
b34976b6 | 7840 | return TRUE; |
252b5132 RH |
7841 | } |
7842 | ||
252b5132 RH |
7843 | /* Finish up dynamic symbol handling. We set the contents of various |
7844 | dynamic sections here. */ | |
7845 | ||
b34976b6 | 7846 | static bfd_boolean |
57e8b36a NC |
7847 | elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, |
7848 | struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) | |
252b5132 RH |
7849 | { |
7850 | bfd * dynobj; | |
e5a52504 | 7851 | struct elf32_arm_link_hash_table *htab; |
b7693d02 | 7852 | struct elf32_arm_link_hash_entry *eh; |
252b5132 RH |
7853 | |
7854 | dynobj = elf_hash_table (info)->dynobj; | |
e5a52504 | 7855 | htab = elf32_arm_hash_table (info); |
b7693d02 | 7856 | eh = (struct elf32_arm_link_hash_entry *) h; |
252b5132 RH |
7857 | |
7858 | if (h->plt.offset != (bfd_vma) -1) | |
7859 | { | |
7860 | asection * splt; | |
252b5132 | 7861 | asection * srel; |
e5a52504 | 7862 | bfd_byte *loc; |
24a1ba0f | 7863 | bfd_vma plt_index; |
947216bf | 7864 | Elf_Internal_Rela rel; |
252b5132 RH |
7865 | |
7866 | /* This symbol has an entry in the procedure linkage table. Set | |
7867 | it up. */ | |
7868 | ||
7869 | BFD_ASSERT (h->dynindx != -1); | |
7870 | ||
7871 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 | 7872 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt")); |
e5a52504 | 7873 | BFD_ASSERT (splt != NULL && srel != NULL); |
252b5132 | 7874 | |
e5a52504 MM |
7875 | /* Fill in the entry in the procedure linkage table. */ |
7876 | if (htab->symbian_p) | |
7877 | { | |
52ab56c2 PB |
7878 | put_arm_insn (htab, output_bfd, |
7879 | elf32_arm_symbian_plt_entry[0], | |
7880 | splt->contents + h->plt.offset); | |
7881 | bfd_put_32 (output_bfd, | |
7882 | elf32_arm_symbian_plt_entry[1], | |
7883 | splt->contents + h->plt.offset + 4); | |
e5a52504 MM |
7884 | |
7885 | /* Fill in the entry in the .rel.plt section. */ | |
2a1b9a48 MM |
7886 | rel.r_offset = (splt->output_section->vma |
7887 | + splt->output_offset | |
52ab56c2 | 7888 | + h->plt.offset + 4); |
e5a52504 | 7889 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
b7693d02 DJ |
7890 | |
7891 | /* Get the index in the procedure linkage table which | |
7892 | corresponds to this symbol. This is the index of this symbol | |
7893 | in all the symbols for which we are making plt entries. The | |
7894 | first entry in the procedure linkage table is reserved. */ | |
7895 | plt_index = ((h->plt.offset - htab->plt_header_size) | |
7896 | / htab->plt_entry_size); | |
e5a52504 MM |
7897 | } |
7898 | else | |
7899 | { | |
00a97672 | 7900 | bfd_vma got_offset, got_address, plt_address; |
e5a52504 MM |
7901 | bfd_vma got_displacement; |
7902 | asection * sgot; | |
52ab56c2 | 7903 | bfd_byte * ptr; |
e5a52504 MM |
7904 | |
7905 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
7906 | BFD_ASSERT (sgot != NULL); | |
7907 | ||
b7693d02 DJ |
7908 | /* Get the offset into the .got.plt table of the entry that |
7909 | corresponds to this function. */ | |
7910 | got_offset = eh->plt_got_offset; | |
7911 | ||
7912 | /* Get the index in the procedure linkage table which | |
7913 | corresponds to this symbol. This is the index of this symbol | |
7914 | in all the symbols for which we are making plt entries. The | |
7915 | first three entries in .got.plt are reserved; after that | |
7916 | symbols appear in the same order as in .plt. */ | |
7917 | plt_index = (got_offset - 12) / 4; | |
e5a52504 | 7918 | |
00a97672 RS |
7919 | /* Calculate the address of the GOT entry. */ |
7920 | got_address = (sgot->output_section->vma | |
7921 | + sgot->output_offset | |
7922 | + got_offset); | |
5e681ec4 | 7923 | |
00a97672 RS |
7924 | /* ...and the address of the PLT entry. */ |
7925 | plt_address = (splt->output_section->vma | |
7926 | + splt->output_offset | |
7927 | + h->plt.offset); | |
5e681ec4 | 7928 | |
52ab56c2 | 7929 | ptr = htab->splt->contents + h->plt.offset; |
00a97672 RS |
7930 | if (htab->vxworks_p && info->shared) |
7931 | { | |
7932 | unsigned int i; | |
7933 | bfd_vma val; | |
7934 | ||
52ab56c2 | 7935 | for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4) |
00a97672 RS |
7936 | { |
7937 | val = elf32_arm_vxworks_shared_plt_entry[i]; | |
7938 | if (i == 2) | |
7939 | val |= got_address - sgot->output_section->vma; | |
7940 | if (i == 5) | |
7941 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
7942 | if (i == 2 || i == 5) |
7943 | bfd_put_32 (output_bfd, val, ptr); | |
7944 | else | |
7945 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
7946 | } |
7947 | } | |
7948 | else if (htab->vxworks_p) | |
b7693d02 | 7949 | { |
00a97672 RS |
7950 | unsigned int i; |
7951 | bfd_vma val; | |
7952 | ||
7953 | for (i = 0; i != htab->plt_entry_size / 4; i++) | |
7954 | { | |
7955 | val = elf32_arm_vxworks_exec_plt_entry[i]; | |
7956 | if (i == 2) | |
7957 | val |= got_address; | |
7958 | if (i == 4) | |
7959 | val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2); | |
7960 | if (i == 5) | |
7961 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
7962 | if (i == 2 || i == 5) |
7963 | bfd_put_32 (output_bfd, val, ptr); | |
7964 | else | |
7965 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
7966 | } |
7967 | ||
7968 | loc = (htab->srelplt2->contents | |
7969 | + (plt_index * 2 + 1) * RELOC_SIZE (htab)); | |
7970 | ||
7971 | /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation | |
7972 | referencing the GOT for this PLT entry. */ | |
7973 | rel.r_offset = plt_address + 8; | |
7974 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
7975 | rel.r_addend = got_offset; | |
7976 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
7977 | loc += RELOC_SIZE (htab); | |
7978 | ||
7979 | /* Create the R_ARM_ABS32 relocation referencing the | |
7980 | beginning of the PLT for this GOT entry. */ | |
7981 | rel.r_offset = got_address; | |
7982 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
7983 | rel.r_addend = 0; | |
7984 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
b7693d02 | 7985 | } |
00a97672 RS |
7986 | else |
7987 | { | |
7988 | /* Calculate the displacement between the PLT slot and the | |
7989 | entry in the GOT. The eight-byte offset accounts for the | |
7990 | value produced by adding to pc in the first instruction | |
7991 | of the PLT stub. */ | |
7992 | got_displacement = got_address - (plt_address + 8); | |
b7693d02 | 7993 | |
00a97672 RS |
7994 | BFD_ASSERT ((got_displacement & 0xf0000000) == 0); |
7995 | ||
7996 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) | |
7997 | { | |
52ab56c2 PB |
7998 | put_thumb_insn (htab, output_bfd, |
7999 | elf32_arm_plt_thumb_stub[0], ptr - 4); | |
8000 | put_thumb_insn (htab, output_bfd, | |
8001 | elf32_arm_plt_thumb_stub[1], ptr - 2); | |
00a97672 RS |
8002 | } |
8003 | ||
52ab56c2 PB |
8004 | put_arm_insn (htab, output_bfd, |
8005 | elf32_arm_plt_entry[0] | |
8006 | | ((got_displacement & 0x0ff00000) >> 20), | |
8007 | ptr + 0); | |
8008 | put_arm_insn (htab, output_bfd, | |
8009 | elf32_arm_plt_entry[1] | |
8010 | | ((got_displacement & 0x000ff000) >> 12), | |
8011 | ptr+ 4); | |
8012 | put_arm_insn (htab, output_bfd, | |
8013 | elf32_arm_plt_entry[2] | |
8014 | | (got_displacement & 0x00000fff), | |
8015 | ptr + 8); | |
5e681ec4 | 8016 | #ifdef FOUR_WORD_PLT |
52ab56c2 | 8017 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12); |
5e681ec4 | 8018 | #endif |
00a97672 | 8019 | } |
252b5132 | 8020 | |
e5a52504 MM |
8021 | /* Fill in the entry in the global offset table. */ |
8022 | bfd_put_32 (output_bfd, | |
8023 | (splt->output_section->vma | |
8024 | + splt->output_offset), | |
8025 | sgot->contents + got_offset); | |
8026 | ||
00a97672 RS |
8027 | /* Fill in the entry in the .rel(a).plt section. */ |
8028 | rel.r_addend = 0; | |
8029 | rel.r_offset = got_address; | |
e5a52504 MM |
8030 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); |
8031 | } | |
57e8b36a | 8032 | |
00a97672 RS |
8033 | loc = srel->contents + plt_index * RELOC_SIZE (htab); |
8034 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 | 8035 | |
f5385ebf | 8036 | if (!h->def_regular) |
252b5132 RH |
8037 | { |
8038 | /* Mark the symbol as undefined, rather than as defined in | |
8039 | the .plt section. Leave the value alone. */ | |
8040 | sym->st_shndx = SHN_UNDEF; | |
d982ba73 PB |
8041 | /* If the symbol is weak, we do need to clear the value. |
8042 | Otherwise, the PLT entry would provide a definition for | |
8043 | the symbol even if the symbol wasn't defined anywhere, | |
8044 | and so the symbol would never be NULL. */ | |
f5385ebf | 8045 | if (!h->ref_regular_nonweak) |
d982ba73 | 8046 | sym->st_value = 0; |
252b5132 RH |
8047 | } |
8048 | } | |
8049 | ||
ba93b8ac DJ |
8050 | if (h->got.offset != (bfd_vma) -1 |
8051 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 | |
8052 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) | |
252b5132 RH |
8053 | { |
8054 | asection * sgot; | |
8055 | asection * srel; | |
947216bf AM |
8056 | Elf_Internal_Rela rel; |
8057 | bfd_byte *loc; | |
00a97672 | 8058 | bfd_vma offset; |
252b5132 RH |
8059 | |
8060 | /* This symbol has an entry in the global offset table. Set it | |
8061 | up. */ | |
252b5132 | 8062 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
00a97672 | 8063 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got")); |
252b5132 RH |
8064 | BFD_ASSERT (sgot != NULL && srel != NULL); |
8065 | ||
00a97672 RS |
8066 | offset = (h->got.offset & ~(bfd_vma) 1); |
8067 | rel.r_addend = 0; | |
252b5132 RH |
8068 | rel.r_offset = (sgot->output_section->vma |
8069 | + sgot->output_offset | |
00a97672 | 8070 | + offset); |
252b5132 | 8071 | |
5e681ec4 PB |
8072 | /* If this is a static link, or it is a -Bsymbolic link and the |
8073 | symbol is defined locally or was forced to be local because | |
8074 | of a version file, we just want to emit a RELATIVE reloc. | |
8075 | The entry in the global offset table will already have been | |
8076 | initialized in the relocate_section function. */ | |
252b5132 | 8077 | if (info->shared |
5e681ec4 PB |
8078 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
8079 | { | |
8080 | BFD_ASSERT((h->got.offset & 1) != 0); | |
8081 | rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
00a97672 RS |
8082 | if (!htab->use_rel) |
8083 | { | |
8084 | rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset); | |
8085 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); | |
8086 | } | |
5e681ec4 | 8087 | } |
252b5132 RH |
8088 | else |
8089 | { | |
5e681ec4 | 8090 | BFD_ASSERT((h->got.offset & 1) == 0); |
00a97672 | 8091 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); |
252b5132 RH |
8092 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
8093 | } | |
8094 | ||
00a97672 RS |
8095 | loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab); |
8096 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
8097 | } |
8098 | ||
f5385ebf | 8099 | if (h->needs_copy) |
252b5132 RH |
8100 | { |
8101 | asection * s; | |
947216bf AM |
8102 | Elf_Internal_Rela rel; |
8103 | bfd_byte *loc; | |
252b5132 RH |
8104 | |
8105 | /* This symbol needs a copy reloc. Set it up. */ | |
252b5132 RH |
8106 | BFD_ASSERT (h->dynindx != -1 |
8107 | && (h->root.type == bfd_link_hash_defined | |
8108 | || h->root.type == bfd_link_hash_defweak)); | |
8109 | ||
8110 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
00a97672 | 8111 | RELOC_SECTION (htab, ".bss")); |
252b5132 RH |
8112 | BFD_ASSERT (s != NULL); |
8113 | ||
00a97672 | 8114 | rel.r_addend = 0; |
252b5132 RH |
8115 | rel.r_offset = (h->root.u.def.value |
8116 | + h->root.u.def.section->output_section->vma | |
8117 | + h->root.u.def.section->output_offset); | |
8118 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); | |
00a97672 RS |
8119 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); |
8120 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
8121 | } |
8122 | ||
00a97672 RS |
8123 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks, |
8124 | the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative | |
8125 | to the ".got" section. */ | |
252b5132 | 8126 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
00a97672 | 8127 | || (!htab->vxworks_p && h == htab->root.hgot)) |
252b5132 RH |
8128 | sym->st_shndx = SHN_ABS; |
8129 | ||
b34976b6 | 8130 | return TRUE; |
252b5132 RH |
8131 | } |
8132 | ||
8133 | /* Finish up the dynamic sections. */ | |
8134 | ||
b34976b6 | 8135 | static bfd_boolean |
57e8b36a | 8136 | elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) |
252b5132 RH |
8137 | { |
8138 | bfd * dynobj; | |
8139 | asection * sgot; | |
8140 | asection * sdyn; | |
8141 | ||
8142 | dynobj = elf_hash_table (info)->dynobj; | |
8143 | ||
8144 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
229fcec5 | 8145 | BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); |
252b5132 RH |
8146 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
8147 | ||
8148 | if (elf_hash_table (info)->dynamic_sections_created) | |
8149 | { | |
8150 | asection *splt; | |
8151 | Elf32_External_Dyn *dyncon, *dynconend; | |
229fcec5 | 8152 | struct elf32_arm_link_hash_table *htab; |
252b5132 | 8153 | |
229fcec5 | 8154 | htab = elf32_arm_hash_table (info); |
252b5132 | 8155 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
24a1ba0f | 8156 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
252b5132 RH |
8157 | |
8158 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 8159 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
9b485d32 | 8160 | |
252b5132 RH |
8161 | for (; dyncon < dynconend; dyncon++) |
8162 | { | |
8163 | Elf_Internal_Dyn dyn; | |
8164 | const char * name; | |
8165 | asection * s; | |
8166 | ||
8167 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
8168 | ||
8169 | switch (dyn.d_tag) | |
8170 | { | |
229fcec5 MM |
8171 | unsigned int type; |
8172 | ||
252b5132 RH |
8173 | default: |
8174 | break; | |
8175 | ||
229fcec5 MM |
8176 | case DT_HASH: |
8177 | name = ".hash"; | |
8178 | goto get_vma_if_bpabi; | |
8179 | case DT_STRTAB: | |
8180 | name = ".dynstr"; | |
8181 | goto get_vma_if_bpabi; | |
8182 | case DT_SYMTAB: | |
8183 | name = ".dynsym"; | |
8184 | goto get_vma_if_bpabi; | |
c0042f5d MM |
8185 | case DT_VERSYM: |
8186 | name = ".gnu.version"; | |
8187 | goto get_vma_if_bpabi; | |
8188 | case DT_VERDEF: | |
8189 | name = ".gnu.version_d"; | |
8190 | goto get_vma_if_bpabi; | |
8191 | case DT_VERNEED: | |
8192 | name = ".gnu.version_r"; | |
8193 | goto get_vma_if_bpabi; | |
8194 | ||
252b5132 RH |
8195 | case DT_PLTGOT: |
8196 | name = ".got"; | |
8197 | goto get_vma; | |
8198 | case DT_JMPREL: | |
00a97672 | 8199 | name = RELOC_SECTION (htab, ".plt"); |
252b5132 RH |
8200 | get_vma: |
8201 | s = bfd_get_section_by_name (output_bfd, name); | |
8202 | BFD_ASSERT (s != NULL); | |
229fcec5 MM |
8203 | if (!htab->symbian_p) |
8204 | dyn.d_un.d_ptr = s->vma; | |
8205 | else | |
8206 | /* In the BPABI, tags in the PT_DYNAMIC section point | |
8207 | at the file offset, not the memory address, for the | |
8208 | convenience of the post linker. */ | |
8209 | dyn.d_un.d_ptr = s->filepos; | |
252b5132 RH |
8210 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
8211 | break; | |
8212 | ||
229fcec5 MM |
8213 | get_vma_if_bpabi: |
8214 | if (htab->symbian_p) | |
8215 | goto get_vma; | |
8216 | break; | |
8217 | ||
252b5132 | 8218 | case DT_PLTRELSZ: |
00a97672 RS |
8219 | s = bfd_get_section_by_name (output_bfd, |
8220 | RELOC_SECTION (htab, ".plt")); | |
252b5132 | 8221 | BFD_ASSERT (s != NULL); |
eea6121a | 8222 | dyn.d_un.d_val = s->size; |
252b5132 RH |
8223 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
8224 | break; | |
229fcec5 | 8225 | |
252b5132 | 8226 | case DT_RELSZ: |
00a97672 | 8227 | case DT_RELASZ: |
229fcec5 MM |
8228 | if (!htab->symbian_p) |
8229 | { | |
8230 | /* My reading of the SVR4 ABI indicates that the | |
8231 | procedure linkage table relocs (DT_JMPREL) should be | |
8232 | included in the overall relocs (DT_REL). This is | |
8233 | what Solaris does. However, UnixWare can not handle | |
8234 | that case. Therefore, we override the DT_RELSZ entry | |
8235 | here to make it not include the JMPREL relocs. Since | |
00a97672 | 8236 | the linker script arranges for .rel(a).plt to follow all |
229fcec5 MM |
8237 | other relocation sections, we don't have to worry |
8238 | about changing the DT_REL entry. */ | |
00a97672 RS |
8239 | s = bfd_get_section_by_name (output_bfd, |
8240 | RELOC_SECTION (htab, ".plt")); | |
229fcec5 MM |
8241 | if (s != NULL) |
8242 | dyn.d_un.d_val -= s->size; | |
8243 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
8244 | break; | |
8245 | } | |
8246 | /* Fall through */ | |
8247 | ||
8248 | case DT_REL: | |
8249 | case DT_RELA: | |
229fcec5 MM |
8250 | /* In the BPABI, the DT_REL tag must point at the file |
8251 | offset, not the VMA, of the first relocation | |
8252 | section. So, we use code similar to that in | |
8253 | elflink.c, but do not check for SHF_ALLOC on the | |
8254 | relcoation section, since relocations sections are | |
8255 | never allocated under the BPABI. The comments above | |
8256 | about Unixware notwithstanding, we include all of the | |
8257 | relocations here. */ | |
8258 | if (htab->symbian_p) | |
8259 | { | |
8260 | unsigned int i; | |
8261 | type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) | |
8262 | ? SHT_REL : SHT_RELA); | |
8263 | dyn.d_un.d_val = 0; | |
8264 | for (i = 1; i < elf_numsections (output_bfd); i++) | |
8265 | { | |
8266 | Elf_Internal_Shdr *hdr | |
8267 | = elf_elfsections (output_bfd)[i]; | |
8268 | if (hdr->sh_type == type) | |
8269 | { | |
8270 | if (dyn.d_tag == DT_RELSZ | |
8271 | || dyn.d_tag == DT_RELASZ) | |
8272 | dyn.d_un.d_val += hdr->sh_size; | |
de52dba4 AM |
8273 | else if ((ufile_ptr) hdr->sh_offset |
8274 | <= dyn.d_un.d_val - 1) | |
229fcec5 MM |
8275 | dyn.d_un.d_val = hdr->sh_offset; |
8276 | } | |
8277 | } | |
8278 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
8279 | } | |
252b5132 | 8280 | break; |
88f7bcd5 NC |
8281 | |
8282 | /* Set the bottom bit of DT_INIT/FINI if the | |
8283 | corresponding function is Thumb. */ | |
8284 | case DT_INIT: | |
8285 | name = info->init_function; | |
8286 | goto get_sym; | |
8287 | case DT_FINI: | |
8288 | name = info->fini_function; | |
8289 | get_sym: | |
8290 | /* If it wasn't set by elf_bfd_final_link | |
4cc11e76 | 8291 | then there is nothing to adjust. */ |
88f7bcd5 NC |
8292 | if (dyn.d_un.d_val != 0) |
8293 | { | |
8294 | struct elf_link_hash_entry * eh; | |
8295 | ||
8296 | eh = elf_link_hash_lookup (elf_hash_table (info), name, | |
b34976b6 | 8297 | FALSE, FALSE, TRUE); |
88f7bcd5 NC |
8298 | if (eh != (struct elf_link_hash_entry *) NULL |
8299 | && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) | |
8300 | { | |
8301 | dyn.d_un.d_val |= 1; | |
b34976b6 | 8302 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
88f7bcd5 NC |
8303 | } |
8304 | } | |
8305 | break; | |
252b5132 RH |
8306 | } |
8307 | } | |
8308 | ||
24a1ba0f | 8309 | /* Fill in the first entry in the procedure linkage table. */ |
e5a52504 | 8310 | if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) |
f7a74f8c | 8311 | { |
00a97672 RS |
8312 | const bfd_vma *plt0_entry; |
8313 | bfd_vma got_address, plt_address, got_displacement; | |
8314 | ||
8315 | /* Calculate the addresses of the GOT and PLT. */ | |
8316 | got_address = sgot->output_section->vma + sgot->output_offset; | |
8317 | plt_address = splt->output_section->vma + splt->output_offset; | |
8318 | ||
8319 | if (htab->vxworks_p) | |
8320 | { | |
8321 | /* The VxWorks GOT is relocated by the dynamic linker. | |
8322 | Therefore, we must emit relocations rather than simply | |
8323 | computing the values now. */ | |
8324 | Elf_Internal_Rela rel; | |
8325 | ||
8326 | plt0_entry = elf32_arm_vxworks_exec_plt0_entry; | |
52ab56c2 PB |
8327 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
8328 | splt->contents + 0); | |
8329 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
8330 | splt->contents + 4); | |
8331 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
8332 | splt->contents + 8); | |
00a97672 RS |
8333 | bfd_put_32 (output_bfd, got_address, splt->contents + 12); |
8334 | ||
8335 | /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */ | |
8336 | rel.r_offset = plt_address + 12; | |
8337 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
8338 | rel.r_addend = 0; | |
8339 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, | |
8340 | htab->srelplt2->contents); | |
8341 | } | |
8342 | else | |
8343 | { | |
8344 | got_displacement = got_address - (plt_address + 16); | |
8345 | ||
8346 | plt0_entry = elf32_arm_plt0_entry; | |
52ab56c2 PB |
8347 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
8348 | splt->contents + 0); | |
8349 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
8350 | splt->contents + 4); | |
8351 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
8352 | splt->contents + 8); | |
8353 | put_arm_insn (htab, output_bfd, plt0_entry[3], | |
8354 | splt->contents + 12); | |
5e681ec4 | 8355 | |
5e681ec4 | 8356 | #ifdef FOUR_WORD_PLT |
00a97672 RS |
8357 | /* The displacement value goes in the otherwise-unused |
8358 | last word of the second entry. */ | |
8359 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); | |
5e681ec4 | 8360 | #else |
00a97672 | 8361 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); |
5e681ec4 | 8362 | #endif |
00a97672 | 8363 | } |
f7a74f8c | 8364 | } |
252b5132 RH |
8365 | |
8366 | /* UnixWare sets the entsize of .plt to 4, although that doesn't | |
8367 | really seem like the right value. */ | |
8368 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; | |
00a97672 RS |
8369 | |
8370 | if (htab->vxworks_p && !info->shared && htab->splt->size > 0) | |
8371 | { | |
8372 | /* Correct the .rel(a).plt.unloaded relocations. They will have | |
8373 | incorrect symbol indexes. */ | |
8374 | int num_plts; | |
eed62c48 | 8375 | unsigned char *p; |
00a97672 RS |
8376 | |
8377 | num_plts = ((htab->splt->size - htab->plt_header_size) | |
8378 | / htab->plt_entry_size); | |
8379 | p = htab->srelplt2->contents + RELOC_SIZE (htab); | |
8380 | ||
8381 | for (; num_plts; num_plts--) | |
8382 | { | |
8383 | Elf_Internal_Rela rel; | |
8384 | ||
8385 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
8386 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
8387 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
8388 | p += RELOC_SIZE (htab); | |
8389 | ||
8390 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
8391 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
8392 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
8393 | p += RELOC_SIZE (htab); | |
8394 | } | |
8395 | } | |
252b5132 RH |
8396 | } |
8397 | ||
8398 | /* Fill in the first three entries in the global offset table. */ | |
229fcec5 | 8399 | if (sgot) |
252b5132 | 8400 | { |
229fcec5 MM |
8401 | if (sgot->size > 0) |
8402 | { | |
8403 | if (sdyn == NULL) | |
8404 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
8405 | else | |
8406 | bfd_put_32 (output_bfd, | |
8407 | sdyn->output_section->vma + sdyn->output_offset, | |
8408 | sgot->contents); | |
8409 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
8410 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
8411 | } | |
252b5132 | 8412 | |
229fcec5 MM |
8413 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
8414 | } | |
252b5132 | 8415 | |
b34976b6 | 8416 | return TRUE; |
252b5132 RH |
8417 | } |
8418 | ||
ba96a88f | 8419 | static void |
57e8b36a | 8420 | elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) |
ba96a88f | 8421 | { |
9b485d32 | 8422 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ |
e489d0ae | 8423 | struct elf32_arm_link_hash_table *globals; |
ba96a88f NC |
8424 | |
8425 | i_ehdrp = elf_elfheader (abfd); | |
8426 | ||
94a3258f PB |
8427 | if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN) |
8428 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM; | |
8429 | else | |
8430 | i_ehdrp->e_ident[EI_OSABI] = 0; | |
ba96a88f | 8431 | i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION; |
e489d0ae | 8432 | |
93204d3a PB |
8433 | if (link_info) |
8434 | { | |
8435 | globals = elf32_arm_hash_table (link_info); | |
8436 | if (globals->byteswap_code) | |
8437 | i_ehdrp->e_flags |= EF_ARM_BE8; | |
8438 | } | |
ba96a88f NC |
8439 | } |
8440 | ||
99e4ae17 | 8441 | static enum elf_reloc_type_class |
57e8b36a | 8442 | elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) |
99e4ae17 | 8443 | { |
f51e552e | 8444 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
99e4ae17 AJ |
8445 | { |
8446 | case R_ARM_RELATIVE: | |
8447 | return reloc_class_relative; | |
8448 | case R_ARM_JUMP_SLOT: | |
8449 | return reloc_class_plt; | |
8450 | case R_ARM_COPY: | |
8451 | return reloc_class_copy; | |
8452 | default: | |
8453 | return reloc_class_normal; | |
8454 | } | |
8455 | } | |
8456 | ||
e16bb312 NC |
8457 | /* Set the right machine number for an Arm ELF file. */ |
8458 | ||
8459 | static bfd_boolean | |
57e8b36a | 8460 | elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) |
e16bb312 NC |
8461 | { |
8462 | if (hdr->sh_type == SHT_NOTE) | |
8463 | *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
8464 | ||
8465 | return TRUE; | |
8466 | } | |
8467 | ||
e489d0ae | 8468 | static void |
57e8b36a | 8469 | elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) |
e16bb312 | 8470 | { |
5a6c6817 | 8471 | bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); |
e16bb312 NC |
8472 | } |
8473 | ||
40a18ebd NC |
8474 | /* Return TRUE if this is an unwinding table entry. */ |
8475 | ||
8476 | static bfd_boolean | |
8477 | is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name) | |
8478 | { | |
8479 | size_t len1, len2; | |
8480 | ||
8481 | len1 = sizeof (ELF_STRING_ARM_unwind) - 1; | |
8482 | len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1; | |
8483 | return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0 | |
8484 | || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0); | |
8485 | } | |
8486 | ||
8487 | ||
8488 | /* Set the type and flags for an ARM section. We do this by | |
8489 | the section name, which is a hack, but ought to work. */ | |
8490 | ||
8491 | static bfd_boolean | |
8492 | elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec) | |
8493 | { | |
8494 | const char * name; | |
8495 | ||
8496 | name = bfd_get_section_name (abfd, sec); | |
8497 | ||
8498 | if (is_arm_elf_unwind_section_name (abfd, name)) | |
8499 | { | |
8500 | hdr->sh_type = SHT_ARM_EXIDX; | |
8501 | hdr->sh_flags |= SHF_LINK_ORDER; | |
8502 | } | |
ee065d83 PB |
8503 | else if (strcmp(name, ".ARM.attributes") == 0) |
8504 | { | |
8505 | hdr->sh_type = SHT_ARM_ATTRIBUTES; | |
8506 | } | |
40a18ebd NC |
8507 | return TRUE; |
8508 | } | |
8509 | ||
ee065d83 PB |
8510 | /* Parse an Arm EABI attributes section. */ |
8511 | static void | |
8512 | elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) | |
8513 | { | |
8514 | bfd_byte *contents; | |
8515 | bfd_byte *p; | |
8516 | bfd_vma len; | |
8517 | ||
8518 | contents = bfd_malloc (hdr->sh_size); | |
8519 | if (!contents) | |
8520 | return; | |
8521 | if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0, | |
8522 | hdr->sh_size)) | |
8523 | { | |
8524 | free (contents); | |
8525 | return; | |
8526 | } | |
8527 | p = contents; | |
8528 | if (*(p++) == 'A') | |
8529 | { | |
8530 | len = hdr->sh_size - 1; | |
8531 | while (len > 0) | |
8532 | { | |
8533 | int namelen; | |
8534 | bfd_vma section_len; | |
8535 | ||
8536 | section_len = bfd_get_32 (abfd, p); | |
8537 | p += 4; | |
8538 | if (section_len > len) | |
8539 | section_len = len; | |
8540 | len -= section_len; | |
8541 | namelen = strlen ((char *)p) + 1; | |
8542 | section_len -= namelen + 4; | |
8543 | if (strcmp((char *)p, "aeabi") != 0) | |
8544 | { | |
8545 | /* Vendor section. Ignore it. */ | |
8546 | p += namelen + section_len; | |
8547 | } | |
8548 | else | |
8549 | { | |
8550 | p += namelen; | |
8551 | while (section_len > 0) | |
8552 | { | |
8553 | int tag; | |
8554 | unsigned int n; | |
8555 | unsigned int val; | |
8556 | bfd_vma subsection_len; | |
8557 | bfd_byte *end; | |
8558 | ||
8559 | tag = read_unsigned_leb128 (abfd, p, &n); | |
8560 | p += n; | |
8561 | subsection_len = bfd_get_32 (abfd, p); | |
8562 | p += 4; | |
8563 | if (subsection_len > section_len) | |
8564 | subsection_len = section_len; | |
8565 | section_len -= subsection_len; | |
8566 | subsection_len -= n + 4; | |
8567 | end = p + subsection_len; | |
8568 | switch (tag) | |
8569 | { | |
8570 | case Tag_File: | |
8571 | while (p < end) | |
8572 | { | |
8573 | bfd_boolean is_string; | |
8574 | ||
8575 | tag = read_unsigned_leb128 (abfd, p, &n); | |
8576 | p += n; | |
8577 | if (tag == 4 || tag == 5) | |
8578 | is_string = 1; | |
8579 | else if (tag < 32) | |
8580 | is_string = 0; | |
8581 | else | |
8582 | is_string = (tag & 1) != 0; | |
8583 | if (tag == Tag_compatibility) | |
8584 | { | |
8585 | val = read_unsigned_leb128 (abfd, p, &n); | |
8586 | p += n; | |
8587 | elf32_arm_add_eabi_attr_compat (abfd, val, | |
8588 | (char *)p); | |
8589 | p += strlen ((char *)p) + 1; | |
8590 | } | |
8591 | else if (is_string) | |
8592 | { | |
8593 | elf32_arm_add_eabi_attr_string (abfd, tag, | |
8594 | (char *)p); | |
8595 | p += strlen ((char *)p) + 1; | |
8596 | } | |
8597 | else | |
8598 | { | |
8599 | val = read_unsigned_leb128 (abfd, p, &n); | |
8600 | p += n; | |
8601 | elf32_arm_add_eabi_attr_int (abfd, tag, val); | |
8602 | } | |
8603 | } | |
8604 | break; | |
8605 | case Tag_Section: | |
8606 | case Tag_Symbol: | |
8607 | /* Don't have anywhere convenient to attach these. | |
8608 | Fall through for now. */ | |
8609 | default: | |
8610 | /* Ignore things we don't kow about. */ | |
8611 | p += subsection_len; | |
8612 | subsection_len = 0; | |
8613 | break; | |
8614 | } | |
8615 | } | |
8616 | } | |
8617 | } | |
8618 | } | |
8619 | free (contents); | |
8620 | } | |
8621 | ||
6dc132d9 L |
8622 | /* Handle an ARM specific section when reading an object file. This is |
8623 | called when bfd_section_from_shdr finds a section with an unknown | |
8624 | type. */ | |
40a18ebd NC |
8625 | |
8626 | static bfd_boolean | |
8627 | elf32_arm_section_from_shdr (bfd *abfd, | |
8628 | Elf_Internal_Shdr * hdr, | |
6dc132d9 L |
8629 | const char *name, |
8630 | int shindex) | |
40a18ebd NC |
8631 | { |
8632 | /* There ought to be a place to keep ELF backend specific flags, but | |
8633 | at the moment there isn't one. We just keep track of the | |
8634 | sections by their name, instead. Fortunately, the ABI gives | |
8635 | names for all the ARM specific sections, so we will probably get | |
8636 | away with this. */ | |
8637 | switch (hdr->sh_type) | |
8638 | { | |
8639 | case SHT_ARM_EXIDX: | |
0951f019 RE |
8640 | case SHT_ARM_PREEMPTMAP: |
8641 | case SHT_ARM_ATTRIBUTES: | |
40a18ebd NC |
8642 | break; |
8643 | ||
8644 | default: | |
8645 | return FALSE; | |
8646 | } | |
8647 | ||
6dc132d9 | 8648 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
40a18ebd NC |
8649 | return FALSE; |
8650 | ||
ee065d83 PB |
8651 | if (hdr->sh_type == SHT_ARM_ATTRIBUTES) |
8652 | elf32_arm_parse_attributes(abfd, hdr); | |
40a18ebd NC |
8653 | return TRUE; |
8654 | } | |
e489d0ae | 8655 | |
8e3de13a NC |
8656 | /* A structure used to record a list of sections, independently |
8657 | of the next and prev fields in the asection structure. */ | |
8658 | typedef struct section_list | |
8659 | { | |
8660 | asection * sec; | |
8661 | struct section_list * next; | |
8662 | struct section_list * prev; | |
8663 | } | |
8664 | section_list; | |
8665 | ||
8666 | /* Unfortunately we need to keep a list of sections for which | |
8667 | an _arm_elf_section_data structure has been allocated. This | |
8668 | is because it is possible for functions like elf32_arm_write_section | |
8669 | to be called on a section which has had an elf_data_structure | |
8670 | allocated for it (and so the used_by_bfd field is valid) but | |
8671 | for which the ARM extended version of this structure - the | |
8672 | _arm_elf_section_data structure - has not been allocated. */ | |
8673 | static section_list * sections_with_arm_elf_section_data = NULL; | |
8674 | ||
8675 | static void | |
957c6e41 | 8676 | record_section_with_arm_elf_section_data (asection * sec) |
8e3de13a NC |
8677 | { |
8678 | struct section_list * entry; | |
8679 | ||
957c6e41 | 8680 | entry = bfd_malloc (sizeof (* entry)); |
8e3de13a NC |
8681 | if (entry == NULL) |
8682 | return; | |
8683 | entry->sec = sec; | |
8684 | entry->next = sections_with_arm_elf_section_data; | |
8685 | entry->prev = NULL; | |
8686 | if (entry->next != NULL) | |
8687 | entry->next->prev = entry; | |
8688 | sections_with_arm_elf_section_data = entry; | |
8689 | } | |
8690 | ||
44444f50 NC |
8691 | static struct section_list * |
8692 | find_arm_elf_section_entry (asection * sec) | |
8e3de13a NC |
8693 | { |
8694 | struct section_list * entry; | |
bd4aae00 | 8695 | static struct section_list * last_entry = NULL; |
8e3de13a | 8696 | |
bd4aae00 NC |
8697 | /* This is a short cut for the typical case where the sections are added |
8698 | to the sections_with_arm_elf_section_data list in forward order and | |
8699 | then looked up here in backwards order. This makes a real difference | |
8700 | to the ld-srec/sec64k.exp linker test. */ | |
44444f50 | 8701 | entry = sections_with_arm_elf_section_data; |
bd4aae00 NC |
8702 | if (last_entry != NULL) |
8703 | { | |
8704 | if (last_entry->sec == sec) | |
44444f50 NC |
8705 | entry = last_entry; |
8706 | else if (last_entry->next != NULL | |
8707 | && last_entry->next->sec == sec) | |
8708 | entry = last_entry->next; | |
bd4aae00 | 8709 | } |
44444f50 NC |
8710 | |
8711 | for (; entry; entry = entry->next) | |
8e3de13a | 8712 | if (entry->sec == sec) |
44444f50 | 8713 | break; |
bd4aae00 | 8714 | |
44444f50 NC |
8715 | if (entry) |
8716 | /* Record the entry prior to this one - it is the entry we are most | |
8717 | likely to want to locate next time. Also this way if we have been | |
8718 | called from unrecord_section_with_arm_elf_section_data() we will not | |
8719 | be caching a pointer that is about to be freed. */ | |
8720 | last_entry = entry->prev; | |
8721 | ||
8722 | return entry; | |
8723 | } | |
8724 | ||
8725 | static _arm_elf_section_data * | |
8726 | get_arm_elf_section_data (asection * sec) | |
8727 | { | |
8728 | struct section_list * entry; | |
8729 | ||
8730 | entry = find_arm_elf_section_entry (sec); | |
8731 | ||
8732 | if (entry) | |
8733 | return elf32_arm_section_data (entry->sec); | |
8734 | else | |
8735 | return NULL; | |
8e3de13a NC |
8736 | } |
8737 | ||
8738 | static void | |
8739 | unrecord_section_with_arm_elf_section_data (asection * sec) | |
8740 | { | |
8741 | struct section_list * entry; | |
8742 | ||
44444f50 NC |
8743 | entry = find_arm_elf_section_entry (sec); |
8744 | ||
8745 | if (entry) | |
8746 | { | |
8747 | if (entry->prev != NULL) | |
8748 | entry->prev->next = entry->next; | |
8749 | if (entry->next != NULL) | |
8750 | entry->next->prev = entry->prev; | |
8751 | if (entry == sections_with_arm_elf_section_data) | |
8752 | sections_with_arm_elf_section_data = entry->next; | |
8753 | free (entry); | |
8754 | } | |
8e3de13a NC |
8755 | } |
8756 | ||
e489d0ae PB |
8757 | /* Called for each symbol. Builds a section map based on mapping symbols. |
8758 | Does not alter any of the symbols. */ | |
8759 | ||
8760 | static bfd_boolean | |
8761 | elf32_arm_output_symbol_hook (struct bfd_link_info *info, | |
8762 | const char *name, | |
8763 | Elf_Internal_Sym *elfsym, | |
8764 | asection *input_sec, | |
00a97672 | 8765 | struct elf_link_hash_entry *h) |
e489d0ae PB |
8766 | { |
8767 | int mapcount; | |
8768 | elf32_arm_section_map *map; | |
8e3de13a NC |
8769 | elf32_arm_section_map *newmap; |
8770 | _arm_elf_section_data *arm_data; | |
e489d0ae PB |
8771 | struct elf32_arm_link_hash_table *globals; |
8772 | ||
00a97672 RS |
8773 | globals = elf32_arm_hash_table (info); |
8774 | if (globals->vxworks_p | |
8775 | && !elf_vxworks_link_output_symbol_hook (info, name, elfsym, | |
8776 | input_sec, h)) | |
8777 | return FALSE; | |
8778 | ||
e489d0ae PB |
8779 | /* Only do this on final link. */ |
8780 | if (info->relocatable) | |
8781 | return TRUE; | |
8782 | ||
8783 | /* Only build a map if we need to byteswap code. */ | |
e489d0ae PB |
8784 | if (!globals->byteswap_code) |
8785 | return TRUE; | |
8786 | ||
8787 | /* We only want mapping symbols. */ | |
b0796911 | 8788 | if (!bfd_is_arm_special_symbol_name (name, BFD_ARM_SPECIAL_SYM_TYPE_MAP)) |
e489d0ae PB |
8789 | return TRUE; |
8790 | ||
8e3de13a NC |
8791 | /* If this section has not been allocated an _arm_elf_section_data |
8792 | structure then we cannot record anything. */ | |
8793 | arm_data = get_arm_elf_section_data (input_sec); | |
8794 | if (arm_data == NULL) | |
8795 | return TRUE; | |
8796 | ||
8797 | mapcount = arm_data->mapcount + 1; | |
8798 | map = arm_data->map; | |
d7f735da | 8799 | |
e489d0ae PB |
8800 | /* TODO: This may be inefficient, but we probably don't usually have many |
8801 | mapping symbols per section. */ | |
8e3de13a NC |
8802 | newmap = bfd_realloc (map, mapcount * sizeof (* map)); |
8803 | if (newmap != NULL) | |
8804 | { | |
8805 | arm_data->map = newmap; | |
8806 | arm_data->mapcount = mapcount; | |
8807 | ||
d7f735da NC |
8808 | newmap[mapcount - 1].vma = elfsym->st_value; |
8809 | newmap[mapcount - 1].type = name[1]; | |
8e3de13a | 8810 | } |
57e8b36a | 8811 | |
e489d0ae PB |
8812 | return TRUE; |
8813 | } | |
8814 | ||
4e617b1e PB |
8815 | typedef struct |
8816 | { | |
8817 | void *finfo; | |
8818 | struct bfd_link_info *info; | |
8819 | int plt_shndx; | |
8820 | bfd_vma plt_offset; | |
8821 | bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *, | |
8822 | asection *, struct elf_link_hash_entry *); | |
8823 | } output_arch_syminfo; | |
8824 | ||
8825 | enum map_symbol_type | |
8826 | { | |
8827 | ARM_MAP_ARM, | |
8828 | ARM_MAP_THUMB, | |
8829 | ARM_MAP_DATA | |
8830 | }; | |
8831 | ||
8832 | ||
8833 | /* Output a single PLT mapping symbol. */ | |
8834 | ||
8835 | static bfd_boolean | |
8836 | elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi, | |
8837 | enum map_symbol_type type, | |
8838 | bfd_vma offset) | |
8839 | { | |
8840 | static const char *names[3] = {"$a", "$t", "$d"}; | |
8841 | struct elf32_arm_link_hash_table *htab; | |
8842 | Elf_Internal_Sym sym; | |
8843 | ||
8844 | htab = elf32_arm_hash_table (osi->info); | |
8845 | sym.st_value = osi->plt_offset + offset; | |
8846 | sym.st_size = 0; | |
8847 | sym.st_other = 0; | |
8848 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
8849 | sym.st_shndx = osi->plt_shndx; | |
8850 | if (!osi->func (osi->finfo, names[type], &sym, htab->splt, NULL)) | |
8851 | return FALSE; | |
8852 | return TRUE; | |
8853 | } | |
8854 | ||
8855 | ||
8856 | /* Output mapping symbols for PLT entries associated with H. */ | |
8857 | ||
8858 | static bfd_boolean | |
8859 | elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf) | |
8860 | { | |
8861 | output_arch_syminfo *osi = (output_arch_syminfo *) inf; | |
8862 | struct elf32_arm_link_hash_table *htab; | |
8863 | struct elf32_arm_link_hash_entry *eh; | |
8864 | bfd_vma addr; | |
8865 | ||
8866 | htab = elf32_arm_hash_table (osi->info); | |
8867 | ||
8868 | if (h->root.type == bfd_link_hash_indirect) | |
8869 | return TRUE; | |
8870 | ||
8871 | if (h->root.type == bfd_link_hash_warning) | |
8872 | /* When warning symbols are created, they **replace** the "real" | |
8873 | entry in the hash table, thus we never get to see the real | |
8874 | symbol in a hash traversal. So look at it now. */ | |
8875 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
8876 | ||
8877 | if (h->plt.offset == (bfd_vma) -1) | |
8878 | return TRUE; | |
8879 | ||
8880 | eh = (struct elf32_arm_link_hash_entry *) h; | |
8881 | addr = h->plt.offset; | |
8882 | if (htab->symbian_p) | |
8883 | { | |
8884 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8885 | return FALSE; | |
8886 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4)) | |
8887 | return FALSE; | |
8888 | } | |
8889 | else if (htab->vxworks_p) | |
8890 | { | |
8891 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8892 | return FALSE; | |
8893 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8)) | |
8894 | return FALSE; | |
8895 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12)) | |
8896 | return FALSE; | |
8897 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20)) | |
8898 | return FALSE; | |
8899 | } | |
8900 | else | |
8901 | { | |
8902 | bfd_boolean thumb_stub; | |
8903 | ||
8904 | thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx; | |
8905 | if (thumb_stub) | |
8906 | { | |
8907 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4)) | |
8908 | return FALSE; | |
8909 | } | |
8910 | #ifdef FOUR_WORD_PLT | |
8911 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8912 | return FALSE; | |
8913 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12)) | |
8914 | return FALSE; | |
8915 | #else | |
8916 | /* A three-word PLT with no Thumb thunk contains only Arm code, | |
8917 | so only need to output a mapping symbol for the first PLT entry and | |
8918 | entries with thumb thunks. */ | |
8919 | if (thumb_stub || addr == 20) | |
8920 | { | |
8921 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8922 | return FALSE; | |
8923 | } | |
8924 | #endif | |
8925 | } | |
8926 | ||
8927 | return TRUE; | |
8928 | } | |
8929 | ||
8930 | ||
8931 | /* Output mapping symbols for the PLT. */ | |
8932 | ||
8933 | static bfd_boolean | |
8934 | elf32_arm_output_arch_local_syms (bfd *output_bfd, | |
8935 | struct bfd_link_info *info, | |
8936 | void *finfo, bfd_boolean (*func) (void *, const char *, | |
8937 | Elf_Internal_Sym *, | |
8938 | asection *, | |
8939 | struct elf_link_hash_entry *)) | |
8940 | { | |
8941 | output_arch_syminfo osi; | |
8942 | struct elf32_arm_link_hash_table *htab; | |
8943 | ||
8944 | htab = elf32_arm_hash_table (info); | |
8945 | if (!htab->splt || htab->splt->size == 0) | |
8946 | return TRUE; | |
8947 | ||
8948 | check_use_blx(htab); | |
8949 | osi.finfo = finfo; | |
8950 | osi.info = info; | |
8951 | osi.func = func; | |
8952 | osi.plt_shndx = _bfd_elf_section_from_bfd_section (output_bfd, | |
8953 | htab->splt->output_section); | |
8954 | osi.plt_offset = htab->splt->output_section->vma; | |
8955 | ||
8956 | /* Output mapping symbols for the plt header. SymbianOS does not have a | |
8957 | plt header. */ | |
8958 | if (htab->vxworks_p) | |
8959 | { | |
8960 | /* VxWorks shared libraries have no PLT header. */ | |
8961 | if (!info->shared) | |
8962 | { | |
8963 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
8964 | return FALSE; | |
8965 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12)) | |
8966 | return FALSE; | |
8967 | } | |
8968 | } | |
8969 | else if (!htab->symbian_p) | |
8970 | { | |
8971 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
8972 | return FALSE; | |
8973 | #ifndef FOUR_WORD_PLT | |
8974 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16)) | |
8975 | return FALSE; | |
8976 | #endif | |
8977 | } | |
8978 | ||
8979 | elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi); | |
8980 | return TRUE; | |
8981 | } | |
8982 | ||
e489d0ae PB |
8983 | /* Allocate target specific section data. */ |
8984 | ||
8985 | static bfd_boolean | |
8986 | elf32_arm_new_section_hook (bfd *abfd, asection *sec) | |
8987 | { | |
f592407e AM |
8988 | if (!sec->used_by_bfd) |
8989 | { | |
8990 | _arm_elf_section_data *sdata; | |
8991 | bfd_size_type amt = sizeof (*sdata); | |
e489d0ae | 8992 | |
f592407e AM |
8993 | sdata = bfd_zalloc (abfd, amt); |
8994 | if (sdata == NULL) | |
8995 | return FALSE; | |
8996 | sec->used_by_bfd = sdata; | |
8997 | } | |
e489d0ae | 8998 | |
957c6e41 | 8999 | record_section_with_arm_elf_section_data (sec); |
8e3de13a | 9000 | |
e489d0ae PB |
9001 | return _bfd_elf_new_section_hook (abfd, sec); |
9002 | } | |
9003 | ||
9004 | ||
9005 | /* Used to order a list of mapping symbols by address. */ | |
9006 | ||
9007 | static int | |
9008 | elf32_arm_compare_mapping (const void * a, const void * b) | |
9009 | { | |
9010 | return ((const elf32_arm_section_map *) a)->vma | |
9011 | > ((const elf32_arm_section_map *) b)->vma; | |
9012 | } | |
9013 | ||
9014 | ||
9015 | /* Do code byteswapping. Return FALSE afterwards so that the section is | |
9016 | written out as normal. */ | |
9017 | ||
9018 | static bfd_boolean | |
9019 | elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec, | |
9020 | bfd_byte *contents) | |
9021 | { | |
9022 | int mapcount; | |
8e3de13a | 9023 | _arm_elf_section_data *arm_data; |
e489d0ae PB |
9024 | elf32_arm_section_map *map; |
9025 | bfd_vma ptr; | |
9026 | bfd_vma end; | |
9027 | bfd_vma offset; | |
9028 | bfd_byte tmp; | |
9029 | int i; | |
57e8b36a | 9030 | |
8e3de13a NC |
9031 | /* If this section has not been allocated an _arm_elf_section_data |
9032 | structure then we cannot record anything. */ | |
9033 | arm_data = get_arm_elf_section_data (sec); | |
9034 | if (arm_data == NULL) | |
9035 | return FALSE; | |
9036 | ||
9037 | mapcount = arm_data->mapcount; | |
9038 | map = arm_data->map; | |
e489d0ae PB |
9039 | |
9040 | if (mapcount == 0) | |
9041 | return FALSE; | |
9042 | ||
8e3de13a | 9043 | qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping); |
e489d0ae PB |
9044 | |
9045 | offset = sec->output_section->vma + sec->output_offset; | |
9046 | ptr = map[0].vma - offset; | |
9047 | for (i = 0; i < mapcount; i++) | |
9048 | { | |
9049 | if (i == mapcount - 1) | |
eea6121a | 9050 | end = sec->size; |
e489d0ae PB |
9051 | else |
9052 | end = map[i + 1].vma - offset; | |
57e8b36a | 9053 | |
e489d0ae PB |
9054 | switch (map[i].type) |
9055 | { | |
9056 | case 'a': | |
9057 | /* Byte swap code words. */ | |
9058 | while (ptr + 3 < end) | |
9059 | { | |
9060 | tmp = contents[ptr]; | |
9061 | contents[ptr] = contents[ptr + 3]; | |
9062 | contents[ptr + 3] = tmp; | |
9063 | tmp = contents[ptr + 1]; | |
9064 | contents[ptr + 1] = contents[ptr + 2]; | |
9065 | contents[ptr + 2] = tmp; | |
9066 | ptr += 4; | |
9067 | } | |
9068 | break; | |
9069 | ||
9070 | case 't': | |
9071 | /* Byte swap code halfwords. */ | |
9072 | while (ptr + 1 < end) | |
9073 | { | |
9074 | tmp = contents[ptr]; | |
9075 | contents[ptr] = contents[ptr + 1]; | |
9076 | contents[ptr + 1] = tmp; | |
9077 | ptr += 2; | |
9078 | } | |
9079 | break; | |
9080 | ||
9081 | case 'd': | |
9082 | /* Leave data alone. */ | |
9083 | break; | |
9084 | } | |
9085 | ptr = end; | |
9086 | } | |
8e3de13a | 9087 | |
93204d3a | 9088 | free (map); |
8e3de13a NC |
9089 | arm_data->mapcount = 0; |
9090 | arm_data->map = NULL; | |
9091 | unrecord_section_with_arm_elf_section_data (sec); | |
9092 | ||
e489d0ae PB |
9093 | return FALSE; |
9094 | } | |
9095 | ||
957c6e41 NC |
9096 | static void |
9097 | unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED, | |
9098 | asection * sec, | |
9099 | void * ignore ATTRIBUTE_UNUSED) | |
9100 | { | |
9101 | unrecord_section_with_arm_elf_section_data (sec); | |
9102 | } | |
9103 | ||
9104 | static bfd_boolean | |
9105 | elf32_arm_close_and_cleanup (bfd * abfd) | |
9106 | { | |
b25e3d87 L |
9107 | if (abfd->sections) |
9108 | bfd_map_over_sections (abfd, | |
9109 | unrecord_section_via_map_over_sections, | |
9110 | NULL); | |
957c6e41 NC |
9111 | |
9112 | return _bfd_elf_close_and_cleanup (abfd); | |
9113 | } | |
9114 | ||
b25e3d87 L |
9115 | static bfd_boolean |
9116 | elf32_arm_bfd_free_cached_info (bfd * abfd) | |
9117 | { | |
9118 | if (abfd->sections) | |
9119 | bfd_map_over_sections (abfd, | |
9120 | unrecord_section_via_map_over_sections, | |
9121 | NULL); | |
9122 | ||
9123 | return _bfd_free_cached_info (abfd); | |
9124 | } | |
9125 | ||
b7693d02 DJ |
9126 | /* Display STT_ARM_TFUNC symbols as functions. */ |
9127 | ||
9128 | static void | |
9129 | elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
9130 | asymbol *asym) | |
9131 | { | |
9132 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; | |
9133 | ||
9134 | if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC) | |
9135 | elfsym->symbol.flags |= BSF_FUNCTION; | |
9136 | } | |
9137 | ||
0beaef2b PB |
9138 | |
9139 | /* Mangle thumb function symbols as we read them in. */ | |
9140 | ||
9141 | static void | |
9142 | elf32_arm_swap_symbol_in (bfd * abfd, | |
9143 | const void *psrc, | |
9144 | const void *pshn, | |
9145 | Elf_Internal_Sym *dst) | |
9146 | { | |
9147 | bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst); | |
9148 | ||
9149 | /* New EABI objects mark thumb function symbols by setting the low bit of | |
9150 | the address. Turn these into STT_ARM_TFUNC. */ | |
9151 | if (ELF_ST_TYPE (dst->st_info) == STT_FUNC | |
9152 | && (dst->st_value & 1)) | |
9153 | { | |
9154 | dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); | |
9155 | dst->st_value &= ~(bfd_vma) 1; | |
9156 | } | |
9157 | } | |
9158 | ||
9159 | ||
9160 | /* Mangle thumb function symbols as we write them out. */ | |
9161 | ||
9162 | static void | |
9163 | elf32_arm_swap_symbol_out (bfd *abfd, | |
9164 | const Elf_Internal_Sym *src, | |
9165 | void *cdst, | |
9166 | void *shndx) | |
9167 | { | |
9168 | Elf_Internal_Sym newsym; | |
9169 | ||
9170 | /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit | |
9171 | of the address set, as per the new EABI. We do this unconditionally | |
9172 | because objcopy does not set the elf header flags until after | |
9173 | it writes out the symbol table. */ | |
9174 | if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) | |
9175 | { | |
9176 | newsym = *src; | |
9177 | newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); | |
0fa3dcad PB |
9178 | if (newsym.st_shndx != SHN_UNDEF) |
9179 | { | |
9180 | /* Do this only for defined symbols. At link type, the static | |
9181 | linker will simulate the work of dynamic linker of resolving | |
9182 | symbols and will carry over the thumbness of found symbols to | |
9183 | the output symbol table. It's not clear how it happens, but | |
9184 | the thumbness of underfined symbols can well be different at | |
9185 | runtime, and writing '1' for them will be confusing for users | |
9186 | and possibly for dynamic linker itself. | |
9187 | */ | |
9188 | newsym.st_value |= 1; | |
9189 | } | |
9190 | ||
0beaef2b PB |
9191 | newsym.st_value |= 1; |
9192 | ||
9193 | src = &newsym; | |
9194 | } | |
9195 | bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); | |
9196 | } | |
9197 | ||
b294bdf8 MM |
9198 | /* Add the PT_ARM_EXIDX program header. */ |
9199 | ||
9200 | static bfd_boolean | |
9201 | elf32_arm_modify_segment_map (bfd *abfd, | |
9202 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
9203 | { | |
9204 | struct elf_segment_map *m; | |
9205 | asection *sec; | |
9206 | ||
9207 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
9208 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
9209 | { | |
9210 | /* If there is already a PT_ARM_EXIDX header, then we do not | |
9211 | want to add another one. This situation arises when running | |
9212 | "strip"; the input binary already has the header. */ | |
9213 | m = elf_tdata (abfd)->segment_map; | |
9214 | while (m && m->p_type != PT_ARM_EXIDX) | |
9215 | m = m->next; | |
9216 | if (!m) | |
9217 | { | |
9218 | m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); | |
9219 | if (m == NULL) | |
9220 | return FALSE; | |
9221 | m->p_type = PT_ARM_EXIDX; | |
9222 | m->count = 1; | |
9223 | m->sections[0] = sec; | |
9224 | ||
9225 | m->next = elf_tdata (abfd)->segment_map; | |
9226 | elf_tdata (abfd)->segment_map = m; | |
9227 | } | |
9228 | } | |
9229 | ||
9230 | return TRUE; | |
9231 | } | |
9232 | ||
9233 | /* We may add a PT_ARM_EXIDX program header. */ | |
9234 | ||
9235 | static int | |
a6b96beb AM |
9236 | elf32_arm_additional_program_headers (bfd *abfd, |
9237 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
b294bdf8 MM |
9238 | { |
9239 | asection *sec; | |
9240 | ||
9241 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
9242 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
9243 | return 1; | |
9244 | else | |
9245 | return 0; | |
9246 | } | |
9247 | ||
0beaef2b PB |
9248 | /* We use this to override swap_symbol_in and swap_symbol_out. */ |
9249 | const struct elf_size_info elf32_arm_size_info = { | |
9250 | sizeof (Elf32_External_Ehdr), | |
9251 | sizeof (Elf32_External_Phdr), | |
9252 | sizeof (Elf32_External_Shdr), | |
9253 | sizeof (Elf32_External_Rel), | |
9254 | sizeof (Elf32_External_Rela), | |
9255 | sizeof (Elf32_External_Sym), | |
9256 | sizeof (Elf32_External_Dyn), | |
9257 | sizeof (Elf_External_Note), | |
9258 | 4, | |
9259 | 1, | |
9260 | 32, 2, | |
9261 | ELFCLASS32, EV_CURRENT, | |
9262 | bfd_elf32_write_out_phdrs, | |
9263 | bfd_elf32_write_shdrs_and_ehdr, | |
9264 | bfd_elf32_write_relocs, | |
9265 | elf32_arm_swap_symbol_in, | |
9266 | elf32_arm_swap_symbol_out, | |
9267 | bfd_elf32_slurp_reloc_table, | |
9268 | bfd_elf32_slurp_symbol_table, | |
9269 | bfd_elf32_swap_dyn_in, | |
9270 | bfd_elf32_swap_dyn_out, | |
9271 | bfd_elf32_swap_reloc_in, | |
9272 | bfd_elf32_swap_reloc_out, | |
9273 | bfd_elf32_swap_reloca_in, | |
9274 | bfd_elf32_swap_reloca_out | |
9275 | }; | |
9276 | ||
252b5132 RH |
9277 | #define ELF_ARCH bfd_arch_arm |
9278 | #define ELF_MACHINE_CODE EM_ARM | |
d0facd1b NC |
9279 | #ifdef __QNXTARGET__ |
9280 | #define ELF_MAXPAGESIZE 0x1000 | |
9281 | #else | |
f21f3fe0 | 9282 | #define ELF_MAXPAGESIZE 0x8000 |
d0facd1b | 9283 | #endif |
b1342370 | 9284 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 9285 | #define ELF_COMMONPAGESIZE 0x1000 |
252b5132 | 9286 | |
ba93b8ac DJ |
9287 | #define bfd_elf32_mkobject elf32_arm_mkobject |
9288 | ||
99e4ae17 AJ |
9289 | #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data |
9290 | #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data | |
252b5132 RH |
9291 | #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags |
9292 | #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data | |
9293 | #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create | |
dc810e39 | 9294 | #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup |
252b5132 | 9295 | #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line |
4ab527b0 | 9296 | #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info |
e489d0ae | 9297 | #define bfd_elf32_new_section_hook elf32_arm_new_section_hook |
3c9458e9 | 9298 | #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol |
957c6e41 | 9299 | #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup |
b25e3d87 | 9300 | #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info |
ee065d83 | 9301 | #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link |
252b5132 RH |
9302 | |
9303 | #define elf_backend_get_symbol_type elf32_arm_get_symbol_type | |
9304 | #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook | |
9305 | #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook | |
9306 | #define elf_backend_check_relocs elf32_arm_check_relocs | |
dc810e39 | 9307 | #define elf_backend_relocate_section elf32_arm_relocate_section |
e489d0ae | 9308 | #define elf_backend_write_section elf32_arm_write_section |
252b5132 | 9309 | #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol |
5e681ec4 | 9310 | #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections |
252b5132 RH |
9311 | #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol |
9312 | #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections | |
e489d0ae | 9313 | #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook |
252b5132 | 9314 | #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections |
ba96a88f | 9315 | #define elf_backend_post_process_headers elf32_arm_post_process_headers |
99e4ae17 | 9316 | #define elf_backend_reloc_type_class elf32_arm_reloc_type_class |
c178919b | 9317 | #define elf_backend_object_p elf32_arm_object_p |
e16bb312 | 9318 | #define elf_backend_section_flags elf32_arm_section_flags |
40a18ebd NC |
9319 | #define elf_backend_fake_sections elf32_arm_fake_sections |
9320 | #define elf_backend_section_from_shdr elf32_arm_section_from_shdr | |
e16bb312 | 9321 | #define elf_backend_final_write_processing elf32_arm_final_write_processing |
5e681ec4 | 9322 | #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol |
b7693d02 | 9323 | #define elf_backend_symbol_processing elf32_arm_symbol_processing |
0beaef2b | 9324 | #define elf_backend_size_info elf32_arm_size_info |
b294bdf8 MM |
9325 | #define elf_backend_modify_segment_map elf32_arm_modify_segment_map |
9326 | #define elf_backend_additional_program_headers \ | |
9327 | elf32_arm_additional_program_headers | |
4e617b1e PB |
9328 | #define elf_backend_output_arch_local_syms \ |
9329 | elf32_arm_output_arch_local_syms | |
252b5132 | 9330 | |
5e681ec4 | 9331 | #define elf_backend_can_refcount 1 |
252b5132 RH |
9332 | #define elf_backend_can_gc_sections 1 |
9333 | #define elf_backend_plt_readonly 1 | |
9334 | #define elf_backend_want_got_plt 1 | |
9335 | #define elf_backend_want_plt_sym 0 | |
4e7fd91e PB |
9336 | #define elf_backend_may_use_rel_p 1 |
9337 | #define elf_backend_may_use_rela_p 0 | |
9338 | #define elf_backend_default_use_rela_p 0 | |
9339 | #define elf_backend_rela_normal 0 | |
252b5132 | 9340 | |
04f7c78d | 9341 | #define elf_backend_got_header_size 12 |
04f7c78d | 9342 | |
252b5132 | 9343 | #include "elf32-target.h" |
7f266840 | 9344 | |
4e7fd91e PB |
9345 | /* VxWorks Targets */ |
9346 | ||
9347 | #undef TARGET_LITTLE_SYM | |
9348 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec | |
9349 | #undef TARGET_LITTLE_NAME | |
9350 | #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks" | |
9351 | #undef TARGET_BIG_SYM | |
9352 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec | |
9353 | #undef TARGET_BIG_NAME | |
9354 | #define TARGET_BIG_NAME "elf32-bigarm-vxworks" | |
9355 | ||
9356 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
9357 | appropriately for VxWorks. */ | |
9358 | static struct bfd_link_hash_table * | |
9359 | elf32_arm_vxworks_link_hash_table_create (bfd *abfd) | |
9360 | { | |
9361 | struct bfd_link_hash_table *ret; | |
9362 | ||
9363 | ret = elf32_arm_link_hash_table_create (abfd); | |
9364 | if (ret) | |
9365 | { | |
9366 | struct elf32_arm_link_hash_table *htab | |
00a97672 | 9367 | = (struct elf32_arm_link_hash_table *) ret; |
4e7fd91e | 9368 | htab->use_rel = 0; |
00a97672 | 9369 | htab->vxworks_p = 1; |
4e7fd91e PB |
9370 | } |
9371 | return ret; | |
9372 | } | |
9373 | ||
00a97672 RS |
9374 | static void |
9375 | elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
9376 | { | |
9377 | elf32_arm_final_write_processing (abfd, linker); | |
9378 | elf_vxworks_final_write_processing (abfd, linker); | |
9379 | } | |
9380 | ||
4e7fd91e PB |
9381 | #undef elf32_bed |
9382 | #define elf32_bed elf32_arm_vxworks_bed | |
9383 | ||
9384 | #undef bfd_elf32_bfd_link_hash_table_create | |
9385 | #define bfd_elf32_bfd_link_hash_table_create \ | |
9386 | elf32_arm_vxworks_link_hash_table_create | |
00a97672 RS |
9387 | #undef elf_backend_add_symbol_hook |
9388 | #define elf_backend_add_symbol_hook \ | |
9389 | elf_vxworks_add_symbol_hook | |
9390 | #undef elf_backend_final_write_processing | |
9391 | #define elf_backend_final_write_processing \ | |
9392 | elf32_arm_vxworks_final_write_processing | |
9393 | #undef elf_backend_emit_relocs | |
9394 | #define elf_backend_emit_relocs \ | |
9395 | elf_vxworks_emit_relocs | |
4e7fd91e PB |
9396 | |
9397 | #undef elf_backend_may_use_rel_p | |
00a97672 | 9398 | #define elf_backend_may_use_rel_p 0 |
4e7fd91e | 9399 | #undef elf_backend_may_use_rela_p |
00a97672 | 9400 | #define elf_backend_may_use_rela_p 1 |
4e7fd91e | 9401 | #undef elf_backend_default_use_rela_p |
00a97672 | 9402 | #define elf_backend_default_use_rela_p 1 |
4e7fd91e | 9403 | #undef elf_backend_rela_normal |
00a97672 RS |
9404 | #define elf_backend_rela_normal 1 |
9405 | #undef elf_backend_want_plt_sym | |
9406 | #define elf_backend_want_plt_sym 1 | |
9407 | #undef ELF_MAXPAGESIZE | |
9408 | #define ELF_MAXPAGESIZE 0x1000 | |
4e7fd91e PB |
9409 | |
9410 | #include "elf32-target.h" | |
9411 | ||
9412 | ||
7f266840 DJ |
9413 | /* Symbian OS Targets */ |
9414 | ||
9415 | #undef TARGET_LITTLE_SYM | |
9416 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec | |
9417 | #undef TARGET_LITTLE_NAME | |
9418 | #define TARGET_LITTLE_NAME "elf32-littlearm-symbian" | |
9419 | #undef TARGET_BIG_SYM | |
9420 | #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec | |
9421 | #undef TARGET_BIG_NAME | |
9422 | #define TARGET_BIG_NAME "elf32-bigarm-symbian" | |
9423 | ||
9424 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
9425 | appropriately for Symbian OS. */ | |
9426 | static struct bfd_link_hash_table * | |
9427 | elf32_arm_symbian_link_hash_table_create (bfd *abfd) | |
9428 | { | |
9429 | struct bfd_link_hash_table *ret; | |
9430 | ||
9431 | ret = elf32_arm_link_hash_table_create (abfd); | |
9432 | if (ret) | |
9433 | { | |
9434 | struct elf32_arm_link_hash_table *htab | |
9435 | = (struct elf32_arm_link_hash_table *)ret; | |
9436 | /* There is no PLT header for Symbian OS. */ | |
9437 | htab->plt_header_size = 0; | |
9438 | /* The PLT entries are each three instructions. */ | |
9439 | htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); | |
9440 | htab->symbian_p = 1; | |
33bfe774 JB |
9441 | /* Symbian uses armv5t or above, so use_blx is always true. */ |
9442 | htab->use_blx = 1; | |
67687978 | 9443 | htab->root.is_relocatable_executable = 1; |
7f266840 DJ |
9444 | } |
9445 | return ret; | |
9446 | } | |
9447 | ||
b35d266b | 9448 | static const struct bfd_elf_special_section |
551b43fd | 9449 | elf32_arm_symbian_special_sections[] = |
7f266840 | 9450 | { |
5cd3778d MM |
9451 | /* In a BPABI executable, the dynamic linking sections do not go in |
9452 | the loadable read-only segment. The post-linker may wish to | |
9453 | refer to these sections, but they are not part of the final | |
9454 | program image. */ | |
7f266840 DJ |
9455 | { ".dynamic", 8, 0, SHT_DYNAMIC, 0 }, |
9456 | { ".dynstr", 7, 0, SHT_STRTAB, 0 }, | |
9457 | { ".dynsym", 7, 0, SHT_DYNSYM, 0 }, | |
9458 | { ".got", 4, 0, SHT_PROGBITS, 0 }, | |
9459 | { ".hash", 5, 0, SHT_HASH, 0 }, | |
5cd3778d MM |
9460 | /* These sections do not need to be writable as the SymbianOS |
9461 | postlinker will arrange things so that no dynamic relocation is | |
9462 | required. */ | |
9463 | { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC }, | |
9464 | { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC }, | |
9465 | { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC }, | |
7f266840 DJ |
9466 | { NULL, 0, 0, 0, 0 } |
9467 | }; | |
9468 | ||
c3c76620 | 9469 | static void |
b34af79c MM |
9470 | elf32_arm_symbian_begin_write_processing (bfd *abfd, |
9471 | struct bfd_link_info *link_info | |
9472 | ATTRIBUTE_UNUSED) | |
c3c76620 MM |
9473 | { |
9474 | /* BPABI objects are never loaded directly by an OS kernel; they are | |
9475 | processed by a postlinker first, into an OS-specific format. If | |
9476 | the D_PAGED bit is set on the file, BFD will align segments on | |
9477 | page boundaries, so that an OS can directly map the file. With | |
9478 | BPABI objects, that just results in wasted space. In addition, | |
9479 | because we clear the D_PAGED bit, map_sections_to_segments will | |
9480 | recognize that the program headers should not be mapped into any | |
9481 | loadable segment. */ | |
9482 | abfd->flags &= ~D_PAGED; | |
9483 | } | |
7f266840 DJ |
9484 | |
9485 | static bfd_boolean | |
b34af79c | 9486 | elf32_arm_symbian_modify_segment_map (bfd *abfd, |
b294bdf8 | 9487 | struct bfd_link_info *info) |
7f266840 DJ |
9488 | { |
9489 | struct elf_segment_map *m; | |
9490 | asection *dynsec; | |
9491 | ||
7f266840 DJ |
9492 | /* BPABI shared libraries and executables should have a PT_DYNAMIC |
9493 | segment. However, because the .dynamic section is not marked | |
9494 | with SEC_LOAD, the generic ELF code will not create such a | |
9495 | segment. */ | |
9496 | dynsec = bfd_get_section_by_name (abfd, ".dynamic"); | |
9497 | if (dynsec) | |
9498 | { | |
8ded5a0f AM |
9499 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) |
9500 | if (m->p_type == PT_DYNAMIC) | |
9501 | break; | |
9502 | ||
9503 | if (m == NULL) | |
9504 | { | |
9505 | m = _bfd_elf_make_dynamic_segment (abfd, dynsec); | |
9506 | m->next = elf_tdata (abfd)->segment_map; | |
9507 | elf_tdata (abfd)->segment_map = m; | |
9508 | } | |
7f266840 DJ |
9509 | } |
9510 | ||
b294bdf8 MM |
9511 | /* Also call the generic arm routine. */ |
9512 | return elf32_arm_modify_segment_map (abfd, info); | |
7f266840 DJ |
9513 | } |
9514 | ||
9515 | #undef elf32_bed | |
9516 | #define elf32_bed elf32_arm_symbian_bed | |
9517 | ||
9518 | /* The dynamic sections are not allocated on SymbianOS; the postlinker | |
9519 | will process them and then discard them. */ | |
9520 | #undef ELF_DYNAMIC_SEC_FLAGS | |
9521 | #define ELF_DYNAMIC_SEC_FLAGS \ | |
9522 | (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED) | |
9523 | ||
9524 | #undef bfd_elf32_bfd_link_hash_table_create | |
9525 | #define bfd_elf32_bfd_link_hash_table_create \ | |
9526 | elf32_arm_symbian_link_hash_table_create | |
00a97672 | 9527 | #undef elf_backend_add_symbol_hook |
7f266840 | 9528 | |
29ef7005 L |
9529 | #undef elf_backend_special_sections |
9530 | #define elf_backend_special_sections elf32_arm_symbian_special_sections | |
7f266840 | 9531 | |
c3c76620 MM |
9532 | #undef elf_backend_begin_write_processing |
9533 | #define elf_backend_begin_write_processing \ | |
9534 | elf32_arm_symbian_begin_write_processing | |
00a97672 RS |
9535 | #undef elf_backend_final_write_processing |
9536 | #define elf_backend_final_write_processing \ | |
9537 | elf32_arm_final_write_processing | |
9538 | #undef elf_backend_emit_relocs | |
c3c76620 | 9539 | |
7f266840 DJ |
9540 | #undef elf_backend_modify_segment_map |
9541 | #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map | |
9542 | ||
9543 | /* There is no .got section for BPABI objects, and hence no header. */ | |
9544 | #undef elf_backend_got_header_size | |
9545 | #define elf_backend_got_header_size 0 | |
9546 | ||
9547 | /* Similarly, there is no .got.plt section. */ | |
9548 | #undef elf_backend_want_got_plt | |
9549 | #define elf_backend_want_got_plt 0 | |
9550 | ||
4e7fd91e | 9551 | #undef elf_backend_may_use_rel_p |
00a97672 | 9552 | #define elf_backend_may_use_rel_p 1 |
4e7fd91e | 9553 | #undef elf_backend_may_use_rela_p |
00a97672 | 9554 | #define elf_backend_may_use_rela_p 0 |
4e7fd91e | 9555 | #undef elf_backend_default_use_rela_p |
00a97672 | 9556 | #define elf_backend_default_use_rela_p 0 |
4e7fd91e | 9557 | #undef elf_backend_rela_normal |
00a97672 RS |
9558 | #define elf_backend_rela_normal 0 |
9559 | #undef elf_backend_want_plt_sym | |
9560 | #define elf_backend_want_plt_sym 0 | |
9561 | #undef ELF_MAXPAGESIZE | |
9562 | #define ELF_MAXPAGESIZE 0x8000 | |
4e7fd91e | 9563 | |
7f266840 | 9564 | #include "elf32-target.h" |