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 */ |
7f266840 DJ |
133 | HOWTO (R_ARM_PC13, /* type */ |
134 | 0, /* rightshift */ | |
135 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
136 | 8, /* bitsize */ | |
137 | FALSE, /* pc_relative */ | |
138 | 0, /* bitpos */ | |
139 | complain_overflow_bitfield,/* complain_on_overflow */ | |
140 | bfd_elf_generic_reloc, /* special_function */ | |
141 | "R_ARM_PC13", /* name */ | |
142 | FALSE, /* partial_inplace */ | |
143 | 0x000000ff, /* src_mask */ | |
144 | 0x000000ff, /* dst_mask */ | |
145 | FALSE), /* pcrel_offset */ | |
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 DJ |
887 | }; |
888 | ||
c19d1205 ZW |
889 | /* Relocations 57 .. 83 are the "group relocations" which we do not |
890 | support. */ | |
891 | ||
892 | static reloc_howto_type elf32_arm_howto_table_2[] = | |
893 | { | |
894 | HOWTO (R_ARM_MOVW_BREL_NC, /* type */ | |
895 | 0, /* rightshift */ | |
896 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
897 | 16, /* bitsize */ | |
898 | FALSE, /* pc_relative */ | |
899 | 0, /* bitpos */ | |
900 | complain_overflow_dont,/* complain_on_overflow */ | |
901 | bfd_elf_generic_reloc, /* special_function */ | |
902 | "R_ARM_MOVW_BREL_NC", /* name */ | |
903 | FALSE, /* partial_inplace */ | |
904 | 0x0000ffff, /* src_mask */ | |
905 | 0x0000ffff, /* dst_mask */ | |
906 | FALSE), /* pcrel_offset */ | |
907 | ||
908 | HOWTO (R_ARM_MOVT_BREL, /* type */ | |
909 | 0, /* rightshift */ | |
910 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
911 | 16, /* bitsize */ | |
912 | FALSE, /* pc_relative */ | |
913 | 0, /* bitpos */ | |
914 | complain_overflow_bitfield,/* complain_on_overflow */ | |
915 | bfd_elf_generic_reloc, /* special_function */ | |
916 | "R_ARM_MOVT_BREL", /* name */ | |
917 | FALSE, /* partial_inplace */ | |
918 | 0x0000ffff, /* src_mask */ | |
919 | 0x0000ffff, /* dst_mask */ | |
920 | FALSE), /* pcrel_offset */ | |
921 | ||
922 | HOWTO (R_ARM_MOVW_BREL, /* type */ | |
923 | 0, /* rightshift */ | |
924 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
925 | 16, /* bitsize */ | |
926 | FALSE, /* pc_relative */ | |
927 | 0, /* bitpos */ | |
928 | complain_overflow_dont,/* complain_on_overflow */ | |
929 | bfd_elf_generic_reloc, /* special_function */ | |
930 | "R_ARM_MOVW_BREL", /* name */ | |
931 | FALSE, /* partial_inplace */ | |
932 | 0x0000ffff, /* src_mask */ | |
933 | 0x0000ffff, /* dst_mask */ | |
934 | FALSE), /* pcrel_offset */ | |
935 | ||
936 | HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */ | |
937 | 0, /* rightshift */ | |
938 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
939 | 16, /* bitsize */ | |
940 | FALSE, /* pc_relative */ | |
941 | 0, /* bitpos */ | |
942 | complain_overflow_dont,/* complain_on_overflow */ | |
943 | bfd_elf_generic_reloc, /* special_function */ | |
944 | "R_ARM_THM_MOVW_BREL_NC",/* name */ | |
945 | FALSE, /* partial_inplace */ | |
946 | 0x040f70ff, /* src_mask */ | |
947 | 0x040f70ff, /* dst_mask */ | |
948 | FALSE), /* pcrel_offset */ | |
949 | ||
950 | HOWTO (R_ARM_THM_MOVT_BREL, /* type */ | |
951 | 0, /* rightshift */ | |
952 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
953 | 16, /* bitsize */ | |
954 | FALSE, /* pc_relative */ | |
955 | 0, /* bitpos */ | |
956 | complain_overflow_bitfield,/* complain_on_overflow */ | |
957 | bfd_elf_generic_reloc, /* special_function */ | |
958 | "R_ARM_THM_MOVT_BREL", /* name */ | |
959 | FALSE, /* partial_inplace */ | |
960 | 0x040f70ff, /* src_mask */ | |
961 | 0x040f70ff, /* dst_mask */ | |
962 | FALSE), /* pcrel_offset */ | |
963 | ||
964 | HOWTO (R_ARM_THM_MOVW_BREL, /* type */ | |
965 | 0, /* rightshift */ | |
966 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
967 | 16, /* bitsize */ | |
968 | FALSE, /* pc_relative */ | |
969 | 0, /* bitpos */ | |
970 | complain_overflow_dont,/* complain_on_overflow */ | |
971 | bfd_elf_generic_reloc, /* special_function */ | |
972 | "R_ARM_THM_MOVW_BREL", /* name */ | |
973 | FALSE, /* partial_inplace */ | |
974 | 0x040f70ff, /* src_mask */ | |
975 | 0x040f70ff, /* dst_mask */ | |
976 | FALSE), /* pcrel_offset */ | |
977 | ||
978 | EMPTY_HOWTO (90), /* unallocated */ | |
979 | EMPTY_HOWTO (91), | |
980 | EMPTY_HOWTO (92), | |
981 | EMPTY_HOWTO (93), | |
982 | ||
983 | HOWTO (R_ARM_PLT32_ABS, /* type */ | |
984 | 0, /* rightshift */ | |
985 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
986 | 32, /* bitsize */ | |
987 | FALSE, /* pc_relative */ | |
988 | 0, /* bitpos */ | |
989 | complain_overflow_dont,/* complain_on_overflow */ | |
990 | bfd_elf_generic_reloc, /* special_function */ | |
991 | "R_ARM_PLT32_ABS", /* name */ | |
992 | FALSE, /* partial_inplace */ | |
993 | 0xffffffff, /* src_mask */ | |
994 | 0xffffffff, /* dst_mask */ | |
995 | FALSE), /* pcrel_offset */ | |
996 | ||
997 | HOWTO (R_ARM_GOT_ABS, /* type */ | |
998 | 0, /* rightshift */ | |
999 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1000 | 32, /* bitsize */ | |
1001 | FALSE, /* pc_relative */ | |
1002 | 0, /* bitpos */ | |
1003 | complain_overflow_dont,/* complain_on_overflow */ | |
1004 | bfd_elf_generic_reloc, /* special_function */ | |
1005 | "R_ARM_GOT_ABS", /* name */ | |
1006 | FALSE, /* partial_inplace */ | |
1007 | 0xffffffff, /* src_mask */ | |
1008 | 0xffffffff, /* dst_mask */ | |
1009 | FALSE), /* pcrel_offset */ | |
1010 | ||
1011 | HOWTO (R_ARM_GOT_PREL, /* type */ | |
1012 | 0, /* rightshift */ | |
1013 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1014 | 32, /* bitsize */ | |
1015 | TRUE, /* pc_relative */ | |
1016 | 0, /* bitpos */ | |
1017 | complain_overflow_dont, /* complain_on_overflow */ | |
1018 | bfd_elf_generic_reloc, /* special_function */ | |
1019 | "R_ARM_GOT_PREL", /* name */ | |
1020 | FALSE, /* partial_inplace */ | |
1021 | 0xffffffff, /* src_mask */ | |
1022 | 0xffffffff, /* dst_mask */ | |
1023 | TRUE), /* pcrel_offset */ | |
1024 | ||
1025 | HOWTO (R_ARM_GOT_BREL12, /* type */ | |
1026 | 0, /* rightshift */ | |
1027 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1028 | 12, /* bitsize */ | |
1029 | FALSE, /* pc_relative */ | |
1030 | 0, /* bitpos */ | |
1031 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1032 | bfd_elf_generic_reloc, /* special_function */ | |
1033 | "R_ARM_GOT_BREL12", /* name */ | |
1034 | FALSE, /* partial_inplace */ | |
1035 | 0x00000fff, /* src_mask */ | |
1036 | 0x00000fff, /* dst_mask */ | |
1037 | FALSE), /* pcrel_offset */ | |
1038 | ||
1039 | HOWTO (R_ARM_GOTOFF12, /* type */ | |
1040 | 0, /* rightshift */ | |
1041 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1042 | 12, /* bitsize */ | |
1043 | FALSE, /* pc_relative */ | |
1044 | 0, /* bitpos */ | |
1045 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1046 | bfd_elf_generic_reloc, /* special_function */ | |
1047 | "R_ARM_GOTOFF12", /* name */ | |
1048 | FALSE, /* partial_inplace */ | |
1049 | 0x00000fff, /* src_mask */ | |
1050 | 0x00000fff, /* dst_mask */ | |
1051 | FALSE), /* pcrel_offset */ | |
1052 | ||
1053 | EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */ | |
1054 | ||
1055 | /* GNU extension to record C++ vtable member usage */ | |
1056 | HOWTO (R_ARM_GNU_VTENTRY, /* type */ | |
ba93b8ac DJ |
1057 | 0, /* rightshift */ |
1058 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1059 | 0, /* bitsize */ |
ba93b8ac DJ |
1060 | FALSE, /* pc_relative */ |
1061 | 0, /* bitpos */ | |
c19d1205 ZW |
1062 | complain_overflow_dont, /* complain_on_overflow */ |
1063 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
1064 | "R_ARM_GNU_VTENTRY", /* name */ | |
1065 | FALSE, /* partial_inplace */ | |
1066 | 0, /* src_mask */ | |
1067 | 0, /* dst_mask */ | |
1068 | FALSE), /* pcrel_offset */ | |
1069 | ||
1070 | /* GNU extension to record C++ vtable hierarchy */ | |
1071 | HOWTO (R_ARM_GNU_VTINHERIT, /* type */ | |
1072 | 0, /* rightshift */ | |
1073 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1074 | 0, /* bitsize */ | |
1075 | FALSE, /* pc_relative */ | |
1076 | 0, /* bitpos */ | |
1077 | complain_overflow_dont, /* complain_on_overflow */ | |
1078 | NULL, /* special_function */ | |
1079 | "R_ARM_GNU_VTINHERIT", /* name */ | |
1080 | FALSE, /* partial_inplace */ | |
1081 | 0, /* src_mask */ | |
1082 | 0, /* dst_mask */ | |
1083 | FALSE), /* pcrel_offset */ | |
1084 | ||
1085 | HOWTO (R_ARM_THM_JUMP11, /* type */ | |
1086 | 1, /* rightshift */ | |
1087 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1088 | 11, /* bitsize */ | |
1089 | TRUE, /* pc_relative */ | |
1090 | 0, /* bitpos */ | |
1091 | complain_overflow_signed, /* complain_on_overflow */ | |
1092 | bfd_elf_generic_reloc, /* special_function */ | |
1093 | "R_ARM_THM_JUMP11", /* name */ | |
1094 | FALSE, /* partial_inplace */ | |
1095 | 0x000007ff, /* src_mask */ | |
1096 | 0x000007ff, /* dst_mask */ | |
1097 | TRUE), /* pcrel_offset */ | |
1098 | ||
1099 | HOWTO (R_ARM_THM_JUMP8, /* type */ | |
1100 | 1, /* rightshift */ | |
1101 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1102 | 8, /* bitsize */ | |
1103 | TRUE, /* pc_relative */ | |
1104 | 0, /* bitpos */ | |
1105 | complain_overflow_signed, /* complain_on_overflow */ | |
1106 | bfd_elf_generic_reloc, /* special_function */ | |
1107 | "R_ARM_THM_JUMP8", /* name */ | |
1108 | FALSE, /* partial_inplace */ | |
1109 | 0x000000ff, /* src_mask */ | |
1110 | 0x000000ff, /* dst_mask */ | |
1111 | TRUE), /* pcrel_offset */ | |
ba93b8ac | 1112 | |
c19d1205 ZW |
1113 | /* TLS relocations */ |
1114 | HOWTO (R_ARM_TLS_GD32, /* type */ | |
ba93b8ac DJ |
1115 | 0, /* rightshift */ |
1116 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1117 | 32, /* bitsize */ | |
1118 | FALSE, /* pc_relative */ | |
1119 | 0, /* bitpos */ | |
1120 | complain_overflow_bitfield,/* complain_on_overflow */ | |
c19d1205 ZW |
1121 | NULL, /* special_function */ |
1122 | "R_ARM_TLS_GD32", /* name */ | |
ba93b8ac DJ |
1123 | TRUE, /* partial_inplace */ |
1124 | 0xffffffff, /* src_mask */ | |
1125 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1126 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1127 | |
ba93b8ac DJ |
1128 | HOWTO (R_ARM_TLS_LDM32, /* type */ |
1129 | 0, /* rightshift */ | |
1130 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1131 | 32, /* bitsize */ | |
1132 | FALSE, /* pc_relative */ | |
1133 | 0, /* bitpos */ | |
1134 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1135 | bfd_elf_generic_reloc, /* special_function */ | |
1136 | "R_ARM_TLS_LDM32", /* name */ | |
1137 | TRUE, /* partial_inplace */ | |
1138 | 0xffffffff, /* src_mask */ | |
1139 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1140 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1141 | |
c19d1205 | 1142 | HOWTO (R_ARM_TLS_LDO32, /* type */ |
ba93b8ac DJ |
1143 | 0, /* rightshift */ |
1144 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1145 | 32, /* bitsize */ | |
1146 | FALSE, /* pc_relative */ | |
1147 | 0, /* bitpos */ | |
1148 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1149 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 1150 | "R_ARM_TLS_LDO32", /* name */ |
ba93b8ac DJ |
1151 | TRUE, /* partial_inplace */ |
1152 | 0xffffffff, /* src_mask */ | |
1153 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1154 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1155 | |
ba93b8ac DJ |
1156 | HOWTO (R_ARM_TLS_IE32, /* type */ |
1157 | 0, /* rightshift */ | |
1158 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1159 | 32, /* bitsize */ | |
1160 | FALSE, /* pc_relative */ | |
1161 | 0, /* bitpos */ | |
1162 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1163 | NULL, /* special_function */ | |
1164 | "R_ARM_TLS_IE32", /* name */ | |
1165 | TRUE, /* partial_inplace */ | |
1166 | 0xffffffff, /* src_mask */ | |
1167 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1168 | FALSE), /* pcrel_offset */ |
7f266840 | 1169 | |
c19d1205 | 1170 | HOWTO (R_ARM_TLS_LE32, /* type */ |
7f266840 DJ |
1171 | 0, /* rightshift */ |
1172 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1173 | 32, /* bitsize */ |
7f266840 DJ |
1174 | FALSE, /* pc_relative */ |
1175 | 0, /* bitpos */ | |
c19d1205 ZW |
1176 | complain_overflow_bitfield,/* complain_on_overflow */ |
1177 | bfd_elf_generic_reloc, /* special_function */ | |
1178 | "R_ARM_TLS_LE32", /* name */ | |
1179 | TRUE, /* partial_inplace */ | |
1180 | 0xffffffff, /* src_mask */ | |
1181 | 0xffffffff, /* dst_mask */ | |
1182 | FALSE), /* pcrel_offset */ | |
7f266840 | 1183 | |
c19d1205 ZW |
1184 | HOWTO (R_ARM_TLS_LDO12, /* type */ |
1185 | 0, /* rightshift */ | |
1186 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1187 | 12, /* bitsize */ | |
1188 | FALSE, /* pc_relative */ | |
7f266840 | 1189 | 0, /* bitpos */ |
c19d1205 | 1190 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1191 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1192 | "R_ARM_TLS_LDO12", /* name */ |
7f266840 | 1193 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1194 | 0x00000fff, /* src_mask */ |
1195 | 0x00000fff, /* dst_mask */ | |
1196 | FALSE), /* pcrel_offset */ | |
7f266840 | 1197 | |
c19d1205 ZW |
1198 | HOWTO (R_ARM_TLS_LE12, /* type */ |
1199 | 0, /* rightshift */ | |
1200 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1201 | 12, /* bitsize */ | |
1202 | FALSE, /* pc_relative */ | |
7f266840 | 1203 | 0, /* bitpos */ |
c19d1205 | 1204 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1205 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1206 | "R_ARM_TLS_LE12", /* name */ |
7f266840 | 1207 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1208 | 0x00000fff, /* src_mask */ |
1209 | 0x00000fff, /* dst_mask */ | |
1210 | FALSE), /* pcrel_offset */ | |
7f266840 | 1211 | |
c19d1205 | 1212 | HOWTO (R_ARM_TLS_IE12GP, /* type */ |
7f266840 DJ |
1213 | 0, /* rightshift */ |
1214 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 ZW |
1215 | 12, /* bitsize */ |
1216 | FALSE, /* pc_relative */ | |
7f266840 | 1217 | 0, /* bitpos */ |
c19d1205 | 1218 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1219 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1220 | "R_ARM_TLS_IE12GP", /* name */ |
7f266840 | 1221 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1222 | 0x00000fff, /* src_mask */ |
1223 | 0x00000fff, /* dst_mask */ | |
1224 | FALSE), /* pcrel_offset */ | |
1225 | }; | |
1226 | ||
1227 | /* 112-127 private relocations | |
1228 | 128 R_ARM_ME_TOO, obsolete | |
1229 | 129-255 unallocated in AAELF. | |
7f266840 | 1230 | |
c19d1205 ZW |
1231 | 249-255 extended, currently unused, relocations: */ |
1232 | ||
1233 | static reloc_howto_type elf32_arm_howto_table_3[4] = | |
7f266840 DJ |
1234 | { |
1235 | HOWTO (R_ARM_RREL32, /* type */ | |
1236 | 0, /* rightshift */ | |
1237 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1238 | 0, /* bitsize */ | |
1239 | FALSE, /* pc_relative */ | |
1240 | 0, /* bitpos */ | |
1241 | complain_overflow_dont,/* complain_on_overflow */ | |
1242 | bfd_elf_generic_reloc, /* special_function */ | |
1243 | "R_ARM_RREL32", /* name */ | |
1244 | FALSE, /* partial_inplace */ | |
1245 | 0, /* src_mask */ | |
1246 | 0, /* dst_mask */ | |
1247 | FALSE), /* pcrel_offset */ | |
1248 | ||
1249 | HOWTO (R_ARM_RABS32, /* type */ | |
1250 | 0, /* rightshift */ | |
1251 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1252 | 0, /* bitsize */ | |
1253 | FALSE, /* pc_relative */ | |
1254 | 0, /* bitpos */ | |
1255 | complain_overflow_dont,/* complain_on_overflow */ | |
1256 | bfd_elf_generic_reloc, /* special_function */ | |
1257 | "R_ARM_RABS32", /* name */ | |
1258 | FALSE, /* partial_inplace */ | |
1259 | 0, /* src_mask */ | |
1260 | 0, /* dst_mask */ | |
1261 | FALSE), /* pcrel_offset */ | |
1262 | ||
1263 | HOWTO (R_ARM_RPC24, /* type */ | |
1264 | 0, /* rightshift */ | |
1265 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1266 | 0, /* bitsize */ | |
1267 | FALSE, /* pc_relative */ | |
1268 | 0, /* bitpos */ | |
1269 | complain_overflow_dont,/* complain_on_overflow */ | |
1270 | bfd_elf_generic_reloc, /* special_function */ | |
1271 | "R_ARM_RPC24", /* name */ | |
1272 | FALSE, /* partial_inplace */ | |
1273 | 0, /* src_mask */ | |
1274 | 0, /* dst_mask */ | |
1275 | FALSE), /* pcrel_offset */ | |
1276 | ||
1277 | HOWTO (R_ARM_RBASE, /* type */ | |
1278 | 0, /* rightshift */ | |
1279 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1280 | 0, /* bitsize */ | |
1281 | FALSE, /* pc_relative */ | |
1282 | 0, /* bitpos */ | |
1283 | complain_overflow_dont,/* complain_on_overflow */ | |
1284 | bfd_elf_generic_reloc, /* special_function */ | |
1285 | "R_ARM_RBASE", /* name */ | |
1286 | FALSE, /* partial_inplace */ | |
1287 | 0, /* src_mask */ | |
1288 | 0, /* dst_mask */ | |
1289 | FALSE) /* pcrel_offset */ | |
1290 | }; | |
1291 | ||
1292 | static reloc_howto_type * | |
1293 | elf32_arm_howto_from_type (unsigned int r_type) | |
1294 | { | |
c19d1205 ZW |
1295 | if (r_type < NUM_ELEM (elf32_arm_howto_table_1)) |
1296 | return &elf32_arm_howto_table_1[r_type]; | |
ba93b8ac | 1297 | |
c19d1205 ZW |
1298 | if (r_type >= R_ARM_MOVW_BREL_NC |
1299 | && r_type < R_ARM_MOVW_BREL_NC + NUM_ELEM (elf32_arm_howto_table_2)) | |
1300 | return &elf32_arm_howto_table_2[r_type - R_ARM_MOVW_BREL_NC]; | |
7f266840 | 1301 | |
c19d1205 ZW |
1302 | if (r_type >= R_ARM_RREL32 |
1303 | && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2)) | |
1304 | return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32]; | |
7f266840 | 1305 | |
c19d1205 | 1306 | return NULL; |
7f266840 DJ |
1307 | } |
1308 | ||
1309 | static void | |
1310 | elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, | |
1311 | Elf_Internal_Rela * elf_reloc) | |
1312 | { | |
1313 | unsigned int r_type; | |
1314 | ||
1315 | r_type = ELF32_R_TYPE (elf_reloc->r_info); | |
1316 | bfd_reloc->howto = elf32_arm_howto_from_type (r_type); | |
1317 | } | |
1318 | ||
1319 | struct elf32_arm_reloc_map | |
1320 | { | |
1321 | bfd_reloc_code_real_type bfd_reloc_val; | |
1322 | unsigned char elf_reloc_val; | |
1323 | }; | |
1324 | ||
1325 | /* All entries in this list must also be present in elf32_arm_howto_table. */ | |
1326 | static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = | |
1327 | { | |
1328 | {BFD_RELOC_NONE, R_ARM_NONE}, | |
1329 | {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24}, | |
39b41c9c PB |
1330 | {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL}, |
1331 | {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24}, | |
7f266840 DJ |
1332 | {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25}, |
1333 | {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22}, | |
1334 | {BFD_RELOC_32, R_ARM_ABS32}, | |
1335 | {BFD_RELOC_32_PCREL, R_ARM_REL32}, | |
1336 | {BFD_RELOC_8, R_ARM_ABS8}, | |
1337 | {BFD_RELOC_16, R_ARM_ABS16}, | |
1338 | {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12}, | |
1339 | {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5}, | |
c19d1205 ZW |
1340 | {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24}, |
1341 | {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL}, | |
1342 | {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11}, | |
1343 | {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19}, | |
1344 | {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8}, | |
1345 | {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6}, | |
7f266840 DJ |
1346 | {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT}, |
1347 | {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT}, | |
1348 | {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE}, | |
c19d1205 | 1349 | {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32}, |
7f266840 DJ |
1350 | {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC}, |
1351 | {BFD_RELOC_ARM_GOT32, R_ARM_GOT32}, | |
1352 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1353 | {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1}, | |
1354 | {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32}, | |
1355 | {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32}, | |
1356 | {BFD_RELOC_ARM_PREL31, R_ARM_PREL31}, | |
ba93b8ac DJ |
1357 | {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}, |
1358 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1359 | {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32}, | |
1360 | {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32}, | |
1361 | {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32}, | |
1362 | {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32}, | |
1363 | {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32}, | |
1364 | {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32}, | |
1365 | {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, | |
1366 | {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, | |
c19d1205 ZW |
1367 | {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT}, |
1368 | {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY}, | |
b6895b4f PB |
1369 | {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC}, |
1370 | {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS}, | |
1371 | {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC}, | |
1372 | {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL}, | |
1373 | {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC}, | |
1374 | {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS}, | |
1375 | {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC}, | |
1376 | {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL}, | |
7f266840 DJ |
1377 | }; |
1378 | ||
1379 | static reloc_howto_type * | |
f1c71a59 ZW |
1380 | elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1381 | bfd_reloc_code_real_type code) | |
7f266840 DJ |
1382 | { |
1383 | unsigned int i; | |
c19d1205 ZW |
1384 | for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++) |
1385 | if (elf32_arm_reloc_map[i].bfd_reloc_val == code) | |
1386 | return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val); | |
7f266840 | 1387 | |
c19d1205 | 1388 | return NULL; |
7f266840 DJ |
1389 | } |
1390 | ||
1391 | /* Support for core dump NOTE sections */ | |
1392 | static bfd_boolean | |
f1c71a59 | 1393 | elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
7f266840 DJ |
1394 | { |
1395 | int offset; | |
1396 | size_t size; | |
1397 | ||
1398 | switch (note->descsz) | |
1399 | { | |
1400 | default: | |
1401 | return FALSE; | |
1402 | ||
1403 | case 148: /* Linux/ARM 32-bit*/ | |
1404 | /* pr_cursig */ | |
1405 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
1406 | ||
1407 | /* pr_pid */ | |
1408 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
1409 | ||
1410 | /* pr_reg */ | |
1411 | offset = 72; | |
1412 | size = 72; | |
1413 | ||
1414 | break; | |
1415 | } | |
1416 | ||
1417 | /* Make a ".reg/999" section. */ | |
1418 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1419 | size, note->descpos + offset); | |
1420 | } | |
1421 | ||
1422 | static bfd_boolean | |
f1c71a59 | 1423 | elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
7f266840 DJ |
1424 | { |
1425 | switch (note->descsz) | |
1426 | { | |
1427 | default: | |
1428 | return FALSE; | |
1429 | ||
1430 | case 124: /* Linux/ARM elf_prpsinfo */ | |
1431 | elf_tdata (abfd)->core_program | |
1432 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); | |
1433 | elf_tdata (abfd)->core_command | |
1434 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); | |
1435 | } | |
1436 | ||
1437 | /* Note that for some reason, a spurious space is tacked | |
1438 | onto the end of the args in some (at least one anyway) | |
1439 | implementations, so strip it off if it exists. */ | |
1440 | ||
1441 | { | |
1442 | char *command = elf_tdata (abfd)->core_command; | |
1443 | int n = strlen (command); | |
1444 | ||
1445 | if (0 < n && command[n - 1] == ' ') | |
1446 | command[n - 1] = '\0'; | |
1447 | } | |
1448 | ||
1449 | return TRUE; | |
1450 | } | |
1451 | ||
1452 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec | |
1453 | #define TARGET_LITTLE_NAME "elf32-littlearm" | |
1454 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vec | |
1455 | #define TARGET_BIG_NAME "elf32-bigarm" | |
1456 | ||
1457 | #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus | |
1458 | #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo | |
1459 | ||
252b5132 RH |
1460 | typedef unsigned long int insn32; |
1461 | typedef unsigned short int insn16; | |
1462 | ||
3a4a14e9 PB |
1463 | /* In lieu of proper flags, assume all EABIv4 or later objects are |
1464 | interworkable. */ | |
57e8b36a | 1465 | #define INTERWORK_FLAG(abfd) \ |
3a4a14e9 | 1466 | (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \ |
85a84e7a | 1467 | || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)) |
9b485d32 | 1468 | |
252b5132 RH |
1469 | /* The linker script knows the section names for placement. |
1470 | The entry_names are used to do simple name mangling on the stubs. | |
1471 | Given a function name, and its type, the stub can be found. The | |
9b485d32 | 1472 | name can be changed. The only requirement is the %s be present. */ |
252b5132 RH |
1473 | #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" |
1474 | #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" | |
1475 | ||
1476 | #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" | |
1477 | #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" | |
1478 | ||
1479 | /* The name of the dynamic interpreter. This is put in the .interp | |
1480 | section. */ | |
1481 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
1482 | ||
5e681ec4 PB |
1483 | #ifdef FOUR_WORD_PLT |
1484 | ||
252b5132 RH |
1485 | /* The first entry in a procedure linkage table looks like |
1486 | this. It is set up so that any shared library function that is | |
59f2c4e7 | 1487 | called before the relocation has been set up calls the dynamic |
9b485d32 | 1488 | linker first. */ |
e5a52504 | 1489 | static const bfd_vma elf32_arm_plt0_entry [] = |
5e681ec4 PB |
1490 | { |
1491 | 0xe52de004, /* str lr, [sp, #-4]! */ | |
1492 | 0xe59fe010, /* ldr lr, [pc, #16] */ | |
1493 | 0xe08fe00e, /* add lr, pc, lr */ | |
1494 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1495 | }; | |
1496 | ||
1497 | /* Subsequent entries in a procedure linkage table look like | |
1498 | this. */ | |
e5a52504 | 1499 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1500 | { |
1501 | 0xe28fc600, /* add ip, pc, #NN */ | |
1502 | 0xe28cca00, /* add ip, ip, #NN */ | |
1503 | 0xe5bcf000, /* ldr pc, [ip, #NN]! */ | |
1504 | 0x00000000, /* unused */ | |
1505 | }; | |
1506 | ||
1507 | #else | |
1508 | ||
5e681ec4 PB |
1509 | /* The first entry in a procedure linkage table looks like |
1510 | this. It is set up so that any shared library function that is | |
1511 | called before the relocation has been set up calls the dynamic | |
1512 | linker first. */ | |
e5a52504 | 1513 | static const bfd_vma elf32_arm_plt0_entry [] = |
917583ad | 1514 | { |
5e681ec4 PB |
1515 | 0xe52de004, /* str lr, [sp, #-4]! */ |
1516 | 0xe59fe004, /* ldr lr, [pc, #4] */ | |
1517 | 0xe08fe00e, /* add lr, pc, lr */ | |
1518 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1519 | 0x00000000, /* &GOT[0] - . */ | |
917583ad | 1520 | }; |
252b5132 RH |
1521 | |
1522 | /* Subsequent entries in a procedure linkage table look like | |
1523 | this. */ | |
e5a52504 | 1524 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1525 | { |
1526 | 0xe28fc600, /* add ip, pc, #0xNN00000 */ | |
1527 | 0xe28cca00, /* add ip, ip, #0xNN000 */ | |
1528 | 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ | |
1529 | }; | |
1530 | ||
1531 | #endif | |
252b5132 | 1532 | |
00a97672 RS |
1533 | /* The format of the first entry in the procedure linkage table |
1534 | for a VxWorks executable. */ | |
1535 | static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] = | |
1536 | { | |
1537 | 0xe52dc008, /* str ip,[sp,#-8]! */ | |
1538 | 0xe59fc000, /* ldr ip,[pc] */ | |
1539 | 0xe59cf008, /* ldr pc,[ip,#8] */ | |
1540 | 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */ | |
1541 | }; | |
1542 | ||
1543 | /* The format of subsequent entries in a VxWorks executable. */ | |
1544 | static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] = | |
1545 | { | |
1546 | 0xe59fc000, /* ldr ip,[pc] */ | |
1547 | 0xe59cf000, /* ldr pc,[ip] */ | |
1548 | 0x00000000, /* .long @got */ | |
1549 | 0xe59fc000, /* ldr ip,[pc] */ | |
1550 | 0xea000000, /* b _PLT */ | |
1551 | 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ | |
1552 | }; | |
1553 | ||
1554 | /* The format of entries in a VxWorks shared library. */ | |
1555 | static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] = | |
1556 | { | |
1557 | 0xe59fc000, /* ldr ip,[pc] */ | |
1558 | 0xe79cf009, /* ldr pc,[ip,r9] */ | |
1559 | 0x00000000, /* .long @got */ | |
1560 | 0xe59fc000, /* ldr ip,[pc] */ | |
1561 | 0xe599f008, /* ldr pc,[r9,#8] */ | |
1562 | 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ | |
1563 | }; | |
1564 | ||
b7693d02 DJ |
1565 | /* An initial stub used if the PLT entry is referenced from Thumb code. */ |
1566 | #define PLT_THUMB_STUB_SIZE 4 | |
1567 | static const bfd_vma elf32_arm_plt_thumb_stub [] = | |
1568 | { | |
1569 | 0x4778, /* bx pc */ | |
1570 | 0x46c0 /* nop */ | |
1571 | }; | |
1572 | ||
e5a52504 MM |
1573 | /* The entries in a PLT when using a DLL-based target with multiple |
1574 | address spaces. */ | |
1575 | static const bfd_vma elf32_arm_symbian_plt_entry [] = | |
1576 | { | |
83a358aa | 1577 | 0xe51ff004, /* ldr pc, [pc, #-4] */ |
e5a52504 MM |
1578 | 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ |
1579 | }; | |
1580 | ||
e489d0ae PB |
1581 | /* Used to build a map of a section. This is required for mixed-endian |
1582 | code/data. */ | |
1583 | ||
1584 | typedef struct elf32_elf_section_map | |
1585 | { | |
1586 | bfd_vma vma; | |
1587 | char type; | |
1588 | } | |
1589 | elf32_arm_section_map; | |
1590 | ||
8e3de13a | 1591 | typedef struct _arm_elf_section_data |
e489d0ae PB |
1592 | { |
1593 | struct bfd_elf_section_data elf; | |
8e3de13a | 1594 | unsigned int mapcount; |
e489d0ae | 1595 | elf32_arm_section_map *map; |
8e3de13a NC |
1596 | } |
1597 | _arm_elf_section_data; | |
e489d0ae PB |
1598 | |
1599 | #define elf32_arm_section_data(sec) \ | |
8e3de13a | 1600 | ((_arm_elf_section_data *) elf_section_data (sec)) |
e489d0ae | 1601 | |
ba93b8ac DJ |
1602 | /* The size of the thread control block. */ |
1603 | #define TCB_SIZE 8 | |
1604 | ||
ee065d83 PB |
1605 | #define NUM_KNOWN_ATTRIBUTES 32 |
1606 | ||
1607 | typedef struct aeabi_attribute | |
1608 | { | |
1609 | int type; | |
1610 | unsigned int i; | |
1611 | char *s; | |
1612 | } aeabi_attribute; | |
1613 | ||
1614 | typedef struct aeabi_attribute_list | |
1615 | { | |
1616 | struct aeabi_attribute_list *next; | |
1617 | int tag; | |
1618 | aeabi_attribute attr; | |
1619 | } aeabi_attribute_list; | |
1620 | ||
ba93b8ac DJ |
1621 | struct elf32_arm_obj_tdata |
1622 | { | |
1623 | struct elf_obj_tdata root; | |
1624 | ||
1625 | /* tls_type for each local got entry. */ | |
1626 | char *local_got_tls_type; | |
ee065d83 PB |
1627 | |
1628 | aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES]; | |
1629 | aeabi_attribute_list *other_eabi_attributes; | |
ba93b8ac DJ |
1630 | }; |
1631 | ||
1632 | #define elf32_arm_tdata(abfd) \ | |
1633 | ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any) | |
1634 | ||
1635 | #define elf32_arm_local_got_tls_type(abfd) \ | |
1636 | (elf32_arm_tdata (abfd)->local_got_tls_type) | |
1637 | ||
1638 | static bfd_boolean | |
1639 | elf32_arm_mkobject (bfd *abfd) | |
1640 | { | |
1641 | bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata); | |
1642 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
1643 | if (abfd->tdata.any == NULL) | |
1644 | return FALSE; | |
1645 | return TRUE; | |
1646 | } | |
1647 | ||
252b5132 RH |
1648 | /* The ARM linker needs to keep track of the number of relocs that it |
1649 | decides to copy in check_relocs for each symbol. This is so that | |
1650 | it can discard PC relative relocs if it doesn't need them when | |
1651 | linking with -Bsymbolic. We store the information in a field | |
1652 | extending the regular ELF linker hash table. */ | |
1653 | ||
ba93b8ac DJ |
1654 | /* This structure keeps track of the number of relocs we have copied |
1655 | for a given symbol. */ | |
5e681ec4 | 1656 | struct elf32_arm_relocs_copied |
917583ad NC |
1657 | { |
1658 | /* Next section. */ | |
5e681ec4 | 1659 | struct elf32_arm_relocs_copied * next; |
917583ad NC |
1660 | /* A section in dynobj. */ |
1661 | asection * section; | |
1662 | /* Number of relocs copied in this section. */ | |
1663 | bfd_size_type count; | |
ba93b8ac DJ |
1664 | /* Number of PC-relative relocs copied in this section. */ |
1665 | bfd_size_type pc_count; | |
917583ad | 1666 | }; |
252b5132 | 1667 | |
ba93b8ac DJ |
1668 | #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent)) |
1669 | ||
ba96a88f | 1670 | /* Arm ELF linker hash entry. */ |
252b5132 | 1671 | struct elf32_arm_link_hash_entry |
917583ad NC |
1672 | { |
1673 | struct elf_link_hash_entry root; | |
252b5132 | 1674 | |
917583ad | 1675 | /* Number of PC relative relocs copied for this symbol. */ |
5e681ec4 | 1676 | struct elf32_arm_relocs_copied * relocs_copied; |
b7693d02 DJ |
1677 | |
1678 | /* We reference count Thumb references to a PLT entry separately, | |
1679 | so that we can emit the Thumb trampoline only if needed. */ | |
1680 | bfd_signed_vma plt_thumb_refcount; | |
1681 | ||
1682 | /* Since PLT entries have variable size if the Thumb prologue is | |
1683 | used, we need to record the index into .got.plt instead of | |
1684 | recomputing it from the PLT offset. */ | |
1685 | bfd_signed_vma plt_got_offset; | |
ba93b8ac DJ |
1686 | |
1687 | #define GOT_UNKNOWN 0 | |
1688 | #define GOT_NORMAL 1 | |
1689 | #define GOT_TLS_GD 2 | |
1690 | #define GOT_TLS_IE 4 | |
1691 | unsigned char tls_type; | |
917583ad | 1692 | }; |
252b5132 | 1693 | |
252b5132 | 1694 | /* Traverse an arm ELF linker hash table. */ |
252b5132 RH |
1695 | #define elf32_arm_link_hash_traverse(table, func, info) \ |
1696 | (elf_link_hash_traverse \ | |
1697 | (&(table)->root, \ | |
b7693d02 | 1698 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
252b5132 RH |
1699 | (info))) |
1700 | ||
1701 | /* Get the ARM elf linker hash table from a link_info structure. */ | |
1702 | #define elf32_arm_hash_table(info) \ | |
1703 | ((struct elf32_arm_link_hash_table *) ((info)->hash)) | |
1704 | ||
9b485d32 | 1705 | /* ARM ELF linker hash table. */ |
252b5132 | 1706 | struct elf32_arm_link_hash_table |
917583ad NC |
1707 | { |
1708 | /* The main hash table. */ | |
1709 | struct elf_link_hash_table root; | |
252b5132 | 1710 | |
4cc11e76 | 1711 | /* The size in bytes of the section containing the Thumb-to-ARM glue. */ |
dc810e39 | 1712 | bfd_size_type thumb_glue_size; |
252b5132 | 1713 | |
4cc11e76 | 1714 | /* The size in bytes of the section containing the ARM-to-Thumb glue. */ |
dc810e39 | 1715 | bfd_size_type arm_glue_size; |
252b5132 | 1716 | |
4cc11e76 | 1717 | /* An arbitrary input BFD chosen to hold the glue sections. */ |
917583ad | 1718 | bfd * bfd_of_glue_owner; |
ba96a88f | 1719 | |
e489d0ae PB |
1720 | /* Nonzero to output a BE8 image. */ |
1721 | int byteswap_code; | |
1722 | ||
9c504268 PB |
1723 | /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. |
1724 | Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */ | |
1725 | int target1_is_rel; | |
1726 | ||
eb043451 PB |
1727 | /* The relocation to use for R_ARM_TARGET2 relocations. */ |
1728 | int target2_reloc; | |
1729 | ||
319850b4 JB |
1730 | /* Nonzero to fix BX instructions for ARMv4 targets. */ |
1731 | int fix_v4bx; | |
1732 | ||
33bfe774 JB |
1733 | /* Nonzero if the ARM/Thumb BLX instructions are available for use. */ |
1734 | int use_blx; | |
1735 | ||
e5a52504 MM |
1736 | /* The number of bytes in the initial entry in the PLT. */ |
1737 | bfd_size_type plt_header_size; | |
1738 | ||
1739 | /* The number of bytes in the subsequent PLT etries. */ | |
1740 | bfd_size_type plt_entry_size; | |
1741 | ||
00a97672 RS |
1742 | /* True if the target system is VxWorks. */ |
1743 | int vxworks_p; | |
1744 | ||
e5a52504 MM |
1745 | /* True if the target system is Symbian OS. */ |
1746 | int symbian_p; | |
1747 | ||
4e7fd91e PB |
1748 | /* True if the target uses REL relocations. */ |
1749 | int use_rel; | |
1750 | ||
5e681ec4 PB |
1751 | /* Short-cuts to get to dynamic linker sections. */ |
1752 | asection *sgot; | |
1753 | asection *sgotplt; | |
1754 | asection *srelgot; | |
1755 | asection *splt; | |
1756 | asection *srelplt; | |
1757 | asection *sdynbss; | |
1758 | asection *srelbss; | |
1759 | ||
00a97672 RS |
1760 | /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */ |
1761 | asection *srelplt2; | |
1762 | ||
ba93b8ac DJ |
1763 | /* Data for R_ARM_TLS_LDM32 relocations. */ |
1764 | union { | |
1765 | bfd_signed_vma refcount; | |
1766 | bfd_vma offset; | |
1767 | } tls_ldm_got; | |
1768 | ||
5e681ec4 PB |
1769 | /* Small local sym to section mapping cache. */ |
1770 | struct sym_sec_cache sym_sec; | |
b7693d02 DJ |
1771 | |
1772 | /* For convenience in allocate_dynrelocs. */ | |
1773 | bfd * obfd; | |
917583ad | 1774 | }; |
252b5132 | 1775 | |
780a67af NC |
1776 | /* Create an entry in an ARM ELF linker hash table. */ |
1777 | ||
1778 | static struct bfd_hash_entry * | |
57e8b36a NC |
1779 | elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, |
1780 | struct bfd_hash_table * table, | |
1781 | const char * string) | |
780a67af NC |
1782 | { |
1783 | struct elf32_arm_link_hash_entry * ret = | |
1784 | (struct elf32_arm_link_hash_entry *) entry; | |
1785 | ||
1786 | /* Allocate the structure if it has not already been allocated by a | |
1787 | subclass. */ | |
1788 | if (ret == (struct elf32_arm_link_hash_entry *) NULL) | |
57e8b36a NC |
1789 | ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); |
1790 | if (ret == NULL) | |
780a67af NC |
1791 | return (struct bfd_hash_entry *) ret; |
1792 | ||
1793 | /* Call the allocation method of the superclass. */ | |
1794 | ret = ((struct elf32_arm_link_hash_entry *) | |
1795 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
1796 | table, string)); | |
57e8b36a | 1797 | if (ret != NULL) |
b7693d02 DJ |
1798 | { |
1799 | ret->relocs_copied = NULL; | |
ba93b8ac | 1800 | ret->tls_type = GOT_UNKNOWN; |
b7693d02 DJ |
1801 | ret->plt_thumb_refcount = 0; |
1802 | ret->plt_got_offset = -1; | |
1803 | } | |
780a67af NC |
1804 | |
1805 | return (struct bfd_hash_entry *) ret; | |
1806 | } | |
1807 | ||
00a97672 RS |
1808 | /* Return true if NAME is the name of the relocation section associated |
1809 | with S. */ | |
1810 | ||
1811 | static bfd_boolean | |
1812 | reloc_section_p (struct elf32_arm_link_hash_table *htab, | |
1813 | const char *name, asection *s) | |
1814 | { | |
1815 | if (htab->use_rel) | |
1816 | return strncmp (name, ".rel", 4) == 0 && strcmp (s->name, name + 4) == 0; | |
1817 | else | |
1818 | return strncmp (name, ".rela", 5) == 0 && strcmp (s->name, name + 5) == 0; | |
1819 | } | |
1820 | ||
1821 | /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up | |
5e681ec4 PB |
1822 | shortcuts to them in our hash table. */ |
1823 | ||
1824 | static bfd_boolean | |
57e8b36a | 1825 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
1826 | { |
1827 | struct elf32_arm_link_hash_table *htab; | |
1828 | ||
e5a52504 MM |
1829 | htab = elf32_arm_hash_table (info); |
1830 | /* BPABI objects never have a GOT, or associated sections. */ | |
1831 | if (htab->symbian_p) | |
1832 | return TRUE; | |
1833 | ||
5e681ec4 PB |
1834 | if (! _bfd_elf_create_got_section (dynobj, info)) |
1835 | return FALSE; | |
1836 | ||
5e681ec4 PB |
1837 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
1838 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
1839 | if (!htab->sgot || !htab->sgotplt) | |
1840 | abort (); | |
1841 | ||
00a97672 RS |
1842 | htab->srelgot = bfd_make_section_with_flags (dynobj, |
1843 | RELOC_SECTION (htab, ".got"), | |
3496cb2a L |
1844 | (SEC_ALLOC | SEC_LOAD |
1845 | | SEC_HAS_CONTENTS | |
1846 | | SEC_IN_MEMORY | |
1847 | | SEC_LINKER_CREATED | |
1848 | | SEC_READONLY)); | |
5e681ec4 | 1849 | if (htab->srelgot == NULL |
5e681ec4 PB |
1850 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) |
1851 | return FALSE; | |
1852 | return TRUE; | |
1853 | } | |
1854 | ||
00a97672 RS |
1855 | /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and |
1856 | .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our | |
5e681ec4 PB |
1857 | hash table. */ |
1858 | ||
1859 | static bfd_boolean | |
57e8b36a | 1860 | elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
1861 | { |
1862 | struct elf32_arm_link_hash_table *htab; | |
1863 | ||
1864 | htab = elf32_arm_hash_table (info); | |
1865 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
1866 | return FALSE; | |
1867 | ||
1868 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
1869 | return FALSE; | |
1870 | ||
1871 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 RS |
1872 | htab->srelplt = bfd_get_section_by_name (dynobj, |
1873 | RELOC_SECTION (htab, ".plt")); | |
5e681ec4 PB |
1874 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
1875 | if (!info->shared) | |
00a97672 RS |
1876 | htab->srelbss = bfd_get_section_by_name (dynobj, |
1877 | RELOC_SECTION (htab, ".bss")); | |
1878 | ||
1879 | if (htab->vxworks_p) | |
1880 | { | |
1881 | if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2)) | |
1882 | return FALSE; | |
1883 | ||
1884 | if (info->shared) | |
1885 | { | |
1886 | htab->plt_header_size = 0; | |
1887 | htab->plt_entry_size | |
1888 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry); | |
1889 | } | |
1890 | else | |
1891 | { | |
1892 | htab->plt_header_size | |
1893 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry); | |
1894 | htab->plt_entry_size | |
1895 | = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry); | |
1896 | } | |
1897 | } | |
5e681ec4 | 1898 | |
e5a52504 MM |
1899 | if (!htab->splt |
1900 | || !htab->srelplt | |
1901 | || !htab->sdynbss | |
5e681ec4 PB |
1902 | || (!info->shared && !htab->srelbss)) |
1903 | abort (); | |
1904 | ||
1905 | return TRUE; | |
1906 | } | |
1907 | ||
1908 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
1909 | ||
1910 | static void | |
fcfa13d2 | 1911 | elf32_arm_copy_indirect_symbol (struct bfd_link_info *info, |
5e681ec4 PB |
1912 | struct elf_link_hash_entry *dir, |
1913 | struct elf_link_hash_entry *ind) | |
1914 | { | |
1915 | struct elf32_arm_link_hash_entry *edir, *eind; | |
1916 | ||
1917 | edir = (struct elf32_arm_link_hash_entry *) dir; | |
1918 | eind = (struct elf32_arm_link_hash_entry *) ind; | |
1919 | ||
1920 | if (eind->relocs_copied != NULL) | |
1921 | { | |
1922 | if (edir->relocs_copied != NULL) | |
1923 | { | |
1924 | struct elf32_arm_relocs_copied **pp; | |
1925 | struct elf32_arm_relocs_copied *p; | |
1926 | ||
fcfa13d2 | 1927 | /* Add reloc counts against the indirect sym to the direct sym |
5e681ec4 PB |
1928 | list. Merge any entries against the same section. */ |
1929 | for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) | |
1930 | { | |
1931 | struct elf32_arm_relocs_copied *q; | |
1932 | ||
1933 | for (q = edir->relocs_copied; q != NULL; q = q->next) | |
1934 | if (q->section == p->section) | |
1935 | { | |
ba93b8ac | 1936 | q->pc_count += p->pc_count; |
5e681ec4 PB |
1937 | q->count += p->count; |
1938 | *pp = p->next; | |
1939 | break; | |
1940 | } | |
1941 | if (q == NULL) | |
1942 | pp = &p->next; | |
1943 | } | |
1944 | *pp = edir->relocs_copied; | |
1945 | } | |
1946 | ||
1947 | edir->relocs_copied = eind->relocs_copied; | |
1948 | eind->relocs_copied = NULL; | |
1949 | } | |
1950 | ||
fcfa13d2 AM |
1951 | /* Copy over PLT info. */ |
1952 | edir->plt_thumb_refcount += eind->plt_thumb_refcount; | |
1953 | eind->plt_thumb_refcount = 0; | |
b7693d02 | 1954 | |
ba93b8ac DJ |
1955 | if (ind->root.type == bfd_link_hash_indirect |
1956 | && dir->got.refcount <= 0) | |
1957 | { | |
1958 | edir->tls_type = eind->tls_type; | |
1959 | eind->tls_type = GOT_UNKNOWN; | |
1960 | } | |
1961 | ||
fcfa13d2 | 1962 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
5e681ec4 PB |
1963 | } |
1964 | ||
9b485d32 | 1965 | /* Create an ARM elf linker hash table. */ |
252b5132 RH |
1966 | |
1967 | static struct bfd_link_hash_table * | |
57e8b36a | 1968 | elf32_arm_link_hash_table_create (bfd *abfd) |
252b5132 RH |
1969 | { |
1970 | struct elf32_arm_link_hash_table *ret; | |
dc810e39 | 1971 | bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); |
252b5132 | 1972 | |
57e8b36a NC |
1973 | ret = bfd_malloc (amt); |
1974 | if (ret == NULL) | |
252b5132 RH |
1975 | return NULL; |
1976 | ||
57e8b36a | 1977 | if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, |
66eb6687 AM |
1978 | elf32_arm_link_hash_newfunc, |
1979 | sizeof (struct elf32_arm_link_hash_entry))) | |
252b5132 | 1980 | { |
e2d34d7d | 1981 | free (ret); |
252b5132 RH |
1982 | return NULL; |
1983 | } | |
1984 | ||
5e681ec4 PB |
1985 | ret->sgot = NULL; |
1986 | ret->sgotplt = NULL; | |
1987 | ret->srelgot = NULL; | |
1988 | ret->splt = NULL; | |
1989 | ret->srelplt = NULL; | |
1990 | ret->sdynbss = NULL; | |
1991 | ret->srelbss = NULL; | |
00a97672 | 1992 | ret->srelplt2 = NULL; |
252b5132 RH |
1993 | ret->thumb_glue_size = 0; |
1994 | ret->arm_glue_size = 0; | |
1995 | ret->bfd_of_glue_owner = NULL; | |
e489d0ae | 1996 | ret->byteswap_code = 0; |
9c504268 | 1997 | ret->target1_is_rel = 0; |
eb043451 | 1998 | ret->target2_reloc = R_ARM_NONE; |
e5a52504 MM |
1999 | #ifdef FOUR_WORD_PLT |
2000 | ret->plt_header_size = 16; | |
2001 | ret->plt_entry_size = 16; | |
2002 | #else | |
2003 | ret->plt_header_size = 20; | |
2004 | ret->plt_entry_size = 12; | |
2005 | #endif | |
33bfe774 JB |
2006 | ret->fix_v4bx = 0; |
2007 | ret->use_blx = 0; | |
00a97672 | 2008 | ret->vxworks_p = 0; |
e5a52504 | 2009 | ret->symbian_p = 0; |
4e7fd91e | 2010 | ret->use_rel = 1; |
5e681ec4 | 2011 | ret->sym_sec.abfd = NULL; |
b7693d02 | 2012 | ret->obfd = abfd; |
ba93b8ac | 2013 | ret->tls_ldm_got.refcount = 0; |
252b5132 RH |
2014 | |
2015 | return &ret->root.root; | |
2016 | } | |
2017 | ||
9b485d32 NC |
2018 | /* Locate the Thumb encoded calling stub for NAME. */ |
2019 | ||
252b5132 | 2020 | static struct elf_link_hash_entry * |
57e8b36a NC |
2021 | find_thumb_glue (struct bfd_link_info *link_info, |
2022 | const char *name, | |
2023 | bfd *input_bfd) | |
252b5132 RH |
2024 | { |
2025 | char *tmp_name; | |
2026 | struct elf_link_hash_entry *hash; | |
2027 | struct elf32_arm_link_hash_table *hash_table; | |
2028 | ||
2029 | /* We need a pointer to the armelf specific hash table. */ | |
2030 | hash_table = elf32_arm_hash_table (link_info); | |
2031 | ||
57e8b36a NC |
2032 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2033 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2034 | |
2035 | BFD_ASSERT (tmp_name); | |
2036 | ||
2037 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2038 | ||
2039 | hash = elf_link_hash_lookup | |
b34976b6 | 2040 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2041 | |
2042 | if (hash == NULL) | |
2043 | /* xgettext:c-format */ | |
d003868e AM |
2044 | (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"), |
2045 | input_bfd, tmp_name, name); | |
252b5132 RH |
2046 | |
2047 | free (tmp_name); | |
2048 | ||
2049 | return hash; | |
2050 | } | |
2051 | ||
9b485d32 NC |
2052 | /* Locate the ARM encoded calling stub for NAME. */ |
2053 | ||
252b5132 | 2054 | static struct elf_link_hash_entry * |
57e8b36a NC |
2055 | find_arm_glue (struct bfd_link_info *link_info, |
2056 | const char *name, | |
2057 | bfd *input_bfd) | |
252b5132 RH |
2058 | { |
2059 | char *tmp_name; | |
2060 | struct elf_link_hash_entry *myh; | |
2061 | struct elf32_arm_link_hash_table *hash_table; | |
2062 | ||
2063 | /* We need a pointer to the elfarm specific hash table. */ | |
2064 | hash_table = elf32_arm_hash_table (link_info); | |
2065 | ||
57e8b36a NC |
2066 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2067 | + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2068 | |
2069 | BFD_ASSERT (tmp_name); | |
2070 | ||
2071 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2072 | ||
2073 | myh = elf_link_hash_lookup | |
b34976b6 | 2074 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2075 | |
2076 | if (myh == NULL) | |
2077 | /* xgettext:c-format */ | |
d003868e AM |
2078 | (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"), |
2079 | input_bfd, tmp_name, name); | |
252b5132 RH |
2080 | |
2081 | free (tmp_name); | |
2082 | ||
2083 | return myh; | |
2084 | } | |
2085 | ||
8f6277f5 | 2086 | /* ARM->Thumb glue (static images): |
252b5132 RH |
2087 | |
2088 | .arm | |
2089 | __func_from_arm: | |
2090 | ldr r12, __func_addr | |
2091 | bx r12 | |
2092 | __func_addr: | |
8f6277f5 | 2093 | .word func @ behave as if you saw a ARM_32 reloc. |
252b5132 | 2094 | |
8f6277f5 PB |
2095 | (relocatable images) |
2096 | .arm | |
2097 | __func_from_arm: | |
2098 | ldr r12, __func_offset | |
2099 | add r12, r12, pc | |
2100 | bx r12 | |
2101 | __func_offset: | |
2102 | .word func - . | |
2103 | */ | |
2104 | ||
2105 | #define ARM2THUMB_STATIC_GLUE_SIZE 12 | |
252b5132 RH |
2106 | static const insn32 a2t1_ldr_insn = 0xe59fc000; |
2107 | static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; | |
2108 | static const insn32 a2t3_func_addr_insn = 0x00000001; | |
2109 | ||
8f6277f5 PB |
2110 | #define ARM2THUMB_PIC_GLUE_SIZE 16 |
2111 | static const insn32 a2t1p_ldr_insn = 0xe59fc004; | |
2112 | static const insn32 a2t2p_add_pc_insn = 0xe08cc00f; | |
2113 | static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c; | |
2114 | ||
9b485d32 | 2115 | /* Thumb->ARM: Thumb->(non-interworking aware) ARM |
252b5132 RH |
2116 | |
2117 | .thumb .thumb | |
2118 | .align 2 .align 2 | |
2119 | __func_from_thumb: __func_from_thumb: | |
2120 | bx pc push {r6, lr} | |
2121 | nop ldr r6, __func_addr | |
2122 | .arm mov lr, pc | |
2123 | __func_change_to_arm: bx r6 | |
2124 | b func .arm | |
2125 | __func_back_to_thumb: | |
2126 | ldmia r13! {r6, lr} | |
2127 | bx lr | |
2128 | __func_addr: | |
9b485d32 | 2129 | .word func */ |
252b5132 RH |
2130 | |
2131 | #define THUMB2ARM_GLUE_SIZE 8 | |
2132 | static const insn16 t2a1_bx_pc_insn = 0x4778; | |
2133 | static const insn16 t2a2_noop_insn = 0x46c0; | |
2134 | static const insn32 t2a3_b_insn = 0xea000000; | |
2135 | ||
7e392df6 | 2136 | #ifndef ELFARM_NABI_C_INCLUDED |
b34976b6 | 2137 | bfd_boolean |
57e8b36a | 2138 | bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) |
252b5132 RH |
2139 | { |
2140 | asection * s; | |
2141 | bfd_byte * foo; | |
2142 | struct elf32_arm_link_hash_table * globals; | |
2143 | ||
2144 | globals = elf32_arm_hash_table (info); | |
2145 | ||
2146 | BFD_ASSERT (globals != NULL); | |
2147 | ||
2148 | if (globals->arm_glue_size != 0) | |
2149 | { | |
2150 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2151 | ||
dc810e39 AM |
2152 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
2153 | ARM2THUMB_GLUE_SECTION_NAME); | |
252b5132 RH |
2154 | |
2155 | BFD_ASSERT (s != NULL); | |
2156 | ||
57e8b36a | 2157 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); |
252b5132 | 2158 | |
eea6121a | 2159 | s->size = globals->arm_glue_size; |
252b5132 RH |
2160 | s->contents = foo; |
2161 | } | |
2162 | ||
2163 | if (globals->thumb_glue_size != 0) | |
2164 | { | |
2165 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2166 | ||
2167 | s = bfd_get_section_by_name | |
2168 | (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2169 | ||
2170 | BFD_ASSERT (s != NULL); | |
2171 | ||
57e8b36a | 2172 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); |
252b5132 | 2173 | |
eea6121a | 2174 | s->size = globals->thumb_glue_size; |
252b5132 RH |
2175 | s->contents = foo; |
2176 | } | |
2177 | ||
b34976b6 | 2178 | return TRUE; |
252b5132 RH |
2179 | } |
2180 | ||
2181 | static void | |
57e8b36a NC |
2182 | record_arm_to_thumb_glue (struct bfd_link_info * link_info, |
2183 | struct elf_link_hash_entry * h) | |
252b5132 RH |
2184 | { |
2185 | const char * name = h->root.root.string; | |
63b0f745 | 2186 | asection * s; |
252b5132 RH |
2187 | char * tmp_name; |
2188 | struct elf_link_hash_entry * myh; | |
14a793b2 | 2189 | struct bfd_link_hash_entry * bh; |
252b5132 | 2190 | struct elf32_arm_link_hash_table * globals; |
dc810e39 | 2191 | bfd_vma val; |
252b5132 RH |
2192 | |
2193 | globals = elf32_arm_hash_table (link_info); | |
2194 | ||
2195 | BFD_ASSERT (globals != NULL); | |
2196 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2197 | ||
2198 | s = bfd_get_section_by_name | |
2199 | (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); | |
2200 | ||
252b5132 RH |
2201 | BFD_ASSERT (s != NULL); |
2202 | ||
57e8b36a | 2203 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
252b5132 RH |
2204 | |
2205 | BFD_ASSERT (tmp_name); | |
2206 | ||
2207 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2208 | ||
2209 | myh = elf_link_hash_lookup | |
b34976b6 | 2210 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2211 | |
2212 | if (myh != NULL) | |
2213 | { | |
9b485d32 | 2214 | /* We've already seen this guy. */ |
252b5132 | 2215 | free (tmp_name); |
9b485d32 | 2216 | return; |
252b5132 RH |
2217 | } |
2218 | ||
57e8b36a NC |
2219 | /* The only trick here is using hash_table->arm_glue_size as the value. |
2220 | Even though the section isn't allocated yet, this is where we will be | |
2221 | putting it. */ | |
14a793b2 | 2222 | bh = NULL; |
dc810e39 AM |
2223 | val = globals->arm_glue_size + 1; |
2224 | _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, | |
2225 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2226 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2227 | |
b7693d02 DJ |
2228 | myh = (struct elf_link_hash_entry *) bh; |
2229 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
2230 | myh->forced_local = 1; | |
2231 | ||
252b5132 RH |
2232 | free (tmp_name); |
2233 | ||
8f6277f5 PB |
2234 | if ((link_info->shared || globals->root.is_relocatable_executable)) |
2235 | globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE; | |
2236 | else | |
2237 | globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE; | |
252b5132 RH |
2238 | |
2239 | return; | |
2240 | } | |
2241 | ||
2242 | static void | |
57e8b36a NC |
2243 | record_thumb_to_arm_glue (struct bfd_link_info *link_info, |
2244 | struct elf_link_hash_entry *h) | |
252b5132 RH |
2245 | { |
2246 | const char *name = h->root.root.string; | |
63b0f745 | 2247 | asection *s; |
252b5132 RH |
2248 | char *tmp_name; |
2249 | struct elf_link_hash_entry *myh; | |
14a793b2 | 2250 | struct bfd_link_hash_entry *bh; |
252b5132 | 2251 | struct elf32_arm_link_hash_table *hash_table; |
dc810e39 | 2252 | bfd_vma val; |
252b5132 RH |
2253 | |
2254 | hash_table = elf32_arm_hash_table (link_info); | |
2255 | ||
2256 | BFD_ASSERT (hash_table != NULL); | |
2257 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); | |
2258 | ||
2259 | s = bfd_get_section_by_name | |
2260 | (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2261 | ||
2262 | BFD_ASSERT (s != NULL); | |
2263 | ||
57e8b36a NC |
2264 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2265 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2266 | |
2267 | BFD_ASSERT (tmp_name); | |
2268 | ||
2269 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2270 | ||
2271 | myh = elf_link_hash_lookup | |
b34976b6 | 2272 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2273 | |
2274 | if (myh != NULL) | |
2275 | { | |
9b485d32 | 2276 | /* We've already seen this guy. */ |
252b5132 | 2277 | free (tmp_name); |
9b485d32 | 2278 | return; |
252b5132 RH |
2279 | } |
2280 | ||
14a793b2 | 2281 | bh = NULL; |
dc810e39 AM |
2282 | val = hash_table->thumb_glue_size + 1; |
2283 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2284 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2285 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2286 | |
9b485d32 | 2287 | /* If we mark it 'Thumb', the disassembler will do a better job. */ |
14a793b2 | 2288 | myh = (struct elf_link_hash_entry *) bh; |
b7693d02 DJ |
2289 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); |
2290 | myh->forced_local = 1; | |
252b5132 RH |
2291 | |
2292 | free (tmp_name); | |
2293 | ||
252b5132 RH |
2294 | #define CHANGE_TO_ARM "__%s_change_to_arm" |
2295 | #define BACK_FROM_ARM "__%s_back_from_arm" | |
2296 | ||
9b485d32 | 2297 | /* Allocate another symbol to mark where we switch to Arm mode. */ |
57e8b36a NC |
2298 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2299 | + strlen (CHANGE_TO_ARM) + 1); | |
252b5132 RH |
2300 | |
2301 | BFD_ASSERT (tmp_name); | |
2302 | ||
2303 | sprintf (tmp_name, CHANGE_TO_ARM, name); | |
2304 | ||
14a793b2 | 2305 | bh = NULL; |
dc810e39 AM |
2306 | val = hash_table->thumb_glue_size + 4, |
2307 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2308 | tmp_name, BSF_LOCAL, s, val, | |
b34976b6 | 2309 | NULL, TRUE, FALSE, &bh); |
252b5132 RH |
2310 | |
2311 | free (tmp_name); | |
2312 | ||
2313 | hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; | |
2314 | ||
2315 | return; | |
2316 | } | |
2317 | ||
8afb0e02 NC |
2318 | /* Add the glue sections to ABFD. This function is called from the |
2319 | linker scripts in ld/emultempl/{armelf}.em. */ | |
9b485d32 | 2320 | |
b34976b6 | 2321 | bfd_boolean |
57e8b36a NC |
2322 | bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, |
2323 | struct bfd_link_info *info) | |
252b5132 | 2324 | { |
252b5132 RH |
2325 | flagword flags; |
2326 | asection *sec; | |
2327 | ||
8afb0e02 NC |
2328 | /* If we are only performing a partial |
2329 | link do not bother adding the glue. */ | |
1049f94e | 2330 | if (info->relocatable) |
b34976b6 | 2331 | return TRUE; |
252b5132 | 2332 | |
252b5132 RH |
2333 | sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
2334 | ||
2335 | if (sec == NULL) | |
2336 | { | |
57db232e NC |
2337 | /* Note: we do not include the flag SEC_LINKER_CREATED, as this |
2338 | will prevent elf_link_input_bfd() from processing the contents | |
2339 | of this section. */ | |
811b4bf6 | 2340 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY; |
252b5132 | 2341 | |
3496cb2a L |
2342 | sec = bfd_make_section_with_flags (abfd, |
2343 | ARM2THUMB_GLUE_SECTION_NAME, | |
2344 | flags); | |
252b5132 RH |
2345 | |
2346 | if (sec == NULL | |
252b5132 | 2347 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2348 | return FALSE; |
9a5aca8c | 2349 | |
57db232e NC |
2350 | /* Set the gc mark to prevent the section from being removed by garbage |
2351 | collection, despite the fact that no relocs refer to this section. */ | |
2352 | sec->gc_mark = 1; | |
252b5132 RH |
2353 | } |
2354 | ||
2355 | sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); | |
2356 | ||
2357 | if (sec == NULL) | |
2358 | { | |
57e8b36a NC |
2359 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
2360 | | SEC_CODE | SEC_READONLY; | |
252b5132 | 2361 | |
3496cb2a L |
2362 | sec = bfd_make_section_with_flags (abfd, |
2363 | THUMB2ARM_GLUE_SECTION_NAME, | |
2364 | flags); | |
252b5132 RH |
2365 | |
2366 | if (sec == NULL | |
252b5132 | 2367 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2368 | return FALSE; |
9a5aca8c | 2369 | |
57db232e | 2370 | sec->gc_mark = 1; |
252b5132 RH |
2371 | } |
2372 | ||
b34976b6 | 2373 | return TRUE; |
8afb0e02 NC |
2374 | } |
2375 | ||
2376 | /* Select a BFD to be used to hold the sections used by the glue code. | |
2377 | This function is called from the linker scripts in ld/emultempl/ | |
2378 | {armelf/pe}.em */ | |
2379 | ||
b34976b6 | 2380 | bfd_boolean |
57e8b36a | 2381 | bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) |
8afb0e02 NC |
2382 | { |
2383 | struct elf32_arm_link_hash_table *globals; | |
2384 | ||
2385 | /* If we are only performing a partial link | |
2386 | do not bother getting a bfd to hold the glue. */ | |
1049f94e | 2387 | if (info->relocatable) |
b34976b6 | 2388 | return TRUE; |
8afb0e02 | 2389 | |
b7693d02 DJ |
2390 | /* Make sure we don't attach the glue sections to a dynamic object. */ |
2391 | BFD_ASSERT (!(abfd->flags & DYNAMIC)); | |
2392 | ||
8afb0e02 NC |
2393 | globals = elf32_arm_hash_table (info); |
2394 | ||
2395 | BFD_ASSERT (globals != NULL); | |
2396 | ||
2397 | if (globals->bfd_of_glue_owner != NULL) | |
b34976b6 | 2398 | return TRUE; |
8afb0e02 | 2399 | |
252b5132 RH |
2400 | /* Save the bfd for later use. */ |
2401 | globals->bfd_of_glue_owner = abfd; | |
cedb70c5 | 2402 | |
b34976b6 | 2403 | return TRUE; |
252b5132 RH |
2404 | } |
2405 | ||
39b41c9c PB |
2406 | static void check_use_blx(struct elf32_arm_link_hash_table *globals) |
2407 | { | |
2408 | if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2) | |
2409 | globals->use_blx = 1; | |
2410 | } | |
2411 | ||
b34976b6 | 2412 | bfd_boolean |
57e8b36a NC |
2413 | bfd_elf32_arm_process_before_allocation (bfd *abfd, |
2414 | struct bfd_link_info *link_info, | |
eb043451 | 2415 | int byteswap_code) |
252b5132 RH |
2416 | { |
2417 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 2418 | Elf_Internal_Rela *internal_relocs = NULL; |
252b5132 RH |
2419 | Elf_Internal_Rela *irel, *irelend; |
2420 | bfd_byte *contents = NULL; | |
252b5132 RH |
2421 | |
2422 | asection *sec; | |
2423 | struct elf32_arm_link_hash_table *globals; | |
2424 | ||
2425 | /* If we are only performing a partial link do not bother | |
2426 | to construct any glue. */ | |
1049f94e | 2427 | if (link_info->relocatable) |
b34976b6 | 2428 | return TRUE; |
252b5132 RH |
2429 | |
2430 | /* Here we have a bfd that is to be included on the link. We have a hook | |
2431 | to do reloc rummaging, before section sizes are nailed down. */ | |
252b5132 | 2432 | globals = elf32_arm_hash_table (link_info); |
39b41c9c | 2433 | check_use_blx (globals); |
252b5132 RH |
2434 | |
2435 | BFD_ASSERT (globals != NULL); | |
2436 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2437 | ||
e489d0ae PB |
2438 | if (byteswap_code && !bfd_big_endian (abfd)) |
2439 | { | |
d003868e AM |
2440 | _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), |
2441 | abfd); | |
e489d0ae PB |
2442 | return FALSE; |
2443 | } | |
2444 | globals->byteswap_code = byteswap_code; | |
f21f3fe0 | 2445 | |
252b5132 RH |
2446 | /* Rummage around all the relocs and map the glue vectors. */ |
2447 | sec = abfd->sections; | |
2448 | ||
2449 | if (sec == NULL) | |
b34976b6 | 2450 | return TRUE; |
252b5132 RH |
2451 | |
2452 | for (; sec != NULL; sec = sec->next) | |
2453 | { | |
2454 | if (sec->reloc_count == 0) | |
2455 | continue; | |
2456 | ||
2457 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
252b5132 | 2458 | |
9b485d32 | 2459 | /* Load the relocs. */ |
6cdc0ccc | 2460 | internal_relocs |
57e8b36a | 2461 | = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, |
45d6a902 | 2462 | (Elf_Internal_Rela *) NULL, FALSE); |
252b5132 | 2463 | |
6cdc0ccc AM |
2464 | if (internal_relocs == NULL) |
2465 | goto error_return; | |
252b5132 | 2466 | |
6cdc0ccc AM |
2467 | irelend = internal_relocs + sec->reloc_count; |
2468 | for (irel = internal_relocs; irel < irelend; irel++) | |
252b5132 RH |
2469 | { |
2470 | long r_type; | |
2471 | unsigned long r_index; | |
252b5132 RH |
2472 | |
2473 | struct elf_link_hash_entry *h; | |
2474 | ||
2475 | r_type = ELF32_R_TYPE (irel->r_info); | |
2476 | r_index = ELF32_R_SYM (irel->r_info); | |
2477 | ||
9b485d32 | 2478 | /* These are the only relocation types we care about. */ |
ba96a88f | 2479 | if ( r_type != R_ARM_PC24 |
b7693d02 | 2480 | && r_type != R_ARM_PLT32 |
5b5bb741 PB |
2481 | && r_type != R_ARM_CALL |
2482 | && r_type != R_ARM_JUMP24 | |
c19d1205 | 2483 | && r_type != R_ARM_THM_CALL) |
252b5132 RH |
2484 | continue; |
2485 | ||
2486 | /* Get the section contents if we haven't done so already. */ | |
2487 | if (contents == NULL) | |
2488 | { | |
2489 | /* Get cached copy if it exists. */ | |
2490 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
2491 | contents = elf_section_data (sec)->this_hdr.contents; | |
2492 | else | |
2493 | { | |
2494 | /* Go get them off disk. */ | |
57e8b36a | 2495 | if (! bfd_malloc_and_get_section (abfd, sec, &contents)) |
252b5132 RH |
2496 | goto error_return; |
2497 | } | |
2498 | } | |
2499 | ||
a7c10850 | 2500 | /* If the relocation is not against a symbol it cannot concern us. */ |
252b5132 RH |
2501 | h = NULL; |
2502 | ||
9b485d32 | 2503 | /* We don't care about local symbols. */ |
252b5132 RH |
2504 | if (r_index < symtab_hdr->sh_info) |
2505 | continue; | |
2506 | ||
9b485d32 | 2507 | /* This is an external symbol. */ |
252b5132 RH |
2508 | r_index -= symtab_hdr->sh_info; |
2509 | h = (struct elf_link_hash_entry *) | |
2510 | elf_sym_hashes (abfd)[r_index]; | |
2511 | ||
2512 | /* If the relocation is against a static symbol it must be within | |
2513 | the current section and so cannot be a cross ARM/Thumb relocation. */ | |
2514 | if (h == NULL) | |
2515 | continue; | |
2516 | ||
b7693d02 DJ |
2517 | /* If the call will go through a PLT entry then we do not need |
2518 | glue. */ | |
2519 | if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1) | |
2520 | continue; | |
2521 | ||
252b5132 RH |
2522 | switch (r_type) |
2523 | { | |
2524 | case R_ARM_PC24: | |
c6596c5e | 2525 | case R_ARM_PLT32: |
5b5bb741 PB |
2526 | case R_ARM_CALL: |
2527 | case R_ARM_JUMP24: | |
252b5132 | 2528 | /* This one is a call from arm code. We need to look up |
2f0ca46a | 2529 | the target of the call. If it is a thumb target, we |
252b5132 | 2530 | insert glue. */ |
39b41c9c PB |
2531 | if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC |
2532 | && !(r_type == R_ARM_CALL && globals->use_blx)) | |
252b5132 RH |
2533 | record_arm_to_thumb_glue (link_info, h); |
2534 | break; | |
2535 | ||
c19d1205 | 2536 | case R_ARM_THM_CALL: |
f21f3fe0 | 2537 | /* This one is a call from thumb code. We look |
2f0ca46a | 2538 | up the target of the call. If it is not a thumb |
bcbdc74c | 2539 | target, we insert glue. */ |
39b41c9c | 2540 | if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx) |
252b5132 RH |
2541 | record_thumb_to_arm_glue (link_info, h); |
2542 | break; | |
2543 | ||
2544 | default: | |
c6596c5e | 2545 | abort (); |
252b5132 RH |
2546 | } |
2547 | } | |
6cdc0ccc AM |
2548 | |
2549 | if (contents != NULL | |
2550 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2551 | free (contents); | |
2552 | contents = NULL; | |
2553 | ||
2554 | if (internal_relocs != NULL | |
2555 | && elf_section_data (sec)->relocs != internal_relocs) | |
2556 | free (internal_relocs); | |
2557 | internal_relocs = NULL; | |
252b5132 RH |
2558 | } |
2559 | ||
b34976b6 | 2560 | return TRUE; |
9a5aca8c | 2561 | |
252b5132 | 2562 | error_return: |
6cdc0ccc AM |
2563 | if (contents != NULL |
2564 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2565 | free (contents); | |
2566 | if (internal_relocs != NULL | |
2567 | && elf_section_data (sec)->relocs != internal_relocs) | |
2568 | free (internal_relocs); | |
9a5aca8c | 2569 | |
b34976b6 | 2570 | return FALSE; |
252b5132 | 2571 | } |
7e392df6 | 2572 | #endif |
252b5132 | 2573 | |
eb043451 | 2574 | |
eb043451 PB |
2575 | /* Set target relocation values needed during linking. */ |
2576 | ||
2577 | void | |
2578 | bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info, | |
2579 | int target1_is_rel, | |
319850b4 | 2580 | char * target2_type, |
33bfe774 JB |
2581 | int fix_v4bx, |
2582 | int use_blx) | |
eb043451 PB |
2583 | { |
2584 | struct elf32_arm_link_hash_table *globals; | |
2585 | ||
2586 | globals = elf32_arm_hash_table (link_info); | |
2587 | ||
2588 | globals->target1_is_rel = target1_is_rel; | |
2589 | if (strcmp (target2_type, "rel") == 0) | |
2590 | globals->target2_reloc = R_ARM_REL32; | |
eeac373a PB |
2591 | else if (strcmp (target2_type, "abs") == 0) |
2592 | globals->target2_reloc = R_ARM_ABS32; | |
eb043451 PB |
2593 | else if (strcmp (target2_type, "got-rel") == 0) |
2594 | globals->target2_reloc = R_ARM_GOT_PREL; | |
2595 | else | |
2596 | { | |
2597 | _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."), | |
2598 | target2_type); | |
2599 | } | |
319850b4 | 2600 | globals->fix_v4bx = fix_v4bx; |
33bfe774 | 2601 | globals->use_blx |= use_blx; |
eb043451 | 2602 | } |
eb043451 | 2603 | |
252b5132 RH |
2604 | /* The thumb form of a long branch is a bit finicky, because the offset |
2605 | encoding is split over two fields, each in it's own instruction. They | |
f21f3fe0 | 2606 | can occur in any order. So given a thumb form of long branch, and an |
252b5132 | 2607 | offset, insert the offset into the thumb branch and return finished |
f21f3fe0 | 2608 | instruction. |
252b5132 | 2609 | |
f21f3fe0 | 2610 | It takes two thumb instructions to encode the target address. Each has |
4cc11e76 | 2611 | 11 bits to invest. The upper 11 bits are stored in one (identified by |
f21f3fe0 UD |
2612 | H-0.. see below), the lower 11 bits are stored in the other (identified |
2613 | by H-1). | |
252b5132 | 2614 | |
f21f3fe0 | 2615 | Combine together and shifted left by 1 (it's a half word address) and |
252b5132 RH |
2616 | there you have it. |
2617 | ||
2618 | Op: 1111 = F, | |
2619 | H-0, upper address-0 = 000 | |
2620 | Op: 1111 = F, | |
2621 | H-1, lower address-0 = 800 | |
2622 | ||
f21f3fe0 | 2623 | They can be ordered either way, but the arm tools I've seen always put |
252b5132 RH |
2624 | the lower one first. It probably doesn't matter. krk@cygnus.com |
2625 | ||
2626 | XXX: Actually the order does matter. The second instruction (H-1) | |
2627 | moves the computed address into the PC, so it must be the second one | |
2628 | in the sequence. The problem, however is that whilst little endian code | |
2629 | stores the instructions in HI then LOW order, big endian code does the | |
dfc5f959 | 2630 | reverse. nickc@cygnus.com. */ |
252b5132 | 2631 | |
dfc5f959 NC |
2632 | #define LOW_HI_ORDER 0xF800F000 |
2633 | #define HI_LOW_ORDER 0xF000F800 | |
252b5132 RH |
2634 | |
2635 | static insn32 | |
57e8b36a | 2636 | insert_thumb_branch (insn32 br_insn, int rel_off) |
252b5132 RH |
2637 | { |
2638 | unsigned int low_bits; | |
2639 | unsigned int high_bits; | |
2640 | ||
252b5132 RH |
2641 | BFD_ASSERT ((rel_off & 1) != 1); |
2642 | ||
dfc5f959 NC |
2643 | rel_off >>= 1; /* Half word aligned address. */ |
2644 | low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ | |
2645 | high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ | |
252b5132 RH |
2646 | |
2647 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) | |
2648 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; | |
2649 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) | |
2650 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; | |
2651 | else | |
9b485d32 | 2652 | /* FIXME: abort is probably not the right call. krk@cygnus.com */ |
57e8b36a | 2653 | abort (); /* Error - not a valid branch instruction form. */ |
252b5132 | 2654 | |
252b5132 RH |
2655 | return br_insn; |
2656 | } | |
2657 | ||
52ab56c2 PB |
2658 | |
2659 | /* Store an Arm insn into an output section not processed by | |
2660 | elf32_arm_write_section. */ | |
2661 | ||
2662 | static void | |
2663 | put_arm_insn (struct elf32_arm_link_hash_table *htab, | |
2664 | bfd * output_bfd, bfd_vma val, void * ptr) | |
2665 | { | |
2666 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
2667 | bfd_putl32 (val, ptr); | |
2668 | else | |
2669 | bfd_putb32 (val, ptr); | |
2670 | } | |
2671 | ||
2672 | ||
2673 | /* Store a 16-bit Thumb insn into an output section not processed by | |
2674 | elf32_arm_write_section. */ | |
2675 | ||
2676 | static void | |
2677 | put_thumb_insn (struct elf32_arm_link_hash_table *htab, | |
2678 | bfd * output_bfd, bfd_vma val, void * ptr) | |
2679 | { | |
2680 | if (htab->byteswap_code != bfd_little_endian (output_bfd)) | |
2681 | bfd_putl16 (val, ptr); | |
2682 | else | |
2683 | bfd_putb16 (val, ptr); | |
2684 | } | |
2685 | ||
2686 | ||
9b485d32 NC |
2687 | /* Thumb code calling an ARM function. */ |
2688 | ||
252b5132 | 2689 | static int |
57e8b36a NC |
2690 | elf32_thumb_to_arm_stub (struct bfd_link_info * info, |
2691 | const char * name, | |
2692 | bfd * input_bfd, | |
2693 | bfd * output_bfd, | |
2694 | asection * input_section, | |
2695 | bfd_byte * hit_data, | |
2696 | asection * sym_sec, | |
2697 | bfd_vma offset, | |
2698 | bfd_signed_vma addend, | |
2699 | bfd_vma val) | |
252b5132 | 2700 | { |
bcbdc74c | 2701 | asection * s = 0; |
dc810e39 | 2702 | bfd_vma my_offset; |
252b5132 RH |
2703 | unsigned long int tmp; |
2704 | long int ret_offset; | |
bcbdc74c NC |
2705 | struct elf_link_hash_entry * myh; |
2706 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
2707 | |
2708 | myh = find_thumb_glue (info, name, input_bfd); | |
2709 | if (myh == NULL) | |
b34976b6 | 2710 | return FALSE; |
252b5132 RH |
2711 | |
2712 | globals = elf32_arm_hash_table (info); | |
2713 | ||
2714 | BFD_ASSERT (globals != NULL); | |
2715 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2716 | ||
2717 | my_offset = myh->root.u.def.value; | |
2718 | ||
2719 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
2720 | THUMB2ARM_GLUE_SECTION_NAME); | |
2721 | ||
2722 | BFD_ASSERT (s != NULL); | |
2723 | BFD_ASSERT (s->contents != NULL); | |
2724 | BFD_ASSERT (s->output_section != NULL); | |
2725 | ||
2726 | if ((my_offset & 0x01) == 0x01) | |
2727 | { | |
2728 | if (sym_sec != NULL | |
2729 | && sym_sec->owner != NULL | |
2730 | && !INTERWORK_FLAG (sym_sec->owner)) | |
2731 | { | |
8f615d07 | 2732 | (*_bfd_error_handler) |
d003868e AM |
2733 | (_("%B(%s): warning: interworking not enabled.\n" |
2734 | " first occurrence: %B: thumb call to arm"), | |
2735 | sym_sec->owner, input_bfd, name); | |
252b5132 | 2736 | |
b34976b6 | 2737 | return FALSE; |
252b5132 RH |
2738 | } |
2739 | ||
2740 | --my_offset; | |
2741 | myh->root.u.def.value = my_offset; | |
2742 | ||
52ab56c2 PB |
2743 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn, |
2744 | s->contents + my_offset); | |
252b5132 | 2745 | |
52ab56c2 PB |
2746 | put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn, |
2747 | s->contents + my_offset + 2); | |
252b5132 RH |
2748 | |
2749 | ret_offset = | |
9b485d32 NC |
2750 | /* Address of destination of the stub. */ |
2751 | ((bfd_signed_vma) val) | |
252b5132 | 2752 | - ((bfd_signed_vma) |
57e8b36a NC |
2753 | /* Offset from the start of the current section |
2754 | to the start of the stubs. */ | |
9b485d32 NC |
2755 | (s->output_offset |
2756 | /* Offset of the start of this stub from the start of the stubs. */ | |
2757 | + my_offset | |
2758 | /* Address of the start of the current section. */ | |
2759 | + s->output_section->vma) | |
2760 | /* The branch instruction is 4 bytes into the stub. */ | |
2761 | + 4 | |
2762 | /* ARM branches work from the pc of the instruction + 8. */ | |
2763 | + 8); | |
252b5132 | 2764 | |
52ab56c2 PB |
2765 | put_arm_insn (globals, output_bfd, |
2766 | (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), | |
2767 | s->contents + my_offset + 4); | |
252b5132 RH |
2768 | } |
2769 | ||
2770 | BFD_ASSERT (my_offset <= globals->thumb_glue_size); | |
2771 | ||
427bfd90 NC |
2772 | /* Now go back and fix up the original BL insn to point to here. */ |
2773 | ret_offset = | |
2774 | /* Address of where the stub is located. */ | |
2775 | (s->output_section->vma + s->output_offset + my_offset) | |
2776 | /* Address of where the BL is located. */ | |
57e8b36a NC |
2777 | - (input_section->output_section->vma + input_section->output_offset |
2778 | + offset) | |
427bfd90 NC |
2779 | /* Addend in the relocation. */ |
2780 | - addend | |
2781 | /* Biassing for PC-relative addressing. */ | |
2782 | - 8; | |
252b5132 RH |
2783 | |
2784 | tmp = bfd_get_32 (input_bfd, hit_data | |
2785 | - input_section->vma); | |
2786 | ||
2787 | bfd_put_32 (output_bfd, | |
dc810e39 | 2788 | (bfd_vma) insert_thumb_branch (tmp, ret_offset), |
252b5132 RH |
2789 | hit_data - input_section->vma); |
2790 | ||
b34976b6 | 2791 | return TRUE; |
252b5132 RH |
2792 | } |
2793 | ||
9b485d32 NC |
2794 | /* Arm code calling a Thumb function. */ |
2795 | ||
252b5132 | 2796 | static int |
57e8b36a NC |
2797 | elf32_arm_to_thumb_stub (struct bfd_link_info * info, |
2798 | const char * name, | |
2799 | bfd * input_bfd, | |
2800 | bfd * output_bfd, | |
2801 | asection * input_section, | |
2802 | bfd_byte * hit_data, | |
2803 | asection * sym_sec, | |
2804 | bfd_vma offset, | |
2805 | bfd_signed_vma addend, | |
2806 | bfd_vma val) | |
252b5132 RH |
2807 | { |
2808 | unsigned long int tmp; | |
dc810e39 | 2809 | bfd_vma my_offset; |
bcbdc74c | 2810 | asection * s; |
252b5132 | 2811 | long int ret_offset; |
bcbdc74c NC |
2812 | struct elf_link_hash_entry * myh; |
2813 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
2814 | |
2815 | myh = find_arm_glue (info, name, input_bfd); | |
2816 | if (myh == NULL) | |
b34976b6 | 2817 | return FALSE; |
252b5132 RH |
2818 | |
2819 | globals = elf32_arm_hash_table (info); | |
2820 | ||
2821 | BFD_ASSERT (globals != NULL); | |
2822 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2823 | ||
2824 | my_offset = myh->root.u.def.value; | |
2825 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
2826 | ARM2THUMB_GLUE_SECTION_NAME); | |
2827 | BFD_ASSERT (s != NULL); | |
2828 | BFD_ASSERT (s->contents != NULL); | |
2829 | BFD_ASSERT (s->output_section != NULL); | |
2830 | ||
2831 | if ((my_offset & 0x01) == 0x01) | |
2832 | { | |
2833 | if (sym_sec != NULL | |
2834 | && sym_sec->owner != NULL | |
2835 | && !INTERWORK_FLAG (sym_sec->owner)) | |
2836 | { | |
8f615d07 | 2837 | (*_bfd_error_handler) |
d003868e AM |
2838 | (_("%B(%s): warning: interworking not enabled.\n" |
2839 | " first occurrence: %B: arm call to thumb"), | |
2840 | sym_sec->owner, input_bfd, name); | |
252b5132 | 2841 | } |
9b485d32 | 2842 | |
252b5132 RH |
2843 | --my_offset; |
2844 | myh->root.u.def.value = my_offset; | |
2845 | ||
8f6277f5 PB |
2846 | if ((info->shared || globals->root.is_relocatable_executable)) |
2847 | { | |
2848 | /* For relocatable objects we can't use absolute addresses, | |
2849 | so construct the address from a relative offset. */ | |
2850 | /* TODO: If the offset is small it's probably worth | |
2851 | constructing the address with adds. */ | |
52ab56c2 PB |
2852 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn, |
2853 | s->contents + my_offset); | |
2854 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn, | |
2855 | s->contents + my_offset + 4); | |
2856 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn, | |
2857 | s->contents + my_offset + 8); | |
8f6277f5 PB |
2858 | /* Adjust the offset by 4 for the position of the add, |
2859 | and 8 for the pipeline offset. */ | |
2860 | ret_offset = (val - (s->output_offset | |
2861 | + s->output_section->vma | |
2862 | + my_offset + 12)) | |
2863 | | 1; | |
2864 | bfd_put_32 (output_bfd, ret_offset, | |
2865 | s->contents + my_offset + 12); | |
2866 | } | |
2867 | else | |
2868 | { | |
52ab56c2 PB |
2869 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn, |
2870 | s->contents + my_offset); | |
252b5132 | 2871 | |
52ab56c2 PB |
2872 | put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn, |
2873 | s->contents + my_offset + 4); | |
252b5132 | 2874 | |
8f6277f5 PB |
2875 | /* It's a thumb address. Add the low order bit. */ |
2876 | bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, | |
2877 | s->contents + my_offset + 8); | |
2878 | } | |
252b5132 RH |
2879 | } |
2880 | ||
2881 | BFD_ASSERT (my_offset <= globals->arm_glue_size); | |
2882 | ||
2883 | tmp = bfd_get_32 (input_bfd, hit_data); | |
2884 | tmp = tmp & 0xFF000000; | |
2885 | ||
9b485d32 | 2886 | /* Somehow these are both 4 too far, so subtract 8. */ |
dc810e39 AM |
2887 | ret_offset = (s->output_offset |
2888 | + my_offset | |
2889 | + s->output_section->vma | |
2890 | - (input_section->output_offset | |
2891 | + input_section->output_section->vma | |
2892 | + offset + addend) | |
2893 | - 8); | |
9a5aca8c | 2894 | |
252b5132 RH |
2895 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); |
2896 | ||
dc810e39 | 2897 | bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); |
252b5132 | 2898 | |
b34976b6 | 2899 | return TRUE; |
252b5132 RH |
2900 | } |
2901 | ||
eb043451 PB |
2902 | /* Some relocations map to different relocations depending on the |
2903 | target. Return the real relocation. */ | |
2904 | static int | |
2905 | arm_real_reloc_type (struct elf32_arm_link_hash_table * globals, | |
2906 | int r_type) | |
2907 | { | |
2908 | switch (r_type) | |
2909 | { | |
2910 | case R_ARM_TARGET1: | |
2911 | if (globals->target1_is_rel) | |
2912 | return R_ARM_REL32; | |
2913 | else | |
2914 | return R_ARM_ABS32; | |
2915 | ||
2916 | case R_ARM_TARGET2: | |
2917 | return globals->target2_reloc; | |
2918 | ||
2919 | default: | |
2920 | return r_type; | |
2921 | } | |
2922 | } | |
eb043451 | 2923 | |
ba93b8ac DJ |
2924 | /* Return the base VMA address which should be subtracted from real addresses |
2925 | when resolving @dtpoff relocation. | |
2926 | This is PT_TLS segment p_vaddr. */ | |
2927 | ||
2928 | static bfd_vma | |
2929 | dtpoff_base (struct bfd_link_info *info) | |
2930 | { | |
2931 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
2932 | if (elf_hash_table (info)->tls_sec == NULL) | |
2933 | return 0; | |
2934 | return elf_hash_table (info)->tls_sec->vma; | |
2935 | } | |
2936 | ||
2937 | /* Return the relocation value for @tpoff relocation | |
2938 | if STT_TLS virtual address is ADDRESS. */ | |
2939 | ||
2940 | static bfd_vma | |
2941 | tpoff (struct bfd_link_info *info, bfd_vma address) | |
2942 | { | |
2943 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
2944 | bfd_vma base; | |
2945 | ||
2946 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
2947 | if (htab->tls_sec == NULL) | |
2948 | return 0; | |
2949 | base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power); | |
2950 | return address - htab->tls_sec->vma + base; | |
2951 | } | |
2952 | ||
00a97672 RS |
2953 | /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA. |
2954 | VALUE is the relocation value. */ | |
2955 | ||
2956 | static bfd_reloc_status_type | |
2957 | elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value) | |
2958 | { | |
2959 | if (value > 0xfff) | |
2960 | return bfd_reloc_overflow; | |
2961 | ||
2962 | value |= bfd_get_32 (abfd, data) & 0xfffff000; | |
2963 | bfd_put_32 (abfd, value, data); | |
2964 | return bfd_reloc_ok; | |
2965 | } | |
2966 | ||
252b5132 | 2967 | /* Perform a relocation as part of a final link. */ |
9b485d32 | 2968 | |
252b5132 | 2969 | static bfd_reloc_status_type |
57e8b36a NC |
2970 | elf32_arm_final_link_relocate (reloc_howto_type * howto, |
2971 | bfd * input_bfd, | |
2972 | bfd * output_bfd, | |
2973 | asection * input_section, | |
2974 | bfd_byte * contents, | |
2975 | Elf_Internal_Rela * rel, | |
2976 | bfd_vma value, | |
2977 | struct bfd_link_info * info, | |
2978 | asection * sym_sec, | |
2979 | const char * sym_name, | |
2980 | int sym_flags, | |
0945cdfd DJ |
2981 | struct elf_link_hash_entry * h, |
2982 | bfd_boolean * unresolved_reloc_p) | |
252b5132 RH |
2983 | { |
2984 | unsigned long r_type = howto->type; | |
2985 | unsigned long r_symndx; | |
2986 | bfd_byte * hit_data = contents + rel->r_offset; | |
2987 | bfd * dynobj = NULL; | |
2988 | Elf_Internal_Shdr * symtab_hdr; | |
2989 | struct elf_link_hash_entry ** sym_hashes; | |
2990 | bfd_vma * local_got_offsets; | |
2991 | asection * sgot = NULL; | |
2992 | asection * splt = NULL; | |
2993 | asection * sreloc = NULL; | |
252b5132 | 2994 | bfd_vma addend; |
ba96a88f NC |
2995 | bfd_signed_vma signed_addend; |
2996 | struct elf32_arm_link_hash_table * globals; | |
f21f3fe0 | 2997 | |
9c504268 PB |
2998 | globals = elf32_arm_hash_table (info); |
2999 | ||
9c504268 PB |
3000 | /* Some relocation type map to different relocations depending on the |
3001 | target. We pick the right one here. */ | |
eb043451 PB |
3002 | r_type = arm_real_reloc_type (globals, r_type); |
3003 | if (r_type != howto->type) | |
3004 | howto = elf32_arm_howto_from_type (r_type); | |
9c504268 | 3005 | |
cac15327 NC |
3006 | /* If the start address has been set, then set the EF_ARM_HASENTRY |
3007 | flag. Setting this more than once is redundant, but the cost is | |
3008 | not too high, and it keeps the code simple. | |
99e4ae17 | 3009 | |
cac15327 NC |
3010 | The test is done here, rather than somewhere else, because the |
3011 | start address is only set just before the final link commences. | |
3012 | ||
3013 | Note - if the user deliberately sets a start address of 0, the | |
3014 | flag will not be set. */ | |
3015 | if (bfd_get_start_address (output_bfd) != 0) | |
3016 | elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; | |
99e4ae17 | 3017 | |
252b5132 RH |
3018 | dynobj = elf_hash_table (info)->dynobj; |
3019 | if (dynobj) | |
3020 | { | |
3021 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
3022 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
3023 | } | |
3024 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
3025 | sym_hashes = elf_sym_hashes (input_bfd); | |
3026 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
3027 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3028 | ||
4e7fd91e | 3029 | if (globals->use_rel) |
ba96a88f | 3030 | { |
4e7fd91e PB |
3031 | addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; |
3032 | ||
3033 | if (addend & ((howto->src_mask + 1) >> 1)) | |
3034 | { | |
3035 | signed_addend = -1; | |
3036 | signed_addend &= ~ howto->src_mask; | |
3037 | signed_addend |= addend; | |
3038 | } | |
3039 | else | |
3040 | signed_addend = addend; | |
ba96a88f NC |
3041 | } |
3042 | else | |
4e7fd91e | 3043 | addend = signed_addend = rel->r_addend; |
f21f3fe0 | 3044 | |
252b5132 RH |
3045 | switch (r_type) |
3046 | { | |
3047 | case R_ARM_NONE: | |
28a094c2 DJ |
3048 | /* We don't need to find a value for this symbol. It's just a |
3049 | marker. */ | |
3050 | *unresolved_reloc_p = FALSE; | |
252b5132 RH |
3051 | return bfd_reloc_ok; |
3052 | ||
00a97672 RS |
3053 | case R_ARM_ABS12: |
3054 | if (!globals->vxworks_p) | |
3055 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
3056 | ||
252b5132 RH |
3057 | case R_ARM_PC24: |
3058 | case R_ARM_ABS32: | |
3059 | case R_ARM_REL32: | |
5b5bb741 PB |
3060 | case R_ARM_CALL: |
3061 | case R_ARM_JUMP24: | |
dfc5f959 | 3062 | case R_ARM_XPC25: |
eb043451 | 3063 | case R_ARM_PREL31: |
7359ea65 | 3064 | case R_ARM_PLT32: |
5e681ec4 PB |
3065 | /* r_symndx will be zero only for relocs against symbols |
3066 | from removed linkonce sections, or sections discarded by | |
3067 | a linker script. */ | |
3068 | if (r_symndx == 0) | |
3069 | return bfd_reloc_ok; | |
3070 | ||
7359ea65 DJ |
3071 | /* Handle relocations which should use the PLT entry. ABS32/REL32 |
3072 | will use the symbol's value, which may point to a PLT entry, but we | |
3073 | don't need to handle that here. If we created a PLT entry, all | |
3074 | branches in this object should go to it. */ | |
ee06dc07 | 3075 | if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
7359ea65 | 3076 | && h != NULL |
c84cd8ee | 3077 | && splt != NULL |
7359ea65 DJ |
3078 | && h->plt.offset != (bfd_vma) -1) |
3079 | { | |
c84cd8ee DJ |
3080 | /* If we've created a .plt section, and assigned a PLT entry to |
3081 | this function, it should not be known to bind locally. If | |
3082 | it were, we would have cleared the PLT entry. */ | |
7359ea65 DJ |
3083 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); |
3084 | ||
3085 | value = (splt->output_section->vma | |
3086 | + splt->output_offset | |
3087 | + h->plt.offset); | |
0945cdfd | 3088 | *unresolved_reloc_p = FALSE; |
7359ea65 DJ |
3089 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
3090 | contents, rel->r_offset, value, | |
00a97672 | 3091 | rel->r_addend); |
7359ea65 DJ |
3092 | } |
3093 | ||
67687978 PB |
3094 | /* When generating a shared object or relocatable executable, these |
3095 | relocations are copied into the output file to be resolved at | |
3096 | run time. */ | |
3097 | if ((info->shared || globals->root.is_relocatable_executable) | |
7359ea65 | 3098 | && (input_section->flags & SEC_ALLOC) |
ee06dc07 PB |
3099 | && (r_type != R_ARM_REL32 |
3100 | || !SYMBOL_CALLS_LOCAL (info, h)) | |
7359ea65 DJ |
3101 | && (h == NULL |
3102 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
3103 | || h->root.type != bfd_link_hash_undefweak) | |
3104 | && r_type != R_ARM_PC24 | |
5b5bb741 PB |
3105 | && r_type != R_ARM_CALL |
3106 | && r_type != R_ARM_JUMP24 | |
ee06dc07 | 3107 | && r_type != R_ARM_PREL31 |
7359ea65 | 3108 | && r_type != R_ARM_PLT32) |
252b5132 | 3109 | { |
947216bf AM |
3110 | Elf_Internal_Rela outrel; |
3111 | bfd_byte *loc; | |
b34976b6 | 3112 | bfd_boolean skip, relocate; |
f21f3fe0 | 3113 | |
0945cdfd DJ |
3114 | *unresolved_reloc_p = FALSE; |
3115 | ||
252b5132 RH |
3116 | if (sreloc == NULL) |
3117 | { | |
3118 | const char * name; | |
f21f3fe0 | 3119 | |
252b5132 RH |
3120 | name = (bfd_elf_string_from_elf_section |
3121 | (input_bfd, | |
3122 | elf_elfheader (input_bfd)->e_shstrndx, | |
3123 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
3124 | if (name == NULL) | |
3125 | return bfd_reloc_notsupported; | |
f21f3fe0 | 3126 | |
00a97672 | 3127 | BFD_ASSERT (reloc_section_p (globals, name, input_section)); |
f21f3fe0 | 3128 | |
252b5132 RH |
3129 | sreloc = bfd_get_section_by_name (dynobj, name); |
3130 | BFD_ASSERT (sreloc != NULL); | |
3131 | } | |
f21f3fe0 | 3132 | |
b34976b6 AM |
3133 | skip = FALSE; |
3134 | relocate = FALSE; | |
f21f3fe0 | 3135 | |
00a97672 | 3136 | outrel.r_addend = addend; |
c629eae0 JJ |
3137 | outrel.r_offset = |
3138 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
3139 | rel->r_offset); | |
3140 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 3141 | skip = TRUE; |
0bb2d96a | 3142 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 3143 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
3144 | outrel.r_offset += (input_section->output_section->vma |
3145 | + input_section->output_offset); | |
f21f3fe0 | 3146 | |
252b5132 | 3147 | if (skip) |
0bb2d96a | 3148 | memset (&outrel, 0, sizeof outrel); |
5e681ec4 PB |
3149 | else if (h != NULL |
3150 | && h->dynindx != -1 | |
7359ea65 | 3151 | && (!info->shared |
5e681ec4 | 3152 | || !info->symbolic |
f5385ebf | 3153 | || !h->def_regular)) |
5e681ec4 | 3154 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
252b5132 RH |
3155 | else |
3156 | { | |
a16385dc MM |
3157 | int symbol; |
3158 | ||
5e681ec4 | 3159 | /* This symbol is local, or marked to become local. */ |
b7693d02 DJ |
3160 | if (sym_flags == STT_ARM_TFUNC) |
3161 | value |= 1; | |
a16385dc | 3162 | if (globals->symbian_p) |
6366ff1e MM |
3163 | { |
3164 | /* On Symbian OS, the data segment and text segement | |
3165 | can be relocated independently. Therefore, we | |
3166 | must indicate the segment to which this | |
3167 | relocation is relative. The BPABI allows us to | |
3168 | use any symbol in the right segment; we just use | |
3169 | the section symbol as it is convenient. (We | |
3170 | cannot use the symbol given by "h" directly as it | |
3171 | will not appear in the dynamic symbol table.) */ | |
10dbd1f3 NC |
3172 | if (sym_sec) |
3173 | symbol = elf_section_data (sym_sec->output_section)->dynindx; | |
3174 | else | |
3175 | symbol = elf_section_data (input_section->output_section)->dynindx; | |
6366ff1e MM |
3176 | BFD_ASSERT (symbol != 0); |
3177 | } | |
a16385dc MM |
3178 | else |
3179 | /* On SVR4-ish systems, the dynamic loader cannot | |
3180 | relocate the text and data segments independently, | |
3181 | so the symbol does not matter. */ | |
3182 | symbol = 0; | |
3183 | outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE); | |
00a97672 RS |
3184 | if (globals->use_rel) |
3185 | relocate = TRUE; | |
3186 | else | |
3187 | outrel.r_addend += value; | |
252b5132 | 3188 | } |
f21f3fe0 | 3189 | |
947216bf | 3190 | loc = sreloc->contents; |
00a97672 RS |
3191 | loc += sreloc->reloc_count++ * RELOC_SIZE (globals); |
3192 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
9a5aca8c | 3193 | |
f21f3fe0 | 3194 | /* If this reloc is against an external symbol, we do not want to |
252b5132 | 3195 | fiddle with the addend. Otherwise, we need to include the symbol |
9b485d32 | 3196 | value so that it becomes an addend for the dynamic reloc. */ |
252b5132 RH |
3197 | if (! relocate) |
3198 | return bfd_reloc_ok; | |
9a5aca8c | 3199 | |
f21f3fe0 | 3200 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
252b5132 RH |
3201 | contents, rel->r_offset, value, |
3202 | (bfd_vma) 0); | |
3203 | } | |
3204 | else switch (r_type) | |
3205 | { | |
00a97672 RS |
3206 | case R_ARM_ABS12: |
3207 | return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); | |
3208 | ||
dfc5f959 | 3209 | case R_ARM_XPC25: /* Arm BLX instruction. */ |
5b5bb741 PB |
3210 | case R_ARM_CALL: |
3211 | case R_ARM_JUMP24: | |
dfc5f959 | 3212 | case R_ARM_PC24: /* Arm B/BL instruction */ |
7359ea65 | 3213 | case R_ARM_PLT32: |
dfc5f959 | 3214 | if (r_type == R_ARM_XPC25) |
252b5132 | 3215 | { |
dfc5f959 NC |
3216 | /* Check for Arm calling Arm function. */ |
3217 | /* FIXME: Should we translate the instruction into a BL | |
3218 | instruction instead ? */ | |
3219 | if (sym_flags != STT_ARM_TFUNC) | |
d003868e AM |
3220 | (*_bfd_error_handler) |
3221 | (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), | |
3222 | input_bfd, | |
3223 | h ? h->root.root.string : "(local)"); | |
dfc5f959 | 3224 | } |
39b41c9c | 3225 | else if (r_type != R_ARM_CALL || !globals->use_blx) |
dfc5f959 NC |
3226 | { |
3227 | /* Check for Arm calling Thumb function. */ | |
3228 | if (sym_flags == STT_ARM_TFUNC) | |
3229 | { | |
57e8b36a NC |
3230 | elf32_arm_to_thumb_stub (info, sym_name, input_bfd, |
3231 | output_bfd, input_section, | |
3232 | hit_data, sym_sec, rel->r_offset, | |
dfc5f959 NC |
3233 | signed_addend, value); |
3234 | return bfd_reloc_ok; | |
3235 | } | |
252b5132 | 3236 | } |
ba96a88f | 3237 | |
dea514f5 PB |
3238 | /* The ARM ELF ABI says that this reloc is computed as: S - P + A |
3239 | where: | |
3240 | S is the address of the symbol in the relocation. | |
3241 | P is address of the instruction being relocated. | |
3242 | A is the addend (extracted from the instruction) in bytes. | |
3243 | ||
3244 | S is held in 'value'. | |
3245 | P is the base address of the section containing the | |
3246 | instruction plus the offset of the reloc into that | |
3247 | section, ie: | |
3248 | (input_section->output_section->vma + | |
3249 | input_section->output_offset + | |
3250 | rel->r_offset). | |
3251 | A is the addend, converted into bytes, ie: | |
3252 | (signed_addend * 4) | |
3253 | ||
3254 | Note: None of these operations have knowledge of the pipeline | |
3255 | size of the processor, thus it is up to the assembler to | |
3256 | encode this information into the addend. */ | |
3257 | value -= (input_section->output_section->vma | |
3258 | + input_section->output_offset); | |
3259 | value -= rel->r_offset; | |
4e7fd91e PB |
3260 | if (globals->use_rel) |
3261 | value += (signed_addend << howto->size); | |
3262 | else | |
3263 | /* RELA addends do not have to be adjusted by howto->size. */ | |
3264 | value += signed_addend; | |
23080146 | 3265 | |
dcb5e6e6 NC |
3266 | signed_addend = value; |
3267 | signed_addend >>= howto->rightshift; | |
9a5aca8c | 3268 | |
59f2c4e7 NC |
3269 | /* It is not an error for an undefined weak reference to be |
3270 | out of range. Any program that branches to such a symbol | |
9a5aca8c AM |
3271 | is going to crash anyway, so there is no point worrying |
3272 | about getting the destination exactly right. */ | |
59f2c4e7 NC |
3273 | if (! h || h->root.type != bfd_link_hash_undefweak) |
3274 | { | |
9b485d32 | 3275 | /* Perform a signed range check. */ |
dcb5e6e6 | 3276 | if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) |
59f2c4e7 NC |
3277 | || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) |
3278 | return bfd_reloc_overflow; | |
3279 | } | |
9a5aca8c | 3280 | |
39b41c9c PB |
3281 | addend = (value & 2); |
3282 | ||
3283 | value = (signed_addend & howto->dst_mask) | |
3284 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); | |
3285 | ||
3286 | /* Set the H bit in the BLX instruction. */ | |
3287 | if (sym_flags == STT_ARM_TFUNC) | |
3288 | { | |
3289 | if (addend) | |
3290 | value |= (1 << 24); | |
3291 | else | |
3292 | value &= ~(bfd_vma)(1 << 24); | |
3293 | } | |
3294 | if (r_type == R_ARM_CALL) | |
3295 | { | |
3296 | /* Select the correct instruction (BL or BLX). */ | |
3297 | if (sym_flags == STT_ARM_TFUNC) | |
3298 | value |= (1 << 28); | |
3299 | else | |
3300 | { | |
3301 | value &= ~(bfd_vma)(1 << 28); | |
3302 | value |= (1 << 24); | |
3303 | } | |
3304 | } | |
252b5132 | 3305 | break; |
f21f3fe0 | 3306 | |
252b5132 RH |
3307 | case R_ARM_ABS32: |
3308 | value += addend; | |
3309 | if (sym_flags == STT_ARM_TFUNC) | |
3310 | value |= 1; | |
3311 | break; | |
f21f3fe0 | 3312 | |
252b5132 | 3313 | case R_ARM_REL32: |
a8bc6c78 PB |
3314 | value += addend; |
3315 | if (sym_flags == STT_ARM_TFUNC) | |
3316 | value |= 1; | |
252b5132 | 3317 | value -= (input_section->output_section->vma |
62efb346 | 3318 | + input_section->output_offset + rel->r_offset); |
252b5132 | 3319 | break; |
eb043451 | 3320 | |
eb043451 PB |
3321 | case R_ARM_PREL31: |
3322 | value -= (input_section->output_section->vma | |
3323 | + input_section->output_offset + rel->r_offset); | |
3324 | value += signed_addend; | |
3325 | if (! h || h->root.type != bfd_link_hash_undefweak) | |
3326 | { | |
3327 | /* Check for overflow */ | |
3328 | if ((value ^ (value >> 1)) & (1 << 30)) | |
3329 | return bfd_reloc_overflow; | |
3330 | } | |
3331 | value &= 0x7fffffff; | |
3332 | value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000); | |
3333 | if (sym_flags == STT_ARM_TFUNC) | |
3334 | value |= 1; | |
3335 | break; | |
252b5132 | 3336 | } |
f21f3fe0 | 3337 | |
252b5132 RH |
3338 | bfd_put_32 (input_bfd, value, hit_data); |
3339 | return bfd_reloc_ok; | |
3340 | ||
3341 | case R_ARM_ABS8: | |
3342 | value += addend; | |
3343 | if ((long) value > 0x7f || (long) value < -0x80) | |
3344 | return bfd_reloc_overflow; | |
3345 | ||
3346 | bfd_put_8 (input_bfd, value, hit_data); | |
3347 | return bfd_reloc_ok; | |
3348 | ||
3349 | case R_ARM_ABS16: | |
3350 | value += addend; | |
3351 | ||
3352 | if ((long) value > 0x7fff || (long) value < -0x8000) | |
3353 | return bfd_reloc_overflow; | |
3354 | ||
3355 | bfd_put_16 (input_bfd, value, hit_data); | |
3356 | return bfd_reloc_ok; | |
3357 | ||
252b5132 | 3358 | case R_ARM_THM_ABS5: |
9b485d32 | 3359 | /* Support ldr and str instructions for the thumb. */ |
4e7fd91e PB |
3360 | if (globals->use_rel) |
3361 | { | |
3362 | /* Need to refetch addend. */ | |
3363 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
3364 | /* ??? Need to determine shift amount from operand size. */ | |
3365 | addend >>= howto->rightshift; | |
3366 | } | |
252b5132 RH |
3367 | value += addend; |
3368 | ||
3369 | /* ??? Isn't value unsigned? */ | |
3370 | if ((long) value > 0x1f || (long) value < -0x10) | |
3371 | return bfd_reloc_overflow; | |
3372 | ||
3373 | /* ??? Value needs to be properly shifted into place first. */ | |
3374 | value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; | |
3375 | bfd_put_16 (input_bfd, value, hit_data); | |
3376 | return bfd_reloc_ok; | |
3377 | ||
dfc5f959 | 3378 | case R_ARM_THM_XPC22: |
c19d1205 | 3379 | case R_ARM_THM_CALL: |
dfc5f959 | 3380 | /* Thumb BL (branch long instruction). */ |
252b5132 | 3381 | { |
b34976b6 AM |
3382 | bfd_vma relocation; |
3383 | bfd_boolean overflow = FALSE; | |
3384 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3385 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
df212a7e | 3386 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; |
ba96a88f | 3387 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; |
b34976b6 | 3388 | bfd_vma check; |
252b5132 | 3389 | bfd_signed_vma signed_check; |
252b5132 | 3390 | |
252b5132 RH |
3391 | /* Need to refetch the addend and squish the two 11 bit pieces |
3392 | together. */ | |
4e7fd91e PB |
3393 | if (globals->use_rel) |
3394 | { | |
3395 | bfd_vma upper = upper_insn & 0x7ff; | |
3396 | bfd_vma lower = lower_insn & 0x7ff; | |
3397 | upper = (upper ^ 0x400) - 0x400; /* Sign extend. */ | |
3398 | addend = (upper << 12) | (lower << 1); | |
3399 | signed_addend = addend; | |
3400 | } | |
cb1afa5c | 3401 | |
dfc5f959 NC |
3402 | if (r_type == R_ARM_THM_XPC22) |
3403 | { | |
3404 | /* Check for Thumb to Thumb call. */ | |
3405 | /* FIXME: Should we translate the instruction into a BL | |
3406 | instruction instead ? */ | |
3407 | if (sym_flags == STT_ARM_TFUNC) | |
d003868e AM |
3408 | (*_bfd_error_handler) |
3409 | (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), | |
3410 | input_bfd, | |
3411 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
3412 | } |
3413 | else | |
252b5132 | 3414 | { |
dfc5f959 NC |
3415 | /* If it is not a call to Thumb, assume call to Arm. |
3416 | If it is a call relative to a section name, then it is not a | |
b7693d02 DJ |
3417 | function call at all, but rather a long jump. Calls through |
3418 | the PLT do not require stubs. */ | |
3419 | if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION | |
3420 | && (h == NULL || splt == NULL | |
3421 | || h->plt.offset == (bfd_vma) -1)) | |
dfc5f959 | 3422 | { |
39b41c9c PB |
3423 | if (globals->use_blx) |
3424 | { | |
3425 | /* Convert BL to BLX. */ | |
3426 | lower_insn = (lower_insn & ~0x1000) | 0x0800; | |
3427 | } | |
3428 | else if (elf32_thumb_to_arm_stub | |
dfc5f959 NC |
3429 | (info, sym_name, input_bfd, output_bfd, input_section, |
3430 | hit_data, sym_sec, rel->r_offset, signed_addend, value)) | |
3431 | return bfd_reloc_ok; | |
3432 | else | |
3433 | return bfd_reloc_dangerous; | |
3434 | } | |
39b41c9c PB |
3435 | else if (sym_flags == STT_ARM_TFUNC && globals->use_blx) |
3436 | { | |
3437 | /* Make sure this is a BL. */ | |
3438 | lower_insn |= 0x1800; | |
3439 | } | |
252b5132 | 3440 | } |
f21f3fe0 | 3441 | |
b7693d02 DJ |
3442 | /* Handle calls via the PLT. */ |
3443 | if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) | |
3444 | { | |
3445 | value = (splt->output_section->vma | |
3446 | + splt->output_offset | |
3447 | + h->plt.offset); | |
33bfe774 JB |
3448 | if (globals->use_blx) |
3449 | { | |
3450 | /* If the Thumb BLX instruction is available, convert the | |
3451 | BL to a BLX instruction to call the ARM-mode PLT entry. */ | |
39b41c9c | 3452 | lower_insn = (lower_insn & ~0x1000) | 0x0800; |
33bfe774 JB |
3453 | } |
3454 | else | |
3455 | /* Target the Thumb stub before the ARM PLT entry. */ | |
3456 | value -= PLT_THUMB_STUB_SIZE; | |
0945cdfd | 3457 | *unresolved_reloc_p = FALSE; |
b7693d02 DJ |
3458 | } |
3459 | ||
ba96a88f | 3460 | relocation = value + signed_addend; |
f21f3fe0 | 3461 | |
252b5132 | 3462 | relocation -= (input_section->output_section->vma |
ba96a88f NC |
3463 | + input_section->output_offset |
3464 | + rel->r_offset); | |
9a5aca8c | 3465 | |
252b5132 RH |
3466 | check = relocation >> howto->rightshift; |
3467 | ||
3468 | /* If this is a signed value, the rightshift just dropped | |
3469 | leading 1 bits (assuming twos complement). */ | |
3470 | if ((bfd_signed_vma) relocation >= 0) | |
3471 | signed_check = check; | |
3472 | else | |
3473 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
3474 | ||
252b5132 | 3475 | /* Assumes two's complement. */ |
ba96a88f | 3476 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
b34976b6 | 3477 | overflow = TRUE; |
252b5132 | 3478 | |
39b41c9c | 3479 | if ((lower_insn & 0x1800) == 0x0800) |
c62e1cc3 NC |
3480 | /* For a BLX instruction, make sure that the relocation is rounded up |
3481 | to a word boundary. This follows the semantics of the instruction | |
3482 | which specifies that bit 1 of the target address will come from bit | |
3483 | 1 of the base address. */ | |
3484 | relocation = (relocation + 2) & ~ 3; | |
cb1afa5c | 3485 | |
c62e1cc3 NC |
3486 | /* Put RELOCATION back into the insn. */ |
3487 | upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff); | |
3488 | lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff); | |
3489 | ||
252b5132 RH |
3490 | /* Put the relocated value back in the object file: */ |
3491 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
3492 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
3493 | ||
3494 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
3495 | } | |
3496 | break; | |
3497 | ||
c19d1205 ZW |
3498 | case R_ARM_THM_JUMP24: |
3499 | /* Thumb32 unconditional branch instruction. */ | |
3500 | { | |
3501 | bfd_vma relocation; | |
3502 | bfd_boolean overflow = FALSE; | |
3503 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3504 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
3505 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
3506 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
3507 | bfd_vma check; | |
3508 | bfd_signed_vma signed_check; | |
3509 | ||
3510 | /* Need to refetch the addend, reconstruct the top three bits, and glue the | |
3511 | two pieces together. */ | |
3512 | if (globals->use_rel) | |
3513 | { | |
3514 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
3515 | bfd_vma hi = (upper_insn & 0x03ff); | |
3516 | bfd_vma I1 = (lower_insn & 0x2000) >> 13; | |
3517 | bfd_vma I2 = (lower_insn & 0x0800) >> 11; | |
3518 | bfd_vma lo = (lower_insn & 0x07ff); | |
3519 | ||
3520 | I1 = !(I1 ^ S); | |
3521 | I2 = !(I2 ^ S); | |
3522 | S = !S; | |
3523 | ||
3524 | signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1); | |
3525 | signed_addend -= (1 << 24); /* Sign extend. */ | |
3526 | } | |
3527 | ||
3528 | /* ??? Should handle interworking? GCC might someday try to | |
3529 | use this for tail calls. */ | |
3530 | ||
3531 | relocation = value + signed_addend; | |
3532 | relocation -= (input_section->output_section->vma | |
3533 | + input_section->output_offset | |
3534 | + rel->r_offset); | |
3535 | ||
3536 | check = relocation >> howto->rightshift; | |
3537 | ||
3538 | /* If this is a signed value, the rightshift just dropped | |
3539 | leading 1 bits (assuming twos complement). */ | |
3540 | if ((bfd_signed_vma) relocation >= 0) | |
3541 | signed_check = check; | |
3542 | else | |
3543 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
3544 | ||
3545 | /* Assumes two's complement. */ | |
3546 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
3547 | overflow = TRUE; | |
3548 | ||
3549 | /* Put RELOCATION back into the insn. */ | |
3550 | { | |
3551 | bfd_vma S = (relocation & 0x01000000) >> 24; | |
3552 | bfd_vma I1 = (relocation & 0x00800000) >> 23; | |
3553 | bfd_vma I2 = (relocation & 0x00400000) >> 22; | |
3554 | bfd_vma hi = (relocation & 0x003ff000) >> 12; | |
3555 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
3556 | ||
3557 | I1 = !(I1 ^ S); | |
3558 | I2 = !(I2 ^ S); | |
3559 | ||
3560 | upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi; | |
3561 | lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo; | |
3562 | } | |
3563 | ||
3564 | /* Put the relocated value back in the object file: */ | |
3565 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
3566 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
3567 | ||
3568 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
3569 | } | |
3570 | ||
3571 | case R_ARM_THM_JUMP19: | |
3572 | /* Thumb32 conditional branch instruction. */ | |
3573 | { | |
3574 | bfd_vma relocation; | |
3575 | bfd_boolean overflow = FALSE; | |
3576 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3577 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
3578 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
3579 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
3580 | bfd_vma check; | |
3581 | bfd_signed_vma signed_check; | |
3582 | ||
3583 | /* Need to refetch the addend, reconstruct the top three bits, | |
3584 | and squish the two 11 bit pieces together. */ | |
3585 | if (globals->use_rel) | |
3586 | { | |
3587 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
3588 | bfd_vma upper = (upper_insn & 0x001f); | |
3589 | bfd_vma J1 = (lower_insn & 0x2000) >> 13; | |
3590 | bfd_vma J2 = (lower_insn & 0x0800) >> 11; | |
3591 | bfd_vma lower = (lower_insn & 0x07ff); | |
3592 | ||
3593 | upper |= J2 << 6; | |
3594 | upper |= J1 << 7; | |
3595 | upper |= ~S << 8; | |
3596 | upper -= 0x0100; /* Sign extend. */ | |
3597 | ||
3598 | addend = (upper << 12) | (lower << 1); | |
3599 | signed_addend = addend; | |
3600 | } | |
3601 | ||
3602 | /* ??? Should handle interworking? GCC might someday try to | |
3603 | use this for tail calls. */ | |
3604 | ||
3605 | relocation = value + signed_addend; | |
3606 | relocation -= (input_section->output_section->vma | |
3607 | + input_section->output_offset | |
3608 | + rel->r_offset); | |
3609 | ||
3610 | check = relocation >> howto->rightshift; | |
3611 | ||
3612 | /* If this is a signed value, the rightshift just dropped | |
3613 | leading 1 bits (assuming twos complement). */ | |
3614 | if ((bfd_signed_vma) relocation >= 0) | |
3615 | signed_check = check; | |
3616 | else | |
3617 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
3618 | ||
3619 | /* Assumes two's complement. */ | |
3620 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
3621 | overflow = TRUE; | |
3622 | ||
3623 | /* Put RELOCATION back into the insn. */ | |
3624 | { | |
3625 | bfd_vma S = (relocation & 0x00100000) >> 20; | |
3626 | bfd_vma J2 = (relocation & 0x00080000) >> 19; | |
3627 | bfd_vma J1 = (relocation & 0x00040000) >> 18; | |
3628 | bfd_vma hi = (relocation & 0x0003f000) >> 12; | |
3629 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
3630 | ||
3631 | upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi; | |
3632 | lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo; | |
3633 | } | |
3634 | ||
3635 | /* Put the relocated value back in the object file: */ | |
3636 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
3637 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
3638 | ||
3639 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
3640 | } | |
3641 | ||
3642 | case R_ARM_THM_JUMP11: | |
3643 | case R_ARM_THM_JUMP8: | |
3644 | case R_ARM_THM_JUMP6: | |
51c5503b NC |
3645 | /* Thumb B (branch) instruction). */ |
3646 | { | |
6cf9e9fe | 3647 | bfd_signed_vma relocation; |
51c5503b NC |
3648 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; |
3649 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
51c5503b NC |
3650 | bfd_signed_vma signed_check; |
3651 | ||
c19d1205 ZW |
3652 | /* CZB cannot jump backward. */ |
3653 | if (r_type == R_ARM_THM_JUMP6) | |
3654 | reloc_signed_min = 0; | |
3655 | ||
4e7fd91e | 3656 | if (globals->use_rel) |
6cf9e9fe | 3657 | { |
4e7fd91e PB |
3658 | /* Need to refetch addend. */ |
3659 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
3660 | if (addend & ((howto->src_mask + 1) >> 1)) | |
3661 | { | |
3662 | signed_addend = -1; | |
3663 | signed_addend &= ~ howto->src_mask; | |
3664 | signed_addend |= addend; | |
3665 | } | |
3666 | else | |
3667 | signed_addend = addend; | |
3668 | /* The value in the insn has been right shifted. We need to | |
3669 | undo this, so that we can perform the address calculation | |
3670 | in terms of bytes. */ | |
3671 | signed_addend <<= howto->rightshift; | |
6cf9e9fe | 3672 | } |
6cf9e9fe | 3673 | relocation = value + signed_addend; |
51c5503b NC |
3674 | |
3675 | relocation -= (input_section->output_section->vma | |
3676 | + input_section->output_offset | |
3677 | + rel->r_offset); | |
3678 | ||
6cf9e9fe NC |
3679 | relocation >>= howto->rightshift; |
3680 | signed_check = relocation; | |
c19d1205 ZW |
3681 | |
3682 | if (r_type == R_ARM_THM_JUMP6) | |
3683 | relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3); | |
3684 | else | |
3685 | relocation &= howto->dst_mask; | |
51c5503b | 3686 | relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); |
cedb70c5 | 3687 | |
51c5503b NC |
3688 | bfd_put_16 (input_bfd, relocation, hit_data); |
3689 | ||
3690 | /* Assumes two's complement. */ | |
3691 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
3692 | return bfd_reloc_overflow; | |
3693 | ||
3694 | return bfd_reloc_ok; | |
3695 | } | |
cedb70c5 | 3696 | |
8375c36b PB |
3697 | case R_ARM_ALU_PCREL7_0: |
3698 | case R_ARM_ALU_PCREL15_8: | |
3699 | case R_ARM_ALU_PCREL23_15: | |
3700 | { | |
3701 | bfd_vma insn; | |
3702 | bfd_vma relocation; | |
3703 | ||
3704 | insn = bfd_get_32 (input_bfd, hit_data); | |
4e7fd91e PB |
3705 | if (globals->use_rel) |
3706 | { | |
3707 | /* Extract the addend. */ | |
3708 | addend = (insn & 0xff) << ((insn & 0xf00) >> 7); | |
3709 | signed_addend = addend; | |
3710 | } | |
8375c36b PB |
3711 | relocation = value + signed_addend; |
3712 | ||
3713 | relocation -= (input_section->output_section->vma | |
3714 | + input_section->output_offset | |
3715 | + rel->r_offset); | |
3716 | insn = (insn & ~0xfff) | |
3717 | | ((howto->bitpos << 7) & 0xf00) | |
3718 | | ((relocation >> howto->bitpos) & 0xff); | |
3719 | bfd_put_32 (input_bfd, value, hit_data); | |
3720 | } | |
3721 | return bfd_reloc_ok; | |
3722 | ||
252b5132 RH |
3723 | case R_ARM_GNU_VTINHERIT: |
3724 | case R_ARM_GNU_VTENTRY: | |
3725 | return bfd_reloc_ok; | |
3726 | ||
c19d1205 | 3727 | case R_ARM_GOTOFF32: |
252b5132 RH |
3728 | /* Relocation is relative to the start of the |
3729 | global offset table. */ | |
3730 | ||
3731 | BFD_ASSERT (sgot != NULL); | |
3732 | if (sgot == NULL) | |
3733 | return bfd_reloc_notsupported; | |
9a5aca8c | 3734 | |
cedb70c5 | 3735 | /* If we are addressing a Thumb function, we need to adjust the |
ee29b9fb RE |
3736 | address by one, so that attempts to call the function pointer will |
3737 | correctly interpret it as Thumb code. */ | |
3738 | if (sym_flags == STT_ARM_TFUNC) | |
3739 | value += 1; | |
3740 | ||
252b5132 RH |
3741 | /* Note that sgot->output_offset is not involved in this |
3742 | calculation. We always want the start of .got. If we | |
3743 | define _GLOBAL_OFFSET_TABLE in a different way, as is | |
3744 | permitted by the ABI, we might have to change this | |
9b485d32 | 3745 | calculation. */ |
252b5132 | 3746 | value -= sgot->output_section->vma; |
f21f3fe0 | 3747 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 3748 | contents, rel->r_offset, value, |
00a97672 | 3749 | rel->r_addend); |
252b5132 RH |
3750 | |
3751 | case R_ARM_GOTPC: | |
a7c10850 | 3752 | /* Use global offset table as symbol value. */ |
252b5132 | 3753 | BFD_ASSERT (sgot != NULL); |
f21f3fe0 | 3754 | |
252b5132 RH |
3755 | if (sgot == NULL) |
3756 | return bfd_reloc_notsupported; | |
3757 | ||
0945cdfd | 3758 | *unresolved_reloc_p = FALSE; |
252b5132 | 3759 | value = sgot->output_section->vma; |
f21f3fe0 | 3760 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 3761 | contents, rel->r_offset, value, |
00a97672 | 3762 | rel->r_addend); |
f21f3fe0 | 3763 | |
252b5132 | 3764 | case R_ARM_GOT32: |
eb043451 | 3765 | case R_ARM_GOT_PREL: |
252b5132 | 3766 | /* Relocation is to the entry for this symbol in the |
9b485d32 | 3767 | global offset table. */ |
252b5132 RH |
3768 | if (sgot == NULL) |
3769 | return bfd_reloc_notsupported; | |
f21f3fe0 | 3770 | |
252b5132 RH |
3771 | if (h != NULL) |
3772 | { | |
3773 | bfd_vma off; | |
5e681ec4 | 3774 | bfd_boolean dyn; |
f21f3fe0 | 3775 | |
252b5132 RH |
3776 | off = h->got.offset; |
3777 | BFD_ASSERT (off != (bfd_vma) -1); | |
5e681ec4 | 3778 | dyn = globals->root.dynamic_sections_created; |
f21f3fe0 | 3779 | |
5e681ec4 | 3780 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
50d6c878 | 3781 | || (info->shared |
5e681ec4 PB |
3782 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
3783 | || (ELF_ST_VISIBILITY (h->other) | |
3784 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
3785 | { |
3786 | /* This is actually a static link, or it is a -Bsymbolic link | |
3787 | and the symbol is defined locally. We must initialize this | |
3788 | entry in the global offset table. Since the offset must | |
3789 | always be a multiple of 4, we use the least significant bit | |
3790 | to record whether we have initialized it already. | |
f21f3fe0 | 3791 | |
00a97672 | 3792 | When doing a dynamic link, we create a .rel(a).got relocation |
f21f3fe0 | 3793 | entry to initialize the value. This is done in the |
9b485d32 | 3794 | finish_dynamic_symbol routine. */ |
252b5132 RH |
3795 | if ((off & 1) != 0) |
3796 | off &= ~1; | |
3797 | else | |
3798 | { | |
ee29b9fb RE |
3799 | /* If we are addressing a Thumb function, we need to |
3800 | adjust the address by one, so that attempts to | |
3801 | call the function pointer will correctly | |
3802 | interpret it as Thumb code. */ | |
3803 | if (sym_flags == STT_ARM_TFUNC) | |
3804 | value |= 1; | |
3805 | ||
252b5132 RH |
3806 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
3807 | h->got.offset |= 1; | |
3808 | } | |
3809 | } | |
0945cdfd DJ |
3810 | else |
3811 | *unresolved_reloc_p = FALSE; | |
f21f3fe0 | 3812 | |
252b5132 RH |
3813 | value = sgot->output_offset + off; |
3814 | } | |
3815 | else | |
3816 | { | |
3817 | bfd_vma off; | |
f21f3fe0 | 3818 | |
252b5132 RH |
3819 | BFD_ASSERT (local_got_offsets != NULL && |
3820 | local_got_offsets[r_symndx] != (bfd_vma) -1); | |
f21f3fe0 | 3821 | |
252b5132 | 3822 | off = local_got_offsets[r_symndx]; |
f21f3fe0 | 3823 | |
252b5132 RH |
3824 | /* The offset must always be a multiple of 4. We use the |
3825 | least significant bit to record whether we have already | |
9b485d32 | 3826 | generated the necessary reloc. */ |
252b5132 RH |
3827 | if ((off & 1) != 0) |
3828 | off &= ~1; | |
3829 | else | |
3830 | { | |
b7693d02 DJ |
3831 | /* If we are addressing a Thumb function, we need to |
3832 | adjust the address by one, so that attempts to | |
3833 | call the function pointer will correctly | |
3834 | interpret it as Thumb code. */ | |
3835 | if (sym_flags == STT_ARM_TFUNC) | |
3836 | value |= 1; | |
3837 | ||
00a97672 RS |
3838 | if (globals->use_rel) |
3839 | bfd_put_32 (output_bfd, value, sgot->contents + off); | |
f21f3fe0 | 3840 | |
252b5132 RH |
3841 | if (info->shared) |
3842 | { | |
3843 | asection * srelgot; | |
947216bf AM |
3844 | Elf_Internal_Rela outrel; |
3845 | bfd_byte *loc; | |
f21f3fe0 | 3846 | |
00a97672 RS |
3847 | srelgot = (bfd_get_section_by_name |
3848 | (dynobj, RELOC_SECTION (globals, ".got"))); | |
252b5132 | 3849 | BFD_ASSERT (srelgot != NULL); |
f21f3fe0 | 3850 | |
00a97672 | 3851 | outrel.r_addend = addend + value; |
252b5132 | 3852 | outrel.r_offset = (sgot->output_section->vma |
f21f3fe0 | 3853 | + sgot->output_offset |
252b5132 RH |
3854 | + off); |
3855 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
947216bf | 3856 | loc = srelgot->contents; |
00a97672 RS |
3857 | loc += srelgot->reloc_count++ * RELOC_SIZE (globals); |
3858 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
252b5132 | 3859 | } |
f21f3fe0 | 3860 | |
252b5132 RH |
3861 | local_got_offsets[r_symndx] |= 1; |
3862 | } | |
f21f3fe0 | 3863 | |
252b5132 RH |
3864 | value = sgot->output_offset + off; |
3865 | } | |
eb043451 PB |
3866 | if (r_type != R_ARM_GOT32) |
3867 | value += sgot->output_section->vma; | |
9a5aca8c | 3868 | |
f21f3fe0 | 3869 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 | 3870 | contents, rel->r_offset, value, |
00a97672 | 3871 | rel->r_addend); |
f21f3fe0 | 3872 | |
ba93b8ac DJ |
3873 | case R_ARM_TLS_LDO32: |
3874 | value = value - dtpoff_base (info); | |
3875 | ||
3876 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
3877 | contents, rel->r_offset, value, |
3878 | rel->r_addend); | |
ba93b8ac DJ |
3879 | |
3880 | case R_ARM_TLS_LDM32: | |
3881 | { | |
3882 | bfd_vma off; | |
3883 | ||
3884 | if (globals->sgot == NULL) | |
3885 | abort (); | |
3886 | ||
3887 | off = globals->tls_ldm_got.offset; | |
3888 | ||
3889 | if ((off & 1) != 0) | |
3890 | off &= ~1; | |
3891 | else | |
3892 | { | |
3893 | /* If we don't know the module number, create a relocation | |
3894 | for it. */ | |
3895 | if (info->shared) | |
3896 | { | |
3897 | Elf_Internal_Rela outrel; | |
3898 | bfd_byte *loc; | |
3899 | ||
3900 | if (globals->srelgot == NULL) | |
3901 | abort (); | |
3902 | ||
00a97672 | 3903 | outrel.r_addend = 0; |
ba93b8ac DJ |
3904 | outrel.r_offset = (globals->sgot->output_section->vma |
3905 | + globals->sgot->output_offset + off); | |
3906 | outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32); | |
3907 | ||
00a97672 RS |
3908 | if (globals->use_rel) |
3909 | bfd_put_32 (output_bfd, outrel.r_addend, | |
3910 | globals->sgot->contents + off); | |
ba93b8ac DJ |
3911 | |
3912 | loc = globals->srelgot->contents; | |
00a97672 RS |
3913 | loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals); |
3914 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac DJ |
3915 | } |
3916 | else | |
3917 | bfd_put_32 (output_bfd, 1, globals->sgot->contents + off); | |
3918 | ||
3919 | globals->tls_ldm_got.offset |= 1; | |
3920 | } | |
3921 | ||
3922 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
3923 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
3924 | ||
3925 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
3926 | contents, rel->r_offset, value, | |
00a97672 | 3927 | rel->r_addend); |
ba93b8ac DJ |
3928 | } |
3929 | ||
3930 | case R_ARM_TLS_GD32: | |
3931 | case R_ARM_TLS_IE32: | |
3932 | { | |
3933 | bfd_vma off; | |
3934 | int indx; | |
3935 | char tls_type; | |
3936 | ||
3937 | if (globals->sgot == NULL) | |
3938 | abort (); | |
3939 | ||
3940 | indx = 0; | |
3941 | if (h != NULL) | |
3942 | { | |
3943 | bfd_boolean dyn; | |
3944 | dyn = globals->root.dynamic_sections_created; | |
3945 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
3946 | && (!info->shared | |
3947 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
3948 | { | |
3949 | *unresolved_reloc_p = FALSE; | |
3950 | indx = h->dynindx; | |
3951 | } | |
3952 | off = h->got.offset; | |
3953 | tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type; | |
3954 | } | |
3955 | else | |
3956 | { | |
3957 | if (local_got_offsets == NULL) | |
3958 | abort (); | |
3959 | off = local_got_offsets[r_symndx]; | |
3960 | tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx]; | |
3961 | } | |
3962 | ||
3963 | if (tls_type == GOT_UNKNOWN) | |
3964 | abort (); | |
3965 | ||
3966 | if ((off & 1) != 0) | |
3967 | off &= ~1; | |
3968 | else | |
3969 | { | |
3970 | bfd_boolean need_relocs = FALSE; | |
3971 | Elf_Internal_Rela outrel; | |
3972 | bfd_byte *loc = NULL; | |
3973 | int cur_off = off; | |
3974 | ||
3975 | /* The GOT entries have not been initialized yet. Do it | |
3976 | now, and emit any relocations. If both an IE GOT and a | |
3977 | GD GOT are necessary, we emit the GD first. */ | |
3978 | ||
3979 | if ((info->shared || indx != 0) | |
3980 | && (h == NULL | |
3981 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
3982 | || h->root.type != bfd_link_hash_undefweak)) | |
3983 | { | |
3984 | need_relocs = TRUE; | |
3985 | if (globals->srelgot == NULL) | |
3986 | abort (); | |
3987 | loc = globals->srelgot->contents; | |
00a97672 | 3988 | loc += globals->srelgot->reloc_count * RELOC_SIZE (globals); |
ba93b8ac DJ |
3989 | } |
3990 | ||
3991 | if (tls_type & GOT_TLS_GD) | |
3992 | { | |
3993 | if (need_relocs) | |
3994 | { | |
00a97672 | 3995 | outrel.r_addend = 0; |
ba93b8ac | 3996 | outrel.r_offset = (globals->sgot->output_section->vma |
00a97672 RS |
3997 | + globals->sgot->output_offset |
3998 | + cur_off); | |
ba93b8ac | 3999 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32); |
ba93b8ac | 4000 | |
00a97672 RS |
4001 | if (globals->use_rel) |
4002 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4003 | globals->sgot->contents + cur_off); | |
4004 | ||
4005 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 4006 | globals->srelgot->reloc_count++; |
00a97672 | 4007 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4008 | |
4009 | if (indx == 0) | |
4010 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
4011 | globals->sgot->contents + cur_off + 4); | |
4012 | else | |
4013 | { | |
00a97672 | 4014 | outrel.r_addend = 0; |
ba93b8ac DJ |
4015 | outrel.r_info = ELF32_R_INFO (indx, |
4016 | R_ARM_TLS_DTPOFF32); | |
4017 | outrel.r_offset += 4; | |
00a97672 RS |
4018 | |
4019 | if (globals->use_rel) | |
4020 | bfd_put_32 (output_bfd, outrel.r_addend, | |
4021 | globals->sgot->contents + cur_off + 4); | |
4022 | ||
4023 | ||
4024 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); | |
ba93b8ac | 4025 | globals->srelgot->reloc_count++; |
00a97672 | 4026 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4027 | } |
4028 | } | |
4029 | else | |
4030 | { | |
4031 | /* If we are not emitting relocations for a | |
4032 | general dynamic reference, then we must be in a | |
4033 | static link or an executable link with the | |
4034 | symbol binding locally. Mark it as belonging | |
4035 | to module 1, the executable. */ | |
4036 | bfd_put_32 (output_bfd, 1, | |
4037 | globals->sgot->contents + cur_off); | |
4038 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
4039 | globals->sgot->contents + cur_off + 4); | |
4040 | } | |
4041 | ||
4042 | cur_off += 8; | |
4043 | } | |
4044 | ||
4045 | if (tls_type & GOT_TLS_IE) | |
4046 | { | |
4047 | if (need_relocs) | |
4048 | { | |
00a97672 RS |
4049 | if (indx == 0) |
4050 | outrel.r_addend = value - dtpoff_base (info); | |
4051 | else | |
4052 | outrel.r_addend = 0; | |
ba93b8ac DJ |
4053 | outrel.r_offset = (globals->sgot->output_section->vma |
4054 | + globals->sgot->output_offset | |
4055 | + cur_off); | |
4056 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32); | |
4057 | ||
00a97672 RS |
4058 | if (globals->use_rel) |
4059 | bfd_put_32 (output_bfd, outrel.r_addend, | |
ba93b8ac DJ |
4060 | globals->sgot->contents + cur_off); |
4061 | ||
00a97672 | 4062 | SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); |
ba93b8ac | 4063 | globals->srelgot->reloc_count++; |
00a97672 | 4064 | loc += RELOC_SIZE (globals); |
ba93b8ac DJ |
4065 | } |
4066 | else | |
4067 | bfd_put_32 (output_bfd, tpoff (info, value), | |
4068 | globals->sgot->contents + cur_off); | |
4069 | cur_off += 4; | |
4070 | } | |
4071 | ||
4072 | if (h != NULL) | |
4073 | h->got.offset |= 1; | |
4074 | else | |
4075 | local_got_offsets[r_symndx] |= 1; | |
4076 | } | |
4077 | ||
4078 | if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32) | |
4079 | off += 8; | |
4080 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
4081 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
4082 | ||
4083 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4084 | contents, rel->r_offset, value, | |
00a97672 | 4085 | rel->r_addend); |
ba93b8ac DJ |
4086 | } |
4087 | ||
4088 | case R_ARM_TLS_LE32: | |
4089 | if (info->shared) | |
4090 | { | |
4091 | (*_bfd_error_handler) | |
4092 | (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"), | |
4093 | input_bfd, input_section, | |
4094 | (long) rel->r_offset, howto->name); | |
4095 | return FALSE; | |
4096 | } | |
4097 | else | |
4098 | value = tpoff (info, value); | |
4099 | ||
4100 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
00a97672 RS |
4101 | contents, rel->r_offset, value, |
4102 | rel->r_addend); | |
ba93b8ac | 4103 | |
319850b4 JB |
4104 | case R_ARM_V4BX: |
4105 | if (globals->fix_v4bx) | |
4106 | { | |
4107 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4108 | ||
4109 | /* Ensure that we have a BX instruction. */ | |
4110 | BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10); | |
4111 | ||
4112 | /* Preserve Rm (lowest four bits) and the condition code | |
4113 | (highest four bits). Other bits encode MOV PC,Rm. */ | |
4114 | insn = (insn & 0xf000000f) | 0x01a0f000; | |
4115 | ||
4116 | bfd_put_32 (input_bfd, insn, hit_data); | |
4117 | } | |
4118 | return bfd_reloc_ok; | |
4119 | ||
b6895b4f PB |
4120 | case R_ARM_MOVW_ABS_NC: |
4121 | case R_ARM_MOVT_ABS: | |
4122 | case R_ARM_MOVW_PREL_NC: | |
4123 | case R_ARM_MOVT_PREL: | |
4124 | { | |
4125 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
4126 | ||
4127 | if (globals->use_rel) | |
4128 | { | |
4129 | addend = ((insn >> 4) & 0xf000) | (insn & 0xfff); | |
4130 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
4131 | } | |
4132 | value += signed_addend; | |
4133 | if (sym_flags == STT_ARM_TFUNC) | |
4134 | value |= 1; | |
4135 | ||
4136 | if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL) | |
4137 | value -= (input_section->output_section->vma | |
4138 | + input_section->output_offset + rel->r_offset); | |
4139 | ||
4140 | if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL) | |
4141 | value >>= 16; | |
4142 | ||
4143 | insn &= 0xfff0f000; | |
4144 | insn |= value & 0xfff; | |
4145 | insn |= (value & 0xf000) << 4; | |
4146 | bfd_put_32 (input_bfd, insn, hit_data); | |
4147 | } | |
4148 | return bfd_reloc_ok; | |
4149 | ||
4150 | case R_ARM_THM_MOVW_ABS_NC: | |
4151 | case R_ARM_THM_MOVT_ABS: | |
4152 | case R_ARM_THM_MOVW_PREL_NC: | |
4153 | case R_ARM_THM_MOVT_PREL: | |
4154 | { | |
4155 | bfd_vma insn; | |
4156 | ||
4157 | insn = bfd_get_16 (input_bfd, hit_data) << 16; | |
4158 | insn |= bfd_get_16 (input_bfd, hit_data + 2); | |
4159 | ||
4160 | if (globals->use_rel) | |
4161 | { | |
4162 | addend = ((insn >> 4) & 0xf000) | |
4163 | | ((insn >> 15) & 0x0800) | |
4164 | | ((insn >> 4) & 0x0700) | |
4165 | | (insn & 0x00ff); | |
4166 | signed_addend = (addend ^ 0x10000) - 0x10000; | |
4167 | } | |
4168 | value += signed_addend; | |
4169 | if (sym_flags == STT_ARM_TFUNC) | |
4170 | value |= 1; | |
4171 | ||
4172 | if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL) | |
4173 | value -= (input_section->output_section->vma | |
4174 | + input_section->output_offset + rel->r_offset); | |
4175 | ||
4176 | if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL) | |
4177 | value >>= 16; | |
4178 | ||
4179 | insn &= 0xfbf08f00; | |
4180 | insn |= (value & 0xf000) << 4; | |
4181 | insn |= (value & 0x0800) << 15; | |
4182 | insn |= (value & 0x0700) << 4; | |
4183 | insn |= (value & 0x00ff); | |
4184 | ||
4185 | bfd_put_16 (input_bfd, insn >> 16, hit_data); | |
4186 | bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); | |
4187 | } | |
4188 | return bfd_reloc_ok; | |
4189 | ||
252b5132 RH |
4190 | default: |
4191 | return bfd_reloc_notsupported; | |
4192 | } | |
4193 | } | |
4194 | ||
ee065d83 PB |
4195 | |
4196 | static int | |
4197 | uleb128_size (unsigned int i) | |
4198 | { | |
4199 | int size; | |
4200 | size = 1; | |
4201 | while (i >= 0x80) | |
4202 | { | |
4203 | i >>= 7; | |
4204 | size++; | |
4205 | } | |
4206 | return size; | |
4207 | } | |
4208 | ||
4209 | /* Return TRUE if the attribute has the default value (0/""). */ | |
4210 | static bfd_boolean | |
4211 | is_default_attr (aeabi_attribute *attr) | |
4212 | { | |
4213 | if ((attr->type & 1) && attr->i != 0) | |
4214 | return FALSE; | |
4215 | if ((attr->type & 2) && attr->s && *attr->s) | |
4216 | return FALSE; | |
4217 | ||
4218 | return TRUE; | |
4219 | } | |
4220 | ||
4221 | /* Return the size of a single attribute. */ | |
4222 | static bfd_vma | |
4223 | eabi_attr_size(int tag, aeabi_attribute *attr) | |
4224 | { | |
4225 | bfd_vma size; | |
4226 | ||
4227 | if (is_default_attr (attr)) | |
4228 | return 0; | |
4229 | ||
4230 | size = uleb128_size (tag); | |
4231 | if (attr->type & 1) | |
4232 | size += uleb128_size (attr->i); | |
4233 | if (attr->type & 2) | |
4234 | size += strlen ((char *)attr->s) + 1; | |
4235 | return size; | |
4236 | } | |
4237 | ||
4238 | /* Returns the size of the eabi object attributess section. */ | |
4239 | bfd_vma | |
4240 | elf32_arm_eabi_attr_size (bfd *abfd) | |
4241 | { | |
4242 | bfd_vma size; | |
4243 | aeabi_attribute *attr; | |
4244 | aeabi_attribute_list *list; | |
4245 | int i; | |
4246 | ||
4247 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
4248 | size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */ | |
4249 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
4250 | size += eabi_attr_size (i, &attr[i]); | |
4251 | ||
4252 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
4253 | list; | |
4254 | list = list->next) | |
4255 | size += eabi_attr_size (list->tag, &list->attr); | |
4256 | ||
4257 | return size; | |
4258 | } | |
4259 | ||
4260 | static bfd_byte * | |
4261 | write_uleb128 (bfd_byte *p, unsigned int val) | |
4262 | { | |
4263 | bfd_byte c; | |
4264 | do | |
4265 | { | |
4266 | c = val & 0x7f; | |
4267 | val >>= 7; | |
4268 | if (val) | |
4269 | c |= 0x80; | |
4270 | *(p++) = c; | |
4271 | } | |
4272 | while (val); | |
4273 | return p; | |
4274 | } | |
4275 | ||
4276 | /* Write attribute ATTR to butter P, and return a pointer to the following | |
4277 | byte. */ | |
4278 | static bfd_byte * | |
4279 | write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr) | |
4280 | { | |
4281 | /* Suppress default entries. */ | |
4282 | if (is_default_attr(attr)) | |
4283 | return p; | |
4284 | ||
4285 | p = write_uleb128 (p, tag); | |
4286 | if (attr->type & 1) | |
4287 | p = write_uleb128 (p, attr->i); | |
4288 | if (attr->type & 2) | |
4289 | { | |
4290 | int len; | |
4291 | ||
4292 | len = strlen (attr->s) + 1; | |
4293 | memcpy (p, attr->s, len); | |
4294 | p += len; | |
4295 | } | |
4296 | ||
4297 | return p; | |
4298 | } | |
4299 | ||
4300 | /* Write the contents of the eabi attributes section to p. */ | |
4301 | void | |
4302 | elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size) | |
4303 | { | |
4304 | bfd_byte *p; | |
4305 | aeabi_attribute *attr; | |
4306 | aeabi_attribute_list *list; | |
4307 | int i; | |
4308 | ||
4309 | p = contents; | |
4310 | *(p++) = 'A'; | |
4311 | bfd_put_32 (abfd, size - 1, p); | |
4312 | p += 4; | |
4313 | memcpy (p, "aeabi", 6); | |
4314 | p += 6; | |
4315 | *(p++) = Tag_File; | |
4316 | bfd_put_32 (abfd, size - 11, p); | |
4317 | p += 4; | |
4318 | ||
4319 | attr = elf32_arm_tdata (abfd)->known_eabi_attributes; | |
4320 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
4321 | p = write_eabi_attribute (p, i, &attr[i]); | |
4322 | ||
4323 | for (list = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
4324 | list; | |
4325 | list = list->next) | |
4326 | p = write_eabi_attribute (p, list->tag, &list->attr); | |
4327 | } | |
4328 | ||
4329 | /* Override final_link to handle EABI object attribute sections. */ | |
4330 | ||
4331 | static bfd_boolean | |
4332 | elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info) | |
4333 | { | |
4334 | asection *o; | |
4335 | struct bfd_link_order *p; | |
4336 | asection *attr_section = NULL; | |
4337 | bfd_byte *contents; | |
4338 | bfd_vma size = 0; | |
4339 | ||
4340 | /* elf32_arm_merge_private_bfd_data will already have merged the | |
4341 | object attributes. Remove the input sections from the link, and set | |
4342 | the contents of the output secton. */ | |
4343 | for (o = abfd->sections; o != NULL; o = o->next) | |
4344 | { | |
4345 | if (strcmp (o->name, ".ARM.attributes") == 0) | |
4346 | { | |
4347 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
4348 | { | |
4349 | asection *input_section; | |
4350 | ||
4351 | if (p->type != bfd_indirect_link_order) | |
4352 | continue; | |
4353 | input_section = p->u.indirect.section; | |
4354 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
4355 | elf_link_input_bfd ignores this section. */ | |
4356 | input_section->flags &= ~SEC_HAS_CONTENTS; | |
4357 | } | |
4358 | ||
4359 | size = elf32_arm_eabi_attr_size (abfd); | |
4360 | bfd_set_section_size (abfd, o, size); | |
4361 | attr_section = o; | |
4362 | /* Skip this section later on. */ | |
4363 | o->map_head.link_order = NULL; | |
4364 | } | |
4365 | } | |
4366 | /* Invoke the ELF linker to do all the work. */ | |
4367 | if (!bfd_elf_final_link (abfd, info)) | |
4368 | return FALSE; | |
4369 | ||
4370 | if (attr_section) | |
4371 | { | |
4372 | contents = bfd_malloc(size); | |
4373 | if (contents == NULL) | |
4374 | return FALSE; | |
4375 | elf32_arm_set_eabi_attr_contents (abfd, contents, size); | |
4376 | bfd_set_section_contents (abfd, attr_section, contents, 0, size); | |
4377 | free (contents); | |
4378 | } | |
4379 | return TRUE; | |
4380 | } | |
4381 | ||
4382 | ||
98c1d4aa NC |
4383 | /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ |
4384 | static void | |
57e8b36a NC |
4385 | arm_add_to_rel (bfd * abfd, |
4386 | bfd_byte * address, | |
4387 | reloc_howto_type * howto, | |
4388 | bfd_signed_vma increment) | |
98c1d4aa | 4389 | { |
98c1d4aa NC |
4390 | bfd_signed_vma addend; |
4391 | ||
c19d1205 | 4392 | if (howto->type == R_ARM_THM_CALL) |
98c1d4aa | 4393 | { |
9a5aca8c AM |
4394 | int upper_insn, lower_insn; |
4395 | int upper, lower; | |
98c1d4aa | 4396 | |
9a5aca8c AM |
4397 | upper_insn = bfd_get_16 (abfd, address); |
4398 | lower_insn = bfd_get_16 (abfd, address + 2); | |
4399 | upper = upper_insn & 0x7ff; | |
4400 | lower = lower_insn & 0x7ff; | |
4401 | ||
4402 | addend = (upper << 12) | (lower << 1); | |
ddda4409 | 4403 | addend += increment; |
9a5aca8c | 4404 | addend >>= 1; |
98c1d4aa | 4405 | |
9a5aca8c AM |
4406 | upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); |
4407 | lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); | |
4408 | ||
dc810e39 AM |
4409 | bfd_put_16 (abfd, (bfd_vma) upper_insn, address); |
4410 | bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); | |
9a5aca8c AM |
4411 | } |
4412 | else | |
4413 | { | |
4414 | bfd_vma contents; | |
4415 | ||
4416 | contents = bfd_get_32 (abfd, address); | |
4417 | ||
4418 | /* Get the (signed) value from the instruction. */ | |
4419 | addend = contents & howto->src_mask; | |
4420 | if (addend & ((howto->src_mask + 1) >> 1)) | |
4421 | { | |
4422 | bfd_signed_vma mask; | |
4423 | ||
4424 | mask = -1; | |
4425 | mask &= ~ howto->src_mask; | |
4426 | addend |= mask; | |
4427 | } | |
4428 | ||
4429 | /* Add in the increment, (which is a byte value). */ | |
4430 | switch (howto->type) | |
4431 | { | |
4432 | default: | |
4433 | addend += increment; | |
4434 | break; | |
4435 | ||
4436 | case R_ARM_PC24: | |
c6596c5e | 4437 | case R_ARM_PLT32: |
5b5bb741 PB |
4438 | case R_ARM_CALL: |
4439 | case R_ARM_JUMP24: | |
9a5aca8c | 4440 | addend <<= howto->size; |
dc810e39 | 4441 | addend += increment; |
9a5aca8c AM |
4442 | |
4443 | /* Should we check for overflow here ? */ | |
4444 | ||
4445 | /* Drop any undesired bits. */ | |
4446 | addend >>= howto->rightshift; | |
4447 | break; | |
4448 | } | |
4449 | ||
4450 | contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
4451 | ||
4452 | bfd_put_32 (abfd, contents, address); | |
ddda4409 | 4453 | } |
98c1d4aa | 4454 | } |
252b5132 | 4455 | |
ba93b8ac DJ |
4456 | #define IS_ARM_TLS_RELOC(R_TYPE) \ |
4457 | ((R_TYPE) == R_ARM_TLS_GD32 \ | |
4458 | || (R_TYPE) == R_ARM_TLS_LDO32 \ | |
4459 | || (R_TYPE) == R_ARM_TLS_LDM32 \ | |
4460 | || (R_TYPE) == R_ARM_TLS_DTPOFF32 \ | |
4461 | || (R_TYPE) == R_ARM_TLS_DTPMOD32 \ | |
4462 | || (R_TYPE) == R_ARM_TLS_TPOFF32 \ | |
4463 | || (R_TYPE) == R_ARM_TLS_LE32 \ | |
4464 | || (R_TYPE) == R_ARM_TLS_IE32) | |
4465 | ||
252b5132 | 4466 | /* Relocate an ARM ELF section. */ |
b34976b6 | 4467 | static bfd_boolean |
57e8b36a NC |
4468 | elf32_arm_relocate_section (bfd * output_bfd, |
4469 | struct bfd_link_info * info, | |
4470 | bfd * input_bfd, | |
4471 | asection * input_section, | |
4472 | bfd_byte * contents, | |
4473 | Elf_Internal_Rela * relocs, | |
4474 | Elf_Internal_Sym * local_syms, | |
4475 | asection ** local_sections) | |
252b5132 | 4476 | { |
b34976b6 AM |
4477 | Elf_Internal_Shdr *symtab_hdr; |
4478 | struct elf_link_hash_entry **sym_hashes; | |
4479 | Elf_Internal_Rela *rel; | |
4480 | Elf_Internal_Rela *relend; | |
4481 | const char *name; | |
b32d3aa2 | 4482 | struct elf32_arm_link_hash_table * globals; |
252b5132 | 4483 | |
4e7fd91e PB |
4484 | globals = elf32_arm_hash_table (info); |
4485 | if (info->relocatable && !globals->use_rel) | |
b34976b6 | 4486 | return TRUE; |
b491616a | 4487 | |
252b5132 RH |
4488 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
4489 | sym_hashes = elf_sym_hashes (input_bfd); | |
4490 | ||
4491 | rel = relocs; | |
4492 | relend = relocs + input_section->reloc_count; | |
4493 | for (; rel < relend; rel++) | |
4494 | { | |
ba96a88f NC |
4495 | int r_type; |
4496 | reloc_howto_type * howto; | |
4497 | unsigned long r_symndx; | |
4498 | Elf_Internal_Sym * sym; | |
4499 | asection * sec; | |
252b5132 | 4500 | struct elf_link_hash_entry * h; |
ba96a88f NC |
4501 | bfd_vma relocation; |
4502 | bfd_reloc_status_type r; | |
4503 | arelent bfd_reloc; | |
ba93b8ac | 4504 | char sym_type; |
0945cdfd | 4505 | bfd_boolean unresolved_reloc = FALSE; |
f21f3fe0 | 4506 | |
252b5132 | 4507 | r_symndx = ELF32_R_SYM (rel->r_info); |
ba96a88f | 4508 | r_type = ELF32_R_TYPE (rel->r_info); |
b32d3aa2 | 4509 | r_type = arm_real_reloc_type (globals, r_type); |
252b5132 | 4510 | |
ba96a88f NC |
4511 | if ( r_type == R_ARM_GNU_VTENTRY |
4512 | || r_type == R_ARM_GNU_VTINHERIT) | |
252b5132 RH |
4513 | continue; |
4514 | ||
b32d3aa2 | 4515 | bfd_reloc.howto = elf32_arm_howto_from_type (r_type); |
ba96a88f | 4516 | howto = bfd_reloc.howto; |
252b5132 | 4517 | |
4e7fd91e | 4518 | if (info->relocatable && globals->use_rel) |
252b5132 | 4519 | { |
1049f94e | 4520 | /* This is a relocatable link. We don't have to change |
252b5132 RH |
4521 | anything, unless the reloc is against a section symbol, |
4522 | in which case we have to adjust according to where the | |
4523 | section symbol winds up in the output section. */ | |
4524 | if (r_symndx < symtab_hdr->sh_info) | |
4525 | { | |
4526 | sym = local_syms + r_symndx; | |
4527 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
4528 | { | |
4529 | sec = local_sections[r_symndx]; | |
98c1d4aa | 4530 | arm_add_to_rel (input_bfd, contents + rel->r_offset, |
dc810e39 AM |
4531 | howto, |
4532 | (bfd_signed_vma) (sec->output_offset | |
4533 | + sym->st_value)); | |
252b5132 RH |
4534 | } |
4535 | } | |
4536 | ||
4537 | continue; | |
4538 | } | |
4539 | ||
4540 | /* This is a final link. */ | |
4541 | h = NULL; | |
4542 | sym = NULL; | |
4543 | sec = NULL; | |
9b485d32 | 4544 | |
252b5132 RH |
4545 | if (r_symndx < symtab_hdr->sh_info) |
4546 | { | |
4547 | sym = local_syms + r_symndx; | |
ba93b8ac | 4548 | sym_type = ELF32_ST_TYPE (sym->st_info); |
252b5132 | 4549 | sec = local_sections[r_symndx]; |
4e7fd91e | 4550 | if (globals->use_rel) |
f8df10f4 | 4551 | { |
4e7fd91e PB |
4552 | relocation = (sec->output_section->vma |
4553 | + sec->output_offset | |
4554 | + sym->st_value); | |
4555 | if ((sec->flags & SEC_MERGE) | |
4556 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
f8df10f4 | 4557 | { |
4e7fd91e PB |
4558 | asection *msec; |
4559 | bfd_vma addend, value; | |
4560 | ||
4561 | if (howto->rightshift) | |
4562 | { | |
4563 | (*_bfd_error_handler) | |
4564 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), | |
4565 | input_bfd, input_section, | |
4566 | (long) rel->r_offset, howto->name); | |
4567 | return FALSE; | |
4568 | } | |
f8df10f4 | 4569 | |
4e7fd91e | 4570 | value = bfd_get_32 (input_bfd, contents + rel->r_offset); |
f8df10f4 | 4571 | |
4e7fd91e PB |
4572 | /* Get the (signed) value from the instruction. */ |
4573 | addend = value & howto->src_mask; | |
4574 | if (addend & ((howto->src_mask + 1) >> 1)) | |
4575 | { | |
4576 | bfd_signed_vma mask; | |
f8df10f4 | 4577 | |
4e7fd91e PB |
4578 | mask = -1; |
4579 | mask &= ~ howto->src_mask; | |
4580 | addend |= mask; | |
4581 | } | |
4582 | msec = sec; | |
4583 | addend = | |
4584 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) | |
4585 | - relocation; | |
4586 | addend += msec->output_section->vma + msec->output_offset; | |
4587 | value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
4588 | bfd_put_32 (input_bfd, value, contents + rel->r_offset); | |
f8df10f4 | 4589 | } |
f8df10f4 | 4590 | } |
4e7fd91e PB |
4591 | else |
4592 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
252b5132 RH |
4593 | } |
4594 | else | |
4595 | { | |
560e09e9 | 4596 | bfd_boolean warned; |
560e09e9 | 4597 | |
b2a8e766 AM |
4598 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
4599 | r_symndx, symtab_hdr, sym_hashes, | |
4600 | h, sec, relocation, | |
4601 | unresolved_reloc, warned); | |
ba93b8ac DJ |
4602 | |
4603 | sym_type = h->type; | |
252b5132 RH |
4604 | } |
4605 | ||
4606 | if (h != NULL) | |
4607 | name = h->root.root.string; | |
4608 | else | |
4609 | { | |
4610 | name = (bfd_elf_string_from_elf_section | |
4611 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
4612 | if (name == NULL || *name == '\0') | |
4613 | name = bfd_section_name (input_bfd, sec); | |
4614 | } | |
f21f3fe0 | 4615 | |
ba93b8ac DJ |
4616 | if (r_symndx != 0 |
4617 | && r_type != R_ARM_NONE | |
4618 | && (h == NULL | |
4619 | || h->root.type == bfd_link_hash_defined | |
4620 | || h->root.type == bfd_link_hash_defweak) | |
4621 | && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
4622 | { | |
4623 | (*_bfd_error_handler) | |
4624 | ((sym_type == STT_TLS | |
4625 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") | |
4626 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), | |
4627 | input_bfd, | |
4628 | input_section, | |
4629 | (long) rel->r_offset, | |
4630 | howto->name, | |
4631 | name); | |
4632 | } | |
4633 | ||
252b5132 RH |
4634 | r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, |
4635 | input_section, contents, rel, | |
4636 | relocation, info, sec, name, | |
4637 | (h ? ELF_ST_TYPE (h->type) : | |
0945cdfd DJ |
4638 | ELF_ST_TYPE (sym->st_info)), h, |
4639 | &unresolved_reloc); | |
4640 | ||
4641 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections | |
4642 | because such sections are not SEC_ALLOC and thus ld.so will | |
4643 | not process them. */ | |
4644 | if (unresolved_reloc | |
4645 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
4646 | && h->def_dynamic)) | |
4647 | { | |
4648 | (*_bfd_error_handler) | |
843fe662 L |
4649 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
4650 | input_bfd, | |
4651 | input_section, | |
4652 | (long) rel->r_offset, | |
4653 | howto->name, | |
4654 | h->root.root.string); | |
0945cdfd DJ |
4655 | return FALSE; |
4656 | } | |
252b5132 RH |
4657 | |
4658 | if (r != bfd_reloc_ok) | |
4659 | { | |
4660 | const char * msg = (const char *) 0; | |
4661 | ||
4662 | switch (r) | |
4663 | { | |
4664 | case bfd_reloc_overflow: | |
cf919dfd PB |
4665 | /* If the overflowing reloc was to an undefined symbol, |
4666 | we have already printed one error message and there | |
4667 | is no point complaining again. */ | |
4668 | if ((! h || | |
4669 | h->root.type != bfd_link_hash_undefined) | |
4670 | && (!((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
4671 | (info, (h ? &h->root : NULL), name, howto->name, |
4672 | (bfd_vma) 0, input_bfd, input_section, | |
4673 | rel->r_offset)))) | |
b34976b6 | 4674 | return FALSE; |
252b5132 RH |
4675 | break; |
4676 | ||
4677 | case bfd_reloc_undefined: | |
4678 | if (!((*info->callbacks->undefined_symbol) | |
4679 | (info, name, input_bfd, input_section, | |
b34976b6 AM |
4680 | rel->r_offset, TRUE))) |
4681 | return FALSE; | |
252b5132 RH |
4682 | break; |
4683 | ||
4684 | case bfd_reloc_outofrange: | |
9b485d32 | 4685 | msg = _("internal error: out of range error"); |
252b5132 RH |
4686 | goto common_error; |
4687 | ||
4688 | case bfd_reloc_notsupported: | |
9b485d32 | 4689 | msg = _("internal error: unsupported relocation error"); |
252b5132 RH |
4690 | goto common_error; |
4691 | ||
4692 | case bfd_reloc_dangerous: | |
9b485d32 | 4693 | msg = _("internal error: dangerous error"); |
252b5132 RH |
4694 | goto common_error; |
4695 | ||
4696 | default: | |
9b485d32 | 4697 | msg = _("internal error: unknown error"); |
252b5132 RH |
4698 | /* fall through */ |
4699 | ||
4700 | common_error: | |
4701 | if (!((*info->callbacks->warning) | |
4702 | (info, msg, name, input_bfd, input_section, | |
4703 | rel->r_offset))) | |
b34976b6 | 4704 | return FALSE; |
252b5132 RH |
4705 | break; |
4706 | } | |
4707 | } | |
4708 | } | |
4709 | ||
b34976b6 | 4710 | return TRUE; |
252b5132 RH |
4711 | } |
4712 | ||
ee065d83 PB |
4713 | /* Allocate/find an object attribute. */ |
4714 | static aeabi_attribute * | |
4715 | elf32_arm_new_eabi_attr (bfd *abfd, int tag) | |
4716 | { | |
4717 | aeabi_attribute *attr; | |
4718 | aeabi_attribute_list *list; | |
4719 | aeabi_attribute_list *p; | |
4720 | aeabi_attribute_list **lastp; | |
4721 | ||
4722 | ||
4723 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
4724 | { | |
4725 | /* Knwon tags are preallocated. */ | |
4726 | attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag]; | |
4727 | } | |
4728 | else | |
4729 | { | |
4730 | /* Create a new tag. */ | |
4731 | list = (aeabi_attribute_list *) | |
4732 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
4733 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
4734 | list->tag = tag; | |
4735 | /* Keep the tag list in order. */ | |
4736 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
4737 | for (p = *lastp; p; p = p->next) | |
4738 | { | |
4739 | if (tag < p->tag) | |
4740 | break; | |
4741 | lastp = &p->next; | |
4742 | } | |
4743 | list->next = *lastp; | |
4744 | *lastp = list; | |
4745 | attr = &list->attr; | |
4746 | } | |
4747 | ||
4748 | return attr; | |
4749 | } | |
4750 | ||
39b41c9c PB |
4751 | int |
4752 | elf32_arm_get_eabi_attr_int (bfd *abfd, int tag) | |
4753 | { | |
4754 | aeabi_attribute_list *p; | |
4755 | ||
4756 | if (tag < NUM_KNOWN_ATTRIBUTES) | |
4757 | { | |
4758 | /* Knwon tags are preallocated. */ | |
4759 | return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i; | |
4760 | } | |
4761 | else | |
4762 | { | |
4763 | for (p = elf32_arm_tdata (abfd)->other_eabi_attributes; | |
4764 | p; | |
4765 | p = p->next) | |
4766 | { | |
4767 | if (tag == p->tag) | |
4768 | return p->attr.i; | |
4769 | if (tag < p->tag) | |
4770 | break; | |
4771 | } | |
4772 | return 0; | |
4773 | } | |
4774 | } | |
4775 | ||
ee065d83 PB |
4776 | void |
4777 | elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i) | |
4778 | { | |
4779 | aeabi_attribute *attr; | |
4780 | ||
4781 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
4782 | attr->type = 1; | |
4783 | attr->i = i; | |
4784 | } | |
4785 | ||
4786 | static char * | |
4787 | attr_strdup (bfd *abfd, const char * s) | |
4788 | { | |
4789 | char * p; | |
4790 | int len; | |
4791 | ||
4792 | len = strlen (s) + 1; | |
4793 | p = (char *)bfd_alloc(abfd, len); | |
4794 | return memcpy (p, s, len); | |
4795 | } | |
4796 | ||
4797 | void | |
4798 | elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s) | |
4799 | { | |
4800 | aeabi_attribute *attr; | |
4801 | ||
4802 | attr = elf32_arm_new_eabi_attr (abfd, tag); | |
4803 | attr->type = 2; | |
4804 | attr->s = attr_strdup (abfd, s); | |
4805 | } | |
4806 | ||
4807 | void | |
4808 | elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s) | |
4809 | { | |
4810 | aeabi_attribute_list *list; | |
4811 | aeabi_attribute_list *p; | |
4812 | aeabi_attribute_list **lastp; | |
4813 | ||
4814 | list = (aeabi_attribute_list *) | |
4815 | bfd_alloc (abfd, sizeof (aeabi_attribute_list)); | |
4816 | memset (list, 0, sizeof (aeabi_attribute_list)); | |
4817 | list->tag = Tag_compatibility; | |
4818 | list->attr.type = 3; | |
4819 | list->attr.i = i; | |
4820 | list->attr.s = attr_strdup (abfd, s); | |
4821 | ||
4822 | lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes; | |
4823 | for (p = *lastp; p; p = p->next) | |
4824 | { | |
4825 | int cmp; | |
4826 | if (p->tag != Tag_compatibility) | |
4827 | break; | |
4828 | cmp = strcmp(s, p->attr.s); | |
4829 | if (cmp < 0 || (cmp == 0 && i < p->attr.i)) | |
4830 | break; | |
4831 | lastp = &p->next; | |
4832 | } | |
4833 | list->next = *lastp; | |
4834 | *lastp = list; | |
4835 | } | |
4836 | ||
c178919b NC |
4837 | /* Set the right machine number. */ |
4838 | ||
4839 | static bfd_boolean | |
57e8b36a | 4840 | elf32_arm_object_p (bfd *abfd) |
c178919b | 4841 | { |
5a6c6817 | 4842 | unsigned int mach; |
57e8b36a | 4843 | |
5a6c6817 | 4844 | mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); |
c178919b | 4845 | |
5a6c6817 NC |
4846 | if (mach != bfd_mach_arm_unknown) |
4847 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); | |
4848 | ||
4849 | else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) | |
4850 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); | |
e16bb312 | 4851 | |
e16bb312 | 4852 | else |
5a6c6817 | 4853 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
c178919b NC |
4854 | |
4855 | return TRUE; | |
4856 | } | |
4857 | ||
fc830a83 | 4858 | /* Function to keep ARM specific flags in the ELF header. */ |
3c9458e9 | 4859 | |
b34976b6 | 4860 | static bfd_boolean |
57e8b36a | 4861 | elf32_arm_set_private_flags (bfd *abfd, flagword flags) |
252b5132 RH |
4862 | { |
4863 | if (elf_flags_init (abfd) | |
4864 | && elf_elfheader (abfd)->e_flags != flags) | |
4865 | { | |
fc830a83 NC |
4866 | if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) |
4867 | { | |
fd2ec330 | 4868 | if (flags & EF_ARM_INTERWORK) |
d003868e AM |
4869 | (*_bfd_error_handler) |
4870 | (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), | |
4871 | abfd); | |
fc830a83 | 4872 | else |
d003868e AM |
4873 | _bfd_error_handler |
4874 | (_("Warning: Clearing the interworking flag of %B due to outside request"), | |
4875 | abfd); | |
fc830a83 | 4876 | } |
252b5132 RH |
4877 | } |
4878 | else | |
4879 | { | |
4880 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 | 4881 | elf_flags_init (abfd) = TRUE; |
252b5132 RH |
4882 | } |
4883 | ||
b34976b6 | 4884 | return TRUE; |
252b5132 RH |
4885 | } |
4886 | ||
ee065d83 PB |
4887 | /* Copy the eabi object attribute from IBFD to OBFD. */ |
4888 | static void | |
4889 | copy_eabi_attributes (bfd *ibfd, bfd *obfd) | |
4890 | { | |
4891 | aeabi_attribute *in_attr; | |
4892 | aeabi_attribute *out_attr; | |
4893 | aeabi_attribute_list *list; | |
4894 | int i; | |
4895 | ||
4896 | in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes; | |
4897 | out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
4898 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
4899 | { | |
4900 | out_attr->i = in_attr->i; | |
4901 | if (in_attr->s && *in_attr->s) | |
4902 | out_attr->s = attr_strdup (obfd, in_attr->s); | |
4903 | in_attr++; | |
4904 | out_attr++; | |
4905 | } | |
4906 | ||
4907 | for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
4908 | list; | |
4909 | list = list->next) | |
4910 | { | |
4911 | in_attr = &list->attr; | |
4912 | switch (in_attr->type) | |
4913 | { | |
4914 | case 1: | |
4915 | elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i); | |
4916 | break; | |
4917 | case 2: | |
4918 | elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s); | |
4919 | break; | |
4920 | case 3: | |
4921 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
4922 | break; | |
4923 | default: | |
4924 | abort(); | |
4925 | } | |
4926 | } | |
4927 | } | |
4928 | ||
4929 | ||
fc830a83 | 4930 | /* Copy backend specific data from one object module to another. */ |
9b485d32 | 4931 | |
b34976b6 | 4932 | static bfd_boolean |
57e8b36a | 4933 | elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 RH |
4934 | { |
4935 | flagword in_flags; | |
4936 | flagword out_flags; | |
4937 | ||
fc830a83 | 4938 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
252b5132 | 4939 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
b34976b6 | 4940 | return TRUE; |
252b5132 | 4941 | |
fc830a83 | 4942 | in_flags = elf_elfheader (ibfd)->e_flags; |
252b5132 RH |
4943 | out_flags = elf_elfheader (obfd)->e_flags; |
4944 | ||
fc830a83 NC |
4945 | if (elf_flags_init (obfd) |
4946 | && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN | |
4947 | && in_flags != out_flags) | |
252b5132 | 4948 | { |
252b5132 | 4949 | /* Cannot mix APCS26 and APCS32 code. */ |
fd2ec330 | 4950 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
b34976b6 | 4951 | return FALSE; |
252b5132 RH |
4952 | |
4953 | /* Cannot mix float APCS and non-float APCS code. */ | |
fd2ec330 | 4954 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
b34976b6 | 4955 | return FALSE; |
252b5132 RH |
4956 | |
4957 | /* If the src and dest have different interworking flags | |
4958 | then turn off the interworking bit. */ | |
fd2ec330 | 4959 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
252b5132 | 4960 | { |
fd2ec330 | 4961 | if (out_flags & EF_ARM_INTERWORK) |
d003868e AM |
4962 | _bfd_error_handler |
4963 | (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), | |
4964 | obfd, ibfd); | |
252b5132 | 4965 | |
fd2ec330 | 4966 | in_flags &= ~EF_ARM_INTERWORK; |
252b5132 | 4967 | } |
1006ba19 PB |
4968 | |
4969 | /* Likewise for PIC, though don't warn for this case. */ | |
fd2ec330 PB |
4970 | if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) |
4971 | in_flags &= ~EF_ARM_PIC; | |
252b5132 RH |
4972 | } |
4973 | ||
4974 | elf_elfheader (obfd)->e_flags = in_flags; | |
b34976b6 | 4975 | elf_flags_init (obfd) = TRUE; |
252b5132 | 4976 | |
94a3258f PB |
4977 | /* Also copy the EI_OSABI field. */ |
4978 | elf_elfheader (obfd)->e_ident[EI_OSABI] = | |
4979 | elf_elfheader (ibfd)->e_ident[EI_OSABI]; | |
4980 | ||
ee065d83 PB |
4981 | /* Copy EABI object attributes. */ |
4982 | copy_eabi_attributes (ibfd, obfd); | |
4983 | ||
4984 | return TRUE; | |
4985 | } | |
4986 | ||
4987 | /* Values for Tag_ABI_PCS_R9_use. */ | |
4988 | enum | |
4989 | { | |
4990 | AEABI_R9_V6, | |
4991 | AEABI_R9_SB, | |
4992 | AEABI_R9_TLS, | |
4993 | AEABI_R9_unused | |
4994 | }; | |
4995 | ||
4996 | /* Values for Tag_ABI_PCS_RW_data. */ | |
4997 | enum | |
4998 | { | |
4999 | AEABI_PCS_RW_data_absolute, | |
5000 | AEABI_PCS_RW_data_PCrel, | |
5001 | AEABI_PCS_RW_data_SBrel, | |
5002 | AEABI_PCS_RW_data_unused | |
5003 | }; | |
5004 | ||
5005 | /* Values for Tag_ABI_enum_size. */ | |
5006 | enum | |
5007 | { | |
5008 | AEABI_enum_unused, | |
5009 | AEABI_enum_short, | |
5010 | AEABI_enum_wide, | |
5011 | AEABI_enum_forced_wide | |
5012 | }; | |
5013 | ||
5014 | /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there | |
5015 | are conflicting attributes. */ | |
5016 | static bfd_boolean | |
5017 | elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd) | |
5018 | { | |
5019 | aeabi_attribute *in_attr; | |
5020 | aeabi_attribute *out_attr; | |
5021 | aeabi_attribute_list *in_list; | |
5022 | aeabi_attribute_list *out_list; | |
5023 | /* Some tags have 0 = don't care, 1 = strong requirement, | |
5024 | 2 = weak requirement. */ | |
5025 | static const int order_312[3] = {3, 1, 2}; | |
5026 | int i; | |
5027 | ||
5028 | if (!elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i) | |
5029 | { | |
5030 | /* This is the first object. Copy the attributes. */ | |
5031 | copy_eabi_attributes (ibfd, obfd); | |
5032 | return TRUE; | |
5033 | } | |
5034 | ||
5035 | /* Use the Tag_null value to indicate the attributes have been | |
5036 | initialized. */ | |
5037 | elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i = 1; | |
5038 | ||
5039 | in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes; | |
5040 | out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes; | |
5041 | /* This needs to happen before Tag_ABI_FP_number_model is merged. */ | |
5042 | if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i) | |
5043 | { | |
5044 | /* Ignore mismatches if teh object doesn't use floating point. */ | |
5045 | if (out_attr[Tag_ABI_FP_number_model].i == 0) | |
5046 | out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i; | |
5047 | else if (in_attr[Tag_ABI_FP_number_model].i != 0) | |
5048 | { | |
5049 | _bfd_error_handler | |
5050 | (_("ERROR: %B uses VFP register arguments, %B does not"), | |
5051 | ibfd, obfd); | |
5052 | return FALSE; | |
5053 | } | |
5054 | } | |
5055 | ||
5056 | for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++) | |
5057 | { | |
5058 | /* Merge this attribute with existing attributes. */ | |
5059 | switch (i) | |
5060 | { | |
5061 | case Tag_CPU_raw_name: | |
5062 | case Tag_CPU_name: | |
5063 | /* Use whichever has the greatest architecture requirements. */ | |
5064 | if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i) | |
5065 | out_attr[i].s = attr_strdup(obfd, in_attr[i].s); | |
5066 | break; | |
5067 | ||
5068 | case Tag_ABI_optimization_goals: | |
5069 | case Tag_ABI_FP_optimization_goals: | |
5070 | /* Use the first value seen. */ | |
5071 | break; | |
5072 | ||
5073 | case Tag_CPU_arch: | |
5074 | case Tag_ARM_ISA_use: | |
5075 | case Tag_THUMB_ISA_use: | |
5076 | case Tag_VFP_arch: | |
5077 | case Tag_WMMX_arch: | |
5078 | case Tag_NEON_arch: | |
5079 | /* ??? Do NEON and WMMX conflict? */ | |
5080 | case Tag_ABI_FP_rounding: | |
5081 | case Tag_ABI_FP_denormal: | |
5082 | case Tag_ABI_FP_exceptions: | |
5083 | case Tag_ABI_FP_user_exceptions: | |
5084 | case Tag_ABI_FP_number_model: | |
5085 | case Tag_ABI_align8_preserved: | |
5086 | case Tag_ABI_HardFP_use: | |
5087 | /* Use the largest value specified. */ | |
5088 | if (in_attr[i].i > out_attr[i].i) | |
5089 | out_attr[i].i = in_attr[i].i; | |
5090 | break; | |
5091 | ||
5092 | case Tag_CPU_arch_profile: | |
5093 | /* Warn if conflicting architecture profiles used. */ | |
5094 | if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i) | |
5095 | { | |
5096 | _bfd_error_handler | |
5097 | (_("ERROR: %B: Conflicting architecture profiles %c/%c"), | |
5098 | ibfd, in_attr[i].i, out_attr[i].i); | |
5099 | return FALSE; | |
5100 | } | |
5101 | if (in_attr[i].i) | |
5102 | out_attr[i].i = in_attr[i].i; | |
5103 | break; | |
5104 | case Tag_PCS_config: | |
5105 | if (out_attr[i].i == 0) | |
5106 | out_attr[i].i = in_attr[i].i; | |
5107 | else if (in_attr[i].i != 0 && out_attr[i].i != 0) | |
5108 | { | |
5109 | /* It's sometimes ok to mix different configs, so this is only | |
5110 | a warning. */ | |
5111 | _bfd_error_handler | |
5112 | (_("Warning: %B: Conflicting platform configuration"), ibfd); | |
5113 | } | |
5114 | break; | |
5115 | case Tag_ABI_PCS_R9_use: | |
5116 | if (out_attr[i].i != AEABI_R9_unused | |
5117 | && in_attr[i].i != AEABI_R9_unused) | |
5118 | { | |
5119 | _bfd_error_handler | |
5120 | (_("ERROR: %B: Conflicting use of R9"), ibfd); | |
5121 | return FALSE; | |
5122 | } | |
5123 | if (out_attr[i].i == AEABI_R9_unused) | |
5124 | out_attr[i].i = in_attr[i].i; | |
5125 | break; | |
5126 | case Tag_ABI_PCS_RW_data: | |
5127 | if (in_attr[i].i == AEABI_PCS_RW_data_SBrel | |
5128 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB | |
5129 | && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused) | |
5130 | { | |
5131 | _bfd_error_handler | |
5132 | (_("ERROR: %B: SB relative addressing conflicts with use of R9"), | |
5133 | ibfd); | |
5134 | return FALSE; | |
5135 | } | |
5136 | /* Use the smallest value specified. */ | |
5137 | if (in_attr[i].i < out_attr[i].i) | |
5138 | out_attr[i].i = in_attr[i].i; | |
5139 | break; | |
5140 | case Tag_ABI_PCS_RO_data: | |
5141 | /* Use the smallest value specified. */ | |
5142 | if (in_attr[i].i < out_attr[i].i) | |
5143 | out_attr[i].i = in_attr[i].i; | |
5144 | break; | |
5145 | case Tag_ABI_PCS_GOT_use: | |
5146 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
5147 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
5148 | out_attr[i].i = in_attr[i].i; | |
5149 | break; | |
5150 | case Tag_ABI_PCS_wchar_t: | |
5151 | if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i) | |
5152 | { | |
5153 | _bfd_error_handler | |
5154 | (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd); | |
5155 | return FALSE; | |
5156 | } | |
5157 | if (in_attr[i].i) | |
5158 | out_attr[i].i = in_attr[i].i; | |
5159 | break; | |
5160 | case Tag_ABI_align8_needed: | |
5161 | /* ??? Check against Tag_ABI_align8_preserved. */ | |
5162 | if (in_attr[i].i > 2 || out_attr[i].i > 2 | |
5163 | || order_312[in_attr[i].i] < order_312[out_attr[i].i]) | |
5164 | out_attr[i].i = in_attr[i].i; | |
5165 | break; | |
5166 | case Tag_ABI_enum_size: | |
5167 | if (in_attr[i].i != AEABI_enum_unused) | |
5168 | { | |
5169 | if (out_attr[i].i == AEABI_enum_unused | |
5170 | || out_attr[i].i == AEABI_enum_forced_wide) | |
5171 | { | |
5172 | /* The existing object is compatible with anything. | |
5173 | Use whatever requirements the new object has. */ | |
5174 | out_attr[i].i = in_attr[i].i; | |
5175 | } | |
5176 | else if (in_attr[i].i != AEABI_enum_forced_wide | |
5177 | && out_attr[i].i != in_attr[i].i) | |
5178 | { | |
5179 | _bfd_error_handler | |
5180 | (_("ERROR: %B: Conflicting enum sizes"), ibfd); | |
5181 | } | |
5182 | } | |
5183 | break; | |
5184 | case Tag_ABI_VFP_args: | |
5185 | /* Aready done. */ | |
5186 | break; | |
5187 | case Tag_ABI_WMMX_args: | |
5188 | if (in_attr[i].i != out_attr[i].i) | |
5189 | { | |
5190 | _bfd_error_handler | |
5191 | (_("ERROR: %B uses iWMMXt register arguments, %B does not"), | |
5192 | ibfd, obfd); | |
5193 | return FALSE; | |
5194 | } | |
5195 | break; | |
5196 | default: /* All known attributes should be explicitly covered. */ | |
5197 | abort (); | |
5198 | } | |
5199 | } | |
5200 | ||
5201 | in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
5202 | out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes; | |
5203 | while (in_list && in_list->tag == Tag_compatibility) | |
5204 | { | |
5205 | in_attr = &in_list->attr; | |
5206 | if (in_attr->i == 0) | |
5207 | continue; | |
5208 | if (in_attr->i == 1) | |
5209 | { | |
5210 | _bfd_error_handler | |
5211 | (_("ERROR: %B: Must be processed by '%s' toolchain"), | |
5212 | ibfd, in_attr->s); | |
5213 | return FALSE; | |
5214 | } | |
5215 | if (!out_list || out_list->tag != Tag_compatibility | |
5216 | || strcmp (in_attr->s, out_list->attr.s) != 0) | |
5217 | { | |
5218 | /* Add this compatibility tag to the output. */ | |
5219 | elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s); | |
5220 | continue; | |
5221 | } | |
5222 | out_attr = &out_list->attr; | |
5223 | /* Check all the input tags with the same identifier. */ | |
5224 | for (;;) | |
5225 | { | |
5226 | if (out_list->tag != Tag_compatibility | |
5227 | || in_attr->i != out_attr->i | |
5228 | || strcmp (in_attr->s, out_attr->s) != 0) | |
5229 | { | |
5230 | _bfd_error_handler | |
5231 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
5232 | ibfd, in_attr->s, in_attr->i); | |
5233 | return FALSE; | |
5234 | } | |
5235 | in_list = in_list->next; | |
5236 | if (in_list->tag != Tag_compatibility | |
5237 | || strcmp (in_attr->s, in_list->attr.s) != 0) | |
5238 | break; | |
5239 | in_attr = &in_list->attr; | |
5240 | out_list = out_list->next; | |
5241 | if (out_list) | |
5242 | out_attr = &out_list->attr; | |
5243 | } | |
5244 | ||
5245 | /* Check the output doesn't have extra tags with this identifier. */ | |
5246 | if (out_list && out_list->tag == Tag_compatibility | |
5247 | && strcmp (in_attr->s, out_list->attr.s) == 0) | |
5248 | { | |
5249 | _bfd_error_handler | |
5250 | (_("ERROR: %B: Incompatible object tag '%s':%d"), | |
5251 | ibfd, in_attr->s, out_list->attr.i); | |
5252 | return FALSE; | |
5253 | } | |
5254 | } | |
5255 | ||
5256 | for (; in_list; in_list = in_list->next) | |
5257 | { | |
5258 | if ((in_list->tag & 128) < 64) | |
eb111b1f BE |
5259 | { |
5260 | _bfd_error_handler | |
5261 | (_("Warning: %B: Unknown EABI object attribute %d"), | |
5262 | ibfd, in_list->tag); | |
5263 | break; | |
5264 | } | |
ee065d83 | 5265 | } |
b34976b6 | 5266 | return TRUE; |
252b5132 RH |
5267 | } |
5268 | ||
3a4a14e9 PB |
5269 | |
5270 | /* Return TRUE if the two EABI versions are incompatible. */ | |
5271 | ||
5272 | static bfd_boolean | |
5273 | elf32_arm_versions_compatible (unsigned iver, unsigned over) | |
5274 | { | |
5275 | /* v4 and v5 are the same spec before and after it was released, | |
5276 | so allow mixing them. */ | |
5277 | if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5) | |
5278 | || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4)) | |
5279 | return TRUE; | |
5280 | ||
5281 | return (iver == over); | |
5282 | } | |
5283 | ||
252b5132 RH |
5284 | /* Merge backend specific data from an object file to the output |
5285 | object file when linking. */ | |
9b485d32 | 5286 | |
b34976b6 | 5287 | static bfd_boolean |
57e8b36a | 5288 | elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
252b5132 RH |
5289 | { |
5290 | flagword out_flags; | |
5291 | flagword in_flags; | |
b34976b6 | 5292 | bfd_boolean flags_compatible = TRUE; |
cf919dfd | 5293 | asection *sec; |
252b5132 | 5294 | |
9b485d32 | 5295 | /* Check if we have the same endianess. */ |
82e51918 | 5296 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 5297 | return FALSE; |
1fe494a5 | 5298 | |
252b5132 RH |
5299 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
5300 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 5301 | return TRUE; |
252b5132 | 5302 | |
ee065d83 PB |
5303 | if (!elf32_arm_merge_eabi_attributes (ibfd, obfd)) |
5304 | return FALSE; | |
5305 | ||
252b5132 RH |
5306 | /* The input BFD must have had its flags initialised. */ |
5307 | /* The following seems bogus to me -- The flags are initialized in | |
5308 | the assembler but I don't think an elf_flags_init field is | |
9b485d32 | 5309 | written into the object. */ |
252b5132 RH |
5310 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
5311 | ||
5312 | in_flags = elf_elfheader (ibfd)->e_flags; | |
5313 | out_flags = elf_elfheader (obfd)->e_flags; | |
5314 | ||
5315 | if (!elf_flags_init (obfd)) | |
5316 | { | |
fe077fa6 NC |
5317 | /* If the input is the default architecture and had the default |
5318 | flags then do not bother setting the flags for the output | |
5319 | architecture, instead allow future merges to do this. If no | |
5320 | future merges ever set these flags then they will retain their | |
5321 | uninitialised values, which surprise surprise, correspond | |
252b5132 | 5322 | to the default values. */ |
fe077fa6 NC |
5323 | if (bfd_get_arch_info (ibfd)->the_default |
5324 | && elf_elfheader (ibfd)->e_flags == 0) | |
b34976b6 | 5325 | return TRUE; |
252b5132 | 5326 | |
b34976b6 | 5327 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
5328 | elf_elfheader (obfd)->e_flags = in_flags; |
5329 | ||
5330 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
5331 | && bfd_get_arch_info (obfd)->the_default) | |
5332 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); | |
5333 | ||
b34976b6 | 5334 | return TRUE; |
252b5132 RH |
5335 | } |
5336 | ||
5a6c6817 NC |
5337 | /* Determine what should happen if the input ARM architecture |
5338 | does not match the output ARM architecture. */ | |
5339 | if (! bfd_arm_merge_machines (ibfd, obfd)) | |
5340 | return FALSE; | |
e16bb312 | 5341 | |
1006ba19 | 5342 | /* Identical flags must be compatible. */ |
252b5132 | 5343 | if (in_flags == out_flags) |
b34976b6 | 5344 | return TRUE; |
252b5132 | 5345 | |
35a0f415 DJ |
5346 | /* Check to see if the input BFD actually contains any sections. If |
5347 | not, its flags may not have been initialised either, but it | |
8e3de13a | 5348 | cannot actually cause any incompatiblity. Do not short-circuit |
35a0f415 | 5349 | dynamic objects; their section list may be emptied by |
d1f161ea | 5350 | elf_link_add_object_symbols. |
35a0f415 | 5351 | |
d1f161ea NC |
5352 | Also check to see if there are no code sections in the input. |
5353 | In this case there is no need to check for code specific flags. | |
5354 | XXX - do we need to worry about floating-point format compatability | |
5355 | in data sections ? */ | |
35a0f415 | 5356 | if (!(ibfd->flags & DYNAMIC)) |
cf919dfd | 5357 | { |
35a0f415 | 5358 | bfd_boolean null_input_bfd = TRUE; |
d1f161ea | 5359 | bfd_boolean only_data_sections = TRUE; |
35a0f415 DJ |
5360 | |
5361 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
cf919dfd | 5362 | { |
35a0f415 DJ |
5363 | /* Ignore synthetic glue sections. */ |
5364 | if (strcmp (sec->name, ".glue_7") | |
5365 | && strcmp (sec->name, ".glue_7t")) | |
5366 | { | |
d1f161ea NC |
5367 | if ((bfd_get_section_flags (ibfd, sec) |
5368 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
5369 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
5370 | only_data_sections = FALSE; | |
5371 | ||
35a0f415 DJ |
5372 | null_input_bfd = FALSE; |
5373 | break; | |
5374 | } | |
cf919dfd | 5375 | } |
d1f161ea NC |
5376 | |
5377 | if (null_input_bfd || only_data_sections) | |
35a0f415 | 5378 | return TRUE; |
cf919dfd | 5379 | } |
cf919dfd | 5380 | |
252b5132 | 5381 | /* Complain about various flag mismatches. */ |
3a4a14e9 PB |
5382 | if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags), |
5383 | EF_ARM_EABI_VERSION (out_flags))) | |
fc830a83 | 5384 | { |
d003868e | 5385 | _bfd_error_handler |
3656d5e3 | 5386 | (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"), |
d003868e AM |
5387 | ibfd, obfd, |
5388 | (in_flags & EF_ARM_EABIMASK) >> 24, | |
5389 | (out_flags & EF_ARM_EABIMASK) >> 24); | |
b34976b6 | 5390 | return FALSE; |
fc830a83 | 5391 | } |
252b5132 | 5392 | |
1006ba19 | 5393 | /* Not sure what needs to be checked for EABI versions >= 1. */ |
00a97672 RS |
5394 | /* VxWorks libraries do not use these flags. */ |
5395 | if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed | |
5396 | && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed | |
5397 | && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) | |
1006ba19 | 5398 | { |
fd2ec330 | 5399 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
1006ba19 | 5400 | { |
d003868e AM |
5401 | _bfd_error_handler |
5402 | (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), | |
5403 | ibfd, obfd, | |
5404 | in_flags & EF_ARM_APCS_26 ? 26 : 32, | |
5405 | out_flags & EF_ARM_APCS_26 ? 26 : 32); | |
b34976b6 | 5406 | flags_compatible = FALSE; |
1006ba19 | 5407 | } |
252b5132 | 5408 | |
fd2ec330 | 5409 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
1006ba19 | 5410 | { |
5eefb65f | 5411 | if (in_flags & EF_ARM_APCS_FLOAT) |
d003868e AM |
5412 | _bfd_error_handler |
5413 | (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), | |
5414 | ibfd, obfd); | |
5eefb65f | 5415 | else |
d003868e AM |
5416 | _bfd_error_handler |
5417 | (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), | |
5418 | ibfd, obfd); | |
63b0f745 | 5419 | |
b34976b6 | 5420 | flags_compatible = FALSE; |
1006ba19 | 5421 | } |
252b5132 | 5422 | |
96a846ea | 5423 | if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) |
1006ba19 | 5424 | { |
96a846ea | 5425 | if (in_flags & EF_ARM_VFP_FLOAT) |
d003868e AM |
5426 | _bfd_error_handler |
5427 | (_("ERROR: %B uses VFP instructions, whereas %B does not"), | |
5428 | ibfd, obfd); | |
5eefb65f | 5429 | else |
d003868e AM |
5430 | _bfd_error_handler |
5431 | (_("ERROR: %B uses FPA instructions, whereas %B does not"), | |
5432 | ibfd, obfd); | |
fde78edd NC |
5433 | |
5434 | flags_compatible = FALSE; | |
5435 | } | |
5436 | ||
5437 | if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) | |
5438 | { | |
5439 | if (in_flags & EF_ARM_MAVERICK_FLOAT) | |
d003868e AM |
5440 | _bfd_error_handler |
5441 | (_("ERROR: %B uses Maverick instructions, whereas %B does not"), | |
5442 | ibfd, obfd); | |
fde78edd | 5443 | else |
d003868e AM |
5444 | _bfd_error_handler |
5445 | (_("ERROR: %B does not use Maverick instructions, whereas %B does"), | |
5446 | ibfd, obfd); | |
63b0f745 | 5447 | |
b34976b6 | 5448 | flags_compatible = FALSE; |
1006ba19 | 5449 | } |
96a846ea RE |
5450 | |
5451 | #ifdef EF_ARM_SOFT_FLOAT | |
5452 | if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) | |
5453 | { | |
5454 | /* We can allow interworking between code that is VFP format | |
5455 | layout, and uses either soft float or integer regs for | |
5456 | passing floating point arguments and results. We already | |
5457 | know that the APCS_FLOAT flags match; similarly for VFP | |
5458 | flags. */ | |
5459 | if ((in_flags & EF_ARM_APCS_FLOAT) != 0 | |
5460 | || (in_flags & EF_ARM_VFP_FLOAT) == 0) | |
5461 | { | |
5462 | if (in_flags & EF_ARM_SOFT_FLOAT) | |
d003868e AM |
5463 | _bfd_error_handler |
5464 | (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), | |
5465 | ibfd, obfd); | |
96a846ea | 5466 | else |
d003868e AM |
5467 | _bfd_error_handler |
5468 | (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), | |
5469 | ibfd, obfd); | |
96a846ea | 5470 | |
b34976b6 | 5471 | flags_compatible = FALSE; |
96a846ea RE |
5472 | } |
5473 | } | |
ee43f35e | 5474 | #endif |
252b5132 | 5475 | |
1006ba19 | 5476 | /* Interworking mismatch is only a warning. */ |
fd2ec330 | 5477 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
8f615d07 | 5478 | { |
e3c8793a NC |
5479 | if (in_flags & EF_ARM_INTERWORK) |
5480 | { | |
d003868e AM |
5481 | _bfd_error_handler |
5482 | (_("Warning: %B supports interworking, whereas %B does not"), | |
5483 | ibfd, obfd); | |
e3c8793a NC |
5484 | } |
5485 | else | |
5486 | { | |
d003868e AM |
5487 | _bfd_error_handler |
5488 | (_("Warning: %B does not support interworking, whereas %B does"), | |
5489 | ibfd, obfd); | |
e3c8793a | 5490 | } |
8f615d07 | 5491 | } |
252b5132 | 5492 | } |
63b0f745 | 5493 | |
1006ba19 | 5494 | return flags_compatible; |
252b5132 RH |
5495 | } |
5496 | ||
9b485d32 NC |
5497 | /* Display the flags field. */ |
5498 | ||
b34976b6 | 5499 | static bfd_boolean |
57e8b36a | 5500 | elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) |
252b5132 | 5501 | { |
fc830a83 NC |
5502 | FILE * file = (FILE *) ptr; |
5503 | unsigned long flags; | |
252b5132 RH |
5504 | |
5505 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
5506 | ||
5507 | /* Print normal ELF private data. */ | |
5508 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
5509 | ||
fc830a83 | 5510 | flags = elf_elfheader (abfd)->e_flags; |
9b485d32 NC |
5511 | /* Ignore init flag - it may not be set, despite the flags field |
5512 | containing valid data. */ | |
252b5132 RH |
5513 | |
5514 | /* xgettext:c-format */ | |
9b485d32 | 5515 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
252b5132 | 5516 | |
fc830a83 NC |
5517 | switch (EF_ARM_EABI_VERSION (flags)) |
5518 | { | |
5519 | case EF_ARM_EABI_UNKNOWN: | |
4cc11e76 | 5520 | /* The following flag bits are GNU extensions and not part of the |
fc830a83 NC |
5521 | official ARM ELF extended ABI. Hence they are only decoded if |
5522 | the EABI version is not set. */ | |
fd2ec330 | 5523 | if (flags & EF_ARM_INTERWORK) |
9b485d32 | 5524 | fprintf (file, _(" [interworking enabled]")); |
9a5aca8c | 5525 | |
fd2ec330 | 5526 | if (flags & EF_ARM_APCS_26) |
6c571f00 | 5527 | fprintf (file, " [APCS-26]"); |
fc830a83 | 5528 | else |
6c571f00 | 5529 | fprintf (file, " [APCS-32]"); |
9a5aca8c | 5530 | |
96a846ea RE |
5531 | if (flags & EF_ARM_VFP_FLOAT) |
5532 | fprintf (file, _(" [VFP float format]")); | |
fde78edd NC |
5533 | else if (flags & EF_ARM_MAVERICK_FLOAT) |
5534 | fprintf (file, _(" [Maverick float format]")); | |
96a846ea RE |
5535 | else |
5536 | fprintf (file, _(" [FPA float format]")); | |
5537 | ||
fd2ec330 | 5538 | if (flags & EF_ARM_APCS_FLOAT) |
9b485d32 | 5539 | fprintf (file, _(" [floats passed in float registers]")); |
9a5aca8c | 5540 | |
fd2ec330 | 5541 | if (flags & EF_ARM_PIC) |
9b485d32 | 5542 | fprintf (file, _(" [position independent]")); |
fc830a83 | 5543 | |
fd2ec330 | 5544 | if (flags & EF_ARM_NEW_ABI) |
9b485d32 | 5545 | fprintf (file, _(" [new ABI]")); |
9a5aca8c | 5546 | |
fd2ec330 | 5547 | if (flags & EF_ARM_OLD_ABI) |
9b485d32 | 5548 | fprintf (file, _(" [old ABI]")); |
9a5aca8c | 5549 | |
fd2ec330 | 5550 | if (flags & EF_ARM_SOFT_FLOAT) |
9b485d32 | 5551 | fprintf (file, _(" [software FP]")); |
9a5aca8c | 5552 | |
96a846ea RE |
5553 | flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT |
5554 | | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI | |
fde78edd NC |
5555 | | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT |
5556 | | EF_ARM_MAVERICK_FLOAT); | |
fc830a83 | 5557 | break; |
9a5aca8c | 5558 | |
fc830a83 | 5559 | case EF_ARM_EABI_VER1: |
9b485d32 | 5560 | fprintf (file, _(" [Version1 EABI]")); |
9a5aca8c | 5561 | |
fc830a83 | 5562 | if (flags & EF_ARM_SYMSARESORTED) |
9b485d32 | 5563 | fprintf (file, _(" [sorted symbol table]")); |
fc830a83 | 5564 | else |
9b485d32 | 5565 | fprintf (file, _(" [unsorted symbol table]")); |
9a5aca8c | 5566 | |
fc830a83 NC |
5567 | flags &= ~ EF_ARM_SYMSARESORTED; |
5568 | break; | |
9a5aca8c | 5569 | |
fd2ec330 PB |
5570 | case EF_ARM_EABI_VER2: |
5571 | fprintf (file, _(" [Version2 EABI]")); | |
5572 | ||
5573 | if (flags & EF_ARM_SYMSARESORTED) | |
5574 | fprintf (file, _(" [sorted symbol table]")); | |
5575 | else | |
5576 | fprintf (file, _(" [unsorted symbol table]")); | |
5577 | ||
5578 | if (flags & EF_ARM_DYNSYMSUSESEGIDX) | |
5579 | fprintf (file, _(" [dynamic symbols use segment index]")); | |
5580 | ||
5581 | if (flags & EF_ARM_MAPSYMSFIRST) | |
5582 | fprintf (file, _(" [mapping symbols precede others]")); | |
5583 | ||
99e4ae17 | 5584 | flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX |
fd2ec330 PB |
5585 | | EF_ARM_MAPSYMSFIRST); |
5586 | break; | |
5587 | ||
d507cf36 PB |
5588 | case EF_ARM_EABI_VER3: |
5589 | fprintf (file, _(" [Version3 EABI]")); | |
8cb51566 PB |
5590 | break; |
5591 | ||
5592 | case EF_ARM_EABI_VER4: | |
5593 | fprintf (file, _(" [Version4 EABI]")); | |
3a4a14e9 | 5594 | goto eabi; |
d507cf36 | 5595 | |
3a4a14e9 PB |
5596 | case EF_ARM_EABI_VER5: |
5597 | fprintf (file, _(" [Version5 EABI]")); | |
5598 | eabi: | |
d507cf36 PB |
5599 | if (flags & EF_ARM_BE8) |
5600 | fprintf (file, _(" [BE8]")); | |
5601 | ||
5602 | if (flags & EF_ARM_LE8) | |
5603 | fprintf (file, _(" [LE8]")); | |
5604 | ||
5605 | flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); | |
5606 | break; | |
5607 | ||
fc830a83 | 5608 | default: |
9b485d32 | 5609 | fprintf (file, _(" <EABI version unrecognised>")); |
fc830a83 NC |
5610 | break; |
5611 | } | |
252b5132 | 5612 | |
fc830a83 | 5613 | flags &= ~ EF_ARM_EABIMASK; |
252b5132 | 5614 | |
fc830a83 | 5615 | if (flags & EF_ARM_RELEXEC) |
9b485d32 | 5616 | fprintf (file, _(" [relocatable executable]")); |
252b5132 | 5617 | |
fc830a83 | 5618 | if (flags & EF_ARM_HASENTRY) |
9b485d32 | 5619 | fprintf (file, _(" [has entry point]")); |
252b5132 | 5620 | |
fc830a83 NC |
5621 | flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); |
5622 | ||
5623 | if (flags) | |
9b485d32 | 5624 | fprintf (file, _("<Unrecognised flag bits set>")); |
9a5aca8c | 5625 | |
252b5132 RH |
5626 | fputc ('\n', file); |
5627 | ||
b34976b6 | 5628 | return TRUE; |
252b5132 RH |
5629 | } |
5630 | ||
5631 | static int | |
57e8b36a | 5632 | elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
252b5132 | 5633 | { |
2f0ca46a NC |
5634 | switch (ELF_ST_TYPE (elf_sym->st_info)) |
5635 | { | |
5636 | case STT_ARM_TFUNC: | |
5637 | return ELF_ST_TYPE (elf_sym->st_info); | |
ce855c42 | 5638 | |
2f0ca46a NC |
5639 | case STT_ARM_16BIT: |
5640 | /* If the symbol is not an object, return the STT_ARM_16BIT flag. | |
5641 | This allows us to distinguish between data used by Thumb instructions | |
5642 | and non-data (which is probably code) inside Thumb regions of an | |
5643 | executable. */ | |
1a0eb693 | 5644 | if (type != STT_OBJECT && type != STT_TLS) |
2f0ca46a NC |
5645 | return ELF_ST_TYPE (elf_sym->st_info); |
5646 | break; | |
9a5aca8c | 5647 | |
ce855c42 NC |
5648 | default: |
5649 | break; | |
2f0ca46a NC |
5650 | } |
5651 | ||
5652 | return type; | |
252b5132 | 5653 | } |
f21f3fe0 | 5654 | |
252b5132 | 5655 | static asection * |
57e8b36a NC |
5656 | elf32_arm_gc_mark_hook (asection * sec, |
5657 | struct bfd_link_info * info ATTRIBUTE_UNUSED, | |
5658 | Elf_Internal_Rela * rel, | |
5659 | struct elf_link_hash_entry * h, | |
5660 | Elf_Internal_Sym * sym) | |
252b5132 RH |
5661 | { |
5662 | if (h != NULL) | |
5663 | { | |
5664 | switch (ELF32_R_TYPE (rel->r_info)) | |
5665 | { | |
5666 | case R_ARM_GNU_VTINHERIT: | |
5667 | case R_ARM_GNU_VTENTRY: | |
5668 | break; | |
5669 | ||
5670 | default: | |
5671 | switch (h->root.type) | |
5672 | { | |
5673 | case bfd_link_hash_defined: | |
5674 | case bfd_link_hash_defweak: | |
5675 | return h->root.u.def.section; | |
5676 | ||
5677 | case bfd_link_hash_common: | |
5678 | return h->root.u.c.p->section; | |
e049a0de ILT |
5679 | |
5680 | default: | |
5681 | break; | |
252b5132 RH |
5682 | } |
5683 | } | |
5684 | } | |
5685 | else | |
1e2f5b6e | 5686 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
9ad5cbcf | 5687 | |
252b5132 RH |
5688 | return NULL; |
5689 | } | |
5690 | ||
780a67af NC |
5691 | /* Update the got entry reference counts for the section being removed. */ |
5692 | ||
b34976b6 | 5693 | static bfd_boolean |
ba93b8ac DJ |
5694 | elf32_arm_gc_sweep_hook (bfd * abfd, |
5695 | struct bfd_link_info * info, | |
5696 | asection * sec, | |
5697 | const Elf_Internal_Rela * relocs) | |
252b5132 | 5698 | { |
5e681ec4 PB |
5699 | Elf_Internal_Shdr *symtab_hdr; |
5700 | struct elf_link_hash_entry **sym_hashes; | |
5701 | bfd_signed_vma *local_got_refcounts; | |
5702 | const Elf_Internal_Rela *rel, *relend; | |
eb043451 PB |
5703 | struct elf32_arm_link_hash_table * globals; |
5704 | ||
5705 | globals = elf32_arm_hash_table (info); | |
5e681ec4 PB |
5706 | |
5707 | elf_section_data (sec)->local_dynrel = NULL; | |
5708 | ||
5709 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
5710 | sym_hashes = elf_sym_hashes (abfd); | |
5711 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
5712 | ||
5713 | relend = relocs + sec->reloc_count; | |
5714 | for (rel = relocs; rel < relend; rel++) | |
eb043451 | 5715 | { |
3eb128b2 AM |
5716 | unsigned long r_symndx; |
5717 | struct elf_link_hash_entry *h = NULL; | |
eb043451 | 5718 | int r_type; |
5e681ec4 | 5719 | |
3eb128b2 AM |
5720 | r_symndx = ELF32_R_SYM (rel->r_info); |
5721 | if (r_symndx >= symtab_hdr->sh_info) | |
5722 | { | |
5723 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5724 | while (h->root.type == bfd_link_hash_indirect | |
5725 | || h->root.type == bfd_link_hash_warning) | |
5726 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5727 | } | |
5728 | ||
eb043451 | 5729 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 5730 | r_type = arm_real_reloc_type (globals, r_type); |
eb043451 PB |
5731 | switch (r_type) |
5732 | { | |
5733 | case R_ARM_GOT32: | |
eb043451 | 5734 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
5735 | case R_ARM_TLS_GD32: |
5736 | case R_ARM_TLS_IE32: | |
3eb128b2 | 5737 | if (h != NULL) |
eb043451 | 5738 | { |
eb043451 PB |
5739 | if (h->got.refcount > 0) |
5740 | h->got.refcount -= 1; | |
5741 | } | |
5742 | else if (local_got_refcounts != NULL) | |
5743 | { | |
5744 | if (local_got_refcounts[r_symndx] > 0) | |
5745 | local_got_refcounts[r_symndx] -= 1; | |
5746 | } | |
5747 | break; | |
5748 | ||
ba93b8ac DJ |
5749 | case R_ARM_TLS_LDM32: |
5750 | elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; | |
5751 | break; | |
5752 | ||
eb043451 PB |
5753 | case R_ARM_ABS32: |
5754 | case R_ARM_REL32: | |
5755 | case R_ARM_PC24: | |
5756 | case R_ARM_PLT32: | |
5b5bb741 PB |
5757 | case R_ARM_CALL: |
5758 | case R_ARM_JUMP24: | |
eb043451 | 5759 | case R_ARM_PREL31: |
c19d1205 | 5760 | case R_ARM_THM_CALL: |
b6895b4f PB |
5761 | case R_ARM_MOVW_ABS_NC: |
5762 | case R_ARM_MOVT_ABS: | |
5763 | case R_ARM_MOVW_PREL_NC: | |
5764 | case R_ARM_MOVT_PREL: | |
5765 | case R_ARM_THM_MOVW_ABS_NC: | |
5766 | case R_ARM_THM_MOVT_ABS: | |
5767 | case R_ARM_THM_MOVW_PREL_NC: | |
5768 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 DJ |
5769 | /* Should the interworking branches be here also? */ |
5770 | ||
3eb128b2 | 5771 | if (h != NULL) |
eb043451 PB |
5772 | { |
5773 | struct elf32_arm_link_hash_entry *eh; | |
5774 | struct elf32_arm_relocs_copied **pp; | |
5775 | struct elf32_arm_relocs_copied *p; | |
5e681ec4 | 5776 | |
b7693d02 | 5777 | eh = (struct elf32_arm_link_hash_entry *) h; |
5e681ec4 | 5778 | |
eb043451 | 5779 | if (h->plt.refcount > 0) |
b7693d02 DJ |
5780 | { |
5781 | h->plt.refcount -= 1; | |
c19d1205 | 5782 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL) |
b7693d02 DJ |
5783 | eh->plt_thumb_refcount--; |
5784 | } | |
5e681ec4 | 5785 | |
eb043451 | 5786 | if (r_type == R_ARM_ABS32 |
eb043451 PB |
5787 | || r_type == R_ARM_REL32) |
5788 | { | |
eb043451 PB |
5789 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; |
5790 | pp = &p->next) | |
5791 | if (p->section == sec) | |
5792 | { | |
5793 | p->count -= 1; | |
ba93b8ac DJ |
5794 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32) |
5795 | p->pc_count -= 1; | |
eb043451 PB |
5796 | if (p->count == 0) |
5797 | *pp = p->next; | |
5798 | break; | |
5799 | } | |
5800 | } | |
5801 | } | |
5802 | break; | |
5e681ec4 | 5803 | |
eb043451 PB |
5804 | default: |
5805 | break; | |
5806 | } | |
5807 | } | |
5e681ec4 | 5808 | |
b34976b6 | 5809 | return TRUE; |
252b5132 RH |
5810 | } |
5811 | ||
780a67af NC |
5812 | /* Look through the relocs for a section during the first phase. */ |
5813 | ||
b34976b6 | 5814 | static bfd_boolean |
57e8b36a NC |
5815 | elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, |
5816 | asection *sec, const Elf_Internal_Rela *relocs) | |
252b5132 | 5817 | { |
b34976b6 AM |
5818 | Elf_Internal_Shdr *symtab_hdr; |
5819 | struct elf_link_hash_entry **sym_hashes; | |
5820 | struct elf_link_hash_entry **sym_hashes_end; | |
5821 | const Elf_Internal_Rela *rel; | |
5822 | const Elf_Internal_Rela *rel_end; | |
5823 | bfd *dynobj; | |
5e681ec4 | 5824 | asection *sreloc; |
b34976b6 | 5825 | bfd_vma *local_got_offsets; |
5e681ec4 | 5826 | struct elf32_arm_link_hash_table *htab; |
9a5aca8c | 5827 | |
1049f94e | 5828 | if (info->relocatable) |
b34976b6 | 5829 | return TRUE; |
9a5aca8c | 5830 | |
5e681ec4 PB |
5831 | htab = elf32_arm_hash_table (info); |
5832 | sreloc = NULL; | |
9a5aca8c | 5833 | |
67687978 PB |
5834 | /* Create dynamic sections for relocatable executables so that we can |
5835 | copy relocations. */ | |
5836 | if (htab->root.is_relocatable_executable | |
5837 | && ! htab->root.dynamic_sections_created) | |
5838 | { | |
5839 | if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) | |
5840 | return FALSE; | |
5841 | } | |
5842 | ||
252b5132 RH |
5843 | dynobj = elf_hash_table (info)->dynobj; |
5844 | local_got_offsets = elf_local_got_offsets (abfd); | |
f21f3fe0 | 5845 | |
252b5132 RH |
5846 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5847 | sym_hashes = elf_sym_hashes (abfd); | |
9b485d32 NC |
5848 | sym_hashes_end = sym_hashes |
5849 | + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); | |
5850 | ||
252b5132 RH |
5851 | if (!elf_bad_symtab (abfd)) |
5852 | sym_hashes_end -= symtab_hdr->sh_info; | |
9b485d32 | 5853 | |
252b5132 RH |
5854 | rel_end = relocs + sec->reloc_count; |
5855 | for (rel = relocs; rel < rel_end; rel++) | |
5856 | { | |
5857 | struct elf_link_hash_entry *h; | |
b7693d02 | 5858 | struct elf32_arm_link_hash_entry *eh; |
252b5132 | 5859 | unsigned long r_symndx; |
eb043451 | 5860 | int r_type; |
9a5aca8c | 5861 | |
252b5132 | 5862 | r_symndx = ELF32_R_SYM (rel->r_info); |
eb043451 | 5863 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 5864 | r_type = arm_real_reloc_type (htab, r_type); |
ba93b8ac DJ |
5865 | |
5866 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
5867 | { | |
5868 | (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd, | |
5869 | r_symndx); | |
5870 | return FALSE; | |
5871 | } | |
5872 | ||
252b5132 RH |
5873 | if (r_symndx < symtab_hdr->sh_info) |
5874 | h = NULL; | |
5875 | else | |
973a3492 L |
5876 | { |
5877 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5878 | while (h->root.type == bfd_link_hash_indirect | |
5879 | || h->root.type == bfd_link_hash_warning) | |
5880 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5881 | } | |
9a5aca8c | 5882 | |
b7693d02 DJ |
5883 | eh = (struct elf32_arm_link_hash_entry *) h; |
5884 | ||
eb043451 | 5885 | switch (r_type) |
252b5132 | 5886 | { |
5e681ec4 | 5887 | case R_ARM_GOT32: |
eb043451 | 5888 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
5889 | case R_ARM_TLS_GD32: |
5890 | case R_ARM_TLS_IE32: | |
5e681ec4 | 5891 | /* This symbol requires a global offset table entry. */ |
ba93b8ac DJ |
5892 | { |
5893 | int tls_type, old_tls_type; | |
5e681ec4 | 5894 | |
ba93b8ac DJ |
5895 | switch (r_type) |
5896 | { | |
5897 | case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break; | |
5898 | case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break; | |
5899 | default: tls_type = GOT_NORMAL; break; | |
5900 | } | |
252b5132 | 5901 | |
ba93b8ac DJ |
5902 | if (h != NULL) |
5903 | { | |
5904 | h->got.refcount++; | |
5905 | old_tls_type = elf32_arm_hash_entry (h)->tls_type; | |
5906 | } | |
5907 | else | |
5908 | { | |
5909 | bfd_signed_vma *local_got_refcounts; | |
5910 | ||
5911 | /* This is a global offset table entry for a local symbol. */ | |
5912 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
5913 | if (local_got_refcounts == NULL) | |
5914 | { | |
5915 | bfd_size_type size; | |
5916 | ||
5917 | size = symtab_hdr->sh_info; | |
5918 | size *= (sizeof (bfd_signed_vma) + sizeof(char)); | |
5919 | local_got_refcounts = bfd_zalloc (abfd, size); | |
5920 | if (local_got_refcounts == NULL) | |
5921 | return FALSE; | |
5922 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
5923 | elf32_arm_local_got_tls_type (abfd) | |
5924 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
5925 | } | |
5926 | local_got_refcounts[r_symndx] += 1; | |
5927 | old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx]; | |
5928 | } | |
5929 | ||
5930 | /* We will already have issued an error message if there is a | |
5931 | TLS / non-TLS mismatch, based on the symbol type. We don't | |
5932 | support any linker relaxations. So just combine any TLS | |
5933 | types needed. */ | |
5934 | if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL | |
5935 | && tls_type != GOT_NORMAL) | |
5936 | tls_type |= old_tls_type; | |
5937 | ||
5938 | if (old_tls_type != tls_type) | |
5939 | { | |
5940 | if (h != NULL) | |
5941 | elf32_arm_hash_entry (h)->tls_type = tls_type; | |
5942 | else | |
5943 | elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
5944 | } | |
5945 | } | |
5946 | /* Fall through */ | |
5947 | ||
5948 | case R_ARM_TLS_LDM32: | |
5949 | if (r_type == R_ARM_TLS_LDM32) | |
5950 | htab->tls_ldm_got.refcount++; | |
5951 | /* Fall through */ | |
252b5132 | 5952 | |
c19d1205 | 5953 | case R_ARM_GOTOFF32: |
5e681ec4 PB |
5954 | case R_ARM_GOTPC: |
5955 | if (htab->sgot == NULL) | |
5956 | { | |
5957 | if (htab->root.dynobj == NULL) | |
5958 | htab->root.dynobj = abfd; | |
5959 | if (!create_got_section (htab->root.dynobj, info)) | |
5960 | return FALSE; | |
5961 | } | |
252b5132 RH |
5962 | break; |
5963 | ||
00a97672 RS |
5964 | case R_ARM_ABS12: |
5965 | /* VxWorks uses dynamic R_ARM_ABS12 relocations for | |
5966 | ldr __GOTT_INDEX__ offsets. */ | |
5967 | if (!htab->vxworks_p) | |
5968 | break; | |
5969 | /* Fall through */ | |
5970 | ||
252b5132 RH |
5971 | case R_ARM_ABS32: |
5972 | case R_ARM_REL32: | |
5973 | case R_ARM_PC24: | |
7359ea65 | 5974 | case R_ARM_PLT32: |
5b5bb741 PB |
5975 | case R_ARM_CALL: |
5976 | case R_ARM_JUMP24: | |
eb043451 | 5977 | case R_ARM_PREL31: |
c19d1205 | 5978 | case R_ARM_THM_CALL: |
b6895b4f PB |
5979 | case R_ARM_MOVW_ABS_NC: |
5980 | case R_ARM_MOVT_ABS: | |
5981 | case R_ARM_MOVW_PREL_NC: | |
5982 | case R_ARM_MOVT_PREL: | |
5983 | case R_ARM_THM_MOVW_ABS_NC: | |
5984 | case R_ARM_THM_MOVT_ABS: | |
5985 | case R_ARM_THM_MOVW_PREL_NC: | |
5986 | case R_ARM_THM_MOVT_PREL: | |
b7693d02 | 5987 | /* Should the interworking branches be listed here? */ |
7359ea65 | 5988 | if (h != NULL) |
5e681ec4 PB |
5989 | { |
5990 | /* If this reloc is in a read-only section, we might | |
5991 | need a copy reloc. We can't check reliably at this | |
5992 | stage whether the section is read-only, as input | |
5993 | sections have not yet been mapped to output sections. | |
5994 | Tentatively set the flag for now, and correct in | |
5995 | adjust_dynamic_symbol. */ | |
7359ea65 | 5996 | if (!info->shared) |
f5385ebf | 5997 | h->non_got_ref = 1; |
7359ea65 | 5998 | |
5e681ec4 | 5999 | /* We may need a .plt entry if the function this reloc |
c84cd8ee DJ |
6000 | refers to is in a different object. We can't tell for |
6001 | sure yet, because something later might force the | |
6002 | symbol local. */ | |
b6895b4f | 6003 | if (r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
f5385ebf | 6004 | h->needs_plt = 1; |
4f199be3 DJ |
6005 | |
6006 | /* If we create a PLT entry, this relocation will reference | |
6007 | it, even if it's an ABS32 relocation. */ | |
6008 | h->plt.refcount += 1; | |
b7693d02 | 6009 | |
c19d1205 | 6010 | if (r_type == R_ARM_THM_CALL) |
b7693d02 | 6011 | eh->plt_thumb_refcount += 1; |
5e681ec4 PB |
6012 | } |
6013 | ||
67687978 PB |
6014 | /* If we are creating a shared library or relocatable executable, |
6015 | and this is a reloc against a global symbol, or a non PC | |
6016 | relative reloc against a local symbol, then we need to copy | |
6017 | the reloc into the shared library. However, if we are linking | |
6018 | with -Bsymbolic, we do not need to copy a reloc against a | |
252b5132 RH |
6019 | global symbol which is defined in an object we are |
6020 | including in the link (i.e., DEF_REGULAR is set). At | |
6021 | this point we have not seen all the input files, so it is | |
6022 | possible that DEF_REGULAR is not set now but will be set | |
6023 | later (it is never cleared). We account for that | |
6024 | possibility below by storing information in the | |
5e681ec4 | 6025 | relocs_copied field of the hash table entry. */ |
67687978 | 6026 | if ((info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 6027 | && (sec->flags & SEC_ALLOC) != 0 |
71a976dd DJ |
6028 | && (r_type == R_ARM_ABS32 |
6029 | || (h != NULL && ! h->needs_plt | |
6030 | && (! info->symbolic || ! h->def_regular)))) | |
252b5132 | 6031 | { |
5e681ec4 PB |
6032 | struct elf32_arm_relocs_copied *p, **head; |
6033 | ||
252b5132 RH |
6034 | /* When creating a shared object, we must copy these |
6035 | reloc types into the output file. We create a reloc | |
6036 | section in dynobj and make room for this reloc. */ | |
6037 | if (sreloc == NULL) | |
6038 | { | |
6039 | const char * name; | |
6040 | ||
6041 | name = (bfd_elf_string_from_elf_section | |
6042 | (abfd, | |
6043 | elf_elfheader (abfd)->e_shstrndx, | |
6044 | elf_section_data (sec)->rel_hdr.sh_name)); | |
6045 | if (name == NULL) | |
b34976b6 | 6046 | return FALSE; |
252b5132 | 6047 | |
00a97672 | 6048 | BFD_ASSERT (reloc_section_p (htab, name, sec)); |
252b5132 RH |
6049 | |
6050 | sreloc = bfd_get_section_by_name (dynobj, name); | |
6051 | if (sreloc == NULL) | |
6052 | { | |
6053 | flagword flags; | |
6054 | ||
252b5132 RH |
6055 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
6056 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
e5a52504 MM |
6057 | if ((sec->flags & SEC_ALLOC) != 0 |
6058 | /* BPABI objects never have dynamic | |
6059 | relocations mapped. */ | |
6060 | && !htab->symbian_p) | |
252b5132 | 6061 | flags |= SEC_ALLOC | SEC_LOAD; |
3496cb2a L |
6062 | sreloc = bfd_make_section_with_flags (dynobj, |
6063 | name, | |
6064 | flags); | |
252b5132 | 6065 | if (sreloc == NULL |
252b5132 | 6066 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
b34976b6 | 6067 | return FALSE; |
252b5132 | 6068 | } |
5e681ec4 PB |
6069 | |
6070 | elf_section_data (sec)->sreloc = sreloc; | |
252b5132 RH |
6071 | } |
6072 | ||
5e681ec4 PB |
6073 | /* If this is a global symbol, we count the number of |
6074 | relocations we need for this symbol. */ | |
6075 | if (h != NULL) | |
252b5132 | 6076 | { |
5e681ec4 PB |
6077 | head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; |
6078 | } | |
6079 | else | |
6080 | { | |
6081 | /* Track dynamic relocs needed for local syms too. | |
6082 | We really need local syms available to do this | |
6083 | easily. Oh well. */ | |
57e8b36a | 6084 | |
5e681ec4 | 6085 | asection *s; |
6edfbbad DJ |
6086 | void *vpp; |
6087 | ||
5e681ec4 PB |
6088 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
6089 | sec, r_symndx); | |
6090 | if (s == NULL) | |
6091 | return FALSE; | |
57e8b36a | 6092 | |
6edfbbad DJ |
6093 | vpp = &elf_section_data (s)->local_dynrel; |
6094 | head = (struct elf32_arm_relocs_copied **) vpp; | |
5e681ec4 | 6095 | } |
57e8b36a | 6096 | |
5e681ec4 PB |
6097 | p = *head; |
6098 | if (p == NULL || p->section != sec) | |
6099 | { | |
6100 | bfd_size_type amt = sizeof *p; | |
57e8b36a | 6101 | |
5e681ec4 | 6102 | p = bfd_alloc (htab->root.dynobj, amt); |
252b5132 | 6103 | if (p == NULL) |
5e681ec4 PB |
6104 | return FALSE; |
6105 | p->next = *head; | |
6106 | *head = p; | |
6107 | p->section = sec; | |
6108 | p->count = 0; | |
ba93b8ac | 6109 | p->pc_count = 0; |
252b5132 | 6110 | } |
57e8b36a | 6111 | |
ba93b8ac DJ |
6112 | if (r_type == R_ARM_REL32) |
6113 | p->pc_count += 1; | |
71a976dd | 6114 | p->count += 1; |
252b5132 RH |
6115 | } |
6116 | break; | |
6117 | ||
6118 | /* This relocation describes the C++ object vtable hierarchy. | |
6119 | Reconstruct it for later use during GC. */ | |
6120 | case R_ARM_GNU_VTINHERIT: | |
c152c796 | 6121 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 6122 | return FALSE; |
252b5132 | 6123 | break; |
9a5aca8c | 6124 | |
252b5132 RH |
6125 | /* This relocation describes which C++ vtable entries are actually |
6126 | used. Record for later use during GC. */ | |
6127 | case R_ARM_GNU_VTENTRY: | |
c152c796 | 6128 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
b34976b6 | 6129 | return FALSE; |
252b5132 RH |
6130 | break; |
6131 | } | |
6132 | } | |
f21f3fe0 | 6133 | |
b34976b6 | 6134 | return TRUE; |
252b5132 RH |
6135 | } |
6136 | ||
3c9458e9 NC |
6137 | /* Treat mapping symbols as special target symbols. */ |
6138 | ||
6139 | static bfd_boolean | |
6140 | elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym) | |
6141 | { | |
b0796911 PB |
6142 | return bfd_is_arm_special_symbol_name (sym->name, |
6143 | BFD_ARM_SPECIAL_SYM_TYPE_ANY); | |
3c9458e9 NC |
6144 | } |
6145 | ||
0367ecfb NC |
6146 | /* This is a copy of elf_find_function() from elf.c except that |
6147 | ARM mapping symbols are ignored when looking for function names | |
6148 | and STT_ARM_TFUNC is considered to a function type. */ | |
252b5132 | 6149 | |
0367ecfb NC |
6150 | static bfd_boolean |
6151 | arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, | |
6152 | asection * section, | |
6153 | asymbol ** symbols, | |
6154 | bfd_vma offset, | |
6155 | const char ** filename_ptr, | |
6156 | const char ** functionname_ptr) | |
6157 | { | |
6158 | const char * filename = NULL; | |
6159 | asymbol * func = NULL; | |
6160 | bfd_vma low_func = 0; | |
6161 | asymbol ** p; | |
252b5132 RH |
6162 | |
6163 | for (p = symbols; *p != NULL; p++) | |
6164 | { | |
6165 | elf_symbol_type *q; | |
6166 | ||
6167 | q = (elf_symbol_type *) *p; | |
6168 | ||
252b5132 RH |
6169 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) |
6170 | { | |
6171 | default: | |
6172 | break; | |
6173 | case STT_FILE: | |
6174 | filename = bfd_asymbol_name (&q->symbol); | |
6175 | break; | |
252b5132 RH |
6176 | case STT_FUNC: |
6177 | case STT_ARM_TFUNC: | |
9d2da7ca | 6178 | case STT_NOTYPE: |
b0796911 | 6179 | /* Skip mapping symbols. */ |
0367ecfb | 6180 | if ((q->symbol.flags & BSF_LOCAL) |
b0796911 PB |
6181 | && bfd_is_arm_special_symbol_name (q->symbol.name, |
6182 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
0367ecfb NC |
6183 | continue; |
6184 | /* Fall through. */ | |
6b40fcba | 6185 | if (bfd_get_section (&q->symbol) == section |
252b5132 RH |
6186 | && q->symbol.value >= low_func |
6187 | && q->symbol.value <= offset) | |
6188 | { | |
6189 | func = (asymbol *) q; | |
6190 | low_func = q->symbol.value; | |
6191 | } | |
6192 | break; | |
6193 | } | |
6194 | } | |
6195 | ||
6196 | if (func == NULL) | |
b34976b6 | 6197 | return FALSE; |
252b5132 | 6198 | |
0367ecfb NC |
6199 | if (filename_ptr) |
6200 | *filename_ptr = filename; | |
6201 | if (functionname_ptr) | |
6202 | *functionname_ptr = bfd_asymbol_name (func); | |
6203 | ||
6204 | return TRUE; | |
6205 | } | |
6206 | ||
6207 | ||
6208 | /* Find the nearest line to a particular section and offset, for error | |
6209 | reporting. This code is a duplicate of the code in elf.c, except | |
6210 | that it uses arm_elf_find_function. */ | |
6211 | ||
6212 | static bfd_boolean | |
6213 | elf32_arm_find_nearest_line (bfd * abfd, | |
6214 | asection * section, | |
6215 | asymbol ** symbols, | |
6216 | bfd_vma offset, | |
6217 | const char ** filename_ptr, | |
6218 | const char ** functionname_ptr, | |
6219 | unsigned int * line_ptr) | |
6220 | { | |
6221 | bfd_boolean found = FALSE; | |
6222 | ||
6223 | /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ | |
6224 | ||
6225 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, | |
6226 | filename_ptr, functionname_ptr, | |
6227 | line_ptr, 0, | |
6228 | & elf_tdata (abfd)->dwarf2_find_line_info)) | |
6229 | { | |
6230 | if (!*functionname_ptr) | |
6231 | arm_elf_find_function (abfd, section, symbols, offset, | |
6232 | *filename_ptr ? NULL : filename_ptr, | |
6233 | functionname_ptr); | |
f21f3fe0 | 6234 | |
0367ecfb NC |
6235 | return TRUE; |
6236 | } | |
6237 | ||
6238 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, | |
6239 | & found, filename_ptr, | |
6240 | functionname_ptr, line_ptr, | |
6241 | & elf_tdata (abfd)->line_info)) | |
6242 | return FALSE; | |
6243 | ||
6244 | if (found && (*functionname_ptr || *line_ptr)) | |
6245 | return TRUE; | |
6246 | ||
6247 | if (symbols == NULL) | |
6248 | return FALSE; | |
6249 | ||
6250 | if (! arm_elf_find_function (abfd, section, symbols, offset, | |
6251 | filename_ptr, functionname_ptr)) | |
6252 | return FALSE; | |
6253 | ||
6254 | *line_ptr = 0; | |
b34976b6 | 6255 | return TRUE; |
252b5132 RH |
6256 | } |
6257 | ||
4ab527b0 FF |
6258 | static bfd_boolean |
6259 | elf32_arm_find_inliner_info (bfd * abfd, | |
6260 | const char ** filename_ptr, | |
6261 | const char ** functionname_ptr, | |
6262 | unsigned int * line_ptr) | |
6263 | { | |
6264 | bfd_boolean found; | |
6265 | found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr, | |
6266 | functionname_ptr, line_ptr, | |
6267 | & elf_tdata (abfd)->dwarf2_find_line_info); | |
6268 | return found; | |
6269 | } | |
6270 | ||
252b5132 RH |
6271 | /* Adjust a symbol defined by a dynamic object and referenced by a |
6272 | regular object. The current definition is in some section of the | |
6273 | dynamic object, but we're not including those sections. We have to | |
6274 | change the definition to something the rest of the link can | |
6275 | understand. */ | |
6276 | ||
b34976b6 | 6277 | static bfd_boolean |
57e8b36a NC |
6278 | elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, |
6279 | struct elf_link_hash_entry * h) | |
252b5132 RH |
6280 | { |
6281 | bfd * dynobj; | |
6282 | asection * s; | |
6283 | unsigned int power_of_two; | |
b7693d02 | 6284 | struct elf32_arm_link_hash_entry * eh; |
67687978 | 6285 | struct elf32_arm_link_hash_table *globals; |
252b5132 | 6286 | |
67687978 | 6287 | globals = elf32_arm_hash_table (info); |
252b5132 RH |
6288 | dynobj = elf_hash_table (info)->dynobj; |
6289 | ||
6290 | /* Make sure we know what is going on here. */ | |
6291 | BFD_ASSERT (dynobj != NULL | |
f5385ebf | 6292 | && (h->needs_plt |
f6e332e6 | 6293 | || h->u.weakdef != NULL |
f5385ebf AM |
6294 | || (h->def_dynamic |
6295 | && h->ref_regular | |
6296 | && !h->def_regular))); | |
252b5132 | 6297 | |
b7693d02 DJ |
6298 | eh = (struct elf32_arm_link_hash_entry *) h; |
6299 | ||
252b5132 RH |
6300 | /* If this is a function, put it in the procedure linkage table. We |
6301 | will fill in the contents of the procedure linkage table later, | |
6302 | when we know the address of the .got section. */ | |
b7693d02 | 6303 | if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC |
f5385ebf | 6304 | || h->needs_plt) |
252b5132 | 6305 | { |
5e681ec4 PB |
6306 | if (h->plt.refcount <= 0 |
6307 | || SYMBOL_CALLS_LOCAL (info, h) | |
6308 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
6309 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
6310 | { |
6311 | /* This case can occur if we saw a PLT32 reloc in an input | |
5e681ec4 PB |
6312 | file, but the symbol was never referred to by a dynamic |
6313 | object, or if all references were garbage collected. In | |
6314 | such a case, we don't actually need to build a procedure | |
6315 | linkage table, and we can just do a PC24 reloc instead. */ | |
6316 | h->plt.offset = (bfd_vma) -1; | |
b7693d02 | 6317 | eh->plt_thumb_refcount = 0; |
f5385ebf | 6318 | h->needs_plt = 0; |
252b5132 RH |
6319 | } |
6320 | ||
b34976b6 | 6321 | return TRUE; |
252b5132 | 6322 | } |
5e681ec4 | 6323 | else |
b7693d02 DJ |
6324 | { |
6325 | /* It's possible that we incorrectly decided a .plt reloc was | |
6326 | needed for an R_ARM_PC24 or similar reloc to a non-function sym | |
6327 | in check_relocs. We can't decide accurately between function | |
6328 | and non-function syms in check-relocs; Objects loaded later in | |
6329 | the link may change h->type. So fix it now. */ | |
6330 | h->plt.offset = (bfd_vma) -1; | |
6331 | eh->plt_thumb_refcount = 0; | |
6332 | } | |
252b5132 RH |
6333 | |
6334 | /* If this is a weak symbol, and there is a real definition, the | |
6335 | processor independent code will have arranged for us to see the | |
6336 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 6337 | if (h->u.weakdef != NULL) |
252b5132 | 6338 | { |
f6e332e6 AM |
6339 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
6340 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
6341 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
6342 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
b34976b6 | 6343 | return TRUE; |
252b5132 RH |
6344 | } |
6345 | ||
ba93b8ac DJ |
6346 | /* If there are no non-GOT references, we do not need a copy |
6347 | relocation. */ | |
6348 | if (!h->non_got_ref) | |
6349 | return TRUE; | |
6350 | ||
252b5132 RH |
6351 | /* This is a reference to a symbol defined by a dynamic object which |
6352 | is not a function. */ | |
6353 | ||
6354 | /* If we are creating a shared library, we must presume that the | |
6355 | only references to the symbol are via the global offset table. | |
6356 | For such cases we need not do anything here; the relocations will | |
67687978 PB |
6357 | be handled correctly by relocate_section. Relocatable executables |
6358 | can reference data in shared objects directly, so we don't need to | |
6359 | do anything here. */ | |
6360 | if (info->shared || globals->root.is_relocatable_executable) | |
b34976b6 | 6361 | return TRUE; |
252b5132 | 6362 | |
909272ee AM |
6363 | if (h->size == 0) |
6364 | { | |
6365 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
6366 | h->root.root.string); | |
6367 | return TRUE; | |
6368 | } | |
6369 | ||
252b5132 RH |
6370 | /* We must allocate the symbol in our .dynbss section, which will |
6371 | become part of the .bss section of the executable. There will be | |
6372 | an entry for this symbol in the .dynsym section. The dynamic | |
6373 | object will contain position independent code, so all references | |
6374 | from the dynamic object to this symbol will go through the global | |
6375 | offset table. The dynamic linker will use the .dynsym entry to | |
6376 | determine the address it must put in the global offset table, so | |
6377 | both the dynamic object and the regular object will refer to the | |
6378 | same memory location for the variable. */ | |
252b5132 RH |
6379 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
6380 | BFD_ASSERT (s != NULL); | |
6381 | ||
6382 | /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to | |
6383 | copy the initial value out of the dynamic object and into the | |
6384 | runtime process image. We need to remember the offset into the | |
00a97672 | 6385 | .rel(a).bss section we are going to use. */ |
252b5132 RH |
6386 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
6387 | { | |
6388 | asection *srel; | |
6389 | ||
00a97672 | 6390 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss")); |
252b5132 | 6391 | BFD_ASSERT (srel != NULL); |
00a97672 | 6392 | srel->size += RELOC_SIZE (globals); |
f5385ebf | 6393 | h->needs_copy = 1; |
252b5132 RH |
6394 | } |
6395 | ||
6396 | /* We need to figure out the alignment required for this symbol. I | |
6397 | have no idea how ELF linkers handle this. */ | |
6398 | power_of_two = bfd_log2 (h->size); | |
6399 | if (power_of_two > 3) | |
6400 | power_of_two = 3; | |
6401 | ||
6402 | /* Apply the required alignment. */ | |
eea6121a | 6403 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
252b5132 RH |
6404 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
6405 | { | |
6406 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 6407 | return FALSE; |
252b5132 RH |
6408 | } |
6409 | ||
6410 | /* Define the symbol as being at this point in the section. */ | |
6411 | h->root.u.def.section = s; | |
eea6121a | 6412 | h->root.u.def.value = s->size; |
252b5132 RH |
6413 | |
6414 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 6415 | s->size += h->size; |
252b5132 | 6416 | |
b34976b6 | 6417 | return TRUE; |
252b5132 RH |
6418 | } |
6419 | ||
5e681ec4 PB |
6420 | /* Allocate space in .plt, .got and associated reloc sections for |
6421 | dynamic relocs. */ | |
6422 | ||
6423 | static bfd_boolean | |
57e8b36a | 6424 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
5e681ec4 PB |
6425 | { |
6426 | struct bfd_link_info *info; | |
6427 | struct elf32_arm_link_hash_table *htab; | |
6428 | struct elf32_arm_link_hash_entry *eh; | |
6429 | struct elf32_arm_relocs_copied *p; | |
6430 | ||
b7693d02 DJ |
6431 | eh = (struct elf32_arm_link_hash_entry *) h; |
6432 | ||
5e681ec4 PB |
6433 | if (h->root.type == bfd_link_hash_indirect) |
6434 | return TRUE; | |
6435 | ||
6436 | if (h->root.type == bfd_link_hash_warning) | |
6437 | /* When warning symbols are created, they **replace** the "real" | |
6438 | entry in the hash table, thus we never get to see the real | |
6439 | symbol in a hash traversal. So look at it now. */ | |
6440 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6441 | ||
6442 | info = (struct bfd_link_info *) inf; | |
6443 | htab = elf32_arm_hash_table (info); | |
6444 | ||
6445 | if (htab->root.dynamic_sections_created | |
6446 | && h->plt.refcount > 0) | |
6447 | { | |
6448 | /* Make sure this symbol is output as a dynamic symbol. | |
6449 | Undefined weak syms won't yet be marked as dynamic. */ | |
6450 | if (h->dynindx == -1 | |
f5385ebf | 6451 | && !h->forced_local) |
5e681ec4 | 6452 | { |
c152c796 | 6453 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
6454 | return FALSE; |
6455 | } | |
6456 | ||
6457 | if (info->shared | |
7359ea65 | 6458 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
5e681ec4 PB |
6459 | { |
6460 | asection *s = htab->splt; | |
6461 | ||
6462 | /* If this is the first .plt entry, make room for the special | |
6463 | first entry. */ | |
eea6121a | 6464 | if (s->size == 0) |
e5a52504 | 6465 | s->size += htab->plt_header_size; |
5e681ec4 | 6466 | |
eea6121a | 6467 | h->plt.offset = s->size; |
5e681ec4 | 6468 | |
b7693d02 DJ |
6469 | /* If we will insert a Thumb trampoline before this PLT, leave room |
6470 | for it. */ | |
33bfe774 | 6471 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) |
b7693d02 DJ |
6472 | { |
6473 | h->plt.offset += PLT_THUMB_STUB_SIZE; | |
6474 | s->size += PLT_THUMB_STUB_SIZE; | |
6475 | } | |
6476 | ||
5e681ec4 PB |
6477 | /* If this symbol is not defined in a regular file, and we are |
6478 | not generating a shared library, then set the symbol to this | |
6479 | location in the .plt. This is required to make function | |
6480 | pointers compare as equal between the normal executable and | |
6481 | the shared library. */ | |
6482 | if (! info->shared | |
f5385ebf | 6483 | && !h->def_regular) |
5e681ec4 PB |
6484 | { |
6485 | h->root.u.def.section = s; | |
6486 | h->root.u.def.value = h->plt.offset; | |
b7693d02 DJ |
6487 | |
6488 | /* Make sure the function is not marked as Thumb, in case | |
6489 | it is the target of an ABS32 relocation, which will | |
6490 | point to the PLT entry. */ | |
6491 | if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) | |
6492 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); | |
5e681ec4 PB |
6493 | } |
6494 | ||
6495 | /* Make room for this entry. */ | |
e5a52504 | 6496 | s->size += htab->plt_entry_size; |
5e681ec4 | 6497 | |
e5a52504 | 6498 | if (!htab->symbian_p) |
b7693d02 DJ |
6499 | { |
6500 | /* We also need to make an entry in the .got.plt section, which | |
6501 | will be placed in the .got section by the linker script. */ | |
6502 | eh->plt_got_offset = htab->sgotplt->size; | |
6503 | htab->sgotplt->size += 4; | |
6504 | } | |
5e681ec4 | 6505 | |
00a97672 RS |
6506 | /* We also need to make an entry in the .rel(a).plt section. */ |
6507 | htab->srelplt->size += RELOC_SIZE (htab); | |
6508 | ||
6509 | /* VxWorks executables have a second set of relocations for | |
6510 | each PLT entry. They go in a separate relocation section, | |
6511 | which is processed by the kernel loader. */ | |
6512 | if (htab->vxworks_p && !info->shared) | |
6513 | { | |
6514 | /* There is a relocation for the initial PLT entry: | |
6515 | an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */ | |
6516 | if (h->plt.offset == htab->plt_header_size) | |
6517 | htab->srelplt2->size += RELOC_SIZE (htab); | |
6518 | ||
6519 | /* There are two extra relocations for each subsequent | |
6520 | PLT entry: an R_ARM_32 relocation for the GOT entry, | |
6521 | and an R_ARM_32 relocation for the PLT entry. */ | |
6522 | htab->srelplt2->size += RELOC_SIZE (htab) * 2; | |
6523 | } | |
5e681ec4 PB |
6524 | } |
6525 | else | |
6526 | { | |
6527 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 6528 | h->needs_plt = 0; |
5e681ec4 PB |
6529 | } |
6530 | } | |
6531 | else | |
6532 | { | |
6533 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 6534 | h->needs_plt = 0; |
5e681ec4 PB |
6535 | } |
6536 | ||
6537 | if (h->got.refcount > 0) | |
6538 | { | |
6539 | asection *s; | |
6540 | bfd_boolean dyn; | |
ba93b8ac DJ |
6541 | int tls_type = elf32_arm_hash_entry (h)->tls_type; |
6542 | int indx; | |
5e681ec4 PB |
6543 | |
6544 | /* Make sure this symbol is output as a dynamic symbol. | |
6545 | Undefined weak syms won't yet be marked as dynamic. */ | |
6546 | if (h->dynindx == -1 | |
f5385ebf | 6547 | && !h->forced_local) |
5e681ec4 | 6548 | { |
c152c796 | 6549 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
6550 | return FALSE; |
6551 | } | |
6552 | ||
e5a52504 MM |
6553 | if (!htab->symbian_p) |
6554 | { | |
6555 | s = htab->sgot; | |
6556 | h->got.offset = s->size; | |
ba93b8ac DJ |
6557 | |
6558 | if (tls_type == GOT_UNKNOWN) | |
6559 | abort (); | |
6560 | ||
6561 | if (tls_type == GOT_NORMAL) | |
6562 | /* Non-TLS symbols need one GOT slot. */ | |
6563 | s->size += 4; | |
6564 | else | |
6565 | { | |
6566 | if (tls_type & GOT_TLS_GD) | |
6567 | /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */ | |
6568 | s->size += 8; | |
6569 | if (tls_type & GOT_TLS_IE) | |
6570 | /* R_ARM_TLS_IE32 needs one GOT slot. */ | |
6571 | s->size += 4; | |
6572 | } | |
6573 | ||
e5a52504 | 6574 | dyn = htab->root.dynamic_sections_created; |
ba93b8ac DJ |
6575 | |
6576 | indx = 0; | |
6577 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
6578 | && (!info->shared | |
6579 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
6580 | indx = h->dynindx; | |
6581 | ||
6582 | if (tls_type != GOT_NORMAL | |
6583 | && (info->shared || indx != 0) | |
6584 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
6585 | || h->root.type != bfd_link_hash_undefweak)) | |
6586 | { | |
6587 | if (tls_type & GOT_TLS_IE) | |
00a97672 | 6588 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
6589 | |
6590 | if (tls_type & GOT_TLS_GD) | |
00a97672 | 6591 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
6592 | |
6593 | if ((tls_type & GOT_TLS_GD) && indx != 0) | |
00a97672 | 6594 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
6595 | } |
6596 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
6597 | || h->root.type != bfd_link_hash_undefweak) | |
6598 | && (info->shared | |
6599 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
00a97672 | 6600 | htab->srelgot->size += RELOC_SIZE (htab); |
e5a52504 | 6601 | } |
5e681ec4 PB |
6602 | } |
6603 | else | |
6604 | h->got.offset = (bfd_vma) -1; | |
6605 | ||
5e681ec4 PB |
6606 | if (eh->relocs_copied == NULL) |
6607 | return TRUE; | |
6608 | ||
6609 | /* In the shared -Bsymbolic case, discard space allocated for | |
6610 | dynamic pc-relative relocs against symbols which turn out to be | |
6611 | defined in regular objects. For the normal shared case, discard | |
6612 | space for pc-relative relocs that have become local due to symbol | |
6613 | visibility changes. */ | |
6614 | ||
67687978 | 6615 | if (info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 6616 | { |
ba93b8ac DJ |
6617 | /* The only reloc that uses pc_count is R_ARM_REL32, which will |
6618 | appear on something like ".long foo - .". We want calls to | |
6619 | protected symbols to resolve directly to the function rather | |
6620 | than going via the plt. If people want function pointer | |
6621 | comparisons to work as expected then they should avoid | |
6622 | writing assembly like ".long foo - .". */ | |
6623 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
6624 | { | |
6625 | struct elf32_arm_relocs_copied **pp; | |
6626 | ||
6627 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; ) | |
6628 | { | |
6629 | p->count -= p->pc_count; | |
6630 | p->pc_count = 0; | |
6631 | if (p->count == 0) | |
6632 | *pp = p->next; | |
6633 | else | |
6634 | pp = &p->next; | |
6635 | } | |
6636 | } | |
6637 | ||
6638 | /* Also discard relocs on undefined weak syms with non-default | |
7359ea65 | 6639 | visibility. */ |
22d606e9 | 6640 | if (eh->relocs_copied != NULL |
5e681ec4 | 6641 | && h->root.type == bfd_link_hash_undefweak) |
22d606e9 AM |
6642 | { |
6643 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
6644 | eh->relocs_copied = NULL; | |
6645 | ||
6646 | /* Make sure undefined weak symbols are output as a dynamic | |
6647 | symbol in PIEs. */ | |
6648 | else if (h->dynindx == -1 | |
6649 | && !h->forced_local) | |
6650 | { | |
6651 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
6652 | return FALSE; | |
6653 | } | |
6654 | } | |
6655 | ||
67687978 PB |
6656 | else if (htab->root.is_relocatable_executable && h->dynindx == -1 |
6657 | && h->root.type == bfd_link_hash_new) | |
6658 | { | |
6659 | /* Output absolute symbols so that we can create relocations | |
6660 | against them. For normal symbols we output a relocation | |
6661 | against the section that contains them. */ | |
6662 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
6663 | return FALSE; | |
6664 | } | |
6665 | ||
5e681ec4 PB |
6666 | } |
6667 | else | |
6668 | { | |
6669 | /* For the non-shared case, discard space for relocs against | |
6670 | symbols which turn out to need copy relocs or are not | |
6671 | dynamic. */ | |
6672 | ||
f5385ebf AM |
6673 | if (!h->non_got_ref |
6674 | && ((h->def_dynamic | |
6675 | && !h->def_regular) | |
5e681ec4 PB |
6676 | || (htab->root.dynamic_sections_created |
6677 | && (h->root.type == bfd_link_hash_undefweak | |
6678 | || h->root.type == bfd_link_hash_undefined)))) | |
6679 | { | |
6680 | /* Make sure this symbol is output as a dynamic symbol. | |
6681 | Undefined weak syms won't yet be marked as dynamic. */ | |
6682 | if (h->dynindx == -1 | |
f5385ebf | 6683 | && !h->forced_local) |
5e681ec4 | 6684 | { |
c152c796 | 6685 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
6686 | return FALSE; |
6687 | } | |
6688 | ||
6689 | /* If that succeeded, we know we'll be keeping all the | |
6690 | relocs. */ | |
6691 | if (h->dynindx != -1) | |
6692 | goto keep; | |
6693 | } | |
6694 | ||
6695 | eh->relocs_copied = NULL; | |
6696 | ||
6697 | keep: ; | |
6698 | } | |
6699 | ||
6700 | /* Finally, allocate space. */ | |
6701 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
6702 | { | |
6703 | asection *sreloc = elf_section_data (p->section)->sreloc; | |
00a97672 | 6704 | sreloc->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
6705 | } |
6706 | ||
6707 | return TRUE; | |
6708 | } | |
6709 | ||
08d1f311 DJ |
6710 | /* Find any dynamic relocs that apply to read-only sections. */ |
6711 | ||
6712 | static bfd_boolean | |
6713 | elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf) | |
6714 | { | |
6715 | struct elf32_arm_link_hash_entry *eh; | |
6716 | struct elf32_arm_relocs_copied *p; | |
6717 | ||
6718 | if (h->root.type == bfd_link_hash_warning) | |
6719 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6720 | ||
6721 | eh = (struct elf32_arm_link_hash_entry *) h; | |
6722 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
6723 | { | |
6724 | asection *s = p->section; | |
6725 | ||
6726 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
6727 | { | |
6728 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
6729 | ||
6730 | info->flags |= DF_TEXTREL; | |
6731 | ||
6732 | /* Not an error, just cut short the traversal. */ | |
6733 | return FALSE; | |
6734 | } | |
6735 | } | |
6736 | return TRUE; | |
6737 | } | |
6738 | ||
252b5132 RH |
6739 | /* Set the sizes of the dynamic sections. */ |
6740 | ||
b34976b6 | 6741 | static bfd_boolean |
57e8b36a NC |
6742 | elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, |
6743 | struct bfd_link_info * info) | |
252b5132 RH |
6744 | { |
6745 | bfd * dynobj; | |
6746 | asection * s; | |
b34976b6 AM |
6747 | bfd_boolean plt; |
6748 | bfd_boolean relocs; | |
5e681ec4 PB |
6749 | bfd *ibfd; |
6750 | struct elf32_arm_link_hash_table *htab; | |
252b5132 | 6751 | |
5e681ec4 | 6752 | htab = elf32_arm_hash_table (info); |
252b5132 RH |
6753 | dynobj = elf_hash_table (info)->dynobj; |
6754 | BFD_ASSERT (dynobj != NULL); | |
39b41c9c | 6755 | check_use_blx (htab); |
252b5132 RH |
6756 | |
6757 | if (elf_hash_table (info)->dynamic_sections_created) | |
6758 | { | |
6759 | /* Set the contents of the .interp section to the interpreter. */ | |
893c4fe2 | 6760 | if (info->executable) |
252b5132 RH |
6761 | { |
6762 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
6763 | BFD_ASSERT (s != NULL); | |
eea6121a | 6764 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
252b5132 RH |
6765 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
6766 | } | |
6767 | } | |
5e681ec4 PB |
6768 | |
6769 | /* Set up .got offsets for local syms, and space for local dynamic | |
6770 | relocs. */ | |
6771 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
252b5132 | 6772 | { |
5e681ec4 PB |
6773 | bfd_signed_vma *local_got; |
6774 | bfd_signed_vma *end_local_got; | |
6775 | char *local_tls_type; | |
6776 | bfd_size_type locsymcount; | |
6777 | Elf_Internal_Shdr *symtab_hdr; | |
6778 | asection *srel; | |
6779 | ||
6780 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
6781 | continue; | |
6782 | ||
6783 | for (s = ibfd->sections; s != NULL; s = s->next) | |
6784 | { | |
6785 | struct elf32_arm_relocs_copied *p; | |
6786 | ||
6edfbbad | 6787 | for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) |
5e681ec4 PB |
6788 | { |
6789 | if (!bfd_is_abs_section (p->section) | |
6790 | && bfd_is_abs_section (p->section->output_section)) | |
6791 | { | |
6792 | /* Input section has been discarded, either because | |
6793 | it is a copy of a linkonce section or due to | |
6794 | linker script /DISCARD/, so we'll be discarding | |
6795 | the relocs too. */ | |
6796 | } | |
6797 | else if (p->count != 0) | |
6798 | { | |
6799 | srel = elf_section_data (p->section)->sreloc; | |
00a97672 | 6800 | srel->size += p->count * RELOC_SIZE (htab); |
5e681ec4 PB |
6801 | if ((p->section->output_section->flags & SEC_READONLY) != 0) |
6802 | info->flags |= DF_TEXTREL; | |
6803 | } | |
6804 | } | |
6805 | } | |
6806 | ||
6807 | local_got = elf_local_got_refcounts (ibfd); | |
6808 | if (!local_got) | |
6809 | continue; | |
6810 | ||
6811 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
6812 | locsymcount = symtab_hdr->sh_info; | |
6813 | end_local_got = local_got + locsymcount; | |
ba93b8ac | 6814 | local_tls_type = elf32_arm_local_got_tls_type (ibfd); |
5e681ec4 PB |
6815 | s = htab->sgot; |
6816 | srel = htab->srelgot; | |
6817 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) | |
6818 | { | |
6819 | if (*local_got > 0) | |
6820 | { | |
eea6121a | 6821 | *local_got = s->size; |
ba93b8ac DJ |
6822 | if (*local_tls_type & GOT_TLS_GD) |
6823 | /* TLS_GD relocs need an 8-byte structure in the GOT. */ | |
6824 | s->size += 8; | |
6825 | if (*local_tls_type & GOT_TLS_IE) | |
6826 | s->size += 4; | |
6827 | if (*local_tls_type == GOT_NORMAL) | |
6828 | s->size += 4; | |
6829 | ||
6830 | if (info->shared || *local_tls_type == GOT_TLS_GD) | |
00a97672 | 6831 | srel->size += RELOC_SIZE (htab); |
5e681ec4 PB |
6832 | } |
6833 | else | |
6834 | *local_got = (bfd_vma) -1; | |
6835 | } | |
252b5132 RH |
6836 | } |
6837 | ||
ba93b8ac DJ |
6838 | if (htab->tls_ldm_got.refcount > 0) |
6839 | { | |
6840 | /* Allocate two GOT entries and one dynamic relocation (if necessary) | |
6841 | for R_ARM_TLS_LDM32 relocations. */ | |
6842 | htab->tls_ldm_got.offset = htab->sgot->size; | |
6843 | htab->sgot->size += 8; | |
6844 | if (info->shared) | |
00a97672 | 6845 | htab->srelgot->size += RELOC_SIZE (htab); |
ba93b8ac DJ |
6846 | } |
6847 | else | |
6848 | htab->tls_ldm_got.offset = -1; | |
6849 | ||
5e681ec4 PB |
6850 | /* Allocate global sym .plt and .got entries, and space for global |
6851 | sym dynamic relocs. */ | |
57e8b36a | 6852 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); |
252b5132 RH |
6853 | |
6854 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
6855 | determined the sizes of the various dynamic sections. Allocate | |
6856 | memory for them. */ | |
b34976b6 AM |
6857 | plt = FALSE; |
6858 | relocs = FALSE; | |
252b5132 RH |
6859 | for (s = dynobj->sections; s != NULL; s = s->next) |
6860 | { | |
6861 | const char * name; | |
252b5132 RH |
6862 | |
6863 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
6864 | continue; | |
6865 | ||
6866 | /* It's OK to base decisions on the section name, because none | |
6867 | of the dynobj section names depend upon the input files. */ | |
6868 | name = bfd_get_section_name (dynobj, s); | |
6869 | ||
24a1ba0f | 6870 | if (strcmp (name, ".plt") == 0) |
252b5132 | 6871 | { |
c456f082 AM |
6872 | /* Remember whether there is a PLT. */ |
6873 | plt = s->size != 0; | |
252b5132 RH |
6874 | } |
6875 | else if (strncmp (name, ".rel", 4) == 0) | |
6876 | { | |
c456f082 | 6877 | if (s->size != 0) |
252b5132 | 6878 | { |
252b5132 | 6879 | /* Remember whether there are any reloc sections other |
00a97672 RS |
6880 | than .rel(a).plt and .rela.plt.unloaded. */ |
6881 | if (s != htab->srelplt && s != htab->srelplt2) | |
b34976b6 | 6882 | relocs = TRUE; |
252b5132 RH |
6883 | |
6884 | /* We use the reloc_count field as a counter if we need | |
6885 | to copy relocs into the output file. */ | |
6886 | s->reloc_count = 0; | |
6887 | } | |
6888 | } | |
c456f082 AM |
6889 | else if (strncmp (name, ".got", 4) != 0 |
6890 | && strcmp (name, ".dynbss") != 0) | |
252b5132 RH |
6891 | { |
6892 | /* It's not one of our sections, so don't allocate space. */ | |
6893 | continue; | |
6894 | } | |
6895 | ||
c456f082 | 6896 | if (s->size == 0) |
252b5132 | 6897 | { |
c456f082 | 6898 | /* If we don't need this section, strip it from the |
00a97672 RS |
6899 | output file. This is mostly to handle .rel(a).bss and |
6900 | .rel(a).plt. We must create both sections in | |
c456f082 AM |
6901 | create_dynamic_sections, because they must be created |
6902 | before the linker maps input sections to output | |
6903 | sections. The linker does that before | |
6904 | adjust_dynamic_symbol is called, and it is that | |
6905 | function which decides whether anything needs to go | |
6906 | into these sections. */ | |
8423293d | 6907 | s->flags |= SEC_EXCLUDE; |
252b5132 RH |
6908 | continue; |
6909 | } | |
6910 | ||
c456f082 AM |
6911 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
6912 | continue; | |
6913 | ||
252b5132 | 6914 | /* Allocate memory for the section contents. */ |
eea6121a | 6915 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
c456f082 | 6916 | if (s->contents == NULL) |
b34976b6 | 6917 | return FALSE; |
252b5132 RH |
6918 | } |
6919 | ||
6920 | if (elf_hash_table (info)->dynamic_sections_created) | |
6921 | { | |
6922 | /* Add some entries to the .dynamic section. We fill in the | |
6923 | values later, in elf32_arm_finish_dynamic_sections, but we | |
6924 | must add the entries now so that we get the correct size for | |
6925 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
6926 | dynamic linker and used by the debugger. */ | |
dc810e39 | 6927 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 6928 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 6929 | |
8532796c | 6930 | if (info->executable) |
252b5132 | 6931 | { |
dc810e39 | 6932 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 6933 | return FALSE; |
252b5132 RH |
6934 | } |
6935 | ||
6936 | if (plt) | |
6937 | { | |
dc810e39 AM |
6938 | if ( !add_dynamic_entry (DT_PLTGOT, 0) |
6939 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
00a97672 RS |
6940 | || !add_dynamic_entry (DT_PLTREL, |
6941 | htab->use_rel ? DT_REL : DT_RELA) | |
dc810e39 | 6942 | || !add_dynamic_entry (DT_JMPREL, 0)) |
b34976b6 | 6943 | return FALSE; |
252b5132 RH |
6944 | } |
6945 | ||
6946 | if (relocs) | |
6947 | { | |
00a97672 RS |
6948 | if (htab->use_rel) |
6949 | { | |
6950 | if (!add_dynamic_entry (DT_REL, 0) | |
6951 | || !add_dynamic_entry (DT_RELSZ, 0) | |
6952 | || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab))) | |
6953 | return FALSE; | |
6954 | } | |
6955 | else | |
6956 | { | |
6957 | if (!add_dynamic_entry (DT_RELA, 0) | |
6958 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6959 | || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab))) | |
6960 | return FALSE; | |
6961 | } | |
252b5132 RH |
6962 | } |
6963 | ||
08d1f311 DJ |
6964 | /* If any dynamic relocs apply to a read-only section, |
6965 | then we need a DT_TEXTREL entry. */ | |
6966 | if ((info->flags & DF_TEXTREL) == 0) | |
6967 | elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, | |
6968 | (PTR) info); | |
6969 | ||
99e4ae17 | 6970 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 6971 | { |
dc810e39 | 6972 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 6973 | return FALSE; |
252b5132 RH |
6974 | } |
6975 | } | |
8532796c | 6976 | #undef add_dynamic_entry |
252b5132 | 6977 | |
b34976b6 | 6978 | return TRUE; |
252b5132 RH |
6979 | } |
6980 | ||
252b5132 RH |
6981 | /* Finish up dynamic symbol handling. We set the contents of various |
6982 | dynamic sections here. */ | |
6983 | ||
b34976b6 | 6984 | static bfd_boolean |
57e8b36a NC |
6985 | elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, |
6986 | struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) | |
252b5132 RH |
6987 | { |
6988 | bfd * dynobj; | |
e5a52504 | 6989 | struct elf32_arm_link_hash_table *htab; |
b7693d02 | 6990 | struct elf32_arm_link_hash_entry *eh; |
252b5132 RH |
6991 | |
6992 | dynobj = elf_hash_table (info)->dynobj; | |
e5a52504 | 6993 | htab = elf32_arm_hash_table (info); |
b7693d02 | 6994 | eh = (struct elf32_arm_link_hash_entry *) h; |
252b5132 RH |
6995 | |
6996 | if (h->plt.offset != (bfd_vma) -1) | |
6997 | { | |
6998 | asection * splt; | |
252b5132 | 6999 | asection * srel; |
e5a52504 | 7000 | bfd_byte *loc; |
24a1ba0f | 7001 | bfd_vma plt_index; |
947216bf | 7002 | Elf_Internal_Rela rel; |
252b5132 RH |
7003 | |
7004 | /* This symbol has an entry in the procedure linkage table. Set | |
7005 | it up. */ | |
7006 | ||
7007 | BFD_ASSERT (h->dynindx != -1); | |
7008 | ||
7009 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
00a97672 | 7010 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt")); |
e5a52504 | 7011 | BFD_ASSERT (splt != NULL && srel != NULL); |
252b5132 | 7012 | |
e5a52504 MM |
7013 | /* Fill in the entry in the procedure linkage table. */ |
7014 | if (htab->symbian_p) | |
7015 | { | |
52ab56c2 PB |
7016 | put_arm_insn (htab, output_bfd, |
7017 | elf32_arm_symbian_plt_entry[0], | |
7018 | splt->contents + h->plt.offset); | |
7019 | bfd_put_32 (output_bfd, | |
7020 | elf32_arm_symbian_plt_entry[1], | |
7021 | splt->contents + h->plt.offset + 4); | |
e5a52504 MM |
7022 | |
7023 | /* Fill in the entry in the .rel.plt section. */ | |
2a1b9a48 MM |
7024 | rel.r_offset = (splt->output_section->vma |
7025 | + splt->output_offset | |
52ab56c2 | 7026 | + h->plt.offset + 4); |
e5a52504 | 7027 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
b7693d02 DJ |
7028 | |
7029 | /* Get the index in the procedure linkage table which | |
7030 | corresponds to this symbol. This is the index of this symbol | |
7031 | in all the symbols for which we are making plt entries. The | |
7032 | first entry in the procedure linkage table is reserved. */ | |
7033 | plt_index = ((h->plt.offset - htab->plt_header_size) | |
7034 | / htab->plt_entry_size); | |
e5a52504 MM |
7035 | } |
7036 | else | |
7037 | { | |
00a97672 | 7038 | bfd_vma got_offset, got_address, plt_address; |
e5a52504 MM |
7039 | bfd_vma got_displacement; |
7040 | asection * sgot; | |
52ab56c2 | 7041 | bfd_byte * ptr; |
e5a52504 MM |
7042 | |
7043 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
7044 | BFD_ASSERT (sgot != NULL); | |
7045 | ||
b7693d02 DJ |
7046 | /* Get the offset into the .got.plt table of the entry that |
7047 | corresponds to this function. */ | |
7048 | got_offset = eh->plt_got_offset; | |
7049 | ||
7050 | /* Get the index in the procedure linkage table which | |
7051 | corresponds to this symbol. This is the index of this symbol | |
7052 | in all the symbols for which we are making plt entries. The | |
7053 | first three entries in .got.plt are reserved; after that | |
7054 | symbols appear in the same order as in .plt. */ | |
7055 | plt_index = (got_offset - 12) / 4; | |
e5a52504 | 7056 | |
00a97672 RS |
7057 | /* Calculate the address of the GOT entry. */ |
7058 | got_address = (sgot->output_section->vma | |
7059 | + sgot->output_offset | |
7060 | + got_offset); | |
5e681ec4 | 7061 | |
00a97672 RS |
7062 | /* ...and the address of the PLT entry. */ |
7063 | plt_address = (splt->output_section->vma | |
7064 | + splt->output_offset | |
7065 | + h->plt.offset); | |
5e681ec4 | 7066 | |
52ab56c2 | 7067 | ptr = htab->splt->contents + h->plt.offset; |
00a97672 RS |
7068 | if (htab->vxworks_p && info->shared) |
7069 | { | |
7070 | unsigned int i; | |
7071 | bfd_vma val; | |
7072 | ||
52ab56c2 | 7073 | for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4) |
00a97672 RS |
7074 | { |
7075 | val = elf32_arm_vxworks_shared_plt_entry[i]; | |
7076 | if (i == 2) | |
7077 | val |= got_address - sgot->output_section->vma; | |
7078 | if (i == 5) | |
7079 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
7080 | if (i == 2 || i == 5) |
7081 | bfd_put_32 (output_bfd, val, ptr); | |
7082 | else | |
7083 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
7084 | } |
7085 | } | |
7086 | else if (htab->vxworks_p) | |
b7693d02 | 7087 | { |
00a97672 RS |
7088 | unsigned int i; |
7089 | bfd_vma val; | |
7090 | ||
7091 | for (i = 0; i != htab->plt_entry_size / 4; i++) | |
7092 | { | |
7093 | val = elf32_arm_vxworks_exec_plt_entry[i]; | |
7094 | if (i == 2) | |
7095 | val |= got_address; | |
7096 | if (i == 4) | |
7097 | val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2); | |
7098 | if (i == 5) | |
7099 | val |= plt_index * RELOC_SIZE (htab); | |
52ab56c2 PB |
7100 | if (i == 2 || i == 5) |
7101 | bfd_put_32 (output_bfd, val, ptr); | |
7102 | else | |
7103 | put_arm_insn (htab, output_bfd, val, ptr); | |
00a97672 RS |
7104 | } |
7105 | ||
7106 | loc = (htab->srelplt2->contents | |
7107 | + (plt_index * 2 + 1) * RELOC_SIZE (htab)); | |
7108 | ||
7109 | /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation | |
7110 | referencing the GOT for this PLT entry. */ | |
7111 | rel.r_offset = plt_address + 8; | |
7112 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
7113 | rel.r_addend = got_offset; | |
7114 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
7115 | loc += RELOC_SIZE (htab); | |
7116 | ||
7117 | /* Create the R_ARM_ABS32 relocation referencing the | |
7118 | beginning of the PLT for this GOT entry. */ | |
7119 | rel.r_offset = got_address; | |
7120 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
7121 | rel.r_addend = 0; | |
7122 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
b7693d02 | 7123 | } |
00a97672 RS |
7124 | else |
7125 | { | |
7126 | /* Calculate the displacement between the PLT slot and the | |
7127 | entry in the GOT. The eight-byte offset accounts for the | |
7128 | value produced by adding to pc in the first instruction | |
7129 | of the PLT stub. */ | |
7130 | got_displacement = got_address - (plt_address + 8); | |
b7693d02 | 7131 | |
00a97672 RS |
7132 | BFD_ASSERT ((got_displacement & 0xf0000000) == 0); |
7133 | ||
7134 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) | |
7135 | { | |
52ab56c2 PB |
7136 | put_thumb_insn (htab, output_bfd, |
7137 | elf32_arm_plt_thumb_stub[0], ptr - 4); | |
7138 | put_thumb_insn (htab, output_bfd, | |
7139 | elf32_arm_plt_thumb_stub[1], ptr - 2); | |
00a97672 RS |
7140 | } |
7141 | ||
52ab56c2 PB |
7142 | put_arm_insn (htab, output_bfd, |
7143 | elf32_arm_plt_entry[0] | |
7144 | | ((got_displacement & 0x0ff00000) >> 20), | |
7145 | ptr + 0); | |
7146 | put_arm_insn (htab, output_bfd, | |
7147 | elf32_arm_plt_entry[1] | |
7148 | | ((got_displacement & 0x000ff000) >> 12), | |
7149 | ptr+ 4); | |
7150 | put_arm_insn (htab, output_bfd, | |
7151 | elf32_arm_plt_entry[2] | |
7152 | | (got_displacement & 0x00000fff), | |
7153 | ptr + 8); | |
5e681ec4 | 7154 | #ifdef FOUR_WORD_PLT |
52ab56c2 | 7155 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12); |
5e681ec4 | 7156 | #endif |
00a97672 | 7157 | } |
252b5132 | 7158 | |
e5a52504 MM |
7159 | /* Fill in the entry in the global offset table. */ |
7160 | bfd_put_32 (output_bfd, | |
7161 | (splt->output_section->vma | |
7162 | + splt->output_offset), | |
7163 | sgot->contents + got_offset); | |
7164 | ||
00a97672 RS |
7165 | /* Fill in the entry in the .rel(a).plt section. */ |
7166 | rel.r_addend = 0; | |
7167 | rel.r_offset = got_address; | |
e5a52504 MM |
7168 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); |
7169 | } | |
57e8b36a | 7170 | |
00a97672 RS |
7171 | loc = srel->contents + plt_index * RELOC_SIZE (htab); |
7172 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 | 7173 | |
f5385ebf | 7174 | if (!h->def_regular) |
252b5132 RH |
7175 | { |
7176 | /* Mark the symbol as undefined, rather than as defined in | |
7177 | the .plt section. Leave the value alone. */ | |
7178 | sym->st_shndx = SHN_UNDEF; | |
d982ba73 PB |
7179 | /* If the symbol is weak, we do need to clear the value. |
7180 | Otherwise, the PLT entry would provide a definition for | |
7181 | the symbol even if the symbol wasn't defined anywhere, | |
7182 | and so the symbol would never be NULL. */ | |
f5385ebf | 7183 | if (!h->ref_regular_nonweak) |
d982ba73 | 7184 | sym->st_value = 0; |
252b5132 RH |
7185 | } |
7186 | } | |
7187 | ||
ba93b8ac DJ |
7188 | if (h->got.offset != (bfd_vma) -1 |
7189 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 | |
7190 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) | |
252b5132 RH |
7191 | { |
7192 | asection * sgot; | |
7193 | asection * srel; | |
947216bf AM |
7194 | Elf_Internal_Rela rel; |
7195 | bfd_byte *loc; | |
00a97672 | 7196 | bfd_vma offset; |
252b5132 RH |
7197 | |
7198 | /* This symbol has an entry in the global offset table. Set it | |
7199 | up. */ | |
252b5132 | 7200 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
00a97672 | 7201 | srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got")); |
252b5132 RH |
7202 | BFD_ASSERT (sgot != NULL && srel != NULL); |
7203 | ||
00a97672 RS |
7204 | offset = (h->got.offset & ~(bfd_vma) 1); |
7205 | rel.r_addend = 0; | |
252b5132 RH |
7206 | rel.r_offset = (sgot->output_section->vma |
7207 | + sgot->output_offset | |
00a97672 | 7208 | + offset); |
252b5132 | 7209 | |
5e681ec4 PB |
7210 | /* If this is a static link, or it is a -Bsymbolic link and the |
7211 | symbol is defined locally or was forced to be local because | |
7212 | of a version file, we just want to emit a RELATIVE reloc. | |
7213 | The entry in the global offset table will already have been | |
7214 | initialized in the relocate_section function. */ | |
252b5132 | 7215 | if (info->shared |
5e681ec4 PB |
7216 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
7217 | { | |
7218 | BFD_ASSERT((h->got.offset & 1) != 0); | |
7219 | rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
00a97672 RS |
7220 | if (!htab->use_rel) |
7221 | { | |
7222 | rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset); | |
7223 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); | |
7224 | } | |
5e681ec4 | 7225 | } |
252b5132 RH |
7226 | else |
7227 | { | |
5e681ec4 | 7228 | BFD_ASSERT((h->got.offset & 1) == 0); |
00a97672 | 7229 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); |
252b5132 RH |
7230 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
7231 | } | |
7232 | ||
00a97672 RS |
7233 | loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab); |
7234 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
7235 | } |
7236 | ||
f5385ebf | 7237 | if (h->needs_copy) |
252b5132 RH |
7238 | { |
7239 | asection * s; | |
947216bf AM |
7240 | Elf_Internal_Rela rel; |
7241 | bfd_byte *loc; | |
252b5132 RH |
7242 | |
7243 | /* This symbol needs a copy reloc. Set it up. */ | |
252b5132 RH |
7244 | BFD_ASSERT (h->dynindx != -1 |
7245 | && (h->root.type == bfd_link_hash_defined | |
7246 | || h->root.type == bfd_link_hash_defweak)); | |
7247 | ||
7248 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
00a97672 | 7249 | RELOC_SECTION (htab, ".bss")); |
252b5132 RH |
7250 | BFD_ASSERT (s != NULL); |
7251 | ||
00a97672 | 7252 | rel.r_addend = 0; |
252b5132 RH |
7253 | rel.r_offset = (h->root.u.def.value |
7254 | + h->root.u.def.section->output_section->vma | |
7255 | + h->root.u.def.section->output_offset); | |
7256 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); | |
00a97672 RS |
7257 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); |
7258 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); | |
252b5132 RH |
7259 | } |
7260 | ||
00a97672 RS |
7261 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks, |
7262 | the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative | |
7263 | to the ".got" section. */ | |
252b5132 | 7264 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
00a97672 | 7265 | || (!htab->vxworks_p && h == htab->root.hgot)) |
252b5132 RH |
7266 | sym->st_shndx = SHN_ABS; |
7267 | ||
b34976b6 | 7268 | return TRUE; |
252b5132 RH |
7269 | } |
7270 | ||
7271 | /* Finish up the dynamic sections. */ | |
7272 | ||
b34976b6 | 7273 | static bfd_boolean |
57e8b36a | 7274 | elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) |
252b5132 RH |
7275 | { |
7276 | bfd * dynobj; | |
7277 | asection * sgot; | |
7278 | asection * sdyn; | |
7279 | ||
7280 | dynobj = elf_hash_table (info)->dynobj; | |
7281 | ||
7282 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
229fcec5 | 7283 | BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); |
252b5132 RH |
7284 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
7285 | ||
7286 | if (elf_hash_table (info)->dynamic_sections_created) | |
7287 | { | |
7288 | asection *splt; | |
7289 | Elf32_External_Dyn *dyncon, *dynconend; | |
229fcec5 | 7290 | struct elf32_arm_link_hash_table *htab; |
252b5132 | 7291 | |
229fcec5 | 7292 | htab = elf32_arm_hash_table (info); |
252b5132 | 7293 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
24a1ba0f | 7294 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
252b5132 RH |
7295 | |
7296 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 7297 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
9b485d32 | 7298 | |
252b5132 RH |
7299 | for (; dyncon < dynconend; dyncon++) |
7300 | { | |
7301 | Elf_Internal_Dyn dyn; | |
7302 | const char * name; | |
7303 | asection * s; | |
7304 | ||
7305 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
7306 | ||
7307 | switch (dyn.d_tag) | |
7308 | { | |
229fcec5 MM |
7309 | unsigned int type; |
7310 | ||
252b5132 RH |
7311 | default: |
7312 | break; | |
7313 | ||
229fcec5 MM |
7314 | case DT_HASH: |
7315 | name = ".hash"; | |
7316 | goto get_vma_if_bpabi; | |
7317 | case DT_STRTAB: | |
7318 | name = ".dynstr"; | |
7319 | goto get_vma_if_bpabi; | |
7320 | case DT_SYMTAB: | |
7321 | name = ".dynsym"; | |
7322 | goto get_vma_if_bpabi; | |
c0042f5d MM |
7323 | case DT_VERSYM: |
7324 | name = ".gnu.version"; | |
7325 | goto get_vma_if_bpabi; | |
7326 | case DT_VERDEF: | |
7327 | name = ".gnu.version_d"; | |
7328 | goto get_vma_if_bpabi; | |
7329 | case DT_VERNEED: | |
7330 | name = ".gnu.version_r"; | |
7331 | goto get_vma_if_bpabi; | |
7332 | ||
252b5132 RH |
7333 | case DT_PLTGOT: |
7334 | name = ".got"; | |
7335 | goto get_vma; | |
7336 | case DT_JMPREL: | |
00a97672 | 7337 | name = RELOC_SECTION (htab, ".plt"); |
252b5132 RH |
7338 | get_vma: |
7339 | s = bfd_get_section_by_name (output_bfd, name); | |
7340 | BFD_ASSERT (s != NULL); | |
229fcec5 MM |
7341 | if (!htab->symbian_p) |
7342 | dyn.d_un.d_ptr = s->vma; | |
7343 | else | |
7344 | /* In the BPABI, tags in the PT_DYNAMIC section point | |
7345 | at the file offset, not the memory address, for the | |
7346 | convenience of the post linker. */ | |
7347 | dyn.d_un.d_ptr = s->filepos; | |
252b5132 RH |
7348 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
7349 | break; | |
7350 | ||
229fcec5 MM |
7351 | get_vma_if_bpabi: |
7352 | if (htab->symbian_p) | |
7353 | goto get_vma; | |
7354 | break; | |
7355 | ||
252b5132 | 7356 | case DT_PLTRELSZ: |
00a97672 RS |
7357 | s = bfd_get_section_by_name (output_bfd, |
7358 | RELOC_SECTION (htab, ".plt")); | |
252b5132 | 7359 | BFD_ASSERT (s != NULL); |
eea6121a | 7360 | dyn.d_un.d_val = s->size; |
252b5132 RH |
7361 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
7362 | break; | |
229fcec5 | 7363 | |
252b5132 | 7364 | case DT_RELSZ: |
00a97672 | 7365 | case DT_RELASZ: |
229fcec5 MM |
7366 | if (!htab->symbian_p) |
7367 | { | |
7368 | /* My reading of the SVR4 ABI indicates that the | |
7369 | procedure linkage table relocs (DT_JMPREL) should be | |
7370 | included in the overall relocs (DT_REL). This is | |
7371 | what Solaris does. However, UnixWare can not handle | |
7372 | that case. Therefore, we override the DT_RELSZ entry | |
7373 | here to make it not include the JMPREL relocs. Since | |
00a97672 | 7374 | the linker script arranges for .rel(a).plt to follow all |
229fcec5 MM |
7375 | other relocation sections, we don't have to worry |
7376 | about changing the DT_REL entry. */ | |
00a97672 RS |
7377 | s = bfd_get_section_by_name (output_bfd, |
7378 | RELOC_SECTION (htab, ".plt")); | |
229fcec5 MM |
7379 | if (s != NULL) |
7380 | dyn.d_un.d_val -= s->size; | |
7381 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
7382 | break; | |
7383 | } | |
7384 | /* Fall through */ | |
7385 | ||
7386 | case DT_REL: | |
7387 | case DT_RELA: | |
229fcec5 MM |
7388 | /* In the BPABI, the DT_REL tag must point at the file |
7389 | offset, not the VMA, of the first relocation | |
7390 | section. So, we use code similar to that in | |
7391 | elflink.c, but do not check for SHF_ALLOC on the | |
7392 | relcoation section, since relocations sections are | |
7393 | never allocated under the BPABI. The comments above | |
7394 | about Unixware notwithstanding, we include all of the | |
7395 | relocations here. */ | |
7396 | if (htab->symbian_p) | |
7397 | { | |
7398 | unsigned int i; | |
7399 | type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) | |
7400 | ? SHT_REL : SHT_RELA); | |
7401 | dyn.d_un.d_val = 0; | |
7402 | for (i = 1; i < elf_numsections (output_bfd); i++) | |
7403 | { | |
7404 | Elf_Internal_Shdr *hdr | |
7405 | = elf_elfsections (output_bfd)[i]; | |
7406 | if (hdr->sh_type == type) | |
7407 | { | |
7408 | if (dyn.d_tag == DT_RELSZ | |
7409 | || dyn.d_tag == DT_RELASZ) | |
7410 | dyn.d_un.d_val += hdr->sh_size; | |
de52dba4 AM |
7411 | else if ((ufile_ptr) hdr->sh_offset |
7412 | <= dyn.d_un.d_val - 1) | |
229fcec5 MM |
7413 | dyn.d_un.d_val = hdr->sh_offset; |
7414 | } | |
7415 | } | |
7416 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
7417 | } | |
252b5132 | 7418 | break; |
88f7bcd5 NC |
7419 | |
7420 | /* Set the bottom bit of DT_INIT/FINI if the | |
7421 | corresponding function is Thumb. */ | |
7422 | case DT_INIT: | |
7423 | name = info->init_function; | |
7424 | goto get_sym; | |
7425 | case DT_FINI: | |
7426 | name = info->fini_function; | |
7427 | get_sym: | |
7428 | /* If it wasn't set by elf_bfd_final_link | |
4cc11e76 | 7429 | then there is nothing to adjust. */ |
88f7bcd5 NC |
7430 | if (dyn.d_un.d_val != 0) |
7431 | { | |
7432 | struct elf_link_hash_entry * eh; | |
7433 | ||
7434 | eh = elf_link_hash_lookup (elf_hash_table (info), name, | |
b34976b6 | 7435 | FALSE, FALSE, TRUE); |
88f7bcd5 NC |
7436 | if (eh != (struct elf_link_hash_entry *) NULL |
7437 | && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) | |
7438 | { | |
7439 | dyn.d_un.d_val |= 1; | |
b34976b6 | 7440 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
88f7bcd5 NC |
7441 | } |
7442 | } | |
7443 | break; | |
252b5132 RH |
7444 | } |
7445 | } | |
7446 | ||
24a1ba0f | 7447 | /* Fill in the first entry in the procedure linkage table. */ |
e5a52504 | 7448 | if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) |
f7a74f8c | 7449 | { |
00a97672 RS |
7450 | const bfd_vma *plt0_entry; |
7451 | bfd_vma got_address, plt_address, got_displacement; | |
7452 | ||
7453 | /* Calculate the addresses of the GOT and PLT. */ | |
7454 | got_address = sgot->output_section->vma + sgot->output_offset; | |
7455 | plt_address = splt->output_section->vma + splt->output_offset; | |
7456 | ||
7457 | if (htab->vxworks_p) | |
7458 | { | |
7459 | /* The VxWorks GOT is relocated by the dynamic linker. | |
7460 | Therefore, we must emit relocations rather than simply | |
7461 | computing the values now. */ | |
7462 | Elf_Internal_Rela rel; | |
7463 | ||
7464 | plt0_entry = elf32_arm_vxworks_exec_plt0_entry; | |
52ab56c2 PB |
7465 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
7466 | splt->contents + 0); | |
7467 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
7468 | splt->contents + 4); | |
7469 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
7470 | splt->contents + 8); | |
00a97672 RS |
7471 | bfd_put_32 (output_bfd, got_address, splt->contents + 12); |
7472 | ||
7473 | /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */ | |
7474 | rel.r_offset = plt_address + 12; | |
7475 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
7476 | rel.r_addend = 0; | |
7477 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, | |
7478 | htab->srelplt2->contents); | |
7479 | } | |
7480 | else | |
7481 | { | |
7482 | got_displacement = got_address - (plt_address + 16); | |
7483 | ||
7484 | plt0_entry = elf32_arm_plt0_entry; | |
52ab56c2 PB |
7485 | put_arm_insn (htab, output_bfd, plt0_entry[0], |
7486 | splt->contents + 0); | |
7487 | put_arm_insn (htab, output_bfd, plt0_entry[1], | |
7488 | splt->contents + 4); | |
7489 | put_arm_insn (htab, output_bfd, plt0_entry[2], | |
7490 | splt->contents + 8); | |
7491 | put_arm_insn (htab, output_bfd, plt0_entry[3], | |
7492 | splt->contents + 12); | |
5e681ec4 | 7493 | |
5e681ec4 | 7494 | #ifdef FOUR_WORD_PLT |
00a97672 RS |
7495 | /* The displacement value goes in the otherwise-unused |
7496 | last word of the second entry. */ | |
7497 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); | |
5e681ec4 | 7498 | #else |
00a97672 | 7499 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); |
5e681ec4 | 7500 | #endif |
00a97672 | 7501 | } |
f7a74f8c | 7502 | } |
252b5132 RH |
7503 | |
7504 | /* UnixWare sets the entsize of .plt to 4, although that doesn't | |
7505 | really seem like the right value. */ | |
7506 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; | |
00a97672 RS |
7507 | |
7508 | if (htab->vxworks_p && !info->shared && htab->splt->size > 0) | |
7509 | { | |
7510 | /* Correct the .rel(a).plt.unloaded relocations. They will have | |
7511 | incorrect symbol indexes. */ | |
7512 | int num_plts; | |
eed62c48 | 7513 | unsigned char *p; |
00a97672 RS |
7514 | |
7515 | num_plts = ((htab->splt->size - htab->plt_header_size) | |
7516 | / htab->plt_entry_size); | |
7517 | p = htab->srelplt2->contents + RELOC_SIZE (htab); | |
7518 | ||
7519 | for (; num_plts; num_plts--) | |
7520 | { | |
7521 | Elf_Internal_Rela rel; | |
7522 | ||
7523 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
7524 | rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); | |
7525 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
7526 | p += RELOC_SIZE (htab); | |
7527 | ||
7528 | SWAP_RELOC_IN (htab) (output_bfd, p, &rel); | |
7529 | rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); | |
7530 | SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); | |
7531 | p += RELOC_SIZE (htab); | |
7532 | } | |
7533 | } | |
252b5132 RH |
7534 | } |
7535 | ||
7536 | /* Fill in the first three entries in the global offset table. */ | |
229fcec5 | 7537 | if (sgot) |
252b5132 | 7538 | { |
229fcec5 MM |
7539 | if (sgot->size > 0) |
7540 | { | |
7541 | if (sdyn == NULL) | |
7542 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
7543 | else | |
7544 | bfd_put_32 (output_bfd, | |
7545 | sdyn->output_section->vma + sdyn->output_offset, | |
7546 | sgot->contents); | |
7547 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
7548 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
7549 | } | |
252b5132 | 7550 | |
229fcec5 MM |
7551 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
7552 | } | |
252b5132 | 7553 | |
b34976b6 | 7554 | return TRUE; |
252b5132 RH |
7555 | } |
7556 | ||
ba96a88f | 7557 | static void |
57e8b36a | 7558 | elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) |
ba96a88f | 7559 | { |
9b485d32 | 7560 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ |
e489d0ae | 7561 | struct elf32_arm_link_hash_table *globals; |
ba96a88f NC |
7562 | |
7563 | i_ehdrp = elf_elfheader (abfd); | |
7564 | ||
94a3258f PB |
7565 | if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN) |
7566 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM; | |
7567 | else | |
7568 | i_ehdrp->e_ident[EI_OSABI] = 0; | |
ba96a88f | 7569 | i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION; |
e489d0ae | 7570 | |
93204d3a PB |
7571 | if (link_info) |
7572 | { | |
7573 | globals = elf32_arm_hash_table (link_info); | |
7574 | if (globals->byteswap_code) | |
7575 | i_ehdrp->e_flags |= EF_ARM_BE8; | |
7576 | } | |
ba96a88f NC |
7577 | } |
7578 | ||
99e4ae17 | 7579 | static enum elf_reloc_type_class |
57e8b36a | 7580 | elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) |
99e4ae17 | 7581 | { |
f51e552e | 7582 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
99e4ae17 AJ |
7583 | { |
7584 | case R_ARM_RELATIVE: | |
7585 | return reloc_class_relative; | |
7586 | case R_ARM_JUMP_SLOT: | |
7587 | return reloc_class_plt; | |
7588 | case R_ARM_COPY: | |
7589 | return reloc_class_copy; | |
7590 | default: | |
7591 | return reloc_class_normal; | |
7592 | } | |
7593 | } | |
7594 | ||
e16bb312 NC |
7595 | /* Set the right machine number for an Arm ELF file. */ |
7596 | ||
7597 | static bfd_boolean | |
57e8b36a | 7598 | elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) |
e16bb312 NC |
7599 | { |
7600 | if (hdr->sh_type == SHT_NOTE) | |
7601 | *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
7602 | ||
7603 | return TRUE; | |
7604 | } | |
7605 | ||
e489d0ae | 7606 | static void |
57e8b36a | 7607 | elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) |
e16bb312 | 7608 | { |
5a6c6817 | 7609 | bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); |
e16bb312 NC |
7610 | } |
7611 | ||
40a18ebd NC |
7612 | /* Return TRUE if this is an unwinding table entry. */ |
7613 | ||
7614 | static bfd_boolean | |
7615 | is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name) | |
7616 | { | |
7617 | size_t len1, len2; | |
7618 | ||
7619 | len1 = sizeof (ELF_STRING_ARM_unwind) - 1; | |
7620 | len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1; | |
7621 | return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0 | |
7622 | || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0); | |
7623 | } | |
7624 | ||
7625 | ||
7626 | /* Set the type and flags for an ARM section. We do this by | |
7627 | the section name, which is a hack, but ought to work. */ | |
7628 | ||
7629 | static bfd_boolean | |
7630 | elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec) | |
7631 | { | |
7632 | const char * name; | |
7633 | ||
7634 | name = bfd_get_section_name (abfd, sec); | |
7635 | ||
7636 | if (is_arm_elf_unwind_section_name (abfd, name)) | |
7637 | { | |
7638 | hdr->sh_type = SHT_ARM_EXIDX; | |
7639 | hdr->sh_flags |= SHF_LINK_ORDER; | |
7640 | } | |
ee065d83 PB |
7641 | else if (strcmp(name, ".ARM.attributes") == 0) |
7642 | { | |
7643 | hdr->sh_type = SHT_ARM_ATTRIBUTES; | |
7644 | } | |
40a18ebd NC |
7645 | return TRUE; |
7646 | } | |
7647 | ||
ee065d83 PB |
7648 | /* Parse an Arm EABI attributes section. */ |
7649 | static void | |
7650 | elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr) | |
7651 | { | |
7652 | bfd_byte *contents; | |
7653 | bfd_byte *p; | |
7654 | bfd_vma len; | |
7655 | ||
7656 | contents = bfd_malloc (hdr->sh_size); | |
7657 | if (!contents) | |
7658 | return; | |
7659 | if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0, | |
7660 | hdr->sh_size)) | |
7661 | { | |
7662 | free (contents); | |
7663 | return; | |
7664 | } | |
7665 | p = contents; | |
7666 | if (*(p++) == 'A') | |
7667 | { | |
7668 | len = hdr->sh_size - 1; | |
7669 | while (len > 0) | |
7670 | { | |
7671 | int namelen; | |
7672 | bfd_vma section_len; | |
7673 | ||
7674 | section_len = bfd_get_32 (abfd, p); | |
7675 | p += 4; | |
7676 | if (section_len > len) | |
7677 | section_len = len; | |
7678 | len -= section_len; | |
7679 | namelen = strlen ((char *)p) + 1; | |
7680 | section_len -= namelen + 4; | |
7681 | if (strcmp((char *)p, "aeabi") != 0) | |
7682 | { | |
7683 | /* Vendor section. Ignore it. */ | |
7684 | p += namelen + section_len; | |
7685 | } | |
7686 | else | |
7687 | { | |
7688 | p += namelen; | |
7689 | while (section_len > 0) | |
7690 | { | |
7691 | int tag; | |
7692 | unsigned int n; | |
7693 | unsigned int val; | |
7694 | bfd_vma subsection_len; | |
7695 | bfd_byte *end; | |
7696 | ||
7697 | tag = read_unsigned_leb128 (abfd, p, &n); | |
7698 | p += n; | |
7699 | subsection_len = bfd_get_32 (abfd, p); | |
7700 | p += 4; | |
7701 | if (subsection_len > section_len) | |
7702 | subsection_len = section_len; | |
7703 | section_len -= subsection_len; | |
7704 | subsection_len -= n + 4; | |
7705 | end = p + subsection_len; | |
7706 | switch (tag) | |
7707 | { | |
7708 | case Tag_File: | |
7709 | while (p < end) | |
7710 | { | |
7711 | bfd_boolean is_string; | |
7712 | ||
7713 | tag = read_unsigned_leb128 (abfd, p, &n); | |
7714 | p += n; | |
7715 | if (tag == 4 || tag == 5) | |
7716 | is_string = 1; | |
7717 | else if (tag < 32) | |
7718 | is_string = 0; | |
7719 | else | |
7720 | is_string = (tag & 1) != 0; | |
7721 | if (tag == Tag_compatibility) | |
7722 | { | |
7723 | val = read_unsigned_leb128 (abfd, p, &n); | |
7724 | p += n; | |
7725 | elf32_arm_add_eabi_attr_compat (abfd, val, | |
7726 | (char *)p); | |
7727 | p += strlen ((char *)p) + 1; | |
7728 | } | |
7729 | else if (is_string) | |
7730 | { | |
7731 | elf32_arm_add_eabi_attr_string (abfd, tag, | |
7732 | (char *)p); | |
7733 | p += strlen ((char *)p) + 1; | |
7734 | } | |
7735 | else | |
7736 | { | |
7737 | val = read_unsigned_leb128 (abfd, p, &n); | |
7738 | p += n; | |
7739 | elf32_arm_add_eabi_attr_int (abfd, tag, val); | |
7740 | } | |
7741 | } | |
7742 | break; | |
7743 | case Tag_Section: | |
7744 | case Tag_Symbol: | |
7745 | /* Don't have anywhere convenient to attach these. | |
7746 | Fall through for now. */ | |
7747 | default: | |
7748 | /* Ignore things we don't kow about. */ | |
7749 | p += subsection_len; | |
7750 | subsection_len = 0; | |
7751 | break; | |
7752 | } | |
7753 | } | |
7754 | } | |
7755 | } | |
7756 | } | |
7757 | free (contents); | |
7758 | } | |
7759 | ||
6dc132d9 L |
7760 | /* Handle an ARM specific section when reading an object file. This is |
7761 | called when bfd_section_from_shdr finds a section with an unknown | |
7762 | type. */ | |
40a18ebd NC |
7763 | |
7764 | static bfd_boolean | |
7765 | elf32_arm_section_from_shdr (bfd *abfd, | |
7766 | Elf_Internal_Shdr * hdr, | |
6dc132d9 L |
7767 | const char *name, |
7768 | int shindex) | |
40a18ebd NC |
7769 | { |
7770 | /* There ought to be a place to keep ELF backend specific flags, but | |
7771 | at the moment there isn't one. We just keep track of the | |
7772 | sections by their name, instead. Fortunately, the ABI gives | |
7773 | names for all the ARM specific sections, so we will probably get | |
7774 | away with this. */ | |
7775 | switch (hdr->sh_type) | |
7776 | { | |
7777 | case SHT_ARM_EXIDX: | |
0951f019 RE |
7778 | case SHT_ARM_PREEMPTMAP: |
7779 | case SHT_ARM_ATTRIBUTES: | |
40a18ebd NC |
7780 | break; |
7781 | ||
7782 | default: | |
7783 | return FALSE; | |
7784 | } | |
7785 | ||
6dc132d9 | 7786 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
40a18ebd NC |
7787 | return FALSE; |
7788 | ||
ee065d83 PB |
7789 | if (hdr->sh_type == SHT_ARM_ATTRIBUTES) |
7790 | elf32_arm_parse_attributes(abfd, hdr); | |
40a18ebd NC |
7791 | return TRUE; |
7792 | } | |
e489d0ae | 7793 | |
8e3de13a NC |
7794 | /* A structure used to record a list of sections, independently |
7795 | of the next and prev fields in the asection structure. */ | |
7796 | typedef struct section_list | |
7797 | { | |
7798 | asection * sec; | |
7799 | struct section_list * next; | |
7800 | struct section_list * prev; | |
7801 | } | |
7802 | section_list; | |
7803 | ||
7804 | /* Unfortunately we need to keep a list of sections for which | |
7805 | an _arm_elf_section_data structure has been allocated. This | |
7806 | is because it is possible for functions like elf32_arm_write_section | |
7807 | to be called on a section which has had an elf_data_structure | |
7808 | allocated for it (and so the used_by_bfd field is valid) but | |
7809 | for which the ARM extended version of this structure - the | |
7810 | _arm_elf_section_data structure - has not been allocated. */ | |
7811 | static section_list * sections_with_arm_elf_section_data = NULL; | |
7812 | ||
7813 | static void | |
957c6e41 | 7814 | record_section_with_arm_elf_section_data (asection * sec) |
8e3de13a NC |
7815 | { |
7816 | struct section_list * entry; | |
7817 | ||
957c6e41 | 7818 | entry = bfd_malloc (sizeof (* entry)); |
8e3de13a NC |
7819 | if (entry == NULL) |
7820 | return; | |
7821 | entry->sec = sec; | |
7822 | entry->next = sections_with_arm_elf_section_data; | |
7823 | entry->prev = NULL; | |
7824 | if (entry->next != NULL) | |
7825 | entry->next->prev = entry; | |
7826 | sections_with_arm_elf_section_data = entry; | |
7827 | } | |
7828 | ||
44444f50 NC |
7829 | static struct section_list * |
7830 | find_arm_elf_section_entry (asection * sec) | |
8e3de13a NC |
7831 | { |
7832 | struct section_list * entry; | |
bd4aae00 | 7833 | static struct section_list * last_entry = NULL; |
8e3de13a | 7834 | |
bd4aae00 NC |
7835 | /* This is a short cut for the typical case where the sections are added |
7836 | to the sections_with_arm_elf_section_data list in forward order and | |
7837 | then looked up here in backwards order. This makes a real difference | |
7838 | to the ld-srec/sec64k.exp linker test. */ | |
44444f50 | 7839 | entry = sections_with_arm_elf_section_data; |
bd4aae00 NC |
7840 | if (last_entry != NULL) |
7841 | { | |
7842 | if (last_entry->sec == sec) | |
44444f50 NC |
7843 | entry = last_entry; |
7844 | else if (last_entry->next != NULL | |
7845 | && last_entry->next->sec == sec) | |
7846 | entry = last_entry->next; | |
bd4aae00 | 7847 | } |
44444f50 NC |
7848 | |
7849 | for (; entry; entry = entry->next) | |
8e3de13a | 7850 | if (entry->sec == sec) |
44444f50 | 7851 | break; |
bd4aae00 | 7852 | |
44444f50 NC |
7853 | if (entry) |
7854 | /* Record the entry prior to this one - it is the entry we are most | |
7855 | likely to want to locate next time. Also this way if we have been | |
7856 | called from unrecord_section_with_arm_elf_section_data() we will not | |
7857 | be caching a pointer that is about to be freed. */ | |
7858 | last_entry = entry->prev; | |
7859 | ||
7860 | return entry; | |
7861 | } | |
7862 | ||
7863 | static _arm_elf_section_data * | |
7864 | get_arm_elf_section_data (asection * sec) | |
7865 | { | |
7866 | struct section_list * entry; | |
7867 | ||
7868 | entry = find_arm_elf_section_entry (sec); | |
7869 | ||
7870 | if (entry) | |
7871 | return elf32_arm_section_data (entry->sec); | |
7872 | else | |
7873 | return NULL; | |
8e3de13a NC |
7874 | } |
7875 | ||
7876 | static void | |
7877 | unrecord_section_with_arm_elf_section_data (asection * sec) | |
7878 | { | |
7879 | struct section_list * entry; | |
7880 | ||
44444f50 NC |
7881 | entry = find_arm_elf_section_entry (sec); |
7882 | ||
7883 | if (entry) | |
7884 | { | |
7885 | if (entry->prev != NULL) | |
7886 | entry->prev->next = entry->next; | |
7887 | if (entry->next != NULL) | |
7888 | entry->next->prev = entry->prev; | |
7889 | if (entry == sections_with_arm_elf_section_data) | |
7890 | sections_with_arm_elf_section_data = entry->next; | |
7891 | free (entry); | |
7892 | } | |
8e3de13a NC |
7893 | } |
7894 | ||
e489d0ae PB |
7895 | /* Called for each symbol. Builds a section map based on mapping symbols. |
7896 | Does not alter any of the symbols. */ | |
7897 | ||
7898 | static bfd_boolean | |
7899 | elf32_arm_output_symbol_hook (struct bfd_link_info *info, | |
7900 | const char *name, | |
7901 | Elf_Internal_Sym *elfsym, | |
7902 | asection *input_sec, | |
00a97672 | 7903 | struct elf_link_hash_entry *h) |
e489d0ae PB |
7904 | { |
7905 | int mapcount; | |
7906 | elf32_arm_section_map *map; | |
8e3de13a NC |
7907 | elf32_arm_section_map *newmap; |
7908 | _arm_elf_section_data *arm_data; | |
e489d0ae PB |
7909 | struct elf32_arm_link_hash_table *globals; |
7910 | ||
00a97672 RS |
7911 | globals = elf32_arm_hash_table (info); |
7912 | if (globals->vxworks_p | |
7913 | && !elf_vxworks_link_output_symbol_hook (info, name, elfsym, | |
7914 | input_sec, h)) | |
7915 | return FALSE; | |
7916 | ||
e489d0ae PB |
7917 | /* Only do this on final link. */ |
7918 | if (info->relocatable) | |
7919 | return TRUE; | |
7920 | ||
7921 | /* Only build a map if we need to byteswap code. */ | |
e489d0ae PB |
7922 | if (!globals->byteswap_code) |
7923 | return TRUE; | |
7924 | ||
7925 | /* We only want mapping symbols. */ | |
b0796911 | 7926 | if (!bfd_is_arm_special_symbol_name (name, BFD_ARM_SPECIAL_SYM_TYPE_MAP)) |
e489d0ae PB |
7927 | return TRUE; |
7928 | ||
8e3de13a NC |
7929 | /* If this section has not been allocated an _arm_elf_section_data |
7930 | structure then we cannot record anything. */ | |
7931 | arm_data = get_arm_elf_section_data (input_sec); | |
7932 | if (arm_data == NULL) | |
7933 | return TRUE; | |
7934 | ||
7935 | mapcount = arm_data->mapcount + 1; | |
7936 | map = arm_data->map; | |
d7f735da | 7937 | |
e489d0ae PB |
7938 | /* TODO: This may be inefficient, but we probably don't usually have many |
7939 | mapping symbols per section. */ | |
8e3de13a NC |
7940 | newmap = bfd_realloc (map, mapcount * sizeof (* map)); |
7941 | if (newmap != NULL) | |
7942 | { | |
7943 | arm_data->map = newmap; | |
7944 | arm_data->mapcount = mapcount; | |
7945 | ||
d7f735da NC |
7946 | newmap[mapcount - 1].vma = elfsym->st_value; |
7947 | newmap[mapcount - 1].type = name[1]; | |
8e3de13a | 7948 | } |
57e8b36a | 7949 | |
e489d0ae PB |
7950 | return TRUE; |
7951 | } | |
7952 | ||
4e617b1e PB |
7953 | typedef struct |
7954 | { | |
7955 | void *finfo; | |
7956 | struct bfd_link_info *info; | |
7957 | int plt_shndx; | |
7958 | bfd_vma plt_offset; | |
7959 | bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *, | |
7960 | asection *, struct elf_link_hash_entry *); | |
7961 | } output_arch_syminfo; | |
7962 | ||
7963 | enum map_symbol_type | |
7964 | { | |
7965 | ARM_MAP_ARM, | |
7966 | ARM_MAP_THUMB, | |
7967 | ARM_MAP_DATA | |
7968 | }; | |
7969 | ||
7970 | ||
7971 | /* Output a single PLT mapping symbol. */ | |
7972 | ||
7973 | static bfd_boolean | |
7974 | elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi, | |
7975 | enum map_symbol_type type, | |
7976 | bfd_vma offset) | |
7977 | { | |
7978 | static const char *names[3] = {"$a", "$t", "$d"}; | |
7979 | struct elf32_arm_link_hash_table *htab; | |
7980 | Elf_Internal_Sym sym; | |
7981 | ||
7982 | htab = elf32_arm_hash_table (osi->info); | |
7983 | sym.st_value = osi->plt_offset + offset; | |
7984 | sym.st_size = 0; | |
7985 | sym.st_other = 0; | |
7986 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
7987 | sym.st_shndx = osi->plt_shndx; | |
7988 | if (!osi->func (osi->finfo, names[type], &sym, htab->splt, NULL)) | |
7989 | return FALSE; | |
7990 | return TRUE; | |
7991 | } | |
7992 | ||
7993 | ||
7994 | /* Output mapping symbols for PLT entries associated with H. */ | |
7995 | ||
7996 | static bfd_boolean | |
7997 | elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf) | |
7998 | { | |
7999 | output_arch_syminfo *osi = (output_arch_syminfo *) inf; | |
8000 | struct elf32_arm_link_hash_table *htab; | |
8001 | struct elf32_arm_link_hash_entry *eh; | |
8002 | bfd_vma addr; | |
8003 | ||
8004 | htab = elf32_arm_hash_table (osi->info); | |
8005 | ||
8006 | if (h->root.type == bfd_link_hash_indirect) | |
8007 | return TRUE; | |
8008 | ||
8009 | if (h->root.type == bfd_link_hash_warning) | |
8010 | /* When warning symbols are created, they **replace** the "real" | |
8011 | entry in the hash table, thus we never get to see the real | |
8012 | symbol in a hash traversal. So look at it now. */ | |
8013 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
8014 | ||
8015 | if (h->plt.offset == (bfd_vma) -1) | |
8016 | return TRUE; | |
8017 | ||
8018 | eh = (struct elf32_arm_link_hash_entry *) h; | |
8019 | addr = h->plt.offset; | |
8020 | if (htab->symbian_p) | |
8021 | { | |
8022 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8023 | return FALSE; | |
8024 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4)) | |
8025 | return FALSE; | |
8026 | } | |
8027 | else if (htab->vxworks_p) | |
8028 | { | |
8029 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8030 | return FALSE; | |
8031 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8)) | |
8032 | return FALSE; | |
8033 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12)) | |
8034 | return FALSE; | |
8035 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20)) | |
8036 | return FALSE; | |
8037 | } | |
8038 | else | |
8039 | { | |
8040 | bfd_boolean thumb_stub; | |
8041 | ||
8042 | thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx; | |
8043 | if (thumb_stub) | |
8044 | { | |
8045 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4)) | |
8046 | return FALSE; | |
8047 | } | |
8048 | #ifdef FOUR_WORD_PLT | |
8049 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8050 | return FALSE; | |
8051 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12)) | |
8052 | return FALSE; | |
8053 | #else | |
8054 | /* A three-word PLT with no Thumb thunk contains only Arm code, | |
8055 | so only need to output a mapping symbol for the first PLT entry and | |
8056 | entries with thumb thunks. */ | |
8057 | if (thumb_stub || addr == 20) | |
8058 | { | |
8059 | if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) | |
8060 | return FALSE; | |
8061 | } | |
8062 | #endif | |
8063 | } | |
8064 | ||
8065 | return TRUE; | |
8066 | } | |
8067 | ||
8068 | ||
8069 | /* Output mapping symbols for the PLT. */ | |
8070 | ||
8071 | static bfd_boolean | |
8072 | elf32_arm_output_arch_local_syms (bfd *output_bfd, | |
8073 | struct bfd_link_info *info, | |
8074 | void *finfo, bfd_boolean (*func) (void *, const char *, | |
8075 | Elf_Internal_Sym *, | |
8076 | asection *, | |
8077 | struct elf_link_hash_entry *)) | |
8078 | { | |
8079 | output_arch_syminfo osi; | |
8080 | struct elf32_arm_link_hash_table *htab; | |
8081 | ||
8082 | htab = elf32_arm_hash_table (info); | |
8083 | if (!htab->splt || htab->splt->size == 0) | |
8084 | return TRUE; | |
8085 | ||
8086 | check_use_blx(htab); | |
8087 | osi.finfo = finfo; | |
8088 | osi.info = info; | |
8089 | osi.func = func; | |
8090 | osi.plt_shndx = _bfd_elf_section_from_bfd_section (output_bfd, | |
8091 | htab->splt->output_section); | |
8092 | osi.plt_offset = htab->splt->output_section->vma; | |
8093 | ||
8094 | /* Output mapping symbols for the plt header. SymbianOS does not have a | |
8095 | plt header. */ | |
8096 | if (htab->vxworks_p) | |
8097 | { | |
8098 | /* VxWorks shared libraries have no PLT header. */ | |
8099 | if (!info->shared) | |
8100 | { | |
8101 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
8102 | return FALSE; | |
8103 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12)) | |
8104 | return FALSE; | |
8105 | } | |
8106 | } | |
8107 | else if (!htab->symbian_p) | |
8108 | { | |
8109 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) | |
8110 | return FALSE; | |
8111 | #ifndef FOUR_WORD_PLT | |
8112 | if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16)) | |
8113 | return FALSE; | |
8114 | #endif | |
8115 | } | |
8116 | ||
8117 | elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi); | |
8118 | return TRUE; | |
8119 | } | |
8120 | ||
e489d0ae PB |
8121 | /* Allocate target specific section data. */ |
8122 | ||
8123 | static bfd_boolean | |
8124 | elf32_arm_new_section_hook (bfd *abfd, asection *sec) | |
8125 | { | |
f592407e AM |
8126 | if (!sec->used_by_bfd) |
8127 | { | |
8128 | _arm_elf_section_data *sdata; | |
8129 | bfd_size_type amt = sizeof (*sdata); | |
e489d0ae | 8130 | |
f592407e AM |
8131 | sdata = bfd_zalloc (abfd, amt); |
8132 | if (sdata == NULL) | |
8133 | return FALSE; | |
8134 | sec->used_by_bfd = sdata; | |
8135 | } | |
e489d0ae | 8136 | |
957c6e41 | 8137 | record_section_with_arm_elf_section_data (sec); |
8e3de13a | 8138 | |
e489d0ae PB |
8139 | return _bfd_elf_new_section_hook (abfd, sec); |
8140 | } | |
8141 | ||
8142 | ||
8143 | /* Used to order a list of mapping symbols by address. */ | |
8144 | ||
8145 | static int | |
8146 | elf32_arm_compare_mapping (const void * a, const void * b) | |
8147 | { | |
8148 | return ((const elf32_arm_section_map *) a)->vma | |
8149 | > ((const elf32_arm_section_map *) b)->vma; | |
8150 | } | |
8151 | ||
8152 | ||
8153 | /* Do code byteswapping. Return FALSE afterwards so that the section is | |
8154 | written out as normal. */ | |
8155 | ||
8156 | static bfd_boolean | |
8157 | elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec, | |
8158 | bfd_byte *contents) | |
8159 | { | |
8160 | int mapcount; | |
8e3de13a | 8161 | _arm_elf_section_data *arm_data; |
e489d0ae PB |
8162 | elf32_arm_section_map *map; |
8163 | bfd_vma ptr; | |
8164 | bfd_vma end; | |
8165 | bfd_vma offset; | |
8166 | bfd_byte tmp; | |
8167 | int i; | |
57e8b36a | 8168 | |
8e3de13a NC |
8169 | /* If this section has not been allocated an _arm_elf_section_data |
8170 | structure then we cannot record anything. */ | |
8171 | arm_data = get_arm_elf_section_data (sec); | |
8172 | if (arm_data == NULL) | |
8173 | return FALSE; | |
8174 | ||
8175 | mapcount = arm_data->mapcount; | |
8176 | map = arm_data->map; | |
e489d0ae PB |
8177 | |
8178 | if (mapcount == 0) | |
8179 | return FALSE; | |
8180 | ||
8e3de13a | 8181 | qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping); |
e489d0ae PB |
8182 | |
8183 | offset = sec->output_section->vma + sec->output_offset; | |
8184 | ptr = map[0].vma - offset; | |
8185 | for (i = 0; i < mapcount; i++) | |
8186 | { | |
8187 | if (i == mapcount - 1) | |
eea6121a | 8188 | end = sec->size; |
e489d0ae PB |
8189 | else |
8190 | end = map[i + 1].vma - offset; | |
57e8b36a | 8191 | |
e489d0ae PB |
8192 | switch (map[i].type) |
8193 | { | |
8194 | case 'a': | |
8195 | /* Byte swap code words. */ | |
8196 | while (ptr + 3 < end) | |
8197 | { | |
8198 | tmp = contents[ptr]; | |
8199 | contents[ptr] = contents[ptr + 3]; | |
8200 | contents[ptr + 3] = tmp; | |
8201 | tmp = contents[ptr + 1]; | |
8202 | contents[ptr + 1] = contents[ptr + 2]; | |
8203 | contents[ptr + 2] = tmp; | |
8204 | ptr += 4; | |
8205 | } | |
8206 | break; | |
8207 | ||
8208 | case 't': | |
8209 | /* Byte swap code halfwords. */ | |
8210 | while (ptr + 1 < end) | |
8211 | { | |
8212 | tmp = contents[ptr]; | |
8213 | contents[ptr] = contents[ptr + 1]; | |
8214 | contents[ptr + 1] = tmp; | |
8215 | ptr += 2; | |
8216 | } | |
8217 | break; | |
8218 | ||
8219 | case 'd': | |
8220 | /* Leave data alone. */ | |
8221 | break; | |
8222 | } | |
8223 | ptr = end; | |
8224 | } | |
8e3de13a | 8225 | |
93204d3a | 8226 | free (map); |
8e3de13a NC |
8227 | arm_data->mapcount = 0; |
8228 | arm_data->map = NULL; | |
8229 | unrecord_section_with_arm_elf_section_data (sec); | |
8230 | ||
e489d0ae PB |
8231 | return FALSE; |
8232 | } | |
8233 | ||
957c6e41 NC |
8234 | static void |
8235 | unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED, | |
8236 | asection * sec, | |
8237 | void * ignore ATTRIBUTE_UNUSED) | |
8238 | { | |
8239 | unrecord_section_with_arm_elf_section_data (sec); | |
8240 | } | |
8241 | ||
8242 | static bfd_boolean | |
8243 | elf32_arm_close_and_cleanup (bfd * abfd) | |
8244 | { | |
b25e3d87 L |
8245 | if (abfd->sections) |
8246 | bfd_map_over_sections (abfd, | |
8247 | unrecord_section_via_map_over_sections, | |
8248 | NULL); | |
957c6e41 NC |
8249 | |
8250 | return _bfd_elf_close_and_cleanup (abfd); | |
8251 | } | |
8252 | ||
b25e3d87 L |
8253 | static bfd_boolean |
8254 | elf32_arm_bfd_free_cached_info (bfd * abfd) | |
8255 | { | |
8256 | if (abfd->sections) | |
8257 | bfd_map_over_sections (abfd, | |
8258 | unrecord_section_via_map_over_sections, | |
8259 | NULL); | |
8260 | ||
8261 | return _bfd_free_cached_info (abfd); | |
8262 | } | |
8263 | ||
b7693d02 DJ |
8264 | /* Display STT_ARM_TFUNC symbols as functions. */ |
8265 | ||
8266 | static void | |
8267 | elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
8268 | asymbol *asym) | |
8269 | { | |
8270 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; | |
8271 | ||
8272 | if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC) | |
8273 | elfsym->symbol.flags |= BSF_FUNCTION; | |
8274 | } | |
8275 | ||
0beaef2b PB |
8276 | |
8277 | /* Mangle thumb function symbols as we read them in. */ | |
8278 | ||
8279 | static void | |
8280 | elf32_arm_swap_symbol_in (bfd * abfd, | |
8281 | const void *psrc, | |
8282 | const void *pshn, | |
8283 | Elf_Internal_Sym *dst) | |
8284 | { | |
8285 | bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst); | |
8286 | ||
8287 | /* New EABI objects mark thumb function symbols by setting the low bit of | |
8288 | the address. Turn these into STT_ARM_TFUNC. */ | |
8289 | if (ELF_ST_TYPE (dst->st_info) == STT_FUNC | |
8290 | && (dst->st_value & 1)) | |
8291 | { | |
8292 | dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); | |
8293 | dst->st_value &= ~(bfd_vma) 1; | |
8294 | } | |
8295 | } | |
8296 | ||
8297 | ||
8298 | /* Mangle thumb function symbols as we write them out. */ | |
8299 | ||
8300 | static void | |
8301 | elf32_arm_swap_symbol_out (bfd *abfd, | |
8302 | const Elf_Internal_Sym *src, | |
8303 | void *cdst, | |
8304 | void *shndx) | |
8305 | { | |
8306 | Elf_Internal_Sym newsym; | |
8307 | ||
8308 | /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit | |
8309 | of the address set, as per the new EABI. We do this unconditionally | |
8310 | because objcopy does not set the elf header flags until after | |
8311 | it writes out the symbol table. */ | |
8312 | if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) | |
8313 | { | |
8314 | newsym = *src; | |
8315 | newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); | |
8316 | newsym.st_value |= 1; | |
8317 | ||
8318 | src = &newsym; | |
8319 | } | |
8320 | bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); | |
8321 | } | |
8322 | ||
b294bdf8 MM |
8323 | /* Add the PT_ARM_EXIDX program header. */ |
8324 | ||
8325 | static bfd_boolean | |
8326 | elf32_arm_modify_segment_map (bfd *abfd, | |
8327 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
8328 | { | |
8329 | struct elf_segment_map *m; | |
8330 | asection *sec; | |
8331 | ||
8332 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
8333 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
8334 | { | |
8335 | /* If there is already a PT_ARM_EXIDX header, then we do not | |
8336 | want to add another one. This situation arises when running | |
8337 | "strip"; the input binary already has the header. */ | |
8338 | m = elf_tdata (abfd)->segment_map; | |
8339 | while (m && m->p_type != PT_ARM_EXIDX) | |
8340 | m = m->next; | |
8341 | if (!m) | |
8342 | { | |
8343 | m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); | |
8344 | if (m == NULL) | |
8345 | return FALSE; | |
8346 | m->p_type = PT_ARM_EXIDX; | |
8347 | m->count = 1; | |
8348 | m->sections[0] = sec; | |
8349 | ||
8350 | m->next = elf_tdata (abfd)->segment_map; | |
8351 | elf_tdata (abfd)->segment_map = m; | |
8352 | } | |
8353 | } | |
8354 | ||
8355 | return TRUE; | |
8356 | } | |
8357 | ||
8358 | /* We may add a PT_ARM_EXIDX program header. */ | |
8359 | ||
8360 | static int | |
8361 | elf32_arm_additional_program_headers (bfd *abfd) | |
8362 | { | |
8363 | asection *sec; | |
8364 | ||
8365 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
8366 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
8367 | return 1; | |
8368 | else | |
8369 | return 0; | |
8370 | } | |
8371 | ||
0beaef2b PB |
8372 | /* We use this to override swap_symbol_in and swap_symbol_out. */ |
8373 | const struct elf_size_info elf32_arm_size_info = { | |
8374 | sizeof (Elf32_External_Ehdr), | |
8375 | sizeof (Elf32_External_Phdr), | |
8376 | sizeof (Elf32_External_Shdr), | |
8377 | sizeof (Elf32_External_Rel), | |
8378 | sizeof (Elf32_External_Rela), | |
8379 | sizeof (Elf32_External_Sym), | |
8380 | sizeof (Elf32_External_Dyn), | |
8381 | sizeof (Elf_External_Note), | |
8382 | 4, | |
8383 | 1, | |
8384 | 32, 2, | |
8385 | ELFCLASS32, EV_CURRENT, | |
8386 | bfd_elf32_write_out_phdrs, | |
8387 | bfd_elf32_write_shdrs_and_ehdr, | |
8388 | bfd_elf32_write_relocs, | |
8389 | elf32_arm_swap_symbol_in, | |
8390 | elf32_arm_swap_symbol_out, | |
8391 | bfd_elf32_slurp_reloc_table, | |
8392 | bfd_elf32_slurp_symbol_table, | |
8393 | bfd_elf32_swap_dyn_in, | |
8394 | bfd_elf32_swap_dyn_out, | |
8395 | bfd_elf32_swap_reloc_in, | |
8396 | bfd_elf32_swap_reloc_out, | |
8397 | bfd_elf32_swap_reloca_in, | |
8398 | bfd_elf32_swap_reloca_out | |
8399 | }; | |
8400 | ||
252b5132 RH |
8401 | #define ELF_ARCH bfd_arch_arm |
8402 | #define ELF_MACHINE_CODE EM_ARM | |
d0facd1b NC |
8403 | #ifdef __QNXTARGET__ |
8404 | #define ELF_MAXPAGESIZE 0x1000 | |
8405 | #else | |
f21f3fe0 | 8406 | #define ELF_MAXPAGESIZE 0x8000 |
d0facd1b | 8407 | #endif |
b1342370 | 8408 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 8409 | #define ELF_COMMONPAGESIZE 0x1000 |
252b5132 | 8410 | |
ba93b8ac DJ |
8411 | #define bfd_elf32_mkobject elf32_arm_mkobject |
8412 | ||
99e4ae17 AJ |
8413 | #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data |
8414 | #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data | |
252b5132 RH |
8415 | #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags |
8416 | #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data | |
8417 | #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create | |
dc810e39 | 8418 | #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup |
252b5132 | 8419 | #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line |
4ab527b0 | 8420 | #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info |
e489d0ae | 8421 | #define bfd_elf32_new_section_hook elf32_arm_new_section_hook |
3c9458e9 | 8422 | #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol |
957c6e41 | 8423 | #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup |
b25e3d87 | 8424 | #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info |
ee065d83 | 8425 | #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link |
252b5132 RH |
8426 | |
8427 | #define elf_backend_get_symbol_type elf32_arm_get_symbol_type | |
8428 | #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook | |
8429 | #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook | |
8430 | #define elf_backend_check_relocs elf32_arm_check_relocs | |
dc810e39 | 8431 | #define elf_backend_relocate_section elf32_arm_relocate_section |
e489d0ae | 8432 | #define elf_backend_write_section elf32_arm_write_section |
252b5132 | 8433 | #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol |
5e681ec4 | 8434 | #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections |
252b5132 RH |
8435 | #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol |
8436 | #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections | |
e489d0ae | 8437 | #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook |
252b5132 | 8438 | #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections |
ba96a88f | 8439 | #define elf_backend_post_process_headers elf32_arm_post_process_headers |
99e4ae17 | 8440 | #define elf_backend_reloc_type_class elf32_arm_reloc_type_class |
c178919b | 8441 | #define elf_backend_object_p elf32_arm_object_p |
e16bb312 | 8442 | #define elf_backend_section_flags elf32_arm_section_flags |
40a18ebd NC |
8443 | #define elf_backend_fake_sections elf32_arm_fake_sections |
8444 | #define elf_backend_section_from_shdr elf32_arm_section_from_shdr | |
e16bb312 | 8445 | #define elf_backend_final_write_processing elf32_arm_final_write_processing |
5e681ec4 | 8446 | #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol |
b7693d02 | 8447 | #define elf_backend_symbol_processing elf32_arm_symbol_processing |
0beaef2b | 8448 | #define elf_backend_size_info elf32_arm_size_info |
b294bdf8 MM |
8449 | #define elf_backend_modify_segment_map elf32_arm_modify_segment_map |
8450 | #define elf_backend_additional_program_headers \ | |
8451 | elf32_arm_additional_program_headers | |
4e617b1e PB |
8452 | #define elf_backend_output_arch_local_syms \ |
8453 | elf32_arm_output_arch_local_syms | |
252b5132 | 8454 | |
5e681ec4 | 8455 | #define elf_backend_can_refcount 1 |
252b5132 RH |
8456 | #define elf_backend_can_gc_sections 1 |
8457 | #define elf_backend_plt_readonly 1 | |
8458 | #define elf_backend_want_got_plt 1 | |
8459 | #define elf_backend_want_plt_sym 0 | |
4e7fd91e PB |
8460 | #define elf_backend_may_use_rel_p 1 |
8461 | #define elf_backend_may_use_rela_p 0 | |
8462 | #define elf_backend_default_use_rela_p 0 | |
8463 | #define elf_backend_rela_normal 0 | |
252b5132 | 8464 | |
04f7c78d | 8465 | #define elf_backend_got_header_size 12 |
04f7c78d | 8466 | |
252b5132 | 8467 | #include "elf32-target.h" |
7f266840 | 8468 | |
4e7fd91e PB |
8469 | /* VxWorks Targets */ |
8470 | ||
8471 | #undef TARGET_LITTLE_SYM | |
8472 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec | |
8473 | #undef TARGET_LITTLE_NAME | |
8474 | #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks" | |
8475 | #undef TARGET_BIG_SYM | |
8476 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec | |
8477 | #undef TARGET_BIG_NAME | |
8478 | #define TARGET_BIG_NAME "elf32-bigarm-vxworks" | |
8479 | ||
8480 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
8481 | appropriately for VxWorks. */ | |
8482 | static struct bfd_link_hash_table * | |
8483 | elf32_arm_vxworks_link_hash_table_create (bfd *abfd) | |
8484 | { | |
8485 | struct bfd_link_hash_table *ret; | |
8486 | ||
8487 | ret = elf32_arm_link_hash_table_create (abfd); | |
8488 | if (ret) | |
8489 | { | |
8490 | struct elf32_arm_link_hash_table *htab | |
00a97672 | 8491 | = (struct elf32_arm_link_hash_table *) ret; |
4e7fd91e | 8492 | htab->use_rel = 0; |
00a97672 | 8493 | htab->vxworks_p = 1; |
4e7fd91e PB |
8494 | } |
8495 | return ret; | |
8496 | } | |
8497 | ||
00a97672 RS |
8498 | static void |
8499 | elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
8500 | { | |
8501 | elf32_arm_final_write_processing (abfd, linker); | |
8502 | elf_vxworks_final_write_processing (abfd, linker); | |
8503 | } | |
8504 | ||
4e7fd91e PB |
8505 | #undef elf32_bed |
8506 | #define elf32_bed elf32_arm_vxworks_bed | |
8507 | ||
8508 | #undef bfd_elf32_bfd_link_hash_table_create | |
8509 | #define bfd_elf32_bfd_link_hash_table_create \ | |
8510 | elf32_arm_vxworks_link_hash_table_create | |
00a97672 RS |
8511 | #undef elf_backend_add_symbol_hook |
8512 | #define elf_backend_add_symbol_hook \ | |
8513 | elf_vxworks_add_symbol_hook | |
8514 | #undef elf_backend_final_write_processing | |
8515 | #define elf_backend_final_write_processing \ | |
8516 | elf32_arm_vxworks_final_write_processing | |
8517 | #undef elf_backend_emit_relocs | |
8518 | #define elf_backend_emit_relocs \ | |
8519 | elf_vxworks_emit_relocs | |
4e7fd91e PB |
8520 | |
8521 | #undef elf_backend_may_use_rel_p | |
00a97672 | 8522 | #define elf_backend_may_use_rel_p 0 |
4e7fd91e | 8523 | #undef elf_backend_may_use_rela_p |
00a97672 | 8524 | #define elf_backend_may_use_rela_p 1 |
4e7fd91e | 8525 | #undef elf_backend_default_use_rela_p |
00a97672 | 8526 | #define elf_backend_default_use_rela_p 1 |
4e7fd91e | 8527 | #undef elf_backend_rela_normal |
00a97672 RS |
8528 | #define elf_backend_rela_normal 1 |
8529 | #undef elf_backend_want_plt_sym | |
8530 | #define elf_backend_want_plt_sym 1 | |
8531 | #undef ELF_MAXPAGESIZE | |
8532 | #define ELF_MAXPAGESIZE 0x1000 | |
4e7fd91e PB |
8533 | |
8534 | #include "elf32-target.h" | |
8535 | ||
8536 | ||
7f266840 DJ |
8537 | /* Symbian OS Targets */ |
8538 | ||
8539 | #undef TARGET_LITTLE_SYM | |
8540 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec | |
8541 | #undef TARGET_LITTLE_NAME | |
8542 | #define TARGET_LITTLE_NAME "elf32-littlearm-symbian" | |
8543 | #undef TARGET_BIG_SYM | |
8544 | #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec | |
8545 | #undef TARGET_BIG_NAME | |
8546 | #define TARGET_BIG_NAME "elf32-bigarm-symbian" | |
8547 | ||
8548 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
8549 | appropriately for Symbian OS. */ | |
8550 | static struct bfd_link_hash_table * | |
8551 | elf32_arm_symbian_link_hash_table_create (bfd *abfd) | |
8552 | { | |
8553 | struct bfd_link_hash_table *ret; | |
8554 | ||
8555 | ret = elf32_arm_link_hash_table_create (abfd); | |
8556 | if (ret) | |
8557 | { | |
8558 | struct elf32_arm_link_hash_table *htab | |
8559 | = (struct elf32_arm_link_hash_table *)ret; | |
8560 | /* There is no PLT header for Symbian OS. */ | |
8561 | htab->plt_header_size = 0; | |
8562 | /* The PLT entries are each three instructions. */ | |
8563 | htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); | |
8564 | htab->symbian_p = 1; | |
33bfe774 JB |
8565 | /* Symbian uses armv5t or above, so use_blx is always true. */ |
8566 | htab->use_blx = 1; | |
67687978 | 8567 | htab->root.is_relocatable_executable = 1; |
7f266840 DJ |
8568 | } |
8569 | return ret; | |
8570 | } | |
8571 | ||
b35d266b | 8572 | static const struct bfd_elf_special_section |
551b43fd | 8573 | elf32_arm_symbian_special_sections[] = |
7f266840 | 8574 | { |
5cd3778d MM |
8575 | /* In a BPABI executable, the dynamic linking sections do not go in |
8576 | the loadable read-only segment. The post-linker may wish to | |
8577 | refer to these sections, but they are not part of the final | |
8578 | program image. */ | |
7f266840 DJ |
8579 | { ".dynamic", 8, 0, SHT_DYNAMIC, 0 }, |
8580 | { ".dynstr", 7, 0, SHT_STRTAB, 0 }, | |
8581 | { ".dynsym", 7, 0, SHT_DYNSYM, 0 }, | |
8582 | { ".got", 4, 0, SHT_PROGBITS, 0 }, | |
8583 | { ".hash", 5, 0, SHT_HASH, 0 }, | |
5cd3778d MM |
8584 | /* These sections do not need to be writable as the SymbianOS |
8585 | postlinker will arrange things so that no dynamic relocation is | |
8586 | required. */ | |
8587 | { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC }, | |
8588 | { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC }, | |
8589 | { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC }, | |
7f266840 DJ |
8590 | { NULL, 0, 0, 0, 0 } |
8591 | }; | |
8592 | ||
c3c76620 | 8593 | static void |
b34af79c MM |
8594 | elf32_arm_symbian_begin_write_processing (bfd *abfd, |
8595 | struct bfd_link_info *link_info | |
8596 | ATTRIBUTE_UNUSED) | |
c3c76620 MM |
8597 | { |
8598 | /* BPABI objects are never loaded directly by an OS kernel; they are | |
8599 | processed by a postlinker first, into an OS-specific format. If | |
8600 | the D_PAGED bit is set on the file, BFD will align segments on | |
8601 | page boundaries, so that an OS can directly map the file. With | |
8602 | BPABI objects, that just results in wasted space. In addition, | |
8603 | because we clear the D_PAGED bit, map_sections_to_segments will | |
8604 | recognize that the program headers should not be mapped into any | |
8605 | loadable segment. */ | |
8606 | abfd->flags &= ~D_PAGED; | |
8607 | } | |
7f266840 DJ |
8608 | |
8609 | static bfd_boolean | |
b34af79c | 8610 | elf32_arm_symbian_modify_segment_map (bfd *abfd, |
b294bdf8 | 8611 | struct bfd_link_info *info) |
7f266840 DJ |
8612 | { |
8613 | struct elf_segment_map *m; | |
8614 | asection *dynsec; | |
8615 | ||
7f266840 DJ |
8616 | /* BPABI shared libraries and executables should have a PT_DYNAMIC |
8617 | segment. However, because the .dynamic section is not marked | |
8618 | with SEC_LOAD, the generic ELF code will not create such a | |
8619 | segment. */ | |
8620 | dynsec = bfd_get_section_by_name (abfd, ".dynamic"); | |
8621 | if (dynsec) | |
8622 | { | |
8623 | m = _bfd_elf_make_dynamic_segment (abfd, dynsec); | |
8624 | m->next = elf_tdata (abfd)->segment_map; | |
8625 | elf_tdata (abfd)->segment_map = m; | |
8626 | } | |
8627 | ||
b294bdf8 MM |
8628 | /* Also call the generic arm routine. */ |
8629 | return elf32_arm_modify_segment_map (abfd, info); | |
7f266840 DJ |
8630 | } |
8631 | ||
8632 | #undef elf32_bed | |
8633 | #define elf32_bed elf32_arm_symbian_bed | |
8634 | ||
8635 | /* The dynamic sections are not allocated on SymbianOS; the postlinker | |
8636 | will process them and then discard them. */ | |
8637 | #undef ELF_DYNAMIC_SEC_FLAGS | |
8638 | #define ELF_DYNAMIC_SEC_FLAGS \ | |
8639 | (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED) | |
8640 | ||
8641 | #undef bfd_elf32_bfd_link_hash_table_create | |
8642 | #define bfd_elf32_bfd_link_hash_table_create \ | |
8643 | elf32_arm_symbian_link_hash_table_create | |
00a97672 | 8644 | #undef elf_backend_add_symbol_hook |
7f266840 | 8645 | |
29ef7005 L |
8646 | #undef elf_backend_special_sections |
8647 | #define elf_backend_special_sections elf32_arm_symbian_special_sections | |
7f266840 | 8648 | |
c3c76620 MM |
8649 | #undef elf_backend_begin_write_processing |
8650 | #define elf_backend_begin_write_processing \ | |
8651 | elf32_arm_symbian_begin_write_processing | |
00a97672 RS |
8652 | #undef elf_backend_final_write_processing |
8653 | #define elf_backend_final_write_processing \ | |
8654 | elf32_arm_final_write_processing | |
8655 | #undef elf_backend_emit_relocs | |
c3c76620 | 8656 | |
7f266840 DJ |
8657 | #undef elf_backend_modify_segment_map |
8658 | #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map | |
8659 | ||
8660 | /* There is no .got section for BPABI objects, and hence no header. */ | |
8661 | #undef elf_backend_got_header_size | |
8662 | #define elf_backend_got_header_size 0 | |
8663 | ||
8664 | /* Similarly, there is no .got.plt section. */ | |
8665 | #undef elf_backend_want_got_plt | |
8666 | #define elf_backend_want_got_plt 0 | |
8667 | ||
4e7fd91e | 8668 | #undef elf_backend_may_use_rel_p |
00a97672 | 8669 | #define elf_backend_may_use_rel_p 1 |
4e7fd91e | 8670 | #undef elf_backend_may_use_rela_p |
00a97672 | 8671 | #define elf_backend_may_use_rela_p 0 |
4e7fd91e | 8672 | #undef elf_backend_default_use_rela_p |
00a97672 | 8673 | #define elf_backend_default_use_rela_p 0 |
4e7fd91e | 8674 | #undef elf_backend_rela_normal |
00a97672 RS |
8675 | #define elf_backend_rela_normal 0 |
8676 | #undef elf_backend_want_plt_sym | |
8677 | #define elf_backend_want_plt_sym 0 | |
8678 | #undef ELF_MAXPAGESIZE | |
8679 | #define ELF_MAXPAGESIZE 0x8000 | |
4e7fd91e | 8680 | |
7f266840 | 8681 | #include "elf32-target.h" |